Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
feat: Implement did:jwk VDR - Create (#311)
Browse files Browse the repository at this point in the history
Implement did:jwk VDR - Create method

Closes #309

Signed-off-by: Sandra Vrtikapa <[email protected]>

Signed-off-by: Sandra Vrtikapa <[email protected]>
  • Loading branch information
sandrask authored Dec 9, 2022
1 parent 54502dd commit 5a3273a
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 21 deletions.
45 changes: 44 additions & 1 deletion component/vdr/jwk/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,56 @@ SPDX-License-Identifier: Apache-2.0
package jwk

import (
"encoding/base64"
"fmt"

"github.com/hyperledger/aries-framework-go/pkg/doc/did"
"github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk"
vdrapi "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr"
"github.com/trustbloc/sidetree-core-go/pkg/canonicalizer"
)

// Create new DID document for didDoc.
func (v *VDR) Create(didDoc *did.Doc, opts ...vdrapi.DIDMethodOption) (*did.DocResolution, error) {
return nil, fmt.Errorf("TODO")
// make sure there is one verification method
if len(didDoc.VerificationMethod) == 0 {
return nil, fmt.Errorf("missing verification method")
}

if len(didDoc.VerificationMethod) > 1 {
return nil, fmt.Errorf("found more than one verification method")
}

if didDoc.VerificationMethod[0].Type != jsonWebKey2020 {
return nil, fmt.Errorf("verification method type[%s] is not supported", didDoc.VerificationMethod[0].Type)
}

key := didDoc.VerificationMethod[0].JSONWebKey()

didJWK, err := createDID(key)
if err != nil {
return nil, fmt.Errorf("error creating DID: %w", err)
}

return createJWKResolutionResult(didJWK, key)
}

func createDID(key *jwk.JWK) (string, error) {
if key == nil {
return "", fmt.Errorf("missing JWK")
}

keyBytes, err := key.MarshalJSON()
if err != nil {
return "", fmt.Errorf("marshal key: %w", err)
}

canonicalBytes, err := canonicalizer.MarshalCanonical(keyBytes)
if err != nil {
return "", fmt.Errorf("marshal canonical: %w", err)
}

didJWK := fmt.Sprintf("did:%s:%s", DIDMethod, base64.RawURLEncoding.EncodeToString(canonicalBytes))

return didJWK, nil
}
205 changes: 201 additions & 4 deletions component/vdr/jwk/creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,216 @@ SPDX-License-Identifier: Apache-2.0
package jwk_test

import (
"crypto/ed25519"
"crypto/rand"
"encoding/json"
"testing"

"github.com/hyperledger/aries-framework-go/pkg/doc/did"
jwkapi "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk"
"github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk/jwksupport"
"github.com/stretchr/testify/require"
"github.com/trustbloc/sidetree-core-go/pkg/canonicalizer"

"github.com/hyperledger/aries-framework-go-ext/component/vdr/jwk"
)

func TestCreate(t *testing.T) {
t.Run("test create", func(t *testing.T) {
t.Run("success - P256 key from spec", func(t *testing.T) {
var key jwkapi.JWK

err := json.Unmarshal([]byte(testP256), &key)
require.NoError(t, err)

vm, err := did.NewVerificationMethodFromJWK("", "JsonWebKey2020", "", &key)
require.NoError(t, err)

testDoc := &did.Doc{}
testDoc.VerificationMethod = []did.VerificationMethod{*vm}

v := jwk.New()
result, err := v.Create(testDoc)
require.NoError(t, err)
require.NotNil(t, result)

didDoc := result.DIDDocument

err = prettyPrint(didDoc)
require.NoError(t, err)

expectedDoc, err := did.ParseDocument([]byte(expectedP256DIDDocument))
require.NoError(t, err)

require.Equal(t, didDoc.ID, expectedDoc.ID)

require.Equal(t, 1, len(didDoc.VerificationMethod))
require.Equal(t, expectedDoc.VerificationMethod[0].ID, didDoc.VerificationMethod[0].ID)
require.Equal(t, expectedDoc.VerificationMethod[0].Controller, didDoc.VerificationMethod[0].Controller)
require.Equal(t, expectedDoc.VerificationMethod[0].Type, didDoc.VerificationMethod[0].Type)
require.Equal(t, expectedDoc.VerificationMethod[0].JSONWebKey().Kty, didDoc.VerificationMethod[0].JSONWebKey().Kty)
require.Equal(t, expectedDoc.VerificationMethod[0].JSONWebKey().Crv, didDoc.VerificationMethod[0].JSONWebKey().Crv)
require.Equal(t, expectedDoc.VerificationMethod[0].JSONWebKey().Use, didDoc.VerificationMethod[0].JSONWebKey().Use)

require.Equal(t, 1, len(didDoc.AssertionMethod))
require.Equal(t, expectedDoc.AssertionMethod[0], didDoc.AssertionMethod[0])
require.Equal(t, 1, len(didDoc.Authentication))
require.Equal(t, expectedDoc.Authentication[0], didDoc.Authentication[0])
require.Equal(t, 1, len(didDoc.CapabilityDelegation))
require.Equal(t, expectedDoc.CapabilityDelegation[0], didDoc.CapabilityDelegation[0])
require.Equal(t, 1, len(didDoc.CapabilityInvocation))
require.Equal(t, expectedDoc.CapabilityInvocation[0], didDoc.CapabilityInvocation[0])
require.Equal(t, 1, len(didDoc.KeyAgreement))
require.Equal(t, expectedDoc.KeyAgreement[0], didDoc.KeyAgreement[0])

canonicalDIDDoc, err := canonicalizer.MarshalCanonical(didDoc)
require.NoError(t, err)
canonicalExpectedDoc, err := canonicalizer.MarshalCanonical(expectedDoc)
require.NoError(t, err)

require.Equal(t, string(canonicalExpectedDoc), string(canonicalDIDDoc))
})

t.Run("success - test X25519 from spec", func(t *testing.T) {
var key jwkapi.JWK

err := json.Unmarshal([]byte(testX25519), &key)
require.NoError(t, err)

vm, err := did.NewVerificationMethodFromJWK("", "JsonWebKey2020", "", &key)
require.NoError(t, err)

testDoc := &did.Doc{}
testDoc.VerificationMethod = []did.VerificationMethod{*vm}

v := jwk.New()
result, err := v.Create(testDoc)
require.NoError(t, err)
require.NotNil(t, result)

didDoc := result.DIDDocument

err = prettyPrint(didDoc)
require.NoError(t, err)

expectedDoc, err := did.ParseDocument([]byte(expectedX25519Document))
require.NoError(t, err)

// this test example from spec did not use JCS so ID will be different;
// hence we cannot check for ID equality

require.Equal(t, 1, len(didDoc.VerificationMethod))
require.Equal(t, expectedDoc.VerificationMethod[0].Type, didDoc.VerificationMethod[0].Type)
require.Equal(t, expectedDoc.VerificationMethod[0].JSONWebKey().Kty, didDoc.VerificationMethod[0].JSONWebKey().Kty)
require.Equal(t, expectedDoc.VerificationMethod[0].JSONWebKey().Crv, didDoc.VerificationMethod[0].JSONWebKey().Crv)
require.Equal(t, expectedDoc.VerificationMethod[0].JSONWebKey().Use, didDoc.VerificationMethod[0].JSONWebKey().Use)

require.Equal(t, 0, len(didDoc.AssertionMethod))
require.Equal(t, 0, len(didDoc.Authentication))
require.Equal(t, 0, len(didDoc.CapabilityDelegation))
require.Equal(t, 0, len(didDoc.CapabilityInvocation))
require.Equal(t, 1, len(didDoc.KeyAgreement))
})

t.Run("test create - generated Ed25519 key", func(t *testing.T) {
_, pk, err := ed25519.GenerateKey(rand.Reader)
require.NoError(t, err)

key, err := jwksupport.JWKFromKey(pk)
require.NoError(t, err)

vm, err := did.NewVerificationMethodFromJWK("", "JsonWebKey2020", "", key)
require.NoError(t, err)

testDoc := &did.Doc{}
testDoc.VerificationMethod = []did.VerificationMethod{*vm}

v := jwk.New()
doc, err := v.Create(nil)
result, err := v.Create(testDoc)
require.NoError(t, err)
require.NotNil(t, result)

didDoc := result.DIDDocument

err = prettyPrint(didDoc)
require.NoError(t, err)
})

t.Run("error - missing verification method", func(t *testing.T) {
testDoc := &did.Doc{}
testDoc.VerificationMethod = []did.VerificationMethod{}

v := jwk.New()
result, err := v.Create(testDoc)
require.Error(t, err)
require.Nil(t, result)
require.Contains(t, err.Error(), "missing verification method")
})

t.Run("error - more than one verification method", func(t *testing.T) {
var key jwkapi.JWK

err := json.Unmarshal([]byte(testX25519), &key)
require.NoError(t, err)

vm, err := did.NewVerificationMethodFromJWK("", "JsonWebKey2020", "", &key)
require.NoError(t, err)

testDoc := &did.Doc{}
testDoc.VerificationMethod = []did.VerificationMethod{*vm, *vm}

v := jwk.New()
result, err := v.Create(testDoc)
require.Error(t, err)
require.Nil(t, doc)
require.Contains(t, err.Error(), "TODO")
require.Nil(t, result)
require.Contains(t, err.Error(), "found more than one verification method")
})

t.Run("error - wrong verification method type", func(t *testing.T) {
var key jwkapi.JWK

err := json.Unmarshal([]byte(testP256), &key)
require.NoError(t, err)

vm, err := did.NewVerificationMethodFromJWK("", "not-supported", "", &key)
require.NoError(t, err)

testDoc := &did.Doc{}
testDoc.VerificationMethod = []did.VerificationMethod{*vm}

v := jwk.New()
result, err := v.Create(testDoc)
require.Error(t, err)
require.Nil(t, result)
require.Contains(t, err.Error(), "verification method type[not-supported] is not supported")
})

t.Run("error - verification method is not JWK", func(t *testing.T) {
pubKey, _, err := ed25519.GenerateKey(rand.Reader)
require.NoError(t, err)

vm := did.NewVerificationMethodFromBytes("", "JsonWebKey2020", "", pubKey)

testDoc := &did.Doc{}
testDoc.VerificationMethod = []did.VerificationMethod{*vm}

v := jwk.New()
result, err := v.Create(testDoc)
require.Error(t, err)
require.Nil(t, result)
require.Contains(t, err.Error(), "missing JWK")
})
}

const testP256 = `{
"crv": "P-256",
"kty": "EC",
"x": "acbIQiuMs3i8_uszEjJ2tpTtRM4EU3yz91PH6CdH2V0",
"y": "_KcyLj9vWMptnmKtm46GqDz8wf74I5LKgrl2GzH3nSE"
}`

const testX25519 = `{
"kty":"OKP",
"crv":"X25519",
"use":"enc",
"x":"3p7bfXt9wbTTW2HC7OQ1Nz-DQ8hbeGdNrfx-FG-IK08"
}`
2 changes: 1 addition & 1 deletion component/vdr/jwk/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go 1.19
require (
github.com/hyperledger/aries-framework-go v0.1.9-0.20221201073943-47b08f16c301
github.com/stretchr/testify v1.8.1
github.com/trustbloc/sidetree-core-go v1.0.0-rc3.0.20221028171319-8d44bd1cace7
)

require (
Expand All @@ -17,7 +18,6 @@ require (
github.com/google/uuid v1.3.0 // indirect
github.com/hyperledger/aries-framework-go/spi v0.0.0-20221025204933-b807371b6f1e // indirect
github.com/kilic/bls12-381 v0.1.1-0.20210503002446-7b7597926c69 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.1.0 // indirect
Expand Down
10 changes: 5 additions & 5 deletions component/vdr/jwk/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -22,8 +21,8 @@ github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/tink/go v1.7.0 h1:6Eox8zONGebBFcCBqkVmt60LaWZa6xg1cl/DwAh/J1w=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand All @@ -39,9 +38,7 @@ github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlT
github.com/kilic/bls12-381 v0.1.1-0.20210503002446-7b7597926c69 h1:kMJlf8z8wUcpyI+FQJIdGjAhfTww1y0AbQEv86bpVQI=
github.com/kilic/bls12-381 v0.1.1-0.20210503002446-7b7597926c69/go.mod h1:tlkavyke+Ac7h8R3gZIjI5LKBcvMlSWnXNMgT3vZXo8=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
Expand All @@ -51,6 +48,7 @@ github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ8
github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM=
github.com/multiformats/go-multibase v0.1.1 h1:3ASCDsuLX8+j4kx58qnJ4YFq/JWTJpCyDW27ztsVTOI=
github.com/multiformats/go-multibase v0.1.1/go.mod h1:ZEjHE+IsUrgp5mhlEAYjMtZwK1k4haNkcaPg9aoe1a8=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
Expand All @@ -77,6 +75,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8 h1:RBkacARv7qY5laaXGlF4wFB/tk5rnthhPb8oIBGoagY=
github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8/go.mod h1:9PdLyPiZIiW3UopXyRnPYyjUXSpiQNHRLu8fOsR3o8M=
github.com/trustbloc/sidetree-core-go v1.0.0-rc3.0.20221028171319-8d44bd1cace7 h1:/7Ak2CW7iJEVF/uYhOu3KUAKTTlNII0DnJlAkw/hGoQ=
github.com/trustbloc/sidetree-core-go v1.0.0-rc3.0.20221028171319-8d44bd1cace7/go.mod h1:SOuPJu8u7DSs2c494HPFAkkZ3KlfR/4swQ+YWqxZ2C8=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand Down Expand Up @@ -106,7 +106,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
15 changes: 5 additions & 10 deletions component/vdr/jwk/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

const (
schemaResV1 = "https://w3id.org/did-resolution/v1"
schemaDIDV1 = "https://w3id.org/did/v1"
schemaDIDV1 = "https://www.w3.org/ns/did/v1"
jwsSuiteV1 = "https://w3id.org/security/suites/jws-2020/v1"
jsonWebKey2020 = "JsonWebKey2020"
)
Expand All @@ -39,23 +39,18 @@ func (v *VDR) Read(didJWK string, _ ...vdrapi.DIDMethodOption) (*did.DocResoluti
return nil, fmt.Errorf("jwk-vdr read: failed to get key: %w", err)
}

didDoc, err := createJSONWebKey2020DIDDoc(didJWK, key)
if err != nil {
return nil, fmt.Errorf("jwk-vdr read: creating did document from JWK key failed: %w", err)
}

return &did.DocResolution{Context: []string{schemaResV1}, DIDDocument: didDoc}, nil //nolint:exhaustruct
return createJWKResolutionResult(didJWK, key)
}

func createJSONWebKey2020DIDDoc(didJWK string, key *jwk.JWK) (*did.Doc, error) {
func createJWKResolutionResult(didJWK string, key *jwk.JWK) (*did.DocResolution, error) {
vm, err := did.NewVerificationMethodFromJWK(fmt.Sprintf("%s#0", didJWK), jsonWebKey2020, didJWK, key)
if err != nil {
return nil, fmt.Errorf("error creating verification method %w", err)
return nil, fmt.Errorf("generate resolution result: error creating verification method: %w", err)
}

didDoc := createDoc(vm, didJWK)

return didDoc, nil
return &did.DocResolution{Context: []string{schemaResV1}, DIDDocument: didDoc}, nil
}

func createDoc(pubKey *did.VerificationMethod, didJWK string) *did.Doc {
Expand Down
Loading

0 comments on commit 5a3273a

Please sign in to comment.