@ledgerhq/coin-evm 8.0.0 → 9.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/CHANGELOG.md +19 -0
- package/docs/getBlock-internal-txs-schema.md +1 -1
- package/docs/network/node/index.md +3 -1
- package/lib/adapters/blockOperations.d.ts +4 -3
- package/lib/adapters/blockOperations.d.ts.map +1 -1
- package/lib/adapters/blockOperations.js +17 -17
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/adapters/etherscan.d.ts +7 -6
- package/lib/adapters/etherscan.d.ts.map +1 -1
- package/lib/adapters/etherscan.js +19 -19
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/adapters/ledger.d.ts +6 -5
- package/lib/adapters/ledger.d.ts.map +1 -1
- package/lib/adapters/ledger.js +15 -15
- package/lib/adapters/ledger.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +1 -2
- package/lib/api/index.js.map +1 -1
- package/lib/logic/common.js +1 -1
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js +3 -3
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +22 -23
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getStakes.d.ts.map +1 -1
- package/lib/logic/getStakes.js +2 -2
- package/lib/logic/getStakes.js.map +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts +3 -2
- package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js +13 -10
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib/logic/listOperations.js +1 -1
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic-public/utils.d.ts +3 -2
- package/lib/logic-public/utils.d.ts.map +1 -1
- package/lib/logic-public/utils.js +7 -6
- package/lib/logic-public/utils.js.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +3 -2
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js +13 -12
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js +11 -11
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/types.d.ts +2 -2
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/explorer/types.js.map +1 -1
- package/lib/network/node/explorerProxy.js +3 -3
- package/lib/network/node/explorerProxy.js.map +1 -1
- package/lib/network/node/index.d.ts.map +1 -1
- package/lib/network/node/index.js +2 -2
- package/lib/network/node/index.js.map +1 -1
- package/lib/network/node/ledger.d.ts +2 -1
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js +9 -10
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +3 -2
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +37 -29
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/staking/contracts.js +2 -2
- package/lib/staking/contracts.js.map +1 -1
- package/lib/staking/fetchers.d.ts.map +1 -1
- package/lib/staking/fetchers.js +7 -7
- package/lib/staking/fetchers.js.map +1 -1
- package/lib/staking/prepareIntents.d.ts +2 -1
- package/lib/staking/prepareIntents.d.ts.map +1 -1
- package/lib/staking/prepareIntents.js +4 -4
- package/lib/staking/prepareIntents.js.map +1 -1
- package/lib/staking/redelegations.d.ts +5 -4
- package/lib/staking/redelegations.d.ts.map +1 -1
- package/lib/staking/redelegations.js +13 -14
- package/lib/staking/redelegations.js.map +1 -1
- package/lib/staking/rewards.d.ts +2 -1
- package/lib/staking/rewards.d.ts.map +1 -1
- package/lib/staking/rewards.js +4 -5
- package/lib/staking/rewards.js.map +1 -1
- package/lib/staking/rewardsFromReceipt.d.ts +2 -1
- package/lib/staking/rewardsFromReceipt.d.ts.map +1 -1
- package/lib/staking/rewardsFromReceipt.js +2 -3
- package/lib/staking/rewardsFromReceipt.js.map +1 -1
- package/lib/staking/unbondings.d.ts +2 -1
- package/lib/staking/unbondings.d.ts.map +1 -1
- package/lib/staking/unbondings.js +4 -5
- package/lib/staking/unbondings.js.map +1 -1
- package/lib/staking/validators/index.d.ts +9 -4
- package/lib/staking/validators/index.d.ts.map +1 -1
- package/lib/staking/validators/index.js +19 -10
- package/lib/staking/validators/index.js.map +1 -1
- package/lib/staking/validators/monad.d.ts +6 -5
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js +33 -29
- 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 +2 -3
- package/lib/staking/validators/monadResolver.js.map +1 -1
- package/lib/staking/validators/somnia.d.ts +3 -2
- package/lib/staking/validators/somnia.d.ts.map +1 -1
- package/lib/staking/validators/somnia.js +16 -15
- package/lib/staking/validators/somnia.js.map +1 -1
- package/lib/staking/validators/types.d.ts +2 -1
- package/lib/staking/validators/types.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.d.ts +2 -1
- package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.js +7 -8
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib/types/staking.d.ts +4 -3
- package/lib/types/staking.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.d.ts +4 -3
- package/lib-es/adapters/blockOperations.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.js +17 -17
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/adapters/etherscan.d.ts +7 -6
- package/lib-es/adapters/etherscan.d.ts.map +1 -1
- package/lib-es/adapters/etherscan.js +19 -19
- package/lib-es/adapters/etherscan.js.map +1 -1
- package/lib-es/adapters/ledger.d.ts +6 -5
- package/lib-es/adapters/ledger.d.ts.map +1 -1
- package/lib-es/adapters/ledger.js +15 -15
- package/lib-es/adapters/ledger.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +1 -2
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/logic/common.js +1 -1
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js +3 -3
- 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 +22 -23
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getStakes.d.ts.map +1 -1
- package/lib-es/logic/getStakes.js +2 -2
- package/lib-es/logic/getStakes.js.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts +3 -2
- package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js +13 -10
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/logic/listOperations.js +1 -1
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic-public/utils.d.ts +3 -2
- package/lib-es/logic-public/utils.d.ts.map +1 -1
- package/lib-es/logic-public/utils.js +7 -6
- package/lib-es/logic-public/utils.js.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +3 -2
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js +13 -12
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js +11 -11
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +2 -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/node/explorerProxy.js +3 -3
- package/lib-es/network/node/explorerProxy.js.map +1 -1
- package/lib-es/network/node/index.d.ts.map +1 -1
- package/lib-es/network/node/index.js +2 -2
- package/lib-es/network/node/index.js.map +1 -1
- package/lib-es/network/node/ledger.d.ts +2 -1
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js +9 -10
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +3 -2
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +37 -29
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/staking/contracts.js +2 -2
- package/lib-es/staking/contracts.js.map +1 -1
- package/lib-es/staking/fetchers.d.ts.map +1 -1
- package/lib-es/staking/fetchers.js +7 -7
- package/lib-es/staking/fetchers.js.map +1 -1
- package/lib-es/staking/prepareIntents.d.ts +2 -1
- package/lib-es/staking/prepareIntents.d.ts.map +1 -1
- package/lib-es/staking/prepareIntents.js +4 -4
- package/lib-es/staking/prepareIntents.js.map +1 -1
- package/lib-es/staking/redelegations.d.ts +5 -4
- package/lib-es/staking/redelegations.d.ts.map +1 -1
- package/lib-es/staking/redelegations.js +13 -14
- package/lib-es/staking/redelegations.js.map +1 -1
- package/lib-es/staking/rewards.d.ts +2 -1
- package/lib-es/staking/rewards.d.ts.map +1 -1
- package/lib-es/staking/rewards.js +4 -5
- package/lib-es/staking/rewards.js.map +1 -1
- package/lib-es/staking/rewardsFromReceipt.d.ts +2 -1
- package/lib-es/staking/rewardsFromReceipt.d.ts.map +1 -1
- package/lib-es/staking/rewardsFromReceipt.js +2 -3
- package/lib-es/staking/rewardsFromReceipt.js.map +1 -1
- package/lib-es/staking/unbondings.d.ts +2 -1
- package/lib-es/staking/unbondings.d.ts.map +1 -1
- package/lib-es/staking/unbondings.js +4 -5
- package/lib-es/staking/unbondings.js.map +1 -1
- package/lib-es/staking/validators/index.d.ts +9 -4
- package/lib-es/staking/validators/index.d.ts.map +1 -1
- package/lib-es/staking/validators/index.js +18 -10
- package/lib-es/staking/validators/index.js.map +1 -1
- package/lib-es/staking/validators/monad.d.ts +6 -5
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js +33 -29
- 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 +2 -3
- package/lib-es/staking/validators/monadResolver.js.map +1 -1
- package/lib-es/staking/validators/somnia.d.ts +3 -2
- package/lib-es/staking/validators/somnia.d.ts.map +1 -1
- package/lib-es/staking/validators/somnia.js +16 -15
- package/lib-es/staking/validators/somnia.js.map +1 -1
- package/lib-es/staking/validators/types.d.ts +2 -1
- package/lib-es/staking/validators/types.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.d.ts +2 -1
- package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js +7 -8
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/types/staking.d.ts +4 -3
- package/lib-es/types/staking.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/adapters/blockOperations.test.ts +86 -67
- package/src/adapters/blockOperations.ts +28 -17
- package/src/adapters/etherscan.test.ts +151 -85
- package/src/adapters/etherscan.ts +27 -18
- package/src/adapters/ledger.test.ts +210 -83
- package/src/adapters/ledger.ts +21 -15
- package/src/api/index.integ.test.ts +7 -6
- package/src/api/index.test.ts +2 -2
- package/src/api/index.ts +1 -2
- package/src/logic/common.ts +1 -1
- package/src/logic/getBalance.ts +4 -3
- package/src/logic/getBlock.ts +43 -27
- package/src/logic/getStakes.ts +2 -1
- package/src/logic/internalTransactionsFetcher.ts +16 -10
- package/src/logic/listOperations.ts +2 -2
- package/src/logic/tests/getBalance.test.ts +5 -3
- package/src/logic/tests/getBlock.test.ts +16 -15
- package/src/logic/tests/internalTransactionsFetcher.test.ts +6 -5
- package/src/logic/tests/listOperations.test.ts +4 -4
- package/src/logic-public/tests/utils.test.ts +6 -5
- package/src/logic-public/utils.ts +8 -5
- package/src/logic.test.ts +5 -5
- package/src/network/explorer/etherscan.test.ts +169 -55
- package/src/network/explorer/etherscan.ts +27 -16
- package/src/network/explorer/index.test.ts +2 -1
- package/src/network/explorer/ledger.test.ts +207 -35
- package/src/network/explorer/ledger.ts +12 -8
- package/src/network/explorer/types.ts +3 -2
- package/src/network/node/explorerProxy.ts +3 -3
- package/src/network/node/index.ts +3 -2
- package/src/network/node/ledger.test.ts +25 -25
- package/src/network/node/ledger.ts +13 -10
- package/src/network/node/rpc.common.ts +84 -28
- package/src/network/node/rpc.test.ts +45 -31
- package/src/staking/contracts.ts +2 -2
- package/src/staking/fetchers.ts +20 -8
- package/src/staking/prepareIntents.test.ts +33 -12
- package/src/staking/prepareIntents.ts +9 -5
- package/src/staking/redelegations.test.ts +96 -35
- package/src/staking/redelegations.ts +20 -12
- package/src/staking/rewards.test.ts +15 -10
- package/src/staking/rewards.ts +8 -5
- package/src/staking/rewardsFromReceipt.test.ts +5 -4
- package/src/staking/rewardsFromReceipt.ts +4 -3
- package/src/staking/unbondings.test.ts +15 -12
- package/src/staking/unbondings.ts +7 -5
- package/src/staking/validators/index.ts +30 -10
- package/src/staking/validators/monad.test.ts +57 -43
- package/src/staking/validators/monad.ts +55 -32
- package/src/staking/validators/monadResolver.ts +4 -3
- package/src/staking/validators/somnia.test.ts +14 -13
- package/src/staking/validators/somnia.ts +35 -19
- package/src/staking/validators/types.ts +2 -0
- package/src/staking/validators/zero_gravity.test.ts +48 -26
- package/src/staking/validators/zero_gravity.ts +14 -8
- package/src/staking/validators.integ.test.ts +2 -2
- package/src/staking/validators.test.ts +30 -26
- package/src/types/staking.ts +9 -2
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
mkEtherscanExplorer,
|
|
11
11
|
mkExternalNode,
|
|
12
12
|
mkLedgerExplorer,
|
|
13
|
+
testLogger,
|
|
13
14
|
} from '../../fixtures/context.fixtures'
|
|
14
15
|
import { getInternalTransactionsByBlock } from '../../network/explorer/etherscan'
|
|
15
16
|
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
@@ -175,7 +176,7 @@ describe('makeSourceFetchers', () => {
|
|
|
175
176
|
explorer: mkLedgerExplorer(),
|
|
176
177
|
})
|
|
177
178
|
|
|
178
|
-
const fetchers = makeSourceFetchers(config, mockNodeApi(), '')
|
|
179
|
+
const fetchers = makeSourceFetchers(config, mockNodeApi(), '', testLogger)
|
|
179
180
|
await expect(fetchers.explorer(1)).rejects.toBeInstanceOf(SourceUnavailableError)
|
|
180
181
|
})
|
|
181
182
|
|
|
@@ -183,7 +184,7 @@ describe('makeSourceFetchers', () => {
|
|
|
183
184
|
const config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
184
185
|
|
|
185
186
|
const { traceBlockErigon: _traceBlockErigon, ...nodeApiWithoutErigon } = mockNodeApi()
|
|
186
|
-
const fetchers = makeSourceFetchers(config, nodeApiWithoutErigon, '')
|
|
187
|
+
const fetchers = makeSourceFetchers(config, nodeApiWithoutErigon, '', testLogger)
|
|
187
188
|
await expect(fetchers.trace_block(1)).rejects.toBeInstanceOf(SourceUnavailableError)
|
|
188
189
|
})
|
|
189
190
|
|
|
@@ -197,7 +198,7 @@ describe('makeSourceFetchers', () => {
|
|
|
197
198
|
const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
|
|
198
199
|
mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
|
|
199
200
|
|
|
200
|
-
const fetchers = makeSourceFetchers(config, mockNodeApi(), 'ethereum')
|
|
201
|
+
const fetchers = makeSourceFetchers(config, mockNodeApi(), 'ethereum', testLogger)
|
|
201
202
|
await expect(fetchers.explorer(99)).rejects.toBeInstanceOf(SourceUnavailableError)
|
|
202
203
|
})
|
|
203
204
|
|
|
@@ -211,7 +212,7 @@ describe('makeSourceFetchers', () => {
|
|
|
211
212
|
const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
|
|
212
213
|
mockGetInternalTransactionsByBlock.mockResolvedValueOnce([])
|
|
213
214
|
|
|
214
|
-
const fetchers = makeSourceFetchers(config, mockNodeApi(), 'ethereum')
|
|
215
|
+
const fetchers = makeSourceFetchers(config, mockNodeApi(), 'ethereum', testLogger)
|
|
215
216
|
await fetchers.explorer(99)
|
|
216
217
|
|
|
217
218
|
expect(mockGetInternalTransactionsByBlock).toHaveBeenCalledWith(config, 99)
|
|
@@ -220,7 +221,7 @@ describe('makeSourceFetchers', () => {
|
|
|
220
221
|
it('empty always resolves to an empty map', async () => {
|
|
221
222
|
const config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
222
223
|
|
|
223
|
-
const fetchers = makeSourceFetchers(config, mockNodeApi(), '')
|
|
224
|
+
const fetchers = makeSourceFetchers(config, mockNodeApi(), '', testLogger)
|
|
224
225
|
await expect(fetchers.empty(1)).resolves.toEqual(new Map<string, BlockOperation[]>())
|
|
225
226
|
})
|
|
226
227
|
})
|
|
@@ -567,6 +567,7 @@ describe('listOperations', () => {
|
|
|
567
567
|
calls: [
|
|
568
568
|
[
|
|
569
569
|
expect.anything(),
|
|
570
|
+
testContext.logger,
|
|
570
571
|
currency,
|
|
571
572
|
address,
|
|
572
573
|
minHeight,
|
|
@@ -575,7 +576,6 @@ describe('listOperations', () => {
|
|
|
575
576
|
// defaults to "desc" without limit
|
|
576
577
|
undefinedLimit,
|
|
577
578
|
'desc',
|
|
578
|
-
testContext.logger,
|
|
579
579
|
],
|
|
580
580
|
],
|
|
581
581
|
})
|
|
@@ -1208,9 +1208,9 @@ describe('listOperations', () => {
|
|
|
1208
1208
|
expect(result.length).toBeGreaterThan(1)
|
|
1209
1209
|
|
|
1210
1210
|
// check how the explorer is called
|
|
1211
|
-
const actualExplorerLimit = getOperationsSpy.mock.calls[0][
|
|
1211
|
+
const actualExplorerLimit = getOperationsSpy.mock.calls[0][7]
|
|
1212
1212
|
expect(actualExplorerLimit).toBe(limit)
|
|
1213
|
-
const actualExplorerOrder = getOperationsSpy.mock.calls[0][
|
|
1213
|
+
const actualExplorerOrder = getOperationsSpy.mock.calls[0][8]
|
|
1214
1214
|
expect(actualExplorerOrder).toBe(expectedExplorerOrder)
|
|
1215
1215
|
|
|
1216
1216
|
// check the result order
|
|
@@ -1562,7 +1562,7 @@ describe('listOperations', () => {
|
|
|
1562
1562
|
}
|
|
1563
1563
|
return jest
|
|
1564
1564
|
.spyOn(ledgerExplorer, 'getOperations')
|
|
1565
|
-
.mockImplementation(async (
|
|
1565
|
+
.mockImplementation(async (_config, _logger, _currencyId, queriedAddress) => {
|
|
1566
1566
|
const coinOps: Array<Operation<MemoNotSupported>> = (
|
|
1567
1567
|
response.lastCoinOperations ?? []
|
|
1568
1568
|
).map((op, i) => ({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { testLogger } from '../../fixtures/context.fixtures'
|
|
4
5
|
import { buildSmartContractDetails, isSmartContractInput, safeEncodeEIP55 } from '../utils'
|
|
5
6
|
|
|
6
7
|
describe('isSmartContractInput', () => {
|
|
@@ -30,7 +31,7 @@ describe('buildSmartContractDetails', () => {
|
|
|
30
31
|
] as const)(
|
|
31
32
|
'classifies sentinel to %s with calldata as deployment and omits contractAddress without deployed address',
|
|
32
33
|
(to, input) => {
|
|
33
|
-
expect(buildSmartContractDetails(to, input)).toEqual({
|
|
34
|
+
expect(buildSmartContractDetails(to, input, testLogger)).toEqual({
|
|
34
35
|
contractInteraction: 'SmartContractDeployment',
|
|
35
36
|
contractPayload: calldata,
|
|
36
37
|
})
|
|
@@ -39,22 +40,22 @@ describe('buildSmartContractDetails', () => {
|
|
|
39
40
|
|
|
40
41
|
it('sets contractAddress from deployed address when to is sentinel', () => {
|
|
41
42
|
const deployed = '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb'
|
|
42
|
-
expect(buildSmartContractDetails('0x', calldata, deployed)).toEqual({
|
|
43
|
+
expect(buildSmartContractDetails('0x', calldata, testLogger, deployed)).toEqual({
|
|
43
44
|
contractInteraction: 'SmartContractDeployment',
|
|
44
|
-
contractAddress: safeEncodeEIP55(deployed),
|
|
45
|
+
contractAddress: safeEncodeEIP55(deployed, testLogger),
|
|
45
46
|
contractPayload: calldata,
|
|
46
47
|
})
|
|
47
48
|
})
|
|
48
49
|
|
|
49
50
|
it('normalizes uppercase 0X hex prefix to a single 0x-prefixed payload', () => {
|
|
50
|
-
expect(buildSmartContractDetails(undefined, '0Xabcdef')).toEqual({
|
|
51
|
+
expect(buildSmartContractDetails(undefined, '0Xabcdef', testLogger)).toEqual({
|
|
51
52
|
contractInteraction: 'SmartContractDeployment',
|
|
52
53
|
contractPayload: '0xabcdef',
|
|
53
54
|
})
|
|
54
55
|
})
|
|
55
56
|
|
|
56
57
|
it('builds contractPayload from trim-aware input (matches isSmartContractInput)', () => {
|
|
57
|
-
expect(buildSmartContractDetails(undefined, ' 0xabcdef ')).toEqual({
|
|
58
|
+
expect(buildSmartContractDetails(undefined, ' 0xabcdef ', testLogger)).toEqual({
|
|
58
59
|
contractInteraction: 'SmartContractDeployment',
|
|
59
60
|
contractPayload: '0xabcdef',
|
|
60
61
|
})
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
StakingTransactionIntent,
|
|
6
6
|
TransactionIntent,
|
|
7
7
|
} from '@ledgerhq/coin-module-framework/api/types'
|
|
8
|
-
import {
|
|
8
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
9
9
|
import BigNumber from 'bignumber.js'
|
|
10
10
|
import eip55 from 'eip55'
|
|
11
11
|
|
|
@@ -26,7 +26,7 @@ import eip55 from 'eip55'
|
|
|
26
26
|
* For now this has only been observed on the from or to fields of an operation
|
|
27
27
|
* so we only use this function for these fields.
|
|
28
28
|
*/
|
|
29
|
-
export const safeEncodeEIP55 = (addr: string): string => {
|
|
29
|
+
export const safeEncodeEIP55 = (addr: string, logger: Logger): string => {
|
|
30
30
|
if (!addr || addr === '0x' || addr === '0x0') {
|
|
31
31
|
return ''
|
|
32
32
|
}
|
|
@@ -34,7 +34,7 @@ export const safeEncodeEIP55 = (addr: string): string => {
|
|
|
34
34
|
try {
|
|
35
35
|
return eip55.encode(addr)
|
|
36
36
|
} catch (e) {
|
|
37
|
-
|
|
37
|
+
logger('EVM Family - utils.ts', 'Failed to eip55 encode address', {
|
|
38
38
|
address: addr,
|
|
39
39
|
error: e,
|
|
40
40
|
})
|
|
@@ -110,20 +110,23 @@ export function isSmartContractInput(input: string | null | undefined): input is
|
|
|
110
110
|
export function buildSmartContractDetails(
|
|
111
111
|
to: string | undefined,
|
|
112
112
|
input: string | undefined,
|
|
113
|
+
logger: Logger,
|
|
113
114
|
deployedContractAddress?: string | undefined
|
|
114
115
|
): Record<string, unknown> | undefined {
|
|
115
116
|
if (!isSmartContractInput(input)) {
|
|
116
117
|
return undefined
|
|
117
118
|
}
|
|
118
119
|
const trimmedInput = input.trim()
|
|
119
|
-
const encodedTo = to ? safeEncodeEIP55(to) : ''
|
|
120
|
+
const encodedTo = to ? safeEncodeEIP55(to, logger) : ''
|
|
120
121
|
const contractInteraction: ContractInteractionKind = encodedTo
|
|
121
122
|
? 'SmartContractInteraction'
|
|
122
123
|
: 'SmartContractDeployment'
|
|
123
124
|
const contractPayload = /^0x/i.test(trimmedInput)
|
|
124
125
|
? `0x${trimmedInput.slice(2)}`
|
|
125
126
|
: `0x${trimmedInput}`
|
|
126
|
-
const encodedDeployed = deployedContractAddress
|
|
127
|
+
const encodedDeployed = deployedContractAddress
|
|
128
|
+
? safeEncodeEIP55(deployedContractAddress, logger)
|
|
129
|
+
: ''
|
|
127
130
|
const contractAddress = encodedDeployed || encodedTo
|
|
128
131
|
return {
|
|
129
132
|
contractInteraction,
|
package/src/logic.test.ts
CHANGED
|
@@ -55,31 +55,31 @@ describe('EVM Family', () => {
|
|
|
55
55
|
describe('safeEncodeEIP55', () => {
|
|
56
56
|
it('Should return encoded address if valid address', () => {
|
|
57
57
|
const address = '0x9aa99c23f67c81701c772b106b4f83f6e858dd2e'
|
|
58
|
-
const encodedAddress = safeEncodeEIP55(address)
|
|
58
|
+
const encodedAddress = safeEncodeEIP55(address, testLogger)
|
|
59
59
|
expect(encodedAddress).toBe('0x9AA99C23F67c81701C772B106b4F83f6e858dd2E')
|
|
60
60
|
})
|
|
61
61
|
|
|
62
62
|
it('Should return empty string if empty address', () => {
|
|
63
63
|
const address = ''
|
|
64
|
-
const encodedAddress = safeEncodeEIP55(address)
|
|
64
|
+
const encodedAddress = safeEncodeEIP55(address, testLogger)
|
|
65
65
|
expect(encodedAddress).toBe('')
|
|
66
66
|
})
|
|
67
67
|
|
|
68
68
|
it('Should return empty string if 0x0 address', () => {
|
|
69
69
|
const address = '0x0'
|
|
70
|
-
const encodedAddress = safeEncodeEIP55(address)
|
|
70
|
+
const encodedAddress = safeEncodeEIP55(address, testLogger)
|
|
71
71
|
expect(encodedAddress).toBe('')
|
|
72
72
|
})
|
|
73
73
|
|
|
74
74
|
it('Should return empty string if 0x address', () => {
|
|
75
75
|
const address = '0x'
|
|
76
|
-
const encodedAddress = safeEncodeEIP55(address)
|
|
76
|
+
const encodedAddress = safeEncodeEIP55(address, testLogger)
|
|
77
77
|
expect(encodedAddress).toBe('')
|
|
78
78
|
})
|
|
79
79
|
|
|
80
80
|
it('Should return address if invalid address', () => {
|
|
81
81
|
const address = '0x00000'
|
|
82
|
-
const encodedAddress = safeEncodeEIP55(address)
|
|
82
|
+
const encodedAddress = safeEncodeEIP55(address, testLogger)
|
|
83
83
|
expect(encodedAddress).toBe(address)
|
|
84
84
|
})
|
|
85
85
|
})
|