@taquito/ledger-signer 24.3.1-beta.1 → 25.0.0-beta.1
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/dist/lib/version.js
CHANGED
|
@@ -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": "
|
|
7
|
-
"version": "
|
|
6
|
+
"commitHash": "9851c9b7e8387a82f8ff0aa6a34277a9108bb68c",
|
|
7
|
+
"version": "25.0.0-beta.1"
|
|
8
8
|
};
|
|
@@ -2494,22 +2494,62 @@ function extractValue(idxLength, response) {
|
|
|
2494
2494
|
}
|
|
2495
2495
|
|
|
2496
2496
|
/**
|
|
2497
|
-
*
|
|
2498
|
-
* @
|
|
2497
|
+
* Checks if something is Uint8Array. Be careful: nodejs Buffer will return true.
|
|
2498
|
+
* @param a - value to test
|
|
2499
|
+
* @returns `true` when the value is a Uint8Array-compatible view.
|
|
2500
|
+
* @example
|
|
2501
|
+
* Check whether a value is a Uint8Array-compatible view.
|
|
2502
|
+
* ```ts
|
|
2503
|
+
* isBytes(new Uint8Array([1, 2, 3]));
|
|
2504
|
+
* ```
|
|
2499
2505
|
*/
|
|
2500
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2501
|
-
/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
|
|
2502
2506
|
function isBytes(a) {
|
|
2503
|
-
|
|
2507
|
+
// Plain `instanceof Uint8Array` is too strict for some Buffer / proxy / cross-realm cases.
|
|
2508
|
+
// The fallback still requires a real ArrayBuffer view, so plain
|
|
2509
|
+
// JSON-deserialized `{ constructor: ... }` spoofing is rejected, and
|
|
2510
|
+
// `BYTES_PER_ELEMENT === 1` keeps the fallback on byte-oriented views.
|
|
2511
|
+
return (a instanceof Uint8Array ||
|
|
2512
|
+
(ArrayBuffer.isView(a) &&
|
|
2513
|
+
a.constructor.name === 'Uint8Array' &&
|
|
2514
|
+
'BYTES_PER_ELEMENT' in a &&
|
|
2515
|
+
a.BYTES_PER_ELEMENT === 1));
|
|
2504
2516
|
}
|
|
2505
|
-
/**
|
|
2517
|
+
/**
|
|
2518
|
+
* Asserts something is a non-negative integer.
|
|
2519
|
+
* @param n - number to validate
|
|
2520
|
+
* @param title - label included in thrown errors
|
|
2521
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
2522
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
2523
|
+
* @example
|
|
2524
|
+
* Validate a non-negative integer option.
|
|
2525
|
+
* ```ts
|
|
2526
|
+
* anumber(32, 'length');
|
|
2527
|
+
* ```
|
|
2528
|
+
*/
|
|
2506
2529
|
function anumber(n, title = '') {
|
|
2530
|
+
if (typeof n !== 'number') {
|
|
2531
|
+
const prefix = title && `"${title}" `;
|
|
2532
|
+
throw new TypeError(`${prefix}expected number, got ${typeof n}`);
|
|
2533
|
+
}
|
|
2507
2534
|
if (!Number.isSafeInteger(n) || n < 0) {
|
|
2508
2535
|
const prefix = title && `"${title}" `;
|
|
2509
|
-
throw new
|
|
2536
|
+
throw new RangeError(`${prefix}expected integer >= 0, got ${n}`);
|
|
2510
2537
|
}
|
|
2511
2538
|
}
|
|
2512
|
-
/**
|
|
2539
|
+
/**
|
|
2540
|
+
* Asserts something is Uint8Array.
|
|
2541
|
+
* @param value - value to validate
|
|
2542
|
+
* @param length - optional exact length constraint
|
|
2543
|
+
* @param title - label included in thrown errors
|
|
2544
|
+
* @returns The validated byte array.
|
|
2545
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
2546
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
2547
|
+
* @example
|
|
2548
|
+
* Validate that a value is a byte array.
|
|
2549
|
+
* ```ts
|
|
2550
|
+
* abytes(new Uint8Array([1, 2, 3]));
|
|
2551
|
+
* ```
|
|
2552
|
+
*/
|
|
2513
2553
|
function abytes(value, length, title = '') {
|
|
2514
2554
|
const bytes = isBytes(value);
|
|
2515
2555
|
const len = value?.length;
|
|
@@ -2518,64 +2558,171 @@ function abytes(value, length, title = '') {
|
|
|
2518
2558
|
const prefix = title && `"${title}" `;
|
|
2519
2559
|
const ofLen = needsLen ? ` of length ${length}` : '';
|
|
2520
2560
|
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
2521
|
-
|
|
2561
|
+
const message = prefix + 'expected Uint8Array' + ofLen + ', got ' + got;
|
|
2562
|
+
if (!bytes)
|
|
2563
|
+
throw new TypeError(message);
|
|
2564
|
+
throw new RangeError(message);
|
|
2522
2565
|
}
|
|
2523
2566
|
return value;
|
|
2524
2567
|
}
|
|
2525
|
-
/**
|
|
2568
|
+
/**
|
|
2569
|
+
* Asserts a hash instance has not been destroyed or finished.
|
|
2570
|
+
* @param instance - hash instance to validate
|
|
2571
|
+
* @param checkFinished - whether to reject finalized instances
|
|
2572
|
+
* @throws If the hash instance has already been destroyed or finalized. {@link Error}
|
|
2573
|
+
* @example
|
|
2574
|
+
* Validate that a hash instance is still usable.
|
|
2575
|
+
* ```ts
|
|
2576
|
+
* import { aexists } from '@noble/hashes/utils.js';
|
|
2577
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
2578
|
+
* const hash = sha256.create();
|
|
2579
|
+
* aexists(hash);
|
|
2580
|
+
* ```
|
|
2581
|
+
*/
|
|
2526
2582
|
function aexists(instance, checkFinished = true) {
|
|
2527
2583
|
if (instance.destroyed)
|
|
2528
2584
|
throw new Error('Hash instance has been destroyed');
|
|
2529
2585
|
if (checkFinished && instance.finished)
|
|
2530
2586
|
throw new Error('Hash#digest() has already been called');
|
|
2531
2587
|
}
|
|
2532
|
-
/**
|
|
2588
|
+
/**
|
|
2589
|
+
* Asserts output is a sufficiently-sized byte array.
|
|
2590
|
+
* @param out - destination buffer
|
|
2591
|
+
* @param instance - hash instance providing output length
|
|
2592
|
+
* Oversized buffers are allowed; downstream code only promises to fill the first `outputLen` bytes.
|
|
2593
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
2594
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
2595
|
+
* @example
|
|
2596
|
+
* Validate a caller-provided digest buffer.
|
|
2597
|
+
* ```ts
|
|
2598
|
+
* import { aoutput } from '@noble/hashes/utils.js';
|
|
2599
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
2600
|
+
* const hash = sha256.create();
|
|
2601
|
+
* aoutput(new Uint8Array(hash.outputLen), hash);
|
|
2602
|
+
* ```
|
|
2603
|
+
*/
|
|
2533
2604
|
function aoutput(out, instance) {
|
|
2534
2605
|
abytes(out, undefined, 'digestInto() output');
|
|
2535
2606
|
const min = instance.outputLen;
|
|
2536
2607
|
if (out.length < min) {
|
|
2537
|
-
throw new
|
|
2608
|
+
throw new RangeError('"digestInto() output" expected to be of length >=' + min);
|
|
2538
2609
|
}
|
|
2539
2610
|
}
|
|
2540
|
-
/**
|
|
2611
|
+
/**
|
|
2612
|
+
* Casts a typed array view to Uint32Array.
|
|
2613
|
+
* `arr.byteOffset` must already be 4-byte aligned or the platform
|
|
2614
|
+
* Uint32Array constructor will throw.
|
|
2615
|
+
* @param arr - source typed array
|
|
2616
|
+
* @returns Uint32Array view over the same buffer.
|
|
2617
|
+
* @example
|
|
2618
|
+
* Reinterpret a byte array as 32-bit words.
|
|
2619
|
+
* ```ts
|
|
2620
|
+
* u32(new Uint8Array(8));
|
|
2621
|
+
* ```
|
|
2622
|
+
*/
|
|
2541
2623
|
function u32(arr) {
|
|
2542
2624
|
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
2543
2625
|
}
|
|
2544
|
-
/**
|
|
2626
|
+
/**
|
|
2627
|
+
* Zeroizes typed arrays in place. Warning: JS provides no guarantees.
|
|
2628
|
+
* @param arrays - arrays to overwrite with zeros
|
|
2629
|
+
* @example
|
|
2630
|
+
* Zeroize sensitive buffers in place.
|
|
2631
|
+
* ```ts
|
|
2632
|
+
* clean(new Uint8Array([1, 2, 3]));
|
|
2633
|
+
* ```
|
|
2634
|
+
*/
|
|
2545
2635
|
function clean(...arrays) {
|
|
2546
2636
|
for (let i = 0; i < arrays.length; i++) {
|
|
2547
2637
|
arrays[i].fill(0);
|
|
2548
2638
|
}
|
|
2549
2639
|
}
|
|
2550
|
-
/**
|
|
2640
|
+
/** Whether the current platform is little-endian. */
|
|
2551
2641
|
const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
|
|
2552
|
-
/**
|
|
2642
|
+
/**
|
|
2643
|
+
* Byte-swap operation for uint32 values.
|
|
2644
|
+
* @param word - source word
|
|
2645
|
+
* @returns Word with reversed byte order.
|
|
2646
|
+
* @example
|
|
2647
|
+
* Reverse the byte order of a 32-bit word.
|
|
2648
|
+
* ```ts
|
|
2649
|
+
* byteSwap(0x11223344);
|
|
2650
|
+
* ```
|
|
2651
|
+
*/
|
|
2553
2652
|
function byteSwap(word) {
|
|
2554
2653
|
return (((word << 24) & 0xff000000) |
|
|
2555
2654
|
((word << 8) & 0xff0000) |
|
|
2556
2655
|
((word >>> 8) & 0xff00) |
|
|
2557
2656
|
((word >>> 24) & 0xff));
|
|
2558
2657
|
}
|
|
2559
|
-
/**
|
|
2658
|
+
/**
|
|
2659
|
+
* Conditionally byte-swaps one 32-bit word on big-endian platforms.
|
|
2660
|
+
* @param n - source word
|
|
2661
|
+
* @returns Original or byte-swapped word depending on platform endianness.
|
|
2662
|
+
* @example
|
|
2663
|
+
* Normalize a 32-bit word for host endianness.
|
|
2664
|
+
* ```ts
|
|
2665
|
+
* swap8IfBE(0x11223344);
|
|
2666
|
+
* ```
|
|
2667
|
+
*/
|
|
2560
2668
|
const swap8IfBE = isLE
|
|
2561
2669
|
? (n) => n
|
|
2562
|
-
: (n) => byteSwap(n);
|
|
2563
|
-
/**
|
|
2670
|
+
: (n) => byteSwap(n) >>> 0;
|
|
2671
|
+
/**
|
|
2672
|
+
* Byte-swaps every word of a Uint32Array in place.
|
|
2673
|
+
* @param arr - array to mutate
|
|
2674
|
+
* @returns The same array after mutation; callers pass live state arrays here.
|
|
2675
|
+
* @example
|
|
2676
|
+
* Reverse the byte order of every word in place.
|
|
2677
|
+
* ```ts
|
|
2678
|
+
* byteSwap32(new Uint32Array([0x11223344]));
|
|
2679
|
+
* ```
|
|
2680
|
+
*/
|
|
2564
2681
|
function byteSwap32(arr) {
|
|
2565
2682
|
for (let i = 0; i < arr.length; i++) {
|
|
2566
2683
|
arr[i] = byteSwap(arr[i]);
|
|
2567
2684
|
}
|
|
2568
2685
|
return arr;
|
|
2569
2686
|
}
|
|
2687
|
+
/**
|
|
2688
|
+
* Conditionally byte-swaps a Uint32Array on big-endian platforms.
|
|
2689
|
+
* @param u - array to normalize for host endianness
|
|
2690
|
+
* @returns Original or byte-swapped array depending on platform endianness.
|
|
2691
|
+
* On big-endian runtimes this mutates `u` in place via `byteSwap32(...)`.
|
|
2692
|
+
* @example
|
|
2693
|
+
* Normalize a word array for host endianness.
|
|
2694
|
+
* ```ts
|
|
2695
|
+
* swap32IfBE(new Uint32Array([0x11223344]));
|
|
2696
|
+
* ```
|
|
2697
|
+
*/
|
|
2570
2698
|
const swap32IfBE = isLE
|
|
2571
2699
|
? (u) => u
|
|
2572
2700
|
: byteSwap32;
|
|
2573
|
-
/**
|
|
2701
|
+
/**
|
|
2702
|
+
* Creates a callable hash function from a stateful class constructor.
|
|
2703
|
+
* @param hashCons - hash constructor or factory
|
|
2704
|
+
* @param info - optional metadata such as DER OID
|
|
2705
|
+
* @returns Frozen callable hash wrapper with `.create()`.
|
|
2706
|
+
* Wrapper construction eagerly calls `hashCons(undefined)` once to read
|
|
2707
|
+
* `outputLen` / `blockLen`, so constructor side effects happen at module
|
|
2708
|
+
* init time.
|
|
2709
|
+
* @example
|
|
2710
|
+
* Wrap a stateful hash constructor into a callable helper.
|
|
2711
|
+
* ```ts
|
|
2712
|
+
* import { createHasher } from '@noble/hashes/utils.js';
|
|
2713
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
2714
|
+
* const wrapped = createHasher(sha256.create, { oid: sha256.oid });
|
|
2715
|
+
* wrapped(new Uint8Array([1]));
|
|
2716
|
+
* ```
|
|
2717
|
+
*/
|
|
2574
2718
|
function createHasher(hashCons, info = {}) {
|
|
2575
|
-
const hashC = (msg, opts) => hashCons(opts)
|
|
2719
|
+
const hashC = (msg, opts) => hashCons(opts)
|
|
2720
|
+
.update(msg)
|
|
2721
|
+
.digest();
|
|
2576
2722
|
const tmp = hashCons(undefined);
|
|
2577
2723
|
hashC.outputLen = tmp.outputLen;
|
|
2578
2724
|
hashC.blockLen = tmp.blockLen;
|
|
2725
|
+
hashC.canXOF = tmp.canXOF;
|
|
2579
2726
|
hashC.create = (opts) => hashCons(opts);
|
|
2580
2727
|
Object.assign(hashC, info);
|
|
2581
2728
|
return Object.freeze(hashC);
|
|
@@ -2586,8 +2733,10 @@ function createHasher(hashCons, info = {}) {
|
|
|
2586
2733
|
* @module
|
|
2587
2734
|
*/
|
|
2588
2735
|
/**
|
|
2589
|
-
* Internal blake
|
|
2590
|
-
*
|
|
2736
|
+
* Internal blake permutation table.
|
|
2737
|
+
* Rows `0..9` serve BLAKE2s, rows `0..11` serve BLAKE2b with `10..11 = 0..1`, and Blake1 also
|
|
2738
|
+
* reuses the later rows shown below. Blake1 expands rounds `10..15` as `SIGMA[i % 10]`, so rows
|
|
2739
|
+
* `10..15` intentionally repeat rows `0..5` for the 14-round (256) and 16-round (512) variants.
|
|
2591
2740
|
*/
|
|
2592
2741
|
// prettier-ignore
|
|
2593
2742
|
const BSIGMA = /* @__PURE__ */ Uint8Array.from([
|
|
@@ -2610,35 +2759,38 @@ const BSIGMA = /* @__PURE__ */ Uint8Array.from([
|
|
|
2610
2759
|
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
|
|
2611
2760
|
]);
|
|
2612
2761
|
|
|
2613
|
-
/**
|
|
2614
|
-
* Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
|
|
2615
|
-
* @todo re-check https://issues.chromium.org/issues/42212588
|
|
2616
|
-
* @module
|
|
2617
|
-
*/
|
|
2618
2762
|
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
2619
2763
|
const _32n = /* @__PURE__ */ BigInt(32);
|
|
2764
|
+
// Split bigint into two 32-bit halves. With `le=true`, returned fields become `{ h: low, l: high
|
|
2765
|
+
// }` to match little-endian word order rather than the property names.
|
|
2620
2766
|
function fromBig(n, le = false) {
|
|
2621
2767
|
if (le)
|
|
2622
2768
|
return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
|
|
2623
2769
|
return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
2624
2770
|
}
|
|
2625
|
-
//
|
|
2771
|
+
// High 32-bit half of a 64-bit right rotate, valid for `s` in `1..31`.
|
|
2626
2772
|
const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
|
|
2773
|
+
// Low 32-bit half of a 64-bit right rotate, valid for `s` in `1..31`.
|
|
2627
2774
|
const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
|
|
2628
|
-
//
|
|
2775
|
+
// High 32-bit half of a 64-bit right rotate, valid for `s` in `33..63`; `32` uses `rotr32*`.
|
|
2629
2776
|
const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
|
|
2777
|
+
// Low 32-bit half of a 64-bit right rotate, valid for `s` in `33..63`; `32` uses `rotr32*`.
|
|
2630
2778
|
const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
|
|
2631
|
-
//
|
|
2779
|
+
// High 32-bit half of a 64-bit right rotate for `s === 32`; this is just the swapped low half.
|
|
2632
2780
|
const rotr32H = (_h, l) => l;
|
|
2781
|
+
// Low 32-bit half of a 64-bit right rotate for `s === 32`; this is just the swapped high half.
|
|
2633
2782
|
const rotr32L = (h, _l) => h;
|
|
2634
|
-
//
|
|
2635
|
-
//
|
|
2783
|
+
// Add two split 64-bit words and return the split `{ h, l }` sum.
|
|
2784
|
+
// JS uses 32-bit signed integers for bitwise operations, so we cannot simply shift the carry out
|
|
2785
|
+
// of the low sum and instead use division.
|
|
2636
2786
|
function add(Ah, Al, Bh, Bl) {
|
|
2637
2787
|
const l = (Al >>> 0) + (Bl >>> 0);
|
|
2638
2788
|
return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
|
|
2639
2789
|
}
|
|
2640
2790
|
// Addition with more than 2 elements
|
|
2791
|
+
// Unmasked low-word accumulator for 3-way addition; pass the raw result into `add3H(...)`.
|
|
2641
2792
|
const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
2793
|
+
// High-word finalize step for 3-way addition; `low` must be the untruncated output of `add3L(...)`.
|
|
2642
2794
|
const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
|
|
2643
2795
|
|
|
2644
2796
|
/**
|
|
@@ -2646,14 +2798,15 @@ const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
|
|
|
2646
2798
|
* b could have been faster, but there is no fast u64 in js, so s is 1.5x faster.
|
|
2647
2799
|
* @module
|
|
2648
2800
|
*/
|
|
2649
|
-
// Same as SHA512_IV
|
|
2801
|
+
// Same IV words as `SHA512_IV`, but endian-swapped into LE u32 low/high halves
|
|
2802
|
+
// for the BLAKE2b u64 helpers below.
|
|
2650
2803
|
const B2B_IV = /* @__PURE__ */ Uint32Array.from([
|
|
2651
2804
|
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372, 0x5f1d36f1, 0xa54ff53a,
|
|
2652
2805
|
0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c, 0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19,
|
|
2653
2806
|
]);
|
|
2654
|
-
//
|
|
2807
|
+
// Shared synchronous BLAKE2b work vector as LE u32 low/high halves.
|
|
2655
2808
|
const BBUF = /* @__PURE__ */ new Uint32Array(32);
|
|
2656
|
-
//
|
|
2809
|
+
// BLAKE2b G mix split into two half-rounds over LE u32 low/high limbs.
|
|
2657
2810
|
function G1b(a, b, c, d, msg, x) {
|
|
2658
2811
|
// NOTE: V is LE here
|
|
2659
2812
|
const Xl = msg[x], Xh = msg[x + 1]; // prettier-ignore
|
|
@@ -2678,6 +2831,7 @@ function G1b(a, b, c, d, msg, x) {
|
|
|
2678
2831
|
((BBUF[2 * c] = Cl), (BBUF[2 * c + 1] = Ch));
|
|
2679
2832
|
((BBUF[2 * d] = Dl), (BBUF[2 * d + 1] = Dh));
|
|
2680
2833
|
}
|
|
2834
|
+
// Second half-round of the same LE-limb BLAKE2b G mix; `x` is the message word offset.
|
|
2681
2835
|
function G2b(a, b, c, d, msg, x) {
|
|
2682
2836
|
// NOTE: V is LE here
|
|
2683
2837
|
const Xl = msg[x], Xh = msg[x + 1]; // prettier-ignore
|
|
@@ -2704,9 +2858,11 @@ function G2b(a, b, c, d, msg, x) {
|
|
|
2704
2858
|
}
|
|
2705
2859
|
function checkBlake2Opts(outputLen, opts = {}, keyLen, saltLen, persLen) {
|
|
2706
2860
|
anumber(keyLen);
|
|
2707
|
-
|
|
2861
|
+
// RFC 7693 §2.1 requires digest length nn in 1..keyLen.
|
|
2862
|
+
if (outputLen <= 0 || outputLen > keyLen)
|
|
2708
2863
|
throw new Error('outputLen bigger than keyLen');
|
|
2709
2864
|
const { key, salt, personalization } = opts;
|
|
2865
|
+
// This API uses `undefined` for the RFC 7693 `kk = 0` case, so a provided key must be non-empty.
|
|
2710
2866
|
if (key !== undefined && (key.length < 1 || key.length > keyLen))
|
|
2711
2867
|
throw new Error('"key" expected to be undefined or of length=1..' + keyLen);
|
|
2712
2868
|
if (salt !== undefined)
|
|
@@ -2724,6 +2880,7 @@ class _BLAKE2 {
|
|
|
2724
2880
|
pos = 0;
|
|
2725
2881
|
blockLen;
|
|
2726
2882
|
outputLen;
|
|
2883
|
+
canXOF = false;
|
|
2727
2884
|
constructor(blockLen, outputLen) {
|
|
2728
2885
|
anumber(blockLen);
|
|
2729
2886
|
anumber(outputLen);
|
|
@@ -2753,7 +2910,7 @@ class _BLAKE2 {
|
|
|
2753
2910
|
}
|
|
2754
2911
|
const take = Math.min(blockLen - this.pos, len - pos);
|
|
2755
2912
|
const dataOffset = offset + pos;
|
|
2756
|
-
//
|
|
2913
|
+
// Zero-copy only for full, 4-byte-aligned, non-final blocks.
|
|
2757
2914
|
if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
|
|
2758
2915
|
const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
|
|
2759
2916
|
swap32IfBE(data32);
|
|
@@ -2781,18 +2938,33 @@ class _BLAKE2 {
|
|
|
2781
2938
|
swap32IfBE(buffer32);
|
|
2782
2939
|
this.compress(buffer32, 0, true);
|
|
2783
2940
|
swap32IfBE(buffer32);
|
|
2941
|
+
// Reject unaligned views explicitly instead of hiding them behind a full scratch copy.
|
|
2942
|
+
if (out.byteOffset & 3)
|
|
2943
|
+
throw new RangeError('"digestInto() output" expected 4-byte aligned byteOffset, got ' + out.byteOffset);
|
|
2944
|
+
const state = this.get();
|
|
2784
2945
|
const out32 = u32(out);
|
|
2785
|
-
|
|
2946
|
+
const full = Math.floor(this.outputLen / 4);
|
|
2947
|
+
for (let i = 0; i < full; i++)
|
|
2948
|
+
out32[i] = swap8IfBE(state[i]);
|
|
2949
|
+
const tail = this.outputLen % 4;
|
|
2950
|
+
if (!tail)
|
|
2951
|
+
return;
|
|
2952
|
+
const off = full * 4;
|
|
2953
|
+
const word = state[full];
|
|
2954
|
+
for (let i = 0; i < tail; i++)
|
|
2955
|
+
out[off + i] = word >>> (8 * i);
|
|
2786
2956
|
}
|
|
2787
2957
|
digest() {
|
|
2788
2958
|
const { buffer, outputLen } = this;
|
|
2789
2959
|
this.digestInto(buffer);
|
|
2960
|
+
// Return a copy so callers do not alias the instance scratch buffer used during finalization.
|
|
2790
2961
|
const res = buffer.slice(0, outputLen);
|
|
2791
2962
|
this.destroy();
|
|
2792
2963
|
return res;
|
|
2793
2964
|
}
|
|
2794
2965
|
_cloneInto(to) {
|
|
2795
2966
|
const { buffer, length, finished, destroyed, outputLen, pos } = this;
|
|
2967
|
+
// Recreate only `dkLen`; key/salt/personalization are already absorbed into the copied state.
|
|
2796
2968
|
to ||= new this.constructor({ dkLen: outputLen });
|
|
2797
2969
|
to.set(...this.get());
|
|
2798
2970
|
to.buffer.set(buffer);
|
|
@@ -2808,9 +2980,9 @@ class _BLAKE2 {
|
|
|
2808
2980
|
return this._cloneInto();
|
|
2809
2981
|
}
|
|
2810
2982
|
}
|
|
2811
|
-
/** Internal blake2b hash class. */
|
|
2983
|
+
/** Internal blake2b hash class with state stored as LE u32 low/high halves. */
|
|
2812
2984
|
class _BLAKE2b extends _BLAKE2 {
|
|
2813
|
-
// Same as SHA-512,
|
|
2985
|
+
// Same IV words as SHA-512 / BLAKE2b, encoded as LE u32 low/high halves.
|
|
2814
2986
|
v0l = B2B_IV[0] | 0;
|
|
2815
2987
|
v0h = B2B_IV[1] | 0;
|
|
2816
2988
|
v1l = B2B_IV[2] | 0;
|
|
@@ -2837,6 +3009,8 @@ class _BLAKE2b extends _BLAKE2 {
|
|
|
2837
3009
|
abytes(key, undefined, 'key');
|
|
2838
3010
|
keyLength = key.length;
|
|
2839
3011
|
}
|
|
3012
|
+
// RFC 7693 §2.5: xor `p[0] = 0x0101kknn` into the low 32 bits of `h[0]`;
|
|
3013
|
+
// the high 32 bits stay at `IV[0]`.
|
|
2840
3014
|
this.v0l ^= this.outputLen | (keyLength << 8) | (0x01 << 16) | (0x01 << 24);
|
|
2841
3015
|
if (salt !== undefined) {
|
|
2842
3016
|
abytes(salt, undefined, 'salt');
|
|
@@ -2898,6 +3072,8 @@ class _BLAKE2b extends _BLAKE2 {
|
|
|
2898
3072
|
}
|
|
2899
3073
|
let j = 0;
|
|
2900
3074
|
const s = BSIGMA;
|
|
3075
|
+
// SIGMA selects 64-bit message words; multiply by 2 because `msg` stores
|
|
3076
|
+
// each word as [low32, high32].
|
|
2901
3077
|
for (let i = 0; i < 12; i++) {
|
|
2902
3078
|
G1b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
|
|
2903
3079
|
G2b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
|
|
@@ -2943,7 +3119,15 @@ class _BLAKE2b extends _BLAKE2 {
|
|
|
2943
3119
|
/**
|
|
2944
3120
|
* Blake2b hash function. 64-bit. 1.5x slower than blake2s in JS.
|
|
2945
3121
|
* @param msg - message that would be hashed
|
|
2946
|
-
* @param opts -
|
|
3122
|
+
* @param opts - Optional output, MAC, salt, and personalization settings.
|
|
3123
|
+
* `dkLen` must be 1..64 bytes; `salt` and `personalization`, if present,
|
|
3124
|
+
* must be 16 bytes each. See {@link Blake2Opts}.
|
|
3125
|
+
* @returns Digest bytes.
|
|
3126
|
+
* @example
|
|
3127
|
+
* Hash a message with Blake2b.
|
|
3128
|
+
* ```ts
|
|
3129
|
+
* blake2b(new Uint8Array([97, 98, 99]));
|
|
3130
|
+
* ```
|
|
2947
3131
|
*/
|
|
2948
3132
|
const blake2b = /* @__PURE__ */ createHasher((opts) => new _BLAKE2b(opts));
|
|
2949
3133
|
|
|
@@ -2996,8 +3180,8 @@ class InvalidDerivationTypeError extends ParameterValidationError {
|
|
|
2996
3180
|
|
|
2997
3181
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
|
|
2998
3182
|
const VERSION = {
|
|
2999
|
-
"commitHash": "
|
|
3000
|
-
"version": "
|
|
3183
|
+
"commitHash": "9851c9b7e8387a82f8ff0aa6a34277a9108bb68c",
|
|
3184
|
+
"version": "25.0.0-beta.1"
|
|
3001
3185
|
};
|
|
3002
3186
|
|
|
3003
3187
|
/**
|