Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

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

Attention: Patch coverage is 76.57658% with 26 lines in your changes missing coverage. Please review.

Project coverage is 58.29%. Comparing base (d5c8f79) to head (1e48abb).
Report is 136 commits behind head on main.

Files with missing lines Patch % Lines
did/jwk.go 76.58% 19 Missing and 7 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #363      +/-   ##
==========================================
+ Coverage   57.99%   58.29%   +0.31%     
==========================================
  Files          52       53       +1     
  Lines        6574     6685     +111     
==========================================
+ Hits         3812     3897      +85     
- Misses       2055     2074      +19     
- Partials      707      714       +7     
Files with missing lines Coverage Δ
did/did.go 100.00% <ø> (ø)
did/jwk.go 76.58% <76.58%> (ø)

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 decentralgabe merged commit 804491d into main May 1, 2023
@decentralgabe decentralgabe deleted the did-jwk branch May 1, 2023 17:54
decentralgabe pushed a commit that referenced this pull request May 1, 2023
* origin/main:
  Implementation of did:jwk (#363)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Idea] Support did:jwk
4 participants