@dynamic-labs/utils 3.0.0-alpha.4 → 3.0.0-alpha.6

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 CHANGED
@@ -1,4 +1,45 @@
1
1
 
2
+ ## [3.0.0-alpha.6](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.5...v3.0.0-alpha.6) (2024-06-18)
3
+
4
+
5
+ ### Features
6
+
7
+ * implement useExternalAuth hook to signin using external jwt auth ([#6039](https://github.com/dynamic-labs/DynamicAuth/issues/6039)) ([ba90908](https://github.com/dynamic-labs/DynamicAuth/commit/ba90908509ec21f708a4a0782a7f94861fc3b484))
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * allow sign-in with different ME BTC wallet after initial connection ([a527b46](https://github.com/dynamic-labs/DynamicAuth/commit/a527b464f321b4fc27730f57c3812e996b5ed878))
13
+ * close sign modal when signing in with a wallet when embedded wallet is enabled ([#6013](https://github.com/dynamic-labs/DynamicAuth/issues/6013)) ([0f4f3c8](https://github.com/dynamic-labs/DynamicAuth/commit/0f4f3c83db162f7a1794a3549b60bbad6b03e2c0))
14
+ * custom network without a valid icon should still display its name in network picker ([#6018](https://github.com/dynamic-labs/DynamicAuth/issues/6018)) ([0b10df6](https://github.com/dynamic-labs/DynamicAuth/commit/0b10df68950bfc9b8492443158a6bb030dc1122c))
15
+ * e2e: remove page pause ([#6045](https://github.com/dynamic-labs/DynamicAuth/issues/6045)) ([55bba00](https://github.com/dynamic-labs/DynamicAuth/commit/55bba0034255055d6ae266b1296542f47ed48e2b))
16
+ * more fixes for connect starknet button ([#6046](https://github.com/dynamic-labs/DynamicAuth/issues/6046)) ([0fb570a](https://github.com/dynamic-labs/DynamicAuth/commit/0fb570a44e65f8dd6d4d2bf5edb2ee54985ec9d4))
17
+ * set verified credentials on embedded wallet creation ([#6044](https://github.com/dynamic-labs/DynamicAuth/issues/6044)) ([b52a96d](https://github.com/dynamic-labs/DynamicAuth/commit/b52a96d321e7efdb30dce9cdb3f6f176c24ceb81))
18
+
19
+ ## [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)
20
+
21
+
22
+ ### ⚠ BREAKING CHANGES
23
+
24
+ * remove viem dependency from non-evm packages (#5508)
25
+ * move rpc providers into their own packages (#5981)
26
+
27
+ ### Features
28
+
29
+ * 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))
30
+ * 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))
31
+
32
+
33
+ ### Bug Fixes
34
+
35
+ * 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))
36
+ * 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))
37
+ * 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))
38
+ * 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))
39
+
40
+
41
+ * 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))
42
+
2
43
  ## [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)
3
44
 
4
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/utils",
3
- "version": "3.0.0-alpha.4",
3
+ "version": "3.0.0-alpha.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
@@ -26,13 +26,12 @@
26
26
  "./package.json": "./package.json"
27
27
  },
28
28
  "dependencies": {
29
- "@dynamic-labs/sdk-api-core": "0.0.461",
29
+ "@dynamic-labs/sdk-api-core": "0.0.470",
30
30
  "tldts": "6.0.16",
31
- "@dynamic-labs/logger": "3.0.0-alpha.4",
32
- "@dynamic-labs/types": "3.0.0-alpha.4",
33
- "buffer": "6.0.3"
31
+ "@dynamic-labs/logger": "3.0.0-alpha.6",
32
+ "@dynamic-labs/types": "3.0.0-alpha.6",
33
+ "buffer": "6.0.3",
34
+ "stream": "0.0.2"
34
35
  },
35
- "peerDependencies": {
36
- "viem": "^2.7.6"
37
- }
36
+ "peerDependencies": {}
38
37
  }
