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

Commit

Permalink
Fix/did web create key (#461) (#462)
Browse files Browse the repository at this point in the history
* owner jwk id and controller strings were mixed up

* did peer jwk id and controller strings were mixed up

* add tests to check for owner key in DID Web Create

* add tests to check verification method controller in did peer resolver

---------

Co-authored-by: Liran Cohen <[email protected]>
  • Loading branch information
decentralgabe and LiranCohen authored Aug 31, 2023
1 parent 7522c30 commit b7be828
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion did/peer/peer0.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (Method0) resolve(didDoc did.DID, _ resolution.Option) (*resolution.Result,
keyReference := Hash + v
id := string(d)

verificationMethod, err := did.ConstructJWKVerificationMethod(id, keyReference, pubKey, cryptoKeyType)
verificationMethod, err := did.ConstructJWKVerificationMethod(keyReference, id, pubKey, cryptoKeyType)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions did/peer/peer0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func TestPeerResolveMethod0(t *testing.T) {
testDoc := getSampleDIDDocumentMethod0()
assert.Equal(t, testDoc.Context, resolved.Document.Context)
assert.Equal(t, testDoc.ID, resolved.ID)
assert.Equal(t, len(resolved.VerificationMethod), 1)
assert.Equal(t, testDoc.ID, resolved.VerificationMethod[0].Controller)
}

func makeSamplePeerDIDDocument0() *did.Document {
Expand Down
2 changes: 1 addition & 1 deletion did/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (d DIDWeb) CreateDoc(kt crypto.KeyType, publicKey []byte) (*did.Document, e
didWebStr := string(d)
keyReference := didWebStr + "#owner"

verificationMethod, err := did.ConstructJWKVerificationMethod(didWebStr, keyReference, publicKey, kt)
verificationMethod, err := did.ConstructJWKVerificationMethod(keyReference, didWebStr, publicKey, kt)
if err != nil {
return nil, fmt.Errorf("could not construct verification method for DIDWeb %+v", d)
}
Expand Down
6 changes: 6 additions & 0 deletions did/web/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ func TestDIDWebCreateDoc(t *testing.T) {
doc, err := didWebBasic.CreateDoc(crypto.Ed25519, pk)
assert.NoError(tt, err)
assert.Equal(tt, string(didWebBasic), doc.ID)
tt.Run("Validate Owner Verification Method", func(t *testing.T) {
assert.Equal(t, len(doc.VerificationMethod), 1)
ownerMethod := doc.VerificationMethod[0]
assert.Contains(t, ownerMethod.ID, "owner")
assert.Equal(t, ownerMethod.Controller, doc.ID)
})
})

t.Run("Unsupported Key Type", func(tt *testing.T) {
Expand Down

0 comments on commit b7be828

Please sign in to comment.