Skip to content

Commit

Permalink
fix: new ledgerjs package
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbrugneaux committed Nov 5, 2024
1 parent 958e77a commit 52afedd
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 49 deletions.
7 changes: 5 additions & 2 deletions packages/sdk/wallets/wallet-base/src/signing-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,15 @@ export function determineTXType(serializedTransaction: string): OldTransactionTy
}

function vrsForRecovery(vRaw: string, r: string, s: string) {
const v = vRaw === '0x' || hexToNumber(vRaw) === 0 ? Y_PARITY_EIP_2098 : Y_PARITY_EIP_2098 + 1
const v =
vRaw === '0x' || hexToNumber(vRaw) === 0 || hexToNumber(vRaw) === 27
? Y_PARITY_EIP_2098
: Y_PARITY_EIP_2098 + 1
return {
v,
r,
s,
yParity: v === Y_PARITY_EIP_2098 ? 0 : 1,
yParity: (v - Y_PARITY_EIP_2098) as 0 | 1,
} as const
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/wallets/wallet-ledger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@celo/wallet-remote": "^6.0.2-beta.0",
"@ethereumjs/util": "8.0.5",
"@ledgerhq/errors": "^6.16.4",
"@ledgerhq/hw-app-eth": "git+https://github.com:celo-org/ledgerjs-hw-app-eth.git",
"@ledgerhq/hw-app-eth": "git+https://github.com:celo-org/ledgerjs-hw-app-eth.git#commit=b10b34511f12beb67488d3d6abab2e88192ae76a",
"@ledgerhq/hw-transport": "^6.30.6",
"debug": "^4.1.1",
"semver": "^7.6.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class LedgerSigner implements Signer {
v = addToV + _v
} else if (_v === 27 || _v === 28) {
const parity = _v - 27 // transforming v into 0 or 1 to become the parity
v = addToV + _v + parity
v = addToV + parity
} else {
v = _v
}
Expand Down
47 changes: 3 additions & 44 deletions packages/sdk/wallets/wallet-ledger/src/ledger-wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { VerifyPublicKeyInput, createVerify } from 'crypto'
import { readFileSync } from 'fs'
import { dirname, join } from 'path'
import Web3 from 'web3'
import { rlpEncodedTx } from '../../wallet-base/lib'
import { legacyLedgerPublicKeyHex } from './data'
import { meetsVersionRequirements } from './ledger-utils'
import { AddressValidation, LedgerWallet } from './ledger-wallet'
Expand Down Expand Up @@ -437,9 +436,10 @@ describe('LedgerWallet class', () => {
'v=1',
async () => {
const signed = await wallet.signTransaction({
// produces a v=1
...celoTransaction,
nonce: 501,
// produces a v=1 according to device or nah, possibly
// unique to nico's device?
nonce: USE_PHYSICAL_LEDGER ? 2 : 101,
})
expect(signed).not.toBeUndefined()
const [_txParams, address] = recoverTransaction(signed.raw)
Expand Down Expand Up @@ -998,44 +998,3 @@ describe('LedgerWallet class', () => {
})
})
})

