UNPKG

@tuum-tech/identify

Version:

A snap for managing Decentralized Identifiers(DIDs)

1,461 lines (1,452 loc) 6.98 MB
var self = window; (() => { var __webpack_modules__ = [, function (__unused_webpack_module, exports, __webpack_require__) { "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(__webpack_require__(2), exports); __exportStar(__webpack_require__(80), exports); __exportStar(__webpack_require__(81), exports); }, (__unused_webpack_module, exports, __webpack_require__) => { "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 = __webpack_require__(3); const nodes_1 = __webpack_require__(80); 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) => { if (args[index] !== undefined) { return { ...partialNode, [key]: args[index] }; } return partialNode; }, { 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', 'markdown']); }, function (__unused_webpack_module, exports, __webpack_require__) { "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(__webpack_require__(4), exports); __exportStar(__webpack_require__(6), exports); __exportStar(__webpack_require__(7), exports); __exportStar(__webpack_require__(17), exports); __exportStar(__webpack_require__(18), exports); __exportStar(__webpack_require__(19), exports); __exportStar(__webpack_require__(20), exports); __exportStar(__webpack_require__(8), exports); __exportStar(__webpack_require__(21), exports); __exportStar(__webpack_require__(22), exports); __exportStar(__webpack_require__(23), exports); __exportStar(__webpack_require__(27), exports); __exportStar(__webpack_require__(28), exports); __exportStar(__webpack_require__(29), exports); __exportStar(__webpack_require__(30), exports); __exportStar(__webpack_require__(31), exports); __exportStar(__webpack_require__(32), exports); }, (__unused_webpack_module, exports, __webpack_require__) => { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assertExhaustive = exports.assertStruct = exports.assert = exports.AssertionError = void 0; const superstruct_1 = __webpack_require__(5); function isErrorWithMessage(error) { return typeof error === 'object' && error !== null && 'message' in error; } function isConstructable(fn) { return Boolean(typeof fn?.prototype?.constructor?.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; }, (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { Struct: () => Struct, StructError: () => StructError, any: () => any, array: () => array, assert: () => assert, assign: () => assign, bigint: () => bigint, boolean: () => boolean, coerce: () => coerce, create: () => create, date: () => date, defaulted: () => defaulted, define: () => define, deprecated: () => deprecated, dynamic: () => dynamic, empty: () => empty, enums: () => enums, func: () => func, instance: () => instance, integer: () => integer, intersection: () => intersection, is: () => is, lazy: () => lazy, literal: () => literal, map: () => map, mask: () => mask, max: () => max, min: () => min, never: () => never, nonempty: () => nonempty, nullable: () => nullable, number: () => number, object: () => object, omit: () => omit, optional: () => optional, partial: () => partial, pattern: () => pattern, pick: () => pick, record: () => record, refine: () => refine, regexp: () => regexp, set: () => set, size: () => size, string: () => string, struct: () => struct, trimmed: () => trimmed, tuple: () => tuple, type: () => type, union: () => union, unknown: () => unknown, validate: () => validate }); class StructError extends TypeError { constructor(failure, failures) { let cached; const { message, explanation, ...rest } = failure; const { path } = failure; const msg = path.length === 0 ? message : `At path: ${path.join('.')} -- ${message}`; super(explanation ?? msg); if (explanation != null) this.cause = msg; Object.assign(this, rest); this.name = this.constructor.name; this.failures = () => { return cached ?? (cached = [failure, ...failures()]); }; } } function isIterable(x) { return isObject(x) && typeof x[Symbol.iterator] === 'function'; } function isObject(x) { return typeof x === 'object' && x != null; } function isPlainObject(x) { if (Object.prototype.toString.call(x) !== '[object Object]') { return false; } const prototype = Object.getPrototypeOf(x); return prototype === null || prototype === Object.prototype; } function print(value) { if (typeof value === 'symbol') { return value.toString(); } return typeof value === 'string' ? JSON.stringify(value) : `${value}`; } function shiftIterator(input) { const { done, value } = input.next(); return done ? undefined : value; } function toFailure(result, context, struct, value) { if (result === true) { return; } else if (result === false) { result = {}; } else if (typeof result === 'string') { result = { message: result }; } const { path, branch } = context; const { type } = struct; const { refinement, message = `Expected a value of type \`${type}\`${refinement ? ` with refinement \`${refinement}\`` : ''}, but received: \`${print(value)}\`` } = result; return { value, type, refinement, key: path[path.length - 1], path, branch, ...result, message }; } function* toFailures(result, context, struct, value) { if (!isIterable(result)) { result = [result]; } for (const r of result) { const failure = toFailure(r, context, struct, value); if (failure) { yield failure; } } } function* run(value, struct, options = {}) { const { path = [], branch = [value], coerce = false, mask = false } = options; const ctx = { path, branch }; if (coerce) { value = struct.coercer(value, ctx); if (mask && struct.type !== 'type' && isObject(struct.schema) && isObject(value) && !Array.isArray(value)) { for (const key in value) { if (struct.schema[key] === undefined) { delete value[key]; } } } } let status = 'valid'; for (const failure of struct.validator(value, ctx)) { failure.explanation = options.message; status = 'not_valid'; yield [failure, undefined]; } for (let [k, v, s] of struct.entries(value, ctx)) { const ts = run(v, s, { path: k === undefined ? path : [...path, k], branch: k === undefined ? branch : [...branch, v], coerce, mask, message: options.message }); for (const t of ts) { if (t[0]) { status = t[0].refinement != null ? 'not_refined' : 'not_valid'; yield [t[0], undefined]; } else if (coerce) { v = t[1]; if (k === undefined) { value = v; } else if (value instanceof Map) { value.set(k, v); } else if (value instanceof Set) { value.add(v); } else if (isObject(value)) { if (v !== undefined || k in value) value[k] = v; } } } } if (status !== 'not_valid') { for (const failure of struct.refiner(value, ctx)) { failure.explanation = options.message; status = 'not_refined'; yield [failure, undefined]; } } if (status === 'valid') { yield [undefined, value]; } } class Struct { constructor(props) { const { type, schema, validator, refiner, coercer = value => value, entries = function* () {} } = props; this.type = type; this.schema = schema; this.entries = entries; this.coercer = coercer; if (validator) { this.validator = (value, context) => { const result = validator(value, context); return toFailures(result, context, this, value); }; } else { this.validator = () => []; } if (refiner) { this.refiner = (value, context) => { const result = refiner(value, context); return toFailures(result, context, this, value); }; } else { this.refiner = () => []; } } assert(value, message) { return assert(value, this, message); } create(value, message) { return create(value, this, message); } is(value) { return is(value, this); } mask(value, message) { return mask(value, this, message); } validate(value, options = {}) { return validate(value, this, options); } } function assert(value, struct, message) { const result = validate(value, struct, { message }); if (result[0]) { throw result[0]; } } function create(value, struct, message) { const result = validate(value, struct, { coerce: true, message }); if (result[0]) { throw result[0]; } else { return result[1]; } } function mask(value, struct, message) { const result = validate(value, struct, { coerce: true, mask: true, message }); if (result[0]) { throw result[0]; } else { return result[1]; } } function is(value, struct) { const result = validate(value, struct); return !result[0]; } function validate(value, struct, options = {}) { const tuples = run(value, struct, options); const tuple = shiftIterator(tuples); if (tuple[0]) { const error = new StructError(tuple[0], function* () { for (const t of tuples) { if (t[0]) { yield t[0]; } } }); return [error, undefined]; } else { const v = tuple[1]; return [undefined, v]; } } function assign(...Structs) { const isType = Structs[0].type === 'type'; const schemas = Structs.map(s => s.schema); const schema = Object.assign({}, ...schemas); return isType ? type(schema) : object(schema); } function define(name, validator) { return new Struct({ type: name, schema: null, validator }); } function deprecated(struct, log) { return new Struct({ ...struct, refiner: (value, ctx) => value === undefined || struct.refiner(value, ctx), validator(value, ctx) { if (value === undefined) { return true; } else { log(value, ctx); return struct.validator(value, ctx); } } }); } function dynamic(fn) { return new Struct({ type: 'dynamic', schema: null, *entries(value, ctx) { const struct = fn(value, ctx); yield* struct.entries(value, ctx); }, validator(value, ctx) { const struct = fn(value, ctx); return struct.validator(value, ctx); }, coercer(value, ctx) { const struct = fn(value, ctx); return struct.coercer(value, ctx); }, refiner(value, ctx) { const struct = fn(value, ctx); return struct.refiner(value, ctx); } }); } function lazy(fn) { let struct; return new Struct({ type: 'lazy', schema: null, *entries(value, ctx) { struct ?? (struct = fn()); yield* struct.entries(value, ctx); }, validator(value, ctx) { struct ?? (struct = fn()); return struct.validator(value, ctx); }, coercer(value, ctx) { struct ?? (struct = fn()); return struct.coercer(value, ctx); }, refiner(value, ctx) { struct ?? (struct = fn()); return struct.refiner(value, ctx); } }); } function omit(struct, keys) { const { schema } = struct; const subschema = { ...schema }; for (const key of keys) { delete subschema[key]; } switch (struct.type) { case 'type': return type(subschema); default: return object(subschema); } } function partial(struct) { const schema = struct instanceof Struct ? { ...struct.schema } : { ...struct }; for (const key in schema) { schema[key] = optional(schema[key]); } return object(schema); } function pick(struct, keys) { const { schema } = struct; const subschema = {}; for (const key of keys) { subschema[key] = schema[key]; } return object(subschema); } function struct(name, validator) { console.warn('superstruct@0.11 - The `struct` helper has been renamed to `define`.'); return define(name, validator); } function any() { return define('any', () => true); } function array(Element) { return new Struct({ type: 'array', schema: Element, *entries(value) { if (Element && Array.isArray(value)) { for (const [i, v] of value.entries()) { yield [i, v, Element]; } } }, coercer(value) { return Array.isArray(value) ? value.slice() : value; }, validator(value) { return Array.isArray(value) || `Expected an array value, but received: ${print(value)}`; } }); } function bigint() { return define('bigint', value => { return typeof value === 'bigint'; }); } function boolean() { return define('boolean', value => { return typeof value === 'boolean'; }); } function date() { return define('date', value => { return value instanceof Date && !isNaN(value.getTime()) || `Expected a valid \`Date\` object, but received: ${print(value)}`; }); } function enums(values) { const schema = {}; const description = values.map(v => print(v)).join(); for (const key of values) { schema[key] = key; } return new Struct({ type: 'enums', schema, validator(value) { return values.includes(value) || `Expected one of \`${description}\`, but received: ${print(value)}`; } }); } function func() { return define('func', value => { return typeof value === 'function' || `Expected a function, but received: ${print(value)}`; }); } function instance(Class) { return define('instance', value => { return value instanceof Class || `Expected a \`${Class.name}\` instance, but received: ${print(value)}`; }); } function integer() { return define('integer', value => { return typeof value === 'number' && !isNaN(value) && Number.isInteger(value) || `Expected an integer, but received: ${print(value)}`; }); } function intersection(Structs) { return new Struct({ type: 'intersection', schema: null, *entries(value, ctx) { for (const S of Structs) { yield* S.entries(value, ctx); } }, *validator(value, ctx) { for (const S of Structs) { yield* S.validator(value, ctx); } }, *refiner(value, ctx) { for (const S of Structs) { yield* S.refiner(value, ctx); } } }); } function literal(constant) { const description = print(constant); const t = typeof constant; return new Struct({ type: 'literal', schema: t === 'string' || t === 'number' || t === 'boolean' ? constant : null, validator(value) { return value === constant || `Expected the literal \`${description}\`, but received: ${print(value)}`; } }); } function map(Key, Value) { return new Struct({ type: 'map', schema: null, *entries(value) { if (Key && Value && value instanceof Map) { for (const [k, v] of value.entries()) { yield [k, k, Key]; yield [k, v, Value]; } } }, coercer(value) { return value instanceof Map ? new Map(value) : value; }, validator(value) { return value instanceof Map || `Expected a \`Map\` object, but received: ${print(value)}`; } }); } function never() { return define('never', () => false); } function nullable(struct) { return new Struct({ ...struct, validator: (value, ctx) => value === null || struct.validator(value, ctx), refiner: (value, ctx) => value === null || struct.refiner(value, ctx) }); } function number() { return define('number', value => { return typeof value === 'number' && !isNaN(value) || `Expected a number, but received: ${print(value)}`; }); } function object(schema) { const knowns = schema ? Object.keys(schema) : []; const Never = never(); return new Struct({ type: 'object', schema: schema ? schema : null, *entries(value) { if (schema && isObject(value)) { const unknowns = new Set(Object.keys(value)); for (const key of knowns) { unknowns.delete(key); yield [key, value[key], schema[key]]; } for (const key of unknowns) { yield [key, value[key], Never]; } } }, validator(value) { return isObject(value) || `Expected an object, but received: ${print(value)}`; }, coercer(value) { return isObject(value) ? { ...value } : value; } }); } function optional(struct) { return new Struct({ ...struct, validator: (value, ctx) => value === undefined || struct.validator(value, ctx), refiner: (value, ctx) => value === undefined || struct.refiner(value, ctx) }); } function record(Key, Value) { return new Struct({ type: 'record', schema: null, *entries(value) { if (isObject(value)) { for (const k in value) { const v = value[k]; yield [k, k, Key]; yield [k, v, Value]; } } }, validator(value) { return isObject(value) || `Expected an object, but received: ${print(value)}`; } }); } function regexp() { return define('regexp', value => { return value instanceof RegExp; }); } function set(Element) { return new Struct({ type: 'set', schema: null, *entries(value) { if (Element && value instanceof Set) { for (const v of value) { yield [v, v, Element]; } } }, coercer(value) { return value instanceof Set ? new Set(value) : value; }, validator(value) { return value instanceof Set || `Expected a \`Set\` object, but received: ${print(value)}`; } }); } function string() { return define('string', value => { return typeof value === 'string' || `Expected a string, but received: ${print(value)}`; }); } function tuple(Structs) { const Never = never(); return new Struct({ type: 'tuple', schema: null, *entries(value) { if (Array.isArray(value)) { const length = Math.max(Structs.length, value.length); for (let i = 0; i < length; i++) { yield [i, value[i], Structs[i] || Never]; } } }, validator(value) { return Array.isArray(value) || `Expected an array, but received: ${print(value)}`; } }); } function type(schema) { const keys = Object.keys(schema); return new Struct({ type: 'type', schema, *entries(value) { if (isObject(value)) { for (const k of keys) { yield [k, value[k], schema[k]]; } } }, validator(value) { return isObject(value) || `Expected an object, but received: ${print(value)}`; }, coercer(value) { return isObject(value) ? { ...value } : value; } }); } function union(Structs) { const description = Structs.map(s => s.type).join(' | '); return new Struct({ type: 'union', schema: null, coercer(value) { for (const S of Structs) { const [error, coerced] = S.validate(value, { coerce: true }); if (!error) { return coerced; } } return value; }, validator(value, ctx) { const failures = []; for (const S of Structs) { const [...tuples] = run(value, S, ctx); const [first] = tuples; if (!first[0]) { return []; } else { for (const [failure] of tuples) { if (failure) { failures.push(failure); } } } } return [`Expected the value to satisfy a union of \`${description}\`, but received: ${print(value)}`, ...failures]; } }); } function unknown() { return define('unknown', () => true); } function coerce(struct, condition, coercer) { return new Struct({ ...struct, coercer: (value, ctx) => { return is(value, condition) ? struct.coercer(coercer(value, ctx), ctx) : struct.coercer(value, ctx); } }); } function defaulted(struct, fallback, options = {}) { return coerce(struct, unknown(), x => { const f = typeof fallback === 'function' ? fallback() : fallback; if (x === undefined) { return f; } if (!options.strict && isPlainObject(x) && isPlainObject(f)) { const ret = { ...x }; let changed = false; for (const key in f) { if (ret[key] === undefined) { ret[key] = f[key]; changed = true; } } if (changed) { return ret; } } return x; }); } function trimmed(struct) { return coerce(struct, string(), x => x.trim()); } function empty(struct) { return refine(struct, 'empty', value => { const size = getSize(value); return size === 0 || `Expected an empty ${struct.type} but received one with a size of \`${size}\``; }); } function getSize(value) { if (value instanceof Map || value instanceof Set) { return value.size; } else { return value.length; } } function max(struct, threshold, options = {}) { const { exclusive } = options; return refine(struct, 'max', value => { return exclusive ? value < threshold : value <= threshold || `Expected a ${struct.type} less than ${exclusive ? '' : 'or equal to '}${threshold} but received \`${value}\``; }); } function min(struct, threshold, options = {}) { const { exclusive } = options; return refine(struct, 'min', value => { return exclusive ? value > threshold : value >= threshold || `Expected a ${struct.type} greater than ${exclusive ? '' : 'or equal to '}${threshold} but received \`${value}\``; }); } function nonempty(struct) { return refine(struct, 'nonempty', value => { const size = getSize(value); return size > 0 || `Expected a nonempty ${struct.type} but received an empty one`; }); } function pattern(struct, regexp) { return refine(struct, 'pattern', value => { return regexp.test(value) || `Expected a ${struct.type} matching \`/${regexp.source}/\` but received "${value}"`; }); } function size(struct, min, max = min) { const expected = `Expected a ${struct.type}`; const of = min === max ? `of \`${min}\`` : `between \`${min}\` and \`${max}\``; return refine(struct, 'size', value => { if (typeof value === 'number' || value instanceof Date) { return min <= value && value <= max || `${expected} ${of} but received \`${value}\``; } else if (value instanceof Map || value instanceof Set) { const { size } = value; return min <= size && size <= max || `${expected} with a size ${of} but received one with a size of \`${size}\``; } else { const { length } = value; return min <= length && length <= max || `${expected} with a length ${of} but received one with a length of \`${length}\``; } }); } function refine(struct, name, refiner) { return new Struct({ ...struct, *refiner(value, ctx) { yield* struct.refiner(value, ctx); const result = refiner(value, ctx); const failures = toFailures(result, ctx, struct, value); for (const failure of failures) { yield { ...failure, refinement: name }; } } }); } }, (__unused_webpack_module, exports, __webpack_require__) => { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.base64 = void 0; const superstruct_1 = __webpack_require__(5); const assert_1 = __webpack_require__(4); const base64 = (struct, options = {}) => { const paddingRequired = options.paddingRequired ?? false; const characterSet = options.characterSet ?? '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; }, (__unused_webpack_module, exports, __webpack_require__) => { "use strict"; var Buffer = __webpack_require__(14)["Buffer"]; 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 = __webpack_require__(4); const hex_1 = __webpack_require__(8); 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) { if (value?.toLowerCase?.() === '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; }, (__unused_webpack_module, exports, __webpack_require__) => { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.remove0x = exports.add0x = exports.isValidChecksumAddress = exports.getChecksumAddress = exports.isValidHexAddress = exports.assertIsStrictHexString = exports.assertIsHexString = exports.isStrictHexString = exports.isHexString = exports.HexChecksumAddressStruct = exports.HexAddressStruct = exports.StrictHexStruct = exports.HexStruct = void 0; const sha3_1 = __webpack_require__(9); const superstruct_1 = __webpack_require__(5); const assert_1 = __webpack_require__(4); const bytes_1 = __webpack_require__(7); 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); exports.HexAddressStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), /^0x[0-9a-f]{40}$/u); exports.HexChecksumAddressStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), /^0x[0-9a-fA-F]{40}$/u); 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 isValidHexAddress(possibleAddress) { return (0, superstruct_1.is)(possibleAddress, exports.HexAddressStruct) || isValidChecksumAddress(possibleAddress); } exports.isValidHexAddress = isValidHexAddress; function getChecksumAddress(address) { (0, assert_1.assert)((0, superstruct_1.is)(address, exports.HexChecksumAddressStruct), 'Invalid hex address.'); const unPrefixed = remove0x(address.toLowerCase()); const unPrefixedHash = remove0x((0, bytes_1.bytesToHex)((0, sha3_1.keccak_256)(unPrefixed))); return `0x${unPrefixed.split('').map((character, nibbleIndex) => { const hashCharacter = unPrefixedHash[nibbleIndex]; (0, assert_1.assert)((0, superstruct_1.is)(hashCharacter, (0, superstruct_1.string)()), 'Hash shorter than address.'); return parseInt(hashCharacter, 16) > 7 ? character.toUpperCase() : character; }).join('')}`; } exports.getChecksumAddress = getChecksumAddress; function isValidChecksumAddress(possibleChecksum) { if (!(0, superstruct_1.is)(possibleChecksum, exports.HexChecksumAddressStruct)) { return false; } return getChecksumAddress(possibleChecksum) === possibleChecksum; } exports.isValidChecksumAddress = isValidChecksumAddress; 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; }, (__unused_webpack_module, exports, __webpack_require__) => { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shake256 = exports.shake128 = exports.keccak_512 = exports.keccak_384 = exports.keccak_256 = exports.keccak_224 = exports.sha3_512 = exports.sha3_384 = exports.sha3_256 = exports.sha3_224 = exports.Keccak = exports.keccakP = void 0; const _assert_js_1 = __webpack_require__(10); const _u64_js_1 = __webpack_require__(11); const utils_js_1 = __webpack_require__(12); const [SHA3_PI, SHA3_ROTL, _SHA3_IOTA] = [[], [], []]; const _0n = BigInt(0); const _1n = BigInt(1); const _2n = BigInt(2); const _7n = BigInt(7); const _256n = BigInt(256); const _0x71n = BigInt(0x71); for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) { [x, y] = [y, (2 * x + 3 * y) % 5]; SHA3_PI.push(2 * (5 * y + x)); SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64); let t = _0n; for (let j = 0; j < 7; j++) { R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n; if (R & _2n) t ^= _1n << (_1n << BigInt(j)) - _1n; } _SHA3_IOTA.push(t); } const [SHA3_IOTA_H, SHA3_IOTA_L] = _u64_js_1.default.split(_SHA3_IOTA, true); const rotlH = (h, l, s) => s > 32 ? _u64_js_1.default.rotlBH(h, l, s) : _u64_js_1.default.rotlSH(h, l, s); const rotlL = (h, l, s) => s > 32 ? _u64_js_1.default.rotlBL(h, l, s) : _u64_js_1.default.rotlSL(h, l, s); function keccakP(s, rounds = 24) { const B = new Uint32Array(5 * 2); for (let round = 24 - rounds; round < 24; round++) { for (let x = 0; x < 10; x++) B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40]; for (let x = 0; x < 10; x += 2) { const idx1 = (x + 8) % 10; const idx0 = (x + 2) % 10; const B0 = B[idx0]; const B1 = B[idx0 + 1]; const Th = rotlH(B0, B1, 1) ^ B[idx1]; const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1]; for (let y = 0; y < 50; y += 10) { s[x + y] ^= Th; s[x + y + 1] ^= Tl; } } let curH = s[2]; let curL = s[3]; for (let t = 0; t < 24; t++) { const shift = SHA3_ROTL[t]; const Th = rotlH(curH, curL, shift); const Tl = rotlL(curH, curL, shift); const PI = SHA3_PI[t]; curH = s[PI]; curL = s[PI + 1]; s[PI] = Th; s[PI + 1] = Tl; } for (let y = 0; y < 50; y += 10) { for (let x = 0; x < 10; x++) B[x] = s[y + x]; for (let x = 0; x < 10; x++) s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10]; } s[0] ^= SHA3_IOTA_H[round]; s[1] ^= SHA3_IOTA_L[round]; } B.fill(0); } exports.keccakP = keccakP; class Keccak extends utils_js_1.Hash { constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) { super(); this.blockLen = blockLen; this.suffix = suffix; this.outputLen = outputLen; this.enableXOF = enableXOF; this.rounds = rounds; this.pos = 0; this.posOut = 0; this.finished = false; this.destroyed = false; _assert_js_1.default.number(outputLen); if (0 >= this.blockLen || this.blockLen >= 200) throw new Error('Sha3 supports only keccak-f1600 function'); this.state = new Uint8Array(200); this.state32 = (0, utils_js_1.u32)(this.state); } keccak() { keccakP(this.state32, this.rounds); this.posOut = 0; this.pos = 0; } update(data) { _assert_js_1.default.exists(this); const { blockLen, state } = this; data = (0, utils_js_1.toBytes)(data); const len = data.length; for (let pos = 0; pos < len;) { const take = Math.min(blockLen - this.pos, len - pos); for (let i = 0; i < take; i++) state[this.pos++] ^= data[pos++]; if (this.pos === blockLen) this.keccak(); } return this; } finish() { if (this.finished) return; this.finished = true; const { state, suffix, pos, blockLen } = this; state[pos] ^= suffix; if ((suffix & 0x80) !== 0 && pos === blockLen - 1) this.keccak(); state[blockLen - 1] ^= 0x80; this.keccak(); } writeInto(out) { _assert_js_1.default.exists(this, false); _assert_js_1.default.bytes(out); this.finish(); const bufferOut = this.state; const { blockLen } = this; for (let pos = 0, len = out.length; pos < len;) { if (this.posOut >= blockLen) this.keccak(); const take = Math.min(blockLen - this.posOut, len - pos); out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos); this.posOut += take; pos += take; } return out; } xofInto(out) { if (!this.enableXOF) throw new Error('XOF is not possible for this instance'); return this.writeInto(out); } xof(bytes) { _assert_js_1.default.number(bytes); return this.xofInto(new Uint8Array(bytes)); } digestInto(out) { _assert_js_1.default.output(out, this); if (this.finished) throw new Error('digest() was already called'); this.writeInto(out); this.destroy(); return out; } digest() { return this.digestInto(new Uint8Array(this.outputLen)); } destroy() { this.destroyed = true; this.state.fill(0); } _cloneInto(to) { const { blockLen, suffix, outputLen, rounds, enableXOF } = this; to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds)); to.state32.set(this.state32); to.pos = this.pos; to.posOut = this.posOut; to.finished = this.finished; to.rounds = rounds; to.suffix = suffix; to.outputLen = outputLen; to.enableXOF = enableXOF; to.destroyed = this.destroyed; return to; } } exports.Keccak = Keccak; const gen = (suffix, blockLen, outputLen) => (0, utils_js_1.wrapConstructor)(() => new Keccak(blockLen, suffix, outputLen)); exports.sha3_224 = gen(0x06, 144, 224 / 8); exports.sha3_256 = gen(0x06, 136, 256 / 8); exports.sha3_384 = gen(0x06, 104, 384 / 8); exports.sha3_512 = gen(0x06, 72, 512 / 8); exports.keccak_224 = gen(0x01, 144, 224 / 8); exports.keccak_256 = gen(0x01, 136, 256 / 8); exports.keccak_384 = gen(0x01, 104, 384 / 8); exports.keccak_512 = gen(0x01, 72, 512 / 8); const genShake = (suffix, blockLen, outputLen) => (0, utils_js_1.wrapXOFConstructorWithOpts)((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === undefined ? outputLen : opts.dkLen, true)); exports.shake128 = genSha