@metamask-previews/network-enablement-controller 4.0.0-preview-f5ec6061 → 4.0.0-preview-e6f8648b

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/NetworkEnablementController.cjs +155 -57
  3. package/dist/NetworkEnablementController.cjs.map +1 -1
  4. package/dist/NetworkEnablementController.d.cts +52 -1
  5. package/dist/NetworkEnablementController.d.cts.map +1 -1
  6. package/dist/NetworkEnablementController.d.mts +52 -1
  7. package/dist/NetworkEnablementController.d.mts.map +1 -1
  8. package/dist/NetworkEnablementController.mjs +153 -56
  9. package/dist/NetworkEnablementController.mjs.map +1 -1
  10. package/dist/index.cjs +4 -1
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +4 -2
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.mts +4 -2
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +2 -1
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/services/Slip44Service.cjs +82 -0
  19. package/dist/services/Slip44Service.cjs.map +1 -0
  20. package/dist/services/Slip44Service.d.cts +46 -0
  21. package/dist/services/Slip44Service.d.cts.map +1 -0
  22. package/dist/services/Slip44Service.d.mts +46 -0
  23. package/dist/services/Slip44Service.d.mts.map +1 -0
  24. package/dist/services/Slip44Service.mjs +75 -0
  25. package/dist/services/Slip44Service.mjs.map +1 -0
  26. package/dist/services/index.cjs +6 -0
  27. package/dist/services/index.cjs.map +1 -0
  28. package/dist/services/index.d.cts +3 -0
  29. package/dist/services/index.d.cts.map +1 -0
  30. package/dist/services/index.d.mts +3 -0
  31. package/dist/services/index.d.mts.map +1 -0
  32. package/dist/services/index.mjs +2 -0
  33. package/dist/services/index.mjs.map +1 -0
  34. package/package.json +2 -1
