@zelana/sdk 0.1.3 → 0.1.5

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