From 869308b3d0672ccaf1bd312973820c974f0b807c Mon Sep 17 00:00:00 2001 From: Gerard Snaauw <33763579+gerardsn@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:15:34 +0200 Subject: [PATCH] VCR: remove credentials based on subject (#3474) --- docs/_static/vcr/vcr_v2.yaml | 14 +- vcr/api/vcr/v2/api.go | 41 +++-- vcr/api/vcr/v2/api_test.go | 52 ++++-- vcr/api/vcr/v2/generated.go | 330 +++++++++++++++++------------------ 4 files changed, 240 insertions(+), 197 deletions(-) diff --git a/docs/_static/vcr/vcr_v2.yaml b/docs/_static/vcr/vcr_v2.yaml index f6e891d38..64dce67d0 100644 --- a/docs/_static/vcr/vcr_v2.yaml +++ b/docs/_static/vcr/vcr_v2.yaml @@ -530,17 +530,17 @@ paths: description: The credential will not be altered in any way, so no need to return it. default: $ref: '../common/error_response.yaml' - /internal/vcr/v2/holder/{did}/vc/{id}: + /internal/vcr/v2/holder/{subjectID}/vc/{id}: 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 + example: 90BC1AE9-752B-432F-ADC3-DD9F9C61843C - name: id in: path description: URL encoded VC ID. @@ -552,15 +552,15 @@ paths: description: | Remove a VerifiableCredential from the holders wallet. After removal the holder can't present the credential any more. It does not revoke the credential or inform the credential issuer that the wallet removed the wallet. - + error returns: * 400 - Invalid credential - * 404 - Credential not found + * 404 - Credential or subject not found * 500 - An error occurred while processing the request operationId: removeCredentialFromWallet tags: - - credential + - credential responses: "204": description: Credential has been removed from the wallet. diff --git a/vcr/api/vcr/v2/api.go b/vcr/api/vcr/v2/api.go index 1105838ea..e9f2763da 100644 --- a/vcr/api/vcr/v2/api.go +++ b/vcr/api/vcr/v2/api.go @@ -23,15 +23,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/nuts-foundation/nuts-node/audit" - "github.com/nuts-foundation/nuts-node/jsonld" - "github.com/nuts-foundation/nuts-node/vcr/credential" - "github.com/nuts-foundation/nuts-node/vcr/holder" - "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" "time" @@ -40,9 +31,18 @@ import ( ssi "github.com/nuts-foundation/go-did" "github.com/nuts-foundation/go-did/did" "github.com/nuts-foundation/go-did/vc" + "github.com/nuts-foundation/nuts-node/audit" "github.com/nuts-foundation/nuts-node/core" + "github.com/nuts-foundation/nuts-node/jsonld" "github.com/nuts-foundation/nuts-node/vcr" + "github.com/nuts-foundation/nuts-node/vcr/credential" + "github.com/nuts-foundation/nuts-node/vcr/holder" + "github.com/nuts-foundation/nuts-node/vcr/issuer" "github.com/nuts-foundation/nuts-node/vcr/signature/proof" + 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" ) var clockFn = func() time.Time { @@ -461,20 +461,31 @@ func (w *Wrapper) GetCredentialsInWallet(ctx context.Context, request GetCredent } func (w *Wrapper) RemoveCredentialFromWallet(ctx context.Context, request RemoveCredentialFromWalletRequestObject) (RemoveCredentialFromWalletResponseObject, error) { - holderDID, err := did.ParseDID(request.Did) + // get DIDs for holder + dids, err := w.SubjectManager.ListDIDs(ctx, request.SubjectID) if err != nil { - return nil, core.InvalidInputError("invalid holder DID: %w", err) + return nil, err } credentialID, err := ssi.ParseURI(request.Id) if err != nil { return nil, core.InvalidInputError("invalid credential ID: %w", err) } - err = w.VCR.Wallet().Remove(ctx, *holderDID, *credentialID) - if err != nil { - return nil, err + var deleted bool + for _, subjectDID := range dids { + err = w.VCR.Wallet().Remove(ctx, subjectDID, *credentialID) + if err != nil { + if errors.Is(err, vcrTypes.ErrNotFound) { + // only return vcrTypes.ErrNotFound if true for all subjectDIDs (deleted=false) + continue + } + return nil, err + } + deleted = true + } + if !deleted { + return nil, vcrTypes.ErrNotFound } return RemoveCredentialFromWallet204Response{}, nil - } // TrustIssuer handles API request to start trusting an issuer of a Verifiable Credential. diff --git a/vcr/api/vcr/v2/api_test.go b/vcr/api/vcr/v2/api_test.go index ce0fcb730..6c6ae24d5 100644 --- a/vcr/api/vcr/v2/api_test.go +++ b/vcr/api/vcr/v2/api_test.go @@ -23,8 +23,7 @@ import ( "encoding/json" "errors" "fmt" - "github.com/nuts-foundation/nuts-node/vdr/didsubject" - "github.com/nuts-foundation/nuts-node/vdr/resolver" + "github.com/nuts-foundation/nuts-node/vcr/types" "net/http" "testing" "time" @@ -41,6 +40,8 @@ import ( "github.com/nuts-foundation/nuts-node/vcr/issuer" "github.com/nuts-foundation/nuts-node/vcr/signature/proof" "github.com/nuts-foundation/nuts-node/vcr/verifier" + "github.com/nuts-foundation/nuts-node/vdr/didsubject" + "github.com/nuts-foundation/nuts-node/vdr/resolver" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" @@ -827,26 +828,57 @@ func TestWrapper_GetCredentialsInWallet(t *testing.T) { }) } -func TestWrapper_RemoveCredentialFromWallet(t *testing.T) { +func TestWrapper_RemoveCredentialFromSubjectWallet(t *testing.T) { + didNuts := did.MustParseDID("did:nuts:123") + didWeb := did.MustParseDID("did:web:example.com") + subject := "subbie" t.Run("ok", func(t *testing.T) { testContext := newMockContext(t) - testContext.mockWallet.EXPECT().Remove(testContext.requestCtx, holderDID, credentialID).Return(nil) + testContext.mockSubjectManager.EXPECT().ListDIDs(testContext.requestCtx, subject).Return([]did.DID{didNuts, didWeb}, nil) + testContext.mockWallet.EXPECT().Remove(testContext.requestCtx, didNuts, credentialID).Return(nil) + testContext.mockWallet.EXPECT().Remove(testContext.requestCtx, didWeb, credentialID).Return(types.ErrNotFound) // only exists on 1 DID response, err := testContext.client.RemoveCredentialFromWallet(testContext.requestCtx, RemoveCredentialFromWalletRequestObject{ - Did: holderDID.String(), - Id: credentialID.String(), + SubjectID: subject, + Id: credentialID.String(), }) assert.NoError(t, err) assert.Equal(t, RemoveCredentialFromWallet204Response{}, response) }) - t.Run("error", func(t *testing.T) { + t.Run("error - credential not found", func(t *testing.T) { + testContext := newMockContext(t) + testContext.mockSubjectManager.EXPECT().ListDIDs(testContext.requestCtx, subject).Return([]did.DID{didNuts, didWeb}, nil) + testContext.mockWallet.EXPECT().Remove(testContext.requestCtx, gomock.AnyOf(didNuts, didWeb), credentialID).Return(types.ErrNotFound).Times(2) + + response, err := testContext.client.RemoveCredentialFromWallet(testContext.requestCtx, RemoveCredentialFromWalletRequestObject{ + SubjectID: subject, + Id: credentialID.String(), + }) + + assert.Empty(t, response) + assert.ErrorIs(t, err, types.ErrNotFound) + }) + t.Run("error - subject not found", func(t *testing.T) { + testContext := newMockContext(t) + testContext.mockSubjectManager.EXPECT().ListDIDs(testContext.requestCtx, subject).Return(nil, didsubject.ErrSubjectNotFound) + + response, err := testContext.client.RemoveCredentialFromWallet(testContext.requestCtx, RemoveCredentialFromWalletRequestObject{ + SubjectID: subject, + Id: credentialID.String(), + }) + + assert.Empty(t, response) + assert.ErrorIs(t, err, didsubject.ErrSubjectNotFound) + }) + t.Run("error - general error", func(t *testing.T) { testContext := newMockContext(t) - testContext.mockWallet.EXPECT().Remove(testContext.requestCtx, holderDID, credentialID).Return(assert.AnError) + testContext.mockSubjectManager.EXPECT().ListDIDs(testContext.requestCtx, subject).Return([]did.DID{didNuts, didWeb}, nil) + testContext.mockWallet.EXPECT().Remove(testContext.requestCtx, didNuts, credentialID).Return(assert.AnError) response, err := testContext.client.RemoveCredentialFromWallet(testContext.requestCtx, RemoveCredentialFromWalletRequestObject{ - Did: holderDID.String(), - Id: credentialID.String(), + SubjectID: subject, + Id: credentialID.String(), }) assert.Empty(t, response) diff --git a/vcr/api/vcr/v2/generated.go b/vcr/api/vcr/v2/generated.go index 19197b89f..3e31b3c92 100644 --- a/vcr/api/vcr/v2/generated.go +++ b/vcr/api/vcr/v2/generated.go @@ -482,9 +482,6 @@ 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, subjectID string, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -493,6 +490,9 @@ type ClientInterface interface { LoadVC(ctx context.Context, subjectID string, body LoadVCJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // RemoveCredentialFromWallet request + RemoveCredentialFromWallet(ctx context.Context, subjectID string, id string, 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) RemoveCredentialFromWallet(ctx context.Context, did string, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewRemoveCredentialFromWalletRequest(c.Server, did, id) +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 } @@ -575,8 +575,8 @@ func (c *Client) RemoveCredentialFromWallet(ctx context.Context, did string, id return c.Client.Do(req) } -func (c *Client) GetCredentialsInWallet(ctx context.Context, subjectID string, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewGetCredentialsInWalletRequest(c.Server, subjectID) +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 } @@ -587,8 +587,8 @@ func (c *Client) GetCredentialsInWallet(ctx context.Context, subjectID string, r return c.Client.Do(req) } -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) +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 } @@ -599,8 +599,8 @@ func (c *Client) LoadVCWithBody(ctx context.Context, subjectID string, contentTy return c.Client.Do(req) } -func (c *Client) LoadVC(ctx context.Context, subjectID string, body LoadVCJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewLoadVCRequest(c.Server, subjectID, body) +func (c *Client) RemoveCredentialFromWallet(ctx context.Context, subjectID string, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRemoveCredentialFromWalletRequest(c.Server, subjectID, id) if err != nil { return nil, err } @@ -855,27 +855,20 @@ func NewCreateVPRequestWithBody(server string, contentType string, body io.Reade return req, nil } -// NewRemoveCredentialFromWalletRequest generates requests for RemoveCredentialFromWallet -func NewRemoveCredentialFromWalletRequest(server string, did string, id string) (*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 - - 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 } @@ -885,7 +878,7 @@ func NewRemoveCredentialFromWalletRequest(server string, did string, id string) return nil, err } - req, err := http.NewRequest("DELETE", queryURL.String(), nil) + req, err := http.NewRequest("GET", queryURL.String(), nil) if err != nil { return nil, err } @@ -893,8 +886,19 @@ func NewRemoveCredentialFromWalletRequest(server string, did string, id string) return req, nil } -// NewGetCredentialsInWalletRequest generates requests for GetCredentialsInWallet -func NewGetCredentialsInWalletRequest(server string, subjectID 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 @@ -916,39 +920,37 @@ func NewGetCredentialsInWalletRequest(server string, subjectID string) (*http.Re return nil, err } - req, err := http.NewRequest("GET", queryURL.String(), nil) + req, err := http.NewRequest("POST", queryURL.String(), body) if err != nil { return nil, err } - return req, nil -} + req.Header.Add("Content-Type", contentType) -// 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) + return req, nil } -// NewLoadVCRequestWithBody generates requests for LoadVC with any type of body -func NewLoadVCRequestWithBody(server string, subjectID string, contentType string, body io.Reader) (*http.Request, error) { +// NewRemoveCredentialFromWalletRequest generates requests for RemoveCredentialFromWallet +func NewRemoveCredentialFromWalletRequest(server string, subjectID string, id string) (*http.Request, error) { var err error var pathParam0 string pathParam0 = subjectID + 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 } @@ -958,13 +960,11 @@ func NewLoadVCRequestWithBody(server string, subjectID string, contentType strin return nil, err } - req, err := http.NewRequest("POST", queryURL.String(), body) + req, err := http.NewRequest("DELETE", queryURL.String(), nil) if err != nil { return nil, err } - req.Header.Add("Content-Type", contentType) - return req, nil } @@ -1465,9 +1465,6 @@ 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, subjectID string, reqEditors ...RequestEditorFn) (*GetCredentialsInWalletResponse, error) @@ -1476,6 +1473,9 @@ type ClientWithResponsesInterface interface { LoadVCWithResponse(ctx context.Context, subjectID string, body LoadVCJSONRequestBody, reqEditors ...RequestEditorFn) (*LoadVCResponse, error) + // RemoveCredentialFromWalletWithResponse request + RemoveCredentialFromWalletWithResponse(ctx context.Context, subjectID string, id string, reqEditors ...RequestEditorFn) (*RemoveCredentialFromWalletResponse, error) + // IssueVCWithBodyWithResponse request with any body IssueVCWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*IssueVCResponse, error) @@ -1554,9 +1554,10 @@ func (r CreateVPResponse) StatusCode() int { return 0 } -type RemoveCredentialFromWalletResponse 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"` @@ -1570,7 +1571,7 @@ type RemoveCredentialFromWalletResponse struct { } // Status returns HTTPResponse.Status -func (r RemoveCredentialFromWalletResponse) Status() string { +func (r GetCredentialsInWalletResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -1578,17 +1579,16 @@ func (r RemoveCredentialFromWalletResponse) Status() string { } // StatusCode returns HTTPResponse.StatusCode -func (r RemoveCredentialFromWalletResponse) StatusCode() int { +func (r GetCredentialsInWalletResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } -type GetCredentialsInWalletResponse struct { +type LoadVCResponse 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 GetCredentialsInWalletResponse struct { } // Status returns HTTPResponse.Status -func (r GetCredentialsInWalletResponse) Status() string { +func (r LoadVCResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -1610,14 +1610,14 @@ func (r GetCredentialsInWalletResponse) Status() string { } // StatusCode returns HTTPResponse.StatusCode -func (r GetCredentialsInWalletResponse) StatusCode() int { +func (r LoadVCResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } -type LoadVCResponse struct { +type RemoveCredentialFromWalletResponse struct { Body []byte HTTPResponse *http.Response ApplicationproblemJSONDefault *struct { @@ -1633,7 +1633,7 @@ type LoadVCResponse struct { } // Status returns HTTPResponse.Status -func (r LoadVCResponse) Status() string { +func (r RemoveCredentialFromWalletResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -1641,7 +1641,7 @@ func (r LoadVCResponse) Status() string { } // StatusCode returns HTTPResponse.StatusCode -func (r LoadVCResponse) StatusCode() int { +func (r RemoveCredentialFromWalletResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } @@ -2015,15 +2015,6 @@ func (c *ClientWithResponses) CreateVPWithResponse(ctx context.Context, body Cre return ParseCreateVPResponse(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...) - if err != nil { - return nil, err - } - return ParseRemoveCredentialFromWalletResponse(rsp) -} - // GetCredentialsInWalletWithResponse request returning *GetCredentialsInWalletResponse func (c *ClientWithResponses) GetCredentialsInWalletWithResponse(ctx context.Context, subjectID string, reqEditors ...RequestEditorFn) (*GetCredentialsInWalletResponse, error) { rsp, err := c.GetCredentialsInWallet(ctx, subjectID, reqEditors...) @@ -2050,6 +2041,15 @@ func (c *ClientWithResponses) LoadVCWithResponse(ctx context.Context, subjectID return ParseLoadVCResponse(rsp) } +// RemoveCredentialFromWalletWithResponse request returning *RemoveCredentialFromWalletResponse +func (c *ClientWithResponses) RemoveCredentialFromWalletWithResponse(ctx context.Context, subjectID string, id string, reqEditors ...RequestEditorFn) (*RemoveCredentialFromWalletResponse, error) { + rsp, err := c.RemoveCredentialFromWallet(ctx, subjectID, id, reqEditors...) + if err != nil { + return nil, err + } + return ParseRemoveCredentialFromWalletResponse(rsp) +} + // IssueVCWithBodyWithResponse request with arbitrary body returning *IssueVCResponse func (c *ClientWithResponses) IssueVCWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*IssueVCResponse, error) { rsp, err := c.IssueVCWithBody(ctx, contentType, body, reqEditors...) @@ -2239,20 +2239,27 @@ func ParseCreateVPResponse(rsp *http.Response) (*CreateVPResponse, error) { return response, nil } -// ParseRemoveCredentialFromWalletResponse parses an HTTP response from a RemoveCredentialFromWalletWithResponse call -func ParseRemoveCredentialFromWalletResponse(rsp *http.Response) (*RemoveCredentialFromWalletResponse, 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 := &RemoveCredentialFromWalletResponse{ + 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. @@ -2274,27 +2281,20 @@ func ParseRemoveCredentialFromWalletResponse(rsp *http.Response) (*RemoveCredent return response, nil } -// ParseGetCredentialsInWalletResponse parses an HTTP response from a GetCredentialsInWalletWithResponse call -func ParseGetCredentialsInWalletResponse(rsp *http.Response) (*GetCredentialsInWalletResponse, 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 := &GetCredentialsInWalletResponse{ + response := &LoadVCResponse{ 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 ParseGetCredentialsInWalletResponse(rsp *http.Response) (*GetCredentialsInW return response, nil } -// ParseLoadVCResponse parses an HTTP response from a LoadVCWithResponse call -func ParseLoadVCResponse(rsp *http.Response) (*LoadVCResponse, 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 := &LoadVCResponse{ + response := &RemoveCredentialFromWalletResponse{ 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 - // 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 + // Remove a VerifiableCredential from the holders wallet. + // (DELETE /internal/vcr/v2/holder/{subjectID}/vc/{id}) + RemoveCredentialFromWallet(ctx echo.Context, subjectID string, id string) error // Issues a new Verifiable Credential // (POST /internal/vcr/v2/issuer/vc) IssueVC(ctx echo.Context) error @@ -2864,31 +2864,23 @@ func (w *ServerInterfaceWrapper) CreateVP(ctx echo.Context) error { return err } -// RemoveCredentialFromWallet converts echo context to params. -func (w *ServerInterfaceWrapper) RemoveCredentialFromWallet(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 - - 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.GetCredentialsInWallet(ctx, subjectID) return err } -// GetCredentialsInWallet converts echo context to params. -func (w *ServerInterfaceWrapper) GetCredentialsInWallet(ctx echo.Context) error { +// LoadVC converts echo context to params. +func (w *ServerInterfaceWrapper) LoadVC(ctx echo.Context) error { var err error // ------------- Path parameter "subjectID" ------------- var subjectID string @@ -2898,22 +2890,30 @@ func (w *ServerInterfaceWrapper) GetCredentialsInWallet(ctx echo.Context) error ctx.Set(JwtBearerAuthScopes, []string{}) // Invoke the callback with all the unmarshaled arguments - err = w.Handler.GetCredentialsInWallet(ctx, subjectID) + err = w.Handler.LoadVC(ctx, subjectID) return err } -// LoadVC converts echo context to params. -func (w *ServerInterfaceWrapper) LoadVC(ctx echo.Context) error { +// RemoveCredentialFromWallet converts echo context to params. +func (w *ServerInterfaceWrapper) RemoveCredentialFromWallet(ctx echo.Context) error { var err error // ------------- Path parameter "subjectID" ------------- var subjectID string subjectID = ctx.Param("subjectID") + // ------------- 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.LoadVC(ctx, subjectID) + err = w.Handler.RemoveCredentialFromWallet(ctx, subjectID, id) return err } @@ -3118,9 +3118,9 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL } router.POST(baseURL+"/internal/vcr/v2/holder/vp", wrapper.CreateVP) - 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.DELETE(baseURL+"/internal/vcr/v2/holder/:subjectID/vc/:id", wrapper.RemoveCredentialFromWallet) 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 RemoveCredentialFromWalletRequestObject struct { - Did string `json:"did"` - Id string `json:"id"` +type GetCredentialsInWalletRequestObject struct { + SubjectID string `json:"subjectID"` } -type RemoveCredentialFromWalletResponseObject interface { - VisitRemoveCredentialFromWalletResponse(w http.ResponseWriter) error +type GetCredentialsInWalletResponseObject interface { + VisitGetCredentialsInWalletResponse(w http.ResponseWriter) error } -type RemoveCredentialFromWallet204Response struct { -} +type GetCredentialsInWallet200JSONResponse []VerifiableCredential -func (response RemoveCredentialFromWallet204Response) VisitRemoveCredentialFromWalletResponse(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 RemoveCredentialFromWalletdefaultApplicationProblemPlusJSONResponse struct { +type GetCredentialsInWalletdefaultApplicationProblemPlusJSONResponse struct { Body struct { // Detail A human-readable explanation specific to this occurrence of the problem. Detail string `json:"detail"` @@ -3204,31 +3204,31 @@ type RemoveCredentialFromWalletdefaultApplicationProblemPlusJSONResponse struct StatusCode int } -func (response RemoveCredentialFromWalletdefaultApplicationProblemPlusJSONResponse) VisitRemoveCredentialFromWalletResponse(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 GetCredentialsInWalletRequestObject struct { +type LoadVCRequestObject struct { SubjectID string `json:"subjectID"` + Body *LoadVCJSONRequestBody } -type GetCredentialsInWalletResponseObject interface { - VisitGetCredentialsInWalletResponse(w http.ResponseWriter) error +type LoadVCResponseObject interface { + VisitLoadVCResponse(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 LoadVC204Response struct { +} - return json.NewEncoder(w).Encode(response) +func (response LoadVC204Response) VisitLoadVCResponse(w http.ResponseWriter) error { + w.WriteHeader(204) + return nil } -type GetCredentialsInWalletdefaultApplicationProblemPlusJSONResponse struct { +type LoadVCdefaultApplicationProblemPlusJSONResponse struct { Body struct { // Detail A human-readable explanation specific to this occurrence of the problem. Detail string `json:"detail"` @@ -3242,31 +3242,31 @@ type GetCredentialsInWalletdefaultApplicationProblemPlusJSONResponse struct { StatusCode int } -func (response GetCredentialsInWalletdefaultApplicationProblemPlusJSONResponse) VisitGetCredentialsInWalletResponse(w http.ResponseWriter) error { +func (response LoadVCdefaultApplicationProblemPlusJSONResponse) VisitLoadVCResponse(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 { +type RemoveCredentialFromWalletRequestObject struct { SubjectID string `json:"subjectID"` - Body *LoadVCJSONRequestBody + Id string `json:"id"` } -type LoadVCResponseObject interface { - VisitLoadVCResponse(w http.ResponseWriter) error +type RemoveCredentialFromWalletResponseObject interface { + VisitRemoveCredentialFromWalletResponse(w http.ResponseWriter) error } -type LoadVC204Response struct { +type RemoveCredentialFromWallet204Response struct { } -func (response LoadVC204Response) VisitLoadVCResponse(w http.ResponseWriter) error { +func (response RemoveCredentialFromWallet204Response) VisitRemoveCredentialFromWalletResponse(w http.ResponseWriter) error { w.WriteHeader(204) return nil } -type LoadVCdefaultApplicationProblemPlusJSONResponse struct { +type RemoveCredentialFromWalletdefaultApplicationProblemPlusJSONResponse struct { Body struct { // Detail A human-readable explanation specific to this occurrence of the problem. Detail string `json:"detail"` @@ -3280,7 +3280,7 @@ type LoadVCdefaultApplicationProblemPlusJSONResponse struct { StatusCode int } -func (response LoadVCdefaultApplicationProblemPlusJSONResponse) VisitLoadVCResponse(w http.ResponseWriter) error { +func (response RemoveCredentialFromWalletdefaultApplicationProblemPlusJSONResponse) VisitRemoveCredentialFromWalletResponse(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/{subjectID}/vc) GetCredentialsInWallet(ctx context.Context, request GetCredentialsInWalletRequestObject) (GetCredentialsInWalletResponseObject, error) // Load a VerifiableCredential into the holders wallet. // (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/{subjectID}/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,32 +3801,6 @@ func (sh *strictHandler) CreateVP(ctx echo.Context) error { return nil } -// 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.RemoveCredentialFromWallet(ctx.Request().Context(), request.(RemoveCredentialFromWalletRequestObject)) - } - for _, middleware := range sh.middlewares { - handler = middleware(handler, "RemoveCredentialFromWallet") - } - - response, err := handler(ctx, request) - - if err != nil { - return err - } 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 -} - // GetCredentialsInWallet operation middleware func (sh *strictHandler) GetCredentialsInWallet(ctx echo.Context, subjectID string) error { var request GetCredentialsInWalletRequestObject @@ -3883,6 +3857,32 @@ func (sh *strictHandler) LoadVC(ctx echo.Context, subjectID string) error { return nil } +// RemoveCredentialFromWallet operation middleware +func (sh *strictHandler) RemoveCredentialFromWallet(ctx echo.Context, subjectID string, id string) error { + var request RemoveCredentialFromWalletRequestObject + + request.SubjectID = subjectID + request.Id = id + + handler := func(ctx echo.Context, request interface{}) (interface{}, error) { + return sh.ssi.RemoveCredentialFromWallet(ctx.Request().Context(), request.(RemoveCredentialFromWalletRequestObject)) + } + for _, middleware := range sh.middlewares { + handler = middleware(handler, "RemoveCredentialFromWallet") + } + + response, err := handler(ctx, request) + + if err != nil { + return err + } 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 +} + // IssueVC operation middleware func (sh *strictHandler) IssueVC(ctx echo.Context) error { var request IssueVCRequestObject