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

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