@exodus/ethereum-lib 3.3.33 → 3.3.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-lib",
3
- "version": "3.3.33",
3
+ "version": "3.3.34",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -25,7 +25,7 @@
25
25
  "@exodus/cronos-meta": "^1.0.4",
26
26
  "@exodus/ethereum-meta": "^1.0.30",
27
27
  "@exodus/ethereumarbnova-meta": "^1.0.2",
28
- "@exodus/ethereumarbone-meta": "^1.1.4",
28
+ "@exodus/ethereumarbone-meta": "^1.1.5",
29
29
  "@exodus/ethereumclassic-meta": "^1.0.1",
30
30
  "@exodus/ethereumgoerli-meta": "^1.0.3",
31
31
  "@exodus/ethereumjs-common": "^2.4.0-exodus.6",
@@ -44,5 +44,5 @@
44
44
  "ms": "^2.1.1",
45
45
  "reselect": "~3.0.1"
46
46
  },
47
- "gitHead": "a3f47ac29169f74502d0889f1cf867416fdce821"
47
+ "gitHead": "b08bcfa935e1f208104276cc6e07a9992ea2147f"
48
48
  }
package/src/constants.js CHANGED
@@ -76,6 +76,7 @@ const CHAIN_DATA = {
76
76
  confirmationsNumber: 3,
77
77
  monitorType: 'no-history',
78
78
  tokenType: 'RSK_ERC20',
79
+ eip1191ChainIdChecksum: true,
79
80
  },
80
81
  flare: {
81
82
  chainId: 14,
@@ -113,6 +114,11 @@ export const ETHEREUM_LIKE_MONITOR_TYPES = mapValues(
113
114
  ({ monitorType }) => monitorType || 'magnifier'
114
115
  )
115
116
  export const CHAIN_IDS = mapValues(CHAIN_DATA, ({ chainId }) => chainId)
117
+
118
+ export const EIP1191_ASSET_NAMES = Object.entries(CHAIN_DATA)
119
+ .filter(([, data]) => data.eip1191ChainIdChecksum)
120
+ .map(([assetName]) => assetName)
121
+
116
122
  export const MIN_GASPRICE = 1e9 // 1 gwei
117
123
  export const DEFAULT_FEE_MONITOR_INTERVAL = '1m'
118
124
  export const CONFIRMATIONS_NUMBER = mapValues(
package/src/encode.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as etherUtil from '@exodus/ethereumjs-util'
2
- import { CHAIN_IDS } from './constants'
2
+ import { CHAIN_IDS, EIP1191_ASSET_NAMES } from './constants'
3
3
 
4
4
  export function validate(address, { baseAssetName } = {}) {
5
5
  if (typeof address !== 'string') return false
@@ -8,14 +8,13 @@ export function validate(address, { baseAssetName } = {}) {
8
8
  if (address.slice(0, 2) !== '0x' || address.length !== 42) return false
9
9
 
10
10
  if (!hasChecksum(address)) return true
11
- if (baseAssetName && CHAIN_IDS[baseAssetName]) {
12
- const checksumWithChainIdResult = etherUtil.isValidChecksumAddress(
13
- address,
14
- CHAIN_IDS[baseAssetName]
15
- )
16
- if (checksumWithChainIdResult) return true
17
- }
18
- return etherUtil.isValidChecksumAddress(address)
11
+
12
+ const eip1191ChainIdChecksum = EIP1191_ASSET_NAMES.includes(baseAssetName)
13
+ const chainId = CHAIN_IDS[baseAssetName]
14
+ return (
15
+ (eip1191ChainIdChecksum && etherUtil.isValidChecksumAddress(address, chainId)) ||
16
+ etherUtil.isValidChecksumAddress(address)
17
+ )
19
18
  }
20
19
 
21
20
  export function hasChecksum(address) {
@@ -30,14 +29,14 @@ export function encodePrivate(privKey) {
30
29
  export function encodePublic(compressedPubKey, { baseAssetName } = {}) {
31
30
  const hash160bits = etherUtil.publicToAddress(compressedPubKey, true)
32
31
 
33
- if (baseAssetName && CHAIN_IDS[baseAssetName]) {
34
- const address = etherUtil.toChecksumAddress(
35
- '0x' + hash160bits.toString('hex'),
36
- CHAIN_IDS[baseAssetName]
37
- )
38
- return baseAssetName === 'rootstock' ? address.toLowerCase() : address
39
- }
40
- return etherUtil.toChecksumAddress('0x' + hash160bits.toString('hex'))
32
+ const eip1191ChainIdChecksum = EIP1191_ASSET_NAMES.includes(baseAssetName)
33
+ const chainId = CHAIN_IDS[baseAssetName]
34
+
35
+ const basicAddress = etherUtil.toChecksumAddress(
36
+ '0x' + hash160bits.toString('hex'),
37
+ eip1191ChainIdChecksum ? chainId : undefined
38
+ )
39
+ return eip1191ChainIdChecksum ? basicAddress.toLowerCase() : basicAddress
41
40
  }
42
41
 
43
42
  export function isValidPrivate(privateKey) {
@@ -48,11 +47,11 @@ export function isValidPrivate(privateKey) {
48
47
  }
49
48
 
50
49
  export function encodePublicFromPrivate(privateKey, { baseAssetName } = {}) {
51
- if (baseAssetName && CHAIN_IDS[baseAssetName]) {
52
- return etherUtil.toChecksumAddress(
53
- etherUtil.privateToAddress(privateKey).toString('hex'),
54
- CHAIN_IDS[baseAssetName]
55
- )
56
- }
57
- return etherUtil.toChecksumAddress(etherUtil.privateToAddress(privateKey).toString('hex'))
50
+ const eip1191ChainIdChecksum = EIP1191_ASSET_NAMES.includes(baseAssetName)
51
+ const chainId = CHAIN_IDS[baseAssetName]
52
+
53
+ return etherUtil.toChecksumAddress(
54
+ '0x' + etherUtil.privateToAddress(privateKey).toString('hex'),
55
+ eip1191ChainIdChecksum ? chainId : undefined
56
+ )
58
57
  }