@exodus/ethereum-lib 4.2.0 → 4.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-lib",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.2",
|
|
4
4
|
"description": "Ethereum Library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -40,8 +40,9 @@
|
|
|
40
40
|
"@exodus/solidity-contract": "^1.1.3",
|
|
41
41
|
"base-x": "^3.0.2",
|
|
42
42
|
"lodash": "^4.17.15",
|
|
43
|
+
"minimalistic-assert": "^1.0.1",
|
|
43
44
|
"ms": "^2.1.1",
|
|
44
45
|
"reselect": "~3.0.1"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "2ed589d85c4eff1a4b41d1d161c8dd0b1a0c3150"
|
|
47
48
|
}
|
|
@@ -1,47 +1,38 @@
|
|
|
1
|
-
/* @flow */
|
|
2
1
|
import { Transaction, FeeMarketEIP1559Transaction } from '@exodus/ethereumjs-tx'
|
|
3
|
-
import Common from '@exodus/ethereumjs-common'
|
|
2
|
+
import Common, { Hardfork } from '@exodus/ethereumjs-common'
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
import { CUSTOM_CHAINS } from '../constants'
|
|
7
|
-
|
|
8
|
-
export default function createEthereumJsTx(unsignedTx: UnsignedTransaction) {
|
|
4
|
+
export default function createEthereumJsTx(unsignedTx) {
|
|
9
5
|
const {
|
|
10
|
-
txData: {
|
|
6
|
+
txData: { chainId, ...txData },
|
|
11
7
|
txMeta: { eip1559Enabled },
|
|
12
8
|
} = unsignedTx
|
|
9
|
+
const { gasPrice, tipGasPrice } = txData
|
|
13
10
|
|
|
14
|
-
let tx
|
|
15
11
|
/*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
So we must prevent building accidentally an EIP1559 tx on bsc if tipGasPrice is set
|
|
20
|
-
`eip` will be set with s corresponding feature flag in the wallet
|
|
12
|
+
EIP1559 is not supported by all ethereum-like assets.
|
|
13
|
+
e.g BSC does not support EIP1559 at the moment, prevent building an EIP1559 transaction
|
|
14
|
+
if `tipGasPrice` or `maxPriorityFeePerGas` is set.
|
|
21
15
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
const isEip1559Tx = !!(unsignedTx.txData.tipGasPrice || unsignedTx.txData.maxPriorityFeePerGas)
|
|
17
|
+
if (eip1559Enabled && isEip1559Tx) {
|
|
18
|
+
return FeeMarketEIP1559Transaction.fromTxData(
|
|
24
19
|
{
|
|
25
20
|
maxFeePerGas: gasPrice,
|
|
26
|
-
maxPriorityFeePerGas,
|
|
27
|
-
|
|
21
|
+
maxPriorityFeePerGas: tipGasPrice,
|
|
22
|
+
// `maxPriorityFeePerGas`, `maxFeePerGas` set in `txData` below take precedence over ^.
|
|
28
23
|
...txData,
|
|
29
24
|
},
|
|
30
25
|
{
|
|
31
|
-
common:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
common: Common.custom(
|
|
27
|
+
{
|
|
28
|
+
chainId,
|
|
29
|
+
},
|
|
30
|
+
{ hardfork: Hardfork.London }
|
|
31
|
+
),
|
|
37
32
|
}
|
|
38
33
|
)
|
|
39
34
|
} else {
|
|
40
35
|
// Legacy tx
|
|
41
|
-
|
|
42
|
-
{ gasPrice, ...txData },
|
|
43
|
-
{ common: Common.custom({ chainId: chain }) }
|
|
44
|
-
)
|
|
36
|
+
return Transaction.fromTxData(txData, { common: Common.custom({ chainId }) })
|
|
45
37
|
}
|
|
46
|
-
return tx
|
|
47
38
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import assert from 'minimalistic-assert'
|
|
1
2
|
import createEthereumJsTx from './create-ethereumjs-tx'
|
|
2
3
|
|
|
3
4
|
export const signHardwareFactory = ({ baseAssetName }) => async ({
|
|
@@ -29,14 +30,27 @@ async function signWithHardwareWallet({ baseAssetName, tx, hardwareDevice, accou
|
|
|
29
30
|
})
|
|
30
31
|
|
|
31
32
|
const { signature } = signatures[0]
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
assert(signature.length >= 65, `signature length should be 65 or more`)
|
|
34
|
+
const V_SIZE = signature.length - 64
|
|
35
|
+
let v = Number.parseInt(signature.slice(0, V_SIZE).toString('hex'), '16')
|
|
34
36
|
if (v === 0 || v === 1) {
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
+
// _processSignature for EIP1559 expects 27 or 28.
|
|
38
|
+
// hardware wallets on the other hand already precomputed the final v (0, 1).
|
|
39
|
+
const diff = 27
|
|
40
|
+
v += diff
|
|
41
|
+
} else if (tx.common.chainId !== undefined) {
|
|
42
|
+
// _processSignature for legacy transactions expects 27 or 28.
|
|
43
|
+
// hardware wallets on the other hand already precomputed the final v (chainId * 2 + 35 + parity).
|
|
44
|
+
const diff = tx.common
|
|
45
|
+
.chainIdBN()
|
|
46
|
+
.muln(2)
|
|
47
|
+
.addn(8)
|
|
48
|
+
.toNumber()
|
|
49
|
+
v -= diff
|
|
37
50
|
}
|
|
38
|
-
|
|
39
|
-
const
|
|
51
|
+
assert([27, 28].includes(v), `unexpected v-value, expected 27 or 28 but got ${v} `)
|
|
52
|
+
const r = signature.slice(V_SIZE, V_SIZE + 32)
|
|
53
|
+
const s = signature.slice(V_SIZE + 32, V_SIZE + 32 + 32)
|
|
40
54
|
|
|
41
55
|
return tx._processSignature(v, r, s)
|
|
42
56
|
}
|