@exodus/ethereum-lib 5.24.1 → 5.24.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/CHANGELOG.md CHANGED
@@ -3,6 +3,30 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [5.24.3](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-lib@5.24.2...@exodus/ethereum-lib@5.24.3) (2026-06-11)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+
12
+ * fix: Ledger clear-signing for EVM token approvals (#8207)
13
+
14
+
15
+
16
+ ## [5.24.2](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-lib@5.24.1...@exodus/ethereum-lib@5.24.2) (2026-05-13)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+
22
+ * fix(ethereum-lib): avoid float precision loss in legacy unsigned-tx fee (#7918)
23
+
24
+ * fix(ethereum-lib): use .gte() instead of >= for currency comparison (#7961)
25
+
26
+ * fix: stale truncated balances after new transaction (#7897)
27
+
28
+
29
+
6
30
  ## [5.24.1](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-lib@5.24.0...@exodus/ethereum-lib@5.24.1) (2026-05-12)
7
31
 
8
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-lib",
3
- "version": "5.24.1",
3
+ "version": "5.24.3",
4
4
  "description": "Ethereum utils, such as for cryptography, address encoding/decoding, transaction building, etc.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -23,13 +23,13 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@exodus/basic-utils": "^3.0.1",
26
+ "@exodus/bytes": "^1.0.0-rc.5",
26
27
  "@exodus/crypto": "^1.0.0-rc.18",
27
28
  "@exodus/currency": "^6.0.1",
28
29
  "@exodus/ethereumjs": "^1.6.0",
29
30
  "@exodus/key-utils": "^3.7.0",
30
31
  "@exodus/models": "^13.0.0",
31
32
  "@exodus/solidity-contract": "^1.1.3",
32
- "base-x": "^3.0.2",
33
33
  "lodash": "^4.17.15",
34
34
  "minimalistic-assert": "^1.0.1",
35
35
  "ms": "^2.1.1",
@@ -51,5 +51,5 @@
51
51
  "type": "git",
52
52
  "url": "git+https://github.com/ExodusMovement/assets.git"
53
53
  },
54
- "gitHead": "7f184588091acba3b358e4af13783ee1e2bab4ba"
54
+ "gitHead": "f9bb7fcf58132b8daa6db82edc0bc53f380029cd"
55
55
  }
@@ -11,6 +11,7 @@ export default function createEthereumLikeAccountState({ asset, extraData = {},
11
11
  balance: asset.currency.ZERO,
12
12
  tokenBalances: {},
13
13
  nonce: 0,
14
+ truncatedAccountState: { balance: asset.currency.ZERO, tokenBalances: Object.create(null) },
14
15
  index: 0,
15
16
  isBlacklisted: null,
16
17
  eip7702Delegation: null,
@@ -222,7 +222,10 @@ const calculateBumpedGasPriceEip1559 = ({
222
222
  prevMaxFeePerGas,
223
223
  })
224
224
 
225
- assert(bumpedGasPrice >= currentBaseFeePerGas, 'bumpedGasPrice must be >= currentBaseFeePerGas')
225
+ assert(
226
+ bumpedGasPrice.gte(currentBaseFeePerGas),
227
+ 'bumpedGasPrice must be >= currentBaseFeePerGas'
228
+ )
226
229
 
227
230
  // Since `calculateBumpedGasPriceNonEip1559` will guarantee that
228
231
  // the returned `bumpedGasPrice` will be greater than the
@@ -36,7 +36,6 @@ export default function createUnsignedTxFactory({ chainId }) {
36
36
  eip1559Enabled,
37
37
  }) => {
38
38
  console.warn('createUnsignedTxFactory is deprecated, use createTxFactory instead')
39
- const baseAsset = asset.baseAsset
40
39
  assert(chainId, 'chainId is required')
41
40
 
42
41
  txValue = assertValidTxValue({ asset, amount, txValue })
@@ -49,11 +48,7 @@ export default function createUnsignedTxFactory({ chainId }) {
49
48
 
50
49
  const _isToken = isToken(asset)
51
50
  const to = _isToken ? asset.contract.address : address
52
- let value = currency2buffer(txValue)
53
-
54
- // TODO: check: present on desktop missing on mobile. This insures we never have a buffer specifying 0.
55
- // In ETH, a buffer of zero length and a buffer specifying 0 imply different things
56
- if (value.equals(Buffer.from([0]))) value = Buffer.alloc(0)
51
+ const value = currency2buffer(txValue)
57
52
 
58
53
  assert(fromAddress, 'createTx: fromAddress is requied')
59
54
 
@@ -70,7 +65,9 @@ export default function createUnsignedTxFactory({ chainId }) {
70
65
 
71
66
  const txMeta = {
72
67
  assetName: asset.name,
73
- fee: baseAsset.currency.baseUnit(gasPrice.toBaseNumber() * gasLimit),
68
+ // Use NumberUnit#mul (BN-backed) to avoid float-precision loss when
69
+ // gasPrice (in wei) * gasLimit exceeds Number.MAX_SAFE_INTEGER (~9e15).
70
+ fee: gasPrice.mul(gasLimit),
74
71
  eip1559Enabled: !!eip1559Enabled,
75
72
  fromAddress,
76
73
  }
@@ -2,16 +2,31 @@ import assert from 'minimalistic-assert'
2
2
 
3
3
  import createEthereumJsTx from './create-ethereumjs-tx.js'
4
4
 
5
+ // Resolves the Ledger `isNft` clear-signing hint for the contract this tx calls.
6
+ // Delegates the on-chain ERC-165 classification to the injected `getIsNft`; stays
7
+ // undefined when there's no contract method call to classify. The hint only drives
8
+ // the device's display resolution and never affects the signed bytes.
9
+ const resolveIsNft = async ({ tx, getIsNft }) => {
10
+ // Only txs with a target and calldata can be token/NFT operations; a plain
11
+ // value transfer has nothing for the device to clear-sign as one.
12
+ if (!tx.to || !tx.data?.length || typeof getIsNft !== 'function') return
13
+
14
+ return getIsNft({ address: tx.to.toString().toLowerCase() })
15
+ }
16
+
5
17
  export const signHardwareFactory =
6
- ({ baseAssetName }) =>
18
+ ({ baseAssetName, getIsNft }) =>
7
19
  async ({ unsignedTx, hardwareDevice, accountIndex }) => {
8
20
  const tx = createEthereumJsTx(unsignedTx)
9
21
 
22
+ const isNft = await resolveIsNft({ tx, getIsNft })
23
+
10
24
  const signedTx = await signWithHardwareWallet({
11
25
  baseAssetName,
12
26
  tx,
13
27
  hardwareDevice,
14
28
  accountIndex,
29
+ isNft,
15
30
  })
16
31
 
17
32
  // serialize and get txId
@@ -20,12 +35,13 @@ export const signHardwareFactory =
20
35
  return { rawTx, txId }
21
36
  }
22
37
 
23
- async function signWithHardwareWallet({ baseAssetName, tx, hardwareDevice, accountIndex }) {
38
+ async function signWithHardwareWallet({ baseAssetName, tx, hardwareDevice, accountIndex, isNft }) {
24
39
  const rlpEncodedTx = tx.serialize()
25
40
  const signatures = await hardwareDevice.signTransaction({
26
41
  assetName: baseAssetName,
27
42
  signableTransaction: rlpEncodedTx,
28
43
  derivationPaths: [`m/44'/60'/${accountIndex}'/0/0`],
44
+ isNft,
29
45
  })
30
46
 
31
47
  const { signature } = signatures[0]
@@ -1,12 +1,9 @@
1
+ import { fromHex, toHex } from '@exodus/bytes/hex.js'
1
2
  import { FeeMarketEIP1559Transaction, Transaction } from '@exodus/ethereumjs/tx'
2
3
  import { padToEven, toBuffer } from '@exodus/ethereumjs/util'
3
- import baseX from 'base-x'
4
4
 
5
5
  export { default as calculateExtraEth } from './calculate-extra-eth.js'
6
6
 
7
- const base10 = baseX('0123456789')
8
- const base16 = baseX('0123456789abcdef')
9
-
10
7
  /* @deprecated */
11
8
  export const isEthereumToken = (asset) => asset.assetType === 'ETHEREUM_ERC20'
12
9
  /* @deprecated */
@@ -54,21 +51,28 @@ export const isEthereumLikeByName = (assetName) => {
54
51
  }
55
52
 
56
53
  export function buffer2currency({ asset, value }) {
57
- return asset.currency.baseUnit(base10.encode(value))
54
+ if (value.length === 0) return asset.currency.ZERO
55
+
56
+ return asset.currency.baseUnit(`0x${toHex(value)}`)
58
57
  }
59
58
 
60
59
  export function currency2buffer(value) {
61
- const b10Value = value.toBaseString()
60
+ // In RLP, a big-endian interpretation of 0 consists of zeros -
61
+ // so after trimming, we should yield empty byte array.
62
+ //
63
+ // https://ethereum.stackexchange.com/a/61021
64
+ if (value.isZero) return Buffer.alloc(0)
62
65
 
63
- // Desktop: const hexValue = new BN(value.toBaseString()).toString(16)
64
- const hexValue = base16.encode(base10.decode(b10Value))
65
-
66
- if (hexValue.includes('.')) {
67
- // <-- probably not necessary anymore
68
- throw new RangeError(`${value.toBaseString()} can not be converted to Buffer`)
66
+ const b10Value = value.toBaseString()
67
+ if (b10Value[0] === '-') throw new RangeError('Negative numbers can not be converted to Buffer')
68
+ if (b10Value.length > 1 && b10Value[0] === '0') {
69
+ // Number is not supposed to be telling us the width, we always convert to smallest buffer that fits it
70
+ throw new RangeError('Padded numbers can not be converted to Buffer')
69
71
  }
70
72
 
71
- return Buffer.from(padToEven(hexValue), 'hex')
73
+ // Desktop: const hexValue = new BN(value.toBaseString()).toString(16)
74
+ const hexValue = BigInt(b10Value).toString(16)
75
+ return fromHex(padToEven(hexValue), 'buffer')
72
76
  }
73
77
 
74
78
  export function normalizeTxId(txId) {