@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.
- package/README.md +1 -1
- package/dist/lib/encoding.js +8 -7
- package/dist/lib/format.js +7 -1
- package/dist/lib/verify-signature.js +6 -6
- package/dist/lib/version.js +2 -2
- package/dist/taquito-utils.es6.js +475 -15
- package/dist/taquito-utils.es6.js.map +1 -1
- package/dist/taquito-utils.umd.js +475 -14
- package/dist/taquito-utils.umd.js.map +1 -1
- package/dist/types/encoding.d.ts +4 -1
- package/package.json +10 -35
- package/signature.json +0 -202
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { hash } from '@stablelib/blake2b';
|
|
2
1
|
import bs58check from 'bs58check';
|
|
3
|
-
import
|
|
2
|
+
import BigNumberJs 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 {
|
|
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
|
|
@@ -2200,6 +2653,7 @@ const payloadLength = {
|
|
|
2200
2653
|
* Copyright (c) 2018 Andrew Kishino
|
|
2201
2654
|
* Copyright (c) 2017 Stephen Andrews
|
|
2202
2655
|
*/
|
|
2656
|
+
const BigNumber = BigNumberJs;
|
|
2203
2657
|
/**
|
|
2204
2658
|
* list of prefixes that can be used to decode an address
|
|
2205
2659
|
*/
|
|
@@ -2427,7 +2881,7 @@ function getPkhfromPk(publicKey) {
|
|
|
2427
2881
|
default:
|
|
2428
2882
|
throw new InvalidPublicKeyError(publicKey, ValidationResult.NO_PREFIX_MATCHED);
|
|
2429
2883
|
}
|
|
2430
|
-
const hashed =
|
|
2884
|
+
const hashed = blake2b(key, { dkLen: 20 });
|
|
2431
2885
|
return b58Encode(hashed, pkhPre);
|
|
2432
2886
|
}
|
|
2433
2887
|
/**
|
|
@@ -2552,7 +3006,7 @@ function encodeBlsAddress(value) {
|
|
|
2552
3006
|
* @example encodeExpr('050a000000160000b2e19a9e74440d86c59f13dab8a18ff873e889ea') // return 'exprv6UsC1sN3Fk2XfgcJCL8NCerP5rCGy1PRESZAqr7L2JdzX55EN'
|
|
2553
3007
|
*/
|
|
2554
3008
|
function encodeExpr(value) {
|
|
2555
|
-
const blakeHash =
|
|
3009
|
+
const blakeHash = blake2b(hex2buf(value), { dkLen: 32 });
|
|
2556
3010
|
return b58Encode(blakeHash, PrefixV2.ScriptExpr);
|
|
2557
3011
|
}
|
|
2558
3012
|
/**
|
|
@@ -2562,7 +3016,7 @@ function encodeExpr(value) {
|
|
|
2562
3016
|
* @example encodeOpHash('0f185d8a30061e8134c162dbb7a6c3ab8f5fdb153363ccd6149b49a33481156a6c00b2e19a9e74440d86c59f13dab8a18ff873e889eaa304ab05da13000001f1585a7384f36e45fb43dc37e8ce172bced3e05700ff0000000002002110c033f3a990c2e46a3d6054ecc2f74072aae7a34b5ac4d9ce9edc11c2410a97695682108951786f05b361da03b97245dc9897e1955e08b5b8d9e153b0bdeb0d') // return 'opapqvVXmebRTCFd2GQFydr4tJj3V5QocQuTmuhbatcHm4Seo2t'
|
|
2563
3017
|
*/
|
|
2564
3018
|
function encodeOpHash(value) {
|
|
2565
|
-
const blakeHash =
|
|
3019
|
+
const blakeHash = blake2b(hex2buf(value), { dkLen: 32 });
|
|
2566
3020
|
return b58Encode(blakeHash, PrefixV2.OperationHash);
|
|
2567
3021
|
}
|
|
2568
3022
|
/**
|
|
@@ -2978,8 +3432,8 @@ function validateSmartRollupAddress(value) {
|
|
|
2978
3432
|
|
|
2979
3433
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
|
|
2980
3434
|
const VERSION = {
|
|
2981
|
-
"commitHash": "
|
|
2982
|
-
"version": "24.3.0-beta.
|
|
3435
|
+
"commitHash": "a312cd3f4fc0ab0fb3351bfffe6ad855772cb077",
|
|
3436
|
+
"version": "24.3.0-beta.3"
|
|
2983
3437
|
};
|
|
2984
3438
|
|
|
2985
3439
|
const BLS12_381_DST = 'BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_';
|
|
@@ -3061,27 +3515,27 @@ function verifySignature(message, publicKey, signature, watermark, pop) {
|
|
|
3061
3515
|
}
|
|
3062
3516
|
}
|
|
3063
3517
|
function verifyEdSignature(sig, msg, publicKey) {
|
|
3064
|
-
const hash
|
|
3518
|
+
const hash = blake2b(msg, { dkLen: 32 });
|
|
3065
3519
|
try {
|
|
3066
|
-
return verify(
|
|
3520
|
+
return ed25519.verify(sig, hash, publicKey);
|
|
3067
3521
|
}
|
|
3068
3522
|
catch {
|
|
3069
3523
|
return false;
|
|
3070
3524
|
}
|
|
3071
3525
|
}
|
|
3072
3526
|
function verifySpSignature(sig, msg, publicKey) {
|
|
3073
|
-
const hash
|
|
3527
|
+
const hash = blake2b(msg, { dkLen: 32 });
|
|
3074
3528
|
try {
|
|
3075
|
-
return secp256k1.verify(sig, hash
|
|
3529
|
+
return secp256k1.verify(sig, hash, publicKey);
|
|
3076
3530
|
}
|
|
3077
3531
|
catch {
|
|
3078
3532
|
return false;
|
|
3079
3533
|
}
|
|
3080
3534
|
}
|
|
3081
3535
|
function verifyP2Signature(sig, msg, publicKey) {
|
|
3082
|
-
const hash
|
|
3536
|
+
const hash = blake2b(msg, { dkLen: 32 });
|
|
3083
3537
|
try {
|
|
3084
|
-
return p256.verify(sig, hash
|
|
3538
|
+
return p256.verify(sig, hash, publicKey);
|
|
3085
3539
|
}
|
|
3086
3540
|
catch {
|
|
3087
3541
|
return false;
|
|
@@ -3146,7 +3600,13 @@ function getDecimal(format) {
|
|
|
3146
3600
|
}
|
|
3147
3601
|
}
|
|
3148
3602
|
function format(from = 'mutez', to = 'mutez', amount) {
|
|
3149
|
-
|
|
3603
|
+
let bigNum;
|
|
3604
|
+
try {
|
|
3605
|
+
bigNum = new BigNumberJs(amount);
|
|
3606
|
+
}
|
|
3607
|
+
catch {
|
|
3608
|
+
return amount;
|
|
3609
|
+
}
|
|
3150
3610
|
if (bigNum.isNaN()) {
|
|
3151
3611
|
return amount;
|
|
3152
3612
|
}
|