Skip to content

Commit b98c900

Browse files
[fix] HD Wallet signing for L2s (#953)
* [fix] HD Wallet signing for L2s * Fix deps and use new getCommon method * Only catch chain not supported error
1 parent 9c2eca7 commit b98c900

File tree

25 files changed

+87
-3296
lines changed

25 files changed

+87
-3296
lines changed

packages/coinbase/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"typescript": "^4.5.5"
2121
},
2222
"dependencies": {
23-
"@web3-onboard/common": "^2.0.0",
23+
"@web3-onboard/common": "^2.0.7",
2424
"@coinbase/wallet-sdk": "^3.0.5"
2525
}
2626
}

packages/common/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/common",
3-
"version": "2.0.6",
3+
"version": "2.0.7",
44
"scripts": {
55
"build": "rollup -c",
66
"dev": "rollup -c -w",
@@ -41,6 +41,7 @@
4141
"typescript": "^4.5.5"
4242
},
4343
"dependencies": {
44+
"@ethereumjs/common": "2.6.2",
4445
"ethers": "5.5.4",
4546
"joi": "^17.4.2",
4647
"rxjs": "^7.5.2"

packages/common/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ export default {
3535
inlineSources: !production
3636
})
3737
],
38-
external: ['joi', 'rxjs', 'ethers']
38+
external: ['joi', 'rxjs', 'ethers', '@ethereumjs/common']
3939
}

packages/common/src/hdwallets.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type Common from '@ethereumjs/common'
2+
import type { CustomNetwork } from './types'
3+
4+
/**
5+
* Creates the common instance used for signing
6+
* transactions with hardware wallets
7+
* @returns the initialized common instance
8+
*/
9+
export const getCommon = async ({
10+
customNetwork,
11+
chainId
12+
}: {
13+
customNetwork?: CustomNetwork
14+
chainId: number
15+
}): Promise<Common> => {
16+
const { default: Common, Hardfork } = await import('@ethereumjs/common')
17+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
18+
// @ts-ignore
19+
const CommonConstructor: typeof Common = Common.default || Common
20+
let common: Common
21+
try {
22+
common = new CommonConstructor({
23+
chain: customNetwork || chainId,
24+
// Berlin is the minimum hardfork that will allow for EIP1559
25+
hardfork: Hardfork.Berlin,
26+
// List of supported EIPS
27+
eips: [1559]
28+
})
29+
} catch (e: any) {
30+
if (e.message && /Chain.*not supported/.test(e.message)) {
31+
common = CommonConstructor.custom({ chainId })
32+
} else {
33+
throw e
34+
}
35+
}
36+
return common
37+
}

packages/common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export { createEIP1193Provider } from './eip-1193'
6262
export { default as accountSelect } from './account-select'
6363
export { entryModal } from './entry-modal'
6464
export { SofiaProLight, SofiaProRegular, SofiaProSemiBold } from './fonts'
65+
export { getCommon } from './hdwallets'
6566

6667
export type {
6768
RequestPatch,

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"typescript": "^4.5.5"
4242
},
4343
"dependencies": {
44-
"@web3-onboard/common": "^2.0.6",
44+
"@web3-onboard/common": "^2.0.7",
4545
"bowser": "^2.11.0",
4646
"ethers": "5.5.3",
4747
"eventemitter3": "^4.0.7",

packages/fortmatic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"typescript": "^4.5.5"
2121
},
2222
"dependencies": {
23-
"@web3-onboard/common": "^2.0.3",
23+
"@web3-onboard/common": "^2.0.7",
2424
"fortmatic": "^2.2.1"
2525
}
2626
}

packages/gnosis/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"typescript": "^4.5.5"
2222
},
2323
"dependencies": {
24-
"@web3-onboard/common": "^2.0.0",
24+
"@web3-onboard/common": "^2.0.7",
2525
"@gnosis.pm/safe-apps-provider": "^0.9.2",
2626
"@gnosis.pm/safe-apps-sdk": "^6.1.1"
2727
}

packages/injected/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"window": "^4.2.7"
2626
},
2727
"dependencies": {
28-
"@web3-onboard/common": "^2.0.2",
28+
"@web3-onboard/common": "^2.0.7",
2929
"joi": "^17.4.2",
3030
"lodash.uniqby": "^4.7.0"
3131
}

