github.com/hyperledger/aries-framework-go@v0.3.2/pkg/internal/test/makemockdoc/makemockdoc.go (about) 1 /* 2 Copyright Avast Software. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package makemockdoc 8 9 import ( 10 "testing" 11 12 "github.com/stretchr/testify/require" 13 14 "github.com/hyperledger/aries-framework-go/pkg/doc/did" 15 "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" 16 "github.com/hyperledger/aries-framework-go/pkg/doc/util/jwkkid" 17 "github.com/hyperledger/aries-framework-go/pkg/kms" 18 ) 19 20 const ( 21 // DefaultKID the KID of the mock doc's verification method. 22 DefaultKID = "#key-1" 23 ed25519VerificationKey2018 = "Ed25519VerificationKey2018" 24 jsonWebKey2020 = "JsonWebKey2020" 25 ) 26 27 // MakeMockDoc creates a key in the given KMS and returns a mock DID Doc with a verification method using the given key. 28 func MakeMockDoc(t *testing.T, keyManager kms.KeyManager, docDID string, keyType kms.KeyType) *did.Doc { 29 t.Helper() 30 31 _, pkb, err := keyManager.CreateAndExportPubKeyBytes(keyType) 32 require.NoError(t, err) 33 34 var pkJWK *jwk.JWK 35 36 var vm *did.VerificationMethod 37 38 if keyType == kms.ED25519Type { 39 vm = &did.VerificationMethod{ 40 ID: DefaultKID, 41 Controller: docDID, 42 Type: ed25519VerificationKey2018, 43 Value: pkb, 44 } 45 } else { 46 pkJWK, err = jwkkid.BuildJWK(pkb, keyType) 47 require.NoError(t, err) 48 49 pkJWK.Algorithm = "ECDSA" 50 51 vm, err = did.NewVerificationMethodFromJWK(DefaultKID, jsonWebKey2020, docDID, pkJWK) 52 require.NoError(t, err) 53 } 54 55 newDoc := &did.Doc{ 56 ID: docDID, 57 AssertionMethod: []did.Verification{ 58 { 59 VerificationMethod: *vm, 60 Relationship: did.AssertionMethod, 61 }, 62 }, 63 VerificationMethod: []did.VerificationMethod{ 64 *vm, 65 }, 66 } 67 68 return newDoc 69 }