@solana/web3.js 1.95.5 → 1.96.0

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/lib/index.iife.js CHANGED
@@ -2401,38 +2401,37 @@ var solanaWeb3 = (function (exports) {
2401
2401
 
2402
2402
  var bufferExports = /*@__PURE__*/ requireBuffer();
2403
2403
 
2404
- function number$1(n) {
2404
+ function anumber$1(n) {
2405
2405
  if (!Number.isSafeInteger(n) || n < 0)
2406
- throw new Error(`positive integer expected, not ${n}`);
2406
+ throw new Error('positive integer expected, got ' + n);
2407
2407
  }
2408
2408
  // copied from utils
2409
- function isBytes$1(a) {
2410
- return (a instanceof Uint8Array ||
2411
- (a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
2409
+ function isBytes$2(a) {
2410
+ return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
2412
2411
  }
2413
- function bytes(b, ...lengths) {
2414
- if (!isBytes$1(b))
2412
+ function abytes$2(b, ...lengths) {
2413
+ if (!isBytes$2(b))
2415
2414
  throw new Error('Uint8Array expected');
2416
2415
  if (lengths.length > 0 && !lengths.includes(b.length))
2417
- throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
2416
+ throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
2418
2417
  }
2419
- function hash(h) {
2418
+ function ahash(h) {
2420
2419
  if (typeof h !== 'function' || typeof h.create !== 'function')
2421
2420
  throw new Error('Hash should be wrapped by utils.wrapConstructor');
2422
- number$1(h.outputLen);
2423
- number$1(h.blockLen);
2421
+ anumber$1(h.outputLen);
2422
+ anumber$1(h.blockLen);
2424
2423
  }
2425
- function exists(instance, checkFinished = true) {
2424
+ function aexists$1(instance, checkFinished = true) {
2426
2425
  if (instance.destroyed)
2427
2426
  throw new Error('Hash instance has been destroyed');
2428
2427
  if (checkFinished && instance.finished)
2429
2428
  throw new Error('Hash#digest() has already been called');
2430
2429
  }
2431
- function output(out, instance) {
2432
- bytes(out);
2430
+ function aoutput$1(out, instance) {
2431
+ abytes$2(out);
2433
2432
  const min = instance.outputLen;
2434
2433
  if (out.length < min) {
2435
- throw new Error(`digestInto() expects output buffer of length at least ${min}`);
2434
+ throw new Error('digestInto() expects output buffer of length at least ' + min);
2436
2435
  }
2437
2436
  }
2438
2437
 
@@ -2445,29 +2444,16 @@ var solanaWeb3 = (function (exports) {
2445
2444
  // from `crypto` to `cryptoNode`, which imports native module.
2446
2445
  // Makes the utils un-importable in browsers without a bundler.
2447
2446
  // Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
2448
- const u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
2449
2447
  // Cast array to view
2450
- const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
2448
+ const createView$1 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
2451
2449
  // The rotate right (circular right shift) operation for uint32
2452
- const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
2453
- const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
2454
- // The byte swap operation for uint32
2455
- const byteSwap = (word) => ((word << 24) & 0xff000000) |
2456
- ((word << 8) & 0xff0000) |
2457
- ((word >>> 8) & 0xff00) |
2458
- ((word >>> 24) & 0xff);
2459
- // In place byte swap for Uint32Array
2460
- function byteSwap32(arr) {
2461
- for (let i = 0; i < arr.length; i++) {
2462
- arr[i] = byteSwap(arr[i]);
2463
- }
2464
- }
2450
+ const rotr$1 = (word, shift) => (word << (32 - shift)) | (word >>> shift);
2465
2451
  /**
2466
2452
  * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
2467
2453
  */
2468
- function utf8ToBytes$1(str) {
2454
+ function utf8ToBytes$2(str) {
2469
2455
  if (typeof str !== 'string')
2470
- throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
2456
+ throw new Error('utf8ToBytes expected string, got ' + typeof str);
2471
2457
  return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
2472
2458
  }
2473
2459
  /**
@@ -2475,10 +2461,10 @@ var solanaWeb3 = (function (exports) {
2475
2461
  * Warning: when Uint8Array is passed, it would NOT get copied.
2476
2462
  * Keep in mind for future mutable operations.
2477
2463
  */
2478
- function toBytes(data) {
2464
+ function toBytes$1(data) {
2479
2465
  if (typeof data === 'string')
2480
- data = utf8ToBytes$1(data);
2481
- bytes(data);
2466
+ data = utf8ToBytes$2(data);
2467
+ abytes$2(data);
2482
2468
  return data;
2483
2469
  }
2484
2470
  /**
@@ -2488,7 +2474,7 @@ var solanaWeb3 = (function (exports) {
2488
2474
  let sum = 0;
2489
2475
  for (let i = 0; i < arrays.length; i++) {
2490
2476
  const a = arrays[i];
2491
- bytes(a);
2477
+ abytes$2(a);
2492
2478
  sum += a.length;
2493
2479
  }
2494
2480
  const res = new Uint8Array(sum);
@@ -2500,14 +2486,14 @@ var solanaWeb3 = (function (exports) {
2500
2486
  return res;
2501
2487
  }
2502
2488
  // For runtime check if class implements interface
2503
- class Hash {
2489
+ let Hash$1 = class Hash {
2504
2490
  // Safe version that clones internal state
2505
2491
  clone() {
2506
2492
  return this._cloneInto();
2507
2493
  }
2508
- }
2509
- function wrapConstructor(hashCons) {
2510
- const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
2494
+ };
2495
+ function wrapConstructor$1(hashCons) {
2496
+ const hashC = (msg) => hashCons().update(toBytes$1(msg)).digest();
2511
2497
  const tmp = hashCons();
2512
2498
  hashC.outputLen = tmp.outputLen;
2513
2499
  hashC.blockLen = tmp.blockLen;
@@ -2531,7 +2517,7 @@ var solanaWeb3 = (function (exports) {
2531
2517
  /**
2532
2518
  * Polyfill for Safari 14
2533
2519
  */
2534
- function setBigUint64(view, byteOffset, value, isLE) {
2520
+ function setBigUint64$1(view, byteOffset, value, isLE) {
2535
2521
  if (typeof view.setBigUint64 === 'function')
2536
2522
  return view.setBigUint64(byteOffset, value, isLE);
2537
2523
  const _32n = BigInt(32);
@@ -2546,16 +2532,16 @@ var solanaWeb3 = (function (exports) {
2546
2532
  /**
2547
2533
  * Choice: a ? b : c
2548
2534
  */
2549
- const Chi = (a, b, c) => (a & b) ^ (~a & c);
2535
+ const Chi$1 = (a, b, c) => (a & b) ^ (~a & c);
2550
2536
  /**
2551
2537
  * Majority function, true if any two inputs is true
2552
2538
  */
2553
- const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
2539
+ const Maj$1 = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
2554
2540
  /**
2555
2541
  * Merkle-Damgard hash construction base class.
2556
2542
  * Could be used to create MD5, RIPEMD, SHA1, SHA2.
2557
2543
  */
2558
- class HashMD extends Hash {
2544
+ let HashMD$1 = class HashMD extends Hash$1 {
2559
2545
  constructor(blockLen, outputLen, padOffset, isLE) {
2560
2546
  super();
2561
2547
  this.blockLen = blockLen;
@@ -2567,18 +2553,18 @@ var solanaWeb3 = (function (exports) {
2567
2553
  this.pos = 0;
2568
2554
  this.destroyed = false;
2569
2555
  this.buffer = new Uint8Array(blockLen);
2570
- this.view = createView(this.buffer);
2556
+ this.view = createView$1(this.buffer);
2571
2557
  }
2572
2558
  update(data) {
2573
- exists(this);
2559
+ aexists$1(this);
2574
2560
  const { view, buffer, blockLen } = this;
2575
- data = toBytes(data);
2561
+ data = toBytes$1(data);
2576
2562
  const len = data.length;
2577
2563
  for (let pos = 0; pos < len;) {
2578
2564
  const take = Math.min(blockLen - this.pos, len - pos);
2579
2565
  // Fast path: we have at least one block in input, cast it to view and process
2580
2566
  if (take === blockLen) {
2581
- const dataView = createView(data);
2567
+ const dataView = createView$1(data);
2582
2568
  for (; blockLen <= len - pos; pos += blockLen)
2583
2569
  this.process(dataView, pos);
2584
2570
  continue;
@@ -2596,8 +2582,8 @@ var solanaWeb3 = (function (exports) {
2596
2582
  return this;
2597
2583
  }
2598
2584
  digestInto(out) {
2599
- exists(this);
2600
- output(out, this);
2585
+ aexists$1(this);
2586
+ aoutput$1(out, this);
2601
2587
  this.finished = true;
2602
2588
  // Padding
2603
2589
  // We can avoid allocation of buffer for padding completely if it
@@ -2619,9 +2605,9 @@ var solanaWeb3 = (function (exports) {
2619
2605
  // Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
2620
2606
  // You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
2621
2607
  // So we just write lowest 64 bits of that value.
2622
- setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
2608
+ setBigUint64$1(view, blockLen - 8, BigInt(this.length * 8), isLE);
2623
2609
  this.process(view, 0);
2624
- const oview = createView(out);
2610
+ const oview = createView$1(out);
2625
2611
  const len = this.outputLen;
2626
2612
  // NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
2627
2613
  if (len % 4)
@@ -2652,26 +2638,27 @@ var solanaWeb3 = (function (exports) {
2652
2638
  to.buffer.set(buffer);
2653
2639
  return to;
2654
2640
  }
2655
- }
2641
+ };
2656
2642
 
2657
- const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
2658
- const _32n = /* @__PURE__ */ BigInt(32);
2659
- // We are not using BigUint64Array, because they are extremely slow as per 2022
2660
- function fromBig(n, le = false) {
2643
+ const U32_MASK64$1 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
2644
+ const _32n$1 = /* @__PURE__ */ BigInt(32);
2645
+ // BigUint64Array is too slow as per 2024, so we implement it using Uint32Array.
2646
+ // TODO: re-check https://issues.chromium.org/issues/42212588
2647
+ function fromBig$1(n, le = false) {
2661
2648
  if (le)
2662
- return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
2663
- return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
2649
+ return { h: Number(n & U32_MASK64$1), l: Number((n >> _32n$1) & U32_MASK64$1) };
2650
+ return { h: Number((n >> _32n$1) & U32_MASK64$1) | 0, l: Number(n & U32_MASK64$1) | 0 };
2664
2651
  }
2665
- function split(lst, le = false) {
2652
+ function split$1(lst, le = false) {
2666
2653
  let Ah = new Uint32Array(lst.length);
2667
2654
  let Al = new Uint32Array(lst.length);
2668
2655
  for (let i = 0; i < lst.length; i++) {
2669
- const { h, l } = fromBig(lst[i], le);
2656
+ const { h, l } = fromBig$1(lst[i], le);
2670
2657
  [Ah[i], Al[i]] = [h, l];
2671
2658
  }
2672
2659
  return [Ah, Al];
2673
2660
  }
2674
- const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
2661
+ const toBig = (h, l) => (BigInt(h >>> 0) << _32n$1) | BigInt(l >>> 0);
2675
2662
  // for Shift in [0, 32)
2676
2663
  const shrSH = (h, _l, s) => h >>> s;
2677
2664
  const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
@@ -2685,11 +2672,11 @@ var solanaWeb3 = (function (exports) {
2685
2672
  const rotr32H = (_h, l) => l;
2686
2673
  const rotr32L = (h, _l) => h;
2687
2674
  // Left rotate for Shift in [1, 32)
2688
- const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
2689
- const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
2675
+ const rotlSH$1 = (h, l, s) => (h << s) | (l >>> (32 - s));
2676
+ const rotlSL$1 = (h, l, s) => (l << s) | (h >>> (32 - s));
2690
2677
  // Left rotate for Shift in (32, 64), NOTE: 32 is special case.
2691
- const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
2692
- const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
2678
+ const rotlBH$1 = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
2679
+ const rotlBL$1 = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
2693
2680
  // JS uses 32-bit signed integers for bitwise operations which means we cannot
2694
2681
  // simple take carry out of low bit sum by shift, we need to use division.
2695
2682
  function add(Ah, Al, Bh, Bl) {
@@ -2705,11 +2692,11 @@ var solanaWeb3 = (function (exports) {
2705
2692
  const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
2706
2693
  // prettier-ignore
2707
2694
  const u64$1 = {
2708
- fromBig, split, toBig,
2695
+ fromBig: fromBig$1, split: split$1, toBig,
2709
2696
  shrSH, shrSL,
2710
2697
  rotrSH, rotrSL, rotrBH, rotrBL,
2711
2698
  rotr32H, rotr32L,
2712
- rotlSH, rotlSL, rotlBH, rotlBL,
2699
+ rotlSH: rotlSH$1, rotlSL: rotlSL$1, rotlBH: rotlBH$1, rotlBL: rotlBL$1,
2713
2700
  add, add3L, add3H, add4L, add4H, add5H, add5L,
2714
2701
  };
2715
2702
 
@@ -2740,7 +2727,7 @@ var solanaWeb3 = (function (exports) {
2740
2727
  // Temporary buffer, not used to store anything between runs
2741
2728
  const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
2742
2729
  const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
2743
- class SHA512 extends HashMD {
2730
+ class SHA512 extends HashMD$1 {
2744
2731
  constructor() {
2745
2732
  super(128, 64, 16, false);
2746
2733
  // We cannot use array here since array allows indexing by variable which means optimizer/compiler cannot use registers.
@@ -2867,7 +2854,7 @@ var solanaWeb3 = (function (exports) {
2867
2854
  this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
2868
2855
  }
2869
2856
  }
2870
- const sha512 = /* @__PURE__ */ wrapConstructor(() => new SHA512());
2857
+ const sha512 = /* @__PURE__ */ wrapConstructor$1(() => new SHA512());
2871
2858
 
2872
2859
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2873
2860
  // 100 lines of code in the file are duplicated from noble-hashes (utils).
@@ -2877,17 +2864,16 @@ var solanaWeb3 = (function (exports) {
2877
2864
  const _0n$5 = /* @__PURE__ */ BigInt(0);
2878
2865
  const _1n$7 = /* @__PURE__ */ BigInt(1);
2879
2866
  const _2n$5 = /* @__PURE__ */ BigInt(2);
2880
- function isBytes(a) {
2881
- return (a instanceof Uint8Array ||
2882
- (a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
2867
+ function isBytes$1(a) {
2868
+ return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
2883
2869
  }
2884
- function abytes(item) {
2885
- if (!isBytes(item))
2870
+ function abytes$1(item) {
2871
+ if (!isBytes$1(item))
2886
2872
  throw new Error('Uint8Array expected');
2887
2873
  }
2888
2874
  function abool(title, value) {
2889
2875
  if (typeof value !== 'boolean')
2890
- throw new Error(`${title} must be valid boolean, got "${value}".`);
2876
+ throw new Error(title + ' boolean expected, got ' + value);
2891
2877
  }
2892
2878
  // Array where index 0xf0 (240) is mapped to string 'f0'
2893
2879
  const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
@@ -2895,7 +2881,7 @@ var solanaWeb3 = (function (exports) {
2895
2881
  * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
2896
2882
  */
2897
2883
  function bytesToHex(bytes) {
2898
- abytes(bytes);
2884
+ abytes$1(bytes);
2899
2885
  // pre-caching improves the speed 6x
2900
2886
  let hex = '';
2901
2887
  for (let i = 0; i < bytes.length; i++) {
@@ -2905,23 +2891,22 @@ var solanaWeb3 = (function (exports) {
2905
2891
  }
2906
2892
  function numberToHexUnpadded(num) {
2907
2893
  const hex = num.toString(16);
2908
- return hex.length & 1 ? `0${hex}` : hex;
2894
+ return hex.length & 1 ? '0' + hex : hex;
2909
2895
  }
2910
2896
  function hexToNumber(hex) {
2911
2897
  if (typeof hex !== 'string')
2912
2898
  throw new Error('hex string expected, got ' + typeof hex);
2913
- // Big Endian
2914
- return BigInt(hex === '' ? '0' : `0x${hex}`);
2899
+ return hex === '' ? _0n$5 : BigInt('0x' + hex); // Big Endian
2915
2900
  }
2916
2901
  // We use optimized technique to convert hex string to byte array
2917
- const asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 };
2918
- function asciiToBase16(char) {
2919
- if (char >= asciis._0 && char <= asciis._9)
2920
- return char - asciis._0;
2921
- if (char >= asciis._A && char <= asciis._F)
2922
- return char - (asciis._A - 10);
2923
- if (char >= asciis._a && char <= asciis._f)
2924
- return char - (asciis._a - 10);
2902
+ const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
2903
+ function asciiToBase16(ch) {
2904
+ if (ch >= asciis._0 && ch <= asciis._9)
2905
+ return ch - asciis._0; // '2' => 50-48
2906
+ if (ch >= asciis.A && ch <= asciis.F)
2907
+ return ch - (asciis.A - 10); // 'B' => 66-(65-10)
2908
+ if (ch >= asciis.a && ch <= asciis.f)
2909
+ return ch - (asciis.a - 10); // 'b' => 98-(97-10)
2925
2910
  return;
2926
2911
  }
2927
2912
  /**
@@ -2933,7 +2918,7 @@ var solanaWeb3 = (function (exports) {
2933
2918
  const hl = hex.length;
2934
2919
  const al = hl / 2;
2935
2920
  if (hl % 2)
2936
- throw new Error('padded hex string expected, got unpadded hex of length ' + hl);
2921
+ throw new Error('hex string expected, got unpadded hex of length ' + hl);
2937
2922
  const array = new Uint8Array(al);
2938
2923
  for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
2939
2924
  const n1 = asciiToBase16(hex.charCodeAt(hi));
@@ -2942,7 +2927,7 @@ var solanaWeb3 = (function (exports) {
2942
2927
  const char = hex[hi] + hex[hi + 1];
2943
2928
  throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
2944
2929
  }
2945
- array[ai] = n1 * 16 + n2;
2930
+ array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163
2946
2931
  }
2947
2932
  return array;
2948
2933
  }
@@ -2951,7 +2936,7 @@ var solanaWeb3 = (function (exports) {
2951
2936
  return hexToNumber(bytesToHex(bytes));
2952
2937
  }
2953
2938
  function bytesToNumberLE(bytes) {
2954
- abytes(bytes);
2939
+ abytes$1(bytes);
2955
2940
  return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
2956
2941
  }
2957
2942
  function numberToBytesBE(n, len) {
@@ -2980,20 +2965,20 @@ var solanaWeb3 = (function (exports) {
2980
2965
  res = hexToBytes(hex);
2981
2966
  }
2982
2967
  catch (e) {
2983
- throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
2968
+ throw new Error(title + ' must be hex string or Uint8Array, cause: ' + e);
2984
2969
  }
2985
2970
  }
2986
- else if (isBytes(hex)) {
2971
+ else if (isBytes$1(hex)) {
2987
2972
  // Uint8Array.from() instead of hash.slice() because node.js Buffer
2988
2973
  // is instance of Uint8Array, and its slice() creates **mutable** copy
2989
2974
  res = Uint8Array.from(hex);
2990
2975
  }
2991
2976
  else {
2992
- throw new Error(`${title} must be hex string or Uint8Array`);
2977
+ throw new Error(title + ' must be hex string or Uint8Array');
2993
2978
  }
2994
2979
  const len = res.length;
2995
2980
  if (typeof expectedLength === 'number' && len !== expectedLength)
2996
- throw new Error(`${title} expected ${expectedLength} bytes, got ${len}`);
2981
+ throw new Error(title + ' of length ' + expectedLength + ' expected, got ' + len);
2997
2982
  return res;
2998
2983
  }
2999
2984
  /**
@@ -3003,7 +2988,7 @@ var solanaWeb3 = (function (exports) {
3003
2988
  let sum = 0;
3004
2989
  for (let i = 0; i < arrays.length; i++) {
3005
2990
  const a = arrays[i];
3006
- abytes(a);
2991
+ abytes$1(a);
3007
2992
  sum += a.length;
3008
2993
  }
3009
2994
  const res = new Uint8Array(sum);
@@ -3026,9 +3011,9 @@ var solanaWeb3 = (function (exports) {
3026
3011
  /**
3027
3012
  * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
3028
3013
  */
3029
- function utf8ToBytes(str) {
3014
+ function utf8ToBytes$1(str) {
3030
3015
  if (typeof str !== 'string')
3031
- throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
3016
+ throw new Error('string expected');
3032
3017
  return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
3033
3018
  }
3034
3019
  // Is positive bigint
@@ -3048,7 +3033,7 @@ var solanaWeb3 = (function (exports) {
3048
3033
  // - b would commonly require subtraction: `inRange('x', x, 0n, P - 1n)`
3049
3034
  // - our way is the cleanest: `inRange('x', x, 0n, P)
3050
3035
  if (!inRange(n, min, max))
3051
- throw new Error(`expected valid ${title}: ${min} <= n < ${max}, got ${typeof n} ${n}`);
3036
+ throw new Error('expected valid ' + title + ': ' + min + ' <= n < ' + max + ', got ' + n);
3052
3037
  }
3053
3038
  // Bit operations
3054
3039
  /**
@@ -3147,7 +3132,7 @@ var solanaWeb3 = (function (exports) {
3147
3132
  function: (val) => typeof val === 'function',
3148
3133
  boolean: (val) => typeof val === 'boolean',
3149
3134
  string: (val) => typeof val === 'string',
3150
- stringOrUint8Array: (val) => typeof val === 'string' || isBytes(val),
3135
+ stringOrUint8Array: (val) => typeof val === 'string' || isBytes$1(val),
3151
3136
  isSafeInteger: (val) => Number.isSafeInteger(val),
3152
3137
  array: (val) => Array.isArray(val),
3153
3138
  field: (val, object) => object.Fp.isValid(val),
@@ -3158,12 +3143,12 @@ var solanaWeb3 = (function (exports) {
3158
3143
  const checkField = (fieldName, type, isOptional) => {
3159
3144
  const checkVal = validatorFns[type];
3160
3145
  if (typeof checkVal !== 'function')
3161
- throw new Error(`Invalid validator "${type}", expected function`);
3146
+ throw new Error('invalid validator function');
3162
3147
  const val = object[fieldName];
3163
3148
  if (isOptional && val === undefined)
3164
3149
  return;
3165
3150
  if (!checkVal(val, object)) {
3166
- throw new Error(`Invalid param ${String(fieldName)}=${val} (${typeof val}), expected ${type}`);
3151
+ throw new Error('param ' + String(fieldName) + ' is invalid. Expected ' + type + ', got ' + val);
3167
3152
  }
3168
3153
  };
3169
3154
  for (const [fieldName, type] of Object.entries(validators))
@@ -3206,7 +3191,7 @@ var solanaWeb3 = (function (exports) {
3206
3191
  __proto__: null,
3207
3192
  aInRange: aInRange,
3208
3193
  abool: abool,
3209
- abytes: abytes,
3194
+ abytes: abytes$1,
3210
3195
  bitGet: bitGet,
3211
3196
  bitLen: bitLen,
3212
3197
  bitMask: bitMask,
@@ -3221,25 +3206,23 @@ var solanaWeb3 = (function (exports) {
3221
3206
  hexToBytes: hexToBytes,
3222
3207
  hexToNumber: hexToNumber,
3223
3208
  inRange: inRange,
3224
- isBytes: isBytes,
3209
+ isBytes: isBytes$1,
3225
3210
  memoized: memoized,
3226
3211
  notImplemented: notImplemented,
3227
3212
  numberToBytesBE: numberToBytesBE,
3228
3213
  numberToBytesLE: numberToBytesLE,
3229
3214
  numberToHexUnpadded: numberToHexUnpadded,
3230
3215
  numberToVarBytesBE: numberToVarBytesBE,
3231
- utf8ToBytes: utf8ToBytes,
3216
+ utf8ToBytes: utf8ToBytes$1,
3232
3217
  validateObject: validateObject
3233
3218
  });
3234
3219
 
3235
3220
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3236
3221
  // Utilities for modular arithmetics and finite fields
3237
3222
  // prettier-ignore
3238
- const _0n$4 = BigInt(0), _1n$6 = BigInt(1), _2n$4 = BigInt(2), _3n$1 = BigInt(3);
3239
- // prettier-ignore
3240
- const _4n = BigInt(4), _5n$1 = BigInt(5), _8n$2 = BigInt(8);
3223
+ const _0n$4 = BigInt(0), _1n$6 = BigInt(1), _2n$4 = /* @__PURE__ */ BigInt(2), _3n$1 = /* @__PURE__ */ BigInt(3);
3241
3224
  // prettier-ignore
3242
- BigInt(9); BigInt(16);
3225
+ const _4n = /* @__PURE__ */ BigInt(4), _5n$1 = /* @__PURE__ */ BigInt(5), _8n$2 = /* @__PURE__ */ BigInt(8);
3243
3226
  // Calculates a modulo b
3244
3227
  function mod(a, b) {
3245
3228
  const result = a % b;
@@ -3253,8 +3236,10 @@ var solanaWeb3 = (function (exports) {
3253
3236
  */
3254
3237
  // TODO: use field version && remove
3255
3238
  function pow(num, power, modulo) {
3256
- if (modulo <= _0n$4 || power < _0n$4)
3257
- throw new Error('Expected power/modulo > 0');
3239
+ if (power < _0n$4)
3240
+ throw new Error('invalid exponent, negatives unsupported');
3241
+ if (modulo <= _0n$4)
3242
+ throw new Error('invalid modulus');
3258
3243
  if (modulo === _1n$6)
3259
3244
  return _0n$4;
3260
3245
  let res = _1n$6;
@@ -3277,9 +3262,10 @@ var solanaWeb3 = (function (exports) {
3277
3262
  }
3278
3263
  // Inverses number over modulo
3279
3264
  function invert(number, modulo) {
3280
- if (number === _0n$4 || modulo <= _0n$4) {
3281
- throw new Error(`invert: expected positive integers, got n=${number} mod=${modulo}`);
3282
- }
3265
+ if (number === _0n$4)
3266
+ throw new Error('invert: expected non-zero number');
3267
+ if (modulo <= _0n$4)
3268
+ throw new Error('invert: expected positive modulus, got ' + modulo);
3283
3269
  // Euclidean GCD https://brilliant.org/wiki/extended-euclidean-algorithm/
3284
3270
  // Fermat's little theorem "CT-like" version inv(n) = n^(m-2) mod m is 30x slower.
3285
3271
  let a = mod(number, modulo);
@@ -3320,8 +3306,11 @@ var solanaWeb3 = (function (exports) {
3320
3306
  for (Q = P - _1n$6, S = 0; Q % _2n$4 === _0n$4; Q /= _2n$4, S++)
3321
3307
  ;
3322
3308
  // Step 2: Select a non-square z such that (z | p) ≡ -1 and set c ≡ zq
3323
- for (Z = _2n$4; Z < P && pow(Z, legendreC, P) !== P - _1n$6; Z++)
3324
- ;
3309
+ for (Z = _2n$4; Z < P && pow(Z, legendreC, P) !== P - _1n$6; Z++) {
3310
+ // Crash instead of infinity loop, we cannot reasonable count until P.
3311
+ if (Z > 1000)
3312
+ throw new Error('Cannot find square root: likely non-prime P');
3313
+ }
3325
3314
  // Fast-path
3326
3315
  if (S === 1) {
3327
3316
  const p1div4 = (P + _1n$6) / _4n;
@@ -3429,7 +3418,7 @@ var solanaWeb3 = (function (exports) {
3429
3418
  // Should have same speed as pow for bigints
3430
3419
  // TODO: benchmark!
3431
3420
  if (power < _0n$4)
3432
- throw new Error('Expected power > 0');
3421
+ throw new Error('invalid exponent, negatives unsupported');
3433
3422
  if (power === _0n$4)
3434
3423
  return f.ONE;
3435
3424
  if (power === _1n$6)
@@ -3492,11 +3481,11 @@ var solanaWeb3 = (function (exports) {
3492
3481
  */
3493
3482
  function Field(ORDER, bitLen, isLE = false, redef = {}) {
3494
3483
  if (ORDER <= _0n$4)
3495
- throw new Error(`Expected Field ORDER > 0, got ${ORDER}`);
3484
+ throw new Error('invalid field: expected ORDER > 0, got ' + ORDER);
3496
3485
  const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen);
3497
3486
  if (BYTES > 2048)
3498
- throw new Error('Field lengths over 2048 bytes are not supported');
3499
- const sqrtP = FpSqrt(ORDER);
3487
+ throw new Error('invalid field: expected ORDER of <= 2048 bytes');
3488
+ let sqrtP; // cached sqrtP
3500
3489
  const f = Object.freeze({
3501
3490
  ORDER,
3502
3491
  BITS,
@@ -3507,7 +3496,7 @@ var solanaWeb3 = (function (exports) {
3507
3496
  create: (num) => mod(num, ORDER),
3508
3497
  isValid: (num) => {
3509
3498
  if (typeof num !== 'bigint')
3510
- throw new Error(`Invalid field element: expected bigint, got ${typeof num}`);
3499
+ throw new Error('invalid field element: expected bigint, got ' + typeof num);
3511
3500
  return _0n$4 <= num && num < ORDER; // 0 is valid element, but it's not invertible
3512
3501
  },
3513
3502
  is0: (num) => num === _0n$4,
@@ -3526,7 +3515,12 @@ var solanaWeb3 = (function (exports) {
3526
3515
  subN: (lhs, rhs) => lhs - rhs,
3527
3516
  mulN: (lhs, rhs) => lhs * rhs,
3528
3517
  inv: (num) => invert(num, ORDER),
3529
- sqrt: redef.sqrt || ((n) => sqrtP(f, n)),
3518
+ sqrt: redef.sqrt ||
3519
+ ((n) => {
3520
+ if (!sqrtP)
3521
+ sqrtP = FpSqrt(ORDER);
3522
+ return sqrtP(f, n);
3523
+ }),
3530
3524
  invertBatch: (lst) => FpInvertBatch(f, lst),
3531
3525
  // TODO: do we really need constant cmov?
3532
3526
  // We don't have const-time bigints anyway, so probably will be not very useful
@@ -3534,7 +3528,7 @@ var solanaWeb3 = (function (exports) {
3534
3528
  toBytes: (num) => (isLE ? numberToBytesLE(num, BYTES) : numberToBytesBE(num, BYTES)),
3535
3529
  fromBytes: (bytes) => {
3536
3530
  if (bytes.length !== BYTES)
3537
- throw new Error(`Fp.fromBytes: expected ${BYTES}, got ${bytes.length}`);
3531
+ throw new Error('Field.fromBytes: expected ' + BYTES + ' bytes, got ' + bytes.length);
3538
3532
  return isLE ? bytesToNumberLE(bytes) : bytesToNumberBE(bytes);
3539
3533
  },
3540
3534
  });
@@ -3582,7 +3576,7 @@ var solanaWeb3 = (function (exports) {
3582
3576
  const minLen = getMinHashLength(fieldOrder);
3583
3577
  // No small numbers: need to understand bias story. No huge numbers: easier to detect JS timings.
3584
3578
  if (len < 16 || len < minLen || len > 1024)
3585
- throw new Error(`expected ${minLen}-1024 bytes of input, got ${len}`);
3579
+ throw new Error('expected ' + minLen + '-1024 bytes of input, got ' + len);
3586
3580
  const num = isLE ? bytesToNumberBE(key) : bytesToNumberLE(key);
3587
3581
  // `mod(x, 11)` can sometimes produce 0. `mod(x, 10) + 1` is the same, but no 0
3588
3582
  const reduced = mod(num, fieldOrder - _1n$6) + _1n$6;
@@ -3593,10 +3587,43 @@ var solanaWeb3 = (function (exports) {
3593
3587
  // Abelian group utilities
3594
3588
  const _0n$3 = BigInt(0);
3595
3589
  const _1n$5 = BigInt(1);
3590
+ function constTimeNegate(condition, item) {
3591
+ const neg = item.negate();
3592
+ return condition ? neg : item;
3593
+ }
3594
+ function validateW(W, bits) {
3595
+ if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
3596
+ throw new Error('invalid window size, expected [1..' + bits + '], got W=' + W);
3597
+ }
3598
+ function calcWOpts(W, bits) {
3599
+ validateW(W, bits);
3600
+ const windows = Math.ceil(bits / W) + 1; // +1, because
3601
+ const windowSize = 2 ** (W - 1); // -1 because we skip zero
3602
+ return { windows, windowSize };
3603
+ }
3604
+ function validateMSMPoints(points, c) {
3605
+ if (!Array.isArray(points))
3606
+ throw new Error('array expected');
3607
+ points.forEach((p, i) => {
3608
+ if (!(p instanceof c))
3609
+ throw new Error('invalid point at index ' + i);
3610
+ });
3611
+ }
3612
+ function validateMSMScalars(scalars, field) {
3613
+ if (!Array.isArray(scalars))
3614
+ throw new Error('array of scalars expected');
3615
+ scalars.forEach((s, i) => {
3616
+ if (!field.isValid(s))
3617
+ throw new Error('invalid scalar at index ' + i);
3618
+ });
3619
+ }
3596
3620
  // Since points in different groups cannot be equal (different object constructor),
3597
3621
  // we can have single place to store precomputes
3598
3622
  const pointPrecomputes = new WeakMap();
3599
3623
  const pointWindowSizes = new WeakMap(); // This allows use make points immutable (nothing changes inside)
3624
+ function getW(P) {
3625
+ return pointWindowSizes.get(P) || 1;
3626
+ }
3600
3627
  // Elliptic curve multiplication of Point by scalar. Fragile.
3601
3628
  // Scalars should always be less than curve order: this should be checked inside of a curve itself.
3602
3629
  // Creates precomputation tables for fast multiplication:
@@ -3609,25 +3636,13 @@ var solanaWeb3 = (function (exports) {
3609
3636
  // TODO: Research returning 2d JS array of windows, instead of a single window. This would allow
3610
3637
  // windows to be in different memory locations
3611
3638
  function wNAF(c, bits) {
3612
- const constTimeNegate = (condition, item) => {
3613
- const neg = item.negate();
3614
- return condition ? neg : item;
3615
- };
3616
- const validateW = (W) => {
3617
- if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
3618
- throw new Error(`Wrong window size=${W}, should be [1..${bits}]`);
3619
- };
3620
- const opts = (W) => {
3621
- validateW(W);
3622
- const windows = Math.ceil(bits / W) + 1; // +1, because
3623
- const windowSize = 2 ** (W - 1); // -1 because we skip zero
3624
- return { windows, windowSize };
3625
- };
3626
3639
  return {
3627
3640
  constTimeNegate,
3641
+ hasPrecomputes(elm) {
3642
+ return getW(elm) !== 1;
3643
+ },
3628
3644
  // non-const time multiplication ladder
3629
- unsafeLadder(elm, n) {
3630
- let p = c.ZERO;
3645
+ unsafeLadder(elm, n, p = c.ZERO) {
3631
3646
  let d = elm;
3632
3647
  while (n > _0n$3) {
3633
3648
  if (n & _1n$5)
@@ -3645,10 +3660,12 @@ var solanaWeb3 = (function (exports) {
3645
3660
  * - 𝑊 is the window size
3646
3661
  * - 𝑛 is the bitlength of the curve order.
3647
3662
  * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
3663
+ * @param elm Point instance
3664
+ * @param W window size
3648
3665
  * @returns precomputed point tables flattened to a single array
3649
3666
  */
3650
3667
  precomputeWindow(elm, W) {
3651
- const { windows, windowSize } = opts(W);
3668
+ const { windows, windowSize } = calcWOpts(W, bits);
3652
3669
  const points = [];
3653
3670
  let p = elm;
3654
3671
  let base = p;
@@ -3674,7 +3691,7 @@ var solanaWeb3 = (function (exports) {
3674
3691
  wNAF(W, precomputes, n) {
3675
3692
  // TODO: maybe check that scalar is less than group order? wNAF behavious is undefined otherwise
3676
3693
  // But need to carefully remove other checks before wNAF. ORDER == bits here
3677
- const { windows, windowSize } = opts(W);
3694
+ const { windows, windowSize } = calcWOpts(W, bits);
3678
3695
  let p = c.ZERO;
3679
3696
  let f = c.BASE;
3680
3697
  const mask = BigInt(2 ** W - 1); // Create mask with W ones: 0b1111 for W=4 etc.
@@ -3718,8 +3735,44 @@ var solanaWeb3 = (function (exports) {
3718
3735
  // which makes it less const-time: around 1 bigint multiply.
3719
3736
  return { p, f };
3720
3737
  },
3721
- wNAFCached(P, n, transform) {
3722
- const W = pointWindowSizes.get(P) || 1;
3738
+ /**
3739
+ * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
3740
+ * @param W window size
3741
+ * @param precomputes precomputed tables
3742
+ * @param n scalar (we don't check here, but should be less than curve order)
3743
+ * @param acc accumulator point to add result of multiplication
3744
+ * @returns point
3745
+ */
3746
+ wNAFUnsafe(W, precomputes, n, acc = c.ZERO) {
3747
+ const { windows, windowSize } = calcWOpts(W, bits);
3748
+ const mask = BigInt(2 ** W - 1); // Create mask with W ones: 0b1111 for W=4 etc.
3749
+ const maxNumber = 2 ** W;
3750
+ const shiftBy = BigInt(W);
3751
+ for (let window = 0; window < windows; window++) {
3752
+ const offset = window * windowSize;
3753
+ if (n === _0n$3)
3754
+ break; // No need to go over empty scalar
3755
+ // Extract W bits.
3756
+ let wbits = Number(n & mask);
3757
+ // Shift number by W bits.
3758
+ n >>= shiftBy;
3759
+ // If the bits are bigger than max size, we'll split those.
3760
+ // +224 => 256 - 32
3761
+ if (wbits > windowSize) {
3762
+ wbits -= maxNumber;
3763
+ n += _1n$5;
3764
+ }
3765
+ if (wbits === 0)
3766
+ continue;
3767
+ let curr = precomputes[offset + Math.abs(wbits) - 1]; // -1 because we skip zero
3768
+ if (wbits < 0)
3769
+ curr = curr.negate();
3770
+ // NOTE: by re-using acc, we can save a lot of additions in case of MSM
3771
+ acc = acc.add(curr);
3772
+ }
3773
+ return acc;
3774
+ },
3775
+ getPrecomputes(W, P, transform) {
3723
3776
  // Calculate precomputes on a first run, reuse them after
3724
3777
  let comp = pointPrecomputes.get(P);
3725
3778
  if (!comp) {
@@ -3727,62 +3780,66 @@ var solanaWeb3 = (function (exports) {
3727
3780
  if (W !== 1)
3728
3781
  pointPrecomputes.set(P, transform(comp));
3729
3782
  }
3730
- return this.wNAF(W, comp, n);
3783
+ return comp;
3784
+ },
3785
+ wNAFCached(P, n, transform) {
3786
+ const W = getW(P);
3787
+ return this.wNAF(W, this.getPrecomputes(W, P, transform), n);
3788
+ },
3789
+ wNAFCachedUnsafe(P, n, transform, prev) {
3790
+ const W = getW(P);
3791
+ if (W === 1)
3792
+ return this.unsafeLadder(P, n, prev); // For W=1 ladder is ~x2 faster
3793
+ return this.wNAFUnsafe(W, this.getPrecomputes(W, P, transform), n, prev);
3731
3794
  },
3732
3795
  // We calculate precomputes for elliptic curve point multiplication
3733
3796
  // using windowed method. This specifies window size and
3734
3797
  // stores precomputed values. Usually only base point would be precomputed.
3735
3798
  setWindowSize(P, W) {
3736
- validateW(W);
3799
+ validateW(W, bits);
3737
3800
  pointWindowSizes.set(P, W);
3738
3801
  pointPrecomputes.delete(P);
3739
3802
  },
3740
3803
  };
3741
3804
  }
3742
3805
  /**
3743
- * Pippenger algorithm for multi-scalar multiplication (MSM).
3744
- * MSM is basically (Pa + Qb + Rc + ...).
3806
+ * Pippenger algorithm for multi-scalar multiplication (MSM, Pa + Qb + Rc + ...).
3745
3807
  * 30x faster vs naive addition on L=4096, 10x faster with precomputes.
3746
3808
  * For N=254bit, L=1, it does: 1024 ADD + 254 DBL. For L=5: 1536 ADD + 254 DBL.
3747
3809
  * Algorithmically constant-time (for same L), even when 1 point + scalar, or when scalar = 0.
3748
3810
  * @param c Curve Point constructor
3749
- * @param field field over CURVE.N - important that it's not over CURVE.P
3811
+ * @param fieldN field over CURVE.N - important that it's not over CURVE.P
3750
3812
  * @param points array of L curve points
3751
3813
  * @param scalars array of L scalars (aka private keys / bigints)
3752
3814
  */
3753
- function pippenger(c, field, points, scalars) {
3815
+ function pippenger(c, fieldN, points, scalars) {
3754
3816
  // If we split scalars by some window (let's say 8 bits), every chunk will only
3755
3817
  // take 256 buckets even if there are 4096 scalars, also re-uses double.
3756
3818
  // TODO:
3757
3819
  // - https://eprint.iacr.org/2024/750.pdf
3758
3820
  // - https://tches.iacr.org/index.php/TCHES/article/view/10287
3759
3821
  // 0 is accepted in scalars
3760
- if (!Array.isArray(points) || !Array.isArray(scalars) || scalars.length !== points.length)
3822
+ validateMSMPoints(points, c);
3823
+ validateMSMScalars(scalars, fieldN);
3824
+ if (points.length !== scalars.length)
3761
3825
  throw new Error('arrays of points and scalars must have equal length');
3762
- scalars.forEach((s, i) => {
3763
- if (!field.isValid(s))
3764
- throw new Error(`wrong scalar at index ${i}`);
3765
- });
3766
- points.forEach((p, i) => {
3767
- if (!(p instanceof c))
3768
- throw new Error(`wrong point at index ${i}`);
3769
- });
3826
+ const zero = c.ZERO;
3770
3827
  const wbits = bitLen(BigInt(points.length));
3771
3828
  const windowSize = wbits > 12 ? wbits - 3 : wbits > 4 ? wbits - 2 : wbits ? 2 : 1; // in bits
3772
3829
  const MASK = (1 << windowSize) - 1;
3773
- const buckets = new Array(MASK + 1).fill(c.ZERO); // +1 for zero array
3774
- const lastBits = Math.floor((field.BITS - 1) / windowSize) * windowSize;
3775
- let sum = c.ZERO;
3830
+ const buckets = new Array(MASK + 1).fill(zero); // +1 for zero array
3831
+ const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
3832
+ let sum = zero;
3776
3833
  for (let i = lastBits; i >= 0; i -= windowSize) {
3777
- buckets.fill(c.ZERO);
3834
+ buckets.fill(zero);
3778
3835
  for (let j = 0; j < scalars.length; j++) {
3779
3836
  const scalar = scalars[j];
3780
3837
  const wbits = Number((scalar >> BigInt(i)) & BigInt(MASK));
3781
3838
  buckets[wbits] = buckets[wbits].add(points[j]);
3782
3839
  }
3783
- let resI = c.ZERO; // not using this will do small speed-up, but will lose ct
3840
+ let resI = zero; // not using this will do small speed-up, but will lose ct
3784
3841
  // Skip first bucket, because it is zero
3785
- for (let j = buckets.length - 1, sumI = c.ZERO; j > 0; j--) {
3842
+ for (let j = buckets.length - 1, sumI = zero; j > 0; j--) {
3786
3843
  sumI = sumI.add(buckets[j]);
3787
3844
  resI = resI.add(sumI);
3788
3845
  }
@@ -3845,6 +3902,10 @@ var solanaWeb3 = (function (exports) {
3845
3902
  function twistedEdwards(curveDef) {
3846
3903
  const CURVE = validateOpts$1(curveDef);
3847
3904
  const { Fp, n: CURVE_ORDER, prehash: prehash, hash: cHash, randomBytes, nByteLength, h: cofactor, } = CURVE;
3905
+ // Important:
3906
+ // There are some places where Fp.BYTES is used instead of nByteLength.
3907
+ // So far, everything has been tested with curves of Fp.BYTES == nByteLength.
3908
+ // TODO: test and find curves which behave otherwise.
3848
3909
  const MASK = _2n$3 << (BigInt(nByteLength * 8) - _1n$4);
3849
3910
  const modP = Fp.create; // Function overrides
3850
3911
  const Fn = Field(CURVE.n, CURVE.nBitLength);
@@ -4058,16 +4119,15 @@ var solanaWeb3 = (function (exports) {
4058
4119
  // It's faster, but should only be used when you don't care about
4059
4120
  // an exposed private key e.g. sig verification.
4060
4121
  // Does NOT allow scalars higher than CURVE.n.
4061
- multiplyUnsafe(scalar) {
4122
+ // Accepts optional accumulator to merge with multiply (important for sparse scalars)
4123
+ multiplyUnsafe(scalar, acc = Point.ZERO) {
4062
4124
  const n = scalar;
4063
4125
  aInRange('scalar', n, _0n$2, CURVE_ORDER); // 0 <= scalar < L
4064
4126
  if (n === _0n$2)
4065
4127
  return I;
4066
- if (this.equals(I) || n === _1n$4)
4128
+ if (this.is0() || n === _1n$4)
4067
4129
  return this;
4068
- if (this.equals(G))
4069
- return this.wNAF(n).p;
4070
- return wnaf.unsafeLadder(this, n);
4130
+ return wnaf.wNAFCachedUnsafe(this, n, Point.normalizeZ, acc);
4071
4131
  }
4072
4132
  // Checks if point is of small order.
4073
4133
  // If you add something to small order point, you will have "dirty"
@@ -4103,6 +4163,7 @@ var solanaWeb3 = (function (exports) {
4103
4163
  const lastByte = hex[len - 1]; // select last byte
4104
4164
  normed[len - 1] = lastByte & ~0x80; // clear last bit
4105
4165
  const y = bytesToNumberLE(normed);
4166
+ // zip215=true is good for consensus-critical apps. =false follows RFC8032 / NIST186-5.
4106
4167
  // RFC8032 prohibits >= p, but ZIP215 doesn't
4107
4168
  // zip215=true: 0 <= y < MASK (2^256 for ed25519)
4108
4169
  // zip215=false: 0 <= y < P (2^255-19 for ed25519)
@@ -4151,7 +4212,7 @@ var solanaWeb3 = (function (exports) {
4151
4212
  }
4152
4213
  /** Convenience method that creates public key and other stuff. RFC8032 5.1.5 */
4153
4214
  function getExtendedPublicKey(key) {
4154
- const len = nByteLength;
4215
+ const len = Fp.BYTES;
4155
4216
  key = ensureBytes('private key', key, len);
4156
4217
  // Hash private key with curve's hash function to produce uniformingly random input
4157
4218
  // Check byte lengths: ensure(64, h(ensure(32, key)))
@@ -4184,23 +4245,29 @@ var solanaWeb3 = (function (exports) {
4184
4245
  const s = modN(r + k * scalar); // S = (r + k * s) mod L
4185
4246
  aInRange('signature.s', s, _0n$2, CURVE_ORDER); // 0 <= s < l
4186
4247
  const res = concatBytes(R, numberToBytesLE(s, Fp.BYTES));
4187
- return ensureBytes('result', res, nByteLength * 2); // 64-byte signature
4248
+ return ensureBytes('result', res, Fp.BYTES * 2); // 64-byte signature
4188
4249
  }
4189
4250
  const verifyOpts = VERIFY_DEFAULT;
4251
+ /**
4252
+ * Verifies EdDSA signature against message and public key. RFC8032 5.1.7.
4253
+ * An extended group equation is checked.
4254
+ */
4190
4255
  function verify(sig, msg, publicKey, options = verifyOpts) {
4191
4256
  const { context, zip215 } = options;
4192
4257
  const len = Fp.BYTES; // Verifies EdDSA signature against message and public key. RFC8032 5.1.7.
4193
4258
  sig = ensureBytes('signature', sig, 2 * len); // An extended group equation is checked.
4194
4259
  msg = ensureBytes('message', msg);
4260
+ publicKey = ensureBytes('publicKey', publicKey, len);
4195
4261
  if (zip215 !== undefined)
4196
4262
  abool('zip215', zip215);
4197
4263
  if (prehash)
4198
4264
  msg = prehash(msg); // for ed25519ph, etc
4199
4265
  const s = bytesToNumberLE(sig.slice(len, 2 * len));
4200
- // zip215: true is good for consensus-critical apps and allows points < 2^256
4201
- // zip215: false follows RFC8032 / NIST186-5 and restricts points to CURVE.p
4202
4266
  let A, R, SB;
4203
4267
  try {
4268
+ // zip215=true is good for consensus-critical apps. =false follows RFC8032 / NIST186-5.
4269
+ // zip215=true: 0 <= y < MASK (2^256 for ed25519)
4270
+ // zip215=false: 0 <= y < P (2^255-19 for ed25519)
4204
4271
  A = Point.fromHex(publicKey, zip215);
4205
4272
  R = Point.fromHex(sig.slice(0, len), zip215);
4206
4273
  SB = G.multiplyUnsafe(s); // 0 <= s < l is done inside
@@ -4212,6 +4279,7 @@ var solanaWeb3 = (function (exports) {
4212
4279
  return false;
4213
4280
  const k = hashDomainToScalar(context, R.toRawBytes(), A.toRawBytes(), msg);
4214
4281
  const RkA = R.add(A.multiplyUnsafe(k));
4282
+ // Extended group equation
4215
4283
  // [8][S]B = [8]R + [8][k]A'
4216
4284
  return RkA.subtract(SB).clearCofactor().equals(Point.ZERO);
4217
4285
  }
@@ -4307,7 +4375,7 @@ var solanaWeb3 = (function (exports) {
4307
4375
  x = mod(-x, P);
4308
4376
  return { isValid: useRoot1 || useRoot2, value: x };
4309
4377
  }
4310
- const Fp$1 = /* @__PURE__ */ (() => Field(ED25519_P, undefined, true))();
4378
+ const Fp = /* @__PURE__ */ (() => Field(ED25519_P, undefined, true))();
4311
4379
  const ed25519Defaults = /* @__PURE__ */ (() => ({
4312
4380
  // Param: a
4313
4381
  a: BigInt(-1), // Fp.create(-1) is proper; our way still works and is faster
@@ -4315,7 +4383,7 @@ var solanaWeb3 = (function (exports) {
4315
4383
  // Negative number is P - number, and division is invert(number, P)
4316
4384
  d: BigInt('37095705934669439343138083508754565189542113879843219016388785533085940283555'),
4317
4385
  // Finite field 𝔽p over which we'll do calculations; 2n**255n - 19n
4318
- Fp: Fp$1,
4386
+ Fp,
4319
4387
  // Subgroup order: how many points curve has
4320
4388
  // 2n**252n + 27742317777372353535851937790883648493n;
4321
4389
  n: BigInt('7237005577332262213973186563042994240857116359379907606001950938285454250989'),
@@ -7976,12 +8044,225 @@ var solanaWeb3 = (function (exports) {
7976
8044
  var bs58Exports = /*@__PURE__*/ requireBs58();
7977
8045
  var bs58 = /*@__PURE__*/getDefaultExportFromCjs(bs58Exports);
7978
8046
 
8047
+ function anumber(n) {
8048
+ if (!Number.isSafeInteger(n) || n < 0)
8049
+ throw new Error('positive integer expected, got ' + n);
8050
+ }
8051
+ // copied from utils
8052
+ function isBytes(a) {
8053
+ return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
8054
+ }
8055
+ function abytes(b, ...lengths) {
8056
+ if (!isBytes(b))
8057
+ throw new Error('Uint8Array expected');
8058
+ if (lengths.length > 0 && !lengths.includes(b.length))
8059
+ throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
8060
+ }
8061
+ function aexists(instance, checkFinished = true) {
8062
+ if (instance.destroyed)
8063
+ throw new Error('Hash instance has been destroyed');
8064
+ if (checkFinished && instance.finished)
8065
+ throw new Error('Hash#digest() has already been called');
8066
+ }
8067
+ function aoutput(out, instance) {
8068
+ abytes(out);
8069
+ const min = instance.outputLen;
8070
+ if (out.length < min) {
8071
+ throw new Error('digestInto() expects output buffer of length at least ' + min);
8072
+ }
8073
+ }
8074
+
8075
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
8076
+ // We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
8077
+ // node.js versions earlier than v19 don't declare it in global scope.
8078
+ // For node.js, package.json#exports field mapping rewrites import
8079
+ // from `crypto` to `cryptoNode`, which imports native module.
8080
+ // Makes the utils un-importable in browsers without a bundler.
8081
+ // Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
8082
+ const u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
8083
+ // Cast array to view
8084
+ const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
8085
+ // The rotate right (circular right shift) operation for uint32
8086
+ const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
8087
+ const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
8088
+ // The byte swap operation for uint32
8089
+ const byteSwap = (word) => ((word << 24) & 0xff000000) |
8090
+ ((word << 8) & 0xff0000) |
8091
+ ((word >>> 8) & 0xff00) |
8092
+ ((word >>> 24) & 0xff);
8093
+ // In place byte swap for Uint32Array
8094
+ function byteSwap32(arr) {
8095
+ for (let i = 0; i < arr.length; i++) {
8096
+ arr[i] = byteSwap(arr[i]);
8097
+ }
8098
+ }
8099
+ /**
8100
+ * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
8101
+ */
8102
+ function utf8ToBytes(str) {
8103
+ if (typeof str !== 'string')
8104
+ throw new Error('utf8ToBytes expected string, got ' + typeof str);
8105
+ return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
8106
+ }
8107
+ /**
8108
+ * Normalizes (non-hex) string or Uint8Array to Uint8Array.
8109
+ * Warning: when Uint8Array is passed, it would NOT get copied.
8110
+ * Keep in mind for future mutable operations.
8111
+ */
8112
+ function toBytes(data) {
8113
+ if (typeof data === 'string')
8114
+ data = utf8ToBytes(data);
8115
+ abytes(data);
8116
+ return data;
8117
+ }
8118
+ // For runtime check if class implements interface
8119
+ class Hash {
8120
+ // Safe version that clones internal state
8121
+ clone() {
8122
+ return this._cloneInto();
8123
+ }
8124
+ }
8125
+ function wrapConstructor(hashCons) {
8126
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
8127
+ const tmp = hashCons();
8128
+ hashC.outputLen = tmp.outputLen;
8129
+ hashC.blockLen = tmp.blockLen;
8130
+ hashC.create = () => hashCons();
8131
+ return hashC;
8132
+ }
8133
+
8134
+ /**
8135
+ * Polyfill for Safari 14
8136
+ */
8137
+ function setBigUint64(view, byteOffset, value, isLE) {
8138
+ if (typeof view.setBigUint64 === 'function')
8139
+ return view.setBigUint64(byteOffset, value, isLE);
8140
+ const _32n = BigInt(32);
8141
+ const _u32_max = BigInt(0xffffffff);
8142
+ const wh = Number((value >> _32n) & _u32_max);
8143
+ const wl = Number(value & _u32_max);
8144
+ const h = isLE ? 4 : 0;
8145
+ const l = isLE ? 0 : 4;
8146
+ view.setUint32(byteOffset + h, wh, isLE);
8147
+ view.setUint32(byteOffset + l, wl, isLE);
8148
+ }
8149
+ /**
8150
+ * Choice: a ? b : c
8151
+ */
8152
+ const Chi = (a, b, c) => (a & b) ^ (~a & c);
8153
+ /**
8154
+ * Majority function, true if any two inputs is true
8155
+ */
8156
+ const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
8157
+ /**
8158
+ * Merkle-Damgard hash construction base class.
8159
+ * Could be used to create MD5, RIPEMD, SHA1, SHA2.
8160
+ */
8161
+ class HashMD extends Hash {
8162
+ constructor(blockLen, outputLen, padOffset, isLE) {
8163
+ super();
8164
+ this.blockLen = blockLen;
8165
+ this.outputLen = outputLen;
8166
+ this.padOffset = padOffset;
8167
+ this.isLE = isLE;
8168
+ this.finished = false;
8169
+ this.length = 0;
8170
+ this.pos = 0;
8171
+ this.destroyed = false;
8172
+ this.buffer = new Uint8Array(blockLen);
8173
+ this.view = createView(this.buffer);
8174
+ }
8175
+ update(data) {
8176
+ aexists(this);
8177
+ const { view, buffer, blockLen } = this;
8178
+ data = toBytes(data);
8179
+ const len = data.length;
8180
+ for (let pos = 0; pos < len;) {
8181
+ const take = Math.min(blockLen - this.pos, len - pos);
8182
+ // Fast path: we have at least one block in input, cast it to view and process
8183
+ if (take === blockLen) {
8184
+ const dataView = createView(data);
8185
+ for (; blockLen <= len - pos; pos += blockLen)
8186
+ this.process(dataView, pos);
8187
+ continue;
8188
+ }
8189
+ buffer.set(data.subarray(pos, pos + take), this.pos);
8190
+ this.pos += take;
8191
+ pos += take;
8192
+ if (this.pos === blockLen) {
8193
+ this.process(view, 0);
8194
+ this.pos = 0;
8195
+ }
8196
+ }
8197
+ this.length += data.length;
8198
+ this.roundClean();
8199
+ return this;
8200
+ }
8201
+ digestInto(out) {
8202
+ aexists(this);
8203
+ aoutput(out, this);
8204
+ this.finished = true;
8205
+ // Padding
8206
+ // We can avoid allocation of buffer for padding completely if it
8207
+ // was previously not allocated here. But it won't change performance.
8208
+ const { buffer, view, blockLen, isLE } = this;
8209
+ let { pos } = this;
8210
+ // append the bit '1' to the message
8211
+ buffer[pos++] = 0b10000000;
8212
+ this.buffer.subarray(pos).fill(0);
8213
+ // we have less than padOffset left in buffer, so we cannot put length in
8214
+ // current block, need process it and pad again
8215
+ if (this.padOffset > blockLen - pos) {
8216
+ this.process(view, 0);
8217
+ pos = 0;
8218
+ }
8219
+ // Pad until full block byte with zeros
8220
+ for (let i = pos; i < blockLen; i++)
8221
+ buffer[i] = 0;
8222
+ // Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
8223
+ // You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
8224
+ // So we just write lowest 64 bits of that value.
8225
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
8226
+ this.process(view, 0);
8227
+ const oview = createView(out);
8228
+ const len = this.outputLen;
8229
+ // NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
8230
+ if (len % 4)
8231
+ throw new Error('_sha2: outputLen should be aligned to 32bit');
8232
+ const outLen = len / 4;
8233
+ const state = this.get();
8234
+ if (outLen > state.length)
8235
+ throw new Error('_sha2: outputLen bigger than state');
8236
+ for (let i = 0; i < outLen; i++)
8237
+ oview.setUint32(4 * i, state[i], isLE);
8238
+ }
8239
+ digest() {
8240
+ const { buffer, outputLen } = this;
8241
+ this.digestInto(buffer);
8242
+ const res = buffer.slice(0, outputLen);
8243
+ this.destroy();
8244
+ return res;
8245
+ }
8246
+ _cloneInto(to) {
8247
+ to || (to = new this.constructor());
8248
+ to.set(...this.get());
8249
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
8250
+ to.length = length;
8251
+ to.pos = pos;
8252
+ to.finished = finished;
8253
+ to.destroyed = destroyed;
8254
+ if (length % blockLen)
8255
+ to.buffer.set(buffer);
8256
+ return to;
8257
+ }
8258
+ }
8259
+
7979
8260
  // SHA2-256 need to try 2^128 hashes to execute birthday attack.
7980
- // BTC network is doing 2^67 hashes/sec as per early 2023.
8261
+ // BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per late 2024.
7981
8262
  // Round constants:
7982
8263
  // first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
7983
8264
  // prettier-ignore
7984
- const SHA256_K = /* @__PURE__ */ new Uint32Array([
8265
+ const SHA256_K$1 = /* @__PURE__ */ new Uint32Array([
7985
8266
  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
7986
8267
  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
7987
8268
  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
@@ -7994,25 +8275,25 @@ var solanaWeb3 = (function (exports) {
7994
8275
  // Initial state:
7995
8276
  // first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19
7996
8277
  // prettier-ignore
7997
- const SHA256_IV = /* @__PURE__ */ new Uint32Array([
8278
+ const SHA256_IV$1 = /* @__PURE__ */ new Uint32Array([
7998
8279
  0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
7999
8280
  ]);
8000
8281
  // Temporary buffer, not used to store anything between runs
8001
8282
  // Named this way because it matches specification.
8002
- const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
8003
- class SHA256 extends HashMD {
8283
+ const SHA256_W$1 = /* @__PURE__ */ new Uint32Array(64);
8284
+ let SHA256$1 = class SHA256 extends HashMD {
8004
8285
  constructor() {
8005
8286
  super(64, 32, 8, false);
8006
8287
  // We cannot use array here since array allows indexing by variable
8007
8288
  // which means optimizer/compiler cannot use registers.
8008
- this.A = SHA256_IV[0] | 0;
8009
- this.B = SHA256_IV[1] | 0;
8010
- this.C = SHA256_IV[2] | 0;
8011
- this.D = SHA256_IV[3] | 0;
8012
- this.E = SHA256_IV[4] | 0;
8013
- this.F = SHA256_IV[5] | 0;
8014
- this.G = SHA256_IV[6] | 0;
8015
- this.H = SHA256_IV[7] | 0;
8289
+ this.A = SHA256_IV$1[0] | 0;
8290
+ this.B = SHA256_IV$1[1] | 0;
8291
+ this.C = SHA256_IV$1[2] | 0;
8292
+ this.D = SHA256_IV$1[3] | 0;
8293
+ this.E = SHA256_IV$1[4] | 0;
8294
+ this.F = SHA256_IV$1[5] | 0;
8295
+ this.G = SHA256_IV$1[6] | 0;
8296
+ this.H = SHA256_IV$1[7] | 0;
8016
8297
  }
8017
8298
  get() {
8018
8299
  const { A, B, C, D, E, F, G, H } = this;
@@ -8032,19 +8313,19 @@ var solanaWeb3 = (function (exports) {
8032
8313
  process(view, offset) {
8033
8314
  // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
8034
8315
  for (let i = 0; i < 16; i++, offset += 4)
8035
- SHA256_W[i] = view.getUint32(offset, false);
8316
+ SHA256_W$1[i] = view.getUint32(offset, false);
8036
8317
  for (let i = 16; i < 64; i++) {
8037
- const W15 = SHA256_W[i - 15];
8038
- const W2 = SHA256_W[i - 2];
8318
+ const W15 = SHA256_W$1[i - 15];
8319
+ const W2 = SHA256_W$1[i - 2];
8039
8320
  const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
8040
8321
  const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
8041
- SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
8322
+ SHA256_W$1[i] = (s1 + SHA256_W$1[i - 7] + s0 + SHA256_W$1[i - 16]) | 0;
8042
8323
  }
8043
8324
  // Compression function main loop, 64 rounds
8044
8325
  let { A, B, C, D, E, F, G, H } = this;
8045
8326
  for (let i = 0; i < 64; i++) {
8046
8327
  const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
8047
- const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
8328
+ const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K$1[i] + SHA256_W$1[i]) | 0;
8048
8329
  const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
8049
8330
  const T2 = (sigma0 + Maj(A, B, C)) | 0;
8050
8331
  H = G;
@@ -8068,18 +8349,18 @@ var solanaWeb3 = (function (exports) {
8068
8349
  this.set(A, B, C, D, E, F, G, H);
8069
8350
  }
8070
8351
  roundClean() {
8071
- SHA256_W.fill(0);
8352
+ SHA256_W$1.fill(0);
8072
8353
  }
8073
8354
  destroy() {
8074
8355
  this.set(0, 0, 0, 0, 0, 0, 0, 0);
8075
8356
  this.buffer.fill(0);
8076
8357
  }
8077
- }
8358
+ };
8078
8359
  /**
8079
8360
  * SHA2-256 hash function
8080
8361
  * @param message - data that would be hashed
8081
8362
  */
8082
- const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
8363
+ const sha256$1 = /* @__PURE__ */ wrapConstructor(() => new SHA256$1());
8083
8364
 
8084
8365
  var lib = {};
8085
8366
 
@@ -9343,7 +9624,7 @@ var solanaWeb3 = (function (exports) {
9343
9624
  /* eslint-disable require-await */
9344
9625
  static async createWithSeed(fromPublicKey, seed, programId) {
9345
9626
  const buffer = bufferExports.Buffer.concat([fromPublicKey.toBuffer(), bufferExports.Buffer.from(seed), programId.toBuffer()]);
9346
- const publicKeyBytes = sha256(buffer);
9627
+ const publicKeyBytes = sha256$1(buffer);
9347
9628
  return new PublicKey(publicKeyBytes);
9348
9629
  }
9349
9630
 
@@ -9360,7 +9641,7 @@ var solanaWeb3 = (function (exports) {
9360
9641
  buffer = bufferExports.Buffer.concat([buffer, toBuffer(seed)]);
9361
9642
  });
9362
9643
  buffer = bufferExports.Buffer.concat([buffer, programId.toBuffer(), bufferExports.Buffer.from('ProgramDerivedAddress')]);
9363
- const publicKeyBytes = sha256(buffer);
9644
+ const publicKeyBytes = sha256$1(buffer);
9364
9645
  if (isOnCurve(publicKeyBytes)) {
9365
9646
  throw new Error(`Invalid seeds, address must fall off the curve`);
9366
9647
  }
@@ -20424,7 +20705,7 @@ var solanaWeb3 = (function (exports) {
20424
20705
  */
20425
20706
  async getConfirmedBlock(slot, commitment) {
20426
20707
  const args = this._buildArgsAtLeastConfirmed([slot], commitment);
20427
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
20708
+ const unsafeRes = await this._rpcRequest('getBlock', args);
20428
20709
  const res = create(unsafeRes, GetConfirmedBlockRpcResult);
20429
20710
  if ('error' in res) {
20430
20711
  throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
@@ -20506,7 +20787,7 @@ var solanaWeb3 = (function (exports) {
20506
20787
  transactionDetails: 'signatures',
20507
20788
  rewards: false
20508
20789
  });
20509
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
20790
+ const unsafeRes = await this._rpcRequest('getBlock', args);
20510
20791
  const res = create(unsafeRes, GetBlockSignaturesRpcResult);
20511
20792
  if ('error' in res) {
20512
20793
  throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
@@ -22394,6 +22675,31 @@ var solanaWeb3 = (function (exports) {
22394
22675
  }
22395
22676
  Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
22396
22677
 
22678
+ const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
22679
+ const _32n = /* @__PURE__ */ BigInt(32);
22680
+ // BigUint64Array is too slow as per 2024, so we implement it using Uint32Array.
22681
+ // TODO: re-check https://issues.chromium.org/issues/42212588
22682
+ function fromBig(n, le = false) {
22683
+ if (le)
22684
+ return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
22685
+ return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
22686
+ }
22687
+ function split(lst, le = false) {
22688
+ let Ah = new Uint32Array(lst.length);
22689
+ let Al = new Uint32Array(lst.length);
22690
+ for (let i = 0; i < lst.length; i++) {
22691
+ const { h, l } = fromBig(lst[i], le);
22692
+ [Ah[i], Al[i]] = [h, l];
22693
+ }
22694
+ return [Ah, Al];
22695
+ }
22696
+ // Left rotate for Shift in [1, 32)
22697
+ const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
22698
+ const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
22699
+ // Left rotate for Shift in (32, 64), NOTE: 32 is special case.
22700
+ const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
22701
+ const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
22702
+
22397
22703
  // SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size.
22398
22704
  // It's called a sponge function.
22399
22705
  // Various per round constants calculations
@@ -22485,7 +22791,7 @@ var solanaWeb3 = (function (exports) {
22485
22791
  this.finished = false;
22486
22792
  this.destroyed = false;
22487
22793
  // Can be passed from user as dkLen
22488
- number$1(outputLen);
22794
+ anumber(outputLen);
22489
22795
  // 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
22490
22796
  if (0 >= this.blockLen || this.blockLen >= 200)
22491
22797
  throw new Error('Sha3 supports only keccak-f1600 function');
@@ -22502,7 +22808,7 @@ var solanaWeb3 = (function (exports) {
22502
22808
  this.pos = 0;
22503
22809
  }
22504
22810
  update(data) {
22505
- exists(this);
22811
+ aexists(this);
22506
22812
  const { blockLen, state } = this;
22507
22813
  data = toBytes(data);
22508
22814
  const len = data.length;
@@ -22528,8 +22834,8 @@ var solanaWeb3 = (function (exports) {
22528
22834
  this.keccak();
22529
22835
  }
22530
22836
  writeInto(out) {
22531
- exists(this, false);
22532
- bytes(out);
22837
+ aexists(this, false);
22838
+ abytes(out);
22533
22839
  this.finish();
22534
22840
  const bufferOut = this.state;
22535
22841
  const { blockLen } = this;
@@ -22550,11 +22856,11 @@ var solanaWeb3 = (function (exports) {
22550
22856
  return this.writeInto(out);
22551
22857
  }
22552
22858
  xof(bytes) {
22553
- number$1(bytes);
22859
+ anumber(bytes);
22554
22860
  return this.xofInto(new Uint8Array(bytes));
22555
22861
  }
22556
22862
  digestInto(out) {
22557
- output(out, this);
22863
+ aoutput(out, this);
22558
22864
  if (this.finished)
22559
22865
  throw new Error('digest() was already called');
22560
22866
  this.writeInto(out);
@@ -22591,15 +22897,120 @@ var solanaWeb3 = (function (exports) {
22591
22897
  */
22592
22898
  const keccak_256 = /* @__PURE__ */ gen(0x01, 136, 256 / 8);
22593
22899
 
22900
+ // SHA2-256 need to try 2^128 hashes to execute birthday attack.
22901
+ // BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per late 2024.
22902
+ // Round constants:
22903
+ // first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
22904
+ // prettier-ignore
22905
+ const SHA256_K = /* @__PURE__ */ new Uint32Array([
22906
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
22907
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
22908
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
22909
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
22910
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
22911
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
22912
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
22913
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
22914
+ ]);
22915
+ // Initial state:
22916
+ // first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19
22917
+ // prettier-ignore
22918
+ const SHA256_IV = /* @__PURE__ */ new Uint32Array([
22919
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
22920
+ ]);
22921
+ // Temporary buffer, not used to store anything between runs
22922
+ // Named this way because it matches specification.
22923
+ const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
22924
+ class SHA256 extends HashMD$1 {
22925
+ constructor() {
22926
+ super(64, 32, 8, false);
22927
+ // We cannot use array here since array allows indexing by variable
22928
+ // which means optimizer/compiler cannot use registers.
22929
+ this.A = SHA256_IV[0] | 0;
22930
+ this.B = SHA256_IV[1] | 0;
22931
+ this.C = SHA256_IV[2] | 0;
22932
+ this.D = SHA256_IV[3] | 0;
22933
+ this.E = SHA256_IV[4] | 0;
22934
+ this.F = SHA256_IV[5] | 0;
22935
+ this.G = SHA256_IV[6] | 0;
22936
+ this.H = SHA256_IV[7] | 0;
22937
+ }
22938
+ get() {
22939
+ const { A, B, C, D, E, F, G, H } = this;
22940
+ return [A, B, C, D, E, F, G, H];
22941
+ }
22942
+ // prettier-ignore
22943
+ set(A, B, C, D, E, F, G, H) {
22944
+ this.A = A | 0;
22945
+ this.B = B | 0;
22946
+ this.C = C | 0;
22947
+ this.D = D | 0;
22948
+ this.E = E | 0;
22949
+ this.F = F | 0;
22950
+ this.G = G | 0;
22951
+ this.H = H | 0;
22952
+ }
22953
+ process(view, offset) {
22954
+ // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
22955
+ for (let i = 0; i < 16; i++, offset += 4)
22956
+ SHA256_W[i] = view.getUint32(offset, false);
22957
+ for (let i = 16; i < 64; i++) {
22958
+ const W15 = SHA256_W[i - 15];
22959
+ const W2 = SHA256_W[i - 2];
22960
+ const s0 = rotr$1(W15, 7) ^ rotr$1(W15, 18) ^ (W15 >>> 3);
22961
+ const s1 = rotr$1(W2, 17) ^ rotr$1(W2, 19) ^ (W2 >>> 10);
22962
+ SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
22963
+ }
22964
+ // Compression function main loop, 64 rounds
22965
+ let { A, B, C, D, E, F, G, H } = this;
22966
+ for (let i = 0; i < 64; i++) {
22967
+ const sigma1 = rotr$1(E, 6) ^ rotr$1(E, 11) ^ rotr$1(E, 25);
22968
+ const T1 = (H + sigma1 + Chi$1(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
22969
+ const sigma0 = rotr$1(A, 2) ^ rotr$1(A, 13) ^ rotr$1(A, 22);
22970
+ const T2 = (sigma0 + Maj$1(A, B, C)) | 0;
22971
+ H = G;
22972
+ G = F;
22973
+ F = E;
22974
+ E = (D + T1) | 0;
22975
+ D = C;
22976
+ C = B;
22977
+ B = A;
22978
+ A = (T1 + T2) | 0;
22979
+ }
22980
+ // Add the compressed chunk to the current hash value
22981
+ A = (A + this.A) | 0;
22982
+ B = (B + this.B) | 0;
22983
+ C = (C + this.C) | 0;
22984
+ D = (D + this.D) | 0;
22985
+ E = (E + this.E) | 0;
22986
+ F = (F + this.F) | 0;
22987
+ G = (G + this.G) | 0;
22988
+ H = (H + this.H) | 0;
22989
+ this.set(A, B, C, D, E, F, G, H);
22990
+ }
22991
+ roundClean() {
22992
+ SHA256_W.fill(0);
22993
+ }
22994
+ destroy() {
22995
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
22996
+ this.buffer.fill(0);
22997
+ }
22998
+ }
22999
+ /**
23000
+ * SHA2-256 hash function
23001
+ * @param message - data that would be hashed
23002
+ */
23003
+ const sha256 = /* @__PURE__ */ wrapConstructor$1(() => new SHA256());
23004
+
22594
23005
  // HMAC (RFC 2104)
22595
- class HMAC extends Hash {
22596
- constructor(hash$1, _key) {
23006
+ class HMAC extends Hash$1 {
23007
+ constructor(hash, _key) {
22597
23008
  super();
22598
23009
  this.finished = false;
22599
23010
  this.destroyed = false;
22600
- hash(hash$1);
22601
- const key = toBytes(_key);
22602
- this.iHash = hash$1.create();
23011
+ ahash(hash);
23012
+ const key = toBytes$1(_key);
23013
+ this.iHash = hash.create();
22603
23014
  if (typeof this.iHash.update !== 'function')
22604
23015
  throw new Error('Expected instance of class which extends utils.Hash');
22605
23016
  this.blockLen = this.iHash.blockLen;
@@ -22607,12 +23018,12 @@ var solanaWeb3 = (function (exports) {
22607
23018
  const blockLen = this.blockLen;
22608
23019
  const pad = new Uint8Array(blockLen);
22609
23020
  // blockLen can be bigger than outputLen
22610
- pad.set(key.length > blockLen ? hash$1.create().update(key).digest() : key);
23021
+ pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
22611
23022
  for (let i = 0; i < pad.length; i++)
22612
23023
  pad[i] ^= 0x36;
22613
23024
  this.iHash.update(pad);
22614
23025
  // By doing update (processing of first block) of outer hash here we can re-use it between multiple calls via clone
22615
- this.oHash = hash$1.create();
23026
+ this.oHash = hash.create();
22616
23027
  // Undo internal XOR && apply outer XOR
22617
23028
  for (let i = 0; i < pad.length; i++)
22618
23029
  pad[i] ^= 0x36 ^ 0x5c;
@@ -22620,13 +23031,13 @@ var solanaWeb3 = (function (exports) {
22620
23031
  pad.fill(0);
22621
23032
  }
22622
23033
  update(buf) {
22623
- exists(this);
23034
+ aexists$1(this);
22624
23035
  this.iHash.update(buf);
22625
23036
  return this;
22626
23037
  }
22627
23038
  digestInto(out) {
22628
- exists(this);
22629
- bytes(out, this.outputLen);
23039
+ aexists$1(this);
23040
+ abytes$2(out, this.outputLen);
22630
23041
  this.finished = true;
22631
23042
  this.iHash.digestInto(out);
22632
23043
  this.oHash.update(out);
@@ -22695,12 +23106,12 @@ var solanaWeb3 = (function (exports) {
22695
23106
  const { endo, Fp, a } = opts;
22696
23107
  if (endo) {
22697
23108
  if (!Fp.eql(a, Fp.ZERO)) {
22698
- throw new Error('Endomorphism can only be defined for Koblitz curves that have a=0');
23109
+ throw new Error('invalid endomorphism, can only be defined for Koblitz curves that have a=0');
22699
23110
  }
22700
23111
  if (typeof endo !== 'object' ||
22701
23112
  typeof endo.beta !== 'bigint' ||
22702
23113
  typeof endo.splitScalar !== 'function') {
22703
- throw new Error('Expected endomorphism with beta: bigint and splitScalar: function');
23114
+ throw new Error('invalid endomorphism, expected beta: bigint and splitScalar: function');
22704
23115
  }
22705
23116
  }
22706
23117
  return Object.freeze({ ...opts });
@@ -22734,7 +23145,8 @@ var solanaWeb3 = (function (exports) {
22734
23145
  throw new E('tlv.encode: long form length too big');
22735
23146
  // length of length with long form flag
22736
23147
  const lenLen = dataLen > 127 ? numberToHexUnpadded((len.length / 2) | 128) : '';
22737
- return `${numberToHexUnpadded(tag)}${lenLen}${len}${data}`;
23148
+ const t = numberToHexUnpadded(tag);
23149
+ return t + lenLen + len + data;
22738
23150
  },
22739
23151
  // v - value, l - left bytes (unparsed)
22740
23152
  decode(tag, data) {
@@ -22787,15 +23199,15 @@ var solanaWeb3 = (function (exports) {
22787
23199
  if (Number.parseInt(hex[0], 16) & 0b1000)
22788
23200
  hex = '00' + hex;
22789
23201
  if (hex.length & 1)
22790
- throw new E('unexpected assertion');
23202
+ throw new E('unexpected DER parsing assertion: unpadded hex');
22791
23203
  return hex;
22792
23204
  },
22793
23205
  decode(data) {
22794
23206
  const { Err: E } = DER;
22795
23207
  if (data[0] & 128)
22796
- throw new E('Invalid signature integer: negative');
23208
+ throw new E('invalid signature integer: negative');
22797
23209
  if (data[0] === 0x00 && !(data[1] & 128))
22798
- throw new E('Invalid signature integer: unnecessary leading zero');
23210
+ throw new E('invalid signature integer: unnecessary leading zero');
22799
23211
  return b2n(data);
22800
23212
  },
22801
23213
  },
@@ -22803,19 +23215,21 @@ var solanaWeb3 = (function (exports) {
22803
23215
  // parse DER signature
22804
23216
  const { Err: E, _int: int, _tlv: tlv } = DER;
22805
23217
  const data = typeof hex === 'string' ? h2b(hex) : hex;
22806
- abytes(data);
23218
+ abytes$1(data);
22807
23219
  const { v: seqBytes, l: seqLeftBytes } = tlv.decode(0x30, data);
22808
23220
  if (seqLeftBytes.length)
22809
- throw new E('Invalid signature: left bytes after parsing');
23221
+ throw new E('invalid signature: left bytes after parsing');
22810
23222
  const { v: rBytes, l: rLeftBytes } = tlv.decode(0x02, seqBytes);
22811
23223
  const { v: sBytes, l: sLeftBytes } = tlv.decode(0x02, rLeftBytes);
22812
23224
  if (sLeftBytes.length)
22813
- throw new E('Invalid signature: left bytes after parsing');
23225
+ throw new E('invalid signature: left bytes after parsing');
22814
23226
  return { r: int.decode(rBytes), s: int.decode(sBytes) };
22815
23227
  },
22816
23228
  hexFromSig(sig) {
22817
23229
  const { _tlv: tlv, _int: int } = DER;
22818
- const seq = `${tlv.encode(0x02, int.encode(sig.r))}${tlv.encode(0x02, int.encode(sig.s))}`;
23230
+ const rs = tlv.encode(0x02, int.encode(sig.r));
23231
+ const ss = tlv.encode(0x02, int.encode(sig.s));
23232
+ const seq = rs + ss;
22819
23233
  return tlv.encode(0x30, seq);
22820
23234
  },
22821
23235
  };
@@ -22865,11 +23279,11 @@ var solanaWeb3 = (function (exports) {
22865
23279
  function normPrivateKeyToScalar(key) {
22866
23280
  const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: N } = CURVE;
22867
23281
  if (lengths && typeof key !== 'bigint') {
22868
- if (isBytes(key))
23282
+ if (isBytes$1(key))
22869
23283
  key = bytesToHex(key);
22870
23284
  // Normalize to hex string, pad. E.g. P521 would norm 130-132 char hex to 132-char bytes
22871
23285
  if (typeof key !== 'string' || !lengths.includes(key.length))
22872
- throw new Error('Invalid key');
23286
+ throw new Error('invalid private key');
22873
23287
  key = key.padStart(nByteLength * 2, '0');
22874
23288
  }
22875
23289
  let num;
@@ -22880,7 +23294,7 @@ var solanaWeb3 = (function (exports) {
22880
23294
  : bytesToNumberBE(ensureBytes('private key', key, nByteLength));
22881
23295
  }
22882
23296
  catch (error) {
22883
- throw new Error(`private key must be ${nByteLength} bytes, hex or bigint, not ${typeof key}`);
23297
+ throw new Error('invalid private key, expected hex or ' + nByteLength + ' bytes, got ' + typeof key);
22884
23298
  }
22885
23299
  if (wrapPrivateKey)
22886
23300
  num = mod(num, N); // disabled by default, enabled for BLS
@@ -22920,7 +23334,7 @@ var solanaWeb3 = (function (exports) {
22920
23334
  if (p.is0()) {
22921
23335
  // (0, 1, 0) aka ZERO is invalid in most contexts.
22922
23336
  // In BLS, ZERO can be serialized, so we allow it.
22923
- // (0, 0, 0) is wrong representation of ZERO and is always invalid.
23337
+ // (0, 0, 0) is invalid representation of ZERO.
22924
23338
  if (CURVE.allowInfinityPoint && !Fp.is0(p.py))
22925
23339
  return;
22926
23340
  throw new Error('bad point: ZERO');
@@ -23144,16 +23558,17 @@ var solanaWeb3 = (function (exports) {
23144
23558
  * an exposed private key e.g. sig verification, which works over *public* keys.
23145
23559
  */
23146
23560
  multiplyUnsafe(sc) {
23147
- aInRange('scalar', sc, _0n, CURVE.n);
23561
+ const { endo, n: N } = CURVE;
23562
+ aInRange('scalar', sc, _0n, N);
23148
23563
  const I = Point.ZERO;
23149
23564
  if (sc === _0n)
23150
23565
  return I;
23151
- if (sc === _1n$1)
23566
+ if (this.is0() || sc === _1n$1)
23152
23567
  return this;
23153
- const { endo } = CURVE;
23154
- if (!endo)
23155
- return wnaf.unsafeLadder(this, sc);
23156
- // Apply endomorphism
23568
+ // Case a: no endomorphism. Case b: has precomputes.
23569
+ if (!endo || wnaf.hasPrecomputes(this))
23570
+ return wnaf.wNAFCachedUnsafe(this, sc, Point.normalizeZ);
23571
+ // Case c: endomorphism
23157
23572
  let { k1neg, k1, k2neg, k2 } = endo.splitScalar(sc);
23158
23573
  let k1p = I;
23159
23574
  let k2p = I;
@@ -23339,7 +23754,9 @@ var solanaWeb3 = (function (exports) {
23339
23754
  return { x, y };
23340
23755
  }
23341
23756
  else {
23342
- throw new Error(`Point of length ${len} was invalid. Expected ${compressedLen} compressed bytes or ${uncompressedLen} uncompressed bytes`);
23757
+ const cl = compressedLen;
23758
+ const ul = uncompressedLen;
23759
+ throw new Error('invalid Point, expected length of ' + cl + ', or uncompressed ' + ul + ', got ' + len);
23343
23760
  }
23344
23761
  },
23345
23762
  });
@@ -23469,7 +23886,7 @@ var solanaWeb3 = (function (exports) {
23469
23886
  * Quick and dirty check for item being public key. Does not validate hex, or being on-curve.
23470
23887
  */
23471
23888
  function isProbPub(item) {
23472
- const arr = isBytes(item);
23889
+ const arr = isBytes$1(item);
23473
23890
  const str = typeof item === 'string';
23474
23891
  const len = (arr || str) && item.length;
23475
23892
  if (arr)
@@ -23504,6 +23921,9 @@ var solanaWeb3 = (function (exports) {
23504
23921
  // int2octets can't be used; pads small msgs with 0: unacceptatble for trunc as per RFC vectors
23505
23922
  const bits2int = CURVE.bits2int ||
23506
23923
  function (bytes) {
23924
+ // Our custom check "just in case"
23925
+ if (bytes.length > 8192)
23926
+ throw new Error('input is too large');
23507
23927
  // For curves with nBitLength % 8 !== 0: bits2octets(bits2octets(m)) !== bits2octets(m)
23508
23928
  // for some cases, since bytes.length * 8 is not actual bitLength.
23509
23929
  const num = bytesToNumberBE(bytes); // check for == u8 done here
@@ -23520,15 +23940,15 @@ var solanaWeb3 = (function (exports) {
23520
23940
  * Converts to bytes. Checks if num in `[0..ORDER_MASK-1]` e.g.: `[0..2^256-1]`.
23521
23941
  */
23522
23942
  function int2octets(num) {
23523
- aInRange(`num < 2^${CURVE.nBitLength}`, num, _0n, ORDER_MASK);
23943
+ aInRange('num < 2^' + CURVE.nBitLength, num, _0n, ORDER_MASK);
23524
23944
  // works with order, can have different size than numToField!
23525
23945
  return numberToBytesBE(num, CURVE.nByteLength);
23526
23946
  }
23527
23947
  // Steps A, D of RFC6979 3.2
23528
23948
  // Creates RFC6979 seed; converts msg/privKey to numbers.
23529
23949
  // Used only in sign, not in verify.
23530
- // NOTE: we cannot assume here that msgHash has same amount of bytes as curve order, this will be wrong at least for P521.
23531
- // Also it can be bigger for P224 + SHA256
23950
+ // NOTE: we cannot assume here that msgHash has same amount of bytes as curve order,
23951
+ // this will be invalid at least for P521. Also it can be bigger for P224 + SHA256
23532
23952
  function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
23533
23953
  if (['recovered', 'canonical'].some((k) => k in opts))
23534
23954
  throw new Error('sign() legacy options not supported');
@@ -23622,39 +24042,48 @@ var solanaWeb3 = (function (exports) {
23622
24042
  const sg = signature;
23623
24043
  msgHash = ensureBytes('msgHash', msgHash);
23624
24044
  publicKey = ensureBytes('publicKey', publicKey);
24045
+ const { lowS, prehash, format } = opts;
24046
+ // Verify opts, deduce signature format
24047
+ validateSigVerOpts(opts);
23625
24048
  if ('strict' in opts)
23626
24049
  throw new Error('options.strict was renamed to lowS');
23627
- validateSigVerOpts(opts);
23628
- const { lowS, prehash } = opts;
24050
+ if (format !== undefined && format !== 'compact' && format !== 'der')
24051
+ throw new Error('format must be compact or der');
24052
+ const isHex = typeof sg === 'string' || isBytes$1(sg);
24053
+ const isObj = !isHex &&
24054
+ !format &&
24055
+ typeof sg === 'object' &&
24056
+ sg !== null &&
24057
+ typeof sg.r === 'bigint' &&
24058
+ typeof sg.s === 'bigint';
24059
+ if (!isHex && !isObj)
24060
+ throw new Error('invalid signature, expected Uint8Array, hex string or Signature instance');
23629
24061
  let _sig = undefined;
23630
24062
  let P;
23631
24063
  try {
23632
- if (typeof sg === 'string' || isBytes(sg)) {
24064
+ if (isObj)
24065
+ _sig = new Signature(sg.r, sg.s);
24066
+ if (isHex) {
23633
24067
  // Signature can be represented in 2 ways: compact (2*nByteLength) & DER (variable-length).
23634
24068
  // Since DER can also be 2*nByteLength bytes, we check for it first.
23635
24069
  try {
23636
- _sig = Signature.fromDER(sg);
24070
+ if (format !== 'compact')
24071
+ _sig = Signature.fromDER(sg);
23637
24072
  }
23638
24073
  catch (derError) {
23639
24074
  if (!(derError instanceof DER.Err))
23640
24075
  throw derError;
23641
- _sig = Signature.fromCompact(sg);
23642
24076
  }
23643
- }
23644
- else if (typeof sg === 'object' && typeof sg.r === 'bigint' && typeof sg.s === 'bigint') {
23645
- const { r, s } = sg;
23646
- _sig = new Signature(r, s);
23647
- }
23648
- else {
23649
- throw new Error('PARSE');
24077
+ if (!_sig && format !== 'der')
24078
+ _sig = Signature.fromCompact(sg);
23650
24079
  }
23651
24080
  P = Point.fromHex(publicKey);
23652
24081
  }
23653
24082
  catch (error) {
23654
- if (error.message === 'PARSE')
23655
- throw new Error(`signature must be Signature instance, Uint8Array or hex string`);
23656
24083
  return false;
23657
24084
  }
24085
+ if (!_sig)
24086
+ return false;
23658
24087
  if (lowS && _sig.hasHighS())
23659
24088
  return false;
23660
24089
  if (prehash)
@@ -23726,18 +24155,18 @@ var solanaWeb3 = (function (exports) {
23726
24155
  const t1 = (pow2(b223, _23n, P) * b22) % P;
23727
24156
  const t2 = (pow2(t1, _6n, P) * b2) % P;
23728
24157
  const root = pow2(t2, _2n, P);
23729
- if (!Fp.eql(Fp.sqr(root), y))
24158
+ if (!Fpk1.eql(Fpk1.sqr(root), y))
23730
24159
  throw new Error('Cannot find square root');
23731
24160
  return root;
23732
24161
  }
23733
- const Fp = Field(secp256k1P, undefined, undefined, { sqrt: sqrtMod });
24162
+ const Fpk1 = Field(secp256k1P, undefined, undefined, { sqrt: sqrtMod });
23734
24163
  /**
23735
24164
  * secp256k1 short weierstrass curve and ECDSA signatures over it.
23736
24165
  */
23737
24166
  const secp256k1 = createCurve({
23738
24167
  a: BigInt(0), // equation params: a, b
23739
24168
  b: BigInt(7), // Seem to be rigid: bitcointalk.org/index.php?topic=289795.msg3183975#msg3183975
23740
- Fp, // Field's prime: 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
24169
+ Fp: Fpk1, // Field's prime: 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
23741
24170
  n: secp256k1N, // Curve order, total count of valid points in the field
23742
24171
  // Base point (x, y) aka generator point
23743
24172
  Gx: BigInt('55066263022277343669578718895168534326250603453777594175500187360389116729240'),