Skip to content

Commit

Permalink
fix: ledger signature crafting
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKheops committed Nov 8, 2023
1 parent b6d14fc commit c615a36
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 17 additions & 5 deletions apps/extension/src/ui/domains/Sign/SignLedgerEthereum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/balances-evm-erc20/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/balances-evm-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/chain-connector-evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -27168,7 +27168,7 @@ __metadata:
peerDependenciesMeta:
typescript:
optional: true
checksum: 263eb99ee46c586a743a37e15e3079546c5ee681d541b5d42db41eeae27638dbeabc6542ac620bdb5e3eaecae1ec3f2ad04cf4693f3f3105bed64a495ff925bd
checksum: 4bcd28a3bc2e0ff2f19a8de2c779dfdc0c7a479fe2c103a03cb4faa96450241075ddbc7e39bde4db9d8ad8e1dbc4d394223cdae00f8e135c2748ba354a2e2665
languageName: node
linkType: hard

Expand Down

0 comments on commit c615a36

Please sign in to comment.