nostr-double-ratchet 0.0.22 → 0.0.23
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.map +1 -1
- package/dist/nostr-double-ratchet.es.js +158 -156
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/package.json +1 -1
- package/src/Session.ts +13 -9
|
@@ -123,7 +123,7 @@ let Ci = class extends Wn {
|
|
|
123
123
|
return t.length = i, t.pos = c, t.finished = s, t.destroyed = o, i % n && t.buffer.set(r), t;
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
|
-
const Bi = (e, t, n) => e & t ^ ~e & n, _i = (e, t, n) => e & t ^ e & n ^ t & n,
|
|
126
|
+
const Bi = (e, t, n) => e & t ^ ~e & n, _i = (e, t, n) => e & t ^ e & n ^ t & n, ki = /* @__PURE__ */ new Uint32Array([
|
|
127
127
|
1116352408,
|
|
128
128
|
1899447441,
|
|
129
129
|
3049323471,
|
|
@@ -198,7 +198,7 @@ const Bi = (e, t, n) => e & t ^ ~e & n, _i = (e, t, n) => e & t ^ e & n ^ t & n,
|
|
|
198
198
|
528734635,
|
|
199
199
|
1541459225
|
|
200
200
|
]), ve = /* @__PURE__ */ new Uint32Array(64);
|
|
201
|
-
let
|
|
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
|
}
|
|
@@ -219,7 +219,7 @@ let ki = class extends Ci {
|
|
|
219
219
|
}
|
|
220
220
|
let { A: r, B: i, C: s, D: o, E: c, F: a, G: l, H: f } = this;
|
|
221
221
|
for (let u = 0; u < 64; u++) {
|
|
222
|
-
const y = re(c, 6) ^ re(c, 11) ^ re(c, 25), b = f + y + Bi(c, a, l) +
|
|
222
|
+
const y = re(c, 6) ^ re(c, 11) ^ re(c, 25), b = f + y + Bi(c, a, l) + ki[u] + ve[u] | 0, h = (re(r, 2) ^ re(r, 13) ^ re(r, 22)) + _i(r, i, s) | 0;
|
|
223
223
|
f = l, l = a, a = c, c = o + b | 0, o = s, s = i, i = r, r = b + h | 0;
|
|
224
224
|
}
|
|
225
225
|
r = r + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, l = l + this.G | 0, f = f + this.H | 0, this.set(r, i, s, o, c, a, l, f);
|
|
@@ -231,10 +231,10 @@ let ki = 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 Lt = /* @__PURE__ */ Si(() => new
|
|
234
|
+
const Lt = /* @__PURE__ */ Si(() => new Ii());
|
|
235
235
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
236
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
|
-
function
|
|
237
|
+
function De(e) {
|
|
238
238
|
if (!at(e))
|
|
239
239
|
throw new Error("Uint8Array expected");
|
|
240
240
|
let t = "";
|
|
@@ -251,7 +251,7 @@ function Zt(e) {
|
|
|
251
251
|
throw new Error("hex string expected, got " + typeof e);
|
|
252
252
|
return BigInt(e === "" ? "0" : `0x${e}`);
|
|
253
253
|
}
|
|
254
|
-
function
|
|
254
|
+
function je(e) {
|
|
255
255
|
if (typeof e != "string")
|
|
256
256
|
throw new Error("hex string expected, got " + typeof e);
|
|
257
257
|
const t = e.length;
|
|
@@ -267,27 +267,27 @@ function De(e) {
|
|
|
267
267
|
return n;
|
|
268
268
|
}
|
|
269
269
|
function F(e) {
|
|
270
|
-
return Zt(
|
|
270
|
+
return Zt(De(e));
|
|
271
271
|
}
|
|
272
272
|
function Gt(e) {
|
|
273
273
|
if (!at(e))
|
|
274
274
|
throw new Error("Uint8Array expected");
|
|
275
|
-
return Zt(
|
|
275
|
+
return Zt(De(Uint8Array.from(e).reverse()));
|
|
276
276
|
}
|
|
277
277
|
function Ne(e, t) {
|
|
278
|
-
return
|
|
278
|
+
return je(e.toString(16).padStart(t * 2, "0"));
|
|
279
279
|
}
|
|
280
280
|
function Ft(e, t) {
|
|
281
281
|
return Ne(e, t).reverse();
|
|
282
282
|
}
|
|
283
283
|
function $i(e) {
|
|
284
|
-
return
|
|
284
|
+
return je(Fn(e));
|
|
285
285
|
}
|
|
286
286
|
function Z(e, t, n) {
|
|
287
287
|
let r;
|
|
288
288
|
if (typeof t == "string")
|
|
289
289
|
try {
|
|
290
|
-
r =
|
|
290
|
+
r = je(t);
|
|
291
291
|
} catch (s) {
|
|
292
292
|
throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${s}`);
|
|
293
293
|
}
|
|
@@ -300,7 +300,7 @@ function Z(e, t, n) {
|
|
|
300
300
|
throw new Error(`${e} expected ${n} bytes, got ${i}`);
|
|
301
301
|
return r;
|
|
302
302
|
}
|
|
303
|
-
function
|
|
303
|
+
function ke(...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) => {
|
|
@@ -354,7 +354,7 @@ function Jn(e, t, n) {
|
|
|
354
354
|
const b = r.slice();
|
|
355
355
|
y.push(b), u += r.length;
|
|
356
356
|
}
|
|
357
|
-
return
|
|
357
|
+
return ke(...y);
|
|
358
358
|
};
|
|
359
359
|
return (u, y) => {
|
|
360
360
|
o(), a(u);
|
|
@@ -396,14 +396,14 @@ const qi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
396
396
|
bitLen: Oi,
|
|
397
397
|
bitMask: Jt,
|
|
398
398
|
bitSet: Mi,
|
|
399
|
-
bytesToHex:
|
|
399
|
+
bytesToHex: De,
|
|
400
400
|
bytesToNumberBE: F,
|
|
401
401
|
bytesToNumberLE: Gt,
|
|
402
|
-
concatBytes:
|
|
402
|
+
concatBytes: ke,
|
|
403
403
|
createHmacDrbg: Jn,
|
|
404
404
|
ensureBytes: Z,
|
|
405
405
|
equalBytes: Ti,
|
|
406
|
-
hexToBytes:
|
|
406
|
+
hexToBytes: je,
|
|
407
407
|
hexToNumber: Zt,
|
|
408
408
|
numberToBytesBE: Ne,
|
|
409
409
|
numberToBytesLE: Ft,
|
|
@@ -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 -= y, o += St);
|
|
674
|
-
const g = h, E = h + Math.abs(d) - 1, S = p % 2 !== 0,
|
|
675
|
-
d === 0 ? f = f.add(n(S, s[g])) : l = l.add(n(
|
|
674
|
+
const g = h, E = h + Math.abs(d) - 1, S = p % 2 !== 0, I = d < 0;
|
|
675
|
+
d === 0 ? f = f.add(n(S, s[g])) : l = l.add(n(I, s[E]));
|
|
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 g = h.toAffine();
|
|
773
|
-
return
|
|
773
|
+
return ke(Uint8Array.from([4]), n.toBytes(g.x), n.toBytes(g.y));
|
|
774
774
|
}), i = t.fromBytes || ((p) => {
|
|
775
775
|
const h = p.subarray(1), d = n.fromBytes(h.subarray(0, n.BYTES)), g = n.fromBytes(h.subarray(n.BYTES, 2 * n.BYTES));
|
|
776
776
|
return { x: d, y: g };
|
|
@@ -791,7 +791,7 @@ function rs(e) {
|
|
|
791
791
|
function a(p) {
|
|
792
792
|
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey: g, n: E } = t;
|
|
793
793
|
if (h && typeof p != "bigint") {
|
|
794
|
-
if (p instanceof Uint8Array && (p =
|
|
794
|
+
if (p instanceof Uint8Array && (p = De(p)), typeof p != "string" || !h.includes(p.length))
|
|
795
795
|
throw new Error("Invalid key");
|
|
796
796
|
p = p.padStart(d * 2, "0");
|
|
797
797
|
}
|
|
@@ -887,7 +887,7 @@ function rs(e) {
|
|
|
887
887
|
*/
|
|
888
888
|
equals(h) {
|
|
889
889
|
f(h);
|
|
890
|
-
const { px: d, py: g, pz: E } = this, { px: S, py:
|
|
890
|
+
const { px: d, py: g, pz: E } = this, { px: S, py: I, pz: B } = h, m = n.eql(n.mul(d, B), n.mul(S, E)), x = n.eql(n.mul(g, B), n.mul(I, E));
|
|
891
891
|
return m && 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, g = n.mul(d, _n), { px: E, py: S, pz:
|
|
905
|
-
let B = n.ZERO, m = n.ZERO, x = n.ZERO, K = n.mul(E, E), M = n.mul(S, S),
|
|
906
|
-
return A = n.add(A, A), x = n.mul(E,
|
|
904
|
+
const { a: h, b: d } = t, g = n.mul(d, _n), { px: E, py: S, pz: I } = this;
|
|
905
|
+
let B = n.ZERO, m = n.ZERO, x = n.ZERO, K = n.mul(E, E), M = n.mul(S, S), k = n.mul(I, I), A = n.mul(E, S);
|
|
906
|
+
return A = n.add(A, A), x = n.mul(E, I), x = n.add(x, x), B = n.mul(h, x), m = n.mul(g, k), m = n.add(B, m), B = n.sub(M, m), m = n.add(M, m), m = n.mul(B, m), B = n.mul(A, B), x = n.mul(g, x), k = n.mul(h, k), A = n.sub(K, k), A = n.mul(h, A), A = n.add(A, x), x = n.add(K, K), K = n.add(x, K), K = n.add(K, k), K = n.mul(K, A), m = n.add(m, K), k = n.mul(S, I), k = n.add(k, k), K = n.mul(k, A), B = n.sub(B, K), x = n.mul(k, M), x = n.add(x, x), x = n.add(x, x), new u(B, m, 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: g, pz: E } = this, { px: S, py:
|
|
914
|
+
const { px: d, py: g, pz: E } = this, { px: S, py: I, pz: B } = h;
|
|
915
915
|
let m = n.ZERO, x = n.ZERO, K = n.ZERO;
|
|
916
|
-
const M = t.a,
|
|
917
|
-
let A = n.mul(d, S), T = n.mul(g,
|
|
916
|
+
const M = t.a, k = n.mul(t.b, _n);
|
|
917
|
+
let A = n.mul(d, S), T = n.mul(g, I), R = n.mul(E, B), H = n.add(d, g), w = n.add(S, I);
|
|
918
918
|
H = n.mul(H, w), w = n.add(A, T), H = n.sub(H, w), w = n.add(d, E);
|
|
919
919
|
let v = n.add(S, B);
|
|
920
|
-
return w = n.mul(w, v), v = n.add(A, R), w = n.sub(w, v), v = n.add(g, E), m = n.add(
|
|
920
|
+
return w = n.mul(w, v), v = n.add(A, R), w = n.sub(w, v), v = n.add(g, E), m = n.add(I, B), v = n.mul(v, m), m = n.add(T, R), v = n.sub(v, m), K = n.mul(M, w), m = n.mul(k, R), K = n.add(m, K), m = n.sub(T, K), K = n.add(T, K), x = n.mul(m, K), T = n.add(A, A), T = n.add(T, A), R = n.mul(M, R), w = n.mul(k, w), T = n.add(T, R), R = n.sub(A, R), R = n.mul(M, R), w = n.add(w, R), A = n.mul(T, w), x = n.add(x, A), A = n.mul(v, w), m = n.mul(H, m), m = n.sub(m, A), A = n.mul(H, T), K = n.mul(v, K), K = n.add(K, A), new u(m, x, K);
|
|
921
921
|
}
|
|
922
922
|
subtract(h) {
|
|
923
923
|
return this.add(h.negate());
|
|
@@ -945,10 +945,10 @@ function rs(e) {
|
|
|
945
945
|
const { endo: g } = t;
|
|
946
946
|
if (!g)
|
|
947
947
|
return b.unsafeLadder(this, h);
|
|
948
|
-
let { k1neg: E, k1: S, k2neg:
|
|
948
|
+
let { k1neg: E, k1: S, k2neg: I, k2: B } = g.splitScalar(h), m = d, x = d, K = this;
|
|
949
949
|
for (; S > ae || B > ae; )
|
|
950
950
|
S & Y && (m = m.add(K)), B & Y && (x = x.add(K)), K = K.double(), S >>= Y, B >>= Y;
|
|
951
|
-
return E && (m = m.negate()),
|
|
951
|
+
return E && (m = m.negate()), I && (x = x.negate()), x = new u(n.mul(x.px, g.beta), x.py, x.pz), m.add(x);
|
|
952
952
|
}
|
|
953
953
|
/**
|
|
954
954
|
* Constant time multiplication.
|
|
@@ -964,12 +964,12 @@ function rs(e) {
|
|
|
964
964
|
let d = h, g, E;
|
|
965
965
|
const { endo: S } = t;
|
|
966
966
|
if (S) {
|
|
967
|
-
const { k1neg:
|
|
968
|
-
let { p: K, f: M } = this.wNAF(B), { p:
|
|
969
|
-
K = b.constTimeNegate(
|
|
967
|
+
const { k1neg: I, k1: B, k2neg: m, k2: x } = S.splitScalar(d);
|
|
968
|
+
let { p: K, f: M } = this.wNAF(B), { p: k, f: A } = this.wNAF(x);
|
|
969
|
+
K = b.constTimeNegate(I, K), k = b.constTimeNegate(m, k), k = new u(n.mul(k.px, S.beta), k.py, k.pz), g = K.add(k), E = M.add(A);
|
|
970
970
|
} else {
|
|
971
|
-
const { p:
|
|
972
|
-
g =
|
|
971
|
+
const { p: I, f: B } = this.wNAF(d);
|
|
972
|
+
g = I, E = B;
|
|
973
973
|
}
|
|
974
974
|
return u.normalizeZ([g, E])[0];
|
|
975
975
|
}
|
|
@@ -980,8 +980,8 @@ function rs(e) {
|
|
|
980
980
|
* @returns non-zero affine point
|
|
981
981
|
*/
|
|
982
982
|
multiplyAndAddUnsafe(h, d, g) {
|
|
983
|
-
const E = u.BASE, S = (B, m) => m === ae || m === Y || !B.equals(E) ? B.multiplyUnsafe(m) : B.multiply(m),
|
|
984
|
-
return
|
|
983
|
+
const E = u.BASE, S = (B, m) => m === ae || m === Y || !B.equals(E) ? B.multiplyUnsafe(m) : B.multiply(m), I = S(this, d).add(S(h, g));
|
|
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: g, pz: E } = this, S = this.is0();
|
|
991
991
|
h == null && (h = S ? n.ONE : n.inv(E));
|
|
992
|
-
const
|
|
992
|
+
const I = n.mul(d, h), B = n.mul(g, h), m = n.mul(E, h);
|
|
993
993
|
if (S)
|
|
994
994
|
return { x: n.ZERO, y: n.ZERO };
|
|
995
995
|
if (!n.eql(m, n.ONE))
|
|
996
996
|
throw new Error("invZ was invalid");
|
|
997
|
-
return { x:
|
|
997
|
+
return { x: I, y: B };
|
|
998
998
|
}
|
|
999
999
|
isTorsionFree() {
|
|
1000
1000
|
const { h, isTorsionFree: d } = t;
|
|
@@ -1012,7 +1012,7 @@ function rs(e) {
|
|
|
1012
1012
|
return this.assertValidity(), r(u, this, h);
|
|
1013
1013
|
}
|
|
1014
1014
|
toHex(h = !0) {
|
|
1015
|
-
return
|
|
1015
|
+
return De(this.toRawBytes(h));
|
|
1016
1016
|
}
|
|
1017
1017
|
}
|
|
1018
1018
|
u.BASE = new u(t.Gx, t.Gy, n.ONE), u.ZERO = new u(n.ZERO, n.ONE, n.ZERO);
|
|
@@ -1051,7 +1051,7 @@ function ss(e) {
|
|
|
1051
1051
|
const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: y } = rs({
|
|
1052
1052
|
...t,
|
|
1053
1053
|
toBytes(w, v, N) {
|
|
1054
|
-
const _ = v.toAffine(), C = n.toBytes(_.x), U =
|
|
1054
|
+
const _ = v.toAffine(), C = n.toBytes(_.x), U = ke;
|
|
1055
1055
|
return N ? U(Uint8Array.from([v.hasEvenY() ? 2 : 3]), C) : U(Uint8Array.from([4]), C, n.toBytes(_.y));
|
|
1056
1056
|
},
|
|
1057
1057
|
fromBytes(w) {
|
|
@@ -1070,7 +1070,7 @@ function ss(e) {
|
|
|
1070
1070
|
} else
|
|
1071
1071
|
throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`);
|
|
1072
1072
|
}
|
|
1073
|
-
}), b = (w) =>
|
|
1073
|
+
}), b = (w) => De(Ne(w, t.nByteLength));
|
|
1074
1074
|
function p(w) {
|
|
1075
1075
|
const v = r >> Y;
|
|
1076
1076
|
return w > v;
|
|
@@ -1110,7 +1110,7 @@ function ss(e) {
|
|
|
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), Ue = c(-U * ge),
|
|
1113
|
+
const $ = C & 1 ? "03" : "02", Q = l.fromHex($ + b(O)), ge = a(O), Ue = c(-U * ge), We = c(_ * ge), we = l.BASE.multiplyAndAddUnsafe(Q, Ue, We);
|
|
1114
1114
|
if (!we)
|
|
1115
1115
|
throw new Error("point at infinify");
|
|
1116
1116
|
return we.assertValidity(), we;
|
|
@@ -1124,14 +1124,14 @@ function ss(e) {
|
|
|
1124
1124
|
}
|
|
1125
1125
|
// DER-encoded
|
|
1126
1126
|
toDERRawBytes() {
|
|
1127
|
-
return
|
|
1127
|
+
return je(this.toDERHex());
|
|
1128
1128
|
}
|
|
1129
1129
|
toDERHex() {
|
|
1130
1130
|
return Be.hexFromSig({ r: this.r, s: this.s });
|
|
1131
1131
|
}
|
|
1132
1132
|
// padded bytes of r, then padded bytes of s
|
|
1133
1133
|
toCompactRawBytes() {
|
|
1134
|
-
return
|
|
1134
|
+
return je(this.toCompactHex());
|
|
1135
1135
|
}
|
|
1136
1136
|
toCompactHex() {
|
|
1137
1137
|
return b(this.r) + b(this.s);
|
|
@@ -1169,14 +1169,14 @@ function ss(e) {
|
|
|
1169
1169
|
function S(w, v = !0) {
|
|
1170
1170
|
return l.fromPrivateKey(w).toRawBytes(v);
|
|
1171
1171
|
}
|
|
1172
|
-
function
|
|
1172
|
+
function I(w) {
|
|
1173
1173
|
const v = w instanceof Uint8Array, N = typeof w == "string", _ = (v || N) && w.length;
|
|
1174
1174
|
return v ? _ === i || _ === s : N ? _ === 2 * i || _ === 2 * s : w instanceof l;
|
|
1175
1175
|
}
|
|
1176
1176
|
function B(w, v, N = !0) {
|
|
1177
|
-
if (
|
|
1177
|
+
if (I(w))
|
|
1178
1178
|
throw new Error("first arg must be private key");
|
|
1179
|
-
if (!
|
|
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
|
}
|
|
@@ -1193,7 +1193,7 @@ function ss(e) {
|
|
|
1193
1193
|
throw new Error(`bigint expected < 2^${t.nBitLength}`);
|
|
1194
1194
|
return Ne(w, t.nByteLength);
|
|
1195
1195
|
}
|
|
1196
|
-
function
|
|
1196
|
+
function k(w, v, N = A) {
|
|
1197
1197
|
if (["recovered", "canonical"].some((Ae) => Ae in N))
|
|
1198
1198
|
throw new Error("sign() legacy options not supported");
|
|
1199
1199
|
const { hash: _, randomBytes: C } = t;
|
|
@@ -1204,7 +1204,7 @@ function ss(e) {
|
|
|
1204
1204
|
const Ae = $ === !0 ? C(n.BYTES) : $;
|
|
1205
1205
|
Ue.push(Z("extraEntropy", Ae));
|
|
1206
1206
|
}
|
|
1207
|
-
const
|
|
1207
|
+
const We = ke(...Ue), we = Q;
|
|
1208
1208
|
function Et(Ae) {
|
|
1209
1209
|
const Le = m(Ae);
|
|
1210
1210
|
if (!y(Le))
|
|
@@ -1218,11 +1218,11 @@ function ss(e) {
|
|
|
1218
1218
|
let Kn = ($e.x === ee ? 0 : 2) | Number($e.y & Y), Nn = Te;
|
|
1219
1219
|
return U && p(Te) && (Nn = h(Te), Kn ^= 1), new g(ee, Nn, Kn);
|
|
1220
1220
|
}
|
|
1221
|
-
return { seed:
|
|
1221
|
+
return { seed: We, k2sig: Et };
|
|
1222
1222
|
}
|
|
1223
1223
|
const A = { lowS: t.lowS, prehash: !1 }, T = { lowS: t.lowS, prehash: !1 };
|
|
1224
1224
|
function R(w, v, N = A) {
|
|
1225
|
-
const { seed: _, k2sig: C } =
|
|
1225
|
+
const { seed: _, k2sig: C } = k(w, v, N), U = t;
|
|
1226
1226
|
return Jn(U.hash.outputLen, U.nByteLength, U.hmac)(_, C);
|
|
1227
1227
|
}
|
|
1228
1228
|
l.BASE._setWindowSize(8);
|
|
@@ -1256,7 +1256,7 @@ function ss(e) {
|
|
|
1256
1256
|
if (U && $.hasHighS())
|
|
1257
1257
|
return !1;
|
|
1258
1258
|
O && (v = t.hash(v));
|
|
1259
|
-
const { r: ge, s: Ue } = $,
|
|
1259
|
+
const { r: ge, s: Ue } = $, We = x(v), we = a(Ue), Et = c(We * we), Ae = c(ge * we), Le = ($e = l.BASE.multiplyAndAddUnsafe(Q, Et, Ae)) == null ? void 0 : $e.toAffine();
|
|
1260
1260
|
return Le ? c(Le.x) === ge : !1;
|
|
1261
1261
|
}
|
|
1262
1262
|
return {
|
|
@@ -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),
|
|
1323
|
+
const ct = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), tt = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), rr = BigInt(1), nt = BigInt(2), kn = (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, y = J(u, n, t) * f % t, b = J(y, 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, g = J(d, a, t) * d % t, E = J(g, c, t) * h % t, S = J(E, n, t) * f % 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, y = J(u, n, t) * f % t, b = J(y, 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, g = J(d, a, t) * d % t, E = J(g, c, t) * h % t, S = J(E, n, t) * f % t, I = J(S, o, t) * p % t, B = J(I, r, t) * l % t, m = J(B, nt, t);
|
|
1326
1326
|
if (!Rt.eql(Rt.sqr(m), e))
|
|
1327
1327
|
throw new Error("Cannot find square root");
|
|
1328
1328
|
return m;
|
|
1329
1329
|
}
|
|
1330
|
-
const Rt = Ji(ct, void 0, void 0, { sqrt: ir }),
|
|
1330
|
+
const Rt = Ji(ct, void 0, void 0, { sqrt: ir }), Ie = as({
|
|
1331
1331
|
a: BigInt(0),
|
|
1332
1332
|
b: BigInt(7),
|
|
1333
1333
|
Fp: Rt,
|
|
@@ -1346,7 +1346,7 @@ const Rt = Ji(ct, void 0, void 0, { sqrt: ir }), ke = 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 =
|
|
1349
|
+
const t = tt, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -rr * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), s = n, o = BigInt("0x100000000000000000000000000000000"), c = kn(s * e, t), a = kn(-r * e, t);
|
|
1350
1350
|
let l = W(e - c * n - a * i, t), f = W(-c * r - a * s, t);
|
|
1351
1351
|
const u = l > o, y = f > o;
|
|
1352
1352
|
if (u && (l = t - l), y && (f = t - f), l > o || f > o)
|
|
@@ -1354,18 +1354,18 @@ const Rt = Ji(ct, void 0, void 0, { sqrt: ir }), ke = as({
|
|
|
1354
1354
|
return { k1neg: u, k1: l, k2neg: y, k2: f };
|
|
1355
1355
|
}
|
|
1356
1356
|
}
|
|
1357
|
-
}, Lt), ut = BigInt(0), sr = (e) => typeof e == "bigint" && ut < e && e < ct, cs = (e) => typeof e == "bigint" && ut < e && e < tt,
|
|
1357
|
+
}, Lt), ut = BigInt(0), sr = (e) => typeof e == "bigint" && ut < e && e < ct, cs = (e) => typeof e == "bigint" && ut < e && e < tt, In = {};
|
|
1358
1358
|
function rt(e, ...t) {
|
|
1359
|
-
let n =
|
|
1359
|
+
let n = In[e];
|
|
1360
1360
|
if (n === void 0) {
|
|
1361
1361
|
const r = Lt(Uint8Array.from(e, (i) => i.charCodeAt(0)));
|
|
1362
|
-
n =
|
|
1362
|
+
n = ke(r, r), In[e] = n;
|
|
1363
1363
|
}
|
|
1364
|
-
return Lt(
|
|
1364
|
+
return Lt(ke(n, ...t));
|
|
1365
1365
|
}
|
|
1366
|
-
const Yt = (e) => e.toRawBytes(!0).slice(1), Ot = (e) => Ne(e, 32), At = (e) => W(e, ct), Fe = (e) => W(e, tt), Xt =
|
|
1366
|
+
const Yt = (e) => e.toRawBytes(!0).slice(1), Ot = (e) => Ne(e, 32), At = (e) => W(e, ct), Fe = (e) => W(e, tt), Xt = Ie.ProjectivePoint, us = (e, t, n) => Xt.BASE.multiplyAndAddUnsafe(e, t, n);
|
|
1367
1367
|
function Pt(e) {
|
|
1368
|
-
let t =
|
|
1368
|
+
let t = Ie.utils.normPrivateKeyToScalar(e), n = Xt.fromPrivateKey(t);
|
|
1369
1369
|
return { scalar: n.hasEvenY() ? t : Fe(-t), bytes: Yt(n) };
|
|
1370
1370
|
}
|
|
1371
1371
|
function or(e) {
|
|
@@ -1407,12 +1407,12 @@ function cr(e, t, n) {
|
|
|
1407
1407
|
return !1;
|
|
1408
1408
|
}
|
|
1409
1409
|
}
|
|
1410
|
-
const
|
|
1410
|
+
const Ze = {
|
|
1411
1411
|
getPublicKey: ls,
|
|
1412
1412
|
sign: fs,
|
|
1413
1413
|
verify: cr,
|
|
1414
1414
|
utils: {
|
|
1415
|
-
randomPrivateKey:
|
|
1415
|
+
randomPrivateKey: Ie.utils.randomPrivateKey,
|
|
1416
1416
|
lift_x: or,
|
|
1417
1417
|
pointToBytes: Yt,
|
|
1418
1418
|
numberToBytesBE: Ne,
|
|
@@ -1694,7 +1694,7 @@ class Ns extends dr {
|
|
|
1694
1694
|
const fe = lr(() => new dr());
|
|
1695
1695
|
lr(() => new Ns());
|
|
1696
1696
|
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1697
|
-
function
|
|
1697
|
+
function Ve(e) {
|
|
1698
1698
|
if (!Number.isSafeInteger(e))
|
|
1699
1699
|
throw new Error(`Wrong integer: ${e}`);
|
|
1700
1700
|
}
|
|
@@ -1708,7 +1708,7 @@ function ye(e) {
|
|
|
1708
1708
|
if (!Array.isArray(t) || t.length && typeof t[0] != "number")
|
|
1709
1709
|
throw new Error("alphabet.encode input should be an array of numbers");
|
|
1710
1710
|
return t.map((n) => {
|
|
1711
|
-
if (
|
|
1711
|
+
if (Ve(n), n < 0 || n >= e.length)
|
|
1712
1712
|
throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${e.length})`);
|
|
1713
1713
|
return e[n];
|
|
1714
1714
|
});
|
|
@@ -1747,7 +1747,7 @@ function pe(e = "") {
|
|
|
1747
1747
|
};
|
|
1748
1748
|
}
|
|
1749
1749
|
function ft(e, t = "=") {
|
|
1750
|
-
if (
|
|
1750
|
+
if (Ve(e), typeof t != "string")
|
|
1751
1751
|
throw new Error("padding chr should be string");
|
|
1752
1752
|
return {
|
|
1753
1753
|
encode(n) {
|
|
@@ -1793,7 +1793,7 @@ function Un(e, t, n) {
|
|
|
1793
1793
|
let r = 0;
|
|
1794
1794
|
const i = [], s = Array.from(e);
|
|
1795
1795
|
for (s.forEach((o) => {
|
|
1796
|
-
if (
|
|
1796
|
+
if (Ve(o), o < 0 || o >= t)
|
|
1797
1797
|
throw new Error(`Wrong integer: ${o}`);
|
|
1798
1798
|
}); ; ) {
|
|
1799
1799
|
let o = 0, c = !0;
|
|
@@ -1827,7 +1827,7 @@ function Ht(e, t, n, r) {
|
|
|
1827
1827
|
let i = 0, s = 0;
|
|
1828
1828
|
const o = 2 ** n - 1, c = [];
|
|
1829
1829
|
for (const a of e) {
|
|
1830
|
-
if (
|
|
1830
|
+
if (Ve(a), a >= 2 ** t)
|
|
1831
1831
|
throw new Error(`convertRadix2: invalid data word=${a} from=${t}`);
|
|
1832
1832
|
if (i = i << t | a, s + t > 32)
|
|
1833
1833
|
throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);
|
|
@@ -1842,7 +1842,7 @@ function Ht(e, t, n, r) {
|
|
|
1842
1842
|
return r && s > 0 && c.push(i >>> 0), c;
|
|
1843
1843
|
}
|
|
1844
1844
|
function Ss(e) {
|
|
1845
|
-
return
|
|
1845
|
+
return Ve(e), {
|
|
1846
1846
|
encode: (t) => {
|
|
1847
1847
|
if (!(t instanceof Uint8Array))
|
|
1848
1848
|
throw new Error("radix.encode input should be Uint8Array");
|
|
@@ -1856,7 +1856,7 @@ function Ss(e) {
|
|
|
1856
1856
|
};
|
|
1857
1857
|
}
|
|
1858
1858
|
function Se(e, t = !1) {
|
|
1859
|
-
if (
|
|
1859
|
+
if (Ve(e), e <= 0 || e > 32)
|
|
1860
1860
|
throw new Error("radix2: bits should be in (0..32]");
|
|
1861
1861
|
if (it(8, e) > 32 || it(e, 8) > 32)
|
|
1862
1862
|
throw new Error("radix2: carry overflow");
|
|
@@ -1910,7 +1910,7 @@ const $n = [0, 2, 3, 5, 6, 7, 9, 10, 11], _s = {
|
|
|
1910
1910
|
return Uint8Array.from(t);
|
|
1911
1911
|
}
|
|
1912
1912
|
}, Dt = de(ye("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), pe("")), Tn = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
1913
|
-
function
|
|
1913
|
+
function Ge(e) {
|
|
1914
1914
|
const t = e >> 25;
|
|
1915
1915
|
let n = (e & 33554431) << 5;
|
|
1916
1916
|
for (let r = 0; r < Tn.length; r++)
|
|
@@ -1924,15 +1924,15 @@ function Rn(e, t, n = 1) {
|
|
|
1924
1924
|
const o = e.charCodeAt(s);
|
|
1925
1925
|
if (o < 33 || o > 126)
|
|
1926
1926
|
throw new Error(`Invalid prefix (${e})`);
|
|
1927
|
-
i =
|
|
1927
|
+
i = Ge(i) ^ o >> 5;
|
|
1928
1928
|
}
|
|
1929
|
-
i =
|
|
1929
|
+
i = Ge(i);
|
|
1930
1930
|
for (let s = 0; s < r; s++)
|
|
1931
|
-
i =
|
|
1931
|
+
i = Ge(i) ^ e.charCodeAt(s) & 31;
|
|
1932
1932
|
for (let s of t)
|
|
1933
|
-
i =
|
|
1933
|
+
i = Ge(i) ^ s;
|
|
1934
1934
|
for (let s = 0; s < 6; s++)
|
|
1935
|
-
i =
|
|
1935
|
+
i = Ge(i);
|
|
1936
1936
|
return i ^= n, Dt.encode(Ht([i % 2 ** 30], 30, 5, !1));
|
|
1937
1937
|
}
|
|
1938
1938
|
function gr(e) {
|
|
@@ -1974,18 +1974,18 @@ function gr(e) {
|
|
|
1974
1974
|
}
|
|
1975
1975
|
return { encode: o, decode: c, decodeToBytes: l, decodeUnsafe: a, fromWords: r, fromWordsUnsafe: s, toWords: i };
|
|
1976
1976
|
}
|
|
1977
|
-
const
|
|
1977
|
+
const ze = gr("bech32");
|
|
1978
1978
|
gr("bech32m");
|
|
1979
|
-
const
|
|
1979
|
+
const ks = {
|
|
1980
1980
|
encode: (e) => new TextDecoder().decode(e),
|
|
1981
1981
|
decode: (e) => new TextEncoder().encode(e)
|
|
1982
|
-
},
|
|
1982
|
+
}, Is = de(Se(4), ye("0123456789abcdef"), pe(""), yr((e) => {
|
|
1983
1983
|
if (typeof e != "string" || e.length % 2)
|
|
1984
1984
|
throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);
|
|
1985
1985
|
return e.toLowerCase();
|
|
1986
1986
|
})), Us = {
|
|
1987
|
-
utf8:
|
|
1988
|
-
hex:
|
|
1987
|
+
utf8: ks,
|
|
1988
|
+
hex: Is,
|
|
1989
1989
|
base16: As,
|
|
1990
1990
|
base32: Cs,
|
|
1991
1991
|
base64: he,
|
|
@@ -2032,7 +2032,7 @@ const Os = /* @__NO_SIDE_EFFECTS__ */ (e, t) => (Object.assign(t, e), t), Ke = 1
|
|
|
2032
2032
|
function tn(e) {
|
|
2033
2033
|
return e << 1 ^ Ps & -(e >> 7);
|
|
2034
2034
|
}
|
|
2035
|
-
function
|
|
2035
|
+
function He(e, t) {
|
|
2036
2036
|
let n = 0;
|
|
2037
2037
|
for (; t > 0; t >>= 1)
|
|
2038
2038
|
n ^= e & -(t & 1), e = tn(e);
|
|
@@ -2049,11 +2049,11 @@ const jt = /* @__PURE__ */ (() => {
|
|
|
2049
2049
|
r |= r << 8, t[e[n]] = (r ^ r >> 4 ^ r >> 5 ^ r >> 6 ^ r >> 7 ^ 99) & 255;
|
|
2050
2050
|
}
|
|
2051
2051
|
return t;
|
|
2052
|
-
})(), Ms = /* @__PURE__ */ jt.map((e, t) => jt.indexOf(t)), Hs = (e) => e << 24 | e >>> 8,
|
|
2052
|
+
})(), Ms = /* @__PURE__ */ jt.map((e, t) => jt.indexOf(t)), Hs = (e) => e << 24 | e >>> 8, kt = (e) => e << 8 | e >>> 24;
|
|
2053
2053
|
function wr(e, t) {
|
|
2054
2054
|
if (e.length !== 256)
|
|
2055
2055
|
throw new Error("Wrong sbox length");
|
|
2056
|
-
const n = new Uint32Array(256).map((l, f) => t(e[f])), r = n.map(
|
|
2056
|
+
const n = new Uint32Array(256).map((l, f) => t(e[f])), r = n.map(kt), i = r.map(kt), s = i.map(kt), o = new Uint32Array(256 * 256), c = new Uint32Array(256 * 256), a = new Uint16Array(256 * 256);
|
|
2057
2057
|
for (let l = 0; l < 256; l++)
|
|
2058
2058
|
for (let f = 0; f < 256; f++) {
|
|
2059
2059
|
const u = l * 256 + f;
|
|
@@ -2061,7 +2061,7 @@ function wr(e, t) {
|
|
|
2061
2061
|
}
|
|
2062
2062
|
return { sbox: e, sbox2: a, T0: n, T1: r, T2: i, T3: s, T01: o, T23: c };
|
|
2063
2063
|
}
|
|
2064
|
-
const nn = /* @__PURE__ */ wr(jt, (e) =>
|
|
2064
|
+
const nn = /* @__PURE__ */ wr(jt, (e) => He(e, 3) << 24 | e << 16 | e << 8 | He(e, 2)), br = /* @__PURE__ */ wr(Ms, (e) => He(e, 11) << 24 | He(e, 13) << 16 | He(e, 9) << 8 | He(e, 14)), qs = /* @__PURE__ */ (() => {
|
|
2065
2065
|
const e = new Uint8Array(16);
|
|
2066
2066
|
for (let t = 0, n = 1; t < 16; t++, n = tn(n))
|
|
2067
2067
|
e[t] = n;
|
|
@@ -2189,10 +2189,10 @@ const Er = /* @__PURE__ */ Os({ blockSize: 16, nonceLength: 16 }, function(t, n,
|
|
|
2189
2189
|
const c = Ds(t), a = G(n), l = mr(s.length, o), f = G(s), u = G(l);
|
|
2190
2190
|
let y = a[0], b = a[1], p = a[2], h = a[3];
|
|
2191
2191
|
for (let d = 0; d + 4 <= f.length; ) {
|
|
2192
|
-
const g = y, E = b, S = p,
|
|
2192
|
+
const g = y, E = b, S = p, I = h;
|
|
2193
2193
|
y = f[d + 0], b = f[d + 1], p = f[d + 2], h = f[d + 3];
|
|
2194
2194
|
const { s0: B, s1: m, s2: x, s3: K } = js(c, y, b, p, h);
|
|
2195
|
-
u[d++] = B ^ g, u[d++] = m ^ E, u[d++] = x ^ S, u[d++] = K ^
|
|
2195
|
+
u[d++] = B ^ g, u[d++] = m ^ E, u[d++] = x ^ S, u[d++] = K ^ 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 (E !== a.length)
|
|
2257
2257
|
throw new Error(`arx: nonce must be ${E} or 16 bytes`);
|
|
2258
2258
|
if (E !== 12) {
|
|
2259
|
-
const
|
|
2260
|
-
|
|
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 S = G(a);
|
|
2263
2263
|
for (Xs(e, d, g, S, 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], y = t[2], b = t[3], p = t[4], h = t[5], d = t[6], g = t[7], E = i, S = n[0],
|
|
2269
|
+
let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1], y = t[2], b = t[3], p = t[4], h = t[5], d = t[6], g = t[7], E = i, S = n[0], I = n[1], B = n[2], m = o, x = c, K = a, M = l, k = f, A = u, T = y, R = b, H = p, w = h, v = d, N = g, _ = E, C = S, U = I, O = B;
|
|
2270
2270
|
for (let Q = 0; Q < s; Q += 2)
|
|
2271
|
-
m = m +
|
|
2271
|
+
m = m + k | 0, _ = L(_ ^ m, 16), H = H + _ | 0, k = L(k ^ H, 12), m = m + k | 0, _ = L(_ ^ m, 8), H = H + _ | 0, k = L(k ^ H, 7), x = x + A | 0, C = L(C ^ x, 16), w = w + C | 0, A = L(A ^ w, 12), x = x + A | 0, C = L(C ^ x, 8), w = w + C | 0, A = L(A ^ w, 7), K = K + T | 0, U = L(U ^ K, 16), v = v + U | 0, T = L(T ^ v, 12), K = K + T | 0, U = L(U ^ K, 8), v = v + U | 0, T = L(T ^ v, 7), M = M + R | 0, O = L(O ^ M, 16), N = N + O | 0, R = L(R ^ N, 12), M = M + R | 0, O = L(O ^ M, 8), N = N + O | 0, R = L(R ^ N, 7), m = m + A | 0, O = L(O ^ m, 16), v = v + O | 0, A = L(A ^ v, 12), m = m + A | 0, O = L(O ^ m, 8), v = v + O | 0, A = L(A ^ v, 7), x = x + T | 0, _ = L(_ ^ x, 16), N = N + _ | 0, T = L(T ^ N, 12), x = x + T | 0, _ = L(_ ^ x, 8), N = N + _ | 0, T = L(T ^ N, 7), K = K + R | 0, C = L(C ^ K, 16), H = H + C | 0, R = L(R ^ H, 12), K = K + R | 0, C = L(C ^ K, 8), H = H + C | 0, R = L(R ^ H, 7), M = M + k | 0, U = L(U ^ M, 16), w = w + U | 0, k = L(k ^ w, 12), M = M + k | 0, U = L(U ^ M, 8), w = w + U | 0, k = L(k ^ w, 7);
|
|
2272
2272
|
let $ = 0;
|
|
2273
|
-
r[$++] = o + m | 0, r[$++] = c + x | 0, r[$++] = a + K | 0, r[$++] = l + M | 0, r[$++] = f +
|
|
2273
|
+
r[$++] = o + m | 0, r[$++] = c + x | 0, r[$++] = a + K | 0, r[$++] = l + M | 0, r[$++] = f + k | 0, r[$++] = u + A | 0, r[$++] = y + T | 0, r[$++] = b + R | 0, r[$++] = p + H | 0, r[$++] = h + w | 0, r[$++] = d + v | 0, r[$++] = g + N | 0, r[$++] = E + _ | 0, r[$++] = S + C | 0, r[$++] = I + U | 0, r[$++] = B + O | 0;
|
|
2274
2274
|
}
|
|
2275
2275
|
const Sr = /* @__PURE__ */ Qs(eo, {
|
|
2276
2276
|
counterRight: !1,
|
|
@@ -2317,7 +2317,7 @@ ht.create = (e, t) => new Ar(e, t);
|
|
|
2317
2317
|
function rn(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
|
|
2320
|
+
const It = new Uint8Array([0]), Hn = 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 = Hn);
|
|
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
|
-
|
|
2329
|
-
return o.destroy(), c.destroy(), a.fill(0),
|
|
2328
|
+
It[0] = l + 1, c.update(l === 0 ? Hn : 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)
|
|
@@ -2409,23 +2409,23 @@ var Br = class {
|
|
|
2409
2409
|
}
|
|
2410
2410
|
}, co = class {
|
|
2411
2411
|
generateSecretKey() {
|
|
2412
|
-
return
|
|
2412
|
+
return Ze.utils.randomPrivateKey();
|
|
2413
2413
|
}
|
|
2414
2414
|
getPublicKey(e) {
|
|
2415
|
-
return P(
|
|
2415
|
+
return P(Ze.getPublicKey(e));
|
|
2416
2416
|
}
|
|
2417
2417
|
finalizeEvent(e, t) {
|
|
2418
2418
|
const n = e;
|
|
2419
|
-
return n.pubkey = P(
|
|
2419
|
+
return n.pubkey = P(Ze.getPublicKey(t)), n.id = qe(n), n.sig = P(Ze.sign(qe(n), t)), n[Re] = !0, n;
|
|
2420
2420
|
}
|
|
2421
2421
|
verifyEvent(e) {
|
|
2422
2422
|
if (typeof e[Re] == "boolean")
|
|
2423
2423
|
return e[Re];
|
|
2424
|
-
const t =
|
|
2424
|
+
const t = qe(e);
|
|
2425
2425
|
if (t !== e.id)
|
|
2426
2426
|
return e[Re] = !1, !1;
|
|
2427
2427
|
try {
|
|
2428
|
-
const n =
|
|
2428
|
+
const n = Ze.verify(e.sig, t, e.pubkey);
|
|
2429
2429
|
return e[Re] = n, n;
|
|
2430
2430
|
} catch {
|
|
2431
2431
|
return e[Re] = !1, !1;
|
|
@@ -2437,7 +2437,7 @@ function uo(e) {
|
|
|
2437
2437
|
throw new Error("can't serialize event with wrong or missing properties");
|
|
2438
2438
|
return JSON.stringify([0, e.pubkey, e.created_at, e.kind, e.tags, e.content]);
|
|
2439
2439
|
}
|
|
2440
|
-
function
|
|
2440
|
+
function qe(e) {
|
|
2441
2441
|
let t = fe(ne.encode(uo(e)));
|
|
2442
2442
|
return P(t);
|
|
2443
2443
|
}
|
|
@@ -2460,7 +2460,7 @@ D(lo, {
|
|
|
2460
2460
|
ClientAuth: () => Hr,
|
|
2461
2461
|
CommunitiesList: () => Do,
|
|
2462
2462
|
CommunityDefinition: () => Na,
|
|
2463
|
-
CommunityPostApproval: () =>
|
|
2463
|
+
CommunityPostApproval: () => ko,
|
|
2464
2464
|
Contacts: () => wo,
|
|
2465
2465
|
CreateOrUpdateProduct: () => ua,
|
|
2466
2466
|
CreateOrUpdateStall: () => ca,
|
|
@@ -2485,7 +2485,7 @@ D(lo, {
|
|
|
2485
2485
|
InterestsList: () => Wo,
|
|
2486
2486
|
Interestsets: () => aa,
|
|
2487
2487
|
JobFeedback: () => Lo,
|
|
2488
|
-
JobRequest: () =>
|
|
2488
|
+
JobRequest: () => Io,
|
|
2489
2489
|
JobResult: () => Uo,
|
|
2490
2490
|
Label: () => _o,
|
|
2491
2491
|
LightningPubRPC: () => Yo,
|
|
@@ -2521,32 +2521,32 @@ D(lo, {
|
|
|
2521
2521
|
ZapGoal: () => $o,
|
|
2522
2522
|
ZapRequest: () => To,
|
|
2523
2523
|
classifyKind: () => fo,
|
|
2524
|
-
isEphemeralKind: () =>
|
|
2524
|
+
isEphemeralKind: () => Ir,
|
|
2525
2525
|
isKind: () => ho,
|
|
2526
2526
|
isParameterizedReplaceableKind: () => Ur,
|
|
2527
2527
|
isRegularKind: () => _r,
|
|
2528
|
-
isReplaceableKind: () =>
|
|
2528
|
+
isReplaceableKind: () => kr
|
|
2529
2529
|
});
|
|
2530
2530
|
function _r(e) {
|
|
2531
2531
|
return 1e3 <= e && e < 1e4 || [1, 2, 4, 5, 6, 7, 8, 16, 40, 41, 42, 43, 44].includes(e);
|
|
2532
2532
|
}
|
|
2533
|
-
function
|
|
2533
|
+
function kr(e) {
|
|
2534
2534
|
return [0, 3].includes(e) || 1e4 <= e && e < 2e4;
|
|
2535
2535
|
}
|
|
2536
|
-
function
|
|
2536
|
+
function Ir(e) {
|
|
2537
2537
|
return 2e4 <= e && e < 3e4;
|
|
2538
2538
|
}
|
|
2539
2539
|
function Ur(e) {
|
|
2540
2540
|
return 3e4 <= e && e < 4e4;
|
|
2541
2541
|
}
|
|
2542
2542
|
function fo(e) {
|
|
2543
|
-
return _r(e) ? "regular" :
|
|
2543
|
+
return _r(e) ? "regular" : kr(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 yo = 0, po = 1, go = 2, wo = 3, bo = 4, vo = 5, on = 6, an = 7, mo = 8, Lr = 13, Eo = 14, xo = 16, $r = 40, Tr = 41, Rr = 42, Or = 43, Pr = 44, Ko = 1040, Mr = 1059, No = 1063, So = 1311, Ao = 1971, Co = 1984, Bo = 1984, _o = 1985,
|
|
2549
|
+
var yo = 0, po = 1, go = 2, wo = 3, bo = 4, vo = 5, on = 6, an = 7, mo = 8, Lr = 13, Eo = 14, xo = 16, $r = 40, Tr = 41, Rr = 42, Or = 43, Pr = 44, Ko = 1040, Mr = 1059, No = 1063, So = 1311, Ao = 1971, Co = 1984, Bo = 1984, _o = 1985, ko = 4550, Io = 5999, Uo = 6999, Lo = 7e3, $o = 9041, To = 9734, Ro = 9735, Oo = 9802, Po = 1e4, Mo = 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, cn = 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, ya = 30311, pa = 30315, ga = 30402, wa = 30403, ba = 31922, va = 31923, ma = 31924, Ea = 31925, xa = 31989, Ka = 31990, Na = 34550, Sa = {};
|
|
2550
2550
|
D(Sa, {
|
|
2551
2551
|
getHex64: () => un,
|
|
2552
2552
|
getInt: () => Dr,
|
|
@@ -2585,11 +2585,11 @@ function Ba(e, t) {
|
|
|
2585
2585
|
function _a(e, t) {
|
|
2586
2586
|
return t === Dr(e, "kind");
|
|
2587
2587
|
}
|
|
2588
|
-
var
|
|
2589
|
-
D(
|
|
2590
|
-
makeAuthEvent: () =>
|
|
2588
|
+
var ka = {};
|
|
2589
|
+
D(ka, {
|
|
2590
|
+
makeAuthEvent: () => Ia
|
|
2591
2591
|
});
|
|
2592
|
-
function
|
|
2592
|
+
function Ia(e, t) {
|
|
2593
2593
|
return {
|
|
2594
2594
|
kind: Hr,
|
|
2595
2595
|
created_at: Math.floor(Date.now() / 1e3),
|
|
@@ -2639,7 +2639,7 @@ function Ra(e) {
|
|
|
2639
2639
|
}
|
|
2640
2640
|
function gt(e) {
|
|
2641
2641
|
var i, s, o, c, a, l, f;
|
|
2642
|
-
let { prefix: t, words: n } =
|
|
2642
|
+
let { prefix: t, words: n } = ze.decode(e, ln), r = new Uint8Array(ze.fromWords(n));
|
|
2643
2643
|
switch (t) {
|
|
2644
2644
|
case "nprofile": {
|
|
2645
2645
|
let u = Ut(r);
|
|
@@ -2726,8 +2726,8 @@ function Ma(e) {
|
|
|
2726
2726
|
return bt("note", z(e));
|
|
2727
2727
|
}
|
|
2728
2728
|
function wt(e, t) {
|
|
2729
|
-
let n =
|
|
2730
|
-
return
|
|
2729
|
+
let n = ze.toWords(t);
|
|
2730
|
+
return ze.encode(e, n, ln);
|
|
2731
2731
|
}
|
|
2732
2732
|
function bt(e, t) {
|
|
2733
2733
|
return wt(e, t);
|
|
@@ -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 ? P(e) : e, i =
|
|
2779
|
+
const r = e instanceof Uint8Array ? P(e) : e, i = Ie.getSharedSecret(r, "02" + t), s = Vr(i);
|
|
2780
2780
|
let o = Uint8Array.from(fr(16)), c = ne.encode(n), a = Er(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 ? P(e) : e;
|
|
2785
|
-
let [i, s] = n.split("?iv="), o =
|
|
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 = Er(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: () => vn,
|
|
3225
3225
|
encrypt: () => bn,
|
|
3226
3226
|
getConversationKey: () => gn,
|
|
3227
|
-
v2: () =>
|
|
3227
|
+
v2: () => Ic
|
|
3228
3228
|
});
|
|
3229
3229
|
var Xr = 1, Qr = 65535;
|
|
3230
3230
|
function gn(e, t) {
|
|
3231
|
-
const n =
|
|
3231
|
+
const n = Ie.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3232
3232
|
return rn(fe, n, "nip44-v2");
|
|
3233
3233
|
}
|
|
3234
3234
|
function ei(e, t) {
|
|
@@ -3269,7 +3269,7 @@ function ti(e, t, n) {
|
|
|
3269
3269
|
const r = lt(n, t);
|
|
3270
3270
|
return ht(fe, e, r);
|
|
3271
3271
|
}
|
|
3272
|
-
function
|
|
3272
|
+
function kc(e) {
|
|
3273
3273
|
if (typeof e != "string")
|
|
3274
3274
|
throw new Error("payload must be a valid string");
|
|
3275
3275
|
const t = e.length;
|
|
@@ -3300,13 +3300,13 @@ function bn(e, t, n = fr(32)) {
|
|
|
3300
3300
|
return he.encode(lt(new Uint8Array([2]), n, c, a));
|
|
3301
3301
|
}
|
|
3302
3302
|
function vn(e, t) {
|
|
3303
|
-
const { nonce: n, ciphertext: r, mac: i } =
|
|
3303
|
+
const { nonce: n, ciphertext: r, mac: i } = kc(e), { chacha_key: s, chacha_nonce: o, hmac_key: c } = ei(t, n), a = ti(c, r, n);
|
|
3304
3304
|
if (!Rs(a, i))
|
|
3305
3305
|
throw new Error("invalid MAC");
|
|
3306
3306
|
const l = Sr(s, o, r);
|
|
3307
3307
|
return _c(l);
|
|
3308
3308
|
}
|
|
3309
|
-
var
|
|
3309
|
+
var Ic = {
|
|
3310
3310
|
utils: {
|
|
3311
3311
|
getConversationKey: gn,
|
|
3312
3312
|
calcPaddedLen: wn
|
|
@@ -3358,7 +3358,7 @@ async function Oc(e) {
|
|
|
3358
3358
|
try {
|
|
3359
3359
|
let t = "", { lud06: n, lud16: r } = JSON.parse(e.content);
|
|
3360
3360
|
if (n) {
|
|
3361
|
-
let { words: o } =
|
|
3361
|
+
let { words: o } = ze.decode(n, 1e3), c = ze.fromWords(o);
|
|
3362
3362
|
t = ue.decode(c);
|
|
3363
3363
|
} else if (r) {
|
|
3364
3364
|
let [o, c] = r.split("@");
|
|
@@ -3447,7 +3447,7 @@ function oi(e, t) {
|
|
|
3447
3447
|
...e,
|
|
3448
3448
|
pubkey: le(t)
|
|
3449
3449
|
};
|
|
3450
|
-
return n.id =
|
|
3450
|
+
return n.id = qe(n), n;
|
|
3451
3451
|
}
|
|
3452
3452
|
function ai(e, t, n) {
|
|
3453
3453
|
return X(
|
|
@@ -3579,7 +3579,7 @@ async function wi(e, t, n, r) {
|
|
|
3579
3579
|
throw new Error("Invalid nostr event, payload tag does not match request body hash");
|
|
3580
3580
|
return !0;
|
|
3581
3581
|
}
|
|
3582
|
-
const
|
|
3582
|
+
const Oe = 30078, Dn = 30078, jn = 1059, Gc = 14, au = 100, Fc = 1;
|
|
3583
3583
|
function cu(e) {
|
|
3584
3584
|
return JSON.stringify({
|
|
3585
3585
|
version: Fc,
|
|
@@ -3693,7 +3693,7 @@ async function* lu(e) {
|
|
|
3693
3693
|
r();
|
|
3694
3694
|
}
|
|
3695
3695
|
}
|
|
3696
|
-
function
|
|
3696
|
+
function Pe(e, t = new Uint8Array(32), n = 1) {
|
|
3697
3697
|
const r = rn(fe, e, t), i = [];
|
|
3698
3698
|
for (let s = 1; s <= n; s++)
|
|
3699
3699
|
i.push(Cr(fe, r, new Uint8Array([s]), 32));
|
|
@@ -3729,7 +3729,7 @@ class st {
|
|
|
3729
3729
|
* @returns A new Session instance
|
|
3730
3730
|
*/
|
|
3731
3731
|
static init(t, n, r, i, s, o) {
|
|
3732
|
-
const c = _e(), [a, l] =
|
|
3732
|
+
const c = _e(), [a, l] = Pe(s, q.getConversationKey(c, n), 2);
|
|
3733
3733
|
let f, u;
|
|
3734
3734
|
i ? (f = { publicKey: le(r), privateKey: r }, u = { publicKey: le(c), privateKey: c }) : u = { publicKey: le(r), privateKey: r };
|
|
3735
3735
|
const y = {
|
|
@@ -3774,16 +3774,16 @@ class st {
|
|
|
3774
3774
|
const n = Date.now(), r = {
|
|
3775
3775
|
...t,
|
|
3776
3776
|
content: t.content || "",
|
|
3777
|
-
kind: t.kind ||
|
|
3777
|
+
kind: t.kind || Oe,
|
|
3778
3778
|
created_at: t.created_at || Math.floor(n / 1e3),
|
|
3779
3779
|
tags: t.tags || [],
|
|
3780
3780
|
pubkey: t.pubkey || Yc
|
|
3781
3781
|
};
|
|
3782
|
-
r.tags.some(([l]) => l === "ms") || r.tags.push(["ms", String(n)]), r.id =
|
|
3782
|
+
r.tags.some(([l]) => l === "ms") || r.tags.push(["ms", String(n)]), r.id = qe(r);
|
|
3783
3783
|
const [i, s] = this.ratchetEncrypt(JSON.stringify(r)), o = q.getConversationKey(this.state.ourCurrentNostrKey.privateKey, this.state.theirNextNostrPublicKey), c = q.encrypt(JSON.stringify(i), o);
|
|
3784
3784
|
return { event: X({
|
|
3785
3785
|
content: s,
|
|
3786
|
-
kind:
|
|
3786
|
+
kind: Oe,
|
|
3787
3787
|
tags: [["header", c]],
|
|
3788
3788
|
created_at: Math.floor(n / 1e3)
|
|
3789
3789
|
}, this.state.ourCurrentNostrKey.privateKey), innerEvent: r };
|
|
@@ -3806,7 +3806,7 @@ class st {
|
|
|
3806
3806
|
}
|
|
3807
3807
|
// 2. RATCHET FUNCTIONS
|
|
3808
3808
|
ratchetEncrypt(t) {
|
|
3809
|
-
const [n, r] =
|
|
3809
|
+
const [n, r] = Pe(this.state.sendingChainKey, new Uint8Array([1]), 2);
|
|
3810
3810
|
return this.state.sendingChainKey = n, [{
|
|
3811
3811
|
number: this.state.sendingChainMessageNumber++,
|
|
3812
3812
|
nextPublicKey: this.state.ourNextNostrKey.publicKey,
|
|
@@ -3817,7 +3817,7 @@ class st {
|
|
|
3817
3817
|
const i = this.trySkippedMessageKeys(t, n, r);
|
|
3818
3818
|
if (i) return i;
|
|
3819
3819
|
this.skipMessageKeys(t.number, r);
|
|
3820
|
-
const [s, o] =
|
|
3820
|
+
const [s, o] = Pe(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3821
3821
|
this.state.receivingChainKey = s, this.state.receivingChainMessageNumber++;
|
|
3822
3822
|
try {
|
|
3823
3823
|
return q.decrypt(n, o);
|
|
@@ -3832,14 +3832,14 @@ class st {
|
|
|
3832
3832
|
}
|
|
3833
3833
|
ratchetStep(t) {
|
|
3834
3834
|
this.state.previousSendingChainMessageCount = this.state.sendingChainMessageNumber, this.state.sendingChainMessageNumber = 0, this.state.receivingChainMessageNumber = 0, this.state.theirNextNostrPublicKey = t;
|
|
3835
|
-
const n = q.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [r, i] =
|
|
3835
|
+
const n = q.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [r, i] = Pe(this.state.rootKey, n, 2);
|
|
3836
3836
|
this.state.receivingChainKey = i, this.state.ourCurrentNostrKey = this.state.ourNextNostrKey;
|
|
3837
3837
|
const s = _e();
|
|
3838
3838
|
this.state.ourNextNostrKey = {
|
|
3839
3839
|
publicKey: le(s),
|
|
3840
3840
|
privateKey: s
|
|
3841
3841
|
};
|
|
3842
|
-
const o = q.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [c, a] =
|
|
3842
|
+
const o = q.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [c, a] = Pe(r, o, 2);
|
|
3843
3843
|
this.state.rootKey = c, this.state.sendingChainKey = a;
|
|
3844
3844
|
}
|
|
3845
3845
|
// 3. MESSAGE KEY FUNCTIONS
|
|
@@ -3858,16 +3858,15 @@ class st {
|
|
|
3858
3858
|
this.state.skippedKeys[n].headerKeys.push(r);
|
|
3859
3859
|
}
|
|
3860
3860
|
for (; this.state.receivingChainMessageNumber < t; ) {
|
|
3861
|
-
const [r, i] =
|
|
3861
|
+
const [r, i] = Pe(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3862
3862
|
this.state.receivingChainKey = r, this.state.skippedKeys[n].messageKeys[this.state.receivingChainMessageNumber] = i, this.state.receivingChainMessageNumber++;
|
|
3863
3863
|
}
|
|
3864
3864
|
}
|
|
3865
3865
|
trySkippedMessageKeys(t, n, r) {
|
|
3866
|
-
var o;
|
|
3867
3866
|
const i = this.state.skippedKeys[r];
|
|
3868
3867
|
if (!i) return null;
|
|
3869
3868
|
const s = i.messageKeys[t.number];
|
|
3870
|
-
return s ? (delete i.messageKeys[t.number], Object.keys(i.messageKeys).length === 0 &&
|
|
3869
|
+
return s ? (delete i.messageKeys[t.number], Object.keys(i.messageKeys).length === 0 && delete this.state.skippedKeys[r], q.decrypt(n, s)) : null;
|
|
3871
3870
|
}
|
|
3872
3871
|
// 4. NOSTR EVENT HANDLING
|
|
3873
3872
|
decryptHeader(t) {
|
|
@@ -3897,7 +3896,7 @@ class st {
|
|
|
3897
3896
|
var c;
|
|
3898
3897
|
const [n, r, i] = this.decryptHeader(t);
|
|
3899
3898
|
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(
|
|
3900
|
-
{ authors: [this.state.theirNextNostrPublicKey], kinds: [
|
|
3899
|
+
{ authors: [this.state.theirNextNostrPublicKey], kinds: [Oe] },
|
|
3901
3900
|
(a) => this.handleNostrEvent(a)
|
|
3902
3901
|
)), r && (this.skipMessageKeys(n.previousChainLength, t.pubkey), this.ratchetStep(n.nextPublicKey)));
|
|
3903
3902
|
const s = this.ratchetDecrypt(n, t.content, t.pubkey), o = JSON.parse(s);
|
|
@@ -3905,7 +3904,7 @@ class st {
|
|
|
3905
3904
|
console.error("Invalid event received", o);
|
|
3906
3905
|
return;
|
|
3907
3906
|
}
|
|
3908
|
-
if (o.id !==
|
|
3907
|
+
if (o.id !== qe(o)) {
|
|
3909
3908
|
console.error("Event hash does not match", o);
|
|
3910
3909
|
return;
|
|
3911
3910
|
}
|
|
@@ -3914,12 +3913,15 @@ class st {
|
|
|
3914
3913
|
subscribeToNostrEvents() {
|
|
3915
3914
|
if (this.nostrNextUnsubscribe) return;
|
|
3916
3915
|
this.nostrNextUnsubscribe = this.nostrSubscribe(
|
|
3917
|
-
{ authors: [this.state.theirNextNostrPublicKey], kinds: [
|
|
3916
|
+
{ authors: [this.state.theirNextNostrPublicKey], kinds: [Oe] },
|
|
3918
3917
|
(n) => this.handleNostrEvent(n)
|
|
3919
|
-
)
|
|
3918
|
+
), this.state.theirCurrentNostrPublicKey && (this.nostrUnsubscribe = this.nostrSubscribe(
|
|
3919
|
+
{ authors: [this.state.theirCurrentNostrPublicKey], kinds: [Oe] },
|
|
3920
|
+
(n) => this.handleNostrEvent(n)
|
|
3921
|
+
));
|
|
3920
3922
|
const t = Object.keys(this.state.skippedKeys);
|
|
3921
|
-
|
|
3922
|
-
{ authors: t, kinds: [
|
|
3923
|
+
t.length && this.nostrSubscribe(
|
|
3924
|
+
{ authors: t, kinds: [Oe] },
|
|
3923
3925
|
(n) => this.handleNostrEvent(n)
|
|
3924
3926
|
);
|
|
3925
3927
|
}
|
|
@@ -3927,11 +3929,11 @@ class st {
|
|
|
3927
3929
|
new TextDecoder("utf-8");
|
|
3928
3930
|
new TextEncoder();
|
|
3929
3931
|
function Qe(e, t) {
|
|
3930
|
-
const n =
|
|
3932
|
+
const n = Ie.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3931
3933
|
return rn(fe, n, "nip44-v2");
|
|
3932
3934
|
}
|
|
3933
3935
|
const Xc = 2 * 24 * 60 * 60, Qc = () => Math.round(Date.now() / 1e3), eu = () => Math.round(Qc() - Math.random() * Xc);
|
|
3934
|
-
class
|
|
3936
|
+
class Me {
|
|
3935
3937
|
constructor(t, n, r, i, s, o, c = []) {
|
|
3936
3938
|
this.inviterEphemeralPublicKey = t, this.sharedSecret = n, this.inviter = r, this.inviterEphemeralPrivateKey = i, this.label = s, this.maxUses = o, this.usedBy = c;
|
|
3937
3939
|
}
|
|
@@ -3939,7 +3941,7 @@ class Pe {
|
|
|
3939
3941
|
if (!t)
|
|
3940
3942
|
throw new Error("Inviter public key is required");
|
|
3941
3943
|
const i = _e(), s = le(i), o = P(_e());
|
|
3942
|
-
return new
|
|
3944
|
+
return new Me(
|
|
3943
3945
|
s,
|
|
3944
3946
|
o,
|
|
3945
3947
|
t,
|
|
@@ -3962,7 +3964,7 @@ class Pe {
|
|
|
3962
3964
|
const { inviter: o, ephemeralKey: c, sharedSecret: a } = s;
|
|
3963
3965
|
if (!o || !c || !a)
|
|
3964
3966
|
throw new Error("Missing required fields (inviter, ephemeralKey, sharedSecret) in invite data.");
|
|
3965
|
-
return new
|
|
3967
|
+
return new Me(
|
|
3966
3968
|
c,
|
|
3967
3969
|
a,
|
|
3968
3970
|
o
|
|
@@ -3970,7 +3972,7 @@ class Pe {
|
|
|
3970
3972
|
}
|
|
3971
3973
|
static deserialize(t) {
|
|
3972
3974
|
const n = JSON.parse(t);
|
|
3973
|
-
return new
|
|
3975
|
+
return new Me(
|
|
3974
3976
|
n.inviterEphemeralPublicKey,
|
|
3975
3977
|
n.sharedSecret,
|
|
3976
3978
|
n.inviter,
|
|
@@ -3992,7 +3994,7 @@ class Pe {
|
|
|
3992
3994
|
const 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;
|
|
3993
3995
|
if (!r || !i)
|
|
3994
3996
|
throw new Error("Invalid invite event: missing session key or sharedSecret");
|
|
3995
|
-
return new
|
|
3997
|
+
return new Me(
|
|
3996
3998
|
r,
|
|
3997
3999
|
i,
|
|
3998
4000
|
s
|
|
@@ -4010,7 +4012,7 @@ class Pe {
|
|
|
4010
4012
|
if (!(!c.created_at || c.created_at <= s)) {
|
|
4011
4013
|
s = c.created_at;
|
|
4012
4014
|
try {
|
|
4013
|
-
const a =
|
|
4015
|
+
const a = Me.fromEvent(c);
|
|
4014
4016
|
r(a);
|
|
4015
4017
|
} catch (a) {
|
|
4016
4018
|
console.error("Error processing invite:", a, "event:", c);
|
|
@@ -4113,14 +4115,14 @@ export {
|
|
|
4113
4115
|
Gc as CHAT_MESSAGE_KIND,
|
|
4114
4116
|
Dn as INVITE_EVENT_KIND,
|
|
4115
4117
|
jn as INVITE_RESPONSE_KIND,
|
|
4116
|
-
|
|
4118
|
+
Me as Invite,
|
|
4117
4119
|
au as MAX_SKIP,
|
|
4118
|
-
|
|
4120
|
+
Oe as MESSAGE_EVENT_KIND,
|
|
4119
4121
|
st as Session,
|
|
4120
4122
|
lu as createEventStream,
|
|
4121
4123
|
uu as deserializeSessionState,
|
|
4122
4124
|
hu as getMillisecondTimestamp,
|
|
4123
|
-
|
|
4125
|
+
Pe as kdf,
|
|
4124
4126
|
cu as serializeSessionState,
|
|
4125
4127
|
fu as skippedMessageIndexKey
|
|
4126
4128
|
};
|