Skip to content

Commit b92fdd8

Browse files
authored
[trezor-v2.2.2-alpha.1] : Bug - Fix trezor signing issue by adding a new transaction type (#1246)
* Fix trezor issue by adding a new transaction type used by ethers in signing * Fix yarn command in PR template * Add empty fall back for value prop in transaction data * Yarn it
1 parent c0206f4 commit b92fdd8

File tree

5 files changed

+61
-33
lines changed

5 files changed

+61
-33
lines changed

packages/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@web3-onboard/portis": "^2.1.1",
3737
"@web3-onboard/sequence": "^2.0.0",
3838
"@web3-onboard/torus": "^2.1.1",
39-
"@web3-onboard/trezor": "^2.3.0-alpha.1",
39+
"@web3-onboard/trezor": "^2.3.0-alpha.2",
4040
"@web3-onboard/walletconnect": "^2.1.1",
4141
"@web3-onboard/web3auth": "^2.1.1",
4242
"vconsole": "^3.9.5"

packages/trezor/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/trezor",
3-
"version": "2.3.0-alpha.1",
3+
"version": "2.3.0-alpha.2",
44
"description": "Trezor hardware wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",
@@ -66,6 +66,6 @@
6666
"eth-crypto": "^2.1.0",
6767
"ethereumjs-util": "^7.1.3",
6868
"hdkey": "^2.0.1",
69-
"trezor-connect": "^8.2.6"
69+
"trezor-connect": "^8.2.11"
7070
}
7171
}

packages/trezor/src/index.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { Account, Asset, ScanAccountsOptions } from '@web3-onboard/hw-common'
22
import type { StaticJsonRpcProvider } from '@ethersproject/providers'
33
import type { TransactionRequest } from '@ethersproject/providers'
4+
import type {
5+
FeeMarketEIP1559TxData,
6+
TxData,
7+
FeeMarketEIP1559Transaction,
8+
Transaction
9+
} from '@ethereumjs/tx'
410

