nostr-double-ratchet 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Session.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { VerifiedEvent, UnsignedEvent } from "nostr-tools";
2
- import { SessionState, Unsubscribe, NostrSubscribe, EventCallback } from "./types";
2
+ import { SessionState, Unsubscribe, NostrSubscribe, EventCallback, Rumor } from "./types";
3
3
  /**
4
4
  * Double ratchet secure communication session over Nostr
5
5
  *
@@ -32,7 +32,10 @@ export declare class Session {
32
32
  * @returns A verified Nostr event containing the encrypted message
33
33
  * @throws Error if we are not the initiator and trying to send the first message
34
34
  */
35
- send(text: string): VerifiedEvent;
35
+ send(text: string): {
36
+ event: VerifiedEvent;
37
+ innerEvent: Rumor;
38
+ };
36
39
  /**
37
40
  * Send a partial Nostr event through the encrypted session.
38
41
  * In addition to chat messages, it could be files, webrtc negotiation or many other types of messages.
@@ -40,7 +43,10 @@ export declare class Session {
40
43
  * @returns A verified Nostr event containing the encrypted message
41
44
  * @throws Error if we are not the initiator and trying to send the first message
42
45
  */
43
- sendEvent(event: Partial<UnsignedEvent>): VerifiedEvent;
46
+ sendEvent(event: Partial<UnsignedEvent>): {
47
+ event: VerifiedEvent;
48
+ innerEvent: Rumor;
49
+ };
44
50
  /**
45
51
  * Subscribes to incoming messages on this session
46
52
  * @param callback Function to be called when a message is received
@@ -1 +1 @@
1
- {"version":3,"file":"Session.d.ts","sourceRoot":"","sources":["../src/Session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,aAAa,EAAE,aAAa,EAA+B,MAAM,aAAa,CAAC;AAE/I,OAAO,EACL,YAAY,EAEZ,WAAW,EACX,cAAc,EACd,aAAa,EAId,MAAM,SAAS,CAAC;AAQjB;;;;;GAKG;AACH,qBAAa,OAAO;IAQN,OAAO,CAAC,cAAc;IAAyB,KAAK,EAAE,YAAY;IAP9E,OAAO,CAAC,gBAAgB,CAAC,CAAc;IACvC,OAAO,CAAC,oBAAoB,CAAC,CAAc;IAC3C,OAAO,CAAC,qBAAqB,CAAoC;IACjE,OAAO,CAAC,6BAA6B,CAAK;IACnC,IAAI,EAAE,MAAM,CAAC;gBAGA,cAAc,EAAE,cAAc,EAAS,KAAK,EAAE,YAAY;IAI9E;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO;IA6BtL;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;IAOjC;;;;;;OAMG;IACH,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa;IAuCvD;;;;OAIG;IACH,OAAO,CAAC,QAAQ,EAAE,aAAa,GAAG,WAAW;IAO7C;;OAEG;IACH,KAAK;IAML,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,cAAc;IAuBtB,OAAO,CAAC,WAAW;IAyBnB,OAAO,CAAC,eAAe;IAyBvB,OAAO,CAAC,qBAAqB;IAqB7B,OAAO,CAAC,aAAa;IAmCrB,OAAO,CAAC,gBAAgB;IAyCxB,OAAO,CAAC,sBAAsB;CAkB/B"}
1
+ {"version":3,"file":"Session.d.ts","sourceRoot":"","sources":["../src/Session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,aAAa,EAAE,aAAa,EAA+B,MAAM,aAAa,CAAC;AAE/I,OAAO,EACL,YAAY,EAEZ,WAAW,EACX,cAAc,EACd,aAAa,EAEb,KAAK,EAEN,MAAM,SAAS,CAAC;AAQjB;;;;;GAKG;AACH,qBAAa,OAAO;IAQN,OAAO,CAAC,cAAc;IAAyB,KAAK,EAAE,YAAY;IAP9E,OAAO,CAAC,gBAAgB,CAAC,CAAc;IACvC,OAAO,CAAC,oBAAoB,CAAC,CAAc;IAC3C,OAAO,CAAC,qBAAqB,CAAoC;IACjE,OAAO,CAAC,6BAA6B,CAAK;IACnC,IAAI,EAAE,MAAM,CAAC;gBAGA,cAAc,EAAE,cAAc,EAAS,KAAK,EAAE,YAAY;IAI9E;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO;IA6BtL;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG;QAAC,KAAK,EAAE,aAAa,CAAC;QAAC,UAAU,EAAE,KAAK,CAAA;KAAC;IAO7D;;;;;;OAMG;IACH,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG;QAAC,KAAK,EAAE,aAAa,CAAC;QAAC,UAAU,EAAE,KAAK,CAAA;KAAC;IAuCnF;;;;OAIG;IACH,OAAO,CAAC,QAAQ,EAAE,aAAa,GAAG,WAAW;IAO7C;;OAEG;IACH,KAAK;IAML,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,cAAc;IAuBtB,OAAO,CAAC,WAAW;IAyBnB,OAAO,CAAC,eAAe;IAyBvB,OAAO,CAAC,qBAAqB;IAqB7B,OAAO,CAAC,aAAa;IAmCrB,OAAO,CAAC,gBAAgB;IAyCxB,OAAO,CAAC,sBAAsB;CAkB/B"}
@@ -198,7 +198,7 @@ const Bi = (e, t, n) => e & t ^ ~e & n, ki = (e, t, n) => e & t ^ e & n ^ t & n,
198
198
  528734635,
199
199
  1541459225
200
200
  ]), ve = /* @__PURE__ */ new Uint32Array(64);
201
- let Ui = class extends Ci {
201
+ let Ii = class extends Ci {
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
  }
@@ -231,9 +231,9 @@ let Ui = class extends Ci {
231
231
  this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
232
232
  }
233
233
  };