@@ -0,0 +1,40 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const isEip9693Event = (event) => event.type === 'eip6963:announceProvider' &&
7
+ event.detail !== undefined;
8
+ class Eip6963Provider {
9
+ constructor() {
10
+ this.providers = [];
11
+ }
12
+ registerProviders() {
13
+ if (typeof window === 'undefined') {
14
+ return;
15
+ }
16
+ window.addEventListener('eip6963:announceProvider', (event) => {
17
+ if (!isEip9693Event(event)) {
18
+ return;
19
+ }
20
+ this.providers.push(event.detail);
21
+ });
22
+ window.dispatchEvent(new Event('eip6963:requestProvider'));
23
+ }
24
+ }
25
+ class Eip6963ProviderSingleton {
26
+ constructor() {
27
+ this.eip6963Provider = new Eip6963Provider();
28
+ }
29
+ static get() {
30
+ var _a;
31
+ if (!((_a = Eip6963ProviderSingleton.instance) === null || _a === void 0 ? void 0 : _a.eip6963Provider)) {
32
+ Eip6963ProviderSingleton.instance = new Eip6963ProviderSingleton();
33
+ Eip6963ProviderSingleton.instance.eip6963Provider.registerProviders();
34
+ }
35
+ return Eip6963ProviderSingleton.instance.eip6963Provider;
36
+ }
37
+ }
38
+
39
+ exports.Eip6963Provider = Eip6963Provider;
40
+ exports.Eip6963ProviderSingleton = Eip6963ProviderSingleton;
@@ -0,0 +1,34 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { EventEmitter } from 'stream';
4
+ export type IEthereum = {
5
+ [key: string]: any;
6
+ providers?: object[];
7
+ request: <T extends string>(params: {
8
+ method: T;
9
+ } | object) => Promise<T extends 'eth_requestAccounts' ? [string] : object>;
10
+ } & EventEmitter;
11
+ /**
12
+ * Represents the assets needed to display a wallet
13
+ */
14
+ type Eip6963ProviderInfo = {
15
+ uuid: string;
16
+ name: string;
17
+ icon: string;
18
+ rdns: string;
19
+ };
20
+ type Eip6963ProviderDetail = {
21
+ info: Eip6963ProviderInfo;
22
+ provider: IEthereum;
23
+ };
24
+ export declare class Eip6963Provider {
25
+ providers: Eip6963ProviderDetail[];
26
+ registerProviders(): void;
27
+ }
28
+ export declare class Eip6963ProviderSingleton {
29
+ readonly eip6963Provider: Eip6963Provider;
30
+ private constructor();
31
+ private static instance;
32
+ static get(): Eip6963Provider;
33
+ }
34
+ export {};
@@ -0,0 +1,35 @@
1
+ 'use client'
2
+ const isEip9693Event = (event) => event.type === 'eip6963:announceProvider' &&
3
+ event.detail !== undefined;
4
+ class Eip6963Provider {
5
+ constructor() {
6
+ this.providers = [];
7
+ }
8
+ registerProviders() {
9
+ if (typeof window === 'undefined') {
10
+ return;
11
+ }
12
+ window.addEventListener('eip6963:announceProvider', (event) => {
13
+ if (!isEip9693Event(event)) {
14
+ return;
15
+ }
16
+ this.providers.push(event.detail);
17
+ });
18
+ window.dispatchEvent(new Event('eip6963:requestProvider'));
19
+ }
20
+ }
21
+ class Eip6963ProviderSingleton {
22
+ constructor() {
23
+ this.eip6963Provider = new Eip6963Provider();
24
+ }
25
+ static get() {
26
+ var _a;
27
+ if (!((_a = Eip6963ProviderSingleton.instance) === null || _a === void 0 ? void 0 : _a.eip6963Provider)) {
28
+ Eip6963ProviderSingleton.instance = new Eip6963ProviderSingleton();
29
+ Eip6963ProviderSingleton.instance.eip6963Provider.registerProviders();
30
+ }
31
+ return Eip6963ProviderSingleton.instance.eip6963Provider;
32
+ }
33
+ }
34
+
35
+ export { Eip6963Provider, Eip6963ProviderSingleton };
@@ -0,0 +1 @@
1
+ export * from './eip6963Provider';
@@ -0,0 +1,14 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var DynamicError = require('./DynamicError.cjs');
7
+
8
+ class ExternalAuthError extends DynamicError.DynamicError {
9
+ constructor(code) {
10
+ super('ExternalAuthError', code);
11
+ }
12
+ }
13
+
14
+ exports.ExternalAuthError = ExternalAuthError;
@@ -0,0 +1,4 @@
1
+ import { DynamicError } from './DynamicError';
2
+ export declare class ExternalAuthError extends DynamicError {
3
+ constructor(code: string);
4
+ }
@@ -0,0 +1,10 @@
1
+ 'use client'
2
+ import { DynamicError } from './DynamicError.js';
3
+
4
+ class ExternalAuthError extends DynamicError {
5
+ constructor(code) {
6
+ super('ExternalAuthError', code);
7
+ }
8
+ }
9
+
10
+ export { ExternalAuthError };
@@ -29,3 +29,4 @@ export * from './CookieInvalidError';
29
29
  export * from './AccessBlockedError';
