@metamask-previews/network-enablement-controller 6.0.5-preview-8bfa290fb → 7.0.0-preview-0a30e47
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 +16 -2
- package/dist/{NetworkEnablementController-method-action-types.d.mts → NetworkEnablementController-method-action-types.d.ts} +2 -2
- package/dist/NetworkEnablementController-method-action-types.d.ts.map +1 -0
- package/dist/{NetworkEnablementController-method-action-types.mjs → NetworkEnablementController-method-action-types.js} +1 -1
- package/dist/NetworkEnablementController-method-action-types.js.map +1 -0
- package/dist/{NetworkEnablementController.d.cts → NetworkEnablementController.d.ts} +10 -10
- package/dist/NetworkEnablementController.d.ts.map +1 -0
- package/dist/{NetworkEnablementController.mjs → NetworkEnablementController.js} +167 -131
- package/dist/NetworkEnablementController.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/{constants.mjs → constants.js} +1 -1
- package/dist/constants.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +6 -6
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/{selectors.d.cts → selectors.d.ts} +18 -30
- package/dist/selectors.d.ts.map +1 -0
- package/dist/{selectors.mjs → selectors.js} +4 -4
- package/dist/selectors.js.map +1 -0
- package/dist/services/{Slip44Service.d.cts → Slip44Service.d.ts} +1 -1
- package/dist/services/Slip44Service.d.ts.map +1 -0
- package/dist/services/Slip44Service.js +167 -0
- package/dist/services/Slip44Service.js.map +1 -0
- package/dist/services/{index.d.cts → index.d.ts} +2 -2
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/{index.mjs → index.js} +2 -2
- package/dist/services/index.js.map +1 -0
- package/dist/{utils.d.mts → utils.d.ts} +3 -3
- package/dist/utils.d.ts.map +1 -0
- package/dist/{utils.mjs → utils.js} +4 -4
- package/dist/utils.js.map +1 -0
- package/package.json +19 -23
- package/dist/NetworkEnablementController-method-action-types.cjs +0 -7
- package/dist/NetworkEnablementController-method-action-types.cjs.map +0 -1
- package/dist/NetworkEnablementController-method-action-types.d.cts +0 -185
- package/dist/NetworkEnablementController-method-action-types.d.cts.map +0 -1
- package/dist/NetworkEnablementController-method-action-types.d.mts.map +0 -1
- package/dist/NetworkEnablementController-method-action-types.mjs.map +0 -1
- package/dist/NetworkEnablementController.cjs +0 -590
- package/dist/NetworkEnablementController.cjs.map +0 -1
- package/dist/NetworkEnablementController.d.cts.map +0 -1
- package/dist/NetworkEnablementController.d.mts +0 -234
- package/dist/NetworkEnablementController.d.mts.map +0 -1
- package/dist/NetworkEnablementController.mjs.map +0 -1
- package/dist/constants.cjs +0 -22
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts +0 -3
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.mts +0 -3
- package/dist/constants.d.mts.map +0 -1
- package/dist/constants.mjs.map +0 -1
- package/dist/index.cjs +0 -18
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -6
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -4
- package/dist/index.mjs.map +0 -1
- package/dist/selectors.cjs +0 -87
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts +0 -280
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs.map +0 -1
- package/dist/services/Slip44Service.cjs +0 -182
- package/dist/services/Slip44Service.cjs.map +0 -1
- package/dist/services/Slip44Service.d.cts.map +0 -1
- package/dist/services/Slip44Service.d.mts +0 -63
- package/dist/services/Slip44Service.d.mts.map +0 -1
- package/dist/services/Slip44Service.mjs +0 -175
- package/dist/services/Slip44Service.mjs.map +0 -1
- package/dist/services/index.cjs +0 -11
- package/dist/services/index.cjs.map +0 -1
- package/dist/services/index.d.cts.map +0 -1
- package/dist/services/index.d.mts +0 -5
- package/dist/services/index.d.mts.map +0 -1
- package/dist/services/index.mjs.map +0 -1
- package/dist/utils.cjs +0 -62
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts +0 -36
- package/dist/utils.d.cts.map +0 -1
- package/dist/utils.d.mts.map +0 -1
- package/dist/utils.mjs.map +0 -1
package/dist/selectors.cjs
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.selectEnabledSolanaNetworks = exports.selectEnabledEvmNetworks = exports.selectEnabledNetworksCount = exports.selectAllEnabledNetworks = exports.createSelectorForEnabledNetworksForNamespace = exports.selectIsNetworkEnabled = exports.selectEnabledNetworkMap = void 0;
|
|
4
|
-
const utils_1 = require("@metamask/utils");
|
|
5
|
-
const reselect_1 = require("reselect");
|
|
6
|
-
const utils_js_1 = require("./utils.cjs");
|
|
7
|
-
/**
|
|
8
|
-
* Base selector to get the enabled network map from the controller state.
|
|
9
|
-
*
|
|
10
|
-
* @param state - The NetworkEnablementController state
|
|
11
|
-
* @returns The enabled network map
|
|
12
|
-
*/
|
|
13
|
-
const selectEnabledNetworkMap = (state) => state.enabledNetworkMap;
|
|
14
|
-
exports.selectEnabledNetworkMap = selectEnabledNetworkMap;
|
|
15
|
-
/**
|
|
16
|
-
* Selector to check if a specific network is enabled.
|
|
17
|
-
*
|
|
18
|
-
* This selector accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID
|
|
19
|
-
* (for any blockchain network) and returns whether the network is currently enabled.
|
|
20
|
-
* It returns false for unknown networks or if there's an error parsing the chain ID.
|
|
21
|
-
*
|
|
22
|
-
* @param chainId - The chain ID to check (Hex or CAIP-2 format)
|
|
23
|
-
* @returns A selector function that returns true if the network is enabled, false otherwise
|
|
24
|
-
*/
|
|
25
|
-
const selectIsNetworkEnabled = (chainId) => (0, reselect_1.createSelector)(exports.selectEnabledNetworkMap, (enabledNetworkMap) => {
|
|
26
|
-
const { namespace, storageKey } = (0, utils_js_1.deriveKeys)(chainId);
|
|
27
|
-
return (namespace in enabledNetworkMap &&
|
|
28
|
-
storageKey in enabledNetworkMap[namespace] &&
|
|
29
|
-
enabledNetworkMap[namespace][storageKey]);
|
|
30
|
-
});
|
|
31
|
-
exports.selectIsNetworkEnabled = selectIsNetworkEnabled;
|
|
32
|
-
/**
|
|
33
|
-
* Selector builder to get all enabled networks for a specific namespace.
|
|
34
|
-
*
|
|
35
|
-
* The selector returned by this function returns an array of chain IDs (as strings) for all enabled networks
|
|
36
|
-
* within the specified namespace (e.g., 'eip155' for EVM networks, 'solana' for Solana).
|
|
37
|
-
*
|
|
38
|
-
* @param namespace - The CAIP namespace to get enabled networks for (e.g., 'eip155', 'solana')
|
|
39
|
-
* @returns A selector function that returns an array of chain ID strings for enabled networks in the namespace
|
|
40
|
-
*/
|
|
41
|
-
const createSelectorForEnabledNetworksForNamespace = (namespace) => (0, reselect_1.createSelector)(exports.selectEnabledNetworkMap, (enabledNetworkMap) => {
|
|
42
|
-
return Object.entries(enabledNetworkMap[namespace] ?? {})
|
|
43
|
-
.filter(([, enabled]) => enabled)
|
|
44
|
-
.map(([id]) => id);
|
|
45
|
-
});
|
|
46
|
-
exports.createSelectorForEnabledNetworksForNamespace = createSelectorForEnabledNetworksForNamespace;
|
|
47
|
-
/**
|
|
48
|
-
* Selector to get all enabled networks across all namespaces.
|
|
49
|
-
*
|
|
50
|
-
* This selector returns a record where keys are CAIP namespaces and values are arrays
|
|
51
|
-
* of enabled chain IDs within each namespace.
|
|
52
|
-
*
|
|
53
|
-
* @returns A selector function that returns a record mapping namespace to array of enabled chain IDs
|
|
54
|
-
*/
|
|
55
|
-
exports.selectAllEnabledNetworks = (0, reselect_1.createSelector)(exports.selectEnabledNetworkMap, (enabledNetworkMap) => {
|
|
56
|
-
return Object.keys(enabledNetworkMap).reduce((acc, ns) => {
|
|
57
|
-
acc[ns] = Object.entries(enabledNetworkMap[ns])
|
|
58
|
-
.filter(([, enabled]) => enabled)
|
|
59
|
-
.map(([id]) => id);
|
|
60
|
-
return acc;
|
|
61
|
-
}, {});
|
|
62
|
-
});
|
|
63
|
-
/**
|
|
64
|
-
* Selector to get the total count of enabled networks across all namespaces.
|
|
65
|
-
*
|
|
66
|
-
* @returns A selector function that returns the total number of enabled networks
|
|
67
|
-
*/
|
|
68
|
-
exports.selectEnabledNetworksCount = (0, reselect_1.createSelector)(exports.selectAllEnabledNetworks, (allEnabledNetworks) => {
|
|
69
|
-
return Object.values(allEnabledNetworks).flat().length;
|
|
70
|
-
});
|
|
71
|
-
/**
|
|
72
|
-
* Selector to get all enabled EVM networks.
|
|
73
|
-
*
|
|
74
|
-
* This is a convenience selector that specifically targets EIP-155 networks.
|
|
75
|
-
*
|
|
76
|
-
* @returns A selector function that returns an array of enabled EVM chain IDs
|
|
77
|
-
*/
|
|
78
|
-
exports.selectEnabledEvmNetworks = (0, reselect_1.createSelector)((0, exports.createSelectorForEnabledNetworksForNamespace)(utils_1.KnownCaipNamespace.Eip155), (enabledEvmNetworks) => enabledEvmNetworks);
|
|
79
|
-
/**
|
|
80
|
-
* Selector to get all enabled Solana networks.
|
|
81
|
-
*
|
|
82
|
-
* This is a convenience selector that specifically targets Solana networks.
|
|
83
|
-
*
|
|
84
|
-
* @returns A selector function that returns an array of enabled Solana chain IDs
|
|
85
|
-
*/
|
|
86
|
-
exports.selectEnabledSolanaNetworks = (0, reselect_1.createSelector)((0, exports.createSelectorForEnabledNetworksForNamespace)(utils_1.KnownCaipNamespace.Solana), (enabledSolanaNetworks) => enabledSolanaNetworks);
|
|
87
|
-
//# sourceMappingURL=selectors.cjs.map
|
package/dist/selectors.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;AACA,2CAAqD;AACrD,uCAA0C;AAG1C,0CAAwC;AAExC;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,KAAuC,EACvC,EAAE,CA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AAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC;aAChC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;QACrB,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC,CACF,CAAC;AAEF;;;;GAIG;AACU,QAAA,0BAA0B,GAAG,IAAA,yBAAc,EACtD,gCAAwB,EACxB,CAAC,kBAAkB,EAAE,EAAE;IACrB,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC;AACzD,CAAC,CACF,CAAC;AAEF;;;;;;GAMG;AACU,QAAA,wBAAwB,GAAG,IAAA,yBAAc,EACpD,IAAA,oDAA4C,EAAC,0BAAkB,CAAC,MAAM,CAAC,EACvE,CAAC,kBAAkB,EAAE,EAAE,CAAC,kBAAkB,CAC3C,CAAC;AAEF;;;;;;GAMG;AACU,QAAA,2BAA2B,GAAG,IAAA,yBAAc,EACvD,IAAA,oDAA4C,EAAC,0BAAkB,CAAC,MAAM,CAAC,EACvE,CAAC,qBAAqB,EAAE,EAAE,CAAC,qBAAqB,CACjD,CAAC","sourcesContent":["import type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';\nimport { KnownCaipNamespace } from '@metamask/utils';\nimport { createSelector } from 'reselect';\n\nimport type { NetworkEnablementControllerState } from './NetworkEnablementController.js';\nimport { deriveKeys } from './utils.js';\n\n/**\n * Base selector to get the enabled network map from the controller state.\n *\n * @param state - The NetworkEnablementController state\n * @returns The enabled network map\n */\nexport const selectEnabledNetworkMap = (\n state: NetworkEnablementControllerState,\n) => state.enabledNetworkMap;\n\n/**\n * Selector to check if a specific network is enabled.\n *\n * This selector accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and returns whether the network is currently enabled.\n * It returns false for unknown networks or if there's an error parsing the chain ID.\n *\n * @param chainId - The chain ID to check (Hex or CAIP-2 format)\n * @returns A selector function that returns true if the network is enabled, false otherwise\n */\nexport const selectIsNetworkEnabled = (chainId: Hex | CaipChainId) =>\n createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n return (\n namespace in enabledNetworkMap &&\n storageKey in enabledNetworkMap[namespace] &&\n enabledNetworkMap[namespace][storageKey]\n );\n });\n\n/**\n * Selector builder to get all enabled networks for a specific namespace.\n *\n * The selector returned by this function returns an array of chain IDs (as strings) for all enabled networks\n * within the specified namespace (e.g., 'eip155' for EVM networks, 'solana' for Solana).\n *\n * @param namespace - The CAIP namespace to get enabled networks for (e.g., 'eip155', 'solana')\n * @returns A selector function that returns an array of chain ID strings for enabled networks in the namespace\n */\nexport const createSelectorForEnabledNetworksForNamespace = (\n namespace: CaipNamespace,\n) =>\n createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {\n return Object.entries(enabledNetworkMap[namespace] ?? {})\n .filter(([, enabled]) => enabled)\n .map(([id]) => id);\n });\n\n/**\n * Selector to get all enabled networks across all namespaces.\n *\n * This selector returns a record where keys are CAIP namespaces and values are arrays\n * of enabled chain IDs within each namespace.\n *\n * @returns A selector function that returns a record mapping namespace to array of enabled chain IDs\n */\nexport const selectAllEnabledNetworks = createSelector(\n selectEnabledNetworkMap,\n (enabledNetworkMap) => {\n return Object.keys(enabledNetworkMap).reduce<\n Record<CaipNamespace, string[]>\n >((acc, ns) => {\n acc[ns] = Object.entries(enabledNetworkMap[ns])\n .filter(([, enabled]) => enabled)\n .map(([id]) => id);\n return acc;\n }, {});\n },\n);\n\n/**\n * Selector to get the total count of enabled networks across all namespaces.\n *\n * @returns A selector function that returns the total number of enabled networks\n */\nexport const selectEnabledNetworksCount = createSelector(\n selectAllEnabledNetworks,\n (allEnabledNetworks) => {\n return Object.values(allEnabledNetworks).flat().length;\n },\n);\n\n/**\n * Selector to get all enabled EVM networks.\n *\n * This is a convenience selector that specifically targets EIP-155 networks.\n *\n * @returns A selector function that returns an array of enabled EVM chain IDs\n */\nexport const selectEnabledEvmNetworks = createSelector(\n createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Eip155),\n (enabledEvmNetworks) => enabledEvmNetworks,\n);\n\n/**\n * Selector to get all enabled Solana networks.\n *\n * This is a convenience selector that specifically targets Solana networks.\n *\n * @returns A selector function that returns an array of enabled Solana chain IDs\n */\nexport const selectEnabledSolanaNetworks = createSelector(\n createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Solana),\n (enabledSolanaNetworks) => enabledSolanaNetworks,\n);\n"]}
|
package/dist/selectors.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,0CAAyC;AAGzF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,UAC3B,gCAAgC;;CACb,CAAC;AAE7B;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,YAAa,GAAG,GAAG,WAAW;;;;;;;;;;;;;;;;2BAbxD,gCAAgC;;;;;;;;;;CAsBrC,CAAC;AAEL;;;;;;;;GAQG;AACH,eAAO,MAAM,4CAA4C,cAC5C,aAAa;;;;;;;;;;;;;;;;2BAlCjB,gCAAgC;;;;;;;;;;CAwCrC,CAAC;AAEL;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;2BAlD5B,gCAAgC;;;;;;;;;;CA8DxC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BArE9B,gCAAgC;;;;;;;;;;;;;;;;;;CA0ExC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAnF5B,gCAAgC;;;;;;;;;;;;;;;;;;CAsFxC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BA/F/B,gCAAgC;;;;;;;;;;;;;;;;;;CAkGxC,CAAC"}
|
package/dist/selectors.d.mts
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import type { CaipChainId, CaipNamespace, Hex } from "@metamask/utils";
|
|
2
|
-
import type { NetworkEnablementControllerState } from "./NetworkEnablementController.mjs";
|
|
3
|
-
/**
|
|
4
|
-
* Base selector to get the enabled network map from the controller state.
|
|
5
|
-
*
|
|
6
|
-
* @param state - The NetworkEnablementController state
|
|
7
|
-
* @returns The enabled network map
|
|
8
|
-
*/
|
|
9
|
-
export declare const selectEnabledNetworkMap: (state: NetworkEnablementControllerState) => {
|
|
10
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Selector to check if a specific network is enabled.
|
|
14
|
-
*
|
|
15
|
-
* This selector accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID
|
|
16
|
-
* (for any blockchain network) and returns whether the network is currently enabled.
|
|
17
|
-
* It returns false for unknown networks or if there's an error parsing the chain ID.
|
|
18
|
-
*
|
|
19
|
-
* @param chainId - The chain ID to check (Hex or CAIP-2 format)
|
|
20
|
-
* @returns A selector function that returns true if the network is enabled, false otherwise
|
|
21
|
-
*/
|
|
22
|
-
export declare const selectIsNetworkEnabled: (chainId: Hex | CaipChainId) => ((state: NetworkEnablementControllerState) => boolean) & {
|
|
23
|
-
clearCache: () => void;
|
|
24
|
-
resultsCount: () => number;
|
|
25
|
-
resetResultsCount: () => void;
|
|
26
|
-
} & {
|
|
27
|
-
resultFunc: (resultFuncArgs_0: {
|
|
28
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
29
|
-
}) => boolean;
|
|
30
|
-
memoizedResultFunc: ((resultFuncArgs_0: {
|
|
31
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
32
|
-
}) => boolean) & {
|
|
33
|
-
clearCache: () => void;
|
|
34
|
-
resultsCount: () => number;
|
|
35
|
-
resetResultsCount: () => void;
|
|
36
|
-
};
|
|
37
|
-
lastResult: () => boolean;
|
|
38
|
-
dependencies: [(state: NetworkEnablementControllerState) => {
|
|
39
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
40
|
-
}];
|
|
41
|
-
recomputations: () => number;
|
|
42
|
-
resetRecomputations: () => void;
|
|
43
|
-
dependencyRecomputations: () => number;
|
|
44
|
-
resetDependencyRecomputations: () => void;
|
|
45
|
-
} & {
|
|
46
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
47
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Selector builder to get all enabled networks for a specific namespace.
|
|
51
|
-
*
|
|
52
|
-
* The selector returned by this function returns an array of chain IDs (as strings) for all enabled networks
|
|
53
|
-
* within the specified namespace (e.g., 'eip155' for EVM networks, 'solana' for Solana).
|
|
54
|
-
*
|
|
55
|
-
* @param namespace - The CAIP namespace to get enabled networks for (e.g., 'eip155', 'solana')
|
|
56
|
-
* @returns A selector function that returns an array of chain ID strings for enabled networks in the namespace
|
|
57
|
-
*/
|
|
58
|
-
export declare const createSelectorForEnabledNetworksForNamespace: (namespace: CaipNamespace) => ((state: NetworkEnablementControllerState) => string[]) & {
|
|
59
|
-
clearCache: () => void;
|
|
60
|
-
resultsCount: () => number;
|
|
61
|
-
resetResultsCount: () => void;
|
|
62
|
-
} & {
|
|
63
|
-
resultFunc: (resultFuncArgs_0: {
|
|
64
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
65
|
-
}) => string[];
|
|
66
|
-
memoizedResultFunc: ((resultFuncArgs_0: {
|
|
67
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
68
|
-
}) => string[]) & {
|
|
69
|
-
clearCache: () => void;
|
|
70
|
-
resultsCount: () => number;
|
|
71
|
-
resetResultsCount: () => void;
|
|
72
|
-
};
|
|
73
|
-
lastResult: () => string[];
|
|
74
|
-
dependencies: [(state: NetworkEnablementControllerState) => {
|
|
75
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
76
|
-
}];
|
|
77
|
-
recomputations: () => number;
|
|
78
|
-
resetRecomputations: () => void;
|
|
79
|
-
dependencyRecomputations: () => number;
|
|
80
|
-
resetDependencyRecomputations: () => void;
|
|
81
|
-
} & {
|
|
82
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
83
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Selector to get all enabled networks across all namespaces.
|
|
87
|
-
*
|
|
88
|
-
* This selector returns a record where keys are CAIP namespaces and values are arrays
|
|
89
|
-
* of enabled chain IDs within each namespace.
|
|
90
|
-
*
|
|
91
|
-
* @returns A selector function that returns a record mapping namespace to array of enabled chain IDs
|
|
92
|
-
*/
|
|
93
|
-
export declare const selectAllEnabledNetworks: ((state: NetworkEnablementControllerState) => Record<string, string[]>) & {
|
|
94
|
-
clearCache: () => void;
|
|
95
|
-
resultsCount: () => number;
|
|
96
|
-
resetResultsCount: () => void;
|
|
97
|
-
} & {
|
|
98
|
-
resultFunc: (resultFuncArgs_0: {
|
|
99
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
100
|
-
}) => Record<string, string[]>;
|
|
101
|
-
memoizedResultFunc: ((resultFuncArgs_0: {
|
|
102
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
103
|
-
}) => Record<string, string[]>) & {
|
|
104
|
-
clearCache: () => void;
|
|
105
|
-
resultsCount: () => number;
|
|
106
|
-
resetResultsCount: () => void;
|
|
107
|
-
};
|
|
108
|
-
lastResult: () => Record<string, string[]>;
|
|
109
|
-
dependencies: [(state: NetworkEnablementControllerState) => {
|
|
110
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
111
|
-
}];
|
|
112
|
-
recomputations: () => number;
|
|
113
|
-
resetRecomputations: () => void;
|
|
114
|
-
dependencyRecomputations: () => number;
|
|
115
|
-
resetDependencyRecomputations: () => void;
|
|
116
|
-
} & {
|
|
117
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
118
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* Selector to get the total count of enabled networks across all namespaces.
|
|
122
|
-
*
|
|
123
|
-
* @returns A selector function that returns the total number of enabled networks
|
|
124
|
-
*/
|
|
125
|
-
export declare const selectEnabledNetworksCount: ((state: NetworkEnablementControllerState) => number) & {
|
|
126
|
-
clearCache: () => void;
|
|
127
|
-
resultsCount: () => number;
|
|
128
|
-
resetResultsCount: () => void;
|
|
129
|
-
} & {
|
|
130
|
-
resultFunc: (resultFuncArgs_0: Record<string, string[]>) => number;
|
|
131
|
-
memoizedResultFunc: ((resultFuncArgs_0: Record<string, string[]>) => number) & {
|
|
132
|
-
clearCache: () => void;
|
|
133
|
-
resultsCount: () => number;
|
|
134
|
-
resetResultsCount: () => void;
|
|
135
|
-
};
|
|
136
|
-
lastResult: () => number;
|
|
137
|
-
dependencies: [((state: NetworkEnablementControllerState) => Record<string, string[]>) & {
|
|
138
|
-
clearCache: () => void;
|
|
139
|
-
resultsCount: () => number;
|
|
140
|
-
resetResultsCount: () => void;
|
|
141
|
-
} & {
|
|
142
|
-
resultFunc: (resultFuncArgs_0: {
|
|
143
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
144
|
-
}) => Record<string, string[]>;
|
|
145
|
-
memoizedResultFunc: ((resultFuncArgs_0: {
|
|
146
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
147
|
-
}) => Record<string, string[]>) & {
|
|
148
|
-
clearCache: () => void;
|
|
149
|
-
resultsCount: () => number;
|
|
150
|
-
resetResultsCount: () => void;
|
|
151
|
-
};
|
|
152
|
-
lastResult: () => Record<string, string[]>;
|
|
153
|
-
dependencies: [(state: NetworkEnablementControllerState) => {
|
|
154
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
155
|
-
}];
|
|
156
|
-
recomputations: () => number;
|
|
157
|
-
resetRecomputations: () => void;
|
|
158
|
-
dependencyRecomputations: () => number;
|
|
159
|
-
resetDependencyRecomputations: () => void;
|
|
160
|
-
} & {
|
|
161
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
162
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
163
|
-
}];
|
|
164
|
-
recomputations: () => number;
|
|
165
|
-
resetRecomputations: () => void;
|
|
166
|
-
dependencyRecomputations: () => number;
|
|
167
|
-
resetDependencyRecomputations: () => void;
|
|
168
|
-
} & {
|
|
169
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
170
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* Selector to get all enabled EVM networks.
|
|
174
|
-
*
|
|
175
|
-
* This is a convenience selector that specifically targets EIP-155 networks.
|
|
176
|
-
*
|
|
177
|
-
* @returns A selector function that returns an array of enabled EVM chain IDs
|
|
178
|
-
*/
|
|
179
|
-
export declare const selectEnabledEvmNetworks: ((state: NetworkEnablementControllerState) => string[]) & {
|
|
180
|
-
clearCache: () => void;
|
|
181
|
-
resultsCount: () => number;
|
|
182
|
-
resetResultsCount: () => void;
|
|
183
|
-
} & {
|
|
184
|
-
resultFunc: (resultFuncArgs_0: string[]) => string[];
|
|
185
|
-
memoizedResultFunc: ((resultFuncArgs_0: string[]) => string[]) & {
|
|
186
|
-
clearCache: () => void;
|
|
187
|
-
resultsCount: () => number;
|
|
188
|
-
resetResultsCount: () => void;
|
|
189
|
-
};
|
|
190
|
-
lastResult: () => string[];
|
|
191
|
-
dependencies: [((state: NetworkEnablementControllerState) => string[]) & {
|
|
192
|
-
clearCache: () => void;
|
|
193
|
-
resultsCount: () => number;
|
|
194
|
-
resetResultsCount: () => void;
|
|
195
|
-
} & {
|
|
196
|
-
resultFunc: (resultFuncArgs_0: {
|
|
197
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
198
|
-
}) => string[];
|
|
199
|
-
memoizedResultFunc: ((resultFuncArgs_0: {
|
|
200
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
201
|
-
}) => string[]) & {
|
|
202
|
-
clearCache: () => void;
|
|
203
|
-
resultsCount: () => number;
|
|
204
|
-
resetResultsCount: () => void;
|
|
205
|
-
};
|
|
206
|
-
lastResult: () => string[];
|
|
207
|
-
dependencies: [(state: NetworkEnablementControllerState) => {
|
|
208
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
209
|
-
}];
|
|
210
|
-
recomputations: () => number;
|
|
211
|
-
resetRecomputations: () => void;
|
|
212
|
-
dependencyRecomputations: () => number;
|
|
213
|
-
resetDependencyRecomputations: () => void;
|
|
214
|
-
} & {
|
|
215
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
216
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
217
|
-
}];
|
|
218
|
-
recomputations: () => number;
|
|
219
|
-
resetRecomputations: () => void;
|
|
220
|
-
dependencyRecomputations: () => number;
|
|
221
|
-
resetDependencyRecomputations: () => void;
|
|
222
|
-
} & {
|
|
223
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
224
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
225
|
-
};
|
|
226
|
-
/**
|
|
227
|
-
* Selector to get all enabled Solana networks.
|
|
228
|
-
*
|
|
229
|
-
* This is a convenience selector that specifically targets Solana networks.
|
|
230
|
-
*
|
|
231
|
-
* @returns A selector function that returns an array of enabled Solana chain IDs
|
|
232
|
-
*/
|
|
233
|
-
export declare const selectEnabledSolanaNetworks: ((state: NetworkEnablementControllerState) => string[]) & {
|
|
234
|
-
clearCache: () => void;
|
|
235
|
-
resultsCount: () => number;
|
|
236
|
-
resetResultsCount: () => void;
|
|
237
|
-
} & {
|
|
238
|
-
resultFunc: (resultFuncArgs_0: string[]) => string[];
|
|
239
|
-
memoizedResultFunc: ((resultFuncArgs_0: string[]) => string[]) & {
|
|
240
|
-
clearCache: () => void;
|
|
241
|
-
resultsCount: () => number;
|
|
242
|
-
resetResultsCount: () => void;
|
|
243
|
-
};
|
|
244
|
-
lastResult: () => string[];
|
|
245
|
-
dependencies: [((state: NetworkEnablementControllerState) => string[]) & {
|
|
246
|
-
clearCache: () => void;
|
|
247
|
-
resultsCount: () => number;
|
|
248
|
-
resetResultsCount: () => void;
|
|
249
|
-
} & {
|
|
250
|
-
resultFunc: (resultFuncArgs_0: {
|
|
251
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
252
|
-
}) => string[];
|
|
253
|
-
memoizedResultFunc: ((resultFuncArgs_0: {
|
|
254
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
255
|
-
}) => string[]) & {
|
|
256
|
-
clearCache: () => void;
|
|
257
|
-
resultsCount: () => number;
|
|
258
|
-
resetResultsCount: () => void;
|
|
259
|
-
};
|
|
260
|
-
lastResult: () => string[];
|
|
261
|
-
dependencies: [(state: NetworkEnablementControllerState) => {
|
|
262
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
263
|
-
}];
|
|
264
|
-
recomputations: () => number;
|
|
265
|
-
resetRecomputations: () => void;
|
|
266
|
-
dependencyRecomputations: () => number;
|
|
267
|
-
resetDependencyRecomputations: () => void;
|
|
268
|
-
} & {
|
|
269
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
270
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
271
|
-
}];
|
|
272
|
-
recomputations: () => number;
|
|
273
|
-
resetRecomputations: () => void;
|
|
274
|
-
dependencyRecomputations: () => number;
|
|
275
|
-
resetDependencyRecomputations: () => void;
|
|
276
|
-
} & {
|
|
277
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
278
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
279
|
-
};
|
|
280
|
-
//# sourceMappingURL=selectors.d.mts.map
|
package/dist/selectors.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,0CAAyC;AAGzF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,UAC3B,gCAAgC;;CACb,CAAC;AAE7B;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,YAAa,GAAG,GAAG,WAAW;;;;;;;;;;;;;;;;2BAbxD,gCAAgC;;;;;;;;;;CAsBrC,CAAC;AAEL;;;;;;;;GAQG;AACH,eAAO,MAAM,4CAA4C,cAC5C,aAAa;;;;;;;;;;;;;;;;2BAlCjB,gCAAgC;;;;;;;;;;CAwCrC,CAAC;AAEL;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;2BAlD5B,gCAAgC;;;;;;;;;;CA8DxC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BArE9B,gCAAgC;;;;;;;;;;;;;;;;;;CA0ExC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAnF5B,gCAAgC;;;;;;;;;;;;;;;;;;CAsFxC,CAAC;AAEF;;;;;;GAMG;AACH,eAA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;AACvB,CAAC,CAAC,CAAC;AAEL;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CACpD,uBAAuB,EACvB,CAAC,iBAAiB,EAAE,EAAE;IACpB,OAAO,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAE1C,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE;QACZ,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;aAC5C,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC;aAChC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;QACrB,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC,CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,cAAc,CACtD,wBAAwB,EACxB,CAAC,kBAAkB,EAAE,EAAE;IACrB,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC;AACzD,CAAC,CACF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CACpD,4CAA4C,CAAC,kBAAkB,CAAC,MAAM,CAAC,EACvE,CAAC,kBAAkB,EAAE,EAAE,CAAC,kBAAkB,CAC3C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,cAAc,CACvD,4CAA4C,CAAC,kBAAkB,CAAC,MAAM,CAAC,EACvE,CAAC,qBAAqB,EAAE,EAAE,CAAC,qBAAqB,CACjD,CAAC","sourcesContent":["import type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';\nimport { KnownCaipNamespace } from '@metamask/utils';\nimport { createSelector } from 'reselect';\n\nimport type { NetworkEnablementControllerState } from './NetworkEnablementController.js';\nimport { deriveKeys } from './utils.js';\n\n/**\n * Base selector to get the enabled network map from the controller state.\n *\n * @param state - The NetworkEnablementController state\n * @returns The enabled network map\n */\nexport const selectEnabledNetworkMap = (\n state: NetworkEnablementControllerState,\n) => state.enabledNetworkMap;\n\n/**\n * Selector to check if a specific network is enabled.\n *\n * This selector accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and returns whether the network is currently enabled.\n * It returns false for unknown networks or if there's an error parsing the chain ID.\n *\n * @param chainId - The chain ID to check (Hex or CAIP-2 format)\n * @returns A selector function that returns true if the network is enabled, false otherwise\n */\nexport const selectIsNetworkEnabled = (chainId: Hex | CaipChainId) =>\n createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n return (\n namespace in enabledNetworkMap &&\n storageKey in enabledNetworkMap[namespace] &&\n enabledNetworkMap[namespace][storageKey]\n );\n });\n\n/**\n * Selector builder to get all enabled networks for a specific namespace.\n *\n * The selector returned by this function returns an array of chain IDs (as strings) for all enabled networks\n * within the specified namespace (e.g., 'eip155' for EVM networks, 'solana' for Solana).\n *\n * @param namespace - The CAIP namespace to get enabled networks for (e.g., 'eip155', 'solana')\n * @returns A selector function that returns an array of chain ID strings for enabled networks in the namespace\n */\nexport const createSelectorForEnabledNetworksForNamespace = (\n namespace: CaipNamespace,\n) =>\n createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {\n return Object.entries(enabledNetworkMap[namespace] ?? {})\n .filter(([, enabled]) => enabled)\n .map(([id]) => id);\n });\n\n/**\n * Selector to get all enabled networks across all namespaces.\n *\n * This selector returns a record where keys are CAIP namespaces and values are arrays\n * of enabled chain IDs within each namespace.\n *\n * @returns A selector function that returns a record mapping namespace to array of enabled chain IDs\n */\nexport const selectAllEnabledNetworks = createSelector(\n selectEnabledNetworkMap,\n (enabledNetworkMap) => {\n return Object.keys(enabledNetworkMap).reduce<\n Record<CaipNamespace, string[]>\n >((acc, ns) => {\n acc[ns] = Object.entries(enabledNetworkMap[ns])\n .filter(([, enabled]) => enabled)\n .map(([id]) => id);\n return acc;\n }, {});\n },\n);\n\n/**\n * Selector to get the total count of enabled networks across all namespaces.\n *\n * @returns A selector function that returns the total number of enabled networks\n */\nexport const selectEnabledNetworksCount = createSelector(\n selectAllEnabledNetworks,\n (allEnabledNetworks) => {\n return Object.values(allEnabledNetworks).flat().length;\n },\n);\n\n/**\n * Selector to get all enabled EVM networks.\n *\n * This is a convenience selector that specifically targets EIP-155 networks.\n *\n * @returns A selector function that returns an array of enabled EVM chain IDs\n */\nexport const selectEnabledEvmNetworks = createSelector(\n createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Eip155),\n (enabledEvmNetworks) => enabledEvmNetworks,\n);\n\n/**\n * Selector to get all enabled Solana networks.\n *\n * This is a convenience selector that specifically targets Solana networks.\n *\n * @returns A selector function that returns an array of enabled Solana chain IDs\n */\nexport const selectEnabledSolanaNetworks = createSelector(\n createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Solana),\n (enabledSolanaNetworks) => enabledSolanaNetworks,\n);\n"]}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
var _a, _Slip44Service_chainIdCache, _Slip44Service_fetchPromise, _Slip44Service_symbolCache, _Slip44Service_fetchChainData;
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.Slip44Service = void 0;
|
|
19
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
20
|
-
// @ts-expect-error: No type definitions for '@metamask/slip44'
|
|
21
|
-
const slip44_1 = __importDefault(require("@metamask/slip44"));
|
|
22
|
-
const CHAINID_NETWORK_URL = 'https://chainid.network/chains.json';
|
|
23
|
-
/**
|
|
24
|
-
* Service for looking up SLIP-44 coin type identifiers.
|
|
25
|
-
*
|
|
26
|
-
* SLIP-44 defines registered coin types used in BIP-44 derivation paths.
|
|
27
|
-
*
|
|
28
|
-
* This service provides two lookup methods:
|
|
29
|
-
* 1. `getEvmSlip44` - For EVM networks, uses chainid.network data (recommended for eip155)
|
|
30
|
-
* 2. `getSlip44BySymbol` - Fallback method using @metamask/slip44 package
|
|
31
|
-
*
|
|
32
|
-
* @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
|
33
|
-
* @see https://chainid.network/chains.json
|
|
34
|
-
*/
|
|
35
|
-
/**
|
|
36
|
-
* Manual overrides for EVM chain IDs where chainid.network returns
|
|
37
|
-
* an incorrect SLIP-44 value due to chain ID collisions.
|
|
38
|
-
*/
|
|
39
|
-
const EVM_SLIP44_OVERRIDES = new Map([
|
|
40
|
-
[999, 2457], // HyperEVM — chainid.network returns 1 (Wanchain collision)
|
|
41
|
-
]);
|
|
42
|
-
class Slip44Service {
|
|
43
|
-
/**
|
|
44
|
-
* Gets the SLIP-44 coin type identifier for an EVM network by chain ID.
|
|
45
|
-
*
|
|
46
|
-
* **IMPORTANT: This method is for EVM networks only (eip155 namespace).**
|
|
47
|
-
* For non-EVM networks (Bitcoin, Solana, Tron, etc.), use `getSlip44BySymbol`.
|
|
48
|
-
*
|
|
49
|
-
* This method checks chainid.network data (which maps chainId directly
|
|
50
|
-
* to slip44). If not found, defaults to 60 (Ethereum).
|
|
51
|
-
*
|
|
52
|
-
* @param chainId - The EVM chain ID as a number (e.g., 1 for Ethereum, 56 for BNB Chain)
|
|
53
|
-
* @returns The SLIP-44 coin type number (defaults to 60 if not found)
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* // For EVM networks only
|
|
57
|
-
* const ethCoinType = await Slip44Service.getEvmSlip44(1);
|
|
58
|
-
* // Returns 60
|
|
59
|
-
*
|
|
60
|
-
* const bnbCoinType = await Slip44Service.getEvmSlip44(56);
|
|
61
|
-
* // Returns 714
|
|
62
|
-
*
|
|
63
|
-
* const unknownEvmChain = await Slip44Service.getEvmSlip44(99999);
|
|
64
|
-
* // Returns 60 (default for EVM)
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
static async getEvmSlip44(chainId) {
|
|
68
|
-
const override = EVM_SLIP44_OVERRIDES.get(chainId);
|
|
69
|
-
if (override !== undefined) {
|
|
70
|
-
return override;
|
|
71
|
-
}
|
|
72
|
-
// Ensure chain data is loaded
|
|
73
|
-
await __classPrivateFieldGet(this, _a, "m", _Slip44Service_fetchChainData).call(this);
|
|
74
|
-
// Check chainId cache first
|
|
75
|
-
const cached = __classPrivateFieldGet(this, _a, "f", _Slip44Service_chainIdCache)?.get(chainId);
|
|
76
|
-
if (cached !== undefined) {
|
|
77
|
-
return cached;
|
|
78
|
-
}
|
|
79
|
-
// Default to 60 (Ethereum) for EVM networks without specific mapping
|
|
80
|
-
return 60;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Gets the SLIP-44 coin type identifier for a non-EVM network by symbol.
|
|
84
|
-
*
|
|
85
|
-
* **IMPORTANT: This method is for non-EVM networks only (Bitcoin, Solana, Tron, etc.).**
|
|
86
|
-
* For EVM networks (eip155 namespace), use `getEvmSlip44` instead.
|
|
87
|
-
*
|
|
88
|
-
* Note: Symbol lookup may return incorrect results for duplicate symbols
|
|
89
|
-
* (e.g., CPC is both CPChain and Capricoin).
|
|
90
|
-
*
|
|
91
|
-
* @param symbol - The network symbol (e.g., 'ETH', 'BTC', 'SOL')
|
|
92
|
-
* @returns The SLIP-44 coin type number, or undefined if not found
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* const ethCoinType = Slip44Service.getSlip44BySymbol('ETH');
|
|
96
|
-
* // Returns 60
|
|
97
|
-
*
|
|
98
|
-
* const btcCoinType = Slip44Service.getSlip44BySymbol('BTC');
|
|
99
|
-
* // Returns 0
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
static getSlip44BySymbol(symbol) {
|
|
103
|
-
// Check cache first
|
|
104
|
-
if (__classPrivateFieldGet(this, _a, "f", _Slip44Service_symbolCache).has(symbol)) {
|
|
105
|
-
return __classPrivateFieldGet(this, _a, "f", _Slip44Service_symbolCache).get(symbol);
|
|
106
|
-
}
|
|
107
|
-
const slip44Data = slip44_1.default;
|
|
108
|
-
const upperSymbol = symbol.toUpperCase();
|
|
109
|
-
// Iterate through all entries to find matching symbol
|
|
110
|
-
// Note: Object.keys returns numeric keys in ascending order,
|
|
111
|
-
// so for duplicate symbols we get the lowest coin type first
|
|
112
|
-
// (which is the convention for resolving duplicates)
|
|
113
|
-
for (const key of Object.keys(slip44Data)) {
|
|
114
|
-
const entry = slip44Data[key];
|
|
115
|
-
if (entry.symbol.toUpperCase() === upperSymbol) {
|
|
116
|
-
const coinType = parseInt(key, 10);
|
|
117
|
-
__classPrivateFieldGet(this, _a, "f", _Slip44Service_symbolCache).set(symbol, coinType);
|
|
118
|
-
return coinType;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// Cache the miss as well to avoid repeated lookups
|
|
122
|
-
__classPrivateFieldGet(this, _a, "f", _Slip44Service_symbolCache).set(symbol, undefined);
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Clears all internal caches.
|
|
127
|
-
* Useful for testing or if the underlying data might change.
|
|
128
|
-
*/
|
|
129
|
-
static clearCache() {
|
|
130
|
-
__classPrivateFieldGet(this, _a, "f", _Slip44Service_symbolCache).clear();
|
|
131
|
-
__classPrivateFieldSet(this, _a, null, "f", _Slip44Service_chainIdCache);
|
|
132
|
-
__classPrivateFieldSet(this, _a, null, "f", _Slip44Service_fetchPromise);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.Slip44Service = Slip44Service;
|
|
136
|
-
_a = Slip44Service, _Slip44Service_fetchChainData = async function _Slip44Service_fetchChainData() {
|
|
137
|
-
if (__classPrivateFieldGet(this, _a, "f", _Slip44Service_chainIdCache) !== null) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
// Avoid duplicate fetches
|
|
141
|
-
if (__classPrivateFieldGet(this, _a, "f", _Slip44Service_fetchPromise)) {
|
|
142
|
-
await __classPrivateFieldGet(this, _a, "f", _Slip44Service_fetchPromise);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
__classPrivateFieldSet(this, _a, (async () => {
|
|
146
|
-
try {
|
|
147
|
-
const chains = await (0, controller_utils_1.fetchWithErrorHandling)({
|
|
148
|
-
url: CHAINID_NETWORK_URL,
|
|
149
|
-
timeout: 10000,
|
|
150
|
-
});
|
|
151
|
-
if (chains && Array.isArray(chains)) {
|
|
152
|
-
__classPrivateFieldSet(this, _a, new Map(chains
|
|
153
|
-
.filter((chain) => chain.slip44 !== undefined)
|
|
154
|
-
.map((chain) => [chain.chainId, chain.slip44])), "f", _Slip44Service_chainIdCache);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
// Invalid response, initialize empty cache
|
|
158
|
-
__classPrivateFieldSet(this, _a, new Map(), "f", _Slip44Service_chainIdCache);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch {
|
|
162
|
-
// Network failed, initialize empty cache so we fall back to symbol lookup
|
|
163
|
-
__classPrivateFieldSet(this, _a, new Map(), "f", _Slip44Service_chainIdCache);
|
|
164
|
-
}
|
|
165
|
-
})(), "f", _Slip44Service_fetchPromise);
|
|
166
|
-
await __classPrivateFieldGet(this, _a, "f", _Slip44Service_fetchPromise);
|
|
167
|
-
__classPrivateFieldSet(this, _a, null, "f", _Slip44Service_fetchPromise);
|
|
168
|
-
};
|
|
169
|
-
/**
|
|
170
|
-
* Cache for chainId to slip44 lookups from chainid.network.
|
|
171
|
-
*/
|
|
172
|
-
_Slip44Service_chainIdCache = { value: null };
|
|
173
|
-
/**
|
|
174
|
-
* Whether a fetch is currently in progress.
|
|
175
|
-
*/
|
|
176
|
-
_Slip44Service_fetchPromise = { value: null };
|
|
177
|
-
/**
|
|
178
|
-
* Cache for symbol to slip44 index lookups.
|
|
179
|
-
* This avoids iterating through all entries on repeated lookups.
|
|
180
|
-
*/
|
|
181
|
-
_Slip44Service_symbolCache = { value: new Map() };
|
|
182
|
-
//# sourceMappingURL=Slip44Service.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Slip44Service.cjs","sourceRoot":"","sources":["../../src/services/Slip44Service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,iEAAoE;AACpE,+DAA+D;AAC/D,8DAAsC;AAEtC,MAAM,mBAAmB,GAAG,qCAAqC,CAAC;AAoClE;;;;;;;;;;;GAWG;AACH;;;GAGG;AACH,MAAM,oBAAoB,GAAgC,IAAI,GAAG,CAAC;IAChE,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,4DAA4D;CAC1E,CAAC,CAAC;AAEH,MAAa,aAAa;IA+DxB;;;;;;;;;;;;;;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AAG,EAAE,mCAAA,CAAC;YACjC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,0EAA0E;YAC1E,uBAAA,IAAI,MAAiB,IAAI,GAAG,EAAE,mCAAA,CAAC;QACjC,CAAC;IACH,CAAC,CAAC,EAAE,mCAAA,CAAC;IAEL,MAAM,uBAAA,IAAI,uCAAc,CAAC;IACzB,uBAAA,IAAI,MAAiB,IAAI,mCAAA,CAAC;AAC5B,CAAC;AA5DD;;GAEG;AACI,uCAA4C,IAAI,EAAnC,CAAoC;AAExD;;GAEG;AACI,uCAAsC,IAAI,EAA7B,CAA8B;AAElD;;;GAGG;AACa,sCAAgD,IAAI,GAAG,EAAE,EAA7C,CAA8C","sourcesContent":["import { fetchWithErrorHandling } from '@metamask/controller-utils';\n// @ts-expect-error: No type definitions for '@metamask/slip44'\nimport slip44 from '@metamask/slip44';\n\nconst CHAINID_NETWORK_URL = 'https://chainid.network/chains.json';\n\n/**\n * Represents a single SLIP-44 entry with its metadata.\n */\nexport type Slip44Entry = {\n index: string;\n symbol: string;\n name: string;\n};\n\n/**\n * Chain data from chainid.network\n */\ntype ChainIdNetworkEntry = {\n chainId: number;\n slip44?: number;\n nativeCurrency?: {\n symbol: string;\n };\n};\n\n/**\n * Internal type for SLIP-44 data from the @metamask/slip44 package.\n * Includes the hex field which we don't expose externally.\n */\ntype Slip44DataEntry = Slip44Entry & {\n // eslint-disable-next-line id-denylist\n hex: `0x${string}`;\n};\n\n/**\n * The SLIP-44 mapping type from the @metamask/slip44 package.\n */\ntype Slip44Data = Record<string, Slip44DataEntry>;\n\n/**\n * Service for looking up SLIP-44 coin type identifiers.\n *\n * SLIP-44 defines registered coin types used in BIP-44 derivation paths.\n *\n * This service provides two lookup methods:\n * 1. `getEvmSlip44` - For EVM networks, uses chainid.network data (recommended for eip155)\n * 2. `getSlip44BySymbol` - Fallback method using @metamask/slip44 package\n *\n * @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md\n * @see https://chainid.network/chains.json\n */\n/**\n * Manual overrides for EVM chain IDs where chainid.network returns\n * an incorrect SLIP-44 value due to chain ID collisions.\n */\nconst EVM_SLIP44_OVERRIDES: ReadonlyMap<number, number> = new Map([\n [999, 2457], // HyperEVM — chainid.network returns 1 (Wanchain collision)\n]);\n\nexport class Slip44Service {\n /**\n * Cache for chainId to slip44 lookups from chainid.network.\n */\n static #chainIdCache: Map<number, number> | null = null;\n\n /**\n * Whether a fetch is currently in progress.\n */\n static #fetchPromise: Promise<void> | null = null;\n\n /**\n * Cache for symbol to slip44 index lookups.\n * This avoids iterating through all entries on repeated lookups.\n */\n static readonly #symbolCache: Map<string, number | undefined> = new Map();\n\n /**\n * Fetches and caches chain data from chainid.network.\n * This is called automatically by getEvmSlip44.\n */\n static async #fetchChainData(): Promise<void> {\n if (this.#chainIdCache !== null) {\n return;\n }\n\n // Avoid duplicate fetches\n if (this.#fetchPromise) {\n await this.#fetchPromise;\n return;\n }\n\n this.#fetchPromise = (async (): Promise<void> => {\n try {\n const chains: ChainIdNetworkEntry[] | undefined =\n await fetchWithErrorHandling({\n url: CHAINID_NETWORK_URL,\n timeout: 10000,\n });\n\n if (chains && Array.isArray(chains)) {\n this.#chainIdCache = new Map(\n chains\n .filter(\n (chain): chain is ChainIdNetworkEntry & { slip44: number } =>\n chain.slip44 !== undefined,\n )\n .map((chain) => [chain.chainId, chain.slip44]),\n );\n } else {\n // Invalid response, initialize empty cache\n this.#chainIdCache = new Map();\n }\n } catch {\n // Network failed, initialize empty cache so we fall back to symbol lookup\n this.#chainIdCache = new Map();\n }\n })();\n\n await this.#fetchPromise;\n this.#fetchPromise = null;\n }\n\n /**\n * Gets the SLIP-44 coin type identifier for an EVM network by chain ID.\n *\n * **IMPORTANT: This method is for EVM networks only (eip155 namespace).**\n * For non-EVM networks (Bitcoin, Solana, Tron, etc.), use `getSlip44BySymbol`.\n *\n * This method checks chainid.network data (which maps chainId directly\n * to slip44). If not found, defaults to 60 (Ethereum).\n *\n * @param chainId - The EVM chain ID as a number (e.g., 1 for Ethereum, 56 for BNB Chain)\n * @returns The SLIP-44 coin type number (defaults to 60 if not found)\n * @example\n * ```typescript\n * // For EVM networks only\n * const ethCoinType = await Slip44Service.getEvmSlip44(1);\n * // Returns 60\n *\n * const bnbCoinType = await Slip44Service.getEvmSlip44(56);\n * // Returns 714\n *\n * const unknownEvmChain = await Slip44Service.getEvmSlip44(99999);\n * // Returns 60 (default for EVM)\n * ```\n */\n static async getEvmSlip44(chainId: number): Promise<number> {\n const override = EVM_SLIP44_OVERRIDES.get(chainId);\n if (override !== undefined) {\n return override;\n }\n\n // Ensure chain data is loaded\n await this.#fetchChainData();\n\n // Check chainId cache first\n const cached = this.#chainIdCache?.get(chainId);\n if (cached !== undefined) {\n return cached;\n }\n\n // Default to 60 (Ethereum) for EVM networks without specific mapping\n return 60;\n }\n\n /**\n * Gets the SLIP-44 coin type identifier for a non-EVM network by symbol.\n *\n * **IMPORTANT: This method is for non-EVM networks only (Bitcoin, Solana, Tron, etc.).**\n * For EVM networks (eip155 namespace), use `getEvmSlip44` instead.\n *\n * Note: Symbol lookup may return incorrect results for duplicate symbols\n * (e.g., CPC is both CPChain and Capricoin).\n *\n * @param symbol - The network symbol (e.g., 'ETH', 'BTC', 'SOL')\n * @returns The SLIP-44 coin type number, or undefined if not found\n * @example\n * ```typescript\n * const ethCoinType = Slip44Service.getSlip44BySymbol('ETH');\n * // Returns 60\n *\n * const btcCoinType = Slip44Service.getSlip44BySymbol('BTC');\n * // Returns 0\n * ```\n */\n static getSlip44BySymbol(symbol: string): number | undefined {\n // Check cache first\n if (this.#symbolCache.has(symbol)) {\n return this.#symbolCache.get(symbol);\n }\n\n const slip44Data = slip44 as Slip44Data;\n const upperSymbol = symbol.toUpperCase();\n\n // Iterate through all entries to find matching symbol\n // Note: Object.keys returns numeric keys in ascending order,\n // so for duplicate symbols we get the lowest coin type first\n // (which is the convention for resolving duplicates)\n for (const key of Object.keys(slip44Data)) {\n const entry = slip44Data[key];\n if (entry.symbol.toUpperCase() === upperSymbol) {\n const coinType = parseInt(key, 10);\n this.#symbolCache.set(symbol, coinType);\n return coinType;\n }\n }\n\n // Cache the miss as well to avoid repeated lookups\n this.#symbolCache.set(symbol, undefined);\n return undefined;\n }\n\n /**\n * Clears all internal caches.\n * Useful for testing or if the underlying data might change.\n */\n static clearCache(): void {\n this.#symbolCache.clear();\n this.#chainIdCache = null;\n this.#fetchPromise = null;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Slip44Service.d.cts","sourceRoot":"","sources":["../../src/services/Slip44Service.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AA+CF,qBAAa,aAAa;;IA+DxB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;WACU,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmB3D;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IA2B5D;;;OAGG;IACH,MAAM,CAAC,UAAU,IAAI,IAAI;CAK1B"}
|