describe('patch-package @ledgerhq/hw-app-eth', () => {
test('was applied correctly', async () => {
const { decodeTxInfo } = await import('@ledgerhq/hw-app-eth/lib/utils')

const kit = newKit('https://alfajores-forno.celo-testnet.org')
const celoTransaction = {
from: ACCOUNT_ADDRESS1,
to: ACCOUNT_ADDRESS2,
chainId: CHAIN_ID,
value: Web3.utils.toWei('1', 'ether'),
nonce: 0,
gas: 99,
maxFeePerGas: 99,
maxPriorityFeePerGas: 99,
feeCurrency: (await kit.contracts.getStableToken(StableToken.cUSD)).address,
}
const serialized = rlpEncodedTx(celoTransaction)
const rawTx = Buffer.from(trimLeading0x(serialized.rlpEncode), 'hex')
let ledgerDecoded: ReturnType<typeof decodeTxInfo>
expect(() => {
ledgerDecoded = decodeTxInfo(rawTx)
}).not.toThrow(/invalid rlp data/)
expect(ledgerDecoded!.txType).toEqual(0x7b)
expect(ledgerDecoded!.chainId.toNumber()).toEqual(CHAIN_ID)
expect(ledgerDecoded!.decodedTx).toMatchInlineSnapshot(`
{
"chainId": {
"data": [
174,
243,
],
"type": "Buffer",
},
"data": "0x",
"feeCurrency": "0x874069fa1eb16d44d622f2e0ca25eea172369bc1",
"to": "0x588e4b68193001e4d10928660ab4165b813717c0",
}
`)
})
})
5 changes: 5 additions & 0 deletions packages/sdk/wallets/wallet-local/src/local-wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ describe('Local wallet class', () => {
"type": "cip66",
}
`)
expect(
recoverTransaction(
'0x7af88382ad5a8063630a94588e4b68193001e4d10928660ab4165b813717c0880de0b6b3a764000083abcdefc094cd2a3d9f938e13cd947ec05abc7fe734df8dd8265c01a00fb404c1a62ab54b47b4ca07f5ac7e7b233be6cd173294c0b1f3a209c36f6265a05ac38f9ddd67ecf936f2dfea2be5f641959e2a66545fffb01ebd8c925ac23b89'
)[1].toLowerCase()
).toBe(wallet.getAccounts()[0].toLowerCase())
})
test('succeeds with cip64', async () => {
const recoverTransactionCIP64 = {
Expand Down
103 changes: 102 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ __metadata:
"@celo/wallet-remote": "npm:^6.0.2-beta.0"
"@ethereumjs/util": "npm:8.0.5"
"@ledgerhq/errors": "npm:^6.16.4"
"@ledgerhq/hw-app-eth": "git+https://github.com:celo-org/ledgerjs-hw-app-eth.git"
"@ledgerhq/hw-app-eth": "git+https://github.com:celo-org/ledgerjs-hw-app-eth.git#commit=b10b34511f12beb67488d3d6abab2e88192ae76a"
"@ledgerhq/hw-transport": "npm:^6.30.6"
"@ledgerhq/hw-transport-node-hid": "npm:^6.28.5"
"@noble/curves": "npm:^1.4.0"
Expand Down Expand Up @@ -3944,6 +3944,16 @@ __metadata:
languageName: node
linkType: hard

"@ledgerhq/cryptoassets-evm-signatures@npm:^13.5.1":
version: 13.5.1
resolution: "@ledgerhq/cryptoassets-evm-signatures@npm:13.5.1"
dependencies:
"@ledgerhq/live-env": "npm:^2.4.0"
axios: "npm:1.7.7"
checksum: 8e9889a0a4c53afcbac0d42eeff5617ac37d9a69528861080a6dbada0a4fced10b5e7157c27224fb854776f5f248d2a77baa33c39525064b440285434422b83b
languageName: node
linkType: hard

"@ledgerhq/cryptoassets@npm:^13.1.1":
version: 13.1.1
resolution: "@ledgerhq/cryptoassets@npm:13.1.1"
Expand Down Expand Up @@ -4018,6 +4028,21 @@ __metadata:
languageName: node
linkType: hard

"@ledgerhq/domain-service@npm:^1.2.10":
version: 1.2.10
resolution: "@ledgerhq/domain-service@npm:1.2.10"
dependencies:
"@ledgerhq/errors": "npm:^6.19.1"
"@ledgerhq/logs": "npm:^6.12.0"
"@ledgerhq/types-live": "npm:^6.52.4"
axios: "npm:1.7.7"
eip55: "npm:^2.1.1"
react: "npm:^18.2.0"
react-dom: "npm:^18.2.0"
checksum: a46d546bd68ee3f7247e63e89b3425ab7df9d62f75501b6db7a13b1a319fb40cb2272c638ddc6c1bee973f66bd70fa4156d3287fa31e20a5bb2d0164d59aaf61
languageName: node
linkType: hard

"@ledgerhq/errors@npm:^6.16.3":
version: 6.16.3
resolution: "@ledgerhq/errors@npm:6.16.3"
Expand Down Expand Up @@ -4059,6 +4084,19 @@ __metadata:
languageName: node
linkType: hard

"@ledgerhq/evm-tools@npm:^1.2.4":
version: 1.2.4
resolution: "@ledgerhq/evm-tools@npm:1.2.4"
dependencies:
"@ledgerhq/cryptoassets-evm-signatures": "npm:^13.5.1"
"@ledgerhq/live-env": "npm:^2.4.0"
axios: "npm:1.7.7"
crypto-js: "npm:4.2.0"
ethers: "npm:5.7.2"
checksum: 5e1e213f39b337a91858ba94418ed816d7fd7591c2798da1754cca6ac96f395c80fbb5e8c41ed568383b669c7eed59e998e5a5f81bee1c92f17f1a4895f97772
languageName: node
linkType: hard

"@ledgerhq/hw-app-eth@git+https://github.com:celo-org/ledgerjs-hw-app-eth.git":
version: 6.37.1
resolution: "@ledgerhq/hw-app-eth@https://github.com:celo-org/ledgerjs-hw-app-eth.git#commit=49bdd4f163f5ff73daa9f54f8e46aa2882b85f44"
Expand All @@ -4081,6 +4119,27 @@ __metadata:
languageName: node
linkType: hard

"@ledgerhq/hw-app-eth@git+https://github.com:celo-org/ledgerjs-hw-app-eth.git#commit=b10b34511f12beb67488d3d6abab2e88192ae76a":
version: 6.40.3
resolution: "@ledgerhq/hw-app-eth@https://github.com:celo-org/ledgerjs-hw-app-eth.git#commit=b10b34511f12beb67488d3d6abab2e88192ae76a"
dependencies:
"@ethersproject/abi": "npm:^5.5.0"
"@ethersproject/rlp": "npm:^5.5.0"
"@ledgerhq/cryptoassets-evm-signatures": "npm:^13.5.1"
"@ledgerhq/domain-service": "npm:^1.2.10"
"@ledgerhq/errors": "npm:^6.19.1"
"@ledgerhq/evm-tools": "npm:^1.2.4"
"@ledgerhq/hw-transport": "npm:^6.31.4"
"@ledgerhq/hw-transport-mocker": "npm:^6.29.4"
"@ledgerhq/logs": "npm:^6.12.0"
"@ledgerhq/types-live": "npm:^6.52.4"
axios: "npm:1.7.7"
bignumber.js: "npm:^9.1.2"
semver: "npm:^7.3.5"
checksum: 42216f1e6d2efa6f33df36b49722b825d17db390cb4dcef76fbd05cafe39978de3e29887bf0b533b22199b212beb4d05a547b5c77d41c8cdf871b7b82143adfa
languageName: node
linkType: hard

"@ledgerhq/hw-transport-mocker@npm:^6.29.0":
version: 6.29.0
resolution: "@ledgerhq/hw-transport-mocker@npm:6.29.0"
Expand All @@ -4092,6 +4151,17 @@ __metadata:
languageName: node
linkType: hard

"@ledgerhq/hw-transport-mocker@npm:^6.29.4":
version: 6.29.4
resolution: "@ledgerhq/hw-transport-mocker@npm:6.29.4"
dependencies:
"@ledgerhq/hw-transport": "npm:^6.31.4"
"@ledgerhq/logs": "npm:^6.12.0"
rxjs: "npm:^7.8.1"
checksum: 6f1568b1723ee6964872b09b712714bacf33c87e83413a33420b7ba11e3c30fa6786f02d2cf7b8bc9b3560f4b5c3b166017d5e0a960267a7824a153687fe32ed
languageName: node
linkType: hard

"@ledgerhq/hw-transport-node-hid-noevents@npm:^6.29.5":
version: 6.29.5
resolution: "@ledgerhq/hw-transport-node-hid-noevents@npm:6.29.5"
Expand Down Expand Up @@ -4208,6 +4278,16 @@ __metadata:
languageName: node
linkType: hard

"@ledgerhq/live-env@npm:^2.4.0":
version: 2.4.0
resolution: "@ledgerhq/live-env@npm:2.4.0"
dependencies:
rxjs: "npm:^7.8.1"
utility-types: "npm:^3.10.0"
checksum: 825337025181bb97ac9c55f413a0cf0b2fff2be62f53b5230d328f592fd0b8b9ee4e2d979bf55f576361b880dd5f1424a9331b2da597414c111c213ab7a15dba
languageName: node
linkType: hard

"@ledgerhq/logs@npm:^6.12.0":
version: 6.12.0
resolution: "@ledgerhq/logs@npm:6.12.0"
Expand Down Expand Up @@ -4239,6 +4319,16 @@ __metadata:
languageName: node
linkType: hard

"@ledgerhq/types-live@npm:^6.52.4":
version: 6.52.4
resolution: "@ledgerhq/types-live@npm:6.52.4"
dependencies:
bignumber.js: "npm:^9.1.2"
rxjs: "npm:^7.8.1"
checksum: 54288b5b334f0e9e57e5dbea9e8f9a86391e2e2daea2db755ee812dd9e687d45e426aab8737bac1c1fe308281ec170f75aca8845f2a3dba0201dc32a3dcdec1a
languageName: node
linkType: hard

"@manypkg/find-root@npm:^1.1.0":
version: 1.1.0
resolution: "@manypkg/find-root@npm:1.1.0"
Expand Down Expand Up @@ -7555,6 +7645,17 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:1.7.7":
version: 1.7.7
resolution: "axios@npm:1.7.7"
dependencies:
follow-redirects: "npm:^1.15.6"
form-data: "npm:^4.0.0"
proxy-from-env: "npm:^1.1.0"
checksum: 7f875ea13b9298cd7b40fd09985209f7a38d38321f1118c701520939de2f113c4ba137832fe8e3f811f99a38e12c8225481011023209a77b0c0641270e20cde1
languageName: node
linkType: hard

"axios@npm:^1.3.4, axios@npm:^1.6.0, axios@npm:^1.6.5":
version: 1.6.8
resolution: "axios@npm:1.6.8"
Expand Down

0 comments on commit 52afedd

Please sign in to comment.