30
30
  export * from './EmbeddedWalletException';
31
31
  export * from './MfaInvalidOtpError';
32
+ export * from './ExternalAuthError';
@@ -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, }) => {
package/src/index.cjs CHANGED
@@ -35,6 +35,7 @@ var CookieInvalidError = require('./errors/CookieInvalidError.cjs');
35
35
  var AccessBlockedError = require('./errors/AccessBlockedError.cjs');
36
36
  var EmbeddedWalletException = require('./errors/EmbeddedWalletException.cjs');
37
37
  var MfaInvalidOtpError = require('./errors/MfaInvalidOtpError.cjs');
38
+ var ExternalAuthError = require('./errors/ExternalAuthError.cjs');
38
39
  var CancellablePromise = require('./CancellablePromise/CancellablePromise.cjs');
39
40
  var isFunction = require('./isFunction/isFunction.cjs');
40
41
  var isMobile = require('./isMobile.cjs');
@@ -43,7 +44,6 @@ var bufferToBase64 = require('./bufferToBase64.cjs');
43
44
  var last = require('./last.cjs');
44
45
  var getProvidersFromWindow = require('./getProvidersFromWindow.cjs');
45
46
  var sleep = require('./sleep/sleep.cjs');
46
- var getOrMapViemChain = require('./getOrMapViemChain.cjs');
47
47
  var retryableFn = require('./retryableFn.cjs');
48
48
  var wrapMethodWithCallback = require('./wrapMethodWithCallback/wrapMethodWithCallback.cjs');
49
49
  var DeferredPromise = require('./DeferredPromise/DeferredPromise.cjs');
@@ -55,6 +55,7 @@ var formatNumberText = require('./formatNumberText/formatNumberText.cjs');
55
55
  var ceil = require('./ceil/ceil.cjs');
56
56
  var trimEnd = require('./trimEnd/trimEnd.cjs');
57
57
  var isLedgerAddressViaVerifiedCredentials = require('./isLedgerAddressViaVerifiedCredentials.cjs');
58
+ var eip6963Provider = require('./eip6963/eip6963Provider.cjs');
58
59
  var runSafe = require('./runSafe/runSafe.cjs');
59
60
  var PlatformService = require('./services/PlatformService/PlatformService.cjs');
60
61
  var createBrowserPlatformService = require('./services/PlatformService/createBrowserPlatformService/createBrowserPlatformService.cjs');
@@ -98,6 +99,7 @@ exports.CookieInvalidError = CookieInvalidError.CookieInvalidError;
98
99
  exports.AccessBlockedError = AccessBlockedError.AccessBlockedError;
99
100
  exports.EmbeddedWalletException = EmbeddedWalletException.EmbeddedWalletException;
100
101
  exports.MfaInvalidOtpError = MfaInvalidOtpError.MfaInvalidOtpError;
102
+ exports.ExternalAuthError = ExternalAuthError.ExternalAuthError;
101
103
  exports.CancellablePromise = CancellablePromise.CancellablePromise;
102
104
  exports.isFunction = isFunction.isFunction;
103
105
  exports.getAndroidVersion = isMobile.getAndroidVersion;
@@ -117,9 +119,6 @@ exports.bufferToBase64 = bufferToBase64.bufferToBase64;
117
119
  exports.last = last.last;
118
120
  exports.getProvidersFromWindow = getProvidersFromWindow.getProvidersFromWindow;
119
121
  exports.sleep = sleep.sleep;
120
- exports.getChain = getOrMapViemChain.getChain;
121
- exports.getOrMapViemChain = getOrMapViemChain.getOrMapViemChain;
122
- exports.mapChain = getOrMapViemChain.mapChain;
123
122
  exports.FALLBACK_UNDEFINED = retryableFn.FALLBACK_UNDEFINED;
124
123
  exports.retryableFn = retryableFn.retryableFn;
125
124
  exports.wrapMethodWithCallback = wrapMethodWithCallback.wrapMethodWithCallback;
@@ -132,6 +131,8 @@ exports.formatNumberText = formatNumberText.formatNumberText;
132
131
  exports.ceil = ceil.ceil;
133
132
  exports.trimEnd = trimEnd.trimEnd;
134
133
  exports.isLedgerAddressViaVerifiedCredentials = isLedgerAddressViaVerifiedCredentials.isLedgerAddressViaVerifiedCredentials;
134
+ exports.Eip6963Provider = eip6963Provider.Eip6963Provider;
135
+ exports.Eip6963ProviderSingleton = eip6963Provider.Eip6963ProviderSingleton;
135
136
  exports.runSafe = runSafe.runSafe;
136
137
  exports.PlatformService = PlatformService.PlatformService;
137
138
  exports.createBrowserPlatformService = createBrowserPlatformService.createBrowserPlatformService;
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';
@@ -21,6 +20,7 @@ export * from './formatNumberText';
21
20
  export * from './ceil';
22
21
  export * from './trimEnd';
23
22
  export * from './isLedgerAddressViaVerifiedCredentials';
23
+ export * from './eip6963';
24
24
  export { runSafe } from './runSafe';
25
25
  export { PlatformService, createBrowserPlatformService, type IPlatformService, } from './services/PlatformService';
26
26
  export { FetchService } from './services/FetchService';
package/src/index.js CHANGED
@@ -31,6 +31,7 @@ export { CookieInvalidError } from './errors/CookieInvalidError.js';
31
31
  export { AccessBlockedError } from './errors/AccessBlockedError.js';
32
32
  export { EmbeddedWalletException } from './errors/EmbeddedWalletException.js';
33
33
  export { MfaInvalidOtpError } from './errors/MfaInvalidOtpError.js';
34
+ export { ExternalAuthError } from './errors/ExternalAuthError.js';
34
35
  export { CancellablePromise } from './CancellablePromise/CancellablePromise.js';
35
36
  export { isFunction } from './isFunction/isFunction.js';
36
37
  export { getAndroidVersion, isAndroid, isIOS, isIPad, isIPhone, isIPhone8OrEarlier, isLegacySafari, isMobile, isSamsungBrowser, isWindows } from './isMobile.js';
@@ -39,7 +40,6 @@ export { bufferToBase64 } from './bufferToBase64.js';
39
40
  export { last } from './last.js';
40
41
  export { getProvidersFromWindow } from './getProvidersFromWindow.js';
41
42
  export { sleep } from './sleep/sleep.js';
42
- export { getChain, getOrMapViemChain, mapChain } from './getOrMapViemChain.js';
43
43
  export { FALLBACK_UNDEFINED, retryableFn } from './retryableFn.js';
44
44
  export { wrapMethodWithCallback } from './wrapMethodWithCallback/wrapMethodWithCallback.js';
45
45
  export { DeferredPromise } from './DeferredPromise/DeferredPromise.js';
@@ -51,6 +51,7 @@ export { formatNumberText } from './formatNumberText/formatNumberText.js';
51
51
  export { ceil } from './ceil/ceil.js';
52
52
  export { trimEnd } from './trimEnd/trimEnd.js';
53
53
  export { isLedgerAddressViaVerifiedCredentials } from './isLedgerAddressViaVerifiedCredentials.js';
54
+ export { Eip6963Provider, Eip6963ProviderSingleton } from './eip6963/eip6963Provider.js';
54
55
  export { runSafe } from './runSafe/runSafe.js';
55
56
  export { PlatformService } from './services/PlatformService/PlatformService.js';
56
57
  export { createBrowserPlatformService } from './services/PlatformService/createBrowserPlatformService/createBrowserPlatformService.js';
@@ -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';
@@ -5,7 +5,6 @@ import './errors/TransactionGasCannotBeSponsoredError.js';
5
5
  import './logger/logger.js';
6
6
  import './bufferPolyfill.js';
7
7
  import { sleep } from './sleep/sleep.js';
8
- import 'viem/chains';
9
8
  import 'tldts';
10
9
 
11
10
  const FALLBACK_UNDEFINED = 'FALLBACK_UNDEFINED';
@@ -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;
@@ -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 };