From 7d6613e6d2e66042f387fce4da4573101e96c79f Mon Sep 17 00:00:00 2001 From: Wout Slakhorst Date: Fri, 27 Sep 2024 08:13:51 +0200 Subject: [PATCH] added checks to VCR.Load() (#3417) --- cmd/root.go | 2 +- docs/_static/vcr/vcr_v2.yaml | 12 +- .../openid4vp_employeecredential/main_test.go | 2 +- .../browser/rfc019_selfsigned/main_test.go | 4 +- e2e-tests/browser/util.go | 4 +- e2e-tests/discovery/run-test.sh | 2 +- e2e-tests/oauth-flow/openid4vp/do-test.sh | 2 +- e2e-tests/oauth-flow/rfc021/do-test.sh | 2 +- vcr/api/vcr/v2/api.go | 72 +++- vcr/api/vcr/v2/api_test.go | 127 +++--- vcr/api/vcr/v2/client.go | 5 +- vcr/api/vcr/v2/generated.go | 382 +++++++++--------- 12 files changed, 345 insertions(+), 271 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index aaa0b3e2da..918595e903 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -211,7 +211,7 @@ func CreateSystem(shutdownCallback context.CancelFunc) *core.System { system.RegisterRoutes(&networkAPI.Wrapper{Service: networkInstance}) system.RegisterRoutes(&vdrAPI.Wrapper{VDR: vdrInstance, SubjectManager: vdrInstance}) system.RegisterRoutes(&vdrAPIv2.Wrapper{VDR: vdrInstance, SubjectManager: vdrInstance}) - system.RegisterRoutes(&vcrAPI.Wrapper{VCR: credentialInstance, ContextManager: jsonld}) + system.RegisterRoutes(&vcrAPI.Wrapper{VCR: credentialInstance, ContextManager: jsonld, SubjectManager: vdrInstance}) system.RegisterRoutes(&openid4vciAPI.Wrapper{ VCR: credentialInstance, VDR: vdrInstance, diff --git a/docs/_static/vcr/vcr_v2.yaml b/docs/_static/vcr/vcr_v2.yaml index 5b6d4133d2..f6e891d382 100644 --- a/docs/_static/vcr/vcr_v2.yaml +++ b/docs/_static/vcr/vcr_v2.yaml @@ -479,17 +479,17 @@ paths: $ref: "#/components/schemas/VerifiablePresentation" default: $ref: '../common/error_response.yaml' - /internal/vcr/v2/holder/{did}/vc: + /internal/vcr/v2/holder/{subjectID}/vc: parameters: - - name: did + - name: subjectID in: path - description: URL encoded DID. + description: Subject ID of the wallet owner at this node. required: true content: plain/text: schema: type: string - example: "did:web:example.com:iam:123" + example: 90BC1AE9-752B-432F-ADC3-DD9F9C61843C get: summary: List all Verifiable Credentials in the holder's wallet. operationId: getCredentialsInWallet @@ -510,8 +510,8 @@ paths: summary: Load a VerifiableCredential into the holders wallet. description: | If a VerifiableCredential is not directly issued to the wallet through e.g. OpenID4VCI, this API allows to add it to a wallet. - The DID of the holder has to be provided in the path. - It's assumed that the credentialSubject.id equals the holder DID. + The subject identifier of the holder has to be provided in the path. + The credentialSubject.id must equal to a DID of the holder, the signature must be valid and the credential must not be expired or revoked. error returns: * 400 - Invalid credential diff --git a/e2e-tests/browser/openid4vp_employeecredential/main_test.go b/e2e-tests/browser/openid4vp_employeecredential/main_test.go index 4fec1373fb..712b487f64 100644 --- a/e2e-tests/browser/openid4vp_employeecredential/main_test.go +++ b/e2e-tests/browser/openid4vp_employeecredential/main_test.go @@ -108,7 +108,7 @@ func Test_UserAccessToken_EmployeeCredential(t *testing.T) { func setupNode(t testing.TB, ctx context.Context, config core.ClientConfig) (string, did.DID, OpenID4VP) { subject, didDoc, err := createDID(config) require.NoError(t, err) - err = browser.IssueOrganizationCredential(didDoc, fmt.Sprintf("%s Organization", didDoc.ID.String()), "Testland", config) + err = browser.IssueOrganizationCredential(subject, didDoc, fmt.Sprintf("%s Organization", didDoc.ID.String()), "Testland", config) require.NoError(t, err) iamClientB, err := iamAPI.NewClient(config.GetAddress()) diff --git a/e2e-tests/browser/rfc019_selfsigned/main_test.go b/e2e-tests/browser/rfc019_selfsigned/main_test.go index 74d16e3528..4e7b436e0c 100644 --- a/e2e-tests/browser/rfc019_selfsigned/main_test.go +++ b/e2e-tests/browser/rfc019_selfsigned/main_test.go @@ -52,14 +52,14 @@ func Test_LoginWithSelfSignedMeans(t *testing.T) { require.NoError(t, err) err = registerCompoundService(verifyingOrganization.ID, purposeOfUse) require.NoError(t, err) - err = browser.IssueOrganizationCredential(verifyingOrganization, "Verifying Organization", "Testland", apps.NodeClientConfig) + err = browser.IssueOrganizationCredential("", verifyingOrganization, "Verifying Organization", "Testland", apps.NodeClientConfig) require.NoError(t, err) issuingOrganization, err := createDID() require.NoError(t, err) err = registerCompoundService(issuingOrganization.ID, purposeOfUse) require.NoError(t, err) - err = browser.IssueOrganizationCredential(issuingOrganization, "Issuing Organization", "Testland", apps.NodeClientConfig) + err = browser.IssueOrganizationCredential("", issuingOrganization, "Issuing Organization", "Testland", apps.NodeClientConfig) require.NoError(t, err) selfSigned := apps.SelfSigned{ diff --git a/e2e-tests/browser/util.go b/e2e-tests/browser/util.go index e45147d6e4..cdb338ad73 100644 --- a/e2e-tests/browser/util.go +++ b/e2e-tests/browser/util.go @@ -26,7 +26,7 @@ import ( vcrAPI "github.com/nuts-foundation/nuts-node/vcr/api/vcr/v2" ) -func IssueOrganizationCredential(organization *did.Document, name, city string, clientConfig core.ClientConfig) error { +func IssueOrganizationCredential(subject string, organization *did.Document, name, city string, clientConfig core.ClientConfig) error { vcrClient := vcrAPI.HTTPClient{ClientConfig: clientConfig} request := vcrAPI.IssueVCRequest{ Issuer: organization.ID.String(), @@ -56,7 +56,7 @@ func IssueOrganizationCredential(organization *did.Document, name, city string, } if organization.ID.Method == "web" { // Need to load it into tbe wallet - return vcrClient.LoadVC(organization.ID, *issuedCredential) + return vcrClient.LoadVC(subject, *issuedCredential) } return nil } diff --git a/e2e-tests/discovery/run-test.sh b/e2e-tests/discovery/run-test.sh index 5e398d99ca..3f721a9a41 100755 --- a/e2e-tests/discovery/run-test.sh +++ b/e2e-tests/discovery/run-test.sh @@ -36,7 +36,7 @@ else exitWithDockerLogs 1 fi -RESPONSE=$(echo $RESPONSE | curl --insecure -s -X POST --data-binary @- http://localhost:28081/internal/vcr/v2/holder/${DID}/vc -H "Content-Type:application/json") +RESPONSE=$(echo $RESPONSE | curl --insecure -s -X POST --data-binary @- http://localhost:28081/internal/vcr/v2/holder/${SUBJECT}/vc -H "Content-Type:application/json") if [[ $RESPONSE -eq "" ]]; then echo "VC stored in wallet" else diff --git a/e2e-tests/oauth-flow/openid4vp/do-test.sh b/e2e-tests/oauth-flow/openid4vp/do-test.sh index 765e306fdb..db68dc0115 100755 --- a/e2e-tests/oauth-flow/openid4vp/do-test.sh +++ b/e2e-tests/oauth-flow/openid4vp/do-test.sh @@ -33,7 +33,7 @@ else exitWithDockerLogs 1 fi -RESPONSE=$(echo $RESPONSE | curl -X POST --data-binary @- http://localhost:28081/internal/vcr/v2/holder/${PARTY_B_DID}/vc -H "Content-Type:application/json") +RESPONSE=$(echo $RESPONSE | curl -X POST --data-binary @- http://localhost:28081/internal/vcr/v2/holder/subjectB/vc -H "Content-Type:application/json") if echo $RESPONSE == ""; then echo "VC stored in wallet" else diff --git a/e2e-tests/oauth-flow/rfc021/do-test.sh b/e2e-tests/oauth-flow/rfc021/do-test.sh index 538d4ef108..05214337ba 100755 --- a/e2e-tests/oauth-flow/rfc021/do-test.sh +++ b/e2e-tests/oauth-flow/rfc021/do-test.sh @@ -54,7 +54,7 @@ else exitWithDockerLogs 1 fi -RESPONSE=$(echo $RESPONSE | curl -X POST --data-binary @- http://localhost:28081/internal/vcr/v2/holder/${VENDOR_B_DID}/vc -H "Content-Type:application/json") +RESPONSE=$(echo $RESPONSE | curl -X POST --data-binary @- http://localhost:28081/internal/vcr/v2/holder/vendorB/vc -H "Content-Type:application/json") if echo $RESPONSE == ""; then echo "VC stored in wallet" else diff --git a/vcr/api/vcr/v2/api.go b/vcr/api/vcr/v2/api.go index c5979340d9..10c9275a70 100644 --- a/vcr/api/vcr/v2/api.go +++ b/vcr/api/vcr/v2/api.go @@ -30,6 +30,7 @@ import ( "github.com/nuts-foundation/nuts-node/vcr/issuer" vcrTypes "github.com/nuts-foundation/nuts-node/vcr/types" "github.com/nuts-foundation/nuts-node/vcr/verifier" + "github.com/nuts-foundation/nuts-node/vdr/didsubject" "github.com/nuts-foundation/nuts-node/vdr/resolver" "net/http" "strings" @@ -55,6 +56,7 @@ var _ StrictServerInterface = (*Wrapper)(nil) type Wrapper struct { ContextManager jsonld.JSONLD VCR vcr.VCR + SubjectManager didsubject.Manager } // Routes registers the handler to the echo router @@ -77,13 +79,14 @@ func (w *Wrapper) Routes(router core.EchoRouter) { // ResolveStatusCode maps errors returned by this API to specific HTTP status codes. func (w *Wrapper) ResolveStatusCode(err error) int { return core.ResolveStatusCode(err, map[error]int{ - vcrTypes.ErrNotFound: http.StatusNotFound, - resolver.ErrServiceNotFound: http.StatusPreconditionFailed, - vcrTypes.ErrRevoked: http.StatusConflict, - resolver.ErrNotFound: http.StatusBadRequest, - resolver.ErrKeyNotFound: http.StatusBadRequest, - did.ErrInvalidDID: http.StatusBadRequest, - vcrTypes.ErrStatusNotFound: http.StatusBadRequest, + vcrTypes.ErrNotFound: http.StatusNotFound, + resolver.ErrServiceNotFound: http.StatusPreconditionFailed, + vcrTypes.ErrRevoked: http.StatusConflict, + resolver.ErrNotFound: http.StatusBadRequest, + resolver.ErrKeyNotFound: http.StatusBadRequest, + did.ErrInvalidDID: http.StatusBadRequest, + vcrTypes.ErrStatusNotFound: http.StatusBadRequest, + didsubject.ErrSubjectNotFound: http.StatusNotFound, }) } @@ -395,14 +398,42 @@ func (w *Wrapper) VerifyVP(ctx context.Context, request VerifyVPRequestObject) ( } func (w *Wrapper) LoadVC(ctx context.Context, request LoadVCRequestObject) (LoadVCResponseObject, error) { - // the actual holder is ignored for now, since we only support a single wallet... - _, err := did.ParseDID(request.Did) - if err != nil { - return nil, core.InvalidInputError("invalid holder DID: %w", err) - } if request.Body == nil { return nil, core.InvalidInputError("missing credential in body") } + + // get DIDs for holder + dids, err := w.SubjectManager.ListDIDs(ctx, request.SubjectID) + if err != nil { + return nil, err + } + + // get credentialSubject.ID for credential + credentialSubject, err := credential.ResolveSubjectDID(*request.Body) + if err != nil { + return nil, core.InvalidInputError("invalid credentialSubject.ID: %w", err) + } + + // check if the credentialSubject.ID is in the list of DIDs + found := false + for _, did := range dids { + if did.Equals(*credentialSubject) { + found = true + break + } + } + if !found { + return nil, core.InvalidInputError("subject does not own DID specified by credentialSubject.ID") + } + + // validate credential + if err = w.VCR.Verifier().Verify(*request.Body, true, true, nil); err != nil { + if errors.Is(err, verifier.VerificationError{}) { + return nil, core.InvalidInputError(err.Error()) + } + return nil, err + } + err = w.VCR.Wallet().Put(ctx, *request.Body) if err != nil { return nil, err @@ -411,14 +442,21 @@ func (w *Wrapper) LoadVC(ctx context.Context, request LoadVCRequestObject) (Load } func (w *Wrapper) GetCredentialsInWallet(ctx context.Context, request GetCredentialsInWalletRequestObject) (GetCredentialsInWalletResponseObject, error) { - holderDID, err := did.ParseDID(request.Did) - if err != nil { - return nil, core.InvalidInputError("invalid holder DID: %w", err) - } - credentials, err := w.VCR.Wallet().List(ctx, *holderDID) + // get DIDs for holder + dids, err := w.SubjectManager.ListDIDs(ctx, request.SubjectID) if err != nil { return nil, err } + + credentials := make([]vc.VerifiableCredential, 0) + for _, did := range dids { + creds, err := w.VCR.Wallet().List(ctx, did) + if err != nil { + return nil, err + } + credentials = append(credentials, creds...) + } + return GetCredentialsInWallet200JSONResponse(credentials), nil } diff --git a/vcr/api/vcr/v2/api_test.go b/vcr/api/vcr/v2/api_test.go index c370091eb4..ce0fcb7304 100644 --- a/vcr/api/vcr/v2/api_test.go +++ b/vcr/api/vcr/v2/api_test.go @@ -23,6 +23,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/nuts-foundation/nuts-node/vdr/didsubject" "github.com/nuts-foundation/nuts-node/vdr/resolver" "net/http" "testing" @@ -47,7 +48,7 @@ import ( var holderDID = did.MustParseDID("did:web:example.com:iam:123") var credentialID = ssi.MustParseURI("did:web:example.com:iam:456#1") -var testVC = vc.VerifiableCredential{ID: &credentialID} +var testVC = vc.VerifiableCredential{ID: &credentialID, CredentialSubject: []interface{}{map[string]interface{}{"ID": holderDID.String()}}} func TestWrapper_IssueVC(t *testing.T) { @@ -735,61 +736,94 @@ func parsedTimeStr(t time.Time) (time.Time, string) { } func TestWrapper_LoadVC(t *testing.T) { - t.Run("test integration with vcr", func(t *testing.T) { - t.Run("successful load", func(t *testing.T) { - testContext := newMockContext(t) - testContext.mockWallet.EXPECT().Put(gomock.Any(), testVC).Return(nil) + subjectID := "holder" + t.Run("successful load", func(t *testing.T) { + testContext := newMockContext(t) + testContext.mockSubjectManager.EXPECT().ListDIDs(gomock.Any(), subjectID).Return([]did.DID{holderDID}, nil) + testContext.mockVerifier.EXPECT().Verify(gomock.Any(), true, true, nil).Return(nil) + testContext.mockWallet.EXPECT().Put(gomock.Any(), testVC).Return(nil) - response, err := testContext.client.LoadVC(testContext.requestCtx, LoadVCRequestObject{Did: holderDID.String(), Body: &testVC}) + response, err := testContext.client.LoadVC(testContext.requestCtx, LoadVCRequestObject{SubjectID: subjectID, Body: &testVC}) - assert.NoError(t, err) - assert.IsType(t, response, LoadVC204Response{}) - }) + assert.NoError(t, err) + assert.IsType(t, response, LoadVC204Response{}) + }) + t.Run("no DIDs for subject", func(t *testing.T) { + testContext := newMockContext(t) + testContext.mockSubjectManager.EXPECT().ListDIDs(gomock.Any(), subjectID).Return([]did.DID{}, didsubject.ErrSubjectNotFound) - t.Run("vcr returns an error", func(t *testing.T) { - testContext := newMockContext(t) - testContext.mockWallet.EXPECT().Put(gomock.Any(), testVC).Return(assert.AnError) + _, err := testContext.client.LoadVC(testContext.requestCtx, LoadVCRequestObject{SubjectID: subjectID, Body: &testVC}) - response, err := testContext.client.LoadVC(testContext.requestCtx, LoadVCRequestObject{Did: holderDID.String(), Body: &testVC}) + assert.ErrorIs(t, err, didsubject.ErrSubjectNotFound) + }) + t.Run("verification failed", func(t *testing.T) { + testContext := newMockContext(t) + testContext.mockSubjectManager.EXPECT().ListDIDs(gomock.Any(), subjectID).Return([]did.DID{holderDID}, nil) + testContext.mockVerifier.EXPECT().Verify(gomock.Any(), true, true, nil).Return(verifier.VerificationError{}) - assert.Empty(t, response) - assert.EqualError(t, err, assert.AnError.Error()) - }) + _, err := testContext.client.LoadVC(testContext.requestCtx, LoadVCRequestObject{SubjectID: subjectID, Body: &testVC}) + + httpErr, ok := err.(core.HTTPStatusCodeError) + require.True(t, ok) + assert.Equal(t, http.StatusBadRequest, httpErr.StatusCode()) }) + t.Run("missing body", func(t *testing.T) { + testContext := newMockContext(t) - t.Run("param check", func(t *testing.T) { - t.Run("invalid credential id format", func(t *testing.T) { - testContext := newMockContext(t) + _, err := testContext.client.LoadVC(testContext.requestCtx, LoadVCRequestObject{SubjectID: subjectID}) - response, err := testContext.client.LoadVC(testContext.requestCtx, LoadVCRequestObject{Did: "%%"}) + assert.EqualError(t, err, "missing credential in body") + }) + t.Run("invalid credentialSubject.ID", func(t *testing.T) { + testContext := newMockContext(t) + testContext.mockSubjectManager.EXPECT().ListDIDs(gomock.Any(), subjectID).Return([]did.DID{holderDID}, nil) - assert.Empty(t, response) - assert.EqualError(t, err, "invalid holder DID: invalid DID") - }) + _, err := testContext.client.LoadVC(testContext.requestCtx, LoadVCRequestObject{SubjectID: subjectID, Body: &vc.VerifiableCredential{ID: &credentialID}}) + + assert.EqualError(t, err, "invalid credentialSubject.ID: unable to get subject DID from VC: there must be at least 1 credentialSubject") + }) + t.Run("subject <> credentialSubject.ID mismatch", func(t *testing.T) { + testContext := newMockContext(t) + testContext.mockSubjectManager.EXPECT().ListDIDs(gomock.Any(), subjectID).Return([]did.DID{did.MustParseDID("did:test:unknown")}, nil) + + _, err := testContext.client.LoadVC(testContext.requestCtx, LoadVCRequestObject{SubjectID: subjectID, Body: &testVC}) + + assert.EqualError(t, err, "subject does not own DID specified by credentialSubject.ID") + }) + t.Run("wallet error", func(t *testing.T) { + testContext := newMockContext(t) + testContext.mockSubjectManager.EXPECT().ListDIDs(gomock.Any(), subjectID).Return([]did.DID{holderDID}, nil) + testContext.mockVerifier.EXPECT().Verify(gomock.Any(), true, true, nil).Return(nil) + testContext.mockWallet.EXPECT().Put(gomock.Any(), testVC).Return(assert.AnError) + + response, err := testContext.client.LoadVC(testContext.requestCtx, LoadVCRequestObject{SubjectID: subjectID, Body: &testVC}) + + assert.Empty(t, response) + assert.EqualError(t, err, assert.AnError.Error()) }) } func TestWrapper_GetCredentialsInWallet(t *testing.T) { + subjectID := "holder" t.Run("ok", func(t *testing.T) { testContext := newMockContext(t) + testContext.mockSubjectManager.EXPECT().ListDIDs(gomock.Any(), subjectID).Return([]did.DID{holderDID}, nil) testContext.mockWallet.EXPECT().List(testContext.requestCtx, holderDID).Return([]vc.VerifiableCredential{testVC}, nil) response, err := testContext.client.GetCredentialsInWallet(testContext.requestCtx, GetCredentialsInWalletRequestObject{ - Did: holderDID.String(), + SubjectID: subjectID, }) assert.NoError(t, err) assert.Equal(t, GetCredentialsInWallet200JSONResponse([]vc.VerifiableCredential{testVC}), response) }) - t.Run("invalid DID", func(t *testing.T) { + t.Run("subject not found", func(t *testing.T) { testContext := newMockContext(t) + testContext.mockSubjectManager.EXPECT().ListDIDs(gomock.Any(), subjectID).Return([]did.DID{}, didsubject.ErrSubjectNotFound) - response, err := testContext.client.GetCredentialsInWallet(testContext.requestCtx, GetCredentialsInWalletRequestObject{ - Did: "%%", - }) + _, err := testContext.client.GetCredentialsInWallet(testContext.requestCtx, GetCredentialsInWalletRequestObject{SubjectID: subjectID}) - assert.Empty(t, response) - assert.EqualError(t, err, "invalid holder DID: invalid DID") + assert.ErrorIs(t, err, didsubject.ErrSubjectNotFound) }) } @@ -1225,13 +1259,14 @@ func TestWrapper_Untrusted(t *testing.T) { } type mockContext struct { - ctrl *gomock.Controller - mockIssuer *issuer.MockIssuer - mockWallet *holder.MockWallet - mockVerifier *verifier.MockVerifier - vcr *vcr.MockVCR - client *Wrapper - requestCtx context.Context + ctrl *gomock.Controller + mockIssuer *issuer.MockIssuer + mockSubjectManager *didsubject.MockManager + mockVerifier *verifier.MockVerifier + mockWallet *holder.MockWallet + vcr *vcr.MockVCR + client *Wrapper + requestCtx context.Context } func newMockContext(t *testing.T) mockContext { @@ -1241,20 +1276,22 @@ func newMockContext(t *testing.T) mockContext { mockIssuer := issuer.NewMockIssuer(ctrl) mockWallet := holder.NewMockWallet(ctrl) mockVerifier := verifier.NewMockVerifier(ctrl) + mockSubjectManager := didsubject.NewMockManager(ctrl) mockVcr.EXPECT().Issuer().Return(mockIssuer).AnyTimes() mockVcr.EXPECT().Wallet().Return(mockWallet).AnyTimes() mockVcr.EXPECT().Verifier().Return(mockVerifier).AnyTimes() - client := &Wrapper{VCR: mockVcr, ContextManager: jsonld.NewTestJSONLDManager(t)} + client := &Wrapper{VCR: mockVcr, ContextManager: jsonld.NewTestJSONLDManager(t), SubjectManager: mockSubjectManager} requestCtx := audit.TestContext() return mockContext{ - ctrl: ctrl, - mockIssuer: mockIssuer, - mockWallet: mockWallet, - mockVerifier: mockVerifier, - vcr: mockVcr, - client: client, - requestCtx: requestCtx, + ctrl: ctrl, + mockIssuer: mockIssuer, + mockSubjectManager: mockSubjectManager, + mockVerifier: mockVerifier, + mockWallet: mockWallet, + vcr: mockVcr, + client: client, + requestCtx: requestCtx, } } diff --git a/vcr/api/vcr/v2/client.go b/vcr/api/vcr/v2/client.go index db0676a6d2..bb77afb380 100644 --- a/vcr/api/vcr/v2/client.go +++ b/vcr/api/vcr/v2/client.go @@ -23,7 +23,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/nuts-foundation/go-did/did" "github.com/nuts-foundation/go-did/vc" "github.com/nuts-foundation/nuts-node/core" "io" @@ -93,10 +92,10 @@ func (hb HTTPClient) Untrusted(credentialType string) ([]string, error) { } // LoadVC loads the given Verifiable Credential into the holder's wallet. -func (hb HTTPClient) LoadVC(holder did.DID, credential vc.VerifiableCredential) error { +func (hb HTTPClient) LoadVC(holderSubjectID string, credential vc.VerifiableCredential) error { ctx := context.Background() - httpResponse, err := hb.client().LoadVC(ctx, holder.String(), credential) + httpResponse, err := hb.client().LoadVC(ctx, holderSubjectID, credential) if err != nil { return err } else if err := core.TestResponseCode(http.StatusNoContent, httpResponse); err != nil { diff --git a/vcr/api/vcr/v2/generated.go b/vcr/api/vcr/v2/generated.go index 32beac6ea3..5ecdc78828 100644 --- a/vcr/api/vcr/v2/generated.go +++ b/vcr/api/vcr/v2/generated.go @@ -482,16 +482,16 @@ type ClientInterface interface { CreateVP(ctx context.Context, body CreateVPJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // RemoveCredentialFromWallet request + RemoveCredentialFromWallet(ctx context.Context, did string, id string, reqEditors ...RequestEditorFn) (*http.Response, error) + // GetCredentialsInWallet request - GetCredentialsInWallet(ctx context.Context, did string, reqEditors ...RequestEditorFn) (*http.Response, error) + GetCredentialsInWallet(ctx context.Context, subjectID string, reqEditors ...RequestEditorFn) (*http.Response, error) // LoadVCWithBody request with any body - LoadVCWithBody(ctx context.Context, did string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + LoadVCWithBody(ctx context.Context, subjectID string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) - LoadVC(ctx context.Context, did string, body LoadVCJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) - - // RemoveCredentialFromWallet request - RemoveCredentialFromWallet(ctx context.Context, did string, id string, reqEditors ...RequestEditorFn) (*http.Response, error) + LoadVC(ctx context.Context, subjectID string, body LoadVCJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // IssueVCWithBody request with any body IssueVCWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -563,8 +563,8 @@ func (c *Client) CreateVP(ctx context.Context, body CreateVPJSONRequestBody, req return c.Client.Do(req) } -func (c *Client) GetCredentialsInWallet(ctx context.Context, did string, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewGetCredentialsInWalletRequest(c.Server, did) +func (c *Client) RemoveCredentialFromWallet(ctx context.Context, did string, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRemoveCredentialFromWalletRequest(c.Server, did, id) if err != nil { return nil, err } @@ -575,8 +575,8 @@ func (c *Client) GetCredentialsInWallet(ctx context.Context, did string, reqEdit return c.Client.Do(req) } -func (c *Client) LoadVCWithBody(ctx context.Context, did string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewLoadVCRequestWithBody(c.Server, did, contentType, body) +func (c *Client) GetCredentialsInWallet(ctx context.Context, subjectID string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetCredentialsInWalletRequest(c.Server, subjectID) if err != nil { return nil, err } @@ -587,8 +587,8 @@ func (c *Client) LoadVCWithBody(ctx context.Context, did string, contentType str return c.Client.Do(req) } -func (c *Client) LoadVC(ctx context.Context, did string, body LoadVCJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewLoadVCRequest(c.Server, did, body) +func (c *Client) LoadVCWithBody(ctx context.Context, subjectID string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewLoadVCRequestWithBody(c.Server, subjectID, contentType, body) if err != nil { return nil, err } @@ -599,8 +599,8 @@ func (c *Client) LoadVC(ctx context.Context, did string, body LoadVCJSONRequestB return c.Client.Do(req) } -func (c *Client) RemoveCredentialFromWallet(ctx context.Context, did string, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewRemoveCredentialFromWalletRequest(c.Server, did, id) +func (c *Client) LoadVC(ctx context.Context, subjectID string, body LoadVCJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewLoadVCRequest(c.Server, subjectID, body) if err != nil { return nil, err } @@ -855,20 +855,27 @@ func NewCreateVPRequestWithBody(server string, contentType string, body io.Reade return req, nil } -// NewGetCredentialsInWalletRequest generates requests for GetCredentialsInWallet -func NewGetCredentialsInWalletRequest(server string, did string) (*http.Request, error) { +// NewRemoveCredentialFromWalletRequest generates requests for RemoveCredentialFromWallet +func NewRemoveCredentialFromWalletRequest(server string, did string, id string) (*http.Request, error) { var err error var pathParam0 string pathParam0 = did + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id) + if err != nil { + return nil, err + } + serverURL, err := url.Parse(server) if err != nil { return nil, err } - operationPath := fmt.Sprintf("/internal/vcr/v2/holder/%s/vc", pathParam0) + operationPath := fmt.Sprintf("/internal/vcr/v2/holder/%s/vc/%s", pathParam0, pathParam1) if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -878,7 +885,7 @@ func NewGetCredentialsInWalletRequest(server string, did string) (*http.Request, return nil, err } - req, err := http.NewRequest("GET", queryURL.String(), nil) + req, err := http.NewRequest("DELETE", queryURL.String(), nil) if err != nil { return nil, err } @@ -886,24 +893,13 @@ func NewGetCredentialsInWalletRequest(server string, did string) (*http.Request, return req, nil } -// NewLoadVCRequest calls the generic LoadVC builder with application/json body -func NewLoadVCRequest(server string, did string, body LoadVCJSONRequestBody) (*http.Request, error) { - var bodyReader io.Reader - buf, err := json.Marshal(body) - if err != nil { - return nil, err - } - bodyReader = bytes.NewReader(buf) - return NewLoadVCRequestWithBody(server, did, "application/json", bodyReader) -} - -// NewLoadVCRequestWithBody generates requests for LoadVC with any type of body -func NewLoadVCRequestWithBody(server string, did string, contentType string, body io.Reader) (*http.Request, error) { +// NewGetCredentialsInWalletRequest generates requests for GetCredentialsInWallet +func NewGetCredentialsInWalletRequest(server string, subjectID string) (*http.Request, error) { var err error var pathParam0 string - pathParam0 = did + pathParam0 = subjectID serverURL, err := url.Parse(server) if err != nil { @@ -920,37 +916,39 @@ func NewLoadVCRequestWithBody(server string, did string, contentType string, bod return nil, err } - req, err := http.NewRequest("POST", queryURL.String(), body) + req, err := http.NewRequest("GET", queryURL.String(), nil) if err != nil { return nil, err } - req.Header.Add("Content-Type", contentType) - return req, nil } -// NewRemoveCredentialFromWalletRequest generates requests for RemoveCredentialFromWallet -func NewRemoveCredentialFromWalletRequest(server string, did string, id string) (*http.Request, error) { +// NewLoadVCRequest calls the generic LoadVC builder with application/json body +func NewLoadVCRequest(server string, subjectID string, body LoadVCJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewLoadVCRequestWithBody(server, subjectID, "application/json", bodyReader) +} + +// NewLoadVCRequestWithBody generates requests for LoadVC with any type of body +func NewLoadVCRequestWithBody(server string, subjectID string, contentType string, body io.Reader) (*http.Request, error) { var err error var pathParam0 string - pathParam0 = did - - var pathParam1 string - - pathParam1, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id) - if err != nil { - return nil, err - } + pathParam0 = subjectID serverURL, err := url.Parse(server) if err != nil { return nil, err } - operationPath := fmt.Sprintf("/internal/vcr/v2/holder/%s/vc/%s", pathParam0, pathParam1) + operationPath := fmt.Sprintf("/internal/vcr/v2/holder/%s/vc", pathParam0) if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -960,11 +958,13 @@ func NewRemoveCredentialFromWalletRequest(server string, did string, id string) return nil, err } - req, err := http.NewRequest("DELETE", queryURL.String(), nil) + req, err := http.NewRequest("POST", queryURL.String(), body) if err != nil { return nil, err } + req.Header.Add("Content-Type", contentType) + return req, nil } @@ -1465,16 +1465,16 @@ type ClientWithResponsesInterface interface { CreateVPWithResponse(ctx context.Context, body CreateVPJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateVPResponse, error) + // RemoveCredentialFromWalletWithResponse request + RemoveCredentialFromWalletWithResponse(ctx context.Context, did string, id string, reqEditors ...RequestEditorFn) (*RemoveCredentialFromWalletResponse, error) + // GetCredentialsInWalletWithResponse request - GetCredentialsInWalletWithResponse(ctx context.Context, did string, reqEditors ...RequestEditorFn) (*GetCredentialsInWalletResponse, error) + GetCredentialsInWalletWithResponse(ctx context.Context, subjectID string, reqEditors ...RequestEditorFn) (*GetCredentialsInWalletResponse, error) // LoadVCWithBodyWithResponse request with any body - LoadVCWithBodyWithResponse(ctx context.Context, did string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*LoadVCResponse, error) + LoadVCWithBodyWithResponse(ctx context.Context, subjectID string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*LoadVCResponse, error) - LoadVCWithResponse(ctx context.Context, did string, body LoadVCJSONRequestBody, reqEditors ...RequestEditorFn) (*LoadVCResponse, error) - - // RemoveCredentialFromWalletWithResponse request - RemoveCredentialFromWalletWithResponse(ctx context.Context, did string, id string, reqEditors ...RequestEditorFn) (*RemoveCredentialFromWalletResponse, error) + LoadVCWithResponse(ctx context.Context, subjectID string, body LoadVCJSONRequestBody, reqEditors ...RequestEditorFn) (*LoadVCResponse, error) // IssueVCWithBodyWithResponse request with any body IssueVCWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*IssueVCResponse, error) @@ -1554,10 +1554,9 @@ func (r CreateVPResponse) StatusCode() int { return 0 } -type GetCredentialsInWalletResponse struct { +type RemoveCredentialFromWalletResponse struct { Body []byte HTTPResponse *http.Response - JSON200 *[]VerifiableCredential ApplicationproblemJSONDefault *struct { // Detail A human-readable explanation specific to this occurrence of the problem. Detail string `json:"detail"` @@ -1571,7 +1570,7 @@ type GetCredentialsInWalletResponse struct { } // Status returns HTTPResponse.Status -func (r GetCredentialsInWalletResponse) Status() string { +func (r RemoveCredentialFromWalletResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -1579,16 +1578,17 @@ func (r GetCredentialsInWalletResponse) Status() string { } // StatusCode returns HTTPResponse.StatusCode -func (r GetCredentialsInWalletResponse) StatusCode() int { +func (r RemoveCredentialFromWalletResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } -type LoadVCResponse struct { +type GetCredentialsInWalletResponse struct { Body []byte HTTPResponse *http.Response + JSON200 *[]VerifiableCredential ApplicationproblemJSONDefault *struct { // Detail A human-readable explanation specific to this occurrence of the problem. Detail string `json:"detail"` @@ -1602,7 +1602,7 @@ type LoadVCResponse struct { } // Status returns HTTPResponse.Status -func (r LoadVCResponse) Status() string { +func (r GetCredentialsInWalletResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -1610,14 +1610,14 @@ func (r LoadVCResponse) Status() string { } // StatusCode returns HTTPResponse.StatusCode -func (r LoadVCResponse) StatusCode() int { +func (r GetCredentialsInWalletResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } -type RemoveCredentialFromWalletResponse struct { +type LoadVCResponse struct { Body []byte HTTPResponse *http.Response ApplicationproblemJSONDefault *struct { @@ -1633,7 +1633,7 @@ type RemoveCredentialFromWalletResponse struct { } // Status returns HTTPResponse.Status -func (r RemoveCredentialFromWalletResponse) Status() string { +func (r LoadVCResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -1641,7 +1641,7 @@ func (r RemoveCredentialFromWalletResponse) Status() string { } // StatusCode returns HTTPResponse.StatusCode -func (r RemoveCredentialFromWalletResponse) StatusCode() int { +func (r LoadVCResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } @@ -2015,39 +2015,39 @@ func (c *ClientWithResponses) CreateVPWithResponse(ctx context.Context, body Cre return ParseCreateVPResponse(rsp) } -// GetCredentialsInWalletWithResponse request returning *GetCredentialsInWalletResponse -func (c *ClientWithResponses) GetCredentialsInWalletWithResponse(ctx context.Context, did string, reqEditors ...RequestEditorFn) (*GetCredentialsInWalletResponse, error) { - rsp, err := c.GetCredentialsInWallet(ctx, did, reqEditors...) +// RemoveCredentialFromWalletWithResponse request returning *RemoveCredentialFromWalletResponse +func (c *ClientWithResponses) RemoveCredentialFromWalletWithResponse(ctx context.Context, did string, id string, reqEditors ...RequestEditorFn) (*RemoveCredentialFromWalletResponse, error) { + rsp, err := c.RemoveCredentialFromWallet(ctx, did, id, reqEditors...) if err != nil { return nil, err } - return ParseGetCredentialsInWalletResponse(rsp) + return ParseRemoveCredentialFromWalletResponse(rsp) } -// LoadVCWithBodyWithResponse request with arbitrary body returning *LoadVCResponse -func (c *ClientWithResponses) LoadVCWithBodyWithResponse(ctx context.Context, did string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*LoadVCResponse, error) { - rsp, err := c.LoadVCWithBody(ctx, did, contentType, body, reqEditors...) +// GetCredentialsInWalletWithResponse request returning *GetCredentialsInWalletResponse +func (c *ClientWithResponses) GetCredentialsInWalletWithResponse(ctx context.Context, subjectID string, reqEditors ...RequestEditorFn) (*GetCredentialsInWalletResponse, error) { + rsp, err := c.GetCredentialsInWallet(ctx, subjectID, reqEditors...) if err != nil { return nil, err } - return ParseLoadVCResponse(rsp) + return ParseGetCredentialsInWalletResponse(rsp) } -func (c *ClientWithResponses) LoadVCWithResponse(ctx context.Context, did string, body LoadVCJSONRequestBody, reqEditors ...RequestEditorFn) (*LoadVCResponse, error) { - rsp, err := c.LoadVC(ctx, did, body, reqEditors...) +// LoadVCWithBodyWithResponse request with arbitrary body returning *LoadVCResponse +func (c *ClientWithResponses) LoadVCWithBodyWithResponse(ctx context.Context, subjectID string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*LoadVCResponse, error) { + rsp, err := c.LoadVCWithBody(ctx, subjectID, contentType, body, reqEditors...) if err != nil { return nil, err } return ParseLoadVCResponse(rsp) } -// RemoveCredentialFromWalletWithResponse request returning *RemoveCredentialFromWalletResponse -func (c *ClientWithResponses) RemoveCredentialFromWalletWithResponse(ctx context.Context, did string, id string, reqEditors ...RequestEditorFn) (*RemoveCredentialFromWalletResponse, error) { - rsp, err := c.RemoveCredentialFromWallet(ctx, did, id, reqEditors...) +func (c *ClientWithResponses) LoadVCWithResponse(ctx context.Context, subjectID string, body LoadVCJSONRequestBody, reqEditors ...RequestEditorFn) (*LoadVCResponse, error) { + rsp, err := c.LoadVC(ctx, subjectID, body, reqEditors...) if err != nil { return nil, err } - return ParseRemoveCredentialFromWalletResponse(rsp) + return ParseLoadVCResponse(rsp) } // IssueVCWithBodyWithResponse request with arbitrary body returning *IssueVCResponse @@ -2239,27 +2239,20 @@ func ParseCreateVPResponse(rsp *http.Response) (*CreateVPResponse, error) { return response, nil } -// ParseGetCredentialsInWalletResponse parses an HTTP response from a GetCredentialsInWalletWithResponse call -func ParseGetCredentialsInWalletResponse(rsp *http.Response) (*GetCredentialsInWalletResponse, error) { +// ParseRemoveCredentialFromWalletResponse parses an HTTP response from a RemoveCredentialFromWalletWithResponse call +func ParseRemoveCredentialFromWalletResponse(rsp *http.Response) (*RemoveCredentialFromWalletResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } - response := &GetCredentialsInWalletResponse{ + response := &RemoveCredentialFromWalletResponse{ Body: bodyBytes, HTTPResponse: rsp, } switch { - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: - var dest []VerifiableCredential - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON200 = &dest - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: var dest struct { // Detail A human-readable explanation specific to this occurrence of the problem. @@ -2281,20 +2274,27 @@ func ParseGetCredentialsInWalletResponse(rsp *http.Response) (*GetCredentialsInW return response, nil } -// ParseLoadVCResponse parses an HTTP response from a LoadVCWithResponse call -func ParseLoadVCResponse(rsp *http.Response) (*LoadVCResponse, error) { +// ParseGetCredentialsInWalletResponse parses an HTTP response from a GetCredentialsInWalletWithResponse call +func ParseGetCredentialsInWalletResponse(rsp *http.Response) (*GetCredentialsInWalletResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } - response := &LoadVCResponse{ + response := &GetCredentialsInWalletResponse{ Body: bodyBytes, HTTPResponse: rsp, } switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest []VerifiableCredential + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: var dest struct { // Detail A human-readable explanation specific to this occurrence of the problem. @@ -2316,15 +2316,15 @@ func ParseLoadVCResponse(rsp *http.Response) (*LoadVCResponse, error) { return response, nil } -// ParseRemoveCredentialFromWalletResponse parses an HTTP response from a RemoveCredentialFromWalletWithResponse call -func ParseRemoveCredentialFromWalletResponse(rsp *http.Response) (*RemoveCredentialFromWalletResponse, error) { +// ParseLoadVCResponse parses an HTTP response from a LoadVCWithResponse call +func ParseLoadVCResponse(rsp *http.Response) (*LoadVCResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } - response := &RemoveCredentialFromWalletResponse{ + response := &LoadVCResponse{ Body: bodyBytes, HTTPResponse: rsp, } @@ -2804,15 +2804,15 @@ type ServerInterface interface { // Create a new Verifiable Presentation for a set of Verifiable Credentials. // (POST /internal/vcr/v2/holder/vp) CreateVP(ctx echo.Context) error - // List all Verifiable Credentials in the holder's wallet. - // (GET /internal/vcr/v2/holder/{did}/vc) - GetCredentialsInWallet(ctx echo.Context, did string) error - // Load a VerifiableCredential into the holders wallet. - // (POST /internal/vcr/v2/holder/{did}/vc) - LoadVC(ctx echo.Context, did string) error // Remove a VerifiableCredential from the holders wallet. // (DELETE /internal/vcr/v2/holder/{did}/vc/{id}) RemoveCredentialFromWallet(ctx echo.Context, did string, id string) error + // List all Verifiable Credentials in the holder's wallet. + // (GET /internal/vcr/v2/holder/{subjectID}/vc) + GetCredentialsInWallet(ctx echo.Context, subjectID string) error + // Load a VerifiableCredential into the holders wallet. + // (POST /internal/vcr/v2/holder/{subjectID}/vc) + LoadVC(ctx echo.Context, subjectID string) error // Issues a new Verifiable Credential // (POST /internal/vcr/v2/issuer/vc) IssueVC(ctx echo.Context) error @@ -2864,56 +2864,56 @@ func (w *ServerInterfaceWrapper) CreateVP(ctx echo.Context) error { return err } -// GetCredentialsInWallet converts echo context to params. -func (w *ServerInterfaceWrapper) GetCredentialsInWallet(ctx echo.Context) error { +// RemoveCredentialFromWallet converts echo context to params. +func (w *ServerInterfaceWrapper) RemoveCredentialFromWallet(ctx echo.Context) error { var err error // ------------- Path parameter "did" ------------- var did string did = ctx.Param("did") + // ------------- Path parameter "id" ------------- + var id string + + err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err)) + } + ctx.Set(JwtBearerAuthScopes, []string{}) // Invoke the callback with all the unmarshaled arguments - err = w.Handler.GetCredentialsInWallet(ctx, did) + err = w.Handler.RemoveCredentialFromWallet(ctx, did, id) return err } -// LoadVC converts echo context to params. -func (w *ServerInterfaceWrapper) LoadVC(ctx echo.Context) error { +// GetCredentialsInWallet converts echo context to params. +func (w *ServerInterfaceWrapper) GetCredentialsInWallet(ctx echo.Context) error { var err error - // ------------- Path parameter "did" ------------- - var did string + // ------------- Path parameter "subjectID" ------------- + var subjectID string - did = ctx.Param("did") + subjectID = ctx.Param("subjectID") ctx.Set(JwtBearerAuthScopes, []string{}) // Invoke the callback with all the unmarshaled arguments - err = w.Handler.LoadVC(ctx, did) + err = w.Handler.GetCredentialsInWallet(ctx, subjectID) return err } -// RemoveCredentialFromWallet converts echo context to params. -func (w *ServerInterfaceWrapper) RemoveCredentialFromWallet(ctx echo.Context) error { +// LoadVC converts echo context to params. +func (w *ServerInterfaceWrapper) LoadVC(ctx echo.Context) error { var err error - // ------------- Path parameter "did" ------------- - var did string - - did = ctx.Param("did") - - // ------------- Path parameter "id" ------------- - var id string + // ------------- Path parameter "subjectID" ------------- + var subjectID string - err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err)) - } + subjectID = ctx.Param("subjectID") ctx.Set(JwtBearerAuthScopes, []string{}) // Invoke the callback with all the unmarshaled arguments - err = w.Handler.RemoveCredentialFromWallet(ctx, did, id) + err = w.Handler.LoadVC(ctx, subjectID) return err } @@ -3118,9 +3118,9 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL } router.POST(baseURL+"/internal/vcr/v2/holder/vp", wrapper.CreateVP) - router.GET(baseURL+"/internal/vcr/v2/holder/:did/vc", wrapper.GetCredentialsInWallet) - router.POST(baseURL+"/internal/vcr/v2/holder/:did/vc", wrapper.LoadVC) router.DELETE(baseURL+"/internal/vcr/v2/holder/:did/vc/:id", wrapper.RemoveCredentialFromWallet) + router.GET(baseURL+"/internal/vcr/v2/holder/:subjectID/vc", wrapper.GetCredentialsInWallet) + router.POST(baseURL+"/internal/vcr/v2/holder/:subjectID/vc", wrapper.LoadVC) router.POST(baseURL+"/internal/vcr/v2/issuer/vc", wrapper.IssueVC) router.GET(baseURL+"/internal/vcr/v2/issuer/vc/search", wrapper.SearchIssuedVCs) router.DELETE(baseURL+"/internal/vcr/v2/issuer/vc/:id", wrapper.RevokeVC) @@ -3173,24 +3173,24 @@ func (response CreateVPdefaultApplicationProblemPlusJSONResponse) VisitCreateVPR return json.NewEncoder(w).Encode(response.Body) } -type GetCredentialsInWalletRequestObject struct { +type RemoveCredentialFromWalletRequestObject struct { Did string `json:"did"` + Id string `json:"id"` } -type GetCredentialsInWalletResponseObject interface { - VisitGetCredentialsInWalletResponse(w http.ResponseWriter) error +type RemoveCredentialFromWalletResponseObject interface { + VisitRemoveCredentialFromWalletResponse(w http.ResponseWriter) error } -type GetCredentialsInWallet200JSONResponse []VerifiableCredential - -func (response GetCredentialsInWallet200JSONResponse) VisitGetCredentialsInWalletResponse(w http.ResponseWriter) error { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(200) +type RemoveCredentialFromWallet204Response struct { +} - return json.NewEncoder(w).Encode(response) +func (response RemoveCredentialFromWallet204Response) VisitRemoveCredentialFromWalletResponse(w http.ResponseWriter) error { + w.WriteHeader(204) + return nil } -type GetCredentialsInWalletdefaultApplicationProblemPlusJSONResponse struct { +type RemoveCredentialFromWalletdefaultApplicationProblemPlusJSONResponse struct { Body struct { // Detail A human-readable explanation specific to this occurrence of the problem. Detail string `json:"detail"` @@ -3204,31 +3204,31 @@ type GetCredentialsInWalletdefaultApplicationProblemPlusJSONResponse struct { StatusCode int } -func (response GetCredentialsInWalletdefaultApplicationProblemPlusJSONResponse) VisitGetCredentialsInWalletResponse(w http.ResponseWriter) error { +func (response RemoveCredentialFromWalletdefaultApplicationProblemPlusJSONResponse) VisitRemoveCredentialFromWalletResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/problem+json") w.WriteHeader(response.StatusCode) return json.NewEncoder(w).Encode(response.Body) } -type LoadVCRequestObject struct { - Did string `json:"did"` - Body *LoadVCJSONRequestBody +type GetCredentialsInWalletRequestObject struct { + SubjectID string `json:"subjectID"` } -type LoadVCResponseObject interface { - VisitLoadVCResponse(w http.ResponseWriter) error +type GetCredentialsInWalletResponseObject interface { + VisitGetCredentialsInWalletResponse(w http.ResponseWriter) error } -type LoadVC204Response struct { -} +type GetCredentialsInWallet200JSONResponse []VerifiableCredential -func (response LoadVC204Response) VisitLoadVCResponse(w http.ResponseWriter) error { - w.WriteHeader(204) - return nil +func (response GetCredentialsInWallet200JSONResponse) VisitGetCredentialsInWalletResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(200) + + return json.NewEncoder(w).Encode(response) } -type LoadVCdefaultApplicationProblemPlusJSONResponse struct { +type GetCredentialsInWalletdefaultApplicationProblemPlusJSONResponse struct { Body struct { // Detail A human-readable explanation specific to this occurrence of the problem. Detail string `json:"detail"` @@ -3242,31 +3242,31 @@ type LoadVCdefaultApplicationProblemPlusJSONResponse struct { StatusCode int } -func (response LoadVCdefaultApplicationProblemPlusJSONResponse) VisitLoadVCResponse(w http.ResponseWriter) error { +func (response GetCredentialsInWalletdefaultApplicationProblemPlusJSONResponse) VisitGetCredentialsInWalletResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/problem+json") w.WriteHeader(response.StatusCode) return json.NewEncoder(w).Encode(response.Body) } -type RemoveCredentialFromWalletRequestObject struct { - Did string `json:"did"` - Id string `json:"id"` +type LoadVCRequestObject struct { + SubjectID string `json:"subjectID"` + Body *LoadVCJSONRequestBody } -type RemoveCredentialFromWalletResponseObject interface { - VisitRemoveCredentialFromWalletResponse(w http.ResponseWriter) error +type LoadVCResponseObject interface { + VisitLoadVCResponse(w http.ResponseWriter) error } -type RemoveCredentialFromWallet204Response struct { +type LoadVC204Response struct { } -func (response RemoveCredentialFromWallet204Response) VisitRemoveCredentialFromWalletResponse(w http.ResponseWriter) error { +func (response LoadVC204Response) VisitLoadVCResponse(w http.ResponseWriter) error { w.WriteHeader(204) return nil } -type RemoveCredentialFromWalletdefaultApplicationProblemPlusJSONResponse struct { +type LoadVCdefaultApplicationProblemPlusJSONResponse struct { Body struct { // Detail A human-readable explanation specific to this occurrence of the problem. Detail string `json:"detail"` @@ -3280,7 +3280,7 @@ type RemoveCredentialFromWalletdefaultApplicationProblemPlusJSONResponse struct StatusCode int } -func (response RemoveCredentialFromWalletdefaultApplicationProblemPlusJSONResponse) VisitRemoveCredentialFromWalletResponse(w http.ResponseWriter) error { +func (response LoadVCdefaultApplicationProblemPlusJSONResponse) VisitLoadVCResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/problem+json") w.WriteHeader(response.StatusCode) @@ -3716,15 +3716,15 @@ type StrictServerInterface interface { // Create a new Verifiable Presentation for a set of Verifiable Credentials. // (POST /internal/vcr/v2/holder/vp) CreateVP(ctx context.Context, request CreateVPRequestObject) (CreateVPResponseObject, error) + // Remove a VerifiableCredential from the holders wallet. + // (DELETE /internal/vcr/v2/holder/{did}/vc/{id}) + RemoveCredentialFromWallet(ctx context.Context, request RemoveCredentialFromWalletRequestObject) (RemoveCredentialFromWalletResponseObject, error) // List all Verifiable Credentials in the holder's wallet. - // (GET /internal/vcr/v2/holder/{did}/vc) + // (GET /internal/vcr/v2/holder/{subjectID}/vc) GetCredentialsInWallet(ctx context.Context, request GetCredentialsInWalletRequestObject) (GetCredentialsInWalletResponseObject, error) // Load a VerifiableCredential into the holders wallet. - // (POST /internal/vcr/v2/holder/{did}/vc) + // (POST /internal/vcr/v2/holder/{subjectID}/vc) LoadVC(ctx context.Context, request LoadVCRequestObject) (LoadVCResponseObject, error) - // Remove a VerifiableCredential from the holders wallet. - // (DELETE /internal/vcr/v2/holder/{did}/vc/{id}) - RemoveCredentialFromWallet(ctx context.Context, request RemoveCredentialFromWalletRequestObject) (RemoveCredentialFromWalletResponseObject, error) // Issues a new Verifiable Credential // (POST /internal/vcr/v2/issuer/vc) IssueVC(ctx context.Context, request IssueVCRequestObject) (IssueVCResponseObject, error) @@ -3801,82 +3801,82 @@ func (sh *strictHandler) CreateVP(ctx echo.Context) error { return nil } -// GetCredentialsInWallet operation middleware -func (sh *strictHandler) GetCredentialsInWallet(ctx echo.Context, did string) error { - var request GetCredentialsInWalletRequestObject +// RemoveCredentialFromWallet operation middleware +func (sh *strictHandler) RemoveCredentialFromWallet(ctx echo.Context, did string, id string) error { + var request RemoveCredentialFromWalletRequestObject request.Did = did + request.Id = id handler := func(ctx echo.Context, request interface{}) (interface{}, error) { - return sh.ssi.GetCredentialsInWallet(ctx.Request().Context(), request.(GetCredentialsInWalletRequestObject)) + return sh.ssi.RemoveCredentialFromWallet(ctx.Request().Context(), request.(RemoveCredentialFromWalletRequestObject)) } for _, middleware := range sh.middlewares { - handler = middleware(handler, "GetCredentialsInWallet") + handler = middleware(handler, "RemoveCredentialFromWallet") } response, err := handler(ctx, request) if err != nil { return err - } else if validResponse, ok := response.(GetCredentialsInWalletResponseObject); ok { - return validResponse.VisitGetCredentialsInWalletResponse(ctx.Response()) + } else if validResponse, ok := response.(RemoveCredentialFromWalletResponseObject); ok { + return validResponse.VisitRemoveCredentialFromWalletResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } -// LoadVC operation middleware -func (sh *strictHandler) LoadVC(ctx echo.Context, did string) error { - var request LoadVCRequestObject - - request.Did = did +// GetCredentialsInWallet operation middleware +func (sh *strictHandler) GetCredentialsInWallet(ctx echo.Context, subjectID string) error { + var request GetCredentialsInWalletRequestObject - var body LoadVCJSONRequestBody - if err := ctx.Bind(&body); err != nil { - return err - } - request.Body = &body + request.SubjectID = subjectID handler := func(ctx echo.Context, request interface{}) (interface{}, error) { - return sh.ssi.LoadVC(ctx.Request().Context(), request.(LoadVCRequestObject)) + return sh.ssi.GetCredentialsInWallet(ctx.Request().Context(), request.(GetCredentialsInWalletRequestObject)) } for _, middleware := range sh.middlewares { - handler = middleware(handler, "LoadVC") + handler = middleware(handler, "GetCredentialsInWallet") } response, err := handler(ctx, request) if err != nil { return err - } else if validResponse, ok := response.(LoadVCResponseObject); ok { - return validResponse.VisitLoadVCResponse(ctx.Response()) + } else if validResponse, ok := response.(GetCredentialsInWalletResponseObject); ok { + return validResponse.VisitGetCredentialsInWalletResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } -// RemoveCredentialFromWallet operation middleware -func (sh *strictHandler) RemoveCredentialFromWallet(ctx echo.Context, did string, id string) error { - var request RemoveCredentialFromWalletRequestObject +// LoadVC operation middleware +func (sh *strictHandler) LoadVC(ctx echo.Context, subjectID string) error { + var request LoadVCRequestObject - request.Did = did - request.Id = id + request.SubjectID = subjectID + + var body LoadVCJSONRequestBody + if err := ctx.Bind(&body); err != nil { + return err + } + request.Body = &body handler := func(ctx echo.Context, request interface{}) (interface{}, error) { - return sh.ssi.RemoveCredentialFromWallet(ctx.Request().Context(), request.(RemoveCredentialFromWalletRequestObject)) + return sh.ssi.LoadVC(ctx.Request().Context(), request.(LoadVCRequestObject)) } for _, middleware := range sh.middlewares { - handler = middleware(handler, "RemoveCredentialFromWallet") + handler = middleware(handler, "LoadVC") } response, err := handler(ctx, request) if err != nil { return err - } else if validResponse, ok := response.(RemoveCredentialFromWalletResponseObject); ok { - return validResponse.VisitRemoveCredentialFromWalletResponse(ctx.Response()) + } else if validResponse, ok := response.(LoadVCResponseObject); ok { + return validResponse.VisitLoadVCResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) }