Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardsn committed Oct 25, 2024
1 parent 2e30c3b commit ee65f15
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions discovery/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (r *clientRegistrationManager) activate(ctx context.Context, serviceID, sub
subjectDIDs = subjectDIDs[:j]

if len(subjectDIDs) == 0 {
return fmt.Errorf("%w: %w for %s", ErrPresentationRegistrationFailed, ErrDIDMethodsNotSupported, subjectID)
return fmt.Errorf("%w: %w for %s", ErrPresentationRegistrationFailed, ErrNoSupportedDIDMethods, subjectID)
}

log.Logger().Debugf("Registering Verifiable Presentation on Discovery Service (service=%s, subject=%s)", service.ID, subjectID)
Expand Down Expand Up @@ -167,7 +167,7 @@ func (r *clientRegistrationManager) deactivate(ctx context.Context, serviceID, s
}
if len(subjectDIDs) == 0 {
// if this means we can't deactivate a previously registered subject because the DID methods have changed, then we rely on the refresh interval to clean up.
return fmt.Errorf("%w: %w for %s", ErrPresentationRegistrationFailed, ErrDIDMethodsNotSupported, subjectID)
return fmt.Errorf("%w: %w for %s", ErrPresentationRegistrationFailed, ErrNoSupportedDIDMethods, subjectID)
}

// find all active presentations
Expand Down Expand Up @@ -287,7 +287,7 @@ func (r *clientRegistrationManager) refresh(ctx context.Context, now time.Time)
for _, candidate := range refreshCandidates {
var loopErr error
if err = r.activate(ctx, candidate.ServiceID, candidate.SubjectID, candidate.Parameters); err != nil {
if errors.Is(err, ErrDIDMethodsNotSupported) {
if errors.Is(err, ErrNoSupportedDIDMethods) {
// DID method no longer supported, remove
err = r.store.updatePresentationRefreshTime(candidate.ServiceID, candidate.SubjectID, nil, nil)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions discovery/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func Test_defaultClientRegistrationManager_activate(t *testing.T) {

err := ctx.manager.activate(audit.TestContext(), unsupportedServiceID, aliceSubject, defaultRegistrationParams(aliceSubject))

assert.ErrorIs(t, err, ErrDIDMethodsNotSupported)
assert.ErrorIs(t, err, ErrNoSupportedDIDMethods)
})
t.Run("no matching credentials", func(t *testing.T) {
ctx := newTestContext(t)
Expand Down Expand Up @@ -255,7 +255,7 @@ func Test_defaultClientRegistrationManager_deactivate(t *testing.T) {

err := ctx.manager.deactivate(audit.TestContext(), unsupportedServiceID, aliceSubject)

assert.ErrorIs(t, err, ErrDIDMethodsNotSupported)
assert.ErrorIs(t, err, ErrNoSupportedDIDMethods)
})
t.Run("deregistering from Discovery Service fails", func(t *testing.T) {
ctx := newTestContext(t)
Expand Down
4 changes: 4 additions & 0 deletions discovery/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ var ErrPresentationAlreadyExists = errors.New("presentation already exists")
// ErrPresentationRegistrationFailed indicates registration of a presentation on a remote Discovery Service failed.
var ErrPresentationRegistrationFailed = errors.New("registration of Verifiable Presentation on remote Discovery Service failed")

// ErrDIDMethodsNotSupported indicates that a received VP does not match the supported DID Methods of the service.
var ErrDIDMethodsNotSupported = errors.New("DID methods not supported")

// ErrNoSupportedDIDMethods indicates that the client cannot create a VP for a subject because it has no (active) DID matching the supported DID Methods of the service.
var ErrNoSupportedDIDMethods = errors.New("subject has no (active) DIDs matching the service")

// authServerURLField is the field name for the authServerURL in the DiscoveryRegistrationCredential.
// it is used to resolve authorization server metadata and thus the endpoints for a service entry.
const authServerURLField = "authServerURL"
Expand Down
2 changes: 1 addition & 1 deletion discovery/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ func TestModule_ActivateServiceForSubject(t *testing.T) {

err := m.ActivateServiceForSubject(context.Background(), testServiceID, aliceSubject, nil)

assert.ErrorIs(t, err, ErrDIDMethodsNotSupported)
assert.ErrorIs(t, err, ErrNoSupportedDIDMethods)
})
t.Run("ok, but couldn't register presentation -> maps to ErrRegistrationFailed", func(t *testing.T) {
storageEngine := storage.NewTestStorageEngine(t)
Expand Down

0 comments on commit ee65f15

Please sign in to comment.