packages/keepkey/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/keepkey",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "KeepKey module for web3-onboard",
55
"module": "dist/index.js",
66
"browser": "dist/index.js",
@@ -24,7 +24,7 @@
2424
"typescript": "^4.5.5"
2525
},
2626
"dependencies": {
27-
"@web3-onboard/common": "^2.0.0",
27+
"@web3-onboard/common": "^2.0.7",
2828
"@ethersproject/providers": "^5.5.0",
2929
"@shapeshiftoss/hdwallet-core": "^1.15.2",
3030
"@shapeshiftoss/hdwallet-keepkey-webusb": "^1.15.2",

packages/keystone/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/keystone",
3-
"version": "2.0.1",
3+
"version": "2.0.3",
44
"description": "Keystone module for web3-onboard",
55
"module": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -18,8 +18,7 @@
1818
"typescript": "^4.5.5"
1919
},
2020
"dependencies": {
21-
"@web3-onboard/common": "^2.0.0",
22-
"@ethereumjs/common": "^2.6.1",
21+
"@web3-onboard/common": "^2.0.7",
2322
"@ethereumjs/tx": "^3.4.0",
2423
"@ethersproject/providers": "^5.5.0",
2524
"@keystonehq/eth-keyring": "^0.11.2-alpha.2"

packages/keystone/src/index.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import {
1+
import type {
22
Account,
3-
accountSelect,
43
Chain,
5-
createEIP1193Provider,
64
CustomNetwork,
7-
ProviderRpcErrorCode,
8-
ProviderRpcError,
95
ScanAccountsOptions,
10-
WalletInit,
11-
EIP1193Provider
6+
WalletInit
127
} from '@web3-onboard/common'
138

149
import type { providers } from 'ethers'
@@ -83,7 +78,6 @@ function keystone({
8378
const { StaticJsonRpcProvider } = await import(
8479
'@ethersproject/providers'
8580
)
86-
const { default: Common, Hardfork } = await import('@ethereumjs/common')
8781

8882
const { default: AirGappedKeyring } = await import(
8983
'@keystonehq/eth-keyring'
@@ -93,6 +87,14 @@ function keystone({
9387
'@ethereumjs/tx'
9488
)
9589

90+
const {
91+
accountSelect,
92+
createEIP1193Provider,
93+
ProviderRpcError,
94+
ProviderRpcErrorCode,
95+
getCommon
96+
} = await import('@web3-onboard/common')
97+
9698
const keyring = AirGappedKeyring.getEmptyKeyring()
9799
await keyring.readKeyring()
98100

@@ -206,16 +208,10 @@ function keystone({
206208
// Set the `from` field to the currently selected account
207209
transactionObject = { ...transactionObject, from }
208210

209-
// @ts-ignore -- Due to weird commonjs exports
210-
const CommonConstructor = Common.default || Common
211-
212-
const common = new Common({
213-
chain: customNetwork || Number.parseInt(currentChain.id) || 1,
214-
// Berlin is the minimum hardfork that will allow for EIP1559
215-
hardfork: Hardfork.Berlin,
216-
// List of supported EIPS
217-
eips: [1559]
218-
})
211+
const chainId = currentChain.hasOwnProperty('id')
212+
? Number.parseInt(currentChain.id)
213+
: 1
214+
const common = await getCommon({ customNetwork, chainId })
219215

220216
transactionObject.gasLimit =
221217
transactionObject.gas || transactionObject.gasLimit

packages/ledger/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/ledger",
3-
"version": "2.0.1",
3+
"version": "2.0.3",
44
"description": "Ledger module for web3-onboard",
55
"module": "dist/index.js",
66
"browser": "dist/index.js",
@@ -21,8 +21,7 @@
2121
"typescript": "^4.5.5"
2222
},
2323
"dependencies": {
24-
"@web3-onboard/common": "^2.0.0",
25-
"@ethereumjs/common": "^2.6.1",
24+
"@web3-onboard/common": "^2.0.7",
2625
"@ethereumjs/tx": "^3.4.0",
2726
"@ethersproject/providers": "^5.5.0",
2827
"@ledgerhq/hw-app-eth": "^6.19.0",

packages/ledger/src/index.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,14 @@ function ledger({
119119
getIcon,
120120
getInterface: async ({ EventEmitter, chains }: GetInterfaceHelpers) => {
121121
const Eth = (await import('@ledgerhq/hw-app-eth')).default
122-
const { default: Common, Hardfork } = await import('@ethereumjs/common')
123122
const ethUtil = await import('ethereumjs-util')
124123

125124
const { SignTypedDataVersion } = await import('@metamask/eth-sig-util')
126125
const { StaticJsonRpcProvider } = await import(
127126
'@ethersproject/providers'
128127
)
129128

130-
const { accountSelect, createEIP1193Provider, ProviderRpcError } =
129+
const { accountSelect, createEIP1193Provider, ProviderRpcError, getCommon } =
131130
await import('@web3-onboard/common')
132131

133132
const { TransactionFactory: Transaction, Capability } = await import(
@@ -294,18 +293,10 @@ function ledger({
294293
// Set the `from` field to the currently selected account
295294
transactionObject = { ...transactionObject, from }
296295

297-
// @ts-ignore
298-
const CommonConstructor = Common.default || Common
299-
const common = new CommonConstructor({
300-
chain:
301-
customNetwork || currentChain.hasOwnProperty('id')
302-
? Number.parseInt(currentChain.id)
303-
: 1,
304-
// Berlin is the minimum hardfork that will allow for EIP1559
305-
hardfork: Hardfork.Berlin,
306-
// List of supported EIPS
307-
eips: [1559]
308-
})
296+
const chainId = currentChain.hasOwnProperty('id')
297+
? Number.parseInt(currentChain.id)
298+
: 1
299+
const common = await getCommon({ customNetwork, chainId })
309300

310301
transactionObject.gasLimit =
311302
transactionObject.gas || transactionObject.gasLimit

packages/magic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"typescript": "^4.5.5"
4343
},
4444
"dependencies": {
45-
"@web3-onboard/common": "^2.0.6",
45+
"@web3-onboard/common": "^2.0.7",
4646
"magic-sdk": "^8.1.0",
4747
"rxjs": "^7.5.2",
4848
"joi": "^17.4.2"

0 commit comments

Comments
 (0)