@exodus/ethereum-api 2.21.2 → 2.21.4

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.21.2",
3
+ "version": "2.21.4",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "author": "Exodus Movement, Inc.",
@@ -10,9 +10,10 @@
10
10
  "access": "restricted"
11
11
  },
12
12
  "dependencies": {
13
+ "@ensdomains/eth-ens-namehash": "^2.0.15",
13
14
  "@exodus/asset-lib": "^3.5.4",
14
15
  "@exodus/crypto": "^1.0.0-rc.0",
15
- "@exodus/ethereum-lib": "^2.19.2",
16
+ "@exodus/ethereum-lib": "^2.19.3",
16
17
  "@exodus/ethereumjs-util": "^7.1.0-exodus.6",
17
18
  "@exodus/simple-retry": "^0.0.6",
18
19
  "@exodus/solidity-contract": "^1.0.1",
@@ -29,5 +30,5 @@
29
30
  "@exodus/assets-base": "^8.0.136",
30
31
  "@exodus/models": "^8.7.2"
31
32
  },
32
- "gitHead": "c04eff51885ea6e09d5d2a6c7a3c8c89a2eb2416"
33
+ "gitHead": "643548a6bec98afc737a9a576c508dd0cef7645c"
33
34
  }
@@ -0,0 +1,8 @@
1
+ export default {
2
+ ethereum: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
3
+ // TODO: add other networks if/when available
4
+ // 'avalanchec': '',
5
+ // 'bsc': '',
6
+ // 'fantommainnet': '',
7
+ // 'matic': '',
8
+ }
@@ -0,0 +1,44 @@
1
+ import { hash } from '@ensdomains/eth-ens-namehash'
2
+ import SolidityContract from '@exodus/solidity-contract'
3
+ import { ABI } from '@exodus/ethereum-lib'
4
+
5
+ import { eth as server } from '../exodus-eth-server'
6
+ import ENS_REGISTRY_ADDRESSES from './addresses'
7
+
8
+ const registry = new SolidityContract(ABI.ensRegistry)
9
+ const resolver = new SolidityContract(ABI.ensResolver)
10
+
11
+ // ENS only available on mainnet atm
12
+ const ENS_REGISTRY_ADDRESS = ENS_REGISTRY_ADDRESSES['ethereum']
13
+
14
+ const getResolverAddress = async (name: string) =>
15
+ server
16
+ .ethCall({
17
+ to: ENS_REGISTRY_ADDRESS,
18
+ data: registry.resolver.methodId + hash(name).slice(2),
19
+ })
20
+ .then((result) => '0x' + result.slice(26))
21
+
22
+ const resolveEnsName = async (name: string) => {
23
+ const resolverAddress = await getResolverAddress(name)
24
+ const hex = await server.ethCall({
25
+ to: resolverAddress,
26
+ data: resolver.addr.methodId + hash(name).slice(2),
27
+ })
28
+ return '0x' + hex.slice(26)
29
+ }
30
+
31
+ const resolveEnsAddress = async (address: string) => {
32
+ const name = `${address.slice(2)}.addr.reverse`
33
+
34
+ const resolverAddress = await getResolverAddress(name)
35
+
36
+ const data = await server.ethCall({
37
+ to: resolverAddress,
38
+ data: resolver.name.methodId + hash(name).slice(2),
39
+ })
40
+
41
+ return resolver.decodeOutput({ data, method: 'name' })[0]
42
+ }
43
+
44
+ export { resolveEnsAddress, resolveEnsName }
@@ -8,9 +8,11 @@ import SolidityContract from '@exodus/solidity-contract'
8
8
  import { bufferToHex } from '@exodus/ethereumjs-util'
9
9
  import { randomUUID } from '@exodus/crypto/randomUUID'
10
10
 
11
+ import { resolveEnsAddress, resolveEnsName } from '../ens'
12
+
11
13
  const RETRY_DELAYS = ['10s']
12
14
 
13
- export function create(defaultURL) {
15
+ export function create(defaultURL, ensAssetName) {
14
16
  let API_URL = defaultURL
15
17
  const ws = createWebSocket(() => {
16
18
  // eslint-disable-next-line
@@ -41,7 +43,7 @@ export function create(defaultURL) {
41
43
  // Default retry function
42
44
  const requestWithRetry = retry(request, { delayTimesMs: RETRY_DELAYS })
43
45
 
44
- return {
46
+ const api = {
45
47
  getURL() {
46
48
  return API_URL
47
49
  },
@@ -239,4 +241,12 @@ export function create(defaultURL) {
239
241
  return request('proxy', requestData, { version: 'v2', method: 'post' })
240
242
  },
241
243
  }
244
+
245
+ return ensAssetName === 'ethereum'
246
+ ? {
247
+ ...api,
248
+ resolveEnsName,
249
+ resolveEnsAddress,
250
+ }
251
+ : api
242
252
  }
@@ -1,32 +1,24 @@
1
+ import { DEFAULT_SERVER_URLS, ETHEREUM_LIKE_ASSETS } from '@exodus/ethereum-lib'
2
+
1
3
  import { create } from './api'
2
4
 
3
- const EXODUS_ETH_SERVER_URL = 'https://geth.a.exodus.io/wallet/v1/'
4
- const EXODUS_ETC_SERVER_URL = 'https://getc.a.exodus.io/wallet/v1/'
5
- const EXODUS_BSC_SERVER_URL = 'https://bsc.a.exodus.io/wallet/v1/'
6
- const EXODUS_POLYGON_SERVER_URL = 'https://polygon.a.exodus.io/wallet/v1/'
7
- const EXODUS_AVAXC_SERVER_URL = 'https://avax-c.a.exodus.io/wallet/v1/'
8
- const EXODUS_FTM_SERVER_URL = 'https://fantom.a.exodus.io/wallet/v1/'
9
- const EXODUS_HARMONY_SERVER_URL = 'https://harmony.a.exodus.io/wallet/v1/'
5
+ // exported for in-library use only.
6
+ export const serverMap = Object.fromEntries(
7
+ ETHEREUM_LIKE_ASSETS.map((assetName) => [
8
+ assetName,
9
+ create(DEFAULT_SERVER_URLS[assetName], assetName),
10
+ ])
11
+ )
12
+
10
13
  // allow self-signed certs
11
14
  // process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
12
- export const eth = create(EXODUS_ETH_SERVER_URL)
13
- export const etc = create(EXODUS_ETC_SERVER_URL)
14
- export const bsc = create(EXODUS_BSC_SERVER_URL)
15
- export const polygon = create(EXODUS_POLYGON_SERVER_URL)
16
- export const avaxc = create(EXODUS_AVAXC_SERVER_URL)
17
- export const ftm = create(EXODUS_FTM_SERVER_URL)
18
- export const harmony = create(EXODUS_HARMONY_SERVER_URL)
19
-
20
- // exported for in-library use only.
21
- export const serverMap = {
22
- ethereum: eth,
23
- ethereumclassic: etc,
24
- bsc,
25
- matic: polygon,
26
- avalanchec: avaxc,
27
- fantommainnet: ftm,
28
- harmonymainnet: harmony,
29
- }
15
+ export const eth = serverMap['ethereum']
16
+ export const etc = serverMap['ethereumclassic']
17
+ export const bsc = serverMap['bsc']
18
+ export const polygon = serverMap['matic']
19
+ export const avaxc = serverMap['avalanchec']
20
+ export const ftm = serverMap['fantommainnet']
21
+ export const harmony = serverMap['harmonymainnet']
30
22
 
31
23
  export function getServer(asset) {
32
24
  const baseAssetName = asset.baseAsset.name