Skip to content

Commit

Permalink
feat(utils): add publicKeyJwk as valid verificationMethod in getEther…
Browse files Browse the repository at this point in the history
…eumAddress (#1096)
  • Loading branch information
mmatteo23 authored Jan 12, 2023
1 parent f2258b6 commit a4209f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/utils/src/__tests__/did-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,20 @@ describe('@veramo/utils did utils', () => {

expect(getEthereumAddress(verificationMethod)).toEqual("0x1B54DaD834f2017ab66C1a1ffF74425889141e51".toLowerCase())
})

it('should return blockchainAccountId for did:key', () => {
const verificationMethod = {
"id": "did:key:zQ3shdHG4u9wPDoEzSokyLm3readHkrpYaXFf9jbc8Eiz1UM5#zQ3shdHG4u9wPDoEzSokyLm3readHkrpYaXFf9jbc8Eiz1UM5",
"type": "EcdsaSecp256k1VerificationKey2019",
"controller": "did:key:zQ3shdHG4u9wPDoEzSokyLm3readHkrpYaXFf9jbc8Eiz1UM5",
"publicKeyJwk": {
"kty": "EC",
"crv": "secp256k1",
"x": "6805tExt2N3AcS9cxs_RJT_RtAkfK6rqIix5B4k0oEg",
"y": "qw0mojIWWljYFYHvsSkcBfaUVfeSf1YEbyFZmzAif2Q"
}
}

expect(getEthereumAddress(verificationMethod)).toEqual("0x923f7158062db4761a8917ad1628d11536c5f07b".toLowerCase())
})
})
3 changes: 2 additions & 1 deletion packages/utils/src/did-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export function getEthereumAddress(verificationMethod: VerificationMethod): stri
} else if (
verificationMethod.publicKeyHex ||
verificationMethod.publicKeyBase58 ||
verificationMethod.publicKeyBase64
verificationMethod.publicKeyBase64 ||
verificationMethod.publicKeyJwk
) {
const pbBytes = extractPublicKeyBytes(verificationMethod)
const pbHex = computePublicKey(pbBytes, false)
Expand Down

0 comments on commit a4209f5

Please sign in to comment.