@taquito/utils 24.3.0-beta.1 → 24.3.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@stablelib/blake2b'), require('bs58check'), require('bignumber.js'), require('typedarray-to-buffer'), require('@taquito/core'), require('@stablelib/ed25519'), require('@noble/curves/secp256k1'), require('@noble/curves/nist'), require('@noble/curves/bls12-381')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@stablelib/blake2b', 'bs58check', 'bignumber.js', 'typedarray-to-buffer', '@taquito/core', '@stablelib/ed25519', '@noble/curves/secp256k1', '@noble/curves/nist', '@noble/curves/bls12-381'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoUtils = {}, global.blake2b, global.bs58check, global.BigNumber, global.toBuffer, global.core, global.ed25519, global.secp256k1, global.nist, global.bls12381));
5
- })(this, (function (exports, blake2b, bs58check, BigNumber, toBuffer, core, ed25519, secp256k1, nist, bls12381) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('bs58check'), require('bignumber.js'), require('typedarray-to-buffer'), require('@taquito/core'), require('@noble/curves/ed25519'), require('@noble/curves/secp256k1'), require('@noble/curves/nist'), require('@noble/curves/bls12-381')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'bs58check', 'bignumber.js', 'typedarray-to-buffer', '@taquito/core', '@noble/curves/ed25519', '@noble/curves/secp256k1', '@noble/curves/nist', '@noble/curves/bls12-381'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoUtils = {}, global.bs58check, global.BigNumber, global.toBuffer, global.core, global.ed25519, global.secp256k1, global.nist, global.bls12381));
5
+ })(this, (function (exports, bs58check, BigNumberJs, toBuffer, core, ed25519, secp256k1, nist, bls12381) { 'use strict';
6
6
 
7
7
  var global$1 = (typeof global !== "undefined" ? global :
8
8
  typeof self !== "undefined" ? self :
@@ -2186,6 +2186,460 @@
2186
2186
  [exports.PrefixV2.SlotHeader]: 48,
2187
2187
  };
2188
2188
 
2189
+ /**
2190
+ * Utilities for hex, bytes, CSPRNG.
2191
+ * @module
2192
+ */
2193
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2194
+ /** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
2195
+ function isBytes(a) {
2196
+ return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
2197
+ }
2198
+ /** Asserts something is positive integer. */
2199
+ function anumber(n, title = '') {
2200
+ if (!Number.isSafeInteger(n) || n < 0) {
2201
+ const prefix = title && `"${title}" `;
2202
+ throw new Error(`${prefix}expected integer >= 0, got ${n}`);
2203
+ }
2204
+ }
2205
+ /** Asserts something is Uint8Array. */
2206
+ function abytes(value, length, title = '') {
2207
+ const bytes = isBytes(value);
2208
+ const len = value?.length;
2209
+ const needsLen = length !== undefined;
2210
+ if (!bytes || (needsLen && len !== length)) {
2211
+ const prefix = title && `"${title}" `;
2212
+ const ofLen = needsLen ? ` of length ${length}` : '';
2213
+ const got = bytes ? `length=${len}` : `type=${typeof value}`;
2214
+ throw new Error(prefix + 'expected Uint8Array' + ofLen + ', got ' + got);
2215
+ }
2216
+ return value;
2217
+ }
2218
+ /** Asserts a hash instance has not been destroyed / finished */
2219
+ function aexists(instance, checkFinished = true) {
2220
+ if (instance.destroyed)
2221
+ throw new Error('Hash instance has been destroyed');
2222
+ if (checkFinished && instance.finished)
2223
+ throw new Error('Hash#digest() has already been called');
2224
+ }
2225
+ /** Asserts output is properly-sized byte array */
2226
+ function aoutput(out, instance) {
2227
+ abytes(out, undefined, 'digestInto() output');
2228
+ const min = instance.outputLen;
2229
+ if (out.length < min) {
2230
+ throw new Error('"digestInto() output" expected to be of length >=' + min);
2231
+ }
2232
+ }
2233
+ /** Cast u8 / u16 / u32 to u32. */
2234
+ function u32(arr) {
2235
+ return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
2236
+ }
2237
+ /** Zeroize a byte array. Warning: JS provides no guarantees. */
2238
+ function clean(...arrays) {
2239
+ for (let i = 0; i < arrays.length; i++) {
2240
+ arrays[i].fill(0);
2241
+ }
2242
+ }
2243
+ /** Is current platform little-endian? Most are. Big-Endian platform: IBM */
2244
+ const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
2245
+ /** The byte swap operation for uint32 */
2246
+ function byteSwap(word) {
2247
+ return (((word << 24) & 0xff000000) |
2248
+ ((word << 8) & 0xff0000) |
2249
+ ((word >>> 8) & 0xff00) |
2250
+ ((word >>> 24) & 0xff));
2251
+ }
2252
+ /** Conditionally byte swap if on a big-endian platform */
2253
+ const swap8IfBE = isLE
2254
+ ? (n) => n
2255
+ : (n) => byteSwap(n);
2256
+ /** In place byte swap for Uint32Array */
2257
+ function byteSwap32(arr) {
2258
+ for (let i = 0; i < arr.length; i++) {
2259
+ arr[i] = byteSwap(arr[i]);
2260
+ }
2261
+ return arr;
2262
+ }
2263
+ const swap32IfBE = isLE
2264
+ ? (u) => u
2265
+ : byteSwap32;
2266
+ /** Creates function with outputLen, blockLen, create properties from a class constructor. */
2267
+ function createHasher(hashCons, info = {}) {
2268
+ const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
2269
+ const tmp = hashCons(undefined);
2270
+ hashC.outputLen = tmp.outputLen;
2271
+ hashC.blockLen = tmp.blockLen;
2272
+ hashC.create = (opts) => hashCons(opts);
2273
+ Object.assign(hashC, info);
2274
+ return Object.freeze(hashC);
2275
+ }
2276
+
2277
+ /**
2278
+ * Internal helpers for blake hash.
2279
+ * @module
2280
+ */
2281
+ /**
2282
+ * Internal blake variable.
2283
+ * For BLAKE2b, the two extra permutations for rounds 10 and 11 are SIGMA[10..11] = SIGMA[0..1].
2284
+ */
2285
+ // prettier-ignore
2286
+ const BSIGMA = /* @__PURE__ */ Uint8Array.from([
2287
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
2288
+ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
2289
+ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
2290
+ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
2291
+ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
2292
+ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
2293
+ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
2294
+ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
2295
+ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
2296
+ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
2297
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
2298
+ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
2299
+ // Blake1, unused in others
2300
+ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
2301
+ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
2302
+ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
2303
+ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
2304
+ ]);
2305
+
2306
+ /**
2307
+ * Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
2308
+ * @todo re-check https://issues.chromium.org/issues/42212588
2309
+ * @module
2310
+ */
2311
+ const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
2312
+ const _32n = /* @__PURE__ */ BigInt(32);
2313
+ function fromBig(n, le = false) {
2314
+ if (le)
2315
+ return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
2316
+ return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
2317
+ }
2318
+ // Right rotate for Shift in [1, 32)
2319
+ const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
2320
+ const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
2321
+ // Right rotate for Shift in (32, 64), NOTE: 32 is special case.
2322
+ const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
2323
+ const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
2324
+ // Right rotate for shift===32 (just swaps l&h)
2325
+ const rotr32H = (_h, l) => l;
2326
+ const rotr32L = (h, _l) => h;
2327
+ // JS uses 32-bit signed integers for bitwise operations which means we cannot
2328
+ // simple take carry out of low bit sum by shift, we need to use division.
2329
+ function add(Ah, Al, Bh, Bl) {
2330
+ const l = (Al >>> 0) + (Bl >>> 0);
2331
+ return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
2332
+ }
2333
+ // Addition with more than 2 elements
2334
+ const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
2335
+ const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
2336
+
2337
+ /**
2338
+ * blake2b (64-bit) & blake2s (8 to 32-bit) hash functions.
2339
+ * b could have been faster, but there is no fast u64 in js, so s is 1.5x faster.
2340
+ * @module
2341
+ */
2342
+ // Same as SHA512_IV, but swapped endianness: LE instead of BE. iv[1] is iv[0], etc.
2343
+ const B2B_IV = /* @__PURE__ */ Uint32Array.from([
2344
+ 0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372, 0x5f1d36f1, 0xa54ff53a,
2345
+ 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c, 0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19,
2346
+ ]);
2347
+ // Temporary buffer
2348
+ const BBUF = /* @__PURE__ */ new Uint32Array(32);
2349
+ // Mixing function G splitted in two halfs
2350
+ function G1b(a, b, c, d, msg, x) {
2351
+ // NOTE: V is LE here
2352
+ const Xl = msg[x], Xh = msg[x + 1]; // prettier-ignore
2353
+ let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1]; // prettier-ignore
2354
+ let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1]; // prettier-ignore
2355
+ let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1]; // prettier-ignore
2356
+ let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1]; // prettier-ignore
2357
+ // v[a] = (v[a] + v[b] + x) | 0;
2358
+ let ll = add3L(Al, Bl, Xl);
2359
+ Ah = add3H(ll, Ah, Bh, Xh);
2360
+ Al = ll | 0;
2361
+ // v[d] = rotr(v[d] ^ v[a], 32)
2362
+ ({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
2363
+ ({ Dh, Dl } = { Dh: rotr32H(Dh, Dl), Dl: rotr32L(Dh) });
2364
+ // v[c] = (v[c] + v[d]) | 0;
2365
+ ({ h: Ch, l: Cl } = add(Ch, Cl, Dh, Dl));
2366
+ // v[b] = rotr(v[b] ^ v[c], 24)
2367
+ ({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
2368
+ ({ Bh, Bl } = { Bh: rotrSH(Bh, Bl, 24), Bl: rotrSL(Bh, Bl, 24) });
2369
+ ((BBUF[2 * a] = Al), (BBUF[2 * a + 1] = Ah));
2370
+ ((BBUF[2 * b] = Bl), (BBUF[2 * b + 1] = Bh));
2371
+ ((BBUF[2 * c] = Cl), (BBUF[2 * c + 1] = Ch));
2372
+ ((BBUF[2 * d] = Dl), (BBUF[2 * d + 1] = Dh));
2373
+ }
2374
+ function G2b(a, b, c, d, msg, x) {
2375
+ // NOTE: V is LE here
2376
+ const Xl = msg[x], Xh = msg[x + 1]; // prettier-ignore
2377
+ let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1]; // prettier-ignore
2378
+ let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1]; // prettier-ignore
2379
+ let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1]; // prettier-ignore
2380
+ let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1]; // prettier-ignore
2381
+ // v[a] = (v[a] + v[b] + x) | 0;
2382
+ let ll = add3L(Al, Bl, Xl);
2383
+ Ah = add3H(ll, Ah, Bh, Xh);
2384
+ Al = ll | 0;
2385
+ // v[d] = rotr(v[d] ^ v[a], 16)
2386
+ ({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
2387
+ ({ Dh, Dl } = { Dh: rotrSH(Dh, Dl, 16), Dl: rotrSL(Dh, Dl, 16) });
2388
+ // v[c] = (v[c] + v[d]) | 0;
2389
+ ({ h: Ch, l: Cl } = add(Ch, Cl, Dh, Dl));
2390
+ // v[b] = rotr(v[b] ^ v[c], 63)
2391
+ ({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
2392
+ ({ Bh, Bl } = { Bh: rotrBH(Bh, Bl, 63), Bl: rotrBL(Bh, Bl, 63) });
2393
+ ((BBUF[2 * a] = Al), (BBUF[2 * a + 1] = Ah));
2394
+ ((BBUF[2 * b] = Bl), (BBUF[2 * b + 1] = Bh));
2395
+ ((BBUF[2 * c] = Cl), (BBUF[2 * c + 1] = Ch));
2396
+ ((BBUF[2 * d] = Dl), (BBUF[2 * d + 1] = Dh));
2397
+ }
2398
+ function checkBlake2Opts(outputLen, opts = {}, keyLen, saltLen, persLen) {
2399
+ anumber(keyLen);
2400
+ if (outputLen < 0 || outputLen > keyLen)
2401
+ throw new Error('outputLen bigger than keyLen');
2402
+ const { key, salt, personalization } = opts;
2403
+ if (key !== undefined && (key.length < 1 || key.length > keyLen))
2404
+ throw new Error('"key" expected to be undefined or of length=1..' + keyLen);
2405
+ if (salt !== undefined)
2406
+ abytes(salt, saltLen, 'salt');
2407
+ if (personalization !== undefined)
2408
+ abytes(personalization, persLen, 'personalization');
2409
+ }
2410
+ /** Internal base class for BLAKE2. */
2411
+ class _BLAKE2 {
2412
+ buffer;
2413
+ buffer32;
2414
+ finished = false;
2415
+ destroyed = false;
2416
+ length = 0;
2417
+ pos = 0;
2418
+ blockLen;
2419
+ outputLen;
2420
+ constructor(blockLen, outputLen) {
2421
+ anumber(blockLen);
2422
+ anumber(outputLen);
2423
+ this.blockLen = blockLen;
2424
+ this.outputLen = outputLen;
2425
+ this.buffer = new Uint8Array(blockLen);
2426
+ this.buffer32 = u32(this.buffer);
2427
+ }
2428
+ update(data) {
2429
+ aexists(this);
2430
+ abytes(data);
2431
+ // Main difference with other hashes: there is flag for last block,
2432
+ // so we cannot process current block before we know that there
2433
+ // is the next one. This significantly complicates logic and reduces ability
2434
+ // to do zero-copy processing
2435
+ const { blockLen, buffer, buffer32 } = this;
2436
+ const len = data.length;
2437
+ const offset = data.byteOffset;
2438
+ const buf = data.buffer;
2439
+ for (let pos = 0; pos < len;) {
2440
+ // If buffer is full and we still have input (don't process last block, same as blake2s)
2441
+ if (this.pos === blockLen) {
2442
+ swap32IfBE(buffer32);
2443
+ this.compress(buffer32, 0, false);
2444
+ swap32IfBE(buffer32);
2445
+ this.pos = 0;
2446
+ }
2447
+ const take = Math.min(blockLen - this.pos, len - pos);
2448
+ const dataOffset = offset + pos;
2449
+ // full block && aligned to 4 bytes && not last in input
2450
+ if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
2451
+ const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
2452
+ swap32IfBE(data32);
2453
+ for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
2454
+ this.length += blockLen;
2455
+ this.compress(data32, pos32, false);
2456
+ }
2457
+ swap32IfBE(data32);
2458
+ continue;
2459
+ }
2460
+ buffer.set(data.subarray(pos, pos + take), this.pos);
2461
+ this.pos += take;
2462
+ this.length += take;
2463
+ pos += take;
2464
+ }
2465
+ return this;
2466
+ }
2467
+ digestInto(out) {
2468
+ aexists(this);
2469
+ aoutput(out, this);
2470
+ const { pos, buffer32 } = this;
2471
+ this.finished = true;
2472
+ // Padding
2473
+ clean(this.buffer.subarray(pos));
2474
+ swap32IfBE(buffer32);
2475
+ this.compress(buffer32, 0, true);
2476
+ swap32IfBE(buffer32);
2477
+ const out32 = u32(out);
2478
+ this.get().forEach((v, i) => (out32[i] = swap8IfBE(v)));
2479
+ }
2480
+ digest() {
2481
+ const { buffer, outputLen } = this;
2482
+ this.digestInto(buffer);
2483
+ const res = buffer.slice(0, outputLen);
2484
+ this.destroy();
2485
+ return res;
2486
+ }
2487
+ _cloneInto(to) {
2488
+ const { buffer, length, finished, destroyed, outputLen, pos } = this;
2489
+ to ||= new this.constructor({ dkLen: outputLen });
2490
+ to.set(...this.get());
2491
+ to.buffer.set(buffer);
2492
+ to.destroyed = destroyed;
2493
+ to.finished = finished;
2494
+ to.length = length;
2495
+ to.pos = pos;
2496
+ // @ts-ignore
2497
+ to.outputLen = outputLen;
2498
+ return to;
2499
+ }
2500
+ clone() {
2501
+ return this._cloneInto();
2502
+ }
2503
+ }
2504
+ /** Internal blake2b hash class. */
2505
+ class _BLAKE2b extends _BLAKE2 {
2506
+ // Same as SHA-512, but LE
2507
+ v0l = B2B_IV[0] | 0;
2508
+ v0h = B2B_IV[1] | 0;
2509
+ v1l = B2B_IV[2] | 0;
2510
+ v1h = B2B_IV[3] | 0;
2511
+ v2l = B2B_IV[4] | 0;
2512
+ v2h = B2B_IV[5] | 0;
2513
+ v3l = B2B_IV[6] | 0;
2514
+ v3h = B2B_IV[7] | 0;
2515
+ v4l = B2B_IV[8] | 0;
2516
+ v4h = B2B_IV[9] | 0;
2517
+ v5l = B2B_IV[10] | 0;
2518
+ v5h = B2B_IV[11] | 0;
2519
+ v6l = B2B_IV[12] | 0;
2520
+ v6h = B2B_IV[13] | 0;
2521
+ v7l = B2B_IV[14] | 0;
2522
+ v7h = B2B_IV[15] | 0;
2523
+ constructor(opts = {}) {
2524
+ const olen = opts.dkLen === undefined ? 64 : opts.dkLen;
2525
+ super(128, olen);
2526
+ checkBlake2Opts(olen, opts, 64, 16, 16);
2527
+ let { key, personalization, salt } = opts;
2528
+ let keyLength = 0;
2529
+ if (key !== undefined) {
2530
+ abytes(key, undefined, 'key');
2531
+ keyLength = key.length;
2532
+ }
2533
+ this.v0l ^= this.outputLen | (keyLength << 8) | (0x01 << 16) | (0x01 << 24);
2534
+ if (salt !== undefined) {
2535
+ abytes(salt, undefined, 'salt');
2536
+ const slt = u32(salt);
2537
+ this.v4l ^= swap8IfBE(slt[0]);
2538
+ this.v4h ^= swap8IfBE(slt[1]);
2539
+ this.v5l ^= swap8IfBE(slt[2]);
2540
+ this.v5h ^= swap8IfBE(slt[3]);
2541
+ }
2542
+ if (personalization !== undefined) {
2543
+ abytes(personalization, undefined, 'personalization');
2544
+ const pers = u32(personalization);
2545
+ this.v6l ^= swap8IfBE(pers[0]);
2546
+ this.v6h ^= swap8IfBE(pers[1]);
2547
+ this.v7l ^= swap8IfBE(pers[2]);
2548
+ this.v7h ^= swap8IfBE(pers[3]);
2549
+ }
2550
+ if (key !== undefined) {
2551
+ // Pad to blockLen and update
2552
+ const tmp = new Uint8Array(this.blockLen);
2553
+ tmp.set(key);
2554
+ this.update(tmp);
2555
+ }
2556
+ }
2557
+ // prettier-ignore
2558
+ get() {
2559
+ let { v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h } = this;
2560
+ return [v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h];
2561
+ }
2562
+ // prettier-ignore
2563
+ set(v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h) {
2564
+ this.v0l = v0l | 0;
2565
+ this.v0h = v0h | 0;
2566
+ this.v1l = v1l | 0;
2567
+ this.v1h = v1h | 0;
2568
+ this.v2l = v2l | 0;
2569
+ this.v2h = v2h | 0;
2570
+ this.v3l = v3l | 0;
2571
+ this.v3h = v3h | 0;
2572
+ this.v4l = v4l | 0;
2573
+ this.v4h = v4h | 0;
2574
+ this.v5l = v5l | 0;
2575
+ this.v5h = v5h | 0;
2576
+ this.v6l = v6l | 0;
2577
+ this.v6h = v6h | 0;
2578
+ this.v7l = v7l | 0;
2579
+ this.v7h = v7h | 0;
2580
+ }
2581
+ compress(msg, offset, isLast) {
2582
+ this.get().forEach((v, i) => (BBUF[i] = v)); // First half from state.
2583
+ BBUF.set(B2B_IV, 16); // Second half from IV.
2584
+ let { h, l } = fromBig(BigInt(this.length));
2585
+ BBUF[24] = B2B_IV[8] ^ l; // Low word of the offset.
2586
+ BBUF[25] = B2B_IV[9] ^ h; // High word.
2587
+ // Invert all bits for last block
2588
+ if (isLast) {
2589
+ BBUF[28] = ~BBUF[28];
2590
+ BBUF[29] = ~BBUF[29];
2591
+ }
2592
+ let j = 0;
2593
+ const s = BSIGMA;
2594
+ for (let i = 0; i < 12; i++) {
2595
+ G1b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
2596
+ G2b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
2597
+ G1b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
2598
+ G2b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
2599
+ G1b(2, 6, 10, 14, msg, offset + 2 * s[j++]);
2600
+ G2b(2, 6, 10, 14, msg, offset + 2 * s[j++]);
2601
+ G1b(3, 7, 11, 15, msg, offset + 2 * s[j++]);
2602
+ G2b(3, 7, 11, 15, msg, offset + 2 * s[j++]);
2603
+ G1b(0, 5, 10, 15, msg, offset + 2 * s[j++]);
2604
+ G2b(0, 5, 10, 15, msg, offset + 2 * s[j++]);
2605
+ G1b(1, 6, 11, 12, msg, offset + 2 * s[j++]);
2606
+ G2b(1, 6, 11, 12, msg, offset + 2 * s[j++]);
2607
+ G1b(2, 7, 8, 13, msg, offset + 2 * s[j++]);
2608
+ G2b(2, 7, 8, 13, msg, offset + 2 * s[j++]);
2609
+ G1b(3, 4, 9, 14, msg, offset + 2 * s[j++]);
2610
+ G2b(3, 4, 9, 14, msg, offset + 2 * s[j++]);
2611
+ }
2612
+ this.v0l ^= BBUF[0] ^ BBUF[16];
2613
+ this.v0h ^= BBUF[1] ^ BBUF[17];
2614
+ this.v1l ^= BBUF[2] ^ BBUF[18];
2615
+ this.v1h ^= BBUF[3] ^ BBUF[19];
2616
+ this.v2l ^= BBUF[4] ^ BBUF[20];
2617
+ this.v2h ^= BBUF[5] ^ BBUF[21];
2618
+ this.v3l ^= BBUF[6] ^ BBUF[22];
2619
+ this.v3h ^= BBUF[7] ^ BBUF[23];
2620
+ this.v4l ^= BBUF[8] ^ BBUF[24];
2621
+ this.v4h ^= BBUF[9] ^ BBUF[25];
2622
+ this.v5l ^= BBUF[10] ^ BBUF[26];
2623
+ this.v5h ^= BBUF[11] ^ BBUF[27];
2624
+ this.v6l ^= BBUF[12] ^ BBUF[28];
2625
+ this.v6h ^= BBUF[13] ^ BBUF[29];
2626
+ this.v7l ^= BBUF[14] ^ BBUF[30];
2627
+ this.v7h ^= BBUF[15] ^ BBUF[31];
2628
+ clean(BBUF);
2629
+ }
2630
+ destroy() {
2631
+ this.destroyed = true;
2632
+ clean(this.buffer32);
2633
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
2634
+ }
2635
+ }
2636
+ /**
2637
+ * Blake2b hash function. 64-bit. 1.5x slower than blake2s in JS.
2638
+ * @param msg - message that would be hashed
2639
+ * @param opts - dkLen output length, key for MAC mode, salt, personalization
2640
+ */
2641
+ const blake2b = /* @__PURE__ */ createHasher((opts) => new _BLAKE2b(opts));
2642
+
2189
2643
  /**
2190
2644
  * @packageDocumentation
2191
2645
  * @module @taquito/utils
@@ -2195,6 +2649,7 @@
2195
2649
  * Copyright (c) 2018 Andrew Kishino
2196
2650
  * Copyright (c) 2017 Stephen Andrews
2197
2651
  */
2652
+ const BigNumber = BigNumberJs;
2198
2653
  /**
2199
2654
  * list of prefixes that can be used to decode an address
2200
2655
  */
@@ -2422,7 +2877,7 @@
2422
2877
  default:
2423
2878
  throw new core.InvalidPublicKeyError(publicKey, core.ValidationResult.NO_PREFIX_MATCHED);
2424
2879
  }
