nostr-double-ratchet 0.0.22 → 0.0.24
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 +1 -0
- package/dist/Session.d.ts.map +1 -1
- package/dist/nostr-double-ratchet.es.js +389 -383
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/package.json +1 -1
- package/src/Session.ts +21 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var bi = Object.defineProperty;
|
|
2
2
|
var vi = (e, t, n) => t in e ? bi(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
-
var
|
|
3
|
+
var J = (e, t, n) => vi(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
4
|
function Sn(e) {
|
|
5
5
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
6
6
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
@@ -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,
|
|
126
|
+
const Bi = (e, t, n) => e & t ^ ~e & n, ki = (e, t, n) => e & t ^ e & n ^ t & n, _i = /* @__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
|
}
|
|
@@ -214,12 +214,12 @@ let ki = class extends Ci {
|
|
|
214
214
|
for (let u = 0; u < 16; u++, n += 4)
|
|
215
215
|
ve[u] = t.getUint32(n, !1);
|
|
216
216
|
for (let u = 16; u < 64; u++) {
|
|
217
|
-
const
|
|
218
|
-
ve[u] = h + ve[u - 7] +
|
|
217
|
+
const p = ve[u - 15], b = ve[u - 2], y = re(p, 7) ^ re(p, 18) ^ p >>> 3, h = re(b, 17) ^ re(b, 19) ^ b >>> 10;
|
|
218
|
+
ve[u] = h + ve[u - 7] + y + ve[u - 16] | 0;
|
|
219
219
|
}
|
|
220
220
|
let { A: r, B: i, C: s, D: o, E: c, F: a, G: l, H: f } = this;
|
|
221
221
|
for (let u = 0; u < 64; u++) {
|
|
222
|
-
const
|
|
222
|
+
const p = re(c, 6) ^ re(c, 11) ^ re(c, 25), b = f + p + Bi(c, a, l) + _i[u] + ve[u] | 0, h = (re(r, 2) ^ re(r, 13) ^ re(r, 22)) + ki(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 _e(...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) => {
|
|
@@ -348,18 +348,18 @@ function Jn(e, t, n) {
|
|
|
348
348
|
if (s++ >= 1e3)
|
|
349
349
|
throw new Error("drbg: tried 1000 values");
|
|
350
350
|
let u = 0;
|
|
351
|
-
const
|
|
351
|
+
const p = [];
|
|
352
352
|
for (; u < t; ) {
|
|
353
353
|
r = c();
|
|
354
354
|
const b = r.slice();
|
|
355
|
-
|
|
355
|
+
p.push(b), u += r.length;
|
|
356
356
|
}
|
|
357
|
-
return
|
|
357
|
+
return _e(...p);
|
|
358
358
|
};
|
|
359
|
-
return (u,
|
|
359
|
+
return (u, p) => {
|
|
360
360
|
o(), a(u);
|
|
361
361
|
let b;
|
|
362
|
-
for (; !(b =
|
|
362
|
+
for (; !(b = p(l())); )
|
|
363
363
|
a();
|
|
364
364
|
return o(), b;
|
|
365
365
|
};
|
|
@@ -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: _e,
|
|
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,
|
|
@@ -430,7 +430,7 @@ function ji(e, t, n) {
|
|
|
430
430
|
t & j && (r = r * e % n), e = e * e % n, t >>= j;
|
|
431
431
|
return r;
|
|
432
432
|
}
|
|
433
|
-
function
|
|
433
|
+
function Y(e, t, n) {
|
|
434
434
|
let r = e;
|
|
435
435
|
for (; t-- > V; )
|
|
436
436
|
r *= r, r %= n;
|
|
@@ -468,15 +468,15 @@ function zi(e) {
|
|
|
468
468
|
return function(c, a) {
|
|
469
469
|
if (c.pow(a, t) === c.neg(c.ONE))
|
|
470
470
|
throw new Error("Cannot find square root");
|
|
471
|
-
let l = r, f = c.pow(c.mul(c.ONE, i), n), u = c.pow(a, s),
|
|
472
|
-
for (; !c.eql(
|
|
473
|
-
if (c.eql(
|
|
471
|
+
let l = r, f = c.pow(c.mul(c.ONE, i), n), u = c.pow(a, s), p = c.pow(a, n);
|
|
472
|
+
for (; !c.eql(p, c.ONE); ) {
|
|
473
|
+
if (c.eql(p, c.ZERO))
|
|
474
474
|
return c.ZERO;
|
|
475
475
|
let b = 1;
|
|
476
|
-
for (let h = c.sqr(
|
|
476
|
+
for (let h = c.sqr(p); b < l && !c.eql(h, c.ONE); b++)
|
|
477
477
|
h = c.sqr(h);
|
|
478
|
-
const
|
|
479
|
-
f = c.sqr(
|
|
478
|
+
const y = c.pow(f, j << BigInt(l - b - 1));
|
|
479
|
+
f = c.sqr(y), u = c.mul(u, y), p = c.mul(p, f), l = b;
|
|
480
480
|
}
|
|
481
481
|
return u;
|
|
482
482
|
};
|
|
@@ -650,7 +650,7 @@ function Qi(e, t) {
|
|
|
650
650
|
let l = i, f = l;
|
|
651
651
|
for (let u = 0; u < o; u++) {
|
|
652
652
|
f = l, a.push(f);
|
|
653
|
-
for (let
|
|
653
|
+
for (let p = 1; p < c; p++)
|
|
654
654
|
f = f.add(l), a.push(f);
|
|
655
655
|
l = f.double();
|
|
656
656
|
}
|
|
@@ -666,13 +666,13 @@ function Qi(e, t) {
|
|
|
666
666
|
wNAF(i, s, o) {
|
|
667
667
|
const { windows: c, windowSize: a } = r(i);
|
|
668
668
|
let l = e.ZERO, f = e.BASE;
|
|
669
|
-
const u = BigInt(2 ** i - 1),
|
|
670
|
-
for (let
|
|
671
|
-
const h =
|
|
669
|
+
const u = BigInt(2 ** i - 1), p = 2 ** i, b = BigInt(i);
|
|
670
|
+
for (let y = 0; y < c; y++) {
|
|
671
|
+
const h = y * a;
|
|
672
672
|
let d = Number(o & u);
|
|
673
|
-
o >>= b, d > a && (d -=
|
|
674
|
-
const g = h, E = h + Math.abs(d) - 1, S =
|
|
675
|
-
d === 0 ? f = f.add(n(S, s[g])) : l = l.add(n(
|
|
673
|
+
o >>= b, d > a && (d -= p, o += St);
|
|
674
|
+
const g = h, E = h + Math.abs(d) - 1, S = y % 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
|
},
|
|
@@ -763,49 +763,49 @@ const { bytesToNumberBE: ts, hexToBytes: ns } = qi, Be = {
|
|
|
763
763
|
}, r = t(n(e.s)), i = t(n(e.r)), s = r.length / 2, o = i.length / 2, c = n(s), a = n(o);
|
|
764
764
|
return `30${n(o + s + 4)}02${a}${i}02${c}${r}`;
|
|
765
765
|
}
|
|
766
|
-
}, ae = BigInt(0),
|
|
766
|
+
}, ae = BigInt(0), X = BigInt(1);
|
|
767
767
|
BigInt(2);
|
|
768
|
-
const
|
|
768
|
+
const kn = BigInt(3);
|
|
769
769
|
BigInt(4);
|
|
770
770
|
function rs(e) {
|
|
771
|
-
const t = es(e), { Fp: n } = t, r = t.toBytes || ((
|
|
771
|
+
const t = es(e), { Fp: n } = t, r = t.toBytes || ((y, h, d) => {
|
|
772
772
|
const g = h.toAffine();
|
|
773
|
-
return
|
|
774
|
-
}), i = t.fromBytes || ((
|
|
775
|
-
const h =
|
|
773
|
+
return _e(Uint8Array.from([4]), n.toBytes(g.x), n.toBytes(g.y));
|
|
774
|
+
}), i = t.fromBytes || ((y) => {
|
|
775
|
+
const h = y.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 };
|
|
777
777
|
});
|
|
778
|
-
function s(
|
|
779
|
-
const { a: h, b: d } = t, g = n.sqr(
|
|
780
|
-
return n.add(n.add(E, n.mul(
|
|
778
|
+
function s(y) {
|
|
779
|
+
const { a: h, b: d } = t, g = n.sqr(y), E = n.mul(g, y);
|
|
780
|
+
return n.add(n.add(E, n.mul(y, h)), d);
|
|
781
781
|
}
|
|
782
782
|
if (!n.eql(n.sqr(t.Gy), s(t.Gx)))
|
|
783
783
|
throw new Error("bad generator point: equation left != right");
|
|
784
|
-
function o(
|
|
785
|
-
return typeof
|
|
784
|
+
function o(y) {
|
|
785
|
+
return typeof y == "bigint" && ae < y && y < t.n;
|
|
786
786
|
}
|
|
787
|
-
function c(
|
|
788
|
-
if (!o(
|
|
787
|
+
function c(y) {
|
|
788
|
+
if (!o(y))
|
|
789
789
|
throw new Error("Expected valid bigint: 0 < bigint < curve.n");
|
|
790
790
|
}
|
|
791
|
-
function a(
|
|
791
|
+
function a(y) {
|
|
792
792
|
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey: g, n: E } = t;
|
|
793
|
-
if (h && typeof
|
|
794
|
-
if (
|
|
793
|
+
if (h && typeof y != "bigint") {
|
|
794
|
+
if (y instanceof Uint8Array && (y = De(y)), typeof y != "string" || !h.includes(y.length))
|
|
795
795
|
throw new Error("Invalid key");
|
|
796
|
-
|
|
796
|
+
y = y.padStart(d * 2, "0");
|
|
797
797
|
}
|
|
798
798
|
let S;
|
|
799
799
|
try {
|
|
800
|
-
S = typeof
|
|
800
|
+
S = typeof y == "bigint" ? y : F(Z("private key", y, d));
|
|
801
801
|
} catch {
|
|
802
|
-
throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof
|
|
802
|
+
throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof y}`);
|
|
803
803
|
}
|
|
804
804
|
return g && (S = W(S, E)), c(S), S;
|
|
805
805
|
}
|
|
806
806
|
const l = /* @__PURE__ */ new Map();
|
|
807
|
-
function f(
|
|
808
|
-
if (!(
|
|
807
|
+
function f(y) {
|
|
808
|
+
if (!(y instanceof u))
|
|
809
809
|
throw new Error("ProjectivePoint expected");
|
|
810
810
|
}
|
|
811
811
|
class u {
|
|
@@ -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,
|
|
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, kn), { 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), _ = 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, _), 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), _ = n.mul(h, _), A = n.sub(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 = n.mul(K, A), m = n.add(m, K), _ = n.mul(S, I), _ = n.add(_, _), K = n.mul(_, A), B = n.sub(B, K), x = n.mul(_, 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, _ = n.mul(t.b, kn);
|
|
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(_, 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(_, 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());
|
|
@@ -940,15 +940,15 @@ function rs(e) {
|
|
|
940
940
|
const d = u.ZERO;
|
|
941
941
|
if (h === ae)
|
|
942
942
|
return d;
|
|
943
|
-
if (c(h), h ===
|
|
943
|
+
if (c(h), h === X)
|
|
944
944
|
return this;
|
|
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
|
-
S &
|
|
951
|
-
return E && (m = m.negate()),
|
|
950
|
+
S & X && (m = m.add(K)), B & X && (x = x.add(K)), K = K.double(), S >>= X, B >>= X;
|
|
951
|
+
return E && (m = m.negate()), 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: _, f: A } = this.wNAF(x);
|
|
969
|
+
K = b.constTimeNegate(I, K), _ = b.constTimeNegate(m, _), _ = new u(n.mul(_.px, S.beta), _.py, _.pz), g = K.add(_), 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 ===
|
|
984
|
-
return
|
|
983
|
+
const E = u.BASE, S = (B, m) => m === ae || m === X || !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,16 +989,16 @@ 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;
|
|
1001
|
-
if (h ===
|
|
1001
|
+
if (h === X)
|
|
1002
1002
|
return !0;
|
|
1003
1003
|
if (d)
|
|
1004
1004
|
return d(u, this);
|
|
@@ -1006,17 +1006,17 @@ function rs(e) {
|
|
|
1006
1006
|
}
|
|
1007
1007
|
clearCofactor() {
|
|
1008
1008
|
const { h, clearCofactor: d } = t;
|
|
1009
|
-
return h ===
|
|
1009
|
+
return h === X ? this : d ? d(u, this) : this.multiplyUnsafe(t.h);
|
|
1010
1010
|
}
|
|
1011
1011
|
toRawBytes(h = !0) {
|
|
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);
|
|
1019
|
-
const
|
|
1019
|
+
const p = t.nBitLength, b = Qi(u, t.endo ? Math.ceil(p / 2) : p);
|
|
1020
1020
|
return {
|
|
1021
1021
|
CURVE: t,
|
|
1022
1022
|
ProjectivePoint: u,
|
|
@@ -1048,40 +1048,40 @@ function ss(e) {
|
|
|
1048
1048
|
function a(w) {
|
|
1049
1049
|
return Tt(w, r);
|
|
1050
1050
|
}
|
|
1051
|
-
const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder:
|
|
1051
|
+
const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: p } = rs({
|
|
1052
1052
|
...t,
|
|
1053
1053
|
toBytes(w, v, N) {
|
|
1054
|
-
const
|
|
1055
|
-
return N ? U(Uint8Array.from([v.hasEvenY() ? 2 : 3]), C) : U(Uint8Array.from([4]), C, n.toBytes(
|
|
1054
|
+
const k = v.toAffine(), C = n.toBytes(k.x), U = _e;
|
|
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
|
-
const v = w.length, N = w[0],
|
|
1058
|
+
const v = w.length, N = w[0], k = w.subarray(1);
|
|
1059
1059
|
if (v === i && (N === 2 || N === 3)) {
|
|
1060
|
-
const C = F(
|
|
1060
|
+
const C = F(k);
|
|
1061
1061
|
if (!o(C))
|
|
1062
1062
|
throw new Error("Point is not on curve");
|
|
1063
1063
|
const U = u(C);
|
|
1064
1064
|
let O = n.sqrt(U);
|
|
1065
|
-
const $ = (O &
|
|
1065
|
+
const $ = (O & X) === X;
|
|
1066
1066
|
return (N & 1) === 1 !== $ && (O = n.neg(O)), { x: C, y: O };
|
|
1067
1067
|
} else if (v === s && N === 4) {
|
|
1068
|
-
const C = n.fromBytes(
|
|
1068
|
+
const C = n.fromBytes(k.subarray(0, n.BYTES)), U = n.fromBytes(k.subarray(n.BYTES, 2 * n.BYTES));
|
|
1069
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
|
}
|
|
1073
|
-
}), b = (w) =>
|
|
1074
|
-
function
|
|
1075
|
-
const v = r >>
|
|
1073
|
+
}), b = (w) => De(Ne(w, t.nByteLength));
|
|
1074
|
+
function y(w) {
|
|
1075
|
+
const v = r >> X;
|
|
1076
1076
|
return w > v;
|
|
1077
1077
|
}
|
|
1078
1078
|
function h(w) {
|
|
1079
|
-
return
|
|
1079
|
+
return y(w) ? c(-w) : w;
|
|
1080
1080
|
}
|
|
1081
1081
|
const d = (w, v, N) => F(w.slice(v, N));
|
|
1082
1082
|
class g {
|
|
1083
|
-
constructor(v, N,
|
|
1084
|
-
this.r = v, this.s = N, this.recovery =
|
|
1083
|
+
constructor(v, N, k) {
|
|
1084
|
+
this.r = v, this.s = N, this.recovery = k, this.assertValidity();
|
|
1085
1085
|
}
|
|
1086
1086
|
// pair (bytes of r, bytes of s)
|
|
1087
1087
|
static fromCompact(v) {
|
|
@@ -1091,47 +1091,47 @@ function ss(e) {
|
|
|
1091
1091
|
// DER encoded ECDSA signature
|
|
1092
1092
|
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
1093
1093
|
static fromDER(v) {
|
|
1094
|
-
const { r: N, s:
|
|
1095
|
-
return new g(N,
|
|
1094
|
+
const { r: N, s: k } = Be.toSig(Z("DER", v));
|
|
1095
|
+
return new g(N, k);
|
|
1096
1096
|
}
|
|
1097
1097
|
assertValidity() {
|
|
1098
|
-
if (!
|
|
1098
|
+
if (!p(this.r))
|
|
1099
1099
|
throw new Error("r must be 0 < r < CURVE.n");
|
|
1100
|
-
if (!
|
|
1100
|
+
if (!p(this.s))
|
|
1101
1101
|
throw new Error("s must be 0 < s < CURVE.n");
|
|
1102
1102
|
}
|
|
1103
1103
|
addRecoveryBit(v) {
|
|
1104
1104
|
return new g(this.r, this.s, v);
|
|
1105
1105
|
}
|
|
1106
1106
|
recoverPublicKey(v) {
|
|
1107
|
-
const { r: N, s:
|
|
1107
|
+
const { r: N, s: k, recovery: C } = this, U = x(Z("msgHash", v));
|
|
1108
1108
|
if (C == null || ![0, 1, 2, 3].includes(C))
|
|
1109
1109
|
throw new Error("recovery id invalid");
|
|
1110
1110
|
const O = C === 2 || C === 3 ? N + t.n : N;
|
|
1111
1111
|
if (O >= n.ORDER)
|
|
1112
1112
|
throw new Error("recovery id 2 or 3 invalid");
|
|
1113
|
-
const $ = C & 1 ? "03" : "02",
|
|
1113
|
+
const $ = C & 1 ? "03" : "02", ee = l.fromHex($ + b(O)), ge = a(O), Ue = c(-U * ge), We = c(k * ge), we = l.BASE.multiplyAndAddUnsafe(ee, Ue, We);
|
|
1114
1114
|
if (!we)
|
|
1115
1115
|
throw new Error("point at infinify");
|
|
1116
1116
|
return we.assertValidity(), we;
|
|
1117
1117
|
}
|
|
1118
1118
|
// Signatures should be low-s, to prevent malleability.
|
|
1119
1119
|
hasHighS() {
|
|
1120
|
-
return
|
|
1120
|
+
return y(this.s);
|
|
1121
1121
|
}
|
|
1122
1122
|
normalizeS() {
|
|
1123
1123
|
return this.hasHighS() ? new g(this.r, c(-this.s), this.recovery) : this;
|
|
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
|
|
1173
|
-
const v = w instanceof Uint8Array, N = typeof w == "string",
|
|
1174
|
-
return v ?
|
|
1172
|
+
function I(w) {
|
|
1173
|
+
const v = w instanceof Uint8Array, N = typeof w == "string", k = (v || N) && w.length;
|
|
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 (
|
|
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,70 +1193,70 @@ 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 _(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
|
-
const { hash:
|
|
1199
|
+
const { hash: k, randomBytes: C } = t;
|
|
1200
1200
|
let { lowS: U, prehash: O, extraEntropy: $ } = N;
|
|
1201
|
-
U == null && (U = !0), w = Z("msgHash", w), O && (w = Z("prehashed msgHash",
|
|
1202
|
-
const
|
|
1201
|
+
U == null && (U = !0), w = Z("msgHash", w), O && (w = Z("prehashed msgHash", k(w)));
|
|
1202
|
+
const ee = x(w), ge = f(v), Ue = [M(ge), M(ee)];
|
|
1203
1203
|
if ($ != null) {
|
|
1204
1204
|
const Ae = $ === !0 ? C(n.BYTES) : $;
|
|
1205
1205
|
Ue.push(Z("extraEntropy", Ae));
|
|
1206
1206
|
}
|
|
1207
|
-
const
|
|
1207
|
+
const We = _e(...Ue), we = ee;
|
|
1208
1208
|
function Et(Ae) {
|
|
1209
1209
|
const Le = m(Ae);
|
|
1210
|
-
if (!
|
|
1210
|
+
if (!p(Le))
|
|
1211
1211
|
return;
|
|
1212
|
-
const xn = a(Le), $e = l.BASE.multiply(Le).toAffine(),
|
|
1213
|
-
if (
|
|
1212
|
+
const xn = a(Le), $e = l.BASE.multiply(Le).toAffine(), te = c($e.x);
|
|
1213
|
+
if (te === ae)
|
|
1214
1214
|
return;
|
|
1215
|
-
const Te = c(xn * c(we +
|
|
1215
|
+
const Te = c(xn * c(we + te * ge));
|
|
1216
1216
|
if (Te === ae)
|
|
1217
1217
|
return;
|
|
1218
|
-
let Kn = ($e.x ===
|
|
1219
|
-
return U &&
|
|
1218
|
+
let Kn = ($e.x === te ? 0 : 2) | Number($e.y & X), Nn = Te;
|
|
1219
|
+
return U && y(Te) && (Nn = h(Te), Kn ^= 1), new g(te, 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:
|
|
1226
|
-
return Jn(U.hash.outputLen, U.nByteLength, U.hmac)(
|
|
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
|
-
function H(w, v, N,
|
|
1229
|
+
function H(w, v, N, k = T) {
|
|
1230
1230
|
var $e;
|
|
1231
1231
|
const C = w;
|
|
1232
|
-
if (v = Z("msgHash", v), N = Z("publicKey", N), "strict" in
|
|
1232
|
+
if (v = Z("msgHash", v), N = Z("publicKey", N), "strict" in k)
|
|
1233
1233
|
throw new Error("options.strict was renamed to lowS");
|
|
1234
|
-
const { lowS: U, prehash: O } =
|
|
1235
|
-
let $,
|
|
1234
|
+
const { lowS: U, prehash: O } = k;
|
|
1235
|
+
let $, ee;
|
|
1236
1236
|
try {
|
|
1237
1237
|
if (typeof C == "string" || C instanceof Uint8Array)
|
|
1238
1238
|
try {
|
|
1239
1239
|
$ = g.fromDER(C);
|
|
1240
|
-
} catch (
|
|
1241
|
-
if (!(
|
|
1242
|
-
throw
|
|
1240
|
+
} catch (te) {
|
|
1241
|
+
if (!(te instanceof Be.Err))
|
|
1242
|
+
throw te;
|
|
1243
1243
|
$ = g.fromCompact(C);
|
|
1244
1244
|
}
|
|
1245
1245
|
else if (typeof C == "object" && typeof C.r == "bigint" && typeof C.s == "bigint") {
|
|
1246
|
-
const { r:
|
|
1247
|
-
$ = new g(
|
|
1246
|
+
const { r: te, s: Te } = C;
|
|
1247
|
+
$ = new g(te, Te);
|
|
1248
1248
|
} else
|
|
1249
1249
|
throw new Error("PARSE");
|
|
1250
|
-
|
|
1251
|
-
} catch (
|
|
1252
|
-
if (
|
|
1250
|
+
ee = l.fromHex(N);
|
|
1251
|
+
} catch (te) {
|
|
1252
|
+
if (te.message === "PARSE")
|
|
1253
1253
|
throw new Error("signature must be Signature instance, Uint8Array or hex string");
|
|
1254
1254
|
return !1;
|
|
1255
1255
|
}
|
|
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(ee, 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), _n = (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 =
|
|
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 = Y(f, n, t) * f % t, p = Y(u, n, t) * f % t, b = Y(p, nt, t) * l % t, y = Y(b, i, t) * b % t, h = Y(y, s, t) * y % t, d = Y(h, c, t) * h % t, g = Y(d, a, t) * d % t, E = Y(g, c, t) * h % t, S = Y(E, n, t) * f % t, I = Y(S, o, t) * y % t, B = Y(I, r, t) * l % t, m = Y(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,26 +1346,26 @@ 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 = _n(s * e, t), a = _n(-r * e, t);
|
|
1350
1350
|
let l = W(e - c * n - a * i, t), f = W(-c * r - a * s, t);
|
|
1351
|
-
const u = l > o,
|
|
1352
|
-
if (u && (l = t - l),
|
|
1351
|
+
const u = l > o, p = f > o;
|
|
1352
|
+
if (u && (l = t - l), p && (f = t - f), l > o || f > o)
|
|
1353
1353
|
throw new Error("splitScalar: Endomorphism failed, k=" + e);
|
|
1354
|
-
return { k1neg: u, k1: l, k2neg:
|
|
1354
|
+
return { k1neg: u, k1: l, k2neg: p, 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 = _e(r, r), In[e] = n;
|
|
1363
1363
|
}
|
|
1364
|
-
return Lt(
|
|
1364
|
+
return Lt(_e(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) {
|
|
@@ -1387,8 +1387,8 @@ function fs(e, t, n = Zn(32)) {
|
|
|
1387
1387
|
const r = Z("message", e), { bytes: i, scalar: s } = Pt(t), o = Z("auxRand", n, 32), c = Ot(s ^ F(rt("BIP0340/aux", o))), a = rt("BIP0340/nonce", c, i, r), l = Fe(F(a));
|
|
1388
1388
|
if (l === ut)
|
|
1389
1389
|
throw new Error("sign failed: k is zero");
|
|
1390
|
-
const { bytes: f, scalar: u } = Pt(l),
|
|
1391
|
-
if (b.set(f, 0), b.set(Ot(Fe(u +
|
|
1390
|
+
const { bytes: f, scalar: u } = Pt(l), p = ar(f, i, r), b = new Uint8Array(64);
|
|
1391
|
+
if (b.set(f, 0), b.set(Ot(Fe(u + p * s)), 32), !cr(b, r, i))
|
|
1392
1392
|
throw new Error("sign: Invalid signature produced");
|
|
1393
1393
|
return b;
|
|
1394
1394
|
}
|
|
@@ -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,
|
|
@@ -1449,13 +1449,13 @@ function z(e) {
|
|
|
1449
1449
|
}
|
|
1450
1450
|
return n;
|
|
1451
1451
|
}
|
|
1452
|
-
function
|
|
1452
|
+
function ps(e) {
|
|
1453
1453
|
if (typeof e != "string")
|
|
1454
1454
|
throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
|
|
1455
1455
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
1456
1456
|
}
|
|
1457
1457
|
function Je(e) {
|
|
1458
|
-
if (typeof e == "string" && (e =
|
|
1458
|
+
if (typeof e == "string" && (e = ps(e)), !Qt(e))
|
|
1459
1459
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
1460
1460
|
return e;
|
|
1461
1461
|
}
|
|
@@ -1487,7 +1487,7 @@ function Mt(e) {
|
|
|
1487
1487
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
1488
1488
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
1489
1489
|
}
|
|
1490
|
-
function
|
|
1490
|
+
function ys(e) {
|
|
1491
1491
|
if (typeof e != "boolean")
|
|
1492
1492
|
throw new Error(`Expected boolean, not ${e}`);
|
|
1493
1493
|
}
|
|
@@ -1516,7 +1516,7 @@ function bs(e, t) {
|
|
|
1516
1516
|
}
|
|
1517
1517
|
const se = {
|
|
1518
1518
|
number: Mt,
|
|
1519
|
-
bool:
|
|
1519
|
+
bool: ys,
|
|
1520
1520
|
bytes: hr,
|
|
1521
1521
|
hash: gs,
|
|
1522
1522
|
exists: ws,
|
|
@@ -1669,12 +1669,12 @@ class dr extends ms {
|
|
|
1669
1669
|
for (let u = 0; u < 16; u++, n += 4)
|
|
1670
1670
|
Ee[u] = t.getUint32(n, !1);
|
|
1671
1671
|
for (let u = 16; u < 64; u++) {
|
|
1672
|
-
const
|
|
1673
|
-
Ee[u] = h + Ee[u - 7] +
|
|
1672
|
+
const p = Ee[u - 15], b = Ee[u - 2], y = ie(p, 7) ^ ie(p, 18) ^ p >>> 3, h = ie(b, 17) ^ ie(b, 19) ^ b >>> 10;
|
|
1673
|
+
Ee[u] = h + Ee[u - 7] + y + Ee[u - 16] | 0;
|
|
1674
1674
|
}
|
|
1675
1675
|
let { A: r, B: i, C: s, D: o, E: c, F: a, G: l, H: f } = this;
|
|
1676
1676
|
for (let u = 0; u < 64; u++) {
|
|
1677
|
-
const
|
|
1677
|
+
const p = ie(c, 6) ^ ie(c, 11) ^ ie(c, 25), b = f + p + Es(c, a, l) + Ks[u] + Ee[u] | 0, h = (ie(r, 2) ^ ie(r, 13) ^ ie(r, 22)) + xs(r, i, s) | 0;
|
|
1678
1678
|
f = l, l = a, a = c, c = o + b | 0, o = s, s = i, i = r, r = b + h | 0;
|
|
1679
1679
|
}
|
|
1680
1680
|
r = r + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, l = l + this.G | 0, f = f + this.H | 0, this.set(r, i, s, o, c, a, l, f);
|
|
@@ -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
|
}
|
|
@@ -1702,13 +1702,13 @@ function de(...e) {
|
|
|
1702
1702
|
const t = (i, s) => (o) => i(s(o)), n = Array.from(e).reverse().reduce((i, s) => i ? t(i, s.encode) : s.encode, void 0), r = e.reduce((i, s) => i ? t(i, s.decode) : s.decode, void 0);
|
|
1703
1703
|
return { encode: n, decode: r };
|
|
1704
1704
|
}
|
|
1705
|
-
function
|
|
1705
|
+
function pe(e) {
|
|
1706
1706
|
return {
|
|
1707
1707
|
encode: (t) => {
|
|
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
|
});
|
|
@@ -1727,7 +1727,7 @@ function ye(e) {
|
|
|
1727
1727
|
}
|
|
1728
1728
|
};
|
|
1729
1729
|
}
|
|
1730
|
-
function
|
|
1730
|
+
function ye(e = "") {
|
|
1731
1731
|
if (typeof e != "string")
|
|
1732
1732
|
throw new Error("join separator should be string");
|
|
1733
1733
|
return {
|
|
@@ -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) {
|
|
@@ -1776,7 +1776,7 @@ function ft(e, t = "=") {
|
|
|
1776
1776
|
}
|
|
1777
1777
|
};
|
|
1778
1778
|
}
|
|
1779
|
-
function
|
|
1779
|
+
function pr(e) {
|
|
1780
1780
|
if (typeof e != "function")
|
|
1781
1781
|
throw new Error("normalize fn should be function");
|
|
1782
1782
|
return { encode: (t) => t, decode: (t) => e(t) };
|
|
@@ -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;
|
|
@@ -1814,7 +1814,7 @@ function Un(e, t, n) {
|
|
|
1814
1814
|
i.push(0);
|
|
1815
1815
|
return i.reverse();
|
|
1816
1816
|
}
|
|
1817
|
-
const
|
|
1817
|
+
const yr = (e, t) => t ? yr(t, e % t) : e, it = (e, t) => e + (t - yr(e, t));
|
|
1818
1818
|
function Ht(e, t, n, r) {
|
|
1819
1819
|
if (!Array.isArray(e))
|
|
1820
1820
|
throw new Error("convertRadix2: data should be array");
|
|
@@ -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");
|
|
@@ -1883,13 +1883,13 @@ function Ln(e) {
|
|
|
1883
1883
|
}
|
|
1884
1884
|
};
|
|
1885
1885
|
}
|
|
1886
|
-
const As = de(Se(4),
|
|
1887
|
-
de(Se(5),
|
|
1888
|
-
de(Se(5),
|
|
1889
|
-
const he = de(Se(6),
|
|
1886
|
+
const As = de(Se(4), pe("0123456789ABCDEF"), ye("")), Cs = de(Se(5), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), ft(5), ye(""));
|
|
1887
|
+
de(Se(5), pe("0123456789ABCDEFGHIJKLMNOPQRSTUV"), ft(5), ye(""));
|
|
1888
|
+
de(Se(5), pe("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), ye(""), pr((e) => e.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
1889
|
+
const he = de(Se(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), ft(6), ye("")), Bs = de(Se(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), ft(6), ye("")), en = (e) => de(Ss(58), pe(e), ye("")), qt = en("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
1890
1890
|
en("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
|
|
1891
1891
|
en("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");
|
|
1892
|
-
const $n = [0, 2, 3, 5, 6, 7, 9, 10, 11],
|
|
1892
|
+
const $n = [0, 2, 3, 5, 6, 7, 9, 10, 11], ks = {
|
|
1893
1893
|
encode(e) {
|
|
1894
1894
|
let t = "";
|
|
1895
1895
|
for (let n = 0; n < e.length; n += 8) {
|
|
@@ -1909,8 +1909,8 @@ const $n = [0, 2, 3, 5, 6, 7, 9, 10, 11], _s = {
|
|
|
1909
1909
|
}
|
|
1910
1910
|
return Uint8Array.from(t);
|
|
1911
1911
|
}
|
|
1912
|
-
}, Dt = de(
|
|
1913
|
-
function
|
|
1912
|
+
}, Dt = de(pe("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), ye("")), Tn = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
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,27 +1924,27 @@ 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) {
|
|
1939
1939
|
const t = e === "bech32" ? 1 : 734539939, n = Se(5), r = n.decode, i = n.encode, s = Ln(r);
|
|
1940
|
-
function o(f, u,
|
|
1940
|
+
function o(f, u, p = 90) {
|
|
1941
1941
|
if (typeof f != "string")
|
|
1942
1942
|
throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);
|
|
1943
1943
|
if (!Array.isArray(u) || u.length && typeof u[0] != "number")
|
|
1944
1944
|
throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);
|
|
1945
1945
|
const b = f.length + 7 + u.length;
|
|
1946
|
-
if (
|
|
1947
|
-
throw new TypeError(`Length ${b} exceeds limit ${
|
|
1946
|
+
if (p !== !1 && b > p)
|
|
1947
|
+
throw new TypeError(`Length ${b} exceeds limit ${p}`);
|
|
1948
1948
|
return f = f.toLowerCase(), `${f}1${Dt.encode(u)}${Rn(f, u, t)}`;
|
|
1949
1949
|
}
|
|
1950
1950
|
function c(f, u = 90) {
|
|
@@ -1952,49 +1952,49 @@ function gr(e) {
|
|
|
1952
1952
|
throw new Error(`bech32.decode input should be string, not ${typeof f}`);
|
|
1953
1953
|
if (f.length < 8 || u !== !1 && f.length > u)
|
|
1954
1954
|
throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${u})`);
|
|
1955
|
-
const
|
|
1956
|
-
if (f !==
|
|
1955
|
+
const p = f.toLowerCase();
|
|
1956
|
+
if (f !== p && f !== f.toUpperCase())
|
|
1957
1957
|
throw new Error("String must be lowercase or uppercase");
|
|
1958
|
-
f =
|
|
1958
|
+
f = p;
|
|
1959
1959
|
const b = f.lastIndexOf("1");
|
|
1960
1960
|
if (b === 0 || b === -1)
|
|
1961
1961
|
throw new Error('Letter "1" must be present between prefix and data only');
|
|
1962
|
-
const
|
|
1962
|
+
const y = f.slice(0, b), h = f.slice(b + 1);
|
|
1963
1963
|
if (h.length < 6)
|
|
1964
1964
|
throw new Error("Data must be at least 6 characters long");
|
|
1965
|
-
const d = Dt.decode(h).slice(0, -6), g = Rn(
|
|
1965
|
+
const d = Dt.decode(h).slice(0, -6), g = Rn(y, d, t);
|
|
1966
1966
|
if (!h.endsWith(g))
|
|
1967
1967
|
throw new Error(`Invalid checksum in ${f}: expected "${g}"`);
|
|
1968
|
-
return { prefix:
|
|
1968
|
+
return { prefix: y, words: d };
|
|
1969
1969
|
}
|
|
1970
1970
|
const a = Ln(c);
|
|
1971
1971
|
function l(f) {
|
|
1972
|
-
const { prefix: u, words:
|
|
1973
|
-
return { prefix: u, words:
|
|
1972
|
+
const { prefix: u, words: p } = c(f, !1);
|
|
1973
|
+
return { prefix: u, words: p, bytes: r(p) };
|
|
1974
1974
|
}
|
|
1975
1975
|
return { encode: o, decode: c, decodeToBytes: l, decodeUnsafe: a, fromWords: r, fromWordsUnsafe: s, toWords: i };
|
|
1976
1976
|
}
|
|
1977
|
-
const
|
|
1977
|
+
const ze = gr("bech32");
|
|
1978
1978
|
gr("bech32m");
|
|
1979
|
-
const
|
|
1979
|
+
const _s = {
|
|
1980
1980
|
encode: (e) => new TextDecoder().decode(e),
|
|
1981
1981
|
decode: (e) => new TextEncoder().encode(e)
|
|
1982
|
-
},
|
|
1982
|
+
}, Is = de(Se(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
1986
|
})), Us = {
|
|
1987
|
-
utf8:
|
|
1988
|
-
hex:
|
|
1987
|
+
utf8: _s,
|
|
1988
|
+
hex: Is,
|
|
1989
1989
|
base16: As,
|
|
1990
1990
|
base32: Cs,
|
|
1991
1991
|
base64: he,
|
|
1992
1992
|
base64url: Bs,
|
|
1993
1993
|
base58: qt,
|
|
1994
|
-
base58xmr:
|
|
1994
|
+
base58xmr: ks
|
|
1995
1995
|
};
|
|
1996
1996
|
`${Object.keys(Us).join(", ")}`;
|
|
1997
|
-
function
|
|
1997
|
+
function kt(e) {
|
|
1998
1998
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
1999
1999
|
throw new Error(`positive integer expected, not ${e}`);
|
|
2000
2000
|
}
|
|
@@ -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, _t = (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(_t), i = r.map(_t), s = i.map(_t), 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;
|
|
@@ -2103,24 +2103,24 @@ function Pn(e, t, n, r, i) {
|
|
|
2103
2103
|
let a = 0;
|
|
2104
2104
|
t ^= e[a++], n ^= e[a++], r ^= e[a++], i ^= e[a++];
|
|
2105
2105
|
const l = e.length / 4 - 2;
|
|
2106
|
-
for (let
|
|
2106
|
+
for (let y = 0; y < l; y++) {
|
|
2107
2107
|
const h = e[a++] ^ xe(o, c, t, n, r, i), d = e[a++] ^ xe(o, c, n, r, i, t), g = e[a++] ^ xe(o, c, r, i, t, n), E = e[a++] ^ xe(o, c, i, t, n, r);
|
|
2108
2108
|
t = h, n = d, r = g, i = E;
|
|
2109
2109
|
}
|
|
2110
|
-
const f = e[a++] ^ oe(s, t, n, r, i), u = e[a++] ^ oe(s, n, r, i, t),
|
|
2111
|
-
return { s0: f, s1: u, s2:
|
|
2110
|
+
const f = e[a++] ^ oe(s, t, n, r, i), u = e[a++] ^ oe(s, n, r, i, t), p = e[a++] ^ oe(s, r, i, t, n), b = e[a++] ^ oe(s, i, t, n, r);
|
|
2111
|
+
return { s0: f, s1: u, s2: p, s3: b };
|
|
2112
2112
|
}
|
|
2113
2113
|
function js(e, t, n, r, i) {
|
|
2114
2114
|
const { sbox2: s, T01: o, T23: c } = br;
|
|
2115
2115
|
let a = 0;
|
|
2116
2116
|
t ^= e[a++], n ^= e[a++], r ^= e[a++], i ^= e[a++];
|
|
2117
2117
|
const l = e.length / 4 - 2;
|
|
2118
|
-
for (let
|
|
2118
|
+
for (let y = 0; y < l; y++) {
|
|
2119
2119
|
const h = e[a++] ^ xe(o, c, t, i, r, n), d = e[a++] ^ xe(o, c, n, t, i, r), g = e[a++] ^ xe(o, c, r, n, t, i), E = e[a++] ^ xe(o, c, i, r, n, t);
|
|
2120
2120
|
t = h, n = d, r = g, i = E;
|
|
2121
2121
|
}
|
|
2122
|
-
const f = e[a++] ^ oe(s, t, i, r, n), u = e[a++] ^ oe(s, n, t, i, r),
|
|
2123
|
-
return { s0: f, s1: u, s2:
|
|
2122
|
+
const f = e[a++] ^ oe(s, t, i, r, n), u = e[a++] ^ oe(s, n, t, i, r), p = e[a++] ^ oe(s, r, n, t, i), b = e[a++] ^ oe(s, i, r, n, t);
|
|
2123
|
+
return { s0: f, s1: u, s2: p, s3: b };
|
|
2124
2124
|
}
|
|
2125
2125
|
function mr(e, t) {
|
|
2126
2126
|
if (!t)
|
|
@@ -2175,24 +2175,24 @@ const Er = /* @__PURE__ */ Os({ blockSize: 16, nonceLength: 16 }, function(t, n,
|
|
|
2175
2175
|
return {
|
|
2176
2176
|
encrypt: (s, o) => {
|
|
2177
2177
|
const c = vr(t), { b: a, o: l, out: f } = Vs(s, i, o), u = G(n);
|
|
2178
|
-
let
|
|
2178
|
+
let p = u[0], b = u[1], y = u[2], h = u[3], d = 0;
|
|
2179
2179
|
for (; d + 4 <= a.length; )
|
|
2180
|
-
|
|
2180
|
+
p ^= a[d + 0], b ^= a[d + 1], y ^= a[d + 2], h ^= a[d + 3], { s0: p, s1: b, s2: y, s3: h } = Pn(c, p, b, y, h), l[d++] = p, l[d++] = b, l[d++] = y, l[d++] = h;
|
|
2181
2181
|
if (i) {
|
|
2182
2182
|
const g = Zs(s.subarray(d * 4));
|
|
2183
|
-
|
|
2183
|
+
p ^= g[0], b ^= g[1], y ^= g[2], h ^= g[3], { s0: p, s1: b, s2: y, s3: h } = Pn(c, p, b, y, h), l[d++] = p, l[d++] = b, l[d++] = y, l[d++] = h;
|
|
2184
2184
|
}
|
|
2185
2185
|
return c.fill(0), f;
|
|
2186
2186
|
},
|
|
2187
2187
|
decrypt: (s, o) => {
|
|
2188
2188
|
zs(s);
|
|
2189
2189
|
const c = Ds(t), a = G(n), l = mr(s.length, o), f = G(s), u = G(l);
|
|
2190
|
-
let
|
|
2190
|
+
let p = a[0], b = a[1], y = a[2], h = a[3];
|
|
2191
2191
|
for (let d = 0; d + 4 <= f.length; ) {
|
|
2192
|
-
const g =
|
|
2193
|
-
|
|
2194
|
-
const { s0: B, s1: m, s2: x, s3: K } = js(c,
|
|
2195
|
-
u[d++] = B ^ g, u[d++] = m ^ E, u[d++] = x ^ S, u[d++] = K ^
|
|
2192
|
+
const g = p, E = b, S = y, I = h;
|
|
2193
|
+
p = f[d + 0], b = f[d + 1], y = f[d + 2], h = f[d + 3];
|
|
2194
|
+
const { s0: B, s1: m, s2: x, s3: K } = js(c, p, b, y, h);
|
|
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
|
}
|
|
@@ -2207,44 +2207,44 @@ function zt(e) {
|
|
|
2207
2207
|
}
|
|
2208
2208
|
const Xe = 64, Ys = 16, Nr = 2 ** 32 - 1, Mn = new Uint32Array();
|
|
2209
2209
|
function Xs(e, t, n, r, i, s, o, c) {
|
|
2210
|
-
const a = i.length, l = new Uint8Array(Xe), f = G(l), u = zt(i) && zt(s),
|
|
2211
|
-
for (let
|
|
2210
|
+
const a = i.length, l = new Uint8Array(Xe), f = G(l), u = zt(i) && zt(s), p = u ? G(i) : Mn, b = u ? G(s) : Mn;
|
|
2211
|
+
for (let y = 0; y < a; o++) {
|
|
2212
2212
|
if (e(t, n, r, f, o, c), o >= Nr)
|
|
2213
2213
|
throw new Error("arx: counter overflow");
|
|
2214
|
-
const h = Math.min(Xe, a -
|
|
2214
|
+
const h = Math.min(Xe, a - y);
|
|
2215
2215
|
if (u && h === Xe) {
|
|
2216
|
-
const d =
|
|
2217
|
-
if (
|
|
2216
|
+
const d = y / 4;
|
|
2217
|
+
if (y % 4 !== 0)
|
|
2218
2218
|
throw new Error("arx: invalid block position");
|
|
2219
2219
|
for (let g = 0, E; g < Ys; g++)
|
|
2220
|
-
E = d + g, b[E] =
|
|
2221
|
-
|
|
2220
|
+
E = d + g, b[E] = p[E] ^ f[g];
|
|
2221
|
+
y += Xe;
|
|
2222
2222
|
continue;
|
|
2223
2223
|
}
|
|
2224
2224
|
for (let d = 0, g; d < h; d++)
|
|
2225
|
-
g =
|
|
2226
|
-
|
|
2225
|
+
g = y + d, s[g] = i[g] ^ l[d];
|
|
2226
|
+
y += h;
|
|
2227
2227
|
}
|
|
2228
2228
|
}
|
|
2229
2229
|
function Qs(e, t) {
|
|
2230
2230
|
const { allowShortKeys: n, extendNonceFn: r, counterLength: i, counterRight: s, rounds: o } = Ts({ allowShortKeys: !1, counterLength: 8, counterRight: !1, rounds: 20 }, t);
|
|
2231
2231
|
if (typeof e != "function")
|
|
2232
2232
|
throw new Error("core must be a function");
|
|
2233
|
-
return
|
|
2233
|
+
return kt(i), kt(o), On(s), On(n), (c, a, l, f, u = 0) => {
|
|
2234
2234
|
ce(c), ce(a), ce(l);
|
|
2235
|
-
const
|
|
2236
|
-
if (f || (f = new Uint8Array(
|
|
2235
|
+
const p = l.length;
|
|
2236
|
+
if (f || (f = new Uint8Array(p)), ce(f), kt(u), u < 0 || u >= Nr)
|
|
2237
2237
|
throw new Error("arx: counter overflow");
|
|
2238
|
-
if (f.length <
|
|
2239
|
-
throw new Error(`arx: output (${f.length}) is shorter than data (${
|
|
2238
|
+
if (f.length < p)
|
|
2239
|
+
throw new Error(`arx: output (${f.length}) is shorter than data (${p})`);
|
|
2240
2240
|
const b = [];
|
|
2241
|
-
let
|
|
2242
|
-
if (
|
|
2241
|
+
let y = c.length, h, d;
|
|
2242
|
+
if (y === 32)
|
|
2243
2243
|
h = c.slice(), b.push(h), d = Kr;
|
|
2244
|
-
else if (
|
|
2244
|
+
else if (y === 16 && n)
|
|
2245
2245
|
h = new Uint8Array(32), h.set(c), h.set(c, 16), d = Js, b.push(h);
|
|
2246
2246
|
else
|
|
2247
|
-
throw new Error(`arx: invalid 32-byte key, got length=${
|
|
2247
|
+
throw new Error(`arx: invalid 32-byte key, got length=${y}`);
|
|
2248
2248
|
zt(a) || (a = a.slice(), b.push(a));
|
|
2249
2249
|
const g = G(h);
|
|
2250
2250
|
if (r) {
|
|
@@ -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],
|
|
2270
|
-
for (let
|
|
2271
|
-
m = m +
|
|
2269
|
+
let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1], p = t[2], b = t[3], y = 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, _ = f, A = u, T = p, R = b, H = y, w = h, v = d, N = g, k = E, C = S, U = I, O = B;
|
|
2270
|
+
for (let ee = 0; ee < s; ee += 2)
|
|
2271
|
+
m = m + _ | 0, k = L(k ^ m, 16), H = H + k | 0, _ = L(_ ^ H, 12), m = m + _ | 0, k = L(k ^ m, 8), H = H + k | 0, _ = L(_ ^ 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, 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), 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 + _ | 0, U = L(U ^ M, 16), w = w + U | 0, _ = L(_ ^ w, 12), M = M + _ | 0, U = L(U ^ M, 8), w = w + U | 0, _ = L(_ ^ 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 + _ | 0, r[$++] = u + A | 0, r[$++] = p + T | 0, r[$++] = b + R | 0, r[$++] = y + H | 0, r[$++] = h + w | 0, r[$++] = d + v | 0, r[$++] = g + N | 0, r[$++] = E + k | 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)
|
|
@@ -2382,15 +2382,15 @@ function sn(e, t) {
|
|
|
2382
2382
|
}
|
|
2383
2383
|
var Br = class {
|
|
2384
2384
|
constructor(e) {
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2385
|
+
J(this, "value");
|
|
2386
|
+
J(this, "next", null);
|
|
2387
|
+
J(this, "prev", null);
|
|
2388
2388
|
this.value = e;
|
|
2389
2389
|
}
|
|
2390
2390
|
}, ao = class {
|
|
2391
2391
|
constructor() {
|
|
2392
|
-
|
|
2393
|
-
|
|
2392
|
+
J(this, "first");
|
|
2393
|
+
J(this, "last");
|
|
2394
2394
|
this.first = null, this.last = null;
|
|
2395
2395
|
}
|
|
2396
2396
|
enqueue(e) {
|
|
@@ -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,11 +2437,11 @@ 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
|
}
|
|
2444
|
-
var
|
|
2444
|
+
var pt = new co(), ke = pt.generateSecretKey, le = pt.getPublicKey, Q = pt.finalizeEvent, yt = pt.verifyEvent, lo = {};
|
|
2445
2445
|
D(lo, {
|
|
2446
2446
|
Application: () => da,
|
|
2447
2447
|
BadgeAward: () => mo,
|
|
@@ -2460,7 +2460,7 @@ D(lo, {
|
|
|
2460
2460
|
ClientAuth: () => Hr,
|
|
2461
2461
|
CommunitiesList: () => Do,
|
|
2462
2462
|
CommunityDefinition: () => Na,
|
|
2463
|
-
CommunityPostApproval: () =>
|
|
2463
|
+
CommunityPostApproval: () => _o,
|
|
2464
2464
|
Contacts: () => wo,
|
|
2465
2465
|
CreateOrUpdateProduct: () => ua,
|
|
2466
2466
|
CreateOrUpdateStall: () => ca,
|
|
@@ -2485,14 +2485,14 @@ D(lo, {
|
|
|
2485
2485
|
InterestsList: () => Wo,
|
|
2486
2486
|
Interestsets: () => aa,
|
|
2487
2487
|
JobFeedback: () => Lo,
|
|
2488
|
-
JobRequest: () =>
|
|
2488
|
+
JobRequest: () => Io,
|
|
2489
2489
|
JobResult: () => Uo,
|
|
2490
|
-
Label: () =>
|
|
2490
|
+
Label: () => ko,
|
|
2491
2491
|
LightningPubRPC: () => Yo,
|
|
2492
2492
|
LiveChatMessage: () => So,
|
|
2493
|
-
LiveEvent: () =>
|
|
2493
|
+
LiveEvent: () => pa,
|
|
2494
2494
|
LongFormArticle: () => la,
|
|
2495
|
-
Metadata: () =>
|
|
2495
|
+
Metadata: () => po,
|
|
2496
2496
|
Mutelist: () => Po,
|
|
2497
2497
|
NWCWalletInfo: () => Jo,
|
|
2498
2498
|
NWCWalletRequest: () => qr,
|
|
@@ -2513,46 +2513,46 @@ D(lo, {
|
|
|
2513
2513
|
Repost: () => on,
|
|
2514
2514
|
Seal: () => Lr,
|
|
2515
2515
|
SearchRelaysList: () => Vo,
|
|
2516
|
-
ShortTextNote: () =>
|
|
2516
|
+
ShortTextNote: () => yo,
|
|
2517
2517
|
Time: () => va,
|
|
2518
2518
|
UserEmojiList: () => Zo,
|
|
2519
|
-
UserStatuses: () =>
|
|
2519
|
+
UserStatuses: () => ya,
|
|
2520
2520
|
Zap: () => Ro,
|
|
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
|
-
isRegularKind: () =>
|
|
2528
|
-
isReplaceableKind: () =>
|
|
2527
|
+
isRegularKind: () => kr,
|
|
2528
|
+
isReplaceableKind: () => _r
|
|
2529
2529
|
});
|
|
2530
|
-
function
|
|
2530
|
+
function kr(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 _r(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
|
|
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
|
|
2549
|
+
var po = 0, yo = 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, ko = 1985, _o = 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, pa = 30311, ya = 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,
|
|
2553
2553
|
getSubscriptionId: () => Aa,
|
|
2554
2554
|
matchEventId: () => Ca,
|
|
2555
|
-
matchEventKind: () =>
|
|
2555
|
+
matchEventKind: () => ka,
|
|
2556
2556
|
matchEventPubkey: () => Ba
|
|
2557
2557
|
});
|
|
2558
2558
|
function un(e, t) {
|
|
@@ -2582,14 +2582,14 @@ function Ca(e, t) {
|
|
|
2582
2582
|
function Ba(e, t) {
|
|
2583
2583
|
return t === un(e, "pubkey");
|
|
2584
2584
|
}
|
|
2585
|
-
function
|
|
2585
|
+
function ka(e, t) {
|
|
2586
2586
|
return t === Dr(e, "kind");
|
|
2587
2587
|
}
|
|
2588
|
-
var
|
|
2589
|
-
D(
|
|
2590
|
-
makeAuthEvent: () =>
|
|
2588
|
+
var _a = {};
|
|
2589
|
+
D(_a, {
|
|
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);
|
|
@@ -2651,7 +2651,7 @@ function gt(e) {
|
|
|
2651
2651
|
type: "nprofile",
|
|
2652
2652
|
data: {
|
|
2653
2653
|
pubkey: P(u[0][0]),
|
|
2654
|
-
relays: u[1] ? u[1].map((
|
|
2654
|
+
relays: u[1] ? u[1].map((p) => ue.decode(p)) : []
|
|
2655
2655
|
}
|
|
2656
2656
|
};
|
|
2657
2657
|
}
|
|
@@ -2669,7 +2669,7 @@ function gt(e) {
|
|
|
2669
2669
|
type: "nevent",
|
|
2670
2670
|
data: {
|
|
2671
2671
|
id: P(u[0][0]),
|
|
2672
|
-
relays: u[1] ? u[1].map((
|
|
2672
|
+
relays: u[1] ? u[1].map((p) => ue.decode(p)) : [],
|
|
2673
2673
|
author: (o = u[2]) != null && o[0] ? P(u[2][0]) : void 0,
|
|
2674
2674
|
kind: (c = u[3]) != null && c[0] ? parseInt(P(u[3][0]), 16) : void 0
|
|
2675
2675
|
}
|
|
@@ -2693,7 +2693,7 @@ function gt(e) {
|
|
|
2693
2693
|
identifier: ue.decode(u[0][0]),
|
|
2694
2694
|
pubkey: P(u[2][0]),
|
|
2695
2695
|
kind: parseInt(P(u[3][0]), 16),
|
|
2696
|
-
relays: u[1] ? u[1].map((
|
|
2696
|
+
relays: u[1] ? u[1].map((p) => ue.decode(p)) : []
|
|
2697
2697
|
}
|
|
2698
2698
|
};
|
|
2699
2699
|
}
|
|
@@ -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) {
|
|
@@ -2965,7 +2965,7 @@ D(rc, {
|
|
|
2965
2965
|
getRepostedEventPointer: () => Jr
|
|
2966
2966
|
});
|
|
2967
2967
|
function ic(e, t, n, r) {
|
|
2968
|
-
return
|
|
2968
|
+
return Q(
|
|
2969
2969
|
{
|
|
2970
2970
|
kind: on,
|
|
2971
2971
|
tags: [...e.tags ?? [], ["e", t.id, n], ["p", t.pubkey]],
|
|
@@ -3000,7 +3000,7 @@ function sc(e, { skipVerification: t } = {}) {
|
|
|
3000
3000
|
} catch {
|
|
3001
3001
|
return;
|
|
3002
3002
|
}
|
|
3003
|
-
if (r.id === n.id && !(!t && !
|
|
3003
|
+
if (r.id === n.id && !(!t && !yt(r)))
|
|
3004
3004
|
return r;
|
|
3005
3005
|
}
|
|
3006
3006
|
var oc = {};
|
|
@@ -3030,7 +3030,7 @@ D(uc, {
|
|
|
3030
3030
|
});
|
|
3031
3031
|
function lc(e, t, n) {
|
|
3032
3032
|
const r = t.tags.filter((i) => i.length >= 2 && (i[0] === "e" || i[0] === "p"));
|
|
3033
|
-
return
|
|
3033
|
+
return Q(
|
|
3034
3034
|
{
|
|
3035
3035
|
...e,
|
|
3036
3036
|
kind: an,
|
|
@@ -3059,7 +3059,7 @@ var hc = {};
|
|
|
3059
3059
|
D(hc, {
|
|
3060
3060
|
matchAll: () => dc,
|
|
3061
3061
|
regex: () => dn,
|
|
3062
|
-
replaceAll: () =>
|
|
3062
|
+
replaceAll: () => pc
|
|
3063
3063
|
});
|
|
3064
3064
|
var dn = () => new RegExp(`\\b${mt.source}\\b`, "g");
|
|
3065
3065
|
function* dc(e) {
|
|
@@ -3077,15 +3077,15 @@ function* dc(e) {
|
|
|
3077
3077
|
} catch {
|
|
3078
3078
|
}
|
|
3079
3079
|
}
|
|
3080
|
-
function
|
|
3080
|
+
function pc(e, t) {
|
|
3081
3081
|
return e.replaceAll(dn(), (n, r) => t({
|
|
3082
3082
|
uri: n,
|
|
3083
3083
|
value: r,
|
|
3084
3084
|
decoded: gt(r)
|
|
3085
3085
|
}));
|
|
3086
3086
|
}
|
|
3087
|
-
var
|
|
3088
|
-
D(
|
|
3087
|
+
var yc = {};
|
|
3088
|
+
D(yc, {
|
|
3089
3089
|
channelCreateEvent: () => gc,
|
|
3090
3090
|
channelHideMessageEvent: () => vc,
|
|
3091
3091
|
channelMessageEvent: () => bc,
|
|
@@ -3100,7 +3100,7 @@ var gc = (e, t) => {
|
|
|
3100
3100
|
n = e.content;
|
|
3101
3101
|
else
|
|
3102
3102
|
return;
|
|
3103
|
-
return
|
|
3103
|
+
return Q(
|
|
3104
3104
|
{
|
|
3105
3105
|
kind: $r,
|
|
3106
3106
|
tags: [...e.tags ?? []],
|
|
@@ -3117,7 +3117,7 @@ var gc = (e, t) => {
|
|
|
3117
3117
|
n = e.content;
|
|
3118
3118
|
else
|
|
3119
3119
|
return;
|
|
3120
|
-
return
|
|
3120
|
+
return Q(
|
|
3121
3121
|
{
|
|
3122
3122
|
kind: Tr,
|
|
3123
3123
|
tags: [["e", e.channel_create_event_id], ...e.tags ?? []],
|
|
@@ -3128,7 +3128,7 @@ var gc = (e, t) => {
|
|
|
3128
3128
|
);
|
|
3129
3129
|
}, bc = (e, t) => {
|
|
3130
3130
|
const n = [["e", e.channel_create_event_id, e.relay_url, "root"]];
|
|
3131
|
-
return e.reply_to_channel_message_event_id && n.push(["e", e.reply_to_channel_message_event_id, e.relay_url, "reply"]),
|
|
3131
|
+
return e.reply_to_channel_message_event_id && n.push(["e", e.reply_to_channel_message_event_id, e.relay_url, "reply"]), Q(
|
|
3132
3132
|
{
|
|
3133
3133
|
kind: Rr,
|
|
3134
3134
|
tags: [...n, ...e.tags ?? []],
|
|
@@ -3145,7 +3145,7 @@ var gc = (e, t) => {
|
|
|
3145
3145
|
n = e.content;
|
|
3146
3146
|
else
|
|
3147
3147
|
return;
|
|
3148
|
-
return
|
|
3148
|
+
return Q(
|
|
3149
3149
|
{
|
|
3150
3150
|
kind: Or,
|
|
3151
3151
|
tags: [["e", e.channel_message_event_id], ...e.tags ?? []],
|
|
@@ -3162,7 +3162,7 @@ var gc = (e, t) => {
|
|
|
3162
3162
|
n = e.content;
|
|
3163
3163
|
else
|
|
3164
3164
|
return;
|
|
3165
|
-
return
|
|
3165
|
+
return Q(
|
|
3166
3166
|
{
|
|
3167
3167
|
kind: Pr,
|
|
3168
3168
|
tags: [["p", e.pubkey_to_mute], ...e.tags ?? []],
|
|
@@ -3175,12 +3175,12 @@ var gc = (e, t) => {
|
|
|
3175
3175
|
D(Ec, {
|
|
3176
3176
|
EMOJI_SHORTCODE_REGEX: () => Yr,
|
|
3177
3177
|
matchAll: () => xc,
|
|
3178
|
-
regex: () =>
|
|
3178
|
+
regex: () => pn,
|
|
3179
3179
|
replaceAll: () => Kc
|
|
3180
3180
|
});
|
|
3181
|
-
var Yr = /:(\w+):/,
|
|
3181
|
+
var Yr = /:(\w+):/, pn = () => new RegExp(`\\B${Yr.source}\\B`, "g");
|
|
3182
3182
|
function* xc(e) {
|
|
3183
|
-
const t = e.matchAll(
|
|
3183
|
+
const t = e.matchAll(pn());
|
|
3184
3184
|
for (const n of t)
|
|
3185
3185
|
try {
|
|
3186
3186
|
const [r, i] = n;
|
|
@@ -3194,7 +3194,7 @@ function* xc(e) {
|
|
|
3194
3194
|
}
|
|
3195
3195
|
}
|
|
3196
3196
|
function Kc(e, t) {
|
|
3197
|
-
return e.replaceAll(
|
|
3197
|
+
return e.replaceAll(pn(), (n, r) => t({
|
|
3198
3198
|
shortcode: n,
|
|
3199
3199
|
name: r
|
|
3200
3200
|
}));
|
|
@@ -3204,17 +3204,17 @@ D(Nc, {
|
|
|
3204
3204
|
useFetchImplementation: () => Sc,
|
|
3205
3205
|
validateGithub: () => Ac
|
|
3206
3206
|
});
|
|
3207
|
-
var
|
|
3207
|
+
var yn;
|
|
3208
3208
|
try {
|
|
3209
|
-
|
|
3209
|
+
yn = fetch;
|
|
3210
3210
|
} catch {
|
|
3211
3211
|
}
|
|
3212
3212
|
function Sc(e) {
|
|
3213
|
-
|
|
3213
|
+
yn = e;
|
|
3214
3214
|
}
|
|
3215
3215
|
async function Ac(e, t, n) {
|
|
3216
3216
|
try {
|
|
3217
|
-
return await (await
|
|
3217
|
+
return await (await yn(`https://gist.github.com/${t}/${n}/raw`)).text() === `Verifying that I control the following Nostr public key: ${e}`;
|
|
3218
3218
|
} catch {
|
|
3219
3219
|
return !1;
|
|
3220
3220
|
}
|
|
@@ -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) {
|
|
@@ -3257,7 +3257,7 @@ function Bc(e) {
|
|
|
3257
3257
|
const t = ne.encode(e), n = t.length, r = Cc(n), i = new Uint8Array(wn(n) - n);
|
|
3258
3258
|
return lt(r, t, i);
|
|
3259
3259
|
}
|
|
3260
|
-
function
|
|
3260
|
+
function kc(e) {
|
|
3261
3261
|
const t = new DataView(e.buffer).getUint16(0), n = e.subarray(2, 2 + t);
|
|
3262
3262
|
if (t < Xr || t > Qr || n.length !== t || e.length !== 2 + wn(t))
|
|
3263
3263
|
throw new Error("invalid padding");
|
|
@@ -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 _c(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 } = _c(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
|
-
return
|
|
3307
|
+
return kc(l);
|
|
3308
3308
|
}
|
|
3309
|
-
var
|
|
3309
|
+
var Ic = {
|
|
3310
3310
|
utils: {
|
|
3311
3311
|
getConversationKey: gn,
|
|
3312
3312
|
calcPaddedLen: wn
|
|
@@ -3336,7 +3336,7 @@ async function $c(e, t, n) {
|
|
|
3336
3336
|
content: i,
|
|
3337
3337
|
tags: [["p", e]]
|
|
3338
3338
|
};
|
|
3339
|
-
return
|
|
3339
|
+
return Q(s, t);
|
|
3340
3340
|
}
|
|
3341
3341
|
var Tc = {};
|
|
3342
3342
|
D(Tc, {
|
|
@@ -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("@");
|
|
@@ -3404,7 +3404,7 @@ function Mc(e) {
|
|
|
3404
3404
|
}
|
|
3405
3405
|
if (!dt(t))
|
|
3406
3406
|
return "Zap request is not a valid Nostr event.";
|
|
3407
|
-
if (!
|
|
3407
|
+
if (!yt(t))
|
|
3408
3408
|
return "Invalid signature on zap request.";
|
|
3409
3409
|
let n = t.tags.find(([s, o]) => s === "p" && o);
|
|
3410
3410
|
if (!n)
|
|
@@ -3447,10 +3447,10 @@ 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
|
-
return
|
|
3453
|
+
return Q(
|
|
3454
3454
|
{
|
|
3455
3455
|
kind: Lr,
|
|
3456
3456
|
content: si(e, t, n),
|
|
@@ -3461,8 +3461,8 @@ function ai(e, t, n) {
|
|
|
3461
3461
|
);
|
|
3462
3462
|
}
|
|
3463
3463
|
function ci(e, t) {
|
|
3464
|
-
const n =
|
|
3465
|
-
return
|
|
3464
|
+
const n = ke();
|
|
3465
|
+
return Q(
|
|
3466
3466
|
{
|
|
3467
3467
|
kind: Mr,
|
|
3468
3468
|
content: si(e, n, t),
|
|
@@ -3501,10 +3501,10 @@ D(Vc, {
|
|
|
3501
3501
|
unpackEventFromToken: () => fi,
|
|
3502
3502
|
validateEvent: () => wi,
|
|
3503
3503
|
validateEventKind: () => di,
|
|
3504
|
-
validateEventMethodTag: () =>
|
|
3504
|
+
validateEventMethodTag: () => yi,
|
|
3505
3505
|
validateEventPayloadTag: () => gi,
|
|
3506
3506
|
validateEventTimestamp: () => hi,
|
|
3507
|
-
validateEventUrlTag: () =>
|
|
3507
|
+
validateEventUrlTag: () => pi,
|
|
3508
3508
|
validateToken: () => Zc
|
|
3509
3509
|
});
|
|
3510
3510
|
var li = "Nostr ";
|
|
@@ -3545,11 +3545,11 @@ function hi(e) {
|
|
|
3545
3545
|
function di(e) {
|
|
3546
3546
|
return e.kind === cn;
|
|
3547
3547
|
}
|
|
3548
|
-
function
|
|
3548
|
+
function pi(e, t) {
|
|
3549
3549
|
const n = e.tags.find((r) => r[0] === "u");
|
|
3550
3550
|
return n ? n.length > 0 && n[1] === t : !1;
|
|
3551
3551
|
}
|
|
3552
|
-
function
|
|
3552
|
+
function yi(e, t) {
|
|
3553
3553
|
const n = e.tags.find((r) => r[0] === "method");
|
|
3554
3554
|
return n ? n.length > 0 && n[1].toLowerCase() === t.toLowerCase() : !1;
|
|
3555
3555
|
}
|
|
@@ -3565,21 +3565,21 @@ function gi(e, t) {
|
|
|
3565
3565
|
return n.length > 0 && n[1] === r;
|
|
3566
3566
|
}
|
|
3567
3567
|
async function wi(e, t, n, r) {
|
|
3568
|
-
if (!
|
|
3568
|
+
if (!yt(e))
|
|
3569
3569
|
throw new Error("Invalid nostr event, signature invalid");
|
|
3570
3570
|
if (!di(e))
|
|
3571
3571
|
throw new Error("Invalid nostr event, kind invalid");
|
|
3572
3572
|
if (!hi(e))
|
|
3573
3573
|
throw new Error("Invalid nostr event, created_at timestamp invalid");
|
|
3574
|
-
if (!
|
|
3574
|
+
if (!pi(e, t))
|
|
3575
3575
|
throw new Error("Invalid nostr event, url tag invalid");
|
|
3576
|
-
if (!
|
|
3576
|
+
if (!yi(e, n))
|
|
3577
3577
|
throw new Error("Invalid nostr event, method tag invalid");
|
|
3578
3578
|
if (r && typeof r == "object" && Object.keys(r).length > 0 && !gi(e, 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));
|
|
@@ -3711,11 +3711,12 @@ const Jc = 1e3, Yc = "0000000000000000000000000000000000000000000000000000000000
|
|
|
3711
3711
|
class st {
|
|
3712
3712
|
// 1. CHANNEL PUBLIC INTERFACE
|
|
3713
3713
|
constructor(t, n) {
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3714
|
+
J(this, "skippedSubscription");
|
|
3715
|
+
J(this, "nostrUnsubscribe");
|
|
3716
|
+
J(this, "nostrNextUnsubscribe");
|
|
3717
|
+
J(this, "internalSubscriptions", /* @__PURE__ */ new Map());
|
|
3718
|
+
J(this, "currentInternalSubscriptionId", 0);
|
|
3719
|
+
J(this, "name");
|
|
3719
3720
|
this.nostrSubscribe = t, this.state = n, this.name = Math.random().toString(36).substring(2, 6);
|
|
3720
3721
|
}
|
|
3721
3722
|
/**
|
|
@@ -3729,10 +3730,10 @@ class st {
|
|
|
3729
3730
|
* @returns A new Session instance
|
|
3730
3731
|
*/
|
|
3731
3732
|
static init(t, n, r, i, s, o) {
|
|
3732
|
-
const c =
|
|
3733
|
+
const c = ke(), [a, l] = Pe(s, q.getConversationKey(c, n), 2);
|
|
3733
3734
|
let f, u;
|
|
3734
3735
|
i ? (f = { publicKey: le(r), privateKey: r }, u = { publicKey: le(c), privateKey: c }) : u = { publicKey: le(r), privateKey: r };
|
|
3735
|
-
const
|
|
3736
|
+
const p = {
|
|
3736
3737
|
rootKey: i ? a : s,
|
|
3737
3738
|
theirNextNostrPublicKey: n,
|
|
3738
3739
|
ourCurrentNostrKey: f,
|
|
@@ -3743,7 +3744,7 @@ class st {
|
|
|
3743
3744
|
receivingChainMessageNumber: 0,
|
|
3744
3745
|
previousSendingChainMessageCount: 0,
|
|
3745
3746
|
skippedKeys: {}
|
|
3746
|
-
}, b = new st(t,
|
|
3747
|
+
}, b = new st(t, p);
|
|
3747
3748
|
return o && (b.name = o), b;
|
|
3748
3749
|
}
|
|
3749
3750
|
/**
|
|
@@ -3774,16 +3775,16 @@ class st {
|
|
|
3774
3775
|
const n = Date.now(), r = {
|
|
3775
3776
|
...t,
|
|
3776
3777
|
content: t.content || "",
|
|
3777
|
-
kind: t.kind ||
|
|
3778
|
+
kind: t.kind || Oe,
|
|
3778
3779
|
created_at: t.created_at || Math.floor(n / 1e3),
|
|
3779
3780
|
tags: t.tags || [],
|
|
3780
3781
|
pubkey: t.pubkey || Yc
|
|
3781
3782
|
};
|
|
3782
|
-
r.tags.some(([l]) => l === "ms") || r.tags.push(["ms", String(n)]), r.id =
|
|
3783
|
+
r.tags.some(([l]) => l === "ms") || r.tags.push(["ms", String(n)]), r.id = qe(r);
|
|
3783
3784
|
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
|
-
return { event:
|
|
3785
|
+
return { event: Q({
|
|
3785
3786
|
content: s,
|
|
3786
|
-
kind:
|
|
3787
|
+
kind: Oe,
|
|
3787
3788
|
tags: [["header", c]],
|
|
3788
3789
|
created_at: Math.floor(n / 1e3)
|
|
3789
3790
|
}, this.state.ourCurrentNostrKey.privateKey), innerEvent: r };
|
|
@@ -3801,12 +3802,12 @@ class st {
|
|
|
3801
3802
|
* Stop listening to incoming messages
|
|
3802
3803
|
*/
|
|
3803
3804
|
close() {
|
|
3804
|
-
var t, n;
|
|
3805
|
-
(t = this.nostrUnsubscribe) == null || t.call(this), (n = this.nostrNextUnsubscribe) == null || n.call(this);
|
|
3805
|
+
var t, n, r;
|
|
3806
|
+
(t = this.nostrUnsubscribe) == null || t.call(this), (n = this.nostrNextUnsubscribe) == null || n.call(this), (r = this.skippedSubscription) == null || r.call(this), this.internalSubscriptions.clear();
|
|
3806
3807
|
}
|
|
3807
3808
|
// 2. RATCHET FUNCTIONS
|
|
3808
3809
|
ratchetEncrypt(t) {
|
|
3809
|
-
const [n, r] =
|
|
3810
|
+
const [n, r] = Pe(this.state.sendingChainKey, new Uint8Array([1]), 2);
|
|
3810
3811
|
return this.state.sendingChainKey = n, [{
|
|
3811
3812
|
number: this.state.sendingChainMessageNumber++,
|
|
3812
3813
|
nextPublicKey: this.state.ourNextNostrKey.publicKey,
|
|
@@ -3817,7 +3818,7 @@ class st {
|
|
|
3817
3818
|
const i = this.trySkippedMessageKeys(t, n, r);
|
|
3818
3819
|
if (i) return i;
|
|
3819
3820
|
this.skipMessageKeys(t.number, r);
|
|
3820
|
-
const [s, o] =
|
|
3821
|
+
const [s, o] = Pe(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3821
3822
|
this.state.receivingChainKey = s, this.state.receivingChainMessageNumber++;
|
|
3822
3823
|
try {
|
|
3823
3824
|
return q.decrypt(n, o);
|
|
@@ -3832,14 +3833,14 @@ class st {
|
|
|
3832
3833
|
}
|
|
3833
3834
|
ratchetStep(t) {
|
|
3834
3835
|
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] =
|
|
3836
|
+
const n = q.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [r, i] = Pe(this.state.rootKey, n, 2);
|
|
3836
3837
|
this.state.receivingChainKey = i, this.state.ourCurrentNostrKey = this.state.ourNextNostrKey;
|
|
3837
|
-
const s =
|
|
3838
|
+
const s = ke();
|
|
3838
3839
|
this.state.ourNextNostrKey = {
|
|
3839
3840
|
publicKey: le(s),
|
|
3840
3841
|
privateKey: s
|
|
3841
3842
|
};
|
|
3842
|
-
const o = q.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [c, a] =
|
|
3843
|
+
const o = q.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [c, a] = Pe(r, o, 2);
|
|
3843
3844
|
this.state.rootKey = c, this.state.sendingChainKey = a;
|
|
3844
3845
|
}
|
|
3845
3846
|
// 3. MESSAGE KEY FUNCTIONS
|
|
@@ -3858,16 +3859,15 @@ class st {
|
|
|
3858
3859
|
this.state.skippedKeys[n].headerKeys.push(r);
|
|
3859
3860
|
}
|
|
3860
3861
|
for (; this.state.receivingChainMessageNumber < t; ) {
|
|
3861
|
-
const [r, i] =
|
|
3862
|
+
const [r, i] = Pe(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3862
3863
|
this.state.receivingChainKey = r, this.state.skippedKeys[n].messageKeys[this.state.receivingChainMessageNumber] = i, this.state.receivingChainMessageNumber++;
|
|
3863
3864
|
}
|
|
3864
3865
|
}
|
|
3865
3866
|
trySkippedMessageKeys(t, n, r) {
|
|
3866
|
-
var o;
|
|
3867
3867
|
const i = this.state.skippedKeys[r];
|
|
3868
3868
|
if (!i) return null;
|
|
3869
3869
|
const s = i.messageKeys[t.number];
|
|
3870
|
-
return s ? (delete i.messageKeys[t.number], Object.keys(i.messageKeys).length === 0 &&
|
|
3870
|
+
return s ? (delete i.messageKeys[t.number], Object.keys(i.messageKeys).length === 0 && delete this.state.skippedKeys[r], q.decrypt(n, s)) : null;
|
|
3871
3871
|
}
|
|
3872
3872
|
// 4. NOSTR EVENT HANDLING
|
|
3873
3873
|
decryptHeader(t) {
|
|
@@ -3894,52 +3894,58 @@ class st {
|
|
|
3894
3894
|
throw new Error("Failed to decrypt header with current and skipped header keys");
|
|
3895
3895
|
}
|
|
3896
3896
|
handleNostrEvent(t) {
|
|
3897
|
-
var c;
|
|
3897
|
+
var c, a;
|
|
3898
3898
|
const [n, r, i] = this.decryptHeader(t);
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3899
|
+
if (!i)
|
|
3900
|
+
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(
|
|
3901
|
+
{ authors: [this.state.theirNextNostrPublicKey], kinds: [Oe] },
|
|
3902
|
+
(l) => this.handleNostrEvent(l)
|
|
3903
|
+
)), r && (this.skipMessageKeys(n.previousChainLength, t.pubkey), this.ratchetStep(n.nextPublicKey));
|
|
3904
|
+
else if (!((a = this.state.skippedKeys[t.pubkey]) != null && a.messageKeys[n.number]))
|
|
3905
|
+
return;
|
|
3903
3906
|
const s = this.ratchetDecrypt(n, t.content, t.pubkey), o = JSON.parse(s);
|
|
3904
3907
|
if (!dt(o)) {
|
|
3905
3908
|
console.error("Invalid event received", o);
|
|
3906
3909
|
return;
|
|
3907
3910
|
}
|
|
3908
|
-
if (o.id !==
|
|
3911
|
+
if (o.id !== qe(o)) {
|
|
3909
3912
|
console.error("Event hash does not match", o);
|
|
3910
3913
|
return;
|
|
3911
3914
|
}
|
|
3912
|
-
this.internalSubscriptions.forEach((
|
|
3915
|
+
this.internalSubscriptions.forEach((l) => l(o, t));
|
|
3913
3916
|
}
|
|
3914
3917
|
subscribeToNostrEvents() {
|
|
3915
3918
|
if (this.nostrNextUnsubscribe) return;
|
|
3916
3919
|
this.nostrNextUnsubscribe = this.nostrSubscribe(
|
|
3917
|
-
{ authors: [this.state.theirNextNostrPublicKey], kinds: [
|
|
3920
|
+
{ authors: [this.state.theirNextNostrPublicKey], kinds: [Oe] },
|
|
3918
3921
|
(n) => this.handleNostrEvent(n)
|
|
3919
|
-
)
|
|
3922
|
+
), this.state.theirCurrentNostrPublicKey && (this.nostrUnsubscribe = this.nostrSubscribe(
|
|
3923
|
+
{ authors: [this.state.theirCurrentNostrPublicKey], kinds: [Oe] },
|
|
3924
|
+
(n) => this.handleNostrEvent(n)
|
|
3925
|
+
));
|
|
3920
3926
|
const t = Object.keys(this.state.skippedKeys);
|
|
3921
|
-
|
|
3922
|
-
{ authors: t, kinds: [
|
|
3927
|
+
t.length && (this.skippedSubscription = this.nostrSubscribe(
|
|
3928
|
+
{ authors: t, kinds: [Oe] },
|
|
3923
3929
|
(n) => this.handleNostrEvent(n)
|
|
3924
|
-
);
|
|
3930
|
+
));
|
|
3925
3931
|
}
|
|
3926
3932
|
}
|
|
3927
3933
|
new TextDecoder("utf-8");
|
|
3928
3934
|
new TextEncoder();
|
|
3929
3935
|
function Qe(e, t) {
|
|
3930
|
-
const n =
|
|
3936
|
+
const n = Ie.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3931
3937
|
return rn(fe, n, "nip44-v2");
|
|
3932
3938
|
}
|
|
3933
3939
|
const Xc = 2 * 24 * 60 * 60, Qc = () => Math.round(Date.now() / 1e3), eu = () => Math.round(Qc() - Math.random() * Xc);
|
|
3934
|
-
class
|
|
3940
|
+
class Me {
|
|
3935
3941
|
constructor(t, n, r, i, s, o, c = []) {
|
|
3936
3942
|
this.inviterEphemeralPublicKey = t, this.sharedSecret = n, this.inviter = r, this.inviterEphemeralPrivateKey = i, this.label = s, this.maxUses = o, this.usedBy = c;
|
|
3937
3943
|
}
|
|
3938
3944
|
static createNew(t, n, r) {
|
|
3939
3945
|
if (!t)
|
|
3940
3946
|
throw new Error("Inviter public key is required");
|
|
3941
|
-
const i =
|
|
3942
|
-
return new
|
|
3947
|
+
const i = ke(), s = le(i), o = P(ke());
|
|
3948
|
+
return new Me(
|
|
3943
3949
|
s,
|
|
3944
3950
|
o,
|
|
3945
3951
|
t,
|
|
@@ -3962,7 +3968,7 @@ class Pe {
|
|
|
3962
3968
|
const { inviter: o, ephemeralKey: c, sharedSecret: a } = s;
|
|
3963
3969
|
if (!o || !c || !a)
|
|
3964
3970
|
throw new Error("Missing required fields (inviter, ephemeralKey, sharedSecret) in invite data.");
|
|
3965
|
-
return new
|
|
3971
|
+
return new Me(
|
|
3966
3972
|
c,
|
|
3967
3973
|
a,
|
|
3968
3974
|
o
|
|
@@ -3970,7 +3976,7 @@ class Pe {
|
|
|
3970
3976
|
}
|
|
3971
3977
|
static deserialize(t) {
|
|
3972
3978
|
const n = JSON.parse(t);
|
|
3973
|
-
return new
|
|
3979
|
+
return new Me(
|
|
3974
3980
|
n.inviterEphemeralPublicKey,
|
|
3975
3981
|
n.sharedSecret,
|
|
3976
3982
|
n.inviter,
|
|
@@ -3984,7 +3990,7 @@ class Pe {
|
|
|
3984
3990
|
var o, c;
|
|
3985
3991
|
if (!t.sig)
|
|
3986
3992
|
throw new Error("Event is not signed");
|
|
3987
|
-
if (!
|
|
3993
|
+
if (!yt(t))
|
|
3988
3994
|
throw new Error("Event signature is invalid");
|
|
3989
3995
|
const { tags: n } = t;
|
|
3990
3996
|
if (!n)
|
|
@@ -3992,7 +3998,7 @@ class Pe {
|
|
|
3992
3998
|
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
3999
|
if (!r || !i)
|
|
3994
4000
|
throw new Error("Invalid invite event: missing session key or sharedSecret");
|
|
3995
|
-
return new
|
|
4001
|
+
return new Me(
|
|
3996
4002
|
r,
|
|
3997
4003
|
i,
|
|
3998
4004
|
s
|
|
@@ -4010,7 +4016,7 @@ class Pe {
|
|
|
4010
4016
|
if (!(!c.created_at || c.created_at <= s)) {
|
|
4011
4017
|
s = c.created_at;
|
|
4012
4018
|
try {
|
|
4013
|
-
const a =
|
|
4019
|
+
const a = Me.fromEvent(c);
|
|
4014
4020
|
r(a);
|
|
4015
4021
|
} catch (a) {
|
|
4016
4022
|
console.error("Error processing invite:", a, "event:", c);
|
|
@@ -4073,18 +4079,18 @@ class Pe {
|
|
|
4073
4079
|
* so the inviter can create the session on their side.
|
|
4074
4080
|
*/
|
|
4075
4081
|
async accept(t, n, r) {
|
|
4076
|
-
const i =
|
|
4082
|
+
const i = ke(), s = le(i), o = this.inviter || this.inviterEphemeralPublicKey, c = z(this.sharedSecret), a = st.init(t, this.inviterEphemeralPublicKey, i, !0, c, void 0), f = await (typeof r == "function" ? r : (h, d) => Promise.resolve(q.encrypt(h, Qe(r, d))))(s, o), u = {
|
|
4077
4083
|
pubkey: n,
|
|
4078
4084
|
content: await q.encrypt(f, c),
|
|
4079
4085
|
created_at: Math.floor(Date.now() / 1e3)
|
|
4080
|
-
},
|
|
4086
|
+
}, p = ke(), b = le(p), y = {
|
|
4081
4087
|
kind: jn,
|
|
4082
4088
|
pubkey: b,
|
|
4083
|
-
content: q.encrypt(JSON.stringify(u), Qe(
|
|
4089
|
+
content: q.encrypt(JSON.stringify(u), Qe(p, this.inviterEphemeralPublicKey)),
|
|
4084
4090
|
created_at: eu(),
|
|
4085
4091
|
tags: [["p", this.inviterEphemeralPublicKey]]
|
|
4086
4092
|
};
|
|
4087
|
-
return { session: a, event:
|
|
4093
|
+
return { session: a, event: Q(y, p) };
|
|
4088
4094
|
}
|
|
4089
4095
|
listen(t, n, r) {
|
|
4090
4096
|
if (!this.inviterEphemeralPrivateKey)
|
|
@@ -4101,8 +4107,8 @@ class Pe {
|
|
|
4101
4107
|
}
|
|
4102
4108
|
const o = await q.decrypt(s.content, Qe(this.inviterEphemeralPrivateKey, s.pubkey)), c = JSON.parse(o), a = z(this.sharedSecret), l = c.pubkey;
|
|
4103
4109
|
this.usedBy.push(l);
|
|
4104
|
-
const f = await q.decrypt(c.content, a),
|
|
4105
|
-
r(
|
|
4110
|
+
const f = await q.decrypt(c.content, a), p = await (typeof t == "function" ? t : (h, d) => Promise.resolve(q.decrypt(h, Qe(t, d))))(f, l), b = s.id, y = st.init(n, p, this.inviterEphemeralPrivateKey, !1, a, b);
|
|
4111
|
+
r(y, l);
|
|
4106
4112
|
} catch (o) {
|
|
4107
4113
|
console.error("Error processing invite message:", o, "event", s);
|
|
4108
4114
|
}
|
|
@@ -4113,14 +4119,14 @@ export {
|
|
|
4113
4119
|
Gc as CHAT_MESSAGE_KIND,
|
|
4114
4120
|
Dn as INVITE_EVENT_KIND,
|
|
4115
4121
|
jn as INVITE_RESPONSE_KIND,
|
|
4116
|
-
|
|
4122
|
+
Me as Invite,
|
|
4117
4123
|
au as MAX_SKIP,
|
|
4118
|
-
|
|
4124
|
+
Oe as MESSAGE_EVENT_KIND,
|
|
4119
4125
|
st as Session,
|
|
4120
4126
|
lu as createEventStream,
|
|
4121
4127
|
uu as deserializeSessionState,
|
|
4122
4128
|
hu as getMillisecondTimestamp,
|
|
4123
|
-
|
|
4129
|
+
Pe as kdf,
|
|
4124
4130
|
cu as serializeSessionState,
|
|
4125
4131
|
fu as skippedMessageIndexKey
|
|
4126
4132
|
};
|