Socket
Socket
Sign inDemoInstall

@metamask/controller-utils

Package Overview
Dependencies
Maintainers
9
Versions
36
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 3.4.0 to 4.0.0

26

CHANGELOG.md

@@ -9,2 +9,25 @@ # Changelog

## [4.0.0]
### Added
- Add constants `BuiltInNetwork` and `ChainId` ([#1354](https://github.com/MetaMask/core/pull/1354))
- Add Aurora network to the `ChainId` constant ([#1327](https://github.com/MetaMask/core/pull/1327))
- Add `InfuraNetworkType` enum ([#1264](https://github.com/MetaMask/core/pull/1264))
### Changed
- **BREAKING:** Bump to Node 16 ([#1262](https://github.com/MetaMask/core/pull/1262))
- **BREAKING:** The `isSafeChainId` chain ID parameter is now type `Hex` rather than `number` ([#1367](https://github.com/MetaMask/core/pull/1367))
- **BREAKING:** The `ChainId` enum and the `GANACHE_CHAIN_ID` constant are now formatted as 0x-prefixed hex strings rather than as decimal strings. ([#1367](https://github.com/MetaMask/core/pull/1367))
- The `query` function has improved type checks for the `ethQuery` argument ([#1266](https://github.com/MetaMask/core/pull/1266))
- This type change could be breaking, but only if you were passing in an invalid `ethQuery` parameter. In that circumstance this would have thrown an error at runtime anyway. Effectively this should be non-breaking for any usage that isn't already broken.
- Bump @metamask/utils from 5.0.1 to 5.0.2 ([#1271](https://github.com/MetaMask/core/pull/1271))
### Removed
- **BREAKING:** Remove `Json` type ([#1370](https://github.com/MetaMask/core/pull/1370))
- **BREAKING:** Remove `NetworksChainId` constant ([#1354](https://github.com/MetaMask/core/pull/1354))
- Use the new `ChainId` constant or the pre-existing `NetworkId` constant instead
- **BREAKING:** Remove localhost network ([#1313](https://github.com/MetaMask/core/pull/1313))
- Remove the entry for localhost from `BUILT_IN_NETWORKS`, `NetworkType`, `ChainId`, and `NetworksTicker`
- **BREAKING:** Remove `hasProperty` function ([#1275](https://github.com/MetaMask/core/pull/1275))
- Use the `hasProperty` function from `@metamask/utils` instead
## [3.4.0]

@@ -90,3 +113,4 @@ ### Added

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@3.4.0...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@4.0.0...HEAD
[4.0.0]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@3.4.0...@metamask/controller-utils@4.0.0
[3.4.0]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@3.3.0...@metamask/controller-utils@3.4.0

@@ -93,0 +117,0 @@ [3.3.0]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@3.2.0...@metamask/controller-utils@3.3.0

15

dist/constants.d.ts

@@ -1,6 +0,6 @@

import { NetworkType, NetworksTicker, NetworksChainId, NetworkId } from './types';
import { NetworkType, NetworksTicker, NetworkId } from './types';
export declare const RPC = "rpc";
export declare const FALL_BACK_VS_CURRENCY = "ETH";
export declare const IPFS_DEFAULT_GATEWAY_URL = "https://cloudflare-ipfs.com/ipfs/";
export declare const GANACHE_CHAIN_ID = "1337";
export declare const GANACHE_CHAIN_ID = "0x539";
/**

@@ -36,3 +36,3 @@ * The largest possible chain ID we can handle.

readonly goerli: {
readonly chainId: NetworksChainId.goerli;
readonly chainId: "0x5";
readonly ticker: NetworksTicker.goerli;

@@ -44,3 +44,3 @@ readonly rpcPrefs: {

readonly sepolia: {
readonly chainId: NetworksChainId.sepolia;
readonly chainId: "0xaa36a7";
readonly ticker: NetworksTicker.sepolia;

@@ -52,3 +52,3 @@ readonly rpcPrefs: {

readonly mainnet: {
readonly chainId: NetworksChainId.mainnet;
readonly chainId: "0x1";
readonly ticker: NetworksTicker.mainnet;

@@ -59,7 +59,2 @@ readonly rpcPrefs: {

};
readonly localhost: {
readonly chainId: NetworksChainId.localhost;
readonly blockExplorerUrl: undefined;
readonly rpcPrefs: undefined;
};
readonly rpc: {

@@ -66,0 +61,0 @@ readonly chainId: undefined;

@@ -9,3 +9,4 @@ "use strict";

// NETWORKS ID
exports.GANACHE_CHAIN_ID = '1337';
// `toHex` not invoked to avoid cyclic dependency
exports.GANACHE_CHAIN_ID = '0x539'; // toHex(1337)
/**

@@ -46,3 +47,3 @@ * The largest possible chain ID we can handle.

[types_1.NetworkType.goerli]: {
chainId: types_1.NetworksChainId.goerli,
chainId: types_1.ChainId.goerli,
ticker: types_1.NetworksTicker.goerli,

@@ -54,3 +55,3 @@ rpcPrefs: {

[types_1.NetworkType.sepolia]: {
chainId: types_1.NetworksChainId.sepolia,
chainId: types_1.ChainId.sepolia,
ticker: types_1.NetworksTicker.sepolia,

@@ -62,3 +63,3 @@ rpcPrefs: {

[types_1.NetworkType.mainnet]: {
chainId: types_1.NetworksChainId.mainnet,
chainId: types_1.ChainId.mainnet,
ticker: types_1.NetworksTicker.mainnet,

@@ -69,7 +70,2 @@ rpcPrefs: {

},
[types_1.NetworkType.localhost]: {
chainId: types_1.NetworksChainId.localhost,
blockExplorerUrl: undefined,
rpcPrefs: undefined,
},
[types_1.NetworkType.rpc]: {

@@ -76,0 +72,0 @@ chainId: undefined,

/**
* Human-readable network name
* The names of built-in Infura networks
*/
export declare enum NetworkType {
localhost = "localhost",
mainnet = "mainnet",
goerli = "goerli",
sepolia = "sepolia",
rpc = "rpc"
}
export declare const InfuraNetworkType: {
readonly mainnet: "mainnet";
readonly goerli: "goerli";
readonly sepolia: "sepolia";
};
export declare type InfuraNetworkType = typeof InfuraNetworkType[keyof typeof InfuraNetworkType];
/**
* The "network type"; either the name of a built-in network, or "rpc" for custom networks.
*/
export declare const NetworkType: {
readonly rpc: "rpc";
readonly mainnet: "mainnet";
readonly goerli: "goerli";
readonly sepolia: "sepolia";
};
export declare type NetworkType = typeof NetworkType[keyof typeof NetworkType];
/**
* A helper to determine whether a given input is NetworkType.

@@ -18,14 +27,34 @@ *

export declare function isNetworkType(val: any): val is NetworkType;
export declare enum NetworksChainId {
mainnet = "1",
goerli = "5",
sepolia = "11155111",
localhost = "",
rpc = ""
/**
* Names of networks built into the wallet.
*
* This includes both Infura and non-Infura networks.
*/
export declare enum BuiltInNetworkName {
Mainnet = "mainnet",
Goerli = "goerli",
Sepolia = "sepolia",
Aurora = "aurora"
}
export declare enum NetworkId {
mainnet = "1",
goerli = "5",
sepolia = "11155111"
}
/**
* Decimal string chain IDs of built-in networks, by name.
*
* `toHex` not invoked to avoid cyclic dependency
*/
export declare const ChainId: {
readonly mainnet: "0x1";
readonly goerli: "0x5";
readonly sepolia: "0xaa36a7";
readonly aurora: "0x4e454152";
};
export declare type ChainId = typeof ChainId[keyof typeof ChainId];
/**
* Decimal string network IDs of built-in Infura networks, by name.
*/
export declare const NetworkId: {
readonly mainnet: "1";
readonly goerli: "5";
readonly sepolia: "11155111";
};
export declare type NetworkId = typeof NetworkId[keyof typeof NetworkId];
export declare enum NetworksTicker {

@@ -35,8 +64,4 @@ mainnet = "ETH",

sepolia = "SepoliaETH",
localhost = "",
rpc = ""
}
export declare type Json = null | boolean | number | string | Json[] | {
[prop: string]: Json;
};
//# sourceMappingURL=types.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NetworksTicker = exports.NetworkId = exports.NetworksChainId = exports.isNetworkType = exports.NetworkType = void 0;
exports.NetworksTicker = exports.NetworkId = exports.ChainId = exports.BuiltInNetworkName = exports.isNetworkType = exports.NetworkType = exports.InfuraNetworkType = void 0;
/**
* Human-readable network name
* The names of built-in Infura networks
*/
var NetworkType;
(function (NetworkType) {
NetworkType["localhost"] = "localhost";
NetworkType["mainnet"] = "mainnet";
NetworkType["goerli"] = "goerli";
NetworkType["sepolia"] = "sepolia";
NetworkType["rpc"] = "rpc";
})(NetworkType = exports.NetworkType || (exports.NetworkType = {}));
exports.InfuraNetworkType = {
mainnet: 'mainnet',
goerli: 'goerli',
sepolia: 'sepolia',
};
/**
* The "network type"; either the name of a built-in network, or "rpc" for custom networks.
*/
exports.NetworkType = Object.assign(Object.assign({}, exports.InfuraNetworkType), { rpc: 'rpc' });
/**
* A helper to determine whether a given input is NetworkType.

@@ -22,19 +23,36 @@ *

function isNetworkType(val) {
return Object.values(NetworkType).includes(val);
return Object.values(exports.NetworkType).includes(val);
}
exports.isNetworkType = isNetworkType;
var NetworksChainId;
(function (NetworksChainId) {
NetworksChainId["mainnet"] = "1";
NetworksChainId["goerli"] = "5";
NetworksChainId["sepolia"] = "11155111";
NetworksChainId["localhost"] = "";
NetworksChainId["rpc"] = "";
})(NetworksChainId = exports.NetworksChainId || (exports.NetworksChainId = {}));
var NetworkId;
(function (NetworkId) {
NetworkId["mainnet"] = "1";
NetworkId["goerli"] = "5";
NetworkId["sepolia"] = "11155111";
})(NetworkId = exports.NetworkId || (exports.NetworkId = {}));
/**
* Names of networks built into the wallet.
*
* This includes both Infura and non-Infura networks.
*/
var BuiltInNetworkName;
(function (BuiltInNetworkName) {
BuiltInNetworkName["Mainnet"] = "mainnet";
BuiltInNetworkName["Goerli"] = "goerli";
BuiltInNetworkName["Sepolia"] = "sepolia";
BuiltInNetworkName["Aurora"] = "aurora";
})(BuiltInNetworkName = exports.BuiltInNetworkName || (exports.BuiltInNetworkName = {}));
/**
* Decimal string chain IDs of built-in networks, by name.
*
* `toHex` not invoked to avoid cyclic dependency
*/
exports.ChainId = {
[BuiltInNetworkName.Mainnet]: '0x1',
[BuiltInNetworkName.Goerli]: '0x5',
[BuiltInNetworkName.Sepolia]: '0xaa36a7',
[BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)
};
/**
* Decimal string network IDs of built-in Infura networks, by name.
*/
exports.NetworkId = {
[exports.InfuraNetworkType.mainnet]: '1',
[exports.InfuraNetworkType.goerli]: '5',
[exports.InfuraNetworkType.sepolia]: '11155111',
};
var NetworksTicker;

@@ -45,5 +63,4 @@ (function (NetworksTicker) {

NetworksTicker["sepolia"] = "SepoliaETH";
NetworksTicker["localhost"] = "";
NetworksTicker["rpc"] = "";
})(NetworksTicker = exports.NetworksTicker || (exports.NetworksTicker = {}));
//# sourceMappingURL=types.js.map
/// <reference types="bn.js" />
import { BN } from 'ethereumjs-util';
import type { Hex } from '@metamask/utils';
import type { Json } from './types';
import { Json } from '@metamask/utils';
/**

@@ -13,3 +13,3 @@ * Checks whether the given number primitive chain ID is safe.

*/
export declare function isSafeChainId(chainId: number): boolean;
export declare function isSafeChainId(chainId: Hex): boolean;
/**

@@ -110,11 +110,8 @@ * Converts a BN object to a hex string with a '0x' prefix.

* wrapper around ethereumjs-util.isValidAddress, with the exception that it
* does not throw an error when provided values that are not hex strings. In
* addition, and by default, this method will return true for hex strings that
* meet the length requirement of a hex address, but are not prefixed with `0x`
* Finally, if the mixedCaseUseChecksum flag is true and a mixed case string is
* provided this method will validate it has the proper checksum formatting.
* by default will return true for hex strings that meet the length requirement
* of a hex address, but are not prefixed with `0x`.
*
* @param possibleAddress - Input parameter to check against.
* @param options - The validation options.
* @param options.allowNonPrefixed - If true will first ensure '0x' is prepended to the string.
* @param options.allowNonPrefixed - If true will allow addresses without `0x` prefix.`
* @returns Whether or not the input is a valid hex address.

@@ -180,2 +177,10 @@ */

export declare function normalizeEnsName(ensName: string): string | null;
declare type EthQueryLike = {
sendAsync: (opts: Partial<{
id: number;
jsonrpc: '2.0';
method: string;
params: unknown;
}>, callback: (...args: [error: unknown, result: undefined] | [error: null, result: unknown]) => void) => void;
};
/**

@@ -189,3 +194,3 @@ * Wrapper method to handle EthQuery requests.

*/
export declare function query(ethQuery: any, method: string, args?: any[]): Promise<any>;
export declare function query(ethQuery: EthQueryLike, method: string, args?: any[]): Promise<any>;
/**

@@ -206,3 +211,2 @@ * Converts valid hex strings to decimal numbers, and handles unexpected arg types.

export declare function isPlainObject(value: unknown): value is PlainObject;
export declare const hasProperty: (object: PlainObject, key: string | number | symbol) => boolean;
/**

@@ -209,0 +213,0 @@ * Like {@link Array}, but always non-empty.

@@ -15,3 +15,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidJson = exports.isNonEmptyArray = exports.hasProperty = exports.isPlainObject = exports.convertHexToDecimal = exports.query = exports.normalizeEnsName = exports.timeoutFetch = exports.fetchWithErrorHandling = exports.handleFetch = exports.successfulFetch = exports.isSmartContractCode = exports.isValidHexAddress = exports.toChecksumHexAddress = exports.safelyExecuteWithTimeout = exports.safelyExecute = exports.toHex = exports.fromHex = exports.hexToText = exports.hexToBN = exports.getBuyURL = exports.weiHexToGweiDec = exports.gweiDecToWEIBN = exports.fractionBN = exports.BNToHex = exports.isSafeChainId = void 0;
exports.isValidJson = exports.isNonEmptyArray = exports.isPlainObject = exports.convertHexToDecimal = exports.query = exports.normalizeEnsName = exports.timeoutFetch = exports.fetchWithErrorHandling = exports.handleFetch = exports.successfulFetch = exports.isSmartContractCode = exports.isValidHexAddress = exports.toChecksumHexAddress = exports.safelyExecuteWithTimeout = exports.safelyExecute = exports.toHex = exports.fromHex = exports.hexToText = exports.hexToBN = exports.getBuyURL = exports.weiHexToGweiDec = exports.gweiDecToWEIBN = exports.fractionBN = exports.BNToHex = exports.isSafeChainId = void 0;
const ethereumjs_util_1 = require("ethereumjs-util");

@@ -33,3 +33,9 @@ const ethjs_unit_1 = require("ethjs-unit");

function isSafeChainId(chainId) {
return (Number.isSafeInteger(chainId) && chainId > 0 && chainId <= constants_1.MAX_SAFE_CHAIN_ID);
if (!(0, ethereumjs_util_1.isHexString)(chainId)) {
return false;
}
const decimalChainId = Number.parseInt(chainId);
return (Number.isSafeInteger(decimalChainId) &&
decimalChainId > 0 &&
decimalChainId <= constants_1.MAX_SAFE_CHAIN_ID);
}

@@ -251,11 +257,8 @@ exports.isSafeChainId = isSafeChainId;

* wrapper around ethereumjs-util.isValidAddress, with the exception that it
* does not throw an error when provided values that are not hex strings. In
* addition, and by default, this method will return true for hex strings that
* meet the length requirement of a hex address, but are not prefixed with `0x`
* Finally, if the mixedCaseUseChecksum flag is true and a mixed case string is
* provided this method will validate it has the proper checksum formatting.
* by default will return true for hex strings that meet the length requirement
* of a hex address, but are not prefixed with `0x`.
*
* @param possibleAddress - Input parameter to check against.
* @param options - The validation options.
* @param options.allowNonPrefixed - If true will first ensure '0x' is prepended to the string.
* @param options.allowNonPrefixed - If true will allow addresses without `0x` prefix.`
* @returns Whether or not the input is a valid hex address.

@@ -413,3 +416,5 @@ */

};
if (typeof ethQuery[method] === 'function') {
if ((0, utils_1.hasProperty)(ethQuery, method) &&
typeof ethQuery[method] === 'function') {
// @ts-expect-error All of the generated method types have this signature, but our EthQuery type doesn't include them
ethQuery[method](...args, cb);

@@ -446,4 +451,2 @@ }

exports.isPlainObject = isPlainObject;
const hasProperty = (object, key) => Reflect.hasOwnProperty.call(object, key);
exports.hasProperty = hasProperty;
/**

@@ -450,0 +453,0 @@ * Type guard for {@link NonEmptyArray}.

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

@@ -32,3 +32,3 @@ "keywords": [

"dependencies": {
"@metamask/utils": "^5.0.1",
"@metamask/utils": "^5.0.2",
"@spruceid/siwe-parser": "1.1.3",

@@ -54,3 +54,3 @@ "eth-ens-namehash": "^2.0.8",

"engines": {
"node": ">=14.0.0"
"node": ">=16.0.0"
},

@@ -57,0 +57,0 @@ "publishConfig": {

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc