@dynamic-labs/utils 3.0.0-alpha.3 → 3.0.0-alpha.5
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/CHANGELOG.md +32 -0
- package/package.json +4 -6
- package/src/handleMobileWalletRedirect/handleMobileWalletRedirect.cjs +0 -1
- package/src/handleMobileWalletRedirect/handleMobileWalletRedirect.js +0 -1
- package/src/hexToString/hexToString.cjs +32 -0
- package/src/hexToString/hexToString.d.ts +12 -0
- package/src/hexToString/hexToString.js +28 -0
- package/src/hexToString/index.d.ts +1 -0
- package/src/index.cjs +4 -4
- package/src/index.d.ts +2 -1
- package/src/index.js +2 -1
- package/src/isHex/index.d.ts +1 -0
- package/src/isHex/isHex.cjs +20 -0
- package/src/isHex/isHex.d.ts +6 -0
- package/src/isHex/isHex.js +16 -0
- package/src/retryableFn.cjs +0 -1
- package/src/retryableFn.js +0 -1
- package/src/getOrMapViemChain.cjs +0 -77
- package/src/getOrMapViemChain.d.ts +0 -11
- package/src/getOrMapViemChain.js +0 -51
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
|
|
2
|
+
## [3.0.0-alpha.5](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.4...v3.0.0-alpha.5) (2024-06-14)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### ⚠ BREAKING CHANGES
|
|
6
|
+
|
|
7
|
+
* remove viem dependency from non-evm packages (#5508)
|
|
8
|
+
* move rpc providers into their own packages (#5981)
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* add in-app browser navigation support for sats-connect ([#5988](https://github.com/dynamic-labs/DynamicAuth/issues/5988)) ([be27d2d](https://github.com/dynamic-labs/DynamicAuth/commit/be27d2d4030bbe2157e879497d8e6a00b4a3e404))
|
|
13
|
+
* move rpc providers into their own packages ([#5981](https://github.com/dynamic-labs/DynamicAuth/issues/5981)) ([d7a62d6](https://github.com/dynamic-labs/DynamicAuth/commit/d7a62d60e79dfa6d6651b0fa103e90b6f8a9ccf3))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* embedded solana wallets can send SPL tokens and estimate gas ([#5982](https://github.com/dynamic-labs/DynamicAuth/issues/5982)) ([36623eb](https://github.com/dynamic-labs/DynamicAuth/commit/36623eb99d1d1dfebfd8b6f3194eeff31e7de2bf))
|
|
19
|
+
* improve logic related to turnkey and emailVerifcation ([#5946](https://github.com/dynamic-labs/DynamicAuth/issues/5946)) ([dd0b2dc](https://github.com/dynamic-labs/DynamicAuth/commit/dd0b2dc6d93a8bbbcb6eef88732e62b747005bb3))
|
|
20
|
+
* show linked wallets with unavailable providers in user wallets list ([#5992](https://github.com/dynamic-labs/DynamicAuth/issues/5992)) ([996079c](https://github.com/dynamic-labs/DynamicAuth/commit/996079ced360651c7b1eb5273548e0548f6f9f3a))
|
|
21
|
+
* switch network modal not closing after switching to a supported network ([#5979](https://github.com/dynamic-labs/DynamicAuth/issues/5979)) ([f239952](https://github.com/dynamic-labs/DynamicAuth/commit/f2399523dd82bb28046992cac4582688b688bdc0))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
* remove viem dependency from non-evm packages ([#5508](https://github.com/dynamic-labs/DynamicAuth/issues/5508)) ([0299dc3](https://github.com/dynamic-labs/DynamicAuth/commit/0299dc3cbb611182d763e9a89d1270c2e2f32df5))
|
|
25
|
+
|
|
26
|
+
## [3.0.0-alpha.4](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.3...v3.0.0-alpha.4) (2024-06-12)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* cache getGenesisHash call to prevent over calling ([#5966](https://github.com/dynamic-labs/DynamicAuth/issues/5966)) ([b4d542f](https://github.com/dynamic-labs/DynamicAuth/commit/b4d542f0a85f5ba8c5b8f02f287caee45b4b6feb))
|
|
32
|
+
* handle raw messages in embedded wallet sign message modal ([#5815](https://github.com/dynamic-labs/DynamicAuth/issues/5815)) ([9adc289](https://github.com/dynamic-labs/DynamicAuth/commit/9adc28993b57c1c7f03c4ce6d500288dcf60881e))
|
|
33
|
+
|
|
2
34
|
## [3.0.0-alpha.3](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.2...v3.0.0-alpha.3) (2024-06-11)
|
|
3
35
|
|
|
4
36
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/utils",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -28,11 +28,9 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@dynamic-labs/sdk-api-core": "0.0.461",
|
|
30
30
|
"tldts": "6.0.16",
|
|
31
|
-
"@dynamic-labs/logger": "3.0.0-alpha.
|
|
32
|
-
"@dynamic-labs/types": "3.0.0-alpha.
|
|
31
|
+
"@dynamic-labs/logger": "3.0.0-alpha.5",
|
|
32
|
+
"@dynamic-labs/types": "3.0.0-alpha.5",
|
|
33
33
|
"buffer": "6.0.3"
|
|
34
34
|
},
|
|
35
|
-
"peerDependencies": {
|
|
36
|
-
"viem": "^2.7.6"
|
|
37
|
-
}
|
|
35
|
+
"peerDependencies": {}
|
|
38
36
|
}
|
|
@@ -9,7 +9,6 @@ require('../logger/logger.cjs');
|
|
|
9
9
|
var isMobile = require('../isMobile.cjs');
|
|
10
10
|
require('../../_virtual/_tslib.cjs');
|
|
11
11
|
require('../bufferPolyfill.cjs');
|
|
12
|
-
require('viem/chains');
|
|
13
12
|
require('tldts');
|
|
14
13
|
|
|
15
14
|
const handleMobileWalletRedirect = ({ nativeLink, universalLink, }) => {
|
|
@@ -5,7 +5,6 @@ import '../logger/logger.js';
|
|
|
5
5
|
import { isSamsungBrowser } from '../isMobile.js';
|
|
6
6
|
import '../../_virtual/_tslib.js';
|
|
7
7
|
import '../bufferPolyfill.js';
|
|
8
|
-
import 'viem/chains';
|
|
9
8
|
import 'tldts';
|
|
10
9
|
|
|
11
10
|
const handleMobileWalletRedirect = ({ nativeLink, universalLink, }) => {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Converts a hexadecimal string to a regular string by interpreting each pair of characters in the
|
|
8
|
+
* hexadecimal string as a byte in ASCII. It automatically handles hex strings prefixed with '0x'.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} hexString - The hexadecimal string to convert. It can optionally start with '0x'.
|
|
11
|
+
* @returns {string} The decoded ASCII string.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* hexToString('68656c6c6f'); // returns 'hello'
|
|
15
|
+
* hexToString('0x68656c6c6f'); // also returns 'hello'
|
|
16
|
+
*/
|
|
17
|
+
const hexToString = (hexString) => {
|
|
18
|
+
const normalizedHexString = hexString.startsWith('0x')
|
|
19
|
+
? hexString.substring(2)
|
|
20
|
+
: hexString;
|
|
21
|
+
let text = '';
|
|
22
|
+
// Ensure we only process complete pairs by rounding down to the nearest even length
|
|
23
|
+
const length = normalizedHexString.length - (normalizedHexString.length % 2);
|
|
24
|
+
for (let i = 0; i < length; i += 2) {
|
|
25
|
+
const hexCode = normalizedHexString.substring(i, i + 2);
|
|
26
|
+
const decimal = parseInt(hexCode, 16);
|
|
27
|
+
text += String.fromCharCode(decimal);
|
|
28
|
+
}
|
|
29
|
+
return text;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.hexToString = hexToString;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a hexadecimal string to a regular string by interpreting each pair of characters in the
|
|
3
|
+
* hexadecimal string as a byte in ASCII. It automatically handles hex strings prefixed with '0x'.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} hexString - The hexadecimal string to convert. It can optionally start with '0x'.
|
|
6
|
+
* @returns {string} The decoded ASCII string.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* hexToString('68656c6c6f'); // returns 'hello'
|
|
10
|
+
* hexToString('0x68656c6c6f'); // also returns 'hello'
|
|
11
|
+
*/
|
|
12
|
+
export declare const hexToString: (hexString: string) => string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/**
|
|
3
|
+
* Converts a hexadecimal string to a regular string by interpreting each pair of characters in the
|
|
4
|
+
* hexadecimal string as a byte in ASCII. It automatically handles hex strings prefixed with '0x'.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} hexString - The hexadecimal string to convert. It can optionally start with '0x'.
|
|
7
|
+
* @returns {string} The decoded ASCII string.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* hexToString('68656c6c6f'); // returns 'hello'
|
|
11
|
+
* hexToString('0x68656c6c6f'); // also returns 'hello'
|
|
12
|
+
*/
|
|
13
|
+
const hexToString = (hexString) => {
|
|
14
|
+
const normalizedHexString = hexString.startsWith('0x')
|
|
15
|
+
? hexString.substring(2)
|
|
16
|
+
: hexString;
|
|
17
|
+
let text = '';
|
|
18
|
+
// Ensure we only process complete pairs by rounding down to the nearest even length
|
|
19
|
+
const length = normalizedHexString.length - (normalizedHexString.length % 2);
|
|
20
|
+
for (let i = 0; i < length; i += 2) {
|
|
21
|
+
const hexCode = normalizedHexString.substring(i, i + 2);
|
|
22
|
+
const decimal = parseInt(hexCode, 16);
|
|
23
|
+
text += String.fromCharCode(decimal);
|
|
24
|
+
}
|
|
25
|
+
return text;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { hexToString };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { hexToString } from './hexToString';
|
package/src/index.cjs
CHANGED
|
@@ -43,7 +43,6 @@ var bufferToBase64 = require('./bufferToBase64.cjs');
|
|
|
43
43
|
var last = require('./last.cjs');
|
|
44
44
|
var getProvidersFromWindow = require('./getProvidersFromWindow.cjs');
|
|
45
45
|
var sleep = require('./sleep/sleep.cjs');
|
|
46
|
-
var getOrMapViemChain = require('./getOrMapViemChain.cjs');
|
|
47
46
|
var retryableFn = require('./retryableFn.cjs');
|
|
48
47
|
var wrapMethodWithCallback = require('./wrapMethodWithCallback/wrapMethodWithCallback.cjs');
|
|
49
48
|
var DeferredPromise = require('./DeferredPromise/DeferredPromise.cjs');
|
|
@@ -61,6 +60,8 @@ var createBrowserPlatformService = require('./services/PlatformService/createBro
|
|
|
61
60
|
var FetchService = require('./services/FetchService/FetchService.cjs');
|
|
62
61
|
var template = require('./template/template.cjs');
|
|
63
62
|
var get = require('./get/get.cjs');
|
|
63
|
+
var hexToString = require('./hexToString/hexToString.cjs');
|
|
64
|
+
var isHex = require('./isHex/isHex.cjs');
|
|
64
65
|
|
|
65
66
|
|
|
66
67
|
|
|
@@ -115,9 +116,6 @@ exports.bufferToBase64 = bufferToBase64.bufferToBase64;
|
|
|
115
116
|
exports.last = last.last;
|
|
116
117
|
exports.getProvidersFromWindow = getProvidersFromWindow.getProvidersFromWindow;
|
|
117
118
|
exports.sleep = sleep.sleep;
|
|
118
|
-
exports.getChain = getOrMapViemChain.getChain;
|
|
119
|
-
exports.getOrMapViemChain = getOrMapViemChain.getOrMapViemChain;
|
|
120
|
-
exports.mapChain = getOrMapViemChain.mapChain;
|
|
121
119
|
exports.FALLBACK_UNDEFINED = retryableFn.FALLBACK_UNDEFINED;
|
|
122
120
|
exports.retryableFn = retryableFn.retryableFn;
|
|
123
121
|
exports.wrapMethodWithCallback = wrapMethodWithCallback.wrapMethodWithCallback;
|
|
@@ -136,3 +134,5 @@ exports.createBrowserPlatformService = createBrowserPlatformService.createBrowse
|
|
|
136
134
|
exports.FetchService = FetchService.FetchService;
|
|
137
135
|
exports.template = template.template;
|
|
138
136
|
exports.get = get.get;
|
|
137
|
+
exports.hexToString = hexToString.hexToString;
|
|
138
|
+
exports.isHex = isHex.isHex;
|
package/src/index.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export * from './bufferToBase64';
|
|
|
9
9
|
export * from './last';
|
|
10
10
|
export * from './getProvidersFromWindow';
|
|
11
11
|
export * from './sleep';
|
|
12
|
-
export * from './getOrMapViemChain';
|
|
13
12
|
export * from './retryableFn';
|
|
14
13
|
export * from './wrapMethodWithCallback';
|
|
15
14
|
export * from './DeferredPromise';
|
|
@@ -26,3 +25,5 @@ export { PlatformService, createBrowserPlatformService, type IPlatformService, }
|
|
|
26
25
|
export { FetchService } from './services/FetchService';
|
|
27
26
|
export { template } from './template';
|
|
28
27
|
export { get } from './get';
|
|
28
|
+
export { hexToString } from './hexToString';
|
|
29
|
+
export { isHex } from './isHex';
|
package/src/index.js
CHANGED
|
@@ -39,7 +39,6 @@ export { bufferToBase64 } from './bufferToBase64.js';
|
|
|
39
39
|
export { last } from './last.js';
|
|
40
40
|
export { getProvidersFromWindow } from './getProvidersFromWindow.js';
|
|
41
41
|
export { sleep } from './sleep/sleep.js';
|
|
42
|
-
export { getChain, getOrMapViemChain, mapChain } from './getOrMapViemChain.js';
|
|
43
42
|
export { FALLBACK_UNDEFINED, retryableFn } from './retryableFn.js';
|
|
44
43
|
export { wrapMethodWithCallback } from './wrapMethodWithCallback/wrapMethodWithCallback.js';
|
|
45
44
|
export { DeferredPromise } from './DeferredPromise/DeferredPromise.js';
|
|
@@ -57,3 +56,5 @@ export { createBrowserPlatformService } from './services/PlatformService/createB
|
|
|
57
56
|
export { FetchService } from './services/FetchService/FetchService.js';
|
|
58
57
|
export { template } from './template/template.js';
|
|
59
58
|
export { get } from './get/get.js';
|
|
59
|
+
export { hexToString } from './hexToString/hexToString.js';
|
|
60
|
+
export { isHex } from './isHex/isHex.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { isHex } from './isHex';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Checks if the provided string is a valid hexadecimal string.
|
|
8
|
+
* @param str The string to check.
|
|
9
|
+
* @returns `true` if the string is a valid hexadecimal string, `false` otherwise.
|
|
10
|
+
*/
|
|
11
|
+
const isHex = (str) => {
|
|
12
|
+
if (typeof str !== 'string') {
|
|
13
|
+
throw new Error('Input must be a string');
|
|
14
|
+
}
|
|
15
|
+
const normalizedStr = str.startsWith('0x') ? str.substring(2) : str;
|
|
16
|
+
const regex = /^[0-9a-fA-F]+$/;
|
|
17
|
+
return regex.test(normalizedStr);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.isHex = isHex;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the provided string is a valid hexadecimal string.
|
|
4
|
+
* @param str The string to check.
|
|
5
|
+
* @returns `true` if the string is a valid hexadecimal string, `false` otherwise.
|
|
6
|
+
*/
|
|
7
|
+
const isHex = (str) => {
|
|
8
|
+
if (typeof str !== 'string') {
|
|
9
|
+
throw new Error('Input must be a string');
|
|
10
|
+
}
|
|
11
|
+
const normalizedStr = str.startsWith('0x') ? str.substring(2) : str;
|
|
12
|
+
const regex = /^[0-9a-fA-F]+$/;
|
|
13
|
+
return regex.test(normalizedStr);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { isHex };
|
package/src/retryableFn.cjs
CHANGED
|
@@ -9,7 +9,6 @@ require('./errors/TransactionGasCannotBeSponsoredError.cjs');
|
|
|
9
9
|
require('./logger/logger.cjs');
|
|
10
10
|
require('./bufferPolyfill.cjs');
|
|
11
11
|
var sleep = require('./sleep/sleep.cjs');
|
|
12
|
-
require('viem/chains');
|
|
13
12
|
require('tldts');
|
|
14
13
|
|
|
15
14
|
const FALLBACK_UNDEFINED = 'FALLBACK_UNDEFINED';
|
package/src/retryableFn.js
CHANGED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var chains = require('viem/chains');
|
|
7
|
-
|
|
8
|
-
function _interopNamespace(e) {
|
|
9
|
-
if (e && e.__esModule) return e;
|
|
10
|
-
var n = Object.create(null);
|
|
11
|
-
if (e) {
|
|
12
|
-
Object.keys(e).forEach(function (k) {
|
|
13
|
-
if (k !== 'default') {
|
|
14
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () { return e[k]; }
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
n["default"] = e;
|
|
23
|
-
return Object.freeze(n);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var chains__namespace = /*#__PURE__*/_interopNamespace(chains);
|
|
27
|
-
|
|
28
|
-
// eslint-disable-next-line import/no-namespace
|
|
29
|
-
/**
|
|
30
|
-
* Gets the chain object for the given chain id.
|
|
31
|
-
* @param chainId - Chain id of the target EVM chain.
|
|
32
|
-
* @returns Viem's chain object.
|
|
33
|
-
*/
|
|
34
|
-
const getChain = (chainId) => {
|
|
35
|
-
for (const chain of Object.values(chains__namespace)) {
|
|
36
|
-
if ('id' in chain) {
|
|
37
|
-
if (chain.id === chainId) {
|
|
38
|
-
return chain;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
throw new Error(`Chain with id ${chainId} not found`);
|
|
43
|
-
};
|
|
44
|
-
const mapChain = (network) => {
|
|
45
|
-
var _a;
|
|
46
|
-
return ({
|
|
47
|
-
blockExplorers: ((_a = network.blockExplorerUrls) === null || _a === void 0 ? void 0 : _a[0])
|
|
48
|
-
? {
|
|
49
|
-
default: {
|
|
50
|
-
name: network.blockExplorerUrls[0],
|
|
51
|
-
url: network.blockExplorerUrls[0],
|
|
52
|
-
},
|
|
53
|
-
}
|
|
54
|
-
: undefined,
|
|
55
|
-
id: network.chainId,
|
|
56
|
-
name: network.vanityName || network.name || network.chainName,
|
|
57
|
-
nativeCurrency: network.nativeCurrency,
|
|
58
|
-
rpcUrls: {
|
|
59
|
-
default: { http: network.rpcUrls },
|
|
60
|
-
public: { http: network.rpcUrls },
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
const getOrMapViemChain = (network) => {
|
|
65
|
-
let chain;
|
|
66
|
-
try {
|
|
67
|
-
chain = getChain(network.chainId);
|
|
68
|
-
}
|
|
69
|
-
catch (_a) {
|
|
70
|
-
chain = mapChain(network);
|
|
71
|
-
}
|
|
72
|
-
return chain;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
exports.getChain = getChain;
|
|
76
|
-
exports.getOrMapViemChain = getOrMapViemChain;
|
|
77
|
-
exports.mapChain = mapChain;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Chain } from 'viem';
|
|
2
|
-
import * as chains from 'viem/chains';
|
|
3
|
-
import { EvmNetwork } from '@dynamic-labs/types';
|
|
4
|
-
/**
|
|
5
|
-
* Gets the chain object for the given chain id.
|
|
6
|
-
* @param chainId - Chain id of the target EVM chain.
|
|
7
|
-
* @returns Viem's chain object.
|
|
8
|
-
*/
|
|
9
|
-
export declare const getChain: (chainId: number) => chains.Chain;
|
|
10
|
-
export declare const mapChain: (network: EvmNetwork) => Chain;
|
|
11
|
-
export declare const getOrMapViemChain: (network: EvmNetwork) => Chain;
|
package/src/getOrMapViemChain.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import * as chains from 'viem/chains';
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line import/no-namespace
|
|
5
|
-
/**
|
|
6
|
-
* Gets the chain object for the given chain id.
|
|
7
|
-
* @param chainId - Chain id of the target EVM chain.
|
|
8
|
-
* @returns Viem's chain object.
|
|
9
|
-
*/
|
|
10
|
-
const getChain = (chainId) => {
|
|
11
|
-
for (const chain of Object.values(chains)) {
|
|
12
|
-
if ('id' in chain) {
|
|
13
|
-
if (chain.id === chainId) {
|
|
14
|
-
return chain;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
throw new Error(`Chain with id ${chainId} not found`);
|
|
19
|
-
};
|
|
20
|
-
const mapChain = (network) => {
|
|
21
|
-
var _a;
|
|
22
|
-
return ({
|
|
23
|
-
blockExplorers: ((_a = network.blockExplorerUrls) === null || _a === void 0 ? void 0 : _a[0])
|
|
24
|
-
? {
|
|
25
|
-
default: {
|
|
26
|
-
name: network.blockExplorerUrls[0],
|
|
27
|
-
url: network.blockExplorerUrls[0],
|
|
28
|
-
},
|
|
29
|
-
}
|
|
30
|
-
: undefined,
|
|
31
|
-
id: network.chainId,
|
|
32
|
-
name: network.vanityName || network.name || network.chainName,
|
|
33
|
-
nativeCurrency: network.nativeCurrency,
|
|
34
|
-
rpcUrls: {
|
|
35
|
-
default: { http: network.rpcUrls },
|
|
36
|
-
public: { http: network.rpcUrls },
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
const getOrMapViemChain = (network) => {
|
|
41
|
-
let chain;
|
|
42
|
-
try {
|
|
43
|
-
chain = getChain(network.chainId);
|
|
44
|
-
}
|
|
45
|
-
catch (_a) {
|
|
46
|
-
chain = mapChain(network);
|
|
47
|
-
}
|
|
48
|
-
return chain;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export { getChain, getOrMapViemChain, mapChain };
|