@metamask-previews/network-enablement-controller 5.6.0-preview-ec4680201 → 5.6.0-preview-40d5fb1e2

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 (41) hide show
  1. package/CHANGELOG.md +0 -6
  2. package/dist/NetworkEnablementController-method-action-types.cjs.map +1 -1
  3. package/dist/NetworkEnablementController-method-action-types.d.cts +2 -2
  4. package/dist/NetworkEnablementController-method-action-types.d.cts.map +1 -1
  5. package/dist/NetworkEnablementController-method-action-types.d.mts +2 -2
  6. package/dist/NetworkEnablementController-method-action-types.d.mts.map +1 -1
  7. package/dist/NetworkEnablementController-method-action-types.mjs.map +1 -1
  8. package/dist/NetworkEnablementController.cjs +30 -50
  9. package/dist/NetworkEnablementController.cjs.map +1 -1
  10. package/dist/NetworkEnablementController.d.cts +3 -4
  11. package/dist/NetworkEnablementController.d.cts.map +1 -1
  12. package/dist/NetworkEnablementController.d.mts +3 -4
  13. package/dist/NetworkEnablementController.d.mts.map +1 -1
  14. package/dist/NetworkEnablementController.mjs +10 -30
  15. package/dist/NetworkEnablementController.mjs.map +1 -1
  16. package/dist/index.cjs +14 -14
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +1 -1
  19. package/dist/index.d.cts.map +1 -1
  20. package/dist/index.d.mts +1 -1
  21. package/dist/index.d.mts.map +1 -1
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/selectors.cjs +2 -2
  24. package/dist/selectors.cjs.map +1 -1
  25. package/dist/selectors.d.cts.map +1 -1
  26. package/dist/selectors.d.mts.map +1 -1
  27. package/dist/selectors.mjs.map +1 -1
  28. package/dist/services/index.cjs +4 -4
  29. package/dist/services/index.cjs.map +1 -1
  30. package/dist/services/index.d.cts.map +1 -1
  31. package/dist/services/index.d.mts.map +1 -1
  32. package/dist/services/index.mjs.map +1 -1
  33. package/dist/utils.cjs +19 -1
  34. package/dist/utils.cjs.map +1 -1
  35. package/dist/utils.d.cts +7 -0
  36. package/dist/utils.d.cts.map +1 -1
  37. package/dist/utils.d.mts +7 -0
  38. package/dist/utils.d.mts.map +1 -1
  39. package/dist/utils.mjs +17 -0
  40. package/dist/utils.mjs.map +1 -1
  41. package/package.json +7 -8
package/dist/utils.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { toHex } from "@metamask/controller-utils";
2
2
  import { toEvmCaipChainId } from "@metamask/multichain-network-controller";
3
3
  import { isCaipChainId, isHexString, KnownCaipNamespace, parseCaipChainId } from "@metamask/utils";
4
+ import { POPULAR_NETWORKS } from "./constants.mjs";
4
5
  /**
5
6
  * Derives the namespace, storage key, and CAIP chain ID from a given chain ID.
6
7
  *
@@ -54,4 +55,20 @@ export function isOnlyNetworkEnabledInNamespace(state, derivedKeys) {
54
55
  // Return false if there are zero or multiple enabled networks
55
56
  return false;
56
57
  }
58
+ /**
59
+ * Checks if a network is considered popular based on its reference.
60
+ *
61
+ * @param reference - The network reference (typically the chain ID reference part)
62
+ * @returns True if the network is popular, false otherwise
63
+ */
64
+ export function isPopularNetwork(reference) {
65
+ try {
66
+ return POPULAR_NETWORKS.includes(toHex(reference));
67
+ }
68
+ catch {
69
+ // If toHex fails (e.g., for non-decimal references like Bitcoin hashes),
70
+ // the network is not popular
71
+ return false;
72
+ }
73
+ }
57
74
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,OAAO,EAAE,gBAAgB,EAAE,gDAAgD;AAE3E,OAAO,EACL,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EACjB,wBAAwB;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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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"]}
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,OAAO,EAAE,gBAAgB,EAAE,gDAAgD;AAE3E,OAAO,EACL,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EACjB,wBAAwB;AAEzB,OAAO,EAAE,gBAAgB,EAAE,wBAAoB;AAa/C;;;;;;;;;;;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;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IAChD,IAAI,CAAC;QACH,OAAO,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,yEAAyE;QACzE,6BAA6B;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;AACH,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 { POPULAR_NETWORKS } from './constants';\nimport type { NetworkEnablementControllerState } from './NetworkEnablementController';\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\n/**\n * Checks if a network is considered popular based on its reference.\n *\n * @param reference - The network reference (typically the chain ID reference part)\n * @returns True if the network is popular, false otherwise\n */\nexport function isPopularNetwork(reference: string): boolean {\n try {\n return POPULAR_NETWORKS.includes(toHex(reference));\n } catch {\n // If toHex fails (e.g., for non-decimal references like Bitcoin hashes),\n // the network is not popular\n return false;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/network-enablement-controller",
3
- "version": "5.6.0-preview-ec4680201",
3
+ "version": "5.6.0-preview-40d5fb1e2",
4
4
  "description": "Provides an interface to the currently enabled network using a MetaMask-compatible provider object",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -46,8 +46,8 @@
46
46
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/network-enablement-controller",
47
47
  "lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
48
48
  "lint:tsconfigs:fix": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts --fix",
49
- "messenger-action-types:check": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check",
50
- "messenger-action-types:generate": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate",
49
+ "messenger-action-types:check": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --check",
50
+ "messenger-action-types:generate": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --generate",
51
51
  "since-latest-release": "../../scripts/since-latest-release.sh",
52
52
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
53
53
  "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
@@ -56,24 +56,23 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "@metamask/base-controller": "^9.1.0",
59
- "@metamask/config-registry-controller": "^0.4.1",
60
59
  "@metamask/controller-utils": "^12.3.0",
61
60
  "@metamask/keyring-api": "^23.5.0",
62
61
  "@metamask/messenger": "^2.0.0",
63
62
  "@metamask/multichain-network-controller": "^3.2.1",
64
63
  "@metamask/network-controller": "^34.0.0",
65
64
  "@metamask/slip44": "^4.3.0",
66
- "@metamask/transaction-controller": "^69.2.1",
65
+ "@metamask/transaction-controller": "^69.0.0",
67
66
  "@metamask/utils": "^11.11.0",
68
67
  "reselect": "^5.1.1"
69
68
  },
70
69
  "devDependencies": {
71
70
  "@metamask/auto-changelog": "^6.1.0",
72
71
  "@ts-bridge/cli": "^0.6.4",
73
- "@types/jest": "^30.0.0",
72
+ "@types/jest": "^29.5.14",
74
73
  "deepmerge": "^4.2.2",
75
- "jest": "^30.4.2",
76
- "ts-jest": "^29.4.11",
74
+ "jest": "^29.7.0",
75
+ "ts-jest": "^29.2.5",
77
76
  "tsx": "^4.20.5",
78
77
  "typedoc": "^0.25.13",
79
78
  "typedoc-plugin-missing-exports": "^2.0.0",