@ledgerhq/coin-evm 5.3.1 → 5.3.3
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 +3 -13
- package/CHANGELOG.md +13 -0
- package/lib/adapters/blockOperations.d.ts +2 -2
- package/lib/adapters/blockOperations.d.ts.map +1 -1
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/logic/combine.d.ts +2 -1
- package/lib/logic/combine.d.ts.map +1 -1
- package/lib/logic/combine.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.map +1 -1
- package/lib/logic/craftTransaction.d.ts +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransactionData.d.ts +1 -1
- package/lib/logic/craftTransactionData.d.ts.map +1 -1
- package/lib/logic/estimateFees.d.ts +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getStakes.d.ts +1 -1
- package/lib/logic/getStakes.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib/logic/validateIntent.d.ts +1 -1
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic.d.ts +1 -1
- package/lib/logic.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +4 -4
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/index.d.ts +2 -2
- package/lib/network/explorer/index.d.ts.map +1 -1
- package/lib/network/explorer/index.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts +2 -2
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/none.d.ts +1 -1
- package/lib/network/explorer/none.d.ts.map +1 -1
- package/lib/network/explorer/none.js.map +1 -1
- package/lib/network/explorer/types.d.ts +1 -1
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/gasTracker/index.d.ts +2 -2
- package/lib/network/gasTracker/index.d.ts.map +1 -1
- package/lib/network/gasTracker/index.js.map +1 -1
- package/lib/network/gasTracker/ledger.d.ts +3 -3
- package/lib/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib/network/gasTracker/ledger.js.map +1 -1
- package/lib/network/gasTracker/types.d.ts +2 -2
- package/lib/network/gasTracker/types.d.ts.map +1 -1
- package/lib/network/node/ledger.d.ts +2 -2
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +3 -3
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/staking/validators/monad.d.ts +2 -1
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js.map +1 -1
- package/lib/staking/validators/monadResolver.d.ts +2 -1
- package/lib/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib/staking/validators/monadResolver.js.map +1 -1
- package/lib/staking/validators/somnia.d.ts.map +1 -1
- package/lib/staking/validators/somnia.js.map +1 -1
- package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib/types/assets.d.ts +1 -1
- package/lib/types/assets.d.ts.map +1 -1
- package/lib/types/transaction.d.ts +1 -1
- package/lib/types/transaction.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.d.ts +2 -2
- package/lib-es/adapters/blockOperations.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/api/index.d.ts +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/config.d.ts +1 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/logic/combine.d.ts +2 -1
- package/lib-es/logic/combine.d.ts.map +1 -1
- package/lib-es/logic/combine.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 +1 -1
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransactionData.d.ts +1 -1
- package/lib-es/logic/craftTransactionData.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.d.ts +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getStakes.d.ts +1 -1
- package/lib-es/logic/getStakes.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts +1 -1
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic.d.ts +1 -1
- package/lib-es/logic.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +4 -4
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/index.d.ts +2 -2
- package/lib-es/network/explorer/index.d.ts.map +1 -1
- package/lib-es/network/explorer/index.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts +2 -2
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/none.d.ts +1 -1
- package/lib-es/network/explorer/none.d.ts.map +1 -1
- package/lib-es/network/explorer/none.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +1 -1
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/gasTracker/index.d.ts +2 -2
- package/lib-es/network/gasTracker/index.d.ts.map +1 -1
- package/lib-es/network/gasTracker/index.js.map +1 -1
- package/lib-es/network/gasTracker/ledger.d.ts +3 -3
- package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib-es/network/gasTracker/ledger.js +1 -1
- package/lib-es/network/gasTracker/ledger.js.map +1 -1
- package/lib-es/network/gasTracker/types.d.ts +2 -2
- package/lib-es/network/gasTracker/types.d.ts.map +1 -1
- package/lib-es/network/node/ledger.d.ts +2 -2
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +1 -1
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +3 -3
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.d.ts +2 -1
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js.map +1 -1
- package/lib-es/staking/validators/monadResolver.d.ts +2 -1
- package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib-es/staking/validators/monadResolver.js.map +1 -1
- package/lib-es/staking/validators/somnia.d.ts.map +1 -1
- package/lib-es/staking/validators/somnia.js.map +1 -1
- package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/types/assets.d.ts +1 -1
- package/lib-es/types/assets.d.ts.map +1 -1
- package/lib-es/types/transaction.d.ts +1 -1
- package/lib-es/types/transaction.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/adapters/blockOperations.test.ts +29 -31
- package/src/adapters/blockOperations.ts +3 -2
- package/src/adapters/etherscan.test.ts +7 -7
- package/src/adapters/ledger.test.ts +2 -2
- package/src/api/getBlock.integ.test.ts +1 -1
- package/src/api/index.fantom.integ.test.ts +1 -1
- package/src/api/index.flare.integ.test.ts +2 -14
- package/src/api/index.integ.test.ts +330 -246
- package/src/api/index.linea.integ.test.ts +1 -1
- package/src/api/index.optimism.integ.test.ts +1 -1
- package/src/api/index.shape.integ.test.ts +1 -1
- package/src/api/index.ts +1 -1
- package/src/config.ts +1 -1
- package/src/fixtures/context.fixtures.ts +79 -1
- package/src/fixtures/ethers.fixtures.ts +26 -0
- package/src/fixtures/ledger.fixtures.ts +1 -1
- package/src/internalTxSources.test.ts +3 -6
- package/src/logic/broadcast.integ.test.ts +6 -18
- package/src/logic/broadcast.test.ts +19 -31
- package/src/logic/broadcastSource.test.ts +6 -7
- package/src/logic/combine.test.ts +2 -2
- package/src/logic/combine.ts +2 -1
- package/src/logic/common.test.ts +120 -112
- package/src/logic/common.ts +2 -7
- package/src/logic/craftTransaction.test.ts +163 -200
- package/src/logic/craftTransaction.ts +3 -2
- package/src/logic/craftTransactionData.test.ts +6 -6
- package/src/logic/craftTransactionData.ts +1 -1
- package/src/logic/estimateFees.test.ts +19 -15
- package/src/logic/estimateFees.ts +6 -3
- package/src/logic/getBalance.test.ts +16 -15
- package/src/logic/getBalance.ts +4 -3
- package/src/logic/getBlock.test.ts +379 -388
- package/src/logic/getBlock.ts +3 -2
- package/src/logic/getBlockInfo.test.ts +7 -9
- package/src/logic/getNextSequence.test.ts +5 -5
- package/src/logic/getStakes.test.ts +35 -35
- package/src/logic/getStakes.ts +1 -1
- package/src/logic/internalTransactionsFetcher.test.ts +26 -24
- package/src/logic/internalTransactionsFetcher.ts +1 -1
- package/src/logic/lastBlock.test.ts +29 -20
- package/src/logic/listOperations.test.ts +44 -40
- package/src/logic/validateIntent.test.ts +152 -101
- package/src/logic/validateIntent.ts +4 -2
- package/src/logic.test.ts +13 -18
- package/src/logic.ts +1 -1
- package/src/network/explorer/etherscan.test.ts +6 -6
- package/src/network/explorer/etherscan.ts +12 -10
- package/src/network/explorer/index.test.ts +52 -22
- package/src/network/explorer/index.ts +2 -2
- package/src/network/explorer/ledger.test.ts +17 -5
- package/src/network/explorer/ledger.ts +3 -2
- package/src/network/explorer/none.ts +2 -1
- package/src/network/explorer/types.ts +1 -1
- package/src/network/gasTracker/index.test.ts +14 -8
- package/src/network/gasTracker/index.ts +2 -2
- package/src/network/gasTracker/ledger.test.ts +34 -29
- package/src/network/gasTracker/ledger.ts +5 -7
- package/src/network/gasTracker/types.ts +2 -2
- package/src/network/node/index.memoization.test.ts +25 -31
- package/src/network/node/index.test.ts +14 -25
- package/src/network/node/ledger.test.ts +45 -60
- package/src/network/node/ledger.ts +6 -5
- package/src/network/node/node.fixtures.ts +0 -2
- package/src/network/node/rpc.common.ts +14 -14
- package/src/network/node/rpc.test.ts +153 -184
- package/src/network/node/types.ts +3 -3
- package/src/staking/detectOperationType.test.ts +1 -1
- package/src/staking/encoder.test.ts +14 -22
- package/src/staking/logic.test.ts +20 -14
- package/src/staking/operations/index.test.ts +29 -29
- package/src/staking/prepareIntents.test.ts +26 -20
- package/src/staking/redelegations.test.ts +50 -33
- package/src/staking/rewards.test.ts +29 -17
- package/src/staking/rewardsFromReceipt.test.ts +20 -21
- package/src/staking/transactionData.test.ts +23 -23
- package/src/staking/validators/monad.test.ts +65 -24
- package/src/staking/validators/monad.ts +2 -1
- package/src/staking/validators/monadResolver.ts +2 -1
- package/src/staking/validators/somnia.test.ts +21 -13
- package/src/staking/validators/somnia.ts +2 -1
- package/src/staking/validators/zero_gravity.test.ts +118 -48
- package/src/staking/validators/zero_gravity.ts +2 -1
- package/src/staking/validators.integ.test.ts +13 -25
- package/src/staking/validators.test.ts +7 -2
- package/src/types/assets.ts +1 -1
- package/src/types/transaction.ts +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { EvmConfig } from '../config'
|
|
4
|
+
import type { EvmConfig } from '../config'
|
|
5
5
|
import { createMockEvmContext } from '../fixtures/context.fixtures'
|
|
6
6
|
import { createApi } from './index'
|
|
7
7
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { EvmConfigInfo } from '../config'
|
|
5
|
-
import { Operation } from '@ledgerhq/coin-module-framework/api/types'
|
|
5
|
+
import type { Operation } from '@ledgerhq/coin-module-framework/api/types'
|
|
6
6
|
import { createMockEvmContext } from '../fixtures/context.fixtures'
|
|
7
7
|
import { createApi } from './index'
|
|
8
8
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { EvmConfig } from '../config'
|
|
4
5
|
import { fail } from 'assert'
|
|
5
|
-
import { EvmConfig } from '../config'
|
|
6
6
|
import { createMockEvmContext } from '../fixtures/context.fixtures'
|
|
7
7
|
import { createApi } from './index'
|
|
8
8
|
|
package/src/api/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { EvmConfigInfo, EvmContext } from '../config'
|
|
4
5
|
import type { EvmCallParams } from '../network/node/types'
|
|
5
6
|
import type {
|
|
6
7
|
CoinModuleImpl,
|
|
@@ -22,7 +23,6 @@ import type {
|
|
|
22
23
|
Validator,
|
|
23
24
|
BalanceOptions,
|
|
24
25
|
} from '@ledgerhq/coin-module-framework/api/index'
|
|
25
|
-
import { type EvmConfigInfo, type EvmContext } from '../config'
|
|
26
26
|
import { craftTransactionData } from '../logic/craftTransactionData'
|
|
27
27
|
import {
|
|
28
28
|
broadcast,
|
package/src/config.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { InternalTxSourceList } from './internalTxSources'
|
|
5
|
-
import { Context, CurrencyConfig } from '@ledgerhq/coin-module-framework/config'
|
|
5
|
+
import type { Context, CurrencyConfig } from '@ledgerhq/coin-module-framework/config'
|
|
6
6
|
import { log } from '@ledgerhq/logs'
|
|
7
7
|
|
|
8
8
|
export type { InternalTxSource, InternalTxSourceList, NonEmptySource } from './internalTxSources'
|
|
@@ -1,10 +1,88 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
EvmCoinConfig,
|
|
6
|
+
EvmConfig,
|
|
7
|
+
EvmConfigInfo,
|
|
8
|
+
EvmContext,
|
|
9
|
+
ExternalNodeConfig,
|
|
10
|
+
LedgerNodeConfig,
|
|
11
|
+
} from '../config'
|
|
5
12
|
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
6
13
|
import { log } from '@ledgerhq/logs'
|
|
7
14
|
|
|
15
|
+
/** Returns an external (JSON-RPC) node config for use in tests. */
|
|
16
|
+
export const mkExternalNode = (partial?: {
|
|
17
|
+
uri?: string
|
|
18
|
+
retries?: number
|
|
19
|
+
}): ExternalNodeConfig => ({
|
|
20
|
+
type: 'external',
|
|
21
|
+
uri: partial?.uri ?? 'http://node.test',
|
|
22
|
+
...(typeof partial?.retries === 'number' && { retries: partial.retries }),
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
/** Returns a Ledger-hosted node config for use in tests. */
|
|
26
|
+
export const mkLedgerNode = (partial?: {
|
|
27
|
+
explorerId?: string
|
|
28
|
+
retries?: number
|
|
29
|
+
}): LedgerNodeConfig => ({
|
|
30
|
+
type: 'ledger',
|
|
31
|
+
explorerId: partial?.explorerId ?? 'test-explorer-id',
|
|
32
|
+
...(typeof partial?.retries === 'number' && { retries: partial.retries }),
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
/** Returns an Etherscan-compatible explorer config for use in tests. */
|
|
36
|
+
export const mkEtherscanExplorer = (partial?: {
|
|
37
|
+
uri?: string
|
|
38
|
+
noCache?: boolean
|
|
39
|
+
}): EvmConfig['explorer'] => ({
|
|
40
|
+
type: 'etherscan',
|
|
41
|
+
uri: partial?.uri ?? 'http://explorer.test',
|
|
42
|
+
...(typeof partial?.noCache === 'boolean' && { noCache: partial.noCache }),
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
/** Returns a Ledger explorer config for use in tests. */
|
|
46
|
+
export const mkLedgerExplorer = (partial?: { explorerId?: string }): EvmConfig['explorer'] => ({
|
|
47
|
+
type: 'ledger',
|
|
48
|
+
explorerId: partial?.explorerId ?? 'test-explorer-id',
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
/** Returns a Ledger gas tracker config for use in tests. */
|
|
52
|
+
export const mkLedgerGasTracker = (partial?: {
|
|
53
|
+
explorerId?: string
|
|
54
|
+
}): NonNullable<EvmConfig['gasTracker']> => ({
|
|
55
|
+
type: 'ledger',
|
|
56
|
+
explorerId: partial?.explorerId ?? 'test-explorer-id',
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Builds a complete {@link EvmConfigInfo} for tests.
|
|
61
|
+
*
|
|
62
|
+
* `chainId` and `node` are required — use {@link mkExternalNode} or {@link mkLedgerNode}
|
|
63
|
+
* to compose the node. All other fields are optional and default to `name: 'test'` and
|
|
64
|
+
* `explorer: { type: 'none' }`.
|
|
65
|
+
*/
|
|
66
|
+
export const createMockEvmConfigInfo = (
|
|
67
|
+
config: Pick<EvmConfigInfo, 'chainId' | 'node'> & Partial<Omit<EvmConfigInfo, 'chainId' | 'node'>>
|
|
68
|
+
): EvmConfigInfo => ({
|
|
69
|
+
status: { type: 'active' },
|
|
70
|
+
name: 'test',
|
|
71
|
+
explorer: { type: 'none' },
|
|
72
|
+
...config,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Builds an {@link EvmCoinConfig} for tests.
|
|
77
|
+
*
|
|
78
|
+
* Wraps {@link createMockEvmConfigInfo} in the `{ info }` shape expected by `setCoinConfig`.
|
|
79
|
+
*/
|
|
80
|
+
export const createMockEvmCoinConfig = (
|
|
81
|
+
config: Pick<EvmConfigInfo, 'chainId' | 'node'> & Partial<Omit<EvmConfigInfo, 'chainId' | 'node'>>
|
|
82
|
+
): EvmCoinConfig => ({
|
|
83
|
+
info: createMockEvmConfigInfo(config),
|
|
84
|
+
})
|
|
85
|
+
|
|
8
86
|
/**
|
|
9
87
|
* Builds a mock {@link EvmContext} for tests.
|
|
10
88
|
*
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Block, JsonRpcProvider, Result, TransactionReceipt, TransactionResponse } from 'ethers'
|
|
5
|
+
|
|
6
|
+
export const mkJsonRpcProvider = (): JsonRpcProvider => Object.create(JsonRpcProvider.prototype)
|
|
7
|
+
|
|
8
|
+
export const mkResult = (...items: unknown[]): Result => {
|
|
9
|
+
return Object.setPrototypeOf(items, Result.prototype)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const mkBlock = (partial: Partial<Block>): Block => {
|
|
13
|
+
const base = { transactions: undefined, prefetchedTransactions: undefined, ...partial }
|
|
14
|
+
return Object.create(Block.prototype, Object.getOwnPropertyDescriptors(base))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const mkTransactionResponse = (
|
|
18
|
+
partial: Partial<TransactionResponse>
|
|
19
|
+
): TransactionResponse => {
|
|
20
|
+
const tx: TransactionResponse = Object.create(TransactionResponse.prototype)
|
|
21
|
+
return Object.assign(tx, partial)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const mkTransactionReceipt = (partial: Partial<TransactionReceipt>): TransactionReceipt => {
|
|
25
|
+
return Object.create(TransactionReceipt.prototype, Object.getOwnPropertyDescriptors(partial))
|
|
26
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { LedgerExplorerOperation } from '../types'
|
|
4
|
+
import type { LedgerExplorerOperation } from '../types'
|
|
5
5
|
|
|
6
6
|
export const coinOperation1: LedgerExplorerOperation = {
|
|
7
7
|
hash: '0xf350d4f8e910419e2d5cec294d44e69af8c6185b7089061d33bb4fc246cefb79',
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
internalTxSourcesFromList,
|
|
7
|
-
type InternalTxSourceList,
|
|
8
|
-
} from './internalTxSources'
|
|
4
|
+
import type { InternalTxSourceList } from './internalTxSources'
|
|
5
|
+
import { DEFAULT_INTERNAL_TX_SOURCES, internalTxSourcesFromList } from './internalTxSources'
|
|
9
6
|
|
|
10
7
|
describe('internalTxSourcesFromList', () => {
|
|
11
8
|
it('builds the default explorer-first strategy', () => {
|
|
@@ -73,7 +70,7 @@ describe('internalTxSourcesFromList', () => {
|
|
|
73
70
|
const raw = ['explorer', 'empty'] as const
|
|
74
71
|
// @ts-expect-error - InternalTxSourceList is branded; only internalTxSourcesFromList can produce it
|
|
75
72
|
const sources: InternalTxSourceList = raw
|
|
76
|
-
|
|
73
|
+
expect(sources).toEqual(raw)
|
|
77
74
|
})
|
|
78
75
|
})
|
|
79
76
|
})
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { Wallet } from 'ethers'
|
|
5
5
|
import { createContext, setCoinConfig } from '../config'
|
|
6
|
+
import { createMockEvmCoinConfig, mkExternalNode, mkLedgerNode } from '../fixtures/context.fixtures'
|
|
6
7
|
import broadcast from './broadcast'
|
|
7
8
|
|
|
8
9
|
describe('Broadcast', () => {
|
|
@@ -10,25 +11,12 @@ describe('Broadcast', () => {
|
|
|
10
11
|
setCoinConfig((currency) => {
|
|
11
12
|
switch (currency) {
|
|
12
13
|
case 'ethereum':
|
|
13
|
-
return {
|
|
14
|
-
info: {
|
|
15
|
-
status: { type: 'active' },
|
|
16
|
-
node: {
|
|
17
|
-
type: 'ledger',
|
|
18
|
-
explorerId: 'eth',
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
} as any
|
|
14
|
+
return createMockEvmCoinConfig({ chainId: 1, node: mkLedgerNode({ explorerId: 'eth' }) })
|
|
22
15
|
case 'sonic':
|
|
23
|
-
return {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
type: 'external',
|
|
28
|
-
uri: 'https://sonic.coin.ledger.com',
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
} as any
|
|
16
|
+
return createMockEvmCoinConfig({
|
|
17
|
+
chainId: 146,
|
|
18
|
+
node: mkExternalNode({ uri: 'https://sonic.coin.ledger.com' }),
|
|
19
|
+
})
|
|
32
20
|
default:
|
|
33
21
|
throw new Error('Unhandled currency')
|
|
34
22
|
}
|
|
@@ -15,9 +15,6 @@ const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
|
15
15
|
|
|
16
16
|
describe('broadcastLogic', () => {
|
|
17
17
|
const nodeApiMock = mockNodeApi()
|
|
18
|
-
const mockCurrency = { id: 'ethereum' } as any
|
|
19
|
-
const mockSignature = '0xabcdef'
|
|
20
|
-
const mockBroadcastConfig = { mevProtection: true } as any
|
|
21
18
|
|
|
22
19
|
beforeEach(() => {
|
|
23
20
|
jest.clearAllMocks()
|
|
@@ -26,55 +23,46 @@ describe('broadcastLogic', () => {
|
|
|
26
23
|
|
|
27
24
|
it('should call getNodeApi and broadcastTransaction with correct arguments', async () => {
|
|
28
25
|
nodeApiMock.broadcastTransaction.mockResolvedValue('txid123')
|
|
29
|
-
const result = await broadcast(mockEvmContext,
|
|
30
|
-
signature:
|
|
31
|
-
broadcastConfig:
|
|
26
|
+
const result = await broadcast(mockEvmContext, 'ethereum', {
|
|
27
|
+
signature: '0xabcdef',
|
|
28
|
+
broadcastConfig: { mevProtected: true },
|
|
29
|
+
})
|
|
30
|
+
expect(mockGetNodeApi).toHaveBeenCalledWith(expect.anything(), 'ethereum')
|
|
31
|
+
expect(nodeApiMock.broadcastTransaction).toHaveBeenCalledWith('ethereum', '0xabcdef', {
|
|
32
|
+
mevProtected: true,
|
|
32
33
|
})
|
|
33
|
-
expect(mockGetNodeApi).toHaveBeenCalledWith(expect.anything(), mockCurrency)
|
|
34
|
-
expect(nodeApiMock.broadcastTransaction).toHaveBeenCalledWith(
|
|
35
|
-
mockCurrency,
|
|
36
|
-
mockSignature,
|
|
37
|
-
mockBroadcastConfig
|
|
38
|
-
)
|
|
39
34
|
expect(result).toBe('txid123')
|
|
40
35
|
})
|
|
41
36
|
|
|
42
37
|
it('should propagate errors from broadcastTransaction', async () => {
|
|
43
38
|
nodeApiMock.broadcastTransaction.mockRejectedValue(new Error('Broadcast failed'))
|
|
44
39
|
await expect(
|
|
45
|
-
broadcast(mockEvmContext,
|
|
46
|
-
signature:
|
|
47
|
-
broadcastConfig:
|
|
40
|
+
broadcast(mockEvmContext, 'ethereum', {
|
|
41
|
+
signature: '0xabcdef',
|
|
42
|
+
broadcastConfig: { mevProtected: true },
|
|
48
43
|
})
|
|
49
44
|
).rejects.toThrow('Broadcast failed')
|
|
50
45
|
})
|
|
51
46
|
|
|
52
47
|
it('should handle undefined broadcastConfig', async () => {
|
|
53
48
|
nodeApiMock.broadcastTransaction.mockResolvedValue('txid456')
|
|
54
|
-
const result = await broadcast(mockEvmContext,
|
|
55
|
-
signature:
|
|
49
|
+
const result = await broadcast(mockEvmContext, 'ethereum', {
|
|
50
|
+
signature: '0xabcdef',
|
|
56
51
|
broadcastConfig: undefined,
|
|
57
52
|
})
|
|
58
|
-
expect(nodeApiMock.broadcastTransaction).toHaveBeenCalledWith(
|
|
59
|
-
mockCurrency,
|
|
60
|
-
mockSignature,
|
|
61
|
-
undefined
|
|
62
|
-
)
|
|
53
|
+
expect(nodeApiMock.broadcastTransaction).toHaveBeenCalledWith('ethereum', '0xabcdef', undefined)
|
|
63
54
|
expect(result).toBe('txid456')
|
|
64
55
|
})
|
|
65
56
|
|
|
66
57
|
it('should handle different signature values', async () => {
|
|
67
58
|
nodeApiMock.broadcastTransaction.mockResolvedValue('txid789')
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
const result = await broadcast(mockEvmContext, 'ethereum', {
|
|
60
|
+
signature: '0x123456',
|
|
61
|
+
broadcastConfig: { mevProtected: true },
|
|
62
|
+
})
|
|
63
|
+
expect(nodeApiMock.broadcastTransaction).toHaveBeenCalledWith('ethereum', '0x123456', {
|
|
64
|
+
mevProtected: true,
|
|
72
65
|
})
|
|
73
|
-
expect(nodeApiMock.broadcastTransaction).toHaveBeenCalledWith(
|
|
74
|
-
mockCurrency,
|
|
75
|
-
anotherSignature,
|
|
76
|
-
mockBroadcastConfig
|
|
77
|
-
)
|
|
78
66
|
expect(result).toBe('txid789')
|
|
79
67
|
})
|
|
80
68
|
})
|
|
@@ -15,7 +15,6 @@ const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
|
15
15
|
|
|
16
16
|
describe('EVM broadcast with source', () => {
|
|
17
17
|
const nodeApiMock = mockNodeApi()
|
|
18
|
-
const mockCurrency = { id: 'ethereum' } as any
|
|
19
18
|
|
|
20
19
|
beforeEach(() => {
|
|
21
20
|
jest.clearAllMocks()
|
|
@@ -24,7 +23,7 @@ describe('EVM broadcast with source', () => {
|
|
|
24
23
|
})
|
|
25
24
|
|
|
26
25
|
it('should broadcast with source headers from broadcastConfig', async () => {
|
|
27
|
-
const result = await broadcast(mockEvmContext,
|
|
26
|
+
const result = await broadcast(mockEvmContext, 'ethereum', {
|
|
28
27
|
signature: '0xsignature',
|
|
29
28
|
broadcastConfig: {
|
|
30
29
|
mevProtected: true,
|
|
@@ -36,7 +35,7 @@ describe('EVM broadcast with source', () => {
|
|
|
36
35
|
})
|
|
37
36
|
|
|
38
37
|
expect(nodeApiMock.broadcastTransaction).toHaveBeenCalledWith(
|
|
39
|
-
|
|
38
|
+
'ethereum',
|
|
40
39
|
'0xsignature',
|
|
41
40
|
expect.objectContaining({
|
|
42
41
|
mevProtected: true,
|
|
@@ -50,7 +49,7 @@ describe('EVM broadcast with source', () => {
|
|
|
50
49
|
})
|
|
51
50
|
|
|
52
51
|
it('should broadcast swap transaction with swap source', async () => {
|
|
53
|
-
const result = await broadcast(mockEvmContext,
|
|
52
|
+
const result = await broadcast(mockEvmContext, 'ethereum', {
|
|
54
53
|
signature: '0xsignature',
|
|
55
54
|
broadcastConfig: {
|
|
56
55
|
mevProtected: false,
|
|
@@ -63,7 +62,7 @@ describe('EVM broadcast with source', () => {
|
|
|
63
62
|
})
|
|
64
63
|
|
|
65
64
|
expect(nodeApiMock.broadcastTransaction).toHaveBeenCalledWith(
|
|
66
|
-
|
|
65
|
+
'ethereum',
|
|
67
66
|
'0xsignature',
|
|
68
67
|
expect.objectContaining({
|
|
69
68
|
source: {
|
|
@@ -76,7 +75,7 @@ describe('EVM broadcast with source', () => {
|
|
|
76
75
|
})
|
|
77
76
|
|
|
78
77
|
it('should broadcast without source when not provided', async () => {
|
|
79
|
-
const result = await broadcast(mockEvmContext,
|
|
78
|
+
const result = await broadcast(mockEvmContext, 'ethereum', {
|
|
80
79
|
signature: '0xsignature',
|
|
81
80
|
broadcastConfig: {
|
|
82
81
|
mevProtected: false,
|
|
@@ -84,7 +83,7 @@ describe('EVM broadcast with source', () => {
|
|
|
84
83
|
})
|
|
85
84
|
|
|
86
85
|
expect(nodeApiMock.broadcastTransaction).toHaveBeenCalledWith(
|
|
87
|
-
|
|
86
|
+
'ethereum',
|
|
88
87
|
'0xsignature',
|
|
89
88
|
expect.objectContaining({
|
|
90
89
|
mevProtected: false,
|
|
@@ -136,7 +136,7 @@ describe('combine', () => {
|
|
|
136
136
|
const serializedUnsignedTx = ethers.Transaction.from(unsignedTx).unsignedSerialized
|
|
137
137
|
|
|
138
138
|
expect(() => {
|
|
139
|
-
combine(serializedUnsignedTx,
|
|
140
|
-
}).toThrow()
|
|
139
|
+
combine(serializedUnsignedTx, [])
|
|
140
|
+
}).toThrow('EVM combine expects exactly one signature')
|
|
141
141
|
})
|
|
142
142
|
})
|
package/src/logic/combine.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import type { SignatureLike } from 'ethers'
|
|
5
|
+
import { Signature, Transaction } from 'ethers'
|
|
5
6
|
|
|
6
7
|
function prefixHexString(hex: string): string {
|
|
7
8
|
return hex.startsWith('0x') ? hex : '0x' + hex
|