From fabcd26e5900556b21f35ebe9aea643825dcc46d Mon Sep 17 00:00:00 2001 From: x1m3 Date: Fri, 17 Nov 2023 16:44:12 +0100 Subject: [PATCH] WIP: Return raw or link qrcode for backward compatibillity --- api_ui/api.yaml | 35 ++++++- internal/api_ui/api.gen.go | 121 +++++++++++++++++++++--- internal/api_ui/server.go | 53 ++++++++--- internal/api_ui/server_test.go | 3 +- internal/core/ports/claims_service.go | 2 +- internal/core/ports/identity_service.go | 2 +- internal/core/ports/link_service.go | 1 + internal/core/services/claims.go | 10 +- internal/core/services/identity.go | 10 +- internal/core/services/link.go | 1 + pkg/link/link_state.go | 10 +- 11 files changed, 204 insertions(+), 44 deletions(-) diff --git a/api_ui/api.yaml b/api_ui/api.yaml index e01d4cd1a..0bd118e7b 100644 --- a/api_ui/api.yaml +++ b/api_ui/api.yaml @@ -49,6 +49,18 @@ paths: tags: - Auth - Connection + parameters: + - name: type + in: query + required: false + description: > + Type: + * `link` - (default value) Return a QR code with a link redirection to the raw content. Easier to scan. + * `raw` - Return the raw QR code. (default value) + schema: + type: string + enum: [ raw, link ] + responses: '200': description: ok @@ -396,7 +408,18 @@ paths: tags: - Credential parameters: + - name: type + in: query + required: false + schema: + type: string + enum: [ raw, link ] + description: > + Type: + * `link` - (default value) Return a QR code with a link redirection to the raw content. Easier to scan. + * `raw` - Return the raw QR code. (default value) - $ref: '#/components/parameters/id' + responses: '200': description: ok @@ -772,6 +795,16 @@ paths: summary: Create Authentication Link QRCode operationId: CreateLinkQrCode parameters: + - name: type + in: query + required: false + schema: + type: string + enum: [ raw, link ] + description: > + Type: + * `link` - (default value) Return a QR code with a link redirection to the raw content. Easier to scan. + * `raw` - Return the raw QR code. (default value) - $ref: '#/components/parameters/id' tags: - Links @@ -990,7 +1023,7 @@ components: - qrCodeLink - schemaType properties: - qrCodeLink: + qrCodeLink: # TODO: Rename to QRCode. It can be a Link or a Raw QR type: string example: iden3comm://?request_uri=https%3A%2F%2Fissuer-demo.polygonid.me%2Fapi%2Fqr-store%3Fid%3Df780a169-8959-4380-9461-f7200e2ed3f4 schemaType: diff --git a/internal/api_ui/api.gen.go b/internal/api_ui/api.gen.go index 58176e41d..76f3bb1db 100644 --- a/internal/api_ui/api.gen.go +++ b/internal/api_ui/api.gen.go @@ -38,6 +38,12 @@ const ( Published StateTransactionStatus = "published" ) +// Defines values for AuthQRCodeParamsType. +const ( + AuthQRCodeParamsTypeLink AuthQRCodeParamsType = "link" + AuthQRCodeParamsTypeRaw AuthQRCodeParamsType = "raw" +) + // Defines values for GetCredentialsParamsStatus. const ( All GetCredentialsParamsStatus = "all" @@ -53,6 +59,18 @@ const ( GetLinksParamsStatusInactive GetLinksParamsStatus = "inactive" ) +// Defines values for CreateLinkQrCodeParamsType. +const ( + CreateLinkQrCodeParamsTypeLink CreateLinkQrCodeParamsType = "link" + CreateLinkQrCodeParamsTypeRaw CreateLinkQrCodeParamsType = "raw" +) + +// Defines values for GetCredentialQrCodeParamsType. +const ( + GetCredentialQrCodeParamsTypeLink GetCredentialQrCodeParamsType = "link" + GetCredentialQrCodeParamsTypeRaw GetCredentialQrCodeParamsType = "raw" +) + // AgentResponse defines model for AgentResponse. type AgentResponse struct { Body interface{} `json:"body"` @@ -318,6 +336,17 @@ type AuthCallbackParams struct { SessionID SessionID `form:"sessionID" json:"sessionID"` } +// AuthQRCodeParams defines parameters for AuthQRCode. +type AuthQRCodeParams struct { + // Type Type: + // * `link` - (default value) Return a QR code with a link redirection to the raw content. Easier to scan. + // * `raw` - Return the raw QR code. (default value) + Type *AuthQRCodeParamsType `form:"type,omitempty" json:"type,omitempty"` +} + +// AuthQRCodeParamsType defines parameters for AuthQRCode. +type AuthQRCodeParamsType string + // GetConnectionsParams defines parameters for GetConnections. type GetConnectionsParams struct { // Query Query string to do full text search in connections. @@ -392,6 +421,28 @@ type GetLinkQRCodeParams struct { SessionID SessionID `form:"sessionID" json:"sessionID"` } +// CreateLinkQrCodeParams defines parameters for CreateLinkQrCode. +type CreateLinkQrCodeParams struct { + // Type Type: + // * `link` - (default value) Return a QR code with a link redirection to the raw content. Easier to scan. + // * `raw` - Return the raw QR code. (default value) + Type *CreateLinkQrCodeParamsType `form:"type,omitempty" json:"type,omitempty"` +} + +// CreateLinkQrCodeParamsType defines parameters for CreateLinkQrCode. +type CreateLinkQrCodeParamsType string + +// GetCredentialQrCodeParams defines parameters for GetCredentialQrCode. +type GetCredentialQrCodeParams struct { + // Type Type: + // * `link` - (default value) Return a QR code with a link redirection to the raw content. Easier to scan. + // * `raw` - Return the raw QR code. (default value) + Type *GetCredentialQrCodeParamsType `form:"type,omitempty" json:"type,omitempty"` +} + +// GetCredentialQrCodeParamsType defines parameters for GetCredentialQrCode. +type GetCredentialQrCodeParamsType string + // GetQrFromStoreParams defines parameters for GetQrFromStore. type GetQrFromStoreParams struct { Id *uuid.UUID `form:"id,omitempty" json:"id,omitempty"` @@ -449,7 +500,7 @@ type ServerInterface interface { AuthCallback(w http.ResponseWriter, r *http.Request, params AuthCallbackParams) // Get Connection QRCode // (GET /v1/authentication/qrcode) - AuthQRCode(w http.ResponseWriter, r *http.Request) + AuthQRCode(w http.ResponseWriter, r *http.Request, params AuthQRCodeParams) // Get Connections // (GET /v1/connections) GetConnections(w http.ResponseWriter, r *http.Request, params GetConnectionsParams) @@ -494,7 +545,7 @@ type ServerInterface interface { GetLinkQRCode(w http.ResponseWriter, r *http.Request, id Id, params GetLinkQRCodeParams) // Create Authentication Link QRCode // (POST /v1/credentials/links/{id}/qrcode) - CreateLinkQrCode(w http.ResponseWriter, r *http.Request, id Id) + CreateLinkQrCode(w http.ResponseWriter, r *http.Request, id Id, params CreateLinkQrCodeParams) // Get Revocation Status // (GET /v1/credentials/revocation/status/{nonce}) GetRevocationStatus(w http.ResponseWriter, r *http.Request, nonce PathNonce) @@ -509,7 +560,7 @@ type ServerInterface interface { GetCredential(w http.ResponseWriter, r *http.Request, id Id) // Get Credential QR code // (GET /v1/credentials/{id}/qrcode) - GetCredentialQrCode(w http.ResponseWriter, r *http.Request, id Id) + GetCredentialQrCode(w http.ResponseWriter, r *http.Request, id Id, params GetCredentialQrCodeParams) // QrCode body // (GET /v1/qr-store) GetQrFromStore(w http.ResponseWriter, r *http.Request, params GetQrFromStoreParams) @@ -584,7 +635,7 @@ func (_ Unimplemented) AuthCallback(w http.ResponseWriter, r *http.Request, para // Get Connection QRCode // (GET /v1/authentication/qrcode) -func (_ Unimplemented) AuthQRCode(w http.ResponseWriter, r *http.Request) { +func (_ Unimplemented) AuthQRCode(w http.ResponseWriter, r *http.Request, params AuthQRCodeParams) { w.WriteHeader(http.StatusNotImplemented) } @@ -674,7 +725,7 @@ func (_ Unimplemented) GetLinkQRCode(w http.ResponseWriter, r *http.Request, id // Create Authentication Link QRCode // (POST /v1/credentials/links/{id}/qrcode) -func (_ Unimplemented) CreateLinkQrCode(w http.ResponseWriter, r *http.Request, id Id) { +func (_ Unimplemented) CreateLinkQrCode(w http.ResponseWriter, r *http.Request, id Id, params CreateLinkQrCodeParams) { w.WriteHeader(http.StatusNotImplemented) } @@ -704,7 +755,7 @@ func (_ Unimplemented) GetCredential(w http.ResponseWriter, r *http.Request, id // Get Credential QR code // (GET /v1/credentials/{id}/qrcode) -func (_ Unimplemented) GetCredentialQrCode(w http.ResponseWriter, r *http.Request, id Id) { +func (_ Unimplemented) GetCredentialQrCode(w http.ResponseWriter, r *http.Request, id Id, params GetCredentialQrCodeParams) { w.WriteHeader(http.StatusNotImplemented) } @@ -896,8 +947,21 @@ func (siw *ServerInterfaceWrapper) AuthCallback(w http.ResponseWriter, r *http.R func (siw *ServerInterfaceWrapper) AuthQRCode(w http.ResponseWriter, r *http.Request) { ctx := r.Context() + var err error + + // Parameter object where we will unmarshal all parameters from the context + var params AuthQRCodeParams + + // ------------- Optional query parameter "type" ------------- + + err = runtime.BindQueryParameter("form", true, false, "type", r.URL.Query(), ¶ms.Type) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "type", Err: err}) + return + } + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.AuthQRCode(w, r) + siw.Handler.AuthQRCode(w, r, params) })) for _, middleware := range siw.HandlerMiddlewares { @@ -1387,8 +1451,19 @@ func (siw *ServerInterfaceWrapper) CreateLinkQrCode(w http.ResponseWriter, r *ht return } + // Parameter object where we will unmarshal all parameters from the context + var params CreateLinkQrCodeParams + + // ------------- Optional query parameter "type" ------------- + + err = runtime.BindQueryParameter("form", true, false, "type", r.URL.Query(), ¶ms.Type) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "type", Err: err}) + return + } + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.CreateLinkQrCode(w, r, id) + siw.Handler.CreateLinkQrCode(w, r, id, params) })) for _, middleware := range siw.HandlerMiddlewares { @@ -1523,8 +1598,19 @@ func (siw *ServerInterfaceWrapper) GetCredentialQrCode(w http.ResponseWriter, r return } + // Parameter object where we will unmarshal all parameters from the context + var params GetCredentialQrCodeParams + + // ------------- Optional query parameter "type" ------------- + + err = runtime.BindQueryParameter("form", true, false, "type", r.URL.Query(), ¶ms.Type) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "type", Err: err}) + return + } + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetCredentialQrCode(w, r, id) + siw.Handler.GetCredentialQrCode(w, r, id, params) })) for _, middleware := range siw.HandlerMiddlewares { @@ -2106,6 +2192,7 @@ func (response AuthCallback500JSONResponse) VisitAuthCallbackResponse(w http.Res } type AuthQRCodeRequestObject struct { + Params AuthQRCodeParams } type AuthQRCodeResponseObject interface { @@ -2660,7 +2747,8 @@ func (response GetLinkQRCode500JSONResponse) VisitGetLinkQRCodeResponse(w http.R } type CreateLinkQrCodeRequestObject struct { - Id Id `json:"id"` + Id Id `json:"id"` + Params CreateLinkQrCodeParams } type CreateLinkQrCodeResponseObject interface { @@ -2862,7 +2950,8 @@ func (response GetCredential500JSONResponse) VisitGetCredentialResponse(w http.R } type GetCredentialQrCodeRequestObject struct { - Id Id `json:"id"` + Id Id `json:"id"` + Params GetCredentialQrCodeParams } type GetCredentialQrCodeResponseObject interface { @@ -3509,9 +3598,11 @@ func (sh *strictHandler) AuthCallback(w http.ResponseWriter, r *http.Request, pa } // AuthQRCode operation middleware -func (sh *strictHandler) AuthQRCode(w http.ResponseWriter, r *http.Request) { +func (sh *strictHandler) AuthQRCode(w http.ResponseWriter, r *http.Request, params AuthQRCodeParams) { var request AuthQRCodeRequestObject + request.Params = params + handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) { return sh.ssi.AuthQRCode(ctx, request.(AuthQRCodeRequestObject)) } @@ -3924,10 +4015,11 @@ func (sh *strictHandler) GetLinkQRCode(w http.ResponseWriter, r *http.Request, i } // CreateLinkQrCode operation middleware -func (sh *strictHandler) CreateLinkQrCode(w http.ResponseWriter, r *http.Request, id Id) { +func (sh *strictHandler) CreateLinkQrCode(w http.ResponseWriter, r *http.Request, id Id, params CreateLinkQrCodeParams) { var request CreateLinkQrCodeRequestObject request.Id = id + request.Params = params handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) { return sh.ssi.CreateLinkQrCode(ctx, request.(CreateLinkQrCodeRequestObject)) @@ -4054,10 +4146,11 @@ func (sh *strictHandler) GetCredential(w http.ResponseWriter, r *http.Request, i } // GetCredentialQrCode operation middleware -func (sh *strictHandler) GetCredentialQrCode(w http.ResponseWriter, r *http.Request, id Id) { +func (sh *strictHandler) GetCredentialQrCode(w http.ResponseWriter, r *http.Request, id Id, params GetCredentialQrCodeParams) { var request GetCredentialQrCodeRequestObject request.Id = id + request.Params = params handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) { return sh.ssi.GetCredentialQrCode(ctx, request.(GetCredentialQrCodeRequestObject)) diff --git a/internal/api_ui/server.go b/internal/api_ui/server.go index 9c0263963..24243b520 100644 --- a/internal/api_ui/server.go +++ b/internal/api_ui/server.go @@ -148,11 +148,20 @@ func (s *Server) AuthCallback(ctx context.Context, request AuthCallbackRequestOb } // AuthQRCode returns the qr code for authenticating a user -func (s *Server) AuthQRCode(ctx context.Context, _ AuthQRCodeRequestObject) (AuthQRCodeResponseObject, error) { - qrCode, err := s.identityService.CreateAuthenticationQRCode(ctx, s.cfg.APIUI.ServerURL, s.cfg.APIUI.IssuerDID) +func (s *Server) AuthQRCode(ctx context.Context, req AuthQRCodeRequestObject) (AuthQRCodeResponseObject, error) { + // TODO: Try to remove qrCode and use only id or make qrCode an object instead of a string + qrCode, id, err := s.identityService.CreateAuthenticationQRCode(ctx, s.cfg.APIUI.ServerURL, s.cfg.APIUI.IssuerDID) if err != nil { return AuthQRCode500JSONResponse{N500JSONResponse{"Unexpected error while creating qr code"}}, nil } + if req.Params.Type != nil && *req.Params.Type == AuthQRCodeParamsTypeRaw { + body, err := s.qrService.Find(ctx, id) + if err != nil { + log.Error(ctx, "qr store. Finding qr", "err", err, "id", id) + return AuthQRCode500JSONResponse{N500JSONResponse{"error looking for qr body"}}, nil + } + return NewQrContentResponse(body), nil + } return NewQrContentResponse([]byte(qrCode)), nil } @@ -530,8 +539,9 @@ func (s *Server) DeleteLink(ctx context.Context, request DeleteLinkRequestObject } // CreateLinkQrCode - Creates a link QrCode -func (s *Server) CreateLinkQrCode(ctx context.Context, request CreateLinkQrCodeRequestObject) (CreateLinkQrCodeResponseObject, error) { - createLinkQrCodeResponse, err := s.linkService.CreateQRCode(ctx, s.cfg.APIUI.IssuerDID, request.Id, s.cfg.APIUI.ServerURL) +// TODO: Test it!!! +func (s *Server) CreateLinkQrCode(ctx context.Context, req CreateLinkQrCodeRequestObject) (CreateLinkQrCodeResponseObject, error) { + createLinkQrCodeResponse, err := s.linkService.CreateQRCode(ctx, s.cfg.APIUI.IssuerDID, req.Id, s.cfg.APIUI.ServerURL) if err != nil { if errors.Is(err, services.ErrLinkNotFound) { return CreateLinkQrCode404JSONResponse{N404JSONResponse{Message: "error: link not found"}}, nil @@ -542,28 +552,48 @@ func (s *Server) CreateLinkQrCode(ctx context.Context, request CreateLinkQrCodeR log.Error(ctx, "Unexpected error while creating qr code", "err", err) return CreateLinkQrCode500JSONResponse{N500JSONResponse{"Unexpected error while creating qr code"}}, nil } + + qrContent := createLinkQrCodeResponse.QrCode + // Backward compatibility. If the type is raw, we return the raw qr code + if req.Params.Type != nil && *req.Params.Type == CreateLinkQrCodeParamsTypeRaw { + rawQrCode, err := s.qrService.Find(ctx, createLinkQrCodeResponse.QrID) + if err != nil { + log.Error(ctx, "qr store. Finding qr", "err", err, "id", qrID) + return CreateLinkQrCode500JSONResponse{N500JSONResponse{"error looking for qr body"}}, nil + } + qrContent = string(rawQrCode) + } return CreateLinkQrCode200JSONResponse{ Issuer: IssuerDescription{ DisplayName: s.cfg.APIUI.IssuerName, Logo: s.cfg.APIUI.IssuerLogo, }, - QrCode: createLinkQrCodeResponse.QrCode, + QrCode: qrContent, SessionID: createLinkQrCodeResponse.SessionID, LinkDetail: getLinkSimpleResponse(*createLinkQrCodeResponse.Link), }, nil } // GetCredentialQrCode - returns a QR Code for fetching the credential -func (s *Server) GetCredentialQrCode(ctx context.Context, request GetCredentialQrCodeRequestObject) (GetCredentialQrCodeResponseObject, error) { - qrLink, schemaType, err := s.claimService.GetCredentialQrCode(ctx, &s.cfg.APIUI.IssuerDID, request.Id, s.cfg.APIUI.ServerURL) +func (s *Server) GetCredentialQrCode(ctx context.Context, req GetCredentialQrCodeRequestObject) (GetCredentialQrCodeResponseObject, error) { + qrContent, schemaType, qrID, err := s.claimService.GetCredentialQrCode(ctx, &s.cfg.APIUI.IssuerDID, req.Id, s.cfg.APIUI.ServerURL) if err != nil { if errors.Is(err, services.ErrClaimNotFound) { return GetCredentialQrCode400JSONResponse{N400JSONResponse{"Credential not found"}}, nil } return GetCredentialQrCode500JSONResponse{N500JSONResponse{err.Error()}}, nil } + // Backward compatibility. If the type is raw, we return the raw qr code + if req.Params.Type != nil && *req.Params.Type == GetCredentialQrCodeParamsTypeRaw { + rawQrCode, err := s.qrService.Find(ctx, qrID) + if err != nil { + log.Error(ctx, "qr store. Finding qr", "err", err, "id", qrID) + return GetCredentialQrCode500JSONResponse{N500JSONResponse{"error looking for qr body"}}, nil + } + qrContent = string(rawQrCode) + } return GetCredentialQrCode200JSONResponse{ - QrCodeLink: qrLink, + QrCodeLink: qrContent, SchemaType: schemaType, }, nil } @@ -598,7 +628,7 @@ func (s *Server) CreateLinkQrCodeCallback(ctx context.Context, request CreateLin // GetLinkQRCode - returns te qr code for adding the credential // -// TODO: Aquí +// TODO: LALA Tocar aquí para que devuelva el qr code de la credencial func (s *Server) GetLinkQRCode(ctx context.Context, request GetLinkQRCodeRequestObject) (GetLinkQRCodeResponseObject, error) { getQRCodeResponse, err := s.linkService.GetQRCode(ctx, request.Params.SessionID, s.cfg.APIUI.IssuerDID, request.Id) if err != nil { @@ -607,8 +637,9 @@ func (s *Server) GetLinkQRCode(ctx context.Context, request GetLinkQRCodeRequest } return GetLinkQRCode400JSONResponse{N400JSONResponse{Message: err.Error()}}, nil } - - if getQRCodeResponse.State.Status == link_state.StatusPending || getQRCodeResponse.State.Status == link_state.StatusDone || getQRCodeResponse.State.Status == link_state.StatusPendingPublish { + if getQRCodeResponse.State.Status == link_state.StatusPending || + getQRCodeResponse.State.Status == link_state.StatusDone || + getQRCodeResponse.State.Status == link_state.StatusPendingPublish { return GetLinkQRCode200JSONResponse{ Status: common.ToPointer(getQRCodeResponse.State.Status), QrCode: getQRCodeResponse.State.QRCode, diff --git a/internal/api_ui/server_test.go b/internal/api_ui/server_test.go index 0f7f559cf..8736445bf 100644 --- a/internal/api_ui/server_test.go +++ b/internal/api_ui/server_test.go @@ -147,7 +147,7 @@ func TestServer_AuthQRCode(t *testing.T) { for _, tc := range []testConfig{ { - name: "should get a qrCode", + name: "should get a qrCode", // TODO: LALA Test type = raw, type = link and type = nil expected: expected{ httpCode: http.StatusOK, response: protocol.AuthorizationRequestMessage{ @@ -1806,6 +1806,7 @@ func TestServer_GetCredentialQrCode(t *testing.T) { }, }, { + // TODO: LALA Test the QR code type to raw, link and none name: "happy path", request: GetCredentialRequestObject{ Id: createdClaim.ID, diff --git a/internal/core/ports/claims_service.go b/internal/core/ports/claims_service.go index 6b4e51e0a..1dc5f15ea 100644 --- a/internal/core/ports/claims_service.go +++ b/internal/core/ports/claims_service.go @@ -185,7 +185,7 @@ type ClaimsService interface { RevokeAllFromConnection(ctx context.Context, connID uuid.UUID, issuerID w3c.DID) error GetRevocationStatus(ctx context.Context, issuerDID w3c.DID, nonce uint64) (*verifiable.RevocationStatus, error) GetByID(ctx context.Context, issID *w3c.DID, id uuid.UUID) (*domain.Claim, error) - GetCredentialQrCode(ctx context.Context, issID *w3c.DID, id uuid.UUID, hostURL string) (string, string, error) + GetCredentialQrCode(ctx context.Context, issID *w3c.DID, id uuid.UUID, hostURL string) (string, string, uuid.UUID, error) Agent(ctx context.Context, req *AgentRequest) (*domain.Agent, error) GetAuthClaim(ctx context.Context, did *w3c.DID) (*domain.Claim, error) GetAuthClaimForPublishing(ctx context.Context, did *w3c.DID, state string) (*domain.Claim, error) diff --git a/internal/core/ports/identity_service.go b/internal/core/ports/identity_service.go index eac5e68bd..3e04b9ebd 100644 --- a/internal/core/ports/identity_service.go +++ b/internal/core/ports/identity_service.go @@ -39,7 +39,7 @@ type IdentityService interface { UpdateIdentityState(ctx context.Context, state *domain.IdentityState) error GetTransactedStates(ctx context.Context) ([]domain.IdentityState, error) GetStates(ctx context.Context, issuerDID w3c.DID) ([]domain.IdentityState, error) - CreateAuthenticationQRCode(ctx context.Context, serverURL string, issuerDID w3c.DID) (string, error) + CreateAuthenticationQRCode(ctx context.Context, serverURL string, issuerDID w3c.DID) (string, uuid.UUID, error) Authenticate(ctx context.Context, message string, sessionID uuid.UUID, serverURL string, issuerDID w3c.DID) (*protocol.AuthorizationResponseMessage, error) GetFailedState(ctx context.Context, identifier w3c.DID) (*domain.IdentityState, error) PublishGenesisStateToRHS(ctx context.Context, did *w3c.DID) error diff --git a/internal/core/ports/link_service.go b/internal/core/ports/link_service.go index 55ec38c68..6514a78a2 100644 --- a/internal/core/ports/link_service.go +++ b/internal/core/ports/link_service.go @@ -18,6 +18,7 @@ import ( type CreateQRCodeResponse struct { Link *domain.Link QrCode string + QrID uuid.UUID SessionID string } diff --git a/internal/core/services/claims.go b/internal/core/services/claims.go index d43c0a193..5d03fe04a 100644 --- a/internal/core/services/claims.go +++ b/internal/core/services/claims.go @@ -294,7 +294,7 @@ func (c *claim) GetByID(ctx context.Context, issID *w3c.DID, id uuid.UUID) (*dom } // GetCredentialQrCode creates a credential QR code for the given credential and returns the QR Link to be used -func (c *claim) GetCredentialQrCode(ctx context.Context, issID *w3c.DID, id uuid.UUID, hostURL string) (string, string, error) { +func (c *claim) GetCredentialQrCode(ctx context.Context, issID *w3c.DID, id uuid.UUID, hostURL string) (string, string, uuid.UUID, error) { getCredentialType := func(credentialType string) string { const schemaParts = 2 parse := strings.Split(credentialType, "#") @@ -306,7 +306,7 @@ func (c *claim) GetCredentialQrCode(ctx context.Context, issID *w3c.DID, id uuid claim, err := c.GetByID(ctx, issID, id) if err != nil { - return "", "", err + return "", "", uuid.Nil, err } credID := uuid.New() qrCode := protocol.CredentialsOfferMessage{ @@ -329,13 +329,13 @@ func (c *claim) GetCredentialQrCode(ctx context.Context, issID *w3c.DID, id uuid raw, err := json.Marshal(qrCode) if err != nil { - return "", "", err + return "", "", uuid.Nil, err } qrID, err := c.qrService.Store(ctx, raw, DefaultQRBodyTTL) if err != nil { - return "", "", err + return "", "", uuid.Nil, err } - return c.qrService.ToURL(hostURL, qrID), getCredentialType(claim.SchemaType), nil + return c.qrService.ToURL(hostURL, qrID), getCredentialType(claim.SchemaType), qrID, nil } func (c *claim) Agent(ctx context.Context, req *ports.AgentRequest) (*domain.Agent, error) { diff --git a/internal/core/services/identity.go b/internal/core/services/identity.go index 28a485678..227522fc5 100644 --- a/internal/core/services/identity.go +++ b/internal/core/services/identity.go @@ -457,7 +457,7 @@ func (i *identity) Authenticate(ctx context.Context, message string, sessionID u return arm, nil } -func (i *identity) CreateAuthenticationQRCode(ctx context.Context, serverURL string, issuerDID w3c.DID) (string, error) { +func (i *identity) CreateAuthenticationQRCode(ctx context.Context, serverURL string, issuerDID w3c.DID) (string, uuid.UUID, error) { sessionID := uuid.New().String() reqID := uuid.New().String() @@ -473,18 +473,18 @@ func (i *identity) CreateAuthenticationQRCode(ctx context.Context, serverURL str }, } if err := i.sessionManager.Set(ctx, sessionID, *qrCode); err != nil { - return "", err + return "", uuid.Nil, err } raw, err := json.Marshal(qrCode) if err != nil { - return "", err + return "", uuid.Nil, err } id, err := i.qrService.Store(ctx, raw, DefaultQRBodyTTL) if err != nil { - return "", err + return "", uuid.Nil, err } - return i.qrService.ToURL(serverURL, id), nil + return i.qrService.ToURL(serverURL, id), id, nil } func (i *identity) update(ctx context.Context, conn db.Querier, id *w3c.DID, currentState domain.IdentityState) error { diff --git a/internal/core/services/link.go b/internal/core/services/link.go index 7247a216e..92838e0f8 100644 --- a/internal/core/services/link.go +++ b/internal/core/services/link.go @@ -197,6 +197,7 @@ func (ls *Link) CreateQRCode(ctx context.Context, issuerDID w3c.DID, linkID uuid return &ports.CreateQRCodeResponse{ SessionID: sessionID, QrCode: ls.qrService.ToURL(serverURL, id), + QrID: id, Link: link, }, nil } diff --git a/pkg/link/link_state.go b/pkg/link/link_state.go index b2f201467..e9b1f1c73 100644 --- a/pkg/link/link_state.go +++ b/pkg/link/link_state.go @@ -31,7 +31,7 @@ type CredentialsLinkMessageBody struct { Credentials []CredentialLink `json:"credentials"` } -// QRCodeMessage - TODO +// QRCodeMessage represents a QRCode message type QRCodeMessage struct { ID string `json:"id"` Typ string `json:"typ,omitempty"` @@ -49,7 +49,7 @@ type State struct { QRCode *string `json:"qrcode"` } -// NewStatePending - TODO +// NewStatePending creates a new pending state func NewStatePending() *State { return &State{Status: StatusPending} } @@ -59,7 +59,7 @@ func (ls *State) String() string { return string(s) } -// CredentialStateCacheKey - TODO +// CredentialStateCacheKey returns the cache key for the credential state func CredentialStateCacheKey(linkID, sessionID string) string { return fmt.Sprintf("credential_link_%s_%s", linkID, sessionID) } @@ -72,7 +72,7 @@ func NewStateError(err error) *State { } } -// NewStateDone - TODO +// NewStateDone creates a new done state func NewStateDone(qrCodeLink string) *State { state := &State{ Status: StatusDone, @@ -81,7 +81,7 @@ func NewStateDone(qrCodeLink string) *State { return state } -// NewStatePendingPublish - TODO +// NewStatePendingPublish creates a new pending publish state func NewStatePendingPublish() *State { state := &State{ Status: StatusPendingPublish,