@zelana/sdk 0.1.2 → 0.1.4

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/index.js CHANGED
@@ -1,27 +1,3 @@
1
- var __create = Object.create;
2
- var __getProtoOf = Object.getPrototypeOf;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __toESM = (mod, isNodeMode, target) => {
7
- target = mod != null ? __create(__getProtoOf(mod)) : {};
8
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
9
- for (let key of __getOwnPropNames(mod))
10
- if (!__hasOwnProp.call(to, key))
11
- __defProp(to, key, {
12
- get: () => mod[key],
13
- enumerable: true
14
- });
15
- return to;
16
- };
17
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
18
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
19
- }) : x)(function(x) {
20
- if (typeof require !== "undefined")
21
- return require.apply(this, arguments);
22
- throw Error('Dynamic require of "' + x + '" is not supported');
23
- });
24
-
25
1
  // node_modules/@noble/ed25519/index.js
26
2
  /*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
27
3
  var ed25519_CURVE = {
@@ -473,11 +449,18 @@ var wNAF = (n) => {
473
449
  return { p, f };
474
450
  };
475
451
 
452
+ // node_modules/@noble/hashes/esm/crypto.js
453
+ var crypto2 = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : undefined;
454
+
476
455
  // node_modules/@noble/hashes/esm/utils.js
477
456
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
478
457
  function isBytes2(a) {
479
458
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
480
459
  }
460
+ function anumber(n) {
461
+ if (!Number.isSafeInteger(n) || n < 0)
462
+ throw new Error("positive integer expected, got " + n);
463
+ }
481
464
  function abytes2(b, ...lengths) {
482
465
  if (!isBytes2(b))
483
466
  throw new Error("Uint8Array expected");
@@ -497,6 +480,12 @@ function aoutput(out, instance) {
497
480
  throw new Error("digestInto() expects output buffer of length at least " + min);
498
481
  }
499
482
  }
483
+ function u8(arr) {
484
+ return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
485
+ }
486
+ function u32(arr) {
487
+ return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
488
+ }
500
489
  function clean(...arrays) {
501
490
  for (let i = 0;i < arrays.length; i++) {
502
491
  arrays[i].fill(0);
@@ -505,6 +494,21 @@ function clean(...arrays) {
505
494
  function createView(arr) {
506
495
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
507
496
  }
497
+ function rotr(word, shift) {
498
+ return word << 32 - shift | word >>> shift;
499
+ }
500
+ var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
501
+ function byteSwap(word) {
502
+ return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
503
+ }
504
+ var swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n);
505
+ function byteSwap32(arr) {
506
+ for (let i = 0;i < arr.length; i++) {
507
+ arr[i] = byteSwap(arr[i]);
508
+ }
509
+ return arr;
510
+ }
511
+ var swap32IfBE = isLE ? (u) => u : byteSwap32;
508
512
  function utf8ToBytes(str) {
509
513
  if (typeof str !== "string")
510
514
  throw new Error("string expected");
@@ -526,22 +530,39 @@ function createHasher(hashCons) {
526
530
  hashC.create = () => hashCons();
527
531
  return hashC;
528
532
  }
533
+ function createXOFer(hashCons) {
534
+ const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
535
+ const tmp = hashCons({});
536
+ hashC.outputLen = tmp.outputLen;
537
+ hashC.blockLen = tmp.blockLen;
538
+ hashC.create = (opts) => hashCons(opts);
539
+ return hashC;
540
+ }
541
+ function randomBytes2(bytesLength = 32) {
542
+ if (crypto2 && typeof crypto2.getRandomValues === "function") {
543
+ return crypto2.getRandomValues(new Uint8Array(bytesLength));
544
+ }
545
+ if (crypto2 && typeof crypto2.randomBytes === "function") {
546
+ return Uint8Array.from(crypto2.randomBytes(bytesLength));
547
+ }
548
+ throw new Error("crypto.getRandomValues must be defined");
549
+ }
529
550
 
530
551
  // node_modules/@noble/hashes/esm/_md.js
531
- function setBigUint64(view, byteOffset, value, isLE) {
552
+ function setBigUint64(view, byteOffset, value, isLE2) {
532
553
  if (typeof view.setBigUint64 === "function")
533
- return view.setBigUint64(byteOffset, value, isLE);
554
+ return view.setBigUint64(byteOffset, value, isLE2);
534
555
  const _32n = BigInt(32);
535
556
  const _u32_max = BigInt(4294967295);
536
557
  const wh = Number(value >> _32n & _u32_max);
537
558
  const wl = Number(value & _u32_max);
538
- const h2 = isLE ? 4 : 0;
539
- const l = isLE ? 0 : 4;
540
- view.setUint32(byteOffset + h2, wh, isLE);
541
- view.setUint32(byteOffset + l, wl, isLE);
559
+ const h2 = isLE2 ? 4 : 0;
560
+ const l = isLE2 ? 0 : 4;
561
+ view.setUint32(byteOffset + h2, wh, isLE2);
562
+ view.setUint32(byteOffset + l, wl, isLE2);
542
563
  }
543
564
  class HashMD extends Hash {
544
- constructor(blockLen, outputLen, padOffset, isLE) {
565
+ constructor(blockLen, outputLen, padOffset, isLE2) {
545
566
  super();
546
567
  this.finished = false;
547
568
  this.length = 0;
@@ -550,7 +571,7 @@ class HashMD extends Hash {
550
571
  this.blockLen = blockLen;
551
572
  this.outputLen = outputLen;
552
573
  this.padOffset = padOffset;
553
- this.isLE = isLE;
574
+ this.isLE = isLE2;
554
575
  this.buffer = new Uint8Array(blockLen);
555
576
  this.view = createView(this.buffer);
556
577
  }
@@ -584,7 +605,7 @@ class HashMD extends Hash {
584
605
  aexists(this);
585
606
  aoutput(out, this);
586
607
  this.finished = true;
587
- const { buffer, view, blockLen, isLE } = this;
608
+ const { buffer, view, blockLen, isLE: isLE2 } = this;
588
609
  let { pos } = this;
589
610
  buffer[pos++] = 128;
590
611
  clean(this.buffer.subarray(pos));
@@ -594,7 +615,7 @@ class HashMD extends Hash {
594
615
  }
595
616
  for (let i = pos;i < blockLen; i++)
596
617
  buffer[i] = 0;
597
- setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
618
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
598
619
  this.process(view, 0);
599
620
  const oview = createView(out);
600
621
  const len = this.outputLen;
@@ -605,7 +626,7 @@ class HashMD extends Hash {
605
626
  if (outLen > state.length)
606
627
  throw new Error("_sha2: outputLen bigger than state");
607
628
  for (let i = 0;i < outLen; i++)
608
- oview.setUint32(4 * i, state[i], isLE);
629
+ oview.setUint32(4 * i, state[i], isLE2);
609
630
  }
610
631
  digest() {
611
632
  const { buffer, outputLen } = this;
@@ -630,6 +651,16 @@ class HashMD extends Hash {
630
651
  return this._cloneInto();
631
652
  }
632
653
  }
654
+ var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
655
+ 1779033703,
656
+ 3144134277,
657
+ 1013904242,
658
+ 2773480762,
659
+ 1359893119,
660
+ 2600822924,
661
+ 528734635,
662
+ 1541459225
663
+ ]);
633
664
  var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
634
665
  1779033703,
635
666
  4089235720,
@@ -1017,7 +1048,7 @@ function bytesEqual(a, b) {
1017
1048
  }
1018
1049
  return true;
1019
1050
  }
1020
- function randomBytes2(length) {
1051
+ function randomBytes3(length) {
1021
1052
  const bytes = new Uint8Array(length);
1022
1053
  if (typeof crypto !== "undefined" && crypto.getRandomValues) {
1023
1054
  crypto.getRandomValues(bytes);
@@ -1030,6 +1061,27 @@ function randomBytes2(length) {
1030
1061
  }
1031
1062
 
1032
1063
  // src/keypair.ts
1064
+ function buildTransferMessage(from, to, amount, nonce, chainId) {
1065
+ return `Zelana L2 Transfer
1066
+
1067
+ From: ${bytesToHex2(from)}
1068
+ To: ${bytesToHex2(to)}
1069
+ Amount: ${amount.toString()} lamports
1070
+ Nonce: ${nonce.toString()}
1071
+ Chain ID: ${chainId.toString()}
1072
+
1073
+ Sign to authorize this L2 transfer.`;
1074
+ }
1075
+ function buildWithdrawMessage(from, toL1Address, amount, nonce) {
1076
+ return `Zelana L2 Withdrawal
1077
+
1078
+ From: ${bytesToHex2(from)}
1079
+ To L1: ${bytesToBase58(toL1Address)}
1080
+ Amount: ${amount.toString()} lamports
1081
+ Nonce: ${nonce.toString()}
1082
+
1083
+ Sign to authorize this withdrawal to Solana L1.`;
1084
+ }
1033
1085
  etc.sha512Sync = (...m) => sha5122(etc.concatBytes(...m));
1034
1086
 
1035
1087
  class Keypair {
@@ -1040,7 +1092,7 @@ class Keypair {
1040
1092
  this._publicKey = publicKey;
1041
1093
  }
1042
1094
  static generate() {
1043
- const secretKey = randomBytes2(32);
1095
+ const secretKey = randomBytes3(32);
1044
1096
  const publicKey = getPublicKey(secretKey);
1045
1097
  return new Keypair(secretKey, publicKey);
1046
1098
  }
@@ -1086,7 +1138,8 @@ class Keypair {
1086
1138
  }
1087
1139
  }
1088
1140
  async signTransfer(to, amount, nonce, chainId = BigInt(1)) {
1089
- const message = concatBytes2(this._publicKey, to, u64ToLeBytes(amount), u64ToLeBytes(nonce), u64ToLeBytes(chainId));
1141
+ const messageText = buildTransferMessage(this._publicKey, to, amount, nonce, chainId);
1142
+ const message = new TextEncoder().encode(messageText);
1090
1143
  const signature = await this.sign(message);
1091
1144
  return {
1092
1145
  from: this.publicKey,
@@ -1099,7 +1152,8 @@ class Keypair {
1099
1152
  };
1100
1153
  }
1101
1154
  async signWithdrawal(toL1Address, amount, nonce) {
1102
- const message = concatBytes2(this._publicKey, toL1Address, u64ToLeBytes(amount), u64ToLeBytes(nonce));
1155
+ const messageText = buildWithdrawMessage(this._publicKey, toL1Address, amount, nonce);
1156
+ const message = new TextEncoder().encode(messageText);
1103
1157
  const signature = await this.sign(message);
1104
1158
  return {
1105
1159
  from: this.publicKey,
@@ -1329,7 +1383,8 @@ class ApiClient {
1329
1383
  nullifier: Array.from(request.nullifier),
1330
1384
  commitment: Array.from(request.commitment),
1331
1385
  ciphertext: Array.from(request.ciphertext),
1332
- ephemeral_key: Array.from(request.ephemeralKey)
1386
+ ephemeral_key: Array.from(request.ephemeralKey),
1387
+ nonce: request.nonce ? Array.from(request.nonce) : undefined
1333
1388
  });
1334
1389
  return {
1335
1390
  txHash: resp.tx_hash,
@@ -1358,6 +1413,7 @@ class ApiClient {
1358
1413
  position: n.position,
1359
1414
  commitment: n.commitment,
1360
1415
  value: BigInt(n.value),
1416
+ blinding: n.blinding,
1361
1417
  memo: n.memo
1362
1418
  })),
1363
1419
  scannedTo: resp.scanned_to
@@ -1628,9 +1684,1471 @@ class ZelanaClient {
1628
1684
  function sleep(ms) {
1629
1685
  return new Promise((resolve) => setTimeout(resolve, ms));
1630
1686
  }
1687
+ // node_modules/@noble/curves/node_modules/@noble/hashes/utils.js
1688
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1689
+ function isBytes3(a) {
1690
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
1691
+ }
1692
+ function anumber2(n, title = "") {
1693
+ if (!Number.isSafeInteger(n) || n < 0) {
1694
+ const prefix = title && `"${title}" `;
1695
+ throw new Error(`${prefix}expected integer >= 0, got ${n}`);
1696
+ }
1697
+ }
1698
+ function abytes3(value, length, title = "") {
1699
+ const bytes = isBytes3(value);
1700
+ const len = value?.length;
1701
+ const needsLen = length !== undefined;
1702
+ if (!bytes || needsLen && len !== length) {
1703
+ const prefix = title && `"${title}" `;
1704
+ const ofLen = needsLen ? ` of length ${length}` : "";
1705
+ const got = bytes ? `length=${len}` : `type=${typeof value}`;
1706
+ throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
1707
+ }
1708
+ return value;
1709
+ }
1710
+ var hasHexBuiltin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function")();
1711
+ var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
1712
+ function bytesToHex3(bytes) {
1713
+ abytes3(bytes);
1714
+ if (hasHexBuiltin)
1715
+ return bytes.toHex();
1716
+ let hex = "";
1717
+ for (let i = 0;i < bytes.length; i++) {
1718
+ hex += hexes[bytes[i]];
1719
+ }
1720
+ return hex;
1721
+ }
1722
+ var asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
1723
+ function asciiToBase16(ch) {
1724
+ if (ch >= asciis._0 && ch <= asciis._9)
1725
+ return ch - asciis._0;
1726
+ if (ch >= asciis.A && ch <= asciis.F)
1727
+ return ch - (asciis.A - 10);
1728
+ if (ch >= asciis.a && ch <= asciis.f)
1729
+ return ch - (asciis.a - 10);
1730
+ return;
1731
+ }
1732
+ function hexToBytes4(hex) {
1733
+ if (typeof hex !== "string")
1734
+ throw new Error("hex string expected, got " + typeof hex);
1735
+ if (hasHexBuiltin)
1736
+ return Uint8Array.fromHex(hex);
1737
+ const hl = hex.length;
1738
+ const al = hl / 2;
1739
+ if (hl % 2)
1740
+ throw new Error("hex string expected, got unpadded hex of length " + hl);
1741
+ const array = new Uint8Array(al);
1742
+ for (let ai = 0, hi = 0;ai < al; ai++, hi += 2) {
1743
+ const n1 = asciiToBase16(hex.charCodeAt(hi));
1744
+ const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
1745
+ if (n1 === undefined || n2 === undefined) {
1746
+ const char = hex[hi] + hex[hi + 1];
1747
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
1748
+ }
1749
+ array[ai] = n1 * 16 + n2;
1750
+ }
1751
+ return array;
1752
+ }
1753
+ function randomBytes4(bytesLength = 32) {
1754
+ const cr2 = typeof globalThis === "object" ? globalThis.crypto : null;
1755
+ if (typeof cr2?.getRandomValues !== "function")
1756
+ throw new Error("crypto.getRandomValues must be defined");
1757
+ return cr2.getRandomValues(new Uint8Array(bytesLength));
1758
+ }
1759
+
1760
+ // node_modules/@noble/curves/utils.js
1761
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1762
+ var _0n = /* @__PURE__ */ BigInt(0);
1763
+ function abignumber(n) {
1764
+ if (typeof n === "bigint") {
1765
+ if (!isPosBig(n))
1766
+ throw new Error("positive bigint expected, got " + n);
1767
+ } else
1768
+ anumber2(n);
1769
+ return n;
1770
+ }
1771
+ function hexToNumber(hex) {
1772
+ if (typeof hex !== "string")
1773
+ throw new Error("hex string expected, got " + typeof hex);
1774
+ return hex === "" ? _0n : BigInt("0x" + hex);
1775
+ }
1776
+ function bytesToNumberLE(bytes) {
1777
+ return hexToNumber(bytesToHex3(copyBytes(abytes3(bytes)).reverse()));
1778
+ }
1779
+ function numberToBytesBE(n, len) {
1780
+ anumber2(len);
1781
+ n = abignumber(n);
1782
+ const res = hexToBytes4(n.toString(16).padStart(len * 2, "0"));
1783
+ if (res.length !== len)
1784
+ throw new Error("number too large");
1785
+ return res;
1786
+ }
1787
+ function numberToBytesLE(n, len) {
1788
+ return numberToBytesBE(n, len).reverse();
1789
+ }
1790
+ function copyBytes(bytes) {
1791
+ return Uint8Array.from(bytes);
1792
+ }
1793
+ var isPosBig = (n) => typeof n === "bigint" && _0n <= n;
1794
+ function inRange(n, min, max) {
1795
+ return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
1796
+ }
1797
+ function aInRange(title, n, min, max) {
1798
+ if (!inRange(n, min, max))
1799
+ throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
1800
+ }
1801
+ function validateObject(object, fields = {}, optFields = {}) {
1802
+ if (!object || typeof object !== "object")
1803
+ throw new Error("expected valid options object");
1804
+ function checkField(fieldName, expectedType, isOpt) {
1805
+ const val = object[fieldName];
1806
+ if (isOpt && val === undefined)
1807
+ return;
1808
+ const current = typeof val;
1809
+ if (current !== expectedType || val === null)
1810
+ throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
1811
+ }
1812
+ const iter = (f, isOpt) => Object.entries(f).forEach(([k, v]) => checkField(k, v, isOpt));
1813
+ iter(fields, false);
1814
+ iter(optFields, true);
1815
+ }
1816
+
1817
+ // node_modules/@noble/curves/abstract/modular.js
1818
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1819
+ var _0n2 = /* @__PURE__ */ BigInt(0);
1820
+ function mod(a, b) {
1821
+ const result = a % b;
1822
+ return result >= _0n2 ? result : b + result;
1823
+ }
1824
+ function pow22(x, power, modulo) {
1825
+ let res = x;
1826
+ while (power-- > _0n2) {
1827
+ res *= res;
1828
+ res %= modulo;
1829
+ }
1830
+ return res;
1831
+ }
1832
+
1833
+ // node_modules/@noble/curves/abstract/curve.js
1834
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1835
+ var pointPrecomputes = new WeakMap;
1836
+ var pointWindowSizes = new WeakMap;
1837
+ function createKeygen(randomSecretKey, getPublicKey2) {
1838
+ return function keygen(seed) {
1839
+ const secretKey = randomSecretKey(seed);
1840
+ return { secretKey, publicKey: getPublicKey2(secretKey) };
1841
+ };
1842
+ }
1843
+
1844
+ // node_modules/@noble/curves/abstract/montgomery.js
1845
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1846
+ var _0n3 = BigInt(0);
1847
+ var _1n = BigInt(1);
1848
+ var _2n = BigInt(2);
1849
+ function validateOpts(curve) {
1850
+ validateObject(curve, {
1851
+ adjustScalarBytes: "function",
1852
+ powPminus2: "function"
1853
+ });
1854
+ return Object.freeze({ ...curve });
1855
+ }
1856
+ function montgomery(curveDef) {
1857
+ const CURVE = validateOpts(curveDef);
1858
+ const { P: P2, type, adjustScalarBytes, powPminus2, randomBytes: rand } = CURVE;
1859
+ const is25519 = type === "x25519";
1860
+ if (!is25519 && type !== "x448")
1861
+ throw new Error("invalid type");
1862
+ const randomBytes_ = rand || randomBytes4;
1863
+ const montgomeryBits = is25519 ? 255 : 448;
1864
+ const fieldLen = is25519 ? 32 : 56;
1865
+ const Gu = is25519 ? BigInt(9) : BigInt(5);
1866
+ const a24 = is25519 ? BigInt(121665) : BigInt(39081);
1867
+ const minScalar = is25519 ? _2n ** BigInt(254) : _2n ** BigInt(447);
1868
+ const maxAdded = is25519 ? BigInt(8) * _2n ** BigInt(251) - _1n : BigInt(4) * _2n ** BigInt(445) - _1n;
1869
+ const maxScalar = minScalar + maxAdded + _1n;
1870
+ const modP = (n) => mod(n, P2);
1871
+ const GuBytes = encodeU(Gu);
1872
+ function encodeU(u) {
1873
+ return numberToBytesLE(modP(u), fieldLen);
1874
+ }
1875
+ function decodeU(u) {
1876
+ const _u = copyBytes(abytes3(u, fieldLen, "uCoordinate"));
1877
+ if (is25519)
1878
+ _u[31] &= 127;
1879
+ return modP(bytesToNumberLE(_u));
1880
+ }
1881
+ function decodeScalar(scalar) {
1882
+ return bytesToNumberLE(adjustScalarBytes(copyBytes(abytes3(scalar, fieldLen, "scalar"))));
1883
+ }
1884
+ function scalarMult(scalar, u) {
1885
+ const pu = montgomeryLadder(decodeU(u), decodeScalar(scalar));
1886
+ if (pu === _0n3)
1887
+ throw new Error("invalid private or public key received");
1888
+ return encodeU(pu);
1889
+ }
1890
+ function scalarMultBase(scalar) {
1891
+ return scalarMult(scalar, GuBytes);
1892
+ }
1893
+ const getPublicKey2 = scalarMultBase;
1894
+ const getSharedSecret = scalarMult;
1895
+ function cswap(swap, x_2, x_3) {
1896
+ const dummy = modP(swap * (x_2 - x_3));
1897
+ x_2 = modP(x_2 - dummy);
1898
+ x_3 = modP(x_3 + dummy);
1899
+ return { x_2, x_3 };
1900
+ }
1901
+ function montgomeryLadder(u, scalar) {
1902
+ aInRange("u", u, _0n3, P2);
1903
+ aInRange("scalar", scalar, minScalar, maxScalar);
1904
+ const k = scalar;
1905
+ const x_1 = u;
1906
+ let x_2 = _1n;
1907
+ let z_2 = _0n3;
1908
+ let x_3 = u;
1909
+ let z_3 = _1n;
1910
+ let swap = _0n3;
1911
+ for (let t = BigInt(montgomeryBits - 1);t >= _0n3; t--) {
1912
+ const k_t = k >> t & _1n;
1913
+ swap ^= k_t;
1914
+ ({ x_2, x_3 } = cswap(swap, x_2, x_3));
1915
+ ({ x_2: z_2, x_3: z_3 } = cswap(swap, z_2, z_3));
1916
+ swap = k_t;
1917
+ const A = x_2 + z_2;
1918
+ const AA = modP(A * A);
1919
+ const B = x_2 - z_2;
1920
+ const BB = modP(B * B);
1921
+ const E = AA - BB;
1922
+ const C2 = x_3 + z_3;
1923
+ const D = x_3 - z_3;
1924
+ const DA = modP(D * A);
1925
+ const CB = modP(C2 * B);
1926
+ const dacb = DA + CB;
1927
+ const da_cb = DA - CB;
1928
+ x_3 = modP(dacb * dacb);
1929
+ z_3 = modP(x_1 * modP(da_cb * da_cb));
1930
+ x_2 = modP(AA * BB);
1931
+ z_2 = modP(E * (AA + modP(a24 * E)));
1932
+ }
1933
+ ({ x_2, x_3 } = cswap(swap, x_2, x_3));
1934
+ ({ x_2: z_2, x_3: z_3 } = cswap(swap, z_2, z_3));
1935
+ const z2 = powPminus2(z_2);
1936
+ return modP(x_2 * z2);
1937
+ }
1938
+ const lengths = {
1939
+ secretKey: fieldLen,
1940
+ publicKey: fieldLen,
1941
+ seed: fieldLen
1942
+ };
1943
+ const randomSecretKey = (seed = randomBytes_(fieldLen)) => {
1944
+ abytes3(seed, lengths.seed, "seed");
1945
+ return seed;
1946
+ };
1947
+ const utils = { randomSecretKey };
1948
+ return Object.freeze({
1949
+ keygen: createKeygen(randomSecretKey, getPublicKey2),
1950
+ getSharedSecret,
1951
+ getPublicKey: getPublicKey2,
1952
+ scalarMult,
1953
+ scalarMultBase,
1954
+ utils,
1955
+ GuBytes: GuBytes.slice(),
1956
+ lengths
1957
+ });
1958
+ }
1959
+
1960
+ // node_modules/@noble/curves/ed25519.js
1961
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1962
+ var _1n2 = BigInt(1);
1963
+ var _2n2 = BigInt(2);
1964
+ var _3n = /* @__PURE__ */ BigInt(3);
1965
+ var _5n = BigInt(5);
1966
+ var _8n = BigInt(8);
1967
+ var ed25519_CURVE_p = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed");
1968
+ function ed25519_pow_2_252_3(x) {
1969
+ const _10n = BigInt(10), _20n = BigInt(20), _40n = BigInt(40), _80n = BigInt(80);
1970
+ const P2 = ed25519_CURVE_p;
1971
+ const x2 = x * x % P2;
1972
+ const b2 = x2 * x % P2;
1973
+ const b4 = pow22(b2, _2n2, P2) * b2 % P2;
1974
+ const b5 = pow22(b4, _1n2, P2) * x % P2;
1975
+ const b10 = pow22(b5, _5n, P2) * b5 % P2;
1976
+ const b20 = pow22(b10, _10n, P2) * b10 % P2;
1977
+ const b40 = pow22(b20, _20n, P2) * b20 % P2;
1978
+ const b80 = pow22(b40, _40n, P2) * b40 % P2;
1979
+ const b160 = pow22(b80, _80n, P2) * b80 % P2;
1980
+ const b240 = pow22(b160, _80n, P2) * b80 % P2;
1981
+ const b250 = pow22(b240, _10n, P2) * b10 % P2;
1982
+ const pow_p_5_8 = pow22(b250, _2n2, P2) * x % P2;
1983
+ return { pow_p_5_8, b2 };
1984
+ }
1985
+ function adjustScalarBytes(bytes) {
1986
+ bytes[0] &= 248;
1987
+ bytes[31] &= 127;
1988
+ bytes[31] |= 64;
1989
+ return bytes;
1990
+ }
1991
+ var x25519 = /* @__PURE__ */ (() => {
1992
+ const P2 = ed25519_CURVE_p;
1993
+ return montgomery({
1994
+ P: P2,
1995
+ type: "x25519",
1996
+ powPminus2: (x) => {
1997
+ const { pow_p_5_8, b2 } = ed25519_pow_2_252_3(x);
1998
+ return mod(pow22(pow_p_5_8, _3n, P2) * b2, P2);
1999
+ },
2000
+ adjustScalarBytes
2001
+ });
2002
+ })();
2003
+
2004
+ // node_modules/@noble/ciphers/utils.js
2005
+ /*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
2006
+ function isBytes4(a) {
2007
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
2008
+ }
2009
+ function abool(b) {
2010
+ if (typeof b !== "boolean")
2011
+ throw new Error(`boolean expected, not ${b}`);
2012
+ }
2013
+ function anumber3(n) {
2014
+ if (!Number.isSafeInteger(n) || n < 0)
2015
+ throw new Error("positive integer expected, got " + n);
2016
+ }
2017
+ function abytes4(value, length, title = "") {
2018
+ const bytes = isBytes4(value);
2019
+ const len = value?.length;
2020
+ const needsLen = length !== undefined;
2021
+ if (!bytes || needsLen && len !== length) {
2022
+ const prefix = title && `"${title}" `;
2023
+ const ofLen = needsLen ? ` of length ${length}` : "";
2024
+ const got = bytes ? `length=${len}` : `type=${typeof value}`;
2025
+ throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
2026
+ }
2027
+ return value;
2028
+ }
2029
+ function aexists2(instance, checkFinished = true) {
2030
+ if (instance.destroyed)
2031
+ throw new Error("Hash instance has been destroyed");
2032
+ if (checkFinished && instance.finished)
2033
+ throw new Error("Hash#digest() has already been called");
2034
+ }
2035
+ function aoutput2(out, instance) {
2036
+ abytes4(out, undefined, "output");
2037
+ const min = instance.outputLen;
2038
+ if (out.length < min) {
2039
+ throw new Error("digestInto() expects output buffer of length at least " + min);
2040
+ }
2041
+ }
2042
+ function u322(arr) {
2043
+ return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
2044
+ }
2045
+ function clean2(...arrays) {
2046
+ for (let i = 0;i < arrays.length; i++) {
2047
+ arrays[i].fill(0);
2048
+ }
2049
+ }
2050
+ function createView2(arr) {
2051
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
2052
+ }
2053
+ var isLE2 = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
2054
+ function checkOpts(defaults, opts) {
2055
+ if (opts == null || typeof opts !== "object")
2056
+ throw new Error("options must be defined");
2057
+ const merged = Object.assign(defaults, opts);
2058
+ return merged;
2059
+ }
2060
+ function equalBytes(a, b) {
2061
+ if (a.length !== b.length)
2062
+ return false;
2063
+ let diff = 0;
2064
+ for (let i = 0;i < a.length; i++)
2065
+ diff |= a[i] ^ b[i];
2066
+ return diff === 0;
2067
+ }
2068
+ var wrapCipher = (params, constructor) => {
2069
+ function wrappedCipher(key, ...args) {
2070
+ abytes4(key, undefined, "key");
2071
+ if (!isLE2)
2072
+ throw new Error("Non little-endian hardware is not yet supported");
2073
+ if (params.nonceLength !== undefined) {
2074
+ const nonce = args[0];
2075
+ abytes4(nonce, params.varSizeNonce ? undefined : params.nonceLength, "nonce");
2076
+ }
2077
+ const tagl = params.tagLength;
2078
+ if (tagl && args[1] !== undefined)
2079
+ abytes4(args[1], undefined, "AAD");
2080
+ const cipher = constructor(key, ...args);
2081
+ const checkOutput = (fnLength, output) => {
2082
+ if (output !== undefined) {
2083
+ if (fnLength !== 2)
2084
+ throw new Error("cipher output not supported");
2085
+ abytes4(output, undefined, "output");
2086
+ }
2087
+ };
2088
+ let called = false;
2089
+ const wrCipher = {
2090
+ encrypt(data, output) {
2091
+ if (called)
2092
+ throw new Error("cannot encrypt() twice with same key + nonce");
2093
+ called = true;
2094
+ abytes4(data);
2095
+ checkOutput(cipher.encrypt.length, output);
2096
+ return cipher.encrypt(data, output);
2097
+ },
2098
+ decrypt(data, output) {
2099
+ abytes4(data);
2100
+ if (tagl && data.length < tagl)
2101
+ throw new Error('"ciphertext" expected length bigger than tagLength=' + tagl);
2102
+ checkOutput(cipher.decrypt.length, output);
2103
+ return cipher.decrypt(data, output);
2104
+ }
2105
+ };
2106
+ return wrCipher;
2107
+ }
2108
+ Object.assign(wrappedCipher, params);
2109
+ return wrappedCipher;
2110
+ };
2111
+ function getOutput(expectedLength, out, onlyAligned = true) {
2112
+ if (out === undefined)
2113
+ return new Uint8Array(expectedLength);
2114
+ if (out.length !== expectedLength)
2115
+ throw new Error('"output" expected Uint8Array of length ' + expectedLength + ", got: " + out.length);
2116
+ if (onlyAligned && !isAligned32(out))
2117
+ throw new Error("invalid output, must be aligned");
2118
+ return out;
2119
+ }
2120
+ function u64Lengths(dataLength, aadLength, isLE3) {
2121
+ abool(isLE3);
2122
+ const num = new Uint8Array(16);
2123
+ const view = createView2(num);
2124
+ view.setBigUint64(0, BigInt(aadLength), isLE3);
2125
+ view.setBigUint64(8, BigInt(dataLength), isLE3);
2126
+ return num;
2127
+ }
2128
+ function isAligned32(bytes) {
2129
+ return bytes.byteOffset % 4 === 0;
2130
+ }
2131
+ function copyBytes2(bytes) {
2132
+ return Uint8Array.from(bytes);
2133
+ }
2134
+
2135
+ // node_modules/@noble/ciphers/_arx.js
2136
+ var encodeStr = (str) => Uint8Array.from(str.split(""), (c) => c.charCodeAt(0));
2137
+ var sigma16 = encodeStr("expand 16-byte k");
2138
+ var sigma32 = encodeStr("expand 32-byte k");
2139
+ var sigma16_32 = u322(sigma16);
2140
+ var sigma32_32 = u322(sigma32);
2141
+ function rotl(a, b) {
2142
+ return a << b | a >>> 32 - b;
2143
+ }
2144
+ function isAligned322(b) {
2145
+ return b.byteOffset % 4 === 0;
2146
+ }
2147
+ var BLOCK_LEN = 64;
2148
+ var BLOCK_LEN32 = 16;
2149
+ var MAX_COUNTER = 2 ** 32 - 1;
2150
+ var U32_EMPTY = Uint32Array.of();
2151
+ function runCipher(core, sigma, key, nonce, data, output, counter, rounds) {
2152
+ const len = data.length;
2153
+ const block = new Uint8Array(BLOCK_LEN);
2154
+ const b32 = u322(block);
2155
+ const isAligned = isAligned322(data) && isAligned322(output);
2156
+ const d32 = isAligned ? u322(data) : U32_EMPTY;
2157
+ const o32 = isAligned ? u322(output) : U32_EMPTY;
2158
+ for (let pos = 0;pos < len; counter++) {
2159
+ core(sigma, key, nonce, b32, counter, rounds);
2160
+ if (counter >= MAX_COUNTER)
2161
+ throw new Error("arx: counter overflow");
2162
+ const take = Math.min(BLOCK_LEN, len - pos);
2163
+ if (isAligned && take === BLOCK_LEN) {
2164
+ const pos32 = pos / 4;
2165
+ if (pos % 4 !== 0)
2166
+ throw new Error("arx: invalid block position");
2167
+ for (let j = 0, posj;j < BLOCK_LEN32; j++) {
2168
+ posj = pos32 + j;
2169
+ o32[posj] = d32[posj] ^ b32[j];
2170
+ }
2171
+ pos += BLOCK_LEN;
2172
+ continue;
2173
+ }
2174
+ for (let j = 0, posj;j < take; j++) {
2175
+ posj = pos + j;
2176
+ output[posj] = data[posj] ^ block[j];
2177
+ }
2178
+ pos += take;
2179
+ }
2180
+ }
2181
+ function createCipher(core, opts) {
2182
+ const { allowShortKeys, extendNonceFn, counterLength, counterRight, rounds } = checkOpts({ allowShortKeys: false, counterLength: 8, counterRight: false, rounds: 20 }, opts);
2183
+ if (typeof core !== "function")
2184
+ throw new Error("core must be a function");
2185
+ anumber3(counterLength);
2186
+ anumber3(rounds);
2187
+ abool(counterRight);
2188
+ abool(allowShortKeys);
2189
+ return (key, nonce, data, output, counter = 0) => {
2190
+ abytes4(key, undefined, "key");
2191
+ abytes4(nonce, undefined, "nonce");
2192
+ abytes4(data, undefined, "data");
2193
+ const len = data.length;
2194
+ if (output === undefined)
2195
+ output = new Uint8Array(len);
2196
+ abytes4(output, undefined, "output");
2197
+ anumber3(counter);
2198
+ if (counter < 0 || counter >= MAX_COUNTER)
2199
+ throw new Error("arx: counter overflow");
2200
+ if (output.length < len)
2201
+ throw new Error(`arx: output (${output.length}) is shorter than data (${len})`);
2202
+ const toClean = [];
2203
+ let l = key.length;
2204
+ let k;
2205
+ let sigma;
2206
+ if (l === 32) {
2207
+ toClean.push(k = copyBytes2(key));
2208
+ sigma = sigma32_32;
2209
+ } else if (l === 16 && allowShortKeys) {
2210
+ k = new Uint8Array(32);
2211
+ k.set(key);
2212
+ k.set(key, 16);
2213
+ sigma = sigma16_32;
2214
+ toClean.push(k);
2215
+ } else {
2216
+ abytes4(key, 32, "arx key");
2217
+ throw new Error("invalid key size");
2218
+ }
2219
+ if (!isAligned322(nonce))
2220
+ toClean.push(nonce = copyBytes2(nonce));
2221
+ const k32 = u322(k);
2222
+ if (extendNonceFn) {
2223
+ if (nonce.length !== 24)
2224
+ throw new Error(`arx: extended nonce must be 24 bytes`);
2225
+ extendNonceFn(sigma, k32, u322(nonce.subarray(0, 16)), k32);
2226
+ nonce = nonce.subarray(16);
2227
+ }
2228
+ const nonceNcLen = 16 - counterLength;
2229
+ if (nonceNcLen !== nonce.length)
2230
+ throw new Error(`arx: nonce must be ${nonceNcLen} or 16 bytes`);
2231
+ if (nonceNcLen !== 12) {
2232
+ const nc = new Uint8Array(12);
2233
+ nc.set(nonce, counterRight ? 0 : 12 - nonce.length);
2234
+ nonce = nc;
2235
+ toClean.push(nonce);
2236
+ }
2237
+ const n32 = u322(nonce);
2238
+ runCipher(core, sigma, k32, n32, data, output, counter, rounds);
2239
+ clean2(...toClean);
2240
+ return output;
2241
+ };
2242
+ }
2243
+
2244
+ // node_modules/@noble/ciphers/_poly1305.js
2245
+ function u8to16(a, i) {
2246
+ return a[i++] & 255 | (a[i++] & 255) << 8;
2247
+ }
2248
+ class Poly1305 {
2249
+ blockLen = 16;
2250
+ outputLen = 16;
2251
+ buffer = new Uint8Array(16);
2252
+ r = new Uint16Array(10);
2253
+ h = new Uint16Array(10);
2254
+ pad = new Uint16Array(8);
2255
+ pos = 0;
2256
+ finished = false;
2257
+ constructor(key) {
2258
+ key = copyBytes2(abytes4(key, 32, "key"));
2259
+ const t0 = u8to16(key, 0);
2260
+ const t1 = u8to16(key, 2);
2261
+ const t2 = u8to16(key, 4);
2262
+ const t3 = u8to16(key, 6);
2263
+ const t4 = u8to16(key, 8);
2264
+ const t5 = u8to16(key, 10);
2265
+ const t6 = u8to16(key, 12);
2266
+ const t7 = u8to16(key, 14);
2267
+ this.r[0] = t0 & 8191;
2268
+ this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
2269
+ this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
2270
+ this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
2271
+ this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
2272
+ this.r[5] = t4 >>> 1 & 8190;
2273
+ this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
2274
+ this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
2275
+ this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
2276
+ this.r[9] = t7 >>> 5 & 127;
2277
+ for (let i = 0;i < 8; i++)
2278
+ this.pad[i] = u8to16(key, 16 + 2 * i);
2279
+ }
2280
+ process(data, offset, isLast = false) {
2281
+ const hibit = isLast ? 0 : 1 << 11;
2282
+ const { h: h2, r } = this;
2283
+ const r0 = r[0];
2284
+ const r1 = r[1];
2285
+ const r2 = r[2];
2286
+ const r3 = r[3];
2287
+ const r4 = r[4];
2288
+ const r5 = r[5];
2289
+ const r6 = r[6];
2290
+ const r7 = r[7];
2291
+ const r8 = r[8];
2292
+ const r9 = r[9];
2293
+ const t0 = u8to16(data, offset + 0);
2294
+ const t1 = u8to16(data, offset + 2);
2295
+ const t2 = u8to16(data, offset + 4);
2296
+ const t3 = u8to16(data, offset + 6);
2297
+ const t4 = u8to16(data, offset + 8);
2298
+ const t5 = u8to16(data, offset + 10);
2299
+ const t6 = u8to16(data, offset + 12);
2300
+ const t7 = u8to16(data, offset + 14);
2301
+ let h0 = h2[0] + (t0 & 8191);
2302
+ let h1 = h2[1] + ((t0 >>> 13 | t1 << 3) & 8191);
2303
+ let h22 = h2[2] + ((t1 >>> 10 | t2 << 6) & 8191);
2304
+ let h3 = h2[3] + ((t2 >>> 7 | t3 << 9) & 8191);
2305
+ let h4 = h2[4] + ((t3 >>> 4 | t4 << 12) & 8191);
2306
+ let h5 = h2[5] + (t4 >>> 1 & 8191);
2307
+ let h6 = h2[6] + ((t4 >>> 14 | t5 << 2) & 8191);
2308
+ let h7 = h2[7] + ((t5 >>> 11 | t6 << 5) & 8191);
2309
+ let h8 = h2[8] + ((t6 >>> 8 | t7 << 8) & 8191);
2310
+ let h9 = h2[9] + (t7 >>> 5 | hibit);
2311
+ let c = 0;
2312
+ let d0 = c + h0 * r0 + h1 * (5 * r9) + h22 * (5 * r8) + h3 * (5 * r7) + h4 * (5 * r6);
2313
+ c = d0 >>> 13;
2314
+ d0 &= 8191;
2315
+ d0 += h5 * (5 * r5) + h6 * (5 * r4) + h7 * (5 * r3) + h8 * (5 * r2) + h9 * (5 * r1);
2316
+ c += d0 >>> 13;
2317
+ d0 &= 8191;
2318
+ let d1 = c + h0 * r1 + h1 * r0 + h22 * (5 * r9) + h3 * (5 * r8) + h4 * (5 * r7);
2319
+ c = d1 >>> 13;
2320
+ d1 &= 8191;
2321
+ d1 += h5 * (5 * r6) + h6 * (5 * r5) + h7 * (5 * r4) + h8 * (5 * r3) + h9 * (5 * r2);
2322
+ c += d1 >>> 13;
2323
+ d1 &= 8191;
2324
+ let d2 = c + h0 * r2 + h1 * r1 + h22 * r0 + h3 * (5 * r9) + h4 * (5 * r8);
2325
+ c = d2 >>> 13;
2326
+ d2 &= 8191;
2327
+ d2 += h5 * (5 * r7) + h6 * (5 * r6) + h7 * (5 * r5) + h8 * (5 * r4) + h9 * (5 * r3);
2328
+ c += d2 >>> 13;
2329
+ d2 &= 8191;
2330
+ let d3 = c + h0 * r3 + h1 * r2 + h22 * r1 + h3 * r0 + h4 * (5 * r9);
2331
+ c = d3 >>> 13;
2332
+ d3 &= 8191;
2333
+ d3 += h5 * (5 * r8) + h6 * (5 * r7) + h7 * (5 * r6) + h8 * (5 * r5) + h9 * (5 * r4);
2334
+ c += d3 >>> 13;
2335
+ d3 &= 8191;
2336
+ let d4 = c + h0 * r4 + h1 * r3 + h22 * r2 + h3 * r1 + h4 * r0;
2337
+ c = d4 >>> 13;
2338
+ d4 &= 8191;
2339
+ d4 += h5 * (5 * r9) + h6 * (5 * r8) + h7 * (5 * r7) + h8 * (5 * r6) + h9 * (5 * r5);
2340
+ c += d4 >>> 13;
2341
+ d4 &= 8191;
2342
+ let d5 = c + h0 * r5 + h1 * r4 + h22 * r3 + h3 * r2 + h4 * r1;
2343
+ c = d5 >>> 13;
2344
+ d5 &= 8191;
2345
+ d5 += h5 * r0 + h6 * (5 * r9) + h7 * (5 * r8) + h8 * (5 * r7) + h9 * (5 * r6);
2346
+ c += d5 >>> 13;
2347
+ d5 &= 8191;
2348
+ let d6 = c + h0 * r6 + h1 * r5 + h22 * r4 + h3 * r3 + h4 * r2;
2349
+ c = d6 >>> 13;
2350
+ d6 &= 8191;
2351
+ d6 += h5 * r1 + h6 * r0 + h7 * (5 * r9) + h8 * (5 * r8) + h9 * (5 * r7);
2352
+ c += d6 >>> 13;
2353
+ d6 &= 8191;
2354
+ let d7 = c + h0 * r7 + h1 * r6 + h22 * r5 + h3 * r4 + h4 * r3;
2355
+ c = d7 >>> 13;
2356
+ d7 &= 8191;
2357
+ d7 += h5 * r2 + h6 * r1 + h7 * r0 + h8 * (5 * r9) + h9 * (5 * r8);
2358
+ c += d7 >>> 13;
2359
+ d7 &= 8191;
2360
+ let d8 = c + h0 * r8 + h1 * r7 + h22 * r6 + h3 * r5 + h4 * r4;
2361
+ c = d8 >>> 13;
2362
+ d8 &= 8191;
2363
+ d8 += h5 * r3 + h6 * r2 + h7 * r1 + h8 * r0 + h9 * (5 * r9);
2364
+ c += d8 >>> 13;
2365
+ d8 &= 8191;
2366
+ let d9 = c + h0 * r9 + h1 * r8 + h22 * r7 + h3 * r6 + h4 * r5;
2367
+ c = d9 >>> 13;
2368
+ d9 &= 8191;
2369
+ d9 += h5 * r4 + h6 * r3 + h7 * r2 + h8 * r1 + h9 * r0;
2370
+ c += d9 >>> 13;
2371
+ d9 &= 8191;
2372
+ c = (c << 2) + c | 0;
2373
+ c = c + d0 | 0;
2374
+ d0 = c & 8191;
2375
+ c = c >>> 13;
2376
+ d1 += c;
2377
+ h2[0] = d0;
2378
+ h2[1] = d1;
2379
+ h2[2] = d2;
2380
+ h2[3] = d3;
2381
+ h2[4] = d4;
2382
+ h2[5] = d5;
2383
+ h2[6] = d6;
2384
+ h2[7] = d7;
2385
+ h2[8] = d8;
2386
+ h2[9] = d9;
2387
+ }
2388
+ finalize() {
2389
+ const { h: h2, pad } = this;
2390
+ const g = new Uint16Array(10);
2391
+ let c = h2[1] >>> 13;
2392
+ h2[1] &= 8191;
2393
+ for (let i = 2;i < 10; i++) {
2394
+ h2[i] += c;
2395
+ c = h2[i] >>> 13;
2396
+ h2[i] &= 8191;
2397
+ }
2398
+ h2[0] += c * 5;
2399
+ c = h2[0] >>> 13;
2400
+ h2[0] &= 8191;
2401
+ h2[1] += c;
2402
+ c = h2[1] >>> 13;
2403
+ h2[1] &= 8191;
2404
+ h2[2] += c;
2405
+ g[0] = h2[0] + 5;
2406
+ c = g[0] >>> 13;
2407
+ g[0] &= 8191;
2408
+ for (let i = 1;i < 10; i++) {
2409
+ g[i] = h2[i] + c;
2410
+ c = g[i] >>> 13;
2411
+ g[i] &= 8191;
2412
+ }
2413
+ g[9] -= 1 << 13;
2414
+ let mask = (c ^ 1) - 1;
2415
+ for (let i = 0;i < 10; i++)
2416
+ g[i] &= mask;
2417
+ mask = ~mask;
2418
+ for (let i = 0;i < 10; i++)
2419
+ h2[i] = h2[i] & mask | g[i];
2420
+ h2[0] = (h2[0] | h2[1] << 13) & 65535;
2421
+ h2[1] = (h2[1] >>> 3 | h2[2] << 10) & 65535;
2422
+ h2[2] = (h2[2] >>> 6 | h2[3] << 7) & 65535;
2423
+ h2[3] = (h2[3] >>> 9 | h2[4] << 4) & 65535;
2424
+ h2[4] = (h2[4] >>> 12 | h2[5] << 1 | h2[6] << 14) & 65535;
2425
+ h2[5] = (h2[6] >>> 2 | h2[7] << 11) & 65535;
2426
+ h2[6] = (h2[7] >>> 5 | h2[8] << 8) & 65535;
2427
+ h2[7] = (h2[8] >>> 8 | h2[9] << 5) & 65535;
2428
+ let f = h2[0] + pad[0];
2429
+ h2[0] = f & 65535;
2430
+ for (let i = 1;i < 8; i++) {
2431
+ f = (h2[i] + pad[i] | 0) + (f >>> 16) | 0;
2432
+ h2[i] = f & 65535;
2433
+ }
2434
+ clean2(g);
2435
+ }
2436
+ update(data) {
2437
+ aexists2(this);
2438
+ abytes4(data);
2439
+ data = copyBytes2(data);
2440
+ const { buffer, blockLen } = this;
2441
+ const len = data.length;
2442
+ for (let pos = 0;pos < len; ) {
2443
+ const take = Math.min(blockLen - this.pos, len - pos);
2444
+ if (take === blockLen) {
2445
+ for (;blockLen <= len - pos; pos += blockLen)
2446
+ this.process(data, pos);
2447
+ continue;
2448
+ }
2449
+ buffer.set(data.subarray(pos, pos + take), this.pos);
2450
+ this.pos += take;
2451
+ pos += take;
2452
+ if (this.pos === blockLen) {
2453
+ this.process(buffer, 0, false);
2454
+ this.pos = 0;
2455
+ }
2456
+ }
2457
+ return this;
2458
+ }
2459
+ destroy() {
2460
+ clean2(this.h, this.r, this.buffer, this.pad);
2461
+ }
2462
+ digestInto(out) {
2463
+ aexists2(this);
2464
+ aoutput2(out, this);
2465
+ this.finished = true;
2466
+ const { buffer, h: h2 } = this;
2467
+ let { pos } = this;
2468
+ if (pos) {
2469
+ buffer[pos++] = 1;
2470
+ for (;pos < 16; pos++)
2471
+ buffer[pos] = 0;
2472
+ this.process(buffer, 0, true);
2473
+ }
2474
+ this.finalize();
2475
+ let opos = 0;
2476
+ for (let i = 0;i < 8; i++) {
2477
+ out[opos++] = h2[i] >>> 0;
2478
+ out[opos++] = h2[i] >>> 8;
2479
+ }
2480
+ return out;
2481
+ }
2482
+ digest() {
2483
+ const { buffer, outputLen } = this;
2484
+ this.digestInto(buffer);
2485
+ const res = buffer.slice(0, outputLen);
2486
+ this.destroy();
2487
+ return res;
2488
+ }
2489
+ }
2490
+ function wrapConstructorWithKey(hashCons) {
2491
+ const hashC = (msg, key) => hashCons(key).update(msg).digest();
2492
+ const tmp = hashCons(new Uint8Array(32));
2493
+ hashC.outputLen = tmp.outputLen;
2494
+ hashC.blockLen = tmp.blockLen;
2495
+ hashC.create = (key) => hashCons(key);
2496
+ return hashC;
2497
+ }
2498
+ var poly1305 = /* @__PURE__ */ (() => wrapConstructorWithKey((key) => new Poly1305(key)))();
2499
+
2500
+ // node_modules/@noble/ciphers/chacha.js
2501
+ function chachaCore(s, k, n, out, cnt, rounds = 20) {
2502
+ let y00 = s[0], y01 = s[1], y02 = s[2], y03 = s[3], y04 = k[0], y05 = k[1], y06 = k[2], y07 = k[3], y08 = k[4], y09 = k[5], y10 = k[6], y11 = k[7], y12 = cnt, y13 = n[0], y14 = n[1], y15 = n[2];
2503
+ let x00 = y00, x01 = y01, x02 = y02, x03 = y03, x04 = y04, x05 = y05, x06 = y06, x07 = y07, x08 = y08, x09 = y09, x10 = y10, x11 = y11, x12 = y12, x13 = y13, x14 = y14, x15 = y15;
2504
+ for (let r = 0;r < rounds; r += 2) {
2505
+ x00 = x00 + x04 | 0;
2506
+ x12 = rotl(x12 ^ x00, 16);
2507
+ x08 = x08 + x12 | 0;
2508
+ x04 = rotl(x04 ^ x08, 12);
2509
+ x00 = x00 + x04 | 0;
2510
+ x12 = rotl(x12 ^ x00, 8);
2511
+ x08 = x08 + x12 | 0;
2512
+ x04 = rotl(x04 ^ x08, 7);
2513
+ x01 = x01 + x05 | 0;
2514
+ x13 = rotl(x13 ^ x01, 16);
2515
+ x09 = x09 + x13 | 0;
2516
+ x05 = rotl(x05 ^ x09, 12);
2517
+ x01 = x01 + x05 | 0;
2518
+ x13 = rotl(x13 ^ x01, 8);
2519
+ x09 = x09 + x13 | 0;
2520
+ x05 = rotl(x05 ^ x09, 7);
2521
+ x02 = x02 + x06 | 0;
2522
+ x14 = rotl(x14 ^ x02, 16);
2523
+ x10 = x10 + x14 | 0;
2524
+ x06 = rotl(x06 ^ x10, 12);
2525
+ x02 = x02 + x06 | 0;
2526
+ x14 = rotl(x14 ^ x02, 8);
2527
+ x10 = x10 + x14 | 0;
2528
+ x06 = rotl(x06 ^ x10, 7);
2529
+ x03 = x03 + x07 | 0;
2530
+ x15 = rotl(x15 ^ x03, 16);
2531
+ x11 = x11 + x15 | 0;
2532
+ x07 = rotl(x07 ^ x11, 12);
2533
+ x03 = x03 + x07 | 0;
2534
+ x15 = rotl(x15 ^ x03, 8);
2535
+ x11 = x11 + x15 | 0;
2536
+ x07 = rotl(x07 ^ x11, 7);
2537
+ x00 = x00 + x05 | 0;
2538
+ x15 = rotl(x15 ^ x00, 16);
2539
+ x10 = x10 + x15 | 0;
2540
+ x05 = rotl(x05 ^ x10, 12);
2541
+ x00 = x00 + x05 | 0;
2542
+ x15 = rotl(x15 ^ x00, 8);
2543
+ x10 = x10 + x15 | 0;
2544
+ x05 = rotl(x05 ^ x10, 7);
2545
+ x01 = x01 + x06 | 0;
2546
+ x12 = rotl(x12 ^ x01, 16);
2547
+ x11 = x11 + x12 | 0;
2548
+ x06 = rotl(x06 ^ x11, 12);
2549
+ x01 = x01 + x06 | 0;
2550
+ x12 = rotl(x12 ^ x01, 8);
2551
+ x11 = x11 + x12 | 0;
2552
+ x06 = rotl(x06 ^ x11, 7);
2553
+ x02 = x02 + x07 | 0;
2554
+ x13 = rotl(x13 ^ x02, 16);
2555
+ x08 = x08 + x13 | 0;
2556
+ x07 = rotl(x07 ^ x08, 12);
2557
+ x02 = x02 + x07 | 0;
2558
+ x13 = rotl(x13 ^ x02, 8);
2559
+ x08 = x08 + x13 | 0;
2560
+ x07 = rotl(x07 ^ x08, 7);
2561
+ x03 = x03 + x04 | 0;
2562
+ x14 = rotl(x14 ^ x03, 16);
2563
+ x09 = x09 + x14 | 0;
2564
+ x04 = rotl(x04 ^ x09, 12);
2565
+ x03 = x03 + x04 | 0;
2566
+ x14 = rotl(x14 ^ x03, 8);
2567
+ x09 = x09 + x14 | 0;
2568
+ x04 = rotl(x04 ^ x09, 7);
2569
+ }
2570
+ let oi = 0;
2571
+ out[oi++] = y00 + x00 | 0;
2572
+ out[oi++] = y01 + x01 | 0;
2573
+ out[oi++] = y02 + x02 | 0;
2574
+ out[oi++] = y03 + x03 | 0;
2575
+ out[oi++] = y04 + x04 | 0;
2576
+ out[oi++] = y05 + x05 | 0;
2577
+ out[oi++] = y06 + x06 | 0;
2578
+ out[oi++] = y07 + x07 | 0;
2579
+ out[oi++] = y08 + x08 | 0;
2580
+ out[oi++] = y09 + x09 | 0;
2581
+ out[oi++] = y10 + x10 | 0;
2582
+ out[oi++] = y11 + x11 | 0;
2583
+ out[oi++] = y12 + x12 | 0;
2584
+ out[oi++] = y13 + x13 | 0;
2585
+ out[oi++] = y14 + x14 | 0;
2586
+ out[oi++] = y15 + x15 | 0;
2587
+ }
2588
+ function hchacha(s, k, i, out) {
2589
+ let x00 = s[0], x01 = s[1], x02 = s[2], x03 = s[3], x04 = k[0], x05 = k[1], x06 = k[2], x07 = k[3], x08 = k[4], x09 = k[5], x10 = k[6], x11 = k[7], x12 = i[0], x13 = i[1], x14 = i[2], x15 = i[3];
2590
+ for (let r = 0;r < 20; r += 2) {
2591
+ x00 = x00 + x04 | 0;
2592
+ x12 = rotl(x12 ^ x00, 16);
2593
+ x08 = x08 + x12 | 0;
2594
+ x04 = rotl(x04 ^ x08, 12);
2595
+ x00 = x00 + x04 | 0;
2596
+ x12 = rotl(x12 ^ x00, 8);
2597
+ x08 = x08 + x12 | 0;
2598
+ x04 = rotl(x04 ^ x08, 7);
2599
+ x01 = x01 + x05 | 0;
2600
+ x13 = rotl(x13 ^ x01, 16);
2601
+ x09 = x09 + x13 | 0;
2602
+ x05 = rotl(x05 ^ x09, 12);
2603
+ x01 = x01 + x05 | 0;
2604
+ x13 = rotl(x13 ^ x01, 8);
2605
+ x09 = x09 + x13 | 0;
2606
+ x05 = rotl(x05 ^ x09, 7);
2607
+ x02 = x02 + x06 | 0;
2608
+ x14 = rotl(x14 ^ x02, 16);
2609
+ x10 = x10 + x14 | 0;
2610
+ x06 = rotl(x06 ^ x10, 12);
2611
+ x02 = x02 + x06 | 0;
2612
+ x14 = rotl(x14 ^ x02, 8);
2613
+ x10 = x10 + x14 | 0;
2614
+ x06 = rotl(x06 ^ x10, 7);
2615
+ x03 = x03 + x07 | 0;
2616
+ x15 = rotl(x15 ^ x03, 16);
2617
+ x11 = x11 + x15 | 0;
2618
+ x07 = rotl(x07 ^ x11, 12);
2619
+ x03 = x03 + x07 | 0;
2620
+ x15 = rotl(x15 ^ x03, 8);
2621
+ x11 = x11 + x15 | 0;
2622
+ x07 = rotl(x07 ^ x11, 7);
2623
+ x00 = x00 + x05 | 0;
2624
+ x15 = rotl(x15 ^ x00, 16);
2625
+ x10 = x10 + x15 | 0;
2626
+ x05 = rotl(x05 ^ x10, 12);
2627
+ x00 = x00 + x05 | 0;
2628
+ x15 = rotl(x15 ^ x00, 8);
2629
+ x10 = x10 + x15 | 0;
2630
+ x05 = rotl(x05 ^ x10, 7);
2631
+ x01 = x01 + x06 | 0;
2632
+ x12 = rotl(x12 ^ x01, 16);
2633
+ x11 = x11 + x12 | 0;
2634
+ x06 = rotl(x06 ^ x11, 12);
2635
+ x01 = x01 + x06 | 0;
2636
+ x12 = rotl(x12 ^ x01, 8);
2637
+ x11 = x11 + x12 | 0;
2638
+ x06 = rotl(x06 ^ x11, 7);
2639
+ x02 = x02 + x07 | 0;
2640
+ x13 = rotl(x13 ^ x02, 16);
2641
+ x08 = x08 + x13 | 0;
2642
+ x07 = rotl(x07 ^ x08, 12);
2643
+ x02 = x02 + x07 | 0;
2644
+ x13 = rotl(x13 ^ x02, 8);
2645
+ x08 = x08 + x13 | 0;
2646
+ x07 = rotl(x07 ^ x08, 7);
2647
+ x03 = x03 + x04 | 0;
2648
+ x14 = rotl(x14 ^ x03, 16);
2649
+ x09 = x09 + x14 | 0;
2650
+ x04 = rotl(x04 ^ x09, 12);
2651
+ x03 = x03 + x04 | 0;
2652
+ x14 = rotl(x14 ^ x03, 8);
2653
+ x09 = x09 + x14 | 0;
2654
+ x04 = rotl(x04 ^ x09, 7);
2655
+ }
2656
+ let oi = 0;
2657
+ out[oi++] = x00;
2658
+ out[oi++] = x01;
2659
+ out[oi++] = x02;
2660
+ out[oi++] = x03;
2661
+ out[oi++] = x12;
2662
+ out[oi++] = x13;
2663
+ out[oi++] = x14;
2664
+ out[oi++] = x15;
2665
+ }
2666
+ var chacha20 = /* @__PURE__ */ createCipher(chachaCore, {
2667
+ counterRight: false,
2668
+ counterLength: 4,
2669
+ allowShortKeys: false
2670
+ });
2671
+ var xchacha20 = /* @__PURE__ */ createCipher(chachaCore, {
2672
+ counterRight: false,
2673
+ counterLength: 8,
2674
+ extendNonceFn: hchacha,
2675
+ allowShortKeys: false
2676
+ });
2677
+ var ZEROS16 = /* @__PURE__ */ new Uint8Array(16);
2678
+ var updatePadded = (h2, msg) => {
2679
+ h2.update(msg);
2680
+ const leftover = msg.length % 16;
2681
+ if (leftover)
2682
+ h2.update(ZEROS16.subarray(leftover));
2683
+ };
2684
+ var ZEROS32 = /* @__PURE__ */ new Uint8Array(32);
2685
+ function computeTag(fn, key, nonce, ciphertext, AAD) {
2686
+ if (AAD !== undefined)
2687
+ abytes4(AAD, undefined, "AAD");
2688
+ const authKey = fn(key, nonce, ZEROS32);
2689
+ const lengths = u64Lengths(ciphertext.length, AAD ? AAD.length : 0, true);
2690
+ const h2 = poly1305.create(authKey);
2691
+ if (AAD)
2692
+ updatePadded(h2, AAD);
2693
+ updatePadded(h2, ciphertext);
2694
+ h2.update(lengths);
2695
+ const res = h2.digest();
2696
+ clean2(authKey, lengths);
2697
+ return res;
2698
+ }
2699
+ var _poly1305_aead = (xorStream) => (key, nonce, AAD) => {
2700
+ const tagLength = 16;
2701
+ return {
2702
+ encrypt(plaintext, output) {
2703
+ const plength = plaintext.length;
2704
+ output = getOutput(plength + tagLength, output, false);
2705
+ output.set(plaintext);
2706
+ const oPlain = output.subarray(0, -tagLength);
2707
+ xorStream(key, nonce, oPlain, oPlain, 1);
2708
+ const tag = computeTag(xorStream, key, nonce, oPlain, AAD);
2709
+ output.set(tag, plength);
2710
+ clean2(tag);
2711
+ return output;
2712
+ },
2713
+ decrypt(ciphertext, output) {
2714
+ output = getOutput(ciphertext.length - tagLength, output, false);
2715
+ const data = ciphertext.subarray(0, -tagLength);
2716
+ const passedTag = ciphertext.subarray(-tagLength);
2717
+ const tag = computeTag(xorStream, key, nonce, data, AAD);
2718
+ if (!equalBytes(passedTag, tag))
2719
+ throw new Error("invalid tag");
2720
+ output.set(ciphertext.subarray(0, -tagLength));
2721
+ xorStream(key, nonce, output, output, 1);
2722
+ clean2(tag);
2723
+ return output;
2724
+ }
2725
+ };
2726
+ };
2727
+ var chacha20poly1305 = /* @__PURE__ */ wrapCipher({ blockSize: 64, nonceLength: 12, tagLength: 16 }, _poly1305_aead(chacha20));
2728
+ var xchacha20poly1305 = /* @__PURE__ */ wrapCipher({ blockSize: 64, nonceLength: 24, tagLength: 16 }, _poly1305_aead(xchacha20));
2729
+
2730
+ // node_modules/@noble/hashes/esm/_blake.js
2731
+ function G1s(a, b, c, d, x) {
2732
+ a = a + b + x | 0;
2733
+ d = rotr(d ^ a, 16);
2734
+ c = c + d | 0;
2735
+ b = rotr(b ^ c, 12);
2736
+ return { a, b, c, d };
2737
+ }
2738
+ function G2s(a, b, c, d, x) {
2739
+ a = a + b + x | 0;
2740
+ d = rotr(d ^ a, 8);
2741
+ c = c + d | 0;
2742
+ b = rotr(b ^ c, 7);
2743
+ return { a, b, c, d };
2744
+ }
2745
+
2746
+ // node_modules/@noble/hashes/esm/blake2.js
2747
+ class BLAKE2 extends Hash {
2748
+ constructor(blockLen, outputLen) {
2749
+ super();
2750
+ this.finished = false;
2751
+ this.destroyed = false;
2752
+ this.length = 0;
2753
+ this.pos = 0;
2754
+ anumber(blockLen);
2755
+ anumber(outputLen);
2756
+ this.blockLen = blockLen;
2757
+ this.outputLen = outputLen;
2758
+ this.buffer = new Uint8Array(blockLen);
2759
+ this.buffer32 = u32(this.buffer);
2760
+ }
2761
+ update(data) {
2762
+ aexists(this);
2763
+ data = toBytes(data);
2764
+ abytes2(data);
2765
+ const { blockLen, buffer, buffer32 } = this;
2766
+ const len = data.length;
2767
+ const offset = data.byteOffset;
2768
+ const buf = data.buffer;
2769
+ for (let pos = 0;pos < len; ) {
2770
+ if (this.pos === blockLen) {
2771
+ swap32IfBE(buffer32);
2772
+ this.compress(buffer32, 0, false);
2773
+ swap32IfBE(buffer32);
2774
+ this.pos = 0;
2775
+ }
2776
+ const take = Math.min(blockLen - this.pos, len - pos);
2777
+ const dataOffset = offset + pos;
2778
+ if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
2779
+ const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
2780
+ swap32IfBE(data32);
2781
+ for (let pos32 = 0;pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
2782
+ this.length += blockLen;
2783
+ this.compress(data32, pos32, false);
2784
+ }
2785
+ swap32IfBE(data32);
2786
+ continue;
2787
+ }
2788
+ buffer.set(data.subarray(pos, pos + take), this.pos);
2789
+ this.pos += take;
2790
+ this.length += take;
2791
+ pos += take;
2792
+ }
2793
+ return this;
2794
+ }
2795
+ digestInto(out) {
2796
+ aexists(this);
2797
+ aoutput(out, this);
2798
+ const { pos, buffer32 } = this;
2799
+ this.finished = true;
2800
+ clean(this.buffer.subarray(pos));
2801
+ swap32IfBE(buffer32);
2802
+ this.compress(buffer32, 0, true);
2803
+ swap32IfBE(buffer32);
2804
+ const out32 = u32(out);
2805
+ this.get().forEach((v, i) => out32[i] = swap8IfBE(v));
2806
+ }
2807
+ digest() {
2808
+ const { buffer, outputLen } = this;
2809
+ this.digestInto(buffer);
2810
+ const res = buffer.slice(0, outputLen);
2811
+ this.destroy();
2812
+ return res;
2813
+ }
2814
+ _cloneInto(to) {
2815
+ const { buffer, length, finished, destroyed, outputLen, pos } = this;
2816
+ to || (to = new this.constructor({ dkLen: outputLen }));
2817
+ to.set(...this.get());
2818
+ to.buffer.set(buffer);
2819
+ to.destroyed = destroyed;
2820
+ to.finished = finished;
2821
+ to.length = length;
2822
+ to.pos = pos;
2823
+ to.outputLen = outputLen;
2824
+ return to;
2825
+ }
2826
+ clone() {
2827
+ return this._cloneInto();
2828
+ }
2829
+ }
2830
+ function compress(s, offset, msg, rounds, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) {
2831
+ let j = 0;
2832
+ for (let i = 0;i < rounds; i++) {
2833
+ ({ a: v0, b: v4, c: v8, d: v12 } = G1s(v0, v4, v8, v12, msg[offset + s[j++]]));
2834
+ ({ a: v0, b: v4, c: v8, d: v12 } = G2s(v0, v4, v8, v12, msg[offset + s[j++]]));
2835
+ ({ a: v1, b: v5, c: v9, d: v13 } = G1s(v1, v5, v9, v13, msg[offset + s[j++]]));
2836
+ ({ a: v1, b: v5, c: v9, d: v13 } = G2s(v1, v5, v9, v13, msg[offset + s[j++]]));
2837
+ ({ a: v2, b: v6, c: v10, d: v14 } = G1s(v2, v6, v10, v14, msg[offset + s[j++]]));
2838
+ ({ a: v2, b: v6, c: v10, d: v14 } = G2s(v2, v6, v10, v14, msg[offset + s[j++]]));
2839
+ ({ a: v3, b: v7, c: v11, d: v15 } = G1s(v3, v7, v11, v15, msg[offset + s[j++]]));
2840
+ ({ a: v3, b: v7, c: v11, d: v15 } = G2s(v3, v7, v11, v15, msg[offset + s[j++]]));
2841
+ ({ a: v0, b: v5, c: v10, d: v15 } = G1s(v0, v5, v10, v15, msg[offset + s[j++]]));
2842
+ ({ a: v0, b: v5, c: v10, d: v15 } = G2s(v0, v5, v10, v15, msg[offset + s[j++]]));
2843
+ ({ a: v1, b: v6, c: v11, d: v12 } = G1s(v1, v6, v11, v12, msg[offset + s[j++]]));
2844
+ ({ a: v1, b: v6, c: v11, d: v12 } = G2s(v1, v6, v11, v12, msg[offset + s[j++]]));
2845
+ ({ a: v2, b: v7, c: v8, d: v13 } = G1s(v2, v7, v8, v13, msg[offset + s[j++]]));
2846
+ ({ a: v2, b: v7, c: v8, d: v13 } = G2s(v2, v7, v8, v13, msg[offset + s[j++]]));
2847
+ ({ a: v3, b: v4, c: v9, d: v14 } = G1s(v3, v4, v9, v14, msg[offset + s[j++]]));
2848
+ ({ a: v3, b: v4, c: v9, d: v14 } = G2s(v3, v4, v9, v14, msg[offset + s[j++]]));
2849
+ }
2850
+ return { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 };
2851
+ }
2852
+
2853
+ // node_modules/@noble/hashes/esm/blake3.js
2854
+ var B3_Flags = {
2855
+ CHUNK_START: 1,
2856
+ CHUNK_END: 2,
2857
+ PARENT: 4,
2858
+ ROOT: 8,
2859
+ KEYED_HASH: 16,
2860
+ DERIVE_KEY_CONTEXT: 32,
2861
+ DERIVE_KEY_MATERIAL: 64
2862
+ };
2863
+ var B3_IV = SHA256_IV.slice();
2864
+ var B3_SIGMA = /* @__PURE__ */ (() => {
2865
+ const Id = Array.from({ length: 16 }, (_, i) => i);
2866
+ const permute = (arr) => [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8].map((i) => arr[i]);
2867
+ const res = [];
2868
+ for (let i = 0, v = Id;i < 7; i++, v = permute(v))
2869
+ res.push(...v);
2870
+ return Uint8Array.from(res);
2871
+ })();
2872
+
2873
+ class BLAKE3 extends BLAKE2 {
2874
+ constructor(opts = {}, flags = 0) {
2875
+ super(64, opts.dkLen === undefined ? 32 : opts.dkLen);
2876
+ this.chunkPos = 0;
2877
+ this.chunksDone = 0;
2878
+ this.flags = 0 | 0;
2879
+ this.stack = [];
2880
+ this.posOut = 0;
2881
+ this.bufferOut32 = new Uint32Array(16);
2882
+ this.chunkOut = 0;
2883
+ this.enableXOF = true;
2884
+ const { key, context } = opts;
2885
+ const hasContext = context !== undefined;
2886
+ if (key !== undefined) {
2887
+ if (hasContext)
2888
+ throw new Error('Only "key" or "context" can be specified at same time');
2889
+ const k = toBytes(key).slice();
2890
+ abytes2(k, 32);
2891
+ this.IV = u32(k);
2892
+ swap32IfBE(this.IV);
2893
+ this.flags = flags | B3_Flags.KEYED_HASH;
2894
+ } else if (hasContext) {
2895
+ const ctx = toBytes(context);
2896
+ const contextKey = new BLAKE3({ dkLen: 32 }, B3_Flags.DERIVE_KEY_CONTEXT).update(ctx).digest();
2897
+ this.IV = u32(contextKey);
2898
+ swap32IfBE(this.IV);
2899
+ this.flags = flags | B3_Flags.DERIVE_KEY_MATERIAL;
2900
+ } else {
2901
+ this.IV = B3_IV.slice();
2902
+ this.flags = flags;
2903
+ }
2904
+ this.state = this.IV.slice();
2905
+ this.bufferOut = u8(this.bufferOut32);
2906
+ }
2907
+ get() {
2908
+ return [];
2909
+ }
2910
+ set() {}
2911
+ b2Compress(counter, flags, buf, bufPos = 0) {
2912
+ const { state: s, pos } = this;
2913
+ const { h: h2, l } = fromBig(BigInt(counter), true);
2914
+ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(B3_SIGMA, bufPos, buf, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], B3_IV[0], B3_IV[1], B3_IV[2], B3_IV[3], h2, l, pos, flags);
2915
+ s[0] = v0 ^ v8;
2916
+ s[1] = v1 ^ v9;
2917
+ s[2] = v2 ^ v10;
2918
+ s[3] = v3 ^ v11;
2919
+ s[4] = v4 ^ v12;
2920
+ s[5] = v5 ^ v13;
2921
+ s[6] = v6 ^ v14;
2922
+ s[7] = v7 ^ v15;
2923
+ }
2924
+ compress(buf, bufPos = 0, isLast = false) {
2925
+ let flags = this.flags;
2926
+ if (!this.chunkPos)
2927
+ flags |= B3_Flags.CHUNK_START;
2928
+ if (this.chunkPos === 15 || isLast)
2929
+ flags |= B3_Flags.CHUNK_END;
2930
+ if (!isLast)
2931
+ this.pos = this.blockLen;
2932
+ this.b2Compress(this.chunksDone, flags, buf, bufPos);
2933
+ this.chunkPos += 1;
2934
+ if (this.chunkPos === 16 || isLast) {
2935
+ let chunk = this.state;
2936
+ this.state = this.IV.slice();
2937
+ for (let last, chunks = this.chunksDone + 1;isLast || !(chunks & 1); chunks >>= 1) {
2938
+ if (!(last = this.stack.pop()))
2939
+ break;
2940
+ this.buffer32.set(last, 0);
2941
+ this.buffer32.set(chunk, 8);
2942
+ this.pos = this.blockLen;
2943
+ this.b2Compress(0, this.flags | B3_Flags.PARENT, this.buffer32, 0);
2944
+ chunk = this.state;
2945
+ this.state = this.IV.slice();
2946
+ }
2947
+ this.chunksDone++;
2948
+ this.chunkPos = 0;
2949
+ this.stack.push(chunk);
2950
+ }
2951
+ this.pos = 0;
2952
+ }
2953
+ _cloneInto(to) {
2954
+ to = super._cloneInto(to);
2955
+ const { IV, flags, state, chunkPos, posOut, chunkOut, stack, chunksDone } = this;
2956
+ to.state.set(state.slice());
2957
+ to.stack = stack.map((i) => Uint32Array.from(i));
2958
+ to.IV.set(IV);
2959
+ to.flags = flags;
2960
+ to.chunkPos = chunkPos;
2961
+ to.chunksDone = chunksDone;
2962
+ to.posOut = posOut;
2963
+ to.chunkOut = chunkOut;
2964
+ to.enableXOF = this.enableXOF;
2965
+ to.bufferOut32.set(this.bufferOut32);
2966
+ return to;
2967
+ }
2968
+ destroy() {
2969
+ this.destroyed = true;
2970
+ clean(this.state, this.buffer32, this.IV, this.bufferOut32);
2971
+ clean(...this.stack);
2972
+ }
2973
+ b2CompressOut() {
2974
+ const { state: s, pos, flags, buffer32, bufferOut32: out32 } = this;
2975
+ const { h: h2, l } = fromBig(BigInt(this.chunkOut++));
2976
+ swap32IfBE(buffer32);
2977
+ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(B3_SIGMA, 0, buffer32, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], B3_IV[0], B3_IV[1], B3_IV[2], B3_IV[3], l, h2, pos, flags);
2978
+ out32[0] = v0 ^ v8;
2979
+ out32[1] = v1 ^ v9;
2980
+ out32[2] = v2 ^ v10;
2981
+ out32[3] = v3 ^ v11;
2982
+ out32[4] = v4 ^ v12;
2983
+ out32[5] = v5 ^ v13;
2984
+ out32[6] = v6 ^ v14;
2985
+ out32[7] = v7 ^ v15;
2986
+ out32[8] = s[0] ^ v8;
2987
+ out32[9] = s[1] ^ v9;
2988
+ out32[10] = s[2] ^ v10;
2989
+ out32[11] = s[3] ^ v11;
2990
+ out32[12] = s[4] ^ v12;
2991
+ out32[13] = s[5] ^ v13;
2992
+ out32[14] = s[6] ^ v14;
2993
+ out32[15] = s[7] ^ v15;
2994
+ swap32IfBE(buffer32);
2995
+ swap32IfBE(out32);
2996
+ this.posOut = 0;
2997
+ }
2998
+ finish() {
2999
+ if (this.finished)
3000
+ return;
3001
+ this.finished = true;
3002
+ clean(this.buffer.subarray(this.pos));
3003
+ let flags = this.flags | B3_Flags.ROOT;
3004
+ if (this.stack.length) {
3005
+ flags |= B3_Flags.PARENT;
3006
+ swap32IfBE(this.buffer32);
3007
+ this.compress(this.buffer32, 0, true);
3008
+ swap32IfBE(this.buffer32);
3009
+ this.chunksDone = 0;
3010
+ this.pos = this.blockLen;
3011
+ } else {
3012
+ flags |= (!this.chunkPos ? B3_Flags.CHUNK_START : 0) | B3_Flags.CHUNK_END;
3013
+ }
3014
+ this.flags = flags;
3015
+ this.b2CompressOut();
3016
+ }
3017
+ writeInto(out) {
3018
+ aexists(this, false);
3019
+ abytes2(out);
3020
+ this.finish();
3021
+ const { blockLen, bufferOut } = this;
3022
+ for (let pos = 0, len = out.length;pos < len; ) {
3023
+ if (this.posOut >= blockLen)
3024
+ this.b2CompressOut();
3025
+ const take = Math.min(blockLen - this.posOut, len - pos);
3026
+ out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
3027
+ this.posOut += take;
3028
+ pos += take;
3029
+ }
3030
+ return out;
3031
+ }
3032
+ xofInto(out) {
3033
+ if (!this.enableXOF)
3034
+ throw new Error("XOF is not possible after digest call");
3035
+ return this.writeInto(out);
3036
+ }
3037
+ xof(bytes) {
3038
+ anumber(bytes);
3039
+ return this.xofInto(new Uint8Array(bytes));
3040
+ }
3041
+ digestInto(out) {
3042
+ aoutput(out, this);
3043
+ if (this.finished)
3044
+ throw new Error("digest() was already called");
3045
+ this.enableXOF = false;
3046
+ this.writeInto(out);
3047
+ this.destroy();
3048
+ return out;
3049
+ }
3050
+ digest() {
3051
+ return this.digestInto(new Uint8Array(this.outputLen));
3052
+ }
3053
+ }
3054
+ var blake3 = /* @__PURE__ */ createXOFer((opts) => new BLAKE3(opts));
3055
+
3056
+ // src/encryption.ts
3057
+ function deriveNoteKey(sharedSecret, ephemeralPk) {
3058
+ const context = new TextEncoder().encode("zelana-note-v1");
3059
+ const input = new Uint8Array(sharedSecret.length + ephemeralPk.length);
3060
+ input.set(sharedSecret, 0);
3061
+ input.set(ephemeralPk, sharedSecret.length);
3062
+ return blake3(input, { context });
3063
+ }
3064
+ function serializePlaintext(pt) {
3065
+ const memoLen = pt.memo?.length ?? 0;
3066
+ const bytes = new Uint8Array(8 + 32 + 2 + memoLen);
3067
+ const view = new DataView(bytes.buffer);
3068
+ view.setBigUint64(0, pt.value, true);
3069
+ bytes.set(pt.randomness, 8);
3070
+ view.setUint16(40, memoLen, true);
3071
+ if (pt.memo && memoLen > 0) {
3072
+ bytes.set(pt.memo.slice(0, 512), 42);
3073
+ }
3074
+ return bytes;
3075
+ }
3076
+ function deserializePlaintext(bytes) {
3077
+ if (bytes.length < 42) {
3078
+ return null;
3079
+ }
3080
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
3081
+ const value = view.getBigUint64(0, true);
3082
+ const randomness = bytes.slice(8, 40);
3083
+ const memoLen = view.getUint16(40, true);
3084
+ if (bytes.length < 42 + memoLen) {
3085
+ return null;
3086
+ }
3087
+ const memo = memoLen > 0 ? bytes.slice(42, 42 + memoLen) : undefined;
3088
+ return { value, randomness, memo };
3089
+ }
3090
+ function encryptNote(value, randomness, recipientPk, memo) {
3091
+ const ephemeralSk = randomBytes2(32);
3092
+ const ephemeralPk = x25519.getPublicKey(ephemeralSk);
3093
+ const sharedSecret = x25519.getSharedSecret(ephemeralSk, recipientPk);
3094
+ const encryptionKey = deriveNoteKey(sharedSecret, ephemeralPk);
3095
+ const plaintext = serializePlaintext({
3096
+ value,
3097
+ randomness: new Uint8Array(randomness),
3098
+ memo: memo?.slice(0, 512)
3099
+ });
3100
+ const nonce = randomBytes2(12);
3101
+ const cipher = chacha20poly1305(encryptionKey, nonce);
3102
+ const ciphertext = cipher.encrypt(plaintext);
3103
+ return {
3104
+ ephemeralPk,
3105
+ nonce,
3106
+ ciphertext
3107
+ };
3108
+ }
3109
+ function decryptNote(encrypted, recipientSk) {
3110
+ try {
3111
+ const sharedSecret = x25519.getSharedSecret(recipientSk, encrypted.ephemeralPk);
3112
+ const encryptionKey = deriveNoteKey(sharedSecret, encrypted.ephemeralPk);
3113
+ const cipher = chacha20poly1305(encryptionKey, encrypted.nonce);
3114
+ const plaintext = cipher.decrypt(encrypted.ciphertext);
3115
+ const pt = deserializePlaintext(plaintext);
3116
+ if (!pt) {
3117
+ return null;
3118
+ }
3119
+ return {
3120
+ value: pt.value,
3121
+ randomness: pt.randomness,
3122
+ memo: pt.memo
3123
+ };
3124
+ } catch {
3125
+ return null;
3126
+ }
3127
+ }
3128
+ function serializeEncryptedNote(note) {
3129
+ const bytes = new Uint8Array(32 + 12 + note.ciphertext.length);
3130
+ bytes.set(note.ephemeralPk, 0);
3131
+ bytes.set(note.nonce, 32);
3132
+ bytes.set(note.ciphertext, 44);
3133
+ return bytes;
3134
+ }
3135
+ function deserializeEncryptedNote(bytes) {
3136
+ if (bytes.length < 44 + 42 + 16) {
3137
+ return null;
3138
+ }
3139
+ return {
3140
+ ephemeralPk: bytes.slice(0, 32),
3141
+ nonce: bytes.slice(32, 44),
3142
+ ciphertext: bytes.slice(44)
3143
+ };
3144
+ }
3145
+ function x25519PublicKey(secretKey) {
3146
+ return x25519.getPublicKey(secretKey);
3147
+ }
3148
+
1631
3149
  // src/shielded.ts
