Skip to content

Commit f658dfb

Browse files
committed
Merge branch 'develop' into release/1.31.0
2 parents af0c8db + fff1ea1 commit f658dfb

File tree

5 files changed

+24
-41
lines changed

5 files changed

+24
-41
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"eth-lattice-keyring": "^0.2.7",
7676
"eth-provider": "^0.6.1",
7777
"eth-sig-util": "^3.0.1",
78+
"ethereumjs-tx": "^2.1.2",
7879
"ethereumjs-util": "^7.0.3",
7980
"fortmatic": "^2.2.1",
8081
"hdkey": "^2.0.1",

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export default {
6666
'walletlink',
6767
'regenerator-runtime/runtime',
6868
'trezor-connect',
69+
'ethereumjs-tx',
6970
'@ethereumjs/tx',
7071
'@ethereumjs/common',
7172
'ethereumjs-util',

src/@types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ declare module 'web3-provider-engine/subproviders/subscriptions'
88
declare module 'web3-provider-engine/subproviders/filters'
99
declare module 'trezor-connect'
1010
declare module 'eth-lattice-keyring'
11+
declare module 'ethereumjs-tx'
1112
declare module '@ethereumjs/tx'
1213
declare module '@ethereumjs/common'
1314
declare module 'ethereumjs-util'

src/modules/select/wallets/lattice.ts

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
1-
import {
2-
LatticeOptions,
3-
WalletModule,
4-
HardwareWalletCustomNetwork,
5-
Helpers
6-
} from '../../../interfaces'
1+
import { LatticeOptions, WalletModule, Helpers } from '../../../interfaces'
72
import latticeIcon from '../wallet-icons/icon-lattice'
83

94
function lattice(
105
options: LatticeOptions & { networkId: number }
116
): WalletModule {
12-
const {
13-
appName,
14-
rpcUrl,
15-
networkId,
16-
preferred,
17-
label,
18-
iconSrc,
19-
svg,
20-
customNetwork
21-
} = options
7+
const { appName, rpcUrl, networkId, preferred, label, iconSrc, svg } = options
228

239
return {
2410
name: label || 'Lattice',
@@ -33,7 +19,6 @@ function lattice(
3319
networkId,
3420
BigNumber,
3521
networkName,
36-
customNetwork,
3722
resetWalletState
3823
})
3924

@@ -72,21 +57,18 @@ async function latticeProvider(options: {
7257
rpcUrl: string
7358
BigNumber: any
7459
networkName: (id: number) => string
75-
customNetwork?: HardwareWalletCustomNetwork
7660
resetWalletState: (options?: {
7761
disconnected: boolean
7862
walletName: string
7963
}) => void
8064
}) {
8165
const { default: EthLatticeKeyring } = await import('eth-lattice-keyring')
82-
const { Transaction } = await import('@ethereumjs/tx')
83-
const { default: Common } = await import('@ethereumjs/common')
66+
const EthereumTx = await import('ethereumjs-tx')
8467
const { default: createProvider } = await import('./providerEngine')
8568

8669
const BASE_PATH = "m/44'/60'/0'/0"
8770

88-
const { networkId, appName, rpcUrl, BigNumber, networkName, customNetwork } =
89-
options
71+
const { networkId, appName, rpcUrl, BigNumber, networkName } = options
9072

9173
const params = {
9274
name: appName,
@@ -246,17 +228,10 @@ async function latticeProvider(options: {
246228
if (addressList.length === 0) {
247229
await enable()
248230
}
249-
const common = new Common({
250-
chain: customNetwork || networkName(networkId)
251-
})
252231

253-
const transaction = Transaction.fromTxData(
254-
{
255-
...transactionData,
256-
gasLimit: transactionData.gas ?? transactionData.gasLimit
257-
},
258-
{ common, freeze: false }
259-
)
232+
const transaction = new EthereumTx.Transaction(transactionData, {
233+
chain: networkName(networkId)
234+
})
260235

261236
try {
262237
const signedTx = await Lattice.signTransaction(

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)