Socket
Socket
Sign inDemoInstall

@metamask/utils

Package Overview
Dependencies
Maintainers
8
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/utils - npm Package Compare versions

Comparing version 3.3.1 to 3.4.0

dist/base64.d.ts

9

dist/assert.js

@@ -50,2 +50,3 @@ "use strict";

*/
// eslint-disable-next-line @typescript-eslint/naming-convention
function getError(ErrorWrapper, message) {

@@ -83,3 +84,5 @@ if (isConstructable(ErrorWrapper)) {

*/
function assert(value, message = 'Assertion failed.', ErrorWrapper = AssertionError) {
function assert(value, message = 'Assertion failed.',
// eslint-disable-next-line @typescript-eslint/naming-convention
ErrorWrapper = AssertionError) {
if (!value) {

@@ -104,3 +107,5 @@ if (message instanceof Error) {

*/
function assertStruct(value, struct, errorPrefix = 'Assertion failed', ErrorWrapper = AssertionError) {
function assertStruct(value, struct, errorPrefix = 'Assertion failed',
// eslint-disable-next-line @typescript-eslint/naming-convention
ErrorWrapper = AssertionError) {
try {

@@ -107,0 +112,0 @@ (0, superstruct_1.assert)(value, struct);

@@ -77,8 +77,8 @@ "use strict";

const lookupTable = getPrecomputedHexValues();
const hex = new Array(bytes.length);
const hexadecimal = new Array(bytes.length);
for (let i = 0; i < bytes.length; i++) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
hex[i] = lookupTable[bytes[i]];
hexadecimal[i] = lookupTable[bytes[i]];
}
return (0, hex_1.add0x)(hex.join(''));
return (0, hex_1.add0x)(hexadecimal.join(''));
}

@@ -98,4 +98,4 @@ exports.bytesToHex = bytesToHex;

assertIsBytes(bytes);
const hex = bytesToHex(bytes);
return BigInt(hex);
const hexadecimal = bytesToHex(bytes);
return BigInt(hexadecimal);
}

@@ -203,4 +203,4 @@ exports.bytesToBigInt = bytesToBigInt;

(0, assert_1.assert)(value >= BigInt(0), 'Value must be a non-negative bigint.');
const hex = value.toString(16);
return hexToBytes(hex);
const hexadecimal = value.toString(16);
return hexToBytes(hexadecimal);
}

@@ -264,4 +264,4 @@ exports.bigIntToBytes = bigIntToBytes;

(0, assert_1.assert)(Number.isSafeInteger(value), 'Value is not a safe integer. Use `bigIntToBytes` instead.');
const hex = value.toString(16);
return hexToBytes(hex);
const hexadecimal = value.toString(16);
return hexToBytes(hexadecimal);
}

@@ -371,2 +371,6 @@ exports.numberToBytes = numberToBytes;

function createDataView(bytes) {
// To maintain compatibility with Node.js, we need to check if the bytes are
// a Buffer. If so, we need to slice the buffer to get the underlying
// ArrayBuffer.
// eslint-disable-next-line no-restricted-globals
if (typeof Buffer !== 'undefined' && bytes instanceof Buffer) {

@@ -373,0 +377,0 @@ const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);

@@ -5,5 +5,5 @@ "use strict";

const superstruct_1 = require("superstruct");
const hex_1 = require("./hex");
const assert_1 = require("./assert");
const bytes_1 = require("./bytes");
const hex_1 = require("./hex");
const NumberLikeStruct = (0, superstruct_1.union)([(0, superstruct_1.number)(), (0, superstruct_1.bigint)(), (0, superstruct_1.string)(), hex_1.StrictHexStruct]);

@@ -85,3 +85,3 @@ const NumberCoercer = (0, superstruct_1.coerce)((0, superstruct_1.number)(), NumberLikeStruct, Number);

if (error instanceof superstruct_1.StructError) {
throw new Error(`Expected a number-like value, got "${error.value}".`);
throw new Error(`Expected a number-like value, got "${String(error.value)}".`);
}

@@ -121,3 +121,3 @@ /* istanbul ignore next */

if (error instanceof superstruct_1.StructError) {
throw new Error(`Expected a bytes-like value, got "${error.value}".`);
throw new Error(`Expected a bytes-like value, got "${String(error.value)}".`);
}

@@ -158,3 +158,3 @@ /* istanbul ignore next */

if (error instanceof superstruct_1.StructError) {
throw new Error(`Expected a bytes-like value, got "${error.value}".`);
throw new Error(`Expected a bytes-like value, got "${String(error.value)}".`);
}

@@ -161,0 +161,0 @@ /* istanbul ignore next */

@@ -39,6 +39,6 @@ import { Struct } from 'superstruct';

*
* @param hex - The hexadecimal string to add the prefix to.
* @param hexadecimal - The hexadecimal string to add the prefix to.
* @returns The prefixed hexadecimal string.
*/
export declare function add0x(hex: string): Hex;
export declare function add0x(hexadecimal: string): Hex;
/**

@@ -48,5 +48,5 @@ * Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have

*
* @param hex - The hexadecimal string to remove the prefix from.
* @param hexadecimal - The hexadecimal string to remove the prefix from.
* @returns The un-prefixed hexadecimal string.
*/
export declare function remove0x(hex: string): string;
export declare function remove0x(hexadecimal: string): string;

@@ -54,13 +54,13 @@ "use strict";

*
* @param hex - The hexadecimal string to add the prefix to.
* @param hexadecimal - The hexadecimal string to add the prefix to.
* @returns The prefixed hexadecimal string.
*/
function add0x(hex) {
if (hex.startsWith('0x')) {
return hex;
function add0x(hexadecimal) {
if (hexadecimal.startsWith('0x')) {
return hexadecimal;
}
if (hex.startsWith('0X')) {
return `0x${hex.substring(2)}`;
if (hexadecimal.startsWith('0X')) {
return `0x${hexadecimal.substring(2)}`;
}
return `0x${hex}`;
return `0x${hexadecimal}`;
}

@@ -72,12 +72,12 @@ exports.add0x = add0x;

*
* @param hex - The hexadecimal string to remove the prefix from.
* @param hexadecimal - The hexadecimal string to remove the prefix from.
* @returns The un-prefixed hexadecimal string.
*/
function remove0x(hex) {
if (hex.startsWith('0x') || hex.startsWith('0X')) {
return hex.substring(2);
function remove0x(hexadecimal) {
if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {
return hexadecimal.substring(2);
}
return hex;
return hexadecimal;
}
exports.remove0x = remove0x;
//# sourceMappingURL=hex.js.map
export * from './assert';
export * from './base64';
export * from './bytes';
export * from './checksum';
export * from './coercers';

@@ -10,2 +12,4 @@ export * from './collections';

export * from './number';
export * from './opaque';
export * from './time';
export * from './versions';

@@ -18,3 +18,5 @@ "use strict";

__exportStar(require("./assert"), exports);
__exportStar(require("./base64"), exports);
__exportStar(require("./bytes"), exports);
__exportStar(require("./checksum"), exports);
__exportStar(require("./coercers"), exports);

@@ -27,3 +29,5 @@ __exportStar(require("./collections"), exports);

__exportStar(require("./number"), exports);
__exportStar(require("./opaque"), exports);
__exportStar(require("./time"), exports);
__exportStar(require("./versions"), exports);
//# sourceMappingURL=index.js.map

@@ -72,3 +72,3 @@ import { Infer, Struct } from 'superstruct';

}>;
export declare type InferWithParams<Type extends Struct<any, unknown>, Params extends JsonRpcParams> = Omit<Infer<Type>, 'params'> & (keyof Params extends undefined ? {
export declare type InferWithParams<Type extends Struct<any>, Params extends JsonRpcParams> = Omit<Infer<Type>, 'params'> & (keyof Params extends undefined ? {
params?: Params;

@@ -81,3 +81,3 @@ } : {

*/
export declare type JsonRpcRequest<Params extends JsonRpcParams> = InferWithParams<typeof JsonRpcRequestStruct, Params>;
export declare type JsonRpcRequest<Params extends JsonRpcParams = JsonRpcParams> = InferWithParams<typeof JsonRpcRequestStruct, Params>;
export declare const JsonRpcNotificationStruct: Struct<{

@@ -96,3 +96,3 @@ method: string;

*/
export declare type JsonRpcNotification<Params extends JsonRpcParams> = InferWithParams<typeof JsonRpcNotificationStruct, Params>;
export declare type JsonRpcNotification<Params extends JsonRpcParams = JsonRpcParams> = InferWithParams<typeof JsonRpcNotificationStruct, Params>;
/**

@@ -105,3 +105,3 @@ * Check if the given value is a valid {@link JsonRpcNotification} object.

*/
export declare function isJsonRpcNotification(value: unknown): value is JsonRpcNotification<JsonRpcParams>;
export declare function isJsonRpcNotification(value: unknown): value is JsonRpcNotification;
/**

@@ -115,3 +115,3 @@ * Assert that the given value is a valid {@link JsonRpcNotification} object.

*/
export declare function assertIsJsonRpcNotification(value: unknown, ErrorWrapper?: AssertionErrorConstructor): asserts value is JsonRpcNotification<JsonRpcParams>;
export declare function assertIsJsonRpcNotification(value: unknown, ErrorWrapper?: AssertionErrorConstructor): asserts value is JsonRpcNotification;
/**

@@ -123,3 +123,3 @@ * Check if the given value is a valid {@link JsonRpcRequest} object.

*/
export declare function isJsonRpcRequest(value: unknown): value is JsonRpcRequest<JsonRpcParams>;
export declare function isJsonRpcRequest(value: unknown): value is JsonRpcRequest;
/**

@@ -133,3 +133,3 @@ * Assert that the given value is a valid {@link JsonRpcRequest} object.

*/
export declare function assertIsJsonRpcRequest(value: unknown, ErrorWrapper?: AssertionErrorConstructor): asserts value is JsonRpcRequest<JsonRpcParams>;
export declare function assertIsJsonRpcRequest(value: unknown, ErrorWrapper?: AssertionErrorConstructor): asserts value is JsonRpcRequest;
export declare const PendingJsonRpcResponseStruct: Struct<{

@@ -136,0 +136,0 @@ id: string | number | null;

@@ -64,3 +64,5 @@ "use strict";

*/
function assertIsJsonRpcNotification(value, ErrorWrapper) {
function assertIsJsonRpcNotification(value,
// eslint-disable-next-line @typescript-eslint/naming-convention
ErrorWrapper) {
(0, assert_1.assertStruct)(value, exports.JsonRpcNotificationStruct, 'Invalid JSON-RPC notification', ErrorWrapper);

@@ -87,3 +89,5 @@ }

*/
function assertIsJsonRpcRequest(value, ErrorWrapper) {
function assertIsJsonRpcRequest(value,
// eslint-disable-next-line @typescript-eslint/naming-convention
ErrorWrapper) {
(0, assert_1.assertStruct)(value, exports.JsonRpcRequestStruct, 'Invalid JSON-RPC request', ErrorWrapper);

@@ -132,3 +136,5 @@ }

*/
function assertIsPendingJsonRpcResponse(response, ErrorWrapper) {
function assertIsPendingJsonRpcResponse(response,
// eslint-disable-next-line @typescript-eslint/naming-convention
ErrorWrapper) {
(0, assert_1.assertStruct)(response, exports.PendingJsonRpcResponseStruct, 'Invalid pending JSON-RPC response', ErrorWrapper);

@@ -155,3 +161,5 @@ }

*/
function assertIsJsonRpcResponse(value, ErrorWrapper) {
function assertIsJsonRpcResponse(value,
// eslint-disable-next-line @typescript-eslint/naming-convention
ErrorWrapper) {
(0, assert_1.assertStruct)(value, exports.JsonRpcResponseStruct, 'Invalid JSON-RPC response', ErrorWrapper);

@@ -178,3 +186,5 @@ }

*/
function assertIsJsonRpcSuccess(value, ErrorWrapper) {
function assertIsJsonRpcSuccess(value,
// eslint-disable-next-line @typescript-eslint/naming-convention
ErrorWrapper) {
(0, assert_1.assertStruct)(value, exports.JsonRpcSuccessStruct, 'Invalid JSON-RPC success response', ErrorWrapper);

@@ -201,3 +211,5 @@ }

*/
function assertIsJsonRpcFailure(value, ErrorWrapper) {
function assertIsJsonRpcFailure(value,
// eslint-disable-next-line @typescript-eslint/naming-convention
ErrorWrapper) {
(0, assert_1.assertStruct)(value, exports.JsonRpcFailureStruct, 'Invalid JSON-RPC failure response', ErrorWrapper);

@@ -224,3 +236,5 @@ }

*/
function assertIsJsonRpcError(value, ErrorWrapper) {
function assertIsJsonRpcError(value,
// eslint-disable-next-line @typescript-eslint/naming-convention
ErrorWrapper) {
(0, assert_1.assertStruct)(value, exports.JsonRpcErrorStruct, 'Invalid JSON-RPC error', ErrorWrapper);

@@ -227,0 +241,0 @@ }

@@ -58,6 +58,6 @@ "use strict";

// but it's incompatible with the Json type.
class B {
class Foo {
}
const b = new B();
(0, tsd_1.expectNotAssignable)(b);
const foo = new Foo();
(0, tsd_1.expectNotAssignable)(foo);
//# sourceMappingURL=json.test-d.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hexToBigInt = exports.hexToNumber = exports.bigIntToHex = exports.numberToHex = void 0;
const assert_1 = require("./assert");
const hex_1 = require("./hex");
const assert_1 = require("./assert");
/**

@@ -7,0 +7,0 @@ * Convert a number to a hexadecimal string. This verifies that the number is a

{
"name": "@metamask/utils",
"version": "3.3.1",
"version": "3.4.0",
"description": "Various JavaScript/TypeScript utilities of wide relevance to the MetaMask codebase.",

@@ -18,9 +18,8 @@ "repository": {

"build:clean": "rimraf dist && yarn build",
"docs": "typedoc",
"docs:publish": "typedoc --cleanOutputDir false --gitRevision \"v$(jq -r .version < ./package.json)\"",
"build:docs": "typedoc",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' --ignore-path .gitignore",
"prepublishOnly": "yarn build:clean && yarn lint && yarn test",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
"prepack": "./scripts/prepack.sh",
"test": "yarn test:source && yarn test:types",

@@ -37,2 +36,3 @@ "test:source": "jest",

"debug": "^4.3.4",
"semver": "^7.3.8",
"superstruct": "^0.16.7"

@@ -43,26 +43,26 @@ },

"@metamask/auto-changelog": "^2.3.0",
"@metamask/eslint-config": "^9.0.0",
"@metamask/eslint-config-jest": "^9.0.0",
"@metamask/eslint-config-nodejs": "^9.0.0",
"@metamask/eslint-config-typescript": "^9.0.1",
"@metamask/eslint-config": "^11.0.1",
"@metamask/eslint-config-jest": "^11.0.0",
"@metamask/eslint-config-nodejs": "^11.0.1",
"@metamask/eslint-config-typescript": "^11.0.0",
"@types/jest": "^28.1.7",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.4",
"eslint-plugin-jsdoc": "^36.1.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"jest": "^28.1.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.2.2",
"json-bigint": "^1.0.0",
"prettier": "^2.2.1",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.11",
"rimraf": "^3.0.2",
"stdio-mock": "^1.2.0",
"ts-jest": "^28.0.8",
"ts-jest": "^29.0.3",
"tsd": "^0.24.1",
"typedoc": "^0.23.10",
"typescript": "~4.7.4"
"typescript": "~4.8.4"
},

@@ -69,0 +69,0 @@ "packageManager": "yarn@3.2.3",

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

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