@exodus/ethereum-lib 4.2.6 → 4.3.0
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 +9 -7
- package/src/abi/index.js +3 -1
- package/src/account-state/parse-legacy-balances.js +7 -4
- package/src/account-state/staking-data.js +2 -0
- package/src/balances/ethereum-balance.js +10 -2
- package/src/constants.js +6 -6
- package/src/encode.js +2 -6
- package/src/fee-monitor/ethereum-like.js +1 -1
- package/src/index.js +4 -6
- package/src/key-identifier.js +31 -34
- package/src/selectors/get-can-accelerate-tx-factory.js +23 -17
- package/src/selectors/get-is-enough-balance-to-accelerate-factory.js +15 -13
- package/src/unsigned-tx/create-ethereumjs-tx.js +3 -3
- package/src/unsigned-tx/index.js +1 -1
- package/src/unsigned-tx/sign-hardware.js +17 -22
- package/src/unsigned-tx/sign-unsigned-tx.js +24 -4
- package/src/utils/calculate-extra-eth.js +2 -7
- package/src/utils/index.js +3 -2
- package/LICENSE.md +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-lib",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Ethereum Library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"lint:fix": "yarn lint --fix"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@exodus/asset-lib": "^
|
|
22
|
+
"@exodus/asset-lib": "^4.1.0",
|
|
23
23
|
"@exodus/aurora-meta": "^1.0.3",
|
|
24
24
|
"@exodus/avalanchec-meta": "^1.0.4",
|
|
25
25
|
"@exodus/basemainnet-meta": "^1.0.6",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@exodus/ethereumgoerli-meta": "^1.0.3",
|
|
35
35
|
"@exodus/ethereumholesky-meta": "^1.0.1",
|
|
36
36
|
"@exodus/ethereumjs-common": "^2.4.0-exodus.6",
|
|
37
|
-
"@exodus/ethereumjs-tx": "^3.3.0-exodus.
|
|
38
|
-
"@exodus/ethereumjs-util": "^7.1.0-exodus.
|
|
37
|
+
"@exodus/ethereumjs-tx": "^3.3.0-exodus.7",
|
|
38
|
+
"@exodus/ethereumjs-util": "^7.1.0-exodus.7",
|
|
39
39
|
"@exodus/fantommainnet-meta": "^1.0.5",
|
|
40
40
|
"@exodus/flare-meta": "^1.0.4",
|
|
41
41
|
"@exodus/harmonymainnet-meta": "^1.0.0",
|
|
@@ -53,8 +53,10 @@
|
|
|
53
53
|
"reselect": "~3.0.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@exodus/assets": "9.1.
|
|
57
|
-
"@exodus/
|
|
56
|
+
"@exodus/assets": "^9.1.1",
|
|
57
|
+
"@exodus/bitcoin-meta": "^1.0.2",
|
|
58
|
+
"@exodus/bnbmainnet-meta": "^1.0.0",
|
|
59
|
+
"@exodus/elliptic": "^6.5.4-precomputed"
|
|
58
60
|
},
|
|
59
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "b4bf49e4180ceb6fb437a2c7dd155829b00aa212"
|
|
60
62
|
}
|
package/src/abi/index.js
CHANGED
|
@@ -19,7 +19,7 @@ import ensRegistry from './ens-registry'
|
|
|
19
19
|
import ensResolver from './ens-resolver'
|
|
20
20
|
import optimismGasOracle from './optimism-gas-oracle'
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const index = {
|
|
23
23
|
ant,
|
|
24
24
|
cdai,
|
|
25
25
|
dai,
|
|
@@ -41,3 +41,5 @@ export default {
|
|
|
41
41
|
ensResolver,
|
|
42
42
|
optimismGasOracle,
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
export default index
|
|
@@ -6,18 +6,21 @@ function parseBalance({ asset, balance }) {
|
|
|
6
6
|
if (isNumberUnit(balance)) {
|
|
7
7
|
if (balance.unitType.equals(currency)) {
|
|
8
8
|
return balance
|
|
9
|
-
} else {
|
|
10
|
-
throw new Error(
|
|
11
|
-
`Balance '${balance.toDefaultString()}' is not of currency ${currency.toString()}`
|
|
12
|
-
)
|
|
13
9
|
}
|
|
10
|
+
|
|
11
|
+
throw new Error(
|
|
12
|
+
`Balance '${balance.toDefaultString()}' is not of currency ${currency.toString()}`
|
|
13
|
+
)
|
|
14
14
|
}
|
|
15
|
+
|
|
15
16
|
if (isString(balance)) {
|
|
16
17
|
return currency.parse(balance)
|
|
17
18
|
}
|
|
19
|
+
|
|
18
20
|
if (isNumber(balance)) {
|
|
19
21
|
return currency.defaultUnit(balance)
|
|
20
22
|
}
|
|
23
|
+
|
|
21
24
|
throw new Error(`Cannot parse balance '${balance}' of currency ${currency}`)
|
|
22
25
|
}
|
|
23
26
|
|
|
@@ -6,6 +6,8 @@ const ethStakeAccountState = ({ currency }) => ({
|
|
|
6
6
|
delegatedBalance: currency.ZERO,
|
|
7
7
|
rewardsBalance: currency.ZERO,
|
|
8
8
|
unclaimedUndelegatedBalance: currency.ZERO,
|
|
9
|
+
totalRewardsReceived: currency.ZERO,
|
|
10
|
+
lastStakingTxProcessed: '',
|
|
9
11
|
})
|
|
10
12
|
|
|
11
13
|
const assetStakingData = {
|
|
@@ -12,9 +12,17 @@ export const getEthereumBalances = ({ asset, liquidBalance, accountState }) => {
|
|
|
12
12
|
['staking', asset.name, 'unclaimedUndelegatedBalance'],
|
|
13
13
|
asset.currency.ZERO
|
|
14
14
|
)
|
|
15
|
-
const
|
|
15
|
+
const rewardsReceived = get(
|
|
16
|
+
accountState,
|
|
17
|
+
['staking', asset.name, 'totalRewardsReceived'],
|
|
18
|
+
asset.currency.ZERO
|
|
19
|
+
)
|
|
20
|
+
const totalBalance = liquidBalance
|
|
21
|
+
.add(delegatedBalance)
|
|
22
|
+
.add(undelegatedBalance)
|
|
23
|
+
.add(rewardsReceived)
|
|
16
24
|
return {
|
|
17
25
|
balance: totalBalance,
|
|
18
|
-
liquidBalance,
|
|
26
|
+
liquidBalance: liquidBalance.add(rewardsReceived),
|
|
19
27
|
}
|
|
20
28
|
}
|
package/src/constants.js
CHANGED
|
@@ -20,7 +20,7 @@ const CHAIN_DATA = {
|
|
|
20
20
|
tokenType: 'ETHEREUM_GOERLI_ERC20',
|
|
21
21
|
},
|
|
22
22
|
ethereumholesky: {
|
|
23
|
-
chainId:
|
|
23
|
+
chainId: 17_000,
|
|
24
24
|
serverUrl: 'https://geth-holesky-testnet-d.a.exodus.io/wallet/v1/',
|
|
25
25
|
confirmationsNumber: 30,
|
|
26
26
|
tokenType: 'ETHEREUM_HOLESKY_ERC20',
|
|
@@ -39,7 +39,7 @@ const CHAIN_DATA = {
|
|
|
39
39
|
tokenType: 'MATIC_ERC20',
|
|
40
40
|
},
|
|
41
41
|
avalanchec: {
|
|
42
|
-
chainId:
|
|
42
|
+
chainId: 43_114,
|
|
43
43
|
serverUrl: 'https://avax-c.a.exodus.io/wallet/v1/',
|
|
44
44
|
confirmationsNumber: 30,
|
|
45
45
|
tokenType: 'AVAX_ERC20',
|
|
@@ -51,20 +51,20 @@ const CHAIN_DATA = {
|
|
|
51
51
|
tokenType: 'FTM_ERC20',
|
|
52
52
|
},
|
|
53
53
|
harmonymainnet: {
|
|
54
|
-
chainId:
|
|
54
|
+
chainId: 1_666_600_000,
|
|
55
55
|
serverUrl: 'https://harmony.a.exodus.io/wallet/v1/',
|
|
56
56
|
confirmationsNumber: 6,
|
|
57
57
|
// tokenType: // we do not support tokens yet
|
|
58
58
|
},
|
|
59
59
|
ethereumarbnova: {
|
|
60
|
-
chainId:
|
|
60
|
+
chainId: 42_170,
|
|
61
61
|
serverUrl: 'https://arbitrum-nova-clarity.a.exodus.io',
|
|
62
62
|
confirmationsNumber: 3,
|
|
63
63
|
monitorType: 'clarity',
|
|
64
64
|
tokenType: 'ETHEREUM_ARBONE_ERC20',
|
|
65
65
|
},
|
|
66
66
|
ethereumarbone: {
|
|
67
|
-
chainId:
|
|
67
|
+
chainId: 42_161,
|
|
68
68
|
serverUrl: 'https://arbitrum-one-clarity.a.exodus.io',
|
|
69
69
|
confirmationsNumber: 3,
|
|
70
70
|
monitorType: 'clarity',
|
|
@@ -93,7 +93,7 @@ const CHAIN_DATA = {
|
|
|
93
93
|
tokenType: 'FLR_ERC20',
|
|
94
94
|
},
|
|
95
95
|
aurora: {
|
|
96
|
-
chainId:
|
|
96
|
+
chainId: 1_313_161_554,
|
|
97
97
|
serverUrl: 'https://aurora.a.exodus.io',
|
|
98
98
|
confirmationsNumber: 3,
|
|
99
99
|
monitorType: 'no-history',
|
package/src/encode.js
CHANGED
|
@@ -18,8 +18,7 @@ export function validate(address, { baseAssetName } = {}) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export function hasChecksum(address) {
|
|
21
|
-
|
|
22
|
-
return true
|
|
21
|
+
return !(/^0x[\dA-F]{40}$/.test(address) || /^0x[\da-f]{40}$/.test(address))
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
export function encodePrivate(privKey) {
|
|
@@ -40,10 +39,7 @@ export function encodePublic(compressedPubKey, { baseAssetName } = {}) {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
export function isValidPrivate(privateKey) {
|
|
43
|
-
|
|
44
|
-
return false
|
|
45
|
-
}
|
|
46
|
-
return true
|
|
42
|
+
return !(privateKey.length !== 32 || !etherUtil.isValidPrivate(privateKey))
|
|
47
43
|
}
|
|
48
44
|
|
|
49
45
|
export function encodePublicFromPrivate(privateKey, { baseAssetName } = {}) {
|
|
@@ -18,7 +18,7 @@ export default class EthereumLikeFeeMonitor extends FeeMonitor {
|
|
|
18
18
|
let gasPrice = parseInt(await this.getGasPrice(), 16)
|
|
19
19
|
|
|
20
20
|
if (!Number.isFinite(gasPrice)) {
|
|
21
|
-
throw new
|
|
21
|
+
throw new TypeError(`Invalid gas price: ${gasPrice}`)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
if (gasPrice < this.minGasPrice) {
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import createContract from './create-contract'
|
|
2
|
-
import ABI from './abi'
|
|
3
|
-
import * as feeData from './fee-data'
|
|
4
|
-
|
|
5
|
-
export { createContract, ABI, feeData }
|
|
6
|
-
|
|
7
1
|
export * from './balances'
|
|
8
2
|
export * from './encode'
|
|
9
3
|
export * from './unsigned-tx'
|
|
@@ -13,3 +7,7 @@ export * from './fee-monitor'
|
|
|
13
7
|
export * from './selectors'
|
|
14
8
|
export { default as createGetKeyIdentifier } from './key-identifier'
|
|
15
9
|
export { default as createEthereumLikeAccountState } from './account-state'
|
|
10
|
+
|
|
11
|
+
export { default as createContract } from './create-contract'
|
|
12
|
+
export * as feeData from './fee-data'
|
|
13
|
+
export { default as ABI } from './abi'
|
package/src/key-identifier.js
CHANGED
|
@@ -3,44 +3,41 @@ import { createGetKeyIdentifier, unhardenDerivationIndex } from '@exodus/key-uti
|
|
|
3
3
|
|
|
4
4
|
const HARDWARE_WALLETS = new Set(['ledger', 'trezor'])
|
|
5
5
|
|
|
6
|
-
const createEthereumGetKeyIdentifier =
|
|
7
|
-
bip44,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
const createEthereumGetKeyIdentifier =
|
|
7
|
+
({ bip44, assetName, keyType = 'secp256k1', allowMetaMaskCompat = false } = {}) =>
|
|
8
|
+
(partialParams = {}) => {
|
|
9
|
+
const params = {
|
|
10
|
+
purpose: 44,
|
|
11
|
+
chainIndex: 0,
|
|
12
|
+
accountIndex: 0,
|
|
13
|
+
addressIndex: 0,
|
|
14
|
+
...partialParams,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { accountIndex, addressIndex, compatibilityMode } = params
|
|
18
|
+
const isHardwareWallet = HARDWARE_WALLETS.has(compatibilityMode)
|
|
19
|
+
const unhardenedBip44 = unhardenDerivationIndex(bip44)
|
|
20
|
+
const isMetaMask = allowMetaMaskCompat && compatibilityMode === 'metamask'
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
if (isMetaMask) {
|
|
23
|
+
assert(addressIndex === 0, 'MetaMask compatibility does not support setting an addressIndex')
|
|
24
|
+
return {
|
|
25
|
+
assetName,
|
|
26
|
+
derivationAlgorithm: 'BIP32',
|
|
27
|
+
derivationPath: `m/44'/${unhardenedBip44}'/0'/0/${accountIndex}`,
|
|
28
|
+
keyType,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return {
|
|
32
|
+
return createGetKeyIdentifier({
|
|
33
|
+
bip44,
|
|
28
34
|
assetName,
|
|
29
|
-
derivationAlgorithm: 'BIP32',
|
|
30
|
-
derivationPath: `m/44'/${unhardenedBip44}'/0'/0/${accountIndex}`,
|
|
31
35
|
keyType,
|
|
32
|
-
|
|
36
|
+
validationRules: {
|
|
37
|
+
allowMultipleAddresses: true,
|
|
38
|
+
allowXPUB: isHardwareWallet,
|
|
39
|
+
},
|
|
40
|
+
})(params)
|
|
33
41
|
}
|
|
34
42
|
|
|
35
|
-
return createGetKeyIdentifier({
|
|
36
|
-
bip44,
|
|
37
|
-
assetName,
|
|
38
|
-
keyType,
|
|
39
|
-
validationRules: {
|
|
40
|
-
allowMultipleAddresses: true,
|
|
41
|
-
allowXPUB: isHardwareWallet,
|
|
42
|
-
},
|
|
43
|
-
})(params)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
43
|
export default createEthereumGetKeyIdentifier
|
|
@@ -51,6 +51,7 @@ function isQueuedPendingTx(tx, baseAssetName, activeWalletAccount, getTxLog) {
|
|
|
51
51
|
if (isQueuedPendingTx.minIndex >= 0 && txAtMinIndex && txAtMinIndex.pending) {
|
|
52
52
|
return tx.data && tx.data.nonce > txAtMinIndex.data.nonce
|
|
53
53
|
}
|
|
54
|
+
|
|
54
55
|
let minPendingNonce = Number.MAX_SAFE_INTEGER
|
|
55
56
|
for (let index = 0; index < txLog.size; index++) {
|
|
56
57
|
const _tx = txLog.getAt(index)
|
|
@@ -128,9 +129,11 @@ export const canAccelerateTx = ({
|
|
|
128
129
|
if (isQueuedPendingTx(tx, baseAssetName, activeWalletAccount, getTxLog))
|
|
129
130
|
return wrapResponseToObject({ errorMessage: 'there is a stuck TX with lower nonce' })
|
|
130
131
|
|
|
131
|
-
const {
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
const {
|
|
133
|
+
gasPrice: currentGasPrice,
|
|
134
|
+
gasPriceEconomicalRate,
|
|
135
|
+
eip1559Enabled,
|
|
136
|
+
} = getFeeData(assetName)
|
|
134
137
|
|
|
135
138
|
if (calculateTxGasPrice(tx).gte(currentGasPrice.mul(gasPriceEconomicalRate)))
|
|
136
139
|
return wrapResponseToObject({ errorMessage: 'the used gas price is still high enough' })
|
|
@@ -149,7 +152,7 @@ export const canAccelerateTx = ({
|
|
|
149
152
|
return wrapResponseToObject({ bumpType: BumpType.RBF })
|
|
150
153
|
}
|
|
151
154
|
|
|
152
|
-
|
|
155
|
+
const getCanAccelerateTxFactory = (
|
|
153
156
|
getFeeDataSelector,
|
|
154
157
|
getFeeSelector,
|
|
155
158
|
activeWalletAccountSelector,
|
|
@@ -180,17 +183,20 @@ export default (
|
|
|
180
183
|
getTxLog,
|
|
181
184
|
getIsExchangeTx,
|
|
182
185
|
assets
|
|
183
|
-
) =>
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
186
|
+
) =>
|
|
187
|
+
(tx) =>
|
|
188
|
+
canAccelerateTx({
|
|
189
|
+
tx,
|
|
190
|
+
assets,
|
|
191
|
+
getFeeData,
|
|
192
|
+
getFee,
|
|
193
|
+
activeWalletAccount,
|
|
194
|
+
getPersonalNoteByTxId,
|
|
195
|
+
getIsRbfEnabled,
|
|
196
|
+
getIsEnoughBalanceToAccelerate,
|
|
197
|
+
getTxLog,
|
|
198
|
+
getIsExchangeTx,
|
|
199
|
+
})
|
|
196
200
|
)
|
|
201
|
+
|
|
202
|
+
export default getCanAccelerateTxFactory
|
|
@@ -4,21 +4,23 @@ export const isEnoughBalanceToAccelerate = (totalBalance, unconfirmedBalance, ex
|
|
|
4
4
|
return totalBalance.sub(unconfirmedBalance).gte(extraEthNeeded)
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const getIsEnoughBalanceToAccelerateFactory = (
|
|
8
|
+
getWalletAccountBalancesSelector,
|
|
9
|
+
getUnconfirmedEthereumBalanceSelector
|
|
10
|
+
) =>
|
|
8
11
|
createSelector(
|
|
9
12
|
getWalletAccountBalancesSelector,
|
|
10
13
|
getUnconfirmedEthereumBalanceSelector,
|
|
11
|
-
(getWalletAccountBalances, getUnconfirmedEthereumBalance) =>
|
|
12
|
-
walletAccount,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
asset: assetName,
|
|
19
|
-
walletAccount,
|
|
20
|
-
})
|
|
14
|
+
(getWalletAccountBalances, getUnconfirmedEthereumBalance) =>
|
|
15
|
+
(walletAccount, assetName, extraEthNeeded) => {
|
|
16
|
+
const totalBalance = getWalletAccountBalances(walletAccount)[assetName]
|
|
17
|
+
const unconfirmedBalance = getUnconfirmedEthereumBalance({
|
|
18
|
+
asset: assetName,
|
|
19
|
+
walletAccount,
|
|
20
|
+
})
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
return isEnoughBalanceToAccelerate(totalBalance, unconfirmedBalance, extraEthNeeded)
|
|
23
|
+
}
|
|
24
24
|
)
|
|
25
|
+
|
|
26
|
+
export default getIsEnoughBalanceToAccelerateFactory
|
|
@@ -31,8 +31,8 @@ export default function createEthereumJsTx(unsignedTx) {
|
|
|
31
31
|
),
|
|
32
32
|
}
|
|
33
33
|
)
|
|
34
|
-
} else {
|
|
35
|
-
// Legacy tx
|
|
36
|
-
return Transaction.fromTxData(txData, { common: Common.custom({ chainId }) })
|
|
37
34
|
}
|
|
35
|
+
|
|
36
|
+
// Legacy tx
|
|
37
|
+
return Transaction.fromTxData(txData, { common: Common.custom({ chainId }) })
|
|
38
38
|
}
|
package/src/unsigned-tx/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default as createUnsignedTx } from './create-unsigned-tx'
|
|
2
2
|
export { default as parseUnsignedTx } from './parse-unsigned-tx'
|
|
3
|
-
export { default as signUnsignedTx } from './sign-unsigned-tx'
|
|
3
|
+
export { default as signUnsignedTx, signUnsignedTxWithSigner } from './sign-unsigned-tx'
|
|
4
4
|
export { default as createAndSignTx } from './create-and-sign-tx'
|
|
5
5
|
export { default as createEthereumJsTx } from './create-ethereumjs-tx'
|
|
6
6
|
export { signHardwareFactory } from './sign-hardware'
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert'
|
|
2
2
|
import createEthereumJsTx from './create-ethereumjs-tx'
|
|
3
3
|
|
|
4
|
-
export const signHardwareFactory =
|
|
5
|
-
|
|
6
|
-
hardwareDevice,
|
|
7
|
-
|
|
8
|
-
}) => {
|
|
9
|
-
const tx = createEthereumJsTx(unsignedTx)
|
|
4
|
+
export const signHardwareFactory =
|
|
5
|
+
({ baseAssetName }) =>
|
|
6
|
+
async ({ unsignedTx, hardwareDevice, accountIndex }) => {
|
|
7
|
+
const tx = createEthereumJsTx(unsignedTx)
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
const signedTx = await signWithHardwareWallet({
|
|
10
|
+
baseAssetName,
|
|
11
|
+
tx,
|
|
12
|
+
hardwareDevice,
|
|
13
|
+
accountIndex,
|
|
14
|
+
})
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
16
|
+
// serialize and get txId
|
|
17
|
+
const rawTx = signedTx.serialize()
|
|
18
|
+
const txId = signedTx.hash().toString('hex')
|
|
19
|
+
return { rawTx, txId }
|
|
20
|
+
}
|
|
23
21
|
|
|
24
22
|
async function signWithHardwareWallet({ baseAssetName, tx, hardwareDevice, accountIndex }) {
|
|
25
23
|
const rlpEncodedTx = tx.serialize()
|
|
@@ -41,13 +39,10 @@ async function signWithHardwareWallet({ baseAssetName, tx, hardwareDevice, accou
|
|
|
41
39
|
} else if (tx.common.chainId !== undefined) {
|
|
42
40
|
// _processSignature for legacy transactions expects 27 or 28.
|
|
43
41
|
// 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()
|
|
42
|
+
const diff = tx.common.chainIdBN().muln(2).addn(8).toNumber()
|
|
49
43
|
v -= diff
|
|
50
44
|
}
|
|
45
|
+
|
|
51
46
|
assert([27, 28].includes(v), `unexpected v-value, expected 27 or 28 but got ${v} `)
|
|
52
47
|
const r = signature.slice(V_SIZE, V_SIZE + 32)
|
|
53
48
|
const s = signature.slice(V_SIZE + 32, V_SIZE + 32 + 32)
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import createEthereumJsTx from './create-ethereumjs-tx'
|
|
2
2
|
|
|
3
|
+
function prepareRawTx(signedTx) {
|
|
4
|
+
// serialize and get txId
|
|
5
|
+
const rawTx = signedTx.serialize()
|
|
6
|
+
const txId = signedTx.hash().toString('hex')
|
|
7
|
+
return { rawTx, txId }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function signUnsignedTxWithSigner(unsignedTx, signer) {
|
|
11
|
+
const tx = createEthereumJsTx(unsignedTx)
|
|
12
|
+
|
|
13
|
+
const ethSigner = async (data) => {
|
|
14
|
+
const sig = await signer({ data, ecOptions: { canonical: true }, enc: 'raw' })
|
|
15
|
+
const signature = new Uint8Array(64)
|
|
16
|
+
signature.set(sig.r.toArrayLike(Uint8Array, 'be', 32), 0)
|
|
17
|
+
signature.set(sig.s.toArrayLike(Uint8Array, 'be', 32), 32)
|
|
18
|
+
return { signature, recid: sig.recoveryParam }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const signedTx = await tx.signWithSigner(ethSigner)
|
|
22
|
+
|
|
23
|
+
return prepareRawTx(signedTx)
|
|
24
|
+
}
|
|
25
|
+
|
|
3
26
|
export default function signUnsignedTx(unsignedTx, privateKey) {
|
|
4
27
|
const tx = createEthereumJsTx(unsignedTx)
|
|
5
28
|
|
|
6
29
|
const signedTx = tx.sign(privateKey)
|
|
7
30
|
|
|
8
|
-
|
|
9
|
-
const rawTx = signedTx.serialize()
|
|
10
|
-
const txId = signedTx.hash().toString('hex')
|
|
11
|
-
return { rawTx, txId }
|
|
31
|
+
return prepareRawTx(signedTx)
|
|
12
32
|
}
|
|
@@ -2,14 +2,9 @@ const defaultMultiplier = 1.1
|
|
|
2
2
|
|
|
3
3
|
// if a wallet has 0 ETH the deposit needed should be more than the fee needed by <multiplier>
|
|
4
4
|
// if a wallet has <N> ETH, the deposit needed should be the fee * <multiplier> - <N>
|
|
5
|
-
export default function({ fee, balance, multiplier = defaultMultiplier }) {
|
|
5
|
+
export default function ({ fee, balance, multiplier = defaultMultiplier }) {
|
|
6
6
|
if (typeof multiplier !== 'number' || multiplier < 1) multiplier = defaultMultiplier
|
|
7
7
|
if (balance.gt(fee)) return balance.unitType.ZERO
|
|
8
8
|
|
|
9
|
-
return fee
|
|
10
|
-
.mul(multiplier)
|
|
11
|
-
.toDefault()
|
|
12
|
-
.sub(balance)
|
|
13
|
-
.toFixed(4, 'ceil')
|
|
14
|
-
.toString()
|
|
9
|
+
return fee.mul(multiplier).sub(balance).toDefault().toFixed(4, 'ceil').toString()
|
|
15
10
|
}
|
package/src/utils/index.js
CHANGED
|
@@ -35,6 +35,7 @@ export const isEthereumLikeToken = (asset) => ETHEREUM_LIKE_TOKEN_TYPES.includes
|
|
|
35
35
|
export const isEthereumLikeTokenByName = (assetName) => {
|
|
36
36
|
throw new Error('Please use isEthereumLikeToken() instead')
|
|
37
37
|
}
|
|
38
|
+
|
|
38
39
|
export const isToken = isEthereumLikeToken
|
|
39
40
|
|
|
40
41
|
// All ethereum-like assets (native coins)
|
|
@@ -55,7 +56,7 @@ export function buffer2currency({ asset, value }) {
|
|
|
55
56
|
export function currency2buffer(value) {
|
|
56
57
|
const b10Value = value.toBaseString()
|
|
57
58
|
|
|
58
|
-
// Desktop: const hexValue = value.
|
|
59
|
+
// Desktop: const hexValue = new BN(value.toBaseString()).toString(16)
|
|
59
60
|
const hexValue = base16.encode(base10.decode(b10Value))
|
|
60
61
|
|
|
61
62
|
if (hexValue.includes('.')) {
|
|
@@ -68,7 +69,7 @@ export function currency2buffer(value) {
|
|
|
68
69
|
|
|
69
70
|
export function normalizeTxId(txId) {
|
|
70
71
|
if (txId.startsWith('0x')) return txId
|
|
71
|
-
|
|
72
|
+
return '0x' + txId
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
// @deprecated
|
package/LICENSE.md
DELETED
|
File without changes
|