-
Notifications
You must be signed in to change notification settings - Fork 161
feat: Allow DID method to Accept supported DID prefixes #108
Conversation
Codecov Report
@@ Coverage Diff @@
## master #108 +/- ##
=======================================
Coverage 91.91% 91.91%
=======================================
Files 19 19
Lines 668 668
=======================================
Hits 614 614
Misses 30 30
Partials 24 24
Continue to review full report at Codecov.
|
@@ -72,6 +72,6 @@ type Opt func(opts *didResolverOpts) | |||
// WithDidMethod to add did method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should update the package docs to indicate that regular expressions are supported and DID methods are checked in the order added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
// resolveDidMethod resolve did method | ||
func (r *DIDResolver) resolveDidMethod(method string) (DidMethod, error) { | ||
for _, v := range r.didMethods { | ||
match, _ := regexp.MatchString(v.id, method) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regular expression should be pre-compiled rather than compiled on demand during resolve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
It would be good to add some description to the commit message so that the reader of the git logs has a better idea of the feature. |
pkg/framework/didresolver/api.go
Outdated
@@ -72,6 +72,6 @@ type Opt func(opts *didResolverOpts) | |||
// WithDidMethod to add did method | |||
func WithDidMethod(id string, method DidMethod) Opt { | |||
return func(opts *didResolverOpts) { | |||
opts.didMethods[id] = method | |||
opts.didMethods = append(opts.didMethods, didMethod{id: id, DidMethod: method}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes using WithDidMethod
awkward. The user now must specify a regex instead of just a DID method. Eg. the regex "rie" matches the string "aries" yet they clearly are not the same strings. To lock down the definition, the user is forced to provide "^rie$", which is counter intuitive.
One way to enable "catch-alls" is to invert control of the pattern matching such that the DidMethod
is responsible for it. Add an Accept(method string) bool
method to DidMethod
, thereby freeing the user from such awkwardness and, incidentally, simplifying WithDidMethod
by removing the id
arg:
resolver := didresolver.New(
WithDidMethod(peer.NewDIDResolver(store)),
WithDidMethod(universal.Resolver(url)),
WithDidMethod(sidetree.Resolver(method, url)),
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/didmethod/peer/resolver.go
Outdated
@@ -12,12 +12,13 @@ import ( | |||
|
|||
// DIDResolver resolver | |||
type DIDResolver struct { | |||
store *DIDStore | |||
store *DIDStore | |||
method string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of peer DIDs the method is always "peer", so this can be hard coded in peer.DIDResolver.Accept()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
- Add accpet method in DidMethod interface - Switch didMethods from map to array closes #101 Signed-off-by: Firas Qutishat <[email protected]>
closes #101
Signed-off-by: Firas Qutishat [email protected]