@metamask/multichain-network-controller 0.1.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/CHANGELOG.md +19 -0
- package/LICENSE +20 -0
- package/README.md +15 -0
- package/dist/MultichainNetworkController.cjs +130 -0
- package/dist/MultichainNetworkController.cjs.map +1 -0
- package/dist/MultichainNetworkController.d.cts +22 -0
- package/dist/MultichainNetworkController.d.cts.map +1 -0
- package/dist/MultichainNetworkController.d.mts +22 -0
- package/dist/MultichainNetworkController.d.mts.map +1 -0
- package/dist/MultichainNetworkController.mjs +126 -0
- package/dist/MultichainNetworkController.mjs.map +1 -0
- package/dist/constants.cjs +61 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +39 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +39 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +57 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.cjs +5 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +117 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +117 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.cjs +71 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +41 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +41 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +63 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../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EAAE,SAAS,EAAE,IAAI,EAAE;IAC5E,gCAAgC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;IACpE,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;CACQ,CAAC","sourcesContent":["import { type StateMetadata } from '@metamask/base-controller';\nimport { BtcScope, SolScope } from '@metamask/keyring-api';\nimport { NetworkStatus } from '@metamask/network-controller';\n\nimport type {\n MultichainNetworkConfiguration,\n MultichainNetworkControllerState,\n MultichainNetworkMetadata,\n SupportedCaipChainId,\n} from './types';\n\nexport const BTC_NATIVE_ASSET = `${BtcScope.Mainnet}/slip44:0`;\nexport const SOL_NATIVE_ASSET = `${SolScope.Mainnet}/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v`;\n\n/**\n * Supported networks by the MultichainNetworkController\n */\nexport const AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS: Record<\n SupportedCaipChainId,\n MultichainNetworkConfiguration\n> = {\n [BtcScope.Mainnet]: {\n chainId: BtcScope.Mainnet,\n name: 'Bitcoin Mainnet',\n nativeCurrency: BTC_NATIVE_ASSET,\n isEvm: false,\n },\n [SolScope.Mainnet]: {\n chainId: SolScope.Mainnet,\n name: 'Solana Mainnet',\n nativeCurrency: SOL_NATIVE_ASSET,\n isEvm: false,\n },\n};\n\n/**\n * Metadata for the supported networks.\n */\nexport const NETWORKS_METADATA: Record<string, MultichainNetworkMetadata> = {\n [BtcScope.Mainnet]: {\n features: [],\n status: NetworkStatus.Available,\n },\n [SolScope.Mainnet]: {\n features: [],\n status: NetworkStatus.Available,\n },\n};\n\n/**\n * Default state of the {@link MultichainNetworkController}.\n *\n * @returns The default state of the {@link MultichainNetworkController}.\n */\nexport const getDefaultMultichainNetworkControllerState =\n (): MultichainNetworkControllerState => ({\n multichainNetworkConfigurationsByChainId:\n AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS,\n selectedMultichainNetworkChainId: SolScope.Mainnet,\n isEvmSelected: true,\n });\n\n/**\n * {@link MultichainNetworkController}'s metadata.\n *\n * This allows us to choose if fields of the state should be persisted or not\n * using the `persist` flag; and if they can be sent to Sentry or not, using\n * the `anonymous` flag.\n */\nexport const MULTICHAIN_NETWORK_CONTROLLER_METADATA = {\n multichainNetworkConfigurationsByChainId: { persist: true, anonymous: true },\n selectedMultichainNetworkChainId: { persist: true, anonymous: true },\n isEvmSelected: { persist: true, anonymous: true },\n} satisfies StateMetadata<MultichainNetworkControllerState>;\n"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toEvmCaipChainId = exports.toMultichainNetworkConfigurationsByChainId = exports.toMultichainNetworkConfiguration = exports.checkIfSupportedCaipChainId = exports.getDefaultMultichainNetworkControllerState = exports.MultichainNetworkController = void 0;
|
|
4
|
+
var MultichainNetworkController_1 = require("./MultichainNetworkController.cjs");
|
|
5
|
+
Object.defineProperty(exports, "MultichainNetworkController", { enumerable: true, get: function () { return MultichainNetworkController_1.MultichainNetworkController; } });
|
|
6
|
+
var constants_1 = require("./constants.cjs");
|
|
7
|
+
Object.defineProperty(exports, "getDefaultMultichainNetworkControllerState", { enumerable: true, get: function () { return constants_1.getDefaultMultichainNetworkControllerState; } });
|
|
8
|
+
var utils_1 = require("./utils.cjs");
|
|
9
|
+
Object.defineProperty(exports, "checkIfSupportedCaipChainId", { enumerable: true, get: function () { return utils_1.checkIfSupportedCaipChainId; } });
|
|
10
|
+
Object.defineProperty(exports, "toMultichainNetworkConfiguration", { enumerable: true, get: function () { return utils_1.toMultichainNetworkConfiguration; } });
|
|
11
|
+
Object.defineProperty(exports, "toMultichainNetworkConfigurationsByChainId", { enumerable: true, get: function () { return utils_1.toMultichainNetworkConfigurationsByChainId; } });
|
|
12
|
+
Object.defineProperty(exports, "toEvmCaipChainId", { enumerable: true, get: function () { return utils_1.toEvmCaipChainId; } });
|
|
13
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iFAA4E;AAAnE,0IAAA,2BAA2B,OAAA;AACpC,6CAAyE;AAAhE,uIAAA,0CAA0C,OAAA;AAiBnD,qCAKiB;AAJf,oHAAA,2BAA2B,OAAA;AAC3B,yHAAA,gCAAgC,OAAA;AAChC,mIAAA,0CAA0C,OAAA;AAC1C,yGAAA,gBAAgB,OAAA","sourcesContent":["export { MultichainNetworkController } from './MultichainNetworkController';\nexport { getDefaultMultichainNetworkControllerState } from './constants';\nexport type {\n MultichainNetworkMetadata,\n SupportedCaipChainId,\n CommonNetworkConfiguration,\n NonEvmNetworkConfiguration,\n EvmNetworkConfiguration,\n MultichainNetworkConfiguration,\n MultichainNetworkControllerState,\n MultichainNetworkControllerGetStateAction,\n MultichainNetworkControllerSetActiveNetworkAction,\n MultichainNetworkControllerStateChange,\n MultichainNetworkControllerNetworkDidChangeEvent,\n MultichainNetworkControllerActions,\n MultichainNetworkControllerEvents,\n MultichainNetworkControllerMessenger,\n} from './types';\nexport {\n checkIfSupportedCaipChainId,\n toMultichainNetworkConfiguration,\n toMultichainNetworkConfigurationsByChainId,\n toEvmCaipChainId,\n} from './utils';\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MultichainNetworkController } from "./MultichainNetworkController.cjs";
|
|
2
|
+
export { getDefaultMultichainNetworkControllerState } from "./constants.cjs";
|
|
3
|
+
export type { MultichainNetworkMetadata, SupportedCaipChainId, CommonNetworkConfiguration, NonEvmNetworkConfiguration, EvmNetworkConfiguration, MultichainNetworkConfiguration, MultichainNetworkControllerState, MultichainNetworkControllerGetStateAction, MultichainNetworkControllerSetActiveNetworkAction, MultichainNetworkControllerStateChange, MultichainNetworkControllerNetworkDidChangeEvent, MultichainNetworkControllerActions, MultichainNetworkControllerEvents, MultichainNetworkControllerMessenger, } from "./types.cjs";
|
|
4
|
+
export { checkIfSupportedCaipChainId, toMultichainNetworkConfiguration, toMultichainNetworkConfigurationsByChainId, toEvmCaipChainId, } from "./utils.cjs";
|
|
5
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,0CAAsC;AAC5E,OAAO,EAAE,0CAA0C,EAAE,wBAAoB;AACzE,YAAY,EACV,yBAAyB,EACzB,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB,EACvB,8BAA8B,EAC9B,gCAAgC,EAChC,yCAAyC,EACzC,iDAAiD,EACjD,sCAAsC,EACtC,gDAAgD,EAChD,kCAAkC,EAClC,iCAAiC,EACjC,oCAAoC,GACrC,oBAAgB;AACjB,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,EAChC,0CAA0C,EAC1C,gBAAgB,GACjB,oBAAgB"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MultichainNetworkController } from "./MultichainNetworkController.mjs";
|
|
2
|
+
export { getDefaultMultichainNetworkControllerState } from "./constants.mjs";
|
|
3
|
+
export type { MultichainNetworkMetadata, SupportedCaipChainId, CommonNetworkConfiguration, NonEvmNetworkConfiguration, EvmNetworkConfiguration, MultichainNetworkConfiguration, MultichainNetworkControllerState, MultichainNetworkControllerGetStateAction, MultichainNetworkControllerSetActiveNetworkAction, MultichainNetworkControllerStateChange, MultichainNetworkControllerNetworkDidChangeEvent, MultichainNetworkControllerActions, MultichainNetworkControllerEvents, MultichainNetworkControllerMessenger, } from "./types.mjs";
|
|
4
|
+
export { checkIfSupportedCaipChainId, toMultichainNetworkConfiguration, toMultichainNetworkConfigurationsByChainId, toEvmCaipChainId, } from "./utils.mjs";
|
|
5
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,0CAAsC;AAC5E,OAAO,EAAE,0CAA0C,EAAE,wBAAoB;AACzE,YAAY,EACV,yBAAyB,EACzB,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB,EACvB,8BAA8B,EAC9B,gCAAgC,EAChC,yCAAyC,EACzC,iDAAiD,EACjD,sCAAsC,EACtC,gDAAgD,EAChD,kCAAkC,EAClC,iCAAiC,EACjC,oCAAoC,GACrC,oBAAgB;AACjB,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,EAChC,0CAA0C,EAC1C,gBAAgB,GACjB,oBAAgB"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { MultichainNetworkController } from "./MultichainNetworkController.mjs";
|
|
2
|
+
export { getDefaultMultichainNetworkControllerState } from "./constants.mjs";
|
|
3
|
+
export { checkIfSupportedCaipChainId, toMultichainNetworkConfiguration, toMultichainNetworkConfigurationsByChainId, toEvmCaipChainId } from "./utils.mjs";
|
|
4
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,0CAAsC;AAC5E,OAAO,EAAE,0CAA0C,EAAE,wBAAoB;AAiBzE,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,EAChC,0CAA0C,EAC1C,gBAAgB,EACjB,oBAAgB","sourcesContent":["export { MultichainNetworkController } from './MultichainNetworkController';\nexport { getDefaultMultichainNetworkControllerState } from './constants';\nexport type {\n MultichainNetworkMetadata,\n SupportedCaipChainId,\n CommonNetworkConfiguration,\n NonEvmNetworkConfiguration,\n EvmNetworkConfiguration,\n MultichainNetworkConfiguration,\n MultichainNetworkControllerState,\n MultichainNetworkControllerGetStateAction,\n MultichainNetworkControllerSetActiveNetworkAction,\n MultichainNetworkControllerStateChange,\n MultichainNetworkControllerNetworkDidChangeEvent,\n MultichainNetworkControllerActions,\n MultichainNetworkControllerEvents,\n MultichainNetworkControllerMessenger,\n} from './types';\nexport {\n checkIfSupportedCaipChainId,\n toMultichainNetworkConfiguration,\n toMultichainNetworkConfigurationsByChainId,\n toEvmCaipChainId,\n} from './utils';\n"]}
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAea,QAAA,kCAAkC,GAAG,6BAA6B,CAAC","sourcesContent":["import {\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { BtcScope, CaipChainId, SolScope } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type {\n NetworkStatus,\n NetworkControllerSetActiveNetworkAction,\n NetworkControllerGetStateAction,\n NetworkClientId,\n} from '@metamask/network-controller';\nimport { type CaipAssetType } from '@metamask/utils';\n\nexport const MULTICHAIN_NETWORK_CONTROLLER_NAME = 'MultichainNetworkController';\n\nexport type MultichainNetworkMetadata = {\n features: string[];\n status: NetworkStatus;\n};\n\nexport type SupportedCaipChainId = SolScope.Mainnet | BtcScope.Mainnet;\n\nexport type CommonNetworkConfiguration = {\n /**\n * EVM network flag.\n */\n isEvm: boolean;\n /**\n * The chain ID of the network.\n */\n chainId: CaipChainId;\n /**\n * The name of the network.\n */\n name: string;\n};\n\nexport type NonEvmNetworkConfiguration = CommonNetworkConfiguration & {\n /**\n * EVM network flag.\n */\n isEvm: false;\n /**\n * The native asset type of the network.\n */\n nativeCurrency: CaipAssetType;\n};\n\n// TODO: The controller only supports non-EVM network configurations at the moment\n// Once we support Caip chain IDs for EVM networks, we can re-enable EVM network configurations\nexport type EvmNetworkConfiguration = CommonNetworkConfiguration & {\n /**\n * EVM network flag.\n */\n isEvm: true;\n /**\n * The native asset type of the network.\n * For EVM, this is the network ticker since there is no standard between\n * tickers and Caip IDs.\n */\n nativeCurrency: string;\n /**\n * The block explorers of the network.\n */\n blockExplorerUrls: string[];\n /**\n * The index of the default block explorer URL.\n */\n defaultBlockExplorerUrlIndex: number;\n};\n\nexport type MultichainNetworkConfiguration =\n | EvmNetworkConfiguration\n | NonEvmNetworkConfiguration;\n\n/**\n * State used by the {@link MultichainNetworkController} to cache network configurations.\n */\nexport type MultichainNetworkControllerState = {\n /**\n * The network configurations by chain ID.\n */\n multichainNetworkConfigurationsByChainId: Record<\n CaipChainId,\n MultichainNetworkConfiguration\n >;\n /**\n * The chain ID of the selected network.\n */\n selectedMultichainNetworkChainId: SupportedCaipChainId;\n /**\n * Whether EVM or non-EVM network is selected\n */\n isEvmSelected: boolean;\n};\n\n/**\n * Returns the state of the {@link MultichainNetworkController}.\n */\nexport type MultichainNetworkControllerGetStateAction =\n ControllerGetStateAction<\n typeof MULTICHAIN_NETWORK_CONTROLLER_NAME,\n MultichainNetworkControllerState\n >;\n\nexport type SetActiveNetworkMethod = (\n id: SupportedCaipChainId | NetworkClientId,\n) => Promise<void>;\n\nexport type MultichainNetworkControllerSetActiveNetworkAction = {\n type: `${typeof MULTICHAIN_NETWORK_CONTROLLER_NAME}:setActiveNetwork`;\n handler: SetActiveNetworkMethod;\n};\n\n/**\n * Event emitted when the state of the {@link MultichainNetworkController} changes.\n */\nexport type MultichainNetworkControllerStateChange = ControllerStateChangeEvent<\n typeof MULTICHAIN_NETWORK_CONTROLLER_NAME,\n MultichainNetworkControllerState\n>;\n\nexport type MultichainNetworkControllerNetworkDidChangeEvent = {\n type: `${typeof MULTICHAIN_NETWORK_CONTROLLER_NAME}:networkDidChange`;\n payload: [NetworkClientId | SupportedCaipChainId];\n};\n\n/**\n * Actions exposed by the {@link MultichainNetworkController}.\n */\nexport type MultichainNetworkControllerActions =\n | MultichainNetworkControllerGetStateAction\n | MultichainNetworkControllerSetActiveNetworkAction;\n\n/**\n * Events emitted by {@link MultichainNetworkController}.\n */\nexport type MultichainNetworkControllerEvents =\n MultichainNetworkControllerNetworkDidChangeEvent;\n\n/**\n * Actions that this controller is allowed to call.\n */\nexport type AllowedActions =\n | NetworkControllerGetStateAction\n | NetworkControllerSetActiveNetworkAction;\n\n// Re-define event here to avoid circular dependency with AccountsController\nexport type AccountsControllerSelectedAccountChangeEvent = {\n type: `AccountsController:selectedAccountChange`;\n payload: [InternalAccount];\n};\n\n/**\n * Events that this controller is allowed to subscribe.\n */\nexport type AllowedEvents = AccountsControllerSelectedAccountChangeEvent;\n\nexport type MultichainNetworkControllerAllowedActions =\n | MultichainNetworkControllerActions\n | AllowedActions;\n\nexport type MultichainNetworkControllerAllowedEvents =\n | MultichainNetworkControllerEvents\n | AllowedEvents;\n\n/**\n * Messenger type for the MultichainNetworkController.\n */\nexport type MultichainNetworkControllerMessenger = RestrictedMessenger<\n typeof MULTICHAIN_NETWORK_CONTROLLER_NAME,\n MultichainNetworkControllerAllowedActions,\n MultichainNetworkControllerAllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type ControllerGetStateAction, type ControllerStateChangeEvent, type RestrictedMessenger } from "@metamask/base-controller";
|
|
2
|
+
import type { BtcScope, CaipChainId, SolScope } from "@metamask/keyring-api";
|
|
3
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
4
|
+
import type { NetworkStatus, NetworkControllerSetActiveNetworkAction, NetworkControllerGetStateAction, NetworkClientId } from "@metamask/network-controller";
|
|
5
|
+
import { type CaipAssetType } from "@metamask/utils";
|
|
6
|
+
export declare const MULTICHAIN_NETWORK_CONTROLLER_NAME = "MultichainNetworkController";
|
|
7
|
+
export type MultichainNetworkMetadata = {
|
|
8
|
+
features: string[];
|
|
9
|
+
status: NetworkStatus;
|
|
10
|
+
};
|
|
11
|
+
export type SupportedCaipChainId = SolScope.Mainnet | BtcScope.Mainnet;
|
|
12
|
+
export type CommonNetworkConfiguration = {
|
|
13
|
+
/**
|
|
14
|
+
* EVM network flag.
|
|
15
|
+
*/
|
|
16
|
+
isEvm: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The chain ID of the network.
|
|
19
|
+
*/
|
|
20
|
+
chainId: CaipChainId;
|
|
21
|
+
/**
|
|
22
|
+
* The name of the network.
|
|
23
|
+
*/
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
26
|
+
export type NonEvmNetworkConfiguration = CommonNetworkConfiguration & {
|
|
27
|
+
/**
|
|
28
|
+
* EVM network flag.
|
|
29
|
+
*/
|
|
30
|
+
isEvm: false;
|
|
31
|
+
/**
|
|
32
|
+
* The native asset type of the network.
|
|
33
|
+
*/
|
|
34
|
+
nativeCurrency: CaipAssetType;
|
|
35
|
+
};
|
|
36
|
+
export type EvmNetworkConfiguration = CommonNetworkConfiguration & {
|
|
37
|
+
/**
|
|
38
|
+
* EVM network flag.
|
|
39
|
+
*/
|
|
40
|
+
isEvm: true;
|
|
41
|
+
/**
|
|
42
|
+
* The native asset type of the network.
|
|
43
|
+
* For EVM, this is the network ticker since there is no standard between
|
|
44
|
+
* tickers and Caip IDs.
|
|
45
|
+
*/
|
|
46
|
+
nativeCurrency: string;
|
|
47
|
+
/**
|
|
48
|
+
* The block explorers of the network.
|
|
49
|
+
*/
|
|
50
|
+
blockExplorerUrls: string[];
|
|
51
|
+
/**
|
|
52
|
+
* The index of the default block explorer URL.
|
|
53
|
+
*/
|
|
54
|
+
defaultBlockExplorerUrlIndex: number;
|
|
55
|
+
};
|
|
56
|
+
export type MultichainNetworkConfiguration = EvmNetworkConfiguration | NonEvmNetworkConfiguration;
|
|
57
|
+
/**
|
|
58
|
+
* State used by the {@link MultichainNetworkController} to cache network configurations.
|
|
59
|
+
*/
|
|
60
|
+
export type MultichainNetworkControllerState = {
|
|
61
|
+
/**
|
|
62
|
+
* The network configurations by chain ID.
|
|
63
|
+
*/
|
|
64
|
+
multichainNetworkConfigurationsByChainId: Record<CaipChainId, MultichainNetworkConfiguration>;
|
|
65
|
+
/**
|
|
66
|
+
* The chain ID of the selected network.
|
|
67
|
+
*/
|
|
68
|
+
selectedMultichainNetworkChainId: SupportedCaipChainId;
|
|
69
|
+
/**
|
|
70
|
+
* Whether EVM or non-EVM network is selected
|
|
71
|
+
*/
|
|
72
|
+
isEvmSelected: boolean;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Returns the state of the {@link MultichainNetworkController}.
|
|
76
|
+
*/
|
|
77
|
+
export type MultichainNetworkControllerGetStateAction = ControllerGetStateAction<typeof MULTICHAIN_NETWORK_CONTROLLER_NAME, MultichainNetworkControllerState>;
|
|
78
|
+
export type SetActiveNetworkMethod = (id: SupportedCaipChainId | NetworkClientId) => Promise<void>;
|
|
79
|
+
export type MultichainNetworkControllerSetActiveNetworkAction = {
|
|
80
|
+
type: `${typeof MULTICHAIN_NETWORK_CONTROLLER_NAME}:setActiveNetwork`;
|
|
81
|
+
handler: SetActiveNetworkMethod;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Event emitted when the state of the {@link MultichainNetworkController} changes.
|
|
85
|
+
*/
|
|
86
|
+
export type MultichainNetworkControllerStateChange = ControllerStateChangeEvent<typeof MULTICHAIN_NETWORK_CONTROLLER_NAME, MultichainNetworkControllerState>;
|
|
87
|
+
export type MultichainNetworkControllerNetworkDidChangeEvent = {
|
|
88
|
+
type: `${typeof MULTICHAIN_NETWORK_CONTROLLER_NAME}:networkDidChange`;
|
|
89
|
+
payload: [NetworkClientId | SupportedCaipChainId];
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Actions exposed by the {@link MultichainNetworkController}.
|
|
93
|
+
*/
|
|
94
|
+
export type MultichainNetworkControllerActions = MultichainNetworkControllerGetStateAction | MultichainNetworkControllerSetActiveNetworkAction;
|
|
95
|
+
/**
|
|
96
|
+
* Events emitted by {@link MultichainNetworkController}.
|
|
97
|
+
*/
|
|
98
|
+
export type MultichainNetworkControllerEvents = MultichainNetworkControllerNetworkDidChangeEvent;
|
|
99
|
+
/**
|
|
100
|
+
* Actions that this controller is allowed to call.
|
|
101
|
+
*/
|
|
102
|
+
export type AllowedActions = NetworkControllerGetStateAction | NetworkControllerSetActiveNetworkAction;
|
|
103
|
+
export type AccountsControllerSelectedAccountChangeEvent = {
|
|
104
|
+
type: `AccountsController:selectedAccountChange`;
|
|
105
|
+
payload: [InternalAccount];
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Events that this controller is allowed to subscribe.
|
|
109
|
+
*/
|
|
110
|
+
export type AllowedEvents = AccountsControllerSelectedAccountChangeEvent;
|
|
111
|
+
export type MultichainNetworkControllerAllowedActions = MultichainNetworkControllerActions | AllowedActions;
|
|
112
|
+
export type MultichainNetworkControllerAllowedEvents = MultichainNetworkControllerEvents | AllowedEvents;
|
|
113
|
+
/**
|
|
114
|
+
* Messenger type for the MultichainNetworkController.
|
|
115
|
+
*/
|
|
116
|
+
export type MultichainNetworkControllerMessenger = RestrictedMessenger<typeof MULTICHAIN_NETWORK_CONTROLLER_NAME, MultichainNetworkControllerAllowedActions, MultichainNetworkControllerAllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
|
117
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,8BAA8B;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,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CAAC,MAAM,CAAC,CACtB,CAAC"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type ControllerGetStateAction, type ControllerStateChangeEvent, type RestrictedMessenger } from "@metamask/base-controller";
|
|
2
|
+
import type { BtcScope, CaipChainId, SolScope } from "@metamask/keyring-api";
|
|
3
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
4
|
+
import type { NetworkStatus, NetworkControllerSetActiveNetworkAction, NetworkControllerGetStateAction, NetworkClientId } from "@metamask/network-controller";
|
|
5
|
+
import { type CaipAssetType } from "@metamask/utils";
|
|
6
|
+
export declare const MULTICHAIN_NETWORK_CONTROLLER_NAME = "MultichainNetworkController";
|
|
7
|
+
export type MultichainNetworkMetadata = {
|
|
8
|
+
features: string[];
|
|
9
|
+
status: NetworkStatus;
|
|
10
|
+
};
|
|
11
|
+
export type SupportedCaipChainId = SolScope.Mainnet | BtcScope.Mainnet;
|
|
12
|
+
export type CommonNetworkConfiguration = {
|
|
13
|
+
/**
|
|
14
|
+
* EVM network flag.
|
|
15
|
+
*/
|
|
16
|
+
isEvm: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The chain ID of the network.
|
|
19
|
+
*/
|
|
20
|
+
chainId: CaipChainId;
|
|
21
|
+
/**
|
|
22
|
+
* The name of the network.
|
|
23
|
+
*/
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
26
|
+
export type NonEvmNetworkConfiguration = CommonNetworkConfiguration & {
|
|
27
|
+
/**
|
|
28
|
+
* EVM network flag.
|
|
29
|
+
*/
|
|
30
|
+
isEvm: false;
|
|
31
|
+
/**
|
|
32
|
+
* The native asset type of the network.
|
|
33
|
+
*/
|
|
34
|
+
nativeCurrency: CaipAssetType;
|
|
35
|
+
};
|
|
36
|
+
export type EvmNetworkConfiguration = CommonNetworkConfiguration & {
|
|
37
|
+
/**
|
|
38
|
+
* EVM network flag.
|
|
39
|
+
*/
|
|
40
|
+
isEvm: true;
|
|
41
|
+
/**
|
|
42
|
+
* The native asset type of the network.
|
|
43
|
+
* For EVM, this is the network ticker since there is no standard between
|
|
44
|
+
* tickers and Caip IDs.
|
|
45
|
+
*/
|
|
46
|
+
nativeCurrency: string;
|
|
47
|
+
/**
|
|
48
|
+
* The block explorers of the network.
|
|
49
|
+
*/
|
|
50
|
+
blockExplorerUrls: string[];
|
|
51
|
+
/**
|
|
52
|
+
* The index of the default block explorer URL.
|
|
53
|
+
*/
|
|
54
|
+
defaultBlockExplorerUrlIndex: number;
|
|
55
|
+
};
|
|
56
|
+
export type MultichainNetworkConfiguration = EvmNetworkConfiguration | NonEvmNetworkConfiguration;
|
|
57
|
+
/**
|
|
58
|
+
* State used by the {@link MultichainNetworkController} to cache network configurations.
|
|
59
|
+
*/
|
|
60
|
+
export type MultichainNetworkControllerState = {
|
|
61
|
+
/**
|
|
62
|
+
* The network configurations by chain ID.
|
|
63
|
+
*/
|
|
64
|
+
multichainNetworkConfigurationsByChainId: Record<CaipChainId, MultichainNetworkConfiguration>;
|
|
65
|
+
/**
|
|
66
|
+
* The chain ID of the selected network.
|
|
67
|
+
*/
|
|
68
|
+
selectedMultichainNetworkChainId: SupportedCaipChainId;
|
|
69
|
+
/**
|
|
70
|
+
* Whether EVM or non-EVM network is selected
|
|
71
|
+
*/
|
|
72
|
+
isEvmSelected: boolean;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Returns the state of the {@link MultichainNetworkController}.
|
|
76
|
+
*/
|
|
77
|
+
export type MultichainNetworkControllerGetStateAction = ControllerGetStateAction<typeof MULTICHAIN_NETWORK_CONTROLLER_NAME, MultichainNetworkControllerState>;
|
|
78
|
+
export type SetActiveNetworkMethod = (id: SupportedCaipChainId | NetworkClientId) => Promise<void>;
|
|
79
|
+
export type MultichainNetworkControllerSetActiveNetworkAction = {
|
|
80
|
+
type: `${typeof MULTICHAIN_NETWORK_CONTROLLER_NAME}:setActiveNetwork`;
|
|
81
|
+
handler: SetActiveNetworkMethod;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Event emitted when the state of the {@link MultichainNetworkController} changes.
|
|
85
|
+
*/
|
|
86
|
+
export type MultichainNetworkControllerStateChange = ControllerStateChangeEvent<typeof MULTICHAIN_NETWORK_CONTROLLER_NAME, MultichainNetworkControllerState>;
|
|
87
|
+
export type MultichainNetworkControllerNetworkDidChangeEvent = {
|
|
88
|
+
type: `${typeof MULTICHAIN_NETWORK_CONTROLLER_NAME}:networkDidChange`;
|
|
89
|
+
payload: [NetworkClientId | SupportedCaipChainId];
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Actions exposed by the {@link MultichainNetworkController}.
|
|
93
|
+
*/
|
|
94
|
+
export type MultichainNetworkControllerActions = MultichainNetworkControllerGetStateAction | MultichainNetworkControllerSetActiveNetworkAction;
|
|
95
|
+
/**
|
|
96
|
+
* Events emitted by {@link MultichainNetworkController}.
|
|
97
|
+
*/
|
|
98
|
+
export type MultichainNetworkControllerEvents = MultichainNetworkControllerNetworkDidChangeEvent;
|
|
99
|
+
/**
|
|
100
|
+
* Actions that this controller is allowed to call.
|
|
101
|
+
*/
|
|
102
|
+
export type AllowedActions = NetworkControllerGetStateAction | NetworkControllerSetActiveNetworkAction;
|
|
103
|
+
export type AccountsControllerSelectedAccountChangeEvent = {
|
|
104
|
+
type: `AccountsController:selectedAccountChange`;
|
|
105
|
+
payload: [InternalAccount];
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Events that this controller is allowed to subscribe.
|
|
109
|
+
*/
|
|
110
|
+
export type AllowedEvents = AccountsControllerSelectedAccountChangeEvent;
|
|
111
|
+
export type MultichainNetworkControllerAllowedActions = MultichainNetworkControllerActions | AllowedActions;
|
|
112
|
+
export type MultichainNetworkControllerAllowedEvents = MultichainNetworkControllerEvents | AllowedEvents;
|
|
113
|
+
/**
|
|
114
|
+
* Messenger type for the MultichainNetworkController.
|
|
115
|
+
*/
|
|
116
|
+
export type MultichainNetworkControllerMessenger = RestrictedMessenger<typeof MULTICHAIN_NETWORK_CONTROLLER_NAME, MultichainNetworkControllerAllowedActions, MultichainNetworkControllerAllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
|
117
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,8BAA8B;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EACV,aAAa,EACb,uCAAuC,EACvC,+BAA+B,EAC/B,eAAe,EAChB,qCAAqC;AACtC,OAAO,EAAE,KAAK,aAAa,EAAE,wBAAwB;AAErD,eAAO,MAAM,kCAAkC,gCAAgC,CAAC;AAEhF,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;AAEvE,MAAM,MAAM,0BAA0B,GAAG;IACvC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,OAAO,EAAE,WAAW,CAAC;IACrB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,0BAA0B,GAAG;IACpE;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;IACb;;OAEG;IACH,cAAc,EAAE,aAAa,CAAC;CAC/B,CAAC;AAIF,MAAM,MAAM,uBAAuB,GAAG,0BAA0B,GAAG;IACjE;;OAEG;IACH,KAAK,EAAE,IAAI,CAAC;I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AAuC,CAAC;AAG5C,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,0CAA0C,CAAC;IACjD,OAAO,EAAE,CAAC,eAAe,CAAC,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,4CAA4C,CAAC;AAEzE,MAAM,MAAM,yCAAyC,GACjD,kCAAkC,GAClC,cAAc,CAAC;AAEnB,MAAM,MAAM,wCAAwC,GAChD,iCAAiC,GACjC,aAAa,CAAC;AAElB;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAAG,mBAAmB,CACpE,OAAO,kCAAkC,EACzC,yCAAyC,EACzC,wCAAwC,EACxC,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC"}
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,MAAM,kCAAkC,GAAG,6BAA6B,CAAC","sourcesContent":["import {\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { BtcScope, CaipChainId, SolScope } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type {\n NetworkStatus,\n NetworkControllerSetActiveNetworkAction,\n NetworkControllerGetStateAction,\n NetworkClientId,\n} from '@metamask/network-controller';\nimport { type CaipAssetType } from '@metamask/utils';\n\nexport const MULTICHAIN_NETWORK_CONTROLLER_NAME = 'MultichainNetworkController';\n\nexport type MultichainNetworkMetadata = {\n features: string[];\n status: NetworkStatus;\n};\n\nexport type SupportedCaipChainId = SolScope.Mainnet | BtcScope.Mainnet;\n\nexport type CommonNetworkConfiguration = {\n /**\n * EVM network flag.\n */\n isEvm: boolean;\n /**\n * The chain ID of the network.\n */\n chainId: CaipChainId;\n /**\n * The name of the network.\n */\n name: string;\n};\n\nexport type NonEvmNetworkConfiguration = CommonNetworkConfiguration & {\n /**\n * EVM network flag.\n */\n isEvm: false;\n /**\n * The native asset type of the network.\n */\n nativeCurrency: CaipAssetType;\n};\n\n// TODO: The controller only supports non-EVM network configurations at the moment\n// Once we support Caip chain IDs for EVM networks, we can re-enable EVM network configurations\nexport type EvmNetworkConfiguration = CommonNetworkConfiguration & {\n /**\n * EVM network flag.\n */\n isEvm: true;\n /**\n * The native asset type of the network.\n * For EVM, this is the network ticker since there is no standard between\n * tickers and Caip IDs.\n */\n nativeCurrency: string;\n /**\n * The block explorers of the network.\n */\n blockExplorerUrls: string[];\n /**\n * The index of the default block explorer URL.\n */\n defaultBlockExplorerUrlIndex: number;\n};\n\nexport type MultichainNetworkConfiguration =\n | EvmNetworkConfiguration\n | NonEvmNetworkConfiguration;\n\n/**\n * State used by the {@link MultichainNetworkController} to cache network configurations.\n */\nexport type MultichainNetworkControllerState = {\n /**\n * The network configurations by chain ID.\n */\n multichainNetworkConfigurationsByChainId: Record<\n CaipChainId,\n MultichainNetworkConfiguration\n >;\n /**\n * The chain ID of the selected network.\n */\n selectedMultichainNetworkChainId: SupportedCaipChainId;\n /**\n * Whether EVM or non-EVM network is selected\n */\n isEvmSelected: boolean;\n};\n\n/**\n * Returns the state of the {@link MultichainNetworkController}.\n */\nexport type MultichainNetworkControllerGetStateAction =\n ControllerGetStateAction<\n typeof MULTICHAIN_NETWORK_CONTROLLER_NAME,\n MultichainNetworkControllerState\n >;\n\nexport type SetActiveNetworkMethod = (\n id: SupportedCaipChainId | NetworkClientId,\n) => Promise<void>;\n\nexport type MultichainNetworkControllerSetActiveNetworkAction = {\n type: `${typeof MULTICHAIN_NETWORK_CONTROLLER_NAME}:setActiveNetwork`;\n handler: SetActiveNetworkMethod;\n};\n\n/**\n * Event emitted when the state of the {@link MultichainNetworkController} changes.\n */\nexport type MultichainNetworkControllerStateChange = ControllerStateChangeEvent<\n typeof MULTICHAIN_NETWORK_CONTROLLER_NAME,\n MultichainNetworkControllerState\n>;\n\nexport type MultichainNetworkControllerNetworkDidChangeEvent = {\n type: `${typeof MULTICHAIN_NETWORK_CONTROLLER_NAME}:networkDidChange`;\n payload: [NetworkClientId | SupportedCaipChainId];\n};\n\n/**\n * Actions exposed by the {@link MultichainNetworkController}.\n */\nexport type MultichainNetworkControllerActions =\n | MultichainNetworkControllerGetStateAction\n | MultichainNetworkControllerSetActiveNetworkAction;\n\n/**\n * Events emitted by {@link MultichainNetworkController}.\n */\nexport type MultichainNetworkControllerEvents =\n MultichainNetworkControllerNetworkDidChangeEvent;\n\n/**\n * Actions that this controller is allowed to call.\n */\nexport type AllowedActions =\n | NetworkControllerGetStateAction\n | NetworkControllerSetActiveNetworkAction;\n\n// Re-define event here to avoid circular dependency with AccountsController\nexport type AccountsControllerSelectedAccountChangeEvent = {\n type: `AccountsController:selectedAccountChange`;\n payload: [InternalAccount];\n};\n\n/**\n * Events that this controller is allowed to subscribe.\n */\nexport type AllowedEvents = AccountsControllerSelectedAccountChangeEvent;\n\nexport type MultichainNetworkControllerAllowedActions =\n | MultichainNetworkControllerActions\n | AllowedActions;\n\nexport type MultichainNetworkControllerAllowedEvents =\n | MultichainNetworkControllerEvents\n | AllowedEvents;\n\n/**\n * Messenger type for the MultichainNetworkController.\n */\nexport type MultichainNetworkControllerMessenger = RestrictedMessenger<\n typeof MULTICHAIN_NETWORK_CONTROLLER_NAME,\n MultichainNetworkControllerAllowedActions,\n MultichainNetworkControllerAllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toMultichainNetworkConfigurationsByChainId = exports.toMultichainNetworkConfiguration = exports.toEvmCaipChainId = exports.checkIfSupportedCaipChainId = exports.getChainIdForNonEvmAddress = void 0;
|
|
4
|
+
const keyring_api_1 = require("@metamask/keyring-api");
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
const addresses_1 = require("@solana/addresses");
|
|
7
|
+
const constants_1 = require("./constants.cjs");
|
|
8
|
+
/**
|
|
9
|
+
* Returns the chain id of the non-EVM network based on the account address.
|
|
10
|
+
*
|
|
11
|
+
* @param address - The address to check.
|
|
12
|
+
* @returns The caip chain id of the non-EVM network.
|
|
13
|
+
*/
|
|
14
|
+
function getChainIdForNonEvmAddress(address) {
|
|
15
|
+
// This condition is not the most robust. Once we support more networks, we will need to update this logic.
|
|
16
|
+
if ((0, addresses_1.isAddress)(address)) {
|
|
17
|
+
return keyring_api_1.SolScope.Mainnet;
|
|
18
|
+
}
|
|
19
|
+
return keyring_api_1.BtcScope.Mainnet;
|
|
20
|
+
}
|
|
21
|
+
exports.getChainIdForNonEvmAddress = getChainIdForNonEvmAddress;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if the Caip chain ID is supported.
|
|
24
|
+
*
|
|
25
|
+
* @param id - The Caip chain IDto check.
|
|
26
|
+
* @returns Whether the chain ID is supported.
|
|
27
|
+
*/
|
|
28
|
+
function checkIfSupportedCaipChainId(id) {
|
|
29
|
+
// Check if the chain id is supported
|
|
30
|
+
return Object.keys(constants_1.AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS).includes(id);
|
|
31
|
+
}
|
|
32
|
+
exports.checkIfSupportedCaipChainId = checkIfSupportedCaipChainId;
|
|
33
|
+
/**
|
|
34
|
+
* Converts a hex chain ID to a Caip chain ID.
|
|
35
|
+
*
|
|
36
|
+
* @param chainId - The hex chain ID to convert.
|
|
37
|
+
* @returns The Caip chain ID.
|
|
38
|
+
*/
|
|
39
|
+
const toEvmCaipChainId = (chainId) => (0, utils_1.toCaipChainId)(utils_1.KnownCaipNamespace.Eip155, (0, utils_1.hexToNumber)(chainId).toString());
|
|
40
|
+
exports.toEvmCaipChainId = toEvmCaipChainId;
|
|
41
|
+
/**
|
|
42
|
+
* Updates a network configuration to the format used by the MultichainNetworkController.
|
|
43
|
+
* This method is exclusive for EVM networks with hex identifiers from the NetworkController.
|
|
44
|
+
*
|
|
45
|
+
* @param network - The network configuration to update.
|
|
46
|
+
* @returns The updated network configuration.
|
|
47
|
+
*/
|
|
48
|
+
const toMultichainNetworkConfiguration = (network) => {
|
|
49
|
+
return {
|
|
50
|
+
chainId: (0, exports.toEvmCaipChainId)(network.chainId),
|
|
51
|
+
isEvm: true,
|
|
52
|
+
name: network.name,
|
|
53
|
+
nativeCurrency: network.nativeCurrency,
|
|
54
|
+
blockExplorerUrls: network.blockExplorerUrls,
|
|
55
|
+
defaultBlockExplorerUrlIndex: network.defaultBlockExplorerUrlIndex || 0,
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
exports.toMultichainNetworkConfiguration = toMultichainNetworkConfiguration;
|
|
59
|
+
/**
|
|
60
|
+
* Updates a record of network configurations to the format used by the MultichainNetworkController.
|
|
61
|
+
* This method is exclusive for EVM networks with hex identifiers from the NetworkController.
|
|
62
|
+
*
|
|
63
|
+
* @param networkConfigurationsByChainId - The network configurations to update.
|
|
64
|
+
* @returns The updated network configurations.
|
|
65
|
+
*/
|
|
66
|
+
const toMultichainNetworkConfigurationsByChainId = (networkConfigurationsByChainId) => Object.entries(networkConfigurationsByChainId).reduce((acc, [, network]) => ({
|
|
67
|
+
...acc,
|
|
68
|
+
[(0, exports.toEvmCaipChainId)(network.chainId)]: (0, exports.toMultichainNetworkConfiguration)(network),
|
|
69
|
+
}), {});
|
|
70
|
+
exports.toMultichainNetworkConfigurationsByChainId = toMultichainNetworkConfigurationsByChainId;
|
|
71
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,uDAA2D;AAE3D,2CAMyB;AACzB,iDAAiE;AAEjE,+CAA0E;AAM1E;;;;;GAKG;AACH,SAAgB,0BAA0B,CACxC,OAAe;IAEf,2GAA2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AAgC,EAAC,OAAO,CAAC;CAC5C,CAAC,EACF,EAAE,CACH,CAAC;AAVS,QAAA,0CAA0C,8CAUnD","sourcesContent":["import { BtcScope, SolScope } from '@metamask/keyring-api';\nimport type { NetworkConfiguration } from '@metamask/network-controller';\nimport {\n type Hex,\n type CaipChainId,\n KnownCaipNamespace,\n toCaipChainId,\n hexToNumber,\n} from '@metamask/utils';\nimport { isAddress as isSolanaAddress } from '@solana/addresses';\n\nimport { AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS } from './constants';\nimport type {\n SupportedCaipChainId,\n MultichainNetworkConfiguration,\n} from './types';\n\n/**\n * Returns the chain id of the non-EVM network based on the account address.\n *\n * @param address - The address to check.\n * @returns The caip chain id of the non-EVM network.\n */\nexport function getChainIdForNonEvmAddress(\n address: string,\n): SupportedCaipChainId {\n // This condition is not the most robust. Once we support more networks, we will need to update this logic.\n if (isSolanaAddress(address)) {\n return SolScope.Mainnet;\n }\n return BtcScope.Mainnet;\n}\n\n/**\n * Checks if the Caip chain ID is supported.\n *\n * @param id - The Caip chain IDto check.\n * @returns Whether the chain ID is supported.\n */\nexport function checkIfSupportedCaipChainId(\n id: CaipChainId,\n): id is SupportedCaipChainId {\n // Check if the chain id is supported\n return Object.keys(AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS).includes(id);\n}\n\n/**\n * Converts a hex chain ID to a Caip chain ID.\n *\n * @param chainId - The hex chain ID to convert.\n * @returns The Caip chain ID.\n */\nexport const toEvmCaipChainId = (chainId: Hex): CaipChainId =>\n toCaipChainId(KnownCaipNamespace.Eip155, hexToNumber(chainId).toString());\n\n/**\n * Updates a network configuration to the format used by the MultichainNetworkController.\n * This method is exclusive for EVM networks with hex identifiers from the NetworkController.\n *\n * @param network - The network configuration to update.\n * @returns The updated network configuration.\n */\nexport const toMultichainNetworkConfiguration = (\n network: NetworkConfiguration,\n): MultichainNetworkConfiguration => {\n return {\n chainId: toEvmCaipChainId(network.chainId),\n isEvm: true,\n name: network.name,\n nativeCurrency: network.nativeCurrency,\n blockExplorerUrls: network.blockExplorerUrls,\n defaultBlockExplorerUrlIndex: network.defaultBlockExplorerUrlIndex || 0,\n };\n};\n\n/**\n * Updates a record of network configurations to the format used by the MultichainNetworkController.\n * This method is exclusive for EVM networks with hex identifiers from the NetworkController.\n *\n * @param networkConfigurationsByChainId - The network configurations to update.\n * @returns The updated network configurations.\n */\nexport const toMultichainNetworkConfigurationsByChainId = (\n networkConfigurationsByChainId: Record<string, NetworkConfiguration>,\n): Record<CaipChainId, MultichainNetworkConfiguration> =>\n Object.entries(networkConfigurationsByChainId).reduce(\n (acc, [, network]) => ({\n ...acc,\n [toEvmCaipChainId(network.chainId)]:\n toMultichainNetworkConfiguration(network),\n }),\n {},\n );\n"]}
|
package/dist/utils.d.cts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { NetworkConfiguration } from "@metamask/network-controller";
|
|
2
|
+
import { type Hex, type CaipChainId } from "@metamask/utils";
|
|
3
|
+
import type { SupportedCaipChainId, MultichainNetworkConfiguration } from "./types.cjs";
|
|
4
|
+
/**
|
|
5
|
+
* Returns the chain id of the non-EVM network based on the account address.
|
|
6
|
+
*
|
|
7
|
+
* @param address - The address to check.
|
|
8
|
+
* @returns The caip chain id of the non-EVM network.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getChainIdForNonEvmAddress(address: string): SupportedCaipChainId;
|
|
11
|
+
/**
|
|
12
|
+
* Checks if the Caip chain ID is supported.
|
|
13
|
+
*
|
|
14
|
+
* @param id - The Caip chain IDto check.
|
|
15
|
+
* @returns Whether the chain ID is supported.
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkIfSupportedCaipChainId(id: CaipChainId): id is SupportedCaipChainId;
|
|
18
|
+
/**
|
|
19
|
+
* Converts a hex chain ID to a Caip chain ID.
|
|
20
|
+
*
|
|
21
|
+
* @param chainId - The hex chain ID to convert.
|
|
22
|
+
* @returns The Caip chain ID.
|
|
23
|
+
*/
|
|
24
|
+
export declare const toEvmCaipChainId: (chainId: Hex) => CaipChainId;
|
|
25
|
+
/**
|
|
26
|
+
* Updates a network configuration to the format used by the MultichainNetworkController.
|
|
27
|
+
* This method is exclusive for EVM networks with hex identifiers from the NetworkController.
|
|
28
|
+
*
|
|
29
|
+
* @param network - The network configuration to update.
|
|
30
|
+
* @returns The updated network configuration.
|
|
31
|
+
*/
|
|
32
|
+
export declare const toMultichainNetworkConfiguration: (network: NetworkConfiguration) => MultichainNetworkConfiguration;
|
|
33
|
+
/**
|
|
34
|
+
* Updates a record of network configurations to the format used by the MultichainNetworkController.
|
|
35
|
+
* This method is exclusive for EVM networks with hex identifiers from the NetworkController.
|
|
36
|
+
*
|
|
37
|
+
* @param networkConfigurationsByChainId - The network configurations to update.
|
|
38
|
+
* @returns The updated network configurations.
|
|
39
|
+
*/
|
|
40
|
+
export declare const toMultichainNetworkConfigurationsByChainId: (networkConfigurationsByChainId: Record<string, NetworkConfiguration>) => Record<CaipChainId, MultichainNetworkConfiguration>;
|
|
41
|
+
//# sourceMappingURL=utils.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AACzE,OAAO,EACL,KAAK,GAAG,EACR,KAAK,WAAW,EAIjB,wBAAwB;AAIzB,OAAO,KAAK,EACV,oBAAoB,EACpB,8BAA8B,EAC/B,oBAAgB;AAEjB;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,GACd,oBAAoB,CAMtB;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,EAAE,EAAE,WAAW,GACd,EAAE,IAAI,oBAAoB,CAG5B;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,YAAa,GAAG,KAAG,WAC2B,CAAC;AAE5E;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,YAClC,oBAAoB,KAC5B,8BASF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,0CAA0C,mCACrB,OAAO,MAAM,EAAE,oBAAoB,CAAC,KACnE,OAAO,WAAW,EAAE,8BAA8B,CAQlD,CAAC"}
|
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { NetworkConfiguration } from "@metamask/network-controller";
|
|
2
|
+
import { type Hex, type CaipChainId } from "@metamask/utils";
|
|
3
|
+
import type { SupportedCaipChainId, MultichainNetworkConfiguration } from "./types.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Returns the chain id of the non-EVM network based on the account address.
|
|
6
|
+
*
|
|
7
|
+
* @param address - The address to check.
|
|
8
|
+
* @returns The caip chain id of the non-EVM network.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getChainIdForNonEvmAddress(address: string): SupportedCaipChainId;
|
|
11
|
+
/**
|
|
12
|
+
* Checks if the Caip chain ID is supported.
|
|
13
|
+
*
|
|
14
|
+
* @param id - The Caip chain IDto check.
|
|
15
|
+
* @returns Whether the chain ID is supported.
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkIfSupportedCaipChainId(id: CaipChainId): id is SupportedCaipChainId;
|
|
18
|
+
/**
|
|
19
|
+
* Converts a hex chain ID to a Caip chain ID.
|
|
20
|
+
*
|
|
21
|
+
* @param chainId - The hex chain ID to convert.
|
|
22
|
+
* @returns The Caip chain ID.
|
|
23
|
+
*/
|
|
24
|
+
export declare const toEvmCaipChainId: (chainId: Hex) => CaipChainId;
|
|
25
|
+
/**
|
|
26
|
+
* Updates a network configuration to the format used by the MultichainNetworkController.
|
|
27
|
+
* This method is exclusive for EVM networks with hex identifiers from the NetworkController.
|
|
28
|
+
*
|
|
29
|
+
* @param network - The network configuration to update.
|
|
30
|
+
* @returns The updated network configuration.
|
|
31
|
+
*/
|
|
32
|
+
export declare const toMultichainNetworkConfiguration: (network: NetworkConfiguration) => MultichainNetworkConfiguration;
|
|
33
|
+
/**
|
|
34
|
+
* Updates a record of network configurations to the format used by the MultichainNetworkController.
|
|
35
|
+
* This method is exclusive for EVM networks with hex identifiers from the NetworkController.
|
|
36
|
+
*
|
|
37
|
+
* @param networkConfigurationsByChainId - The network configurations to update.
|
|
38
|
+
* @returns The updated network configurations.
|
|
39
|
+
*/
|
|
40
|
+
export declare const toMultichainNetworkConfigurationsByChainId: (networkConfigurationsByChainId: Record<string, NetworkConfiguration>) => Record<CaipChainId, MultichainNetworkConfiguration>;
|
|
41
|
+
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AACzE,OAAO,EACL,KAAK,GAAG,EACR,KAAK,WAAW,EAIjB,wBAAwB;AAIzB,OAAO,KAAK,EACV,oBAAoB,EACpB,8BAA8B,EAC/B,oBAAgB;AAEjB;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,GACd,oBAAoB,CAMtB;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,EAAE,EAAE,WAAW,GACd,EAAE,IAAI,oBAAoB,CAG5B;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,YAAa,GAAG,KAAG,WAC2B,CAAC;AAE5E;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,YAClC,oBAAoB,KAC5B,8BASF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,0CAA0C,mCACrB,OAAO,MAAM,EAAE,oBAAoB,CAAC,KACnE,OAAO,WAAW,EAAE,8BAA8B,CAQlD,CAAC"}
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { BtcScope, SolScope } from "@metamask/keyring-api";
|
|
2
|
+
import { KnownCaipNamespace, toCaipChainId, hexToNumber } from "@metamask/utils";
|
|
3
|
+
import { isAddress as isSolanaAddress } from "@solana/addresses";
|
|
4
|
+
import { AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS } from "./constants.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Returns the chain id of the non-EVM network based on the account address.
|
|
7
|
+
*
|
|
8
|
+
* @param address - The address to check.
|
|
9
|
+
* @returns The caip chain id of the non-EVM network.
|
|
10
|
+
*/
|
|
11
|
+
export function getChainIdForNonEvmAddress(address) {
|
|
12
|
+
// This condition is not the most robust. Once we support more networks, we will need to update this logic.
|
|
13
|
+
if (isSolanaAddress(address)) {
|
|
14
|
+
return SolScope.Mainnet;
|
|
15
|
+
}
|
|
16
|
+
return BtcScope.Mainnet;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the Caip chain ID is supported.
|
|
20
|
+
*
|
|
21
|
+
* @param id - The Caip chain IDto check.
|
|
22
|
+
* @returns Whether the chain ID is supported.
|
|
23
|
+
*/
|
|
24
|
+
export function checkIfSupportedCaipChainId(id) {
|
|
25
|
+
// Check if the chain id is supported
|
|
26
|
+
return Object.keys(AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS).includes(id);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Converts a hex chain ID to a Caip chain ID.
|
|
30
|
+
*
|
|
31
|
+
* @param chainId - The hex chain ID to convert.
|
|
32
|
+
* @returns The Caip chain ID.
|
|
33
|
+
*/
|
|
34
|
+
export const toEvmCaipChainId = (chainId) => toCaipChainId(KnownCaipNamespace.Eip155, hexToNumber(chainId).toString());
|
|
35
|
+
/**
|
|
36
|
+
* Updates a network configuration to the format used by the MultichainNetworkController.
|
|
37
|
+
* This method is exclusive for EVM networks with hex identifiers from the NetworkController.
|
|
38
|
+
*
|
|
39
|
+
* @param network - The network configuration to update.
|
|
40
|
+
* @returns The updated network configuration.
|
|
41
|
+
*/
|
|
42
|
+
export const toMultichainNetworkConfiguration = (network) => {
|
|
43
|
+
return {
|
|
44
|
+
chainId: toEvmCaipChainId(network.chainId),
|
|
45
|
+
isEvm: true,
|
|
46
|
+
name: network.name,
|
|
47
|
+
nativeCurrency: network.nativeCurrency,
|
|
48
|
+
blockExplorerUrls: network.blockExplorerUrls,
|
|
49
|
+
defaultBlockExplorerUrlIndex: network.defaultBlockExplorerUrlIndex || 0,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Updates a record of network configurations to the format used by the MultichainNetworkController.
|
|
54
|
+
* This method is exclusive for EVM networks with hex identifiers from the NetworkController.
|
|
55
|
+
*
|
|
56
|
+
* @param networkConfigurationsByChainId - The network configurations to update.
|
|
57
|
+
* @returns The updated network configurations.
|
|
58
|
+
*/
|
|
59
|
+
export const toMultichainNetworkConfigurationsByChainId = (networkConfigurationsByChainId) => Object.entries(networkConfigurationsByChainId).reduce((acc, [, network]) => ({
|
|
60
|
+
...acc,
|
|
61
|
+
[toEvmCaipChainId(network.chainId)]: toMultichainNetworkConfiguration(network),
|
|
62
|
+
}), {});
|
|
63
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,8BAA8B;AAE3D,OAAO,EAGL,kBAAkB,EAClB,aAAa,EACb,WAAW,EACZ,wBAAwB;AACzB,OAAO,EAAE,SAAS,IAAI,eAAe,EAAE,0BAA0B;AAEjE,OAAO,EAAE,2CAA2C,EAAE,wBAAoB;AAM1E;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,OAAe;IAEf,2GAA2G;IAC3G,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE;QAC5B,OAAO,QAAQ,CAAC,OAAO,CAAC;KACzB;IACD,OAAO,QAAQ,CAAC,OAAO,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,EAAe;IAEf,qCAAqC;IACrC,OAAO,MAAM,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC/E,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAY,EAAe,EAAE,CAC5D,aAAa,CAAC,kBAAkB,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AAE5E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,OAA6B,EACG,EAAE;IAClC,OAAO;QACL,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC;QAC1C,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;QAC5C,4BAA4B,EAAE,OAAO,CAAC,4BAA4B,IAAI,CAAC;KACxE,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,0CAA0C,GAAG,CACxD,8BAAoE,EACf,EAAE,CACvD,MAAM,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAC,MAAM,CACnD,CAAC,GAAG,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IACrB,GAAG,GAAG;IACN,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EACjC,gCAAgC,CAAC,OAAO,CAAC;CAC5C,CAAC,EACF,EAAE,CACH,CAAC","sourcesContent":["import { BtcScope, SolScope } from '@metamask/keyring-api';\nimport type { NetworkConfiguration } from '@metamask/network-controller';\nimport {\n type Hex,\n type CaipChainId,\n KnownCaipNamespace,\n toCaipChainId,\n hexToNumber,\n} from '@metamask/utils';\nimport { isAddress as isSolanaAddress } from '@solana/addresses';\n\nimport { AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS } from './constants';\nimport type {\n SupportedCaipChainId,\n MultichainNetworkConfiguration,\n} from './types';\n\n/**\n * Returns the chain id of the non-EVM network based on the account address.\n *\n * @param address - The address to check.\n * @returns The caip chain id of the non-EVM network.\n */\nexport function getChainIdForNonEvmAddress(\n address: string,\n): SupportedCaipChainId {\n // This condition is not the most robust. Once we support more networks, we will need to update this logic.\n if (isSolanaAddress(address)) {\n return SolScope.Mainnet;\n }\n return BtcScope.Mainnet;\n}\n\n/**\n * Checks if the Caip chain ID is supported.\n *\n * @param id - The Caip chain IDto check.\n * @returns Whether the chain ID is supported.\n */\nexport function checkIfSupportedCaipChainId(\n id: CaipChainId,\n): id is SupportedCaipChainId {\n // Check if the chain id is supported\n return Object.keys(AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS).includes(id);\n}\n\n/**\n * Converts a hex chain ID to a Caip chain ID.\n *\n * @param chainId - The hex chain ID to convert.\n * @returns The Caip chain ID.\n */\nexport const toEvmCaipChainId = (chainId: Hex): CaipChainId =>\n toCaipChainId(KnownCaipNamespace.Eip155, hexToNumber(chainId).toString());\n\n/**\n * Updates a network configuration to the format used by the MultichainNetworkController.\n * This method is exclusive for EVM networks with hex identifiers from the NetworkController.\n *\n * @param network - The network configuration to update.\n * @returns The updated network configuration.\n */\nexport const toMultichainNetworkConfiguration = (\n network: NetworkConfiguration,\n): MultichainNetworkConfiguration => {\n return {\n chainId: toEvmCaipChainId(network.chainId),\n isEvm: true,\n name: network.name,\n nativeCurrency: network.nativeCurrency,\n blockExplorerUrls: network.blockExplorerUrls,\n defaultBlockExplorerUrlIndex: network.defaultBlockExplorerUrlIndex || 0,\n };\n};\n\n/**\n * Updates a record of network configurations to the format used by the MultichainNetworkController.\n * This method is exclusive for EVM networks with hex identifiers from the NetworkController.\n *\n * @param networkConfigurationsByChainId - The network configurations to update.\n * @returns The updated network configurations.\n */\nexport const toMultichainNetworkConfigurationsByChainId = (\n networkConfigurationsByChainId: Record<string, NetworkConfiguration>,\n): Record<CaipChainId, MultichainNetworkConfiguration> =>\n Object.entries(networkConfigurationsByChainId).reduce(\n (acc, [, network]) => ({\n ...acc,\n [toEvmCaipChainId(network.chainId)]:\n toMultichainNetworkConfiguration(network),\n }),\n {},\n );\n"]}
|