nostr-double-ratchet 0.0.33 → 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.
@@ -1,7 +1,7 @@
1
1
  var Ki = Object.defineProperty;
2
2
  var Ni = (e, t, n) => t in e ? Ki(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
3
  var J = (e, t, n) => Ni(e, typeof t != "symbol" ? t + "" : t, n);
4
- function kn(e) {
4
+ function Bn(e) {
5
5
  if (!Number.isSafeInteger(e) || e < 0)
6
6
  throw new Error(`Wrong positive integer: ${e}`);
7
7
  }
@@ -14,7 +14,7 @@ function Fn(e, ...t) {
14
14
  function Si(e) {
15
15
  if (typeof e != "function" || typeof e.create != "function")
16
16
  throw new Error("Hash should be wrapped by utils.wrapConstructor");
17
- kn(e.outputLen), kn(e.blockLen);
17
+ Bn(e.outputLen), Bn(e.blockLen);
18
18
  }
19
19
  function et(e, t = !0) {
20
20
  if (e.destroyed)
@@ -33,17 +33,17 @@ const xt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.
33
33
  const Gn = (e) => e instanceof Uint8Array, Kt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), re = (e, t) => e << 32 - t | e >>> t, Ci = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
34
34
  if (!Ci)
35
35
  throw new Error("Non little-endian hardware is not supported");
36
- function Bi(e) {
36
+ function ki(e) {
37
37
  if (typeof e != "string")
38
38
  throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
39
39
  return new Uint8Array(new TextEncoder().encode(e));
40
40
  }
41
41
  function Vt(e) {
42
- if (typeof e == "string" && (e = Bi(e)), !Gn(e))
42
+ if (typeof e == "string" && (e = ki(e)), !Gn(e))
43
43
  throw new Error(`expected Uint8Array, got ${typeof e}`);
44
44
  return e;
45
45
  }
46
- function ki(...e) {
46
+ function Bi(...e) {
47
47
  const t = new Uint8Array(e.reduce((r, i) => r + i.length, 0));
48
48
  let n = 0;
49
49
  return e.forEach((r) => {
@@ -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
  }
@@ -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) {
@@ -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))
@@ -671,8 +671,8 @@ function is(e, t) {
671
671
  const h = g * a;
672
672
  let d = Number(o & u);
673
673
  o >>= w, d > a && (d -= p, o += St);
674
- const y = h, E = h + Math.abs(d) - 1, S = g % 2 !== 0, _ = d < 0;
675
- d === 0 ? f = f.add(n(S, s[y])) : l = l.add(n(_, s[E]));
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
  },
@@ -722,7 +722,7 @@ function ss(e) {
722
722
  }
723
723
  return Object.freeze({ ...t });
724
724
  }
725
- const { bytesToNumberBE: os, hexToBytes: as } = Vi, Be = {
725
+ const { bytesToNumberBE: os, hexToBytes: as } = Vi, ke = {
726
726
  // asn.1 DER encoding utils
727
727
  Err: class extends Error {
728
728
  constructor(t = "") {
@@ -730,7 +730,7 @@ const { bytesToNumberBE: os, hexToBytes: as } = Vi, Be = {
730
730
  }
731
731
  },
732
732
  _parseInt(e) {
733
- const { Err: t } = Be;
733
+ const { Err: t } = ke;
734
734
  if (e.length < 2 || e[0] !== 2)
735
735
  throw new t("Invalid signature integer tag");
736
736
  const n = e[1], r = e.subarray(2, n + 2);
@@ -743,7 +743,7 @@ const { bytesToNumberBE: os, hexToBytes: as } = Vi, Be = {
743
743
  return { d: os(r), l: e.subarray(n + 2) };
744
744
  },
745
745
  toSig(e) {
746
- const { Err: t } = Be, n = typeof e == "string" ? as(e) : e;
746
+ const { Err: t } = ke, n = typeof e == "string" ? as(e) : e;
747
747
  if (!(n instanceof Uint8Array))
748
748
  throw new Error("ui8a expected");
749
749
  let r = n.length;
@@ -751,7 +751,7 @@ const { bytesToNumberBE: os, hexToBytes: as } = Vi, Be = {
751
751
  throw new t("Invalid signature tag");
752
752
  if (n[1] !== r - 2)
753
753
  throw new t("Invalid signature: incorrect length");
754
- const { d: i, l: s } = Be._parseInt(n.subarray(2)), { d: o, l: c } = Be._parseInt(s);
754
+ const { d: i, l: s } = ke._parseInt(n.subarray(2)), { d: o, l: c } = ke._parseInt(s);
755
755
  if (c.length)
756
756
  throw new t("Invalid signature: left bytes after parsing");
757
757
  return { r: i, s: o };
@@ -776,8 +776,8 @@ function cs(e) {
776
776
  return { x: d, y };
777
777
  });
778
778
  function s(g) {
779
- const { a: h, b: d } = t, y = n.sqr(g), E = n.mul(y, g);
780
- return n.add(n.add(E, n.mul(g, h)), d);
779
+ const { a: h, b: d } = t, y = n.sqr(g), m = n.mul(y, g);
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)))
783
783
  throw new Error("bad generator point: equation left != right");
@@ -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: y, n: E } = 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 y && (S = V(S, E)), 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) {
@@ -825,8 +825,8 @@ function cs(e) {
825
825
  throw new Error("invalid affine point");
826
826
  if (h instanceof u)
827
827
  throw new Error("projective point not allowed");
828
- const E = (S) => n.eql(S, n.ZERO);
829
- return E(d) && E(y) ? u.ZERO : new u(d, y, n.ONE);
828
+ const m = (S) => n.eql(S, n.ZERO);
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;
@@ -842,7 +842,7 @@ function cs(e) {
842
842
  */
843
843
  static normalizeZ(h) {
844
844
  const d = n.invertBatch(h.map((y) => y.pz));
845
- return h.map((y, E) => y.toAffine(d[E])).map(u.fromAffine);
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 y = n.sqr(d), E = s(h);
874
- if (!n.eql(y, E))
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,8 +887,8 @@ function cs(e) {
887
887
  */
888
888
  equals(h) {
889
889
  f(h);
890
- const { px: d, py: y, pz: E } = this, { px: S, py: _, pz: B } = h, m = n.eql(n.mul(d, B), n.mul(S, E)), x = n.eql(n.mul(y, B), n.mul(_, E));
891
- return m && x;
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
+ return E && x;
892
892
  }
893
893
  /**
894
894
  * Flips point to one corresponding to (x, -y) in Affine coordinates.
@@ -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, y = n.mul(d, Ln), { px: E, py: S, pz: _ } = this;
905
- let B = n.ZERO, m = n.ZERO, x = n.ZERO, K = n.mul(E, E), M = n.mul(S, S), I = n.mul(_, _), A = n.mul(E, S);
906
- return A = n.add(A, A), x = n.mul(E, _), x = n.add(x, x), B = n.mul(h, x), m = n.mul(y, I), m = n.add(B, m), B = n.sub(M, m), m = n.add(M, m), m = n.mul(B, m), B = n.mul(A, B), 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), m = n.add(m, K), I = n.mul(S, _), I = n.add(I, I), K = n.mul(I, A), B = n.sub(B, K), x = n.mul(I, M), x = n.add(x, x), x = n.add(x, x), new u(B, m, 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: y, pz: E } = this, { px: S, py: _, pz: B } = h;
915
- let m = n.ZERO, x = n.ZERO, K = n.ZERO;
914
+ const { px: d, py: y, pz: m } = this, { px: S, py: U, pz: k } = h;
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(y, _), T = n.mul(E, B), D = n.add(d, y), b = n.add(S, _);
918
- D = n.mul(D, b), b = n.add(A, R), D = n.sub(D, b), b = n.add(d, E);
919
- let v = n.add(S, B);
920
- return b = n.mul(b, v), v = n.add(A, T), b = n.sub(b, v), v = n.add(y, E), m = n.add(_, B), v = n.mul(v, m), m = n.add(R, T), v = n.sub(v, m), K = n.mul(M, b), m = n.mul(I, T), K = n.add(m, K), m = n.sub(R, K), K = n.add(R, K), x = n.mul(m, 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), m = n.mul(D, m), m = n.sub(m, A), A = n.mul(D, R), K = n.mul(v, K), K = n.add(K, A), new u(m, x, K);
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
+ D = n.mul(D, b), b = n.add(A, R), D = n.sub(D, b), b = n.add(d, m);
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(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 y = n.invertBatch(d.map((E) => E.pz));
931
- return d.map((E, S) => E.toAffine(y[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
  /**
@@ -945,10 +945,10 @@ function cs(e) {
945
945
  const { endo: y } = t;
946
946
  if (!y)
947
947
  return w.unsafeLadder(this, h);
948
- let { k1neg: E, k1: S, k2neg: _, k2: B } = y.splitScalar(h), m = d, x = d, K = this;
949
- for (; S > ce || B > ce; )
950
- S & X && (m = m.add(K)), B & X && (x = x.add(K)), K = K.double(), S >>= X, B >>= X;
951
- return E && (m = m.negate()), _ && (x = x.negate()), x = new u(n.mul(x.px, y.beta), x.py, x.pz), m.add(x);
948
+ let { k1neg: m, k1: S, k2neg: U, k2: k } = y.splitScalar(h), E = d, x = d, K = this;
949
+ for (; S > ce || k > ce; )
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()), 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, y, E;
964
+ let d = h, y, m;
965
965
  const { endo: S } = t;
966
966
  if (S) {
967
- const { k1neg: _, k1: B, k2neg: m, k2: x } = S.splitScalar(d);
968
- let { p: K, f: M } = this.wNAF(B), { p: I, f: A } = this.wNAF(x);
969
- K = w.constTimeNegate(_, K), I = w.constTimeNegate(m, I), I = new u(n.mul(I.px, S.beta), I.py, I.pz), y = K.add(I), E = M.add(A);
967
+ const { k1neg: U, k1: k, k2neg: E, k2: x } = S.splitScalar(d);
968
+ let { p: K, f: M } = this.wNAF(k), { p: I, f: A } = this.wNAF(x);
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: B } = this.wNAF(d);
972
- y = _, E = B;
971
+ const { p: U, f: k } = this.wNAF(d);
972
+ y = U, m = k;
973
973
  }
974
- return u.normalizeZ([y, E])[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.
@@ -980,21 +980,21 @@ function cs(e) {
980
980
  * @returns non-zero affine point
981
981
  */
982
982
  multiplyAndAddUnsafe(h, d, y) {
983
- const E = u.BASE, S = (B, m) => m === ce || m === X || !B.equals(E) ? B.multiplyUnsafe(m) : B.multiply(m), _ = S(this, d).add(S(h, y));
984
- return _.is0() ? void 0 : _;
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: y, pz: E } = this, S = this.is0();
991
- h == null && (h = S ? n.ONE : n.inv(E));
992
- const _ = n.mul(d, h), B = n.mul(y, h), m = n.mul(E, h);
990
+ const { px: d, py: y, pz: m } = this, S = this.is0();
991
+ h == null && (h = S ? n.ONE : n.inv(m));
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
- if (!n.eql(m, n.ONE))
995
+ if (!n.eql(E, n.ONE))
996
996
  throw new Error("invZ was invalid");
997
- return { x: _, y: B };
997
+ return { x: U, y: k };
998
998
  }
999
999
  isTorsionFree() {
1000
1000
  const { h, isTorsionFree: d } = t;
@@ -1051,22 +1051,22 @@ function ls(e) {
1051
1051
  const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: p } = cs({
1052
1052
  ...t,
1053
1053
  toBytes(b, v, N) {
1054
- const k = v.toAffine(), C = n.toBytes(k.x), U = Ie;
1055
- return N ? U(Uint8Array.from([v.hasEvenY() ? 2 : 3]), C) : U(Uint8Array.from([4]), C, n.toBytes(k.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
- const v = b.length, N = b[0], k = b.subarray(1);
1058
+ const v = b.length, N = b[0], B = b.subarray(1);
1059
1059
  if (v === i && (N === 2 || N === 3)) {
1060
- const C = G(k);
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(k.subarray(0, n.BYTES)), U = n.fromBytes(k.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
  }
@@ -1080,8 +1080,8 @@ function ls(e) {
1080
1080
  }
1081
1081
  const d = (b, v, N) => G(b.slice(v, N));
1082
1082
  class y {
1083
- constructor(v, N, k) {
1084
- this.r = v, this.s = N, this.recovery = k, this.assertValidity();
1083
+ constructor(v, N, B) {
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) {
@@ -1091,8 +1091,8 @@ function ls(e) {
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
- const { r: N, s: k } = Be.toSig(Z("DER", v));
1095
- return new y(N, k);
1094
+ const { r: N, s: B } = ke.toSig(Z("DER", v));
1095
+ return new y(N, B);
1096
1096
  }
1097
1097
  assertValidity() {
1098
1098
  if (!p(this.r))
@@ -1104,13 +1104,13 @@ function ls(e) {
1104
1104
  return new y(this.r, this.s, v);
1105
1105
  }
1106
1106
  recoverPublicKey(v) {
1107
- const { r: N, s: k, 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(k * 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;
@@ -1127,7 +1127,7 @@ function ls(e) {
1127
1127
  return je(this.toDERHex());
1128
1128
  }
1129
1129
  toDERHex() {
1130
- return Be.hexFromSig({ r: this.r, s: this.s });
1130
+ return ke.hexFromSig({ r: this.r, s: this.s });
1131
1131
  }
1132
1132
  // padded bytes of r, then padded bytes of s
1133
1133
  toCompactRawBytes() {
@@ -1137,7 +1137,7 @@ function ls(e) {
1137
1137
  return w(this.r) + w(this.s);
1138
1138
  }
1139
1139
  }
1140
- const E = {
1140
+ const m = {
1141
1141
  isValidPrivateKey(b) {
1142
1142
  try {
1143
1143
  return f(b), !0;
@@ -1169,22 +1169,22 @@ function ls(e) {
1169
1169
  function S(b, v = !0) {
1170
1170
  return l.fromPrivateKey(b).toRawBytes(v);
1171
1171
  }
1172
- function _(b) {
1173
- const v = b instanceof Uint8Array, N = typeof b == "string", k = (v || N) && b.length;
1174
- return v ? k === i || k === s : N ? k === 2 * i || k === 2 * s : b instanceof l;
1172
+ function U(b) {
1173
+ const v = b instanceof Uint8Array, N = typeof b == "string", B = (v || N) && b.length;
1174
+ return v ? B === i || B === s : N ? B === 2 * i || B === 2 * s : b instanceof l;
1175
1175
  }
1176
- function B(b, v, N = !0) {
1177
- if (_(b))
1176
+ function k(b, v, N = !0) {
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
  }
1183
- const m = t.bits2int || function(b) {
1183
+ const E = t.bits2int || function(b) {
1184
1184
  const v = G(b), N = b.length * 8 - t.nBitLength;
1185
1185
  return N > 0 ? v >> BigInt(N) : v;
1186
1186
  }, x = t.bits2int_modN || function(b) {
1187
- return c(m(b));
1187
+ return c(E(b));
1188
1188
  }, K = Jt(t.nBitLength);
1189
1189
  function M(b) {
1190
1190
  if (typeof b != "bigint")
@@ -1196,17 +1196,17 @@ function ls(e) {
1196
1196
  function I(b, v, N = A) {
1197
1197
  if (["recovered", "canonical"].some((Ae) => Ae in N))
1198
1198
  throw new Error("sign() legacy options not supported");
1199
- const { hash: k, 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", k(b)));
1202
- const ee = x(b), ge = f(v), Ue = [M(ge), M(ee)];
1199
+ const { hash: B, randomBytes: C } = t;
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
- const Le = m(Ae);
1209
+ const Le = E(Ae);
1210
1210
  if (!p(Le))
1211
1211
  return;
1212
1212
  const An = a(Le), $e = l.BASE.multiply(Le).toAffine(), te = c($e.x);
@@ -1215,30 +1215,30 @@ function ls(e) {
1215
1215
  const Re = c(An * c(we + te * ge));
1216
1216
  if (Re === ce)
1217
1217
  return;
1218
- let Cn = ($e.x === te ? 0 : 2) | Number($e.y & X), Bn = Re;
1219
- return U && g(Re) && (Bn = h(Re), Cn ^= 1), new y(te, Bn, Cn);
1218
+ let Cn = ($e.x === te ? 0 : 2) | Number($e.y & X), kn = Re;
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: k, k2sig: C } = I(b, v, N), U = t;
1226
- return er(U.hash.outputLen, U.nByteLength, U.hmac)(k, 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
- function D(b, v, N, k = R) {
1229
+ function D(b, v, N, B = R) {
1230
1230
  var $e;
1231
1231
  const C = b;
1232
- if (v = Z("msgHash", v), N = Z("publicKey", N), "strict" in k)
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 } = k;
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
1239
  $ = y.fromDER(C);
1240
1240
  } catch (te) {
1241
- if (!(te instanceof Be.Err))
1241
+ if (!(te instanceof ke.Err))
1242
1242
  throw te;
1243
1243
  $ = y.fromCompact(C);
1244
1244
  }
@@ -1253,21 +1253,21 @@ 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 {
1263
1263
  CURVE: t,
1264
1264
  getPublicKey: S,
1265
- getSharedSecret: B,
1265
+ getSharedSecret: k,
1266
1266
  sign: T,
1267
1267
  verify: D,
1268
1268
  ProjectivePoint: l,
1269
1269
  Signature: y,
1270
- utils: E
1270
+ utils: m
1271
1271
  };
1272
1272
  }
1273
1273
  let sr = class extends Jn {
@@ -1311,7 +1311,7 @@ or.create = (e, t) => new sr(e, t);
1311
1311
  function fs(e) {
1312
1312
  return {
1313
1313
  hash: e,
1314
- hmac: (t, ...n) => or(e, t, ki(...n)),
1314
+ hmac: (t, ...n) => or(e, t, Bi(...n)),
1315
1315
  randomBytes: Yn
1316
1316
  };
1317
1317
  }
@@ -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, 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, E = Y(y, c, t) * h % t, S = Y(E, n, t) * f % t, _ = Y(S, o, t) * g % t, B = Y(_, r, t) * l % t, m = Y(B, nt, t);
1326
- if (!Ot.eql(Ot.sqr(m), 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, 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
+ if (!Ot.eql(Ot.sqr(E), e))
1327
1327
  throw new Error("Cannot find square root");
1328
- return m;
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,
@@ -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,7 +1380,7 @@ 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)) {
@@ -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,
@@ -1422,7 +1422,7 @@ const Ze = {
1422
1422
  }
1423
1423
  }, Ct = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
1424
1424
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1425
- const Qt = (e) => e instanceof Uint8Array, Bt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), ie = (e, t) => e << 32 - t | e >>> t, ws = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
1425
+ const Qt = (e) => e instanceof Uint8Array, kt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), ie = (e, t) => e << 32 - t | e >>> t, ws = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
1426
1426
  if (!ws)
1427
1427
  throw new Error("Non little-endian hardware is not supported");
1428
1428
  const bs = Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
@@ -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");
@@ -1530,7 +1530,7 @@ function Ns(e, t, n, r) {
1530
1530
  }
1531
1531
  class Ss extends dr {
1532
1532
  constructor(t, n, r, i) {
1533
- 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 = Bt(this.buffer);
1533
+ 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);
1534
1534
  }
1535
1535
  update(t) {
1536
1536
  se.exists(this);
@@ -1540,7 +1540,7 @@ class Ss extends dr {
1540
1540
  for (let o = 0; o < s; ) {
1541
1541
  const c = Math.min(i - this.pos, s - o);
1542
1542
  if (c === i) {
1543
- const a = Bt(t);
1543
+ const a = kt(t);
1544
1544
  for (; i <= s - o; o += i)
1545
1545
  this.process(a, o);
1546
1546
  continue;
@@ -1557,7 +1557,7 @@ class Ss extends dr {
1557
1557
  for (let u = o; u < i; u++)
1558
1558
  n[u] = 0;
1559
1559
  Ns(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
1560
- const c = Bt(t), a = this.outputLen;
1560
+ const c = kt(t), a = this.outputLen;
1561
1561
  if (a % 4)
1562
1562
  throw new Error("_sha2: outputLen should be aligned to 32bit");
1563
1563
  const l = a / 4, f = this.get();
@@ -1578,7 +1578,7 @@ class Ss extends dr {
1578
1578
  return t.length = i, t.pos = c, t.finished = s, t.destroyed = o, i % n && t.buffer.set(r), t;
1579
1579
  }
1580
1580
  }
1581
- const As = (e, t, n) => e & t ^ ~e & n, Cs = (e, t, n) => e & t ^ e & n ^ t & n, Bs = new Uint32Array([
1581
+ const As = (e, t, n) => e & t ^ ~e & n, Cs = (e, t, n) => e & t ^ e & n ^ t & n, ks = new Uint32Array([
1582
1582
  1116352408,
1583
1583
  1899447441,
1584
1584
  3049323471,
@@ -1674,7 +1674,7 @@ class wr extends Ss {
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 p = ie(c, 6) ^ ie(c, 11) ^ ie(c, 25), w = f + p + As(c, a, l) + Bs[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);
@@ -1686,13 +1686,13 @@ class wr extends Ss {
1686
1686
  this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
1687
1687
  }
1688
1688
  }
1689
- class ks extends wr {
1689
+ class Bs extends wr {
1690
1690
  constructor() {
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 ks());
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;
@@ -1979,22 +1979,22 @@ 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,
1994
1994
  base58xmr: $s
1995
1995
  };
1996
1996
  `${Object.keys(Os).join(", ")}`;
1997
- function kt(e) {
1997
+ function Bt(e) {
1998
1998
  if (!Number.isSafeInteger(e) || e < 0)
1999
1999
  throw new Error(`positive integer expected, not ${e}`);
2000
2000
  }
@@ -2104,8 +2104,8 @@ 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), y = e[a++] ^ xe(o, c, r, i, t, n), E = e[a++] ^ xe(o, c, i, t, n, r);
2108
- t = h, n = d, r = y, i = E;
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
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
2111
  return { s0: f, s1: u, s2: p, s3: w };
@@ -2116,8 +2116,8 @@ 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), y = e[a++] ^ xe(o, c, r, n, t, i), E = e[a++] ^ xe(o, c, i, r, n, t);
2120
- t = h, n = d, r = y, i = E;
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
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
2123
  return { s0: f, s1: u, s2: p, s3: w };
@@ -2189,10 +2189,10 @@ const Sr = /* @__PURE__ */ qs({ blockSize: 16, nonceLength: 16 }, function(t, n,
2189
2189
  const c = Zs(t), a = F(n), l = Nr(s.length, o), f = F(s), u = F(l);
2190
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 y = p, E = w, S = g, _ = h;
2192
+ const y = p, m = w, S = g, U = h;
2193
2193
  p = f[d + 0], w = f[d + 1], g = f[d + 2], h = f[d + 3];
2194
- const { s0: B, s1: m, s2: x, s3: K } = Fs(c, p, w, g, h);
2195
- u[d++] = B ^ y, u[d++] = m ^ E, u[d++] = x ^ S, u[d++] = K ^ _;
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
  }
@@ -2205,19 +2205,19 @@ function L(e, t) {
2205
2205
  function Wt(e) {
2206
2206
  return e.byteOffset % 4 === 0;
2207
2207
  }
2208
- const Xe = 64, no = 16, Br = 2 ** 32 - 1, jn = new Uint32Array();
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
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
- if (e(t, n, r, f, o, c), o >= Br)
2212
+ if (e(t, n, r, f, o, c), o >= kr)
2213
2213
  throw new Error("arx: counter overflow");
2214
2214
  const h = Math.min(Xe, a - g);
2215
2215
  if (u && h === Xe) {
2216
2216
  const d = g / 4;
2217
2217
  if (g % 4 !== 0)
2218
2218
  throw new Error("arx: invalid block position");
2219
- for (let y = 0, E; y < no; y++)
2220
- E = d + y, w[E] = p[E] ^ f[y];
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
  }
@@ -2230,10 +2230,10 @@ function io(e, t) {
2230
2230
  const { allowShortKeys: n, extendNonceFn: r, counterLength: i, counterRight: s, rounds: o } = Hs({ allowShortKeys: !1, counterLength: 8, counterRight: !1, rounds: 20 }, t);
2231
2231
  if (typeof e != "function")
2232
2232
  throw new Error("core must be a function");
2233
- return kt(i), kt(o), Dn(s), Dn(n), (c, a, l, f, u = 0) => {
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
2235
  const p = l.length;
2236
- if (f || (f = new Uint8Array(p)), ue(f), kt(u), u < 0 || u >= Br)
2236
+ if (f || (f = new Uint8Array(p)), ue(f), Bt(u), u < 0 || u >= kr)
2237
2237
  throw new Error("arx: counter overflow");
2238
2238
  if (f.length < p)
2239
2239
  throw new Error(`arx: output (${f.length}) is shorter than data (${p})`);
@@ -2252,12 +2252,12 @@ function io(e, t) {
2252
2252
  throw new Error("arx: extended nonce must be 24 bytes");
2253
2253
  r(d, y, F(a.subarray(0, 16)), y), a = a.subarray(16);
2254
2254
  }
2255
- const E = 16 - i;
2256
- if (E !== a.length)
2257
- throw new Error(`arx: nonce must be ${E} or 16 bytes`);
2258
- if (E !== 12) {
2259
- const _ = new Uint8Array(12);
2260
- _.set(a, s ? 0 : 12 - a.length), a = _, w.push(a);
2255
+ const m = 16 - i;
2256
+ if (m !== a.length)
2257
+ throw new Error(`arx: nonce must be ${m} or 16 bytes`);
2258
+ if (m !== 12) {
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
2263
  for (ro(e, d, y, S, l, f, u, o); w.length > 0; )
@@ -2266,13 +2266,13 @@ function io(e, t) {
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], p = t[2], w = t[3], g = t[4], h = t[5], d = t[6], y = t[7], E = i, S = n[0], _ = n[1], B = n[2], m = o, x = c, K = a, M = l, I = f, A = u, R = p, T = w, D = g, b = h, v = d, N = y, k = E, C = S, U = _, O = B;
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
- m = m + I | 0, k = L(k ^ m, 16), D = D + k | 0, I = L(I ^ D, 12), m = m + I | 0, k = L(k ^ m, 8), D = D + k | 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), m = m + A | 0, O = L(O ^ m, 16), v = v + O | 0, A = L(A ^ v, 12), m = m + A | 0, O = L(O ^ m, 8), v = v + O | 0, A = L(A ^ v, 7), x = x + R | 0, k = L(k ^ x, 16), N = N + k | 0, R = L(R ^ N, 12), x = x + R | 0, k = L(k ^ x, 8), N = N + k | 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 + m | 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[$++] = E + k | 0, r[$++] = S + C | 0, r[$++] = _ + U | 0, r[$++] = B + 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
- const kr = /* @__PURE__ */ io(so, {
2275
+ const Br = /* @__PURE__ */ io(so, {
2276
2276
  counterRight: !1,
2277
2277
  counterLength: 4,
2278
2278
  allowShortKeys: !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(), ke = 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,
@@ -2507,14 +2507,14 @@ H(go, {
2507
2507
  OpenTimestamps: () => So,
2508
2508
  Pinlist: () => Do,
2509
2509
  PrivateDirectMessage: () => Or,
2510
- ProblemTracker: () => Bo,
2510
+ ProblemTracker: () => ko,
2511
2511
  ProfileBadges: () => aa,
2512
2512
  PublicChatsList: () => Wo,
2513
2513
  Reaction: () => un,
2514
2514
  RecommendRelay: () => mo,
2515
2515
  RelayList: () => qo,
2516
2516
  Relaysets: () => ia,
2517
- Report: () => ko,
2517
+ Report: () => Bo,
2518
2518
  Reporting: () => Io,
2519
2519
  Repost: () => cn,
2520
2520
  Seal: () => Tr,
@@ -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, Bo = 1971, ko = 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
- getSubscriptionId: () => Ba,
2560
- matchEventId: () => ka,
2561
- matchEventKind: () => _a,
2559
+ getSubscriptionId: () => ka,
2560
+ matchEventId: () => Ba,
2561
+ matchEventKind: () => Ua,
2562
2562
  matchEventPubkey: () => Ia
2563
2563
  });
2564
2564
  function hn(e, t) {
@@ -2569,7 +2569,7 @@ function Vr(e, t) {
2569
2569
  let n = t.length, r = e.indexOf(`"${t}":`) + n + 3, i = e.slice(r), s = Math.min(i.indexOf(","), i.indexOf("}"));
2570
2570
  return parseInt(i.slice(0, s), 10);
2571
2571
  }
2572
- function Ba(e) {
2572
+ function ka(e) {
2573
2573
  let t = e.slice(0, 22).indexOf('"EVENT"');
2574
2574
  if (t === -1)
2575
2575
  return null;
@@ -2582,17 +2582,17 @@ function Ba(e) {
2582
2582
  let s = r + 1 + i;
2583
2583
  return e.slice(r + 1, s);
2584
2584
  }
2585
- function ka(e, t) {
2585
+ function Ba(e, t) {
2586
2586
  return t === hn(e, "id");
2587
2587
  }
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)
@@ -2670,7 +2670,7 @@ function wt(e) {
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)
@@ -2690,7 +2690,7 @@ function wt(e) {
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]))
@@ -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,15 +3065,15 @@ function fc(e) {
3065
3065
  mac: n.subarray(-32)
3066
3066
  };
3067
3067
  }
3068
- function bn(e, t, n = yr(32)) {
3069
- const { chacha_key: r, chacha_nonce: i, hmac_key: s } = ni(t, n), o = uc(e), c = kr(r, i, o), a = ri(s, c, n);
3068
+ function bn(e, t, n = pr(32)) {
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
  }
3072
3072
  function vn(e, t) {
3073
3073
  const { nonce: n, ciphertext: r, mac: i } = fc(e), { chacha_key: s, chacha_nonce: o, hmac_key: c } = ni(t, n), a = ri(c, r, n);
3074
3074
  if (!Ds(a, i))
3075
3075
  throw new Error("invalid MAC");
3076
- const l = kr(s, o, r);
3076
+ const l = Br(s, o, r);
3077
3077
  return lc(l);
3078
3078
  }
3079
3079
  var hc = {
@@ -3106,7 +3106,7 @@ function ui(e, t, n) {
3106
3106
  );
3107
3107
  }
3108
3108
  function li(e, t) {
3109
- const n = ke();
3109
+ const n = Be();
3110
3110
  return Q(
3111
3111
  {
3112
3112
  kind: jr,
@@ -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) {
@@ -3261,11 +3261,11 @@ function Cc(e) {
3261
3261
  author: n[1]
3262
3262
  };
3263
3263
  }
3264
- var Bc = {};
3265
- H(Bc, {
3264
+ var kc = {};
3265
+ H(kc, {
3266
3266
  parse: () => Ic
3267
3267
  });
3268
- var kc = /\W/m, Vn = /\W |\W$|$|,| /m;
3268
+ var Bc = /\W/m, Vn = /\W |\W$|$|,| /m;
3269
3269
  function* Ic(e) {
3270
3270
  const t = e.length;
3271
3271
  let n = 0, r = 0;
@@ -3274,7 +3274,7 @@ function* Ic(e) {
3274
3274
  if (i === -1)
3275
3275
  break;
3276
3276
  if (e.substring(i - 5, i) === "nostr") {
3277
- const s = e.substring(i + 60).match(kc), o = s ? i + 60 + s.index : t;
3277
+ const s = e.substring(i + 60).match(Bc), o = s ? i + 60 + s.index : t;
3278
3278
  try {
3279
3279
  let c, { data: a, type: l } = wt(e.substring(i + 1, o));
3280
3280
  switch (l) {
@@ -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)
@@ -3539,40 +3539,31 @@ async function Jc(e) {
3539
3539
  }
3540
3540
  return null;
3541
3541
  }
3542
- function Yc({
3543
- profile: e,
3544
- event: t,
3545
- amount: n,
3546
- relays: r,
3547
- comment: i = ""
3548
- }) {
3549
- if (!n)
3550
- throw new Error("amount not given");
3551
- if (!e)
3552
- throw new Error("profile not given");
3553
- let s = {
3542
+ function Yc(e) {
3543
+ let t = {
3554
3544
  kind: 9734,
3555
3545
  created_at: Math.round(Date.now() / 1e3),
3556
- content: i,
3546
+ content: e.comment || "",
3557
3547
  tags: [
3558
- ["p", e],
3559
- ["amount", n.toString()],
3560
- ["relays", ...r]
3548
+ ["p", "pubkey" in e ? e.pubkey : e.event.pubkey],
3549
+ ["amount", e.amount.toString()],
3550
+ ["relays", ...e.relays]
3561
3551
  ]
3562
3552
  };
3563
- if (t && typeof t == "string" && s.tags.push(["e", t]), t && typeof t == "object") {
3564
- if (on(t.kind)) {
3565
- const o = ["a", `${t.kind}:${t.pubkey}:`];
3566
- s.tags.push(o);
3567
- } else if (an(t.kind)) {
3568
- let o = t.tags.find(([a, l]) => a === "d" && l);
3569
- if (!o)
3553
+ if ("event" in e) {
3554
+ if (t.tags.push(["e", e.event.id]), on(e.event.kind)) {
3555
+ const n = ["a", `${e.event.kind}:${e.event.pubkey}:`];
3556
+ t.tags.push(n);
3557
+ } else if (an(e.event.kind)) {
3558
+ let n = e.event.tags.find(([i, s]) => i === "d" && s);
3559
+ if (!n)
3570
3560
  throw new Error("d tag not found or is empty");
3571
- const c = ["a", `${t.kind}:${t.pubkey}:${o[1]}`];
3572
- s.tags.push(c);
3561
+ const r = ["a", `${e.event.kind}:${e.event.pubkey}:${n[1]}`];
3562
+ t.tags.push(r);
3573
3563
  }
3564
+ t.tags.push(["k", e.event.kind.toString()]);
3574
3565
  }
3575
- return s;
3566
+ return t;
3576
3567
  }
3577
3568
  function Xc(e) {
3578
3569
  let t;
@@ -3581,7 +3572,7 @@ function Xc(e) {
3581
3572
  } catch {
3582
3573
  return "Invalid zap request JSON.";
3583
3574
  }
3584
- if (!pt(t))
3575
+ if (!yt(t))
3585
3576
  return "Zap request is not a valid Nostr event.";
3586
3577
  if (!gt(t))
3587
3578
  return "Invalid signature on zap request.";
@@ -3651,7 +3642,7 @@ H(tu, {
3651
3642
  validateEventUrlTag: () => vi,
3652
3643
  validateToken: () => ru
3653
3644
  });
3654
- var yi = "Nostr ";
3645
+ var pi = "Nostr ";
3655
3646
  async function nu(e, t, n, r = !1, i) {
3656
3647
  const s = {
3657
3648
  kind: fn,
@@ -3664,7 +3655,7 @@ async function nu(e, t, n, r = !1, i) {
3664
3655
  };
3665
3656
  i && s.tags.push(["payload", Sn(i)]);
3666
3657
  const o = await n(s);
3667
- return (r ? yi : "") + he.encode(ne.encode(JSON.stringify(o)));
3658
+ return (r ? pi : "") + he.encode(ne.encode(JSON.stringify(o)));
3668
3659
  }
3669
3660
  async function ru(e, t, n) {
3670
3661
  const r = await gi(e).catch((s) => {
@@ -3677,7 +3668,7 @@ async function ru(e, t, n) {
3677
3668
  async function gi(e) {
3678
3669
  if (!e)
3679
3670
  throw new Error("Missing token");
3680
- e = e.replace(yi, "");
3671
+ e = e.replace(pi, "");
3681
3672
  const t = le.decode(he.decode(e));
3682
3673
  if (!t || t.length === 0 || !t.startsWith("{"))
3683
3674
  throw new Error("Invalid token");
@@ -3723,8 +3714,8 @@ async function xi(e, t, n, r) {
3723
3714
  throw new Error("Invalid nostr event, payload tag does not match request body hash");
3724
3715
  return !0;
3725
3716
  }
3726
- const Oe = 1060, Lt = 30078, Zn = 1059, iu = 14, wu = 100, su = 1;
3727
- function bu(e) {
3717
+ const Oe = 1060, Lt = 30078, Zn = 1059, iu = 14, bu = 100, su = 1;
3718
+ function vu(e) {
3728
3719
  return JSON.stringify({
3729
3720
  version: su,
3730
3721
  rootKey: P(e.rootKey),
@@ -3759,7 +3750,7 @@ function bu(e) {
3759
3750
  )
3760
3751
  });
3761
3752
  }
3762
- function vu(e) {
3753
+ function mu(e) {
3763
3754
  const t = JSON.parse(e);
3764
3755
  if (!t.version) {
3765
3756
  const n = {};
@@ -3822,7 +3813,38 @@ function vu(e) {
3822
3813
  )
3823
3814
  };
3824
3815
  }
3825
- 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) {
3826
3848
  const t = [];
3827
3849
  let n = null;
3828
3850
  const r = e.onEvent((i) => {
@@ -3840,18 +3862,18 @@ async function* mu(e) {
3840
3862
  function Me(e, t = new Uint8Array(32), n = 1) {
3841
3863
  const r = rn(fe, e, t), i = [];
3842
3864
  for (let s = 1; s <= n; s++)
3843
- i.push(_r(fe, r, new Uint8Array([s]), 32));
3865
+ i.push(Ur(fe, r, new Uint8Array([s]), 32));
3844
3866
  return i;
3845
3867
  }
3846
- function Eu(e, t) {
3868
+ function xu(e, t) {
3847
3869
  return `${e}:${t}`;
3848
3870
  }
3849
- function xu(e) {
3871
+ function Ku(e) {
3850
3872
  var n;
3851
3873
  const t = (n = e.tags) == null ? void 0 : n.find((r) => r[0] === "ms");
3852
3874
  return t ? parseInt(t[1]) : e.created_at * 1e3;
3853
3875
  }
3854
- const ou = 1e3, au = "0000000000000000000000000000000000000000000000000000000000000000";
3876
+ const au = 1e3, cu = "0000000000000000000000000000000000000000000000000000000000000000";
3855
3877
  class ot {
3856
3878
  // 1. CHANNEL PUBLIC INTERFACE
3857
3879
  constructor(t, n) {
@@ -3874,7 +3896,7 @@ class ot {
3874
3896
  * @returns A new Session instance
3875
3897
  */
3876
3898
  static init(t, n, r, i, s, o) {
3877
- const c = ke();
3899
+ const c = Be();
3878
3900
  let a, l, f, u;
3879
3901
  i ? ([a, l] = Me(s, q.getConversationKey(c, n), 2), f = {
3880
3902
  publicKey: ae(r),
@@ -3931,7 +3953,7 @@ class ot {
3931
3953
  kind: t.kind || Oe,
3932
3954
  created_at: t.created_at || Math.floor(n / 1e3),
3933
3955
  tags: t.tags || [],
3934
- pubkey: t.pubkey || au
3956
+ pubkey: t.pubkey || cu
3935
3957
  };
3936
3958
  r.tags.some(([l]) => l === "ms") || r.tags.push(["ms", String(n)]), r.id = De(r);
3937
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);
@@ -3978,7 +4000,7 @@ class ot {
3978
4000
  this.state.previousSendingChainMessageCount = this.state.sendingChainMessageNumber, this.state.sendingChainMessageNumber = 0, this.state.receivingChainMessageNumber = 0;
3979
4001
  const t = q.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [n, r] = Me(this.state.rootKey, t, 2);
3980
4002
  this.state.receivingChainKey = r, this.state.ourCurrentNostrKey = this.state.ourNextNostrKey;
3981
- const i = ke();
4003
+ const i = Be();
3982
4004
  this.state.ourNextNostrKey = {
3983
4005
  publicKey: ae(i),
3984
4006
  privateKey: i
@@ -3989,7 +4011,7 @@ class ot {
3989
4011
  // 3. MESSAGE KEY FUNCTIONS
3990
4012
  skipMessageKeys(t, n) {
3991
4013
  if (!(t <= this.state.receivingChainMessageNumber)) {
3992
- if (t > this.state.receivingChainMessageNumber + ou)
4014
+ if (t > this.state.receivingChainMessageNumber + au)
3993
4015
  throw new Error("Too many skipped messages");
3994
4016
  if (!this.state.skippedKeys[n]) {
3995
4017
  if (this.state.skippedKeys[n] = {
@@ -4039,24 +4061,32 @@ class ot {
4039
4061
  throw new Error("Failed to decrypt header with current and skipped header keys");
4040
4062
  }
4041
4063
  handleNostrEvent(t) {
4042
- var n, r;
4064
+ var i, s;
4065
+ const n = ou(this.state);
4066
+ let r = !1;
4043
4067
  try {
4044
- const [i, s, o] = this.decryptHeader(t);
4045
- if (!o)
4046
- 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(
4047
- { authors: [this.state.theirNextNostrPublicKey], kinds: [Oe] },
4048
- (l) => this.handleNostrEvent(l)
4049
- )), s && (this.skipMessageKeys(i.previousChainLength, t.pubkey), this.ratchetStep());
4050
- 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]))
4051
4072
  return;
4052
- const c = this.ratchetDecrypt(i, t.content, t.pubkey), a = JSON.parse(c);
4053
- 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;
4054
4076
  return;
4055
- this.internalSubscriptions.forEach((l) => l(a, t));
4056
- } catch (i) {
4057
- if (i instanceof Error && i.message.includes("Failed to decrypt header"))
4077
+ }
4078
+ if (f.id !== De(f)) {
4079
+ this.state = n;
4058
4080
  return;
4059
- throw i;
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"))
4088
+ return;
4089
+ throw o;
4060
4090
  }
4061
4091
  }
4062
4092
  subscribeToNostrEvents() {
@@ -4078,10 +4108,10 @@ class ot {
4078
4108
  new TextDecoder("utf-8");
4079
4109
  new TextEncoder();
4080
4110
  function Qe(e, t) {
4081
- const n = _e.getSharedSecret(e, "02" + t).subarray(1, 33);
4111
+ const n = Ue.getSharedSecret(e, "02" + t).subarray(1, 33);
4082
4112
  return rn(fe, n, "nip44-v2");
4083
4113
  }
4084
- 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);
4085
4115
  class Pe {
4086
4116
  constructor(t, n, r, i, s, o, c = []) {
4087
4117
  this.inviterEphemeralPublicKey = t, this.sharedSecret = n, this.inviter = r, this.inviterEphemeralPrivateKey = i, this.deviceId = s, this.maxUses = o, this.usedBy = c;
@@ -4089,7 +4119,7 @@ class Pe {
4089
4119
  static createNew(t, n, r) {
4090
4120
  if (!t)
4091
4121
  throw new Error("Inviter public key is required");
4092
- const i = ke(), s = ae(i), o = P(ke());
4122
+ const i = Be(), s = ae(i), o = P(Be());
4093
4123
  return new Pe(
4094
4124
  s,
4095
4125
  o,
@@ -4241,29 +4271,33 @@ class Pe {
4241
4271
  * @param nostrSubscribe - A function to subscribe to Nostr events
4242
4272
  * @param inviteePublicKey - The invitee's public key
4243
4273
  * @param encryptor - The invitee's secret key or a signing/encrypt function
4274
+ * @param deviceId - Optional device ID to identify the invitee's device
4244
4275
  * @returns An object containing the new session and an event to be published
4245
4276
  *
4246
4277
  * 1. Inner event: No signature, content encrypted with DH(inviter, invitee).
4247
- * Purpose: Authenticate invitee. Contains invitee session key.
4278
+ * Purpose: Authenticate invitee. Contains invitee session key and deviceId.
4248
4279
  * 2. Envelope: No signature, content encrypted with DH(inviter, random key).
4249
4280
  * Purpose: Contains inner event. Hides invitee from others who might have the shared Nostr key.
4250
4281
 
4251
4282
  * Note: You need to publish the returned event on Nostr using NDK or another Nostr system of your choice,
4252
4283
  * so the inviter can create the session on their side.
4253
4284
  */
4254
- async accept(t, n, r) {
4255
- const i = ke(), s = ae(i), o = this.inviter || this.inviterEphemeralPublicKey, c = j(this.sharedSecret), a = ot.init(t, this.inviterEphemeralPublicKey, i, !0, c, void 0), f = await (typeof r == "function" ? r : (d, y) => Promise.resolve(q.encrypt(d, Qe(r, y))))(s, o), u = {
4285
+ async accept(t, n, r, i) {
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({
4287
+ sessionKey: o,
4288
+ deviceId: i
4289
+ }), p = await f(u, c), w = {
4256
4290
  pubkey: n,
4257
- content: await q.encrypt(f, c),
4291
+ content: await q.encrypt(p, a),
4258
4292
  created_at: Math.floor(Date.now() / 1e3)
4259
- }, p = JSON.stringify(u), w = ke(), g = ae(w), h = {
4293
+ }, g = JSON.stringify(w), h = Be(), d = ae(h), y = {
4260
4294
  kind: Zn,
4261
- pubkey: g,
4262
- content: q.encrypt(p, Qe(w, this.inviterEphemeralPublicKey)),
4263
- created_at: lu(),
4295
+ pubkey: d,
4296
+ content: q.encrypt(g, Qe(h, this.inviterEphemeralPublicKey)),
4297
+ created_at: fu(),
4264
4298
  tags: [["p", this.inviterEphemeralPublicKey]]
4265
4299
  };
4266
- return { session: a, event: Q(h, w) };
4300
+ return { session: l, event: Q(y, h) };
4267
4301
  }
4268
4302
  listen(t, n, r) {
4269
4303
  if (!this.inviterEphemeralPrivateKey)
@@ -4278,8 +4312,16 @@ class Pe {
4278
4312
  return;
4279
4313
  const o = await q.decrypt(s.content, Qe(this.inviterEphemeralPrivateKey, s.pubkey)), c = JSON.parse(o), a = j(this.sharedSecret), l = c.pubkey;
4280
4314
  this.usedBy.push(l);
4281
- const f = await q.decrypt(c.content, a), p = await (typeof t == "function" ? t : (h, d) => Promise.resolve(q.decrypt(h, Qe(t, d))))(f, l), w = s.id, g = ot.init(n, p, this.inviterEphemeralPrivateKey, !1, a, w);
4282
- r(g, 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);
4316
+ let w, g;
4317
+ try {
4318
+ const y = JSON.parse(p);
4319
+ w = y.sessionKey, g = y.deviceId;
4320
+ } catch {
4321
+ w = p;
4322
+ }
4323
+ const h = s.id, d = ot.init(n, w, this.inviterEphemeralPrivateKey, !1, a, h);
4324
+ r(d, l, g);
4283
4325
  } catch {
4284
4326
  }
4285
4327
  });
@@ -4290,13 +4332,14 @@ export {
4290
4332
  Lt as INVITE_EVENT_KIND,
4291
4333
  Zn as INVITE_RESPONSE_KIND,
4292
4334
  Pe as Invite,
4293
- wu as MAX_SKIP,
4335
+ bu as MAX_SKIP,
4294
4336
  Oe as MESSAGE_EVENT_KIND,
4295
4337
  ot as Session,
4296
- mu as createEventStream,
4297
- vu as deserializeSessionState,
4298
- xu as getMillisecondTimestamp,
4338
+ Eu as createEventStream,
4339
+ ou as deepCopyState,
4340
+ mu as deserializeSessionState,
4341
+ Ku as getMillisecondTimestamp,
4299
4342
  Me as kdf,
4300
- bu as serializeSessionState,
4301
- Eu as skippedMessageIndexKey
4343
+ vu as serializeSessionState,
4344
+ xu as skippedMessageIndexKey
4302
4345
  };