@exodus/ethereum-api 2.22.0 → 2.22.1

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.
Files changed (2) hide show
  1. package/package.json +4 -3
  2. package/src/ens/index.js +34 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "2.22.0",
3
+ "version": "2.22.1",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -14,7 +14,6 @@
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
19
  "@exodus/ethereum-lib": "^2.20.0",
@@ -22,6 +21,8 @@
22
21
  "@exodus/simple-retry": "^0.0.6",
23
22
  "@exodus/solidity-contract": "^1.0.1",
24
23
  "fetchival": "0.3.3",
24
+ "idna-uts46-hx": "^2.3.1",
25
+ "js-sha3": "^0.8.0",
25
26
  "make-concurrent": "4.0.0",
26
27
  "minimalistic-assert": "^1.0.1",
27
28
  "ms": "^2.1.1",
@@ -34,5 +35,5 @@
34
35
  "@exodus/assets-base": "^8.0.136",
35
36
  "@exodus/models": "^8.7.2"
36
37
  },
37
- "gitHead": "57fae619663ea5193c733bd089c9031447f0d025"
38
+ "gitHead": "6a99fbefed718767bf3f8a81f18881084ffbdb6c"
38
39
  }
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]