511
// cannot be dynamically imported
612
import { Buffer } from 'buffer'
@@ -132,7 +138,9 @@ function trezor(options: TrezorOptions): WalletInit {
132138
getIcon,
133139
getInterface: async ({ EventEmitter, chains }) => {
134140
const { default: Trezor } = await import('trezor-connect')
135-
const { Transaction } = await import('@ethereumjs/tx')
141+
const { Transaction, FeeMarketEIP1559Transaction } = await import(
142+
'@ethereumjs/tx'
143+
)
136144

137145
const { createEIP1193Provider, ProviderRpcError } = await import(
138146
'@web3-onboard/common'
@@ -293,7 +301,7 @@ function trezor(options: TrezorOptions): WalletInit {
293301
) {
294302
return {
295303
to: transactionData.to!,
296-
value: transactionData.value!,
304+
value: transactionData.value || '',
297305
gasLimit: gasLimit!,
298306
maxFeePerGas: transactionData.maxFeePerGas!,
299307
maxPriorityFeePerGas: transactionData.maxPriorityFeePerGas!,
@@ -306,7 +314,7 @@ function trezor(options: TrezorOptions): WalletInit {
306314
}
307315
return {
308316
to: transactionData.to!,
309-
value: transactionData.value!,
317+
value: transactionData.value || '',
310318
gasPrice: transactionData.gasPrice!,
311319
gasLimit: gasLimit!,
312320
nonce: transactionData.nonce!,
@@ -380,11 +388,11 @@ function trezor(options: TrezorOptions): WalletInit {
380388
const updateBigNumberFields =
381389
bigNumberFieldsToStrings(populatedTransaction)
382390

383-
// Set the `from` field to the currently selected account
384391
const transactionData = createTrezorTransactionObject(
385392
updateBigNumberFields as TransactionObject
386393
)
387394

395+
transactionData.from = address
388396
const chainId = currentChain.hasOwnProperty('id')
389397
? Number(currentChain.id)
390398
: 1
@@ -404,26 +412,27 @@ function trezor(options: TrezorOptions): WalletInit {
404412
throw new Error(message)
405413
}
406414

407-
const { r, s } = trezorResult.payload
408-
let v = trezorResult.payload.v
409-
410-
// EIP155 support. check/recalc signature v value.
411-
const rv = parseInt(v, 16)
412-
let cv = Number(currentChain.id) * 2 + 35
413-
if (rv !== cv && (rv & cv) !== rv) {
414-
cv += 1 // add signature v bit.
415+
let signedTx: FeeMarketEIP1559Transaction | Transaction
416+
if (
417+
transactionData!.maxFeePerGas ||
418+
transactionData!.maxPriorityFeePerGas
419+
) {
420+
signedTx = FeeMarketEIP1559Transaction.fromTxData(
421+
{
422+
...(transactionData as FeeMarketEIP1559TxData),
423+
...trezorResult.payload
424+
},
425+
{ common }
426+
)
427+
} else {
428+
signedTx = Transaction.fromTxData(
429+
{
430+
...(transactionData as TxData),
431+
...trezorResult.payload
432+
},
433+
{ common }
434+
)
415435
}
416-
v = cv.toString(16)
417-
418-
const signedTx = Transaction.fromTxData(
419-
{
420-
...populatedTransaction,
421-
v: `0x${v}`,
422-
r: r,
423-
s: s
424-
},
425-
{ common }
426-
)
427436
return signedTx ? `0x${signedTx.serialize().toString('hex')}` : ''
428437
}
429438

pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
- [ ] The version field in `package.json` is incremented following [semantic versioning](https://semver.org/)
66
- [ ] The box that allows repo maintainers to update this PR is checked
77
- [ ] I tested locally to make sure this feature/fix works
8-
- [ ] I have run `yarn type-check` & `yarn build` to confirm there are not any associated errors
8+
- [ ] I have run `yarn check` & `yarn build` to confirm there are not any associated errors
99
- [ ] This PR passes the Circle CI checks

yarn.lock

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,6 +2974,25 @@
29742974
dependencies:
29752975
"@walletconnect/window-getters" "^1.0.0"
29762976

2977+
"@web3-onboard/core@^2.8.1":
2978+
version "2.8.1"
2979+
resolved "https://registry.yarnpkg.com/@web3-onboard/core/-/core-2.8.1.tgz#559552f667850578e319a94ed98948d77da496f6"
2980+
integrity sha512-96wrXCYbXzjNC1r0r6fN2KMQddpSIrxunpTkhaO6IDiglEyX2+Im7OWktUxQDlwBce36gv6ahFwxL+dmAVXSkg==
2981+
dependencies:
2982+
"@web3-onboard/common" "^2.2.1"
2983+
bignumber.js "^9.0.0"
2984+
bnc-sdk "^4.4.1"
2985+
bowser "^2.11.0"
2986+
ethers "5.5.3"
2987+
eventemitter3 "^4.0.7"
2988+
joi "17.6.0"
2989+
lodash.merge "^4.6.2"
2990+
lodash.partition "^4.6.0"
2991+
nanoid "^4.0.0"
2992+
rxjs "^7.5.2"
2993+
svelte "^3.49.0"
2994+
svelte-i18n "^3.3.13"
2995+
29772996
"@web3auth/base-plugin@^1.0.1":
29782997
version "1.0.1"
29792998
resolved "https://registry.yarnpkg.com/@web3auth/base-plugin/-/base-plugin-1.0.1.tgz#1e2a87acf745299fdff6f92e6c46ee9bc38aa670"
@@ -4596,7 +4615,7 @@ cross-fetch@^2.1.0:
45964615
node-fetch "^2.6.7"
45974616
whatwg-fetch "^2.0.4"
45984617

4599-
cross-fetch@^3.1.4, cross-fetch@^3.1.5:
4618+
cross-fetch@^3.1.5:
46004619
version "3.1.5"
46014620
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
46024621
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
@@ -10275,13 +10294,13 @@ tr46@~0.0.3:
1027510294
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
1027610295
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=
1027710296

10278-
trezor-connect@^8.2.6:
10279-
version "8.2.6"
10280-
resolved "https://registry.yarnpkg.com/trezor-connect/-/trezor-connect-8.2.6.tgz#2731f9af2837116307672aeba747cf29c02b6229"
10281-
integrity sha512-ioa/NkwtFHY94VI95q4JPdoDU3HaQFFIqdS47751zHa5q8qVBzwf5vgUrNS+q3vJ2ZNE7mTk/r4FjURtDB1xjA==
10297+
trezor-connect@^8.2.11:
10298+
version "8.2.11"
10299+
resolved "https://registry.yarnpkg.com/trezor-connect/-/trezor-connect-8.2.11.tgz#6484a52f1e492748939f01a891ab9b2df28950c1"
10300+
integrity sha512-08yQrFJjZ/PjB4ZaHSnEwahG7cnc4FDndDxIen6kQ3hlpHmnu+J2V/ldUs5FOlZx22XDg5bhTKuIqytZrj9B0w==
1028210301
dependencies:
1028310302
"@babel/runtime" "^7.15.4"
10284-
cross-fetch "^3.1.4"
10303+
cross-fetch "^3.1.5"
1028510304
events "^3.3.0"
1028610305

1028710306
ts-custom-error@^3.2.0:

0 commit comments

Comments
 (0)