diff --git a/packages/web5/tests/test-utils/test-user-agent.ts b/packages/web5/tests/test-utils/test-user-agent.ts index cc3758c01..5150bd92f 100644 --- a/packages/web5/tests/test-utils/test-user-agent.ts +++ b/packages/web5/tests/test-utils/test-user-agent.ts @@ -2,8 +2,8 @@ import type { DidIonCreateOptions } from '@tbd54566975/dids'; import { DidIonApi, DidKeyApi, DidResolver } from '@tbd54566975/dids'; import { Web5UserAgent, ProfileApi, ProfileStore } from '@tbd54566975/web5-user-agent'; -import { Dwn, DataStoreLevel, EventLogLevel, MessageStoreLevel } from '@tbd54566975/dwn-sdk-js'; -import { KeyManager, KeyManagerOptions, KeyManagerStore, ManagedKeyPair, ManagedKey, KmsKeyStore, KmsPrivateKeyStore, ManagedPrivateKey, LocalKms} from '@tbd54566975/crypto'; +import { Dwn, DataStoreLevel, EventLogLevel, MessageStoreLevel, Encoder } from '@tbd54566975/dwn-sdk-js'; +import { KeyManager, KeyManagerOptions, KeyManagerStore, ManagedKeyPair, ManagedKey, KmsKeyStore, KmsPrivateKeyStore, ManagedPrivateKey, LocalKms, ImportableKeyPair} from '@tbd54566975/crypto'; import { MemoryStore } from '@tbd54566975/common'; import { AppStorage } from '../../src/app-storage.js'; @@ -25,6 +25,7 @@ export type TestAgentOptions = { didIon: DidIonApi; didKey: DidKeyApi; signKeyPair: ManagedKeyPair; + keyManager: KeyManager; } export type TestProfile = { @@ -48,6 +49,8 @@ export class TestAgent { didIon: DidIonApi; didKey: DidKeyApi; signKeyPair: ManagedKeyPair; + keyManager: KeyManager; + kid?: string; constructor(options: TestAgentOptions) { this.agent = options.agent; @@ -62,6 +65,7 @@ export class TestAgent { this.didIon = options.didIon; this.didKey = options.didKey; this.signKeyPair = options.signKeyPair; + this.keyManager = options.keyManager; } async clearStorage(): Promise { @@ -151,7 +155,8 @@ export class TestAgent { didResolver, didIon : DidIon, didKey : DidKey, - signKeyPair : keyPair + signKeyPair : keyPair, + keyManager : keyManager, }); } @@ -160,6 +165,7 @@ export class TestAgent { const DidKey = new DidKeyApi(); const appDidState = await DidKey.create(); + console.log('creating did ion with options: ', options.profileDidOptions); const profileDidState = await DidIon.create(options.profileDidOptions); const profile = await this.profileApi.createProfile({ @@ -169,8 +175,36 @@ export class TestAgent { }); // TODO: Import did auth key into key manager (but will have to convert format from jwk to key material) + const key = profileDidState.keys[0]; + + console.log('did ion key: ', key); + console.log('did verification methods: ', profileDidState.didDocument?.verificationMethod); + + const importableKey: ImportableKeyPair = { + privateKey: { + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + extractable : true, + kms : 'local', + material : Encoder.base64UrlToBytes(key.privateKeyJwk.d), + type : 'private', + usages : ['sign'], + }, + publicKey: { + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + extractable : true, + kms : 'local', + material : Encoder.base64UrlToBytes(key.privateKeyJwk.x), + type : 'public', + usages : ['verify'], + } + }; + const keypair = await this.keyManager.importKey(importableKey); + + this.kid = keypair.privateKey.id; - return { did: profile.did.id }; + return { + did: profile.did.id, + }; } async openStorage() { diff --git a/packages/web5/tests/web5-vc-ssi.spec.ts b/packages/web5/tests/web5-vc-ssi.spec.ts index 058b46c7b..a219f272d 100644 --- a/packages/web5/tests/web5-vc-ssi.spec.ts +++ b/packages/web5/tests/web5-vc-ssi.spec.ts @@ -47,7 +47,7 @@ describe('web5.vc.ssi', () => { const result = await vcApi.create({ credentialSubject : { firstName: 'alice' }, - kid : testAgent.signKeyPair.privateKey.id, + kid : testAgent.kid, }); console.log('vc api create: ', result); expect(result.status.code).to.equal(202); diff --git a/packages/web5/tests/web5-vc.spec.ts b/packages/web5/tests/web5-vc.spec.ts index 5b32a755d..99c0fa26b 100644 --- a/packages/web5/tests/web5-vc.spec.ts +++ b/packages/web5/tests/web5-vc.spec.ts @@ -9,7 +9,7 @@ import jwt from 'jsonwebtoken'; let did: string; let vcApi: VcApi; -let testAgent; +let testAgent: TestAgent; let testProfileOptions: TestProfileOptions; describe('web5.vc', () => { @@ -36,9 +36,11 @@ describe('web5.vc', () => { it('valid vc', async () => { const credentialSubject = {firstName: 'alice'}; - const vcCreateRequest: VcCreateRequest = { credentialSubject: credentialSubject, kid: testAgent.signKeyPair.privateKey.id}; + const vcCreateRequest: VcCreateRequest = { credentialSubject: credentialSubject, kid: testAgent.kid}; const result = await vcApi.create(vcCreateRequest); + console.log(result); + const resultRecord = await result.record?.data.text(); const decodedVc = jwt.decode(resultRecord, { complete: true });