2425
- const hashed = blake2b.hash(key, 20);
2880
+ const hashed = blake2b(key, { dkLen: 20 });
2426
2881
  return b58Encode(hashed, pkhPre);
2427
2882
  }
2428
2883
  /**
@@ -2547,7 +3002,7 @@
2547
3002
  * @example encodeExpr('050a000000160000b2e19a9e74440d86c59f13dab8a18ff873e889ea') // return 'exprv6UsC1sN3Fk2XfgcJCL8NCerP5rCGy1PRESZAqr7L2JdzX55EN'
2548
3003
  */
2549
3004
  function encodeExpr(value) {
2550
- const blakeHash = blake2b.hash(hex2buf(value), 32);
3005
+ const blakeHash = blake2b(hex2buf(value), { dkLen: 32 });
2551
3006
  return b58Encode(blakeHash, exports.PrefixV2.ScriptExpr);
2552
3007
  }
2553
3008
  /**
@@ -2557,7 +3012,7 @@
2557
3012
  * @example encodeOpHash('0f185d8a30061e8134c162dbb7a6c3ab8f5fdb153363ccd6149b49a33481156a6c00b2e19a9e74440d86c59f13dab8a18ff873e889eaa304ab05da13000001f1585a7384f36e45fb43dc37e8ce172bced3e05700ff0000000002002110c033f3a990c2e46a3d6054ecc2f74072aae7a34b5ac4d9ce9edc11c2410a97695682108951786f05b361da03b97245dc9897e1955e08b5b8d9e153b0bdeb0d') // return 'opapqvVXmebRTCFd2GQFydr4tJj3V5QocQuTmuhbatcHm4Seo2t'
2558
3013
  */
