nostr-double-ratchet 0.0.34 → 0.0.35

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.
@@ -67,13 +67,13 @@ function Yn(e = 32) {
67
67
  return xt.getRandomValues(new Uint8Array(e));
68
68
  throw new Error("crypto.getRandomValues must be defined");
69
69
  }
70
- function _i(e, t, n, r) {
70
+ function Ui(e, t, n, r) {
71
71
  if (typeof e.setBigUint64 == "function")
72
72
  return e.setBigUint64(t, n, r);
73
73
  const i = BigInt(32), s = BigInt(4294967295), o = Number(n >> i & s), c = Number(n & s), a = r ? 4 : 0, l = r ? 0 : 4;
74
74
  e.setUint32(t + a, o, r), e.setUint32(t + l, c, r);
75
75
  }
76
- let Ui = class extends Jn {
76
+ let _i = class extends Jn {
77
77
  constructor(t, n, r, i) {
78
78
  super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view = Kt(this.buffer);
79
79
  }
@@ -101,7 +101,7 @@ let Ui = class extends Jn {
101
101
  n[o++] = 128, this.buffer.subarray(o).fill(0), this.padOffset > i - o && (this.process(r, 0), o = 0);
102
102
  for (let u = o; u < i; u++)
103
103
  n[u] = 0;
104
- _i(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
104
+ Ui(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
105
105
  const c = Kt(t), a = this.outputLen;
106
106
  if (a % 4)
107
107
  throw new Error("_sha2: outputLen should be aligned to 32bit");
@@ -198,7 +198,7 @@ const Li = (e, t, n) => e & t ^ ~e & n, $i = (e, t, n) => e & t ^ e & n ^ t & n,
198
198
  528734635,
199
199
  1541459225
200
200
  ]), ve = /* @__PURE__ */ new Uint32Array(64);
201
- let Ti = class extends Ui {
201
+ let Ti = class extends _i {
202
202
  constructor() {
203
203
  super(64, 32, 8, !1), this.A = be[0] | 0, this.B = be[1] | 0, this.C = be[2] | 0, this.D = be[3] | 0, this.E = be[4] | 0, this.F = be[5] | 0, this.G = be[6] | 0, this.H = be[7] | 0;
204
204
  }
@@ -214,12 +214,12 @@ let Ti = class extends Ui {
214
214
  for (let u = 0; u < 16; u++, n += 4)
215
215
  ve[u] = t.getUint32(n, !1);
216
216
  for (let u = 16; u < 64; u++) {
217
- const y = ve[u - 15], w = ve[u - 2], g = re(y, 7) ^ re(y, 18) ^ y >>> 3, h = re(w, 17) ^ re(w, 19) ^ w >>> 10;
217
+ const p = ve[u - 15], w = ve[u - 2], g = re(p, 7) ^ re(p, 18) ^ p >>> 3, h = re(w, 17) ^ re(w, 19) ^ w >>> 10;
218
218
  ve[u] = h + ve[u - 7] + g + ve[u - 16] | 0;
219
219
  }
220
220
  let { A: r, B: i, C: s, D: o, E: c, F: a, G: l, H: f } = this;
221
221
  for (let u = 0; u < 64; u++) {
222
- const y = re(c, 6) ^ re(c, 11) ^ re(c, 25), w = f + y + Li(c, a, l) + Ri[u] + ve[u] | 0, h = (re(r, 2) ^ re(r, 13) ^ re(r, 22)) + $i(r, i, s) | 0;
222
+ const p = re(c, 6) ^ re(c, 11) ^ re(c, 25), w = f + p + Li(c, a, l) + Ri[u] + ve[u] | 0, h = (re(r, 2) ^ re(r, 13) ^ re(r, 22)) + $i(r, i, s) | 0;
223
223
  f = l, l = a, a = c, c = o + w | 0, o = s, s = i, i = r, r = w + h | 0;
224
224
  }
225
225
  r = r + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, l = l + this.G | 0, f = f + this.H | 0, this.set(r, i, s, o, c, a, l, f);
@@ -348,18 +348,18 @@ function er(e, t, n) {
348
348
  if (s++ >= 1e3)
349
349
  throw new Error("drbg: tried 1000 values");
350
350
  let u = 0;
351
- const y = [];
351
+ const p = [];
352
352
  for (; u < t; ) {
353
353
  r = c();
354
354
  const w = r.slice();
355
- y.push(w), u += r.length;
355
+ p.push(w), u += r.length;
356
356
  }
357
- return Ie(...y);
357
+ return Ie(...p);
358
358
  };
359
- return (u, y) => {
359
+ return (u, p) => {
360
360
  o(), a(u);
361
361
  let w;
362
- for (; !(w = y(l())); )
362
+ for (; !(w = p(l())); )
363
363
  a();
364
364
  return o(), w;
365
365
  };
@@ -413,7 +413,7 @@ const Vi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
413
413
  validateObject: Ye
414
414
  }, Symbol.toStringTag, { value: "Module" }));
415
415
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
416
- const W = BigInt(0), z = BigInt(1), Ce = BigInt(2), Zi = BigInt(3), Rt = BigInt(4), _n = BigInt(5), Un = BigInt(8);
416
+ const W = BigInt(0), z = BigInt(1), Ce = BigInt(2), Zi = BigInt(3), Rt = BigInt(4), Un = BigInt(5), _n = BigInt(8);
417
417
  BigInt(9);
418
418
  BigInt(16);
419
419
  function V(e, t) {
@@ -468,15 +468,15 @@ function Gi(e) {
468
468
  return function(c, a) {
469
469
  if (c.pow(a, t) === c.neg(c.ONE))
470
470
  throw new Error("Cannot find square root");
471
- let l = r, f = c.pow(c.mul(c.ONE, i), n), u = c.pow(a, s), y = c.pow(a, n);
472
- for (; !c.eql(y, c.ONE); ) {
473
- if (c.eql(y, c.ZERO))
471
+ let l = r, f = c.pow(c.mul(c.ONE, i), n), u = c.pow(a, s), p = c.pow(a, n);
472
+ for (; !c.eql(p, c.ONE); ) {
473
+ if (c.eql(p, c.ZERO))
474
474
  return c.ZERO;
475
475
  let w = 1;
476
- for (let h = c.sqr(y); w < l && !c.eql(h, c.ONE); w++)
476
+ for (let h = c.sqr(p); w < l && !c.eql(h, c.ONE); w++)
477
477
  h = c.sqr(h);
478
478
  const g = c.pow(f, z << BigInt(l - w - 1));
479
- f = c.sqr(g), u = c.mul(u, g), y = c.mul(y, f), l = w;
479
+ f = c.sqr(g), u = c.mul(u, g), p = c.mul(p, f), l = w;
480
480
  }
481
481
  return u;
482
482
  };
@@ -491,8 +491,8 @@ function Ji(e) {
491
491
  return s;
492
492
  };
493
493
  }
494
- if (e % Un === _n) {
495
- const t = (e - _n) / Un;
494
+ if (e % _n === Un) {
495
+ const t = (e - Un) / _n;
496
496
  return function(r, i) {
497
497
  const s = r.mul(i, Ce), o = r.pow(s, t), c = r.mul(i, o), a = r.mul(r.mul(c, Ce), o), l = r.mul(c, r.sub(a, r.ONE));
498
498
  if (!r.eql(r.sqr(l), i))
@@ -650,7 +650,7 @@ function is(e, t) {
650
650
  let l = i, f = l;
651
651
  for (let u = 0; u < o; u++) {
652
652
  f = l, a.push(f);
653
- for (let y = 1; y < c; y++)
653
+ for (let p = 1; p < c; p++)
654
654
  f = f.add(l), a.push(f);
655
655
  l = f.double();
656
656
  }
@@ -666,13 +666,13 @@ function is(e, t) {
666
666
  wNAF(i, s, o) {
667
667
  const { windows: c, windowSize: a } = r(i);
668
668
  let l = e.ZERO, f = e.BASE;
669
- const u = BigInt(2 ** i - 1), y = 2 ** i, w = BigInt(i);
669
+ const u = BigInt(2 ** i - 1), p = 2 ** i, w = BigInt(i);
670
670
  for (let g = 0; g < c; g++) {
671
671
  const h = g * a;
672
672
  let d = Number(o & u);
673
- o >>= w, d > a && (d -= y, o += St);
674
- const p = h, m = h + Math.abs(d) - 1, S = g % 2 !== 0, _ = d < 0;
675
- d === 0 ? f = f.add(n(S, s[p])) : l = l.add(n(_, s[m]));
673
+ o >>= w, d > a && (d -= p, o += St);
674
+ const y = h, m = h + Math.abs(d) - 1, S = g % 2 !== 0, U = d < 0;
675
+ d === 0 ? f = f.add(n(S, s[y])) : l = l.add(n(U, s[m]));
676
676
  }
677
677
  return { p: l, f };
678
678
  },
@@ -769,14 +769,14 @@ const Ln = BigInt(3);
769
769
  BigInt(4);
770
770
  function cs(e) {
771
771
  const t = ss(e), { Fp: n } = t, r = t.toBytes || ((g, h, d) => {
772
- const p = h.toAffine();
773
- return Ie(Uint8Array.from([4]), n.toBytes(p.x), n.toBytes(p.y));
772
+ const y = h.toAffine();
773
+ return Ie(Uint8Array.from([4]), n.toBytes(y.x), n.toBytes(y.y));
774
774
  }), i = t.fromBytes || ((g) => {
775
- const h = g.subarray(1), d = n.fromBytes(h.subarray(0, n.BYTES)), p = n.fromBytes(h.subarray(n.BYTES, 2 * n.BYTES));
776
- return { x: d, y: p };
775
+ const h = g.subarray(1), d = n.fromBytes(h.subarray(0, n.BYTES)), y = n.fromBytes(h.subarray(n.BYTES, 2 * n.BYTES));
776
+ return { x: d, y };
777
777
  });
778
778
  function s(g) {
779
- const { a: h, b: d } = t, p = n.sqr(g), m = n.mul(p, g);
779
+ const { a: h, b: d } = t, y = n.sqr(g), m = n.mul(y, g);
780
780
  return n.add(n.add(m, n.mul(g, h)), d);
781
781
  }
782
782
  if (!n.eql(n.sqr(t.Gy), s(t.Gx)))
@@ -789,7 +789,7 @@ function cs(e) {
789
789
  throw new Error("Expected valid bigint: 0 < bigint < curve.n");
790
790
  }
791
791
  function a(g) {
792
- const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey: p, n: m } = t;
792
+ const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey: y, n: m } = t;
793
793
  if (h && typeof g != "bigint") {
794
794
  if (g instanceof Uint8Array && (g = qe(g)), typeof g != "string" || !h.includes(g.length))
795
795
  throw new Error("Invalid key");
@@ -801,7 +801,7 @@ function cs(e) {
801
801
  } catch {
802
802
  throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof g}`);
803
803
  }
804
- return p && (S = V(S, m)), c(S), S;
804
+ return y && (S = V(S, m)), c(S), S;
805
805
  }
806
806
  const l = /* @__PURE__ */ new Map();
807
807
  function f(g) {
@@ -809,24 +809,24 @@ function cs(e) {
809
809
  throw new Error("ProjectivePoint expected");
810
810
  }
811
811
  class u {
812
- constructor(h, d, p) {
813
- if (this.px = h, this.py = d, this.pz = p, h == null || !n.isValid(h))
812
+ constructor(h, d, y) {
813
+ if (this.px = h, this.py = d, this.pz = y, h == null || !n.isValid(h))
814
814
  throw new Error("x required");
815
815
  if (d == null || !n.isValid(d))
816
816
  throw new Error("y required");
817
- if (p == null || !n.isValid(p))
817
+ if (y == null || !n.isValid(y))
818
818
  throw new Error("z required");
819
819
  }
820
820
  // Does not validate if the point is on-curve.
821
821
  // Use fromHex instead, or call assertValidity() later.
822
822
  static fromAffine(h) {
823
- const { x: d, y: p } = h || {};
824
- if (!h || !n.isValid(d) || !n.isValid(p))
823
+ const { x: d, y } = h || {};
824
+ if (!h || !n.isValid(d) || !n.isValid(y))
825
825
  throw new Error("invalid affine point");
826
826
  if (h instanceof u)
827
827
  throw new Error("projective point not allowed");
828
828
  const m = (S) => n.eql(S, n.ZERO);
829
- return m(d) && m(p) ? u.ZERO : new u(d, p, n.ONE);
829
+ return m(d) && m(y) ? u.ZERO : new u(d, y, n.ONE);
830
830
  }
831
831
  get x() {
832
832
  return this.toAffine().x;
@@ -841,8 +841,8 @@ function cs(e) {
841
841
  * Optimization: converts a list of projective points to a list of identical points with Z=1.
842
842
  */
843
843
  static normalizeZ(h) {
844
- const d = n.invertBatch(h.map((p) => p.pz));
845
- return h.map((p, m) => p.toAffine(d[m])).map(u.fromAffine);
844
+ const d = n.invertBatch(h.map((y) => y.pz));
845
+ return h.map((y, m) => y.toAffine(d[m])).map(u.fromAffine);
846
846
  }
847
847
  /**
848
848
  * Converts hash string or Uint8Array to Point.
@@ -870,8 +870,8 @@ function cs(e) {
870
870
  const { x: h, y: d } = this.toAffine();
871
871
  if (!n.isValid(h) || !n.isValid(d))
872
872
  throw new Error("bad point: x or y not FE");
873
- const p = n.sqr(d), m = s(h);
874
- if (!n.eql(p, m))
873
+ const y = n.sqr(d), m = s(h);
874
+ if (!n.eql(y, m))
875
875
  throw new Error("bad point: equation left != right");
876
876
  if (!this.isTorsionFree())
877
877
  throw new Error("bad point: not in prime-order subgroup");
@@ -887,7 +887,7 @@ function cs(e) {
887
887
  */
888
888
  equals(h) {
889
889
  f(h);
890
- const { px: d, py: p, pz: m } = this, { px: S, py: _, pz: k } = h, E = n.eql(n.mul(d, k), n.mul(S, m)), x = n.eql(n.mul(p, k), n.mul(_, m));
890
+ const { px: d, py: y, pz: m } = this, { px: S, py: U, pz: k } = h, E = n.eql(n.mul(d, k), n.mul(S, m)), x = n.eql(n.mul(y, k), n.mul(U, m));
891
891
  return E && x;
892
892
  }
893
893
  /**
@@ -901,9 +901,9 @@ function cs(e) {
901
901
  // https://eprint.iacr.org/2015/1060, algorithm 3
902
902
  // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
903
903
  double() {
904
- const { a: h, b: d } = t, p = n.mul(d, Ln), { px: m, py: S, pz: _ } = this;
905
- let k = n.ZERO, E = n.ZERO, x = n.ZERO, K = n.mul(m, m), M = n.mul(S, S), I = n.mul(_, _), A = n.mul(m, S);
906
- return A = n.add(A, A), x = n.mul(m, _), x = n.add(x, x), k = n.mul(h, x), E = n.mul(p, I), E = n.add(k, E), k = n.sub(M, E), E = n.add(M, E), E = n.mul(k, E), k = n.mul(A, k), x = n.mul(p, x), I = n.mul(h, I), A = n.sub(K, I), A = n.mul(h, A), A = n.add(A, x), x = n.add(K, K), K = n.add(x, K), K = n.add(K, I), K = n.mul(K, A), E = n.add(E, K), I = n.mul(S, _), I = n.add(I, I), K = n.mul(I, A), k = n.sub(k, K), x = n.mul(I, M), x = n.add(x, x), x = n.add(x, x), new u(k, E, x);
904
+ const { a: h, b: d } = t, y = n.mul(d, Ln), { px: m, py: S, pz: U } = this;
905
+ let k = n.ZERO, E = n.ZERO, x = n.ZERO, K = n.mul(m, m), M = n.mul(S, S), I = n.mul(U, U), A = n.mul(m, S);
906
+ return A = n.add(A, A), x = n.mul(m, U), x = n.add(x, x), k = n.mul(h, x), E = n.mul(y, I), E = n.add(k, E), k = n.sub(M, E), E = n.add(M, E), E = n.mul(k, E), k = n.mul(A, k), x = n.mul(y, x), I = n.mul(h, I), A = n.sub(K, I), A = n.mul(h, A), A = n.add(A, x), x = n.add(K, K), K = n.add(x, K), K = n.add(K, I), K = n.mul(K, A), E = n.add(E, K), I = n.mul(S, U), I = n.add(I, I), K = n.mul(I, A), k = n.sub(k, K), x = n.mul(I, M), x = n.add(x, x), x = n.add(x, x), new u(k, E, x);
907
907
  }
908
908
  // Renes-Costello-Batina exception-free addition formula.
909
909
  // There is 30% faster Jacobian formula, but it is not complete.
@@ -911,13 +911,13 @@ function cs(e) {
911
911
  // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
912
912
  add(h) {
913
913
  f(h);
914
- const { px: d, py: p, pz: m } = this, { px: S, py: _, pz: k } = h;
914
+ const { px: d, py: y, pz: m } = this, { px: S, py: U, pz: k } = h;
915
915
  let E = n.ZERO, x = n.ZERO, K = n.ZERO;
916
916
  const M = t.a, I = n.mul(t.b, Ln);
917
- let A = n.mul(d, S), R = n.mul(p, _), T = n.mul(m, k), D = n.add(d, p), b = n.add(S, _);
917
+ let A = n.mul(d, S), R = n.mul(y, U), T = n.mul(m, k), D = n.add(d, y), b = n.add(S, U);
918
918
  D = n.mul(D, b), b = n.add(A, R), D = n.sub(D, b), b = n.add(d, m);
919
919
  let v = n.add(S, k);
920
- return b = n.mul(b, v), v = n.add(A, T), b = n.sub(b, v), v = n.add(p, m), E = n.add(_, k), v = n.mul(v, E), E = n.add(R, T), v = n.sub(v, E), K = n.mul(M, b), E = n.mul(I, T), K = n.add(E, K), E = n.sub(R, K), K = n.add(R, K), x = n.mul(E, K), R = n.add(A, A), R = n.add(R, A), T = n.mul(M, T), b = n.mul(I, b), R = n.add(R, T), T = n.sub(A, T), T = n.mul(M, T), b = n.add(b, T), A = n.mul(R, b), x = n.add(x, A), A = n.mul(v, b), E = n.mul(D, E), E = n.sub(E, A), A = n.mul(D, R), K = n.mul(v, K), K = n.add(K, A), new u(E, x, K);
920
+ return b = n.mul(b, v), v = n.add(A, T), b = n.sub(b, v), v = n.add(y, m), E = n.add(U, k), v = n.mul(v, E), E = n.add(R, T), v = n.sub(v, E), K = n.mul(M, b), E = n.mul(I, T), K = n.add(E, K), E = n.sub(R, K), K = n.add(R, K), x = n.mul(E, K), R = n.add(A, A), R = n.add(R, A), T = n.mul(M, T), b = n.mul(I, b), R = n.add(R, T), T = n.sub(A, T), T = n.mul(M, T), b = n.add(b, T), A = n.mul(R, b), x = n.add(x, A), A = n.mul(v, b), E = n.mul(D, E), E = n.sub(E, A), A = n.mul(D, R), K = n.mul(v, K), K = n.add(K, A), new u(E, x, K);
921
921
  }
922
922
  subtract(h) {
923
923
  return this.add(h.negate());
@@ -927,8 +927,8 @@ function cs(e) {
927
927
  }
928
928
  wNAF(h) {
929
929
  return w.wNAFCached(this, l, h, (d) => {
930
- const p = n.invertBatch(d.map((m) => m.pz));
931
- return d.map((m, S) => m.toAffine(p[S])).map(u.fromAffine);
930
+ const y = n.invertBatch(d.map((m) => m.pz));
931
+ return d.map((m, S) => m.toAffine(y[S])).map(u.fromAffine);
932
932
  });
933
933
  }
934
934
  /**
@@ -942,13 +942,13 @@ function cs(e) {
942
942
  return d;
943
943
  if (c(h), h === X)
944
944
  return this;
945
- const { endo: p } = t;
946
- if (!p)
945
+ const { endo: y } = t;
946
+ if (!y)
947
947
  return w.unsafeLadder(this, h);
948
- let { k1neg: m, k1: S, k2neg: _, k2: k } = p.splitScalar(h), E = d, x = d, K = this;
948
+ let { k1neg: m, k1: S, k2neg: U, k2: k } = y.splitScalar(h), E = d, x = d, K = this;
949
949
  for (; S > ce || k > ce; )
950
950
  S & X && (E = E.add(K)), k & X && (x = x.add(K)), K = K.double(), S >>= X, k >>= X;
951
- return m && (E = E.negate()), _ && (x = x.negate()), x = new u(n.mul(x.px, p.beta), x.py, x.pz), E.add(x);
951
+ return m && (E = E.negate()), U && (x = x.negate()), x = new u(n.mul(x.px, y.beta), x.py, x.pz), E.add(x);
952
952
  }
953
953
  /**
954
954
  * Constant time multiplication.
@@ -961,17 +961,17 @@ function cs(e) {
961
961
  */
962
962
  multiply(h) {
963
963
  c(h);
964
- let d = h, p, m;
964
+ let d = h, y, m;
965
965
  const { endo: S } = t;
966
966
  if (S) {
967
- const { k1neg: _, k1: k, k2neg: E, k2: x } = S.splitScalar(d);
967
+ const { k1neg: U, k1: k, k2neg: E, k2: x } = S.splitScalar(d);
968
968
  let { p: K, f: M } = this.wNAF(k), { p: I, f: A } = this.wNAF(x);
969
- K = w.constTimeNegate(_, K), I = w.constTimeNegate(E, I), I = new u(n.mul(I.px, S.beta), I.py, I.pz), p = K.add(I), m = M.add(A);
969
+ K = w.constTimeNegate(U, K), I = w.constTimeNegate(E, I), I = new u(n.mul(I.px, S.beta), I.py, I.pz), y = K.add(I), m = M.add(A);
970
970
  } else {
971
- const { p: _, f: k } = this.wNAF(d);
972
- p = _, m = k;
971
+ const { p: U, f: k } = this.wNAF(d);
972
+ y = U, m = k;
973
973
  }
974
- return u.normalizeZ([p, m])[0];
974
+ return u.normalizeZ([y, m])[0];
975
975
  }
976
976
  /**
977
977
  * Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
@@ -979,22 +979,22 @@ function cs(e) {
979
979
  * The trick could be useful if both P and Q are not G (not in our case).
980
980
  * @returns non-zero affine point
981
981
  */
982
- multiplyAndAddUnsafe(h, d, p) {
983
- const m = u.BASE, S = (k, E) => E === ce || E === X || !k.equals(m) ? k.multiplyUnsafe(E) : k.multiply(E), _ = S(this, d).add(S(h, p));
984
- return _.is0() ? void 0 : _;
982
+ multiplyAndAddUnsafe(h, d, y) {
983
+ const m = u.BASE, S = (k, E) => E === ce || E === X || !k.equals(m) ? k.multiplyUnsafe(E) : k.multiply(E), U = S(this, d).add(S(h, y));
984
+ return U.is0() ? void 0 : U;
985
985
  }
986
986
  // Converts Projective point to affine (x, y) coordinates.
987
987
  // Can accept precomputed Z^-1 - for example, from invertBatch.
988
988
  // (x, y, z) ∋ (x=x/z, y=y/z)
989
989
  toAffine(h) {
990
- const { px: d, py: p, pz: m } = this, S = this.is0();
990
+ const { px: d, py: y, pz: m } = this, S = this.is0();
991
991
  h == null && (h = S ? n.ONE : n.inv(m));
992
- const _ = n.mul(d, h), k = n.mul(p, h), E = n.mul(m, h);
992
+ const U = n.mul(d, h), k = n.mul(y, h), E = n.mul(m, h);
993
993
  if (S)
994
994
  return { x: n.ZERO, y: n.ZERO };
995
995
  if (!n.eql(E, n.ONE))
996
996
  throw new Error("invZ was invalid");
997
- return { x: _, y: k };
997
+ return { x: U, y: k };
998
998
  }
999
999
  isTorsionFree() {
1000
1000
  const { h, isTorsionFree: d } = t;
@@ -1016,7 +1016,7 @@ function cs(e) {
1016
1016
  }
1017
1017
  }
1018
1018
  u.BASE = new u(t.Gx, t.Gy, n.ONE), u.ZERO = new u(n.ZERO, n.ONE, n.ZERO);
1019
- const y = t.nBitLength, w = is(u, t.endo ? Math.ceil(y / 2) : y);
1019
+ const p = t.nBitLength, w = is(u, t.endo ? Math.ceil(p / 2) : p);
1020
1020
  return {
1021
1021
  CURVE: t,
1022
1022
  ProjectivePoint: u,
@@ -1048,11 +1048,11 @@ function ls(e) {
1048
1048
  function a(b) {
1049
1049
  return Tt(b, r);
1050
1050
  }
1051
- const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: y } = cs({
1051
+ const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: p } = cs({
1052
1052
  ...t,
1053
1053
  toBytes(b, v, N) {
1054
- const B = v.toAffine(), C = n.toBytes(B.x), U = Ie;
1055
- return N ? U(Uint8Array.from([v.hasEvenY() ? 2 : 3]), C) : U(Uint8Array.from([4]), C, n.toBytes(B.y));
1054
+ const B = v.toAffine(), C = n.toBytes(B.x), _ = Ie;
1055
+ return N ? _(Uint8Array.from([v.hasEvenY() ? 2 : 3]), C) : _(Uint8Array.from([4]), C, n.toBytes(B.y));
1056
1056
  },
1057
1057
  fromBytes(b) {
1058
1058
  const v = b.length, N = b[0], B = b.subarray(1);
@@ -1060,13 +1060,13 @@ function ls(e) {
1060
1060
  const C = G(B);
1061
1061
  if (!o(C))
1062
1062
  throw new Error("Point is not on curve");
1063
- const U = u(C);
1064
- let O = n.sqrt(U);
1063
+ const _ = u(C);
1064
+ let O = n.sqrt(_);
1065
1065
  const $ = (O & X) === X;
1066
1066
  return (N & 1) === 1 !== $ && (O = n.neg(O)), { x: C, y: O };
1067
1067
  } else if (v === s && N === 4) {
1068
- const C = n.fromBytes(B.subarray(0, n.BYTES)), U = n.fromBytes(B.subarray(n.BYTES, 2 * n.BYTES));
1069
- return { x: C, y: U };
1068
+ const C = n.fromBytes(B.subarray(0, n.BYTES)), _ = n.fromBytes(B.subarray(n.BYTES, 2 * n.BYTES));
1069
+ return { x: C, y: _ };
1070
1070
  } else
1071
1071
  throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`);
1072
1072
  }
@@ -1079,38 +1079,38 @@ function ls(e) {
1079
1079
  return g(b) ? c(-b) : b;
1080
1080
  }
1081
1081
  const d = (b, v, N) => G(b.slice(v, N));
1082
- class p {
1082
+ class y {
1083
1083
  constructor(v, N, B) {
1084
1084
  this.r = v, this.s = N, this.recovery = B, this.assertValidity();
1085
1085
  }
1086
1086
  // pair (bytes of r, bytes of s)
1087
1087
  static fromCompact(v) {
1088
1088
  const N = t.nByteLength;
1089
- return v = Z("compactSignature", v, N * 2), new p(d(v, 0, N), d(v, N, 2 * N));
1089
+ return v = Z("compactSignature", v, N * 2), new y(d(v, 0, N), d(v, N, 2 * N));
1090
1090
  }
1091
1091
  // DER encoded ECDSA signature
1092
1092
  // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
1093
1093
  static fromDER(v) {
1094
1094
  const { r: N, s: B } = ke.toSig(Z("DER", v));
1095
- return new p(N, B);
1095
+ return new y(N, B);
1096
1096
  }
1097
1097
  assertValidity() {
1098
- if (!y(this.r))
1098
+ if (!p(this.r))
1099
1099
  throw new Error("r must be 0 < r < CURVE.n");
1100
- if (!y(this.s))
1100
+ if (!p(this.s))
1101
1101
  throw new Error("s must be 0 < s < CURVE.n");
1102
1102
  }
1103
1103
  addRecoveryBit(v) {
1104
- return new p(this.r, this.s, v);
1104
+ return new y(this.r, this.s, v);
1105
1105
  }
1106
1106
  recoverPublicKey(v) {
1107
- const { r: N, s: B, recovery: C } = this, U = x(Z("msgHash", v));
1107
+ const { r: N, s: B, recovery: C } = this, _ = x(Z("msgHash", v));
1108
1108
  if (C == null || ![0, 1, 2, 3].includes(C))
1109
1109
  throw new Error("recovery id invalid");
1110
1110
  const O = C === 2 || C === 3 ? N + t.n : N;
1111
1111
  if (O >= n.ORDER)
1112
1112
  throw new Error("recovery id 2 or 3 invalid");
1113
- const $ = (C & 1) === 0 ? "02" : "03", ee = l.fromHex($ + w(O)), ge = a(O), Ue = c(-U * ge), Ve = c(B * ge), we = l.BASE.multiplyAndAddUnsafe(ee, Ue, Ve);
1113
+ const $ = (C & 1) === 0 ? "02" : "03", ee = l.fromHex($ + w(O)), ge = a(O), _e = c(-_ * ge), Ve = c(B * ge), we = l.BASE.multiplyAndAddUnsafe(ee, _e, Ve);
1114
1114
  if (!we)
1115
1115
  throw new Error("point at infinify");
1116
1116
  return we.assertValidity(), we;
@@ -1120,7 +1120,7 @@ function ls(e) {
1120
1120
  return g(this.s);
1121
1121
  }
1122
1122
  normalizeS() {
1123
- return this.hasHighS() ? new p(this.r, c(-this.s), this.recovery) : this;
1123
+ return this.hasHighS() ? new y(this.r, c(-this.s), this.recovery) : this;
1124
1124
  }
1125
1125
  // DER-encoded
1126
1126
  toDERRawBytes() {
@@ -1169,14 +1169,14 @@ function ls(e) {
1169
1169
  function S(b, v = !0) {
1170
1170
  return l.fromPrivateKey(b).toRawBytes(v);
1171
1171
  }
1172
- function _(b) {
1172
+ function U(b) {
1173
1173
  const v = b instanceof Uint8Array, N = typeof b == "string", B = (v || N) && b.length;
1174
1174
  return v ? B === i || B === s : N ? B === 2 * i || B === 2 * s : b instanceof l;
1175
1175
  }
1176
1176
  function k(b, v, N = !0) {
1177
- if (_(b))
1177
+ if (U(b))
1178
1178
  throw new Error("first arg must be private key");
1179
- if (!_(v))
1179
+ if (!U(v))
1180
1180
  throw new Error("second arg must be public key");
1181
1181
  return l.fromHex(v).multiply(f(b)).toRawBytes(N);
1182
1182
  }
@@ -1197,17 +1197,17 @@ function ls(e) {
1197
1197
  if (["recovered", "canonical"].some((Ae) => Ae in N))
1198
1198
  throw new Error("sign() legacy options not supported");
1199
1199
  const { hash: B, randomBytes: C } = t;
1200
- let { lowS: U, prehash: O, extraEntropy: $ } = N;
1201
- U == null && (U = !0), b = Z("msgHash", b), O && (b = Z("prehashed msgHash", B(b)));
1202
- const ee = x(b), ge = f(v), Ue = [M(ge), M(ee)];
1200
+ let { lowS: _, prehash: O, extraEntropy: $ } = N;
1201
+ _ == null && (_ = !0), b = Z("msgHash", b), O && (b = Z("prehashed msgHash", B(b)));
1202
+ const ee = x(b), ge = f(v), _e = [M(ge), M(ee)];
1203
1203
  if ($ != null) {
1204
1204
  const Ae = $ === !0 ? C(n.BYTES) : $;
1205
- Ue.push(Z("extraEntropy", Ae));
1205
+ _e.push(Z("extraEntropy", Ae));
1206
1206
  }
1207
- const Ve = Ie(...Ue), we = ee;
1207
+ const Ve = Ie(..._e), we = ee;
1208
1208
  function Et(Ae) {
1209
1209
  const Le = E(Ae);
1210
- if (!y(Le))
1210
+ if (!p(Le))
1211
1211
  return;
1212
1212
  const An = a(Le), $e = l.BASE.multiply(Le).toAffine(), te = c($e.x);
1213
1213
  if (te === ce)
@@ -1216,14 +1216,14 @@ function ls(e) {
1216
1216
  if (Re === ce)
1217
1217
  return;
1218
1218
  let Cn = ($e.x === te ? 0 : 2) | Number($e.y & X), kn = Re;
1219
- return U && g(Re) && (kn = h(Re), Cn ^= 1), new p(te, kn, Cn);
1219
+ return _ && g(Re) && (kn = h(Re), Cn ^= 1), new y(te, kn, Cn);
1220
1220
  }
1221
1221
  return { seed: Ve, k2sig: Et };
1222
1222
  }
1223
1223
  const A = { lowS: t.lowS, prehash: !1 }, R = { lowS: t.lowS, prehash: !1 };
1224
1224
  function T(b, v, N = A) {
1225
- const { seed: B, k2sig: C } = I(b, v, N), U = t;
1226
- return er(U.hash.outputLen, U.nByteLength, U.hmac)(B, C);
1225
+ const { seed: B, k2sig: C } = I(b, v, N), _ = t;
1226
+ return er(_.hash.outputLen, _.nByteLength, _.hmac)(B, C);
1227
1227
  }
1228
1228
  l.BASE._setWindowSize(8);
1229
1229
  function D(b, v, N, B = R) {
@@ -1231,20 +1231,20 @@ function ls(e) {
1231
1231
  const C = b;
1232
1232
  if (v = Z("msgHash", v), N = Z("publicKey", N), "strict" in B)
1233
1233
  throw new Error("options.strict was renamed to lowS");
1234
- const { lowS: U, prehash: O } = B;
1234
+ const { lowS: _, prehash: O } = B;
1235
1235
  let $, ee;
1236
1236
  try {
1237
1237
  if (typeof C == "string" || C instanceof Uint8Array)
1238
1238
  try {
1239
- $ = p.fromDER(C);
1239
+ $ = y.fromDER(C);
1240
1240
  } catch (te) {
1241
1241
  if (!(te instanceof ke.Err))
1242
1242
  throw te;
1243
- $ = p.fromCompact(C);
1243
+ $ = y.fromCompact(C);
1244
1244
  }
1245
1245
  else if (typeof C == "object" && typeof C.r == "bigint" && typeof C.s == "bigint") {
1246
1246
  const { r: te, s: Re } = C;
1247
- $ = new p(te, Re);
1247
+ $ = new y(te, Re);
1248
1248
  } else
1249
1249
  throw new Error("PARSE");
1250
1250
  ee = l.fromHex(N);
@@ -1253,10 +1253,10 @@ function ls(e) {
1253
1253
  throw new Error("signature must be Signature instance, Uint8Array or hex string");
1254
1254
  return !1;
1255
1255
  }
1256
- if (U && $.hasHighS())
1256
+ if (_ && $.hasHighS())
1257
1257
  return !1;
1258
1258
  O && (v = t.hash(v));
1259
- const { r: ge, s: Ue } = $, Ve = x(v), we = a(Ue), Et = c(Ve * we), Ae = c(ge * we), Le = ($e = l.BASE.multiplyAndAddUnsafe(ee, Et, Ae)) == null ? void 0 : $e.toAffine();
1259
+ const { r: ge, s: _e } = $, Ve = x(v), we = a(_e), Et = c(Ve * we), Ae = c(ge * we), Le = ($e = l.BASE.multiplyAndAddUnsafe(ee, Et, Ae)) == null ? void 0 : $e.toAffine();
1260
1260
  return Le ? c(Le.x) === ge : !1;
1261
1261
  }
1262
1262
  return {
@@ -1266,7 +1266,7 @@ function ls(e) {
1266
1266
  sign: T,
1267
1267
  verify: D,
1268
1268
  ProjectivePoint: l,
1269
- Signature: p,
1269
+ Signature: y,
1270
1270
  utils: m
1271
1271
  };
1272
1272
  }
@@ -1322,12 +1322,12 @@ function hs(e, t) {
1322
1322
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1323
1323
  const ut = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), tt = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), ar = BigInt(1), nt = BigInt(2), $n = (e, t) => (e + t / nt) / t;
1324
1324
  function cr(e) {
1325
- const t = ut, n = BigInt(3), r = BigInt(6), i = BigInt(11), s = BigInt(22), o = BigInt(23), c = BigInt(44), a = BigInt(88), l = e * e * e % t, f = l * l * e % t, u = Y(f, n, t) * f % t, y = Y(u, n, t) * f % t, w = Y(y, nt, t) * l % t, g = Y(w, i, t) * w % t, h = Y(g, s, t) * g % t, d = Y(h, c, t) * h % t, p = Y(d, a, t) * d % t, m = Y(p, c, t) * h % t, S = Y(m, n, t) * f % t, _ = Y(S, o, t) * g % t, k = Y(_, r, t) * l % t, E = Y(k, nt, t);
1325
+ const t = ut, n = BigInt(3), r = BigInt(6), i = BigInt(11), s = BigInt(22), o = BigInt(23), c = BigInt(44), a = BigInt(88), l = e * e * e % t, f = l * l * e % t, u = Y(f, n, t) * f % t, p = Y(u, n, t) * f % t, w = Y(p, nt, t) * l % t, g = Y(w, i, t) * w % t, h = Y(g, s, t) * g % t, d = Y(h, c, t) * h % t, y = Y(d, a, t) * d % t, m = Y(y, c, t) * h % t, S = Y(m, n, t) * f % t, U = Y(S, o, t) * g % t, k = Y(U, r, t) * l % t, E = Y(k, nt, t);
1326
1326
  if (!Ot.eql(Ot.sqr(E), e))
1327
1327
  throw new Error("Cannot find square root");
1328
1328
  return E;
1329
1329
  }
1330
- const Ot = ts(ut, void 0, void 0, { sqrt: cr }), _e = hs({
1330
+ const Ot = ts(ut, void 0, void 0, { sqrt: cr }), Ue = hs({
1331
1331
  a: BigInt(0),
1332
1332
  b: BigInt(7),
1333
1333
  Fp: Ot,
@@ -1348,10 +1348,10 @@ const Ot = ts(ut, void 0, void 0, { sqrt: cr }), _e = hs({
1348
1348
  splitScalar: (e) => {
1349
1349
  const t = tt, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -ar * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), s = n, o = BigInt("0x100000000000000000000000000000000"), c = $n(s * e, t), a = $n(-r * e, t);
1350
1350
  let l = V(e - c * n - a * i, t), f = V(-c * r - a * s, t);
1351
- const u = l > o, y = f > o;
1352
- if (u && (l = t - l), y && (f = t - f), l > o || f > o)
1351
+ const u = l > o, p = f > o;
1352
+ if (u && (l = t - l), p && (f = t - f), l > o || f > o)
1353
1353
  throw new Error("splitScalar: Endomorphism failed, k=" + e);
1354
- return { k1neg: u, k1: l, k2neg: y, k2: f };
1354
+ return { k1neg: u, k1: l, k2neg: p, k2: f };
1355
1355
  }
1356
1356
  }
1357
1357
  }, $t), lt = BigInt(0), ur = (e) => typeof e == "bigint" && lt < e && e < ut, ds = (e) => typeof e == "bigint" && lt < e && e < tt, Rn = {};
@@ -1363,9 +1363,9 @@ function rt(e, ...t) {
1363
1363
  }
1364
1364
  return $t(Ie(n, ...t));
1365
1365
  }
1366
- const Yt = (e) => e.toRawBytes(!0).slice(1), Mt = (e) => Ne(e, 32), At = (e) => V(e, ut), Ge = (e) => V(e, tt), Xt = _e.ProjectivePoint, ps = (e, t, n) => Xt.BASE.multiplyAndAddUnsafe(e, t, n);
1366
+ const Yt = (e) => e.toRawBytes(!0).slice(1), Mt = (e) => Ne(e, 32), At = (e) => V(e, ut), Ge = (e) => V(e, tt), Xt = Ue.ProjectivePoint, ys = (e, t, n) => Xt.BASE.multiplyAndAddUnsafe(e, t, n);
1367
1367
  function Pt(e) {
1368
- let t = _e.utils.normPrivateKeyToScalar(e), n = Xt.fromPrivateKey(t);
1368
+ let t = Ue.utils.normPrivateKeyToScalar(e), n = Xt.fromPrivateKey(t);
1369
1369
  return { scalar: n.hasEvenY() ? t : Ge(-t), bytes: Yt(n) };
1370
1370
  }
1371
1371
  function lr(e) {
@@ -1380,15 +1380,15 @@ function lr(e) {
1380
1380
  function fr(...e) {
1381
1381
  return Ge(G(rt("BIP0340/challenge", ...e)));
1382
1382
  }
1383
- function ys(e) {
1383
+ function ps(e) {
1384
1384
  return Pt(e).bytes;
1385
1385
  }
1386
1386
  function gs(e, t, n = Yn(32)) {
1387
1387
  const r = Z("message", e), { bytes: i, scalar: s } = Pt(t), o = Z("auxRand", n, 32), c = Mt(s ^ G(rt("BIP0340/aux", o))), a = rt("BIP0340/nonce", c, i, r), l = Ge(G(a));
1388
1388
  if (l === lt)
1389
1389
  throw new Error("sign failed: k is zero");
1390
- const { bytes: f, scalar: u } = Pt(l), y = fr(f, i, r), w = new Uint8Array(64);
1391
- if (w.set(f, 0), w.set(Mt(Ge(u + y * s)), 32), !hr(w, r, i))
1390
+ const { bytes: f, scalar: u } = Pt(l), p = fr(f, i, r), w = new Uint8Array(64);
1391
+ if (w.set(f, 0), w.set(Mt(Ge(u + p * s)), 32), !hr(w, r, i))
1392
1392
  throw new Error("sign: Invalid signature produced");
1393
1393
  return w;
1394
1394
  }
@@ -1401,18 +1401,18 @@ function hr(e, t, n) {
1401
1401
  const a = G(r.subarray(32, 64));
1402
1402
  if (!ds(a))
1403
1403
  return !1;
1404
- const l = fr(Mt(c), Yt(o), i), f = ps(o, a, Ge(-l));
1404
+ const l = fr(Mt(c), Yt(o), i), f = ys(o, a, Ge(-l));
1405
1405
  return !(!f || !f.hasEvenY() || f.toAffine().x !== c);
1406
1406
  } catch {
1407
1407
  return !1;
1408
1408
  }
1409
1409
  }
1410
1410
  const Ze = {
1411
- getPublicKey: ys,
1411
+ getPublicKey: ps,
1412
1412
  sign: gs,
1413
1413
  verify: hr,
1414
1414
  utils: {
1415
- randomPrivateKey: _e.utils.randomPrivateKey,
1415
+ randomPrivateKey: Ue.utils.randomPrivateKey,
1416
1416
  lift_x: lr,
1417
1417
  pointToBytes: Yt,
1418
1418
  numberToBytesBE: Ne,
@@ -1474,11 +1474,11 @@ class dr {
1474
1474
  return this._cloneInto();
1475
1475
  }
1476
1476
  }
1477
- function pr(e) {
1477
+ function yr(e) {
1478
1478
  const t = (r) => e().update(Je(r)).digest(), n = e();
1479
1479
  return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
1480
1480
  }
1481
- function yr(e = 32) {
1481
+ function pr(e = 32) {
1482
1482
  if (Ct && typeof Ct.getRandomValues == "function")
1483
1483
  return Ct.getRandomValues(new Uint8Array(e));
1484
1484
  throw new Error("crypto.getRandomValues must be defined");
@@ -1669,12 +1669,12 @@ class wr extends Ss {
1669
1669
  for (let u = 0; u < 16; u++, n += 4)
1670
1670
  Ee[u] = t.getUint32(n, !1);
1671
1671
  for (let u = 16; u < 64; u++) {
1672
- const y = Ee[u - 15], w = Ee[u - 2], g = ie(y, 7) ^ ie(y, 18) ^ y >>> 3, h = ie(w, 17) ^ ie(w, 19) ^ w >>> 10;
1672
+ const p = Ee[u - 15], w = Ee[u - 2], g = ie(p, 7) ^ ie(p, 18) ^ p >>> 3, h = ie(w, 17) ^ ie(w, 19) ^ w >>> 10;
1673
1673
  Ee[u] = h + Ee[u - 7] + g + Ee[u - 16] | 0;
1674
1674
  }
1675
1675
  let { A: r, B: i, C: s, D: o, E: c, F: a, G: l, H: f } = this;
1676
1676
  for (let u = 0; u < 64; u++) {
1677
- const y = ie(c, 6) ^ ie(c, 11) ^ ie(c, 25), w = f + y + As(c, a, l) + ks[u] + Ee[u] | 0, h = (ie(r, 2) ^ ie(r, 13) ^ ie(r, 22)) + Cs(r, i, s) | 0;
1677
+ const p = ie(c, 6) ^ ie(c, 11) ^ ie(c, 25), w = f + p + As(c, a, l) + ks[u] + Ee[u] | 0, h = (ie(r, 2) ^ ie(r, 13) ^ ie(r, 22)) + Cs(r, i, s) | 0;
1678
1678
  f = l, l = a, a = c, c = o + w | 0, o = s, s = i, i = r, r = w + h | 0;
1679
1679
  }
1680
1680
  r = r + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, l = l + this.G | 0, f = f + this.H | 0, this.set(r, i, s, o, c, a, l, f);
@@ -1691,8 +1691,8 @@ class Bs extends wr {
1691
1691
  super(), this.A = -1056596264, this.B = 914150663, this.C = 812702999, this.D = -150054599, this.E = -4191439, this.F = 1750603025, this.G = 1694076839, this.H = -1090891868, this.outputLen = 28;
1692
1692
  }
1693
1693
  }
1694
- const fe = pr(() => new wr());
1695
- pr(() => new Bs());
1694
+ const fe = yr(() => new wr());
1695
+ yr(() => new Bs());
1696
1696
  /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1697
1697
  function We(e) {
1698
1698
  if (!Number.isSafeInteger(e))
@@ -1702,7 +1702,7 @@ function de(...e) {
1702
1702
  const t = (i, s) => (o) => i(s(o)), n = Array.from(e).reverse().reduce((i, s) => i ? t(i, s.encode) : s.encode, void 0), r = e.reduce((i, s) => i ? t(i, s.decode) : s.decode, void 0);
1703
1703
  return { encode: n, decode: r };
1704
1704
  }
1705
- function pe(e) {
1705
+ function ye(e) {
1706
1706
  return {
1707
1707
  encode: (t) => {
1708
1708
  if (!Array.isArray(t) || t.length && typeof t[0] != "number")
@@ -1727,7 +1727,7 @@ function pe(e) {
1727
1727
  }
1728
1728
  };
1729
1729
  }
1730
- function ye(e = "") {
1730
+ function pe(e = "") {
1731
1731
  if (typeof e != "string")
1732
1732
  throw new Error("join separator should be string");
1733
1733
  return {
@@ -1883,10 +1883,10 @@ function On(e) {
1883
1883
  }
1884
1884
  };
1885
1885
  }
1886
- const _s = de(Se(4), pe("0123456789ABCDEF"), ye("")), Us = de(Se(5), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), ht(5), ye(""));
1887
- de(Se(5), pe("0123456789ABCDEFGHIJKLMNOPQRSTUV"), ht(5), ye(""));
1888
- de(Se(5), pe("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), ye(""), br((e) => e.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
1889
- const he = de(Se(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), ht(6), ye("")), Ls = de(Se(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), ht(6), ye("")), en = (e) => de(Is(58), pe(e), ye("")), qt = en("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
1886
+ const Us = de(Se(4), ye("0123456789ABCDEF"), pe("")), _s = de(Se(5), ye("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), ht(5), pe(""));
1887
+ de(Se(5), ye("0123456789ABCDEFGHIJKLMNOPQRSTUV"), ht(5), pe(""));
1888
+ de(Se(5), ye("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), pe(""), br((e) => e.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
1889
+ const he = de(Se(6), ye("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), ht(6), pe("")), Ls = de(Se(6), ye("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), ht(6), pe("")), en = (e) => de(Is(58), ye(e), pe("")), qt = en("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
1890
1890
  en("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
1891
1891
  en("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");
1892
1892
  const Mn = [0, 2, 3, 5, 6, 7, 9, 10, 11], $s = {
@@ -1909,7 +1909,7 @@ const Mn = [0, 2, 3, 5, 6, 7, 9, 10, 11], $s = {
1909
1909
  }
1910
1910
  return Uint8Array.from(t);
1911
1911
  }
1912
- }, jt = de(pe("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), ye("")), Pn = [996825010, 642813549, 513874426, 1027748829, 705979059];
1912
+ }, jt = de(ye("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), pe("")), Pn = [996825010, 642813549, 513874426, 1027748829, 705979059];
1913
1913
  function Fe(e) {
1914
1914
  const t = e >> 25;
1915
1915
  let n = (e & 33554431) << 5;
@@ -1937,14 +1937,14 @@ function Hn(e, t, n = 1) {
1937
1937
  }
1938
1938
  function mr(e) {
1939
1939
  const t = e === "bech32" ? 1 : 734539939, n = Se(5), r = n.decode, i = n.encode, s = On(r);
1940
- function o(f, u, y = 90) {
1940
+ function o(f, u, p = 90) {
1941
1941
  if (typeof f != "string")
1942
1942
  throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);
1943
1943
  if (!Array.isArray(u) || u.length && typeof u[0] != "number")
1944
1944
  throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);
1945
1945
  const w = f.length + 7 + u.length;
1946
- if (y !== !1 && w > y)
1947
- throw new TypeError(`Length ${w} exceeds limit ${y}`);
1946
+ if (p !== !1 && w > p)
1947
+ throw new TypeError(`Length ${w} exceeds limit ${p}`);
1948
1948
  return f = f.toLowerCase(), `${f}1${jt.encode(u)}${Hn(f, u, t)}`;
1949
1949
  }
1950
1950
  function c(f, u = 90) {
@@ -1952,25 +1952,25 @@ function mr(e) {
1952
1952
  throw new Error(`bech32.decode input should be string, not ${typeof f}`);
1953
1953
  if (f.length < 8 || u !== !1 && f.length > u)
1954
1954
  throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${u})`);
1955
- const y = f.toLowerCase();
1956
- if (f !== y && f !== f.toUpperCase())
1955
+ const p = f.toLowerCase();
1956
+ if (f !== p && f !== f.toUpperCase())
1957
1957
  throw new Error("String must be lowercase or uppercase");
1958
- f = y;
1958
+ f = p;
1959
1959
  const w = f.lastIndexOf("1");
1960
1960
  if (w === 0 || w === -1)
1961
1961
  throw new Error('Letter "1" must be present between prefix and data only');
1962
1962
  const g = f.slice(0, w), h = f.slice(w + 1);
1963
1963
  if (h.length < 6)
1964
1964
  throw new Error("Data must be at least 6 characters long");
1965
- const d = jt.decode(h).slice(0, -6), p = Hn(g, d, t);
1966
- if (!h.endsWith(p))
1967
- throw new Error(`Invalid checksum in ${f}: expected "${p}"`);
1965
+ const d = jt.decode(h).slice(0, -6), y = Hn(g, d, t);
1966
+ if (!h.endsWith(y))
1967
+ throw new Error(`Invalid checksum in ${f}: expected "${y}"`);
1968
1968
  return { prefix: g, words: d };
1969
1969
  }
1970
1970
  const a = On(c);
1971
1971
  function l(f) {
1972
- const { prefix: u, words: y } = c(f, !1);
1973
- return { prefix: u, words: y, bytes: r(y) };
1972
+ const { prefix: u, words: p } = c(f, !1);
1973
+ return { prefix: u, words: p, bytes: r(p) };
1974
1974
  }
1975
1975
  return { encode: o, decode: c, decodeToBytes: l, decodeUnsafe: a, fromWords: r, fromWordsUnsafe: s, toWords: i };
1976
1976
  }
@@ -1979,15 +1979,15 @@ mr("bech32m");
1979
1979
  const Rs = {
1980
1980
  encode: (e) => new TextDecoder().decode(e),
1981
1981
  decode: (e) => new TextEncoder().encode(e)
1982
- }, Ts = de(Se(4), pe("0123456789abcdef"), ye(""), br((e) => {
1982
+ }, Ts = de(Se(4), ye("0123456789abcdef"), pe(""), br((e) => {
1983
1983
  if (typeof e != "string" || e.length % 2)
1984
1984
  throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);
1985
1985
  return e.toLowerCase();
1986
1986
  })), Os = {
1987
1987
  utf8: Rs,
1988
1988
  hex: Ts,
1989
- base16: _s,
1990
- base32: Us,
1989
+ base16: Us,
1990
+ base32: _s,
1991
1991
  base64: he,
1992
1992
  base64url: Ls,
1993
1993
  base58: qt,
@@ -2104,11 +2104,11 @@ function qn(e, t, n, r, i) {
2104
2104
  t ^= e[a++], n ^= e[a++], r ^= e[a++], i ^= e[a++];
2105
2105
  const l = e.length / 4 - 2;
2106
2106
  for (let g = 0; g < l; g++) {
2107
- const h = e[a++] ^ xe(o, c, t, n, r, i), d = e[a++] ^ xe(o, c, n, r, i, t), p = e[a++] ^ xe(o, c, r, i, t, n), m = e[a++] ^ xe(o, c, i, t, n, r);
2108
- t = h, n = d, r = p, i = m;
2107
+ const h = e[a++] ^ xe(o, c, t, n, r, i), d = e[a++] ^ xe(o, c, n, r, i, t), y = e[a++] ^ xe(o, c, r, i, t, n), m = e[a++] ^ xe(o, c, i, t, n, r);
2108
+ t = h, n = d, r = y, i = m;
2109
2109
  }
2110
- const f = e[a++] ^ oe(s, t, n, r, i), u = e[a++] ^ oe(s, n, r, i, t), y = e[a++] ^ oe(s, r, i, t, n), w = e[a++] ^ oe(s, i, t, n, r);
2111
- return { s0: f, s1: u, s2: y, s3: w };
2110
+ const f = e[a++] ^ oe(s, t, n, r, i), u = e[a++] ^ oe(s, n, r, i, t), p = e[a++] ^ oe(s, r, i, t, n), w = e[a++] ^ oe(s, i, t, n, r);
2111
+ return { s0: f, s1: u, s2: p, s3: w };
2112
2112
  }
2113
2113
  function Fs(e, t, n, r, i) {
2114
2114
  const { sbox2: s, T01: o, T23: c } = xr;
@@ -2116,11 +2116,11 @@ function Fs(e, t, n, r, i) {
2116
2116
  t ^= e[a++], n ^= e[a++], r ^= e[a++], i ^= e[a++];
2117
2117
  const l = e.length / 4 - 2;
2118
2118
  for (let g = 0; g < l; g++) {
2119
- const h = e[a++] ^ xe(o, c, t, i, r, n), d = e[a++] ^ xe(o, c, n, t, i, r), p = e[a++] ^ xe(o, c, r, n, t, i), m = e[a++] ^ xe(o, c, i, r, n, t);
2120
- t = h, n = d, r = p, i = m;
2119
+ const h = e[a++] ^ xe(o, c, t, i, r, n), d = e[a++] ^ xe(o, c, n, t, i, r), y = e[a++] ^ xe(o, c, r, n, t, i), m = e[a++] ^ xe(o, c, i, r, n, t);
2120
+ t = h, n = d, r = y, i = m;
2121
2121
  }
2122
- const f = e[a++] ^ oe(s, t, i, r, n), u = e[a++] ^ oe(s, n, t, i, r), y = e[a++] ^ oe(s, r, n, t, i), w = e[a++] ^ oe(s, i, r, n, t);
2123
- return { s0: f, s1: u, s2: y, s3: w };
2122
+ const f = e[a++] ^ oe(s, t, i, r, n), u = e[a++] ^ oe(s, n, t, i, r), p = e[a++] ^ oe(s, r, n, t, i), w = e[a++] ^ oe(s, i, r, n, t);
2123
+ return { s0: f, s1: u, s2: p, s3: w };
2124
2124
  }
2125
2125
  function Nr(e, t) {
2126
2126
  if (!t)
@@ -2175,24 +2175,24 @@ const Sr = /* @__PURE__ */ qs({ blockSize: 16, nonceLength: 16 }, function(t, n,
2175
2175
  return {
2176
2176
  encrypt: (s, o) => {
2177
2177
  const c = Kr(t), { b: a, o: l, out: f } = Js(s, i, o), u = F(n);
2178
- let y = u[0], w = u[1], g = u[2], h = u[3], d = 0;
2178
+ let p = u[0], w = u[1], g = u[2], h = u[3], d = 0;
2179
2179
  for (; d + 4 <= a.length; )
2180
- y ^= a[d + 0], w ^= a[d + 1], g ^= a[d + 2], h ^= a[d + 3], { s0: y, s1: w, s2: g, s3: h } = qn(c, y, w, g, h), l[d++] = y, l[d++] = w, l[d++] = g, l[d++] = h;
2180
+ p ^= a[d + 0], w ^= a[d + 1], g ^= a[d + 2], h ^= a[d + 3], { s0: p, s1: w, s2: g, s3: h } = qn(c, p, w, g, h), l[d++] = p, l[d++] = w, l[d++] = g, l[d++] = h;
2181
2181
  if (i) {
2182
- const p = Xs(s.subarray(d * 4));
2183
- y ^= p[0], w ^= p[1], g ^= p[2], h ^= p[3], { s0: y, s1: w, s2: g, s3: h } = qn(c, y, w, g, h), l[d++] = y, l[d++] = w, l[d++] = g, l[d++] = h;
2182
+ const y = Xs(s.subarray(d * 4));
2183
+ p ^= y[0], w ^= y[1], g ^= y[2], h ^= y[3], { s0: p, s1: w, s2: g, s3: h } = qn(c, p, w, g, h), l[d++] = p, l[d++] = w, l[d++] = g, l[d++] = h;
2184
2184
  }
2185
2185
  return c.fill(0), f;
2186
2186
  },
2187
2187
  decrypt: (s, o) => {
2188
2188
  Gs(s);
2189
2189
  const c = Zs(t), a = F(n), l = Nr(s.length, o), f = F(s), u = F(l);
2190
- let y = a[0], w = a[1], g = a[2], h = a[3];
2190
+ let p = a[0], w = a[1], g = a[2], h = a[3];
2191
2191
  for (let d = 0; d + 4 <= f.length; ) {
2192
- const p = y, m = w, S = g, _ = h;
2193
- y = f[d + 0], w = f[d + 1], g = f[d + 2], h = f[d + 3];
2194
- const { s0: k, s1: E, s2: x, s3: K } = Fs(c, y, w, g, h);
2195
- u[d++] = k ^ p, u[d++] = E ^ m, u[d++] = x ^ S, u[d++] = K ^ _;
2192
+ const y = p, m = w, S = g, U = h;
2193
+ p = f[d + 0], w = f[d + 1], g = f[d + 2], h = f[d + 3];
2194
+ const { s0: k, s1: E, s2: x, s3: K } = Fs(c, p, w, g, h);
2195
+ u[d++] = k ^ y, u[d++] = E ^ m, u[d++] = x ^ S, u[d++] = K ^ U;
2196
2196
  }
2197
2197
  return c.fill(0), Ys(l, i);
2198
2198
  }
@@ -2207,7 +2207,7 @@ function Wt(e) {
2207
2207
  }
2208
2208
  const Xe = 64, no = 16, kr = 2 ** 32 - 1, jn = new Uint32Array();
2209
2209
  function ro(e, t, n, r, i, s, o, c) {
2210
- const a = i.length, l = new Uint8Array(Xe), f = F(l), u = Wt(i) && Wt(s), y = u ? F(i) : jn, w = u ? F(s) : jn;
2210
+ const a = i.length, l = new Uint8Array(Xe), f = F(l), u = Wt(i) && Wt(s), p = u ? F(i) : jn, w = u ? F(s) : jn;
2211
2211
  for (let g = 0; g < a; o++) {
2212
2212
  if (e(t, n, r, f, o, c), o >= kr)
2213
2213
  throw new Error("arx: counter overflow");
@@ -2216,13 +2216,13 @@ function ro(e, t, n, r, i, s, o, c) {
2216
2216
  const d = g / 4;
2217
2217
  if (g % 4 !== 0)
2218
2218
  throw new Error("arx: invalid block position");
2219
- for (let p = 0, m; p < no; p++)
2220
- m = d + p, w[m] = y[m] ^ f[p];
2219
+ for (let y = 0, m; y < no; y++)
2220
+ m = d + y, w[m] = p[m] ^ f[y];
2221
2221
  g += Xe;
2222
2222
  continue;
2223
2223
  }
2224
- for (let d = 0, p; d < h; d++)
2225
- p = g + d, s[p] = i[p] ^ l[d];
2224
+ for (let d = 0, y; d < h; d++)
2225
+ y = g + d, s[y] = i[y] ^ l[d];
2226
2226
  g += h;
2227
2227
  }
2228
2228
  }
@@ -2232,11 +2232,11 @@ function io(e, t) {
2232
2232
  throw new Error("core must be a function");
2233
2233
  return Bt(i), Bt(o), Dn(s), Dn(n), (c, a, l, f, u = 0) => {
2234
2234
  ue(c), ue(a), ue(l);
2235
- const y = l.length;
2236
- if (f || (f = new Uint8Array(y)), ue(f), Bt(u), u < 0 || u >= kr)
2235
+ const p = l.length;
2236
+ if (f || (f = new Uint8Array(p)), ue(f), Bt(u), u < 0 || u >= kr)
2237
2237
  throw new Error("arx: counter overflow");
2238
- if (f.length < y)
2239
- throw new Error(`arx: output (${f.length}) is shorter than data (${y})`);
2238
+ if (f.length < p)
2239
+ throw new Error(`arx: output (${f.length}) is shorter than data (${p})`);
2240
2240
  const w = [];
2241
2241
  let g = c.length, h, d;
2242
2242
  if (g === 32)
@@ -2246,31 +2246,31 @@ function io(e, t) {
2246
2246
  else
2247
2247
  throw new Error(`arx: invalid 32-byte key, got length=${g}`);
2248
2248
  Wt(a) || (a = a.slice(), w.push(a));
2249
- const p = F(h);
2249
+ const y = F(h);
2250
2250
  if (r) {
2251
2251
  if (a.length !== 24)
2252
2252
  throw new Error("arx: extended nonce must be 24 bytes");
2253
- r(d, p, F(a.subarray(0, 16)), p), a = a.subarray(16);
2253
+ r(d, y, F(a.subarray(0, 16)), y), a = a.subarray(16);
2254
2254
  }
2255
2255
  const m = 16 - i;
2256
2256
  if (m !== a.length)
2257
2257
  throw new Error(`arx: nonce must be ${m} or 16 bytes`);
2258
2258
  if (m !== 12) {
2259
- const _ = new Uint8Array(12);
2260
- _.set(a, s ? 0 : 12 - a.length), a = _, w.push(a);
2259
+ const U = new Uint8Array(12);
2260
+ U.set(a, s ? 0 : 12 - a.length), a = U, w.push(a);
2261
2261
  }
2262
2262
  const S = F(a);
2263
- for (ro(e, d, p, S, l, f, u, o); w.length > 0; )
2263
+ for (ro(e, d, y, S, l, f, u, o); w.length > 0; )
2264
2264
  w.pop().fill(0);
2265
2265
  return f;
2266
2266
  };
2267
2267
  }
2268
2268
  function so(e, t, n, r, i, s = 20) {
2269
- let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1], y = t[2], w = t[3], g = t[4], h = t[5], d = t[6], p = t[7], m = i, S = n[0], _ = n[1], k = n[2], E = o, x = c, K = a, M = l, I = f, A = u, R = y, T = w, D = g, b = h, v = d, N = p, B = m, C = S, U = _, O = k;
2269
+ let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1], p = t[2], w = t[3], g = t[4], h = t[5], d = t[6], y = t[7], m = i, S = n[0], U = n[1], k = n[2], E = o, x = c, K = a, M = l, I = f, A = u, R = p, T = w, D = g, b = h, v = d, N = y, B = m, C = S, _ = U, O = k;
2270
2270
  for (let ee = 0; ee < s; ee += 2)
2271
- E = E + I | 0, B = L(B ^ E, 16), D = D + B | 0, I = L(I ^ D, 12), E = E + I | 0, B = L(B ^ E, 8), D = D + B | 0, I = L(I ^ D, 7), x = x + A | 0, C = L(C ^ x, 16), b = b + C | 0, A = L(A ^ b, 12), x = x + A | 0, C = L(C ^ x, 8), b = b + C | 0, A = L(A ^ b, 7), K = K + R | 0, U = L(U ^ K, 16), v = v + U | 0, R = L(R ^ v, 12), K = K + R | 0, U = L(U ^ K, 8), v = v + U | 0, R = L(R ^ v, 7), M = M + T | 0, O = L(O ^ M, 16), N = N + O | 0, T = L(T ^ N, 12), M = M + T | 0, O = L(O ^ M, 8), N = N + O | 0, T = L(T ^ N, 7), E = E + A | 0, O = L(O ^ E, 16), v = v + O | 0, A = L(A ^ v, 12), E = E + A | 0, O = L(O ^ E, 8), v = v + O | 0, A = L(A ^ v, 7), x = x + R | 0, B = L(B ^ x, 16), N = N + B | 0, R = L(R ^ N, 12), x = x + R | 0, B = L(B ^ x, 8), N = N + B | 0, R = L(R ^ N, 7), K = K + T | 0, C = L(C ^ K, 16), D = D + C | 0, T = L(T ^ D, 12), K = K + T | 0, C = L(C ^ K, 8), D = D + C | 0, T = L(T ^ D, 7), M = M + I | 0, U = L(U ^ M, 16), b = b + U | 0, I = L(I ^ b, 12), M = M + I | 0, U = L(U ^ M, 8), b = b + U | 0, I = L(I ^ b, 7);
2271
+ E = E + I | 0, B = L(B ^ E, 16), D = D + B | 0, I = L(I ^ D, 12), E = E + I | 0, B = L(B ^ E, 8), D = D + B | 0, I = L(I ^ D, 7), x = x + A | 0, C = L(C ^ x, 16), b = b + C | 0, A = L(A ^ b, 12), x = x + A | 0, C = L(C ^ x, 8), b = b + C | 0, A = L(A ^ b, 7), K = K + R | 0, _ = L(_ ^ K, 16), v = v + _ | 0, R = L(R ^ v, 12), K = K + R | 0, _ = L(_ ^ K, 8), v = v + _ | 0, R = L(R ^ v, 7), M = M + T | 0, O = L(O ^ M, 16), N = N + O | 0, T = L(T ^ N, 12), M = M + T | 0, O = L(O ^ M, 8), N = N + O | 0, T = L(T ^ N, 7), E = E + A | 0, O = L(O ^ E, 16), v = v + O | 0, A = L(A ^ v, 12), E = E + A | 0, O = L(O ^ E, 8), v = v + O | 0, A = L(A ^ v, 7), x = x + R | 0, B = L(B ^ x, 16), N = N + B | 0, R = L(R ^ N, 12), x = x + R | 0, B = L(B ^ x, 8), N = N + B | 0, R = L(R ^ N, 7), K = K + T | 0, C = L(C ^ K, 16), D = D + C | 0, T = L(T ^ D, 12), K = K + T | 0, C = L(C ^ K, 8), D = D + C | 0, T = L(T ^ D, 7), M = M + I | 0, _ = L(_ ^ M, 16), b = b + _ | 0, I = L(I ^ b, 12), M = M + I | 0, _ = L(_ ^ M, 8), b = b + _ | 0, I = L(I ^ b, 7);
2272
2272
  let $ = 0;
2273
- r[$++] = o + E | 0, r[$++] = c + x | 0, r[$++] = a + K | 0, r[$++] = l + M | 0, r[$++] = f + I | 0, r[$++] = u + A | 0, r[$++] = y + R | 0, r[$++] = w + T | 0, r[$++] = g + D | 0, r[$++] = h + b | 0, r[$++] = d + v | 0, r[$++] = p + N | 0, r[$++] = m + B | 0, r[$++] = S + C | 0, r[$++] = _ + U | 0, r[$++] = k + O | 0;
2273
+ r[$++] = o + E | 0, r[$++] = c + x | 0, r[$++] = a + K | 0, r[$++] = l + M | 0, r[$++] = f + I | 0, r[$++] = u + A | 0, r[$++] = p + R | 0, r[$++] = w + T | 0, r[$++] = g + D | 0, r[$++] = h + b | 0, r[$++] = d + v | 0, r[$++] = y + N | 0, r[$++] = m + B | 0, r[$++] = S + C | 0, r[$++] = U + _ | 0, r[$++] = k + O | 0;
2274
2274
  }
2275
2275
  const Br = /* @__PURE__ */ io(so, {
2276
2276
  counterRight: !1,
@@ -2317,22 +2317,22 @@ dt.create = (e, t) => new Ir(e, t);
2317
2317
  function rn(e, t, n) {
2318
2318
  return se.hash(e), n === void 0 && (n = new Uint8Array(e.outputLen)), dt(e, Je(n), Je(t));
2319
2319
  }
2320
- const _t = new Uint8Array([0]), zn = new Uint8Array();
2321
- function _r(e, t, n, r = 32) {
2320
+ const Ut = new Uint8Array([0]), zn = new Uint8Array();
2321
+ function Ur(e, t, n, r = 32) {
2322
2322
  if (se.hash(e), se.number(r), r > 255 * e.outputLen)
2323
2323
  throw new Error("Length should be <= 255*HashLen");
2324
2324
  const i = Math.ceil(r / e.outputLen);
2325
2325
  n === void 0 && (n = zn);
2326
2326
  const s = new Uint8Array(i * e.outputLen), o = dt.create(e, t), c = o._cloneInto(), a = new Uint8Array(o.outputLen);
2327
2327
  for (let l = 0; l < i; l++)
2328
- _t[0] = l + 1, c.update(l === 0 ? zn : a).update(n).update(_t).digestInto(a), s.set(a, e.outputLen * l), o._cloneInto(c);
2329
- return o.destroy(), c.destroy(), a.fill(0), _t.fill(0), s.slice(0, r);
2328
+ Ut[0] = l + 1, c.update(l === 0 ? zn : a).update(n).update(Ut).digestInto(a), s.set(a, e.outputLen * l), o._cloneInto(c);
2329
+ return o.destroy(), c.destroy(), a.fill(0), Ut.fill(0), s.slice(0, r);
2330
2330
  }
2331
2331
  var oo = Object.defineProperty, H = (e, t) => {
2332
2332
  for (var n in t)
2333
2333
  oo(e, n, { get: t[n], enumerable: !0 });
2334
2334
  }, Te = Symbol("verified"), ao = (e) => e instanceof Object;
2335
- function pt(e) {
2335
+ function yt(e) {
2336
2336
  if (!ao(e) || typeof e.kind != "number" || typeof e.content != "string" || typeof e.created_at != "number" || typeof e.pubkey != "string" || !e.pubkey.match(/^[a-f0-9]{64}$/) || !Array.isArray(e.tags))
2337
2337
  return !1;
2338
2338
  for (let t = 0; t < e.tags.length; t++) {
@@ -2348,7 +2348,7 @@ function pt(e) {
2348
2348
  var co = {};
2349
2349
  H(co, {
2350
2350
  Queue: () => ho,
2351
- QueueNode: () => Ur,
2351
+ QueueNode: () => _r,
2352
2352
  binarySearch: () => sn,
2353
2353
  bytesToHex: () => P,
2354
2354
  hexToBytes: () => j,
@@ -2386,7 +2386,7 @@ function sn(e, t) {
2386
2386
  }
2387
2387
  return [n, !1];
2388
2388
  }
2389
- var Ur = class {
2389
+ var _r = class {
2390
2390
  constructor(e) {
2391
2391
  J(this, "value");
2392
2392
  J(this, "next", null);
@@ -2400,7 +2400,7 @@ var Ur = class {
2400
2400
  this.first = null, this.last = null;
2401
2401
  }
2402
2402
  enqueue(e) {
2403
- const t = new Ur(e);
2403
+ const t = new _r(e);
2404
2404
  return this.last ? this.last === this.first ? (this.last = t, this.last.prev = this.first, this.first.next = t) : (t.prev = this.last, this.last.next = t, this.last = t) : (this.first = t, this.last = t), !0;
2405
2405
  }
2406
2406
  dequeue() {
@@ -2413,7 +2413,7 @@ var Ur = class {
2413
2413
  const e = this.first;
2414
2414
  return this.first = e.next, this.first && (this.first.prev = null), e.value;
2415
2415
  }
2416
- }, po = class {
2416
+ }, yo = class {
2417
2417
  generateSecretKey() {
2418
2418
  return Ze.utils.randomPrivateKey();
2419
2419
  }
@@ -2438,18 +2438,18 @@ var Ur = class {
2438
2438
  }
2439
2439
  }
2440
2440
  };
2441
- function yo(e) {
2442
- if (!pt(e))
2441
+ function po(e) {
2442
+ if (!yt(e))
2443
2443
  throw new Error("can't serialize event with wrong or missing properties");
2444
2444
  return JSON.stringify([0, e.pubkey, e.created_at, e.kind, e.tags, e.content]);
2445
2445
  }
2446
2446
  function De(e) {
2447
- let t = fe(ne.encode(yo(e)));
2447
+ let t = fe(ne.encode(po(e)));
2448
2448
  return P(t);
2449
2449
  }
2450
- var yt = new po(), Be = yt.generateSecretKey, ae = yt.getPublicKey, Q = yt.finalizeEvent, gt = yt.verifyEvent, go = {};
2450
+ var pt = new yo(), Be = pt.generateSecretKey, ae = pt.getPublicKey, Q = pt.finalizeEvent, gt = pt.verifyEvent, go = {};
2451
2451
  H(go, {
2452
- Application: () => ya,
2452
+ Application: () => pa,
2453
2453
  BadgeAward: () => No,
2454
2454
  BadgeDefinition: () => ca,
2455
2455
  BlockedRelaysList: () => Vo,
@@ -2466,7 +2466,7 @@ H(go, {
2466
2466
  ClientAuth: () => zr,
2467
2467
  CommunitiesList: () => zo,
2468
2468
  CommunityDefinition: () => Aa,
2469
- CommunityPostApproval: () => Uo,
2469
+ CommunityPostApproval: () => _o,
2470
2470
  Contacts: () => Eo,
2471
2471
  CreateOrUpdateProduct: () => fa,
2472
2472
  CreateOrUpdateStall: () => la,
@@ -2475,7 +2475,7 @@ H(go, {
2475
2475
  DirectMessageRelaysList: () => Jo,
2476
2476
  DraftClassifiedListing: () => va,
2477
2477
  DraftLong: () => da,
2478
- Emojisets: () => pa,
2478
+ Emojisets: () => ya,
2479
2479
  EncryptedDirectMessage: () => xo,
2480
2480
  EventDeletion: () => Ko,
2481
2481
  FileMetadata: () => Ao,
@@ -2493,7 +2493,7 @@ H(go, {
2493
2493
  JobFeedback: () => Ro,
2494
2494
  JobRequest: () => Lo,
2495
2495
  JobResult: () => $o,
2496
- Label: () => _o,
2496
+ Label: () => Uo,
2497
2497
  LightningPubRPC: () => Qo,
2498
2498
  LiveChatMessage: () => Co,
2499
2499
  LiveEvent: () => ga,
@@ -2550,15 +2550,15 @@ function wo(e) {
2550
2550
  }
2551
2551
  function bo(e, t) {
2552
2552
  const n = t instanceof Array ? t : [t];
2553
- return pt(e) && n.includes(e.kind) || !1;
2553
+ return yt(e) && n.includes(e.kind) || !1;
2554
2554
  }
2555
- var vo = 0, Rr = 1, mo = 2, Eo = 3, xo = 4, Ko = 5, cn = 6, un = 7, No = 8, Tr = 13, Or = 14, ln = 16, Mr = 40, Pr = 41, Hr = 42, Dr = 43, qr = 44, So = 1040, jr = 1059, Ao = 1063, Co = 1311, ko = 1971, Bo = 1984, Io = 1984, _o = 1985, Uo = 4550, Lo = 5999, $o = 6999, Ro = 7e3, To = 9041, Oo = 9734, Mo = 9735, Po = 9802, Ho = 1e4, Do = 10001, qo = 10002, jo = 10003, zo = 10004, Wo = 10005, Vo = 10006, Zo = 10007, Fo = 10015, Go = 10030, Jo = 10050, Yo = 10096, Xo = 13194, Qo = 21e3, zr = 22242, Wr = 23194, ea = 23195, ta = 24133, fn = 27235, na = 3e4, ra = 30001, ia = 30002, sa = 30003, oa = 30004, aa = 30008, ca = 30009, ua = 30015, la = 30017, fa = 30018, ha = 30023, da = 30024, pa = 30030, ya = 30078, ga = 30311, wa = 30315, ba = 30402, va = 30403, ma = 31922, Ea = 31923, xa = 31924, Ka = 31925, Na = 31989, Sa = 31990, Aa = 34550, Ca = {};
2555
+ var vo = 0, Rr = 1, mo = 2, Eo = 3, xo = 4, Ko = 5, cn = 6, un = 7, No = 8, Tr = 13, Or = 14, ln = 16, Mr = 40, Pr = 41, Hr = 42, Dr = 43, qr = 44, So = 1040, jr = 1059, Ao = 1063, Co = 1311, ko = 1971, Bo = 1984, Io = 1984, Uo = 1985, _o = 4550, Lo = 5999, $o = 6999, Ro = 7e3, To = 9041, Oo = 9734, Mo = 9735, Po = 9802, Ho = 1e4, Do = 10001, qo = 10002, jo = 10003, zo = 10004, Wo = 10005, Vo = 10006, Zo = 10007, Fo = 10015, Go = 10030, Jo = 10050, Yo = 10096, Xo = 13194, Qo = 21e3, zr = 22242, Wr = 23194, ea = 23195, ta = 24133, fn = 27235, na = 3e4, ra = 30001, ia = 30002, sa = 30003, oa = 30004, aa = 30008, ca = 30009, ua = 30015, la = 30017, fa = 30018, ha = 30023, da = 30024, ya = 30030, pa = 30078, ga = 30311, wa = 30315, ba = 30402, va = 30403, ma = 31922, Ea = 31923, xa = 31924, Ka = 31925, Na = 31989, Sa = 31990, Aa = 34550, Ca = {};
2556
2556
  H(Ca, {
2557
2557
  getHex64: () => hn,
2558
2558
  getInt: () => Vr,
2559
2559
  getSubscriptionId: () => ka,
2560
2560
  matchEventId: () => Ba,
2561
- matchEventKind: () => _a,
2561
+ matchEventKind: () => Ua,
2562
2562
  matchEventPubkey: () => Ia
2563
2563
  });
2564
2564
  function hn(e, t) {
@@ -2588,11 +2588,11 @@ function Ba(e, t) {
2588
2588
  function Ia(e, t) {
2589
2589
  return t === hn(e, "pubkey");
2590
2590
  }
2591
- function _a(e, t) {
2591
+ function Ua(e, t) {
2592
2592
  return t === Vr(e, "kind");
2593
2593
  }
2594
- var Ua = {};
2595
- H(Ua, {
2594
+ var _a = {};
2595
+ H(_a, {
2596
2596
  makeAuthEvent: () => La
2597
2597
  });
2598
2598
  function La(e, t) {
@@ -2656,7 +2656,7 @@ function wt(e) {
2656
2656
  let { prefix: t, words: n } = ze.decode(e, dn), r = new Uint8Array(ze.fromWords(n));
2657
2657
  switch (t) {
2658
2658
  case "nprofile": {
2659
- let u = Ut(r);
2659
+ let u = _t(r);
2660
2660
  if (!((i = u[0]) != null && i[0]))
2661
2661
  throw new Error("missing TLV 0 for nprofile");
2662
2662
  if (u[0][0].length !== 32)
@@ -2665,12 +2665,12 @@ function wt(e) {
2665
2665
  type: "nprofile",
2666
2666
  data: {
2667
2667
  pubkey: P(u[0][0]),
2668
- relays: u[1] ? u[1].map((y) => le.decode(y)) : []
2668
+ relays: u[1] ? u[1].map((p) => le.decode(p)) : []
2669
2669
  }
2670
2670
  };
2671
2671
  }
2672
2672
  case "nevent": {
2673
- let u = Ut(r);
2673
+ let u = _t(r);
2674
2674
  if (!((s = u[0]) != null && s[0]))
2675
2675
  throw new Error("missing TLV 0 for nevent");
2676
2676
  if (u[0][0].length !== 32)
@@ -2683,14 +2683,14 @@ function wt(e) {
2683
2683
  type: "nevent",
2684
2684
  data: {
2685
2685
  id: P(u[0][0]),
2686
- relays: u[1] ? u[1].map((y) => le.decode(y)) : [],
2686
+ relays: u[1] ? u[1].map((p) => le.decode(p)) : [],
2687
2687
  author: (o = u[2]) != null && o[0] ? P(u[2][0]) : void 0,
2688
2688
  kind: (c = u[3]) != null && c[0] ? parseInt(P(u[3][0]), 16) : void 0
2689
2689
  }
2690
2690
  };
2691
2691
  }
2692
2692
  case "naddr": {
2693
- let u = Ut(r);
2693
+ let u = _t(r);
2694
2694
  if (!((a = u[0]) != null && a[0]))
2695
2695
  throw new Error("missing TLV 0 for naddr");
2696
2696
  if (!((l = u[2]) != null && l[0]))
@@ -2707,7 +2707,7 @@ function wt(e) {
2707
2707
  identifier: le.decode(u[0][0]),
2708
2708
  pubkey: P(u[2][0]),
2709
2709
  kind: parseInt(P(u[3][0]), 16),
2710
- relays: u[1] ? u[1].map((y) => le.decode(y)) : []
2710
+ relays: u[1] ? u[1].map((p) => le.decode(p)) : []
2711
2711
  }
2712
2712
  };
2713
2713
  }
@@ -2720,7 +2720,7 @@ function wt(e) {
2720
2720
  throw new Error(`unknown prefix ${t}`);
2721
2721
  }
2722
2722
  }
2723
- function Ut(e) {
2723
+ function _t(e) {
2724
2724
  let t = {}, n = e;
2725
2725
  for (; n.length > 0; ) {
2726
2726
  let r = n[0], i = n[1], s = n.slice(2, 2 + i);
@@ -2747,7 +2747,7 @@ function vt(e, t) {
2747
2747
  return bt(e, t);
2748
2748
  }
2749
2749
  function ja(e) {
2750
- let t = pn({
2750
+ let t = yn({
2751
2751
  0: [j(e.pubkey)],
2752
2752
  1: (e.relays || []).map((n) => ne.encode(n))
2753
2753
  });
@@ -2756,7 +2756,7 @@ function ja(e) {
2756
2756
  function za(e) {
2757
2757
  let t;
2758
2758
  e.kind !== void 0 && (t = Ma(e.kind));
2759
- let n = pn({
2759
+ let n = yn({
2760
2760
  0: [j(e.id)],
2761
2761
  1: (e.relays || []).map((r) => ne.encode(r)),
2762
2762
  2: e.author ? [j(e.author)] : [],
@@ -2767,7 +2767,7 @@ function za(e) {
2767
2767
  function Wa(e) {
2768
2768
  let t = new ArrayBuffer(4);
2769
2769
  new DataView(t).setUint32(0, e.kind, !1);
2770
- let n = pn({
2770
+ let n = yn({
2771
2771
  0: [ne.encode(e.identifier)],
2772
2772
  1: (e.relays || []).map((r) => ne.encode(r)),
2773
2773
  2: [j(e.pubkey)],
@@ -2775,7 +2775,7 @@ function Wa(e) {
2775
2775
  });
2776
2776
  return bt("naddr", n);
2777
2777
  }
2778
- function pn(e) {
2778
+ function yn(e) {
2779
2779
  let t = [];
2780
2780
  return Object.entries(e).reverse().forEach(([n, r]) => {
2781
2781
  r.forEach((i) => {
@@ -2790,13 +2790,13 @@ H(Va, {
2790
2790
  encrypt: () => Fr
2791
2791
  });
2792
2792
  function Fr(e, t, n) {
2793
- const r = e instanceof Uint8Array ? P(e) : e, i = _e.getSharedSecret(r, "02" + t), s = Gr(i);
2794
- let o = Uint8Array.from(yr(16)), c = ne.encode(n), a = Sr(s, o).encrypt(c), l = he.encode(new Uint8Array(a)), f = he.encode(new Uint8Array(o.buffer));
2793
+ const r = e instanceof Uint8Array ? P(e) : e, i = Ue.getSharedSecret(r, "02" + t), s = Gr(i);
2794
+ let o = Uint8Array.from(pr(16)), c = ne.encode(n), a = Sr(s, o).encrypt(c), l = he.encode(new Uint8Array(a)), f = he.encode(new Uint8Array(o.buffer));
2795
2795
  return `${l}?iv=${f}`;
2796
2796
  }
2797
2797
  function Za(e, t, n) {
2798
2798
  const r = e instanceof Uint8Array ? P(e) : e;
2799
- let [i, s] = n.split("?iv="), o = _e.getSharedSecret(r, "02" + t), c = Gr(o), a = he.decode(s), l = he.decode(i), f = Sr(c, a).decrypt(l);
2799
+ let [i, s] = n.split("?iv="), o = Ue.getSharedSecret(r, "02" + t), c = Gr(o), a = he.decode(s), l = he.decode(i), f = Sr(c, a).decrypt(l);
2800
2800
  return le.decode(f);
2801
2801
  }
2802
2802
  function Gr(e) {
@@ -2804,14 +2804,14 @@ function Gr(e) {
2804
2804
  }
2805
2805
  var Fa = {};
2806
2806
  H(Fa, {
2807
- NIP05_REGEX: () => yn,
2807
+ NIP05_REGEX: () => pn,
2808
2808
  isNip05: () => Ga,
2809
2809
  isValid: () => Xa,
2810
2810
  queryProfile: () => Jr,
2811
2811
  searchDomain: () => Ya,
2812
2812
  useFetchImplementation: () => Ja
2813
2813
  });
2814
- var yn = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/, Ga = (e) => yn.test(e || ""), mt;
2814
+ var pn = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/, Ga = (e) => pn.test(e || ""), mt;
2815
2815
  try {
2816
2816
  mt = fetch;
2817
2817
  } catch {
@@ -2831,7 +2831,7 @@ async function Ya(e, t = "") {
2831
2831
  }
2832
2832
  async function Jr(e) {
2833
2833
  var i;
2834
- const t = e.match(yn);
2834
+ const t = e.match(pn);
2835
2835
  if (!t)
2836
2836
  return null;
2837
2837
  const [, n = "_", r] = t;
@@ -2987,7 +2987,7 @@ H(ac, {
2987
2987
  unwrapEvent: () => mn,
2988
2988
  unwrapManyEvents: () => fi,
2989
2989
  wrapEvent: () => st,
2990
- wrapManyEvents: () => pc
2990
+ wrapManyEvents: () => yc
2991
2991
  });
2992
2992
  var q = {};
2993
2993
  H(q, {
@@ -2998,11 +2998,11 @@ H(q, {
2998
2998
  });
2999
2999
  var ei = 1, ti = 65535;
3000
3000
  function gn(e, t) {
3001
- const n = _e.getSharedSecret(e, "02" + t).subarray(1, 33);
3001
+ const n = Ue.getSharedSecret(e, "02" + t).subarray(1, 33);
3002
3002
  return rn(fe, n, "nip44-v2");
3003
3003
  }
3004
3004
  function ni(e, t) {
3005
- const n = _r(fe, e, t, 76);
3005
+ const n = Ur(fe, e, t, 76);
3006
3006
  return {
3007
3007
  chacha_key: n.subarray(0, 32),
3008
3008
  chacha_nonce: n.subarray(32, 44),
@@ -3065,7 +3065,7 @@ function fc(e) {
3065
3065
  mac: n.subarray(-32)
3066
3066
  };
3067
3067
  }
3068
- function bn(e, t, n = yr(32)) {
3068
+ function bn(e, t, n = pr(32)) {
3069
3069
  const { chacha_key: r, chacha_nonce: i, hmac_key: s } = ni(t, n), o = uc(e), c = Br(r, i, o), a = ri(s, c, n);
3070
3070
  return he.encode(ft(new Uint8Array([2]), n, c, a));
3071
3071
  }
@@ -3121,7 +3121,7 @@ function st(e, t, n) {
3121
3121
  const r = ci(e, t), i = ui(r, t, n);
3122
3122
  return li(i, n);
3123
3123
  }
3124
- function pc(e, t, n) {
3124
+ function yc(e, t, n) {
3125
3125
  if (!n || n.length === 0)
3126
3126
  throw new Error("At least one recipient is required.");
3127
3127
  const r = ae(t), i = [st(e, t, r)];
@@ -3139,7 +3139,7 @@ function fi(e, t) {
3139
3139
  n.push(mn(r, t));
3140
3140
  }), n.sort((r, i) => r.created_at - i.created_at), n;
3141
3141
  }
3142
- function yc(e, t, n, r) {
3142
+ function pc(e, t, n, r) {
3143
3143
  const i = {
3144
3144
  created_at: Math.ceil(Date.now() / 1e3),
3145
3145
  kind: Or,
@@ -3151,7 +3151,7 @@ function yc(e, t, n, r) {
3151
3151
  }), r && i.tags.push(["e", r.eventId, r.relayUrl || "", "reply"]), n && i.tags.push(["subject", n]), i;
3152
3152
  }
3153
3153
  function hi(e, t, n, r, i) {
3154
- const s = yc(t, n, r, i);
3154
+ const s = pc(t, n, r, i);
3155
3155
  return st(s, e, t.publicKey);
3156
3156
  }
3157
3157
  function gc(e, t, n, r, i) {
@@ -3337,15 +3337,15 @@ function* Ic(e) {
3337
3337
  }
3338
3338
  n !== t && (yield { type: "text", text: e.substring(n) });
3339
3339
  }
3340
- var _c = {};
3341
- H(_c, {
3342
- channelCreateEvent: () => Uc,
3340
+ var Uc = {};
3341
+ H(Uc, {
3342
+ channelCreateEvent: () => _c,
3343
3343
  channelHideMessageEvent: () => Rc,
3344
3344
  channelMessageEvent: () => $c,
3345
3345
  channelMetadataEvent: () => Lc,
3346
3346
  channelMuteUserEvent: () => Tc
3347
3347
  });
3348
- var Uc = (e, t) => {
3348
+ var _c = (e, t) => {
3349
3349
  let n;
3350
3350
  if (typeof e.content == "object")
3351
3351
  n = JSON.stringify(e.content);
@@ -3426,12 +3426,12 @@ var Uc = (e, t) => {
3426
3426
  );
3427
3427
  }, Oc = {};
3428
3428
  H(Oc, {
3429
- EMOJI_SHORTCODE_REGEX: () => pi,
3429
+ EMOJI_SHORTCODE_REGEX: () => yi,
3430
3430
  matchAll: () => Mc,
3431
3431
  regex: () => xn,
3432
3432
  replaceAll: () => Pc
3433
3433
  });
3434
- var pi = /:(\w+):/, xn = () => new RegExp(`\\B${pi.source}\\B`, "g");
3434
+ var yi = /:(\w+):/, xn = () => new RegExp(`\\B${yi.source}\\B`, "g");
3435
3435
  function* Mc(e) {
3436
3436
  const t = e.matchAll(xn());
3437
3437
  for (const n of t)
@@ -3572,7 +3572,7 @@ function Xc(e) {
3572
3572
  } catch {
3573
3573
  return "Invalid zap request JSON.";
3574
3574
  }
3575
- if (!pt(t))
3575
+ if (!yt(t))
3576
3576
  return "Zap request is not a valid Nostr event.";
3577
3577
  if (!gt(t))
3578
3578
  return "Invalid signature on zap request.";
@@ -3642,7 +3642,7 @@ H(tu, {
3642
3642
  validateEventUrlTag: () => vi,
3643
3643
  validateToken: () => ru
3644
3644
  });
3645
- var yi = "Nostr ";
3645
+ var pi = "Nostr ";
3646
3646
  async function nu(e, t, n, r = !1, i) {
3647
3647
  const s = {
3648
3648
  kind: fn,
@@ -3655,7 +3655,7 @@ async function nu(e, t, n, r = !1, i) {
3655
3655
  };
3656
3656
  i && s.tags.push(["payload", Sn(i)]);
3657
3657
  const o = await n(s);
3658
- return (r ? yi : "") + he.encode(ne.encode(JSON.stringify(o)));
3658
+ return (r ? pi : "") + he.encode(ne.encode(JSON.stringify(o)));
3659
3659
  }
3660
3660
  async function ru(e, t, n) {
3661
3661
  const r = await gi(e).catch((s) => {
@@ -3668,7 +3668,7 @@ async function ru(e, t, n) {
3668
3668
  async function gi(e) {
3669
3669
  if (!e)
3670
3670
  throw new Error("Missing token");
3671
- e = e.replace(yi, "");
3671
+ e = e.replace(pi, "");
3672
3672
  const t = le.decode(he.decode(e));
3673
3673
  if (!t || t.length === 0 || !t.startsWith("{"))
3674
3674
  throw new Error("Invalid token");
@@ -3714,8 +3714,8 @@ async function xi(e, t, n, r) {
3714
3714
  throw new Error("Invalid nostr event, payload tag does not match request body hash");
3715
3715
  return !0;
3716
3716
  }
3717
- const Oe = 1060, Lt = 30078, Zn = 1059, iu = 14, wu = 100, su = 1;
3718
- function bu(e) {
3717
+ const Oe = 1060, Lt = 30078, Zn = 1059, iu = 14, bu = 100, su = 1;
3718
+ function vu(e) {
3719
3719
  return JSON.stringify({
3720
3720
  version: su,
3721
3721
  rootKey: P(e.rootKey),
@@ -3750,7 +3750,7 @@ function bu(e) {
3750
3750
  )
3751
3751
  });
3752
3752
  }
3753
- function vu(e) {
3753
+ function mu(e) {
3754
3754
  const t = JSON.parse(e);
3755
3755
  if (!t.version) {
3756
3756
  const n = {};
@@ -3813,7 +3813,38 @@ function vu(e) {
3813
3813
  )
3814
3814
  };
3815
3815
  }
3816
- async function* mu(e) {
3816
+ function ou(e) {
3817
+ return {
3818
+ rootKey: new Uint8Array(e.rootKey),
3819
+ theirCurrentNostrPublicKey: e.theirCurrentNostrPublicKey,
3820
+ theirNextNostrPublicKey: e.theirNextNostrPublicKey,
3821
+ ourCurrentNostrKey: e.ourCurrentNostrKey ? {
3822
+ publicKey: e.ourCurrentNostrKey.publicKey,
3823
+ privateKey: new Uint8Array(e.ourCurrentNostrKey.privateKey)
3824
+ } : void 0,
3825
+ ourNextNostrKey: {
3826
+ publicKey: e.ourNextNostrKey.publicKey,
3827
+ privateKey: new Uint8Array(e.ourNextNostrKey.privateKey)
3828
+ },
3829
+ receivingChainKey: e.receivingChainKey ? new Uint8Array(e.receivingChainKey) : void 0,
3830
+ sendingChainKey: e.sendingChainKey ? new Uint8Array(e.sendingChainKey) : void 0,
3831
+ sendingChainMessageNumber: e.sendingChainMessageNumber,
3832
+ receivingChainMessageNumber: e.receivingChainMessageNumber,
3833
+ previousSendingChainMessageCount: e.previousSendingChainMessageCount,
3834
+ skippedKeys: Object.fromEntries(
3835
+ Object.entries(e.skippedKeys).map(([t, n]) => [
3836
+ t,
3837
+ {
3838
+ headerKeys: n.headerKeys.map((r) => new Uint8Array(r)),
3839
+ messageKeys: Object.fromEntries(
3840
+ Object.entries(n.messageKeys).map(([r, i]) => [r, new Uint8Array(i)])
3841
+ )
3842
+ }
3843
+ ])
3844
+ )
3845
+ };
3846
+ }
3847
+ async function* Eu(e) {
3817
3848
  const t = [];
3818
3849
  let n = null;
3819
3850
  const r = e.onEvent((i) => {
@@ -3831,18 +3862,18 @@ async function* mu(e) {
3831
3862
  function Me(e, t = new Uint8Array(32), n = 1) {
3832
3863
  const r = rn(fe, e, t), i = [];
3833
3864
  for (let s = 1; s <= n; s++)
3834
- i.push(_r(fe, r, new Uint8Array([s]), 32));
3865
+ i.push(Ur(fe, r, new Uint8Array([s]), 32));
3835
3866
  return i;
3836
3867
  }
3837
- function Eu(e, t) {
3868
+ function xu(e, t) {
3838
3869
  return `${e}:${t}`;
3839
3870
  }
3840
- function xu(e) {
3871
+ function Ku(e) {
3841
3872
  var n;
3842
3873
  const t = (n = e.tags) == null ? void 0 : n.find((r) => r[0] === "ms");
3843
3874
  return t ? parseInt(t[1]) : e.created_at * 1e3;
3844
3875
  }
3845
- const ou = 1e3, au = "0000000000000000000000000000000000000000000000000000000000000000";
3876
+ const au = 1e3, cu = "0000000000000000000000000000000000000000000000000000000000000000";
3846
3877
  class ot {
3847
3878
  // 1. CHANNEL PUBLIC INTERFACE
3848
3879
  constructor(t, n) {
@@ -3877,7 +3908,7 @@ class ot {
3877
3908
  publicKey: ae(r),
3878
3909
  privateKey: r
3879
3910
  });
3880
- const y = {
3911
+ const p = {
3881
3912
  rootKey: a,
3882
3913
  theirNextNostrPublicKey: n,
3883
3914
  ourCurrentNostrKey: f,
@@ -3888,7 +3919,7 @@ class ot {
3888
3919
  receivingChainMessageNumber: 0,
3889
3920
  previousSendingChainMessageCount: 0,
3890
3921
  skippedKeys: {}
3891
- }, w = new ot(t, y);
3922
+ }, w = new ot(t, p);
3892
3923
  return o && (w.name = o), w;
3893
3924
  }
3894
3925
  /**
@@ -3922,7 +3953,7 @@ class ot {
3922
3953
  kind: t.kind || Oe,
3923
3954
  created_at: t.created_at || Math.floor(n / 1e3),
3924
3955
  tags: t.tags || [],
3925
- pubkey: t.pubkey || au
3956
+ pubkey: t.pubkey || cu
3926
3957
  };
3927
3958
  r.tags.some(([l]) => l === "ms") || r.tags.push(["ms", String(n)]), r.id = De(r);
3928
3959
  const [i, s] = this.ratchetEncrypt(JSON.stringify(r)), o = q.getConversationKey(this.state.ourCurrentNostrKey.privateKey, this.state.theirNextNostrPublicKey), c = q.encrypt(JSON.stringify(i), o);
@@ -3980,7 +4011,7 @@ class ot {
3980
4011
  // 3. MESSAGE KEY FUNCTIONS
3981
4012
  skipMessageKeys(t, n) {
3982
4013
  if (!(t <= this.state.receivingChainMessageNumber)) {
3983
- if (t > this.state.receivingChainMessageNumber + ou)
4014
+ if (t > this.state.receivingChainMessageNumber + au)
3984
4015
  throw new Error("Too many skipped messages");
3985
4016
  if (!this.state.skippedKeys[n]) {
3986
4017
  if (this.state.skippedKeys[n] = {
@@ -4030,24 +4061,32 @@ class ot {
4030
4061
  throw new Error("Failed to decrypt header with current and skipped header keys");
4031
4062
  }
4032
4063
  handleNostrEvent(t) {
4033
- var n, r;
4064
+ var i, s;
4065
+ const n = ou(this.state);
4066
+ let r = !1;
4034
4067
  try {
4035
- const [i, s, o] = this.decryptHeader(t);
4036
- if (!o)
4037
- this.state.theirNextNostrPublicKey !== i.nextPublicKey && (this.state.theirCurrentNostrPublicKey = this.state.theirNextNostrPublicKey, this.state.theirNextNostrPublicKey = i.nextPublicKey, (n = this.nostrUnsubscribe) == null || n.call(this), this.nostrUnsubscribe = this.nostrNextUnsubscribe, this.nostrNextUnsubscribe = this.nostrSubscribe(
4038
- { authors: [this.state.theirNextNostrPublicKey], kinds: [Oe] },
4039
- (l) => this.handleNostrEvent(l)
4040
- )), s && (this.skipMessageKeys(i.previousChainLength, t.pubkey), this.ratchetStep());
4041
- else if (!((r = this.state.skippedKeys[t.pubkey]) != null && r.messageKeys[i.number]))
4068
+ const [o, c, a] = this.decryptHeader(t);
4069
+ if (!a && this.state.theirNextNostrPublicKey !== o.nextPublicKey && (this.state.theirCurrentNostrPublicKey = this.state.theirNextNostrPublicKey, this.state.theirNextNostrPublicKey = o.nextPublicKey, r = !0), !a)
4070
+ c && (this.skipMessageKeys(o.previousChainLength, t.pubkey), this.ratchetStep());
4071
+ else if (!((i = this.state.skippedKeys[t.pubkey]) != null && i.messageKeys[o.number]))
4042
4072
  return;
4043
- const c = this.ratchetDecrypt(i, t.content, t.pubkey), a = JSON.parse(c);
4044
- if (!pt(a) || a.id !== De(a))
4073
+ const l = this.ratchetDecrypt(o, t.content, t.pubkey), f = JSON.parse(l);
4074
+ if (!yt(f)) {
4075
+ this.state = n;
4045
4076
  return;
4046
- this.internalSubscriptions.forEach((l) => l(a, t));
4047
- } catch (i) {
4048
- if (i instanceof Error && i.message.includes("Failed to decrypt header"))
4077
+ }
4078
+ if (f.id !== De(f)) {
4079
+ this.state = n;
4080
+ return;
4081
+ }
4082
+ r && ((s = this.nostrUnsubscribe) == null || s.call(this), this.nostrUnsubscribe = this.nostrNextUnsubscribe, this.nostrNextUnsubscribe = this.nostrSubscribe(
4083
+ { authors: [this.state.theirNextNostrPublicKey], kinds: [Oe] },
4084
+ (u) => this.handleNostrEvent(u)
4085
+ )), this.internalSubscriptions.forEach((u) => u(f, t));
4086
+ } catch (o) {
4087
+ if (this.state = n, o instanceof Error && (o.message.includes("Failed to decrypt header") || o.message === "invalid MAC"))
4049
4088
  return;
4050
- throw i;
4089
+ throw o;
4051
4090
  }
4052
4091
  }
4053
4092
  subscribeToNostrEvents() {
@@ -4069,10 +4108,10 @@ class ot {
4069
4108
  new TextDecoder("utf-8");
4070
4109
  new TextEncoder();
4071
4110
  function Qe(e, t) {
4072
- const n = _e.getSharedSecret(e, "02" + t).subarray(1, 33);
4111
+ const n = Ue.getSharedSecret(e, "02" + t).subarray(1, 33);
4073
4112
  return rn(fe, n, "nip44-v2");
4074
4113
  }
4075
- const cu = 2 * 24 * 60 * 60, uu = () => Math.round(Date.now() / 1e3), lu = () => Math.round(uu() - Math.random() * cu);
4114
+ const uu = 2 * 24 * 60 * 60, lu = () => Math.round(Date.now() / 1e3), fu = () => Math.round(lu() - Math.random() * uu);
4076
4115
  class Pe {
4077
4116
  constructor(t, n, r, i, s, o, c = []) {
4078
4117
  this.inviterEphemeralPublicKey = t, this.sharedSecret = n, this.inviter = r, this.inviterEphemeralPrivateKey = i, this.deviceId = s, this.maxUses = o, this.usedBy = c;
@@ -4131,7 +4170,7 @@ class Pe {
4131
4170
  const { tags: n } = t;
4132
4171
  if (!n)
4133
4172
  throw new Error("Invalid invite event: missing tags");
4134
- const r = (a = n.find(([y]) => y === "ephemeralKey")) == null ? void 0 : a[1], i = (l = n.find(([y]) => y === "sharedSecret")) == null ? void 0 : l[1], s = t.pubkey, o = (f = n.find(([y]) => y === "d")) == null ? void 0 : f[1], c = (u = o == null ? void 0 : o.split("/")) == null ? void 0 : u[2];
4173
+ const r = (a = n.find(([p]) => p === "ephemeralKey")) == null ? void 0 : a[1], i = (l = n.find(([p]) => p === "sharedSecret")) == null ? void 0 : l[1], s = t.pubkey, o = (f = n.find(([p]) => p === "d")) == null ? void 0 : f[1], c = (u = o == null ? void 0 : o.split("/")) == null ? void 0 : u[2];
4135
4174
  if (!r || !i)
4136
4175
  throw new Error("Invalid invite event: missing session key or sharedSecret");
4137
4176
  return new Pe(
@@ -4247,18 +4286,18 @@ class Pe {
4247
4286
  const s = Be(), o = ae(s), c = this.inviter || this.inviterEphemeralPublicKey, a = j(this.sharedSecret), l = ot.init(t, this.inviterEphemeralPublicKey, s, !0, a, void 0), f = typeof r == "function" ? r : (m, S) => Promise.resolve(q.encrypt(m, Qe(r, S))), u = JSON.stringify({
4248
4287
  sessionKey: o,
4249
4288
  deviceId: i
4250
- }), y = await f(u, c), w = {
4289
+ }), p = await f(u, c), w = {
4251
4290
  pubkey: n,
4252
- content: await q.encrypt(y, a),
4291
+ content: await q.encrypt(p, a),
4253
4292
  created_at: Math.floor(Date.now() / 1e3)
4254
- }, g = JSON.stringify(w), h = Be(), d = ae(h), p = {
4293
+ }, g = JSON.stringify(w), h = Be(), d = ae(h), y = {
4255
4294
  kind: Zn,
4256
4295
  pubkey: d,
4257
4296
  content: q.encrypt(g, Qe(h, this.inviterEphemeralPublicKey)),
4258
- created_at: lu(),
4297
+ created_at: fu(),
4259
4298
  tags: [["p", this.inviterEphemeralPublicKey]]
4260
4299
  };
4261
- return { session: l, event: Q(p, h) };
4300
+ return { session: l, event: Q(y, h) };
4262
4301
  }
4263
4302
  listen(t, n, r) {
4264
4303
  if (!this.inviterEphemeralPrivateKey)
@@ -4273,13 +4312,13 @@ class Pe {
4273
4312
  return;
4274
4313
  const o = await q.decrypt(s.content, Qe(this.inviterEphemeralPrivateKey, s.pubkey)), c = JSON.parse(o), a = j(this.sharedSecret), l = c.pubkey;
4275
4314
  this.usedBy.push(l);
4276
- const f = await q.decrypt(c.content, a), y = await (typeof t == "function" ? t : (p, m) => Promise.resolve(q.decrypt(p, Qe(t, m))))(f, l);
4315
+ const f = await q.decrypt(c.content, a), p = await (typeof t == "function" ? t : (y, m) => Promise.resolve(q.decrypt(y, Qe(t, m))))(f, l);
4277
4316
  let w, g;
4278
4317
  try {
4279
- const p = JSON.parse(y);
4280
- w = p.sessionKey, g = p.deviceId;
4318
+ const y = JSON.parse(p);
4319
+ w = y.sessionKey, g = y.deviceId;
4281
4320
  } catch {
4282
- w = y;
4321
+ w = p;
4283
4322
  }
4284
4323
  const h = s.id, d = ot.init(n, w, this.inviterEphemeralPrivateKey, !1, a, h);
4285
4324
  r(d, l, g);
@@ -4293,13 +4332,14 @@ export {
4293
4332
  Lt as INVITE_EVENT_KIND,
4294
4333
  Zn as INVITE_RESPONSE_KIND,
4295
4334
  Pe as Invite,
4296
- wu as MAX_SKIP,
4335
+ bu as MAX_SKIP,
4297
4336
  Oe as MESSAGE_EVENT_KIND,
4298
4337
  ot as Session,
4299
- mu as createEventStream,
4300
- vu as deserializeSessionState,
4301
- xu as getMillisecondTimestamp,
4338
+ Eu as createEventStream,
4339
+ ou as deepCopyState,
4340
+ mu as deserializeSessionState,
4341
+ Ku as getMillisecondTimestamp,
4302
4342
  Me as kdf,
4303
- bu as serializeSessionState,
4304
- Eu as skippedMessageIndexKey
4343
+ vu as serializeSessionState,
4344
+ xu as skippedMessageIndexKey
4305
4345
  };