Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ES256K-R verification with checksumAddress in eip155 blockchainAccountId #232

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@babel/core": "7.18.2",
"@babel/preset-env": "7.17.12",
"@babel/preset-typescript": "7.17.12",
"@ethersproject/address": "5.6.1",
"@semantic-release/changelog": "6.0.1",
"@semantic-release/git": "10.0.1",
"@types/elliptic": "6.4.14",
Expand Down
2 changes: 1 addition & 1 deletion src/VerifierAlgorithm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function verifyRecoverableES256K(
const recoveredKey: any = secp256k1.recoverPubKey(hash, <SignatureInput>sigObj, <number>sigObj.recoveryParam)
const recoveredPublicKeyHex: string = recoveredKey.encode('hex')
const recoveredCompressedPublicKeyHex: string = recoveredKey.encode('hex', true)
const recoveredAddress: string = toEthereumAddress(recoveredPublicKeyHex)
const recoveredAddress: string = toEthereumAddress(recoveredPublicKeyHex).toLowerCase()

const signer: VerificationMethod | undefined = authenticators.find((pk: VerificationMethod) => {
const keyHex = bytesToHex(extractPublicKeyBytes(pk))
Expand Down
24 changes: 24 additions & 0 deletions src/__tests__/JWT.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { VerificationMethod } from 'did-resolver'
import { TokenVerifier } from 'jsontokens'
import MockDate from 'mockdate'
import { fromString } from 'uint8arrays/from-string'
import { getAddress } from "@ethersproject/address"
import {
createJWS,
createJWT,
Expand Down Expand Up @@ -549,6 +550,29 @@ describe('verifyJWT()', () => {
return expect(payload).toMatchSnapshot()
})

it('handles ES256K-R algorithm with checksum address in blockchainAccountId - github #231', async () => {
expect.assertions(1)
const verificationMethod = {
id: `${did}#keys-1`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
owner: did,
blockchainAccountId: `eip155:1:${getAddress(address)}`,
}
const ethResolver = {
resolve: jest.fn().mockReturnValue({
didDocument: {
id: did,
verificationMethod: [
verificationMethod
],
},
}),
}
const jwt = await createJWT({ hello: 'world' }, { issuer: aud, signer: recoverySigner, alg: 'ES256K-R' })
const result = await verifyJWT(jwt, { resolver: ethResolver })
return expect(result.signer).toEqual(verificationMethod)
})

it('accepts a valid exp', async () => {
expect.assertions(1)
const jwt = await createJWT({ exp: NOW }, { issuer: did, signer })
Expand Down
2 changes: 1 addition & 1 deletion src/blockchains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const verifyBlockchainAccountId = (publicKey: string, blockchainAccountId
default:
return false
}
return chain.join(':') === blockchainAccountId
return chain.join(':').toLowerCase() === blockchainAccountId.toLowerCase()
}
return false
}
55 changes: 54 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,54 @@
minimatch "^3.1.2"
strip-json-comments "^3.1.1"

"@ethersproject/[email protected]":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/address/-/address-5.6.1.tgz#ab57818d9aefee919c5721d28cd31fd95eff413d"
integrity sha512-uOgF0kS5MJv9ZvCz7x6T2EXJSzotiybApn4XlOgoTX0xdtyVIJ7pF+6cGPxiEq/dpBiTfMiw7Yc81JcwhSYA0Q==
dependencies:
"@ethersproject/bignumber" "^5.6.2"
"@ethersproject/bytes" "^5.6.1"
"@ethersproject/keccak256" "^5.6.1"
"@ethersproject/logger" "^5.6.0"
"@ethersproject/rlp" "^5.6.1"

"@ethersproject/bignumber@^5.6.2":
version "5.6.2"
resolved "https://registry.yarnpkg.com/@ethersproject/bignumber/-/bignumber-5.6.2.tgz#72a0717d6163fab44c47bcc82e0c550ac0315d66"
integrity sha512-v7+EEUbhGqT3XJ9LMPsKvXYHFc8eHxTowFCG/HgJErmq4XHJ2WR7aeyICg3uTOAQ7Icn0GFHAohXEhxQHq4Ubw==
dependencies:
"@ethersproject/bytes" "^5.6.1"
"@ethersproject/logger" "^5.6.0"
bn.js "^5.2.1"

"@ethersproject/bytes@^5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/bytes/-/bytes-5.6.1.tgz#24f916e411f82a8a60412344bf4a813b917eefe7"
integrity sha512-NwQt7cKn5+ZE4uDn+X5RAXLp46E1chXoaMmrxAyA0rblpxz8t58lVkrHXoRIn0lz1joQElQ8410GqhTqMOwc6g==
dependencies:
"@ethersproject/logger" "^5.6.0"

"@ethersproject/keccak256@^5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/keccak256/-/keccak256-5.6.1.tgz#b867167c9b50ba1b1a92bccdd4f2d6bd168a91cc"
integrity sha512-bB7DQHCTRDooZZdL3lk9wpL0+XuG3XLGHLh3cePnybsO3V0rdCAOQGpn/0R3aODmnTOOkCATJiD2hnL+5bwthA==
dependencies:
"@ethersproject/bytes" "^5.6.1"
js-sha3 "0.8.0"

"@ethersproject/logger@^5.6.0":
version "5.6.0"
resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.6.0.tgz#d7db1bfcc22fd2e4ab574cba0bb6ad779a9a3e7a"
integrity sha512-BiBWllUROH9w+P21RzoxJKzqoqpkyM1pRnEKG69bulE9TSQD8SAIvTQqIMZmmCO8pUNkgLP1wndX1gKghSpBmg==

"@ethersproject/rlp@^5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/rlp/-/rlp-5.6.1.tgz#df8311e6f9f24dcb03d59a2bac457a28a4fe2bd8"
integrity sha512-uYjmcZx+DKlFUk7a5/W9aQVaoEC7+1MOBgNtvNg13+RnuUwT4F0zTovC0tmay5SmRslb29V1B7Y5KCri46WhuQ==
dependencies:
"@ethersproject/bytes" "^5.6.1"
"@ethersproject/logger" "^5.6.0"

"@gar/promisify@^1.0.1", "@gar/promisify@^1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6"
Expand Down Expand Up @@ -2819,6 +2867,11 @@ bn.js@^4.11.9:
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88"
integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==

bn.js@^5.2.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70"
integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==

boolbase@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
Expand Down Expand Up @@ -5354,7 +5407,7 @@ [email protected]:
import-local "^3.0.2"
jest-cli "^28.1.0"

js-sha3@^0.8.0:
js-sha3@0.8.0, js-sha3@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.8.0.tgz#b9b7a5da73afad7dedd0f8c463954cbde6818840"
integrity sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==
Expand Down