From b7be828d9b9dbe7aa363f14399dfba64555bd9fa Mon Sep 17 00:00:00 2001 From: Gabe <7622243+decentralgabe@users.noreply.github.com> Date: Thu, 31 Aug 2023 13:29:04 -0700 Subject: [PATCH] Fix/did web create key (#461) (#462) * 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 --- did/peer/peer0.go | 2 +- did/peer/peer0_test.go | 2 ++ did/web/web.go | 2 +- did/web/web_test.go | 6 ++++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/did/peer/peer0.go b/did/peer/peer0.go index 648166fe..4a56af9d 100644 --- a/did/peer/peer0.go +++ b/did/peer/peer0.go @@ -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 } diff --git a/did/peer/peer0_test.go b/did/peer/peer0_test.go index 9e29ea45..025dbede 100644 --- a/did/peer/peer0_test.go +++ b/did/peer/peer0_test.go @@ -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 { diff --git a/did/web/web.go b/did/web/web.go index 9d876543..49b97a46 100644 --- a/did/web/web.go +++ b/did/web/web.go @@ -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) } diff --git a/did/web/web_test.go b/did/web/web_test.go index 07d0e834..6cf56473 100644 --- a/did/web/web_test.go +++ b/did/web/web_test.go @@ -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) {