2559
3014
  function encodeOpHash(value) {
2560
- const blakeHash = blake2b.hash(hex2buf(value), 32);
3015
+ const blakeHash = blake2b(hex2buf(value), { dkLen: 32 });
2561
3016
  return b58Encode(blakeHash, exports.PrefixV2.OperationHash);
2562
3017
  }
2563
3018
  /**
@@ -2973,8 +3428,8 @@
2973
3428
 
2974
3429
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
2975
3430
  const VERSION = {
2976
- "commitHash": "05df48fee92f846cba793920d6fa829afd6a1847",
2977
- "version": "24.3.0-beta.1"
3431
+ "commitHash": "a312cd3f4fc0ab0fb3351bfffe6ad855772cb077",
3432
+ "version": "24.3.0-beta.3"
2978
3433
  };
2979
3434
 
2980
3435
  const BLS12_381_DST = 'BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_';
@@ -3056,16 +3511,16 @@
3056
3511
  }
3057
3512
  }
3058
3513
  function verifyEdSignature(sig, msg, publicKey) {
3059
- const hash = blake2b.hash(msg, 32);
3514
+ const hash = blake2b(msg, { dkLen: 32 });
3060
3515
  try {
3061
- return ed25519.verify(publicKey, hash, sig);
3516
+ return ed25519.ed25519.verify(sig, hash, publicKey);
3062
3517
  }
3063
3518
  catch {
3064
3519
  return false;
3065
3520
  }
3066
3521
  }
3067
3522
  function verifySpSignature(sig, msg, publicKey) {
3068
- const hash = blake2b.hash(msg, 32);
3523
+ const hash = blake2b(msg, { dkLen: 32 });
3069
3524
  try {
3070
3525
  return secp256k1.secp256k1.verify(sig, hash, publicKey);
3071
3526
  }
@@ -3074,7 +3529,7 @@
3074
3529
  }
3075
3530
  }
3076
3531
  function verifyP2Signature(sig, msg, publicKey) {
3077
- const hash = blake2b.hash(msg, 32);
3532
+ const hash = blake2b(msg, { dkLen: 32 });
3078
3533
  try {
3079
3534
  return nist.p256.verify(sig, hash, publicKey);
3080
3535
  }
@@ -3141,7 +3596,13 @@
3141
3596
  }
3142
3597
  }
3143
3598
  function format(from = 'mutez', to = 'mutez', amount) {
3144
- const bigNum = new BigNumber(amount);
3599
+ let bigNum;
3600
+ try {
3601
+ bigNum = new BigNumberJs(amount);
3602
+ }
3603
+ catch {
3604
+ return amount;
3605
+ }
3145
3606
  if (bigNum.isNaN()) {
3146
3607
  return amount;
3147
3608
  }