You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@metamask/controller-utils

Package Overview
Dependencies
Maintainers
3
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/controller-utils - npm Package Compare versions

Comparing version
11.15.0
to
11.16.0
+15
-1
CHANGELOG.md

@@ -10,2 +10,15 @@ # Changelog

## [11.16.0]
### Added
- Add `getCircuitState` method to `ServicePolicy` ([#7164](https://github.com/MetaMask/core/pull/7164))
- This can be used when working with a chain of services to know whether a service's underlying circuit is open or closed.
- Add `onAvailable` method to `ServicePolicy` ([#7164](https://github.com/MetaMask/core/pull/7164))
- This can be used to listen for the initial successful execution of the service, or the first successful execution after the service becomes degraded or the circuit breaks.
- Add `reset` method to `ServicePolicy` ([#7164](https://github.com/MetaMask/core/pull/7164))
- This can be used when working with a chain of services to reset the state of the circuit breaker policy (e.g. if a primary recovers and we want to reset the failovers).
- Export `CockatielEventEmitter` and `CockatielFailureReason` from Cockatiel ([#7164](https://github.com/MetaMask/core/pull/7164))
- These can be used to further transform types for event emitters/listeners.
## [11.15.0]

@@ -600,3 +613,4 @@

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@11.15.0...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@11.16.0...HEAD
[11.16.0]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@11.15.0...@metamask/controller-utils@11.16.0
[11.15.0]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@11.14.1...@metamask/controller-utils@11.15.0

@@ -603,0 +617,0 @@ [11.14.1]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@11.14.0...@metamask/controller-utils@11.14.1

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createServicePolicy = exports.DEFAULT_DEGRADED_THRESHOLD = exports.DEFAULT_CIRCUIT_BREAK_DURATION = exports.DEFAULT_MAX_CONSECUTIVE_FAILURES = exports.DEFAULT_MAX_RETRIES = exports.handleWhen = exports.handleAll = exports.ExponentialBackoff = exports.ConstantBackoff = exports.CircuitState = exports.BrokenCircuitError = void 0;
exports.createServicePolicy = exports.DEFAULT_DEGRADED_THRESHOLD = exports.DEFAULT_CIRCUIT_BREAK_DURATION = exports.DEFAULT_MAX_CONSECUTIVE_FAILURES = exports.DEFAULT_MAX_RETRIES = exports.handleWhen = exports.handleAll = exports.ExponentialBackoff = exports.ConstantBackoff = exports.CircuitState = exports.CockatielEventEmitter = exports.BrokenCircuitError = void 0;
const cockatiel_1 = require("cockatiel");
Object.defineProperty(exports, "BrokenCircuitError", { enumerable: true, get: function () { return cockatiel_1.BrokenCircuitError; } });
Object.defineProperty(exports, "CircuitState", { enumerable: true, get: function () { return cockatiel_1.CircuitState; } });
Object.defineProperty(exports, "CockatielEventEmitter", { enumerable: true, get: function () { return cockatiel_1.EventEmitter; } });
Object.defineProperty(exports, "ExponentialBackoff", { enumerable: true, get: function () { return cockatiel_1.ExponentialBackoff; } });

@@ -12,2 +13,13 @@ Object.defineProperty(exports, "ConstantBackoff", { enumerable: true, get: function () { return cockatiel_1.ConstantBackoff; } });

/**
* Availability statuses that the service can be in.
*
* Used to keep track of whether the `onAvailable` event should be fired.
*/
const AVAILABILITY_STATUSES = {
Available: 'available',
Degraded: 'degraded',
Unavailable: 'unavailable',
Unknown: 'unknown',
};
/**
* The maximum number of times that a failing service should be re-run before

@@ -115,2 +127,3 @@ * giving up.

const { maxRetries = exports.DEFAULT_MAX_RETRIES, retryFilterPolicy = cockatiel_1.handleAll, maxConsecutiveFailures = exports.DEFAULT_MAX_CONSECUTIVE_FAILURES, circuitBreakDuration = exports.DEFAULT_CIRCUIT_BREAK_DURATION, degradedThreshold = exports.DEFAULT_DEGRADED_THRESHOLD, backoff = new cockatiel_1.ExponentialBackoff(), } = options;
let availabilityStatus = AVAILABILITY_STATUSES.Unknown;
const retryPolicy = (0, cockatiel_1.retry)(retryFilterPolicy, {

@@ -125,2 +138,3 @@ // Note that although the option here is called "max attempts", it's really

const onRetry = retryPolicy.onRetry.bind(retryPolicy);
const consecutiveBreaker = new cockatiel_1.ConsecutiveBreaker(maxConsecutiveFailures);
const circuitBreakerPolicy = (0, cockatiel_1.circuitBreaker)((0, cockatiel_1.handleWhen)(isServiceFailure), {

@@ -134,3 +148,3 @@ // While the circuit is open, any additional invocations of the service

halfOpenAfter: circuitBreakDuration,
breaker: new cockatiel_1.ConsecutiveBreaker(maxConsecutiveFailures),
breaker: consecutiveBreaker,
});

@@ -141,6 +155,13 @@ let internalCircuitState = getInternalCircuitState(circuitBreakerPolicy.state);

});
circuitBreakerPolicy.onBreak(() => {
availabilityStatus = AVAILABILITY_STATUSES.Unavailable;
});
const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);
const onDegradedEventEmitter = new cockatiel_1.EventEmitter();
const onDegraded = onDegradedEventEmitter.addListener;
const onAvailableEventEmitter = new cockatiel_1.EventEmitter();
const onAvailable = onAvailableEventEmitter.addListener;
retryPolicy.onGiveUp((data) => {
if (circuitBreakerPolicy.state === cockatiel_1.CircuitState.Closed) {
availabilityStatus = AVAILABILITY_STATUSES.Degraded;
onDegradedEventEmitter.emit(data);

@@ -150,10 +171,34 @@ }

retryPolicy.onSuccess(({ duration }) => {
if (circuitBreakerPolicy.state === cockatiel_1.CircuitState.Closed &&
duration > degradedThreshold) {
onDegradedEventEmitter.emit();
if (circuitBreakerPolicy.state === cockatiel_1.CircuitState.Closed) {
if (duration > degradedThreshold) {
availabilityStatus = AVAILABILITY_STATUSES.Degraded;
onDegradedEventEmitter.emit();
}
else if (availabilityStatus !== AVAILABILITY_STATUSES.Available) {
availabilityStatus = AVAILABILITY_STATUSES.Available;
onAvailableEventEmitter.emit();
}
}
});
const onDegraded = onDegradedEventEmitter.addListener;
// Every time the retry policy makes an attempt, it executes the circuit
// breaker policy, which executes the service.
//
// Calling:
//
// policy.execute(() => {
// // do what the service does
// })
//
// is equivalent to:
//
// retryPolicy.execute(() => {
// circuitBreakerPolicy.execute(() => {
// // do what the service does
// });
// });
//
// So if the retry policy succeeds or fails, it is because the circuit breaker
// policy succeeded or failed. And if there are any event listeners registered
// on the retry policy, by the time they are called, the state of the circuit
// breaker will have already changed.
const policy = (0, cockatiel_1.wrap)(retryPolicy, circuitBreakerPolicy);

@@ -166,2 +211,16 @@ const getRemainingCircuitOpenDuration = () => {

};
const getCircuitState = () => {
return circuitBreakerPolicy.state;
};
const reset = () => {
// Set the state of the policy to "isolated" regardless of its current state
const { dispose } = circuitBreakerPolicy.isolate();
// Reset the state to "closed"
dispose();
// Reset the counter on the breaker as well
consecutiveBreaker.success();
// Re-initialize the availability status so that if the service is executed
// successfully, onAvailable listeners will be called again
availabilityStatus = AVAILABILITY_STATUSES.Unknown;
};
return {

@@ -171,6 +230,9 @@ ...policy,

circuitBreakDuration,
getCircuitState,
getRemainingCircuitOpenDuration,
reset,
retryPolicy,
onBreak,
onDegraded,
onAvailable,
onRetry,

@@ -177,0 +239,0 @@ };

@@ -1,5 +0,5 @@

import { BrokenCircuitError, CircuitState, ExponentialBackoff, ConstantBackoff, handleAll, handleWhen } from "cockatiel";
import { BrokenCircuitError, CircuitState, EventEmitter as CockatielEventEmitter, ExponentialBackoff, ConstantBackoff, handleAll, handleWhen } from "cockatiel";
import type { CircuitBreakerPolicy, Event as CockatielEvent, FailureReason, IBackoffFactory, IPolicy, Policy, RetryPolicy } from "cockatiel";
export { BrokenCircuitError, CircuitState, ConstantBackoff, ExponentialBackoff, handleAll, handleWhen, };
export type { CockatielEvent };
export { BrokenCircuitError, CockatielEventEmitter, CircuitState, ConstantBackoff, ExponentialBackoff, handleAll, handleWhen, };
export type { CockatielEvent, FailureReason as CockatielFailureReason };
/**

@@ -58,2 +58,6 @@ * The options for `createServicePolicy`.

/**
* @returns The state of the underlying circuit.
*/
getCircuitState: () => CircuitState;
/**
* If the circuit is open and ongoing requests are paused, returns the number

@@ -65,2 +69,7 @@ * of milliseconds before the requests will be attempted again. If the circuit

/**
* Resets the internal circuit breaker policy (if it is open, it will now be
* closed).
*/
reset: () => void;
/**
* The Cockatiel retry policy that the service policy uses internally.

@@ -83,2 +92,8 @@ */

/**
* A function which is called when the service succeeds for the first time,
* or when the service fails enough times to cause the circuit to break and
* then recovers.
*/
onAvailable: CockatielEvent<void>;
/**
* A function which will be called by the retry policy each time the service

@@ -85,0 +100,0 @@ * fails and the policy kicks off a timer to re-run the service. This is

@@ -1,5 +0,5 @@

import { BrokenCircuitError, CircuitState, ExponentialBackoff, ConstantBackoff, handleAll, handleWhen } from "cockatiel";
import { BrokenCircuitError, CircuitState, EventEmitter as CockatielEventEmitter, ExponentialBackoff, ConstantBackoff, handleAll, handleWhen } from "cockatiel";
import type { CircuitBreakerPolicy, Event as CockatielEvent, FailureReason, IBackoffFactory, IPolicy, Policy, RetryPolicy } from "cockatiel";
export { BrokenCircuitError, CircuitState, ConstantBackoff, ExponentialBackoff, handleAll, handleWhen, };
export type { CockatielEvent };
export { BrokenCircuitError, CockatielEventEmitter, CircuitState, ConstantBackoff, ExponentialBackoff, handleAll, handleWhen, };
export type { CockatielEvent, FailureReason as CockatielFailureReason };
/**

@@ -58,2 +58,6 @@ * The options for `createServicePolicy`.

/**
* @returns The state of the underlying circuit.
*/
getCircuitState: () => CircuitState;
/**
* If the circuit is open and ongoing requests are paused, returns the number

@@ -65,2 +69,7 @@ * of milliseconds before the requests will be attempted again. If the circuit

/**
* Resets the internal circuit breaker policy (if it is open, it will now be
* closed).
*/
reset: () => void;
/**
* The Cockatiel retry policy that the service policy uses internally.

@@ -83,2 +92,8 @@ */

/**
* A function which is called when the service succeeds for the first time,
* or when the service fails enough times to cause the circuit to break and
* then recovers.
*/
onAvailable: CockatielEvent<void>;
/**
* A function which will be called by the retry policy each time the service

@@ -85,0 +100,0 @@ * fails and the policy kicks off a timer to re-run the service. This is

import { BrokenCircuitError, CircuitState, EventEmitter as CockatielEventEmitter, ConsecutiveBreaker, ExponentialBackoff, ConstantBackoff, circuitBreaker, handleAll, handleWhen, retry, wrap } from "cockatiel";
export { BrokenCircuitError, CircuitState, ConstantBackoff, ExponentialBackoff, handleAll, handleWhen };
export { BrokenCircuitError, CockatielEventEmitter, CircuitState, ConstantBackoff, ExponentialBackoff, handleAll, handleWhen };
/**
* Availability statuses that the service can be in.
*
* Used to keep track of whether the `onAvailable` event should be fired.
*/
const AVAILABILITY_STATUSES = {
Available: 'available',
Degraded: 'degraded',
Unavailable: 'unavailable',
Unknown: 'unknown',
};
/**
* The maximum number of times that a failing service should be re-run before

@@ -106,2 +117,3 @@ * giving up.

const { maxRetries = DEFAULT_MAX_RETRIES, retryFilterPolicy = handleAll, maxConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES, circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION, degradedThreshold = DEFAULT_DEGRADED_THRESHOLD, backoff = new ExponentialBackoff(), } = options;
let availabilityStatus = AVAILABILITY_STATUSES.Unknown;
const retryPolicy = retry(retryFilterPolicy, {

@@ -116,2 +128,3 @@ // Note that although the option here is called "max attempts", it's really

const onRetry = retryPolicy.onRetry.bind(retryPolicy);
const consecutiveBreaker = new ConsecutiveBreaker(maxConsecutiveFailures);
const circuitBreakerPolicy = circuitBreaker(handleWhen(isServiceFailure), {

@@ -125,3 +138,3 @@ // While the circuit is open, any additional invocations of the service

halfOpenAfter: circuitBreakDuration,
breaker: new ConsecutiveBreaker(maxConsecutiveFailures),
breaker: consecutiveBreaker,
});

@@ -132,6 +145,13 @@ let internalCircuitState = getInternalCircuitState(circuitBreakerPolicy.state);

});
circuitBreakerPolicy.onBreak(() => {
availabilityStatus = AVAILABILITY_STATUSES.Unavailable;
});
const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);
const onDegradedEventEmitter = new CockatielEventEmitter();
const onDegraded = onDegradedEventEmitter.addListener;
const onAvailableEventEmitter = new CockatielEventEmitter();
const onAvailable = onAvailableEventEmitter.addListener;
retryPolicy.onGiveUp((data) => {
if (circuitBreakerPolicy.state === CircuitState.Closed) {
availabilityStatus = AVAILABILITY_STATUSES.Degraded;
onDegradedEventEmitter.emit(data);

@@ -141,10 +161,34 @@ }

retryPolicy.onSuccess(({ duration }) => {
if (circuitBreakerPolicy.state === CircuitState.Closed &&
duration > degradedThreshold) {
onDegradedEventEmitter.emit();
if (circuitBreakerPolicy.state === CircuitState.Closed) {
if (duration > degradedThreshold) {
availabilityStatus = AVAILABILITY_STATUSES.Degraded;
onDegradedEventEmitter.emit();
}
else if (availabilityStatus !== AVAILABILITY_STATUSES.Available) {
availabilityStatus = AVAILABILITY_STATUSES.Available;
onAvailableEventEmitter.emit();
}
}
});
const onDegraded = onDegradedEventEmitter.addListener;
// Every time the retry policy makes an attempt, it executes the circuit
// breaker policy, which executes the service.
//
// Calling:
//
// policy.execute(() => {
// // do what the service does
// })
//
// is equivalent to:
//
// retryPolicy.execute(() => {
// circuitBreakerPolicy.execute(() => {
// // do what the service does
// });
// });
//
// So if the retry policy succeeds or fails, it is because the circuit breaker
// policy succeeded or failed. And if there are any event listeners registered
// on the retry policy, by the time they are called, the state of the circuit
// breaker will have already changed.
const policy = wrap(retryPolicy, circuitBreakerPolicy);

@@ -157,2 +201,16 @@ const getRemainingCircuitOpenDuration = () => {

};
const getCircuitState = () => {
return circuitBreakerPolicy.state;
};
const reset = () => {
// Set the state of the policy to "isolated" regardless of its current state
const { dispose } = circuitBreakerPolicy.isolate();
// Reset the state to "closed"
dispose();
// Reset the counter on the breaker as well
consecutiveBreaker.success();
// Re-initialize the availability status so that if the service is executed
// successfully, onAvailable listeners will be called again
availabilityStatus = AVAILABILITY_STATUSES.Unknown;
};
return {

@@ -162,6 +220,9 @@ ...policy,

circuitBreakDuration,
getCircuitState,
getRemainingCircuitOpenDuration,
reset,
retryPolicy,
onBreak,
onDegraded,
onAvailable,
onRetry,

@@ -168,0 +229,0 @@ };

+3
-2

@@ -17,7 +17,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.fractionBN = exports.fetchWithErrorHandling = exports.convertHexToDecimal = exports.BNToHex = exports.NETWORKS_BYPASSING_VALIDATION = exports.DAYS = exports.DAY = exports.HOURS = exports.HOUR = exports.MINUTES = exports.MINUTE = exports.SECONDS = exports.SECOND = exports.CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP = exports.ApprovalType = exports.ORIGIN_METAMASK = exports.NFT_API_TIMEOUT = exports.NFT_API_VERSION = exports.NFT_API_BASE_URL = exports.OPENSEA_PROXY_URL = exports.BUILT_IN_NETWORKS = exports.BUILT_IN_CUSTOM_NETWORKS_RPC = exports.TESTNET_TICKER_SYMBOLS = exports.ASSET_TYPES = exports.GWEI = exports.ERC1155_TOKEN_RECEIVER_INTERFACE_ID = exports.ERC1155_METADATA_URI_INTERFACE_ID = exports.ERC1155_INTERFACE_ID = exports.ERC721_ENUMERABLE_INTERFACE_ID = exports.ERC721_METADATA_INTERFACE_ID = exports.ERC721_INTERFACE_ID = exports.ERC20 = exports.ERC1155 = exports.ERC721 = exports.MAX_SAFE_CHAIN_ID = exports.GANACHE_CHAIN_ID = exports.IPFS_DEFAULT_GATEWAY_URL = exports.FALL_BACK_VS_CURRENCY = exports.RPC = exports.handleWhen = exports.handleAll = exports.createServicePolicy = exports.ExponentialBackoff = exports.DEFAULT_MAX_RETRIES = exports.DEFAULT_MAX_CONSECUTIVE_FAILURES = exports.DEFAULT_DEGRADED_THRESHOLD = exports.DEFAULT_CIRCUIT_BREAK_DURATION = exports.ConstantBackoff = exports.CircuitState = exports.BrokenCircuitError = void 0;
exports.isEqualCaseInsensitive = exports.weiHexToGweiDec = exports.toHex = exports.toChecksumHexAddress = exports.timeoutFetch = exports.successfulFetch = exports.safelyExecuteWithTimeout = exports.safelyExecute = exports.query = exports.normalizeEnsName = exports.isValidHexAddress = exports.isValidJson = exports.isSmartContractCode = exports.isSafeDynamicKey = exports.isSafeChainId = exports.isPlainObject = exports.isNonEmptyArray = exports.HttpError = exports.hexToText = exports.hexToBN = exports.handleFetch = exports.gweiDecToWEIBN = exports.getBuyURL = exports.fromHex = void 0;
exports.fetchWithErrorHandling = exports.convertHexToDecimal = exports.BNToHex = exports.NETWORKS_BYPASSING_VALIDATION = exports.DAYS = exports.DAY = exports.HOURS = exports.HOUR = exports.MINUTES = exports.MINUTE = exports.SECONDS = exports.SECOND = exports.CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP = exports.ApprovalType = exports.ORIGIN_METAMASK = exports.NFT_API_TIMEOUT = exports.NFT_API_VERSION = exports.NFT_API_BASE_URL = exports.OPENSEA_PROXY_URL = exports.BUILT_IN_NETWORKS = exports.BUILT_IN_CUSTOM_NETWORKS_RPC = exports.TESTNET_TICKER_SYMBOLS = exports.ASSET_TYPES = exports.GWEI = exports.ERC1155_TOKEN_RECEIVER_INTERFACE_ID = exports.ERC1155_METADATA_URI_INTERFACE_ID = exports.ERC1155_INTERFACE_ID = exports.ERC721_ENUMERABLE_INTERFACE_ID = exports.ERC721_METADATA_INTERFACE_ID = exports.ERC721_INTERFACE_ID = exports.ERC20 = exports.ERC1155 = exports.ERC721 = exports.MAX_SAFE_CHAIN_ID = exports.GANACHE_CHAIN_ID = exports.IPFS_DEFAULT_GATEWAY_URL = exports.FALL_BACK_VS_CURRENCY = exports.RPC = exports.handleWhen = exports.handleAll = exports.createServicePolicy = exports.ExponentialBackoff = exports.DEFAULT_MAX_RETRIES = exports.DEFAULT_MAX_CONSECUTIVE_FAILURES = exports.DEFAULT_DEGRADED_THRESHOLD = exports.DEFAULT_CIRCUIT_BREAK_DURATION = exports.ConstantBackoff = exports.CockatielEventEmitter = exports.CircuitState = exports.BrokenCircuitError = void 0;
exports.isEqualCaseInsensitive = exports.weiHexToGweiDec = exports.toHex = exports.toChecksumHexAddress = exports.timeoutFetch = exports.successfulFetch = exports.safelyExecuteWithTimeout = exports.safelyExecute = exports.query = exports.normalizeEnsName = exports.isValidHexAddress = exports.isValidJson = exports.isSmartContractCode = exports.isSafeDynamicKey = exports.isSafeChainId = exports.isPlainObject = exports.isNonEmptyArray = exports.HttpError = exports.hexToText = exports.hexToBN = exports.handleFetch = exports.gweiDecToWEIBN = exports.getBuyURL = exports.fromHex = exports.fractionBN = void 0;
var create_service_policy_1 = require("./create-service-policy.cjs");
Object.defineProperty(exports, "BrokenCircuitError", { enumerable: true, get: function () { return create_service_policy_1.BrokenCircuitError; } });
Object.defineProperty(exports, "CircuitState", { enumerable: true, get: function () { return create_service_policy_1.CircuitState; } });
Object.defineProperty(exports, "CockatielEventEmitter", { enumerable: true, get: function () { return create_service_policy_1.CockatielEventEmitter; } });
Object.defineProperty(exports, "ConstantBackoff", { enumerable: true, get: function () { return create_service_policy_1.ConstantBackoff; } });

@@ -24,0 +25,0 @@ Object.defineProperty(exports, "DEFAULT_CIRCUIT_BREAK_DURATION", { enumerable: true, get: function () { return create_service_policy_1.DEFAULT_CIRCUIT_BREAK_DURATION; } });

@@ -1,3 +0,3 @@

export { BrokenCircuitError, CircuitState, ConstantBackoff, DEFAULT_CIRCUIT_BREAK_DURATION, DEFAULT_DEGRADED_THRESHOLD, DEFAULT_MAX_CONSECUTIVE_FAILURES, DEFAULT_MAX_RETRIES, ExponentialBackoff, createServicePolicy, handleAll, handleWhen, } from "./create-service-policy.cjs";
export type { CockatielEvent, CreateServicePolicyOptions, ServicePolicy, } from "./create-service-policy.cjs";
export { BrokenCircuitError, CircuitState, CockatielEventEmitter, ConstantBackoff, DEFAULT_CIRCUIT_BREAK_DURATION, DEFAULT_DEGRADED_THRESHOLD, DEFAULT_MAX_CONSECUTIVE_FAILURES, DEFAULT_MAX_RETRIES, ExponentialBackoff, createServicePolicy, handleAll, handleWhen, } from "./create-service-policy.cjs";
export type { CockatielEvent, CreateServicePolicyOptions, CockatielFailureReason, ServicePolicy, } from "./create-service-policy.cjs";
export { RPC, FALL_BACK_VS_CURRENCY, IPFS_DEFAULT_GATEWAY_URL, GANACHE_CHAIN_ID, MAX_SAFE_CHAIN_ID, ERC721, ERC1155, ERC20, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC1155_INTERFACE_ID, ERC1155_METADATA_URI_INTERFACE_ID, ERC1155_TOKEN_RECEIVER_INTERFACE_ID, GWEI, ASSET_TYPES, TESTNET_TICKER_SYMBOLS, BUILT_IN_CUSTOM_NETWORKS_RPC, BUILT_IN_NETWORKS, OPENSEA_PROXY_URL, NFT_API_BASE_URL, NFT_API_VERSION, NFT_API_TIMEOUT, ORIGIN_METAMASK, ApprovalType, CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP, SECOND, SECONDS, MINUTE, MINUTES, HOUR, HOURS, DAY, DAYS, NETWORKS_BYPASSING_VALIDATION, } from "./constants.cjs";

@@ -4,0 +4,0 @@ export type { NonEmptyArray } from "./util.cjs";

@@ -1,3 +0,3 @@

export { BrokenCircuitError, CircuitState, ConstantBackoff, DEFAULT_CIRCUIT_BREAK_DURATION, DEFAULT_DEGRADED_THRESHOLD, DEFAULT_MAX_CONSECUTIVE_FAILURES, DEFAULT_MAX_RETRIES, ExponentialBackoff, createServicePolicy, handleAll, handleWhen, } from "./create-service-policy.mjs";
export type { CockatielEvent, CreateServicePolicyOptions, ServicePolicy, } from "./create-service-policy.mjs";
export { BrokenCircuitError, CircuitState, CockatielEventEmitter, ConstantBackoff, DEFAULT_CIRCUIT_BREAK_DURATION, DEFAULT_DEGRADED_THRESHOLD, DEFAULT_MAX_CONSECUTIVE_FAILURES, DEFAULT_MAX_RETRIES, ExponentialBackoff, createServicePolicy, handleAll, handleWhen, } from "./create-service-policy.mjs";
export type { CockatielEvent, CreateServicePolicyOptions, CockatielFailureReason, ServicePolicy, } from "./create-service-policy.mjs";
export { RPC, FALL_BACK_VS_CURRENCY, IPFS_DEFAULT_GATEWAY_URL, GANACHE_CHAIN_ID, MAX_SAFE_CHAIN_ID, ERC721, ERC1155, ERC20, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC1155_INTERFACE_ID, ERC1155_METADATA_URI_INTERFACE_ID, ERC1155_TOKEN_RECEIVER_INTERFACE_ID, GWEI, ASSET_TYPES, TESTNET_TICKER_SYMBOLS, BUILT_IN_CUSTOM_NETWORKS_RPC, BUILT_IN_NETWORKS, OPENSEA_PROXY_URL, NFT_API_BASE_URL, NFT_API_VERSION, NFT_API_TIMEOUT, ORIGIN_METAMASK, ApprovalType, CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP, SECOND, SECONDS, MINUTE, MINUTES, HOUR, HOURS, DAY, DAYS, NETWORKS_BYPASSING_VALIDATION, } from "./constants.mjs";

@@ -4,0 +4,0 @@ export type { NonEmptyArray } from "./util.mjs";

@@ -1,2 +0,2 @@

export { BrokenCircuitError, CircuitState, ConstantBackoff, DEFAULT_CIRCUIT_BREAK_DURATION, DEFAULT_DEGRADED_THRESHOLD, DEFAULT_MAX_CONSECUTIVE_FAILURES, DEFAULT_MAX_RETRIES, ExponentialBackoff, createServicePolicy, handleAll, handleWhen } from "./create-service-policy.mjs";
export { BrokenCircuitError, CircuitState, CockatielEventEmitter, ConstantBackoff, DEFAULT_CIRCUIT_BREAK_DURATION, DEFAULT_DEGRADED_THRESHOLD, DEFAULT_MAX_CONSECUTIVE_FAILURES, DEFAULT_MAX_RETRIES, ExponentialBackoff, createServicePolicy, handleAll, handleWhen } from "./create-service-policy.mjs";
export { RPC, FALL_BACK_VS_CURRENCY, IPFS_DEFAULT_GATEWAY_URL, GANACHE_CHAIN_ID, MAX_SAFE_CHAIN_ID, ERC721, ERC1155, ERC20, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC1155_INTERFACE_ID, ERC1155_METADATA_URI_INTERFACE_ID, ERC1155_TOKEN_RECEIVER_INTERFACE_ID, GWEI, ASSET_TYPES, TESTNET_TICKER_SYMBOLS, BUILT_IN_CUSTOM_NETWORKS_RPC, BUILT_IN_NETWORKS, OPENSEA_PROXY_URL, NFT_API_BASE_URL, NFT_API_VERSION, NFT_API_TIMEOUT, ORIGIN_METAMASK, ApprovalType, CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP, SECOND, SECONDS, MINUTE, MINUTES, HOUR, HOURS, DAY, DAYS, NETWORKS_BYPASSING_VALIDATION } from "./constants.mjs";

@@ -3,0 +3,0 @@ export { BNToHex, convertHexToDecimal, fetchWithErrorHandling, fractionBN, fromHex, getBuyURL, gweiDecToWEIBN, handleFetch, hexToBN, hexToText, HttpError, isNonEmptyArray, isPlainObject, isSafeChainId, isSafeDynamicKey, isSmartContractCode, isValidJson, isValidHexAddress, normalizeEnsName, query, safelyExecute, safelyExecuteWithTimeout, successfulFetch, timeoutFetch, toChecksumHexAddress, toHex, weiHexToGweiDec, isEqualCaseInsensitive } from "./util.mjs";

@@ -6,5 +6,6 @@ import { ParsedMessage } from "@spruceid/siwe-parser";

* Sign-In With Ethereum (SIWE)(EIP-4361) message with request metadata
* @property {string} from - Subject account address
* @property {string} origin - The RFC 3986 originating authority of the signing request, including scheme
* @property {ParsedMessage} siwe - The data parsed from the message
*
* @property from - Subject account address
* @property origin - The RFC 3986 originating authority of the signing request, including scheme
* @property siwe - The data parsed from the message
*/

@@ -11,0 +12,0 @@ export interface WrappedSIWERequest {

@@ -6,5 +6,6 @@ import { ParsedMessage } from "@spruceid/siwe-parser";

* Sign-In With Ethereum (SIWE)(EIP-4361) message with request metadata
* @property {string} from - Subject account address
* @property {string} origin - The RFC 3986 originating authority of the signing request, including scheme
* @property {ParsedMessage} siwe - The data parsed from the message
*
* @property from - Subject account address
* @property origin - The RFC 3986 originating authority of the signing request, including scheme
* @property siwe - The data parsed from the message
*/

@@ -11,0 +12,0 @@ export interface WrappedSIWERequest {

@@ -87,16 +87,16 @@ "use strict";

exports.ChainId = {
[BuiltInNetworkName.Mainnet]: '0x1',
[BuiltInNetworkName.Goerli]: '0x5',
[BuiltInNetworkName.Sepolia]: '0xaa36a7',
[BuiltInNetworkName.Aurora]: '0x4e454152',
[BuiltInNetworkName.LineaGoerli]: '0xe704',
[BuiltInNetworkName.LineaSepolia]: '0xe705',
[BuiltInNetworkName.LineaMainnet]: '0xe708',
[BuiltInNetworkName.MegaETHTestnet]: '0x18c6',
[BuiltInNetworkName.MonadTestnet]: '0x279f',
[BuiltInNetworkName.BaseMainnet]: '0x2105',
[BuiltInNetworkName.ArbitrumOne]: '0xa4b1',
[BuiltInNetworkName.BscMainnet]: '0x38',
[BuiltInNetworkName.OptimismMainnet]: '0xa',
[BuiltInNetworkName.PolygonMainnet]: '0x89',
[BuiltInNetworkName.Mainnet]: '0x1', // toHex(1)
[BuiltInNetworkName.Goerli]: '0x5', // toHex(5)
[BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111)
[BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)
[BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140)
[BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)
[BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)
[BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)
[BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)
[BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453)
[BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161)
[BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56)
[BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)
[BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)
[BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)

@@ -103,0 +103,0 @@ };

@@ -195,2 +195,3 @@ /**

* Thrown errors will not be caught, but the trace will still be recorded.
*
* @param context - The context in which the operation is running.

@@ -197,0 +198,0 @@ */

@@ -195,2 +195,3 @@ /**

* Thrown errors will not be caught, but the trace will still be recorded.
*
* @param context - The context in which the operation is running.

@@ -197,0 +198,0 @@ */

@@ -82,16 +82,16 @@ /**

export const ChainId = {
[BuiltInNetworkName.Mainnet]: '0x1',
[BuiltInNetworkName.Goerli]: '0x5',
[BuiltInNetworkName.Sepolia]: '0xaa36a7',
[BuiltInNetworkName.Aurora]: '0x4e454152',
[BuiltInNetworkName.LineaGoerli]: '0xe704',
[BuiltInNetworkName.LineaSepolia]: '0xe705',
[BuiltInNetworkName.LineaMainnet]: '0xe708',
[BuiltInNetworkName.MegaETHTestnet]: '0x18c6',
[BuiltInNetworkName.MonadTestnet]: '0x279f',
[BuiltInNetworkName.BaseMainnet]: '0x2105',
[BuiltInNetworkName.ArbitrumOne]: '0xa4b1',
[BuiltInNetworkName.BscMainnet]: '0x38',
[BuiltInNetworkName.OptimismMainnet]: '0xa',
[BuiltInNetworkName.PolygonMainnet]: '0x89',
[BuiltInNetworkName.Mainnet]: '0x1', // toHex(1)
[BuiltInNetworkName.Goerli]: '0x5', // toHex(5)
[BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111)
[BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)
[BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140)
[BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)
[BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)
[BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)
[BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)
[BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453)
[BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161)
[BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56)
[BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)
[BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)
[BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)

@@ -98,0 +98,0 @@ };

@@ -56,4 +56,2 @@ "use strict";

*/
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/naming-convention
function BNToHex(inputBn) {

@@ -128,4 +126,2 @@ return (0, utils_1.add0x)(inputBn.toString(16));

case '1':
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
return `https://buy.coinbase.com/?code=9ec56d01-7e81-5017-930c-513daa27bb6a&amount=${amount}&address=${address}&crypto_currency=ETH`;

@@ -510,4 +506,2 @@ case '5':

*/
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/naming-convention
function isNonEmptyArray(value) {

@@ -514,0 +508,0 @@ return Array.isArray(value) && value.length > 0;

@@ -58,4 +58,2 @@ function $importDefault(module) {

*/
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/naming-convention
export function BNToHex(inputBn) {

@@ -126,4 +124,2 @@ return add0x(inputBn.toString(16));

case '1':
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
return `https://buy.coinbase.com/?code=9ec56d01-7e81-5017-930c-513daa27bb6a&amount=${amount}&address=${address}&crypto_currency=ETH`;

@@ -491,4 +487,2 @@ case '5':

*/
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/naming-convention
export function isNonEmptyArray(value) {

@@ -495,0 +489,0 @@ return Array.isArray(value) && value.length > 0;

{
"name": "@metamask/controller-utils",
"version": "11.15.0",
"version": "11.16.0",
"description": "Data and convenience functions shared by multiple packages",

@@ -39,2 +39,3 @@ "keywords": [

"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
"build:docs": "typedoc",

@@ -66,2 +67,3 @@ "changelog:update": "../../scripts/update-changelog.sh @metamask/controller-utils",

"@metamask/auto-changelog": "^3.4.4",
"@ts-bridge/cli": "^0.6.4",
"@types/jest": "^27.4.1",

@@ -77,3 +79,3 @@ "@types/lodash": "^4.14.191",

"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.2.2"
"typescript": "~5.3.3"
},

@@ -80,0 +82,0 @@ "peerDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet