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

Refactor DID package #371

Merged
merged 5 commits into from
May 8, 2023
Merged

Refactor DID package #371

merged 5 commits into from
May 8, 2023

Conversation

decentralgabe
Copy link
Member

  • move each did method into its own directory
  • break out resolver code into new file
  • make usage of shared utils a bit more clear

no new code - just refactoring

@codecov-commenter
Copy link

codecov-commenter commented May 8, 2023

Codecov Report

Merging #371 (0e5bfe9) into main (d231d5b) will decrease coverage by 2.43%.
The diff coverage is 51.37%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #371      +/-   ##
==========================================
- Coverage   59.25%   56.83%   -2.43%     
==========================================
  Files          55       65      +10     
  Lines        6840     6900      +60     
==========================================
- Hits         4053     3921     -132     
- Misses       2076     2283     +207     
+ Partials      711      696      -15     
Impacted Files Coverage Δ
did/model.go 90.48% <ø> (+1.19%) ⬆️
did/pkh/resolver.go 0.00% <0.00%> (ø)
did/web/resolver.go 0.00% <0.00%> (ø)
did/util.go 25.38% <2.56%> (-38.62%) ⬇️
did/resolution/resolver.go 16.95% <3.85%> (ø)
did/ion/operations.go 52.61% <33.33%> (ø)
did/key/key.go 48.26% <36.00%> (ø)
did/peer/peer2.go 47.47% <47.47%> (ø)
credential/exchange/verification.go 59.26% <50.00%> (ø)
credential/jwt.go 40.43% <50.00%> (ø)
... and 13 more

... and 1 file with indirect coverage changes

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.

Thanks!

@@ -1,12 +1,15 @@
package did
package resolver
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid stuttering, and seems like a better name for the package.

Suggested change
package resolver
package resolution

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea

Comment on lines 10 to 21
func TestDIDDocumentMetadata(t *testing.T) {
// good
var metadata DocumentMetadata
assert.True(t, metadata.IsValid())

// bad
badMetadata := DocumentMetadata{
Created: "bad",
Updated: time.Now().UTC().Format(time.RFC3339),
}
assert.False(t, badMetadata.IsValid())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't tell if this was existing, but the tests could be separated

Suggested change
func TestDIDDocumentMetadata(t *testing.T) {
// good
var metadata DocumentMetadata
assert.True(t, metadata.IsValid())
// bad
badMetadata := DocumentMetadata{
Created: "bad",
Updated: time.Now().UTC().Format(time.RFC3339),
}
assert.False(t, badMetadata.IsValid())
}
func TestDIDDocumentMetadata_IsValid(t *testing.T) {
t.Run("returns true with empty", func(t *testing.T) {
var metadata DocumentMetadata
assert.True(t, metadata.IsValid())
})
t.Run("returns false when created field is not a timestamp", func(t *testing.T) {
badMetadata := DocumentMetadata{
Created: "bad",
Updated: time.Now().UTC().Format(time.RFC3339),
}
assert.False(t, badMetadata.IsValid())
})
}

Comment on lines +35 to +41
// The '=' at the end is an artifact of the encoding, and will mess up the decoding
// over the partials, so is removed.
// https://identity.foundation/peer-did-method-spec/index.html#generation-method
// ds := string(d)
// if ds[len(ds)-1] == '=' {
// d = DIDPeer(ds[:len(ds)-1])
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be deleted?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not familiar with the code so would prefer leaving it

Comment on lines 14 to 22
// unsupported type
_, err := encodePublicKeyWithKeyMultiCodecType(crypto.KeyType("unsupported"), nil)
assert.Error(t, err)
assert.Contains(t, err.Error(), "not a supported key type")

// bad public key
_, err = encodePublicKeyWithKeyMultiCodecType(crypto.Ed25519, nil)
assert.Error(t, err)
assert.Contains(t, err.Error(), "unknown public key type; could not convert to bytes")
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment to the above. Though I see this was only moved. Up to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@decentralgabe decentralgabe merged commit 989cdd2 into main May 8, 2023
@decentralgabe decentralgabe deleted the resolver branch May 8, 2023 18:14
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.

None yet

3 participants