UNPKG

@cityofzion/neon-js

Version:

Neon-JS SDK for interacting with NEO blockchain

1,282 lines (1,246 loc) 1.87 MB
/******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 8463 (__unused_webpack_module, exports) { "use strict"; /** * Hex, bytes and number utilities. * @module */ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.notImplemented = exports.bitMask = void 0; exports.isBytes = isBytes; exports.abytes = abytes; exports.abool = abool; exports.numberToHexUnpadded = numberToHexUnpadded; exports.hexToNumber = hexToNumber; exports.bytesToHex = bytesToHex; exports.hexToBytes = hexToBytes; exports.bytesToNumberBE = bytesToNumberBE; exports.bytesToNumberLE = bytesToNumberLE; exports.numberToBytesBE = numberToBytesBE; exports.numberToBytesLE = numberToBytesLE; exports.numberToVarBytesBE = numberToVarBytesBE; exports.ensureBytes = ensureBytes; exports.concatBytes = concatBytes; exports.equalBytes = equalBytes; exports.utf8ToBytes = utf8ToBytes; exports.inRange = inRange; exports.aInRange = aInRange; exports.bitLen = bitLen; exports.bitGet = bitGet; exports.bitSet = bitSet; exports.createHmacDrbg = createHmacDrbg; exports.validateObject = validateObject; exports.memoized = memoized; // 100 lines of code in the file are duplicated from noble-hashes (utils). // This is OK: `abstract` directory does not use noble-hashes. // User may opt-in into using different hashing library. This way, noble-hashes // won't be included into their bundle. const _0n = /* @__PURE__ */ BigInt(0); const _1n = /* @__PURE__ */ BigInt(1); function isBytes(a) { return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array'); } function abytes(item) { if (!isBytes(item)) throw new Error('Uint8Array expected'); } function abool(title, value) { if (typeof value !== 'boolean') throw new Error(title + ' boolean expected, got ' + value); } // Used in weierstrass, der function numberToHexUnpadded(num) { const hex = num.toString(16); return hex.length & 1 ? '0' + hex : hex; } function hexToNumber(hex) { if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex); return hex === '' ? _0n : BigInt('0x' + hex); // Big Endian } // Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex const hasHexBuiltin = // @ts-ignore typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function'; // Array where index 0xf0 (240) is mapped to string 'f0' const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0')); /** * Convert byte array to hex string. Uses built-in function, when available. * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123' */ function bytesToHex(bytes) { abytes(bytes); // @ts-ignore if (hasHexBuiltin) return bytes.toHex(); // pre-caching improves the speed 6x let hex = ''; for (let i = 0; i < bytes.length; i++) { hex += hexes[bytes[i]]; } return hex; } // We use optimized technique to convert hex string to byte array const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 }; function asciiToBase16(ch) { if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0; // '2' => 50-48 if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10); // 'B' => 66-(65-10) if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10); // 'b' => 98-(97-10) return; } /** * Convert hex string to byte array. Uses built-in function, when available. * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23]) */ function hexToBytes(hex) { if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex); // @ts-ignore if (hasHexBuiltin) return Uint8Array.fromHex(hex); const hl = hex.length; const al = hl / 2; if (hl % 2) throw new Error('hex string expected, got unpadded hex of length ' + hl); const array = new Uint8Array(al); for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) { const n1 = asciiToBase16(hex.charCodeAt(hi)); const n2 = asciiToBase16(hex.charCodeAt(hi + 1)); if (n1 === undefined || n2 === undefined) { const char = hex[hi] + hex[hi + 1]; throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi); } array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163 } return array; } // BE: Big Endian, LE: Little Endian function bytesToNumberBE(bytes) { return hexToNumber(bytesToHex(bytes)); } function bytesToNumberLE(bytes) { abytes(bytes); return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse())); } function numberToBytesBE(n, len) { return hexToBytes(n.toString(16).padStart(len * 2, '0')); } function numberToBytesLE(n, len) { return numberToBytesBE(n, len).reverse(); } // Unpadded, rarely used function numberToVarBytesBE(n) { return hexToBytes(numberToHexUnpadded(n)); } /** * Takes hex string or Uint8Array, converts to Uint8Array. * Validates output length. * Will throw error for other types. * @param title descriptive title for an error e.g. 'private key' * @param hex hex string or Uint8Array * @param expectedLength optional, will compare to result array's length * @returns */ function ensureBytes(title, hex, expectedLength) { let res; if (typeof hex === 'string') { try { res = hexToBytes(hex); } catch (e) { throw new Error(title + ' must be hex string or Uint8Array, cause: ' + e); } } else if (isBytes(hex)) { // Uint8Array.from() instead of hash.slice() because node.js Buffer // is instance of Uint8Array, and its slice() creates **mutable** copy res = Uint8Array.from(hex); } else { throw new Error(title + ' must be hex string or Uint8Array'); } const len = res.length; if (typeof expectedLength === 'number' && len !== expectedLength) throw new Error(title + ' of length ' + expectedLength + ' expected, got ' + len); return res; } /** * Copies several Uint8Arrays into one. */ function concatBytes(...arrays) { let sum = 0; for (let i = 0; i < arrays.length; i++) { const a = arrays[i]; abytes(a); sum += a.length; } const res = new Uint8Array(sum); for (let i = 0, pad = 0; i < arrays.length; i++) { const a = arrays[i]; res.set(a, pad); pad += a.length; } return res; } // Compares 2 u8a-s in kinda constant time function equalBytes(a, b) { if (a.length !== b.length) return false; let diff = 0; for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i]; return diff === 0; } /** * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99]) */ function utf8ToBytes(str) { if (typeof str !== 'string') throw new Error('string expected'); return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809 } // Is positive bigint const isPosBig = (n) => typeof n === 'bigint' && _0n <= n; function inRange(n, min, max) { return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max; } /** * Asserts min <= n < max. NOTE: It's < max and not <= max. * @example * aInRange('x', x, 1n, 256n); // would assume x is in (1n..255n) */ function aInRange(title, n, min, max) { // Why min <= n < max and not a (min < n < max) OR b (min <= n <= max)? // consider P=256n, min=0n, max=P // - a for min=0 would require -1: `inRange('x', x, -1n, P)` // - b would commonly require subtraction: `inRange('x', x, 0n, P - 1n)` // - our way is the cleanest: `inRange('x', x, 0n, P) if (!inRange(n, min, max)) throw new Error('expected valid ' + title + ': ' + min + ' <= n < ' + max + ', got ' + n); } // Bit operations /** * Calculates amount of bits in a bigint. * Same as `n.toString(2).length` * TODO: merge with nLength in modular */ function bitLen(n) { let len; for (len = 0; n > _0n; n >>= _1n, len += 1) ; return len; } /** * Gets single bit at position. * NOTE: first bit position is 0 (same as arrays) * Same as `!!+Array.from(n.toString(2)).reverse()[pos]` */ function bitGet(n, pos) { return (n >> BigInt(pos)) & _1n; } /** * Sets single bit at position. */ function bitSet(n, pos, value) { return n | ((value ? _1n : _0n) << BigInt(pos)); } /** * Calculate mask for N bits. Not using ** operator with bigints because of old engines. * Same as BigInt(`0b${Array(i).fill('1').join('')}`) */ const bitMask = (n) => (_1n << BigInt(n)) - _1n; exports.bitMask = bitMask; // DRBG const u8n = (len) => new Uint8Array(len); // creates Uint8Array const u8fr = (arr) => Uint8Array.from(arr); // another shortcut /** * Minimal HMAC-DRBG from NIST 800-90 for RFC6979 sigs. * @returns function that will call DRBG until 2nd arg returns something meaningful * @example * const drbg = createHmacDRBG<Key>(32, 32, hmac); * drbg(seed, bytesToKey); // bytesToKey must return Key or undefined */ function createHmacDrbg(hashLen, qByteLen, hmacFn) { if (typeof hashLen !== 'number' || hashLen < 2) throw new Error('hashLen must be a number'); if (typeof qByteLen !== 'number' || qByteLen < 2) throw new Error('qByteLen must be a number'); if (typeof hmacFn !== 'function') throw new Error('hmacFn must be a function'); // Step B, Step C: set hashLen to 8*ceil(hlen/8) let v = u8n(hashLen); // Minimal non-full-spec HMAC-DRBG from NIST 800-90 for RFC6979 sigs. let k = u8n(hashLen); // Steps B and C of RFC6979 3.2: set hashLen, in our case always same let i = 0; // Iterations counter, will throw when over 1000 const reset = () => { v.fill(1); k.fill(0); i = 0; }; const h = (...b) => hmacFn(k, v, ...b); // hmac(k)(v, ...values) const reseed = (seed = u8n(0)) => { // HMAC-DRBG reseed() function. Steps D-G k = h(u8fr([0x00]), seed); // k = hmac(k || v || 0x00 || seed) v = h(); // v = hmac(k || v) if (seed.length === 0) return; k = h(u8fr([0x01]), seed); // k = hmac(k || v || 0x01 || seed) v = h(); // v = hmac(k || v) }; const gen = () => { // HMAC-DRBG generate() function if (i++ >= 1000) throw new Error('drbg: tried 1000 values'); let len = 0; const out = []; while (len < qByteLen) { v = h(); const sl = v.slice(); out.push(sl); len += v.length; } return concatBytes(...out); }; const genUntil = (seed, pred) => { reset(); reseed(seed); // Steps D-G let res = undefined; // Step H: grind until k is in [1..n-1] while (!(res = pred(gen()))) reseed(); reset(); return res; }; return genUntil; } // Validating curves and fields const validatorFns = { bigint: (val) => typeof val === 'bigint', function: (val) => typeof val === 'function', boolean: (val) => typeof val === 'boolean', string: (val) => typeof val === 'string', stringOrUint8Array: (val) => typeof val === 'string' || isBytes(val), isSafeInteger: (val) => Number.isSafeInteger(val), array: (val) => Array.isArray(val), field: (val, object) => object.Fp.isValid(val), hash: (val) => typeof val === 'function' && Number.isSafeInteger(val.outputLen), }; // type Record<K extends string | number | symbol, T> = { [P in K]: T; } function validateObject(object, validators, optValidators = {}) { const checkField = (fieldName, type, isOptional) => { const checkVal = validatorFns[type]; if (typeof checkVal !== 'function') throw new Error('invalid validator function'); const val = object[fieldName]; if (isOptional && val === undefined) return; if (!checkVal(val, object)) { throw new Error('param ' + String(fieldName) + ' is invalid. Expected ' + type + ', got ' + val); } }; for (const [fieldName, type] of Object.entries(validators)) checkField(fieldName, type, false); for (const [fieldName, type] of Object.entries(optValidators)) checkField(fieldName, type, true); return object; } // validate type tests // const o: { a: number; b: number; c: number } = { a: 1, b: 5, c: 6 }; // const z0 = validateObject(o, { a: 'isSafeInteger' }, { c: 'bigint' }); // Ok! // // Should fail type-check // const z1 = validateObject(o, { a: 'tmp' }, { c: 'zz' }); // const z2 = validateObject(o, { a: 'isSafeInteger' }, { c: 'zz' }); // const z3 = validateObject(o, { test: 'boolean', z: 'bug' }); // const z4 = validateObject(o, { a: 'boolean', z: 'bug' }); /** * throws not implemented error */ const notImplemented = () => { throw new Error('not implemented'); }; exports.notImplemented = notImplemented; /** * Memoizes (caches) computation result. * Uses WeakMap: the value is going auto-cleaned by GC after last reference is removed. */ function memoized(fn) { const map = new WeakMap(); return (arg, ...args) => { const val = map.get(arg); if (val !== undefined) return val; const computed = fn(arg, ...args); map.set(arg, computed); return computed; }; } //# sourceMappingURL=utils.js.map /***/ }, /***/ 8460 (__unused_webpack_module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.aoutput = exports.anumber = exports.aexists = exports.abytes = void 0; /** * Internal assertion helpers. * @module * @deprecated */ const utils_ts_1 = __webpack_require__(9074); /** @deprecated Use import from `noble/hashes/utils` module */ exports.abytes = utils_ts_1.abytes; /** @deprecated Use import from `noble/hashes/utils` module */ exports.aexists = utils_ts_1.aexists; /** @deprecated Use import from `noble/hashes/utils` module */ exports.anumber = utils_ts_1.anumber; /** @deprecated Use import from `noble/hashes/utils` module */ exports.aoutput = utils_ts_1.aoutput; //# sourceMappingURL=_assert.js.map /***/ }, /***/ 6423 (__unused_webpack_module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.SHA512_IV = exports.SHA384_IV = exports.SHA224_IV = exports.SHA256_IV = exports.HashMD = void 0; exports.setBigUint64 = setBigUint64; exports.Chi = Chi; exports.Maj = Maj; /** * Internal Merkle-Damgard hash utils. * @module */ const utils_ts_1 = __webpack_require__(9074); /** Polyfill for Safari 14. https://caniuse.com/mdn-javascript_builtins_dataview_setbiguint64 */ function setBigUint64(view, byteOffset, value, isLE) { if (typeof view.setBigUint64 === 'function') return view.setBigUint64(byteOffset, value, isLE); const _32n = BigInt(32); const _u32_max = BigInt(0xffffffff); const wh = Number((value >> _32n) & _u32_max); const wl = Number(value & _u32_max); const h = isLE ? 4 : 0; const l = isLE ? 0 : 4; view.setUint32(byteOffset + h, wh, isLE); view.setUint32(byteOffset + l, wl, isLE); } /** Choice: a ? b : c */ function Chi(a, b, c) { return (a & b) ^ (~a & c); } /** Majority function, true if any two inputs is true. */ function Maj(a, b, c) { return (a & b) ^ (a & c) ^ (b & c); } /** * Merkle-Damgard hash construction base class. * Could be used to create MD5, RIPEMD, SHA1, SHA2. */ class HashMD extends utils_ts_1.Hash { constructor(blockLen, outputLen, padOffset, isLE) { super(); this.finished = false; this.length = 0; this.pos = 0; this.destroyed = false; this.blockLen = blockLen; this.outputLen = outputLen; this.padOffset = padOffset; this.isLE = isLE; this.buffer = new Uint8Array(blockLen); this.view = (0, utils_ts_1.createView)(this.buffer); } update(data) { (0, utils_ts_1.aexists)(this); data = (0, utils_ts_1.toBytes)(data); (0, utils_ts_1.abytes)(data); const { view, buffer, blockLen } = this; const len = data.length; for (let pos = 0; pos < len;) { const take = Math.min(blockLen - this.pos, len - pos); // Fast path: we have at least one block in input, cast it to view and process if (take === blockLen) { const dataView = (0, utils_ts_1.createView)(data); for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos); continue; } buffer.set(data.subarray(pos, pos + take), this.pos); this.pos += take; pos += take; if (this.pos === blockLen) { this.process(view, 0); this.pos = 0; } } this.length += data.length; this.roundClean(); return this; } digestInto(out) { (0, utils_ts_1.aexists)(this); (0, utils_ts_1.aoutput)(out, this); this.finished = true; // Padding // We can avoid allocation of buffer for padding completely if it // was previously not allocated here. But it won't change performance. const { buffer, view, blockLen, isLE } = this; let { pos } = this; // append the bit '1' to the message buffer[pos++] = 0b10000000; (0, utils_ts_1.clean)(this.buffer.subarray(pos)); // we have less than padOffset left in buffer, so we cannot put length in // current block, need process it and pad again if (this.padOffset > blockLen - pos) { this.process(view, 0); pos = 0; } // Pad until full block byte with zeros for (let i = pos; i < blockLen; i++) buffer[i] = 0; // Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that // You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen. // So we just write lowest 64 bits of that value. setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE); this.process(view, 0); const oview = (0, utils_ts_1.createView)(out); const len = this.outputLen; // NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT if (len % 4) throw new Error('_sha2: outputLen should be aligned to 32bit'); const outLen = len / 4; const state = this.get(); if (outLen > state.length) throw new Error('_sha2: outputLen bigger than state'); for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE); } digest() { const { buffer, outputLen } = this; this.digestInto(buffer); const res = buffer.slice(0, outputLen); this.destroy(); return res; } _cloneInto(to) { to || (to = new this.constructor()); to.set(...this.get()); const { blockLen, buffer, length, finished, destroyed, pos } = this; to.destroyed = destroyed; to.finished = finished; to.length = length; to.pos = pos; if (length % blockLen) to.buffer.set(buffer); return to; } clone() { return this._cloneInto(); } } exports.HashMD = HashMD; /** * Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53. * Check out `test/misc/sha2-gen-iv.js` for recomputation guide. */ /** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */ exports.SHA256_IV = Uint32Array.from([ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, ]); /** Initial SHA224 state. Bits 32..64 of frac part of sqrt of primes 23..53 */ exports.SHA224_IV = Uint32Array.from([ 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4, ]); /** Initial SHA384 state. Bits 0..64 of frac part of sqrt of primes 23..53 */ exports.SHA384_IV = Uint32Array.from([ 0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939, 0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4, ]); /** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */ exports.SHA512_IV = Uint32Array.from([ 0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1, 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179, ]); //# sourceMappingURL=_md.js.map /***/ }, /***/ 8081 (__unused_webpack_module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.toBig = exports.shrSL = exports.shrSH = exports.rotrSL = exports.rotrSH = exports.rotrBL = exports.rotrBH = exports.rotr32L = exports.rotr32H = exports.rotlSL = exports.rotlSH = exports.rotlBL = exports.rotlBH = exports.add5L = exports.add5H = exports.add4L = exports.add4H = exports.add3L = exports.add3H = void 0; exports.add = add; exports.fromBig = fromBig; exports.split = split; /** * Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array. * @todo re-check https://issues.chromium.org/issues/42212588 * @module */ const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1); const _32n = /* @__PURE__ */ BigInt(32); function fromBig(n, le = false) { if (le) return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) }; return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 }; } function split(lst, le = false) { const len = lst.length; let Ah = new Uint32Array(len); let Al = new Uint32Array(len); for (let i = 0; i < len; i++) { const { h, l } = fromBig(lst[i], le); [Ah[i], Al[i]] = [h, l]; } return [Ah, Al]; } const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0); exports.toBig = toBig; // for Shift in [0, 32) const shrSH = (h, _l, s) => h >>> s; exports.shrSH = shrSH; const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s); exports.shrSL = shrSL; // Right rotate for Shift in [1, 32) const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s)); exports.rotrSH = rotrSH; const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s); exports.rotrSL = rotrSL; // Right rotate for Shift in (32, 64), NOTE: 32 is special case. const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32)); exports.rotrBH = rotrBH; const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s)); exports.rotrBL = rotrBL; // Right rotate for shift===32 (just swaps l&h) const rotr32H = (_h, l) => l; exports.rotr32H = rotr32H; const rotr32L = (h, _l) => h; exports.rotr32L = rotr32L; // Left rotate for Shift in [1, 32) const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s)); exports.rotlSH = rotlSH; const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s)); exports.rotlSL = rotlSL; // Left rotate for Shift in (32, 64), NOTE: 32 is special case. const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s)); exports.rotlBH = rotlBH; const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s)); exports.rotlBL = rotlBL; // JS uses 32-bit signed integers for bitwise operations which means we cannot // simple take carry out of low bit sum by shift, we need to use division. function add(Ah, Al, Bh, Bl) { const l = (Al >>> 0) + (Bl >>> 0); return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 }; } // Addition with more than 2 elements const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0); exports.add3L = add3L; const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0; exports.add3H = add3H; const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0); exports.add4L = add4L; const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0; exports.add4H = add4H; const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0); exports.add5L = add5L; const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0; exports.add5H = add5H; // prettier-ignore const u64 = { fromBig, split, toBig, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, rotr32H, rotr32L, rotlSH, rotlSL, rotlBH, rotlBL, add, add3L, add3H, add4L, add4H, add5H, add5L, }; exports["default"] = u64; //# sourceMappingURL=_u64.js.map /***/ }, /***/ 6134 (__unused_webpack_module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.crypto = void 0; /** * Internal webcrypto alias. * We prefer WebCrypto aka globalThis.crypto, which exists in node.js 16+. * Falls back to Node.js built-in crypto for Node.js <=v14. * See utils.ts for details. * @module */ // @ts-ignore const nc = __webpack_require__(7598); exports.crypto = nc && typeof nc === 'object' && 'webcrypto' in nc ? nc.webcrypto : nc && typeof nc === 'object' && 'randomBytes' in nc ? nc : undefined; //# sourceMappingURL=cryptoNode.js.map /***/ }, /***/ 4500 (__unused_webpack_module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.hmac = exports.HMAC = void 0; /** * HMAC: RFC2104 message authentication code. * @module */ const utils_ts_1 = __webpack_require__(9074); class HMAC extends utils_ts_1.Hash { constructor(hash, _key) { super(); this.finished = false; this.destroyed = false; (0, utils_ts_1.ahash)(hash); const key = (0, utils_ts_1.toBytes)(_key); this.iHash = hash.create(); if (typeof this.iHash.update !== 'function') throw new Error('Expected instance of class which extends utils.Hash'); this.blockLen = this.iHash.blockLen; this.outputLen = this.iHash.outputLen; const blockLen = this.blockLen; const pad = new Uint8Array(blockLen); // blockLen can be bigger than outputLen pad.set(key.length > blockLen ? hash.create().update(key).digest() : key); for (let i = 0; i < pad.length; i++) pad[i] ^= 0x36; this.iHash.update(pad); // By doing update (processing of first block) of outer hash here we can re-use it between multiple calls via clone this.oHash = hash.create(); // Undo internal XOR && apply outer XOR for (let i = 0; i < pad.length; i++) pad[i] ^= 0x36 ^ 0x5c; this.oHash.update(pad); (0, utils_ts_1.clean)(pad); } update(buf) { (0, utils_ts_1.aexists)(this); this.iHash.update(buf); return this; } digestInto(out) { (0, utils_ts_1.aexists)(this); (0, utils_ts_1.abytes)(out, this.outputLen); this.finished = true; this.iHash.digestInto(out); this.oHash.update(out); this.oHash.digestInto(out); this.destroy(); } digest() { const out = new Uint8Array(this.oHash.outputLen); this.digestInto(out); return out; } _cloneInto(to) { // Create new instance without calling constructor since key already in state and we don't know it. to || (to = Object.create(Object.getPrototypeOf(this), {})); const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this; to = to; to.finished = finished; to.destroyed = destroyed; to.blockLen = blockLen; to.outputLen = outputLen; to.oHash = oHash._cloneInto(to.oHash); to.iHash = iHash._cloneInto(to.iHash); return to; } clone() { return this._cloneInto(); } destroy() { this.destroyed = true; this.oHash.destroy(); this.iHash.destroy(); } } exports.HMAC = HMAC; /** * HMAC: RFC2104 message authentication code. * @param hash - function that would be used e.g. sha256 * @param key - message key * @param message - message data * @example * import { hmac } from '@noble/hashes/hmac'; * import { sha256 } from '@noble/hashes/sha2'; * const mac1 = hmac(sha256, 'key', 'message'); */ const hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest(); exports.hmac = hmac; exports.hmac.create = (hash, key) => new HMAC(hash, key); //# sourceMappingURL=hmac.js.map /***/ }, /***/ 7154 (__unused_webpack_module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.pbkdf2 = pbkdf2; exports.pbkdf2Async = pbkdf2Async; /** * PBKDF (RFC 2898). Can be used to create a key from password and salt. * @module */ const hmac_ts_1 = __webpack_require__(4500); // prettier-ignore const utils_ts_1 = __webpack_require__(9074); // Common prologue and epilogue for sync/async functions function pbkdf2Init(hash, _password, _salt, _opts) { (0, utils_ts_1.ahash)(hash); const opts = (0, utils_ts_1.checkOpts)({ dkLen: 32, asyncTick: 10 }, _opts); const { c, dkLen, asyncTick } = opts; (0, utils_ts_1.anumber)(c); (0, utils_ts_1.anumber)(dkLen); (0, utils_ts_1.anumber)(asyncTick); if (c < 1) throw new Error('iterations (c) should be >= 1'); const password = (0, utils_ts_1.kdfInputToBytes)(_password); const salt = (0, utils_ts_1.kdfInputToBytes)(_salt); // DK = PBKDF2(PRF, Password, Salt, c, dkLen); const DK = new Uint8Array(dkLen); // U1 = PRF(Password, Salt + INT_32_BE(i)) const PRF = hmac_ts_1.hmac.create(hash, password); const PRFSalt = PRF._cloneInto().update(salt); return { c, dkLen, asyncTick, DK, PRF, PRFSalt }; } function pbkdf2Output(PRF, PRFSalt, DK, prfW, u) { PRF.destroy(); PRFSalt.destroy(); if (prfW) prfW.destroy(); (0, utils_ts_1.clean)(u); return DK; } /** * PBKDF2-HMAC: RFC 2898 key derivation function * @param hash - hash function that would be used e.g. sha256 * @param password - password from which a derived key is generated * @param salt - cryptographic salt * @param opts - {c, dkLen} where c is work factor and dkLen is output message size * @example * const key = pbkdf2(sha256, 'password', 'salt', { dkLen: 32, c: Math.pow(2, 18) }); */ function pbkdf2(hash, password, salt, opts) { const { c, dkLen, DK, PRF, PRFSalt } = pbkdf2Init(hash, password, salt, opts); let prfW; // Working copy const arr = new Uint8Array(4); const view = (0, utils_ts_1.createView)(arr); const u = new Uint8Array(PRF.outputLen); // DK = T1 + T2 + ⋯ + Tdklen/hlen for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) { // Ti = F(Password, Salt, c, i) const Ti = DK.subarray(pos, pos + PRF.outputLen); view.setInt32(0, ti, false); // F(Password, Salt, c, i) = U1 ^ U2 ^ ⋯ ^ Uc // U1 = PRF(Password, Salt + INT_32_BE(i)) (prfW = PRFSalt._cloneInto(prfW)).update(arr).digestInto(u); Ti.set(u.subarray(0, Ti.length)); for (let ui = 1; ui < c; ui++) { // Uc = PRF(Password, Uc−1) PRF._cloneInto(prfW).update(u).digestInto(u); for (let i = 0; i < Ti.length; i++) Ti[i] ^= u[i]; } } return pbkdf2Output(PRF, PRFSalt, DK, prfW, u); } /** * PBKDF2-HMAC: RFC 2898 key derivation function. Async version. * @example * await pbkdf2Async(sha256, 'password', 'salt', { dkLen: 32, c: 500_000 }); */ async function pbkdf2Async(hash, password, salt, opts) { const { c, dkLen, asyncTick, DK, PRF, PRFSalt } = pbkdf2Init(hash, password, salt, opts); let prfW; // Working copy const arr = new Uint8Array(4); const view = (0, utils_ts_1.createView)(arr); const u = new Uint8Array(PRF.outputLen); // DK = T1 + T2 + ⋯ + Tdklen/hlen for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) { // Ti = F(Password, Salt, c, i) const Ti = DK.subarray(pos, pos + PRF.outputLen); view.setInt32(0, ti, false); // F(Password, Salt, c, i) = U1 ^ U2 ^ ⋯ ^ Uc // U1 = PRF(Password, Salt + INT_32_BE(i)) (prfW = PRFSalt._cloneInto(prfW)).update(arr).digestInto(u); Ti.set(u.subarray(0, Ti.length)); await (0, utils_ts_1.asyncLoop)(c - 1, asyncTick, () => { // Uc = PRF(Password, Uc−1) PRF._cloneInto(prfW).update(u).digestInto(u); for (let i = 0; i < Ti.length; i++) Ti[i] ^= u[i]; }); } return pbkdf2Output(PRF, PRFSalt, DK, prfW, u); } //# sourceMappingURL=pbkdf2.js.map /***/ }, /***/ 5308 (__unused_webpack_module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.scrypt = scrypt; exports.scryptAsync = scryptAsync; /** * RFC 7914 Scrypt KDF. Can be used to create a key from password and salt. * @module */ const pbkdf2_ts_1 = __webpack_require__(7154); const sha2_ts_1 = __webpack_require__(4599); // prettier-ignore const utils_ts_1 = __webpack_require__(9074); // The main Scrypt loop: uses Salsa extensively. // Six versions of the function were tried, this is the fastest one. // prettier-ignore function XorAndSalsa(prev, pi, input, ii, out, oi) { // Based on https://cr.yp.to/salsa20.html // Xor blocks let y00 = prev[pi++] ^ input[ii++], y01 = prev[pi++] ^ input[ii++]; let y02 = prev[pi++] ^ input[ii++], y03 = prev[pi++] ^ input[ii++]; let y04 = prev[pi++] ^ input[ii++], y05 = prev[pi++] ^ input[ii++]; let y06 = prev[pi++] ^ input[ii++], y07 = prev[pi++] ^ input[ii++]; let y08 = prev[pi++] ^ input[ii++], y09 = prev[pi++] ^ input[ii++]; let y10 = prev[pi++] ^ input[ii++], y11 = prev[pi++] ^ input[ii++]; let y12 = prev[pi++] ^ input[ii++], y13 = prev[pi++] ^ input[ii++]; let y14 = prev[pi++] ^ input[ii++], y15 = prev[pi++] ^ input[ii++]; // Save state to temporary variables (salsa) let x00 = y00, x01 = y01, x02 = y02, x03 = y03, x04 = y04, x05 = y05, x06 = y06, x07 = y07, x08 = y08, x09 = y09, x10 = y10, x11 = y11, x12 = y12, x13 = y13, x14 = y14, x15 = y15; // Main loop (salsa) for (let i = 0; i < 8; i += 2) { x04 ^= (0, utils_ts_1.rotl)(x00 + x12 | 0, 7); x08 ^= (0, utils_ts_1.rotl)(x04 + x00 | 0, 9); x12 ^= (0, utils_ts_1.rotl)(x08 + x04 | 0, 13); x00 ^= (0, utils_ts_1.rotl)(x12 + x08 | 0, 18); x09 ^= (0, utils_ts_1.rotl)(x05 + x01 | 0, 7); x13 ^= (0, utils_ts_1.rotl)(x09 + x05 | 0, 9); x01 ^= (0, utils_ts_1.rotl)(x13 + x09 | 0, 13); x05 ^= (0, utils_ts_1.rotl)(x01 + x13 | 0, 18); x14 ^= (0, utils_ts_1.rotl)(x10 + x06 | 0, 7); x02 ^= (0, utils_ts_1.rotl)(x14 + x10 | 0, 9); x06 ^= (0, utils_ts_1.rotl)(x02 + x14 | 0, 13); x10 ^= (0, utils_ts_1.rotl)(x06 + x02 | 0, 18); x03 ^= (0, utils_ts_1.rotl)(x15 + x11 | 0, 7); x07 ^= (0, utils_ts_1.rotl)(x03 + x15 | 0, 9); x11 ^= (0, utils_ts_1.rotl)(x07 + x03 | 0, 13); x15 ^= (0, utils_ts_1.rotl)(x11 + x07 | 0, 18); x01 ^= (0, utils_ts_1.rotl)(x00 + x03 | 0, 7); x02 ^= (0, utils_ts_1.rotl)(x01 + x00 | 0, 9); x03 ^= (0, utils_ts_1.rotl)(x02 + x01 | 0, 13); x00 ^= (0, utils_ts_1.rotl)(x03 + x02 | 0, 18); x06 ^= (0, utils_ts_1.rotl)(x05 + x04 | 0, 7); x07 ^= (0, utils_ts_1.rotl)(x06 + x05 | 0, 9); x04 ^= (0, utils_ts_1.rotl)(x07 + x06 | 0, 13); x05 ^= (0, utils_ts_1.rotl)(x04 + x07 | 0, 18); x11 ^= (0, utils_ts_1.rotl)(x10 + x09 | 0, 7); x08 ^= (0, utils_ts_1.rotl)(x11 + x10 | 0, 9); x09 ^= (0, utils_ts_1.rotl)(x08 + x11 | 0, 13); x10 ^= (0, utils_ts_1.rotl)(x09 + x08 | 0, 18); x12 ^= (0, utils_ts_1.rotl)(x15 + x14 | 0, 7); x13 ^= (0, utils_ts_1.rotl)(x12 + x15 | 0, 9); x14 ^= (0, utils_ts_1.rotl)(x13 + x12 | 0, 13); x15 ^= (0, utils_ts_1.rotl)(x14 + x13 | 0, 18); } // Write output (salsa) out[oi++] = (y00 + x00) | 0; out[oi++] = (y01 + x01) | 0; out[oi++] = (y02 + x02) | 0; out[oi++] = (y03 + x03) | 0; out[oi++] = (y04 + x04) | 0; out[oi++] = (y05 + x05) | 0; out[oi++] = (y06 + x06) | 0; out[oi++] = (y07 + x07) | 0; out[oi++] = (y08 + x08) | 0; out[oi++] = (y09 + x09) | 0; out[oi++] = (y10 + x10) | 0; out[oi++] = (y11 + x11) | 0; out[oi++] = (y12 + x12) | 0; out[oi++] = (y13 + x13) | 0; out[oi++] = (y14 + x14) | 0; out[oi++] = (y15 + x15) | 0; } function BlockMix(input, ii, out, oi, r) { // The block B is r 128-byte chunks (which is equivalent of 2r 64-byte chunks) let head = oi + 0; let tail = oi + 16 * r; for (let i = 0; i < 16; i++) out[tail + i] = input[ii + (2 * r - 1) * 16 + i]; // X ← B[2r−1] for (let i = 0; i < r; i++, head += 16, ii += 16) { // We write odd & even Yi at same time. Even: 0bXXXXX0 Odd: 0bXXXXX1 XorAndSalsa(out, tail, input, ii, out, head); // head[i] = Salsa(blockIn[2*i] ^ tail[i-1]) if (i > 0) tail += 16; // First iteration overwrites tmp value in tail XorAndSalsa(out, head, input, (ii += 16), out, tail); // tail[i] = Salsa(blockIn[2*i+1] ^ head[i]) } } // Common prologue and epilogue for sync/async functions function scryptInit(password, salt, _opts) { // Maxmem - 1GB+1KB by default const opts = (0, utils_ts_1.checkOpts)({ dkLen: 32, asyncTick: 10, maxmem: 1024 ** 3 + 1024, }, _opts); const { N, r, p, dkLen, asyncTick, maxmem, onProgress } = opts; (0, utils_ts_1.anumber)(N); (0, utils_ts_1.anumber)(r); (0, utils_ts_1.anumber)(p); (0, utils_ts_1.anumber)(dkLen); (0, utils_ts_1.anumber)(asyncTick); (0, utils_ts_1.anumber)(maxmem); if (onProgress !== undefined && typeof onProgress !== 'function') throw new Error('progressCb should be function'); const blockSize = 128 * r; const blockSize32 = blockSize / 4; // Max N is 2^32 (Integrify is 32-bit). Real limit is 2^22: JS engines Uint8Array limit is 4GB in 2024. // Spec check `N >= 2^(blockSize / 8)` is not done for compat with popular libs, // which used incorrect r: 1, p: 8. Also, the check seems to be a spec error: // https://www.rfc-editor.org/errata_search.php?rfc=7914 const pow32 = Math.pow(2, 32); if (N <= 1 || (N & (N - 1)) !== 0 || N > pow32) { throw new Error('Scrypt: N must be larger than 1, a power of 2, and less than 2^32'); } if (p < 0 || p > ((pow32 - 1) * 32) / blockSize) { throw new Error('Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)'); } if (dkLen < 0 || dkLen > (pow32 - 1) * 32) { throw new Error('Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32'); } const memUsed = blockSize * (N + p); if (memUsed > maxmem) { throw new Error('Scrypt: memused is bigger than maxMem. Expected 128 * r * (N + p) > maxmem of ' + maxmem); } // [B0...Bp−1] ← PBKDF2HMAC-SHA256(Passphrase, Salt, 1, blockSize*ParallelizationFactor) // Since it has only one iteration there is no reason to use async variant const B = (0, pbkdf2_ts_1.pbkdf2)(sha2_ts_1.sha256, password, salt, { c: 1, dkLen: blockSize * p }); const B32 = (0, utils_ts_1.u32)(B); // Re-used between parallel iterations. Array(iterations) of B const V = (0, utils_ts_1.u32)(new Uint8Array(blockSize * N)); const tmp = (0, utils_ts_1.u32)(new Uint8Array(blockSize)); let blockMixCb = () => { }; if (onProgress) { const totalBlockMix = 2 * N * p; // Invoke callback if progress changes from 10.01 to 10.02 // Allows to draw smooth progress bar on up to 8K screen const callbackPer = Math.max(Math.floor(totalBlockMix / 10000), 1); let blockMixCnt = 0; blockMixCb = () => { blockMixCnt++; if (onProgress && (!(blockMixCnt % callbackPer) || blockMixCnt === totalBlockMix)) onProgress(blockMixCnt / totalBlockMix); }; } return { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb, asyncTick }; } function scryptOutput(password, dkLen, B, V, tmp) { const res = (0, pbkdf2_ts_1.pbkdf2)(sha2_ts_1.sha256, password, B, { c: 1, dkLen }); (0, utils_ts_1.clean)(B, V, tmp); return res; } /** * Scrypt KDF from RFC 7914. * @param password - pass * @param salt - salt * @param opts - parameters * - `N` is cpu/mem work factor (power of 2 e.g. 2**18) * - `r` is block size (8 is common), fine-tunes sequential memory read size and performance * - `p` is parallelization factor (1 is common) * - `dkLen` is output key length in bytes e.g. 32. * - `asyncTick` - (default: 10) max time in ms for which async function can block execution * - `maxmem` - (default: `1024 ** 3 + 1024` aka 1GB+1KB). A limit that the app could use for scrypt * - `onProgress` - callback function that would be executed for progress report * @returns Derived key * @example * scrypt('password', 'salt', { N: 2**18, r: 8, p: 1, dkLen: 32 }); */ function scrypt(password, salt, opts) { const { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb } = scryptInit(password, salt, opts); (0, utils_ts_1.swap32IfBE)(B32); for (let pi = 0; pi < p; pi++) { const Pi = blockSize32 * pi; for (let i = 0; i < blockSize32; i++) V[i] = B32[Pi + i]; // V[0] = B[i] for (let i = 0, pos = 0; i < N - 1; i++) { BlockMix(V, pos, V, (pos += blockSize32), r); // V[i] = BlockMix(V[i-1]); blockMixCb(); } BlockMix(V, (N - 1) * blockSize32, B32, Pi, r); // Process last element blockMixCb(); for (let i = 0; i < N; i++) { // First u32 of the last 64-byte block (u32 is LE) const j = B32[Pi + blockSize32 - 16] % N; // j = Integrify(X) % iterations for (let k = 0; k < blockSize32; k++) tmp[k] = B32[Pi + k] ^ V[j * blockSize32 + k]; // tmp = B ^ V[j] BlockMix(tmp, 0, B32, Pi, r); // B = BlockMix(B ^ V[j]) blockMixCb(); } } (0, utils_ts_1.swap32IfBE)(B32); return scryptOutput(password, dkLen, B, V, tmp); } /** * Scrypt KDF from RFC 7914. Async version. * @example * await scryptAsync('password', 'salt', { N: 2**18, r: 8, p: 1, dkLen: 32 }); */ async function scryptAsync(password, salt, opts) { const { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb, asyncTick } = scryptInit(password, salt, opts); (0, utils_ts_1.swap32IfBE)(B32); for (let pi = 0; pi < p; pi++) { const Pi = blockSize32 * pi; for (let i = 0; i < blockSize32; i++) V[i] = B32[Pi + i]; // V[0] = B[i] let pos = 0; await (0, utils_ts_1.asyncLoop)(N - 1, asyncTick, () => { BlockMix(V, pos, V, (pos += blockSize32), r); // V[i] = BlockMix(V[i-1]); blockMixCb(); }); BlockMix(V, (N - 1) * blockSize32, B32, Pi, r); // Process last element blockMixCb(); await (0, utils_ts_1.asyncLoop)(N, asyncTick, () => { // First u32 of the last 64-byte block (u32 is LE) const j = B32[Pi + blockSize32 - 16] % N; // j = Integrify(X) % iterations for (let k = 0; k < blockSize32; k++) tmp[k] = B32[Pi + k] ^ V[j * blockSize32 + k]; // tmp = B ^ V[j] BlockMix(tmp, 0, B32, Pi, r); // B = BlockMix(B ^ V[j]) blockMixCb(); }); } (0, utils_ts_1.swap32IfBE)(B32); return scryptOutput(password, dkLen, B, V, tmp); } //# sourceMappingURL=scrypt.js.map /***/ }, /***/ 4599 (__unused_webpack_module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.sha512_224 = exports.sha512_256 = exports.sha384 = exports.sha512 = exports.sha224 = exports.sha256 = exports.SHA512_256 = exports.SHA512_224 = exports.SHA384 = exports.SHA512 = exports.SHA224 = exports.SHA256 = void 0; /** * SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256. * SHA256 is the fastest hash implementable in JS, even faster than Blake3. * Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and * [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf). * @module */ const _md_ts_1 = __webpack_require__(6423); const u64 = __webpack_require__(8081); const utils_ts_1 = __webpack_require__(9074); /** * Round constants: * First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311) */ // prettier-ignore const SHA256_K = /* @__PURE__ */ Uint32Array.from([ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 ]); /** Reusable temporary buffer. "W" comes straight from spec. */ const SHA256_W = /* @__PURE__ */ new Uint32Array(64); class SHA256 extends _md_ts_1.HashMD { constructor(outputLen = 32) { super(64, outputLen, 8, false); // We cannot use array here since array allows indexing by variable // which means optimizer/compiler cannot use registers. this.A = _md_ts_1.SHA256_IV[0] | 0; this.B = _md_ts_1.SHA256_IV[1] | 0; this.C = _md_ts_1.SHA256_IV[2] | 0; this.D = _md_ts_1.SHA256_IV[3] | 0; this.E = _md_ts_1.SHA256_IV[4] | 0; this.F = _md_ts_1.SHA256_IV[5] | 0; this.G = _md_ts_1.SHA256_IV[6] | 0; this.H = _md_ts_1.SHA256_IV[7] | 0; } get() { const { A, B, C, D, E, F, G, H } = this; return [A, B, C, D, E, F, G, H]; } // prettier-ignore set(A, B, C, D, E, F, G, H) { this.A = A | 0; this.B = B | 0; this.C = C | 0; this.D = D | 0; this.E = E | 0; this.F = F | 0; this.G = G | 0; this.H = H | 0; } process(view, offset) { // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array for (let i = 0; i < 16; i++, offset += 4) SHA256_W[i] = view.getUint32(offset, false); for (let i = 16; i < 64; i++) { const W15 = SHA256_W[i - 15]; const W2 = SHA256_W[i - 2]; const s0 = (0, utils_ts_1.rotr)(W15, 7) ^ (0, utils_ts_1.rotr)(W15, 18) ^ (W15 >>> 3); const s1 = (0, utils_ts_1.rotr)(W2, 17) ^ (0, utils_ts_1.rotr)(W2, 19) ^ (W2 >>> 10); SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0; } // Compression function main loop, 64 rounds let { A, B, C, D, E, F, G, H } = this; for (let i = 0; i < 64; i++) { const sigma1 = (0, utils_ts_1.rotr)(E, 6) ^ (0, utils_ts_1.rotr)(E, 11) ^ (0, utils_ts_1.rotr)(E, 25); const T1 = (H + sigma1 + (0, _md_ts_1.Chi)(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0; const sigma0 = (0, utils_ts_1.rotr)(A, 2) ^ (0, utils_ts_1.rotr)(A, 13) ^ (0, utils_ts_1.rotr)(A, 22); const T2 = (sigma0 + (0, _md_ts_1.Maj)(A, B, C)) | 0; H = G; G = F; F = E; E = (D + T1) | 0; D = C; C = B; B = A; A = (T1 + T2) | 0; } // Add the compressed chunk to the current hash value A = (A + this.A) | 0; B = (B + this.B) | 0; C = (C + this.C) | 0; D = (D + this.D) | 0; E = (E + this.E) | 0; F = (F + this.F) | 0; G = (G + this.G) | 0; H = (H + this.H) | 0; this.set(A, B, C, D, E, F, G, H); } roundClean() { (0, utils_ts_1.clean)(SHA256_W); } destroy() { this.set(0, 0, 0, 0, 0, 0, 0, 0); (0, utils_ts_1.clean)(this.buffer); } } exports.SHA256 = SHA256; class SHA224 extends SHA256 { constructor() { super(28); this.A = _md_ts_1.SHA224_IV[0] | 0; this.B = _md_ts_1.SHA224_IV[1] | 0; this.C = _md_ts_1.SHA224_IV[2] | 0; this.D = _md_ts_1.SHA224_IV[3] | 0; this.E = _md_ts_1.SHA224_IV[4] | 0; this.F = _md_ts_1.SHA224_IV[5] | 0; this.G = _md_ts_1.SHA224_IV[6] | 0; this.H = _md_ts_1.SHA224_IV[7] | 0; } } exports.SHA224 = SHA224; // SHA2-512 is slower than sha256 in js because u64 operations are slow. // Round contants // First 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409 // prettier-ignore const K512 = /* @__PURE__ */ (() => u64.split([ '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc', '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118', '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2', '0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',