diff --git a/__tests__/shared/didcomm.ts b/__tests__/shared/didcomm.ts index 918fceb3f..71136df6a 100644 --- a/__tests__/shared/didcomm.ts +++ b/__tests__/shared/didcomm.ts @@ -18,7 +18,7 @@ export default (testContext: { agent = testContext.getAgent() sender = await agent.didManagerImport({ - did: 'did:key:z6MkgbqNU4uF9NKSz5BqJQ4XKVHuQZYcUZP8pXGsJC8nTHwo', + did: 'did:fake:z6MkgbqNU4uF9NKSz5BqJQ4XKVHuQZYcUZP8pXGsJC8nTHwo', keys: [ { type: 'Ed25519', @@ -30,12 +30,12 @@ export default (testContext: { }, ], services: [], - provider: 'did:key', + provider: 'did:fake', alias: 'sender', }) receiver = await agent.didManagerImport({ - did: 'did:key:z6MkrPhffVLBZpxH7xvKNyD4sRVZeZsNTWJkLdHdgWbfgNu3', + did: 'did:fake:z6MkrPhffVLBZpxH7xvKNyD4sRVZeZsNTWJkLdHdgWbfgNu3', keys: [ { type: 'Ed25519', @@ -47,7 +47,7 @@ export default (testContext: { }, ], services: [], - provider: 'did:key', + provider: 'did:fake', alias: 'receiver', }) return true diff --git a/packages/did-comm/src/action-handler.ts b/packages/did-comm/src/action-handler.ts index 0730b2c37..997a53438 100644 --- a/packages/did-comm/src/action-handler.ts +++ b/packages/did-comm/src/action-handler.ts @@ -276,18 +276,7 @@ export class DIDComm implements IAgentPlugin { // 2.2 get public key bytes and key IDs for supported recipient keys const recipients: { kid: string; publicKeyBytes: Uint8Array }[] = keyAgreementKeys - .map((pk) => { - const publicKeyHex = pk.publicKeyHex! - let publicKeyBytes = u8a.fromString(publicKeyHex, 'base16') - if (['Ed25519VerificationKey2018', 'Ed25519'].includes(pk.type)) { - publicKeyBytes = convertPublicKeyToX25519(publicKeyBytes) - } else if (!['X25519KeyAgreementKey2019', 'X25519'].includes(pk.type)) { - // other key agreement keys not supported - return null - } - const kid = pk.id - return { kid, publicKeyBytes } - }) + .map((pk) => ({ kid: pk.id, publicKeyBytes: u8a.fromString(pk.publicKeyHex!, 'base16') })) .filter(isDefined) // 3. create Encrypter for each recipient diff --git a/packages/did-comm/src/utils.ts b/packages/did-comm/src/utils.ts index ba065dbd3..49c5a1a33 100644 --- a/packages/did-comm/src/utils.ts +++ b/packages/did-comm/src/utils.ts @@ -245,7 +245,11 @@ export async function dereferenceDidKeys( .map((key) => { const hexKey = convertToPublicKeyHex(key, convert) const { publicKeyHex, publicKeyBase58, publicKeyBase64, publicKeyJwk, ...keyProps } = key - return { ...keyProps, publicKeyHex: hexKey } + const newKey = { ...keyProps, publicKeyHex: hexKey } + if (convert && 'Ed25519VerificationKey2018' === newKey.type) { + newKey.type = 'X25519KeyAgreementKey2019' + } + return newKey }) .filter((key) => key.publicKeyHex.length > 0) }