Skip to content

Commit d1eb042

Browse files
1.29.0-0.5.10: Fix Trezor txn sign issue (#635)
1 parent 6dd022b commit d1eb042

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "1.29.0-0.5.9",
3+
"version": "1.29.0-0.5.10",
44
"description": "Onboard users to web3 by allowing them to select a wallet, get that wallet ready to transact and have access to synced wallet state.",
55
"keywords": [
66
"ethereum",

src/modules/select/wallets/trezor.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ async function trezorProvider(options: {
374374
if (addressToPath.size === 0) {
375375
await enable()
376376
}
377-
378377
const path = [...addressToPath.values()][0]
378+
const { BN, toBuffer } = ethUtil
379379
const common = new Common({
380380
chain: customNetwork || networkName(networkId)
381381
})
@@ -386,18 +386,23 @@ async function trezorProvider(options: {
386386
},
387387
{ common, freeze: false }
388388
)
389-
389+
transaction.v = new BN(toBuffer(networkId))
390+
transaction.r = transaction.s = new BN(toBuffer(0))
390391
const trezorResult = await trezorSignTransaction(path, transactionData)
391-
392392
if (!trezorResult.success) {
393393
throw new Error(trezorResult.payload.error)
394394
}
395-
396-
const signature = trezorResult.payload
397-
transaction.v = signature.v
398-
transaction.r = signature.r
399-
transaction.s = signature.s
400-
395+
let v = trezorResult.payload.v.toString(16)
396+
// EIP155 support. check/recalc signature v value.
397+
const rv = parseInt(v, 16)
398+
let cv = networkId * 2 + 35
399+
if (rv !== cv && (rv & cv) !== rv) {
400+
cv += 1 // add signature v bit.
401+
}
402+
v = cv.toString(16)
403+
transaction.v = new BN(toBuffer(`0x${v}`))
404+
transaction.r = new BN(toBuffer(`${trezorResult.payload.r}`))
405+
transaction.s = new BN(toBuffer(`${trezorResult.payload.s}`))
401406
return `0x${transaction.serialize().toString('hex')}`
402407
}
403408

0 commit comments

Comments
 (0)