@exodus/ethereum-api 2.22.0 → 2.23.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -9,19 +9,21 @@
9
9
  ],
10
10
  "author": "Exodus Movement, Inc.",
11
11
  "license": "UNLICENSED",
12
- "homepage": "https://github.com/ExodusMovement/ethereum#readme",
12
+ "homepage": "https://github.com/ExodusMovement/assets/tree/main/ethereum",
13
13
  "publishConfig": {
14
14
  "access": "restricted"
15
15
  },
16
16
  "dependencies": {
17
- "@ensdomains/eth-ens-namehash": "^2.0.15",
18
17
  "@exodus/asset-lib": "^3.5.4",
19
18
  "@exodus/crypto": "^1.0.0-rc.0",
20
- "@exodus/ethereum-lib": "^2.20.0",
19
+ "@exodus/ethereum-lib": "^2.21.0",
21
20
  "@exodus/ethereumjs-util": "^7.1.0-exodus.6",
21
+ "@exodus/fetch": "^1.2.1",
22
22
  "@exodus/simple-retry": "^0.0.6",
23
23
  "@exodus/solidity-contract": "^1.0.1",
24
- "fetchival": "0.3.3",
24
+ "events": "^1.1.1",
25
+ "idna-uts46-hx": "^2.3.1",
26
+ "js-sha3": "^0.8.0",
25
27
  "make-concurrent": "4.0.0",
26
28
  "minimalistic-assert": "^1.0.1",
27
29
  "ms": "^2.1.1",
@@ -34,5 +36,5 @@
34
36
  "@exodus/assets-base": "^8.0.136",
35
37
  "@exodus/models": "^8.7.2"
36
38
  },
37
- "gitHead": "57fae619663ea5193c733bd089c9031447f0d025"
39
+ "gitHead": "5a1621d8fb3c1ecf4c47dc37f284e9a40d7fd018"
38
40
  }
package/src/ens/index.js CHANGED
@@ -1,5 +1,6 @@
1
- import { hash } from '@ensdomains/eth-ens-namehash'
2
1
  import SolidityContract from '@exodus/solidity-contract'
2
+ import { toUnicode } from 'idna-uts46-hx'
3
+ import { keccak256 } from 'js-sha3'
3
4
  import { ABI } from '@exodus/ethereum-lib'
4
5
 
5
6
  import ENS_REGISTRY_ADDRESSES from './addresses'
@@ -7,6 +8,35 @@ import ENS_REGISTRY_ADDRESSES from './addresses'
7
8
  const registry = new SolidityContract(ABI.ensRegistry)
8
9
  const resolver = new SolidityContract(ABI.ensResolver)
9
10
 
11
+ function normalize(name) {
12
+ // Implementation based on @ensdomains/eth-ens-namehash package
13
+ return name ? toUnicode(name, { useStd3ASCII: true, transitional: false }) : name
14
+ }
15
+
16
+ function namehash(inputName) {
17
+ // Implementation based on @ensdomains/eth-ens-namehash package
18
+
19
+ // Reject empty names:
20
+ var node = ''
21
+ var i
22
+ for (i = 0; i < 32; i++) {
23
+ node += '00'
24
+ }
25
+
26
+ var name = normalize(inputName)
27
+
28
+ if (name) {
29
+ var labels = name.split('.')
30
+
31
+ for (i = labels.length - 1; i >= 0; i--) {
32
+ var labelSha = keccak256(labels[i])
33
+ node = keccak256(Buffer.from(node + labelSha, 'hex'))
34
+ }
35
+ }
36
+
37
+ return '0x' + node
38
+ }
39
+
10
40
  // ENS only available on mainnet atm
11
41
  const ENS_REGISTRY_ADDRESS = ENS_REGISTRY_ADDRESSES['ethereum']
12
42
 
@@ -14,7 +44,7 @@ const getResolverAddress = async (name: string, server: Object) =>
14
44
  server
15
45
  .ethCall({
16
46
  to: ENS_REGISTRY_ADDRESS,
17
- data: registry.resolver.methodId + hash(name).slice(2),
47
+ data: registry.resolver.methodId + namehash(name).slice(2),
18
48
  })
19
49
  .then((result) => '0x' + result.slice(26))
20
50
 
@@ -22,7 +52,7 @@ const resolveEnsName = async (name: string, server: Object) => {
22
52
  const resolverAddress = await getResolverAddress(name, server)
23
53
  const hex = await server.ethCall({
24
54
  to: resolverAddress,
25
- data: resolver.addr.methodId + hash(name).slice(2),
55
+ data: resolver.addr.methodId + namehash(name).slice(2),
26
56
  })
27
57
  return '0x' + hex.slice(26)
28
58
  }
@@ -34,7 +64,7 @@ const resolveEnsAddress = async (address: string, server: Object) => {
34
64
 
35
65
  const data = await server.ethCall({
36
66
  to: resolverAddress,
37
- data: resolver.name.methodId + hash(name).slice(2),
67
+ data: resolver.name.methodId + namehash(name).slice(2),
38
68
  })
39
69
 
40
70
  return resolver.decodeOutput({ data, method: 'name' })[0]
@@ -1,9 +1,6 @@
1
1
  import ms from 'ms'
2
2
  import makeConcurrent from 'make-concurrent'
3
- import fetchival from 'fetchival'
4
- // The module in desktop explicitly sets node-fetch. Do we need this?
5
- // import fetch from '../fetch'
6
- // fetchival.fetch = fetch
3
+ import { fetchival } from '@exodus/fetch'
7
4
 
8
5
  const ETHERSCAN_API_URL = 'https://api.etherscan.io/api'
9
6
  const DEFAULT_ETHERSCAN_API_KEY = 'XM3VGRSNW1TMSIR14I9MVFP15X74GNHTRI'
@@ -1,4 +1,4 @@
1
- import { EventEmitter } from 'events'
1
+ import EventEmitter from 'events/' // '/' forces it to use the module from node_modules
2
2
  import ms from 'ms'
3
3
  import WebSocket from '../websocket'
4
4
 
@@ -1,8 +1,8 @@
1
1
  import urlJoin from 'url-join'
2
2
  import url from 'url'
3
- import fetchival from 'fetchival'
4
3
  import ms from 'ms'
5
4
  import createWebSocket from './ws'
5
+ import { fetchival } from '@exodus/fetch'
6
6
  import { retry } from '@exodus/simple-retry'
7
7
  import SolidityContract from '@exodus/solidity-contract'
8
8
  import { bufferToHex } from '@exodus/ethereumjs-util'
@@ -1,5 +1,5 @@
1
1
  import ms from 'ms'
2
- import { EventEmitter } from 'events'
2
+ import EventEmitter from 'events/' // '/' forces it to use the module from node_modules
3
3
  import WebSocket from '../websocket'
4
4
 
5
5
  const RECONNECT_INTERVAL = ms('10s')
@@ -6,11 +6,14 @@
6
6
  */
7
7
  if (
8
8
  typeof process !== 'undefined' &&
9
- process &&
10
9
  (process.type === 'renderer' || process.type === 'worker')
11
10
  ) {
12
11
  // THIS IS FOR DESKTOP
13
- module.exports = require('ws')
12
+ if (process.env.EXODUS_DISABLE_WS) {
13
+ module.exports = globalThis.WebSocket
14
+ } else {
15
+ module.exports = require('ws')
16
+ }
14
17
  } else {
15
18
  // eslint-disable-next-line no-undef
16
19
  if (global.window?.WebSocket) {