@exodus/ethereum-lib 2.26.7 → 2.26.9

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": "2.26.7",
3
+ "version": "2.26.9",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -29,5 +29,5 @@
29
29
  "ms": "^2.1.1",
30
30
  "reselect": "~3.0.1"
31
31
  },
32
- "gitHead": "2930e8d91f3a63810a062b39e35318926ae304ac"
32
+ "gitHead": "894830a79d49d9673b40143b4893234bc01a7cbc"
33
33
  }
package/src/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { mapValues } from '@exodus/basic-utils'
2
2
 
3
- const CHAIN_DATA = {
3
+ export const CHAIN_DATA = {
4
4
  ethereum: {
5
5
  chainId: 1,
6
6
  serverUrl: 'https://geth.a.exodus.io/wallet/v1/',
package/src/encode.js CHANGED
@@ -1,12 +1,20 @@
1
1
  import * as etherUtil from '@exodus/ethereumjs-util'
2
+ import { CHAIN_IDS } from './constants'
2
3
 
3
- export function validate(address) {
4
+ export function validate(address, { baseAssetName } = {}) {
4
5
  if (typeof address !== 'string') return false
5
6
 
6
7
  // https://github.com/ethereumjs/ethereumjs-util/issues/54
7
8
  if (address.slice(0, 2) !== '0x' || address.length !== 42) return false
8
9
 
9
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
+ }
10
18
  return etherUtil.isValidChecksumAddress(address)
11
19
  }
12
20
 
@@ -19,8 +27,12 @@ export function encodePrivate(privKey) {
19
27
  return '0x' + privKey.toString('hex')
20
28
  }
21
29
 
22
- export function encodePublic(compressedPubKey) {
30
+ export function encodePublic(compressedPubKey, { baseAssetName } = {}) {
23
31
  const hash160bits = etherUtil.publicToAddress(compressedPubKey, true)
32
+
33
+ if (baseAssetName && CHAIN_IDS[baseAssetName]) {
34
+ return etherUtil.toChecksumAddress('0x' + hash160bits.toString('hex'), CHAIN_IDS[baseAssetName])
35
+ }
24
36
  return etherUtil.toChecksumAddress('0x' + hash160bits.toString('hex'))
25
37
  }
26
38
 
@@ -31,6 +43,12 @@ export function isValidPrivate(privateKey) {
31
43
  return true
32
44
  }
33
45
 
34
- export function encodePublicFromPrivate(privateKey) {
46
+ export function encodePublicFromPrivate(privateKey, { baseAssetName } = {}) {
47
+ if (baseAssetName && CHAIN_IDS[baseAssetName]) {
48
+ return etherUtil.toChecksumAddress(
49
+ etherUtil.privateToAddress(privateKey).toString('hex'),
50
+ CHAIN_IDS[baseAssetName]
51
+ )
52
+ }
35
53
  return etherUtil.toChecksumAddress(etherUtil.privateToAddress(privateKey).toString('hex'))
36
54
  }