Skip to content

Commit

Permalink
fix retraction
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardsn committed Oct 17, 2024
1 parent 813b2e7 commit 0a852a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions discovery/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +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
})
if err != nil {
return err
Expand Down
9 changes: 8 additions & 1 deletion discovery/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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 @@ -220,7 +221,13 @@ func Test_defaultClientRegistrationManager_deactivate(t *testing.T) {
t.Run("registered", func(t *testing.T) {
ctx := newTestContext(t)
ctx.invoker.EXPECT().Register(gomock.Any(), gomock.Any(), gomock.Any())
ctx.wallet.EXPECT().BuildPresentation(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), false).Return(&vpAlice, nil)
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())
return &vpAlice, nil // not a revocation VP
})
ctx.subjectManager.EXPECT().ListDIDs(gomock.Any(), aliceSubject).Return([]did.DID{aliceDID}, nil)
_, err := ctx.store.add(testServiceID, vpAlice, testSeed, 1)
require.NoError(t, err)
Expand Down
8 changes: 6 additions & 2 deletions discovery/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,15 @@ func (m *Module) validateRegistration(definition ServiceDefinition, presentation
}

func (m *Module) validateRetraction(serviceID string, presentation vc.VerifiablePresentation) error {
// Presentation might be a retraction (deletion of an earlier credentialRecord) must contain no credentials, and refer to the VP being retracted by ID.
// If those conditions aren't met, we don't need to register the retraction.
// RFC022 §3.4:it MUST specify RetractedVerifiablePresentation as type, in addition to the VerifiablePresentation.
// presentation.IsType(retractionPresentationType) // satisfied by the switch one level up

// RFC022 §3.4: it MUST NOT contain any credentials.
if len(presentation.VerifiableCredential) > 0 {
return errRetractionContainsCredentials
}

// RFC022 §3.4: it MUST contain a retract_jti JWT claim, containing the jti of the presentation to retract.
// Check that the retraction refers to an existing presentation.
// If not, it might've already been removed due to expiry or superseded by a newer presentation.
retractJTIRaw, _ := presentation.JWT().Get("retract_jti")
Expand Down

0 comments on commit 0a852a0

Please sign in to comment.