234
- const $t = /* @__PURE__ */ Ai(() => new Ui());
234
+ const $t = /* @__PURE__ */ Ai(() => new Ii());
235
235
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
236
- const Gn = BigInt(0), ot = BigInt(1), Ii = BigInt(2), at = (e) => e instanceof Uint8Array, Li = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
236
+ const Gn = BigInt(0), ot = BigInt(1), Ui = BigInt(2), at = (e) => e instanceof Uint8Array, Li = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
237
237
  function De(e) {
238
238
  if (!at(e))
239
239
  throw new Error("Uint8Array expected");
@@ -300,7 +300,7 @@ function W(e, t, n) {
300
300
  throw new Error(`${e} expected ${n} bytes, got ${i}`);
301
301
  return r;
302
302
  }
303
- function Ue(...e) {
303
+ function Ie(...e) {
304
304
  const t = new Uint8Array(e.reduce((r, i) => r + i.length, 0));
305
305
  let n = 0;
306
306
  return e.forEach((r) => {
@@ -331,7 +331,7 @@ function Oi(e) {
331
331
  function Mi(e, t) {
332
332
  return e >> BigInt(t) & ot;
333
333
  }
334
- const Pi = (e, t, n) => e | (n ? ot : Gn) << BigInt(t), Yt = (e) => (Ii << BigInt(e - 1)) - ot, Nt = (e) => new Uint8Array(e), Cn = (e) => Uint8Array.from(e);
334
+ const Pi = (e, t, n) => e | (n ? ot : Gn) << BigInt(t), Yt = (e) => (Ui << BigInt(e - 1)) - ot, Nt = (e) => new Uint8Array(e), Cn = (e) => Uint8Array.from(e);
335
335
  function Jn(e, t, n) {
336
336
  if (typeof e != "number" || e < 2)
337
337
  throw new Error("hashLen must be a number");
@@ -354,7 +354,7 @@ function Jn(e, t, n) {
354
354
  const b = r.slice();
355
355
  g.push(b), u += r.length;
356
356
  }
357
- return Ue(...g);
357
+ return Ie(...g);
358
358
  };
359
359
  return (u, g) => {
360
360
  o(), a(u);
@@ -399,7 +399,7 @@ const qi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
399
399
  bytesToHex: De,
400
400
  bytesToNumberBE: F,
401
401
  bytesToNumberLE: Ft,
402
- concatBytes: Ue,
402
+ concatBytes: Ie,
403
403
  createHmacDrbg: Jn,
404
404
  ensureBytes: W,
405
405
  equalBytes: Ti,
@@ -671,8 +671,8 @@ function Qi(e, t) {
671
671
  const h = p * a;
672
672
  let d = Number(o & u);
673
673
  o >>= b, d > a && (d -= g, o += At);
674
- const y = h, m = h + Math.abs(d) - 1, A = p % 2 !== 0, U = d < 0;
675
- d === 0 ? f = f.add(n(A, s[y])) : l = l.add(n(U, s[m]));
674
+ const y = h, m = h + Math.abs(d) - 1, A = p % 2 !== 0, I = d < 0;
675
+ d === 0 ? f = f.add(n(A, s[y])) : l = l.add(n(I, s[m]));
676
676
  }
677
677
  return { p: l, f };
678
678
  },
@@ -770,7 +770,7 @@ BigInt(4);
770
770
  function rs(e) {
771
771
  const t = es(e), { Fp: n } = t, r = t.toBytes || ((p, h, d) => {
772
772
  const y = h.toAffine();
773
- return Ue(Uint8Array.from([4]), n.toBytes(y.x), n.toBytes(y.y));
773
+ return Ie(Uint8Array.from([4]), n.toBytes(y.x), n.toBytes(y.y));
774
774
  }), i = t.fromBytes || ((p) => {
775
775
  const h = p.subarray(1), d = n.fromBytes(h.subarray(0, n.BYTES)), y = n.fromBytes(h.subarray(n.BYTES, 2 * n.BYTES));
776
776
  return { x: d, y };
@@ -887,7 +887,7 @@ function rs(e) {
887
887
  */
888
888
  equals(h) {
889
889
  f(h);
890
- const { px: d, py: y, pz: m } = this, { px: A, py: U, pz: B } = h, E = n.eql(n.mul(d, B), n.mul(A, m)), x = n.eql(n.mul(y, B), n.mul(U, m));
890
+ const { px: d, py: y, pz: m } = this, { px: A, py: I, pz: B } = h, E = n.eql(n.mul(d, B), n.mul(A, m)), x = n.eql(n.mul(y, B), n.mul(I, m));
891
891
  return E && x;
892
892
  }
893
893
  /**
@@ -901,9 +901,9 @@ function rs(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, _n), { px: m, py: A, pz: U } = this;
905
- let B = n.ZERO, E = n.ZERO, x = n.ZERO, S = n.mul(m, m), P = n.mul(A, A), _ = n.mul(U, U), K = n.mul(m, A);
906
- return K = n.add(K, K), x = n.mul(m, U), x = n.add(x, x), B = n.mul(h, x), E = n.mul(y, _), E = n.add(B, E), B = n.sub(P, E), E = n.add(P, E), E = n.mul(B, E), B = n.mul(K, B), x = n.mul(y, x), _ = n.mul(h, _), K = n.sub(S, _), K = n.mul(h, K), K = n.add(K, x), x = n.add(S, S), S = n.add(x, S), S = n.add(S, _), S = n.mul(S, K), E = n.add(E, S), _ = n.mul(A, U), _ = n.add(_, _), S = n.mul(_, K), B = n.sub(B, S), x = n.mul(_, P), x = n.add(x, x), x = n.add(x, x), new u(B, E, x);
904
+ const { a: h, b: d } = t, y = n.mul(d, _n), { px: m, py: A, pz: I } = this;
905
+ let B = n.ZERO, E = n.ZERO, x = n.ZERO, S = n.mul(m, m), P = n.mul(A, A), _ = n.mul(I, I), K = n.mul(m, A);
906
+ return K = n.add(K, K), x = n.mul(m, I), x = n.add(x, x), B = n.mul(h, x), E = n.mul(y, _), E = n.add(B, E), B = n.sub(P, E), E = n.add(P, E), E = n.mul(B, E), B = n.mul(K, B), x = n.mul(y, x), _ = n.mul(h, _), K = n.sub(S, _), K = n.mul(h, K), K = n.add(K, x), x = n.add(S, S), S = n.add(x, S), S = n.add(S, _), S = n.mul(S, K), E = n.add(E, S), _ = n.mul(A, I), _ = n.add(_, _), S = n.mul(_, K), B = n.sub(B, S), x = n.mul(_, P), x = n.add(x, x), x = n.add(x, x), new u(B, 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 rs(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: m } = this, { px: A, py: U, pz: B } = h;
914
+ const { px: d, py: y, pz: m } = this, { px: A, py: I, pz: B } = h;
915
915
  let E = n.ZERO, x = n.ZERO, S = n.ZERO;
916
916
  const P = t.a, _ = n.mul(t.b, _n);
917
- let K = n.mul(d, A), T = n.mul(y, U), R = n.mul(m, B), H = n.add(d, y), w = n.add(A, U);
917
+ let K = n.mul(d, A), T = n.mul(y, I), R = n.mul(m, B), H = n.add(d, y), w = n.add(A, I);
918
918
  H = n.mul(H, w), w = n.add(K, T), H = n.sub(H, w), w = n.add(d, m);
919
919
  let v = n.add(A, B);
920
- return w = n.mul(w, v), v = n.add(K, R), w = n.sub(w, v), v = n.add(y, m), E = n.add(U, B), v = n.mul(v, E), E = n.add(T, R), v = n.sub(v, E), S = n.mul(P, w), E = n.mul(_, R), S = n.add(E, S), E = n.sub(T, S), S = n.add(T, S), x = n.mul(E, S), T = n.add(K, K), T = n.add(T, K), R = n.mul(P, R), w = n.mul(_, w), T = n.add(T, R), R = n.sub(K, R), R = n.mul(P, R), w = n.add(w, R), K = n.mul(T, w), x = n.add(x, K), K = n.mul(v, w), E = n.mul(H, E), E = n.sub(E, K), K = n.mul(H, T), S = n.mul(v, S), S = n.add(S, K), new u(E, x, S);
920
+ return w = n.mul(w, v), v = n.add(K, R), w = n.sub(w, v), v = n.add(y, m), E = n.add(I, B), v = n.mul(v, E), E = n.add(T, R), v = n.sub(v, E), S = n.mul(P, w), E = n.mul(_, R), S = n.add(E, S), E = n.sub(T, S), S = n.add(T, S), x = n.mul(E, S), T = n.add(K, K), T = n.add(T, K), R = n.mul(P, R), w = n.mul(_, w), T = n.add(T, R), R = n.sub(K, R), R = n.mul(P, R), w = n.add(w, R), K = n.mul(T, w), x = n.add(x, K), K = n.mul(v, w), E = n.mul(H, E), E = n.sub(E, K), K = n.mul(H, T), S = n.mul(v, S), S = n.add(S, K), new u(E, x, S);
921
921
  }
922
922
  subtract(h) {
923
923
  return this.add(h.negate());
@@ -945,10 +945,10 @@ function rs(e) {
945
945
  const { endo: y } = t;
946
946
  if (!y)
947
947
  return b.unsafeLadder(this, h);
948
- let { k1neg: m, k1: A, k2neg: U, k2: B } = y.splitScalar(h), E = d, x = d, S = this;
948
+ let { k1neg: m, k1: A, k2neg: I, k2: B } = y.splitScalar(h), E = d, x = d, S = this;
949
949
  for (; A > ae || B > ae; )
950
950
  A & Y && (E = E.add(S)), B & Y && (x = x.add(S)), S = S.double(), A >>= Y, B >>= Y;
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);
951
+ return m && (E = E.negate()), I && (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.
@@ -964,12 +964,12 @@ function rs(e) {
964
964
  let d = h, y, m;
965
965
  const { endo: A } = t;
966
966
  if (A) {
967
- const { k1neg: U, k1: B, k2neg: E, k2: x } = A.splitScalar(d);
967
+ const { k1neg: I, k1: B, k2neg: E, k2: x } = A.splitScalar(d);
968
968
  let { p: S, f: P } = this.wNAF(B), { p: _, f: K } = this.wNAF(x);
969
- S = b.constTimeNegate(U, S), _ = b.constTimeNegate(E, _), _ = new u(n.mul(_.px, A.beta), _.py, _.pz), y = S.add(_), m = P.add(K);
969
+ S = b.constTimeNegate(I, S), _ = b.constTimeNegate(E, _), _ = new u(n.mul(_.px, A.beta), _.py, _.pz), y = S.add(_), m = P.add(K);
970
970
  } else {
971
- const { p: U, f: B } = this.wNAF(d);
972
- y = U, m = B;
971
+ const { p: I, f: B } = this.wNAF(d);
972
+ y = I, m = B;
973
973
  }
974
974
  return u.normalizeZ([y, m])[0];
975
975
  }
@@ -980,8 +980,8 @@ function rs(e) {
980
980
  * @returns non-zero affine point
981
981
  */
982
982
  multiplyAndAddUnsafe(h, d, y) {
983
- const m = u.BASE, A = (B, E) => E === ae || E === Y || !B.equals(m) ? B.multiplyUnsafe(E) : B.multiply(E), U = A(this, d).add(A(h, y));
984
- return U.is0() ? void 0 : U;
983
+ const m = u.BASE, A = (B, E) => E === ae || E === Y || !B.equals(m) ? B.multiplyUnsafe(E) : B.multiply(E), I = A(this, d).add(A(h, y));
984
+ return I.is0() ? void 0 : I;
985
985
  }
986
986
  // Converts Projective point to affine (x, y) coordinates.
987
987
  // Can accept precomputed Z^-1 - for example, from invertBatch.
@@ -989,12 +989,12 @@ function rs(e) {
989
989
  toAffine(h) {
990
990
  const { px: d, py: y, pz: m } = this, A = this.is0();
991
991
  h == null && (h = A ? n.ONE : n.inv(m));
992
- const U = n.mul(d, h), B = n.mul(y, h), E = n.mul(m, h);
992
+ const I = n.mul(d, h), B = n.mul(y, h), E = n.mul(m, h);
993
993
  if (A)
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: U, y: B };
997
+ return { x: I, y: B };
998
998
  }
999
999
  isTorsionFree() {
1000
1000
  const { h, isTorsionFree: d } = t;
@@ -1051,8 +1051,8 @@ function ss(e) {
1051
1051
  const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: g } = rs({
1052
1052
  ...t,
1053
1053
  toBytes(w, v, N) {
1054
- const k = v.toAffine(), C = n.toBytes(k.x), I = Ue;
1055
- return N ? I(Uint8Array.from([v.hasEvenY() ? 2 : 3]), C) : I(Uint8Array.from([4]), C, n.toBytes(k.y));
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));
1056
1056
  },
1057
1057
  fromBytes(w) {
1058
1058
  const v = w.length, N = w[0], k = w.subarray(1);
@@ -1060,13 +1060,13 @@ function ss(e) {
1060
1060
  const C = F(k);
1061
1061
  if (!o(C))
1062
1062
  throw new Error("Point is not on curve");
1063
- const I = u(C);
1064
- let O = n.sqrt(I);
1063
+ const U = u(C);
1064
+ let O = n.sqrt(U);
1065
1065
  const $ = (O & Y) === Y;
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)), I = n.fromBytes(k.subarray(n.BYTES, 2 * n.BYTES));
1069
- return { x: C, y: I };
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 };
1070
1070
  } else
1071
1071
  throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`);
1072
1072
  }
@@ -1104,13 +1104,13 @@ function ss(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, I = x(W("msgHash", v));
1107
+ const { r: N, s: k, recovery: C } = this, U = x(W("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 ? "03" : "02", Q = l.fromHex($ + b(O)), ge = a(O), Le = c(-I * ge), We = c(k * ge), we = l.BASE.multiplyAndAddUnsafe(Q, Le, We);
1113
+ const $ = C & 1 ? "03" : "02", Q = l.fromHex($ + b(O)), ge = a(O), Le = c(-U * ge), We = c(k * ge), we = l.BASE.multiplyAndAddUnsafe(Q, Le, We);
1114
1114
  if (!we)
1115
1115
  throw new Error("point at infinify");
1116
1116
  return we.assertValidity(), we;
@@ -1169,14 +1169,14 @@ function ss(e) {
1169
1169
  function A(w, v = !0) {
1170
1170
  return l.fromPrivateKey(w).toRawBytes(v);
1171
1171
  }
1172
- function U(w) {
1172
+ function I(w) {
1173
1173
  const v = w instanceof Uint8Array, N = typeof w == "string", k = (v || N) && w.length;
1174
1174
  return v ? k === i || k === s : N ? k === 2 * i || k === 2 * s : w instanceof l;
1175
1175
  }
1176
1176
  function B(w, v, N = !0) {
1177
- if (U(w))
1177
+ if (I(w))
1178
1178
  throw new Error("first arg must be private key");
1179
- if (!U(v))
1179
+ if (!I(v))
1180
1180
  throw new Error("second arg must be public key");
1181
1181
  return l.fromHex(v).multiply(f(w)).toRawBytes(N);
1182
1182
  }
@@ -1197,14 +1197,14 @@ function ss(e) {
1197
1197
  if (["recovered", "canonical"].some((Ke) => Ke in N))
1198
1198
  throw new Error("sign() legacy options not supported");
1199
1199
  const { hash: k, randomBytes: C } = t;
1200
- let { lowS: I, prehash: O, extraEntropy: $ } = N;
1201
- I == null && (I = !0), w = W("msgHash", w), O && (w = W("prehashed msgHash", k(w)));
1200
+ let { lowS: U, prehash: O, extraEntropy: $ } = N;
1201
+ U == null && (U = !0), w = W("msgHash", w), O && (w = W("prehashed msgHash", k(w)));
1202
1202
  const Q = x(w), ge = f(v), Le = [P(ge), P(Q)];
1203
1203
  if ($ != null) {
1204
1204
  const Ke = $ === !0 ? C(n.BYTES) : $;
1205
1205
  Le.push(W("extraEntropy", Ke));
1206
1206
  }
1207
- const We = Ue(...Le), we = Q;
1207
+ const We = Ie(...Le), we = Q;
1208
1208
  function mt(Ke) {
1209
1209
  const $e = E(Ke);
1210
1210
  if (!g($e))
@@ -1216,14 +1216,14 @@ function ss(e) {
1216
1216
  if (Re === ae)
1217
1217
  return;
1218
1218
  let Nn = (Te.x === ee ? 0 : 2) | Number(Te.y & Y), An = Re;
1219
- return I && p(Re) && (An = h(Re), Nn ^= 1), new y(ee, An, Nn);
1219
+ return U && p(Re) && (An = h(Re), Nn ^= 1), new y(ee, An, Nn);
1220
1220
  }
1221
1221
  return { seed: We, k2sig: mt };
1222
1222
  }
1223
1223
  const K = { lowS: t.lowS, prehash: !1 }, T = { lowS: t.lowS, prehash: !1 };
1224
1224
  function R(w, v, N = K) {
1225
- const { seed: k, k2sig: C } = _(w, v, N), I = t;
1226
- return Jn(I.hash.outputLen, I.nByteLength, I.hmac)(k, C);
1225
+ const { seed: k, k2sig: C } = _(w, v, N), U = t;
1226
+ return Jn(U.hash.outputLen, U.nByteLength, U.hmac)(k, C);
1227
1227
  }
1228
1228
  l.BASE._setWindowSize(8);
1229
1229
  function H(w, v, N, k = T) {
@@ -1231,7 +1231,7 @@ function ss(e) {
1231
1231
  const C = w;
1232
1232
  if (v = W("msgHash", v), N = W("publicKey", N), "strict" in k)
1233
1233
  throw new Error("options.strict was renamed to lowS");
1234
- const { lowS: I, prehash: O } = k;
1234
+ const { lowS: U, prehash: O } = k;
1235
1235
  let $, Q;
1236
1236
  try {
1237
1237
  if (typeof C == "string" || C instanceof Uint8Array)
@@ -1253,7 +1253,7 @@ function ss(e) {
1253
1253
  throw new Error("signature must be Signature instance, Uint8Array or hex string");
1254
1254
  return !1;
1255
1255
  }
1256
- if (I && $.hasHighS())
1256
+ if (U && $.hasHighS())
1257
1257
  return !1;
1258
1258
  O && (v = t.hash(v));
1259
1259
  const { r: ge, s: Le } = $, We = x(v), we = a(Le), mt = c(We * we), Ke = c(ge * we), $e = (Te = l.BASE.multiplyAndAddUnsafe(Q, mt, Ke)) == null ? void 0 : Te.toAffine();
@@ -1320,14 +1320,14 @@ function as(e, t) {
1320
1320
  return Object.freeze({ ...n(t), create: n });
1321
1321
  }
1322
1322
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1323
- const ct = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), tt = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), rr = BigInt(1), nt = BigInt(2), Un = (e, t) => (e + t / nt) / t;
1323
+ const ct = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), tt = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), rr = BigInt(1), nt = BigInt(2), In = (e, t) => (e + t / nt) / t;
1324
1324
  function ir(e) {
1325
- const t = ct, 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 = J(f, n, t) * f % t, g = J(u, n, t) * f % t, b = J(g, nt, t) * l % t, p = J(b, i, t) * b % t, h = J(p, s, t) * p % t, d = J(h, c, t) * h % t, y = J(d, a, t) * d % t, m = J(y, c, t) * h % t, A = J(m, n, t) * f % t, U = J(A, o, t) * p % t, B = J(U, r, t) * l % t, E = J(B, nt, t);
1325
+ const t = ct, 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 = J(f, n, t) * f % t, g = J(u, n, t) * f % t, b = J(g, nt, t) * l % t, p = J(b, i, t) * b % t, h = J(p, s, t) * p % t, d = J(h, c, t) * h % t, y = J(d, a, t) * d % t, m = J(y, c, t) * h % t, A = J(m, n, t) * f % t, I = J(A, o, t) * p % t, B = J(I, r, t) * l % t, E = J(B, 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 = Ji(ct, void 0, void 0, { sqrt: ir }), Ie = as({
1330
+ const Ot = Ji(ct, void 0, void 0, { sqrt: ir }), Ue = as({
1331
1331
  a: BigInt(0),
1332
1332
  b: BigInt(7),
1333
1333
  Fp: Ot,
@@ -1346,7 +1346,7 @@ const Ot = Ji(ct, void 0, void 0, { sqrt: ir }), Ie = as({
1346
1346
  endo: {
1347
1347
  beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
1348
1348
  splitScalar: (e) => {
1349
- const t = tt, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -rr * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), s = n, o = BigInt("0x100000000000000000000000000000000"), c = Un(s * e, t), a = Un(-r * e, t);
1349
+ const t = tt, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -rr * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), s = n, o = BigInt("0x100000000000000000000000000000000"), c = In(s * e, t), a = In(-r * e, t);
1350
1350
  let l = V(e - c * n - a * i, t), f = V(-c * r - a * s, t);
1351
1351
  const u = l > o, g = f > o;
1352
1352
  if (u && (l = t - l), g && (f = t - f), l > o || f > o)
@@ -1354,18 +1354,18 @@ const Ot = Ji(ct, void 0, void 0, { sqrt: ir }), Ie = as({
1354
1354
  return { k1neg: u, k1: l, k2neg: g, k2: f };
1355
1355
  }
1356
1356
  }
1357
- }, $t), ut = BigInt(0), sr = (e) => typeof e == "bigint" && ut < e && e < ct, cs = (e) => typeof e == "bigint" && ut < e && e < tt, In = {};
1357
+ }, $t), ut = BigInt(0), sr = (e) => typeof e == "bigint" && ut < e && e < ct, cs = (e) => typeof e == "bigint" && ut < e && e < tt, Un = {};
1358
1358
  function rt(e, ...t) {
1359
- let n = In[e];
1359
+ let n = Un[e];
1360
1360
  if (n === void 0) {
1361
1361
  const r = $t(Uint8Array.from(e, (i) => i.charCodeAt(0)));
1362
- n = Ue(r, r), In[e] = n;
1362
+ n = Ie(r, r), Un[e] = n;
1363
1363
  }
1364
- return $t(Ue(n, ...t));
1364
+ return $t(Ie(n, ...t));
1365
1365
  }
1366
- const Xt = (e) => e.toRawBytes(!0).slice(1), Mt = (e) => Ne(e, 32), Kt = (e) => V(e, ct), Fe = (e) => V(e, tt), Qt = Ie.ProjectivePoint, us = (e, t, n) => Qt.BASE.multiplyAndAddUnsafe(e, t, n);
1366
+ const Xt = (e) => e.toRawBytes(!0).slice(1), Mt = (e) => Ne(e, 32), Kt = (e) => V(e, ct), Fe = (e) => V(e, tt), Qt = Ue.ProjectivePoint, us = (e, t, n) => Qt.BASE.multiplyAndAddUnsafe(e, t, n);
1367
1367
  function Pt(e) {
1368
- let t = Ie.utils.normPrivateKeyToScalar(e), n = Qt.fromPrivateKey(t);
1368
+ let t = Ue.utils.normPrivateKeyToScalar(e), n = Qt.fromPrivateKey(t);
1369
1369
  return { scalar: n.hasEvenY() ? t : Fe(-t), bytes: Xt(n) };
1370
1370
  }
1371
1371
  function or(e) {
@@ -1412,7 +1412,7 @@ const Ze = {
1412
1412
  sign: fs,
1413
1413
  verify: cr,
1414
1414
  utils: {
1415
- randomPrivateKey: Ie.utils.randomPrivateKey,
1415
+ randomPrivateKey: Ue.utils.randomPrivateKey,
1416
1416
  lift_x: or,
1417
1417
  pointToBytes: Xt,
1418
1418
  numberToBytesBE: Ne,
@@ -1979,13 +1979,13 @@ gr("bech32m");
1979
1979
  const _s = {
1980
1980
  encode: (e) => new TextDecoder().decode(e),
1981
1981
  decode: (e) => new TextEncoder().encode(e)
1982
- }, Us = de(Ae(4), pe("0123456789abcdef"), ye(""), pr((e) => {
1982
+ }, Is = de(Ae(4), pe("0123456789abcdef"), ye(""), pr((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
- })), Is = {
1986
+ })), Us = {
1987
1987
  utf8: _s,
1988
- hex: Us,
1988
+ hex: Is,
1989
1989
  base16: Ks,
1990
1990
  base32: Cs,
1991
1991
  base64: he,
@@ -1993,7 +1993,7 @@ const _s = {
1993
1993
  base58: Dt,
1994
1994
  base58xmr: ks
1995
1995
  };
1996
- `${Object.keys(Is).join(", ")}`;
1996
+ `${Object.keys(Us).join(", ")}`;
1997
1997
  function kt(e) {
1998
1998
  if (!Number.isSafeInteger(e) || e < 0)
1999
1999
  throw new Error(`positive integer expected, not ${e}`);
@@ -2189,10 +2189,10 @@ const mr = /* @__PURE__ */ Os({ blockSize: 16, nonceLength: 16 }, function(t, n,
2189
2189
  const c = Ds(t), a = Z(n), l = Er(s.length, o), f = Z(s), u = Z(l);
2190
2190
  let g = a[0], b = a[1], p = a[2], h = a[3];
2191
2191
  for (let d = 0; d + 4 <= f.length; ) {
2192
- const y = g, m = b, A = p, U = h;
2192
+ const y = g, m = b, A = p, I = h;
2193
2193
  g = f[d + 0], b = f[d + 1], p = f[d + 2], h = f[d + 3];
2194
2194
  const { s0: B, s1: E, s2: x, s3: S } = js(c, g, b, p, h);
2195
- u[d++] = B ^ y, u[d++] = E ^ m, u[d++] = x ^ A, u[d++] = S ^ U;
2195
+ u[d++] = B ^ y, u[d++] = E ^ m, u[d++] = x ^ A, u[d++] = S ^ I;
2196
2196
  }
2197
2197
  return c.fill(0), Ws(l, i);
2198
2198
  }
@@ -2256,8 +2256,8 @@ function Qs(e, t) {
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 U = new Uint8Array(12);
2260
- U.set(a, s ? 0 : 12 - a.length), a = U, b.push(a);
2259
+ const I = new Uint8Array(12);
2260
+ I.set(a, s ? 0 : 12 - a.length), a = I, b.push(a);
2261
2261
  }
2262
2262
  const A = Z(a);
2263
2263
  for (Xs(e, d, y, A, l, f, u, o); b.length > 0; )
@@ -2266,11 +2266,11 @@ function Qs(e, t) {
2266
2266
  };
2267
2267
  }
2268
2268
  function eo(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], g = t[2], b = t[3], p = t[4], h = t[5], d = t[6], y = t[7], m = i, A = n[0], U = n[1], B = n[2], E = o, x = c, S = a, P = l, _ = f, K = u, T = g, R = b, H = p, w = h, v = d, N = y, k = m, C = A, I = U, O = B;
2269
+ let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1], g = t[2], b = t[3], p = t[4], h = t[5], d = t[6], y = t[7], m = i, A = n[0], I = n[1], B = n[2], E = o, x = c, S = a, P = l, _ = f, K = u, T = g, R = b, H = p, w = h, v = d, N = y, k = m, C = A, U = I, O = B;
2270
2270
  for (let Q = 0; Q < s; Q += 2)
2271
- E = E + _ | 0, k = L(k ^ E, 16), H = H + k | 0, _ = L(_ ^ H, 12), E = E + _ | 0, k = L(k ^ E, 8), H = H + k | 0, _ = L(_ ^ H, 7), x = x + K | 0, C = L(C ^ x, 16), w = w + C | 0, K = L(K ^ w, 12), x = x + K | 0, C = L(C ^ x, 8), w = w + C | 0, K = L(K ^ w, 7), S = S + T | 0, I = L(I ^ S, 16), v = v + I | 0, T = L(T ^ v, 12), S = S + T | 0, I = L(I ^ S, 8), v = v + I | 0, T = L(T ^ v, 7), P = P + R | 0, O = L(O ^ P, 16), N = N + O | 0, R = L(R ^ N, 12), P = P + R | 0, O = L(O ^ P, 8), N = N + O | 0, R = L(R ^ N, 7), E = E + K | 0, O = L(O ^ E, 16), v = v + O | 0, K = L(K ^ v, 12), E = E + K | 0, O = L(O ^ E, 8), v = v + O | 0, K = L(K ^ v, 7), x = x + T | 0, k = L(k ^ x, 16), N = N + k | 0, T = L(T ^ N, 12), x = x + T | 0, k = L(k ^ x, 8), N = N + k | 0, T = L(T ^ N, 7), S = S + R | 0, C = L(C ^ S, 16), H = H + C | 0, R = L(R ^ H, 12), S = S + R | 0, C = L(C ^ S, 8), H = H + C | 0, R = L(R ^ H, 7), P = P + _ | 0, I = L(I ^ P, 16), w = w + I | 0, _ = L(_ ^ w, 12), P = P + _ | 0, I = L(I ^ P, 8), w = w + I | 0, _ = L(_ ^ w, 7);
2271
+ E = E + _ | 0, k = L(k ^ E, 16), H = H + k | 0, _ = L(_ ^ H, 12), E = E + _ | 0, k = L(k ^ E, 8), H = H + k | 0, _ = L(_ ^ H, 7), x = x + K | 0, C = L(C ^ x, 16), w = w + C | 0, K = L(K ^ w, 12), x = x + K | 0, C = L(C ^ x, 8), w = w + C | 0, K = L(K ^ w, 7), S = S + T | 0, U = L(U ^ S, 16), v = v + U | 0, T = L(T ^ v, 12), S = S + T | 0, U = L(U ^ S, 8), v = v + U | 0, T = L(T ^ v, 7), P = P + R | 0, O = L(O ^ P, 16), N = N + O | 0, R = L(R ^ N, 12), P = P + R | 0, O = L(O ^ P, 8), N = N + O | 0, R = L(R ^ N, 7), E = E + K | 0, O = L(O ^ E, 16), v = v + O | 0, K = L(K ^ v, 12), E = E + K | 0, O = L(O ^ E, 8), v = v + O | 0, K = L(K ^ v, 7), x = x + T | 0, k = L(k ^ x, 16), N = N + k | 0, T = L(T ^ N, 12), x = x + T | 0, k = L(k ^ x, 8), N = N + k | 0, T = L(T ^ N, 7), S = S + R | 0, C = L(C ^ S, 16), H = H + C | 0, R = L(R ^ H, 12), S = S + R | 0, C = L(C ^ S, 8), H = H + C | 0, R = L(R ^ H, 7), P = P + _ | 0, U = L(U ^ P, 16), w = w + U | 0, _ = L(_ ^ w, 12), P = P + _ | 0, U = L(U ^ P, 8), w = w + U | 0, _ = L(_ ^ w, 7);
2272
2272
  let $ = 0;
2273
- r[$++] = o + E | 0, r[$++] = c + x | 0, r[$++] = a + S | 0, r[$++] = l + P | 0, r[$++] = f + _ | 0, r[$++] = u + K | 0, r[$++] = g + T | 0, r[$++] = b + R | 0, r[$++] = p + H | 0, r[$++] = h + w | 0, r[$++] = d + v | 0, r[$++] = y + N | 0, r[$++] = m + k | 0, r[$++] = A + C | 0, r[$++] = U + I | 0, r[$++] = B + O | 0;
2273
+ r[$++] = o + E | 0, r[$++] = c + x | 0, r[$++] = a + S | 0, r[$++] = l + P | 0, r[$++] = f + _ | 0, r[$++] = u + K | 0, r[$++] = g + T | 0, r[$++] = b + R | 0, r[$++] = p + H | 0, r[$++] = h + w | 0, r[$++] = d + v | 0, r[$++] = y + N | 0, r[$++] = m + k | 0, r[$++] = A + C | 0, r[$++] = I + U | 0, r[$++] = B + O | 0;
2274
2274
  }
2275
2275
  const Ar = /* @__PURE__ */ Qs(eo, {
2276
2276
  counterRight: !1,
@@ -2317,7 +2317,7 @@ ht.create = (e, t) => new Kr(e, t);
2317
2317
  function sn(e, t, n) {
2318
2318
  return se.hash(e), n === void 0 && (n = new Uint8Array(e.outputLen)), ht(e, Je(n), Je(t));
2319
2319
  }
2320
- const Ut = new Uint8Array([0]), qn = new Uint8Array();
2320
+ const It = new Uint8Array([0]), qn = new Uint8Array();
2321
2321
  function Cr(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");
@@ -2325,8 +2325,8 @@ function Cr(e, t, n, r = 32) {
2325
2325
  n === void 0 && (n = qn);
2326
2326
  const s = new Uint8Array(i * e.outputLen), o = ht.create(e, t), c = o._cloneInto(), a = new Uint8Array(o.outputLen);
2327
2327
  for (let l = 0; l < i; l++)
2328
- Ut[0] = l + 1, c.update(l === 0 ? qn : 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);
2328
+ It[0] = l + 1, c.update(l === 0 ? qn : a).update(n).update(It).digestInto(a), s.set(a, e.outputLen * l), o._cloneInto(c);
2329
+ return o.destroy(), c.destroy(), a.fill(0), It.fill(0), s.slice(0, r);
2330
2330
  }
2331
2331
  var to = Object.defineProperty, D = (e, t) => {
2332
2332
  for (var n in t)
@@ -2485,8 +2485,8 @@ D(lo, {
2485
2485
  InterestsList: () => Wo,
2486
2486
  Interestsets: () => aa,
2487
2487
  JobFeedback: () => Lo,
2488
- JobRequest: () => Uo,
2489
- JobResult: () => Io,
2488
+ JobRequest: () => Io,
2489
+ JobResult: () => Uo,
2490
2490
  Label: () => ko,
2491
2491
  LightningPubRPC: () => Yo,
2492
2492
  LiveChatMessage: () => Ao,
@@ -2521,9 +2521,9 @@ D(lo, {
2521
2521
  ZapGoal: () => $o,
2522
2522
  ZapRequest: () => To,
2523
2523
  classifyKind: () => fo,
2524
- isEphemeralKind: () => Ur,
2524
+ isEphemeralKind: () => Ir,
2525
2525
  isKind: () => ho,
2526
- isParameterizedReplaceableKind: () => Ir,
2526
+ isParameterizedReplaceableKind: () => Ur,
2527
2527
  isRegularKind: () => kr,
2528
2528
  isReplaceableKind: () => _r
2529
2529
  });
@@ -2533,20 +2533,20 @@ function kr(e) {
2533
2533
  function _r(e) {
2534
2534
  return [0, 3].includes(e) || 1e4 <= e && e < 2e4;
2535
2535
  }
2536
- function Ur(e) {
2536
+ function Ir(e) {
2537
2537
  return 2e4 <= e && e < 3e4;
2538
2538
  }
2539
- function Ir(e) {
2539
+ function Ur(e) {
2540
2540
  return 3e4 <= e && e < 4e4;
2541
2541
  }
2542
2542
  function fo(e) {
2543
- return kr(e) ? "regular" : _r(e) ? "replaceable" : Ur(e) ? "ephemeral" : Ir(e) ? "parameterized" : "unknown";
2543
+ return kr(e) ? "regular" : _r(e) ? "replaceable" : Ir(e) ? "ephemeral" : Ur(e) ? "parameterized" : "unknown";
2544
2544
  }
2545
2545
  function ho(e, t) {
2546
2546
  const n = t instanceof Array ? t : [t];
2547
2547
  return dt(e) && n.includes(e.kind) || !1;
2548
2548
  }
2549
- var po = 0, yo = 1, go = 2, wo = 3, bo = 4, vo = 5, an = 6, cn = 7, Eo = 8, Lr = 13, mo = 14, xo = 16, $r = 40, Tr = 41, Rr = 42, Or = 43, Mr = 44, So = 1040, Pr = 1059, No = 1063, Ao = 1311, Ko = 1971, Co = 1984, Bo = 1984, ko = 1985, _o = 4550, Uo = 5999, Io = 6999, Lo = 7e3, $o = 9041, To = 9734, Ro = 9735, Oo = 9802, Mo = 1e4, Po = 10001, Ho = 10002, qo = 10003, Do = 10004, jo = 10005, zo = 10006, Vo = 10007, Wo = 10015, Zo = 10030, Go = 10050, Fo = 10096, Jo = 13194, Yo = 21e3, Hr = 22242, qr = 23194, Xo = 23195, Qo = 24133, un = 27235, ea = 3e4, ta = 30001, na = 30002, ra = 30003, ia = 30004, sa = 30008, oa = 30009, aa = 30015, ca = 30017, ua = 30018, la = 30023, fa = 30024, ha = 30030, da = 30078, pa = 30311, ya = 30315, ga = 30402, wa = 30403, ba = 31922, va = 31923, Ea = 31924, ma = 31925, xa = 31989, Sa = 31990, Na = 34550, Aa = {};
2549
+ var po = 0, yo = 1, go = 2, wo = 3, bo = 4, vo = 5, an = 6, cn = 7, Eo = 8, Lr = 13, mo = 14, xo = 16, $r = 40, Tr = 41, Rr = 42, Or = 43, Mr = 44, So = 1040, Pr = 1059, No = 1063, Ao = 1311, Ko = 1971, Co = 1984, Bo = 1984, ko = 1985, _o = 4550, Io = 5999, Uo = 6999, Lo = 7e3, $o = 9041, To = 9734, Ro = 9735, Oo = 9802, Mo = 1e4, Po = 10001, Ho = 10002, qo = 10003, Do = 10004, jo = 10005, zo = 10006, Vo = 10007, Wo = 10015, Zo = 10030, Go = 10050, Fo = 10096, Jo = 13194, Yo = 21e3, Hr = 22242, qr = 23194, Xo = 23195, Qo = 24133, un = 27235, ea = 3e4, ta = 30001, na = 30002, ra = 30003, ia = 30004, sa = 30008, oa = 30009, aa = 30015, ca = 30017, ua = 30018, la = 30023, fa = 30024, ha = 30030, da = 30078, pa = 30311, ya = 30315, ga = 30402, wa = 30403, ba = 31922, va = 31923, Ea = 31924, ma = 31925, xa = 31989, Sa = 31990, Na = 34550, Aa = {};
2550
2550
  D(Aa, {
2551
2551
  getHex64: () => ln,
2552
2552
  getInt: () => Dr,
@@ -2587,9 +2587,9 @@ function ka(e, t) {
2587
2587
  }
2588
2588
  var _a = {};
2589
2589
  D(_a, {
2590
- makeAuthEvent: () => Ua
2590
+ makeAuthEvent: () => Ia
2591
2591
  });
2592
- function Ua(e, t) {
2592
+ function Ia(e, t) {
2593
2593
  return {
2594
2594
  kind: Hr,
2595
2595
  created_at: Math.floor(Date.now() / 1e3),
@@ -2600,9 +2600,9 @@ function Ua(e, t) {
2600
2600
  content: ""
2601
2601
  };
2602
2602
  }
2603
- var Ia;
2603
+ var Ua;
2604
2604
  try {
2605
- Ia = WebSocket;
2605
+ Ua = WebSocket;
2606
2606
  } catch {
2607
2607
  }
2608
2608
  var La;
@@ -2642,7 +2642,7 @@ function gt(e) {
2642
2642
  let { prefix: t, words: n } = ze.decode(e, fn), r = new Uint8Array(ze.fromWords(n));
2643
2643
  switch (t) {
2644
2644
  case "nprofile": {
2645
- let u = It(r);
2645
+ let u = Ut(r);
2646
2646
  if (!((i = u[0]) != null && i[0]))
2647
2647
  throw new Error("missing TLV 0 for nprofile");
2648
2648
  if (u[0][0].length !== 32)
@@ -2656,7 +2656,7 @@ function gt(e) {
2656
2656
  };
2657
2657
  }
2658
2658
  case "nevent": {
2659
- let u = It(r);
2659
+ let u = Ut(r);
2660
2660
  if (!((s = u[0]) != null && s[0]))
2661
2661
  throw new Error("missing TLV 0 for nevent");
2662
2662
  if (u[0][0].length !== 32)
@@ -2676,7 +2676,7 @@ function gt(e) {
2676
2676
  };
2677
2677
  }
2678
2678
  case "naddr": {
2679
- let u = It(r);
2679
+ let u = Ut(r);
2680
2680
  if (!((a = u[0]) != null && a[0]))
2681
2681
  throw new Error("missing TLV 0 for naddr");
2682
2682
  if (!((l = u[2]) != null && l[0]))
@@ -2706,7 +2706,7 @@ function gt(e) {
2706
2706
  throw new Error(`unknown prefix ${t}`);
2707
2707
  }
2708
2708
  }
2709
- function It(e) {
2709
+ function Ut(e) {
2710
2710
  let t = {}, n = e;
2711
2711
  for (; n.length > 0; ) {
2712
2712
  let r = n[0], i = n[1], s = n.slice(2, 2 + i);
@@ -2776,13 +2776,13 @@ D(ja, {
2776
2776
  encrypt: () => zr
2777
2777
  });
2778
2778
  async function zr(e, t, n) {
2779
- const r = e instanceof Uint8Array ? M(e) : e, i = Ie.getSharedSecret(r, "02" + t), s = Vr(i);
2779
+ const r = e instanceof Uint8Array ? M(e) : e, i = Ue.getSharedSecret(r, "02" + t), s = Vr(i);
2780
2780
  let o = Uint8Array.from(fr(16)), c = ne.encode(n), a = mr(s, o).encrypt(c), l = he.encode(new Uint8Array(a)), f = he.encode(new Uint8Array(o.buffer));
2781
2781
  return `${l}?iv=${f}`;
2782
2782
  }
2783
2783
  async function za(e, t, n) {
2784
2784
  const r = e instanceof Uint8Array ? M(e) : e;
2785
- let [i, s] = n.split("?iv="), o = Ie.getSharedSecret(r, "02" + t), c = Vr(o), a = he.decode(s), l = he.decode(i), f = mr(c, a).decrypt(l);
2785
+ let [i, s] = n.split("?iv="), o = Ue.getSharedSecret(r, "02" + t), c = Vr(o), a = he.decode(s), l = he.decode(i), f = mr(c, a).decrypt(l);
2786
2786
  return ue.decode(f);
2787
2787
  }
2788
2788
  function Vr(e) {
@@ -3224,11 +3224,11 @@ D(q, {
3224
3224
  decrypt: () => En,
3225
3225
  encrypt: () => vn,
3226
3226
  getConversationKey: () => wn,
3227
- v2: () => Uc
3227
+ v2: () => Ic
3228
3228
  });
3229
3229
  var Xr = 1, Qr = 65535;
3230
3230
  function wn(e, t) {
3231
- const n = Ie.getSharedSecret(e, "02" + t).subarray(1, 33);
3231
+ const n = Ue.getSharedSecret(e, "02" + t).subarray(1, 33);
3232
3232
  return sn(fe, n, "nip44-v2");
3233
3233
  }
3234
3234
  function ei(e, t) {
@@ -3306,15 +3306,15 @@ function En(e, t) {
3306
3306
  const l = Ar(s, o, r);
3307
3307
  return kc(l);
3308
3308
  }
3309
- var Uc = {
3309
+ var Ic = {
3310
3310
  utils: {
3311
3311
  getConversationKey: wn,
3312
3312
  calcPaddedLen: bn
3313
3313
  },
3314
3314
  encrypt: vn,
3315
3315
  decrypt: En
3316
- }, Ic = {};
3317
- D(Ic, {
3316
+ }, Uc = {};
3317
+ D(Uc, {
3318
3318
  makeNwcRequestEvent: () => $c,
3319
3319
  parseConnectionString: () => Lc
3320
3320
  });
@@ -3669,6 +3669,10 @@ function Me(e, t = new Uint8Array(32), n = 1) {
3669
3669
  function Lt(e, t) {
3670
3670
  return `${e}:${t}`;
3671
3671
  }
3672
+ function au(e) {
3673
+ const t = e.tags.find((n) => n[0] === "ms");
3674
+ return t ? parseInt(t[1]) : e.created_at * 1e3;
3675
+ }
3672
3676
  const Fc = 1e3, Jc = "0000000000000000000000000000000000000000000000000000000000000000";
3673
3677
  class st {
3674
3678
  // 1. CHANNEL PUBLIC INTERFACE
@@ -3743,12 +3747,12 @@ class st {
3743
3747
  };
3744
3748
  n.tags.some(([a]) => a === "ms") || n.tags.push(["ms", Date.now().toString()]), n.id = qe(n);
3745
3749
  const [r, i] = this.ratchetEncrypt(JSON.stringify(n)), s = q.getConversationKey(this.state.ourCurrentNostrKey.privateKey, this.state.theirNextNostrPublicKey), o = q.encrypt(JSON.stringify(r), s);
3746
- return X({
3750
+ return { event: X({
3747
3751
  content: i,
3748
3752
  kind: Be,
3749
3753
  tags: [["header", o]],
3750
3754
  created_at: Math.floor(Date.now() / 1e3)
3751
- }, this.state.ourCurrentNostrKey.privateKey);
3755
+ }, this.state.ourCurrentNostrKey.privateKey), innerEvent: n };
3752
3756
  }
3753
3757
  /**
3754
3758
  * Subscribes to incoming messages on this session
@@ -3894,7 +3898,7 @@ class st {
3894
3898
  new TextDecoder("utf-8");
3895
3899
  new TextEncoder();
3896
3900
  function Qe(e, t) {
3897
- const n = Ie.getSharedSecret(e, "02" + t).subarray(1, 33);
3901
+ const n = Ue.getSharedSecret(e, "02" + t).subarray(1, 33);
3898
3902
  return sn(fe, n, "nip44-v2");
3899
3903
  }
3900
3904
  class Pe {
@@ -4082,6 +4086,7 @@ export {
4082
4086
  st as Session,
4083
4087
  ou as createEventStream,
4084
4088
  su as deserializeSessionState,
4089
+ au as getMillisecondTimestamp,
4085
4090
  Me as kdf,
4086
4091
  iu as serializeSessionState,
4087
4092
  Lt as skippedMessageIndexKey
@@ -1 +1 @@
1
- (function(H,J){typeof exports=="object"&&typeof module<"u"?J(exports):typeof define=="function"&&define.amd?define(["exports"],J):(H=typeof globalThis<"u"?globalThis:H||self,J(H["nostr-double-ratchet"]={}))})(this,function(H){"use strict";var Jc=Object.defineProperty;var Yc=(H,J,ke)=>J in H?Jc(H,J,{enumerable:!0,configurable:!0,writable:!0,value:ke}):H[J]=ke;var ie=(H,J,ke)=>Yc(H,typeof J!="symbol"?J+"":J,ke);function J(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function ke(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Ei(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");J(e.outputLen),J(e.blockLen)}function nt(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function mi(e,t){ke(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const At=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Cn=e=>e instanceof Uint8Array,Kt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),se=(e,t)=>e<<32-t|e>>>t;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function xi(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ct(e){if(typeof e=="string"&&(e=xi(e)),!Cn(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function Si(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!Cn(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}let Bn=class{clone(){return this._cloneInto()}};function Ni(e){const t=r=>e().update(Ct(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function kn(e=32){if(At&&typeof At.getRandomValues=="function")return At.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Ai(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),c=Number(n&s),a=r?4:0,l=r?0:4;e.setUint32(t+a,o,r),e.setUint32(t+l,c,r)}let Ki=class extends Bn{constructor(t,n,r,i){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)}update(t){nt(this);const{view:n,buffer:r,blockLen:i}=this;t=Ct(t);const s=t.length;for(let o=0;o<s;){const c=Math.min(i-this.pos,s-o);if(c===i){const a=Kt(t);for(;i<=s-o;o+=i)this.process(a,o);continue}r.set(t.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){nt(this),mi(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(r,0),o=0);for(let u=o;u<i;u++)n[u]=0;Ai(r,i-8,BigInt(this.length*8),s),this.process(r,0);const c=Kt(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)c.setUint32(4*u,f[u],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:c}=this;return t.length=i,t.pos=c,t.finished=s,t.destroyed=o,i%n&&t.buffer.set(r),t}};const Ci=(e,t,n)=>e&t^~e&n,Bi=(e,t,n)=>e&t^e&n^t&n,ki=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),be=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ve=new Uint32Array(64);let _i=class extends Ki{constructor(){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}get(){const{A:t,B:n,C:r,D:i,E:s,F:o,G:c,H:a}=this;return[t,n,r,i,s,o,c,a]}set(t,n,r,i,s,o,c,a){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(t,n){for(let u=0;u<16;u++,n+=4)ve[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const g=ve[u-15],b=ve[u-2],p=se(g,7)^se(g,18)^g>>>3,h=se(b,17)^se(b,19)^b>>>10;ve[u]=h+ve[u-7]+p+ve[u-16]|0}let{A:r,B:i,C:s,D:o,E:c,F:a,G:l,H:f}=this;for(let u=0;u<64;u++){const g=se(c,6)^se(c,11)^se(c,25),b=f+g+Ci(c,a,l)+ki[u]+ve[u]|0,h=(se(r,2)^se(r,13)^se(r,22))+Bi(r,i,s)|0;f=l,l=a,a=c,c=o+b|0,o=s,s=i,i=r,r=b+h|0}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)}roundClean(){ve.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Bt=Ni(()=>new _i);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _n=BigInt(0),rt=BigInt(1),Ii=BigInt(2),it=e=>e instanceof Uint8Array,Ui=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Me(e){if(!it(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Ui[e[n]];return t}function In(e){const t=e.toString(16);return t.length&1?`0${t}`:t}function kt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return BigInt(e===""?"0":`0x${e}`)}function Pe(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){const i=r*2,s=e.slice(i,i+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[r]=o}return n}function Y(e){return kt(Me(e))}function _t(e){if(!it(e))throw new Error("Uint8Array expected");return kt(Me(Uint8Array.from(e).reverse()))}function Ee(e,t){return Pe(e.toString(16).padStart(t*2,"0"))}function It(e,t){return Ee(e,t).reverse()}function Li(e){return Pe(In(e))}function Z(e,t,n){let r;if(typeof t=="string")try{r=Pe(t)}catch(s){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${s}`)}else if(it(t))r=Uint8Array.from(t);else throw new Error(`${e} must be hex string or Uint8Array`);const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(`${e} expected ${n} bytes, got ${i}`);return r}function _e(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!it(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function $i(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Ti(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ri(e){let t;for(t=0;e>_n;e>>=rt,t+=1);return t}function Oi(e,t){return e>>BigInt(t)&rt}const Mi=(e,t,n)=>e|(n?rt:_n)<<BigInt(t),Ut=e=>(Ii<<BigInt(e-1))-rt,Lt=e=>new Uint8Array(e),Un=e=>Uint8Array.from(e);function Ln(e,t,n){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=Lt(e),i=Lt(e),s=0;const o=()=>{r.fill(1),i.fill(0),s=0},c=(...u)=>n(i,r,...u),a=(u=Lt())=>{i=c(Un([0]),u),r=c(),u.length!==0&&(i=c(Un([1]),u),r=c())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const g=[];for(;u<t;){r=c();const b=r.slice();g.push(b),u+=r.length}return _e(...g)};return(u,g)=>{o(),a(u);let b;for(;!(b=g(l()));)a();return o(),b}}const Pi={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Fe(e,t,n={}){const r=(i,s,o)=>{const c=Pi[s];if(typeof c!="function")throw new Error(`Invalid validator "${s}", expected function`);const a=e[i];if(!(o&&a===void 0)&&!c(a,e))throw new Error(`Invalid param ${String(i)}=${a} (${typeof a}), expected ${s}`)};for(const[i,s]of Object.entries(t))r(i,s,!1);for(const[i,s]of Object.entries(n))r(i,s,!0);return e}const Hi=Object.freeze(Object.defineProperty({__proto__:null,bitGet:Oi,bitLen:Ri,bitMask:Ut,bitSet:Mi,bytesToHex:Me,bytesToNumberBE:Y,bytesToNumberLE:_t,concatBytes:_e,createHmacDrbg:Ln,ensureBytes:Z,equalBytes:$i,hexToBytes:Pe,hexToNumber:kt,numberToBytesBE:Ee,numberToBytesLE:It,numberToHexUnpadded:In,numberToVarBytesBE:Li,utf8ToBytes:Ti,validateObject:Fe},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const V=BigInt(0),z=BigInt(1),Ie=BigInt(2),Di=BigInt(3),$t=BigInt(4),$n=BigInt(5),Tn=BigInt(8);BigInt(9),BigInt(16);function W(e,t){const n=e%t;return n>=V?n:t+n}function qi(e,t,n){if(n<=V||t<V)throw new Error("Expected power/modulo > 0");if(n===z)return V;let r=z;for(;t>V;)t&z&&(r=r*e%n),e=e*e%n,t>>=z;return r}function X(e,t,n){let r=e;for(;t-- >V;)r*=r,r%=n;return r}function Tt(e,t){if(e===V||t<=V)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=W(e,t),r=t,i=V,s=z;for(;n!==V;){const c=r/n,a=r%n,l=i-s*c;r=n,n=a,i=s,s=l}if(r!==z)throw new Error("invert: does not exist");return W(i,t)}function ji(e){const t=(e-z)/Ie;let n,r,i;for(n=e-z,r=0;n%Ie===V;n/=Ie,r++);for(i=Ie;i<e&&qi(i,t,e)!==e-z;i++);if(r===1){const o=(e+z)/$t;return function(a,l){const f=a.pow(l,o);if(!a.eql(a.sqr(f),l))throw new Error("Cannot find square root");return f}}const s=(n+z)/Ie;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let l=r,f=c.pow(c.mul(c.ONE,i),n),u=c.pow(a,s),g=c.pow(a,n);for(;!c.eql(g,c.ONE);){if(c.eql(g,c.ZERO))return c.ZERO;let b=1;for(let h=c.sqr(g);b<l&&!c.eql(h,c.ONE);b++)h=c.sqr(h);const p=c.pow(f,z<<BigInt(l-b-1));f=c.sqr(p),u=c.mul(u,p),g=c.mul(g,f),l=b}return u}}function zi(e){if(e%$t===Di){const t=(e+z)/$t;return function(r,i){const s=r.pow(i,t);if(!r.eql(r.sqr(s),i))throw new Error("Cannot find square root");return s}}if(e%Tn===$n){const t=(e-$n)/Tn;return function(r,i){const s=r.mul(i,Ie),o=r.pow(s,t),c=r.mul(i,o),a=r.mul(r.mul(c,Ie),o),l=r.mul(c,r.sub(a,r.ONE));if(!r.eql(r.sqr(l),i))throw new Error("Cannot find square root");return l}}return ji(e)}const Vi=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wi(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=Vi.reduce((r,i)=>(r[i]="function",r),t);return Fe(e,n)}function Zi(e,t,n){if(n<V)throw new Error("Expected power > 0");if(n===V)return e.ONE;if(n===z)return t;let r=e.ONE,i=t;for(;n>V;)n&z&&(r=e.mul(r,i)),i=e.sqr(i),n>>=z;return r}function Gi(e,t){const n=new Array(t.length),r=t.reduce((s,o,c)=>e.is0(o)?s:(n[c]=s,e.mul(s,o)),e.ONE),i=e.inv(r);return t.reduceRight((s,o,c)=>e.is0(o)?s:(n[c]=e.mul(s,n[c]),e.mul(s,o)),i),n}function Rn(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Fi(e,t,n=!1,r={}){if(e<=V)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:i,nByteLength:s}=Rn(e,t);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");const o=zi(e),c=Object.freeze({ORDER:e,BITS:i,BYTES:s,MASK:Ut(i),ZERO:V,ONE:z,create:a=>W(a,e),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return V<=a&&a<e},is0:a=>a===V,isOdd:a=>(a&z)===z,neg:a=>W(-a,e),eql:(a,l)=>a===l,sqr:a=>W(a*a,e),add:(a,l)=>W(a+l,e),sub:(a,l)=>W(a-l,e),mul:(a,l)=>W(a*l,e),pow:(a,l)=>Zi(c,a,l),div:(a,l)=>W(a*Tt(l,e),e),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Tt(a,e),sqrt:r.sqrt||(a=>o(c,a)),invertBatch:a=>Gi(c,a),cmov:(a,l,f)=>f?l:a,toBytes:a=>n?It(a,s):Ee(a,s),fromBytes:a=>{if(a.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${a.length}`);return n?_t(a):Y(a)}});return Object.freeze(c)}function On(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Mn(e){const t=On(e);return t+Math.ceil(t/2)}function Ji(e,t,n=!1){const r=e.length,i=On(t),s=Mn(t);if(r<16||r<s||r>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);const o=n?Y(e):_t(e),c=W(o,t-z)+z;return n?It(c,i):Ee(c,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Yi=BigInt(0),Rt=BigInt(1);function Xi(e,t){const n=(i,s)=>{const o=s.negate();return i?o:s},r=i=>{const s=Math.ceil(t/i)+1,o=2**(i-1);return{windows:s,windowSize:o}};return{constTimeNegate:n,unsafeLadder(i,s){let o=e.ZERO,c=i;for(;s>Yi;)s&Rt&&(o=o.add(c)),c=c.double(),s>>=Rt;return o},precomputeWindow(i,s){const{windows:o,windowSize:c}=r(s),a=[];let l=i,f=l;for(let u=0;u<o;u++){f=l,a.push(f);for(let g=1;g<c;g++)f=f.add(l),a.push(f);l=f.double()}return a},wNAF(i,s,o){const{windows:c,windowSize:a}=r(i);let l=e.ZERO,f=e.BASE;const u=BigInt(2**i-1),g=2**i,b=BigInt(i);for(let p=0;p<c;p++){const h=p*a;let d=Number(o&u);o>>=b,d>a&&(d-=g,o+=Rt);const y=h,m=h+Math.abs(d)-1,A=p%2!==0,I=d<0;d===0?f=f.add(n(A,s[y])):l=l.add(n(I,s[m]))}return{p:l,f}},wNAFCached(i,s,o,c){const a=i._WINDOW_SIZE||1;let l=s.get(i);return l||(l=this.precomputeWindow(i,a),a!==1&&s.set(i,c(l))),this.wNAF(a,l,o)}}}function Pn(e){return Wi(e.Fp),Fe(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Rn(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Qi(e){const t=Pn(e);Fe(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:i}=t;if(n){if(!r.eql(i,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}const{bytesToNumberBE:es,hexToBytes:ts}=Hi,Ue={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=Ue;if(e.length<2||e[0]!==2)throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:es(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=Ue,n=typeof e=="string"?ts(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:i,l:s}=Ue._parseInt(n.subarray(2)),{d:o,l:c}=Ue._parseInt(s);if(c.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s:o}},hexFromSig(e){const t=l=>Number.parseInt(l[0],16)&8?"00"+l:l,n=l=>{const f=l.toString(16);return f.length&1?`0${f}`:f},r=t(n(e.s)),i=t(n(e.r)),s=r.length/2,o=i.length/2,c=n(s),a=n(o);return`30${n(o+s+4)}02${a}${i}02${c}${r}`}},ue=BigInt(0),Q=BigInt(1);BigInt(2);const Hn=BigInt(3);BigInt(4);function ns(e){const t=Qi(e),{Fp:n}=t,r=t.toBytes||((p,h,d)=>{const y=h.toAffine();return _e(Uint8Array.from([4]),n.toBytes(y.x),n.toBytes(y.y))}),i=t.fromBytes||(p=>{const h=p.subarray(1),d=n.fromBytes(h.subarray(0,n.BYTES)),y=n.fromBytes(h.subarray(n.BYTES,2*n.BYTES));return{x:d,y}});function s(p){const{a:h,b:d}=t,y=n.sqr(p),m=n.mul(y,p);return n.add(n.add(m,n.mul(p,h)),d)}if(!n.eql(n.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function o(p){return typeof p=="bigint"&&ue<p&&p<t.n}function c(p){if(!o(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(p){const{allowedPrivateKeyLengths:h,nByteLength:d,wrapPrivateKey:y,n:m}=t;if(h&&typeof p!="bigint"){if(p instanceof Uint8Array&&(p=Me(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(d*2,"0")}let A;try{A=typeof p=="bigint"?p:Y(Z("private key",p,d))}catch{throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof p}`)}return y&&(A=W(A,m)),c(A),A}const l=new Map;function f(p){if(!(p instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(h,d,y){if(this.px=h,this.py=d,this.pz=y,h==null||!n.isValid(h))throw new Error("x required");if(d==null||!n.isValid(d))throw new Error("y required");if(y==null||!n.isValid(y))throw new Error("z required")}static fromAffine(h){const{x:d,y}=h||{};if(!h||!n.isValid(d)||!n.isValid(y))throw new Error("invalid affine point");if(h instanceof u)throw new Error("projective point not allowed");const m=A=>n.eql(A,n.ZERO);return m(d)&&m(y)?u.ZERO:new u(d,y,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){const d=n.invertBatch(h.map(y=>y.pz));return h.map((y,m)=>y.toAffine(d[m])).map(u.fromAffine)}static fromHex(h){const d=u.fromAffine(i(Z("pointHex",h)));return d.assertValidity(),d}static fromPrivateKey(h){return u.BASE.multiply(a(h))}_setWindowSize(h){this._WINDOW_SIZE=h,l.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:h,y:d}=this.toAffine();if(!n.isValid(h)||!n.isValid(d))throw new Error("bad point: x or y not FE");const y=n.sqr(d),m=s(h);if(!n.eql(y,m))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:h}=this.toAffine();if(n.isOdd)return!n.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);const{px:d,py:y,pz:m}=this,{px:A,py:I,pz:B}=h,E=n.eql(n.mul(d,B),n.mul(A,m)),x=n.eql(n.mul(y,B),n.mul(I,m));return E&&x}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:h,b:d}=t,y=n.mul(d,Hn),{px:m,py:A,pz:I}=this;let B=n.ZERO,E=n.ZERO,x=n.ZERO,S=n.mul(m,m),P=n.mul(A,A),_=n.mul(I,I),K=n.mul(m,A);return K=n.add(K,K),x=n.mul(m,I),x=n.add(x,x),B=n.mul(h,x),E=n.mul(y,_),E=n.add(B,E),B=n.sub(P,E),E=n.add(P,E),E=n.mul(B,E),B=n.mul(K,B),x=n.mul(y,x),_=n.mul(h,_),K=n.sub(S,_),K=n.mul(h,K),K=n.add(K,x),x=n.add(S,S),S=n.add(x,S),S=n.add(S,_),S=n.mul(S,K),E=n.add(E,S),_=n.mul(A,I),_=n.add(_,_),S=n.mul(_,K),B=n.sub(B,S),x=n.mul(_,P),x=n.add(x,x),x=n.add(x,x),new u(B,E,x)}add(h){f(h);const{px:d,py:y,pz:m}=this,{px:A,py:I,pz:B}=h;let E=n.ZERO,x=n.ZERO,S=n.ZERO;const P=t.a,_=n.mul(t.b,Hn);let K=n.mul(d,A),R=n.mul(y,I),O=n.mul(m,B),j=n.add(d,y),w=n.add(A,I);j=n.mul(j,w),w=n.add(K,R),j=n.sub(j,w),w=n.add(d,m);let v=n.add(A,B);return w=n.mul(w,v),v=n.add(K,O),w=n.sub(w,v),v=n.add(y,m),E=n.add(I,B),v=n.mul(v,E),E=n.add(R,O),v=n.sub(v,E),S=n.mul(P,w),E=n.mul(_,O),S=n.add(E,S),E=n.sub(R,S),S=n.add(R,S),x=n.mul(E,S),R=n.add(K,K),R=n.add(R,K),O=n.mul(P,O),w=n.mul(_,w),R=n.add(R,O),O=n.sub(K,O),O=n.mul(P,O),w=n.add(w,O),K=n.mul(R,w),x=n.add(x,K),K=n.mul(v,w),E=n.mul(j,E),E=n.sub(E,K),K=n.mul(j,R),S=n.mul(v,S),S=n.add(S,K),new u(E,x,S)}subtract(h){return this.add(h.negate())}is0(){return this.equals(u.ZERO)}wNAF(h){return b.wNAFCached(this,l,h,d=>{const y=n.invertBatch(d.map(m=>m.pz));return d.map((m,A)=>m.toAffine(y[A])).map(u.fromAffine)})}multiplyUnsafe(h){const d=u.ZERO;if(h===ue)return d;if(c(h),h===Q)return this;const{endo:y}=t;if(!y)return b.unsafeLadder(this,h);let{k1neg:m,k1:A,k2neg:I,k2:B}=y.splitScalar(h),E=d,x=d,S=this;for(;A>ue||B>ue;)A&Q&&(E=E.add(S)),B&Q&&(x=x.add(S)),S=S.double(),A>>=Q,B>>=Q;return m&&(E=E.negate()),I&&(x=x.negate()),x=new u(n.mul(x.px,y.beta),x.py,x.pz),E.add(x)}multiply(h){c(h);let d=h,y,m;const{endo:A}=t;if(A){const{k1neg:I,k1:B,k2neg:E,k2:x}=A.splitScalar(d);let{p:S,f:P}=this.wNAF(B),{p:_,f:K}=this.wNAF(x);S=b.constTimeNegate(I,S),_=b.constTimeNegate(E,_),_=new u(n.mul(_.px,A.beta),_.py,_.pz),y=S.add(_),m=P.add(K)}else{const{p:I,f:B}=this.wNAF(d);y=I,m=B}return u.normalizeZ([y,m])[0]}multiplyAndAddUnsafe(h,d,y){const m=u.BASE,A=(B,E)=>E===ue||E===Q||!B.equals(m)?B.multiplyUnsafe(E):B.multiply(E),I=A(this,d).add(A(h,y));return I.is0()?void 0:I}toAffine(h){const{px:d,py:y,pz:m}=this,A=this.is0();h==null&&(h=A?n.ONE:n.inv(m));const I=n.mul(d,h),B=n.mul(y,h),E=n.mul(m,h);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(E,n.ONE))throw new Error("invZ was invalid");return{x:I,y:B}}isTorsionFree(){const{h,isTorsionFree:d}=t;if(h===Q)return!0;if(d)return d(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h,clearCofactor:d}=t;return h===Q?this:d?d(u,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),r(u,this,h)}toHex(h=!0){return Me(this.toRawBytes(h))}}u.BASE=new u(t.Gx,t.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const g=t.nBitLength,b=Xi(u,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:o}}function rs(e){const t=Pn(e);return Fe(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function is(e){const t=rs(e),{Fp:n,n:r}=t,i=n.BYTES+1,s=2*n.BYTES+1;function o(w){return ue<w&&w<n.ORDER}function c(w){return W(w,r)}function a(w){return Tt(w,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:g}=ns({...t,toBytes(w,v,N){const k=v.toAffine(),C=n.toBytes(k.x),L=_e;return N?L(Uint8Array.from([v.hasEvenY()?2:3]),C):L(Uint8Array.from([4]),C,n.toBytes(k.y))},fromBytes(w){const v=w.length,N=w[0],k=w.subarray(1);if(v===i&&(N===2||N===3)){const C=Y(k);if(!o(C))throw new Error("Point is not on curve");const L=u(C);let M=n.sqrt(L);const $=(M&Q)===Q;return(N&1)===1!==$&&(M=n.neg(M)),{x:C,y:M}}else if(v===s&&N===4){const C=n.fromBytes(k.subarray(0,n.BYTES)),L=n.fromBytes(k.subarray(n.BYTES,2*n.BYTES));return{x:C,y:L}}else throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`)}}),b=w=>Me(Ee(w,t.nByteLength));function p(w){const v=r>>Q;return w>v}function h(w){return p(w)?c(-w):w}const d=(w,v,N)=>Y(w.slice(v,N));class y{constructor(v,N,k){this.r=v,this.s=N,this.recovery=k,this.assertValidity()}static fromCompact(v){const N=t.nByteLength;return v=Z("compactSignature",v,N*2),new y(d(v,0,N),d(v,N,2*N))}static fromDER(v){const{r:N,s:k}=Ue.toSig(Z("DER",v));return new y(N,k)}assertValidity(){if(!g(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!g(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(v){return new y(this.r,this.s,v)}recoverPublicKey(v){const{r:N,s:k,recovery:C}=this,L=x(Z("msgHash",v));if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");const M=C===2||C===3?N+t.n:N;if(M>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const $=C&1?"03":"02",ne=l.fromHex($+b(M)),Ce=a(M),Ve=c(-L*Ce),tt=c(k*Ce),Be=l.BASE.multiplyAndAddUnsafe(ne,Ve,tt);if(!Be)throw new Error("point at infinify");return Be.assertValidity(),Be}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Pe(this.toDERHex())}toDERHex(){return Ue.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Pe(this.toCompactHex())}toCompactHex(){return b(this.r)+b(this.s)}}const m={isValidPrivateKey(w){try{return f(w),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const w=Mn(t.n);return Ji(t.randomBytes(w),t.n)},precompute(w=8,v=l.BASE){return v._setWindowSize(w),v.multiply(BigInt(3)),v}};function A(w,v=!0){return l.fromPrivateKey(w).toRawBytes(v)}function I(w){const v=w instanceof Uint8Array,N=typeof w=="string",k=(v||N)&&w.length;return v?k===i||k===s:N?k===2*i||k===2*s:w instanceof l}function B(w,v,N=!0){if(I(w))throw new Error("first arg must be private key");if(!I(v))throw new Error("second arg must be public key");return l.fromHex(v).multiply(f(w)).toRawBytes(N)}const E=t.bits2int||function(w){const v=Y(w),N=w.length*8-t.nBitLength;return N>0?v>>BigInt(N):v},x=t.bits2int_modN||function(w){return c(E(w))},S=Ut(t.nBitLength);function P(w){if(typeof w!="bigint")throw new Error("bigint expected");if(!(ue<=w&&w<S))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Ee(w,t.nByteLength)}function _(w,v,N=K){if(["recovered","canonical"].some(Oe=>Oe in N))throw new Error("sign() legacy options not supported");const{hash:k,randomBytes:C}=t;let{lowS:L,prehash:M,extraEntropy:$}=N;L==null&&(L=!0),w=Z("msgHash",w),M&&(w=Z("prehashed msgHash",k(w)));const ne=x(w),Ce=f(v),Ve=[P(Ce),P(ne)];if($!=null){const Oe=$===!0?C(n.BYTES):$;Ve.push(Z("extraEntropy",Oe))}const tt=_e(...Ve),Be=ne;function Kn(Oe){const We=E(Oe);if(!g(We))return;const wi=a(We),Ze=l.BASE.multiply(We).toAffine(),re=c(Ze.x);if(re===ue)return;const Ge=c(wi*c(Be+re*Ce));if(Ge===ue)return;let bi=(Ze.x===re?0:2)|Number(Ze.y&Q),vi=Ge;return L&&p(Ge)&&(vi=h(Ge),bi^=1),new y(re,vi,bi)}return{seed:tt,k2sig:Kn}}const K={lowS:t.lowS,prehash:!1},R={lowS:t.lowS,prehash:!1};function O(w,v,N=K){const{seed:k,k2sig:C}=_(w,v,N),L=t;return Ln(L.hash.outputLen,L.nByteLength,L.hmac)(k,C)}l.BASE._setWindowSize(8);function j(w,v,N,k=R){var Ze;const C=w;if(v=Z("msgHash",v),N=Z("publicKey",N),"strict"in k)throw new Error("options.strict was renamed to lowS");const{lowS:L,prehash:M}=k;let $,ne;try{if(typeof C=="string"||C instanceof Uint8Array)try{$=y.fromDER(C)}catch(re){if(!(re instanceof Ue.Err))throw re;$=y.fromCompact(C)}else if(typeof C=="object"&&typeof C.r=="bigint"&&typeof C.s=="bigint"){const{r:re,s:Ge}=C;$=new y(re,Ge)}else throw new Error("PARSE");ne=l.fromHex(N)}catch(re){if(re.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(L&&$.hasHighS())return!1;M&&(v=t.hash(v));const{r:Ce,s:Ve}=$,tt=x(v),Be=a(Ve),Kn=c(tt*Be),Oe=c(Ce*Be),We=(Ze=l.BASE.multiplyAndAddUnsafe(ne,Kn,Oe))==null?void 0:Ze.toAffine();return We?c(We.x)===Ce:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:B,sign:O,verify:j,ProjectivePoint:l,Signature:y,utils:m}}let Dn=class extends Bn{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Ei(t);const r=Ct(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,s=new Uint8Array(i);s.set(r.length>i?t.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(t){return nt(this),this.iHash.update(t),this}digestInto(t){nt(this),ke(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:i,destroyed:s,blockLen:o,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=s,t.blockLen=o,t.outputLen=c,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const qn=(e,t,n)=>new Dn(e,t).update(n).digest();qn.create=(e,t)=>new Dn(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ss(e){return{hash:e,hmac:(t,...n)=>qn(e,t,Si(...n)),randomBytes:kn}}function os(e,t){const n=r=>is({...e,...ss(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const st=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ot=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),jn=BigInt(1),at=BigInt(2),zn=(e,t)=>(e+t/at)/t;function Vn(e){const t=st,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=X(f,n,t)*f%t,g=X(u,n,t)*f%t,b=X(g,at,t)*l%t,p=X(b,i,t)*b%t,h=X(p,s,t)*p%t,d=X(h,c,t)*h%t,y=X(d,a,t)*d%t,m=X(y,c,t)*h%t,A=X(m,n,t)*f%t,I=X(A,o,t)*p%t,B=X(I,r,t)*l%t,E=X(B,at,t);if(!Ot.eql(Ot.sqr(E),e))throw new Error("Cannot find square root");return E}const Ot=Fi(st,void 0,void 0,{sqrt:Vn}),Le=os({a:BigInt(0),b:BigInt(7),Fp:Ot,n:ot,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=ot,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-jn*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),c=zn(s*e,t),a=zn(-r*e,t);let l=W(e-c*n-a*i,t),f=W(-c*r-a*s,t);const u=l>o,g=f>o;if(u&&(l=t-l),g&&(f=t-f),l>o||f>o)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:u,k1:l,k2neg:g,k2:f}}}},Bt),ct=BigInt(0),Wn=e=>typeof e=="bigint"&&ct<e&&e<st,as=e=>typeof e=="bigint"&&ct<e&&e<ot,Zn={};function ut(e,...t){let n=Zn[e];if(n===void 0){const r=Bt(Uint8Array.from(e,i=>i.charCodeAt(0)));n=_e(r,r),Zn[e]=n}return Bt(_e(n,...t))}const Mt=e=>e.toRawBytes(!0).slice(1),Pt=e=>Ee(e,32),Ht=e=>W(e,st),Je=e=>W(e,ot),Dt=Le.ProjectivePoint,cs=(e,t,n)=>Dt.BASE.multiplyAndAddUnsafe(e,t,n);function qt(e){let t=Le.utils.normPrivateKeyToScalar(e),n=Dt.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Je(-t),bytes:Mt(n)}}function Gn(e){if(!Wn(e))throw new Error("bad x: need 0 < x < p");const t=Ht(e*e),n=Ht(t*e+BigInt(7));let r=Vn(n);r%at!==ct&&(r=Ht(-r));const i=new Dt(e,r,jn);return i.assertValidity(),i}function Fn(...e){return Je(Y(ut("BIP0340/challenge",...e)))}function us(e){return qt(e).bytes}function ls(e,t,n=kn(32)){const r=Z("message",e),{bytes:i,scalar:s}=qt(t),o=Z("auxRand",n,32),c=Pt(s^Y(ut("BIP0340/aux",o))),a=ut("BIP0340/nonce",c,i,r),l=Je(Y(a));if(l===ct)throw new Error("sign failed: k is zero");const{bytes:f,scalar:u}=qt(l),g=Fn(f,i,r),b=new Uint8Array(64);if(b.set(f,0),b.set(Pt(Je(u+g*s)),32),!Jn(b,r,i))throw new Error("sign: Invalid signature produced");return b}function Jn(e,t,n){const r=Z("signature",e,64),i=Z("message",t),s=Z("publicKey",n,32);try{const o=Gn(Y(s)),c=Y(r.subarray(0,32));if(!Wn(c))return!1;const a=Y(r.subarray(32,64));if(!as(a))return!1;const l=Fn(Pt(c),Mt(o),i),f=cs(o,a,Je(-l));return!(!f||!f.hasEvenY()||f.toAffine().x!==c)}catch{return!1}}const Ye={getPublicKey:us,sign:ls,verify:Jn,utils:{randomPrivateKey:Le.utils.randomPrivateKey,lift_x:Gn,pointToBytes:Mt,numberToBytesBE:Ee,bytesToNumberBE:Y,taggedHash:ut,mod:W}},jt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const zt=e=>e instanceof Uint8Array,Vt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),oe=(e,t)=>e<<32-t|e>>>t;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");const fs=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function T(e){if(!zt(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=fs[e[n]];return t}function F(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){const i=r*2,s=e.slice(i,i+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[r]=o}return n}function hs(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Xe(e){if(typeof e=="string"&&(e=hs(e)),!zt(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function lt(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!zt(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}class Yn{clone(){return this._cloneInto()}}function Xn(e){const t=r=>e().update(Xe(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Qn(e=32){if(jt&&typeof jt.getRandomValues=="function")return jt.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Wt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function ds(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function er(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function ps(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Wt(e.outputLen),Wt(e.blockLen)}function ys(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function gs(e,t){er(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const ae={number:Wt,bool:ds,bytes:er,hash:ps,exists:ys,output:gs};function ws(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),c=Number(n&s),a=r?4:0,l=r?0:4;e.setUint32(t+a,o,r),e.setUint32(t+l,c,r)}class bs extends Yn{constructor(t,n,r,i){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=Vt(this.buffer)}update(t){ae.exists(this);const{view:n,buffer:r,blockLen:i}=this;t=Xe(t);const s=t.length;for(let o=0;o<s;){const c=Math.min(i-this.pos,s-o);if(c===i){const a=Vt(t);for(;i<=s-o;o+=i)this.process(a,o);continue}r.set(t.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ae.exists(this),ae.output(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(r,0),o=0);for(let u=o;u<i;u++)n[u]=0;ws(r,i-8,BigInt(this.length*8),s),this.process(r,0);const c=Vt(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)c.setUint32(4*u,f[u],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:c}=this;return t.length=i,t.pos=c,t.finished=s,t.destroyed=o,i%n&&t.buffer.set(r),t}}const vs=(e,t,n)=>e&t^~e&n,Es=(e,t,n)=>e&t^e&n^t&n,ms=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),me=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),xe=new Uint32Array(64);class tr extends bs{constructor(){super(64,32,8,!1),this.A=me[0]|0,this.B=me[1]|0,this.C=me[2]|0,this.D=me[3]|0,this.E=me[4]|0,this.F=me[5]|0,this.G=me[6]|0,this.H=me[7]|0}get(){const{A:t,B:n,C:r,D:i,E:s,F:o,G:c,H:a}=this;return[t,n,r,i,s,o,c,a]}set(t,n,r,i,s,o,c,a){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(t,n){for(let u=0;u<16;u++,n+=4)xe[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const g=xe[u-15],b=xe[u-2],p=oe(g,7)^oe(g,18)^g>>>3,h=oe(b,17)^oe(b,19)^b>>>10;xe[u]=h+xe[u-7]+p+xe[u-16]|0}let{A:r,B:i,C:s,D:o,E:c,F:a,G:l,H:f}=this;for(let u=0;u<64;u++){const g=oe(c,6)^oe(c,11)^oe(c,25),b=f+g+vs(c,a,l)+ms[u]+xe[u]|0,h=(oe(r,2)^oe(r,13)^oe(r,22))+Es(r,i,s)|0;f=l,l=a,a=c,c=o+b|0,o=s,s=i,i=r,r=b+h|0}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)}roundClean(){xe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class xs extends tr{constructor(){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}}const le=Xn(()=>new tr);Xn(()=>new xs);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function He(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function fe(...e){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);return{encode:n,decode:r}}function he(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return t.map(n=>{if(He(n),n<0||n>=e.length)throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${e.length})`);return e[n]})},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("alphabet.decode input should be array of strings");return t.map(n=>{if(typeof n!="string")throw new Error(`alphabet.decode: not string element=${n}`);const r=e.indexOf(n);if(r===-1)throw new Error(`Unknown letter: "${n}". Allowed: ${e}`);return r})}}}function de(e=""){if(typeof e!="string")throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("join.encode input should be array of strings");for(let n of t)if(typeof n!="string")throw new Error(`join.encode: non-string input=${n}`);return t.join(e)},decode:t=>{if(typeof t!="string")throw new Error("join.decode input should be string");return t.split(e)}}}function ft(e,t="="){if(He(e),typeof t!="string")throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let r of n)if(typeof r!="string")throw new Error(`padding.encode: non-string input=${r}`);for(;n.length*e%8;)n.push(t);return n},decode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let i of n)if(typeof i!="string")throw new Error(`padding.decode: non-string input=${i}`);let r=n.length;if(r*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--)if(!((r-1)*e%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function nr(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function rr(e,t,n){if(t<2)throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let r=0;const i=[],s=Array.from(e);for(s.forEach(o=>{if(He(o),o<0||o>=t)throw new Error(`Wrong integer: ${o}`)});;){let o=0,c=!0;for(let a=r;a<s.length;a++){const l=s[a],f=t*o+l;if(!Number.isSafeInteger(f)||t*o/t!==o||f-l!==t*o)throw new Error("convertRadix: carry overflow");if(o=f%n,s[a]=Math.floor(f/n),!Number.isSafeInteger(s[a])||s[a]*n+o!==f)throw new Error("convertRadix: carry overflow");if(c)s[a]?c=!1:r=a;else continue}if(i.push(o),c)break}for(let o=0;o<e.length-1&&e[o]===0;o++)i.push(0);return i.reverse()}const ir=(e,t)=>t?ir(t,e%t):e,ht=(e,t)=>e+(t-ir(e,t));function Zt(e,t,n,r){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(ht(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${ht(t,n)}`);let i=0,s=0;const o=2**n-1,c=[];for(const a of e){if(He(a),a>=2**t)throw new Error(`convertRadix2: invalid data word=${a} from=${t}`);if(i=i<<t|a,s+t>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);for(s+=t;s>=n;s-=n)c.push((i>>s-n&o)>>>0);i&=2**s-1}if(i=i<<n-s&o,!r&&s>=t)throw new Error("Excess padding");if(!r&&i)throw new Error(`Non-zero padding: ${i}`);return r&&s>0&&c.push(i>>>0),c}function Ss(e){return He(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return rr(Array.from(t),2**8,e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(rr(t,e,2**8))}}}function Se(e,t=!1){if(He(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(ht(8,e)>32||ht(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!(n instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return Zt(Array.from(n),8,e,!t)},decode:n=>{if(!Array.isArray(n)||n.length&&typeof n[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(Zt(n,e,8,t))}}}function sr(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}const Ns=fe(Se(4),he("0123456789ABCDEF"),de("")),As=fe(Se(5),he("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),ft(5),de(""));fe(Se(5),he("0123456789ABCDEFGHIJKLMNOPQRSTUV"),ft(5),de("")),fe(Se(5),he("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),de(""),nr(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const pe=fe(Se(6),he("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),ft(6),de("")),Ks=fe(Se(6),he("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),ft(6),de("")),Gt=e=>fe(Ss(58),he(e),de("")),Ft=Gt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Gt("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Gt("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const or=[0,2,3,5,6,7,9,10,11],Cs={encode(e){let t="";for(let n=0;n<e.length;n+=8){const r=e.subarray(n,n+8);t+=Ft.encode(r).padStart(or[r.length],"1")}return t},decode(e){let t=[];for(let n=0;n<e.length;n+=11){const r=e.slice(n,n+11),i=or.indexOf(r.length),s=Ft.decode(r);for(let o=0;o<s.length-i;o++)if(s[o]!==0)throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(s.slice(s.length-i)))}return Uint8Array.from(t)}},Jt=fe(he("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),de("")),ar=[996825010,642813549,513874426,1027748829,705979059];function Qe(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r<ar.length;r++)(t>>r&1)===1&&(n^=ar[r]);return n}function cr(e,t,n=1){const r=e.length;let i=1;for(let s=0;s<r;s++){const o=e.charCodeAt(s);if(o<33||o>126)throw new Error(`Invalid prefix (${e})`);i=Qe(i)^o>>5}i=Qe(i);for(let s=0;s<r;s++)i=Qe(i)^e.charCodeAt(s)&31;for(let s of t)i=Qe(i)^s;for(let s=0;s<6;s++)i=Qe(i);return i^=n,Jt.encode(Zt([i%2**30],30,5,!1))}function ur(e){const t=e==="bech32"?1:734539939,n=Se(5),r=n.decode,i=n.encode,s=sr(r);function o(f,u,g=90){if(typeof f!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);if(!Array.isArray(u)||u.length&&typeof u[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);const b=f.length+7+u.length;if(g!==!1&&b>g)throw new TypeError(`Length ${b} exceeds limit ${g}`);return f=f.toLowerCase(),`${f}1${Jt.encode(u)}${cr(f,u,t)}`}function c(f,u=90){if(typeof f!="string")throw new Error(`bech32.decode input should be string, not ${typeof f}`);if(f.length<8||u!==!1&&f.length>u)throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${u})`);const g=f.toLowerCase();if(f!==g&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");f=g;const b=f.lastIndexOf("1");if(b===0||b===-1)throw new Error('Letter "1" must be present between prefix and data only');const p=f.slice(0,b),h=f.slice(b+1);if(h.length<6)throw new Error("Data must be at least 6 characters long");const d=Jt.decode(h).slice(0,-6),y=cr(p,d,t);if(!h.endsWith(y))throw new Error(`Invalid checksum in ${f}: expected "${y}"`);return{prefix:p,words:d}}const a=sr(c);function l(f){const{prefix:u,words:g}=c(f,!1);return{prefix:u,words:g,bytes:r(g)}}return{encode:o,decode:c,decodeToBytes:l,decodeUnsafe:a,fromWords:r,fromWordsUnsafe:s,toWords:i}}const De=ur("bech32");ur("bech32m");const Bs={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},ks=fe(Se(4),he("0123456789abcdef"),de(""),nr(e=>{if(typeof e!="string"||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));`${Object.keys({utf8:Bs,hex:ks,base16:Ns,base32:As,base64:pe,base64url:Ks,base58:Ft,base58xmr:Cs}).join(", ")}`;function Yt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function lr(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function _s(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function ye(e,...t){if(!_s(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */const G=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4));if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function Is(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function Us(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}const Ls=(e,t)=>(Object.assign(t,e),t),Ne=16,$s=283;function Xt(e){return e<<1^$s&-(e>>7)}function qe(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(t&1),e=Xt(e);return n}const Qt=(()=>{let e=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=Xt(r))e[n]=r;const t=new Uint8Array(256);t[0]=99;for(let n=0;n<255;n++){let r=e[255-n];r|=r<<8,t[e[n]]=(r^r>>4^r>>5^r>>6^r>>7^99)&255}return t})(),Ts=Qt.map((e,t)=>Qt.indexOf(t)),Rs=e=>e<<24|e>>>8,en=e=>e<<8|e>>>24;function fr(e,t){if(e.length!==256)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((l,f)=>t(e[f])),r=n.map(en),i=r.map(en),s=i.map(en),o=new Uint32Array(256*256),c=new Uint32Array(256*256),a=new Uint16Array(256*256);for(let l=0;l<256;l++)for(let f=0;f<256;f++){const u=l*256+f;o[u]=n[l]^r[f],c[u]=i[l]^s[f],a[u]=e[l]<<8|e[f]}return{sbox:e,sbox2:a,T0:n,T1:r,T2:i,T3:s,T01:o,T23:c}}const tn=fr(Qt,e=>qe(e,3)<<24|e<<16|e<<8|qe(e,2)),hr=fr(Ts,e=>qe(e,11)<<24|qe(e,13)<<16|qe(e,9)<<8|qe(e,14)),Os=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=Xt(n))e[t]=n;return e})();function dr(e){ye(e);const t=e.length;if(![16,24,32].includes(t))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);const{sbox2:n}=tn,r=G(e),i=r.length,s=c=>ce(n,c,c,c,c),o=new Uint32Array(t+28);o.set(r);for(let c=i;c<o.length;c++){let a=o[c-1];c%i===0?a=s(Rs(a))^Os[c/i-1]:i>6&&c%i===4&&(a=s(a)),o[c]=o[c-i]^a}return o}function Ms(e){const t=dr(e),n=t.slice(),r=t.length,{sbox2:i}=tn,{T0:s,T1:o,T2:c,T3:a}=hr;for(let l=0;l<r;l+=4)for(let f=0;f<4;f++)n[l+f]=t[r-l-4+f];t.fill(0);for(let l=4;l<r-4;l++){const f=n[l],u=ce(i,f,f,f,f);n[l]=s[u&255]^o[u>>>8&255]^c[u>>>16&255]^a[u>>>24]}return n}function Ae(e,t,n,r,i,s){return e[n<<8&65280|r>>>8&255]^t[i>>>8&65280|s>>>24&255]}function ce(e,t,n,r,i){return e[t&255|n&65280]|e[r>>>16&255|i>>>16&65280]<<16}function pr(e,t,n,r,i){const{sbox2:s,T01:o,T23:c}=tn;let a=0;t^=e[a++],n^=e[a++],r^=e[a++],i^=e[a++];const l=e.length/4-2;for(let p=0;p<l;p++){const h=e[a++]^Ae(o,c,t,n,r,i),d=e[a++]^Ae(o,c,n,r,i,t),y=e[a++]^Ae(o,c,r,i,t,n),m=e[a++]^Ae(o,c,i,t,n,r);t=h,n=d,r=y,i=m}const f=e[a++]^ce(s,t,n,r,i),u=e[a++]^ce(s,n,r,i,t),g=e[a++]^ce(s,r,i,t,n),b=e[a++]^ce(s,i,t,n,r);return{s0:f,s1:u,s2:g,s3:b}}function Ps(e,t,n,r,i){const{sbox2:s,T01:o,T23:c}=hr;let a=0;t^=e[a++],n^=e[a++],r^=e[a++],i^=e[a++];const l=e.length/4-2;for(let p=0;p<l;p++){const h=e[a++]^Ae(o,c,t,i,r,n),d=e[a++]^Ae(o,c,n,t,i,r),y=e[a++]^Ae(o,c,r,n,t,i),m=e[a++]^Ae(o,c,i,r,n,t);t=h,n=d,r=y,i=m}const f=e[a++]^ce(s,t,i,r,n),u=e[a++]^ce(s,n,t,i,r),g=e[a++]^ce(s,r,n,t,i),b=e[a++]^ce(s,i,r,n,t);return{s0:f,s1:u,s2:g,s3:b}}function yr(e,t){if(!t)return new Uint8Array(e);if(ye(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}function Hs(e){if(ye(e),e.length%Ne!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Ne}`)}function Ds(e,t,n){let r=e.length;const i=r%Ne;if(!t&&i!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const s=G(e);if(t){let a=Ne-i;a||(a=Ne),r=r+a}const o=yr(r,n),c=G(o);return{b:s,o:c,out:o}}function qs(e,t){if(!t)return e;const n=e.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=e[n-1];if(r<=0||r>16)throw new Error(`aes/pcks5: wrong padding byte: ${r}`);const i=e.subarray(0,-r);for(let s=0;s<r;s++)if(e[n-s-1]!==r)throw new Error("aes/pcks5: wrong padding");return i}function js(e){const t=new Uint8Array(16),n=G(t);t.set(e);const r=Ne-e.length;for(let i=Ne-r;i<Ne;i++)t[i]=r;return n}const gr=Ls({blockSize:16,nonceLength:16},function(t,n,r={}){ye(t),ye(n,16);const i=!r.disablePadding;return{encrypt:(s,o)=>{const c=dr(t),{b:a,o:l,out:f}=Ds(s,i,o),u=G(n);let g=u[0],b=u[1],p=u[2],h=u[3],d=0;for(;d+4<=a.length;)g^=a[d+0],b^=a[d+1],p^=a[d+2],h^=a[d+3],{s0:g,s1:b,s2:p,s3:h}=pr(c,g,b,p,h),l[d++]=g,l[d++]=b,l[d++]=p,l[d++]=h;if(i){const y=js(s.subarray(d*4));g^=y[0],b^=y[1],p^=y[2],h^=y[3],{s0:g,s1:b,s2:p,s3:h}=pr(c,g,b,p,h),l[d++]=g,l[d++]=b,l[d++]=p,l[d++]=h}return c.fill(0),f},decrypt:(s,o)=>{Hs(s);const c=Ms(t),a=G(n),l=yr(s.length,o),f=G(s),u=G(l);let g=a[0],b=a[1],p=a[2],h=a[3];for(let d=0;d+4<=f.length;){const y=g,m=b,A=p,I=h;g=f[d+0],b=f[d+1],p=f[d+2],h=f[d+3];const{s0:B,s1:E,s2:x,s3:S}=Ps(c,g,b,p,h);u[d++]=B^y,u[d++]=E^m,u[d++]=x^A,u[d++]=S^I}return c.fill(0),qs(l,i)}}}),wr=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),zs=wr("expand 16-byte k"),Vs=wr("expand 32-byte k"),Ws=G(zs),br=G(Vs);br.slice();function U(e,t){return e<<t|e>>>32-t}function nn(e){return e.byteOffset%4===0}const dt=64,Zs=16,vr=2**32-1,Er=new Uint32Array;function Gs(e,t,n,r,i,s,o,c){const a=i.length,l=new Uint8Array(dt),f=G(l),u=nn(i)&&nn(s),g=u?G(i):Er,b=u?G(s):Er;for(let p=0;p<a;o++){if(e(t,n,r,f,o,c),o>=vr)throw new Error("arx: counter overflow");const h=Math.min(dt,a-p);if(u&&h===dt){const d=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let y=0,m;y<Zs;y++)m=d+y,b[m]=g[m]^f[y];p+=dt;continue}for(let d=0,y;d<h;d++)y=p+d,s[y]=i[y]^l[d];p+=h}}function Fs(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:s,rounds:o}=Is({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return Yt(i),Yt(o),lr(s),lr(n),(c,a,l,f,u=0)=>{ye(c),ye(a),ye(l);const g=l.length;if(f||(f=new Uint8Array(g)),ye(f),Yt(u),u<0||u>=vr)throw new Error("arx: counter overflow");if(f.length<g)throw new Error(`arx: output (${f.length}) is shorter than data (${g})`);const b=[];let p=c.length,h,d;if(p===32)h=c.slice(),b.push(h),d=br;else if(p===16&&n)h=new Uint8Array(32),h.set(c),h.set(c,16),d=Ws,b.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);nn(a)||(a=a.slice(),b.push(a));const y=G(h);if(r){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(d,y,G(a.subarray(0,16)),y),a=a.subarray(16)}const m=16-i;if(m!==a.length)throw new Error(`arx: nonce must be ${m} or 16 bytes`);if(m!==12){const I=new Uint8Array(12);I.set(a,s?0:12-a.length),a=I,b.push(a)}const A=G(a);for(Gs(e,d,y,A,l,f,u,o);b.length>0;)b.pop().fill(0);return f}}function Js(e,t,n,r,i,s=20){let o=e[0],c=e[1],a=e[2],l=e[3],f=t[0],u=t[1],g=t[2],b=t[3],p=t[4],h=t[5],d=t[6],y=t[7],m=i,A=n[0],I=n[1],B=n[2],E=o,x=c,S=a,P=l,_=f,K=u,R=g,O=b,j=p,w=h,v=d,N=y,k=m,C=A,L=I,M=B;for(let ne=0;ne<s;ne+=2)E=E+_|0,k=U(k^E,16),j=j+k|0,_=U(_^j,12),E=E+_|0,k=U(k^E,8),j=j+k|0,_=U(_^j,7),x=x+K|0,C=U(C^x,16),w=w+C|0,K=U(K^w,12),x=x+K|0,C=U(C^x,8),w=w+C|0,K=U(K^w,7),S=S+R|0,L=U(L^S,16),v=v+L|0,R=U(R^v,12),S=S+R|0,L=U(L^S,8),v=v+L|0,R=U(R^v,7),P=P+O|0,M=U(M^P,16),N=N+M|0,O=U(O^N,12),P=P+O|0,M=U(M^P,8),N=N+M|0,O=U(O^N,7),E=E+K|0,M=U(M^E,16),v=v+M|0,K=U(K^v,12),E=E+K|0,M=U(M^E,8),v=v+M|0,K=U(K^v,7),x=x+R|0,k=U(k^x,16),N=N+k|0,R=U(R^N,12),x=x+R|0,k=U(k^x,8),N=N+k|0,R=U(R^N,7),S=S+O|0,C=U(C^S,16),j=j+C|0,O=U(O^j,12),S=S+O|0,C=U(C^S,8),j=j+C|0,O=U(O^j,7),P=P+_|0,L=U(L^P,16),w=w+L|0,_=U(_^w,12),P=P+_|0,L=U(L^P,8),w=w+L|0,_=U(_^w,7);let $=0;r[$++]=o+E|0,r[$++]=c+x|0,r[$++]=a+S|0,r[$++]=l+P|0,r[$++]=f+_|0,r[$++]=u+K|0,r[$++]=g+R|0,r[$++]=b+O|0,r[$++]=p+j|0,r[$++]=h+w|0,r[$++]=d+v|0,r[$++]=y+N|0,r[$++]=m+k|0,r[$++]=A+C|0,r[$++]=I+L|0,r[$++]=B+M|0}const mr=Fs(Js,{counterRight:!1,counterLength:4,allowShortKeys:!1});class xr extends Yn{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,ae.hash(t);const r=Xe(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,s=new Uint8Array(i);s.set(r.length>i?t.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(t){return ae.exists(this),this.iHash.update(t),this}digestInto(t){ae.exists(this),ae.bytes(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:i,destroyed:s,blockLen:o,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=s,t.blockLen=o,t.outputLen=c,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const pt=(e,t,n)=>new xr(e,t).update(n).digest();pt.create=(e,t)=>new xr(e,t);function rn(e,t,n){return ae.hash(e),n===void 0&&(n=new Uint8Array(e.outputLen)),pt(e,Xe(n),Xe(t))}const sn=new Uint8Array([0]),Sr=new Uint8Array;function Nr(e,t,n,r=32){if(ae.hash(e),ae.number(r),r>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const i=Math.ceil(r/e.outputLen);n===void 0&&(n=Sr);const s=new Uint8Array(i*e.outputLen),o=pt.create(e,t),c=o._cloneInto(),a=new Uint8Array(o.outputLen);for(let l=0;l<i;l++)sn[0]=l+1,c.update(l===0?Sr:a).update(n).update(sn).digestInto(a),s.set(a,e.outputLen*l),o._cloneInto(c);return o.destroy(),c.destroy(),a.fill(0),sn.fill(0),s.slice(0,r)}var Ys=Object.defineProperty,D=(e,t)=>{for(var n in t)Ys(e,n,{get:t[n],enumerable:!0})},je=Symbol("verified"),Xs=e=>e instanceof Object;function yt(e){if(!Xs(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))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}var Qs={};D(Qs,{Queue:()=>ro,QueueNode:()=>Ar,binarySearch:()=>on,insertEventIntoAscendingList:()=>no,insertEventIntoDescendingList:()=>to,normalizeURL:()=>eo,utf8Decoder:()=>ge,utf8Encoder:()=>te});var ge=new TextDecoder("utf-8"),te=new TextEncoder;function eo(e){e.indexOf("://")===-1&&(e="wss://"+e);let t=new URL(e);return t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),(t.port==="80"&&t.protocol==="ws:"||t.port==="443"&&t.protocol==="wss:")&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}function to(e,t){const[n,r]=on(e,i=>t.id===i.id?0:t.created_at===i.created_at?-1:i.created_at-t.created_at);return r||e.splice(n,0,t),e}function no(e,t){const[n,r]=on(e,i=>t.id===i.id?0:t.created_at===i.created_at?-1:t.created_at-i.created_at);return r||e.splice(n,0,t),e}function on(e,t){let n=0,r=e.length-1;for(;n<=r;){const i=Math.floor((n+r)/2),s=t(e[i]);if(s===0)return[i,!0];s<0?r=i-1:n=i+1}return[n,!1]}var Ar=class{constructor(e){ie(this,"value");ie(this,"next",null);ie(this,"prev",null);this.value=e}},ro=class{constructor(){ie(this,"first");ie(this,"last");this.first=null,this.last=null}enqueue(e){const t=new Ar(e);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}dequeue(){if(!this.first)return null;if(this.first===this.last){const t=this.first;return this.first=null,this.last=null,t.value}const e=this.first;return this.first=e.next,e.value}},io=class{generateSecretKey(){return Ye.utils.randomPrivateKey()}getPublicKey(e){return T(Ye.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=T(Ye.getPublicKey(t)),n.id=ze(n),n.sig=T(Ye.sign(ze(n),t)),n[je]=!0,n}verifyEvent(e){if(typeof e[je]=="boolean")return e[je];const t=ze(e);if(t!==e.id)return e[je]=!1,!1;try{const n=Ye.verify(e.sig,t,e.pubkey);return e[je]=n,n}catch{return e[je]=!1,!1}}};function so(e){if(!yt(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function ze(e){let t=le(te.encode(so(e)));return T(t)}var gt=new io,$e=gt.generateSecretKey,we=gt.getPublicKey,ee=gt.finalizeEvent,wt=gt.verifyEvent,oo={};D(oo,{Application:()=>ua,BadgeAward:()=>go,BadgeDefinition:()=>na,BlockedRelaysList:()=>Ho,BookmarkList:()=>Oo,Bookmarksets:()=>Qo,Calendar:()=>ga,CalendarEventRSVP:()=>wa,ChannelCreation:()=>Ir,ChannelHideMessage:()=>$r,ChannelMessage:()=>Lr,ChannelMetadata:()=>Ur,ChannelMuteUser:()=>Tr,ClassifiedListing:()=>ha,ClientAuth:()=>Or,CommunitiesList:()=>Mo,CommunityDefinition:()=>Ea,CommunityPostApproval:()=>Ko,Contacts:()=>ho,CreateOrUpdateProduct:()=>sa,CreateOrUpdateStall:()=>ia,Curationsets:()=>ea,Date:()=>pa,DirectMessageRelaysList:()=>zo,DraftClassifiedListing:()=>da,DraftLong:()=>aa,Emojisets:()=>ca,EncryptedDirectMessage:()=>po,EventDeletion:()=>yo,FileMetadata:()=>Eo,FileServerPreference:()=>Vo,Followsets:()=>Jo,GenericRepost:()=>bo,Genericlists:()=>Yo,GiftWrap:()=>Rr,HTTPAuth:()=>un,Handlerinformation:()=>va,Handlerrecommendation:()=>ba,Highlights:()=>Lo,InterestsList:()=>qo,Interestsets:()=>ra,JobFeedback:()=>ko,JobRequest:()=>Co,JobResult:()=>Bo,Label:()=>Ao,LightningPubRPC:()=>Zo,LiveChatMessage:()=>mo,LiveEvent:()=>la,LongFormArticle:()=>oa,Metadata:()=>uo,Mutelist:()=>$o,NWCWalletInfo:()=>Wo,NWCWalletRequest:()=>Mr,NWCWalletResponse:()=>Go,NostrConnect:()=>Fo,OpenTimestamps:()=>vo,Pinlist:()=>To,PrivateDirectMessage:()=>wo,ProblemTracker:()=>xo,ProfileBadges:()=>ta,PublicChatsList:()=>Po,Reaction:()=>cn,RecommendRelay:()=>fo,RelayList:()=>Ro,Relaysets:()=>Xo,Report:()=>So,Reporting:()=>No,Repost:()=>an,Seal:()=>_r,SearchRelaysList:()=>Do,ShortTextNote:()=>lo,Time:()=>ya,UserEmojiList:()=>jo,UserStatuses:()=>fa,Zap:()=>Uo,ZapGoal:()=>_o,ZapRequest:()=>Io,classifyKind:()=>ao,isEphemeralKind:()=>Br,isKind:()=>co,isParameterizedReplaceableKind:()=>kr,isRegularKind:()=>Kr,isReplaceableKind:()=>Cr});function Kr(e){return 1e3<=e&&e<1e4||[1,2,4,5,6,7,8,16,40,41,42,43,44].includes(e)}function Cr(e){return[0,3].includes(e)||1e4<=e&&e<2e4}function Br(e){return 2e4<=e&&e<3e4}function kr(e){return 3e4<=e&&e<4e4}function ao(e){return Kr(e)?"regular":Cr(e)?"replaceable":Br(e)?"ephemeral":kr(e)?"parameterized":"unknown"}function co(e,t){const n=t instanceof Array?t:[t];return yt(e)&&n.includes(e.kind)||!1}var uo=0,lo=1,fo=2,ho=3,po=4,yo=5,an=6,cn=7,go=8,_r=13,wo=14,bo=16,Ir=40,Ur=41,Lr=42,$r=43,Tr=44,vo=1040,Rr=1059,Eo=1063,mo=1311,xo=1971,So=1984,No=1984,Ao=1985,Ko=4550,Co=5999,Bo=6999,ko=7e3,_o=9041,Io=9734,Uo=9735,Lo=9802,$o=1e4,To=10001,Ro=10002,Oo=10003,Mo=10004,Po=10005,Ho=10006,Do=10007,qo=10015,jo=10030,zo=10050,Vo=10096,Wo=13194,Zo=21e3,Or=22242,Mr=23194,Go=23195,Fo=24133,un=27235,Jo=3e4,Yo=30001,Xo=30002,Qo=30003,ea=30004,ta=30008,na=30009,ra=30015,ia=30017,sa=30018,oa=30023,aa=30024,ca=30030,ua=30078,la=30311,fa=30315,ha=30402,da=30403,pa=31922,ya=31923,ga=31924,wa=31925,ba=31989,va=31990,Ea=34550,ma={};D(ma,{getHex64:()=>ln,getInt:()=>Pr,getSubscriptionId:()=>xa,matchEventId:()=>Sa,matchEventKind:()=>Aa,matchEventPubkey:()=>Na});function ln(e,t){let n=t.length+3,r=e.indexOf(`"${t}":`)+n,i=e.slice(r).indexOf('"')+r+1;return e.slice(i,i+64)}function Pr(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,i=e.slice(r),s=Math.min(i.indexOf(","),i.indexOf("}"));return parseInt(i.slice(0,s),10)}function xa(e){let t=e.slice(0,22).indexOf('"EVENT"');if(t===-1)return null;let n=e.slice(t+7+1).indexOf('"');if(n===-1)return null;let r=t+7+1+n,i=e.slice(r+1,80).indexOf('"');if(i===-1)return null;let s=r+1+i;return e.slice(r+1,s)}function Sa(e,t){return t===ln(e,"id")}function Na(e,t){return t===ln(e,"pubkey")}function Aa(e,t){return t===Pr(e,"kind")}var Ka={};D(Ka,{makeAuthEvent:()=>Ca});function Ca(e,t){return{kind:Or,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}var Ba;try{Ba=WebSocket}catch{}var ka;try{ka=WebSocket}catch{}var _a={};D(_a,{BECH32_REGEX:()=>Hr,Bech32MaxSize:()=>fn,NostrTypeGuard:()=>Ia,decode:()=>bt,encodeBytes:()=>Et,naddrEncode:()=>Ma,neventEncode:()=>Oa,noteEncode:()=>Ta,nprofileEncode:()=>Ra,npubEncode:()=>$a,nsecEncode:()=>La});var Ia={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},fn=5e3,Hr=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function Ua(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=e&255,t}function bt(e){var i,s,o,c,a,l,f;let{prefix:t,words:n}=De.decode(e,fn),r=new Uint8Array(De.fromWords(n));switch(t){case"nprofile":{let u=hn(r);if(!((i=u[0])!=null&&i[0]))throw new Error("missing TLV 0 for nprofile");if(u[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:T(u[0][0]),relays:u[1]?u[1].map(g=>ge.decode(g)):[]}}}case"nevent":{let u=hn(r);if(!((s=u[0])!=null&&s[0]))throw new Error("missing TLV 0 for nevent");if(u[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(u[2]&&u[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(u[3]&&u[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:T(u[0][0]),relays:u[1]?u[1].map(g=>ge.decode(g)):[],author:(o=u[2])!=null&&o[0]?T(u[2][0]):void 0,kind:(c=u[3])!=null&&c[0]?parseInt(T(u[3][0]),16):void 0}}}case"naddr":{let u=hn(r);if(!((a=u[0])!=null&&a[0]))throw new Error("missing TLV 0 for naddr");if(!((l=u[2])!=null&&l[0]))throw new Error("missing TLV 2 for naddr");if(u[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((f=u[3])!=null&&f[0]))throw new Error("missing TLV 3 for naddr");if(u[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:ge.decode(u[0][0]),pubkey:T(u[2][0]),kind:parseInt(T(u[3][0]),16),relays:u[1]?u[1].map(g=>ge.decode(g)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:T(r)};default:throw new Error(`unknown prefix ${t}`)}}function hn(e){let t={},n=e;for(;n.length>0;){let r=n[0],i=n[1],s=n.slice(2,2+i);if(n=n.slice(2+i),s.length<i)throw new Error(`not enough data to read on TLV ${r}`);t[r]=t[r]||[],t[r].push(s)}return t}function La(e){return Et("nsec",e)}function $a(e){return Et("npub",F(e))}function Ta(e){return Et("note",F(e))}function vt(e,t){let n=De.toWords(t);return De.encode(e,n,fn)}function Et(e,t){return vt(e,t)}function Ra(e){let t=dn({0:[F(e.pubkey)],1:(e.relays||[]).map(n=>te.encode(n))});return vt("nprofile",t)}function Oa(e){let t;e.kind!==void 0&&(t=Ua(e.kind));let n=dn({0:[F(e.id)],1:(e.relays||[]).map(r=>te.encode(r)),2:e.author?[F(e.author)]:[],3:t?[new Uint8Array(t)]:[]});return vt("nevent",n)}function Ma(e){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,e.kind,!1);let n=dn({0:[te.encode(e.identifier)],1:(e.relays||[]).map(r=>te.encode(r)),2:[F(e.pubkey)],3:[new Uint8Array(t)]});return vt("naddr",n)}function dn(e){let t=[];return Object.entries(e).reverse().forEach(([n,r])=>{r.forEach(i=>{let s=new Uint8Array(i.length+2);s.set([parseInt(n)],0),s.set([i.length],1),s.set(i,2),t.push(s)})}),lt(...t)}var Pa={};D(Pa,{decrypt:()=>Ha,encrypt:()=>Dr});async function Dr(e,t,n){const r=e instanceof Uint8Array?T(e):e,i=Le.getSharedSecret(r,"02"+t),s=qr(i);let o=Uint8Array.from(Qn(16)),c=te.encode(n),a=gr(s,o).encrypt(c),l=pe.encode(new Uint8Array(a)),f=pe.encode(new Uint8Array(o.buffer));return`${l}?iv=${f}`}async function Ha(e,t,n){const r=e instanceof Uint8Array?T(e):e;let[i,s]=n.split("?iv="),o=Le.getSharedSecret(r,"02"+t),c=qr(o),a=pe.decode(s),l=pe.decode(i),f=gr(c,a).decrypt(l);return ge.decode(f)}function qr(e){return e.slice(1,33)}var Da={};D(Da,{NIP05_REGEX:()=>pn,isNip05:()=>qa,isValid:()=>Va,queryProfile:()=>jr,searchDomain:()=>za,useFetchImplementation:()=>ja});var pn=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,qa=e=>pn.test(e||""),mt;try{mt=fetch}catch{}function ja(e){mt=e}async function za(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await mt(n,{redirect:"manual"});if(r.status!==200)throw Error("Wrong response code");return(await r.json()).names}catch{return{}}}async function jr(e){var i;const t=e.match(pn);if(!t)return null;const[,n="_",r]=t;try{const s=`https://${r}/.well-known/nostr.json?name=${n}`,o=await mt(s,{redirect:"manual"});if(o.status!==200)throw Error("Wrong response code");const c=await o.json(),a=c.names[n];return a?{pubkey:a,relays:(i=c.relays)==null?void 0:i[a]}:null}catch{return null}}async function Va(e,t){const n=await jr(t);return n?n.pubkey===e:!1}var Wa={};D(Wa,{parse:()=>Za});function Za(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let i=e.tags.length-1;i>=0;i--){const s=e.tags[i];if(s[0]==="e"&&s[1]){const[o,c,a,l,f]=s,u={id:c,relays:a?[a]:[],author:f};if(l==="root"){t.root=u;continue}if(l==="reply"){t.reply=u;continue}if(l==="mention"){t.mentions.push(u);continue}n?r=u:n=u,t.mentions.push(u);continue}if(s[0]==="q"&&s[1]){const[o,c,a]=s;t.quotes.push({id:c,relays:a?[a]:[]})}if(s[0]==="p"&&s[1]){t.profiles.push({pubkey:s[1],relays:s[2]?[s[2]]:[]});continue}}return t.root||(t.root=r||n||t.reply),t.reply||(t.reply=n||t.root),[t.reply,t.root].forEach(i=>{if(!i)return;let s=t.mentions.indexOf(i);if(s!==-1&&t.mentions.splice(s,1),i.author){let o=t.profiles.find(c=>c.pubkey===i.author);o&&o.relays&&(i.relays||(i.relays=[]),o.relays.forEach(c=>{var a;((a=i.relays)==null?void 0:a.indexOf(c))===-1&&i.relays.push(c)}),o.relays=i.relays)}}),t.mentions.forEach(i=>{if(i.author){let s=t.profiles.find(o=>o.pubkey===i.author);s&&s.relays&&(i.relays||(i.relays=[]),s.relays.forEach(o=>{i.relays.indexOf(o)===-1&&i.relays.push(o)}),s.relays=i.relays)}}),t}var Ga={};D(Ga,{fetchRelayInformation:()=>Ja,useFetchImplementation:()=>Fa});var zr;try{zr=fetch}catch{}function Fa(e){zr=e}async function Ja(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}var Ya={};D(Ya,{fastEventHash:()=>Wr,getPow:()=>Vr,minePow:()=>Xa});function Vr(e){let t=0;for(let n=0;n<64;n+=8){const r=parseInt(e.substring(n,n+8),16);if(r===0)t+=32;else{t+=Math.clz32(r);break}}return t}function Xa(e,t){let n=0;const r=e,i=["nonce",n.toString(),t.toString()];for(r.tags.push(i);;){const s=Math.floor(new Date().getTime()/1e3);if(s!==r.created_at&&(n=0,r.created_at=s),i[1]=(++n).toString(),r.id=Wr(r),Vr(r.id)>=t)break}return r}function Wr(e){return T(le(te.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}var Qa={};D(Qa,{finishRepostEvent:()=>ec,getRepostedEvent:()=>tc,getRepostedEventPointer:()=>Zr});function ec(e,t,n,r){return ee({kind:an,tags:[...e.tags??[],["e",t.id,n],["p",t.pubkey]],content:e.content===""?"":JSON.stringify(t),created_at:e.created_at},r)}function Zr(e){if(e.kind!==an)return;let t,n;for(let r=e.tags.length-1;r>=0&&(t===void 0||n===void 0);r--){const i=e.tags[r];i.length>=2&&(i[0]==="e"&&t===void 0?t=i:i[0]==="p"&&n===void 0&&(n=i))}if(t!==void 0)return{id:t[1],relays:[t[2],n==null?void 0:n[2]].filter(r=>typeof r=="string"),author:n==null?void 0:n[1]}}function tc(e,{skipVerification:t}={}){const n=Zr(e);if(n===void 0||e.content==="")return;let r;try{r=JSON.parse(e.content)}catch{return}if(r.id===n.id&&!(!t&&!wt(r)))return r}var nc={};D(nc,{NOSTR_URI_REGEX:()=>xt,parse:()=>ic,test:()=>rc});var xt=new RegExp(`nostr:(${Hr.source})`);function rc(e){return typeof e=="string"&&new RegExp(`^${xt.source}$`).test(e)}function ic(e){const t=e.match(new RegExp(`^${xt.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:bt(t[1])}}var sc={};D(sc,{finishReactionEvent:()=>oc,getReactedEventPointer:()=>ac});function oc(e,t,n){const r=t.tags.filter(i=>i.length>=2&&(i[0]==="e"||i[0]==="p"));return ee({...e,kind:cn,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function ac(e){if(e.kind!==cn)return;let t,n;for(let r=e.tags.length-1;r>=0&&(t===void 0||n===void 0);r--){const i=e.tags[r];i.length>=2&&(i[0]==="e"&&t===void 0?t=i:i[0]==="p"&&n===void 0&&(n=i))}if(!(t===void 0||n===void 0))return{id:t[1],relays:[t[2],n[2]].filter(r=>r!==void 0),author:n[1]}}var cc={};D(cc,{matchAll:()=>uc,regex:()=>yn,replaceAll:()=>lc});var yn=()=>new RegExp(`\\b${xt.source}\\b`,"g");function*uc(e){const t=e.matchAll(yn());for(const n of t)try{const[r,i]=n;yield{uri:r,value:i,decoded:bt(i),start:n.index,end:n.index+r.length}}catch{}}function lc(e,t){return e.replaceAll(yn(),(n,r)=>t({uri:n,value:r,decoded:bt(r)}))}var fc={};D(fc,{channelCreateEvent:()=>hc,channelHideMessageEvent:()=>yc,channelMessageEvent:()=>pc,channelMetadataEvent:()=>dc,channelMuteUserEvent:()=>gc});var hc=(e,t)=>{let n;if(typeof e.content=="object")n=JSON.stringify(e.content);else if(typeof e.content=="string")n=e.content;else return;return ee({kind:Ir,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},dc=(e,t)=>{let n;if(typeof e.content=="object")n=JSON.stringify(e.content);else if(typeof e.content=="string")n=e.content;else return;return ee({kind:Ur,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},pc=(e,t)=>{const n=[["e",e.channel_create_event_id,e.relay_url,"root"]];return e.reply_to_channel_message_event_id&&n.push(["e",e.reply_to_channel_message_event_id,e.relay_url,"reply"]),ee({kind:Lr,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},yc=(e,t)=>{let n;if(typeof e.content=="object")n=JSON.stringify(e.content);else if(typeof e.content=="string")n=e.content;else return;return ee({kind:$r,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},gc=(e,t)=>{let n;if(typeof e.content=="object")n=JSON.stringify(e.content);else if(typeof e.content=="string")n=e.content;else return;return ee({kind:Tr,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)},wc={};D(wc,{EMOJI_SHORTCODE_REGEX:()=>Gr,matchAll:()=>bc,regex:()=>gn,replaceAll:()=>vc});var Gr=/:(\w+):/,gn=()=>new RegExp(`\\B${Gr.source}\\B`,"g");function*bc(e){const t=e.matchAll(gn());for(const n of t)try{const[r,i]=n;yield{shortcode:r,name:i,start:n.index,end:n.index+r.length}}catch{}}function vc(e,t){return e.replaceAll(gn(),(n,r)=>t({shortcode:n,name:r}))}var Ec={};D(Ec,{useFetchImplementation:()=>mc,validateGithub:()=>xc});var wn;try{wn=fetch}catch{}function mc(e){wn=e}async function xc(e,t,n){try{return await(await wn(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch{return!1}}var q={};D(q,{decrypt:()=>mn,encrypt:()=>En,getConversationKey:()=>bn,v2:()=>Cc});var Fr=1,Jr=65535;function bn(e,t){const n=Le.getSharedSecret(e,"02"+t).subarray(1,33);return rn(le,n,"nip44-v2")}function Yr(e,t){const n=Nr(le,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function vn(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,n=t<=256?32:t/8;return n*(Math.floor((e-1)/n)+1)}function Sc(e){if(!Number.isSafeInteger(e)||e<Fr||e>Jr)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}function Nc(e){const t=te.encode(e),n=t.length,r=Sc(n),i=new Uint8Array(vn(n)-n);return lt(r,t,i)}function Ac(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<Fr||t>Jr||n.length!==t||e.length!==2+vn(t))throw new Error("invalid padding");return ge.decode(n)}function Xr(e,t,n){if(n.length!==32)throw new Error("AAD associated data must be 32 bytes");const r=lt(n,t);return pt(le,e,r)}function Kc(e){if(typeof e!="string")throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if(e[0]==="#")throw new Error("unknown encryption version");let n;try{n=pe.decode(e)}catch(s){throw new Error("invalid base64: "+s.message)}const r=n.length;if(r<99||r>65603)throw new Error("invalid data length: "+r);const i=n[0];if(i!==2)throw new Error("unknown encryption version "+i);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}function En(e,t,n=Qn(32)){const{chacha_key:r,chacha_nonce:i,hmac_key:s}=Yr(t,n),o=Nc(e),c=mr(r,i,o),a=Xr(s,c,n);return pe.encode(lt(new Uint8Array([2]),n,c,a))}function mn(e,t){const{nonce:n,ciphertext:r,mac:i}=Kc(e),{chacha_key:s,chacha_nonce:o,hmac_key:c}=Yr(t,n),a=Xr(c,r,n);if(!Us(a,i))throw new Error("invalid MAC");const l=mr(s,o,r);return Ac(l)}var Cc={utils:{getConversationKey:bn,calcPaddedLen:vn},encrypt:En,decrypt:mn},Bc={};D(Bc,{makeNwcRequestEvent:()=>_c,parseConnectionString:()=>kc});function kc(e){const{pathname:t,searchParams:n}=new URL(e),r=t,i=n.get("relay"),s=n.get("secret");if(!r||!i||!s)throw new Error("invalid connection string");return{pubkey:r,relay:i,secret:s}}async function _c(e,t,n){const i=await Dr(t,e,JSON.stringify({method:"pay_invoice",params:{invoice:n}})),s={kind:Mr,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",e]]};return ee(s,t)}var Ic={};D(Ic,{getZapEndpoint:()=>Lc,makeZapReceipt:()=>Rc,makeZapRequest:()=>$c,useFetchImplementation:()=>Uc,validateZapRequest:()=>Tc});var xn;try{xn=fetch}catch{}function Uc(e){xn=e}async function Lc(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(n){let{words:o}=De.decode(n,1e3),c=De.fromWords(o);t=ge.decode(c)}else if(r){let[o,c]=r.split("@");t=new URL(`/.well-known/lnurlp/${o}`,`https://${c}`).toString()}else return null;let s=await(await xn(t)).json();if(s.allowsNostr&&s.nostrPubkey)return s.callback}catch{}return null}function $c({profile:e,event:t,amount:n,relays:r,comment:i=""}){if(!n)throw new Error("amount not given");if(!e)throw new Error("profile not given");let s={kind:9734,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",e],["amount",n.toString()],["relays",...r]]};return t&&s.tags.push(["e",t]),s}function Tc(e){let t;try{t=JSON.parse(e)}catch{return"Invalid zap request JSON."}if(!yt(t))return"Zap request is not a valid Nostr event.";if(!wt(t))return"Invalid signature on zap request.";let n=t.tags.find(([s,o])=>s==="p"&&o);if(!n)return"Zap request doesn't have a 'p' tag.";if(!n[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let r=t.tags.find(([s,o])=>s==="e"&&o);return r&&!r[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":t.tags.find(([s,o])=>s==="relays"&&o)?null:"Zap request doesn't have a 'relays' tag."}function Rc({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let i=JSON.parse(e),s=i.tags.filter(([c])=>c==="e"||c==="p"||c==="a"),o={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...s,["P",i.pubkey],["bolt11",n],["description",e]]};return t&&o.tags.push(["preimage",t]),o}var Oc={};D(Oc,{createRumor:()=>ii,createSeal:()=>si,createWrap:()=>oi,unwrapEvent:()=>ai,unwrapManyEvents:()=>Hc,wrapEvent:()=>Sn,wrapManyEvents:()=>Pc});var Mc=2*24*60*60,Qr=()=>Math.round(Date.now()/1e3),ei=()=>Math.round(Qr()-Math.random()*Mc),ti=(e,t)=>bn(e,t),ni=(e,t,n)=>En(JSON.stringify(e),ti(t,n)),ri=(e,t)=>JSON.parse(mn(e.content,ti(t,e.pubkey)));function ii(e,t){const n={created_at:Qr(),content:"",tags:[],...e,pubkey:we(t)};return n.id=ze(n),n}function si(e,t,n){return ee({kind:_r,content:ni(e,t,n),created_at:ei(),tags:[]},t)}function oi(e,t){const n=$e();return ee({kind:Rr,content:ni(e,n,t),created_at:ei(),tags:[["p",t]]},n)}function Sn(e,t,n){const r=ii(e,t),i=si(r,t,n);return oi(i,n)}function Pc(e,t,n){if(!n||n.length===0)throw new Error("At least one recipient is required.");const r=we(t),i=[Sn(e,t,r)];return n.forEach(s=>{i.push(Sn(e,t,s))}),i}function ai(e,t){const n=ri(e,t);return ri(n,t)}function Hc(e,t){let n=[];return e.forEach(r=>{n.push(ai(r,t))}),n.sort((r,i)=>r.created_at-i.created_at),n}var Dc={};D(Dc,{getToken:()=>qc,hashPayload:()=>Nn,unpackEventFromToken:()=>ui,validateEvent:()=>yi,validateEventKind:()=>fi,validateEventMethodTag:()=>di,validateEventPayloadTag:()=>pi,validateEventTimestamp:()=>li,validateEventUrlTag:()=>hi,validateToken:()=>jc});var ci="Nostr ";async function qc(e,t,n,r=!1,i){const s={kind:un,tags:[["u",e],["method",t]],created_at:Math.round(new Date().getTime()/1e3),content:""};i&&s.tags.push(["payload",Nn(i)]);const o=await n(s);return(r?ci:"")+pe.encode(te.encode(JSON.stringify(o)))}async function jc(e,t,n){const r=await ui(e).catch(s=>{throw s});return await yi(r,t,n).catch(s=>{throw s})}async function ui(e){if(!e)throw new Error("Missing token");e=e.replace(ci,"");const t=ge.decode(pe.decode(e));if(!t||t.length===0||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function li(e){return e.created_at?Math.round(new Date().getTime()/1e3)-e.created_at<60:!1}function fi(e){return e.kind===un}function hi(e,t){const n=e.tags.find(r=>r[0]==="u");return n?n.length>0&&n[1]===t:!1}function di(e,t){const n=e.tags.find(r=>r[0]==="method");return n?n.length>0&&n[1].toLowerCase()===t.toLowerCase():!1}function Nn(e){const t=le(te.encode(JSON.stringify(e)));return T(t)}function pi(e,t){const n=e.tags.find(i=>i[0]==="payload");if(!n)return!1;const r=Nn(t);return n.length>0&&n[1]===r}async function yi(e,t,n,r){if(!wt(e))throw new Error("Invalid nostr event, signature invalid");if(!fi(e))throw new Error("Invalid nostr event, kind invalid");if(!li(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!hi(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!di(e,n))throw new Error("Invalid nostr event, method tag invalid");if(r&&typeof r=="object"&&Object.keys(r).length>0&&!pi(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}const Ke=30078,An=30078,gi=14,zc=100;function Vc(e){return JSON.stringify({rootKey:T(e.rootKey),theirCurrentNostrPublicKey:e.theirCurrentNostrPublicKey,theirNextNostrPublicKey:e.theirNextNostrPublicKey,ourCurrentNostrKey:e.ourCurrentNostrKey?{publicKey:e.ourCurrentNostrKey.publicKey,privateKey:T(e.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:e.ourNextNostrKey.publicKey,privateKey:T(e.ourNextNostrKey.privateKey)},receivingChainKey:e.receivingChainKey?T(e.receivingChainKey):void 0,sendingChainKey:e.sendingChainKey?T(e.sendingChainKey):void 0,sendingChainMessageNumber:e.sendingChainMessageNumber,receivingChainMessageNumber:e.receivingChainMessageNumber,previousSendingChainMessageCount:e.previousSendingChainMessageCount,skippedMessageKeys:Object.fromEntries(Object.entries(e.skippedMessageKeys).map(([t,n])=>[t,T(n)])),skippedHeaderKeys:Object.fromEntries(Object.entries(e.skippedHeaderKeys).map(([t,n])=>[t,n.map(r=>T(r))]))})}function Wc(e){const t=JSON.parse(e);return{rootKey:F(t.rootKey),theirCurrentNostrPublicKey:t.theirCurrentNostrPublicKey,theirNextNostrPublicKey:t.theirNextNostrPublicKey,ourCurrentNostrKey:t.ourCurrentNostrKey?{publicKey:t.ourCurrentNostrKey.publicKey,privateKey:F(t.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:t.ourNextNostrKey.publicKey,privateKey:F(t.ourNextNostrKey.privateKey)},receivingChainKey:t.receivingChainKey?F(t.receivingChainKey):void 0,sendingChainKey:t.sendingChainKey?F(t.sendingChainKey):void 0,sendingChainMessageNumber:t.sendingChainMessageNumber,receivingChainMessageNumber:t.receivingChainMessageNumber,previousSendingChainMessageCount:t.previousSendingChainMessageCount,skippedMessageKeys:Object.fromEntries(Object.entries(t.skippedMessageKeys).map(([n,r])=>[n,F(r)])),skippedHeaderKeys:Object.fromEntries(Object.entries(t.skippedHeaderKeys||{}).map(([n,r])=>[n,r.map(i=>F(i))]))}}async function*Zc(e){const t=[];let n=null;const r=e.onEvent(i=>{n?(n(i),n=null):t.push(i)});try{for(;;)t.length>0?yield t.shift():yield new Promise(i=>{n=i})}finally{r()}}function Te(e,t=new Uint8Array(32),n=1){const r=rn(le,e,t),i=[];for(let s=1;s<=n;s++)i.push(Nr(le,r,new Uint8Array([s]),32));return i}function St(e,t){return`${e}:${t}`}const Gc=1e3,Fc="0000000000000000000000000000000000000000000000000000000000000000";class et{constructor(t,n){ie(this,"nostrUnsubscribe");ie(this,"nostrNextUnsubscribe");ie(this,"internalSubscriptions",new Map);ie(this,"currentInternalSubscriptionId",0);ie(this,"name");this.nostrSubscribe=t,this.state=n,this.name=Math.random().toString(36).substring(2,6)}static init(t,n,r,i,s,o){const c=$e(),[a,l]=Te(s,q.getConversationKey(c,n),2);let f,u;i?(f={publicKey:we(r),privateKey:r},u={publicKey:we(c),privateKey:c}):u={publicKey:we(r),privateKey:r};const g={rootKey:i?a:s,theirNextNostrPublicKey:n,ourCurrentNostrKey:f,ourNextNostrKey:u,receivingChainKey:void 0,sendingChainKey:i?l:void 0,sendingChainMessageNumber:0,receivingChainMessageNumber:0,previousSendingChainMessageCount:0,skippedMessageKeys:{},skippedHeaderKeys:{}},b=new et(t,g);return o&&(b.name=o),b}send(t){return this.sendEvent({content:t,kind:gi})}sendEvent(t){if(!this.state.theirNextNostrPublicKey||!this.state.ourCurrentNostrKey)throw new Error("we are not the initiator, so we can't send the first message");if("sig"in t)throw new Error("Event must be unsigned "+JSON.stringify(t));const n={...t,content:t.content||"",kind:t.kind||Ke,created_at:t.created_at||Math.floor(Date.now()/1e3),tags:t.tags||[],pubkey:t.pubkey||Fc};n.tags.some(([a])=>a==="ms")||n.tags.push(["ms",Date.now().toString()]),n.id=ze(n);const[r,i]=this.ratchetEncrypt(JSON.stringify(n)),s=q.getConversationKey(this.state.ourCurrentNostrKey.privateKey,this.state.theirNextNostrPublicKey),o=q.encrypt(JSON.stringify(r),s);return ee({content:i,kind:Ke,tags:[["header",o]],created_at:Math.floor(Date.now()/1e3)},this.state.ourCurrentNostrKey.privateKey)}onEvent(t){const n=this.currentInternalSubscriptionId++;return this.internalSubscriptions.set(n,t),this.subscribeToNostrEvents(),()=>this.internalSubscriptions.delete(n)}close(){var t,n;(t=this.nostrUnsubscribe)==null||t.call(this),(n=this.nostrNextUnsubscribe)==null||n.call(this)}ratchetEncrypt(t){const[n,r]=Te(this.state.sendingChainKey,new Uint8Array([1]),2);return this.state.sendingChainKey=n,[{number:this.state.sendingChainMessageNumber++,nextPublicKey:this.state.ourNextNostrKey.publicKey,previousChainLength:this.state.previousSendingChainMessageCount},q.encrypt(t,r)]}ratchetDecrypt(t,n,r){const i=this.trySkippedMessageKeys(t,n,r);if(i)return i;this.skipMessageKeys(t.number,r);const[s,o]=Te(this.state.receivingChainKey,new Uint8Array([1]),2);this.state.receivingChainKey=s,this.state.receivingChainMessageNumber++;try{return q.decrypt(n,o)}catch(c){throw console.error(this.name,"Decryption failed:",c,{messageKey:T(o).slice(0,4),receivingChainKey:T(this.state.receivingChainKey).slice(0,4),sendingChainKey:this.state.sendingChainKey&&T(this.state.sendingChainKey).slice(0,4),rootKey:T(this.state.rootKey).slice(0,4)}),c}}ratchetStep(t){this.state.previousSendingChainMessageCount=this.state.sendingChainMessageNumber,this.state.sendingChainMessageNumber=0,this.state.receivingChainMessageNumber=0,this.state.theirNextNostrPublicKey=t;const n=q.getConversationKey(this.state.ourNextNostrKey.privateKey,this.state.theirNextNostrPublicKey),[r,i]=Te(this.state.rootKey,n,2);this.state.receivingChainKey=i,this.state.ourCurrentNostrKey=this.state.ourNextNostrKey;const s=$e();this.state.ourNextNostrKey={publicKey:we(s),privateKey:s};const o=q.getConversationKey(this.state.ourNextNostrKey.privateKey,this.state.theirNextNostrPublicKey),[c,a]=Te(r,o,2);this.state.rootKey=c,this.state.sendingChainKey=a}skipMessageKeys(t,n){if(this.state.receivingChainMessageNumber+Gc<t)throw new Error("Too many skipped messages");for(;this.state.receivingChainMessageNumber<t;){const[r,i]=Te(this.state.receivingChainKey,new Uint8Array([1]),2);this.state.receivingChainKey=r;const s=St(n,this.state.receivingChainMessageNumber);if(this.state.skippedMessageKeys[s]=i,!this.state.skippedHeaderKeys[n]){const o=[];if(this.state.ourCurrentNostrKey){const a=q.getConversationKey(this.state.ourCurrentNostrKey.privateKey,n);o.push(a)}const c=q.getConversationKey(this.state.ourNextNostrKey.privateKey,n);o.push(c),this.state.skippedHeaderKeys[n]=o}this.state.receivingChainMessageNumber++}}trySkippedMessageKeys(t,n,r){var s;const i=St(r,t.number);if(i in this.state.skippedMessageKeys){const o=this.state.skippedMessageKeys[i];return delete this.state.skippedMessageKeys[i],Object.keys(this.state.skippedMessageKeys).some(a=>a.startsWith(`${r}:`))||(delete this.state.skippedHeaderKeys[r],(s=this.nostrUnsubscribe)==null||s.call(this),this.nostrUnsubscribe=void 0),q.decrypt(n,o)}return null}decryptHeader(t){const n=t.tags[0][1];if(this.state.ourCurrentNostrKey){const s=q.getConversationKey(this.state.ourCurrentNostrKey.privateKey,t.pubkey);try{return[JSON.parse(q.decrypt(n,s)),!1,!1]}catch{}}const r=q.getConversationKey(this.state.ourNextNostrKey.privateKey,t.pubkey);try{return[JSON.parse(q.decrypt(n,r)),!0,!1]}catch{}const i=this.state.skippedHeaderKeys[t.pubkey];if(i)for(const s of i)try{return[JSON.parse(q.decrypt(n,s)),!1,!0]}catch{}throw new Error("Failed to decrypt header with current and skipped header keys")}handleNostrEvent(t){var c;const[n,r,i]=this.decryptHeader(t);if(!i)this.state.theirNextNostrPublicKey!==n.nextPublicKey&&(this.state.theirCurrentNostrPublicKey=this.state.theirNextNostrPublicKey,this.state.theirNextNostrPublicKey=n.nextPublicKey,(c=this.nostrUnsubscribe)==null||c.call(this),this.nostrUnsubscribe=this.nostrNextUnsubscribe,this.nostrNextUnsubscribe=this.nostrSubscribe({authors:[this.state.theirNextNostrPublicKey],kinds:[Ke]},a=>this.handleNostrEvent(a))),r&&(this.skipMessageKeys(n.previousChainLength,t.pubkey),this.ratchetStep(n.nextPublicKey));else if(!(St(t.pubkey,n.number)in this.state.skippedMessageKeys))return;const s=this.ratchetDecrypt(n,t.content,t.pubkey),o=JSON.parse(s);if(!yt(o)){console.error("Invalid event received",o);return}if(o.id!==ze(o)){console.error("Event hash does not match",o);return}this.internalSubscriptions.forEach(a=>a(o,t))}subscribeToNostrEvents(){if(this.nostrNextUnsubscribe)return;this.nostrNextUnsubscribe=this.nostrSubscribe({authors:[this.state.theirNextNostrPublicKey],kinds:[Ke]},n=>this.handleNostrEvent(n));const t=Object.keys(this.state.skippedHeaderKeys);this.state.theirCurrentNostrPublicKey&&!t.includes(this.state.theirCurrentNostrPublicKey)&&t.push(this.state.theirCurrentNostrPublicKey),this.nostrUnsubscribe=this.nostrSubscribe({authors:t,kinds:[Ke]},n=>this.handleNostrEvent(n))}}new TextDecoder("utf-8"),new TextEncoder;function Nt(e,t){const n=Le.getSharedSecret(e,"02"+t).subarray(1,33);return rn(le,n,"nip44-v2")}class Re{constructor(t,n,r,i,s,o,c=[]){this.inviterEphemeralPublicKey=t,this.sharedSecret=n,this.inviter=r,this.inviterEphemeralPrivateKey=i,this.label=s,this.maxUses=o,this.usedBy=c}static createNew(t,n,r){if(!t)throw new Error("Inviter public key is required");const i=$e(),s=we(i),o=T($e());return new Re(s,o,t,i,n,r)}static fromUrl(t){const r=new URL(t).hash.slice(1);if(!r)throw new Error("No invite data found in the URL hash.");const i=decodeURIComponent(r);let s;try{s=JSON.parse(i)}catch(l){throw new Error("Invite data in URL hash is not valid JSON: "+l)}const{inviter:o,ephemeralKey:c,sharedSecret:a}=s;if(!o||!c||!a)throw new Error("Missing required fields (inviter, ephemeralKey, sharedSecret) in invite data.");return new Re(c,a,o)}static deserialize(t){const n=JSON.parse(t);return new Re(n.inviterEphemeralPublicKey,n.sharedSecret,n.inviter,n.inviterEphemeralPrivateKey?new Uint8Array(n.inviterEphemeralPrivateKey):void 0,n.label,n.maxUses,n.usedBy)}static fromEvent(t){var o,c;if(!t.sig)throw new Error("Event is not signed");if(!wt(t))throw new Error("Event signature is invalid");const{tags:n}=t,r=(o=n.find(([a])=>a==="ephemeralKey"))==null?void 0:o[1],i=(c=n.find(([a])=>a==="sharedSecret"))==null?void 0:c[1],s=t.pubkey;if(!r||!i)throw new Error("Invalid invite event: missing session key or sharedSecret");return new Re(r,i,s)}static fromUser(t,n,r){const i={kinds:[An],authors:[t],limit:1,"#d":["nostr-double-ratchet/invite"]};let s=0;return n(i,c=>{if(!(!c.created_at||c.created_at<=s)){s=c.created_at;try{const a=Re.fromEvent(c);r(a)}catch(a){console.error("Error processing invite:",a,"event:",c)}}})}serialize(){return JSON.stringify({inviterEphemeralPublicKey:this.inviterEphemeralPublicKey,sharedSecret:this.sharedSecret,inviter:this.inviter,inviterEphemeralPrivateKey:this.inviterEphemeralPrivateKey?Array.from(this.inviterEphemeralPrivateKey):void 0,label:this.label,maxUses:this.maxUses,usedBy:this.usedBy})}getUrl(t="https://iris.to"){const n={inviter:this.inviter,ephemeralKey:this.inviterEphemeralPublicKey,sharedSecret:this.sharedSecret},r=new URL(t);return r.hash=encodeURIComponent(JSON.stringify(n)),r.toString()}getEvent(){return{kind:An,pubkey:this.inviter,content:"",created_at:Math.floor(Date.now()/1e3),tags:[["ephemeralKey",this.inviterEphemeralPublicKey],["sharedSecret",this.sharedSecret],["d","nostr-double-ratchet/invite"]]}}async accept(t,n,r){const i=$e(),s=we(i),o=this.inviter||this.inviterEphemeralPublicKey,c=F(this.sharedSecret),a=et.init(t,this.inviterEphemeralPublicKey,i,!0,c,void 0),l=$e(),f=we(l),g=await(typeof r=="function"?r:(h,d)=>Promise.resolve(q.encrypt(h,Nt(r,d))))(s,o),b={pubkey:n,tags:[["sharedSecret",this.sharedSecret]],content:await q.encrypt(g,c),created_at:Math.floor(Date.now()/1e3)},p={kind:Ke,pubkey:f,content:q.encrypt(JSON.stringify(b),Nt(l,this.inviterEphemeralPublicKey)),created_at:Math.floor(Date.now()/1e3),tags:[["p",this.inviterEphemeralPublicKey]]};return{session:a,event:ee(p,l)}}listen(t,n,r){if(!this.inviterEphemeralPrivateKey)throw new Error("Inviter session key is not available");const i={kinds:[Ke],"#p":[this.inviterEphemeralPublicKey]};return n(i,async s=>{try{if(this.maxUses&&this.usedBy.length>=this.maxUses){console.error("Invite has reached maximum number of uses");return}const o=await q.decrypt(s.content,Nt(this.inviterEphemeralPrivateKey,s.pubkey)),c=JSON.parse(o);if(!c.tags||!c.tags.some(([h,d])=>h==="sharedSecret"&&d===this.sharedSecret)){console.error("Invalid secret from event",s);return}const a=F(this.sharedSecret),l=c.pubkey;this.usedBy.push(l);const f=await q.decrypt(c.content,a),g=await(typeof t=="function"?t:(h,d)=>Promise.resolve(q.decrypt(h,Nt(t,d))))(f,l),b=s.id,p=et.init(n,g,this.inviterEphemeralPrivateKey,!1,a,b);r(p,l)}catch(o){console.error("Error processing invite message:",o,"event",s)}})}}H.CHAT_MESSAGE_KIND=gi,H.INVITE_EVENT_KIND=An,H.Invite=Re,H.MAX_SKIP=zc,H.MESSAGE_EVENT_KIND=Ke,H.Session=et,H.createEventStream=Zc,H.deserializeSessionState=Wc,H.kdf=Te,H.serializeSessionState=Vc,H.skippedMessageIndexKey=St,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})});
1
+ (function(H,J){typeof exports=="object"&&typeof module<"u"?J(exports):typeof define=="function"&&define.amd?define(["exports"],J):(H=typeof globalThis<"u"?globalThis:H||self,J(H["nostr-double-ratchet"]={}))})(this,function(H){"use strict";var Yc=Object.defineProperty;var Xc=(H,J,ke)=>J in H?Yc(H,J,{enumerable:!0,configurable:!0,writable:!0,value:ke}):H[J]=ke;var ie=(H,J,ke)=>Xc(H,typeof J!="symbol"?J+"":J,ke);function J(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function ke(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Ei(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");J(e.outputLen),J(e.blockLen)}function nt(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function mi(e,t){ke(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const At=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Cn=e=>e instanceof Uint8Array,Kt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),se=(e,t)=>e<<32-t|e>>>t;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function xi(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ct(e){if(typeof e=="string"&&(e=xi(e)),!Cn(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function Si(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!Cn(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}let Bn=class{clone(){return this._cloneInto()}};function Ni(e){const t=r=>e().update(Ct(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function kn(e=32){if(At&&typeof At.getRandomValues=="function")return At.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Ai(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),c=Number(n&s),a=r?4:0,l=r?0:4;e.setUint32(t+a,o,r),e.setUint32(t+l,c,r)}let Ki=class extends Bn{constructor(t,n,r,i){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)}update(t){nt(this);const{view:n,buffer:r,blockLen:i}=this;t=Ct(t);const s=t.length;for(let o=0;o<s;){const c=Math.min(i-this.pos,s-o);if(c===i){const a=Kt(t);for(;i<=s-o;o+=i)this.process(a,o);continue}r.set(t.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){nt(this),mi(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(r,0),o=0);for(let u=o;u<i;u++)n[u]=0;Ai(r,i-8,BigInt(this.length*8),s),this.process(r,0);const c=Kt(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)c.setUint32(4*u,f[u],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:c}=this;return t.length=i,t.pos=c,t.finished=s,t.destroyed=o,i%n&&t.buffer.set(r),t}};const Ci=(e,t,n)=>e&t^~e&n,Bi=(e,t,n)=>e&t^e&n^t&n,ki=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),be=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ve=new Uint32Array(64);let _i=class extends Ki{constructor(){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}get(){const{A:t,B:n,C:r,D:i,E:s,F:o,G:c,H:a}=this;return[t,n,r,i,s,o,c,a]}set(t,n,r,i,s,o,c,a){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(t,n){for(let u=0;u<16;u++,n+=4)ve[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const g=ve[u-15],b=ve[u-2],p=se(g,7)^se(g,18)^g>>>3,h=se(b,17)^se(b,19)^b>>>10;ve[u]=h+ve[u-7]+p+ve[u-16]|0}let{A:r,B:i,C:s,D:o,E:c,F:a,G:l,H:f}=this;for(let u=0;u<64;u++){const g=se(c,6)^se(c,11)^se(c,25),b=f+g+Ci(c,a,l)+ki[u]+ve[u]|0,h=(se(r,2)^se(r,13)^se(r,22))+Bi(r,i,s)|0;f=l,l=a,a=c,c=o+b|0,o=s,s=i,i=r,r=b+h|0}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)}roundClean(){ve.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Bt=Ni(()=>new _i);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _n=BigInt(0),rt=BigInt(1),Ii=BigInt(2),it=e=>e instanceof Uint8Array,Ui=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Oe(e){if(!it(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Ui[e[n]];return t}function In(e){const t=e.toString(16);return t.length&1?`0${t}`:t}function kt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return BigInt(e===""?"0":`0x${e}`)}function Pe(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){const i=r*2,s=e.slice(i,i+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[r]=o}return n}function Y(e){return kt(Oe(e))}function _t(e){if(!it(e))throw new Error("Uint8Array expected");return kt(Oe(Uint8Array.from(e).reverse()))}function Ee(e,t){return Pe(e.toString(16).padStart(t*2,"0"))}function It(e,t){return Ee(e,t).reverse()}function Li(e){return Pe(In(e))}function Z(e,t,n){let r;if(typeof t=="string")try{r=Pe(t)}catch(s){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${s}`)}else if(it(t))r=Uint8Array.from(t);else throw new Error(`${e} must be hex string or Uint8Array`);const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(`${e} expected ${n} bytes, got ${i}`);return r}function _e(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!it(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function $i(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Ti(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ri(e){let t;for(t=0;e>_n;e>>=rt,t+=1);return t}function Mi(e,t){return e>>BigInt(t)&rt}const Oi=(e,t,n)=>e|(n?rt:_n)<<BigInt(t),Ut=e=>(Ii<<BigInt(e-1))-rt,Lt=e=>new Uint8Array(e),Un=e=>Uint8Array.from(e);function Ln(e,t,n){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=Lt(e),i=Lt(e),s=0;const o=()=>{r.fill(1),i.fill(0),s=0},c=(...u)=>n(i,r,...u),a=(u=Lt())=>{i=c(Un([0]),u),r=c(),u.length!==0&&(i=c(Un([1]),u),r=c())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const g=[];for(;u<t;){r=c();const b=r.slice();g.push(b),u+=r.length}return _e(...g)};return(u,g)=>{o(),a(u);let b;for(;!(b=g(l()));)a();return o(),b}}const Pi={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Fe(e,t,n={}){const r=(i,s,o)=>{const c=Pi[s];if(typeof c!="function")throw new Error(`Invalid validator "${s}", expected function`);const a=e[i];if(!(o&&a===void 0)&&!c(a,e))throw new Error(`Invalid param ${String(i)}=${a} (${typeof a}), expected ${s}`)};for(const[i,s]of Object.entries(t))r(i,s,!1);for(const[i,s]of Object.entries(n))r(i,s,!0);return e}const Hi=Object.freeze(Object.defineProperty({__proto__:null,bitGet:Mi,bitLen:Ri,bitMask:Ut,bitSet:Oi,bytesToHex:Oe,bytesToNumberBE:Y,bytesToNumberLE:_t,concatBytes:_e,createHmacDrbg:Ln,ensureBytes:Z,equalBytes:$i,hexToBytes:Pe,hexToNumber:kt,numberToBytesBE:Ee,numberToBytesLE:It,numberToHexUnpadded:In,numberToVarBytesBE:Li,utf8ToBytes:Ti,validateObject:Fe},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const V=BigInt(0),z=BigInt(1),Ie=BigInt(2),Di=BigInt(3),$t=BigInt(4),$n=BigInt(5),Tn=BigInt(8);BigInt(9),BigInt(16);function W(e,t){const n=e%t;return n>=V?n:t+n}function qi(e,t,n){if(n<=V||t<V)throw new Error("Expected power/modulo > 0");if(n===z)return V;let r=z;for(;t>V;)t&z&&(r=r*e%n),e=e*e%n,t>>=z;return r}function X(e,t,n){let r=e;for(;t-- >V;)r*=r,r%=n;return r}function Tt(e,t){if(e===V||t<=V)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=W(e,t),r=t,i=V,s=z;for(;n!==V;){const c=r/n,a=r%n,l=i-s*c;r=n,n=a,i=s,s=l}if(r!==z)throw new Error("invert: does not exist");return W(i,t)}function ji(e){const t=(e-z)/Ie;let n,r,i;for(n=e-z,r=0;n%Ie===V;n/=Ie,r++);for(i=Ie;i<e&&qi(i,t,e)!==e-z;i++);if(r===1){const o=(e+z)/$t;return function(a,l){const f=a.pow(l,o);if(!a.eql(a.sqr(f),l))throw new Error("Cannot find square root");return f}}const s=(n+z)/Ie;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let l=r,f=c.pow(c.mul(c.ONE,i),n),u=c.pow(a,s),g=c.pow(a,n);for(;!c.eql(g,c.ONE);){if(c.eql(g,c.ZERO))return c.ZERO;let b=1;for(let h=c.sqr(g);b<l&&!c.eql(h,c.ONE);b++)h=c.sqr(h);const p=c.pow(f,z<<BigInt(l-b-1));f=c.sqr(p),u=c.mul(u,p),g=c.mul(g,f),l=b}return u}}function zi(e){if(e%$t===Di){const t=(e+z)/$t;return function(r,i){const s=r.pow(i,t);if(!r.eql(r.sqr(s),i))throw new Error("Cannot find square root");return s}}if(e%Tn===$n){const t=(e-$n)/Tn;return function(r,i){const s=r.mul(i,Ie),o=r.pow(s,t),c=r.mul(i,o),a=r.mul(r.mul(c,Ie),o),l=r.mul(c,r.sub(a,r.ONE));if(!r.eql(r.sqr(l),i))throw new Error("Cannot find square root");return l}}return ji(e)}const Vi=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wi(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=Vi.reduce((r,i)=>(r[i]="function",r),t);return Fe(e,n)}function Zi(e,t,n){if(n<V)throw new Error("Expected power > 0");if(n===V)return e.ONE;if(n===z)return t;let r=e.ONE,i=t;for(;n>V;)n&z&&(r=e.mul(r,i)),i=e.sqr(i),n>>=z;return r}function Gi(e,t){const n=new Array(t.length),r=t.reduce((s,o,c)=>e.is0(o)?s:(n[c]=s,e.mul(s,o)),e.ONE),i=e.inv(r);return t.reduceRight((s,o,c)=>e.is0(o)?s:(n[c]=e.mul(s,n[c]),e.mul(s,o)),i),n}function Rn(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Fi(e,t,n=!1,r={}){if(e<=V)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:i,nByteLength:s}=Rn(e,t);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");const o=zi(e),c=Object.freeze({ORDER:e,BITS:i,BYTES:s,MASK:Ut(i),ZERO:V,ONE:z,create:a=>W(a,e),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return V<=a&&a<e},is0:a=>a===V,isOdd:a=>(a&z)===z,neg:a=>W(-a,e),eql:(a,l)=>a===l,sqr:a=>W(a*a,e),add:(a,l)=>W(a+l,e),sub:(a,l)=>W(a-l,e),mul:(a,l)=>W(a*l,e),pow:(a,l)=>Zi(c,a,l),div:(a,l)=>W(a*Tt(l,e),e),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Tt(a,e),sqrt:r.sqrt||(a=>o(c,a)),invertBatch:a=>Gi(c,a),cmov:(a,l,f)=>f?l:a,toBytes:a=>n?It(a,s):Ee(a,s),fromBytes:a=>{if(a.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${a.length}`);return n?_t(a):Y(a)}});return Object.freeze(c)}function Mn(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function On(e){const t=Mn(e);return t+Math.ceil(t/2)}function Ji(e,t,n=!1){const r=e.length,i=Mn(t),s=On(t);if(r<16||r<s||r>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);const o=n?Y(e):_t(e),c=W(o,t-z)+z;return n?It(c,i):Ee(c,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Yi=BigInt(0),Rt=BigInt(1);function Xi(e,t){const n=(i,s)=>{const o=s.negate();return i?o:s},r=i=>{const s=Math.ceil(t/i)+1,o=2**(i-1);return{windows:s,windowSize:o}};return{constTimeNegate:n,unsafeLadder(i,s){let o=e.ZERO,c=i;for(;s>Yi;)s&Rt&&(o=o.add(c)),c=c.double(),s>>=Rt;return o},precomputeWindow(i,s){const{windows:o,windowSize:c}=r(s),a=[];let l=i,f=l;for(let u=0;u<o;u++){f=l,a.push(f);for(let g=1;g<c;g++)f=f.add(l),a.push(f);l=f.double()}return a},wNAF(i,s,o){const{windows:c,windowSize:a}=r(i);let l=e.ZERO,f=e.BASE;const u=BigInt(2**i-1),g=2**i,b=BigInt(i);for(let p=0;p<c;p++){const h=p*a;let d=Number(o&u);o>>=b,d>a&&(d-=g,o+=Rt);const y=h,m=h+Math.abs(d)-1,A=p%2!==0,I=d<0;d===0?f=f.add(n(A,s[y])):l=l.add(n(I,s[m]))}return{p:l,f}},wNAFCached(i,s,o,c){const a=i._WINDOW_SIZE||1;let l=s.get(i);return l||(l=this.precomputeWindow(i,a),a!==1&&s.set(i,c(l))),this.wNAF(a,l,o)}}}function Pn(e){return Wi(e.Fp),Fe(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Rn(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Qi(e){const t=Pn(e);Fe(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:i}=t;if(n){if(!r.eql(i,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}const{bytesToNumberBE:es,hexToBytes:ts}=Hi,Ue={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=Ue;if(e.length<2||e[0]!==2)throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:es(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=Ue,n=typeof e=="string"?ts(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:i,l:s}=Ue._parseInt(n.subarray(2)),{d:o,l:c}=Ue._parseInt(s);if(c.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s:o}},hexFromSig(e){const t=l=>Number.parseInt(l[0],16)&8?"00"+l:l,n=l=>{const f=l.toString(16);return f.length&1?`0${f}`:f},r=t(n(e.s)),i=t(n(e.r)),s=r.length/2,o=i.length/2,c=n(s),a=n(o);return`30${n(o+s+4)}02${a}${i}02${c}${r}`}},ue=BigInt(0),Q=BigInt(1);BigInt(2);const Hn=BigInt(3);BigInt(4);function ns(e){const t=Qi(e),{Fp:n}=t,r=t.toBytes||((p,h,d)=>{const y=h.toAffine();return _e(Uint8Array.from([4]),n.toBytes(y.x),n.toBytes(y.y))}),i=t.fromBytes||(p=>{const h=p.subarray(1),d=n.fromBytes(h.subarray(0,n.BYTES)),y=n.fromBytes(h.subarray(n.BYTES,2*n.BYTES));return{x:d,y}});function s(p){const{a:h,b:d}=t,y=n.sqr(p),m=n.mul(y,p);return n.add(n.add(m,n.mul(p,h)),d)}if(!n.eql(n.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function o(p){return typeof p=="bigint"&&ue<p&&p<t.n}function c(p){if(!o(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(p){const{allowedPrivateKeyLengths:h,nByteLength:d,wrapPrivateKey:y,n:m}=t;if(h&&typeof p!="bigint"){if(p instanceof Uint8Array&&(p=Oe(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(d*2,"0")}let A;try{A=typeof p=="bigint"?p:Y(Z("private key",p,d))}catch{throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof p}`)}return y&&(A=W(A,m)),c(A),A}const l=new Map;function f(p){if(!(p instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(h,d,y){if(this.px=h,this.py=d,this.pz=y,h==null||!n.isValid(h))throw new Error("x required");if(d==null||!n.isValid(d))throw new Error("y required");if(y==null||!n.isValid(y))throw new Error("z required")}static fromAffine(h){const{x:d,y}=h||{};if(!h||!n.isValid(d)||!n.isValid(y))throw new Error("invalid affine point");if(h instanceof u)throw new Error("projective point not allowed");const m=A=>n.eql(A,n.ZERO);return m(d)&&m(y)?u.ZERO:new u(d,y,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){const d=n.invertBatch(h.map(y=>y.pz));return h.map((y,m)=>y.toAffine(d[m])).map(u.fromAffine)}static fromHex(h){const d=u.fromAffine(i(Z("pointHex",h)));return d.assertValidity(),d}static fromPrivateKey(h){return u.BASE.multiply(a(h))}_setWindowSize(h){this._WINDOW_SIZE=h,l.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:h,y:d}=this.toAffine();if(!n.isValid(h)||!n.isValid(d))throw new Error("bad point: x or y not FE");const y=n.sqr(d),m=s(h);if(!n.eql(y,m))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:h}=this.toAffine();if(n.isOdd)return!n.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);const{px:d,py:y,pz:m}=this,{px:A,py:I,pz:B}=h,E=n.eql(n.mul(d,B),n.mul(A,m)),x=n.eql(n.mul(y,B),n.mul(I,m));return E&&x}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:h,b:d}=t,y=n.mul(d,Hn),{px:m,py:A,pz:I}=this;let B=n.ZERO,E=n.ZERO,x=n.ZERO,S=n.mul(m,m),P=n.mul(A,A),_=n.mul(I,I),K=n.mul(m,A);return K=n.add(K,K),x=n.mul(m,I),x=n.add(x,x),B=n.mul(h,x),E=n.mul(y,_),E=n.add(B,E),B=n.sub(P,E),E=n.add(P,E),E=n.mul(B,E),B=n.mul(K,B),x=n.mul(y,x),_=n.mul(h,_),K=n.sub(S,_),K=n.mul(h,K),K=n.add(K,x),x=n.add(S,S),S=n.add(x,S),S=n.add(S,_),S=n.mul(S,K),E=n.add(E,S),_=n.mul(A,I),_=n.add(_,_),S=n.mul(_,K),B=n.sub(B,S),x=n.mul(_,P),x=n.add(x,x),x=n.add(x,x),new u(B,E,x)}add(h){f(h);const{px:d,py:y,pz:m}=this,{px:A,py:I,pz:B}=h;let E=n.ZERO,x=n.ZERO,S=n.ZERO;const P=t.a,_=n.mul(t.b,Hn);let K=n.mul(d,A),R=n.mul(y,I),M=n.mul(m,B),j=n.add(d,y),w=n.add(A,I);j=n.mul(j,w),w=n.add(K,R),j=n.sub(j,w),w=n.add(d,m);let v=n.add(A,B);return w=n.mul(w,v),v=n.add(K,M),w=n.sub(w,v),v=n.add(y,m),E=n.add(I,B),v=n.mul(v,E),E=n.add(R,M),v=n.sub(v,E),S=n.mul(P,w),E=n.mul(_,M),S=n.add(E,S),E=n.sub(R,S),S=n.add(R,S),x=n.mul(E,S),R=n.add(K,K),R=n.add(R,K),M=n.mul(P,M),w=n.mul(_,w),R=n.add(R,M),M=n.sub(K,M),M=n.mul(P,M),w=n.add(w,M),K=n.mul(R,w),x=n.add(x,K),K=n.mul(v,w),E=n.mul(j,E),E=n.sub(E,K),K=n.mul(j,R),S=n.mul(v,S),S=n.add(S,K),new u(E,x,S)}subtract(h){return this.add(h.negate())}is0(){return this.equals(u.ZERO)}wNAF(h){return b.wNAFCached(this,l,h,d=>{const y=n.invertBatch(d.map(m=>m.pz));return d.map((m,A)=>m.toAffine(y[A])).map(u.fromAffine)})}multiplyUnsafe(h){const d=u.ZERO;if(h===ue)return d;if(c(h),h===Q)return this;const{endo:y}=t;if(!y)return b.unsafeLadder(this,h);let{k1neg:m,k1:A,k2neg:I,k2:B}=y.splitScalar(h),E=d,x=d,S=this;for(;A>ue||B>ue;)A&Q&&(E=E.add(S)),B&Q&&(x=x.add(S)),S=S.double(),A>>=Q,B>>=Q;return m&&(E=E.negate()),I&&(x=x.negate()),x=new u(n.mul(x.px,y.beta),x.py,x.pz),E.add(x)}multiply(h){c(h);let d=h,y,m;const{endo:A}=t;if(A){const{k1neg:I,k1:B,k2neg:E,k2:x}=A.splitScalar(d);let{p:S,f:P}=this.wNAF(B),{p:_,f:K}=this.wNAF(x);S=b.constTimeNegate(I,S),_=b.constTimeNegate(E,_),_=new u(n.mul(_.px,A.beta),_.py,_.pz),y=S.add(_),m=P.add(K)}else{const{p:I,f:B}=this.wNAF(d);y=I,m=B}return u.normalizeZ([y,m])[0]}multiplyAndAddUnsafe(h,d,y){const m=u.BASE,A=(B,E)=>E===ue||E===Q||!B.equals(m)?B.multiplyUnsafe(E):B.multiply(E),I=A(this,d).add(A(h,y));return I.is0()?void 0:I}toAffine(h){const{px:d,py:y,pz:m}=this,A=this.is0();h==null&&(h=A?n.ONE:n.inv(m));const I=n.mul(d,h),B=n.mul(y,h),E=n.mul(m,h);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(E,n.ONE))throw new Error("invZ was invalid");return{x:I,y:B}}isTorsionFree(){const{h,isTorsionFree:d}=t;if(h===Q)return!0;if(d)return d(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h,clearCofactor:d}=t;return h===Q?this:d?d(u,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),r(u,this,h)}toHex(h=!0){return Oe(this.toRawBytes(h))}}u.BASE=new u(t.Gx,t.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const g=t.nBitLength,b=Xi(u,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:o}}function rs(e){const t=Pn(e);return Fe(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function is(e){const t=rs(e),{Fp:n,n:r}=t,i=n.BYTES+1,s=2*n.BYTES+1;function o(w){return ue<w&&w<n.ORDER}function c(w){return W(w,r)}function a(w){return Tt(w,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:g}=ns({...t,toBytes(w,v,N){const k=v.toAffine(),C=n.toBytes(k.x),L=_e;return N?L(Uint8Array.from([v.hasEvenY()?2:3]),C):L(Uint8Array.from([4]),C,n.toBytes(k.y))},fromBytes(w){const v=w.length,N=w[0],k=w.subarray(1);if(v===i&&(N===2||N===3)){const C=Y(k);if(!o(C))throw new Error("Point is not on curve");const L=u(C);let O=n.sqrt(L);const $=(O&Q)===Q;return(N&1)===1!==$&&(O=n.neg(O)),{x:C,y:O}}else if(v===s&&N===4){const C=n.fromBytes(k.subarray(0,n.BYTES)),L=n.fromBytes(k.subarray(n.BYTES,2*n.BYTES));return{x:C,y:L}}else throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`)}}),b=w=>Oe(Ee(w,t.nByteLength));function p(w){const v=r>>Q;return w>v}function h(w){return p(w)?c(-w):w}const d=(w,v,N)=>Y(w.slice(v,N));class y{constructor(v,N,k){this.r=v,this.s=N,this.recovery=k,this.assertValidity()}static fromCompact(v){const N=t.nByteLength;return v=Z("compactSignature",v,N*2),new y(d(v,0,N),d(v,N,2*N))}static fromDER(v){const{r:N,s:k}=Ue.toSig(Z("DER",v));return new y(N,k)}assertValidity(){if(!g(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!g(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(v){return new y(this.r,this.s,v)}recoverPublicKey(v){const{r:N,s:k,recovery:C}=this,L=x(Z("msgHash",v));if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");const O=C===2||C===3?N+t.n:N;if(O>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const $=C&1?"03":"02",ne=l.fromHex($+b(O)),Ce=a(O),Ve=c(-L*Ce),tt=c(k*Ce),Be=l.BASE.multiplyAndAddUnsafe(ne,Ve,tt);if(!Be)throw new Error("point at infinify");return Be.assertValidity(),Be}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Pe(this.toDERHex())}toDERHex(){return Ue.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Pe(this.toCompactHex())}toCompactHex(){return b(this.r)+b(this.s)}}const m={isValidPrivateKey(w){try{return f(w),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const w=On(t.n);return Ji(t.randomBytes(w),t.n)},precompute(w=8,v=l.BASE){return v._setWindowSize(w),v.multiply(BigInt(3)),v}};function A(w,v=!0){return l.fromPrivateKey(w).toRawBytes(v)}function I(w){const v=w instanceof Uint8Array,N=typeof w=="string",k=(v||N)&&w.length;return v?k===i||k===s:N?k===2*i||k===2*s:w instanceof l}function B(w,v,N=!0){if(I(w))throw new Error("first arg must be private key");if(!I(v))throw new Error("second arg must be public key");return l.fromHex(v).multiply(f(w)).toRawBytes(N)}const E=t.bits2int||function(w){const v=Y(w),N=w.length*8-t.nBitLength;return N>0?v>>BigInt(N):v},x=t.bits2int_modN||function(w){return c(E(w))},S=Ut(t.nBitLength);function P(w){if(typeof w!="bigint")throw new Error("bigint expected");if(!(ue<=w&&w<S))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Ee(w,t.nByteLength)}function _(w,v,N=K){if(["recovered","canonical"].some(Me=>Me in N))throw new Error("sign() legacy options not supported");const{hash:k,randomBytes:C}=t;let{lowS:L,prehash:O,extraEntropy:$}=N;L==null&&(L=!0),w=Z("msgHash",w),O&&(w=Z("prehashed msgHash",k(w)));const ne=x(w),Ce=f(v),Ve=[P(Ce),P(ne)];if($!=null){const Me=$===!0?C(n.BYTES):$;Ve.push(Z("extraEntropy",Me))}const tt=_e(...Ve),Be=ne;function Kn(Me){const We=E(Me);if(!g(We))return;const wi=a(We),Ze=l.BASE.multiply(We).toAffine(),re=c(Ze.x);if(re===ue)return;const Ge=c(wi*c(Be+re*Ce));if(Ge===ue)return;let bi=(Ze.x===re?0:2)|Number(Ze.y&Q),vi=Ge;return L&&p(Ge)&&(vi=h(Ge),bi^=1),new y(re,vi,bi)}return{seed:tt,k2sig:Kn}}const K={lowS:t.lowS,prehash:!1},R={lowS:t.lowS,prehash:!1};function M(w,v,N=K){const{seed:k,k2sig:C}=_(w,v,N),L=t;return Ln(L.hash.outputLen,L.nByteLength,L.hmac)(k,C)}l.BASE._setWindowSize(8);function j(w,v,N,k=R){var Ze;const C=w;if(v=Z("msgHash",v),N=Z("publicKey",N),"strict"in k)throw new Error("options.strict was renamed to lowS");const{lowS:L,prehash:O}=k;let $,ne;try{if(typeof C=="string"||C instanceof Uint8Array)try{$=y.fromDER(C)}catch(re){if(!(re instanceof Ue.Err))throw re;$=y.fromCompact(C)}else if(typeof C=="object"&&typeof C.r=="bigint"&&typeof C.s=="bigint"){const{r:re,s:Ge}=C;$=new y(re,Ge)}else throw new Error("PARSE");ne=l.fromHex(N)}catch(re){if(re.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(L&&$.hasHighS())return!1;O&&(v=t.hash(v));const{r:Ce,s:Ve}=$,tt=x(v),Be=a(Ve),Kn=c(tt*Be),Me=c(Ce*Be),We=(Ze=l.BASE.multiplyAndAddUnsafe(ne,Kn,Me))==null?void 0:Ze.toAffine();return We?c(We.x)===Ce:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:B,sign:M,verify:j,ProjectivePoint:l,Signature:y,utils:m}}let Dn=class extends Bn{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Ei(t);const r=Ct(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,s=new Uint8Array(i);s.set(r.length>i?t.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(t){return nt(this),this.iHash.update(t),this}digestInto(t){nt(this),ke(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:i,destroyed:s,blockLen:o,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=s,t.blockLen=o,t.outputLen=c,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const qn=(e,t,n)=>new Dn(e,t).update(n).digest();qn.create=(e,t)=>new Dn(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ss(e){return{hash:e,hmac:(t,...n)=>qn(e,t,Si(...n)),randomBytes:kn}}function os(e,t){const n=r=>is({...e,...ss(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const st=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ot=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),jn=BigInt(1),at=BigInt(2),zn=(e,t)=>(e+t/at)/t;function Vn(e){const t=st,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=X(f,n,t)*f%t,g=X(u,n,t)*f%t,b=X(g,at,t)*l%t,p=X(b,i,t)*b%t,h=X(p,s,t)*p%t,d=X(h,c,t)*h%t,y=X(d,a,t)*d%t,m=X(y,c,t)*h%t,A=X(m,n,t)*f%t,I=X(A,o,t)*p%t,B=X(I,r,t)*l%t,E=X(B,at,t);if(!Mt.eql(Mt.sqr(E),e))throw new Error("Cannot find square root");return E}const Mt=Fi(st,void 0,void 0,{sqrt:Vn}),Le=os({a:BigInt(0),b:BigInt(7),Fp:Mt,n:ot,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=ot,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-jn*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),c=zn(s*e,t),a=zn(-r*e,t);let l=W(e-c*n-a*i,t),f=W(-c*r-a*s,t);const u=l>o,g=f>o;if(u&&(l=t-l),g&&(f=t-f),l>o||f>o)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:u,k1:l,k2neg:g,k2:f}}}},Bt),ct=BigInt(0),Wn=e=>typeof e=="bigint"&&ct<e&&e<st,as=e=>typeof e=="bigint"&&ct<e&&e<ot,Zn={};function ut(e,...t){let n=Zn[e];if(n===void 0){const r=Bt(Uint8Array.from(e,i=>i.charCodeAt(0)));n=_e(r,r),Zn[e]=n}return Bt(_e(n,...t))}const Ot=e=>e.toRawBytes(!0).slice(1),Pt=e=>Ee(e,32),Ht=e=>W(e,st),Je=e=>W(e,ot),Dt=Le.ProjectivePoint,cs=(e,t,n)=>Dt.BASE.multiplyAndAddUnsafe(e,t,n);function qt(e){let t=Le.utils.normPrivateKeyToScalar(e),n=Dt.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Je(-t),bytes:Ot(n)}}function Gn(e){if(!Wn(e))throw new Error("bad x: need 0 < x < p");const t=Ht(e*e),n=Ht(t*e+BigInt(7));let r=Vn(n);r%at!==ct&&(r=Ht(-r));const i=new Dt(e,r,jn);return i.assertValidity(),i}function Fn(...e){return Je(Y(ut("BIP0340/challenge",...e)))}function us(e){return qt(e).bytes}function ls(e,t,n=kn(32)){const r=Z("message",e),{bytes:i,scalar:s}=qt(t),o=Z("auxRand",n,32),c=Pt(s^Y(ut("BIP0340/aux",o))),a=ut("BIP0340/nonce",c,i,r),l=Je(Y(a));if(l===ct)throw new Error("sign failed: k is zero");const{bytes:f,scalar:u}=qt(l),g=Fn(f,i,r),b=new Uint8Array(64);if(b.set(f,0),b.set(Pt(Je(u+g*s)),32),!Jn(b,r,i))throw new Error("sign: Invalid signature produced");return b}function Jn(e,t,n){const r=Z("signature",e,64),i=Z("message",t),s=Z("publicKey",n,32);try{const o=Gn(Y(s)),c=Y(r.subarray(0,32));if(!Wn(c))return!1;const a=Y(r.subarray(32,64));if(!as(a))return!1;const l=Fn(Pt(c),Ot(o),i),f=cs(o,a,Je(-l));return!(!f||!f.hasEvenY()||f.toAffine().x!==c)}catch{return!1}}const Ye={getPublicKey:us,sign:ls,verify:Jn,utils:{randomPrivateKey:Le.utils.randomPrivateKey,lift_x:Gn,pointToBytes:Ot,numberToBytesBE:Ee,bytesToNumberBE:Y,taggedHash:ut,mod:W}},jt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const zt=e=>e instanceof Uint8Array,Vt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),oe=(e,t)=>e<<32-t|e>>>t;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");const fs=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function T(e){if(!zt(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=fs[e[n]];return t}function F(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){const i=r*2,s=e.slice(i,i+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[r]=o}return n}function hs(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Xe(e){if(typeof e=="string"&&(e=hs(e)),!zt(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function lt(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!zt(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}class Yn{clone(){return this._cloneInto()}}function Xn(e){const t=r=>e().update(Xe(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Qn(e=32){if(jt&&typeof jt.getRandomValues=="function")return jt.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Wt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function ds(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function er(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function ps(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Wt(e.outputLen),Wt(e.blockLen)}function ys(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function gs(e,t){er(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const ae={number:Wt,bool:ds,bytes:er,hash:ps,exists:ys,output:gs};function ws(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),c=Number(n&s),a=r?4:0,l=r?0:4;e.setUint32(t+a,o,r),e.setUint32(t+l,c,r)}class bs extends Yn{constructor(t,n,r,i){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=Vt(this.buffer)}update(t){ae.exists(this);const{view:n,buffer:r,blockLen:i}=this;t=Xe(t);const s=t.length;for(let o=0;o<s;){const c=Math.min(i-this.pos,s-o);if(c===i){const a=Vt(t);for(;i<=s-o;o+=i)this.process(a,o);continue}r.set(t.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ae.exists(this),ae.output(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(r,0),o=0);for(let u=o;u<i;u++)n[u]=0;ws(r,i-8,BigInt(this.length*8),s),this.process(r,0);const c=Vt(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)c.setUint32(4*u,f[u],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:c}=this;return t.length=i,t.pos=c,t.finished=s,t.destroyed=o,i%n&&t.buffer.set(r),t}}const vs=(e,t,n)=>e&t^~e&n,Es=(e,t,n)=>e&t^e&n^t&n,ms=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),me=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),xe=new Uint32Array(64);class tr extends bs{constructor(){super(64,32,8,!1),this.A=me[0]|0,this.B=me[1]|0,this.C=me[2]|0,this.D=me[3]|0,this.E=me[4]|0,this.F=me[5]|0,this.G=me[6]|0,this.H=me[7]|0}get(){const{A:t,B:n,C:r,D:i,E:s,F:o,G:c,H:a}=this;return[t,n,r,i,s,o,c,a]}set(t,n,r,i,s,o,c,a){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(t,n){for(let u=0;u<16;u++,n+=4)xe[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const g=xe[u-15],b=xe[u-2],p=oe(g,7)^oe(g,18)^g>>>3,h=oe(b,17)^oe(b,19)^b>>>10;xe[u]=h+xe[u-7]+p+xe[u-16]|0}let{A:r,B:i,C:s,D:o,E:c,F:a,G:l,H:f}=this;for(let u=0;u<64;u++){const g=oe(c,6)^oe(c,11)^oe(c,25),b=f+g+vs(c,a,l)+ms[u]+xe[u]|0,h=(oe(r,2)^oe(r,13)^oe(r,22))+Es(r,i,s)|0;f=l,l=a,a=c,c=o+b|0,o=s,s=i,i=r,r=b+h|0}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)}roundClean(){xe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class xs extends tr{constructor(){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}}const le=Xn(()=>new tr);Xn(()=>new xs);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function He(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function fe(...e){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);return{encode:n,decode:r}}function he(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return t.map(n=>{if(He(n),n<0||n>=e.length)throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${e.length})`);return e[n]})},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("alphabet.decode input should be array of strings");return t.map(n=>{if(typeof n!="string")throw new Error(`alphabet.decode: not string element=${n}`);const r=e.indexOf(n);if(r===-1)throw new Error(`Unknown letter: "${n}". Allowed: ${e}`);return r})}}}function de(e=""){if(typeof e!="string")throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("join.encode input should be array of strings");for(let n of t)if(typeof n!="string")throw new Error(`join.encode: non-string input=${n}`);return t.join(e)},decode:t=>{if(typeof t!="string")throw new Error("join.decode input should be string");return t.split(e)}}}function ft(e,t="="){if(He(e),typeof t!="string")throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let r of n)if(typeof r!="string")throw new Error(`padding.encode: non-string input=${r}`);for(;n.length*e%8;)n.push(t);return n},decode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let i of n)if(typeof i!="string")throw new Error(`padding.decode: non-string input=${i}`);let r=n.length;if(r*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--)if(!((r-1)*e%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function nr(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function rr(e,t,n){if(t<2)throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let r=0;const i=[],s=Array.from(e);for(s.forEach(o=>{if(He(o),o<0||o>=t)throw new Error(`Wrong integer: ${o}`)});;){let o=0,c=!0;for(let a=r;a<s.length;a++){const l=s[a],f=t*o+l;if(!Number.isSafeInteger(f)||t*o/t!==o||f-l!==t*o)throw new Error("convertRadix: carry overflow");if(o=f%n,s[a]=Math.floor(f/n),!Number.isSafeInteger(s[a])||s[a]*n+o!==f)throw new Error("convertRadix: carry overflow");if(c)s[a]?c=!1:r=a;else continue}if(i.push(o),c)break}for(let o=0;o<e.length-1&&e[o]===0;o++)i.push(0);return i.reverse()}const ir=(e,t)=>t?ir(t,e%t):e,ht=(e,t)=>e+(t-ir(e,t));function Zt(e,t,n,r){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(ht(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${ht(t,n)}`);let i=0,s=0;const o=2**n-1,c=[];for(const a of e){if(He(a),a>=2**t)throw new Error(`convertRadix2: invalid data word=${a} from=${t}`);if(i=i<<t|a,s+t>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);for(s+=t;s>=n;s-=n)c.push((i>>s-n&o)>>>0);i&=2**s-1}if(i=i<<n-s&o,!r&&s>=t)throw new Error("Excess padding");if(!r&&i)throw new Error(`Non-zero padding: ${i}`);return r&&s>0&&c.push(i>>>0),c}function Ss(e){return He(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return rr(Array.from(t),2**8,e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(rr(t,e,2**8))}}}function Se(e,t=!1){if(He(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(ht(8,e)>32||ht(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!(n instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return Zt(Array.from(n),8,e,!t)},decode:n=>{if(!Array.isArray(n)||n.length&&typeof n[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(Zt(n,e,8,t))}}}function sr(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}const Ns=fe(Se(4),he("0123456789ABCDEF"),de("")),As=fe(Se(5),he("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),ft(5),de(""));fe(Se(5),he("0123456789ABCDEFGHIJKLMNOPQRSTUV"),ft(5),de("")),fe(Se(5),he("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),de(""),nr(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const pe=fe(Se(6),he("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),ft(6),de("")),Ks=fe(Se(6),he("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),ft(6),de("")),Gt=e=>fe(Ss(58),he(e),de("")),Ft=Gt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");Gt("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Gt("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const or=[0,2,3,5,6,7,9,10,11],Cs={encode(e){let t="";for(let n=0;n<e.length;n+=8){const r=e.subarray(n,n+8);t+=Ft.encode(r).padStart(or[r.length],"1")}return t},decode(e){let t=[];for(let n=0;n<e.length;n+=11){const r=e.slice(n,n+11),i=or.indexOf(r.length),s=Ft.decode(r);for(let o=0;o<s.length-i;o++)if(s[o]!==0)throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(s.slice(s.length-i)))}return Uint8Array.from(t)}},Jt=fe(he("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),de("")),ar=[996825010,642813549,513874426,1027748829,705979059];function Qe(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r<ar.length;r++)(t>>r&1)===1&&(n^=ar[r]);return n}function cr(e,t,n=1){const r=e.length;let i=1;for(let s=0;s<r;s++){const o=e.charCodeAt(s);if(o<33||o>126)throw new Error(`Invalid prefix (${e})`);i=Qe(i)^o>>5}i=Qe(i);for(let s=0;s<r;s++)i=Qe(i)^e.charCodeAt(s)&31;for(let s of t)i=Qe(i)^s;for(let s=0;s<6;s++)i=Qe(i);return i^=n,Jt.encode(Zt([i%2**30],30,5,!1))}function ur(e){const t=e==="bech32"?1:734539939,n=Se(5),r=n.decode,i=n.encode,s=sr(r);function o(f,u,g=90){if(typeof f!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);if(!Array.isArray(u)||u.length&&typeof u[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);const b=f.length+7+u.length;if(g!==!1&&b>g)throw new TypeError(`Length ${b} exceeds limit ${g}`);return f=f.toLowerCase(),`${f}1${Jt.encode(u)}${cr(f,u,t)}`}function c(f,u=90){if(typeof f!="string")throw new Error(`bech32.decode input should be string, not ${typeof f}`);if(f.length<8||u!==!1&&f.length>u)throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${u})`);const g=f.toLowerCase();if(f!==g&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");f=g;const b=f.lastIndexOf("1");if(b===0||b===-1)throw new Error('Letter "1" must be present between prefix and data only');const p=f.slice(0,b),h=f.slice(b+1);if(h.length<6)throw new Error("Data must be at least 6 characters long");const d=Jt.decode(h).slice(0,-6),y=cr(p,d,t);if(!h.endsWith(y))throw new Error(`Invalid checksum in ${f}: expected "${y}"`);return{prefix:p,words:d}}const a=sr(c);function l(f){const{prefix:u,words:g}=c(f,!1);return{prefix:u,words:g,bytes:r(g)}}return{encode:o,decode:c,decodeToBytes:l,decodeUnsafe:a,fromWords:r,fromWordsUnsafe:s,toWords:i}}const De=ur("bech32");ur("bech32m");const Bs={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},ks=fe(Se(4),he("0123456789abcdef"),de(""),nr(e=>{if(typeof e!="string"||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));`${Object.keys({utf8:Bs,hex:ks,base16:Ns,base32:As,base64:pe,base64url:Ks,base58:Ft,base58xmr:Cs}).join(", ")}`;function Yt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function lr(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function _s(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function ye(e,...t){if(!_s(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */const G=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4));if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function Is(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function Us(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}const Ls=(e,t)=>(Object.assign(t,e),t),Ne=16,$s=283;function Xt(e){return e<<1^$s&-(e>>7)}function qe(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(t&1),e=Xt(e);return n}const Qt=(()=>{let e=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=Xt(r))e[n]=r;const t=new Uint8Array(256);t[0]=99;for(let n=0;n<255;n++){let r=e[255-n];r|=r<<8,t[e[n]]=(r^r>>4^r>>5^r>>6^r>>7^99)&255}return t})(),Ts=Qt.map((e,t)=>Qt.indexOf(t)),Rs=e=>e<<24|e>>>8,en=e=>e<<8|e>>>24;function fr(e,t){if(e.length!==256)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((l,f)=>t(e[f])),r=n.map(en),i=r.map(en),s=i.map(en),o=new Uint32Array(256*256),c=new Uint32Array(256*256),a=new Uint16Array(256*256);for(let l=0;l<256;l++)for(let f=0;f<256;f++){const u=l*256+f;o[u]=n[l]^r[f],c[u]=i[l]^s[f],a[u]=e[l]<<8|e[f]}return{sbox:e,sbox2:a,T0:n,T1:r,T2:i,T3:s,T01:o,T23:c}}const tn=fr(Qt,e=>qe(e,3)<<24|e<<16|e<<8|qe(e,2)),hr=fr(Ts,e=>qe(e,11)<<24|qe(e,13)<<16|qe(e,9)<<8|qe(e,14)),Ms=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=Xt(n))e[t]=n;return e})();function dr(e){ye(e);const t=e.length;if(![16,24,32].includes(t))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);const{sbox2:n}=tn,r=G(e),i=r.length,s=c=>ce(n,c,c,c,c),o=new Uint32Array(t+28);o.set(r);for(let c=i;c<o.length;c++){let a=o[c-1];c%i===0?a=s(Rs(a))^Ms[c/i-1]:i>6&&c%i===4&&(a=s(a)),o[c]=o[c-i]^a}return o}function Os(e){const t=dr(e),n=t.slice(),r=t.length,{sbox2:i}=tn,{T0:s,T1:o,T2:c,T3:a}=hr;for(let l=0;l<r;l+=4)for(let f=0;f<4;f++)n[l+f]=t[r-l-4+f];t.fill(0);for(let l=4;l<r-4;l++){const f=n[l],u=ce(i,f,f,f,f);n[l]=s[u&255]^o[u>>>8&255]^c[u>>>16&255]^a[u>>>24]}return n}function Ae(e,t,n,r,i,s){return e[n<<8&65280|r>>>8&255]^t[i>>>8&65280|s>>>24&255]}function ce(e,t,n,r,i){return e[t&255|n&65280]|e[r>>>16&255|i>>>16&65280]<<16}function pr(e,t,n,r,i){const{sbox2:s,T01:o,T23:c}=tn;let a=0;t^=e[a++],n^=e[a++],r^=e[a++],i^=e[a++];const l=e.length/4-2;for(let p=0;p<l;p++){const h=e[a++]^Ae(o,c,t,n,r,i),d=e[a++]^Ae(o,c,n,r,i,t),y=e[a++]^Ae(o,c,r,i,t,n),m=e[a++]^Ae(o,c,i,t,n,r);t=h,n=d,r=y,i=m}const f=e[a++]^ce(s,t,n,r,i),u=e[a++]^ce(s,n,r,i,t),g=e[a++]^ce(s,r,i,t,n),b=e[a++]^ce(s,i,t,n,r);return{s0:f,s1:u,s2:g,s3:b}}function Ps(e,t,n,r,i){const{sbox2:s,T01:o,T23:c}=hr;let a=0;t^=e[a++],n^=e[a++],r^=e[a++],i^=e[a++];const l=e.length/4-2;for(let p=0;p<l;p++){const h=e[a++]^Ae(o,c,t,i,r,n),d=e[a++]^Ae(o,c,n,t,i,r),y=e[a++]^Ae(o,c,r,n,t,i),m=e[a++]^Ae(o,c,i,r,n,t);t=h,n=d,r=y,i=m}const f=e[a++]^ce(s,t,i,r,n),u=e[a++]^ce(s,n,t,i,r),g=e[a++]^ce(s,r,n,t,i),b=e[a++]^ce(s,i,r,n,t);return{s0:f,s1:u,s2:g,s3:b}}function yr(e,t){if(!t)return new Uint8Array(e);if(ye(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}function Hs(e){if(ye(e),e.length%Ne!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Ne}`)}function Ds(e,t,n){let r=e.length;const i=r%Ne;if(!t&&i!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const s=G(e);if(t){let a=Ne-i;a||(a=Ne),r=r+a}const o=yr(r,n),c=G(o);return{b:s,o:c,out:o}}function qs(e,t){if(!t)return e;const n=e.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=e[n-1];if(r<=0||r>16)throw new Error(`aes/pcks5: wrong padding byte: ${r}`);const i=e.subarray(0,-r);for(let s=0;s<r;s++)if(e[n-s-1]!==r)throw new Error("aes/pcks5: wrong padding");return i}function js(e){const t=new Uint8Array(16),n=G(t);t.set(e);const r=Ne-e.length;for(let i=Ne-r;i<Ne;i++)t[i]=r;return n}const gr=Ls({blockSize:16,nonceLength:16},function(t,n,r={}){ye(t),ye(n,16);const i=!r.disablePadding;return{encrypt:(s,o)=>{const c=dr(t),{b:a,o:l,out:f}=Ds(s,i,o),u=G(n);let g=u[0],b=u[1],p=u[2],h=u[3],d=0;for(;d+4<=a.length;)g^=a[d+0],b^=a[d+1],p^=a[d+2],h^=a[d+3],{s0:g,s1:b,s2:p,s3:h}=pr(c,g,b,p,h),l[d++]=g,l[d++]=b,l[d++]=p,l[d++]=h;if(i){const y=js(s.subarray(d*4));g^=y[0],b^=y[1],p^=y[2],h^=y[3],{s0:g,s1:b,s2:p,s3:h}=pr(c,g,b,p,h),l[d++]=g,l[d++]=b,l[d++]=p,l[d++]=h}return c.fill(0),f},decrypt:(s,o)=>{Hs(s);const c=Os(t),a=G(n),l=yr(s.length,o),f=G(s),u=G(l);let g=a[0],b=a[1],p=a[2],h=a[3];for(let d=0;d+4<=f.length;){const y=g,m=b,A=p,I=h;g=f[d+0],b=f[d+1],p=f[d+2],h=f[d+3];const{s0:B,s1:E,s2:x,s3:S}=Ps(c,g,b,p,h);u[d++]=B^y,u[d++]=E^m,u[d++]=x^A,u[d++]=S^I}return c.fill(0),qs(l,i)}}}),wr=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),zs=wr("expand 16-byte k"),Vs=wr("expand 32-byte k"),Ws=G(zs),br=G(Vs);br.slice();function U(e,t){return e<<t|e>>>32-t}function nn(e){return e.byteOffset%4===0}const dt=64,Zs=16,vr=2**32-1,Er=new Uint32Array;function Gs(e,t,n,r,i,s,o,c){const a=i.length,l=new Uint8Array(dt),f=G(l),u=nn(i)&&nn(s),g=u?G(i):Er,b=u?G(s):Er;for(let p=0;p<a;o++){if(e(t,n,r,f,o,c),o>=vr)throw new Error("arx: counter overflow");const h=Math.min(dt,a-p);if(u&&h===dt){const d=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let y=0,m;y<Zs;y++)m=d+y,b[m]=g[m]^f[y];p+=dt;continue}for(let d=0,y;d<h;d++)y=p+d,s[y]=i[y]^l[d];p+=h}}function Fs(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:s,rounds:o}=Is({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return Yt(i),Yt(o),lr(s),lr(n),(c,a,l,f,u=0)=>{ye(c),ye(a),ye(l);const g=l.length;if(f||(f=new Uint8Array(g)),ye(f),Yt(u),u<0||u>=vr)throw new Error("arx: counter overflow");if(f.length<g)throw new Error(`arx: output (${f.length}) is shorter than data (${g})`);const b=[];let p=c.length,h,d;if(p===32)h=c.slice(),b.push(h),d=br;else if(p===16&&n)h=new Uint8Array(32),h.set(c),h.set(c,16),d=Ws,b.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);nn(a)||(a=a.slice(),b.push(a));const y=G(h);if(r){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(d,y,G(a.subarray(0,16)),y),a=a.subarray(16)}const m=16-i;if(m!==a.length)throw new Error(`arx: nonce must be ${m} or 16 bytes`);if(m!==12){const I=new Uint8Array(12);I.set(a,s?0:12-a.length),a=I,b.push(a)}const A=G(a);for(Gs(e,d,y,A,l,f,u,o);b.length>0;)b.pop().fill(0);return f}}function Js(e,t,n,r,i,s=20){let o=e[0],c=e[1],a=e[2],l=e[3],f=t[0],u=t[1],g=t[2],b=t[3],p=t[4],h=t[5],d=t[6],y=t[7],m=i,A=n[0],I=n[1],B=n[2],E=o,x=c,S=a,P=l,_=f,K=u,R=g,M=b,j=p,w=h,v=d,N=y,k=m,C=A,L=I,O=B;for(let ne=0;ne<s;ne+=2)E=E+_|0,k=U(k^E,16),j=j+k|0,_=U(_^j,12),E=E+_|0,k=U(k^E,8),j=j+k|0,_=U(_^j,7),x=x+K|0,C=U(C^x,16),w=w+C|0,K=U(K^w,12),x=x+K|0,C=U(C^x,8),w=w+C|0,K=U(K^w,7),S=S+R|0,L=U(L^S,16),v=v+L|0,R=U(R^v,12),S=S+R|0,L=U(L^S,8),v=v+L|0,R=U(R^v,7),P=P+M|0,O=U(O^P,16),N=N+O|0,M=U(M^N,12),P=P+M|0,O=U(O^P,8),N=N+O|0,M=U(M^N,7),E=E+K|0,O=U(O^E,16),v=v+O|0,K=U(K^v,12),E=E+K|0,O=U(O^E,8),v=v+O|0,K=U(K^v,7),x=x+R|0,k=U(k^x,16),N=N+k|0,R=U(R^N,12),x=x+R|0,k=U(k^x,8),N=N+k|0,R=U(R^N,7),S=S+M|0,C=U(C^S,16),j=j+C|0,M=U(M^j,12),S=S+M|0,C=U(C^S,8),j=j+C|0,M=U(M^j,7),P=P+_|0,L=U(L^P,16),w=w+L|0,_=U(_^w,12),P=P+_|0,L=U(L^P,8),w=w+L|0,_=U(_^w,7);let $=0;r[$++]=o+E|0,r[$++]=c+x|0,r[$++]=a+S|0,r[$++]=l+P|0,r[$++]=f+_|0,r[$++]=u+K|0,r[$++]=g+R|0,r[$++]=b+M|0,r[$++]=p+j|0,r[$++]=h+w|0,r[$++]=d+v|0,r[$++]=y+N|0,r[$++]=m+k|0,r[$++]=A+C|0,r[$++]=I+L|0,r[$++]=B+O|0}const mr=Fs(Js,{counterRight:!1,counterLength:4,allowShortKeys:!1});class xr extends Yn{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,ae.hash(t);const r=Xe(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,s=new Uint8Array(i);s.set(r.length>i?t.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(t){return ae.exists(this),this.iHash.update(t),this}digestInto(t){ae.exists(this),ae.bytes(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:i,destroyed:s,blockLen:o,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=s,t.blockLen=o,t.outputLen=c,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const pt=(e,t,n)=>new xr(e,t).update(n).digest();pt.create=(e,t)=>new xr(e,t);function rn(e,t,n){return ae.hash(e),n===void 0&&(n=new Uint8Array(e.outputLen)),pt(e,Xe(n),Xe(t))}const sn=new Uint8Array([0]),Sr=new Uint8Array;function Nr(e,t,n,r=32){if(ae.hash(e),ae.number(r),r>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const i=Math.ceil(r/e.outputLen);n===void 0&&(n=Sr);const s=new Uint8Array(i*e.outputLen),o=pt.create(e,t),c=o._cloneInto(),a=new Uint8Array(o.outputLen);for(let l=0;l<i;l++)sn[0]=l+1,c.update(l===0?Sr:a).update(n).update(sn).digestInto(a),s.set(a,e.outputLen*l),o._cloneInto(c);return o.destroy(),c.destroy(),a.fill(0),sn.fill(0),s.slice(0,r)}var Ys=Object.defineProperty,D=(e,t)=>{for(var n in t)Ys(e,n,{get:t[n],enumerable:!0})},je=Symbol("verified"),Xs=e=>e instanceof Object;function yt(e){if(!Xs(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))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}var Qs={};D(Qs,{Queue:()=>ro,QueueNode:()=>Ar,binarySearch:()=>on,insertEventIntoAscendingList:()=>no,insertEventIntoDescendingList:()=>to,normalizeURL:()=>eo,utf8Decoder:()=>ge,utf8Encoder:()=>te});var ge=new TextDecoder("utf-8"),te=new TextEncoder;function eo(e){e.indexOf("://")===-1&&(e="wss://"+e);let t=new URL(e);return t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),(t.port==="80"&&t.protocol==="ws:"||t.port==="443"&&t.protocol==="wss:")&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}function to(e,t){const[n,r]=on(e,i=>t.id===i.id?0:t.created_at===i.created_at?-1:i.created_at-t.created_at);return r||e.splice(n,0,t),e}function no(e,t){const[n,r]=on(e,i=>t.id===i.id?0:t.created_at===i.created_at?-1:t.created_at-i.created_at);return r||e.splice(n,0,t),e}function on(e,t){let n=0,r=e.length-1;for(;n<=r;){const i=Math.floor((n+r)/2),s=t(e[i]);if(s===0)return[i,!0];s<0?r=i-1:n=i+1}return[n,!1]}var Ar=class{constructor(e){ie(this,"value");ie(this,"next",null);ie(this,"prev",null);this.value=e}},ro=class{constructor(){ie(this,"first");ie(this,"last");this.first=null,this.last=null}enqueue(e){const t=new Ar(e);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}dequeue(){if(!this.first)return null;if(this.first===this.last){const t=this.first;return this.first=null,this.last=null,t.value}const e=this.first;return this.first=e.next,e.value}},io=class{generateSecretKey(){return Ye.utils.randomPrivateKey()}getPublicKey(e){return T(Ye.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=T(Ye.getPublicKey(t)),n.id=ze(n),n.sig=T(Ye.sign(ze(n),t)),n[je]=!0,n}verifyEvent(e){if(typeof e[je]=="boolean")return e[je];const t=ze(e);if(t!==e.id)return e[je]=!1,!1;try{const n=Ye.verify(e.sig,t,e.pubkey);return e[je]=n,n}catch{return e[je]=!1,!1}}};function so(e){if(!yt(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function ze(e){let t=le(te.encode(so(e)));return T(t)}var gt=new io,$e=gt.generateSecretKey,we=gt.getPublicKey,ee=gt.finalizeEvent,wt=gt.verifyEvent,oo={};D(oo,{Application:()=>ua,BadgeAward:()=>go,BadgeDefinition:()=>na,BlockedRelaysList:()=>Ho,BookmarkList:()=>Mo,Bookmarksets:()=>Qo,Calendar:()=>ga,CalendarEventRSVP:()=>wa,ChannelCreation:()=>Ir,ChannelHideMessage:()=>$r,ChannelMessage:()=>Lr,ChannelMetadata:()=>Ur,ChannelMuteUser:()=>Tr,ClassifiedListing:()=>ha,ClientAuth:()=>Mr,CommunitiesList:()=>Oo,CommunityDefinition:()=>Ea,CommunityPostApproval:()=>Ko,Contacts:()=>ho,CreateOrUpdateProduct:()=>sa,CreateOrUpdateStall:()=>ia,Curationsets:()=>ea,Date:()=>pa,DirectMessageRelaysList:()=>zo,DraftClassifiedListing:()=>da,DraftLong:()=>aa,Emojisets:()=>ca,EncryptedDirectMessage:()=>po,EventDeletion:()=>yo,FileMetadata:()=>Eo,FileServerPreference:()=>Vo,Followsets:()=>Jo,GenericRepost:()=>bo,Genericlists:()=>Yo,GiftWrap:()=>Rr,HTTPAuth:()=>un,Handlerinformation:()=>va,Handlerrecommendation:()=>ba,Highlights:()=>Lo,InterestsList:()=>qo,Interestsets:()=>ra,JobFeedback:()=>ko,JobRequest:()=>Co,JobResult:()=>Bo,Label:()=>Ao,LightningPubRPC:()=>Zo,LiveChatMessage:()=>mo,LiveEvent:()=>la,LongFormArticle:()=>oa,Metadata:()=>uo,Mutelist:()=>$o,NWCWalletInfo:()=>Wo,NWCWalletRequest:()=>Or,NWCWalletResponse:()=>Go,NostrConnect:()=>Fo,OpenTimestamps:()=>vo,Pinlist:()=>To,PrivateDirectMessage:()=>wo,ProblemTracker:()=>xo,ProfileBadges:()=>ta,PublicChatsList:()=>Po,Reaction:()=>cn,RecommendRelay:()=>fo,RelayList:()=>Ro,Relaysets:()=>Xo,Report:()=>So,Reporting:()=>No,Repost:()=>an,Seal:()=>_r,SearchRelaysList:()=>Do,ShortTextNote:()=>lo,Time:()=>ya,UserEmojiList:()=>jo,UserStatuses:()=>fa,Zap:()=>Uo,ZapGoal:()=>_o,ZapRequest:()=>Io,classifyKind:()=>ao,isEphemeralKind:()=>Br,isKind:()=>co,isParameterizedReplaceableKind:()=>kr,isRegularKind:()=>Kr,isReplaceableKind:()=>Cr});function Kr(e){return 1e3<=e&&e<1e4||[1,2,4,5,6,7,8,16,40,41,42,43,44].includes(e)}function Cr(e){return[0,3].includes(e)||1e4<=e&&e<2e4}function Br(e){return 2e4<=e&&e<3e4}function kr(e){return 3e4<=e&&e<4e4}function ao(e){return Kr(e)?"regular":Cr(e)?"replaceable":Br(e)?"ephemeral":kr(e)?"parameterized":"unknown"}function co(e,t){const n=t instanceof Array?t:[t];return yt(e)&&n.includes(e.kind)||!1}var uo=0,lo=1,fo=2,ho=3,po=4,yo=5,an=6,cn=7,go=8,_r=13,wo=14,bo=16,Ir=40,Ur=41,Lr=42,$r=43,Tr=44,vo=1040,Rr=1059,Eo=1063,mo=1311,xo=1971,So=1984,No=1984,Ao=1985,Ko=4550,Co=5999,Bo=6999,ko=7e3,_o=9041,Io=9734,Uo=9735,Lo=9802,$o=1e4,To=10001,Ro=10002,Mo=10003,Oo=10004,Po=10005,Ho=10006,Do=10007,qo=10015,jo=10030,zo=10050,Vo=10096,Wo=13194,Zo=21e3,Mr=22242,Or=23194,Go=23195,Fo=24133,un=27235,Jo=3e4,Yo=30001,Xo=30002,Qo=30003,ea=30004,ta=30008,na=30009,ra=30015,ia=30017,sa=30018,oa=30023,aa=30024,ca=30030,ua=30078,la=30311,fa=30315,ha=30402,da=30403,pa=31922,ya=31923,ga=31924,wa=31925,ba=31989,va=31990,Ea=34550,ma={};D(ma,{getHex64:()=>ln,getInt:()=>Pr,getSubscriptionId:()=>xa,matchEventId:()=>Sa,matchEventKind:()=>Aa,matchEventPubkey:()=>Na});function ln(e,t){let n=t.length+3,r=e.indexOf(`"${t}":`)+n,i=e.slice(r).indexOf('"')+r+1;return e.slice(i,i+64)}function Pr(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,i=e.slice(r),s=Math.min(i.indexOf(","),i.indexOf("}"));return parseInt(i.slice(0,s),10)}function xa(e){let t=e.slice(0,22).indexOf('"EVENT"');if(t===-1)return null;let n=e.slice(t+7+1).indexOf('"');if(n===-1)return null;let r=t+7+1+n,i=e.slice(r+1,80).indexOf('"');if(i===-1)return null;let s=r+1+i;return e.slice(r+1,s)}function Sa(e,t){return t===ln(e,"id")}function Na(e,t){return t===ln(e,"pubkey")}function Aa(e,t){return t===Pr(e,"kind")}var Ka={};D(Ka,{makeAuthEvent:()=>Ca});function Ca(e,t){return{kind:Mr,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}var Ba;try{Ba=WebSocket}catch{}var ka;try{ka=WebSocket}catch{}var _a={};D(_a,{BECH32_REGEX:()=>Hr,Bech32MaxSize:()=>fn,NostrTypeGuard:()=>Ia,decode:()=>bt,encodeBytes:()=>Et,naddrEncode:()=>Oa,neventEncode:()=>Ma,noteEncode:()=>Ta,nprofileEncode:()=>Ra,npubEncode:()=>$a,nsecEncode:()=>La});var Ia={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},fn=5e3,Hr=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function Ua(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=e&255,t}function bt(e){var i,s,o,c,a,l,f;let{prefix:t,words:n}=De.decode(e,fn),r=new Uint8Array(De.fromWords(n));switch(t){case"nprofile":{let u=hn(r);if(!((i=u[0])!=null&&i[0]))throw new Error("missing TLV 0 for nprofile");if(u[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:T(u[0][0]),relays:u[1]?u[1].map(g=>ge.decode(g)):[]}}}case"nevent":{let u=hn(r);if(!((s=u[0])!=null&&s[0]))throw new Error("missing TLV 0 for nevent");if(u[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(u[2]&&u[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(u[3]&&u[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:T(u[0][0]),relays:u[1]?u[1].map(g=>ge.decode(g)):[],author:(o=u[2])!=null&&o[0]?T(u[2][0]):void 0,kind:(c=u[3])!=null&&c[0]?parseInt(T(u[3][0]),16):void 0}}}case"naddr":{let u=hn(r);if(!((a=u[0])!=null&&a[0]))throw new Error("missing TLV 0 for naddr");if(!((l=u[2])!=null&&l[0]))throw new Error("missing TLV 2 for naddr");if(u[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((f=u[3])!=null&&f[0]))throw new Error("missing TLV 3 for naddr");if(u[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:ge.decode(u[0][0]),pubkey:T(u[2][0]),kind:parseInt(T(u[3][0]),16),relays:u[1]?u[1].map(g=>ge.decode(g)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:T(r)};default:throw new Error(`unknown prefix ${t}`)}}function hn(e){let t={},n=e;for(;n.length>0;){let r=n[0],i=n[1],s=n.slice(2,2+i);if(n=n.slice(2+i),s.length<i)throw new Error(`not enough data to read on TLV ${r}`);t[r]=t[r]||[],t[r].push(s)}return t}function La(e){return Et("nsec",e)}function $a(e){return Et("npub",F(e))}function Ta(e){return Et("note",F(e))}function vt(e,t){let n=De.toWords(t);return De.encode(e,n,fn)}function Et(e,t){return vt(e,t)}function Ra(e){let t=dn({0:[F(e.pubkey)],1:(e.relays||[]).map(n=>te.encode(n))});return vt("nprofile",t)}function Ma(e){let t;e.kind!==void 0&&(t=Ua(e.kind));let n=dn({0:[F(e.id)],1:(e.relays||[]).map(r=>te.encode(r)),2:e.author?[F(e.author)]:[],3:t?[new Uint8Array(t)]:[]});return vt("nevent",n)}function Oa(e){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,e.kind,!1);let n=dn({0:[te.encode(e.identifier)],1:(e.relays||[]).map(r=>te.encode(r)),2:[F(e.pubkey)],3:[new Uint8Array(t)]});return vt("naddr",n)}function dn(e){let t=[];return Object.entries(e).reverse().forEach(([n,r])=>{r.forEach(i=>{let s=new Uint8Array(i.length+2);s.set([parseInt(n)],0),s.set([i.length],1),s.set(i,2),t.push(s)})}),lt(...t)}var Pa={};D(Pa,{decrypt:()=>Ha,encrypt:()=>Dr});async function Dr(e,t,n){const r=e instanceof Uint8Array?T(e):e,i=Le.getSharedSecret(r,"02"+t),s=qr(i);let o=Uint8Array.from(Qn(16)),c=te.encode(n),a=gr(s,o).encrypt(c),l=pe.encode(new Uint8Array(a)),f=pe.encode(new Uint8Array(o.buffer));return`${l}?iv=${f}`}async function Ha(e,t,n){const r=e instanceof Uint8Array?T(e):e;let[i,s]=n.split("?iv="),o=Le.getSharedSecret(r,"02"+t),c=qr(o),a=pe.decode(s),l=pe.decode(i),f=gr(c,a).decrypt(l);return ge.decode(f)}function qr(e){return e.slice(1,33)}var Da={};D(Da,{NIP05_REGEX:()=>pn,isNip05:()=>qa,isValid:()=>Va,queryProfile:()=>jr,searchDomain:()=>za,useFetchImplementation:()=>ja});var pn=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,qa=e=>pn.test(e||""),mt;try{mt=fetch}catch{}function ja(e){mt=e}async function za(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await mt(n,{redirect:"manual"});if(r.status!==200)throw Error("Wrong response code");return(await r.json()).names}catch{return{}}}async function jr(e){var i;const t=e.match(pn);if(!t)return null;const[,n="_",r]=t;try{const s=`https://${r}/.well-known/nostr.json?name=${n}`,o=await mt(s,{redirect:"manual"});if(o.status!==200)throw Error("Wrong response code");const c=await o.json(),a=c.names[n];return a?{pubkey:a,relays:(i=c.relays)==null?void 0:i[a]}:null}catch{return null}}async function Va(e,t){const n=await jr(t);return n?n.pubkey===e:!1}var Wa={};D(Wa,{parse:()=>Za});function Za(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let i=e.tags.length-1;i>=0;i--){const s=e.tags[i];if(s[0]==="e"&&s[1]){const[o,c,a,l,f]=s,u={id:c,relays:a?[a]:[],author:f};if(l==="root"){t.root=u;continue}if(l==="reply"){t.reply=u;continue}if(l==="mention"){t.mentions.push(u);continue}n?r=u:n=u,t.mentions.push(u);continue}if(s[0]==="q"&&s[1]){const[o,c,a]=s;t.quotes.push({id:c,relays:a?[a]:[]})}if(s[0]==="p"&&s[1]){t.profiles.push({pubkey:s[1],relays:s[2]?[s[2]]:[]});continue}}return t.root||(t.root=r||n||t.reply),t.reply||(t.reply=n||t.root),[t.reply,t.root].forEach(i=>{if(!i)return;let s=t.mentions.indexOf(i);if(s!==-1&&t.mentions.splice(s,1),i.author){let o=t.profiles.find(c=>c.pubkey===i.author);o&&o.relays&&(i.relays||(i.relays=[]),o.relays.forEach(c=>{var a;((a=i.relays)==null?void 0:a.indexOf(c))===-1&&i.relays.push(c)}),o.relays=i.relays)}}),t.mentions.forEach(i=>{if(i.author){let s=t.profiles.find(o=>o.pubkey===i.author);s&&s.relays&&(i.relays||(i.relays=[]),s.relays.forEach(o=>{i.relays.indexOf(o)===-1&&i.relays.push(o)}),s.relays=i.relays)}}),t}var Ga={};D(Ga,{fetchRelayInformation:()=>Ja,useFetchImplementation:()=>Fa});var zr;try{zr=fetch}catch{}function Fa(e){zr=e}async function Ja(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}var Ya={};D(Ya,{fastEventHash:()=>Wr,getPow:()=>Vr,minePow:()=>Xa});function Vr(e){let t=0;for(let n=0;n<64;n+=8){const r=parseInt(e.substring(n,n+8),16);if(r===0)t+=32;else{t+=Math.clz32(r);break}}return t}function Xa(e,t){let n=0;const r=e,i=["nonce",n.toString(),t.toString()];for(r.tags.push(i);;){const s=Math.floor(new Date().getTime()/1e3);if(s!==r.created_at&&(n=0,r.created_at=s),i[1]=(++n).toString(),r.id=Wr(r),Vr(r.id)>=t)break}return r}function Wr(e){return T(le(te.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}var Qa={};D(Qa,{finishRepostEvent:()=>ec,getRepostedEvent:()=>tc,getRepostedEventPointer:()=>Zr});function ec(e,t,n,r){return ee({kind:an,tags:[...e.tags??[],["e",t.id,n],["p",t.pubkey]],content:e.content===""?"":JSON.stringify(t),created_at:e.created_at},r)}function Zr(e){if(e.kind!==an)return;let t,n;for(let r=e.tags.length-1;r>=0&&(t===void 0||n===void 0);r--){const i=e.tags[r];i.length>=2&&(i[0]==="e"&&t===void 0?t=i:i[0]==="p"&&n===void 0&&(n=i))}if(t!==void 0)return{id:t[1],relays:[t[2],n==null?void 0:n[2]].filter(r=>typeof r=="string"),author:n==null?void 0:n[1]}}function tc(e,{skipVerification:t}={}){const n=Zr(e);if(n===void 0||e.content==="")return;let r;try{r=JSON.parse(e.content)}catch{return}if(r.id===n.id&&!(!t&&!wt(r)))return r}var nc={};D(nc,{NOSTR_URI_REGEX:()=>xt,parse:()=>ic,test:()=>rc});var xt=new RegExp(`nostr:(${Hr.source})`);function rc(e){return typeof e=="string"&&new RegExp(`^${xt.source}$`).test(e)}function ic(e){const t=e.match(new RegExp(`^${xt.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:bt(t[1])}}var sc={};D(sc,{finishReactionEvent:()=>oc,getReactedEventPointer:()=>ac});function oc(e,t,n){const r=t.tags.filter(i=>i.length>=2&&(i[0]==="e"||i[0]==="p"));return ee({...e,kind:cn,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function ac(e){if(e.kind!==cn)return;let t,n;for(let r=e.tags.length-1;r>=0&&(t===void 0||n===void 0);r--){const i=e.tags[r];i.length>=2&&(i[0]==="e"&&t===void 0?t=i:i[0]==="p"&&n===void 0&&(n=i))}if(!(t===void 0||n===void 0))return{id:t[1],relays:[t[2],n[2]].filter(r=>r!==void 0),author:n[1]}}var cc={};D(cc,{matchAll:()=>uc,regex:()=>yn,replaceAll:()=>lc});var yn=()=>new RegExp(`\\b${xt.source}\\b`,"g");function*uc(e){const t=e.matchAll(yn());for(const n of t)try{const[r,i]=n;yield{uri:r,value:i,decoded:bt(i),start:n.index,end:n.index+r.length}}catch{}}function lc(e,t){return e.replaceAll(yn(),(n,r)=>t({uri:n,value:r,decoded:bt(r)}))}var fc={};D(fc,{channelCreateEvent:()=>hc,channelHideMessageEvent:()=>yc,channelMessageEvent:()=>pc,channelMetadataEvent:()=>dc,channelMuteUserEvent:()=>gc});var hc=(e,t)=>{let n;if(typeof e.content=="object")n=JSON.stringify(e.content);else if(typeof e.content=="string")n=e.content;else return;return ee({kind:Ir,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},dc=(e,t)=>{let n;if(typeof e.content=="object")n=JSON.stringify(e.content);else if(typeof e.content=="string")n=e.content;else return;return ee({kind:Ur,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},pc=(e,t)=>{const n=[["e",e.channel_create_event_id,e.relay_url,"root"]];return e.reply_to_channel_message_event_id&&n.push(["e",e.reply_to_channel_message_event_id,e.relay_url,"reply"]),ee({kind:Lr,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},yc=(e,t)=>{let n;if(typeof e.content=="object")n=JSON.stringify(e.content);else if(typeof e.content=="string")n=e.content;else return;return ee({kind:$r,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},gc=(e,t)=>{let n;if(typeof e.content=="object")n=JSON.stringify(e.content);else if(typeof e.content=="string")n=e.content;else return;return ee({kind:Tr,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)},wc={};D(wc,{EMOJI_SHORTCODE_REGEX:()=>Gr,matchAll:()=>bc,regex:()=>gn,replaceAll:()=>vc});var Gr=/:(\w+):/,gn=()=>new RegExp(`\\B${Gr.source}\\B`,"g");function*bc(e){const t=e.matchAll(gn());for(const n of t)try{const[r,i]=n;yield{shortcode:r,name:i,start:n.index,end:n.index+r.length}}catch{}}function vc(e,t){return e.replaceAll(gn(),(n,r)=>t({shortcode:n,name:r}))}var Ec={};D(Ec,{useFetchImplementation:()=>mc,validateGithub:()=>xc});var wn;try{wn=fetch}catch{}function mc(e){wn=e}async function xc(e,t,n){try{return await(await wn(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch{return!1}}var q={};D(q,{decrypt:()=>mn,encrypt:()=>En,getConversationKey:()=>bn,v2:()=>Cc});var Fr=1,Jr=65535;function bn(e,t){const n=Le.getSharedSecret(e,"02"+t).subarray(1,33);return rn(le,n,"nip44-v2")}function Yr(e,t){const n=Nr(le,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function vn(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,n=t<=256?32:t/8;return n*(Math.floor((e-1)/n)+1)}function Sc(e){if(!Number.isSafeInteger(e)||e<Fr||e>Jr)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}function Nc(e){const t=te.encode(e),n=t.length,r=Sc(n),i=new Uint8Array(vn(n)-n);return lt(r,t,i)}function Ac(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<Fr||t>Jr||n.length!==t||e.length!==2+vn(t))throw new Error("invalid padding");return ge.decode(n)}function Xr(e,t,n){if(n.length!==32)throw new Error("AAD associated data must be 32 bytes");const r=lt(n,t);return pt(le,e,r)}function Kc(e){if(typeof e!="string")throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if(e[0]==="#")throw new Error("unknown encryption version");let n;try{n=pe.decode(e)}catch(s){throw new Error("invalid base64: "+s.message)}const r=n.length;if(r<99||r>65603)throw new Error("invalid data length: "+r);const i=n[0];if(i!==2)throw new Error("unknown encryption version "+i);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}function En(e,t,n=Qn(32)){const{chacha_key:r,chacha_nonce:i,hmac_key:s}=Yr(t,n),o=Nc(e),c=mr(r,i,o),a=Xr(s,c,n);return pe.encode(lt(new Uint8Array([2]),n,c,a))}function mn(e,t){const{nonce:n,ciphertext:r,mac:i}=Kc(e),{chacha_key:s,chacha_nonce:o,hmac_key:c}=Yr(t,n),a=Xr(c,r,n);if(!Us(a,i))throw new Error("invalid MAC");const l=mr(s,o,r);return Ac(l)}var Cc={utils:{getConversationKey:bn,calcPaddedLen:vn},encrypt:En,decrypt:mn},Bc={};D(Bc,{makeNwcRequestEvent:()=>_c,parseConnectionString:()=>kc});function kc(e){const{pathname:t,searchParams:n}=new URL(e),r=t,i=n.get("relay"),s=n.get("secret");if(!r||!i||!s)throw new Error("invalid connection string");return{pubkey:r,relay:i,secret:s}}async function _c(e,t,n){const i=await Dr(t,e,JSON.stringify({method:"pay_invoice",params:{invoice:n}})),s={kind:Or,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",e]]};return ee(s,t)}var Ic={};D(Ic,{getZapEndpoint:()=>Lc,makeZapReceipt:()=>Rc,makeZapRequest:()=>$c,useFetchImplementation:()=>Uc,validateZapRequest:()=>Tc});var xn;try{xn=fetch}catch{}function Uc(e){xn=e}async function Lc(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(n){let{words:o}=De.decode(n,1e3),c=De.fromWords(o);t=ge.decode(c)}else if(r){let[o,c]=r.split("@");t=new URL(`/.well-known/lnurlp/${o}`,`https://${c}`).toString()}else return null;let s=await(await xn(t)).json();if(s.allowsNostr&&s.nostrPubkey)return s.callback}catch{}return null}function $c({profile:e,event:t,amount:n,relays:r,comment:i=""}){if(!n)throw new Error("amount not given");if(!e)throw new Error("profile not given");let s={kind:9734,created_at:Math.round(Date.now()/1e3),content:i,tags:[["p",e],["amount",n.toString()],["relays",...r]]};return t&&s.tags.push(["e",t]),s}function Tc(e){let t;try{t=JSON.parse(e)}catch{return"Invalid zap request JSON."}if(!yt(t))return"Zap request is not a valid Nostr event.";if(!wt(t))return"Invalid signature on zap request.";let n=t.tags.find(([s,o])=>s==="p"&&o);if(!n)return"Zap request doesn't have a 'p' tag.";if(!n[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let r=t.tags.find(([s,o])=>s==="e"&&o);return r&&!r[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":t.tags.find(([s,o])=>s==="relays"&&o)?null:"Zap request doesn't have a 'relays' tag."}function Rc({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let i=JSON.parse(e),s=i.tags.filter(([c])=>c==="e"||c==="p"||c==="a"),o={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...s,["P",i.pubkey],["bolt11",n],["description",e]]};return t&&o.tags.push(["preimage",t]),o}var Mc={};D(Mc,{createRumor:()=>ii,createSeal:()=>si,createWrap:()=>oi,unwrapEvent:()=>ai,unwrapManyEvents:()=>Hc,wrapEvent:()=>Sn,wrapManyEvents:()=>Pc});var Oc=2*24*60*60,Qr=()=>Math.round(Date.now()/1e3),ei=()=>Math.round(Qr()-Math.random()*Oc),ti=(e,t)=>bn(e,t),ni=(e,t,n)=>En(JSON.stringify(e),ti(t,n)),ri=(e,t)=>JSON.parse(mn(e.content,ti(t,e.pubkey)));function ii(e,t){const n={created_at:Qr(),content:"",tags:[],...e,pubkey:we(t)};return n.id=ze(n),n}function si(e,t,n){return ee({kind:_r,content:ni(e,t,n),created_at:ei(),tags:[]},t)}function oi(e,t){const n=$e();return ee({kind:Rr,content:ni(e,n,t),created_at:ei(),tags:[["p",t]]},n)}function Sn(e,t,n){const r=ii(e,t),i=si(r,t,n);return oi(i,n)}function Pc(e,t,n){if(!n||n.length===0)throw new Error("At least one recipient is required.");const r=we(t),i=[Sn(e,t,r)];return n.forEach(s=>{i.push(Sn(e,t,s))}),i}function ai(e,t){const n=ri(e,t);return ri(n,t)}function Hc(e,t){let n=[];return e.forEach(r=>{n.push(ai(r,t))}),n.sort((r,i)=>r.created_at-i.created_at),n}var Dc={};D(Dc,{getToken:()=>qc,hashPayload:()=>Nn,unpackEventFromToken:()=>ui,validateEvent:()=>yi,validateEventKind:()=>fi,validateEventMethodTag:()=>di,validateEventPayloadTag:()=>pi,validateEventTimestamp:()=>li,validateEventUrlTag:()=>hi,validateToken:()=>jc});var ci="Nostr ";async function qc(e,t,n,r=!1,i){const s={kind:un,tags:[["u",e],["method",t]],created_at:Math.round(new Date().getTime()/1e3),content:""};i&&s.tags.push(["payload",Nn(i)]);const o=await n(s);return(r?ci:"")+pe.encode(te.encode(JSON.stringify(o)))}async function jc(e,t,n){const r=await ui(e).catch(s=>{throw s});return await yi(r,t,n).catch(s=>{throw s})}async function ui(e){if(!e)throw new Error("Missing token");e=e.replace(ci,"");const t=ge.decode(pe.decode(e));if(!t||t.length===0||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function li(e){return e.created_at?Math.round(new Date().getTime()/1e3)-e.created_at<60:!1}function fi(e){return e.kind===un}function hi(e,t){const n=e.tags.find(r=>r[0]==="u");return n?n.length>0&&n[1]===t:!1}function di(e,t){const n=e.tags.find(r=>r[0]==="method");return n?n.length>0&&n[1].toLowerCase()===t.toLowerCase():!1}function Nn(e){const t=le(te.encode(JSON.stringify(e)));return T(t)}function pi(e,t){const n=e.tags.find(i=>i[0]==="payload");if(!n)return!1;const r=Nn(t);return n.length>0&&n[1]===r}async function yi(e,t,n,r){if(!wt(e))throw new Error("Invalid nostr event, signature invalid");if(!fi(e))throw new Error("Invalid nostr event, kind invalid");if(!li(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!hi(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!di(e,n))throw new Error("Invalid nostr event, method tag invalid");if(r&&typeof r=="object"&&Object.keys(r).length>0&&!pi(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}const Ke=30078,An=30078,gi=14,zc=100;function Vc(e){return JSON.stringify({rootKey:T(e.rootKey),theirCurrentNostrPublicKey:e.theirCurrentNostrPublicKey,theirNextNostrPublicKey:e.theirNextNostrPublicKey,ourCurrentNostrKey:e.ourCurrentNostrKey?{publicKey:e.ourCurrentNostrKey.publicKey,privateKey:T(e.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:e.ourNextNostrKey.publicKey,privateKey:T(e.ourNextNostrKey.privateKey)},receivingChainKey:e.receivingChainKey?T(e.receivingChainKey):void 0,sendingChainKey:e.sendingChainKey?T(e.sendingChainKey):void 0,sendingChainMessageNumber:e.sendingChainMessageNumber,receivingChainMessageNumber:e.receivingChainMessageNumber,previousSendingChainMessageCount:e.previousSendingChainMessageCount,skippedMessageKeys:Object.fromEntries(Object.entries(e.skippedMessageKeys).map(([t,n])=>[t,T(n)])),skippedHeaderKeys:Object.fromEntries(Object.entries(e.skippedHeaderKeys).map(([t,n])=>[t,n.map(r=>T(r))]))})}function Wc(e){const t=JSON.parse(e);return{rootKey:F(t.rootKey),theirCurrentNostrPublicKey:t.theirCurrentNostrPublicKey,theirNextNostrPublicKey:t.theirNextNostrPublicKey,ourCurrentNostrKey:t.ourCurrentNostrKey?{publicKey:t.ourCurrentNostrKey.publicKey,privateKey:F(t.ourCurrentNostrKey.privateKey)}:void 0,ourNextNostrKey:{publicKey:t.ourNextNostrKey.publicKey,privateKey:F(t.ourNextNostrKey.privateKey)},receivingChainKey:t.receivingChainKey?F(t.receivingChainKey):void 0,sendingChainKey:t.sendingChainKey?F(t.sendingChainKey):void 0,sendingChainMessageNumber:t.sendingChainMessageNumber,receivingChainMessageNumber:t.receivingChainMessageNumber,previousSendingChainMessageCount:t.previousSendingChainMessageCount,skippedMessageKeys:Object.fromEntries(Object.entries(t.skippedMessageKeys).map(([n,r])=>[n,F(r)])),skippedHeaderKeys:Object.fromEntries(Object.entries(t.skippedHeaderKeys||{}).map(([n,r])=>[n,r.map(i=>F(i))]))}}async function*Zc(e){const t=[];let n=null;const r=e.onEvent(i=>{n?(n(i),n=null):t.push(i)});try{for(;;)t.length>0?yield t.shift():yield new Promise(i=>{n=i})}finally{r()}}function Te(e,t=new Uint8Array(32),n=1){const r=rn(le,e,t),i=[];for(let s=1;s<=n;s++)i.push(Nr(le,r,new Uint8Array([s]),32));return i}function St(e,t){return`${e}:${t}`}function Gc(e){const t=e.tags.find(n=>n[0]==="ms");return t?parseInt(t[1]):e.created_at*1e3}const Fc=1e3,Jc="0000000000000000000000000000000000000000000000000000000000000000";class et{constructor(t,n){ie(this,"nostrUnsubscribe");ie(this,"nostrNextUnsubscribe");ie(this,"internalSubscriptions",new Map);ie(this,"currentInternalSubscriptionId",0);ie(this,"name");this.nostrSubscribe=t,this.state=n,this.name=Math.random().toString(36).substring(2,6)}static init(t,n,r,i,s,o){const c=$e(),[a,l]=Te(s,q.getConversationKey(c,n),2);let f,u;i?(f={publicKey:we(r),privateKey:r},u={publicKey:we(c),privateKey:c}):u={publicKey:we(r),privateKey:r};const g={rootKey:i?a:s,theirNextNostrPublicKey:n,ourCurrentNostrKey:f,ourNextNostrKey:u,receivingChainKey:void 0,sendingChainKey:i?l:void 0,sendingChainMessageNumber:0,receivingChainMessageNumber:0,previousSendingChainMessageCount:0,skippedMessageKeys:{},skippedHeaderKeys:{}},b=new et(t,g);return o&&(b.name=o),b}send(t){return this.sendEvent({content:t,kind:gi})}sendEvent(t){if(!this.state.theirNextNostrPublicKey||!this.state.ourCurrentNostrKey)throw new Error("we are not the initiator, so we can't send the first message");if("sig"in t)throw new Error("Event must be unsigned "+JSON.stringify(t));const n={...t,content:t.content||"",kind:t.kind||Ke,created_at:t.created_at||Math.floor(Date.now()/1e3),tags:t.tags||[],pubkey:t.pubkey||Jc};n.tags.some(([a])=>a==="ms")||n.tags.push(["ms",Date.now().toString()]),n.id=ze(n);const[r,i]=this.ratchetEncrypt(JSON.stringify(n)),s=q.getConversationKey(this.state.ourCurrentNostrKey.privateKey,this.state.theirNextNostrPublicKey),o=q.encrypt(JSON.stringify(r),s);return{event:ee({content:i,kind:Ke,tags:[["header",o]],created_at:Math.floor(Date.now()/1e3)},this.state.ourCurrentNostrKey.privateKey),innerEvent:n}}onEvent(t){const n=this.currentInternalSubscriptionId++;return this.internalSubscriptions.set(n,t),this.subscribeToNostrEvents(),()=>this.internalSubscriptions.delete(n)}close(){var t,n;(t=this.nostrUnsubscribe)==null||t.call(this),(n=this.nostrNextUnsubscribe)==null||n.call(this)}ratchetEncrypt(t){const[n,r]=Te(this.state.sendingChainKey,new Uint8Array([1]),2);return this.state.sendingChainKey=n,[{number:this.state.sendingChainMessageNumber++,nextPublicKey:this.state.ourNextNostrKey.publicKey,previousChainLength:this.state.previousSendingChainMessageCount},q.encrypt(t,r)]}ratchetDecrypt(t,n,r){const i=this.trySkippedMessageKeys(t,n,r);if(i)return i;this.skipMessageKeys(t.number,r);const[s,o]=Te(this.state.receivingChainKey,new Uint8Array([1]),2);this.state.receivingChainKey=s,this.state.receivingChainMessageNumber++;try{return q.decrypt(n,o)}catch(c){throw console.error(this.name,"Decryption failed:",c,{messageKey:T(o).slice(0,4),receivingChainKey:T(this.state.receivingChainKey).slice(0,4),sendingChainKey:this.state.sendingChainKey&&T(this.state.sendingChainKey).slice(0,4),rootKey:T(this.state.rootKey).slice(0,4)}),c}}ratchetStep(t){this.state.previousSendingChainMessageCount=this.state.sendingChainMessageNumber,this.state.sendingChainMessageNumber=0,this.state.receivingChainMessageNumber=0,this.state.theirNextNostrPublicKey=t;const n=q.getConversationKey(this.state.ourNextNostrKey.privateKey,this.state.theirNextNostrPublicKey),[r,i]=Te(this.state.rootKey,n,2);this.state.receivingChainKey=i,this.state.ourCurrentNostrKey=this.state.ourNextNostrKey;const s=$e();this.state.ourNextNostrKey={publicKey:we(s),privateKey:s};const o=q.getConversationKey(this.state.ourNextNostrKey.privateKey,this.state.theirNextNostrPublicKey),[c,a]=Te(r,o,2);this.state.rootKey=c,this.state.sendingChainKey=a}skipMessageKeys(t,n){if(this.state.receivingChainMessageNumber+Fc<t)throw new Error("Too many skipped messages");for(;this.state.receivingChainMessageNumber<t;){const[r,i]=Te(this.state.receivingChainKey,new Uint8Array([1]),2);this.state.receivingChainKey=r;const s=St(n,this.state.receivingChainMessageNumber);if(this.state.skippedMessageKeys[s]=i,!this.state.skippedHeaderKeys[n]){const o=[];if(this.state.ourCurrentNostrKey){const a=q.getConversationKey(this.state.ourCurrentNostrKey.privateKey,n);o.push(a)}const c=q.getConversationKey(this.state.ourNextNostrKey.privateKey,n);o.push(c),this.state.skippedHeaderKeys[n]=o}this.state.receivingChainMessageNumber++}}trySkippedMessageKeys(t,n,r){var s;const i=St(r,t.number);if(i in this.state.skippedMessageKeys){const o=this.state.skippedMessageKeys[i];return delete this.state.skippedMessageKeys[i],Object.keys(this.state.skippedMessageKeys).some(a=>a.startsWith(`${r}:`))||(delete this.state.skippedHeaderKeys[r],(s=this.nostrUnsubscribe)==null||s.call(this),this.nostrUnsubscribe=void 0),q.decrypt(n,o)}return null}decryptHeader(t){const n=t.tags[0][1];if(this.state.ourCurrentNostrKey){const s=q.getConversationKey(this.state.ourCurrentNostrKey.privateKey,t.pubkey);try{return[JSON.parse(q.decrypt(n,s)),!1,!1]}catch{}}const r=q.getConversationKey(this.state.ourNextNostrKey.privateKey,t.pubkey);try{return[JSON.parse(q.decrypt(n,r)),!0,!1]}catch{}const i=this.state.skippedHeaderKeys[t.pubkey];if(i)for(const s of i)try{return[JSON.parse(q.decrypt(n,s)),!1,!0]}catch{}throw new Error("Failed to decrypt header with current and skipped header keys")}handleNostrEvent(t){var c;const[n,r,i]=this.decryptHeader(t);if(!i)this.state.theirNextNostrPublicKey!==n.nextPublicKey&&(this.state.theirCurrentNostrPublicKey=this.state.theirNextNostrPublicKey,this.state.theirNextNostrPublicKey=n.nextPublicKey,(c=this.nostrUnsubscribe)==null||c.call(this),this.nostrUnsubscribe=this.nostrNextUnsubscribe,this.nostrNextUnsubscribe=this.nostrSubscribe({authors:[this.state.theirNextNostrPublicKey],kinds:[Ke]},a=>this.handleNostrEvent(a))),r&&(this.skipMessageKeys(n.previousChainLength,t.pubkey),this.ratchetStep(n.nextPublicKey));else if(!(St(t.pubkey,n.number)in this.state.skippedMessageKeys))return;const s=this.ratchetDecrypt(n,t.content,t.pubkey),o=JSON.parse(s);if(!yt(o)){console.error("Invalid event received",o);return}if(o.id!==ze(o)){console.error("Event hash does not match",o);return}this.internalSubscriptions.forEach(a=>a(o,t))}subscribeToNostrEvents(){if(this.nostrNextUnsubscribe)return;this.nostrNextUnsubscribe=this.nostrSubscribe({authors:[this.state.theirNextNostrPublicKey],kinds:[Ke]},n=>this.handleNostrEvent(n));const t=Object.keys(this.state.skippedHeaderKeys);this.state.theirCurrentNostrPublicKey&&!t.includes(this.state.theirCurrentNostrPublicKey)&&t.push(this.state.theirCurrentNostrPublicKey),this.nostrUnsubscribe=this.nostrSubscribe({authors:t,kinds:[Ke]},n=>this.handleNostrEvent(n))}}new TextDecoder("utf-8"),new TextEncoder;function Nt(e,t){const n=Le.getSharedSecret(e,"02"+t).subarray(1,33);return rn(le,n,"nip44-v2")}class Re{constructor(t,n,r,i,s,o,c=[]){this.inviterEphemeralPublicKey=t,this.sharedSecret=n,this.inviter=r,this.inviterEphemeralPrivateKey=i,this.label=s,this.maxUses=o,this.usedBy=c}static createNew(t,n,r){if(!t)throw new Error("Inviter public key is required");const i=$e(),s=we(i),o=T($e());return new Re(s,o,t,i,n,r)}static fromUrl(t){const r=new URL(t).hash.slice(1);if(!r)throw new Error("No invite data found in the URL hash.");const i=decodeURIComponent(r);let s;try{s=JSON.parse(i)}catch(l){throw new Error("Invite data in URL hash is not valid JSON: "+l)}const{inviter:o,ephemeralKey:c,sharedSecret:a}=s;if(!o||!c||!a)throw new Error("Missing required fields (inviter, ephemeralKey, sharedSecret) in invite data.");return new Re(c,a,o)}static deserialize(t){const n=JSON.parse(t);return new Re(n.inviterEphemeralPublicKey,n.sharedSecret,n.inviter,n.inviterEphemeralPrivateKey?new Uint8Array(n.inviterEphemeralPrivateKey):void 0,n.label,n.maxUses,n.usedBy)}static fromEvent(t){var o,c;if(!t.sig)throw new Error("Event is not signed");if(!wt(t))throw new Error("Event signature is invalid");const{tags:n}=t,r=(o=n.find(([a])=>a==="ephemeralKey"))==null?void 0:o[1],i=(c=n.find(([a])=>a==="sharedSecret"))==null?void 0:c[1],s=t.pubkey;if(!r||!i)throw new Error("Invalid invite event: missing session key or sharedSecret");return new Re(r,i,s)}static fromUser(t,n,r){const i={kinds:[An],authors:[t],limit:1,"#d":["nostr-double-ratchet/invite"]};let s=0;return n(i,c=>{if(!(!c.created_at||c.created_at<=s)){s=c.created_at;try{const a=Re.fromEvent(c);r(a)}catch(a){console.error("Error processing invite:",a,"event:",c)}}})}serialize(){return JSON.stringify({inviterEphemeralPublicKey:this.inviterEphemeralPublicKey,sharedSecret:this.sharedSecret,inviter:this.inviter,inviterEphemeralPrivateKey:this.inviterEphemeralPrivateKey?Array.from(this.inviterEphemeralPrivateKey):void 0,label:this.label,maxUses:this.maxUses,usedBy:this.usedBy})}getUrl(t="https://iris.to"){const n={inviter:this.inviter,ephemeralKey:this.inviterEphemeralPublicKey,sharedSecret:this.sharedSecret},r=new URL(t);return r.hash=encodeURIComponent(JSON.stringify(n)),r.toString()}getEvent(){return{kind:An,pubkey:this.inviter,content:"",created_at:Math.floor(Date.now()/1e3),tags:[["ephemeralKey",this.inviterEphemeralPublicKey],["sharedSecret",this.sharedSecret],["d","nostr-double-ratchet/invite"]]}}async accept(t,n,r){const i=$e(),s=we(i),o=this.inviter||this.inviterEphemeralPublicKey,c=F(this.sharedSecret),a=et.init(t,this.inviterEphemeralPublicKey,i,!0,c,void 0),l=$e(),f=we(l),g=await(typeof r=="function"?r:(h,d)=>Promise.resolve(q.encrypt(h,Nt(r,d))))(s,o),b={pubkey:n,tags:[["sharedSecret",this.sharedSecret]],content:await q.encrypt(g,c),created_at:Math.floor(Date.now()/1e3)},p={kind:Ke,pubkey:f,content:q.encrypt(JSON.stringify(b),Nt(l,this.inviterEphemeralPublicKey)),created_at:Math.floor(Date.now()/1e3),tags:[["p",this.inviterEphemeralPublicKey]]};return{session:a,event:ee(p,l)}}listen(t,n,r){if(!this.inviterEphemeralPrivateKey)throw new Error("Inviter session key is not available");const i={kinds:[Ke],"#p":[this.inviterEphemeralPublicKey]};return n(i,async s=>{try{if(this.maxUses&&this.usedBy.length>=this.maxUses){console.error("Invite has reached maximum number of uses");return}const o=await q.decrypt(s.content,Nt(this.inviterEphemeralPrivateKey,s.pubkey)),c=JSON.parse(o);if(!c.tags||!c.tags.some(([h,d])=>h==="sharedSecret"&&d===this.sharedSecret)){console.error("Invalid secret from event",s);return}const a=F(this.sharedSecret),l=c.pubkey;this.usedBy.push(l);const f=await q.decrypt(c.content,a),g=await(typeof t=="function"?t:(h,d)=>Promise.resolve(q.decrypt(h,Nt(t,d))))(f,l),b=s.id,p=et.init(n,g,this.inviterEphemeralPrivateKey,!1,a,b);r(p,l)}catch(o){console.error("Error processing invite message:",o,"event",s)}})}}H.CHAT_MESSAGE_KIND=gi,H.INVITE_EVENT_KIND=An,H.Invite=Re,H.MAX_SKIP=zc,H.MESSAGE_EVENT_KIND=Ke,H.Session=et,H.createEventStream=Zc,H.deserializeSessionState=Wc,H.getMillisecondTimestamp=Gc,H.kdf=Te,H.serializeSessionState=Vc,H.skippedMessageIndexKey=St,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})});
package/dist/utils.d.ts CHANGED
@@ -5,4 +5,5 @@ export declare function deserializeSessionState(data: string): SessionState;
5
5
  export declare function createEventStream(session: Session): AsyncGenerator<Rumor, void, unknown>;
6
6
  export declare function kdf(input1: Uint8Array, input2?: Uint8Array, numOutputs?: number): Uint8Array[];
7
7
  export declare function skippedMessageIndexKey(nostrSender: string, number: number): string;
8
+ export declare function getMillisecondTimestamp(event: Rumor): number;
8
9
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CA+BjE;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAgClE;AAED,wBAAuB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CA0B/F;AAED,wBAAgB,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,GAAE,UAA+B,EAAE,UAAU,GAAE,MAAU,GAAG,UAAU,EAAE,CAQrH;AAED,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAElF"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CA+BjE;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAgClE;AAED,wBAAuB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CA0B/F;AAED,wBAAgB,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,GAAE,UAA+B,EAAE,UAAU,GAAE,MAAU,GAAG,UAAU,EAAE,CAQrH;AAED,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAElF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,KAAK,UAMnD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nostr-double-ratchet",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "type": "module",
5
5
  "packageManager": "yarn@1.22.22",
6
6
  "description": "Nostr double ratchet library",
package/src/Session.ts CHANGED
@@ -80,7 +80,7 @@ export class Session {
80
80
  * @returns A verified Nostr event containing the encrypted message
81
81
  * @throws Error if we are not the initiator and trying to send the first message
82
82
  */
83
- send(text: string): VerifiedEvent {
83
+ send(text: string): {event: VerifiedEvent, innerEvent: Rumor} {
84
84
  return this.sendEvent({
85
85
  content: text,
86
86
  kind: CHAT_MESSAGE_KIND
@@ -94,7 +94,7 @@ export class Session {
94
94
  * @returns A verified Nostr event containing the encrypted message
95
95
  * @throws Error if we are not the initiator and trying to send the first message
96
96
  */
97
- sendEvent(event: Partial<UnsignedEvent>): VerifiedEvent {
97
+ sendEvent(event: Partial<UnsignedEvent>): {event: VerifiedEvent, innerEvent: Rumor} {
98
98
  if (!this.state.theirNextNostrPublicKey || !this.state.ourCurrentNostrKey) {
99
99
  throw new Error("we are not the initiator, so we can't send the first message");
100
100
  }
@@ -130,7 +130,7 @@ export class Session {
130
130
  created_at: Math.floor(Date.now() / 1000)
131
131
  }, this.state.ourCurrentNostrKey.privateKey);
132
132
 
133
- return nostrEvent;
133
+ return {event: nostrEvent, innerEvent: rumor as Rumor};
134
134
  }
135
135
 
136
136
  /**
package/src/utils.ts CHANGED
@@ -111,4 +111,12 @@ export function kdf(input1: Uint8Array, input2: Uint8Array = new Uint8Array(32),
111
111
 
112
112
  export function skippedMessageIndexKey(nostrSender: string, number: number): string {
113
113
  return `${nostrSender}:${number}`;
114
+ }
115
+
116
+ export function getMillisecondTimestamp(event: Rumor) {
117
+ const msTag = event.tags.find(tag => tag[0] === "ms");
118
+ if (msTag) {
119
+ return parseInt(msTag[1]);
120
+ }
121
+ return event.created_at * 1000;
114
122
  }