From c615a360272037dd7318c4d10030cf6a724de364 Mon Sep 17 00:00:00 2001 From: Kheops <26880866+0xKheops@users.noreply.github.com> Date: Wed, 8 Nov 2023 12:44:06 +0900 Subject: [PATCH] fix: ledger signature crafting --- apps/extension/package.json | 2 +- .../ui/domains/Sign/SignLedgerEthereum.tsx | 22 ++++++++++++++----- packages/balances-evm-erc20/package.json | 2 +- packages/balances-evm-native/package.json | 2 +- packages/chain-connector-evm/package.json | 2 +- yarn.lock | 16 +++++++------- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/apps/extension/package.json b/apps/extension/package.json index c7e964ec71..30ce25b63b 100644 --- a/apps/extension/package.json +++ b/apps/extension/package.json @@ -137,7 +137,7 @@ "typescript": "^5.2.2", "url-join": "^5.0.0", "uuid": "^8.3.2", - "viem": "^1.18.3", + "viem": "^1.18.9", "webextension-polyfill": "0.8.0", "webpack": "^5.88.1", "webpack-cli": "^4.10.0", diff --git a/apps/extension/src/ui/domains/Sign/SignLedgerEthereum.tsx b/apps/extension/src/ui/domains/Sign/SignLedgerEthereum.tsx index 2c6877fc13..c791077758 100644 --- a/apps/extension/src/ui/domains/Sign/SignLedgerEthereum.tsx +++ b/apps/extension/src/ui/domains/Sign/SignLedgerEthereum.tsx @@ -28,11 +28,23 @@ import { import { LedgerSigningStatus } from "./LedgerSigningStatus" import { SignHardwareEthereumProps } from "./SignHardwareEthereum" -const toSignature = ({ v, r, s }: { v: string | number; r: string; s: string }): Signature => ({ - v: typeof v === "string" ? hexToBigInt(`0x${v}`) : BigInt(v), - r: `0x${r}`, - s: `0x${s}`, -}) +const toSignature = ({ v, r, s }: { v: string | number; r: string; s: string }): Signature => { + const parseV = (v: string | number) => { + const parsed = typeof v === "string" ? hexToBigInt(`0x${v}`) : BigInt(v) + + // ideally this should be done in viem + if (parsed === 0n) return 27n + if (parsed === 1n) return 28n + + return parsed + } + + return { + v: parseV(v), + r: `0x${r}`, + s: `0x${s}`, + } +} const signWithLedger = async ( ledger: LedgerEthereumApp, diff --git a/packages/balances-evm-erc20/package.json b/packages/balances-evm-erc20/package.json index 7bf751f184..8a2b743ded 100644 --- a/packages/balances-evm-erc20/package.json +++ b/packages/balances-evm-erc20/package.json @@ -31,7 +31,7 @@ "@talismn/util": "workspace:*", "anylogger": "^1.0.11", "lodash": "4.17.21", - "viem": "^1.18.3" + "viem": "^1.18.9" }, "devDependencies": { "@polkadot/util": "^11.1.1", diff --git a/packages/balances-evm-native/package.json b/packages/balances-evm-native/package.json index 073a9d68fe..98e1d778c4 100644 --- a/packages/balances-evm-native/package.json +++ b/packages/balances-evm-native/package.json @@ -31,7 +31,7 @@ "@talismn/util": "workspace:*", "anylogger": "^1.0.11", "lodash": "4.17.21", - "viem": "^1.18.3" + "viem": "^1.18.9" }, "devDependencies": { "@talismn/eslint-config": "workspace:*", diff --git a/packages/chain-connector-evm/package.json b/packages/chain-connector-evm/package.json index 39e21a7989..ca4d2f1bd2 100644 --- a/packages/chain-connector-evm/package.json +++ b/packages/chain-connector-evm/package.json @@ -30,7 +30,7 @@ "@talismn/util": "workspace:*", "anylogger": "^1.0.11", "lodash": "4.17.21", - "viem": "^1.18.3" + "viem": "^1.18.9" }, "devDependencies": { "@talismn/eslint-config": "workspace:*", diff --git a/yarn.lock b/yarn.lock index 1cbe0ad63a..a7d88d331a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7857,7 +7857,7 @@ __metadata: lodash: 4.17.21 ts-jest: ^28.0.2 typescript: ^5.2.2 - viem: ^1.18.3 + viem: ^1.18.9 peerDependencies: "@polkadot/util": 11.x languageName: unknown @@ -7880,7 +7880,7 @@ __metadata: lodash: 4.17.21 ts-jest: ^28.0.2 typescript: ^5.2.2 - viem: ^1.18.3 + viem: ^1.18.9 languageName: unknown linkType: soft @@ -8122,7 +8122,7 @@ __metadata: lodash: 4.17.21 ts-jest: ^28.0.2 typescript: ^5.2.2 - viem: ^1.18.3 + viem: ^1.18.9 languageName: unknown linkType: soft @@ -15527,7 +15527,7 @@ __metadata: url: ^0.11.0 url-join: ^5.0.0 uuid: ^8.3.2 - viem: ^1.18.3 + viem: ^1.18.9 webextension-polyfill: 0.8.0 webpack: ^5.88.1 webpack-bundle-analyzer: ^4.9.0 @@ -27151,9 +27151,9 @@ __metadata: languageName: node linkType: hard -"viem@npm:^1.18.3": - version: 1.18.3 - resolution: "viem@npm:1.18.3" +"viem@npm:^1.18.9": + version: 1.18.9 + resolution: "viem@npm:1.18.9" dependencies: "@adraffy/ens-normalize": 1.9.4 "@noble/curves": 1.2.0 @@ -27168,7 +27168,7 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 263eb99ee46c586a743a37e15e3079546c5ee681d541b5d42db41eeae27638dbeabc6542ac620bdb5e3eaecae1ec3f2ad04cf4693f3f3105bed64a495ff925bd + checksum: 4bcd28a3bc2e0ff2f19a8de2c779dfdc0c7a479fe2c103a03cb4faa96450241075ddbc7e39bde4db9d8ad8e1dbc4d394223cdae00f8e135c2748ba354a2e2665 languageName: node linkType: hard