@@ -21,8 +21,26 @@ export type NetworksInfo = {
21
21
  * For other networks, the keys are CAIP chain IDs.
22
22
  */
23
23
  type EnabledMap = Record<CaipNamespace, Record<CaipChainId | Hex, boolean>>;
24
+ /**
25
+ * A native asset identifier in CAIP-19-like format.
26
+ * Format: `{caip2ChainId}/slip44:{coinType}`
27
+ *
28
+ * @example
29
+ * - `eip155:1/slip44:60` for Ethereum mainnet (ETH)
30
+ * - `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501` for Solana mainnet (SOL)
31
+ * - `bip122:000000000019d6689c085ae165831e93/slip44:0` for Bitcoin mainnet (BTC)
32
+ */
33
+ export type NativeAssetIdentifier = `${CaipChainId}/slip44:${number}`;
34
+ /**
35
+ * A map of CAIP-2 chain IDs to their native asset identifiers.
36
+ * Uses CAIP-19-like format to identify the native asset for each chain.
37
+ *
38
+ * @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
39
+ */
40
+ export type NativeAssetIdentifiersMap = Record<CaipChainId, NativeAssetIdentifier>;
24
41
  export type NetworkEnablementControllerState = {
25
42
  enabledNetworkMap: EnabledMap;
43
+ nativeAssetIdentifiers: NativeAssetIdentifiersMap;
26
44
  };
27
45
  export type NetworkEnablementControllerGetStateAction = ControllerGetStateAction<typeof controllerName, NetworkEnablementControllerState>;
28
46
  export type NetworkEnablementControllerSetEnabledNetworksAction = {
@@ -45,6 +63,39 @@ export type NetworkEnablementControllerEvents = NetworkEnablementControllerState
45
63
  */
46
64
  export type AllowedEvents = NetworkControllerNetworkAddedEvent | NetworkControllerNetworkRemovedEvent | NetworkControllerStateChangeEvent | TransactionControllerTransactionSubmittedEvent;
47
65
  export type NetworkEnablementControllerMessenger = Messenger<typeof controllerName, NetworkEnablementControllerActions | AllowedActions, NetworkEnablementControllerEvents | AllowedEvents>;
66
+ /**
67
+ * Network configuration with chain ID and native currency symbol.
68
+ * Used to initialize native asset identifiers.
69
+ */
70
+ export type NetworkConfig = {
71
+ chainId: CaipChainId;
72
+ nativeCurrency: string;
73
+ };
74
+ /**
75
+ * Initializes the native asset identifiers map from network configurations.
76
+ * This function should be called from the client during controller initialization
77
+ * to populate the nativeAssetIdentifiers state based on actual network configurations.
78
+ *
79
+ * @param networks - Array of network configurations with chainId and nativeCurrency
80
+ * @returns A map of CAIP-2 chain IDs to their native asset identifiers
81
+ * @example
82
+ * ```typescript
83
+ * const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)
84
+ * .map(config => ({
85
+ * chainId: toEvmCaipChainId(config.chainId),
86
+ * nativeCurrency: config.nativeCurrency,
87
+ * }));
88
+ *
89
+ * const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)
90
+ * .map(config => ({
91
+ * chainId: config.chainId,
92
+ * nativeCurrency: config.nativeCurrency,
93
+ * }));
94
+ *
95
+ * const nativeAssetIdentifiers = initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);
96
+ * ```
97
+ */
98
+ export declare function initNativeAssetIdentifiers(networks: NetworkConfig[]): NativeAssetIdentifiersMap;
48
99
  /**
49
100
  * Controller responsible for managing network enablement state across different blockchain networks.
50
101
  *
@@ -116,7 +167,7 @@ export declare class NetworkEnablementController extends BaseController<typeof c
116
167
  * Initializes the network enablement state from network controller configurations.
117
168
  *
118
169
  * This method reads the current network configurations from both NetworkController
119
- * and MultichainNetworkController and syncs the enabled network map accordingly.
170
+ * and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.
120
171
  * It ensures proper namespace buckets exist for all configured networks and only
121
172
  * adds missing networks with a default value of false, preserving existing user settings.
122
173
  *
@@ -1 +1 @@
1
- {"version":3,"file":"NetworkEnablementController.d.cts","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,yCAAyC,EAAE,gDAAgD;AACzG,OAAO,KAAK,EACV,+BAA+B,EAC/B,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,oCAAoC,GACpC,iCAAiC,GACjC,8CAA8C,CAAC;AAEnD,MAAM,MAAM,oCAAoC,GAAG,SAAS,CAC1D,OAAO,cAAc,EACrB,kCAAkC,GAAG,cAAc,EACnD,iCAAiC,GAAG,aAAa,CAClD,CAAC;AAgDF;;;;;;;;GAQG;AACH,qBAAa,2BAA4B,SAAQ,cAAc,CAC7D,OAAO,cAAc,EACrB,gCAAgC,EAChC,oCAAoC,CACrC;;IACC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,oCAAoC,CAAC;QAChD,KAAK,CAAC,EAAE,OAAO,CAAC,gCAAgC,CAAC,CAAC;KACnD;IAoBD;;;;;;;;;;;;;;;OAeG;IACH,aAAa,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,IAAI;IAsB/C;;;;;;;;;;;;;;;OAeG;IACH,wBAAwB,CACtB,OAAO,EAAE,GAAG,GAAG,WAAW,EAC1B,SAAS,EAAE,aAAa,GACvB,IAAI;IA0BP;;;;;;;;;OASG;IACH,wBAAwB,IAAI,IAAI;IA0EhC;;;;;;;;;;OAUG;IACH,IAAI,IAAI,IAAI;IAwCZ;;;;;;;;;;;;;OAaG;IACH,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,IAAI;IAShD;;;;;;;OAOG;IACH,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,OAAO;CAiItD"}
1
+ {"version":3,"file":"NetworkEnablementController.d.cts","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,yCAAyC,EAAE,gDAAgD;AACzG,OAAO,KAAK,EACV,+BAA+B,EAC/B,kCAAkC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AG,GAAG,WAAW,GAAG,IAAI;IAShD;;;;;;;OAOG;IACH,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,OAAO;CAkLtD"}
@@ -21,8 +21,26 @@ export type NetworksInfo = {
21
21
  * For other networks, the keys are CAIP chain IDs.
22
22
  */
23
23
  type EnabledMap = Record<CaipNamespace, Record<CaipChainId | Hex, boolean>>;
24
+ /**
25
+ * A native asset identifier in CAIP-19-like format.
26
+ * Format: `{caip2ChainId}/slip44:{coinType}`
27
+ *
28
+ * @example
29
+ * - `eip155:1/slip44:60` for Ethereum mainnet (ETH)
30
+ * - `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501` for Solana mainnet (SOL)
31
+ * - `bip122:000000000019d6689c085ae165831e93/slip44:0` for Bitcoin mainnet (BTC)
32
+ */
33
+ export type NativeAssetIdentifier = `${CaipChainId}/slip44:${number}`;
34
+ /**
35
+ * A map of CAIP-2 chain IDs to their native asset identifiers.
36
+ * Uses CAIP-19-like format to identify the native asset for each chain.
37
+ *
38
+ * @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
39
+ */
40
+ export type NativeAssetIdentifiersMap = Record<CaipChainId, NativeAssetIdentifier>;
24
41
  export type NetworkEnablementControllerState = {
25
42
  enabledNetworkMap: EnabledMap;
43
+ nativeAssetIdentifiers: NativeAssetIdentifiersMap;
26
44
  };
27
45
  export type NetworkEnablementControllerGetStateAction = ControllerGetStateAction<typeof controllerName, NetworkEnablementControllerState>;
28
46
  export type NetworkEnablementControllerSetEnabledNetworksAction = {
@@ -45,6 +63,39 @@ export type NetworkEnablementControllerEvents = NetworkEnablementControllerState
45
63
  */
46
64
  export type AllowedEvents = NetworkControllerNetworkAddedEvent | NetworkControllerNetworkRemovedEvent | NetworkControllerStateChangeEvent | TransactionControllerTransactionSubmittedEvent;
47
65
  export type NetworkEnablementControllerMessenger = Messenger<typeof controllerName, NetworkEnablementControllerActions | AllowedActions, NetworkEnablementControllerEvents | AllowedEvents>;
66
+ /**
67
+ * Network configuration with chain ID and native currency symbol.
68
+ * Used to initialize native asset identifiers.
69
+ */
70
+ export type NetworkConfig = {
71
+ chainId: CaipChainId;
72
+ nativeCurrency: string;
73
+ };
74
+ /**
75
+ * Initializes the native asset identifiers map from network configurations.
76
+ * This function should be called from the client during controller initialization
77
+ * to populate the nativeAssetIdentifiers state based on actual network configurations.
78
+ *
79
+ * @param networks - Array of network configurations with chainId and nativeCurrency
80
+ * @returns A map of CAIP-2 chain IDs to their native asset identifiers
81
+ * @example
82
+ * ```typescript
83
+ * const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)
84
+ * .map(config => ({
85
+ * chainId: toEvmCaipChainId(config.chainId),
86
+ * nativeCurrency: config.nativeCurrency,
87
+ * }));
88
+ *
89
+ * const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)
90
+ * .map(config => ({
91
+ * chainId: config.chainId,
92
+ * nativeCurrency: config.nativeCurrency,
93
+ * }));
94
+ *
95
+ * const nativeAssetIdentifiers = initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);
96
+ * ```
97
+ */
98
+ export declare function initNativeAssetIdentifiers(networks: NetworkConfig[]): NativeAssetIdentifiersMap;
48
99
  /**
49
100
  * Controller responsible for managing network enablement state across different blockchain networks.
50
101
  *
@@ -116,7 +167,7 @@ export declare class NetworkEnablementController extends BaseController<typeof c
116
167
  * Initializes the network enablement state from network controller configurations.
117
168
  *
118
169
  * This method reads the current network configurations from both NetworkController
119
- * and MultichainNetworkController and syncs the enabled network map accordingly.
170
+ * and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.
120
171
  * It ensures proper namespace buckets exist for all configured networks and only
121
172
  * adds missing networks with a default value of false, preserving existing user settings.
122
173
  *
@@ -1 +1 @@
1
- {"version":3,"file":"NetworkEnablementController.d.mts","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kC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,CAAC;AAEpD,MAAM,MAAM,2CAA2C,GACrD,0BAA0B,CACxB,OAAO,cAAc,EACrB,gCAAgC,CACjC,CAAC;AAEJ,MAAM,MAAM,iCAAiC,GAC3C,2CAA2C,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,kCAAkC,GAClC,oCAAoC,GACpC,iCAAiC,GACjC,8CAA8C,CAAC;AAEnD,MAAM,MAAM,oCAAoC,GAAG,SAAS,CAC1D,OAAO,cAAc,EACrB,kCAAkC,GAAG,cAAc,EACnD,iCAAiC,GAAG,aAAa,CAClD,CAAC;AAgDF;;;;;;;;GAQG;AACH,qBAAa,2BAA4B,SAAQ,cAAc,CAC7D,OAAO,cAAc,EACrB,gCAAgC,EAChC,oCAAoC,CACrC;;IACC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,oCAAoC,CAAC;QAChD,KAAK,CAAC,EAAE,OAAO,CAAC,gCAAgC,CAAC,CAAC;KACnD;IAoBD;;;;;;;;;;;;;;;OAeG;IACH,aAAa,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,IAAI;IAsB/C;;;;;;;;;;;;;;;OAeG;IACH,wBAAwB,CACtB,OAAO,EAAE,GAAG,GAAG,WAAW,EAC1B,SAAS,EAAE,aAAa,GACvB,IAAI;IA0BP;;;;;;;;;OASG;IACH,wBAAwB,IAAI,IAAI;IA0EhC;;;;;;;;;;OAUG;IACH,IAAI,IAAI,IAAI;IAwCZ;;;;;;;;;;;;;OAaG;IACH,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,IAAI;IAShD;;;;;;;OAOG;IACH,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,OAAO;CAiItD"}
1
+ {"version":3,"file":"NetworkEnablementController.d.mts","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;A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,WAAW,EAC1B,SAAS,EAAE,aAAa,GACvB,IAAI;IA0BP;;;;;;;;;OASG;IACH,wBAAwB,IAAI,IAAI;IA2EhC;;;;;;;;;;OAUG;IACH,IAAI,IAAI,IAAI;IAiDZ;;;;;;;;;;;;;OAaG;IACH,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,IAAI;IAShD;;;;;;;OAOG;IACH,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,OAAO;CAkLtD"}
@@ -3,14 +3,59 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  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");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _NetworkEnablementController_instances, _NetworkEnablementController_ensureNamespaceBucket, _NetworkEnablementController_isInPopularNetworksMode, _NetworkEnablementController_removeNetworkEntry, _NetworkEnablementController_onAddNetwork;
6
+ var _NetworkEnablementController_instances, _NetworkEnablementController_onNetworkControllerStateChange, _NetworkEnablementController_ensureNamespaceBucket, _NetworkEnablementController_updateNativeAssetIdentifier, _NetworkEnablementController_isInPopularNetworksMode, _NetworkEnablementController_removeNetworkEntry, _NetworkEnablementController_onAddNetwork;
7
7
  import { BaseController } from "@metamask/base-controller";
8
8
  import { BuiltInNetworkName, ChainId } from "@metamask/controller-utils";
9
9
  import { BtcScope, SolScope, TrxScope } from "@metamask/keyring-api";
10
10
  import { KnownCaipNamespace } from "@metamask/utils";
11
11
  import { POPULAR_NETWORKS } from "./constants.mjs";
12
+ import { Slip44Service } from "./services/index.mjs";
12
13
  import { deriveKeys, isOnlyNetworkEnabledInNamespace, isPopularNetwork } from "./utils.mjs";
13
14
  const controllerName = 'NetworkEnablementController';
15
+ /**
16
+ * Builds a native asset identifier in CAIP-19-like format.
17
+ *
18
+ * @param caipChainId - The CAIP-2 chain ID (e.g., 'eip155:1', 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')
19
+ * @param slip44CoinType - The SLIP-44 coin type number
20
+ * @returns The native asset identifier string (e.g., 'eip155:1/slip44:60')
21
+ */
22
+ function buildNativeAssetIdentifier(caipChainId, slip44CoinType) {
23
+ return `${caipChainId}/slip44:${slip44CoinType}`;
24
+ }
25
+ /**
26
+ * Initializes the native asset identifiers map from network configurations.
27
+ * This function should be called from the client during controller initialization
28
+ * to populate the nativeAssetIdentifiers state based on actual network configurations.
29
+ *
30
+ * @param networks - Array of network configurations with chainId and nativeCurrency
31
+ * @returns A map of CAIP-2 chain IDs to their native asset identifiers
32
+ * @example
33
+ * ```typescript
34
+ * const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)
35
+ * .map(config => ({
36
+ * chainId: toEvmCaipChainId(config.chainId),
37
+ * nativeCurrency: config.nativeCurrency,
38
+ * }));
39
+ *
40
+ * const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)
41
+ * .map(config => ({
42
+ * chainId: config.chainId,
43
+ * nativeCurrency: config.nativeCurrency,
44
+ * }));
45
+ *
46
+ * const nativeAssetIdentifiers = initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);
47
+ * ```
48
+ */
49
+ export function initNativeAssetIdentifiers(networks) {
50
+ const result = {};
51
+ for (const { chainId, nativeCurrency } of networks) {
52
+ const slip44CoinType = Slip44Service.getSlip44BySymbol(nativeCurrency);
53
+ if (slip44CoinType !== undefined) {
54
+ result[chainId] = buildNativeAssetIdentifier(chainId, slip44CoinType);
55
+ }
56
+ }
57
+ return result;
58
+ }
14
59
  /**
15
60
  * Gets the default state for the NetworkEnablementController.
16
61
  *
@@ -44,6 +89,9 @@ const getDefaultNetworkEnablementControllerState = () => ({
44
89
  [TrxScope.Shasta]: false,
45
90
  },
46
91
  },
92
+ // nativeAssetIdentifiers is initialized as empty and should be populated
93
+ // by the client using initNativeAssetIdentifiers() during controller init
94
+ nativeAssetIdentifiers: {},
47
95
  });
48
96
  // Metadata for the controller state
49
97
  const metadata = {
@@ -53,6 +101,12 @@ const metadata = {
53
101
  includeInDebugSnapshot: true,
54
102
  usedInUi: true,
55
103
  },
104
+ nativeAssetIdentifiers: {
105
+ includeInStateLogs: true,
106
+ persist: true,
107
+ includeInDebugSnapshot: true,
108
+ usedInUi: true,
109
+ },
56
110
  };
57
111
  /**
58
112
  * Controller responsible for managing network enablement state across different blockchain networks.
@@ -82,12 +136,15 @@ export class NetworkEnablementController extends BaseController {
82
136
  },
83
137
  });
84
138
  _NetworkEnablementController_instances.add(this);
85
- messenger.subscribe('NetworkController:networkAdded', ({ chainId }) => {
86
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_onAddNetwork).call(this, chainId);
139
+ messenger.subscribe('NetworkController:networkAdded', ({ chainId, nativeCurrency }) => {
140
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_onAddNetwork).call(this, chainId, nativeCurrency);
87
141
  });
88
142
  messenger.subscribe('NetworkController:networkRemoved', ({ chainId }) => {
89
143
  __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_removeNetworkEntry).call(this, chainId);
90
144
  });
145
+ messenger.subscribe('NetworkController:stateChange', (_newState, patches) => {
146
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_onNetworkControllerStateChange).call(this, patches);
147
+ });
91
148
  }
92
149
  /**
93
150
  * Enables or disables a network for the user.
@@ -107,20 +164,20 @@ export class NetworkEnablementController extends BaseController {
107
164
  */
108
165
  enableNetwork(chainId) {
109
166
  const { namespace, storageKey } = deriveKeys(chainId);
110
- this.update((s) => {
167
+ this.update((state) => {
111
168
  // disable all networks in all namespaces first
112
- Object.keys(s.enabledNetworkMap).forEach((ns) => {
113
- Object.keys(s.enabledNetworkMap[ns]).forEach((key) => {
114
- s.enabledNetworkMap[ns][key] = false;
169
+ Object.keys(state.enabledNetworkMap).forEach((ns) => {
170
+ Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {
171
+ state.enabledNetworkMap[ns][key] = false;
115
172
  });
116
173
  });
117
174
  // if the namespace bucket does not exist, return
118
175
  // new nemespace are added only when a new network is added
119
- if (!s.enabledNetworkMap[namespace]) {
176
+ if (!state.enabledNetworkMap[namespace]) {
120
177
  return;
121
178
  }
122
179
  // enable the network
123
- s.enabledNetworkMap[namespace][storageKey] = true;
180
+ state.enabledNetworkMap[namespace][storageKey] = true;
124
181
  });
125
182
  }
126
183
  /**
@@ -145,17 +202,17 @@ export class NetworkEnablementController extends BaseController {
145
202
  if (derivedNamespace !== namespace) {
146
203
  throw new Error(`Chain ID ${chainId} belongs to namespace ${derivedNamespace}, but namespace ${namespace} was specified`);
147
204
  }
148
- this.update((s) => {
205
+ this.update((state) => {
149
206
  // Ensure the namespace bucket exists
150
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, namespace);
207
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
151
208
  // Disable all networks in the specified namespace first
152
- if (s.enabledNetworkMap[namespace]) {
153
- Object.keys(s.enabledNetworkMap[namespace]).forEach((key) => {
154
- s.enabledNetworkMap[namespace][key] = false;
209
+ if (state.enabledNetworkMap[namespace]) {
210
+ Object.keys(state.enabledNetworkMap[namespace]).forEach((key) => {
211
+ state.enabledNetworkMap[namespace][key] = false;
155
212
  });
156
213
  }
157
214
  // Enable the target network in the specified namespace
158
- s.enabledNetworkMap[namespace][storageKey] = true;
215
+ state.enabledNetworkMap[namespace][storageKey] = true;
159
216
  });
160
217
  }
161
218
  /**
@@ -169,11 +226,11 @@ export class NetworkEnablementController extends BaseController {
169
226
  * Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.
170
227
  */
171
228
  enableAllPopularNetworks() {
172
- this.update((s) => {
229
+ this.update((state) => {
173
230
  // First disable all networks across all namespaces
174
- Object.keys(s.enabledNetworkMap).forEach((ns) => {
175
- Object.keys(s.enabledNetworkMap[ns]).forEach((key) => {
176
- s.enabledNetworkMap[ns][key] = false;
231
+ Object.keys(state.enabledNetworkMap).forEach((ns) => {
232
+ Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {
233
+ state.enabledNetworkMap[ns][key] = false;
177
234
  });
178
235
  });
179
236
  // Get current network configurations to check if networks exist
@@ -185,35 +242,36 @@ export class NetworkEnablementController extends BaseController {
185
242
  // Check if network exists in NetworkController configurations
186
243
  if (networkControllerState.networkConfigurationsByChainId[chainId]) {
187
244
  // Ensure namespace bucket exists
188
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, namespace);
245
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
189
246
  // Enable the network
190
- s.enabledNetworkMap[namespace][storageKey] = true;
247
+ state.enabledNetworkMap[namespace][storageKey] = true;
191
248
  }
192
249
  });
193
250
  // Enable Solana mainnet if it exists in MultichainNetworkController configurations
194
251
  const solanaKeys = deriveKeys(SolScope.Mainnet);
195
252
  if (multichainState.multichainNetworkConfigurationsByChainId[SolScope.Mainnet]) {
196
253
  // Ensure namespace bucket exists
197
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, solanaKeys.namespace);
254
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, solanaKeys.namespace);
198
255
  // Enable Solana mainnet
199
- s.enabledNetworkMap[solanaKeys.namespace][solanaKeys.storageKey] = true;
256
+ state.enabledNetworkMap[solanaKeys.namespace][solanaKeys.storageKey] =
257
+ true;
200
258
  }
201
259
  // Enable Bitcoin mainnet if it exists in MultichainNetworkController configurations
202
260
  const bitcoinKeys = deriveKeys(BtcScope.Mainnet);
203
261
  if (multichainState.multichainNetworkConfigurationsByChainId[BtcScope.Mainnet]) {
204
262
  // Ensure namespace bucket exists
205
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, bitcoinKeys.namespace);
263
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, bitcoinKeys.namespace);
206
264
  // Enable Bitcoin mainnet
207
- s.enabledNetworkMap[bitcoinKeys.namespace][bitcoinKeys.storageKey] =
265
+ state.enabledNetworkMap[bitcoinKeys.namespace][bitcoinKeys.storageKey] =
208
266
  true;
209
267
  }
210
268
  // Enable Tron mainnet if it exists in MultichainNetworkController configurations
211
269
  const tronKeys = deriveKeys(TrxScope.Mainnet);
212
270
  if (multichainState.multichainNetworkConfigurationsByChainId[TrxScope.Mainnet]) {
213
271
  // Ensure namespace bucket exists
214
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, tronKeys.namespace);
272
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, tronKeys.namespace);
215
273
  // Enable Tron mainnet
216
- s.enabledNetworkMap[tronKeys.namespace][tronKeys.storageKey] = true;
274
+ state.enabledNetworkMap[tronKeys.namespace][tronKeys.storageKey] = true;
217
275
  }
218
276
  });
219
277
  }
@@ -221,7 +279,7 @@ export class NetworkEnablementController extends BaseController {
221
279
  * Initializes the network enablement state from network controller configurations.
222
280
  *
223
281
  * This method reads the current network configurations from both NetworkController
224
- * and MultichainNetworkController and syncs the enabled network map accordingly.
282
+ * and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.
225
283
  * It ensures proper namespace buckets exist for all configured networks and only
226
284
  * adds missing networks with a default value of false, preserving existing user settings.
227
285
  *
@@ -229,28 +287,34 @@ export class NetworkEnablementController extends BaseController {
229
287
  * have been initialized and their configurations are available.
230
288
  */
231
289
  init() {
232
- this.update((s) => {
290
+ this.update((state) => {
233
291
  // Get network configurations from NetworkController (EVM networks)
234
292
  const networkControllerState = this.messenger.call('NetworkController:getState');
235
293
  // Get network configurations from MultichainNetworkController (all networks)
236
294
  const multichainState = this.messenger.call('MultichainNetworkController:getState');
237
295
  // Initialize namespace buckets for EVM networks from NetworkController
238
- Object.keys(networkControllerState.networkConfigurationsByChainId).forEach((chainId) => {
239
- const { namespace, storageKey } = deriveKeys(chainId);
240
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, namespace);
296
+ Object.entries(networkControllerState.networkConfigurationsByChainId).forEach(([chainId, config]) => {
297
+ var _a;
298
+ const { namespace, storageKey, caipChainId } = deriveKeys(chainId);
299
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
241
300
  // Only add network if it doesn't already exist in state (preserves user settings)
242
- if (s.enabledNetworkMap[namespace][storageKey] === undefined) {
243
- s.enabledNetworkMap[namespace][storageKey] = false;
301
+ (_a = state.enabledNetworkMap[namespace])[storageKey] ?? (_a[storageKey] = false);
302
+ // Sync nativeAssetIdentifiers using the nativeCurrency symbol
303
+ if (state.nativeAssetIdentifiers[caipChainId] === undefined) {
304
+ const slip44CoinType = Slip44Service.getSlip44BySymbol(config.nativeCurrency);
305
+ if (slip44CoinType !== undefined) {
306
+ state.nativeAssetIdentifiers[caipChainId] =
307
+ buildNativeAssetIdentifier(caipChainId, slip44CoinType);
308
+ }
244
309
  }
245
310
  });
246
311
  // Initialize namespace buckets for all networks from MultichainNetworkController
247
312
  Object.keys(multichainState.multichainNetworkConfigurationsByChainId).forEach((chainId) => {
313
+ var _a;
248
314
  const { namespace, storageKey } = deriveKeys(chainId);
249
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, namespace);
315
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
250
316
  // Only add network if it doesn't already exist in state (preserves user settings)
251
- if (s.enabledNetworkMap[namespace][storageKey] === undefined) {
252
- s.enabledNetworkMap[namespace][storageKey] = false;
253
- }
317
+ (_a = state.enabledNetworkMap[namespace])[storageKey] ?? (_a[storageKey] = false);
254
318
  });
255
319
  });
256
320
  }
@@ -271,8 +335,8 @@ export class NetworkEnablementController extends BaseController {
271
335
  disableNetwork(chainId) {
272
336
  const derivedKeys = deriveKeys(chainId);
273
337
  const { namespace, storageKey } = derivedKeys;
274
- this.update((s) => {
275
- s.enabledNetworkMap[namespace][storageKey] = false;
338
+ this.update((state) => {
339
+ state.enabledNetworkMap[namespace][storageKey] = false;
276
340
  });
277
341
  }
278
342
  /**
@@ -289,10 +353,36 @@ export class NetworkEnablementController extends BaseController {
289
353
  return this.state.enabledNetworkMap[namespace]?.[storageKey] ?? false;
290
354
  }
291
355
  }
292
- _NetworkEnablementController_instances = new WeakSet(), _NetworkEnablementController_ensureNamespaceBucket = function _NetworkEnablementController_ensureNamespaceBucket(state, ns) {
356
+ _NetworkEnablementController_instances = new WeakSet(), _NetworkEnablementController_onNetworkControllerStateChange = function _NetworkEnablementController_onNetworkControllerStateChange(patches) {
357
+ // Look for patches that replace a network configuration
358
+ // Path format: ['networkConfigurationsByChainId', chainId]
359
+ for (const patch of patches) {
360
+ if (patch.path.length === 2 &&
361
+ patch.path[0] === 'networkConfigurationsByChainId' &&
362
+ patch.op === 'replace' &&
363
+ patch.value &&
364
+ typeof patch.value === 'object' &&
365
+ 'nativeCurrency' in patch.value) {
366
+ const chainId = patch.path[1];
367
+ const networkConfig = patch.value;
368
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_updateNativeAssetIdentifier).call(this, chainId, networkConfig.nativeCurrency);
369
+ }
370
+ }
371
+ }, _NetworkEnablementController_ensureNamespaceBucket = function _NetworkEnablementController_ensureNamespaceBucket(state, ns) {
293
372
  if (!state.enabledNetworkMap[ns]) {
294
373
  state.enabledNetworkMap[ns] = {};
295
374
  }
375
+ }, _NetworkEnablementController_updateNativeAssetIdentifier = function _NetworkEnablementController_updateNativeAssetIdentifier(chainId, symbol) {
376
+ const slip44CoinType = Slip44Service.getSlip44BySymbol(symbol);
377
+ const { caipChainId } = deriveKeys(chainId);
378
+ this.update((state) => {
379
+ if (slip44CoinType === undefined) {
380
+ // Remove the entry if no SLIP-44 mapping exists for the symbol
381
+ delete state.nativeAssetIdentifiers[caipChainId];
382
+ return;
383
+ }
384
+ state.nativeAssetIdentifiers[caipChainId] = buildNativeAssetIdentifier(caipChainId, slip44CoinType);
385
+ });
296
386
  }, _NetworkEnablementController_isInPopularNetworksMode = function _NetworkEnablementController_isInPopularNetworksMode() {
297
387
  // Get current network configurations to check which popular networks exist
298
388
  const networkControllerState = this.messenger.call('NetworkController:getState');
@@ -310,22 +400,25 @@ _NetworkEnablementController_instances = new WeakSet(), _NetworkEnablementContro
310
400
  return enabledPopularNetworksCount > 1;
311
401
  }, _NetworkEnablementController_removeNetworkEntry = function _NetworkEnablementController_removeNetworkEntry(chainId) {
312
402
  const derivedKeys = deriveKeys(chainId);
313
- const { namespace, storageKey } = derivedKeys;
314
- this.update((s) => {
403
+ const { namespace, storageKey, caipChainId } = derivedKeys;
404
+ this.update((state) => {
315
405
  // fallback and enable ethereum mainnet
316
406
  if (isOnlyNetworkEnabledInNamespace(this.state, derivedKeys)) {
317
- s.enabledNetworkMap[namespace][ChainId[BuiltInNetworkName.Mainnet]] =
318
- true;
407
+ state.enabledNetworkMap[namespace][ChainId[BuiltInNetworkName.Mainnet]] = true;
319
408
  }
320
- if (namespace in s.enabledNetworkMap) {
321
- delete s.enabledNetworkMap[namespace][storageKey];
409
+ if (namespace in state.enabledNetworkMap) {
410
+ delete state.enabledNetworkMap[namespace][storageKey];
322
411
  }
412
+ // Remove from nativeAssetIdentifiers as well
413
+ delete state.nativeAssetIdentifiers[caipChainId];
323
414
  });
324
- }, _NetworkEnablementController_onAddNetwork = function _NetworkEnablementController_onAddNetwork(chainId) {
325
- const { namespace, storageKey, reference } = deriveKeys(chainId);
326
- this.update((s) => {
415
+ }, _NetworkEnablementController_onAddNetwork = function _NetworkEnablementController_onAddNetwork(chainId, nativeCurrency) {
416
+ const { namespace, storageKey, reference, caipChainId } = deriveKeys(chainId);
417
+ // Look up the SLIP-44 coin type for the native currency
418
+ const slip44CoinType = Slip44Service.getSlip44BySymbol(nativeCurrency);
419
+ this.update((state) => {
327
420
  // Ensure the namespace bucket exists
328
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, namespace);
421
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
329
422
  // Check if popular networks mode is active (>2 popular networks enabled)
330
423
  const inPopularNetworksMode = __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_isInPopularNetworksMode).call(this);
331
424
  // Check if the network being added is a popular network
@@ -334,17 +427,21 @@ _NetworkEnablementController_instances = new WeakSet(), _NetworkEnablementContro
334
427
  const shouldKeepCurrentSelection = inPopularNetworksMode && isAddedNetworkPopular;
335
428
  if (shouldKeepCurrentSelection) {
336
429
  // Add the popular network but don't enable it (keep current selection)
337
- s.enabledNetworkMap[namespace][storageKey] = true;
430
+ state.enabledNetworkMap[namespace][storageKey] = true;
338
431
  }
339
432
  else {
340
433
  // Switch to the newly added network (disable all others, enable this one)
341
- Object.keys(s.enabledNetworkMap).forEach((ns) => {
342
- Object.keys(s.enabledNetworkMap[ns]).forEach((key) => {
343
- s.enabledNetworkMap[ns][key] = false;
434
+ Object.keys(state.enabledNetworkMap).forEach((ns) => {
435
+ Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {
436
+ state.enabledNetworkMap[ns][key] = false;
344
437
  });
345
438
  });
346
439
  // Enable the newly added network
347
- s.enabledNetworkMap[namespace][storageKey] = true;
440
+ state.enabledNetworkMap[namespace][storageKey] = true;
441
+ }
442
+ // Update nativeAssetIdentifiers with the CAIP-19-like identifier
443
+ if (slip44CoinType !== undefined) {
444
+ state.nativeAssetIdentifiers[caipChainId] = buildNativeAssetIdentifier(caipChainId, slip44CoinType);
348
445
  }
349
446
  });
350
447
  };