Skip to content

Commit

Permalink
move retraction type from .type to .vp.type
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardsn committed Oct 17, 2024
1 parent 0a852a0 commit 1bab169
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
17 changes: 10 additions & 7 deletions discovery/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ func (r *defaultClientRegistrationManager) deactivate(ctx context.Context, servi
func (r *defaultClientRegistrationManager) deregisterPresentation(ctx context.Context, subjectDID did.DID, service ServiceDefinition, vp vc.VerifiablePresentation) error {
presentation, err := r.buildPresentation(ctx, subjectDID, service, nil, map[string]interface{}{
"retract_jti": vp.ID.String(),
"type": []ssi.URI{vc.VerifiablePresentationTypeV1URI(), retractionPresentationType}, // this overrides the default 'type' so must include all types
})
}, &retractionPresentationType)
if err != nil {
return err
}
Expand Down Expand Up @@ -264,15 +263,18 @@ func (r *defaultClientRegistrationManager) findCredentialsAndBuildPresentation(c
return nil, fmt.Errorf(errStr, service.ID, subjectDID, err)
}

return r.buildPresentation(ctx, subjectDID, service, matchingCredentials, nil)
return r.buildPresentation(ctx, subjectDID, service, matchingCredentials, nil, nil)
}

func (r *defaultClientRegistrationManager) buildPresentation(ctx context.Context, subjectDID did.DID, service ServiceDefinition,
credentials []vc.VerifiableCredential, additionalProperties map[string]interface{}) (*vc.VerifiablePresentation, error) {
func (r *defaultClientRegistrationManager) buildPresentation(ctx context.Context, subjectDID did.DID, service ServiceDefinition, credentials []vc.VerifiableCredential, additionalProperties map[string]interface{}, additionalVPType *ssi.URI) (*vc.VerifiablePresentation, error) {
nonce := nutsCrypto.GenerateNonce()
// Make sure the presentation is not valid for longer than the max validity as defined by the Service Definitio.
expires := time.Now().Add(time.Duration(service.PresentationMaxValidity-1) * time.Second).Truncate(time.Second)
holderURI := subjectDID.URI()
var additionalVPTypes []ssi.URI
if additionalVPType != nil {
additionalVPTypes = append(additionalVPTypes, *additionalVPType)
}
return r.vcr.Wallet().BuildPresentation(ctx, credentials, holder.PresentationOptions{
ProofOptions: proof.ProofOptions{
Created: time.Now(),
Expand All @@ -281,8 +283,9 @@ func (r *defaultClientRegistrationManager) buildPresentation(ctx context.Context
Nonce: &nonce,
AdditionalProperties: additionalProperties,
},
Format: vc.JWTPresentationProofFormat,
Holder: &holderURI,
AdditionalTypes: additionalVPTypes,
Format: vc.JWTPresentationProofFormat,
Holder: &holderURI,
}, &subjectDID, false)
}

Expand Down
5 changes: 1 addition & 4 deletions discovery/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package discovery

import (
"context"
"encoding/json"
"errors"
"github.com/lestrrat-go/jwx/v2/jwt"
"github.com/nuts-foundation/go-did/did"
Expand Down Expand Up @@ -223,9 +222,7 @@ func Test_defaultClientRegistrationManager_deactivate(t *testing.T) {
ctx.invoker.EXPECT().Register(gomock.Any(), gomock.Any(), gomock.Any())
ctx.wallet.EXPECT().BuildPresentation(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), false).DoAndReturn(
func(ctx context.Context, credentials []vc.VerifiableCredential, options holder.PresentationOptions, signerDID *did.DID, validateVC bool) (*vc.VerifiablePresentation, error) {
bs, err := json.Marshal(options.ProofOptions.AdditionalProperties["type"])
require.NoError(t, err)
assert.Contains(t, string(bs), retractionPresentationType.String())
assert.Equal(t, options.AdditionalTypes[0], retractionPresentationType)
return &vpAlice, nil // not a revocation VP
})
ctx.subjectManager.EXPECT().ListDIDs(gomock.Any(), aliceSubject).Return([]did.DID{aliceDID}, nil)
Expand Down

0 comments on commit 1bab169

Please sign in to comment.