Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of did:jwk #363

Merged
merged 7 commits into from
May 1, 2023
Merged

Implementation of did:jwk #363

merged 7 commits into from
May 1, 2023

Conversation

decentralgabe
Copy link
Member

@decentralgabe decentralgabe commented Apr 27, 2023

Fixes #186

@codecov-commenter
Copy link

codecov-commenter commented Apr 28, 2023

Codecov Report

Merging #363 (44d765b) into main (d5c8f79) will increase coverage by 0.28%.
The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #363      +/-   ##
==========================================
+ Coverage   57.99%   58.27%   +0.28%     
==========================================
  Files          52       53       +1     
  Lines        6574     6686     +112     
==========================================
+ Hits         3812     3896      +84     
- Misses       2055     2075      +20     
- Partials      707      715       +8     
Impacted Files Coverage Δ
did/did.go 100.00% <ø> (ø)
did/jwk.go 75.00% <75.00%> (ø)

Copy link
Contributor

@andresuribe87 andresuribe87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! Some minor comments.

did/jwk.go Outdated Show resolved Hide resolved
return false
}

func GetSupportedDIDJWKTypes() []crypto.KeyType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this function call crypto.GetSupportedKeyTypes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +147 to +155
func isSupportedJWKType(kt crypto.KeyType) bool {
jwkTypes := GetSupportedDIDJWKTypes()
for _, t := range jwkTypes {
if t == kt {
return true
}
}
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem like this is the same as crypto.IsSupportedKeyType. Is it possible to DRY this up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it happens to overlap but it's a distinct method since there's no guarantee we enable all supported key types for did key and DID JWK. for example, did:jwk can support any JWK type. did:key only supports what's in the spec.

did/jwk.go Outdated
Comment on lines 166 to 168
if !strings.HasPrefix(did, JWKPrefix) {
return nil, fmt.Errorf("not a did:jwk DID: %s", did)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit of logic is also done in the Suffix function, which is called inside Expand. Consider removing it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

did/jwk.go Outdated Show resolved Hide resolved
did/jwk.go Outdated Show resolved Hide resolved
did/jwk_test.go Outdated
assert.NotEmpty(t, pk)
assert.NotEmpty(t, sk)

gotJWK, err := jwk.FromRaw(sk)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the secretKey, no? Should you pass in the pk, i.e. publicKey ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

did/jwk_test.go Outdated Show resolved Hide resolved
did/jwk_test.go Outdated
badDID := DIDJWK("bad")
_, err := badDID.Expand()
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid did:jwk: bad")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be useful to have the error say that the prefix wasn't found. That way it's informative to devs how to fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

did/jwk_test.go Outdated
Comment on lines 174 to 179
t.Run("DID but not a valid did:jwk", func(t *testing.T) {
badDID := DIDKey("did:jwk:bad")
_, err := badDID.Expand()
assert.Error(t, err)
assert.Contains(t, err.Error(), "could not parse did:key: invalid did:key: did:jwk:bad")
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the intention behind testing methods from DIDKey here? I'm not sure I follow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad copy and paste, updating

decentralgabe and others added 2 commits May 1, 2023 12:27
Co-authored-by: Andres Uribe <auribe@tbd.email>
@decentralgabe decentralgabe merged commit 804491d into main May 1, 2023
@decentralgabe decentralgabe deleted the did-jwk branch May 1, 2023 17:54
decentralgabe added a commit that referenced this pull request May 1, 2023
* origin/main:
  Implementation of did:jwk (#363)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Idea] Support did:jwk
4 participants