@metamask-previews/network-enablement-controller 6.0.5-preview-5b293ee50 → 6.0.5-preview-3866c0ff1
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 +1 -0
- 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 +12 -16
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAmB;IAC9C,KAAK,EAAE,mBAAmB;IAC1B,QAAQ,EAAE,gBAAgB;IAC1B,QAAQ,EAAE,cAAc;IACxB,QAAQ,EAAE,uBAAuB;IACjC,QAAQ,EAAE,4BAA4B;IACtC,MAAM,EAAE,uBAAuB;IAC/B,KAAK,EAAE,gBAAgB;IACvB,MAAM,EAAE,gBAAgB;IACxB,OAAO,EAAE,0CAA0C;IACnD,OAAO,EAAE,mBAAmB;IAC5B,aAAa,EAAE,qBAAqB;IACpC,OAAO,EAAE,iBAAiB;IAC1B,MAAM,EAAE,cAAc;IACtB,QAAQ,EAAE,iBAAiB;IAC3B,QAAQ,EAAE,aAAa;IACvB,QAAQ,EAAE,mBAAmB;CAC9B,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nexport const POPULAR_NETWORKS: readonly Hex[] = [\n '0x1', // Ethereum Mainnet\n '0xe708', // Linea (59144)\n '0x2105', // Base (8453)\n '0xa4b1', // Arbitrum One (42161)\n '0xa86a', // Avalanche C-Chain (43114)\n '0x38', // BNB Smart Chain (56)\n '0xa', // Optimism (10)\n '0x89', // Polygon (137)\n '0x531', // Sei (Assuming 1329 used in EVM context)\n '0x144', // zkSync Era (324)\n '0x2a15c308d', // Palm (11297108109)\n '0x3e7', // HyperEVM (999)\n '0x8f', // Monad (143)\n '0x10e6', // MegaETH (4326)\n '0x13b2', // Arc (5042)\n '0x1237', // Robinhood (4663)\n];\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { NetworkEnablementController } from
|
|
2
|
-
export type { NetworkEnablementControllerState, NetworkEnablementControllerGetStateAction, NetworkEnablementControllerActions, NetworkEnablementControllerEvents, NetworkEnablementControllerStateChangeEvent, NetworkEnablementControllerMessenger, NativeAssetIdentifier, NativeAssetIdentifiersMap, NetworkConfig, } from
|
|
3
|
-
export type { NetworkEnablementControllerEnableNetworkAction, NetworkEnablementControllerEnableNetworkInNamespaceAction, NetworkEnablementControllerEnableAllPopularNetworksAction, NetworkEnablementControllerInitAction, NetworkEnablementControllerInitNativeAssetIdentifiersAction, NetworkEnablementControllerDisableNetworkAction, NetworkEnablementControllerIsNetworkEnabledAction, NetworkEnablementControllerListPopularEvmNetworksAction, NetworkEnablementControllerListPopularMultichainNetworksAction, NetworkEnablementControllerListPopularNetworksAction, } from
|
|
4
|
-
export { selectEnabledNetworkMap, selectIsNetworkEnabled, createSelectorForEnabledNetworksForNamespace, selectAllEnabledNetworks, selectEnabledNetworksCount, selectEnabledEvmNetworks, selectEnabledSolanaNetworks, } from
|
|
5
|
-
export { Slip44Service, getEvmSlip44, getSlip44BySymbol, } from
|
|
6
|
-
//# sourceMappingURL=index.d.
|
|
1
|
+
export { NetworkEnablementController } from './NetworkEnablementController.js';
|
|
2
|
+
export type { NetworkEnablementControllerState, NetworkEnablementControllerGetStateAction, NetworkEnablementControllerActions, NetworkEnablementControllerEvents, NetworkEnablementControllerStateChangeEvent, NetworkEnablementControllerMessenger, NativeAssetIdentifier, NativeAssetIdentifiersMap, NetworkConfig, } from './NetworkEnablementController.js';
|
|
3
|
+
export type { NetworkEnablementControllerEnableNetworkAction, NetworkEnablementControllerEnableNetworkInNamespaceAction, NetworkEnablementControllerEnableAllPopularNetworksAction, NetworkEnablementControllerInitAction, NetworkEnablementControllerInitNativeAssetIdentifiersAction, NetworkEnablementControllerDisableNetworkAction, NetworkEnablementControllerIsNetworkEnabledAction, NetworkEnablementControllerListPopularEvmNetworksAction, NetworkEnablementControllerListPopularMultichainNetworksAction, NetworkEnablementControllerListPopularNetworksAction, } from './NetworkEnablementController-method-action-types.js';
|
|
4
|
+
export { selectEnabledNetworkMap, selectIsNetworkEnabled, createSelectorForEnabledNetworksForNamespace, selectAllEnabledNetworks, selectEnabledNetworksCount, selectEnabledEvmNetworks, selectEnabledSolanaNetworks, } from './selectors.js';
|
|
5
|
+
export { Slip44Service, getEvmSlip44, getSlip44BySymbol, } from './services/index.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,YAAY,EACV,gCAAgC,EAChC,yCAAyC,EACzC,kCAAkC,EAClC,iCAAiC,EACjC,2CAA2C,EAC3C,oCAAoC,EACpC,qBAAqB,EACrB,yBAAyB,EACzB,aAAa,GACd,MAAM,kCAAkC,CAAC;AAE1C,YAAY,EACV,8CAA8C,EAC9C,yDAAyD,EACzD,yDAAyD,EACzD,qCAAqC,EACrC,2DAA2D,EAC3D,+CAA+C,EAC/C,iDAAiD,EACjD,uDAAuD,EACvD,8DAA8D,EAC9D,oDAAoD,GACrD,MAAM,sDAAsD,CAAC;AAE9D,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,4CAA4C,EAC5C,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,aAAa,EACb,YAAY,EACZ,iBAAiB,GAClB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { NetworkEnablementController } from './NetworkEnablementController.js';
|
|
2
|
+
export { selectEnabledNetworkMap, selectIsNetworkEnabled, createSelectorForEnabledNetworksForNamespace, selectAllEnabledNetworks, selectEnabledNetworksCount, selectEnabledEvmNetworks, selectEnabledSolanaNetworks, } from './selectors.js';
|
|
3
|
+
export { Slip44Service, getEvmSlip44, getSlip44BySymbol, } from './services/index.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AA2B/E,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,4CAA4C,EAC5C,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,aAAa,EACb,YAAY,EACZ,iBAAiB,GAClB,MAAM,qBAAqB,CAAC","sourcesContent":["export { NetworkEnablementController } from './NetworkEnablementController.js';\n\nexport type {\n NetworkEnablementControllerState,\n NetworkEnablementControllerGetStateAction,\n NetworkEnablementControllerActions,\n NetworkEnablementControllerEvents,\n NetworkEnablementControllerStateChangeEvent,\n NetworkEnablementControllerMessenger,\n NativeAssetIdentifier,\n NativeAssetIdentifiersMap,\n NetworkConfig,\n} from './NetworkEnablementController.js';\n\nexport type {\n NetworkEnablementControllerEnableNetworkAction,\n NetworkEnablementControllerEnableNetworkInNamespaceAction,\n NetworkEnablementControllerEnableAllPopularNetworksAction,\n NetworkEnablementControllerInitAction,\n NetworkEnablementControllerInitNativeAssetIdentifiersAction,\n NetworkEnablementControllerDisableNetworkAction,\n NetworkEnablementControllerIsNetworkEnabledAction,\n NetworkEnablementControllerListPopularEvmNetworksAction,\n NetworkEnablementControllerListPopularMultichainNetworksAction,\n NetworkEnablementControllerListPopularNetworksAction,\n} from './NetworkEnablementController-method-action-types.js';\n\nexport {\n selectEnabledNetworkMap,\n selectIsNetworkEnabled,\n createSelectorForEnabledNetworksForNamespace,\n selectAllEnabledNetworks,\n selectEnabledNetworksCount,\n selectEnabledEvmNetworks,\n selectEnabledSolanaNetworks,\n} from './selectors.js';\n\nexport {\n Slip44Service,\n getEvmSlip44,\n getSlip44BySymbol,\n} from './services/index.js';\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CaipChainId, CaipNamespace, Hex } from
|
|
2
|
-
import type { NetworkEnablementControllerState } from
|
|
1
|
+
import type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';
|
|
2
|
+
import type { NetworkEnablementControllerState } from './NetworkEnablementController.js';
|
|
3
3
|
/**
|
|
4
4
|
* Base selector to get the enabled network map from the controller state.
|
|
5
5
|
*
|
|
@@ -35,16 +35,14 @@ export declare const selectIsNetworkEnabled: (chainId: Hex | CaipChainId) => ((s
|
|
|
35
35
|
resetResultsCount: () => void;
|
|
36
36
|
};
|
|
37
37
|
lastResult: () => boolean;
|
|
38
|
-
dependencies: [
|
|
39
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
40
|
-
}];
|
|
38
|
+
dependencies: [typeof selectEnabledNetworkMap];
|
|
41
39
|
recomputations: () => number;
|
|
42
40
|
resetRecomputations: () => void;
|
|
43
41
|
dependencyRecomputations: () => number;
|
|
44
42
|
resetDependencyRecomputations: () => void;
|
|
45
43
|
} & {
|
|
46
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
47
44
|
memoize: typeof import("reselect").weakMapMemoize;
|
|
45
|
+
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
48
46
|
};
|
|
49
47
|
/**
|
|
50
48
|
* Selector builder to get all enabled networks for a specific namespace.
|
|
@@ -71,16 +69,14 @@ export declare const createSelectorForEnabledNetworksForNamespace: (namespace: C
|
|
|
71
69
|
resetResultsCount: () => void;
|
|
72
70
|
};
|
|
73
71
|
lastResult: () => string[];
|
|
74
|
-
dependencies: [
|
|
75
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
76
|
-
}];
|
|
72
|
+
dependencies: [typeof selectEnabledNetworkMap];
|
|
77
73
|
recomputations: () => number;
|
|
78
74
|
resetRecomputations: () => void;
|
|
79
75
|
dependencyRecomputations: () => number;
|
|
80
76
|
resetDependencyRecomputations: () => void;
|
|
81
77
|
} & {
|
|
82
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
83
78
|
memoize: typeof import("reselect").weakMapMemoize;
|
|
79
|
+
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
84
80
|
};
|
|
85
81
|
/**
|
|
86
82
|
* Selector to get all enabled networks across all namespaces.
|
|
@@ -106,16 +102,14 @@ export declare const selectAllEnabledNetworks: ((state: NetworkEnablementControl
|
|
|
106
102
|
resetResultsCount: () => void;
|
|
107
103
|
};
|
|
108
104
|
lastResult: () => Record<string, string[]>;
|
|
109
|
-
dependencies: [
|
|
110
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
111
|
-
}];
|
|
105
|
+
dependencies: [typeof selectEnabledNetworkMap];
|
|
112
106
|
recomputations: () => number;
|
|
113
107
|
resetRecomputations: () => void;
|
|
114
108
|
dependencyRecomputations: () => number;
|
|
115
109
|
resetDependencyRecomputations: () => void;
|
|
116
110
|
} & {
|
|
117
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
118
111
|
memoize: typeof import("reselect").weakMapMemoize;
|
|
112
|
+
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
119
113
|
};
|
|
120
114
|
/**
|
|
121
115
|
* Selector to get the total count of enabled networks across all namespaces.
|
|
@@ -150,24 +144,22 @@ export declare const selectEnabledNetworksCount: ((state: NetworkEnablementContr
|
|
|
150
144
|
resetResultsCount: () => void;
|
|
151
145
|
};
|
|
152
146
|
lastResult: () => Record<string, string[]>;
|
|
153
|
-
dependencies: [
|
|
154
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
155
|
-
}];
|
|
147
|
+
dependencies: [typeof selectEnabledNetworkMap];
|
|
156
148
|
recomputations: () => number;
|
|
157
149
|
resetRecomputations: () => void;
|
|
158
150
|
dependencyRecomputations: () => number;
|
|
159
151
|
resetDependencyRecomputations: () => void;
|
|
160
152
|
} & {
|
|
161
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
162
153
|
memoize: typeof import("reselect").weakMapMemoize;
|
|
154
|
+
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
163
155
|
}];
|
|
164
156
|
recomputations: () => number;
|
|
165
157
|
resetRecomputations: () => void;
|
|
166
158
|
dependencyRecomputations: () => number;
|
|
167
159
|
resetDependencyRecomputations: () => void;
|
|
168
160
|
} & {
|
|
169
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
170
161
|
memoize: typeof import("reselect").weakMapMemoize;
|
|
162
|
+
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
171
163
|
};
|
|
172
164
|
/**
|
|
173
165
|
* Selector to get all enabled EVM networks.
|
|
@@ -204,24 +196,22 @@ export declare const selectEnabledEvmNetworks: ((state: NetworkEnablementControl
|
|
|
204
196
|
resetResultsCount: () => void;
|
|
205
197
|
};
|
|
206
198
|
lastResult: () => string[];
|
|
207
|
-
dependencies: [
|
|
208
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
209
|
-
}];
|
|
199
|
+
dependencies: [typeof selectEnabledNetworkMap];
|
|
210
200
|
recomputations: () => number;
|
|
211
201
|
resetRecomputations: () => void;
|
|
212
202
|
dependencyRecomputations: () => number;
|
|
213
203
|
resetDependencyRecomputations: () => void;
|
|
214
204
|
} & {
|
|
215
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
216
205
|
memoize: typeof import("reselect").weakMapMemoize;
|
|
206
|
+
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
217
207
|
}];
|
|
218
208
|
recomputations: () => number;
|
|
219
209
|
resetRecomputations: () => void;
|
|
220
210
|
dependencyRecomputations: () => number;
|
|
221
211
|
resetDependencyRecomputations: () => void;
|
|
222
212
|
} & {
|
|
223
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
224
213
|
memoize: typeof import("reselect").weakMapMemoize;
|
|
214
|
+
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
225
215
|
};
|
|
226
216
|
/**
|
|
227
217
|
* Selector to get all enabled Solana networks.
|
|
@@ -258,23 +248,21 @@ export declare const selectEnabledSolanaNetworks: ((state: NetworkEnablementCont
|
|
|
258
248
|
resetResultsCount: () => void;
|
|
259
249
|
};
|
|
260
250
|
lastResult: () => string[];
|
|
261
|
-
dependencies: [
|
|
262
|
-
[x: string]: Record<`${string}:${string}` | `0x${string}`, boolean>;
|
|
263
|
-
}];
|
|
251
|
+
dependencies: [typeof selectEnabledNetworkMap];
|
|
264
252
|
recomputations: () => number;
|
|
265
253
|
resetRecomputations: () => void;
|
|
266
254
|
dependencyRecomputations: () => number;
|
|
267
255
|
resetDependencyRecomputations: () => void;
|
|
268
256
|
} & {
|
|
269
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
270
257
|
memoize: typeof import("reselect").weakMapMemoize;
|
|
258
|
+
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
271
259
|
}];
|
|
272
260
|
recomputations: () => number;
|
|
273
261
|
resetRecomputations: () => void;
|
|
274
262
|
dependencyRecomputations: () => number;
|
|
275
263
|
resetDependencyRecomputations: () => void;
|
|
276
264
|
} & {
|
|
277
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
278
265
|
memoize: typeof import("reselect").weakMapMemoize;
|
|
266
|
+
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
279
267
|
};
|
|
280
|
-
//# sourceMappingURL=selectors.d.
|
|
268
|
+
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAIvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,kCAAkC,CAAC;AAGzF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,UAC3B,gCAAgC;;CACb,CAAC;AAE7B;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,YAAa,GAAG,GAAG,WAAW;;;;;;;;;;;;;;;;;;;;;;;;CAS7D,CAAC;AAEL;;;;;;;;GAQG;AACH,eAAO,MAAM,4CAA4C,cAC5C,aAAa;;;;;;;;;;;;;;;;;;;;;;;;CAMtB,CAAC;AAEL;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;CAYpC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAKtC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGpC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGvC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { KnownCaipNamespace } from
|
|
2
|
-
import { createSelector } from
|
|
3
|
-
import { deriveKeys } from
|
|
1
|
+
import { KnownCaipNamespace } from '@metamask/utils';
|
|
2
|
+
import { createSelector } from 'reselect';
|
|
3
|
+
import { deriveKeys } from './utils.js';
|
|
4
4
|
/**
|
|
5
5
|
* Base selector to get the enabled network map from the controller state.
|
|
6
6
|
*
|
|
@@ -78,4 +78,4 @@ export const selectEnabledEvmNetworks = createSelector(createSelectorForEnabledN
|
|
|
78
78
|
* @returns A selector function that returns an array of enabled Solana chain IDs
|
|
79
79
|
*/
|
|
80
80
|
export const selectEnabledSolanaNetworks = createSelector(createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Solana), (enabledSolanaNetworks) => enabledSolanaNetworks);
|
|
81
|
-
//# sourceMappingURL=selectors.
|
|
81
|
+
//# sourceMappingURL=selectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.js","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,KAAuC,EACvC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC;AAE7B;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAA0B,EAAE,EAAE,CACnE,cAAc,CAAC,uBAAuB,EAAE,CAAC,iBAAiB,EAAE,EAAE;IAC5D,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAEtD,OAAO,CACL,SAAS,IAAI,iBAAiB;QAC9B,UAAU,IAAI,iBAAiB,CAAC,SAAS,CAAC;QAC1C,iBAAiB,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,CACzC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEL;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,4CAA4C,GAAG,CAC1D,SAAwB,EACxB,EAAE,CACF,cAAc,CAAC,uBAAuB,EAAE,CAAC,iBAAiB,EAAE,EAAE;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;SACtD,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC;SAChC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Slip44Service.d.ts","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;IACH,OAAa,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAiB1D;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAyB3D;IAED;;;OAGG;IACH,MAAM,CAAC,UAAU,IAAI,IAAI,CAIxB;CACF"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { fetchWithErrorHandling } from '@metamask/controller-utils';
|
|
2
|
+
// @ts-expect-error: No type definitions for '@metamask/slip44'
|
|
3
|
+
import slip44 from '@metamask/slip44';
|
|
4
|
+
const CHAINID_NETWORK_URL = 'https://chainid.network/chains.json';
|
|
5
|
+
/**
|
|
6
|
+
* Service for looking up SLIP-44 coin type identifiers.
|
|
7
|
+
*
|
|
8
|
+
* SLIP-44 defines registered coin types used in BIP-44 derivation paths.
|
|
9
|
+
*
|
|
10
|
+
* This service provides two lookup methods:
|
|
11
|
+
* 1. `getEvmSlip44` - For EVM networks, uses chainid.network data (recommended for eip155)
|
|
12
|
+
* 2. `getSlip44BySymbol` - Fallback method using @metamask/slip44 package
|
|
13
|
+
*
|
|
14
|
+
* @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
|
15
|
+
* @see https://chainid.network/chains.json
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Manual overrides for EVM chain IDs where chainid.network returns
|
|
19
|
+
* an incorrect SLIP-44 value due to chain ID collisions.
|
|
20
|
+
*/
|
|
21
|
+
const EVM_SLIP44_OVERRIDES = new Map([
|
|
22
|
+
[999, 2457], // HyperEVM — chainid.network returns 1 (Wanchain collision)
|
|
23
|
+
]);
|
|
24
|
+
export class Slip44Service {
|
|
25
|
+
/**
|
|
26
|
+
* Cache for chainId to slip44 lookups from chainid.network.
|
|
27
|
+
*/
|
|
28
|
+
static #chainIdCache = null;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a fetch is currently in progress.
|
|
31
|
+
*/
|
|
32
|
+
static #fetchPromise = null;
|
|
33
|
+
/**
|
|
34
|
+
* Cache for symbol to slip44 index lookups.
|
|
35
|
+
* This avoids iterating through all entries on repeated lookups.
|
|
36
|
+
*/
|
|
37
|
+
static #symbolCache = new Map();
|
|
38
|
+
/**
|
|
39
|
+
* Fetches and caches chain data from chainid.network.
|
|
40
|
+
* This is called automatically by getEvmSlip44.
|
|
41
|
+
*/
|
|
42
|
+
static async #fetchChainData() {
|
|
43
|
+
if (this.#chainIdCache !== null) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// Avoid duplicate fetches
|
|
47
|
+
if (this.#fetchPromise) {
|
|
48
|
+
await this.#fetchPromise;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.#fetchPromise = (async () => {
|
|
52
|
+
try {
|
|
53
|
+
const chains = await fetchWithErrorHandling({
|
|
54
|
+
url: CHAINID_NETWORK_URL,
|
|
55
|
+
timeout: 10000,
|
|
56
|
+
});
|
|
57
|
+
if (chains && Array.isArray(chains)) {
|
|
58
|
+
this.#chainIdCache = new Map(chains
|
|
59
|
+
.filter((chain) => chain.slip44 !== undefined)
|
|
60
|
+
.map((chain) => [chain.chainId, chain.slip44]));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// Invalid response, initialize empty cache
|
|
64
|
+
this.#chainIdCache = new Map();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// Network failed, initialize empty cache so we fall back to symbol lookup
|
|
69
|
+
this.#chainIdCache = new Map();
|
|
70
|
+
}
|
|
71
|
+
})();
|
|
72
|
+
await this.#fetchPromise;
|
|
73
|
+
this.#fetchPromise = null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Gets the SLIP-44 coin type identifier for an EVM network by chain ID.
|
|
77
|
+
*
|
|
78
|
+
* **IMPORTANT: This method is for EVM networks only (eip155 namespace).**
|
|
79
|
+
* For non-EVM networks (Bitcoin, Solana, Tron, etc.), use `getSlip44BySymbol`.
|
|
80
|
+
*
|
|
81
|
+
* This method checks chainid.network data (which maps chainId directly
|
|
82
|
+
* to slip44). If not found, defaults to 60 (Ethereum).
|
|
83
|
+
*
|
|
84
|
+
* @param chainId - The EVM chain ID as a number (e.g., 1 for Ethereum, 56 for BNB Chain)
|
|
85
|
+
* @returns The SLIP-44 coin type number (defaults to 60 if not found)
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* // For EVM networks only
|
|
89
|
+
* const ethCoinType = await Slip44Service.getEvmSlip44(1);
|
|
90
|
+
* // Returns 60
|
|
91
|
+
*
|
|
92
|
+
* const bnbCoinType = await Slip44Service.getEvmSlip44(56);
|
|
93
|
+
* // Returns 714
|
|
94
|
+
*
|
|
95
|
+
* const unknownEvmChain = await Slip44Service.getEvmSlip44(99999);
|
|
96
|
+
* // Returns 60 (default for EVM)
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
static async getEvmSlip44(chainId) {
|
|
100
|
+
const override = EVM_SLIP44_OVERRIDES.get(chainId);
|
|
101
|
+
if (override !== undefined) {
|
|
102
|
+
return override;
|
|
103
|
+
}
|
|
104
|
+
// Ensure chain data is loaded
|
|
105
|
+
await this.#fetchChainData();
|
|
106
|
+
// Check chainId cache first
|
|
107
|
+
const cached = this.#chainIdCache?.get(chainId);
|
|
108
|
+
if (cached !== undefined) {
|
|
109
|
+
return cached;
|
|
110
|
+
}
|
|
111
|
+
// Default to 60 (Ethereum) for EVM networks without specific mapping
|
|
112
|
+
return 60;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Gets the SLIP-44 coin type identifier for a non-EVM network by symbol.
|
|
116
|
+
*
|
|
117
|
+
* **IMPORTANT: This method is for non-EVM networks only (Bitcoin, Solana, Tron, etc.).**
|
|
118
|
+
* For EVM networks (eip155 namespace), use `getEvmSlip44` instead.
|
|
119
|
+
*
|
|
120
|
+
* Note: Symbol lookup may return incorrect results for duplicate symbols
|
|
121
|
+
* (e.g., CPC is both CPChain and Capricoin).
|
|
122
|
+
*
|
|
123
|
+
* @param symbol - The network symbol (e.g., 'ETH', 'BTC', 'SOL')
|
|
124
|
+
* @returns The SLIP-44 coin type number, or undefined if not found
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const ethCoinType = Slip44Service.getSlip44BySymbol('ETH');
|
|
128
|
+
* // Returns 60
|
|
129
|
+
*
|
|
130
|
+
* const btcCoinType = Slip44Service.getSlip44BySymbol('BTC');
|
|
131
|
+
* // Returns 0
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
static getSlip44BySymbol(symbol) {
|
|
135
|
+
// Check cache first
|
|
136
|
+
if (this.#symbolCache.has(symbol)) {
|
|
137
|
+
return this.#symbolCache.get(symbol);
|
|
138
|
+
}
|
|
139
|
+
const slip44Data = slip44;
|
|
140
|
+
const upperSymbol = symbol.toUpperCase();
|
|
141
|
+
// Iterate through all entries to find matching symbol
|
|
142
|
+
// Note: Object.keys returns numeric keys in ascending order,
|
|
143
|
+
// so for duplicate symbols we get the lowest coin type first
|
|
144
|
+
// (which is the convention for resolving duplicates)
|
|
145
|
+
for (const key of Object.keys(slip44Data)) {
|
|
146
|
+
const entry = slip44Data[key];
|
|
147
|
+
if (entry.symbol.toUpperCase() === upperSymbol) {
|
|
148
|
+
const coinType = parseInt(key, 10);
|
|
149
|
+
this.#symbolCache.set(symbol, coinType);
|
|
150
|
+
return coinType;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Cache the miss as well to avoid repeated lookups
|
|
154
|
+
this.#symbolCache.set(symbol, undefined);
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Clears all internal caches.
|
|
159
|
+
* Useful for testing or if the underlying data might change.
|
|
160
|
+
*/
|
|
161
|
+
static clearCache() {
|
|
162
|
+
this.#symbolCache.clear();
|
|
163
|
+
this.#chainIdCache = null;
|
|
164
|
+
this.#fetchPromise = null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=Slip44Service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Slip44Service.js","sourceRoot":"","sources":["../../src/services/Slip44Service.ts"],"names":[],"mappings":"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","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,5 +1,5 @@
|
|
|
1
|
-
import { Slip44Service } from
|
|
1
|
+
import { Slip44Service } from './Slip44Service.js';
|
|
2
2
|
export { Slip44Service };
|
|
3
3
|
export declare const getEvmSlip44: typeof Slip44Service.getEvmSlip44;
|
|
4
4
|
export declare const getSlip44BySymbol: typeof Slip44Service.getSlip44BySymbol;
|
|
5
|
-
//# sourceMappingURL=index.d.
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,CAAC;AAIzB,eAAO,MAAM,YAAY,mCAAiD,CAAC;AAE3E,eAAO,MAAM,iBAAiB,wCACuB,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Slip44Service } from
|
|
1
|
+
import { Slip44Service } from './Slip44Service.js';
|
|
2
2
|
export { Slip44Service };
|
|
3
3
|
// Re-export static methods as standalone functions for convenience
|
|
4
4
|
// getEvmSlip44: For EVM networks (eip155) - uses chainId lookup, defaults to 60
|
|
5
5
|
export const getEvmSlip44 = Slip44Service.getEvmSlip44.bind(Slip44Service);
|
|
6
6
|
// getSlip44BySymbol: For non-EVM networks (Bitcoin, Solana, Tron) - uses symbol lookup
|
|
7
7
|
export const getSlip44BySymbol = Slip44Service.getSlip44BySymbol.bind(Slip44Service);
|
|
8
|
-
//# sourceMappingURL=index.
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,mEAAmE;AACnE,gFAAgF;AAChF,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AAC3E,uFAAuF;AACvF,MAAM,CAAC,MAAM,iBAAiB,GAC5B,aAAa,CAAC,iBAAiB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC","sourcesContent":["import { Slip44Service } from './Slip44Service.js';\n\nexport { Slip44Service };\n\n// Re-export static methods as standalone functions for convenience\n// getEvmSlip44: For EVM networks (eip155) - uses chainId lookup, defaults to 60\nexport const getEvmSlip44 = Slip44Service.getEvmSlip44.bind(Slip44Service);\n// getSlip44BySymbol: For non-EVM networks (Bitcoin, Solana, Tron) - uses symbol lookup\nexport const getSlip44BySymbol =\n Slip44Service.getSlip44BySymbol.bind(Slip44Service);\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CaipChainId, CaipNamespace, Hex } from
|
|
2
|
-
import type { NetworkEnablementControllerState } from
|
|
1
|
+
import type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';
|
|
2
|
+
import type { NetworkEnablementControllerState } from './NetworkEnablementController.js';
|
|
3
3
|
/**
|
|
4
4
|
* Represents the parsed keys derived from a chain ID.
|
|
5
5
|
*/
|
|
@@ -33,4 +33,4 @@ export declare function deriveKeys(chainId: Hex | CaipChainId): DerivedKeys;
|
|
|
33
33
|
* @returns True if the network is the only enabled network in the namespace, false otherwise
|
|
34
34
|
*/
|
|
35
35
|
export declare function isOnlyNetworkEnabledInNamespace(state: NetworkEnablementControllerState, derivedKeys: DerivedKeys): boolean;
|
|
36
|
-
//# sourceMappingURL=utils.d.
|
|
36
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAQvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,kCAAkC,CAAC;AAEzF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,GAAG,GAAG,WAAW,CAAC;IAC9B,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,WAAW,CAalE;AAED;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,gCAAgC,EACvC,WAAW,EAAE,WAAW,GACvB,OAAO,CAuBT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { toHex } from
|
|
2
|
-
import { toEvmCaipChainId } from
|
|
3
|
-
import { isCaipChainId, isHexString, KnownCaipNamespace, parseCaipChainId } from
|
|
1
|
+
import { toHex } from '@metamask/controller-utils';
|
|
2
|
+
import { toEvmCaipChainId } from '@metamask/multichain-network-controller';
|
|
3
|
+
import { isCaipChainId, isHexString, KnownCaipNamespace, parseCaipChainId, } from '@metamask/utils';
|
|
4
4
|
/**
|
|
5
5
|
* Derives the namespace, storage key, and CAIP chain ID from a given chain ID.
|
|
6
6
|
*
|
|
@@ -54,4 +54,4 @@ export function isOnlyNetworkEnabledInNamespace(state, derivedKeys) {
|
|
|
54
54
|
// Return false if there are zero or multiple enabled networks
|
|
55
55
|
return false;
|
|
56
56
|
}
|
|
57
|
-
//# sourceMappingURL=utils.
|
|
57
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAE3E,OAAO,EACL,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAczB;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,OAA0B;IACnD,MAAM,WAAW,GAAG,aAAa,CAAC,OAAO,CAAC;QACxC,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE9B,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAC/D,IAAI,UAAU,CAAC;IACf,IAAI,SAAS,KAAM,kBAAkB,CAAC,MAAiB,EAAE,CAAC;QACxD,UAAU,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC;SAAM,CAAC;QACN,UAAU,GAAG,WAAW,CAAC;IAC3B,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;AAC3D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,+BAA+B,CAC7C,KAAuC,EACvC,WAAwB;IAExB,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC;IAE9C,0CAA0C;IAC1C,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAEpD,6CAA6C;IAC7C,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CACrD,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,CAC1B,CAAC;IAEF,yEAAyE;IACzE,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,MAAM,CAAC,cAAc,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;QAC5C,OAAO,cAAc,KAAK,UAAU,CAAC;IACvC,CAAC;IAED,8DAA8D;IAC9D,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport { toEvmCaipChainId } from '@metamask/multichain-network-controller';\nimport type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';\nimport {\n isCaipChainId,\n isHexString,\n KnownCaipNamespace,\n parseCaipChainId,\n} from '@metamask/utils';\n\nimport type { NetworkEnablementControllerState } from './NetworkEnablementController.js';\n\n/**\n * Represents the parsed keys derived from a chain ID.\n */\nexport type DerivedKeys = {\n namespace: CaipNamespace;\n storageKey: Hex | CaipChainId;\n caipChainId: CaipChainId;\n reference: string;\n};\n\n/**\n * Derives the namespace, storage key, and CAIP chain ID from a given chain ID.\n *\n * This utility function handles the conversion between different chain ID formats.\n * For EVM networks, it converts Hex chain IDs to CAIP-2 format and determines\n * the appropriate storage key. For non-EVM networks, it parses the CAIP-2 chain ID\n * and uses the full chain ID as the storage key.\n *\n * @param chainId - The chain ID to derive keys from (Hex or CAIP-2 format)\n * @returns An object containing namespace, storageKey, and caipId\n * @throws Error if the chain ID cannot be parsed\n */\nexport function deriveKeys(chainId: Hex | CaipChainId): DerivedKeys {\n const caipChainId = isCaipChainId(chainId)\n ? chainId\n : toEvmCaipChainId(chainId);\n\n const { namespace, reference } = parseCaipChainId(caipChainId);\n let storageKey;\n if (namespace === (KnownCaipNamespace.Eip155 as string)) {\n storageKey = isHexString(chainId) ? chainId : toHex(reference);\n } else {\n storageKey = caipChainId;\n }\n return { namespace, storageKey, caipChainId, reference };\n}\n\n/**\n * Checks if the specified network is the only enabled network in its namespace.\n *\n * This function is used to prevent unnecessary state updates when trying to enable\n * This method is used to prevent the last network in a namespace from being removed.\n *\n * @param state - The current controller state\n * @param derivedKeys - The parsed keys object containing namespace and storageKey\n * @returns True if the network is the only enabled network in the namespace, false otherwise\n */\nexport function isOnlyNetworkEnabledInNamespace(\n state: NetworkEnablementControllerState,\n derivedKeys: DerivedKeys,\n): boolean {\n const { namespace, storageKey } = derivedKeys;\n\n // Early return if namespace doesn't exist\n if (!state.enabledNetworkMap[namespace]) {\n return false;\n }\n\n const networks = state.enabledNetworkMap[namespace];\n\n // Get all enabled networks in this namespace\n const enabledNetworks = Object.entries(networks).filter(\n ([_, enabled]) => enabled,\n );\n\n // Check if there's exactly one enabled network and it matches our target\n if (enabledNetworks.length === 1) {\n const [onlyEnabledKey] = enabledNetworks[0];\n return onlyEnabledKey === storageKey;\n }\n\n // Return false if there are zero or multiple enabled networks\n return false;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/network-enablement-controller",
|
|
3
|
-
"version": "6.0.5-preview-
|
|
3
|
+
"version": "6.0.5-preview-3866c0ff1",
|
|
4
4
|
"description": "Provides an interface to the currently enabled network using a MetaMask-compatible provider object",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -18,19 +18,12 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/"
|
|
20
20
|
],
|
|
21
|
+
"type": "module",
|
|
21
22
|
"sideEffects": false,
|
|
22
|
-
"main": "./dist/index.cjs",
|
|
23
|
-
"types": "./dist/index.d.cts",
|
|
24
23
|
"exports": {
|
|
25
24
|
".": {
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
"default": "./dist/index.mjs"
|
|
29
|
-
},
|
|
30
|
-
"require": {
|
|
31
|
-
"types": "./dist/index.d.cts",
|
|
32
|
-
"default": "./dist/index.cjs"
|
|
33
|
-
}
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
34
27
|
},
|
|
35
28
|
"./package.json": "./package.json"
|
|
36
29
|
},
|
|
@@ -39,9 +32,11 @@
|
|
|
39
32
|
"registry": "https://registry.npmjs.org/"
|
|
40
33
|
},
|
|
41
34
|
"scripts": {
|
|
42
|
-
"build": "
|
|
43
|
-
"build:all": "
|
|
35
|
+
"build": "tsc --project tsconfig.build.json",
|
|
36
|
+
"build:all": "tsc --build tsconfig.build.json --verbose",
|
|
37
|
+
"build:clean": "yarn build:only-clean && yarn build",
|
|
44
38
|
"build:docs": "typedoc",
|
|
39
|
+
"build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
|
|
45
40
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/network-enablement-controller",
|
|
46
41
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/network-enablement-controller",
|
|
47
42
|
"lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
|
|
@@ -69,17 +64,18 @@
|
|
|
69
64
|
},
|
|
70
65
|
"devDependencies": {
|
|
71
66
|
"@metamask/auto-changelog": "^6.1.0",
|
|
72
|
-
"@ts-bridge/cli": "^0.6.4",
|
|
73
67
|
"@types/jest": "^30.0.0",
|
|
68
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
74
69
|
"deepmerge": "^4.2.2",
|
|
75
70
|
"jest": "^30.4.2",
|
|
71
|
+
"rimraf": "^5.0.5",
|
|
76
72
|
"ts-jest": "^29.4.11",
|
|
77
73
|
"tsx": "^4.20.5",
|
|
78
74
|
"typedoc": "^0.25.13",
|
|
79
75
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
80
|
-
"typescript": "
|
|
76
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2"
|
|
81
77
|
},
|
|
82
78
|
"engines": {
|
|
83
|
-
"node": "^
|
|
79
|
+
"node": "^22.14.0 || ^24"
|
|
84
80
|
}
|
|
85
81
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkEnablementController-method-action-types.cjs","sourceRoot":"","sources":["../src/NetworkEnablementController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { NetworkEnablementController } from './NetworkEnablementController.js';\n\n/**\n * Enables or disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally. This dual parameter support allows for backward\n * compatibility with existing EVM chain ID formats while supporting newer\n * multi-chain standards.\n *\n * When enabling a non-popular network, this method will disable all other networks\n * to ensure only one network is active at a time (exclusive mode).\n *\n * @param chainId - The chain ID of the network to enable or disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\nexport type NetworkEnablementControllerEnableNetworkAction = {\n type: `NetworkEnablementController:enableNetwork`;\n handler: NetworkEnablementController['enableNetwork'];\n};\n\n/**\n * Enables a network for the user within a specific namespace.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and enables it within the specified namespace.\n * The method validates that the chainId belongs to the specified namespace for safety.\n *\n * Before enabling the target network, this method disables all other networks\n * in the same namespace to ensure exclusive behavior within the namespace.\n *\n * @param chainId - The chain ID of the network to enable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @param namespace - The CAIP namespace where the network should be enabled\n * @throws Error if the chainId's derived namespace doesn't match the provided namespace\n */\nexport type NetworkEnablementControllerEnableNetworkInNamespaceAction = {\n type: `NetworkEnablementController:enableNetworkInNamespace`;\n handler: NetworkEnablementController['enableNetworkInNamespace'];\n};\n\n/**\n * Enables all popular networks and Solana mainnet.\n *\n * This method first disables all networks across all namespaces, then enables\n * all networks defined in POPULAR_NETWORKS (EVM networks), Solana mainnet, and\n * Bitcoin mainnet. This provides exclusive behavior - only popular networks will\n * be enabled after calling this method.\n *\n * Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.\n */\nexport type NetworkEnablementControllerEnableAllPopularNetworksAction = {\n type: `NetworkEnablementController:enableAllPopularNetworks`;\n handler: NetworkEnablementController['enableAllPopularNetworks'];\n};\n\n/**\n * Initializes the network enablement state from network controller configurations.\n *\n * This method reads the current network configurations from both NetworkController\n * and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.\n * It ensures proper namespace buckets exist for all configured networks and only\n * adds missing networks with a default value of false, preserving existing user settings.\n *\n * This method should be called after the NetworkController and MultichainNetworkController\n * have been initialized and their configurations are available.\n */\nexport type NetworkEnablementControllerInitAction = {\n type: `NetworkEnablementController:init`;\n handler: NetworkEnablementController['init'];\n};\n\n/**\n * Initializes the native asset identifiers from network configurations.\n * This method should be called from the client during controller initialization\n * to populate the nativeAssetIdentifiers state based on actual network configurations.\n *\n * @param networks - Array of network configurations with chainId and nativeCurrency\n * @example\n * ```typescript\n * const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)\n * .map(config => ({\n * chainId: toEvmCaipChainId(config.chainId),\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)\n * .map(config => ({\n * chainId: config.chainId,\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * await controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);\n * ```\n */\nexport type NetworkEnablementControllerInitNativeAssetIdentifiersAction = {\n type: `NetworkEnablementController:initNativeAssetIdentifiers`;\n handler: NetworkEnablementController['initNativeAssetIdentifiers'];\n};\n\n/**\n * Disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally.\n *\n * Note: This method will prevent disabling the last remaining enabled network\n * to ensure at least one network is always available.\n *\n * @param chainId - The chain ID of the network to disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\nexport type NetworkEnablementControllerDisableNetworkAction = {\n type: `NetworkEnablementController:disableNetwork`;\n handler: NetworkEnablementController['disableNetwork'];\n};\n\n/**\n * Restores the enabled network map to a previously snapshotted state.\n *\n * Not a general merge API: only updates keys already present in the current\n * map. Missing snapshot values default to `false`. Intended for callers with\n * direct controller access (e.g. extension) to undo `#onAddNetwork` filter\n * switches when adding a network without changing the active selection.\n *\n * @param enabledNetworkMap - Previously snapshotted enabledNetworkMap.\n */\nexport type NetworkEnablementControllerRestoreEnabledNetworkMapAction = {\n type: `NetworkEnablementController:restoreEnabledNetworkMap`;\n handler: NetworkEnablementController['restoreEnabledNetworkMap'];\n};\n\n/**\n * Checks if a network is enabled.\n *\n * @param chainId - The chain ID of the network to check. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @returns True if the network is enabled, false otherwise\n */\nexport type NetworkEnablementControllerIsNetworkEnabledAction = {\n type: `NetworkEnablementController:isNetworkEnabled`;\n handler: NetworkEnablementController['isNetworkEnabled'];\n};\n\n/**\n * Returns popular EVM network chain IDs in hex form, restricted to networks\n * that exist in NetworkController (networkConfigurationsByChainId). Source is\n * the bundled `POPULAR_NETWORKS` unioned with registry-featured EVM chains.\n *\n * @returns Hex chain IDs for popular EVM networks that are configured.\n */\nexport type NetworkEnablementControllerListPopularEvmNetworksAction = {\n type: `NetworkEnablementController:listPopularEvmNetworks`;\n handler: NetworkEnablementController['listPopularEvmNetworks'];\n};\n\n/**\n * Returns popular multichain (Bitcoin, Solana, Tron, Stellar) mainnet chain IDs in\n * CAIP-2 form, restricted to networks that exist in MultichainNetworkController\n * (multichainNetworkConfigurationsByChainId).\n *\n * @returns CAIP-2 chain IDs for Bitcoin, Solana, Tron, and Stellar mainnets that are configured.\n */\nexport type NetworkEnablementControllerListPopularMultichainNetworksAction = {\n type: `NetworkEnablementController:listPopularMultichainNetworks`;\n handler: NetworkEnablementController['listPopularMultichainNetworks'];\n};\n\n/**\n * Returns the list of popular network chain IDs in CAIP-2 form, restricted to\n * networks that exist in NetworkController (networkConfigurationsByChainId) and\n * MultichainNetworkController (multichainNetworkConfigurationsByChainId). EVM\n * popular networks come from POPULAR_NETWORKS; multichain popular are Bitcoin,\n * Solana, Tron, and Stellar mainnets.\n *\n * @returns CAIP-2 chain IDs for popular EVM networks and multichain mainnets that are configured.\n */\nexport type NetworkEnablementControllerListPopularNetworksAction = {\n type: `NetworkEnablementController:listPopularNetworks`;\n handler: NetworkEnablementController['listPopularNetworks'];\n};\n\n/**\n * Union of all NetworkEnablementController action types.\n */\nexport type NetworkEnablementControllerMethodActions =\n | NetworkEnablementControllerEnableNetworkAction\n | NetworkEnablementControllerEnableNetworkInNamespaceAction\n | NetworkEnablementControllerEnableAllPopularNetworksAction\n | NetworkEnablementControllerInitAction\n | NetworkEnablementControllerInitNativeAssetIdentifiersAction\n | NetworkEnablementControllerDisableNetworkAction\n | NetworkEnablementControllerRestoreEnabledNetworkMapAction\n | NetworkEnablementControllerIsNetworkEnabledAction\n | NetworkEnablementControllerListPopularEvmNetworksAction\n | NetworkEnablementControllerListPopularMultichainNetworksAction\n | NetworkEnablementControllerListPopularNetworksAction;\n"]}
|