@exodus/ethereum-lib 5.6.0 → 5.7.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 CHANGED
@@ -3,6 +3,21 @@
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.7.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-lib@5.6.0...@exodus/ethereum-lib@5.7.0) (2024-10-29)
7
+
8
+
9
+ ### Features
10
+
11
+ * introduce exodus/ethereumjs ([#4339](https://github.com/ExodusMovement/assets/issues/4339)) ([e81d577](https://github.com/ExodusMovement/assets/commit/e81d5771c4956a22cfcf434a999310bbb5be81a3))
12
+ * load more imports from ethereumjs/util ([#4379](https://github.com/ExodusMovement/assets/issues/4379)) ([dead85c](https://github.com/ExodusMovement/assets/commit/dead85cfb55223c344af506d8d7ca7cf7eeb516c))
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * remove stray direct dependencies ([#4176](https://github.com/ExodusMovement/assets/issues/4176)) ([c4f93fa](https://github.com/ExodusMovement/assets/commit/c4f93fad5a930b40d326d7add1093b2d4f243f2a))
18
+
19
+
20
+
6
21
  ## [5.6.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-lib@5.5.0...@exodus/ethereum-lib@5.6.0) (2024-10-04)
7
22
 
8
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-lib",
3
- "version": "5.6.0",
3
+ "version": "5.7.0",
4
4
  "description": "Ethereum Library",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -23,16 +23,12 @@
23
23
  "dependencies": {
24
24
  "@exodus/basic-utils": "^3.0.1",
25
25
  "@exodus/currency": "^5.0.2",
26
- "@exodus/ethereum-meta": "^2.0.0",
27
- "@exodus/ethereumjs-common": "^2.4.0-exodus.6",
28
- "@exodus/ethereumjs-tx": "^3.3.0-exodus.7",
29
- "@exodus/ethereumjs-util": "^7.1.0-exodus.7",
26
+ "@exodus/ethereumjs": "^1.2.0",
30
27
  "@exodus/key-utils": "^3.7.0",
31
28
  "@exodus/models": "^12.0.1",
32
29
  "@exodus/solidity-contract": "^1.1.3",
33
30
  "@metamask/eth-sig-util": "^4.0.1",
34
31
  "base-x": "^3.0.2",
35
- "ethjs-util": "^0.1.6",
36
32
  "lodash": "^4.17.15",
37
33
  "minimalistic-assert": "^1.0.1",
38
34
  "ms": "^2.1.1",
@@ -43,6 +39,7 @@
43
39
  "@exodus/bitcoin-meta": "^2.0.0",
44
40
  "@exodus/bsc-meta": "^2.0.0",
45
41
  "@exodus/crypto": "^1.0.0-rc.13",
42
+ "@exodus/ethereum-meta": "^2.0.0",
46
43
  "@exodus/ethereumclassic-meta": "^2.0.0",
47
44
  "@exodus/fantommainnet-meta": "^2.0.0",
48
45
  "@exodus/matic-meta": "^2.0.0"
@@ -54,5 +51,5 @@
54
51
  "type": "git",
55
52
  "url": "git+https://github.com/ExodusMovement/assets.git"
56
53
  },
57
- "gitHead": "a20bb277d8dfa3d3137d35ee8fa45333f9dd91d3"
54
+ "gitHead": "24fdca197cb82cfb999348146080364ff9b78c34"
58
55
  }
@@ -11,7 +11,7 @@ function parseBalance({ asset, balance }) {
11
11
  }
12
12
 
13
13
  throw new Error(
14
- `Balance '${balance.toDefaultString()}' is not of currency ${currency.toString()}`
14
+ `Balance '${balance.toDefaultString({ unit: true })}' is not of currency ${currency.toDefaultString({ unit: true })}`
15
15
  )
16
16
  }
17
17
 
@@ -1,14 +1,14 @@
1
- import ethUtil from '@exodus/ethereumjs-util'
1
+ import { bufferToHex, toBuffer } from '@exodus/ethereumjs/util'
2
2
 
3
3
  // TODO: obsolete, remove this
4
4
  // TODO: migrate to using solidity-contract
5
5
  export default function createContract(addresses, currency) {
6
6
  // First 4 bytes of Keccak256('transfer(address,uint256)')
7
- // const TRANSFER_METHOD_ID = ethUtil.bufferToHex(ethUtil.sha3('transfer(address,uint256)').slice(0, 4))
7
+ // const TRANSFER_METHOD_ID = bufferToHex(sha3('transfer(address,uint256)').slice(0, 4))
8
8
  const TRANSFER_METHOD_ID = '0xa9059cbb'
9
9
 
10
10
  // Keccak256('Transfer(address,address,uint256)')
11
- // const TRANSFER_EVENT_ID = ethUtil.bufferToHex(ethUtil.sha3('Transfer(address,address,uint256)'))
11
+ // const TRANSFER_EVENT_ID = bufferToHex(sha3('Transfer(address,address,uint256)'))
12
12
  const TRANSFER_EVENT_ID = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
13
13
 
14
14
  const transfer = {
@@ -17,33 +17,33 @@ export default function createContract(addresses, currency) {
17
17
 
18
18
  build(to, bufAmount) {
19
19
  return Buffer.concat([
20
- ethUtil.toBuffer(TRANSFER_METHOD_ID),
21
- ethUtil.zeros(12),
22
- ethUtil.toBuffer(to),
23
- ethUtil.zeros(32 - bufAmount.length),
20
+ toBuffer(TRANSFER_METHOD_ID),
21
+ Buffer.alloc(12),
22
+ toBuffer(to),
23
+ Buffer.alloc(32 - bufAmount.length),
24
24
  bufAmount,
25
25
  ])
26
26
  },
27
27
 
28
28
  test(data) {
29
- return ethUtil.bufferToHex(data.slice(0, 4)) === TRANSFER_METHOD_ID
29
+ return bufferToHex(data.slice(0, 4)) === TRANSFER_METHOD_ID
30
30
  },
31
31
 
32
32
  parse(data) {
33
33
  if (!transfer.test(data)) throw new Error('It is not transfer data')
34
34
 
35
35
  return {
36
- to: ethUtil.bufferToHex(data.slice(16, 36)),
37
- amount: currency.baseUnit(ethUtil.bufferToHex(data.slice(36, 68))),
36
+ to: bufferToHex(data.slice(16, 36)),
37
+ amount: currency.baseUnit(bufferToHex(data.slice(36, 68))),
38
38
  }
39
39
  },
40
40
  }
41
41
 
42
- // ethUtil.bufferToHex(ethUtil.sha3('approve(address,uint256)').slice(0, 4))
42
+ // bufferToHex(sha3('approve(address,uint256)').slice(0, 4))
43
43
  const APPROVE_METHOD_ID = '0x095ea7b3'
44
44
 
45
45
  // TODO: not verified:
46
- // ethUtil.bufferToHex(ethUtil.sha3('Approval(address,address,uint256)'))
46
+ // bufferToHex(sha3('Approval(address,address,uint256)'))
47
47
  const APPROVE_EVENT_ID = '0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925'
48
48
 
49
49
  const approve = {
@@ -52,24 +52,24 @@ export default function createContract(addresses, currency) {
52
52
 
53
53
  build(address, bufAmount) {
54
54
  return Buffer.concat([
55
- ethUtil.toBuffer(APPROVE_METHOD_ID),
56
- ethUtil.zeros(12),
57
- ethUtil.toBuffer(address),
58
- ethUtil.zeros(32 - bufAmount.length),
55
+ toBuffer(APPROVE_METHOD_ID),
56
+ Buffer.alloc(12),
57
+ toBuffer(address),
58
+ Buffer.alloc(32 - bufAmount.length),
59
59
  bufAmount,
60
60
  ])
61
61
  },
62
62
 
63
63
  test(data) {
64
- return ethUtil.bufferToHex(data.slice(0, 4)) === APPROVE_METHOD_ID
64
+ return bufferToHex(data.slice(0, 4)) === APPROVE_METHOD_ID
65
65
  },
66
66
 
67
67
  parse(data) {
68
68
  if (!approve.test(data)) throw new Error('It is not approve data')
69
69
 
70
70
  return {
71
- address: ethUtil.bufferToHex(data.slice(16, 36)),
72
- amount: currency.baseUnit(ethUtil.bufferToHex(data.slice(36, 68))),
71
+ address: bufferToHex(data.slice(16, 36)),
72
+ amount: currency.baseUnit(bufferToHex(data.slice(36, 68))),
73
73
  }
74
74
  },
75
75
  }
package/src/encode.js CHANGED
@@ -1,4 +1,10 @@
1
- import * as etherUtil from '@exodus/ethereumjs-util'
1
+ import {
2
+ isValidChecksumAddress,
3
+ isValidPrivate as _isValidPrivate,
4
+ privateToAddress,
5
+ publicToAddress,
6
+ toChecksumAddress,
7
+ } from '@exodus/ethereumjs/util'
2
8
  import assert from 'minimalistic-assert'
3
9
 
4
10
  export const validateFactory = ({ chainId, useEip1191ChainIdChecksum }) => {
@@ -15,8 +21,8 @@ export const validateFactory = ({ chainId, useEip1191ChainIdChecksum }) => {
15
21
  if (!hasChecksum(address)) return true
16
22
 
17
23
  return (
18
- (useEip1191ChainIdChecksum && etherUtil.isValidChecksumAddress(address, chainId)) ||
19
- etherUtil.isValidChecksumAddress(address)
24
+ (useEip1191ChainIdChecksum && isValidChecksumAddress(address, chainId)) ||
25
+ isValidChecksumAddress(address)
20
26
  )
21
27
  }
22
28
  }
@@ -35,9 +41,9 @@ export const encodePublicFactory = ({ chainId, useEip1191ChainIdChecksum }) => {
35
41
  'chainId is required when useEip1191ChainIdChecksum is true'
36
42
  )
37
43
  return (compressedPubKey) => {
38
- const hash160bits = etherUtil.publicToAddress(compressedPubKey, true)
44
+ const hash160bits = publicToAddress(compressedPubKey, true)
39
45
 
40
- const basicAddress = etherUtil.toChecksumAddress(
46
+ const basicAddress = toChecksumAddress(
41
47
  '0x' + hash160bits.toString('hex'),
42
48
  useEip1191ChainIdChecksum ? chainId : undefined
43
49
  )
@@ -46,7 +52,7 @@ export const encodePublicFactory = ({ chainId, useEip1191ChainIdChecksum }) => {
46
52
  }
47
53
 
48
54
  export function isValidPrivate(privateKey) {
49
- return !(privateKey.length !== 32 || !etherUtil.isValidPrivate(privateKey))
55
+ return privateKey.length === 32 && _isValidPrivate(privateKey)
50
56
  }
51
57
 
52
58
  export const encodePublicFromPrivateFactory = ({ chainId, useEip1191ChainIdChecksum }) => {
@@ -55,8 +61,8 @@ export const encodePublicFromPrivateFactory = ({ chainId, useEip1191ChainIdCheck
55
61
  'chainId is required when useEip1191ChainIdChecksum is true'
56
62
  )
57
63
  return (privateKey) => {
58
- return etherUtil.toChecksumAddress(
59
- '0x' + etherUtil.privateToAddress(privateKey).toString('hex'),
64
+ return toChecksumAddress(
65
+ '0x' + privateToAddress(privateKey).toString('hex'),
60
66
  useEip1191ChainIdChecksum ? chainId : undefined
61
67
  )
62
68
  }
@@ -1,4 +1,4 @@
1
- import { hashPersonalMessage } from '@exodus/ethereumjs-util'
1
+ import { hashPersonalMessage } from '@exodus/ethereumjs/util'
2
2
  import {
3
3
  personalSign,
4
4
  signTypedData,
@@ -1,7 +1,5 @@
1
- import CommonCJS, { Hardfork } from '@exodus/ethereumjs-common'
2
- import { FeeMarketEIP1559Transaction, Transaction } from '@exodus/ethereumjs-tx'
3
-
4
- const Common = CommonCJS.default || CommonCJS
1
+ import { Common, Hardfork } from '@exodus/ethereumjs/common'
2
+ import { FeeMarketEIP1559Transaction, Transaction } from '@exodus/ethereumjs/tx'
5
3
 
6
4
  export default function createEthereumJsTx(unsignedTx) {
7
5
  const {
@@ -1,5 +1,4 @@
1
- import { toBuffer } from '@exodus/ethereumjs-util'
2
- import { intToBuffer } from 'ethjs-util'
1
+ import { intToBuffer, toBuffer } from '@exodus/ethereumjs/util'
3
2
  import assert from 'minimalistic-assert'
4
3
 
5
4
  import { currency2buffer, isToken } from '../utils/index.js'
@@ -1,4 +1,4 @@
1
- import * as ethUtil from '@exodus/ethereumjs-util'
1
+ import { bufferToInt } from '@exodus/ethereumjs/util'
2
2
 
3
3
  import { buffer2currency, isToken } from '../utils/index.js'
4
4
 
@@ -7,7 +7,7 @@ export default function parseUnsignedTx(asset, unsignedTx) {
7
7
  const _isToken = isToken(asset)
8
8
  const baseAsset = asset.baseAsset
9
9
  const gasPrice = buffer2currency({ asset: baseAsset, value: txData.gasPrice })
10
- const gasLimit = ethUtil.bufferToInt(txData.gasLimit)
10
+ const gasLimit = bufferToInt(txData.gasLimit)
11
11
 
12
12
  let { to, data, value } = txData
13
13
  let amount
@@ -16,7 +16,7 @@ export default function parseUnsignedTx(asset, unsignedTx) {
16
16
  const { method, values } = asset.contract.decodeInput(data)
17
17
  if (method === 'transfer' || method === 'approve') {
18
18
  to = values[0]
19
- amount = asset.currency.baseUnit(values[1]).toDefault()
19
+ amount = asset.currency.baseUnit(values[1])
20
20
  } else {
21
21
  to = values[0]
22
22
  amount = asset.currency.ZERO
@@ -6,5 +6,10 @@ export default function ({ fee, balance, multiplier = defaultMultiplier }) {
6
6
  if (typeof multiplier !== 'number' || multiplier < 1) multiplier = defaultMultiplier
7
7
  if (balance.gt(fee)) return balance.unitType.ZERO
8
8
 
9
- return fee.mul(multiplier).sub(balance).toDefault().toFixed(4, 'ceil').toString()
9
+ return fee
10
+ .mul(multiplier)
11
+ .sub(balance)
12
+ .toDefault() // ensure correct unit before `toFixed`
13
+ .toFixed(4, 'ceil')
14
+ .toDefaultString({ unit: true })
10
15
  }
@@ -1,5 +1,5 @@
1
- import { FeeMarketEIP1559Transaction, Transaction } from '@exodus/ethereumjs-tx'
2
- import * as ethUtil from '@exodus/ethereumjs-util'
1
+ import { FeeMarketEIP1559Transaction, Transaction } from '@exodus/ethereumjs/tx'
2
+ import { padToEven, toBuffer } from '@exodus/ethereumjs/util'
3
3
  import baseX from 'base-x'
4
4
 
5
5
  // eslint-disable-next-line @exodus/import/no-deprecated
@@ -61,7 +61,7 @@ export const isEthereumLikeByName = (assetName) => {
61
61
  }
62
62
 
63
63
  export function buffer2currency({ asset, value }) {
64
- return asset.currency.baseUnit(base10.encode(value)).toDefault()
64
+ return asset.currency.baseUnit(base10.encode(value))
65
65
  }
66
66
 
67
67
  export function currency2buffer(value) {
@@ -75,7 +75,7 @@ export function currency2buffer(value) {
75
75
  throw new RangeError(`${value.toBaseString()} can not be converted to Buffer`)
76
76
  }
77
77
 
78
- return Buffer.from(ethUtil.padToEven(hexValue), 'hex')
78
+ return Buffer.from(padToEven(hexValue), 'hex')
79
79
  }
80
80
 
81
81
  export function normalizeTxId(txId) {
@@ -92,7 +92,7 @@ const TRANSACTION_TYPE = 2
92
92
  const TRANSACTION_TYPE_BUFFER = Buffer.from(TRANSACTION_TYPE.toString(16).padStart(2, '0'), 'hex')
93
93
 
94
94
  export function deserialize(hex) {
95
- const buf = ethUtil.toBuffer(hex)
95
+ const buf = toBuffer(hex)
96
96
  return buf.slice(0, 1).equals(TRANSACTION_TYPE_BUFFER)
97
97
  ? FeeMarketEIP1559Transaction.fromSerializedTx(buf)
98
98
  : Transaction.fromSerializedTx(buf)