@ledgerhq/coin-evm 5.4.1 → 8.0.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/.oxlintrc.json +1 -1
- package/CHANGELOG.md +234 -0
- package/docs/evm-family-integration-process/README.md +1 -1
- package/knip.json +2 -3
- package/lib/adapters/blockOperations.js +6 -6
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/adapters/etherscan.js +23 -23
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/adapters/ledger.js +17 -17
- package/lib/adapters/ledger.js.map +1 -1
- package/lib/api/index.js +4 -4
- package/lib/api/index.js.map +1 -1
- package/lib/config.d.ts +21 -16
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +5 -25
- package/lib/config.js.map +1 -1
- package/lib/errors.d.ts +9 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +15 -1
- package/lib/errors.js.map +1 -1
- package/lib/logic/broadcast.js +1 -1
- package/lib/logic/broadcast.js.map +1 -1
- package/lib/logic/common.d.ts +2 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js +4 -4
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +2 -2
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +9 -9
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js +50 -16
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +19 -11
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getBlockInfo.js +1 -1
- package/lib/logic/getBlockInfo.js.map +1 -1
- package/lib/logic/getNextSequence.d.ts.map +1 -1
- package/lib/logic/getNextSequence.js +1 -1
- package/lib/logic/getNextSequence.js.map +1 -1
- package/lib/logic/index.d.ts +2 -0
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +4 -0
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/lastBlock.js +1 -1
- package/lib/logic/lastBlock.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +10 -1
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js +12 -12
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic-public/index.d.ts +3 -0
- package/lib/logic-public/index.d.ts.map +1 -0
- package/lib/logic-public/index.js +19 -0
- package/lib/logic-public/index.js.map +1 -0
- package/lib/{utils.d.ts → logic-public/utils.d.ts} +0 -44
- package/lib/logic-public/utils.d.ts.map +1 -0
- package/lib/logic-public/utils.js +166 -0
- package/lib/logic-public/utils.js.map +1 -0
- package/lib/logic.d.ts +2 -1
- package/lib/logic.d.ts.map +1 -1
- package/lib/logic.js +3 -3
- package/lib/logic.js.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +16 -3
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js +61 -6
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts +50 -4
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js +286 -37
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/none.d.ts +1 -0
- package/lib/network/explorer/none.d.ts.map +1 -1
- package/lib/network/explorer/none.js +4 -1
- package/lib/network/explorer/none.js.map +1 -1
- package/lib/network/explorer/types.d.ts +15 -2
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/explorer/types.js.map +1 -1
- package/lib/network/index.d.ts +5 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +23 -0
- package/lib/network/index.js.map +1 -0
- package/lib/network/node/explorerProxy.d.ts +27 -0
- package/lib/network/node/explorerProxy.d.ts.map +1 -0
- package/lib/network/node/explorerProxy.js +262 -0
- package/lib/network/node/explorerProxy.js.map +1 -0
- package/lib/network/node/index.d.ts +2 -1
- package/lib/network/node/index.d.ts.map +1 -1
- package/lib/network/node/index.js +11 -10
- package/lib/network/node/index.js.map +1 -1
- package/lib/network/node/ledger.js +7 -7
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +2 -2
- package/lib/network/node/rpc.common.js +19 -19
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/withNodeSources.d.ts +21 -0
- package/lib/network/node/withNodeSources.d.ts.map +1 -0
- package/lib/network/node/withNodeSources.js +78 -0
- package/lib/network/node/withNodeSources.js.map +1 -0
- package/lib/nodeSources.d.ts +15 -0
- package/lib/nodeSources.d.ts.map +1 -0
- package/lib/nodeSources.js +33 -0
- package/lib/nodeSources.js.map +1 -0
- package/lib/staking/contracts.js +1 -1
- package/lib/staking/contracts.js.map +1 -1
- package/lib/staking/fetchers.js +1 -1
- package/lib/staking/fetchers.js.map +1 -1
- package/lib/staking/operations/sei.js +1 -1
- package/lib/staking/operations/sei.js.map +1 -1
- package/lib/staking/prepareIntents.js +3 -3
- package/lib/staking/prepareIntents.js.map +1 -1
- package/lib/staking/rewards.js +1 -1
- package/lib/staking/rewards.js.map +1 -1
- package/lib/staking/transactionData.js +2 -2
- package/lib/staking/transactionData.js.map +1 -1
- package/lib/staking/utils.d.ts +45 -0
- package/lib/staking/utils.d.ts.map +1 -0
- package/lib/{utils.js → staking/utils.js} +5 -164
- package/lib/staking/utils.js.map +1 -0
- package/lib/staking/validators/sei.js +1 -1
- package/lib/staking/validators/sei.js.map +1 -1
- package/lib/types/staking.d.ts +2 -2
- package/lib-es/adapters/blockOperations.js +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/adapters/etherscan.js +1 -1
- package/lib-es/adapters/etherscan.js.map +1 -1
- package/lib-es/adapters/ledger.js +1 -1
- package/lib-es/adapters/ledger.js.map +1 -1
- package/lib-es/api/index.js +2 -2
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/config.d.ts +21 -16
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +1 -21
- package/lib-es/config.js.map +1 -1
- package/lib-es/errors.d.ts +9 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +13 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/broadcast.js +1 -1
- package/lib-es/logic/broadcast.js.map +1 -1
- package/lib-es/logic/common.d.ts +2 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +3 -3
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +2 -2
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +6 -6
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js +50 -16
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +16 -8
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getBlockInfo.js +1 -1
- package/lib-es/logic/getBlockInfo.js.map +1 -1
- package/lib-es/logic/getNextSequence.d.ts.map +1 -1
- package/lib-es/logic/getNextSequence.js +1 -1
- package/lib-es/logic/getNextSequence.js.map +1 -1
- package/lib-es/logic/index.d.ts +2 -0
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +4 -0
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/lastBlock.js +1 -1
- package/lib-es/logic/lastBlock.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +10 -1
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js +4 -4
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic-public/index.d.ts +3 -0
- package/lib-es/logic-public/index.d.ts.map +1 -0
- package/lib-es/logic-public/index.js +4 -0
- package/lib-es/logic-public/index.js.map +1 -0
- package/lib-es/{utils.d.ts → logic-public/utils.d.ts} +0 -44
- package/lib-es/logic-public/utils.d.ts.map +1 -0
- package/lib-es/logic-public/utils.js +150 -0
- package/lib-es/logic-public/utils.js.map +1 -0
- package/lib-es/logic.d.ts +2 -1
- package/lib-es/logic.d.ts.map +1 -1
- package/lib-es/logic.js +3 -3
- package/lib-es/logic.js.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +16 -3
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js +60 -5
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts +50 -4
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js +283 -37
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/none.d.ts +1 -0
- package/lib-es/network/explorer/none.d.ts.map +1 -1
- package/lib-es/network/explorer/none.js +2 -0
- package/lib-es/network/explorer/none.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +15 -2
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/explorer/types.js.map +1 -1
- package/lib-es/network/index.d.ts +5 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +7 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/network/node/explorerProxy.d.ts +27 -0
- package/lib-es/network/node/explorerProxy.d.ts.map +1 -0
- package/lib-es/network/node/explorerProxy.js +254 -0
- package/lib-es/network/node/explorerProxy.js.map +1 -0
- package/lib-es/network/node/index.d.ts +2 -1
- package/lib-es/network/node/index.d.ts.map +1 -1
- package/lib-es/network/node/index.js +11 -10
- package/lib-es/network/node/index.js.map +1 -1
- package/lib-es/network/node/ledger.js +1 -1
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +2 -2
- package/lib-es/network/node/rpc.common.js +3 -3
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/withNodeSources.d.ts +21 -0
- package/lib-es/network/node/withNodeSources.d.ts.map +1 -0
- package/lib-es/network/node/withNodeSources.js +74 -0
- package/lib-es/network/node/withNodeSources.js.map +1 -0
- package/lib-es/nodeSources.d.ts +15 -0
- package/lib-es/nodeSources.d.ts.map +1 -0
- package/lib-es/nodeSources.js +28 -0
- package/lib-es/nodeSources.js.map +1 -0
- package/lib-es/staking/contracts.js +1 -1
- package/lib-es/staking/contracts.js.map +1 -1
- package/lib-es/staking/fetchers.js +1 -1
- package/lib-es/staking/fetchers.js.map +1 -1
- package/lib-es/staking/operations/sei.js +1 -1
- package/lib-es/staking/operations/sei.js.map +1 -1
- package/lib-es/staking/prepareIntents.js +1 -1
- package/lib-es/staking/prepareIntents.js.map +1 -1
- package/lib-es/staking/rewards.js +1 -1
- package/lib-es/staking/rewards.js.map +1 -1
- package/lib-es/staking/transactionData.js +1 -1
- package/lib-es/staking/transactionData.js.map +1 -1
- package/lib-es/staking/utils.d.ts +45 -0
- package/lib-es/staking/utils.d.ts.map +1 -0
- package/lib-es/{utils.js → staking/utils.js} +1 -147
- package/lib-es/staking/utils.js.map +1 -0
- package/lib-es/staking/validators/sei.js +1 -1
- package/lib-es/staking/validators/sei.js.map +1 -1
- package/lib-es/types/staking.d.ts +2 -2
- package/package.json +75 -9
- package/src/adapters/blockOperations.ts +1 -1
- package/src/adapters/etherscan.ts +1 -1
- package/src/adapters/ledger.ts +1 -1
- package/src/api/getBlock.integ.test.ts +10 -4
- package/src/api/index.arbitrum.integ.test.ts +1 -0
- package/src/api/index.arc.integ.test.ts +1 -0
- package/src/api/index.avalanche_c_chain_fuji.integ.test.ts +1 -0
- package/src/api/index.cronos.integ.test.ts +1 -0
- package/src/api/index.flare.integ.test.ts +4 -2
- package/src/api/index.linea.integ.test.ts +4 -2
- package/src/api/index.monad_testnet.integ.test.ts +95 -4
- package/src/api/index.optimism.integ.test.ts +1 -0
- package/src/api/index.rsk.integ.test.ts +1 -0
- package/src/api/index.shape.integ.test.ts +4 -2
- package/src/api/index.somnia.integ.test.ts +1 -0
- package/src/api/index.ts +2 -2
- package/src/config.ts +22 -35
- package/src/errors.ts +13 -0
- package/src/fixtures/context.fixtures.ts +9 -4
- package/src/logic/broadcast.ts +1 -1
- package/src/logic/common.ts +4 -2
- package/src/logic/craftTransaction.ts +2 -1
- package/src/logic/estimateFees.ts +20 -6
- package/src/logic/getBalance.ts +72 -26
- package/src/logic/getBlock.ts +26 -14
- package/src/logic/getBlockInfo.ts +1 -1
- package/src/logic/getNextSequence.ts +4 -1
- package/src/logic/index.ts +4 -0
- package/src/logic/lastBlock.ts +1 -1
- package/src/logic/listOperations.ts +14 -1
- package/src/logic/tests/broadcast.integ.test.ts +53 -0
- package/src/logic/{broadcast.test.ts → tests/broadcast.test.ts} +7 -7
- package/src/logic/{broadcastSource.test.ts → tests/broadcastSource.test.ts} +6 -6
- package/src/logic/{combine.test.ts → tests/combine.test.ts} +1 -1
- package/src/logic/{common.test.ts → tests/common.test.ts} +45 -21
- package/src/logic/{computeGasLimit.test.ts → tests/computeGasLimit.test.ts} +2 -2
- package/src/logic/{craftTransaction.test.ts → tests/craftTransaction.test.ts} +7 -7
- package/src/logic/{craftTransactionData.test.ts → tests/craftTransactionData.test.ts} +4 -4
- package/src/logic/{estimateFees.test.ts → tests/estimateFees.test.ts} +12 -12
- package/src/logic/tests/getBalance.test.ts +602 -0
- package/src/logic/{getBlock.test.ts → tests/getBlock.test.ts} +182 -89
- package/src/logic/{getBlockInfo.test.ts → tests/getBlockInfo.test.ts} +8 -8
- package/src/logic/{getErc20Data.test.ts → tests/getErc20Data.test.ts} +1 -1
- package/src/logic/{getNextSequence.test.ts → tests/getNextSequence.test.ts} +7 -7
- package/src/logic/{getStakes.test.ts → tests/getStakes.test.ts} +13 -13
- package/src/logic/{internalTransactionsFetcher.test.ts → tests/internalTransactionsFetcher.test.ts} +8 -8
- package/src/logic/{lastBlock.test.ts → tests/lastBlock.test.ts} +7 -7
- package/src/logic/{listOperations.test.ts → tests/listOperations.test.ts} +125 -6
- package/src/logic/{validateAddress.test.ts → tests/validateAddress.test.ts} +1 -1
- package/src/logic/{validateIntent.test.ts → tests/validateIntent.test.ts} +80 -78
- package/src/logic/validateIntent.ts +7 -4
- package/src/logic-public/index.ts +18 -0
- package/src/{utils.test.ts → logic-public/tests/utils.test.ts} +1 -27
- package/src/logic-public/utils.ts +184 -0
- package/src/logic.test.ts +5 -59
- package/src/logic.ts +5 -3
- package/src/network/explorer/etherscan.test.ts +403 -195
- package/src/network/explorer/etherscan.ts +99 -10
- package/src/network/explorer/index.test.ts +27 -0
- package/src/network/explorer/ledger.test.ts +792 -62
- package/src/network/explorer/ledger.ts +426 -54
- package/src/network/explorer/none.ts +3 -0
- package/src/network/explorer/types.ts +29 -5
- package/src/network/index.ts +7 -0
- package/src/network/node/explorerProxy.test.ts +673 -0
- package/src/network/node/explorerProxy.ts +308 -0
- package/src/network/node/index.memoization.test.ts +22 -10
- package/src/network/node/index.test.ts +6 -3
- package/src/network/node/index.ts +11 -7
- package/src/network/node/ledger.ts +1 -1
- package/src/network/node/node.fixtures.ts +2 -1
- package/src/network/node/rpc.common.ts +3 -3
- package/src/network/node/rpc.test.ts +66 -105
- package/src/network/node/withNodeSources.test.ts +240 -0
- package/src/network/node/withNodeSources.ts +95 -0
- package/src/nodeSources.ts +38 -0
- package/src/staking/contracts.ts +1 -1
- package/src/staking/encoder.test.ts +1 -1
- package/src/staking/fetchers.ts +1 -1
- package/src/staking/operations/sei.ts +1 -1
- package/src/staking/prepareIntents.ts +1 -1
- package/src/staking/redelegations.test.ts +3 -1
- package/src/staking/rewards.test.ts +1 -1
- package/src/staking/rewards.ts +1 -1
- package/src/staking/transactionData.ts +1 -1
- package/src/staking/unbondings.test.ts +2 -1
- package/src/staking/utils.test.ts +25 -0
- package/src/{utils.ts → staking/utils.ts} +2 -182
- package/src/staking/validators/sei.ts +1 -1
- package/src/staking/validators.test.ts +1 -0
- package/src/types/staking.ts +2 -2
- package/lib/constants.d.ts +0 -2
- package/lib/constants.d.ts.map +0 -1
- package/lib/constants.js +0 -11
- package/lib/constants.js.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
- package/lib-es/constants.d.ts +0 -2
- package/lib-es/constants.d.ts.map +0 -1
- package/lib-es/constants.js +0 -7
- package/lib-es/constants.js.map +0 -1
- package/lib-es/utils.d.ts.map +0 -1
- package/lib-es/utils.js.map +0 -1
- package/src/constants.ts +0 -9
- package/src/logic/broadcast.integ.test.ts +0 -46
- package/src/logic/getBalance.test.ts +0 -362
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
StakingTransactionIntent,
|
|
6
|
+
TransactionIntent,
|
|
7
|
+
} from '@ledgerhq/coin-module-framework/api/types'
|
|
8
|
+
import { log } from '@ledgerhq/logs'
|
|
9
|
+
import BigNumber from 'bignumber.js'
|
|
10
|
+
import eip55 from 'eip55'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Some addresses returned by the explorers are not 40 characters hex addresses
|
|
14
|
+
* For example the explorers may return "0x0" as an address (for example for
|
|
15
|
+
* some events or contract interactions, like a contract creation transaction)
|
|
16
|
+
*
|
|
17
|
+
* This is not a valid EIP55 address and thus will fail when trying to encode it
|
|
18
|
+
* with a "Bad address" error.
|
|
19
|
+
* cf:
|
|
20
|
+
* https://github.com/cryptocoinjs/eip55/blob/v2.1.1/index.js#L5-L6
|
|
21
|
+
* https://github.com/cryptocoinjs/eip55/blob/v2.1.1/index.js#L63-L65
|
|
22
|
+
*
|
|
23
|
+
* Since we can't control what the explorer returns, and we don't want the app to crash
|
|
24
|
+
* in these cases, we simply ignore the address and return an empty string.
|
|
25
|
+
*
|
|
26
|
+
* For now this has only been observed on the from or to fields of an operation
|
|
27
|
+
* so we only use this function for these fields.
|
|
28
|
+
*/
|
|
29
|
+
export const safeEncodeEIP55 = (addr: string): string => {
|
|
30
|
+
if (!addr || addr === '0x' || addr === '0x0') {
|
|
31
|
+
return ''
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
return eip55.encode(addr)
|
|
36
|
+
} catch (e) {
|
|
37
|
+
log('EVM Family - utils.ts', 'Failed to eip55 encode address', {
|
|
38
|
+
address: addr,
|
|
39
|
+
error: e,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
return addr
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Helper adding when necessary a 0
|
|
48
|
+
* prefix if string length is odd
|
|
49
|
+
*/
|
|
50
|
+
export const padHexString = (str: string): string => {
|
|
51
|
+
return str.length % 2 !== 0 ? '0' + str : str
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* arbitrary default value for a new transaction nonce
|
|
56
|
+
* the actual nonce will be set by `prepareForSignOperation`
|
|
57
|
+
*/
|
|
58
|
+
export const DEFAULT_NONCE = -1
|
|
59
|
+
|
|
60
|
+
export const DEFAULT_GAS_LIMIT = new BigNumber(21000)
|
|
61
|
+
|
|
62
|
+
export function isEthAddress(address: string): boolean {
|
|
63
|
+
return /^(0x)?[0-9a-fA-F]{40}$/.test(address)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* True when `value` is a 0x-prefixed, even-length hex string (the empty payload `"0x"` is valid).
|
|
68
|
+
* When `byteLength` is provided, also checks the payload is exactly that many bytes.
|
|
69
|
+
*
|
|
70
|
+
* Unlike {@link isEthAddress}, this requires the `0x` prefix, which is why it is used to validate
|
|
71
|
+
* untrusted `call` params rather than reusing the more lenient address matcher.
|
|
72
|
+
*/
|
|
73
|
+
export function isHexString(value: string, byteLength?: number): boolean {
|
|
74
|
+
if (!/^0x([0-9a-fA-F]{2})*$/.test(value)) {
|
|
75
|
+
return false
|
|
76
|
+
}
|
|
77
|
+
return byteLength === undefined || (value.length - 2) / 2 === byteLength
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Discriminant for smart contract call vs contract creation (deployment). */
|
|
81
|
+
export type ContractInteractionKind = 'SmartContractInteraction' | 'SmartContractDeployment'
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* True when `input` carries non-trivial calldata or init code (not empty / whitespace-only /
|
|
85
|
+
* bare hex prefix). Leading and trailing whitespace are ignored; `0x` / `0X` with no payload
|
|
86
|
+
* after trim are treated as empty.
|
|
87
|
+
*/
|
|
88
|
+
export function isSmartContractInput(input: string | null | undefined): input is string {
|
|
89
|
+
if (input === null || input === undefined) {
|
|
90
|
+
return false
|
|
91
|
+
}
|
|
92
|
+
const trimmed = input.trim()
|
|
93
|
+
if (trimmed === '') {
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
if (trimmed.length === 2 && trimmed.toLowerCase() === '0x') {
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
return true
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Builds flat `details` fields for coin-framework operation when a tx has smart contract input.
|
|
104
|
+
*
|
|
105
|
+
* `contractAddress` (when present) identifies the relevant contract: for
|
|
106
|
+
* `SmartContractInteraction` it is the called address (`to`); for
|
|
107
|
+
* `SmartContractDeployment` it is the created contract when
|
|
108
|
+
* `deployedContractAddress` is known (e.g. from a receipt), otherwise omitted.
|
|
109
|
+
*/
|
|
110
|
+
export function buildSmartContractDetails(
|
|
111
|
+
to: string | undefined,
|
|
112
|
+
input: string | undefined,
|
|
113
|
+
deployedContractAddress?: string | undefined
|
|
114
|
+
): Record<string, unknown> | undefined {
|
|
115
|
+
if (!isSmartContractInput(input)) {
|
|
116
|
+
return undefined
|
|
117
|
+
}
|
|
118
|
+
const trimmedInput = input.trim()
|
|
119
|
+
const encodedTo = to ? safeEncodeEIP55(to) : ''
|
|
120
|
+
const contractInteraction: ContractInteractionKind = encodedTo
|
|
121
|
+
? 'SmartContractInteraction'
|
|
122
|
+
: 'SmartContractDeployment'
|
|
123
|
+
const contractPayload = /^0x/i.test(trimmedInput)
|
|
124
|
+
? `0x${trimmedInput.slice(2)}`
|
|
125
|
+
: `0x${trimmedInput}`
|
|
126
|
+
const encodedDeployed = deployedContractAddress ? safeEncodeEIP55(deployedContractAddress) : ''
|
|
127
|
+
const contractAddress = encodedDeployed || encodedTo
|
|
128
|
+
return {
|
|
129
|
+
contractInteraction,
|
|
130
|
+
...(contractAddress ? { contractAddress } : {}),
|
|
131
|
+
contractPayload,
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Normalizes an Ethereum address to lowercase to avoid checksum validation issues.
|
|
137
|
+
*
|
|
138
|
+
* Some chains like RSK use EIP-1191 (chain-specific checksum) instead of EIP-55.
|
|
139
|
+
* When an address has a valid EIP-1191 checksum but not a valid EIP-55 checksum,
|
|
140
|
+
* ethers.js will throw "bad address checksum" error.
|
|
141
|
+
*
|
|
142
|
+
* Converting the address to lowercase bypasses checksum validation in ethers.js
|
|
143
|
+
* since lowercase addresses are treated as not checksummed.
|
|
144
|
+
*
|
|
145
|
+
* @see https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP60.md
|
|
146
|
+
*/
|
|
147
|
+
export function normalizeAddress(address: string): string {
|
|
148
|
+
return address.toLowerCase()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Safely converts a value to BigInt, returning 0n if conversion fails
|
|
153
|
+
*/
|
|
154
|
+
export const safeBigInt = (value: string | number | bigint): bigint => {
|
|
155
|
+
try {
|
|
156
|
+
return BigInt(value.toString())
|
|
157
|
+
} catch {
|
|
158
|
+
return 0n
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export const unwrapProxy = (proxy: unknown): unknown => {
|
|
163
|
+
if (proxy && typeof proxy === 'object' && proxy.constructor.name === 'Proxy') {
|
|
164
|
+
return Object.fromEntries(Object.entries(proxy).map(([k, v]) => [k, unwrapProxy(v)]))
|
|
165
|
+
}
|
|
166
|
+
if (Array.isArray(proxy)) return proxy.map(unwrapProxy)
|
|
167
|
+
return proxy
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Checks if a transaction intent is a staking intent
|
|
172
|
+
*/
|
|
173
|
+
// NOTE: `valId`/`withdrawId` should eventually be promoted to first-class properties of
|
|
174
|
+
// `StakingTransactionIntent` in @ledgerhq/coin-module-framework. Kept as local augmentations for now.
|
|
175
|
+
export type EvmStakingIntent = StakingTransactionIntent & {
|
|
176
|
+
valId?: string
|
|
177
|
+
withdrawId?: string
|
|
178
|
+
txValue?: bigint
|
|
179
|
+
shares?: bigint
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function isStakingIntent(intent: TransactionIntent): intent is EvmStakingIntent {
|
|
183
|
+
return intent.intentType === 'staking'
|
|
184
|
+
}
|
package/src/logic.test.ts
CHANGED
|
@@ -8,17 +8,11 @@ jest.mock('./network/node/index', () => ({
|
|
|
8
8
|
),
|
|
9
9
|
}))
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
createMockEvmCoinConfig,
|
|
14
|
-
createMockEvmConfigInfo,
|
|
15
|
-
mkExternalNode,
|
|
16
|
-
mkLedgerNode,
|
|
17
|
-
} from './fixtures/context.fixtures'
|
|
11
|
+
import { createMockEvmConfigInfo, mkExternalNode, testLogger } from './fixtures/context.fixtures'
|
|
18
12
|
import { getAdditionalLayer2Fees } from './logic'
|
|
13
|
+
import { padHexString, safeEncodeEIP55 } from './logic-public'
|
|
19
14
|
import { getNodeApi } from './network/node/index'
|
|
20
15
|
import { mockNodeApi } from './network/node/node.fixtures'
|
|
21
|
-
import { padHexString, safeEncodeEIP55 } from './utils'
|
|
22
16
|
|
|
23
17
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
24
18
|
const nodeApiMock = mockNodeApi()
|
|
@@ -27,54 +21,6 @@ const {
|
|
|
27
21
|
getScrollAdditionalFees: mockGetScrollAdditionalFees,
|
|
28
22
|
} = nodeApiMock
|
|
29
23
|
|
|
30
|
-
jest.mock('./config')
|
|
31
|
-
const mockGetConfig = jest.mocked(getCoinConfig)
|
|
32
|
-
|
|
33
|
-
mockGetConfig.mockImplementation((currencyId) => {
|
|
34
|
-
switch (currencyId) {
|
|
35
|
-
case 'ethereum':
|
|
36
|
-
return createMockEvmCoinConfig({
|
|
37
|
-
chainId: 1,
|
|
38
|
-
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
39
|
-
explorer: { type: 'ledger', explorerId: 'eth' },
|
|
40
|
-
})
|
|
41
|
-
case 'matic':
|
|
42
|
-
return createMockEvmCoinConfig({
|
|
43
|
-
chainId: 137,
|
|
44
|
-
node: mkLedgerNode({ explorerId: 'matic' }),
|
|
45
|
-
explorer: { type: 'ledger', explorerId: 'matic' },
|
|
46
|
-
})
|
|
47
|
-
case 'optimism':
|
|
48
|
-
return createMockEvmCoinConfig({ chainId: 10, node: mkExternalNode({ uri: 'optimism_uri' }) })
|
|
49
|
-
case 'scroll':
|
|
50
|
-
return createMockEvmCoinConfig({
|
|
51
|
-
chainId: 534352,
|
|
52
|
-
node: mkExternalNode({ uri: 'scroll_uri' }),
|
|
53
|
-
})
|
|
54
|
-
case 'polygon':
|
|
55
|
-
return createMockEvmCoinConfig({
|
|
56
|
-
chainId: 137,
|
|
57
|
-
node: mkLedgerNode({ explorerId: 'polygon' }),
|
|
58
|
-
})
|
|
59
|
-
case 'bsc':
|
|
60
|
-
return createMockEvmCoinConfig({ chainId: 56, node: mkLedgerNode({ explorerId: 'bsc' }) })
|
|
61
|
-
case 'anything':
|
|
62
|
-
return createMockEvmCoinConfig({
|
|
63
|
-
chainId: 1,
|
|
64
|
-
node: mkExternalNode({ uri: 'anything' }),
|
|
65
|
-
explorer: { type: 'etherscan', uri: 'anything' },
|
|
66
|
-
})
|
|
67
|
-
case 'somethingelse':
|
|
68
|
-
return createMockEvmCoinConfig({
|
|
69
|
-
chainId: 1,
|
|
70
|
-
node: mkLedgerNode({ explorerId: 'somethingelse' }),
|
|
71
|
-
explorer: { type: 'blockscout', uri: 'somethingelse' },
|
|
72
|
-
})
|
|
73
|
-
default:
|
|
74
|
-
throw new Error(`unexpected currencyId: ${currencyId}`)
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
|
|
78
24
|
describe('EVM Family', () => {
|
|
79
25
|
describe('logic.ts', () => {
|
|
80
26
|
describe('getAdditionalLayer2Fees', () => {
|
|
@@ -85,15 +31,15 @@ describe('EVM Family', () => {
|
|
|
85
31
|
|
|
86
32
|
it('should try to get additionalFees for a valid layer 2', async () => {
|
|
87
33
|
const cfg = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
88
|
-
await getAdditionalLayer2Fees(cfg, 'optimism', '')
|
|
34
|
+
await getAdditionalLayer2Fees(cfg, 'optimism', '', testLogger)
|
|
89
35
|
expect(mockGetOptimismAdditionalFees).toHaveBeenCalled()
|
|
90
|
-
await getAdditionalLayer2Fees(cfg, 'scroll', '')
|
|
36
|
+
await getAdditionalLayer2Fees(cfg, 'scroll', '', testLogger)
|
|
91
37
|
expect(mockGetScrollAdditionalFees).toHaveBeenCalled()
|
|
92
38
|
})
|
|
93
39
|
|
|
94
40
|
it('should not try to get additionalFees for an invalid layer 2', async () => {
|
|
95
41
|
const cfg = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
96
|
-
await getAdditionalLayer2Fees(cfg, 'ethereum', '')
|
|
42
|
+
await getAdditionalLayer2Fees(cfg, 'ethereum', '', testLogger)
|
|
97
43
|
expect(mockGetOptimismAdditionalFees).not.toHaveBeenCalled()
|
|
98
44
|
expect(mockGetScrollAdditionalFees).not.toHaveBeenCalled()
|
|
99
45
|
})
|
package/src/logic.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { EvmConfigInfo } from './config'
|
|
5
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
5
6
|
import type BigNumber from 'bignumber.js'
|
|
6
7
|
import { getNodeApi } from './network/node/index'
|
|
7
8
|
|
|
@@ -12,7 +13,8 @@ import { getNodeApi } from './network/node/index'
|
|
|
12
13
|
export const getAdditionalLayer2Fees = async (
|
|
13
14
|
config: EvmConfigInfo,
|
|
14
15
|
currencyId: string,
|
|
15
|
-
transaction: string
|
|
16
|
+
transaction: string,
|
|
17
|
+
logger: Logger
|
|
16
18
|
): Promise<BigNumber | undefined> => {
|
|
17
19
|
switch (currencyId) {
|
|
18
20
|
case 'optimism':
|
|
@@ -21,12 +23,12 @@ export const getAdditionalLayer2Fees = async (
|
|
|
21
23
|
case 'blast_sepolia':
|
|
22
24
|
case 'base':
|
|
23
25
|
case 'base_sepolia': {
|
|
24
|
-
const nodeApi = getNodeApi(config, currencyId)
|
|
26
|
+
const nodeApi = getNodeApi(config, currencyId, logger)
|
|
25
27
|
const additionalFees = await nodeApi.getOptimismAdditionalFees(currencyId, transaction)
|
|
26
28
|
return additionalFees
|
|
27
29
|
}
|
|
28
30
|
case 'scroll': {
|
|
29
|
-
const nodeApi = getNodeApi(config, currencyId)
|
|
31
|
+
const nodeApi = getNodeApi(config, currencyId, logger)
|
|
30
32
|
const additionalFees = await nodeApi.getScrollAdditionalFees(currencyId, transaction)
|
|
31
33
|
return additionalFees
|
|
32
34
|
}
|