1632
3150
  function generateShieldedKeys() {
1633
- const spendingKey = randomBytes2(32);
3151
+ const spendingKey = randomBytes3(32);
1634
3152
  const viewingKey = deriveViewingKey(spendingKey);
1635
3153
  const publicKey = derivePublicKey(spendingKey);
1636
3154
  return { spendingKey, viewingKey, publicKey };
@@ -1653,7 +3171,7 @@ function derivePublicKey(spendingKey) {
1653
3171
  function createNote(value, ownerPk, position) {
1654
3172
  return {
1655
3173
  value,
1656
- randomness: randomBytes2(32),
3174
+ randomness: randomBytes3(32),
1657
3175
  ownerPk: new Uint8Array(ownerPk),
1658
3176
  position
1659
3177
  };
@@ -1750,7 +3268,7 @@ class ShieldedTransactionBuilder {
1750
3268
  const commitment = computeCommitment(note);
1751
3269
  return { note, commitment, memo: output.memo };
1752
3270
  });
1753
- const encryptedOutputs = outputsWithCommitments.map((o) => encryptNote(o.note, o.memo));
3271
+ const encryptedOutputs = outputsWithCommitments.map((o) => encryptNote2(o.note, o.note.ownerPk, o.memo));
1754
3272
  return {
1755
3273
  nullifiers: inputsWithNullifiers.map((i) => i.nullifier),
1756
3274
  commitments: outputsWithCommitments.map((o) => o.commitment),
@@ -1772,29 +3290,14 @@ class ShieldedTransactionBuilder {
1772
3290
  return this;
1773
3291
  }
1774
3292
  }
1775
- function encryptNote(note, memo) {
1776
- const ephemeralPk = randomBytes2(32);
1777
- const nonce = randomBytes2(12);
1778
- const plaintext = concatBytes2(u64ToLeBytes(note.value), note.randomness, memo ? new Uint8Array([...u16ToLeBytes(memo.length), ...memo]) : new Uint8Array([0, 0]));
1779
- const key = sha5122(concatBytes2(ephemeralPk, note.ownerPk)).slice(0, 32);
1780
- const ciphertext = xorEncrypt(plaintext, key, nonce);
3293
+ function encryptNote2(note, recipientViewingPk, memo) {
3294
+ const encrypted = encryptNote(note.value, note.randomness, recipientViewingPk, memo);
1781
3295
  return {
1782
- ephemeralPk,
1783
- nonce,
1784
- ciphertext
3296
+ ephemeralPk: encrypted.ephemeralPk,
3297
+ nonce: encrypted.nonce,
3298
+ ciphertext: encrypted.ciphertext
1785
3299
  };
1786
3300
  }
1787
- function xorEncrypt(data, key, nonce) {
1788
- const stream = sha5122(concatBytes2(key, nonce));
1789
- const result = new Uint8Array(data.length);
1790
- for (let i = 0;i < data.length; i++) {
1791
- result[i] = data[i] ^ stream[i % stream.length];
1792
- }
1793
- return result;
1794
- }
1795
- function u16ToLeBytes(value) {
1796
- return new Uint8Array([value & 255, value >> 8 & 255]);
1797
- }
1798
3301
  function tryDecryptNote(encrypted, viewingKey, ownerPk, position) {
1799
3302
  return null;
1800
3303
  }
@@ -1833,18 +3336,19 @@ class OwnershipProver {
1833
3336
  this.initialized = true;
1834
3337
  }
1835
3338
  async loadWasmModule(wasmUrl) {
3339
+ if (wasmUrl) {
3340
+ const importFn = new Function("url", "return import(url)");
3341
+ const module = await importFn(wasmUrl);
3342
+ await module.default();
3343
+ return module;
3344
+ }
1836
3345
  try {
1837
- const module = await import("zelana-ownership-prover");
3346
+ const dynamicImport = new Function("specifier", "return import(specifier)");
3347
+ const module = await dynamicImport("zelana-ownership-prover");
1838
3348
  await module.default();
1839
3349
  return module;
1840
3350
  } catch {
1841
- if (wasmUrl) {
1842
- const importFn = new Function("url", "return import(url)");
1843
- const module = await importFn(wasmUrl);
1844
- await module.default();
1845
- return module;
1846
- }
1847
- throw new Error("Could not load WASM module");
3351
+ throw new Error("Could not load WASM module. Please provide a wasmUrl or install zelana-ownership-prover.");
1848
3352
  }
1849
3353
  }
1850
3354
  async loadNoirCircuit(circuitUrl) {
@@ -1989,17 +3493,22 @@ class MockOwnershipProver extends OwnershipProver {
1989
3493
  }
1990
3494
  var mockProver = new MockOwnershipProver;
1991
3495
  export {
3496
+ x25519PublicKey,
1992
3497
  u64ToLeBytes,
1993
3498
  tryDecryptNote,
1994
3499
  shieldedKeysFromSpendingKey,
1995
3500
  shielded,
1996
- randomBytes2 as randomBytes,
3501
+ serializeEncryptedNote,
3502
+ randomBytes3 as randomBytes,
1997
3503
  noteWithRandomness,
1998
3504
  mockProver,
1999
3505
  leBytesToU64,
2000
3506
  hexToBytes2 as hexToBytes,
2001
3507
  getProver,
2002
3508
  generateShieldedKeys,
3509
+ encryptNote,
3510
+ deserializeEncryptedNote,
3511
+ decryptNote,
2003
3512
  createNote,
2004
3513
  concatBytes2 as concatBytes,
2005
3514
  computeOwnershipWitness,