@metamask-previews/network-controller 34.0.0-preview-42cce76ad → 34.0.0-preview-a2621f612
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 +11 -0
- package/dist/NetworkController.cjs +8 -36
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +1 -1
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +1 -1
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +8 -36
- package/dist/NetworkController.mjs.map +1 -1
- package/dist/create-network-client.cjs +7 -7
- package/dist/create-network-client.cjs.map +1 -1
- package/dist/create-network-client.d.cts.map +1 -1
- package/dist/create-network-client.d.mts.map +1 -1
- package/dist/create-network-client.mjs +8 -8
- package/dist/create-network-client.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +1 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
+
- **BREAKING:** `BuiltInNetworkClientId` is now `string` instead of `InfuraNetworkType` ([#9432](https://github.com/MetaMask/core/pull/9432))
|
|
13
|
+
- This type was previously constrained to known Infura network names (e.g. `"mainnet"`, `"sepolia"`). It is now `string` to allow dynamically configured Infura networks whose names are not bundled into the package.
|
|
14
|
+
- If you have code that narrows on `BuiltInNetworkClientId`, you will need to remove the narrowing or check the network client type via `NetworkClientType` instead.
|
|
15
|
+
- **BREAKING:** `InfuraNetworkClientConfiguration.network` is now `string` instead of `InfuraNetworkType` ([#9432](https://github.com/MetaMask/core/pull/9432))
|
|
16
|
+
- Previously only known Infura network names were accepted. Any valid Infura subdomain string is now accepted.
|
|
17
|
+
- **BREAKING:** `NetworkController.getNetworkClientById` no longer distinguishes between Infura and custom network clients when the provided ID is not found ([#9432](https://github.com/MetaMask/core/pull/9432))
|
|
18
|
+
- The method now checks the Infura registry first and falls back to the custom registry, without using `isInfuraNetworkType` to decide which registry to consult.
|
|
19
|
+
- The error message when no client is found has changed from `"No Infura network client was found with the ID \"<id>\"."` / `"No custom network client was found with the ID \"<id>\"."` to `"No network client was found with ID \"<id>\"."`.
|
|
20
|
+
- Remove validation that prevented a custom RPC endpoint from having a `networkClientId` that matches a known Infura network name ([#9432](https://github.com/MetaMask/core/pull/9432))
|
|
21
|
+
- Remove validation that required an Infura RPC endpoint URL's implied chain ID to match the chain ID of the network configuration it belongs to ([#9432](https://github.com/MetaMask/core/pull/9432))
|
|
22
|
+
- This allows Infura-backed networks to be added and updated dynamically without being constrained to the known Infura network list bundled in `@metamask/controller-utils`.
|
|
12
23
|
- Bump `@metamask/messenger` from `^1.2.0` to `^2.0.0` ([#9392](https://github.com/MetaMask/core/pull/9392))
|
|
13
24
|
- Bump `@metamask/connectivity-controller` from `^0.2.0` to `^0.3.0` ([#9435](https://github.com/MetaMask/core/pull/9435))
|
|
14
25
|
|
|
@@ -286,16 +286,12 @@ function isValidUrl(url) {
|
|
|
286
286
|
*
|
|
287
287
|
* @param rpcEndpointUrl - The URL to operate on.
|
|
288
288
|
* @returns The Infura network name that the URL references.
|
|
289
|
-
* @throws if
|
|
290
|
-
* present in the URL.
|
|
289
|
+
* @throws if no Infura network is present in the URL.
|
|
291
290
|
*/
|
|
292
291
|
function deriveInfuraNetworkNameFromRpcEndpointUrl(rpcEndpointUrl) {
|
|
293
292
|
const match = INFURA_URL_REGEX.exec(rpcEndpointUrl);
|
|
294
293
|
if (match?.groups) {
|
|
295
|
-
|
|
296
|
-
return match.groups.networkName;
|
|
297
|
-
}
|
|
298
|
-
throw new Error(`Unknown Infura network '${match.groups.networkName}'`);
|
|
294
|
+
return match.groups.networkName;
|
|
299
295
|
}
|
|
300
296
|
throw new Error('Could not derive Infura network from RPC endpoint URL');
|
|
301
297
|
}
|
|
@@ -531,18 +527,13 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
531
527
|
throw new Error('No network client ID was provided.');
|
|
532
528
|
}
|
|
533
529
|
const autoManagedNetworkClientRegistry = __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated).call(this);
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
// This is impossible to reach
|
|
537
|
-
/* istanbul ignore if */
|
|
538
|
-
if (!infuraNetworkClient) {
|
|
539
|
-
throw new Error(`No Infura network client was found with the ID "${networkClientId}".`);
|
|
540
|
-
}
|
|
530
|
+
const infuraNetworkClient = autoManagedNetworkClientRegistry[types_1.NetworkClientType.Infura][networkClientId];
|
|
531
|
+
if (infuraNetworkClient) {
|
|
541
532
|
return infuraNetworkClient;
|
|
542
533
|
}
|
|
543
534
|
const customNetworkClient = autoManagedNetworkClientRegistry[types_1.NetworkClientType.Custom][networkClientId];
|
|
544
535
|
if (!customNetworkClient) {
|
|
545
|
-
throw new Error(`No
|
|
536
|
+
throw new Error(`No network client was found with ID "${networkClientId}".`);
|
|
546
537
|
}
|
|
547
538
|
return customNetworkClient;
|
|
548
539
|
}
|
|
@@ -1053,7 +1044,6 @@ _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId
|
|
|
1053
1044
|
const autoManagedNetworkClientRegistry = __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated).call(this);
|
|
1054
1045
|
for (const networkClientsById of Object.values(autoManagedNetworkClientRegistry)) {
|
|
1055
1046
|
for (const networkClientId of Object.keys(networkClientsById)) {
|
|
1056
|
-
// Type assertion: We can assume that `networkClientId` is valid here.
|
|
1057
1047
|
const networkClient = networkClientsById[networkClientId];
|
|
1058
1048
|
if (networkClient.configuration.failoverRpcUrls &&
|
|
1059
1049
|
networkClient.configuration.failoverRpcUrls.length > 0) {
|
|
@@ -1101,10 +1091,7 @@ async function _NetworkController_refreshNetwork(networkClientId, options = {})
|
|
|
1101
1091
|
* @returns The resulting metadata for the network.
|
|
1102
1092
|
*/
|
|
1103
1093
|
async function _NetworkController_determineNetworkMetadata(networkClientId) {
|
|
1104
|
-
|
|
1105
|
-
const networkClient = (0, controller_utils_1.isInfuraNetworkType)(networkClientId)
|
|
1106
|
-
? this.getNetworkClientById(networkClientId)
|
|
1107
|
-
: this.getNetworkClientById(networkClientId);
|
|
1094
|
+
const networkClient = this.getNetworkClientById(networkClientId);
|
|
1108
1095
|
const isInfura = networkClient.configuration.type === types_1.NetworkClientType.Infura;
|
|
1109
1096
|
let networkStatus;
|
|
1110
1097
|
let isEIP1559Compatible;
|
|
@@ -1331,11 +1318,6 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1331
1318
|
const networkClientId = 'networkClientId' in rpcEndpointFields
|
|
1332
1319
|
? rpcEndpointFields.networkClientId
|
|
1333
1320
|
: undefined;
|
|
1334
|
-
if (rpcEndpointFields.type === RpcEndpointType.Custom &&
|
|
1335
|
-
networkClientId !== undefined &&
|
|
1336
|
-
(0, controller_utils_1.isInfuraNetworkType)(networkClientId)) {
|
|
1337
|
-
throw new Error(`${errorMessagePrefix}: Custom RPC endpoint '${rpcEndpointFields.url}' has invalid network client ID '${networkClientId}'`);
|
|
1338
|
-
}
|
|
1339
1321
|
if (mode === 'update' &&
|
|
1340
1322
|
networkClientId !== undefined &&
|
|
1341
1323
|
rpcEndpointFields.type === RpcEndpointType.Custom &&
|
|
@@ -1378,17 +1360,6 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1378
1360
|
if (infuraRpcEndpoints.length > 1) {
|
|
1379
1361
|
throw new Error(`${errorMessagePrefix}: There cannot be more than one Infura RPC endpoint`);
|
|
1380
1362
|
}
|
|
1381
|
-
const soleInfuraRpcEndpoint = infuraRpcEndpoints[0];
|
|
1382
|
-
if (soleInfuraRpcEndpoint) {
|
|
1383
|
-
const infuraNetworkName = deriveInfuraNetworkNameFromRpcEndpointUrl(soleInfuraRpcEndpoint.url);
|
|
1384
|
-
const infuraNetworkNickname = controller_utils_1.NetworkNickname[infuraNetworkName];
|
|
1385
|
-
const infuraChainId = controller_utils_1.ChainId[infuraNetworkName];
|
|
1386
|
-
if (networkFields.chainId !== infuraChainId) {
|
|
1387
|
-
throw new Error(mode === 'add'
|
|
1388
|
-
? `Could not add network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`
|
|
1389
|
-
: `Could not update network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`);
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
1363
|
if (networkFields.rpcEndpoints[networkFields.defaultRpcEndpointIndex] ===
|
|
1393
1364
|
undefined) {
|
|
1394
1365
|
throw new Error(`${errorMessagePrefix}: \`defaultRpcEndpointIndex\` must refer to an entry in \`rpcEndpoints\``);
|
|
@@ -1550,9 +1521,10 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1550
1521
|
[types_1.NetworkClientType.Infura]: {},
|
|
1551
1522
|
});
|
|
1552
1523
|
}, _NetworkController_applyNetworkSelection = function _NetworkController_applyNetworkSelection(networkClientId, { updateState, } = {}) {
|
|
1524
|
+
const networkClient = this.getNetworkClientById(networkClientId);
|
|
1553
1525
|
const autoManagedNetworkClientRegistry = __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated).call(this);
|
|
1554
1526
|
let autoManagedNetworkClient;
|
|
1555
|
-
if (
|
|
1527
|
+
if (networkClient.configuration.type === types_1.NetworkClientType.Infura) {
|
|
1556
1528
|
const possibleAutoManagedNetworkClient = autoManagedNetworkClientRegistry[types_1.NetworkClientType.Infura][networkClientId];
|
|
1557
1529
|
// This is impossible to reach
|
|
1558
1530
|
/* istanbul ignore if */
|