@container23/caml-metamask-snap
Version:
CAML AML search metamask Snap
1,157 lines (1,135 loc) • 242 kB
JavaScript
(function (f) {
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = f();
} else if (typeof define === "function" && define.amd) {
define([], f);
} else {
var g;
if (typeof window !== "undefined") {
g = window;
} else if (typeof global !== "undefined") {
g = global;
} else if (typeof self !== "undefined") {
g = self;
} else {
g = this;
}
g.snap = f();
}
})(function () {
var define, module, exports;
return function () {
function r(e, n, t) {
function o(i, f) {
if (!n[i]) {
if (!e[i]) {
var c = "function" == typeof require && require;
if (!f && c) return c(i, !0);
if (u) return u(i, !0);
var a = new Error("Cannot find module '" + i + "'");
throw a.code = "MODULE_NOT_FOUND", a;
}
var p = n[i] = {
exports: {}
};
e[i][0].call(p.exports, function (r) {
var n = e[i][1][r];
return o(n || r);
}, p, p.exports, r, e, n, t);
}
return n[i].exports;
}
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]);
return o;
}
return r;
}()({
1: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.text = exports.spinner = exports.panel = exports.heading = exports.divider = exports.copyable = void 0;
const utils_1 = require("@metamask/utils");
const nodes_1 = require("./nodes");
function createBuilder(type, struct, keys = []) {
return (...args) => {
if (args.length === 1 && (0, utils_1.isPlainObject)(args[0])) {
const node = {
...args[0],
type
};
(0, utils_1.assertStruct)(node, struct, `Invalid ${type} component`);
return node;
}
const node = keys.reduce((partialNode, key, index) => {
return {
...partialNode,
[key]: args[index]
};
}, {
type
});
(0, utils_1.assertStruct)(node, struct, `Invalid ${type} component`);
return node;
};
}
exports.copyable = createBuilder(nodes_1.NodeType.Copyable, nodes_1.CopyableStruct, ['value']);
exports.divider = createBuilder(nodes_1.NodeType.Divider, nodes_1.DividerStruct);
exports.heading = createBuilder(nodes_1.NodeType.Heading, nodes_1.HeadingStruct, ['value']);
exports.panel = createBuilder(nodes_1.NodeType.Panel, nodes_1.PanelStruct, ['children']);
exports.spinner = createBuilder(nodes_1.NodeType.Spinner, nodes_1.SpinnerStruct);
exports.text = createBuilder(nodes_1.NodeType.Text, nodes_1.TextStruct, ['value']);
}, {
"./nodes": 3,
"@metamask/utils": 13
}],
2: [function (require, module, exports) {
"use strict";
var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = {
enumerable: true,
get: function () {
return m[k];
}
};
}
Object.defineProperty(o, k2, desc);
} : function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});
var __exportStar = this && this.__exportStar || function (m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", {
value: true
});
__exportStar(require("./builder"), exports);
__exportStar(require("./nodes"), exports);
__exportStar(require("./validation"), exports);
}, {
"./builder": 1,
"./nodes": 3,
"./validation": 4
}],
3: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ComponentStruct = exports.TextStruct = exports.SpinnerStruct = exports.PanelStruct = exports.HeadingStruct = exports.DividerStruct = exports.CopyableStruct = exports.NodeType = void 0;
const superstruct_1 = require("superstruct");
const NodeStruct = (0, superstruct_1.object)({
type: (0, superstruct_1.string)()
});
const ParentStruct = (0, superstruct_1.assign)(NodeStruct, (0, superstruct_1.object)({
children: (0, superstruct_1.array)((0, superstruct_1.lazy)(() => exports.ComponentStruct))
}));
const LiteralStruct = (0, superstruct_1.assign)(NodeStruct, (0, superstruct_1.object)({
value: (0, superstruct_1.unknown)()
}));
var NodeType;
(function (NodeType) {
NodeType["Copyable"] = "copyable";
NodeType["Divider"] = "divider";
NodeType["Heading"] = "heading";
NodeType["Panel"] = "panel";
NodeType["Spinner"] = "spinner";
NodeType["Text"] = "text";
})(NodeType = exports.NodeType || (exports.NodeType = {}));
exports.CopyableStruct = (0, superstruct_1.assign)(LiteralStruct, (0, superstruct_1.object)({
type: (0, superstruct_1.literal)(NodeType.Copyable),
value: (0, superstruct_1.string)()
}));
exports.DividerStruct = (0, superstruct_1.assign)(NodeStruct, (0, superstruct_1.object)({
type: (0, superstruct_1.literal)(NodeType.Divider)
}));
exports.HeadingStruct = (0, superstruct_1.assign)(LiteralStruct, (0, superstruct_1.object)({
type: (0, superstruct_1.literal)(NodeType.Heading),
value: (0, superstruct_1.string)()
}));
exports.PanelStruct = (0, superstruct_1.assign)(ParentStruct, (0, superstruct_1.object)({
type: (0, superstruct_1.literal)(NodeType.Panel)
}));
exports.SpinnerStruct = (0, superstruct_1.assign)(NodeStruct, (0, superstruct_1.object)({
type: (0, superstruct_1.literal)(NodeType.Spinner)
}));
exports.TextStruct = (0, superstruct_1.assign)(LiteralStruct, (0, superstruct_1.object)({
type: (0, superstruct_1.literal)(NodeType.Text),
value: (0, superstruct_1.string)()
}));
exports.ComponentStruct = (0, superstruct_1.union)([exports.CopyableStruct, exports.DividerStruct, exports.HeadingStruct, exports.PanelStruct, exports.SpinnerStruct, exports.TextStruct]);
}, {
"superstruct": 75
}],
4: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.assertIsComponent = exports.isComponent = void 0;
const utils_1 = require("@metamask/utils");
const superstruct_1 = require("superstruct");
const nodes_1 = require("./nodes");
function isComponent(value) {
return (0, superstruct_1.is)(value, nodes_1.ComponentStruct);
}
exports.isComponent = isComponent;
function assertIsComponent(value) {
(0, utils_1.assertStruct)(value, nodes_1.ComponentStruct, 'Invalid component');
}
exports.assertIsComponent = assertIsComponent;
}, {
"./nodes": 3,
"@metamask/utils": 13,
"superstruct": 75
}],
5: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.assertExhaustive = exports.assertStruct = exports.assert = exports.AssertionError = void 0;
const superstruct_1 = require("superstruct");
function isErrorWithMessage(error) {
return typeof error === 'object' && error !== null && 'message' in error;
}
function isConstructable(fn) {
var _a, _b;
return Boolean(typeof ((_b = (_a = fn === null || fn === void 0 ? void 0 : fn.prototype) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name) === 'string');
}
function getErrorMessage(error) {
const message = isErrorWithMessage(error) ? error.message : String(error);
if (message.endsWith('.')) {
return message.slice(0, -1);
}
return message;
}
function getError(ErrorWrapper, message) {
if (isConstructable(ErrorWrapper)) {
return new ErrorWrapper({
message
});
}
return ErrorWrapper({
message
});
}
class AssertionError extends Error {
constructor(options) {
super(options.message);
this.code = 'ERR_ASSERTION';
}
}
exports.AssertionError = AssertionError;
function assert(value, message = 'Assertion failed.', ErrorWrapper = AssertionError) {
if (!value) {
if (message instanceof Error) {
throw message;
}
throw getError(ErrorWrapper, message);
}
}
exports.assert = assert;
function assertStruct(value, struct, errorPrefix = 'Assertion failed', ErrorWrapper = AssertionError) {
try {
(0, superstruct_1.assert)(value, struct);
} catch (error) {
throw getError(ErrorWrapper, `${errorPrefix}: ${getErrorMessage(error)}.`);
}
}
exports.assertStruct = assertStruct;
function assertExhaustive(_object) {
throw new Error('Invalid branch reached. Should be detected during compilation.');
}
exports.assertExhaustive = assertExhaustive;
}, {
"superstruct": 75
}],
6: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.base64 = void 0;
const superstruct_1 = require("superstruct");
const assert_1 = require("./assert");
const base64 = (struct, options = {}) => {
var _a, _b;
const paddingRequired = (_a = options.paddingRequired) !== null && _a !== void 0 ? _a : false;
const characterSet = (_b = options.characterSet) !== null && _b !== void 0 ? _b : 'base64';
let letters;
if (characterSet === 'base64') {
letters = String.raw`[A-Za-z0-9+\/]`;
} else {
(0, assert_1.assert)(characterSet === 'base64url');
letters = String.raw`[-_A-Za-z0-9]`;
}
let re;
if (paddingRequired) {
re = new RegExp(`^(?:${letters}{4})*(?:${letters}{3}=|${letters}{2}==)?$`, 'u');
} else {
re = new RegExp(`^(?:${letters}{4})*(?:${letters}{2,3}|${letters}{3}=|${letters}{2}==)?$`, 'u');
}
return (0, superstruct_1.pattern)(struct, re);
};
exports.base64 = base64;
}, {
"./assert": 5,
"superstruct": 75
}],
7: [function (require, module, exports) {
(function () {
(function () {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createDataView = exports.concatBytes = exports.valueToBytes = exports.stringToBytes = exports.numberToBytes = exports.signedBigIntToBytes = exports.bigIntToBytes = exports.hexToBytes = exports.bytesToString = exports.bytesToNumber = exports.bytesToSignedBigInt = exports.bytesToBigInt = exports.bytesToHex = exports.assertIsBytes = exports.isBytes = void 0;
const assert_1 = require("./assert");
const hex_1 = require("./hex");
const HEX_MINIMUM_NUMBER_CHARACTER = 48;
const HEX_MAXIMUM_NUMBER_CHARACTER = 58;
const HEX_CHARACTER_OFFSET = 87;
function getPrecomputedHexValuesBuilder() {
const lookupTable = [];
return () => {
if (lookupTable.length === 0) {
for (let i = 0; i < 256; i++) {
lookupTable.push(i.toString(16).padStart(2, '0'));
}
}
return lookupTable;
};
}
const getPrecomputedHexValues = getPrecomputedHexValuesBuilder();
function isBytes(value) {
return value instanceof Uint8Array;
}
exports.isBytes = isBytes;
function assertIsBytes(value) {
(0, assert_1.assert)(isBytes(value), 'Value must be a Uint8Array.');
}
exports.assertIsBytes = assertIsBytes;
function bytesToHex(bytes) {
assertIsBytes(bytes);
if (bytes.length === 0) {
return '0x';
}
const lookupTable = getPrecomputedHexValues();
const hexadecimal = new Array(bytes.length);
for (let i = 0; i < bytes.length; i++) {
hexadecimal[i] = lookupTable[bytes[i]];
}
return (0, hex_1.add0x)(hexadecimal.join(''));
}
exports.bytesToHex = bytesToHex;
function bytesToBigInt(bytes) {
assertIsBytes(bytes);
const hexadecimal = bytesToHex(bytes);
return BigInt(hexadecimal);
}
exports.bytesToBigInt = bytesToBigInt;
function bytesToSignedBigInt(bytes) {
assertIsBytes(bytes);
let value = BigInt(0);
for (const byte of bytes) {
value = (value << BigInt(8)) + BigInt(byte);
}
return BigInt.asIntN(bytes.length * 8, value);
}
exports.bytesToSignedBigInt = bytesToSignedBigInt;
function bytesToNumber(bytes) {
assertIsBytes(bytes);
const bigint = bytesToBigInt(bytes);
(0, assert_1.assert)(bigint <= BigInt(Number.MAX_SAFE_INTEGER), 'Number is not a safe integer. Use `bytesToBigInt` instead.');
return Number(bigint);
}
exports.bytesToNumber = bytesToNumber;
function bytesToString(bytes) {
assertIsBytes(bytes);
return new TextDecoder().decode(bytes);
}
exports.bytesToString = bytesToString;
function hexToBytes(value) {
var _a;
if (((_a = value === null || value === void 0 ? void 0 : value.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(value)) === '0x') {
return new Uint8Array();
}
(0, hex_1.assertIsHexString)(value);
const strippedValue = (0, hex_1.remove0x)(value).toLowerCase();
const normalizedValue = strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;
const bytes = new Uint8Array(normalizedValue.length / 2);
for (let i = 0; i < bytes.length; i++) {
const c1 = normalizedValue.charCodeAt(i * 2);
const c2 = normalizedValue.charCodeAt(i * 2 + 1);
const n1 = c1 - (c1 < HEX_MAXIMUM_NUMBER_CHARACTER ? HEX_MINIMUM_NUMBER_CHARACTER : HEX_CHARACTER_OFFSET);
const n2 = c2 - (c2 < HEX_MAXIMUM_NUMBER_CHARACTER ? HEX_MINIMUM_NUMBER_CHARACTER : HEX_CHARACTER_OFFSET);
bytes[i] = n1 * 16 + n2;
}
return bytes;
}
exports.hexToBytes = hexToBytes;
function bigIntToBytes(value) {
(0, assert_1.assert)(typeof value === 'bigint', 'Value must be a bigint.');
(0, assert_1.assert)(value >= BigInt(0), 'Value must be a non-negative bigint.');
const hexadecimal = value.toString(16);
return hexToBytes(hexadecimal);
}
exports.bigIntToBytes = bigIntToBytes;
function bigIntFits(value, bytes) {
(0, assert_1.assert)(bytes > 0);
const mask = value >> BigInt(31);
return !((~value & mask) + (value & ~mask) >> BigInt(bytes * 8 + ~0));
}
function signedBigIntToBytes(value, byteLength) {
(0, assert_1.assert)(typeof value === 'bigint', 'Value must be a bigint.');
(0, assert_1.assert)(typeof byteLength === 'number', 'Byte length must be a number.');
(0, assert_1.assert)(byteLength > 0, 'Byte length must be greater than 0.');
(0, assert_1.assert)(bigIntFits(value, byteLength), 'Byte length is too small to represent the given value.');
let numberValue = value;
const bytes = new Uint8Array(byteLength);
for (let i = 0; i < bytes.length; i++) {
bytes[i] = Number(BigInt.asUintN(8, numberValue));
numberValue >>= BigInt(8);
}
return bytes.reverse();
}
exports.signedBigIntToBytes = signedBigIntToBytes;
function numberToBytes(value) {
(0, assert_1.assert)(typeof value === 'number', 'Value must be a number.');
(0, assert_1.assert)(value >= 0, 'Value must be a non-negative number.');
(0, assert_1.assert)(Number.isSafeInteger(value), 'Value is not a safe integer. Use `bigIntToBytes` instead.');
const hexadecimal = value.toString(16);
return hexToBytes(hexadecimal);
}
exports.numberToBytes = numberToBytes;
function stringToBytes(value) {
(0, assert_1.assert)(typeof value === 'string', 'Value must be a string.');
return new TextEncoder().encode(value);
}
exports.stringToBytes = stringToBytes;
function valueToBytes(value) {
if (typeof value === 'bigint') {
return bigIntToBytes(value);
}
if (typeof value === 'number') {
return numberToBytes(value);
}
if (typeof value === 'string') {
if (value.startsWith('0x')) {
return hexToBytes(value);
}
return stringToBytes(value);
}
if (isBytes(value)) {
return value;
}
throw new TypeError(`Unsupported value type: "${typeof value}".`);
}
exports.valueToBytes = valueToBytes;
function concatBytes(values) {
const normalizedValues = new Array(values.length);
let byteLength = 0;
for (let i = 0; i < values.length; i++) {
const value = valueToBytes(values[i]);
normalizedValues[i] = value;
byteLength += value.length;
}
const bytes = new Uint8Array(byteLength);
for (let i = 0, offset = 0; i < normalizedValues.length; i++) {
bytes.set(normalizedValues[i], offset);
offset += normalizedValues[i].length;
}
return bytes;
}
exports.concatBytes = concatBytes;
function createDataView(bytes) {
if (typeof Buffer !== 'undefined' && bytes instanceof Buffer) {
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
return new DataView(buffer);
}
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
}
exports.createDataView = createDataView;
}).call(this);
}).call(this, require("buffer").Buffer);
}, {
"./assert": 5,
"./hex": 12,
"buffer": 24
}],
8: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ChecksumStruct = void 0;
const superstruct_1 = require("superstruct");
const base64_1 = require("./base64");
exports.ChecksumStruct = (0, superstruct_1.size)((0, base64_1.base64)((0, superstruct_1.string)(), {
paddingRequired: true
}), 44, 44);
}, {
"./base64": 6,
"superstruct": 75
}],
9: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createHex = exports.createBytes = exports.createBigInt = exports.createNumber = void 0;
const superstruct_1 = require("superstruct");
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]);
const NumberCoercer = (0, superstruct_1.coerce)((0, superstruct_1.number)(), NumberLikeStruct, Number);
const BigIntCoercer = (0, superstruct_1.coerce)((0, superstruct_1.bigint)(), NumberLikeStruct, BigInt);
const BytesLikeStruct = (0, superstruct_1.union)([hex_1.StrictHexStruct, (0, superstruct_1.instance)(Uint8Array)]);
const BytesCoercer = (0, superstruct_1.coerce)((0, superstruct_1.instance)(Uint8Array), (0, superstruct_1.union)([hex_1.StrictHexStruct]), bytes_1.hexToBytes);
const HexCoercer = (0, superstruct_1.coerce)(hex_1.StrictHexStruct, (0, superstruct_1.instance)(Uint8Array), bytes_1.bytesToHex);
function createNumber(value) {
try {
const result = (0, superstruct_1.create)(value, NumberCoercer);
(0, assert_1.assert)(Number.isFinite(result), `Expected a number-like value, got "${value}".`);
return result;
} catch (error) {
if (error instanceof superstruct_1.StructError) {
throw new Error(`Expected a number-like value, got "${value}".`);
}
throw error;
}
}
exports.createNumber = createNumber;
function createBigInt(value) {
try {
return (0, superstruct_1.create)(value, BigIntCoercer);
} catch (error) {
if (error instanceof superstruct_1.StructError) {
throw new Error(`Expected a number-like value, got "${String(error.value)}".`);
}
throw error;
}
}
exports.createBigInt = createBigInt;
function createBytes(value) {
if (typeof value === 'string' && value.toLowerCase() === '0x') {
return new Uint8Array();
}
try {
return (0, superstruct_1.create)(value, BytesCoercer);
} catch (error) {
if (error instanceof superstruct_1.StructError) {
throw new Error(`Expected a bytes-like value, got "${String(error.value)}".`);
}
throw error;
}
}
exports.createBytes = createBytes;
function createHex(value) {
if (value instanceof Uint8Array && value.length === 0 || typeof value === 'string' && value.toLowerCase() === '0x') {
return '0x';
}
try {
return (0, superstruct_1.create)(value, HexCoercer);
} catch (error) {
if (error instanceof superstruct_1.StructError) {
throw new Error(`Expected a bytes-like value, got "${String(error.value)}".`);
}
throw error;
}
}
exports.createHex = createHex;
}, {
"./assert": 5,
"./bytes": 7,
"./hex": 12,
"superstruct": 75
}],
10: [function (require, module, exports) {
"use strict";
var __classPrivateFieldSet = this && this.__classPrivateFieldSet || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
};
var __classPrivateFieldGet = this && this.__classPrivateFieldGet || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _FrozenMap_map, _FrozenSet_set;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.FrozenSet = exports.FrozenMap = void 0;
class FrozenMap {
constructor(entries) {
_FrozenMap_map.set(this, void 0);
__classPrivateFieldSet(this, _FrozenMap_map, new Map(entries), "f");
Object.freeze(this);
}
get size() {
return __classPrivateFieldGet(this, _FrozenMap_map, "f").size;
}
[(_FrozenMap_map = new WeakMap(), Symbol.iterator)]() {
return __classPrivateFieldGet(this, _FrozenMap_map, "f")[Symbol.iterator]();
}
entries() {
return __classPrivateFieldGet(this, _FrozenMap_map, "f").entries();
}
forEach(callbackfn, thisArg) {
return __classPrivateFieldGet(this, _FrozenMap_map, "f").forEach((value, key, _map) => callbackfn.call(thisArg, value, key, this));
}
get(key) {
return __classPrivateFieldGet(this, _FrozenMap_map, "f").get(key);
}
has(key) {
return __classPrivateFieldGet(this, _FrozenMap_map, "f").has(key);
}
keys() {
return __classPrivateFieldGet(this, _FrozenMap_map, "f").keys();
}
values() {
return __classPrivateFieldGet(this, _FrozenMap_map, "f").values();
}
toString() {
return `FrozenMap(${this.size}) {${this.size > 0 ? ` ${[...this.entries()].map(([key, value]) => `${String(key)} => ${String(value)}`).join(', ')} ` : ''}}`;
}
}
exports.FrozenMap = FrozenMap;
class FrozenSet {
constructor(values) {
_FrozenSet_set.set(this, void 0);
__classPrivateFieldSet(this, _FrozenSet_set, new Set(values), "f");
Object.freeze(this);
}
get size() {
return __classPrivateFieldGet(this, _FrozenSet_set, "f").size;
}
[(_FrozenSet_set = new WeakMap(), Symbol.iterator)]() {
return __classPrivateFieldGet(this, _FrozenSet_set, "f")[Symbol.iterator]();
}
entries() {
return __classPrivateFieldGet(this, _FrozenSet_set, "f").entries();
}
forEach(callbackfn, thisArg) {
return __classPrivateFieldGet(this, _FrozenSet_set, "f").forEach((value, value2, _set) => callbackfn.call(thisArg, value, value2, this));
}
has(value) {
return __classPrivateFieldGet(this, _FrozenSet_set, "f").has(value);
}
keys() {
return __classPrivateFieldGet(this, _FrozenSet_set, "f").keys();
}
values() {
return __classPrivateFieldGet(this, _FrozenSet_set, "f").values();
}
toString() {
return `FrozenSet(${this.size}) {${this.size > 0 ? ` ${[...this.values()].map(member => String(member)).join(', ')} ` : ''}}`;
}
}
exports.FrozenSet = FrozenSet;
Object.freeze(FrozenMap);
Object.freeze(FrozenMap.prototype);
Object.freeze(FrozenSet);
Object.freeze(FrozenSet.prototype);
}, {}],
11: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
}, {}],
12: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.remove0x = exports.add0x = exports.assertIsStrictHexString = exports.assertIsHexString = exports.isStrictHexString = exports.isHexString = exports.StrictHexStruct = exports.HexStruct = void 0;
const superstruct_1 = require("superstruct");
const assert_1 = require("./assert");
exports.HexStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), /^(?:0x)?[0-9a-f]+$/iu);
exports.StrictHexStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), /^0x[0-9a-f]+$/iu);
function isHexString(value) {
return (0, superstruct_1.is)(value, exports.HexStruct);
}
exports.isHexString = isHexString;
function isStrictHexString(value) {
return (0, superstruct_1.is)(value, exports.StrictHexStruct);
}
exports.isStrictHexString = isStrictHexString;
function assertIsHexString(value) {
(0, assert_1.assert)(isHexString(value), 'Value must be a hexadecimal string.');
}
exports.assertIsHexString = assertIsHexString;
function assertIsStrictHexString(value) {
(0, assert_1.assert)(isStrictHexString(value), 'Value must be a hexadecimal string, starting with "0x".');
}
exports.assertIsStrictHexString = assertIsStrictHexString;
function add0x(hexadecimal) {
if (hexadecimal.startsWith('0x')) {
return hexadecimal;
}
if (hexadecimal.startsWith('0X')) {
return `0x${hexadecimal.substring(2)}`;
}
return `0x${hexadecimal}`;
}
exports.add0x = add0x;
function remove0x(hexadecimal) {
if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {
return hexadecimal.substring(2);
}
return hexadecimal;
}
exports.remove0x = remove0x;
}, {
"./assert": 5,
"superstruct": 75
}],
13: [function (require, module, exports) {
"use strict";
var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = {
enumerable: true,
get: function () {
return m[k];
}
};
}
Object.defineProperty(o, k2, desc);
} : function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});
var __exportStar = this && this.__exportStar || function (m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", {
value: true
});
__exportStar(require("./assert"), exports);
__exportStar(require("./base64"), exports);
__exportStar(require("./bytes"), exports);
__exportStar(require("./checksum"), exports);
__exportStar(require("./coercers"), exports);
__exportStar(require("./collections"), exports);
__exportStar(require("./encryption-types"), exports);
__exportStar(require("./hex"), exports);
__exportStar(require("./json"), exports);
__exportStar(require("./keyring"), exports);
__exportStar(require("./logging"), exports);
__exportStar(require("./misc"), exports);
__exportStar(require("./number"), exports);
__exportStar(require("./opaque"), exports);
__exportStar(require("./time"), exports);
__exportStar(require("./transaction-types"), exports);
__exportStar(require("./versions"), exports);
}, {
"./assert": 5,
"./base64": 6,
"./bytes": 7,
"./checksum": 8,
"./coercers": 9,
"./collections": 10,
"./encryption-types": 11,
"./hex": 12,
"./json": 14,
"./keyring": 15,
"./logging": 16,
"./misc": 17,
"./number": 18,
"./opaque": 19,
"./time": 20,
"./transaction-types": 21,
"./versions": 22
}],
14: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getJsonRpcIdValidator = exports.assertIsJsonRpcError = exports.isJsonRpcError = exports.assertIsJsonRpcFailure = exports.isJsonRpcFailure = exports.assertIsJsonRpcSuccess = exports.isJsonRpcSuccess = exports.assertIsJsonRpcResponse = exports.isJsonRpcResponse = exports.assertIsPendingJsonRpcResponse = exports.isPendingJsonRpcResponse = exports.JsonRpcResponseStruct = exports.JsonRpcFailureStruct = exports.JsonRpcSuccessStruct = exports.PendingJsonRpcResponseStruct = exports.assertIsJsonRpcRequest = exports.isJsonRpcRequest = exports.assertIsJsonRpcNotification = exports.isJsonRpcNotification = exports.JsonRpcNotificationStruct = exports.JsonRpcRequestStruct = exports.JsonRpcParamsStruct = exports.JsonRpcErrorStruct = exports.JsonRpcIdStruct = exports.JsonRpcVersionStruct = exports.jsonrpc2 = exports.getJsonSize = exports.isValidJson = exports.JsonStruct = exports.UnsafeJsonStruct = void 0;
const superstruct_1 = require("superstruct");
const assert_1 = require("./assert");
const finiteNumber = () => (0, superstruct_1.define)('finite number', value => {
return (0, superstruct_1.is)(value, (0, superstruct_1.number)()) && Number.isFinite(value);
});
exports.UnsafeJsonStruct = (0, superstruct_1.union)([(0, superstruct_1.literal)(null), (0, superstruct_1.boolean)(), finiteNumber(), (0, superstruct_1.string)(), (0, superstruct_1.array)((0, superstruct_1.lazy)(() => exports.UnsafeJsonStruct)), (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.lazy)(() => exports.UnsafeJsonStruct))]);
exports.JsonStruct = (0, superstruct_1.define)('Json', (value, context) => {
function checkStruct(innerValue, struct) {
const iterator = struct.validator(innerValue, context);
const errors = [...iterator];
if (errors.length > 0) {
return errors;
}
return true;
}
try {
const unsafeResult = checkStruct(value, exports.UnsafeJsonStruct);
if (unsafeResult !== true) {
return unsafeResult;
}
return checkStruct(JSON.parse(JSON.stringify(value)), exports.UnsafeJsonStruct);
} catch (error) {
if (error instanceof RangeError) {
return 'Circular reference detected';
}
return false;
}
});
function isValidJson(value) {
return (0, superstruct_1.is)(value, exports.JsonStruct);
}
exports.isValidJson = isValidJson;
function getJsonSize(value) {
(0, assert_1.assertStruct)(value, exports.JsonStruct, 'Invalid JSON value');
const json = JSON.stringify(value);
return new TextEncoder().encode(json).byteLength;
}
exports.getJsonSize = getJsonSize;
exports.jsonrpc2 = '2.0';
exports.JsonRpcVersionStruct = (0, superstruct_1.literal)(exports.jsonrpc2);
exports.JsonRpcIdStruct = (0, superstruct_1.nullable)((0, superstruct_1.union)([(0, superstruct_1.number)(), (0, superstruct_1.string)()]));
exports.JsonRpcErrorStruct = (0, superstruct_1.object)({
code: (0, superstruct_1.integer)(),
message: (0, superstruct_1.string)(),
data: (0, superstruct_1.optional)(exports.JsonStruct),
stack: (0, superstruct_1.optional)((0, superstruct_1.string)())
});
exports.JsonRpcParamsStruct = (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.record)((0, superstruct_1.string)(), exports.JsonStruct), (0, superstruct_1.array)(exports.JsonStruct)]));
exports.JsonRpcRequestStruct = (0, superstruct_1.object)({
id: exports.JsonRpcIdStruct,
jsonrpc: exports.JsonRpcVersionStruct,
method: (0, superstruct_1.string)(),
params: exports.JsonRpcParamsStruct
});
exports.JsonRpcNotificationStruct = (0, superstruct_1.omit)(exports.JsonRpcRequestStruct, ['id']);
function isJsonRpcNotification(value) {
return (0, superstruct_1.is)(value, exports.JsonRpcNotificationStruct);
}
exports.isJsonRpcNotification = isJsonRpcNotification;
function assertIsJsonRpcNotification(value, ErrorWrapper) {
(0, assert_1.assertStruct)(value, exports.JsonRpcNotificationStruct, 'Invalid JSON-RPC notification', ErrorWrapper);
}
exports.assertIsJsonRpcNotification = assertIsJsonRpcNotification;
function isJsonRpcRequest(value) {
return (0, superstruct_1.is)(value, exports.JsonRpcRequestStruct);
}
exports.isJsonRpcRequest = isJsonRpcRequest;
function assertIsJsonRpcRequest(value, ErrorWrapper) {
(0, assert_1.assertStruct)(value, exports.JsonRpcRequestStruct, 'Invalid JSON-RPC request', ErrorWrapper);
}
exports.assertIsJsonRpcRequest = assertIsJsonRpcRequest;
exports.PendingJsonRpcResponseStruct = (0, superstruct_1.object)({
id: exports.JsonRpcIdStruct,
jsonrpc: exports.JsonRpcVersionStruct,
result: (0, superstruct_1.optional)((0, superstruct_1.unknown)()),
error: (0, superstruct_1.optional)(exports.JsonRpcErrorStruct)
});
exports.JsonRpcSuccessStruct = (0, superstruct_1.object)({
id: exports.JsonRpcIdStruct,
jsonrpc: exports.JsonRpcVersionStruct,
result: exports.JsonStruct
});
exports.JsonRpcFailureStruct = (0, superstruct_1.object)({
id: exports.JsonRpcIdStruct,
jsonrpc: exports.JsonRpcVersionStruct,
error: exports.JsonRpcErrorStruct
});
exports.JsonRpcResponseStruct = (0, superstruct_1.union)([exports.JsonRpcSuccessStruct, exports.JsonRpcFailureStruct]);
function isPendingJsonRpcResponse(response) {
return (0, superstruct_1.is)(response, exports.PendingJsonRpcResponseStruct);
}
exports.isPendingJsonRpcResponse = isPendingJsonRpcResponse;
function assertIsPendingJsonRpcResponse(response, ErrorWrapper) {
(0, assert_1.assertStruct)(response, exports.PendingJsonRpcResponseStruct, 'Invalid pending JSON-RPC response', ErrorWrapper);
}
exports.assertIsPendingJsonRpcResponse = assertIsPendingJsonRpcResponse;
function isJsonRpcResponse(response) {
return (0, superstruct_1.is)(response, exports.JsonRpcResponseStruct);
}
exports.isJsonRpcResponse = isJsonRpcResponse;
function assertIsJsonRpcResponse(value, ErrorWrapper) {
(0, assert_1.assertStruct)(value, exports.JsonRpcResponseStruct, 'Invalid JSON-RPC response', ErrorWrapper);
}
exports.assertIsJsonRpcResponse = assertIsJsonRpcResponse;
function isJsonRpcSuccess(value) {
return (0, superstruct_1.is)(value, exports.JsonRpcSuccessStruct);
}
exports.isJsonRpcSuccess = isJsonRpcSuccess;
function assertIsJsonRpcSuccess(value, ErrorWrapper) {
(0, assert_1.assertStruct)(value, exports.JsonRpcSuccessStruct, 'Invalid JSON-RPC success response', ErrorWrapper);
}
exports.assertIsJsonRpcSuccess = assertIsJsonRpcSuccess;
function isJsonRpcFailure(value) {
return (0, superstruct_1.is)(value, exports.JsonRpcFailureStruct);
}
exports.isJsonRpcFailure = isJsonRpcFailure;
function assertIsJsonRpcFailure(value, ErrorWrapper) {
(0, assert_1.assertStruct)(value, exports.JsonRpcFailureStruct, 'Invalid JSON-RPC failure response', ErrorWrapper);
}
exports.assertIsJsonRpcFailure = assertIsJsonRpcFailure;
function isJsonRpcError(value) {
return (0, superstruct_1.is)(value, exports.JsonRpcErrorStruct);
}
exports.isJsonRpcError = isJsonRpcError;
function assertIsJsonRpcError(value, ErrorWrapper) {
(0, assert_1.assertStruct)(value, exports.JsonRpcErrorStruct, 'Invalid JSON-RPC error', ErrorWrapper);
}
exports.assertIsJsonRpcError = assertIsJsonRpcError;
function getJsonRpcIdValidator(options) {
const {
permitEmptyString,
permitFractions,
permitNull
} = Object.assign({
permitEmptyString: true,
permitFractions: false,
permitNull: true
}, options);
const isValidJsonRpcId = id => {
return Boolean(typeof id === 'number' && (permitFractions || Number.isInteger(id)) || typeof id === 'string' && (permitEmptyString || id.length > 0) || permitNull && id === null);
};
return isValidJsonRpcId;
}
exports.getJsonRpcIdValidator = getJsonRpcIdValidator;
}, {
"./assert": 5,
"superstruct": 75
}],
15: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
}, {}],
16: [function (require, module, exports) {
"use strict";
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createModuleLogger = exports.createProjectLogger = void 0;
const debug_1 = __importDefault(require("debug"));
const globalLogger = (0, debug_1.default)('metamask');
function createProjectLogger(projectName) {
return globalLogger.extend(projectName);
}
exports.createProjectLogger = createProjectLogger;
function createModuleLogger(projectLogger, moduleName) {
return projectLogger.extend(moduleName);
}
exports.createModuleLogger = createModuleLogger;
}, {
"debug": 26
}],
17: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.calculateNumberSize = exports.calculateStringSize = exports.isASCII = exports.isPlainObject = exports.ESCAPE_CHARACTERS_REGEXP = exports.JsonSize = exports.hasProperty = exports.isObject = exports.isNullOrUndefined = exports.isNonEmptyArray = void 0;
function isNonEmptyArray(value) {
return Array.isArray(value) && value.length > 0;
}
exports.isNonEmptyArray = isNonEmptyArray;
function isNullOrUndefined(value) {
return value === null || value === undefined;
}
exports.isNullOrUndefined = isNullOrUndefined;
function isObject(value) {
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
}
exports.isObject = isObject;
const hasProperty = (objectToCheck, name) => Object.hasOwnProperty.call(objectToCheck, name);
exports.hasProperty = hasProperty;
var JsonSize;
(function (JsonSize) {
JsonSize[JsonSize["Null"] = 4] = "Null";
JsonSize[JsonSize["Comma"] = 1] = "Comma";
JsonSize[JsonSize["Wrapper"] = 1] = "Wrapper";
JsonSize[JsonSize["True"] = 4] = "True";
JsonSize[JsonSize["False"] = 5] = "False";
JsonSize[JsonSize["Quote"] = 1] = "Quote";
JsonSize[JsonSize["Colon"] = 1] = "Colon";
JsonSize[JsonSize["Date"] = 24] = "Date";
})(JsonSize = exports.JsonSize || (exports.JsonSize = {}));
exports.ESCAPE_CHARACTERS_REGEXP = /"|\\|\n|\r|\t/gu;
function isPlainObject(value) {
if (typeof value !== 'object' || value === null) {
return false;
}
try {
let proto = value;
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto);
}
return Object.getPrototypeOf(value) === proto;
} catch (_) {
return false;
}
}
exports.isPlainObject = isPlainObject;
function isASCII(character) {
return character.charCodeAt(0) <= 127;
}
exports.isASCII = isASCII;
function calculateStringSize(value) {
var _a;
const size = value.split('').reduce((total, character) => {
if (isASCII(character)) {
return total + 1;
}
return total + 2;
}, 0);
return size + ((_a = value.match(exports.ESCAPE_CHARACTERS_REGEXP)) !== null && _a !== void 0 ? _a : []).length;
}
exports.calculateStringSize = calculateStringSize;
function calculateNumberSize(value) {
return value.toString().length;
}
exports.calculateNumberSize = calculateNumberSize;
}, {}],
18: [function (require, module, exports) {
"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 numberToHex = value => {
(0, assert_1.assert)(typeof value === 'number', 'Value must be a number.');
(0, assert_1.assert)(value >= 0, 'Value must be a non-negative number.');
(0, assert_1.assert)(Number.isSafeInteger(value), 'Value is not a safe integer. Use `bigIntToHex` instead.');
return (0, hex_1.add0x)(value.toString(16));
};
exports.numberToHex = numberToHex;
const bigIntToHex = value => {
(0, assert_1.assert)(typeof value === 'bigint', 'Value must be a bigint.');
(0, assert_1.assert)(value >= 0, 'Value must be a non-negative bigint.');
return (0, hex_1.add0x)(value.toString(16));
};
exports.bigIntToHex = bigIntToHex;
const hexToNumber = value => {
(0, hex_1.assertIsHexString)(value);
const numberValue = parseInt(value, 16);
(0, assert_1.assert)(Number.isSafeInteger(numberValue), 'Value is not a safe integer. Use `hexToBigInt` instead.');
return numberValue;
};
exports.hexToNumber = hexToNumber;
const hexToBigInt = value => {
(0, hex_1.assertIsHexString)(value);
return BigInt((0, hex_1.add0x)(value));
};
exports.hexToBigInt = hexToBigInt;
}, {
"./assert": 5,
"./hex": 12
}],
19: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
}, {}],
20: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.timeSince = exports.inMilliseconds = exports.Duration = void 0;
var Duration;
(function (Duration) {
Duration[Duration["Millisecond"] = 1] = "Millisecond";
Duration[Duration["Second"] = 1000] = "Second";
Duration[Duration["Minute"] = 60000] = "Minute";
Duration[Duration["Hour"] = 3600000] = "Hour";
Duration[Duration["Day"] = 86400000] = "Day";
Duration[Duration["Week"] = 604800000] = "Week";
Duration[Duration["Year"] = 31536000000] = "Year";
})(Duration = exports.Duration || (exports.Duration = {}));
const isNonNegativeInteger = number => Number.isInteger(number) && number >= 0;
const assertIsNonNegativeInteger = (number, name) => {
if (!isNonNegativeInteger(number)) {
throw new Error(`"${name}" must be a non-negative integer. Received: "${number}".`);
}
};
function inMilliseconds(count, duration) {
assertIsNonNegativeInteger(count, 'count');
return count * duration;
}
exports.inMilliseconds = inMilliseconds;
function timeSince(timestamp) {
assertIsNonNegativeInteger(timestamp, 'timestamp');
return Date.now() - timestamp;
}
exports.timeSince = timeSince;
}, {}],
21: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
}, {}],
22: [function (require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.satisfiesVersionRange = exports.gtRange = exports.gtVersion = exports.assertIsSemVerRange = exports.assertIsSemVerVersion = exports.isValidSemVerRange = exports.isValidSemVerVersion = exports.VersionRangeStruct = exports.VersionStruct = void 0;
const semver_1 = require("semver");
const superstruct_1 = require("superstruct");
const assert_1 = require("./assert");
exports.VersionStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'Version', value => {
if ((0, semver_1.valid)(value) === null) {
return `Expected SemVer version, got "${value}"`;
}
return true;
});
exports.VersionRangeStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'Version range', value => {
if ((0, semver_1.validRange)(value) === null) {
return `Expected SemVer range, got "${value}"`;
}
return true;
});
function isValidSemVerVersion(version) {
return (0, superstruct_1.is)(version, exports.VersionStruct);
}
exports.isValidSemVerVersion = isValidSemVerVersion;
function isValidSemVerRange(versionRange) {
return (0, superstruct_1.is)(versionRange, exports.VersionRangeStruct);
}
exports.isValidSemVerRange = isValidSemVerRange;
function assertIsSemVerVersion(version) {
(0, assert_1.assertStruct)(version, exports.VersionStruct);
}
exports.assertIsSemVerVersion = assertIsSemVerVersion;
function assertIsSemVerRange(range) {
(0, assert_1.assertStruct)(range, exports.VersionRangeStruct);
}
exports.assertIsSemVerRange = assertIsSemVerRange;
function gtVersion(version1, version2) {
return (0, semver_1.gt)(version1, version2);
}
exports.gtVersion = gtVersion;
function gtRange(version, range) {
return (0, semver_1.gtr)(version, range);
}
expo