nostr-double-ratchet 0.0.31 → 0.0.33
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/README.md +4 -2
- package/dist/Invite.d.ts +5 -0
- package/dist/Invite.d.ts.map +1 -1
- package/dist/SessionManager.d.ts +2 -1
- package/dist/SessionManager.d.ts.map +1 -1
- package/dist/UserRecord.d.ts +78 -31
- package/dist/UserRecord.d.ts.map +1 -1
- package/dist/nostr-double-ratchet.es.js +360 -335
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/package.json +4 -4
- package/src/Invite.ts +25 -0
- package/src/SessionManager.ts +18 -11
- package/src/UserRecord.ts +235 -146
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var J = (e, t, n) =>
|
|
4
|
-
function
|
|
1
|
+
var Ki = Object.defineProperty;
|
|
2
|
+
var Ni = (e, t, n) => t in e ? Ki(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var J = (e, t, n) => Ni(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
function kn(e) {
|
|
5
5
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
6
6
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
7
7
|
}
|
|
@@ -14,7 +14,7 @@ function Fn(e, ...t) {
|
|
|
14
14
|
function Si(e) {
|
|
15
15
|
if (typeof e != "function" || typeof e.create != "function")
|
|
16
16
|
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
17
|
-
|
|
17
|
+
kn(e.outputLen), kn(e.blockLen);
|
|
18
18
|
}
|
|
19
19
|
function et(e, t = !0) {
|
|
20
20
|
if (e.destroyed)
|
|
@@ -30,7 +30,7 @@ function Ai(e, t) {
|
|
|
30
30
|
}
|
|
31
31
|
const xt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
32
32
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
33
|
-
const Gn = (e) => e instanceof Uint8Array,
|
|
33
|
+
const Gn = (e) => e instanceof Uint8Array, Kt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), re = (e, t) => e << 32 - t | e >>> t, Ci = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
34
34
|
if (!Ci)
|
|
35
35
|
throw new Error("Non little-endian hardware is not supported");
|
|
36
36
|
function Bi(e) {
|
|
@@ -38,7 +38,7 @@ function Bi(e) {
|
|
|
38
38
|
throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
|
|
39
39
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function Vt(e) {
|
|
42
42
|
if (typeof e == "string" && (e = Bi(e)), !Gn(e))
|
|
43
43
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
44
44
|
return e;
|
|
@@ -59,7 +59,7 @@ let Jn = class {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
function Ii(e) {
|
|
62
|
-
const t = (r) => e().update(
|
|
62
|
+
const t = (r) => e().update(Vt(r)).digest(), n = e();
|
|
63
63
|
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
64
64
|
}
|
|
65
65
|
function Yn(e = 32) {
|
|
@@ -75,17 +75,17 @@ function _i(e, t, n, r) {
|
|
|
75
75
|
}
|
|
76
76
|
let Ui = class extends Jn {
|
|
77
77
|
constructor(t, n, r, i) {
|
|
78
|
-
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view =
|
|
78
|
+
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view = Kt(this.buffer);
|
|
79
79
|
}
|
|
80
80
|
update(t) {
|
|
81
81
|
et(this);
|
|
82
82
|
const { view: n, buffer: r, blockLen: i } = this;
|
|
83
|
-
t =
|
|
83
|
+
t = Vt(t);
|
|
84
84
|
const s = t.length;
|
|
85
85
|
for (let o = 0; o < s; ) {
|
|
86
86
|
const c = Math.min(i - this.pos, s - o);
|
|
87
87
|
if (c === i) {
|
|
88
|
-
const a =
|
|
88
|
+
const a = Kt(t);
|
|
89
89
|
for (; i <= s - o; o += i)
|
|
90
90
|
this.process(a, o);
|
|
91
91
|
continue;
|
|
@@ -102,7 +102,7 @@ let Ui = class extends Jn {
|
|
|
102
102
|
for (let u = o; u < i; u++)
|
|
103
103
|
n[u] = 0;
|
|
104
104
|
_i(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
105
|
-
const c =
|
|
105
|
+
const c = Kt(t), a = this.outputLen;
|
|
106
106
|
if (a % 4)
|
|
107
107
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
108
108
|
const l = a / 4, f = this.get();
|
|
@@ -231,10 +231,10 @@ let Ti = class extends Ui {
|
|
|
231
231
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
|
|
232
232
|
}
|
|
233
233
|
};
|
|
234
|
-
const
|
|
234
|
+
const $t = /* @__PURE__ */ Ii(() => new Ti());
|
|
235
235
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
236
236
|
const Xn = BigInt(0), at = BigInt(1), Oi = BigInt(2), ct = (e) => e instanceof Uint8Array, Mi = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
237
|
-
function
|
|
237
|
+
function qe(e) {
|
|
238
238
|
if (!ct(e))
|
|
239
239
|
throw new Error("Uint8Array expected");
|
|
240
240
|
let t = "";
|
|
@@ -246,7 +246,7 @@ function Qn(e) {
|
|
|
246
246
|
const t = e.toString(16);
|
|
247
247
|
return t.length & 1 ? `0${t}` : t;
|
|
248
248
|
}
|
|
249
|
-
function
|
|
249
|
+
function Zt(e) {
|
|
250
250
|
if (typeof e != "string")
|
|
251
251
|
throw new Error("hex string expected, got " + typeof e);
|
|
252
252
|
return BigInt(e === "" ? "0" : `0x${e}`);
|
|
@@ -267,18 +267,18 @@ function je(e) {
|
|
|
267
267
|
return n;
|
|
268
268
|
}
|
|
269
269
|
function G(e) {
|
|
270
|
-
return
|
|
270
|
+
return Zt(qe(e));
|
|
271
271
|
}
|
|
272
|
-
function
|
|
272
|
+
function Ft(e) {
|
|
273
273
|
if (!ct(e))
|
|
274
274
|
throw new Error("Uint8Array expected");
|
|
275
|
-
return
|
|
275
|
+
return Zt(qe(Uint8Array.from(e).reverse()));
|
|
276
276
|
}
|
|
277
|
-
function
|
|
277
|
+
function Ne(e, t) {
|
|
278
278
|
return je(e.toString(16).padStart(t * 2, "0"));
|
|
279
279
|
}
|
|
280
|
-
function
|
|
281
|
-
return
|
|
280
|
+
function Gt(e, t) {
|
|
281
|
+
return Ne(e, t).reverse();
|
|
282
282
|
}
|
|
283
283
|
function Pi(e) {
|
|
284
284
|
return je(Qn(e));
|
|
@@ -317,12 +317,12 @@ function Hi(e, t) {
|
|
|
317
317
|
return !1;
|
|
318
318
|
return !0;
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function Di(e) {
|
|
321
321
|
if (typeof e != "string")
|
|
322
322
|
throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
|
|
323
323
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
324
324
|
}
|
|
325
|
-
function
|
|
325
|
+
function qi(e) {
|
|
326
326
|
let t;
|
|
327
327
|
for (t = 0; e > Xn; e >>= at, t += 1)
|
|
328
328
|
;
|
|
@@ -331,7 +331,7 @@ function Di(e) {
|
|
|
331
331
|
function ji(e, t) {
|
|
332
332
|
return e >> BigInt(t) & at;
|
|
333
333
|
}
|
|
334
|
-
const zi = (e, t, n) => e | (n ? at : Xn) << BigInt(t),
|
|
334
|
+
const zi = (e, t, n) => e | (n ? at : Xn) << BigInt(t), Jt = (e) => (Oi << BigInt(e - 1)) - at, Nt = (e) => new Uint8Array(e), In = (e) => Uint8Array.from(e);
|
|
335
335
|
function er(e, t, n) {
|
|
336
336
|
if (typeof e != "number" || e < 2)
|
|
337
337
|
throw new Error("hashLen must be a number");
|
|
@@ -339,11 +339,11 @@ function er(e, t, n) {
|
|
|
339
339
|
throw new Error("qByteLen must be a number");
|
|
340
340
|
if (typeof n != "function")
|
|
341
341
|
throw new Error("hmacFn must be a function");
|
|
342
|
-
let r =
|
|
342
|
+
let r = Nt(e), i = Nt(e), s = 0;
|
|
343
343
|
const o = () => {
|
|
344
344
|
r.fill(1), i.fill(0), s = 0;
|
|
345
|
-
}, c = (...u) => n(i, r, ...u), a = (u =
|
|
346
|
-
i = c(
|
|
345
|
+
}, c = (...u) => n(i, r, ...u), a = (u = Nt()) => {
|
|
346
|
+
i = c(In([0]), u), r = c(), u.length !== 0 && (i = c(In([1]), u), r = c());
|
|
347
347
|
}, l = () => {
|
|
348
348
|
if (s++ >= 1e3)
|
|
349
349
|
throw new Error("drbg: tried 1000 values");
|
|
@@ -393,27 +393,27 @@ function Ye(e, t, n = {}) {
|
|
|
393
393
|
const Vi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
394
394
|
__proto__: null,
|
|
395
395
|
bitGet: ji,
|
|
396
|
-
bitLen:
|
|
397
|
-
bitMask:
|
|
396
|
+
bitLen: qi,
|
|
397
|
+
bitMask: Jt,
|
|
398
398
|
bitSet: zi,
|
|
399
|
-
bytesToHex:
|
|
399
|
+
bytesToHex: qe,
|
|
400
400
|
bytesToNumberBE: G,
|
|
401
|
-
bytesToNumberLE:
|
|
401
|
+
bytesToNumberLE: Ft,
|
|
402
402
|
concatBytes: Ie,
|
|
403
403
|
createHmacDrbg: er,
|
|
404
404
|
ensureBytes: Z,
|
|
405
405
|
equalBytes: Hi,
|
|
406
406
|
hexToBytes: je,
|
|
407
|
-
hexToNumber:
|
|
408
|
-
numberToBytesBE:
|
|
409
|
-
numberToBytesLE:
|
|
407
|
+
hexToNumber: Zt,
|
|
408
|
+
numberToBytesBE: Ne,
|
|
409
|
+
numberToBytesLE: Gt,
|
|
410
410
|
numberToHexUnpadded: Qn,
|
|
411
411
|
numberToVarBytesBE: Pi,
|
|
412
|
-
utf8ToBytes:
|
|
412
|
+
utf8ToBytes: Di,
|
|
413
413
|
validateObject: Ye
|
|
414
414
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
415
415
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
416
|
-
const W = BigInt(0), z = BigInt(1), Ce = BigInt(2), Zi = BigInt(3),
|
|
416
|
+
const W = BigInt(0), z = BigInt(1), Ce = BigInt(2), Zi = BigInt(3), Rt = BigInt(4), _n = BigInt(5), Un = BigInt(8);
|
|
417
417
|
BigInt(9);
|
|
418
418
|
BigInt(16);
|
|
419
419
|
function V(e, t) {
|
|
@@ -436,7 +436,7 @@ function Y(e, t, n) {
|
|
|
436
436
|
r *= r, r %= n;
|
|
437
437
|
return r;
|
|
438
438
|
}
|
|
439
|
-
function
|
|
439
|
+
function Tt(e, t) {
|
|
440
440
|
if (e === W || t <= W)
|
|
441
441
|
throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);
|
|
442
442
|
let n = V(e, t), r = t, i = W, s = z;
|
|
@@ -456,7 +456,7 @@ function Gi(e) {
|
|
|
456
456
|
for (i = Ce; i < e && Fi(i, t, e) !== e - z; i++)
|
|
457
457
|
;
|
|
458
458
|
if (r === 1) {
|
|
459
|
-
const o = (e + z) /
|
|
459
|
+
const o = (e + z) / Rt;
|
|
460
460
|
return function(a, l) {
|
|
461
461
|
const f = a.pow(l, o);
|
|
462
462
|
if (!a.eql(a.sqr(f), l))
|
|
@@ -482,8 +482,8 @@ function Gi(e) {
|
|
|
482
482
|
};
|
|
483
483
|
}
|
|
484
484
|
function Ji(e) {
|
|
485
|
-
if (e %
|
|
486
|
-
const t = (e + z) /
|
|
485
|
+
if (e % Rt === Zi) {
|
|
486
|
+
const t = (e + z) / Rt;
|
|
487
487
|
return function(r, i) {
|
|
488
488
|
const s = r.pow(i, t);
|
|
489
489
|
if (!r.eql(r.sqr(s), i))
|
|
@@ -491,8 +491,8 @@ function Ji(e) {
|
|
|
491
491
|
return s;
|
|
492
492
|
};
|
|
493
493
|
}
|
|
494
|
-
if (e %
|
|
495
|
-
const t = (e -
|
|
494
|
+
if (e % Un === _n) {
|
|
495
|
+
const t = (e - _n) / Un;
|
|
496
496
|
return function(r, i) {
|
|
497
497
|
const s = r.mul(i, Ce), o = r.pow(s, t), c = r.mul(i, o), a = r.mul(r.mul(c, Ce), o), l = r.mul(c, r.sub(a, r.ONE));
|
|
498
498
|
if (!r.eql(r.sqr(l), i))
|
|
@@ -560,7 +560,7 @@ function ts(e, t, n = !1, r = {}) {
|
|
|
560
560
|
ORDER: e,
|
|
561
561
|
BITS: i,
|
|
562
562
|
BYTES: s,
|
|
563
|
-
MASK:
|
|
563
|
+
MASK: Jt(i),
|
|
564
564
|
ZERO: W,
|
|
565
565
|
ONE: z,
|
|
566
566
|
create: (a) => V(a, e),
|
|
@@ -578,23 +578,23 @@ function ts(e, t, n = !1, r = {}) {
|
|
|
578
578
|
sub: (a, l) => V(a - l, e),
|
|
579
579
|
mul: (a, l) => V(a * l, e),
|
|
580
580
|
pow: (a, l) => Qi(c, a, l),
|
|
581
|
-
div: (a, l) => V(a *
|
|
581
|
+
div: (a, l) => V(a * Tt(l, e), e),
|
|
582
582
|
// Same as above, but doesn't normalize
|
|
583
583
|
sqrN: (a) => a * a,
|
|
584
584
|
addN: (a, l) => a + l,
|
|
585
585
|
subN: (a, l) => a - l,
|
|
586
586
|
mulN: (a, l) => a * l,
|
|
587
|
-
inv: (a) =>
|
|
587
|
+
inv: (a) => Tt(a, e),
|
|
588
588
|
sqrt: r.sqrt || ((a) => o(c, a)),
|
|
589
589
|
invertBatch: (a) => es(c, a),
|
|
590
590
|
// TODO: do we really need constant cmov?
|
|
591
591
|
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
592
592
|
cmov: (a, l, f) => f ? l : a,
|
|
593
|
-
toBytes: (a) => n ?
|
|
593
|
+
toBytes: (a) => n ? Gt(a, s) : Ne(a, s),
|
|
594
594
|
fromBytes: (a) => {
|
|
595
595
|
if (a.length !== s)
|
|
596
596
|
throw new Error(`Fp.fromBytes: expected ${s}, got ${a.length}`);
|
|
597
|
-
return n ?
|
|
597
|
+
return n ? Ft(a) : G(a);
|
|
598
598
|
}
|
|
599
599
|
});
|
|
600
600
|
return Object.freeze(c);
|
|
@@ -613,8 +613,8 @@ function ns(e, t, n = !1) {
|
|
|
613
613
|
const r = e.length, i = nr(t), s = rr(t);
|
|
614
614
|
if (r < 16 || r < s || r > 1024)
|
|
615
615
|
throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);
|
|
616
|
-
const o = n ? G(e) :
|
|
617
|
-
return n ?
|
|
616
|
+
const o = n ? G(e) : Ft(e), c = V(o, t - z) + z;
|
|
617
|
+
return n ? Gt(c, i) : Ne(c, i);
|
|
618
618
|
}
|
|
619
619
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
620
620
|
const rs = BigInt(0), St = BigInt(1);
|
|
@@ -765,7 +765,7 @@ const { bytesToNumberBE: os, hexToBytes: as } = Vi, Be = {
|
|
|
765
765
|
}
|
|
766
766
|
}, ce = BigInt(0), X = BigInt(1);
|
|
767
767
|
BigInt(2);
|
|
768
|
-
const
|
|
768
|
+
const Ln = BigInt(3);
|
|
769
769
|
BigInt(4);
|
|
770
770
|
function cs(e) {
|
|
771
771
|
const t = ss(e), { Fp: n } = t, r = t.toBytes || ((g, h, d) => {
|
|
@@ -791,7 +791,7 @@ function cs(e) {
|
|
|
791
791
|
function a(g) {
|
|
792
792
|
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey: y, n: E } = t;
|
|
793
793
|
if (h && typeof g != "bigint") {
|
|
794
|
-
if (g instanceof Uint8Array && (g =
|
|
794
|
+
if (g instanceof Uint8Array && (g = qe(g)), typeof g != "string" || !h.includes(g.length))
|
|
795
795
|
throw new Error("Invalid key");
|
|
796
796
|
g = g.padStart(d * 2, "0");
|
|
797
797
|
}
|
|
@@ -901,9 +901,9 @@ function cs(e) {
|
|
|
901
901
|
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
902
902
|
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
903
903
|
double() {
|
|
904
|
-
const { a: h, b: d } = t, y = n.mul(d,
|
|
905
|
-
let B = n.ZERO, m = n.ZERO, x = n.ZERO,
|
|
906
|
-
return A = n.add(A, A), x = n.mul(E, _), x = n.add(x, x), B = n.mul(h, x), m = n.mul(y, I), m = n.add(B, m), B = n.sub(M, m), m = n.add(M, m), m = n.mul(B, m), B = n.mul(A, B), x = n.mul(y, x), I = n.mul(h, I), A = n.sub(
|
|
904
|
+
const { a: h, b: d } = t, y = n.mul(d, Ln), { px: E, py: S, pz: _ } = this;
|
|
905
|
+
let B = n.ZERO, m = n.ZERO, x = n.ZERO, K = n.mul(E, E), M = n.mul(S, S), I = n.mul(_, _), A = n.mul(E, S);
|
|
906
|
+
return A = n.add(A, A), x = n.mul(E, _), x = n.add(x, x), B = n.mul(h, x), m = n.mul(y, I), m = n.add(B, m), B = n.sub(M, m), m = n.add(M, m), m = n.mul(B, m), B = n.mul(A, B), x = n.mul(y, x), I = n.mul(h, I), A = n.sub(K, I), A = n.mul(h, A), A = n.add(A, x), x = n.add(K, K), K = n.add(x, K), K = n.add(K, I), K = n.mul(K, A), m = n.add(m, K), I = n.mul(S, _), I = n.add(I, I), K = n.mul(I, A), B = n.sub(B, K), x = n.mul(I, M), x = n.add(x, x), x = n.add(x, x), new u(B, m, x);
|
|
907
907
|
}
|
|
908
908
|
// Renes-Costello-Batina exception-free addition formula.
|
|
909
909
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
@@ -912,12 +912,12 @@ function cs(e) {
|
|
|
912
912
|
add(h) {
|
|
913
913
|
f(h);
|
|
914
914
|
const { px: d, py: y, pz: E } = this, { px: S, py: _, pz: B } = h;
|
|
915
|
-
let m = n.ZERO, x = n.ZERO,
|
|
916
|
-
const M = t.a, I = n.mul(t.b,
|
|
917
|
-
let A = n.mul(d, S), R = n.mul(y, _), T = n.mul(E, B),
|
|
918
|
-
|
|
915
|
+
let m = n.ZERO, x = n.ZERO, K = n.ZERO;
|
|
916
|
+
const M = t.a, I = n.mul(t.b, Ln);
|
|
917
|
+
let A = n.mul(d, S), R = n.mul(y, _), T = n.mul(E, B), D = n.add(d, y), b = n.add(S, _);
|
|
918
|
+
D = n.mul(D, b), b = n.add(A, R), D = n.sub(D, b), b = n.add(d, E);
|
|
919
919
|
let v = n.add(S, B);
|
|
920
|
-
return b = n.mul(b, v), v = n.add(A, T), b = n.sub(b, v), v = n.add(y, E), m = n.add(_, B), v = n.mul(v, m), m = n.add(R, T), v = n.sub(v, m),
|
|
920
|
+
return b = n.mul(b, v), v = n.add(A, T), b = n.sub(b, v), v = n.add(y, E), m = n.add(_, B), v = n.mul(v, m), m = n.add(R, T), v = n.sub(v, m), K = n.mul(M, b), m = n.mul(I, T), K = n.add(m, K), m = n.sub(R, K), K = n.add(R, K), x = n.mul(m, K), R = n.add(A, A), R = n.add(R, A), T = n.mul(M, T), b = n.mul(I, b), R = n.add(R, T), T = n.sub(A, T), T = n.mul(M, T), b = n.add(b, T), A = n.mul(R, b), x = n.add(x, A), A = n.mul(v, b), m = n.mul(D, m), m = n.sub(m, A), A = n.mul(D, R), K = n.mul(v, K), K = n.add(K, A), new u(m, x, K);
|
|
921
921
|
}
|
|
922
922
|
subtract(h) {
|
|
923
923
|
return this.add(h.negate());
|
|
@@ -945,9 +945,9 @@ function cs(e) {
|
|
|
945
945
|
const { endo: y } = t;
|
|
946
946
|
if (!y)
|
|
947
947
|
return w.unsafeLadder(this, h);
|
|
948
|
-
let { k1neg: E, k1: S, k2neg: _, k2: B } = y.splitScalar(h), m = d, x = d,
|
|
948
|
+
let { k1neg: E, k1: S, k2neg: _, k2: B } = y.splitScalar(h), m = d, x = d, K = this;
|
|
949
949
|
for (; S > ce || B > ce; )
|
|
950
|
-
S & X && (m = m.add(
|
|
950
|
+
S & X && (m = m.add(K)), B & X && (x = x.add(K)), K = K.double(), S >>= X, B >>= X;
|
|
951
951
|
return E && (m = m.negate()), _ && (x = x.negate()), x = new u(n.mul(x.px, y.beta), x.py, x.pz), m.add(x);
|
|
952
952
|
}
|
|
953
953
|
/**
|
|
@@ -965,8 +965,8 @@ function cs(e) {
|
|
|
965
965
|
const { endo: S } = t;
|
|
966
966
|
if (S) {
|
|
967
967
|
const { k1neg: _, k1: B, k2neg: m, k2: x } = S.splitScalar(d);
|
|
968
|
-
let { p:
|
|
969
|
-
|
|
968
|
+
let { p: K, f: M } = this.wNAF(B), { p: I, f: A } = this.wNAF(x);
|
|
969
|
+
K = w.constTimeNegate(_, K), I = w.constTimeNegate(m, I), I = new u(n.mul(I.px, S.beta), I.py, I.pz), y = K.add(I), E = M.add(A);
|
|
970
970
|
} else {
|
|
971
971
|
const { p: _, f: B } = this.wNAF(d);
|
|
972
972
|
y = _, E = B;
|
|
@@ -1012,7 +1012,7 @@ function cs(e) {
|
|
|
1012
1012
|
return this.assertValidity(), r(u, this, h);
|
|
1013
1013
|
}
|
|
1014
1014
|
toHex(h = !0) {
|
|
1015
|
-
return
|
|
1015
|
+
return qe(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);
|
|
@@ -1046,31 +1046,31 @@ function ls(e) {
|
|
|
1046
1046
|
return V(b, r);
|
|
1047
1047
|
}
|
|
1048
1048
|
function a(b) {
|
|
1049
|
-
return
|
|
1049
|
+
return Tt(b, r);
|
|
1050
1050
|
}
|
|
1051
1051
|
const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: p } = cs({
|
|
1052
1052
|
...t,
|
|
1053
|
-
toBytes(b, v,
|
|
1053
|
+
toBytes(b, v, N) {
|
|
1054
1054
|
const k = v.toAffine(), C = n.toBytes(k.x), U = Ie;
|
|
1055
|
-
return
|
|
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(b) {
|
|
1058
|
-
const v = b.length,
|
|
1059
|
-
if (v === i && (
|
|
1058
|
+
const v = b.length, N = b[0], k = b.subarray(1);
|
|
1059
|
+
if (v === i && (N === 2 || N === 3)) {
|
|
1060
1060
|
const C = G(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
1065
|
const $ = (O & X) === X;
|
|
1066
|
-
return (
|
|
1067
|
-
} else if (v === s &&
|
|
1066
|
+
return (N & 1) === 1 !== $ && (O = n.neg(O)), { x: C, y: O };
|
|
1067
|
+
} else if (v === s && N === 4) {
|
|
1068
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
|
-
}), w = (b) =>
|
|
1073
|
+
}), w = (b) => qe(Ne(b, t.nByteLength));
|
|
1074
1074
|
function g(b) {
|
|
1075
1075
|
const v = r >> X;
|
|
1076
1076
|
return b > v;
|
|
@@ -1078,21 +1078,21 @@ function ls(e) {
|
|
|
1078
1078
|
function h(b) {
|
|
1079
1079
|
return g(b) ? c(-b) : b;
|
|
1080
1080
|
}
|
|
1081
|
-
const d = (b, v,
|
|
1081
|
+
const d = (b, v, N) => G(b.slice(v, N));
|
|
1082
1082
|
class y {
|
|
1083
|
-
constructor(v,
|
|
1084
|
-
this.r = v, this.s =
|
|
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) {
|
|
1088
|
-
const
|
|
1089
|
-
return v = Z("compactSignature", v,
|
|
1088
|
+
const N = t.nByteLength;
|
|
1089
|
+
return v = Z("compactSignature", v, N * 2), new y(d(v, 0, N), d(v, N, 2 * N));
|
|
1090
1090
|
}
|
|
1091
1091
|
// DER encoded ECDSA signature
|
|
1092
1092
|
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
1093
1093
|
static fromDER(v) {
|
|
1094
|
-
const { r:
|
|
1095
|
-
return new y(
|
|
1094
|
+
const { r: N, s: k } = Be.toSig(Z("DER", v));
|
|
1095
|
+
return new y(N, k);
|
|
1096
1096
|
}
|
|
1097
1097
|
assertValidity() {
|
|
1098
1098
|
if (!p(this.r))
|
|
@@ -1104,10 +1104,10 @@ function ls(e) {
|
|
|
1104
1104
|
return new y(this.r, this.s, v);
|
|
1105
1105
|
}
|
|
1106
1106
|
recoverPublicKey(v) {
|
|
1107
|
-
const { r:
|
|
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
|
-
const O = C === 2 || C === 3 ?
|
|
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
1113
|
const $ = (C & 1) === 0 ? "02" : "03", ee = l.fromHex($ + w(O)), ge = a(O), Ue = c(-U * ge), Ve = c(k * ge), we = l.BASE.multiplyAndAddUnsafe(ee, Ue, Ve);
|
|
@@ -1170,34 +1170,34 @@ function ls(e) {
|
|
|
1170
1170
|
return l.fromPrivateKey(b).toRawBytes(v);
|
|
1171
1171
|
}
|
|
1172
1172
|
function _(b) {
|
|
1173
|
-
const v = b instanceof Uint8Array,
|
|
1174
|
-
return v ? k === i || k === s :
|
|
1173
|
+
const v = b instanceof Uint8Array, N = typeof b == "string", k = (v || N) && b.length;
|
|
1174
|
+
return v ? k === i || k === s : N ? k === 2 * i || k === 2 * s : b instanceof l;
|
|
1175
1175
|
}
|
|
1176
|
-
function B(b, v,
|
|
1176
|
+
function B(b, v, N = !0) {
|
|
1177
1177
|
if (_(b))
|
|
1178
1178
|
throw new Error("first arg must be private key");
|
|
1179
1179
|
if (!_(v))
|
|
1180
1180
|
throw new Error("second arg must be public key");
|
|
1181
|
-
return l.fromHex(v).multiply(f(b)).toRawBytes(
|
|
1181
|
+
return l.fromHex(v).multiply(f(b)).toRawBytes(N);
|
|
1182
1182
|
}
|
|
1183
1183
|
const m = t.bits2int || function(b) {
|
|
1184
|
-
const v = G(b),
|
|
1185
|
-
return
|
|
1184
|
+
const v = G(b), N = b.length * 8 - t.nBitLength;
|
|
1185
|
+
return N > 0 ? v >> BigInt(N) : v;
|
|
1186
1186
|
}, x = t.bits2int_modN || function(b) {
|
|
1187
1187
|
return c(m(b));
|
|
1188
|
-
},
|
|
1188
|
+
}, K = Jt(t.nBitLength);
|
|
1189
1189
|
function M(b) {
|
|
1190
1190
|
if (typeof b != "bigint")
|
|
1191
1191
|
throw new Error("bigint expected");
|
|
1192
|
-
if (!(ce <= b && b <
|
|
1192
|
+
if (!(ce <= b && b < K))
|
|
1193
1193
|
throw new Error(`bigint expected < 2^${t.nBitLength}`);
|
|
1194
|
-
return
|
|
1194
|
+
return Ne(b, t.nByteLength);
|
|
1195
1195
|
}
|
|
1196
|
-
function I(b, v,
|
|
1197
|
-
if (["recovered", "canonical"].some((Ae) => Ae in
|
|
1196
|
+
function I(b, v, N = A) {
|
|
1197
|
+
if (["recovered", "canonical"].some((Ae) => Ae in N))
|
|
1198
1198
|
throw new Error("sign() legacy options not supported");
|
|
1199
1199
|
const { hash: k, randomBytes: C } = t;
|
|
1200
|
-
let { lowS: U, prehash: O, extraEntropy: $ } =
|
|
1200
|
+
let { lowS: U, prehash: O, extraEntropy: $ } = N;
|
|
1201
1201
|
U == null && (U = !0), b = Z("msgHash", b), O && (b = Z("prehashed msgHash", k(b)));
|
|
1202
1202
|
const ee = x(b), ge = f(v), Ue = [M(ge), M(ee)];
|
|
1203
1203
|
if ($ != null) {
|
|
@@ -1209,27 +1209,27 @@ function ls(e) {
|
|
|
1209
1209
|
const Le = m(Ae);
|
|
1210
1210
|
if (!p(Le))
|
|
1211
1211
|
return;
|
|
1212
|
-
const
|
|
1212
|
+
const An = a(Le), $e = l.BASE.multiply(Le).toAffine(), te = c($e.x);
|
|
1213
1213
|
if (te === ce)
|
|
1214
1214
|
return;
|
|
1215
|
-
const Re = c(
|
|
1215
|
+
const Re = c(An * c(we + te * ge));
|
|
1216
1216
|
if (Re === ce)
|
|
1217
1217
|
return;
|
|
1218
|
-
let
|
|
1219
|
-
return U && g(Re) && (
|
|
1218
|
+
let Cn = ($e.x === te ? 0 : 2) | Number($e.y & X), Bn = Re;
|
|
1219
|
+
return U && g(Re) && (Bn = h(Re), Cn ^= 1), new y(te, Bn, Cn);
|
|
1220
1220
|
}
|
|
1221
1221
|
return { seed: Ve, k2sig: Et };
|
|
1222
1222
|
}
|
|
1223
1223
|
const A = { lowS: t.lowS, prehash: !1 }, R = { lowS: t.lowS, prehash: !1 };
|
|
1224
|
-
function T(b, v,
|
|
1225
|
-
const { seed: k, k2sig: C } = I(b, v,
|
|
1224
|
+
function T(b, v, N = A) {
|
|
1225
|
+
const { seed: k, k2sig: C } = I(b, v, N), U = t;
|
|
1226
1226
|
return er(U.hash.outputLen, U.nByteLength, U.hmac)(k, C);
|
|
1227
1227
|
}
|
|
1228
1228
|
l.BASE._setWindowSize(8);
|
|
1229
|
-
function
|
|
1229
|
+
function D(b, v, N, k = R) {
|
|
1230
1230
|
var $e;
|
|
1231
1231
|
const C = b;
|
|
1232
|
-
if (v = Z("msgHash", v),
|
|
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
1234
|
const { lowS: U, prehash: O } = k;
|
|
1235
1235
|
let $, ee;
|
|
@@ -1247,7 +1247,7 @@ function ls(e) {
|
|
|
1247
1247
|
$ = new y(te, Re);
|
|
1248
1248
|
} else
|
|
1249
1249
|
throw new Error("PARSE");
|
|
1250
|
-
ee = l.fromHex(
|
|
1250
|
+
ee = l.fromHex(N);
|
|
1251
1251
|
} catch (te) {
|
|
1252
1252
|
if (te.message === "PARSE")
|
|
1253
1253
|
throw new Error("signature must be Signature instance, Uint8Array or hex string");
|
|
@@ -1264,7 +1264,7 @@ function ls(e) {
|
|
|
1264
1264
|
getPublicKey: S,
|
|
1265
1265
|
getSharedSecret: B,
|
|
1266
1266
|
sign: T,
|
|
1267
|
-
verify:
|
|
1267
|
+
verify: D,
|
|
1268
1268
|
ProjectivePoint: l,
|
|
1269
1269
|
Signature: y,
|
|
1270
1270
|
utils: E
|
|
@@ -1273,7 +1273,7 @@ function ls(e) {
|
|
|
1273
1273
|
let sr = class extends Jn {
|
|
1274
1274
|
constructor(t, n) {
|
|
1275
1275
|
super(), this.finished = !1, this.destroyed = !1, Si(t);
|
|
1276
|
-
const r =
|
|
1276
|
+
const r = Vt(n);
|
|
1277
1277
|
if (this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
1278
1278
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
1279
1279
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
@@ -1320,17 +1320,17 @@ function hs(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 ut = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), tt = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), ar = BigInt(1), nt = BigInt(2),
|
|
1323
|
+
const ut = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), tt = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), ar = BigInt(1), nt = BigInt(2), $n = (e, t) => (e + t / nt) / t;
|
|
1324
1324
|
function cr(e) {
|
|
1325
1325
|
const t = ut, n = BigInt(3), r = BigInt(6), i = BigInt(11), s = BigInt(22), o = BigInt(23), c = BigInt(44), a = BigInt(88), l = e * e * e % t, f = l * l * e % t, u = Y(f, n, t) * f % t, p = Y(u, n, t) * f % t, w = Y(p, nt, t) * l % t, g = Y(w, i, t) * w % t, h = Y(g, s, t) * g % t, d = Y(h, c, t) * h % t, y = Y(d, a, t) * d % t, E = Y(y, c, t) * h % t, S = Y(E, n, t) * f % t, _ = Y(S, o, t) * g % t, B = Y(_, r, t) * l % t, m = Y(B, nt, t);
|
|
1326
|
-
if (!
|
|
1326
|
+
if (!Ot.eql(Ot.sqr(m), e))
|
|
1327
1327
|
throw new Error("Cannot find square root");
|
|
1328
1328
|
return m;
|
|
1329
1329
|
}
|
|
1330
|
-
const
|
|
1330
|
+
const Ot = ts(ut, void 0, void 0, { sqrt: cr }), _e = hs({
|
|
1331
1331
|
a: BigInt(0),
|
|
1332
1332
|
b: BigInt(7),
|
|
1333
|
-
Fp:
|
|
1333
|
+
Fp: Ot,
|
|
1334
1334
|
n: tt,
|
|
1335
1335
|
// Base point (x, y) aka generator point
|
|
1336
1336
|
Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
|
|
@@ -1346,7 +1346,7 @@ const Tt = ts(ut, void 0, void 0, { sqrt: cr }), _e = hs({
|
|
|
1346
1346
|
endo: {
|
|
1347
1347
|
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
1348
1348
|
splitScalar: (e) => {
|
|
1349
|
-
const t = tt, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -ar * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), s = n, o = BigInt("0x100000000000000000000000000000000"), c =
|
|
1349
|
+
const t = tt, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -ar * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), s = n, o = BigInt("0x100000000000000000000000000000000"), c = $n(s * e, t), a = $n(-r * e, t);
|
|
1350
1350
|
let l = V(e - c * n - a * i, t), f = V(-c * r - a * s, t);
|
|
1351
1351
|
const u = l > o, p = f > o;
|
|
1352
1352
|
if (u && (l = t - l), p && (f = t - f), l > o || f > o)
|
|
@@ -1354,19 +1354,19 @@ const Tt = ts(ut, void 0, void 0, { sqrt: cr }), _e = hs({
|
|
|
1354
1354
|
return { k1neg: u, k1: l, k2neg: p, k2: f };
|
|
1355
1355
|
}
|
|
1356
1356
|
}
|
|
1357
|
-
},
|
|
1357
|
+
}, $t), lt = BigInt(0), ur = (e) => typeof e == "bigint" && lt < e && e < ut, ds = (e) => typeof e == "bigint" && lt < e && e < tt, Rn = {};
|
|
1358
1358
|
function rt(e, ...t) {
|
|
1359
|
-
let n =
|
|
1359
|
+
let n = Rn[e];
|
|
1360
1360
|
if (n === void 0) {
|
|
1361
|
-
const r =
|
|
1362
|
-
n = Ie(r, r),
|
|
1361
|
+
const r = $t(Uint8Array.from(e, (i) => i.charCodeAt(0)));
|
|
1362
|
+
n = Ie(r, r), Rn[e] = n;
|
|
1363
1363
|
}
|
|
1364
|
-
return
|
|
1364
|
+
return $t(Ie(n, ...t));
|
|
1365
1365
|
}
|
|
1366
|
-
const
|
|
1367
|
-
function
|
|
1368
|
-
let t = _e.utils.normPrivateKeyToScalar(e), n =
|
|
1369
|
-
return { scalar: n.hasEvenY() ? t : Ge(-t), bytes:
|
|
1366
|
+
const Yt = (e) => e.toRawBytes(!0).slice(1), Mt = (e) => Ne(e, 32), At = (e) => V(e, ut), Ge = (e) => V(e, tt), Xt = _e.ProjectivePoint, ps = (e, t, n) => Xt.BASE.multiplyAndAddUnsafe(e, t, n);
|
|
1367
|
+
function Pt(e) {
|
|
1368
|
+
let t = _e.utils.normPrivateKeyToScalar(e), n = Xt.fromPrivateKey(t);
|
|
1369
|
+
return { scalar: n.hasEvenY() ? t : Ge(-t), bytes: Yt(n) };
|
|
1370
1370
|
}
|
|
1371
1371
|
function lr(e) {
|
|
1372
1372
|
if (!ur(e))
|
|
@@ -1374,21 +1374,21 @@ function lr(e) {
|
|
|
1374
1374
|
const t = At(e * e), n = At(t * e + BigInt(7));
|
|
1375
1375
|
let r = cr(n);
|
|
1376
1376
|
r % nt !== lt && (r = At(-r));
|
|
1377
|
-
const i = new
|
|
1377
|
+
const i = new Xt(e, r, ar);
|
|
1378
1378
|
return i.assertValidity(), i;
|
|
1379
1379
|
}
|
|
1380
1380
|
function fr(...e) {
|
|
1381
1381
|
return Ge(G(rt("BIP0340/challenge", ...e)));
|
|
1382
1382
|
}
|
|
1383
1383
|
function ys(e) {
|
|
1384
|
-
return
|
|
1384
|
+
return Pt(e).bytes;
|
|
1385
1385
|
}
|
|
1386
1386
|
function gs(e, t, n = Yn(32)) {
|
|
1387
|
-
const r = Z("message", e), { bytes: i, scalar: s } =
|
|
1387
|
+
const r = Z("message", e), { bytes: i, scalar: s } = Pt(t), o = Z("auxRand", n, 32), c = Mt(s ^ G(rt("BIP0340/aux", o))), a = rt("BIP0340/nonce", c, i, r), l = Ge(G(a));
|
|
1388
1388
|
if (l === lt)
|
|
1389
1389
|
throw new Error("sign failed: k is zero");
|
|
1390
|
-
const { bytes: f, scalar: u } =
|
|
1391
|
-
if (w.set(f, 0), w.set(
|
|
1390
|
+
const { bytes: f, scalar: u } = Pt(l), p = fr(f, i, r), w = new Uint8Array(64);
|
|
1391
|
+
if (w.set(f, 0), w.set(Mt(Ge(u + p * s)), 32), !hr(w, r, i))
|
|
1392
1392
|
throw new Error("sign: Invalid signature produced");
|
|
1393
1393
|
return w;
|
|
1394
1394
|
}
|
|
@@ -1401,7 +1401,7 @@ function hr(e, t, n) {
|
|
|
1401
1401
|
const a = G(r.subarray(32, 64));
|
|
1402
1402
|
if (!ds(a))
|
|
1403
1403
|
return !1;
|
|
1404
|
-
const l = fr(
|
|
1404
|
+
const l = fr(Mt(c), Yt(o), i), f = ps(o, a, Ge(-l));
|
|
1405
1405
|
return !(!f || !f.hasEvenY() || f.toAffine().x !== c);
|
|
1406
1406
|
} catch {
|
|
1407
1407
|
return !1;
|
|
@@ -1414,20 +1414,20 @@ const Ze = {
|
|
|
1414
1414
|
utils: {
|
|
1415
1415
|
randomPrivateKey: _e.utils.randomPrivateKey,
|
|
1416
1416
|
lift_x: lr,
|
|
1417
|
-
pointToBytes:
|
|
1418
|
-
numberToBytesBE:
|
|
1417
|
+
pointToBytes: Yt,
|
|
1418
|
+
numberToBytesBE: Ne,
|
|
1419
1419
|
bytesToNumberBE: G,
|
|
1420
1420
|
taggedHash: rt,
|
|
1421
1421
|
mod: V
|
|
1422
1422
|
}
|
|
1423
1423
|
}, Ct = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
1424
1424
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1425
|
-
const
|
|
1425
|
+
const Qt = (e) => e instanceof Uint8Array, Bt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), ie = (e, t) => e << 32 - t | e >>> t, ws = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1426
1426
|
if (!ws)
|
|
1427
1427
|
throw new Error("Non little-endian hardware is not supported");
|
|
1428
1428
|
const bs = Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
1429
1429
|
function P(e) {
|
|
1430
|
-
if (!
|
|
1430
|
+
if (!Qt(e))
|
|
1431
1431
|
throw new Error("Uint8Array expected");
|
|
1432
1432
|
let t = "";
|
|
1433
1433
|
for (let n = 0; n < e.length; n++)
|
|
@@ -1455,7 +1455,7 @@ function vs(e) {
|
|
|
1455
1455
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
1456
1456
|
}
|
|
1457
1457
|
function Je(e) {
|
|
1458
|
-
if (typeof e == "string" && (e = vs(e)), !
|
|
1458
|
+
if (typeof e == "string" && (e = vs(e)), !Qt(e))
|
|
1459
1459
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
1460
1460
|
return e;
|
|
1461
1461
|
}
|
|
@@ -1463,7 +1463,7 @@ function ft(...e) {
|
|
|
1463
1463
|
const t = new Uint8Array(e.reduce((r, i) => r + i.length, 0));
|
|
1464
1464
|
let n = 0;
|
|
1465
1465
|
return e.forEach((r) => {
|
|
1466
|
-
if (!
|
|
1466
|
+
if (!Qt(r))
|
|
1467
1467
|
throw new Error("Uint8Array expected");
|
|
1468
1468
|
t.set(r, n), n += r.length;
|
|
1469
1469
|
}), t;
|
|
@@ -1483,7 +1483,7 @@ function yr(e = 32) {
|
|
|
1483
1483
|
return Ct.getRandomValues(new Uint8Array(e));
|
|
1484
1484
|
throw new Error("crypto.getRandomValues must be defined");
|
|
1485
1485
|
}
|
|
1486
|
-
function
|
|
1486
|
+
function Ht(e) {
|
|
1487
1487
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
1488
1488
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
1489
1489
|
}
|
|
@@ -1500,7 +1500,7 @@ function gr(e, ...t) {
|
|
|
1500
1500
|
function Es(e) {
|
|
1501
1501
|
if (typeof e != "function" || typeof e.create != "function")
|
|
1502
1502
|
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
1503
|
-
|
|
1503
|
+
Ht(e.outputLen), Ht(e.blockLen);
|
|
1504
1504
|
}
|
|
1505
1505
|
function xs(e, t = !0) {
|
|
1506
1506
|
if (e.destroyed)
|
|
@@ -1508,21 +1508,21 @@ function xs(e, t = !0) {
|
|
|
1508
1508
|
if (t && e.finished)
|
|
1509
1509
|
throw new Error("Hash#digest() has already been called");
|
|
1510
1510
|
}
|
|
1511
|
-
function
|
|
1511
|
+
function Ks(e, t) {
|
|
1512
1512
|
gr(e);
|
|
1513
1513
|
const n = t.outputLen;
|
|
1514
1514
|
if (e.length < n)
|
|
1515
1515
|
throw new Error(`digestInto() expects output buffer of length at least ${n}`);
|
|
1516
1516
|
}
|
|
1517
1517
|
const se = {
|
|
1518
|
-
number:
|
|
1518
|
+
number: Ht,
|
|
1519
1519
|
bool: ms,
|
|
1520
1520
|
bytes: gr,
|
|
1521
1521
|
hash: Es,
|
|
1522
1522
|
exists: xs,
|
|
1523
|
-
output:
|
|
1523
|
+
output: Ks
|
|
1524
1524
|
};
|
|
1525
|
-
function
|
|
1525
|
+
function Ns(e, t, n, r) {
|
|
1526
1526
|
if (typeof e.setBigUint64 == "function")
|
|
1527
1527
|
return e.setBigUint64(t, n, r);
|
|
1528
1528
|
const i = BigInt(32), s = BigInt(4294967295), o = Number(n >> i & s), c = Number(n & s), a = r ? 4 : 0, l = r ? 0 : 4;
|
|
@@ -1556,7 +1556,7 @@ class Ss extends dr {
|
|
|
1556
1556
|
n[o++] = 128, this.buffer.subarray(o).fill(0), this.padOffset > i - o && (this.process(r, 0), o = 0);
|
|
1557
1557
|
for (let u = o; u < i; u++)
|
|
1558
1558
|
n[u] = 0;
|
|
1559
|
-
|
|
1559
|
+
Ns(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
1560
1560
|
const c = Bt(t), a = this.outputLen;
|
|
1561
1561
|
if (a % 4)
|
|
1562
1562
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
@@ -1781,7 +1781,7 @@ function br(e) {
|
|
|
1781
1781
|
throw new Error("normalize fn should be function");
|
|
1782
1782
|
return { encode: (t) => t, decode: (t) => e(t) };
|
|
1783
1783
|
}
|
|
1784
|
-
function
|
|
1784
|
+
function Tn(e, t, n) {
|
|
1785
1785
|
if (t < 2)
|
|
1786
1786
|
throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);
|
|
1787
1787
|
if (n < 2)
|
|
@@ -1815,7 +1815,7 @@ function Rn(e, t, n) {
|
|
|
1815
1815
|
return i.reverse();
|
|
1816
1816
|
}
|
|
1817
1817
|
const vr = (e, t) => t ? vr(t, e % t) : e, it = (e, t) => e + (t - vr(e, t));
|
|
1818
|
-
function
|
|
1818
|
+
function Dt(e, t, n, r) {
|
|
1819
1819
|
if (!Array.isArray(e))
|
|
1820
1820
|
throw new Error("convertRadix2: data should be array");
|
|
1821
1821
|
if (t <= 0 || t > 32)
|
|
@@ -1846,12 +1846,12 @@ function Is(e) {
|
|
|
1846
1846
|
encode: (t) => {
|
|
1847
1847
|
if (!(t instanceof Uint8Array))
|
|
1848
1848
|
throw new Error("radix.encode input should be Uint8Array");
|
|
1849
|
-
return
|
|
1849
|
+
return Tn(Array.from(t), 2 ** 8, e);
|
|
1850
1850
|
},
|
|
1851
1851
|
decode: (t) => {
|
|
1852
1852
|
if (!Array.isArray(t) || t.length && typeof t[0] != "number")
|
|
1853
1853
|
throw new Error("radix.decode input should be array of strings");
|
|
1854
|
-
return Uint8Array.from(
|
|
1854
|
+
return Uint8Array.from(Tn(t, e, 2 ** 8));
|
|
1855
1855
|
}
|
|
1856
1856
|
};
|
|
1857
1857
|
}
|
|
@@ -1864,16 +1864,16 @@ function Se(e, t = !1) {
|
|
|
1864
1864
|
encode: (n) => {
|
|
1865
1865
|
if (!(n instanceof Uint8Array))
|
|
1866
1866
|
throw new Error("radix2.encode input should be Uint8Array");
|
|
1867
|
-
return
|
|
1867
|
+
return Dt(Array.from(n), 8, e, !t);
|
|
1868
1868
|
},
|
|
1869
1869
|
decode: (n) => {
|
|
1870
1870
|
if (!Array.isArray(n) || n.length && typeof n[0] != "number")
|
|
1871
1871
|
throw new Error("radix2.decode input should be array of strings");
|
|
1872
|
-
return Uint8Array.from(
|
|
1872
|
+
return Uint8Array.from(Dt(n, e, 8, t));
|
|
1873
1873
|
}
|
|
1874
1874
|
};
|
|
1875
1875
|
}
|
|
1876
|
-
function
|
|
1876
|
+
function On(e) {
|
|
1877
1877
|
if (typeof e != "function")
|
|
1878
1878
|
throw new Error("unsafeWrapper fn should be function");
|
|
1879
1879
|
return function(...t) {
|
|
@@ -1886,22 +1886,22 @@ function Tn(e) {
|
|
|
1886
1886
|
const _s = de(Se(4), pe("0123456789ABCDEF"), ye("")), Us = de(Se(5), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), ht(5), ye(""));
|
|
1887
1887
|
de(Se(5), pe("0123456789ABCDEFGHIJKLMNOPQRSTUV"), ht(5), ye(""));
|
|
1888
1888
|
de(Se(5), pe("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), ye(""), br((e) => e.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
1889
|
-
const he = de(Se(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), ht(6), ye("")), Ls = de(Se(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), ht(6), ye("")),
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
const
|
|
1889
|
+
const he = de(Se(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), ht(6), ye("")), Ls = de(Se(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), ht(6), ye("")), en = (e) => de(Is(58), pe(e), ye("")), qt = en("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
1890
|
+
en("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
|
|
1891
|
+
en("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");
|
|
1892
|
+
const Mn = [0, 2, 3, 5, 6, 7, 9, 10, 11], $s = {
|
|
1893
1893
|
encode(e) {
|
|
1894
1894
|
let t = "";
|
|
1895
1895
|
for (let n = 0; n < e.length; n += 8) {
|
|
1896
1896
|
const r = e.subarray(n, n + 8);
|
|
1897
|
-
t += qt.encode(r).padStart(
|
|
1897
|
+
t += qt.encode(r).padStart(Mn[r.length], "1");
|
|
1898
1898
|
}
|
|
1899
1899
|
return t;
|
|
1900
1900
|
},
|
|
1901
1901
|
decode(e) {
|
|
1902
1902
|
let t = [];
|
|
1903
1903
|
for (let n = 0; n < e.length; n += 11) {
|
|
1904
|
-
const r = e.slice(n, n + 11), i =
|
|
1904
|
+
const r = e.slice(n, n + 11), i = Mn.indexOf(r.length), s = qt.decode(r);
|
|
1905
1905
|
for (let o = 0; o < s.length - i; o++)
|
|
1906
1906
|
if (s[o] !== 0)
|
|
1907
1907
|
throw new Error("base58xmr: wrong padding");
|
|
@@ -1909,15 +1909,15 @@ const On = [0, 2, 3, 5, 6, 7, 9, 10, 11], $s = {
|
|
|
1909
1909
|
}
|
|
1910
1910
|
return Uint8Array.from(t);
|
|
1911
1911
|
}
|
|
1912
|
-
},
|
|
1912
|
+
}, jt = de(pe("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), ye("")), Pn = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
1913
1913
|
function Fe(e) {
|
|
1914
1914
|
const t = e >> 25;
|
|
1915
1915
|
let n = (e & 33554431) << 5;
|
|
1916
|
-
for (let r = 0; r <
|
|
1917
|
-
(t >> r & 1) === 1 && (n ^=
|
|
1916
|
+
for (let r = 0; r < Pn.length; r++)
|
|
1917
|
+
(t >> r & 1) === 1 && (n ^= Pn[r]);
|
|
1918
1918
|
return n;
|
|
1919
1919
|
}
|
|
1920
|
-
function
|
|
1920
|
+
function Hn(e, t, n = 1) {
|
|
1921
1921
|
const r = e.length;
|
|
1922
1922
|
let i = 1;
|
|
1923
1923
|
for (let s = 0; s < r; s++) {
|
|
@@ -1933,10 +1933,10 @@ function Pn(e, t, n = 1) {
|
|
|
1933
1933
|
i = Fe(i) ^ s;
|
|
1934
1934
|
for (let s = 0; s < 6; s++)
|
|
1935
1935
|
i = Fe(i);
|
|
1936
|
-
return i ^= n,
|
|
1936
|
+
return i ^= n, jt.encode(Dt([i % 2 ** 30], 30, 5, !1));
|
|
1937
1937
|
}
|
|
1938
1938
|
function mr(e) {
|
|
1939
|
-
const t = e === "bech32" ? 1 : 734539939, n = Se(5), r = n.decode, i = n.encode, s =
|
|
1939
|
+
const t = e === "bech32" ? 1 : 734539939, n = Se(5), r = n.decode, i = n.encode, s = On(r);
|
|
1940
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}`);
|
|
@@ -1945,7 +1945,7 @@ function mr(e) {
|
|
|
1945
1945
|
const w = f.length + 7 + u.length;
|
|
1946
1946
|
if (p !== !1 && w > p)
|
|
1947
1947
|
throw new TypeError(`Length ${w} exceeds limit ${p}`);
|
|
1948
|
-
return f = f.toLowerCase(), `${f}1${
|
|
1948
|
+
return f = f.toLowerCase(), `${f}1${jt.encode(u)}${Hn(f, u, t)}`;
|
|
1949
1949
|
}
|
|
1950
1950
|
function c(f, u = 90) {
|
|
1951
1951
|
if (typeof f != "string")
|
|
@@ -1962,12 +1962,12 @@ function mr(e) {
|
|
|
1962
1962
|
const g = f.slice(0, w), h = f.slice(w + 1);
|
|
1963
1963
|
if (h.length < 6)
|
|
1964
1964
|
throw new Error("Data must be at least 6 characters long");
|
|
1965
|
-
const d =
|
|
1965
|
+
const d = jt.decode(h).slice(0, -6), y = Hn(g, d, t);
|
|
1966
1966
|
if (!h.endsWith(y))
|
|
1967
1967
|
throw new Error(`Invalid checksum in ${f}: expected "${y}"`);
|
|
1968
1968
|
return { prefix: g, words: d };
|
|
1969
1969
|
}
|
|
1970
|
-
const a =
|
|
1970
|
+
const a = On(c);
|
|
1971
1971
|
function l(f) {
|
|
1972
1972
|
const { prefix: u, words: p } = c(f, !1);
|
|
1973
1973
|
return { prefix: u, words: p, bytes: r(p) };
|
|
@@ -1998,7 +1998,7 @@ function kt(e) {
|
|
|
1998
1998
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
1999
1999
|
throw new Error(`positive integer expected, not ${e}`);
|
|
2000
2000
|
}
|
|
2001
|
-
function
|
|
2001
|
+
function Dn(e) {
|
|
2002
2002
|
if (typeof e != "boolean")
|
|
2003
2003
|
throw new Error(`boolean expected, not ${e}`);
|
|
2004
2004
|
}
|
|
@@ -2020,7 +2020,7 @@ function Hs(e, t) {
|
|
|
2020
2020
|
throw new Error("options must be defined");
|
|
2021
2021
|
return Object.assign(e, t);
|
|
2022
2022
|
}
|
|
2023
|
-
function
|
|
2023
|
+
function Ds(e, t) {
|
|
2024
2024
|
if (e.length !== t.length)
|
|
2025
2025
|
return !1;
|
|
2026
2026
|
let n = 0;
|
|
@@ -2028,19 +2028,19 @@ function qs(e, t) {
|
|
|
2028
2028
|
n |= e[r] ^ t[r];
|
|
2029
2029
|
return n === 0;
|
|
2030
2030
|
}
|
|
2031
|
-
const
|
|
2032
|
-
function
|
|
2031
|
+
const qs = /* @__NO_SIDE_EFFECTS__ */ (e, t) => (Object.assign(t, e), t), Ke = 16, js = 283;
|
|
2032
|
+
function tn(e) {
|
|
2033
2033
|
return e << 1 ^ js & -(e >> 7);
|
|
2034
2034
|
}
|
|
2035
2035
|
function He(e, t) {
|
|
2036
2036
|
let n = 0;
|
|
2037
2037
|
for (; t > 0; t >>= 1)
|
|
2038
|
-
n ^= e & -(t & 1), e =
|
|
2038
|
+
n ^= e & -(t & 1), e = tn(e);
|
|
2039
2039
|
return n;
|
|
2040
2040
|
}
|
|
2041
|
-
const
|
|
2041
|
+
const zt = /* @__PURE__ */ (() => {
|
|
2042
2042
|
let e = new Uint8Array(256);
|
|
2043
|
-
for (let n = 0, r = 1; n < 256; n++, r ^=
|
|
2043
|
+
for (let n = 0, r = 1; n < 256; n++, r ^= tn(r))
|
|
2044
2044
|
e[n] = r;
|
|
2045
2045
|
const t = new Uint8Array(256);
|
|
2046
2046
|
t[0] = 99;
|
|
@@ -2049,7 +2049,7 @@ 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
|
-
})(), zs = /* @__PURE__ */
|
|
2052
|
+
})(), zs = /* @__PURE__ */ zt.map((e, t) => zt.indexOf(t)), Ws = (e) => e << 24 | e >>> 8, It = (e) => e << 8 | e >>> 24;
|
|
2053
2053
|
function Er(e, t) {
|
|
2054
2054
|
if (e.length !== 256)
|
|
2055
2055
|
throw new Error("Wrong sbox length");
|
|
@@ -2061,18 +2061,18 @@ function Er(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
|
|
2064
|
+
const nn = /* @__PURE__ */ Er(zt, (e) => He(e, 3) << 24 | e << 16 | e << 8 | He(e, 2)), xr = /* @__PURE__ */ Er(zs, (e) => He(e, 11) << 24 | He(e, 13) << 16 | He(e, 9) << 8 | He(e, 14)), Vs = /* @__PURE__ */ (() => {
|
|
2065
2065
|
const e = new Uint8Array(16);
|
|
2066
|
-
for (let t = 0, n = 1; t < 16; t++, n =
|
|
2066
|
+
for (let t = 0, n = 1; t < 16; t++, n = tn(n))
|
|
2067
2067
|
e[t] = n;
|
|
2068
2068
|
return e;
|
|
2069
2069
|
})();
|
|
2070
|
-
function
|
|
2070
|
+
function Kr(e) {
|
|
2071
2071
|
ue(e);
|
|
2072
2072
|
const t = e.length;
|
|
2073
2073
|
if (![16, 24, 32].includes(t))
|
|
2074
2074
|
throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);
|
|
2075
|
-
const { sbox2: n } =
|
|
2075
|
+
const { sbox2: n } = nn, r = F(e), i = r.length, s = (c) => oe(n, c, c, c, c), o = new Uint32Array(t + 28);
|
|
2076
2076
|
o.set(r);
|
|
2077
2077
|
for (let c = i; c < o.length; c++) {
|
|
2078
2078
|
let a = o[c - 1];
|
|
@@ -2081,7 +2081,7 @@ function Nr(e) {
|
|
|
2081
2081
|
return o;
|
|
2082
2082
|
}
|
|
2083
2083
|
function Zs(e) {
|
|
2084
|
-
const t =
|
|
2084
|
+
const t = Kr(e), n = t.slice(), r = t.length, { sbox2: i } = nn, { T0: s, T1: o, T2: c, T3: a } = xr;
|
|
2085
2085
|
for (let l = 0; l < r; l += 4)
|
|
2086
2086
|
for (let f = 0; f < 4; f++)
|
|
2087
2087
|
n[l + f] = t[r - l - 4 + f];
|
|
@@ -2099,7 +2099,7 @@ function oe(e, t, n, r, i) {
|
|
|
2099
2099
|
return e[t & 255 | n & 65280] | e[r >>> 16 & 255 | i >>> 16 & 65280] << 16;
|
|
2100
2100
|
}
|
|
2101
2101
|
function qn(e, t, n, r, i) {
|
|
2102
|
-
const { sbox2: s, T01: o, T23: c } =
|
|
2102
|
+
const { sbox2: s, T01: o, T23: c } = nn;
|
|
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;
|
|
@@ -2122,7 +2122,7 @@ function Fs(e, t, n, r, i) {
|
|
|
2122
2122
|
const f = e[a++] ^ oe(s, t, i, r, n), u = e[a++] ^ oe(s, n, t, i, r), p = e[a++] ^ oe(s, r, n, t, i), w = e[a++] ^ oe(s, i, r, n, t);
|
|
2123
2123
|
return { s0: f, s1: u, s2: p, s3: w };
|
|
2124
2124
|
}
|
|
2125
|
-
function
|
|
2125
|
+
function Nr(e, t) {
|
|
2126
2126
|
if (!t)
|
|
2127
2127
|
return new Uint8Array(e);
|
|
2128
2128
|
if (ue(t), t.length < e)
|
|
@@ -2130,20 +2130,20 @@ function Kr(e, t) {
|
|
|
2130
2130
|
return t;
|
|
2131
2131
|
}
|
|
2132
2132
|
function Gs(e) {
|
|
2133
|
-
if (ue(e), e.length %
|
|
2134
|
-
throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${
|
|
2133
|
+
if (ue(e), e.length % Ke !== 0)
|
|
2134
|
+
throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Ke}`);
|
|
2135
2135
|
}
|
|
2136
2136
|
function Js(e, t, n) {
|
|
2137
2137
|
let r = e.length;
|
|
2138
|
-
const i = r %
|
|
2138
|
+
const i = r % Ke;
|
|
2139
2139
|
if (!t && i !== 0)
|
|
2140
2140
|
throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");
|
|
2141
2141
|
const s = F(e);
|
|
2142
2142
|
if (t) {
|
|
2143
|
-
let a =
|
|
2144
|
-
a || (a =
|
|
2143
|
+
let a = Ke - i;
|
|
2144
|
+
a || (a = Ke), r = r + a;
|
|
2145
2145
|
}
|
|
2146
|
-
const o =
|
|
2146
|
+
const o = Nr(r, n), c = F(o);
|
|
2147
2147
|
return { b: s, o: c, out: o };
|
|
2148
2148
|
}
|
|
2149
2149
|
function Ys(e, t) {
|
|
@@ -2164,17 +2164,17 @@ function Ys(e, t) {
|
|
|
2164
2164
|
function Xs(e) {
|
|
2165
2165
|
const t = new Uint8Array(16), n = F(t);
|
|
2166
2166
|
t.set(e);
|
|
2167
|
-
const r =
|
|
2168
|
-
for (let i =
|
|
2167
|
+
const r = Ke - e.length;
|
|
2168
|
+
for (let i = Ke - r; i < Ke; i++)
|
|
2169
2169
|
t[i] = r;
|
|
2170
2170
|
return n;
|
|
2171
2171
|
}
|
|
2172
|
-
const Sr = /* @__PURE__ */
|
|
2172
|
+
const Sr = /* @__PURE__ */ qs({ blockSize: 16, nonceLength: 16 }, function(t, n, r = {}) {
|
|
2173
2173
|
ue(t), ue(n, 16);
|
|
2174
2174
|
const i = !r.disablePadding;
|
|
2175
2175
|
return {
|
|
2176
2176
|
encrypt: (s, o) => {
|
|
2177
|
-
const c =
|
|
2177
|
+
const c = Kr(t), { b: a, o: l, out: f } = Js(s, i, o), u = F(n);
|
|
2178
2178
|
let p = u[0], w = u[1], g = u[2], h = u[3], d = 0;
|
|
2179
2179
|
for (; d + 4 <= a.length; )
|
|
2180
2180
|
p ^= a[d + 0], w ^= a[d + 1], g ^= a[d + 2], h ^= a[d + 3], { s0: p, s1: w, s2: g, s3: h } = qn(c, p, w, g, h), l[d++] = p, l[d++] = w, l[d++] = g, l[d++] = h;
|
|
@@ -2186,13 +2186,13 @@ const Sr = /* @__PURE__ */ Ds({ blockSize: 16, nonceLength: 16 }, function(t, n,
|
|
|
2186
2186
|
},
|
|
2187
2187
|
decrypt: (s, o) => {
|
|
2188
2188
|
Gs(s);
|
|
2189
|
-
const c = Zs(t), a = F(n), l =
|
|
2189
|
+
const c = Zs(t), a = F(n), l = Nr(s.length, o), f = F(s), u = F(l);
|
|
2190
2190
|
let p = a[0], w = a[1], g = a[2], h = a[3];
|
|
2191
2191
|
for (let d = 0; d + 4 <= f.length; ) {
|
|
2192
2192
|
const y = p, E = w, S = g, _ = h;
|
|
2193
2193
|
p = f[d + 0], w = f[d + 1], g = f[d + 2], h = f[d + 3];
|
|
2194
|
-
const { s0: B, s1: m, s2: x, s3:
|
|
2195
|
-
u[d++] = B ^ y, u[d++] = m ^ E, u[d++] = x ^ S, u[d++] =
|
|
2194
|
+
const { s0: B, s1: m, s2: x, s3: K } = Fs(c, p, w, g, h);
|
|
2195
|
+
u[d++] = B ^ y, u[d++] = m ^ E, u[d++] = x ^ S, u[d++] = K ^ _;
|
|
2196
2196
|
}
|
|
2197
2197
|
return c.fill(0), Ys(l, i);
|
|
2198
2198
|
}
|
|
@@ -2202,12 +2202,12 @@ Cr.slice();
|
|
|
2202
2202
|
function L(e, t) {
|
|
2203
2203
|
return e << t | e >>> 32 - t;
|
|
2204
2204
|
}
|
|
2205
|
-
function
|
|
2205
|
+
function Wt(e) {
|
|
2206
2206
|
return e.byteOffset % 4 === 0;
|
|
2207
2207
|
}
|
|
2208
|
-
const Xe = 64, no = 16, Br = 2 ** 32 - 1,
|
|
2208
|
+
const Xe = 64, no = 16, Br = 2 ** 32 - 1, jn = new Uint32Array();
|
|
2209
2209
|
function ro(e, t, n, r, i, s, o, c) {
|
|
2210
|
-
const a = i.length, l = new Uint8Array(Xe), f = F(l), u =
|
|
2210
|
+
const a = i.length, l = new Uint8Array(Xe), f = F(l), u = Wt(i) && Wt(s), p = u ? F(i) : jn, w = u ? F(s) : jn;
|
|
2211
2211
|
for (let g = 0; g < a; o++) {
|
|
2212
2212
|
if (e(t, n, r, f, o, c), o >= Br)
|
|
2213
2213
|
throw new Error("arx: counter overflow");
|
|
@@ -2230,7 +2230,7 @@ function io(e, t) {
|
|
|
2230
2230
|
const { allowShortKeys: n, extendNonceFn: r, counterLength: i, counterRight: s, rounds: o } = Hs({ allowShortKeys: !1, counterLength: 8, counterRight: !1, rounds: 20 }, t);
|
|
2231
2231
|
if (typeof e != "function")
|
|
2232
2232
|
throw new Error("core must be a function");
|
|
2233
|
-
return kt(i), kt(o),
|
|
2233
|
+
return kt(i), kt(o), Dn(s), Dn(n), (c, a, l, f, u = 0) => {
|
|
2234
2234
|
ue(c), ue(a), ue(l);
|
|
2235
2235
|
const p = l.length;
|
|
2236
2236
|
if (f || (f = new Uint8Array(p)), ue(f), kt(u), u < 0 || u >= Br)
|
|
@@ -2245,7 +2245,7 @@ function io(e, t) {
|
|
|
2245
2245
|
h = new Uint8Array(32), h.set(c), h.set(c, 16), d = to, w.push(h);
|
|
2246
2246
|
else
|
|
2247
2247
|
throw new Error(`arx: invalid 32-byte key, got length=${g}`);
|
|
2248
|
-
|
|
2248
|
+
Wt(a) || (a = a.slice(), w.push(a));
|
|
2249
2249
|
const y = F(h);
|
|
2250
2250
|
if (r) {
|
|
2251
2251
|
if (a.length !== 24)
|
|
@@ -2266,11 +2266,11 @@ function io(e, t) {
|
|
|
2266
2266
|
};
|
|
2267
2267
|
}
|
|
2268
2268
|
function so(e, t, n, r, i, s = 20) {
|
|
2269
|
-
let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1], p = t[2], w = t[3], g = t[4], h = t[5], d = t[6], y = t[7], E = i, S = n[0], _ = n[1], B = n[2], m = o, x = c,
|
|
2269
|
+
let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1], p = t[2], w = t[3], g = t[4], h = t[5], d = t[6], y = t[7], E = i, S = n[0], _ = n[1], B = n[2], m = o, x = c, K = a, M = l, I = f, A = u, R = p, T = w, D = g, b = h, v = d, N = y, k = E, C = S, U = _, O = B;
|
|
2270
2270
|
for (let ee = 0; ee < s; ee += 2)
|
|
2271
|
-
m = m + I | 0, k = L(k ^ m, 16),
|
|
2271
|
+
m = m + I | 0, k = L(k ^ m, 16), D = D + k | 0, I = L(I ^ D, 12), m = m + I | 0, k = L(k ^ m, 8), D = D + k | 0, I = L(I ^ D, 7), x = x + A | 0, C = L(C ^ x, 16), b = b + C | 0, A = L(A ^ b, 12), x = x + A | 0, C = L(C ^ x, 8), b = b + C | 0, A = L(A ^ b, 7), K = K + R | 0, U = L(U ^ K, 16), v = v + U | 0, R = L(R ^ v, 12), K = K + R | 0, U = L(U ^ K, 8), v = v + U | 0, R = L(R ^ v, 7), M = M + T | 0, O = L(O ^ M, 16), N = N + O | 0, T = L(T ^ N, 12), M = M + T | 0, O = L(O ^ M, 8), N = N + O | 0, T = L(T ^ N, 7), m = m + A | 0, O = L(O ^ m, 16), v = v + O | 0, A = L(A ^ v, 12), m = m + A | 0, O = L(O ^ m, 8), v = v + O | 0, A = L(A ^ v, 7), x = x + R | 0, k = L(k ^ x, 16), N = N + k | 0, R = L(R ^ N, 12), x = x + R | 0, k = L(k ^ x, 8), N = N + k | 0, R = L(R ^ N, 7), K = K + T | 0, C = L(C ^ K, 16), D = D + C | 0, T = L(T ^ D, 12), K = K + T | 0, C = L(C ^ K, 8), D = D + C | 0, T = L(T ^ D, 7), M = M + I | 0, U = L(U ^ M, 16), b = b + U | 0, I = L(I ^ b, 12), M = M + I | 0, U = L(U ^ M, 8), b = b + U | 0, I = L(I ^ b, 7);
|
|
2272
2272
|
let $ = 0;
|
|
2273
|
-
r[$++] = o + m | 0, r[$++] = c + x | 0, r[$++] = a +
|
|
2273
|
+
r[$++] = o + m | 0, r[$++] = c + x | 0, r[$++] = a + K | 0, r[$++] = l + M | 0, r[$++] = f + I | 0, r[$++] = u + A | 0, r[$++] = p + R | 0, r[$++] = w + T | 0, r[$++] = g + D | 0, r[$++] = h + b | 0, r[$++] = d + v | 0, r[$++] = y + N | 0, r[$++] = E + k | 0, r[$++] = S + C | 0, r[$++] = _ + U | 0, r[$++] = B + O | 0;
|
|
2274
2274
|
}
|
|
2275
2275
|
const kr = /* @__PURE__ */ io(so, {
|
|
2276
2276
|
counterRight: !1,
|
|
@@ -2314,18 +2314,18 @@ class Ir extends dr {
|
|
|
2314
2314
|
}
|
|
2315
2315
|
const dt = (e, t, n) => new Ir(e, t).update(n).digest();
|
|
2316
2316
|
dt.create = (e, t) => new Ir(e, t);
|
|
2317
|
-
function
|
|
2317
|
+
function rn(e, t, n) {
|
|
2318
2318
|
return se.hash(e), n === void 0 && (n = new Uint8Array(e.outputLen)), dt(e, Je(n), Je(t));
|
|
2319
2319
|
}
|
|
2320
|
-
const _t = new Uint8Array([0]),
|
|
2320
|
+
const _t = new Uint8Array([0]), zn = new Uint8Array();
|
|
2321
2321
|
function _r(e, t, n, r = 32) {
|
|
2322
2322
|
if (se.hash(e), se.number(r), r > 255 * e.outputLen)
|
|
2323
2323
|
throw new Error("Length should be <= 255*HashLen");
|
|
2324
2324
|
const i = Math.ceil(r / e.outputLen);
|
|
2325
|
-
n === void 0 && (n =
|
|
2325
|
+
n === void 0 && (n = zn);
|
|
2326
2326
|
const s = new Uint8Array(i * e.outputLen), o = dt.create(e, t), c = o._cloneInto(), a = new Uint8Array(o.outputLen);
|
|
2327
2327
|
for (let l = 0; l < i; l++)
|
|
2328
|
-
_t[0] = l + 1, c.update(l === 0 ?
|
|
2328
|
+
_t[0] = l + 1, c.update(l === 0 ? zn : a).update(n).update(_t).digestInto(a), s.set(a, e.outputLen * l), o._cloneInto(c);
|
|
2329
2329
|
return o.destroy(), c.destroy(), a.fill(0), _t.fill(0), s.slice(0, r);
|
|
2330
2330
|
}
|
|
2331
2331
|
var oo = Object.defineProperty, H = (e, t) => {
|
|
@@ -2349,7 +2349,7 @@ var co = {};
|
|
|
2349
2349
|
H(co, {
|
|
2350
2350
|
Queue: () => ho,
|
|
2351
2351
|
QueueNode: () => Ur,
|
|
2352
|
-
binarySearch: () =>
|
|
2352
|
+
binarySearch: () => sn,
|
|
2353
2353
|
bytesToHex: () => P,
|
|
2354
2354
|
hexToBytes: () => j,
|
|
2355
2355
|
insertEventIntoAscendingList: () => fo,
|
|
@@ -2369,14 +2369,14 @@ function uo(e) {
|
|
|
2369
2369
|
}
|
|
2370
2370
|
}
|
|
2371
2371
|
function lo(e, t) {
|
|
2372
|
-
const [n, r] =
|
|
2372
|
+
const [n, r] = sn(e, (i) => t.id === i.id ? 0 : t.created_at === i.created_at ? -1 : i.created_at - t.created_at);
|
|
2373
2373
|
return r || e.splice(n, 0, t), e;
|
|
2374
2374
|
}
|
|
2375
2375
|
function fo(e, t) {
|
|
2376
|
-
const [n, r] =
|
|
2376
|
+
const [n, r] = sn(e, (i) => t.id === i.id ? 0 : t.created_at === i.created_at ? -1 : t.created_at - i.created_at);
|
|
2377
2377
|
return r || e.splice(n, 0, t), e;
|
|
2378
2378
|
}
|
|
2379
|
-
function
|
|
2379
|
+
function sn(e, t) {
|
|
2380
2380
|
let n = 0, r = e.length - 1;
|
|
2381
2381
|
for (; n <= r; ) {
|
|
2382
2382
|
const i = Math.floor((n + r) / 2), s = t(e[i]);
|
|
@@ -2422,12 +2422,12 @@ var Ur = class {
|
|
|
2422
2422
|
}
|
|
2423
2423
|
finalizeEvent(e, t) {
|
|
2424
2424
|
const n = e;
|
|
2425
|
-
return n.pubkey = P(Ze.getPublicKey(t)), n.id =
|
|
2425
|
+
return n.pubkey = P(Ze.getPublicKey(t)), n.id = De(n), n.sig = P(Ze.sign(De(n), t)), n[Te] = !0, n;
|
|
2426
2426
|
}
|
|
2427
2427
|
verifyEvent(e) {
|
|
2428
2428
|
if (typeof e[Te] == "boolean")
|
|
2429
2429
|
return e[Te];
|
|
2430
|
-
const t =
|
|
2430
|
+
const t = De(e);
|
|
2431
2431
|
if (t !== e.id)
|
|
2432
2432
|
return e[Te] = !1, !1;
|
|
2433
2433
|
try {
|
|
@@ -2443,25 +2443,25 @@ function yo(e) {
|
|
|
2443
2443
|
throw new Error("can't serialize event with wrong or missing properties");
|
|
2444
2444
|
return JSON.stringify([0, e.pubkey, e.created_at, e.kind, e.tags, e.content]);
|
|
2445
2445
|
}
|
|
2446
|
-
function
|
|
2446
|
+
function De(e) {
|
|
2447
2447
|
let t = fe(ne.encode(yo(e)));
|
|
2448
2448
|
return P(t);
|
|
2449
2449
|
}
|
|
2450
2450
|
var yt = new po(), ke = yt.generateSecretKey, ae = yt.getPublicKey, Q = yt.finalizeEvent, gt = yt.verifyEvent, go = {};
|
|
2451
2451
|
H(go, {
|
|
2452
2452
|
Application: () => ya,
|
|
2453
|
-
BadgeAward: () =>
|
|
2453
|
+
BadgeAward: () => No,
|
|
2454
2454
|
BadgeDefinition: () => ca,
|
|
2455
2455
|
BlockedRelaysList: () => Vo,
|
|
2456
2456
|
BookmarkList: () => jo,
|
|
2457
2457
|
Bookmarksets: () => sa,
|
|
2458
2458
|
Calendar: () => xa,
|
|
2459
|
-
CalendarEventRSVP: () =>
|
|
2459
|
+
CalendarEventRSVP: () => Ka,
|
|
2460
2460
|
ChannelCreation: () => Mr,
|
|
2461
|
-
ChannelHideMessage: () =>
|
|
2461
|
+
ChannelHideMessage: () => Dr,
|
|
2462
2462
|
ChannelMessage: () => Hr,
|
|
2463
2463
|
ChannelMetadata: () => Pr,
|
|
2464
|
-
ChannelMuteUser: () =>
|
|
2464
|
+
ChannelMuteUser: () => qr,
|
|
2465
2465
|
ClassifiedListing: () => ba,
|
|
2466
2466
|
ClientAuth: () => zr,
|
|
2467
2467
|
CommunitiesList: () => zo,
|
|
@@ -2477,16 +2477,16 @@ H(go, {
|
|
|
2477
2477
|
DraftLong: () => da,
|
|
2478
2478
|
Emojisets: () => pa,
|
|
2479
2479
|
EncryptedDirectMessage: () => xo,
|
|
2480
|
-
EventDeletion: () =>
|
|
2480
|
+
EventDeletion: () => Ko,
|
|
2481
2481
|
FileMetadata: () => Ao,
|
|
2482
2482
|
FileServerPreference: () => Yo,
|
|
2483
2483
|
Followsets: () => na,
|
|
2484
|
-
GenericRepost: () =>
|
|
2484
|
+
GenericRepost: () => ln,
|
|
2485
2485
|
Genericlists: () => ra,
|
|
2486
2486
|
GiftWrap: () => jr,
|
|
2487
|
-
HTTPAuth: () =>
|
|
2487
|
+
HTTPAuth: () => fn,
|
|
2488
2488
|
Handlerinformation: () => Sa,
|
|
2489
|
-
Handlerrecommendation: () =>
|
|
2489
|
+
Handlerrecommendation: () => Na,
|
|
2490
2490
|
Highlights: () => Po,
|
|
2491
2491
|
InterestsList: () => Fo,
|
|
2492
2492
|
Interestsets: () => ua,
|
|
@@ -2505,18 +2505,18 @@ H(go, {
|
|
|
2505
2505
|
NWCWalletResponse: () => ea,
|
|
2506
2506
|
NostrConnect: () => ta,
|
|
2507
2507
|
OpenTimestamps: () => So,
|
|
2508
|
-
Pinlist: () =>
|
|
2508
|
+
Pinlist: () => Do,
|
|
2509
2509
|
PrivateDirectMessage: () => Or,
|
|
2510
2510
|
ProblemTracker: () => Bo,
|
|
2511
2511
|
ProfileBadges: () => aa,
|
|
2512
2512
|
PublicChatsList: () => Wo,
|
|
2513
|
-
Reaction: () =>
|
|
2513
|
+
Reaction: () => un,
|
|
2514
2514
|
RecommendRelay: () => mo,
|
|
2515
|
-
RelayList: () =>
|
|
2515
|
+
RelayList: () => qo,
|
|
2516
2516
|
Relaysets: () => ia,
|
|
2517
2517
|
Report: () => ko,
|
|
2518
2518
|
Reporting: () => Io,
|
|
2519
|
-
Repost: () =>
|
|
2519
|
+
Repost: () => cn,
|
|
2520
2520
|
Seal: () => Tr,
|
|
2521
2521
|
SearchRelaysList: () => Zo,
|
|
2522
2522
|
ShortTextNote: () => Rr,
|
|
@@ -2527,41 +2527,41 @@ H(go, {
|
|
|
2527
2527
|
ZapGoal: () => To,
|
|
2528
2528
|
ZapRequest: () => Oo,
|
|
2529
2529
|
classifyKind: () => wo,
|
|
2530
|
-
isAddressableKind: () =>
|
|
2530
|
+
isAddressableKind: () => an,
|
|
2531
2531
|
isEphemeralKind: () => $r,
|
|
2532
2532
|
isKind: () => bo,
|
|
2533
2533
|
isRegularKind: () => Lr,
|
|
2534
|
-
isReplaceableKind: () =>
|
|
2534
|
+
isReplaceableKind: () => on
|
|
2535
2535
|
});
|
|
2536
2536
|
function Lr(e) {
|
|
2537
2537
|
return 1e3 <= e && e < 1e4 || [1, 2, 4, 5, 6, 7, 8, 16, 40, 41, 42, 43, 44].includes(e);
|
|
2538
2538
|
}
|
|
2539
|
-
function
|
|
2539
|
+
function on(e) {
|
|
2540
2540
|
return [0, 3].includes(e) || 1e4 <= e && e < 2e4;
|
|
2541
2541
|
}
|
|
2542
2542
|
function $r(e) {
|
|
2543
2543
|
return 2e4 <= e && e < 3e4;
|
|
2544
2544
|
}
|
|
2545
|
-
function
|
|
2545
|
+
function an(e) {
|
|
2546
2546
|
return 3e4 <= e && e < 4e4;
|
|
2547
2547
|
}
|
|
2548
2548
|
function wo(e) {
|
|
2549
|
-
return Lr(e) ? "regular" :
|
|
2549
|
+
return Lr(e) ? "regular" : on(e) ? "replaceable" : $r(e) ? "ephemeral" : an(e) ? "parameterized" : "unknown";
|
|
2550
2550
|
}
|
|
2551
2551
|
function bo(e, t) {
|
|
2552
2552
|
const n = t instanceof Array ? t : [t];
|
|
2553
2553
|
return pt(e) && n.includes(e.kind) || !1;
|
|
2554
2554
|
}
|
|
2555
|
-
var vo = 0, Rr = 1, mo = 2, Eo = 3, xo = 4,
|
|
2555
|
+
var vo = 0, Rr = 1, mo = 2, Eo = 3, xo = 4, Ko = 5, cn = 6, un = 7, No = 8, Tr = 13, Or = 14, ln = 16, Mr = 40, Pr = 41, Hr = 42, Dr = 43, qr = 44, So = 1040, jr = 1059, Ao = 1063, Co = 1311, Bo = 1971, ko = 1984, Io = 1984, _o = 1985, Uo = 4550, Lo = 5999, $o = 6999, Ro = 7e3, To = 9041, Oo = 9734, Mo = 9735, Po = 9802, Ho = 1e4, Do = 10001, qo = 10002, jo = 10003, zo = 10004, Wo = 10005, Vo = 10006, Zo = 10007, Fo = 10015, Go = 10030, Jo = 10050, Yo = 10096, Xo = 13194, Qo = 21e3, zr = 22242, Wr = 23194, ea = 23195, ta = 24133, fn = 27235, na = 3e4, ra = 30001, ia = 30002, sa = 30003, oa = 30004, aa = 30008, ca = 30009, ua = 30015, la = 30017, fa = 30018, ha = 30023, da = 30024, pa = 30030, ya = 30078, ga = 30311, wa = 30315, ba = 30402, va = 30403, ma = 31922, Ea = 31923, xa = 31924, Ka = 31925, Na = 31989, Sa = 31990, Aa = 34550, Ca = {};
|
|
2556
2556
|
H(Ca, {
|
|
2557
|
-
getHex64: () =>
|
|
2557
|
+
getHex64: () => hn,
|
|
2558
2558
|
getInt: () => Vr,
|
|
2559
2559
|
getSubscriptionId: () => Ba,
|
|
2560
2560
|
matchEventId: () => ka,
|
|
2561
2561
|
matchEventKind: () => _a,
|
|
2562
2562
|
matchEventPubkey: () => Ia
|
|
2563
2563
|
});
|
|
2564
|
-
function
|
|
2564
|
+
function hn(e, t) {
|
|
2565
2565
|
let n = t.length + 3, r = e.indexOf(`"${t}":`) + n, i = e.slice(r).indexOf('"') + r + 1;
|
|
2566
2566
|
return e.slice(i, i + 64);
|
|
2567
2567
|
}
|
|
@@ -2583,10 +2583,10 @@ function Ba(e) {
|
|
|
2583
2583
|
return e.slice(r + 1, s);
|
|
2584
2584
|
}
|
|
2585
2585
|
function ka(e, t) {
|
|
2586
|
-
return t ===
|
|
2586
|
+
return t === hn(e, "id");
|
|
2587
2587
|
}
|
|
2588
2588
|
function Ia(e, t) {
|
|
2589
|
-
return t ===
|
|
2589
|
+
return t === hn(e, "pubkey");
|
|
2590
2590
|
}
|
|
2591
2591
|
function _a(e, t) {
|
|
2592
2592
|
return t === Vr(e, "kind");
|
|
@@ -2619,16 +2619,16 @@ try {
|
|
|
2619
2619
|
var Ta = {};
|
|
2620
2620
|
H(Ta, {
|
|
2621
2621
|
BECH32_REGEX: () => Zr,
|
|
2622
|
-
Bech32MaxSize: () =>
|
|
2622
|
+
Bech32MaxSize: () => dn,
|
|
2623
2623
|
NostrTypeGuard: () => Oa,
|
|
2624
2624
|
decode: () => wt,
|
|
2625
2625
|
decodeNostrURI: () => Pa,
|
|
2626
2626
|
encodeBytes: () => vt,
|
|
2627
2627
|
naddrEncode: () => Wa,
|
|
2628
2628
|
neventEncode: () => za,
|
|
2629
|
-
noteEncode: () =>
|
|
2629
|
+
noteEncode: () => qa,
|
|
2630
2630
|
nprofileEncode: () => ja,
|
|
2631
|
-
npubEncode: () =>
|
|
2631
|
+
npubEncode: () => Da,
|
|
2632
2632
|
nsecEncode: () => Ha
|
|
2633
2633
|
});
|
|
2634
2634
|
var Oa = {
|
|
@@ -2639,7 +2639,7 @@ var Oa = {
|
|
|
2639
2639
|
isNPub: (e) => /^npub1[a-z\d]{58}$/.test(e || ""),
|
|
2640
2640
|
isNote: (e) => /^note1[a-z\d]+$/.test(e || ""),
|
|
2641
2641
|
isNcryptsec: (e) => /^ncryptsec1[a-z\d]+$/.test(e || "")
|
|
2642
|
-
},
|
|
2642
|
+
}, dn = 5e3, Zr = /[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;
|
|
2643
2643
|
function Ma(e) {
|
|
2644
2644
|
const t = new Uint8Array(4);
|
|
2645
2645
|
return t[0] = e >> 24 & 255, t[1] = e >> 16 & 255, t[2] = e >> 8 & 255, t[3] = e & 255, t;
|
|
@@ -2653,7 +2653,7 @@ function Pa(e) {
|
|
|
2653
2653
|
}
|
|
2654
2654
|
function wt(e) {
|
|
2655
2655
|
var i, s, o, c, a, l, f;
|
|
2656
|
-
let { prefix: t, words: n } = ze.decode(e,
|
|
2656
|
+
let { prefix: t, words: n } = ze.decode(e, dn), r = new Uint8Array(ze.fromWords(n));
|
|
2657
2657
|
switch (t) {
|
|
2658
2658
|
case "nprofile": {
|
|
2659
2659
|
let u = Ut(r);
|
|
@@ -2733,21 +2733,21 @@ function Ut(e) {
|
|
|
2733
2733
|
function Ha(e) {
|
|
2734
2734
|
return vt("nsec", e);
|
|
2735
2735
|
}
|
|
2736
|
-
function
|
|
2736
|
+
function Da(e) {
|
|
2737
2737
|
return vt("npub", j(e));
|
|
2738
2738
|
}
|
|
2739
|
-
function
|
|
2739
|
+
function qa(e) {
|
|
2740
2740
|
return vt("note", j(e));
|
|
2741
2741
|
}
|
|
2742
2742
|
function bt(e, t) {
|
|
2743
2743
|
let n = ze.toWords(t);
|
|
2744
|
-
return ze.encode(e, n,
|
|
2744
|
+
return ze.encode(e, n, dn);
|
|
2745
2745
|
}
|
|
2746
2746
|
function vt(e, t) {
|
|
2747
2747
|
return bt(e, t);
|
|
2748
2748
|
}
|
|
2749
2749
|
function ja(e) {
|
|
2750
|
-
let t =
|
|
2750
|
+
let t = pn({
|
|
2751
2751
|
0: [j(e.pubkey)],
|
|
2752
2752
|
1: (e.relays || []).map((n) => ne.encode(n))
|
|
2753
2753
|
});
|
|
@@ -2756,7 +2756,7 @@ function ja(e) {
|
|
|
2756
2756
|
function za(e) {
|
|
2757
2757
|
let t;
|
|
2758
2758
|
e.kind !== void 0 && (t = Ma(e.kind));
|
|
2759
|
-
let n =
|
|
2759
|
+
let n = pn({
|
|
2760
2760
|
0: [j(e.id)],
|
|
2761
2761
|
1: (e.relays || []).map((r) => ne.encode(r)),
|
|
2762
2762
|
2: e.author ? [j(e.author)] : [],
|
|
@@ -2767,7 +2767,7 @@ function za(e) {
|
|
|
2767
2767
|
function Wa(e) {
|
|
2768
2768
|
let t = new ArrayBuffer(4);
|
|
2769
2769
|
new DataView(t).setUint32(0, e.kind, !1);
|
|
2770
|
-
let n =
|
|
2770
|
+
let n = pn({
|
|
2771
2771
|
0: [ne.encode(e.identifier)],
|
|
2772
2772
|
1: (e.relays || []).map((r) => ne.encode(r)),
|
|
2773
2773
|
2: [j(e.pubkey)],
|
|
@@ -2775,7 +2775,7 @@ function Wa(e) {
|
|
|
2775
2775
|
});
|
|
2776
2776
|
return bt("naddr", n);
|
|
2777
2777
|
}
|
|
2778
|
-
function
|
|
2778
|
+
function pn(e) {
|
|
2779
2779
|
let t = [];
|
|
2780
2780
|
return Object.entries(e).reverse().forEach(([n, r]) => {
|
|
2781
2781
|
r.forEach((i) => {
|
|
@@ -2804,14 +2804,14 @@ function Gr(e) {
|
|
|
2804
2804
|
}
|
|
2805
2805
|
var Fa = {};
|
|
2806
2806
|
H(Fa, {
|
|
2807
|
-
NIP05_REGEX: () =>
|
|
2807
|
+
NIP05_REGEX: () => yn,
|
|
2808
2808
|
isNip05: () => Ga,
|
|
2809
2809
|
isValid: () => Xa,
|
|
2810
2810
|
queryProfile: () => Jr,
|
|
2811
2811
|
searchDomain: () => Ya,
|
|
2812
2812
|
useFetchImplementation: () => Ja
|
|
2813
2813
|
});
|
|
2814
|
-
var
|
|
2814
|
+
var yn = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/, Ga = (e) => yn.test(e || ""), mt;
|
|
2815
2815
|
try {
|
|
2816
2816
|
mt = fetch;
|
|
2817
2817
|
} catch {
|
|
@@ -2831,7 +2831,7 @@ async function Ya(e, t = "") {
|
|
|
2831
2831
|
}
|
|
2832
2832
|
async function Jr(e) {
|
|
2833
2833
|
var i;
|
|
2834
|
-
const t = e.match(
|
|
2834
|
+
const t = e.match(yn);
|
|
2835
2835
|
if (!t)
|
|
2836
2836
|
return null;
|
|
2837
2837
|
const [, n = "_", r] = t;
|
|
@@ -2984,22 +2984,22 @@ H(ac, {
|
|
|
2984
2984
|
createRumor: () => ci,
|
|
2985
2985
|
createSeal: () => ui,
|
|
2986
2986
|
createWrap: () => li,
|
|
2987
|
-
unwrapEvent: () =>
|
|
2987
|
+
unwrapEvent: () => mn,
|
|
2988
2988
|
unwrapManyEvents: () => fi,
|
|
2989
2989
|
wrapEvent: () => st,
|
|
2990
2990
|
wrapManyEvents: () => pc
|
|
2991
2991
|
});
|
|
2992
|
-
var
|
|
2993
|
-
H(
|
|
2994
|
-
decrypt: () =>
|
|
2995
|
-
encrypt: () =>
|
|
2996
|
-
getConversationKey: () =>
|
|
2992
|
+
var q = {};
|
|
2993
|
+
H(q, {
|
|
2994
|
+
decrypt: () => vn,
|
|
2995
|
+
encrypt: () => bn,
|
|
2996
|
+
getConversationKey: () => gn,
|
|
2997
2997
|
v2: () => hc
|
|
2998
2998
|
});
|
|
2999
2999
|
var ei = 1, ti = 65535;
|
|
3000
|
-
function
|
|
3000
|
+
function gn(e, t) {
|
|
3001
3001
|
const n = _e.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3002
|
-
return
|
|
3002
|
+
return rn(fe, n, "nip44-v2");
|
|
3003
3003
|
}
|
|
3004
3004
|
function ni(e, t) {
|
|
3005
3005
|
const n = _r(fe, e, t, 76);
|
|
@@ -3009,7 +3009,7 @@ function ni(e, t) {
|
|
|
3009
3009
|
hmac_key: n.subarray(44, 76)
|
|
3010
3010
|
};
|
|
3011
3011
|
}
|
|
3012
|
-
function
|
|
3012
|
+
function wn(e) {
|
|
3013
3013
|
if (!Number.isSafeInteger(e) || e < 1)
|
|
3014
3014
|
throw new Error("expected positive integer");
|
|
3015
3015
|
if (e <= 32)
|
|
@@ -3024,12 +3024,12 @@ function cc(e) {
|
|
|
3024
3024
|
return new DataView(t.buffer).setUint16(0, e, !1), t;
|
|
3025
3025
|
}
|
|
3026
3026
|
function uc(e) {
|
|
3027
|
-
const t = ne.encode(e), n = t.length, r = cc(n), i = new Uint8Array(
|
|
3027
|
+
const t = ne.encode(e), n = t.length, r = cc(n), i = new Uint8Array(wn(n) - n);
|
|
3028
3028
|
return ft(r, t, i);
|
|
3029
3029
|
}
|
|
3030
3030
|
function lc(e) {
|
|
3031
3031
|
const t = new DataView(e.buffer).getUint16(0), n = e.subarray(2, 2 + t);
|
|
3032
|
-
if (t < ei || t > ti || n.length !== t || e.length !== 2 +
|
|
3032
|
+
if (t < ei || t > ti || n.length !== t || e.length !== 2 + wn(t))
|
|
3033
3033
|
throw new Error("invalid padding");
|
|
3034
3034
|
return le.decode(n);
|
|
3035
3035
|
}
|
|
@@ -3065,25 +3065,25 @@ function fc(e) {
|
|
|
3065
3065
|
mac: n.subarray(-32)
|
|
3066
3066
|
};
|
|
3067
3067
|
}
|
|
3068
|
-
function
|
|
3068
|
+
function bn(e, t, n = yr(32)) {
|
|
3069
3069
|
const { chacha_key: r, chacha_nonce: i, hmac_key: s } = ni(t, n), o = uc(e), c = kr(r, i, o), a = ri(s, c, n);
|
|
3070
3070
|
return he.encode(ft(new Uint8Array([2]), n, c, a));
|
|
3071
3071
|
}
|
|
3072
|
-
function
|
|
3072
|
+
function vn(e, t) {
|
|
3073
3073
|
const { nonce: n, ciphertext: r, mac: i } = fc(e), { chacha_key: s, chacha_nonce: o, hmac_key: c } = ni(t, n), a = ri(c, r, n);
|
|
3074
|
-
if (!
|
|
3074
|
+
if (!Ds(a, i))
|
|
3075
3075
|
throw new Error("invalid MAC");
|
|
3076
3076
|
const l = kr(s, o, r);
|
|
3077
3077
|
return lc(l);
|
|
3078
3078
|
}
|
|
3079
3079
|
var hc = {
|
|
3080
3080
|
utils: {
|
|
3081
|
-
getConversationKey:
|
|
3082
|
-
calcPaddedLen:
|
|
3081
|
+
getConversationKey: gn,
|
|
3082
|
+
calcPaddedLen: wn
|
|
3083
3083
|
},
|
|
3084
|
-
encrypt:
|
|
3085
|
-
decrypt:
|
|
3086
|
-
}, dc = 2 * 24 * 60 * 60, ii = () => Math.round(Date.now() / 1e3), si = () => Math.round(ii() - Math.random() * dc), oi = (e, t) =>
|
|
3084
|
+
encrypt: bn,
|
|
3085
|
+
decrypt: vn
|
|
3086
|
+
}, dc = 2 * 24 * 60 * 60, ii = () => Math.round(Date.now() / 1e3), si = () => Math.round(ii() - Math.random() * dc), oi = (e, t) => gn(e, t), ai = (e, t, n) => bn(JSON.stringify(e), oi(t, n)), Wn = (e, t) => JSON.parse(vn(e.content, oi(t, e.pubkey)));
|
|
3087
3087
|
function ci(e, t) {
|
|
3088
3088
|
const n = {
|
|
3089
3089
|
created_at: ii(),
|
|
@@ -3092,7 +3092,7 @@ function ci(e, t) {
|
|
|
3092
3092
|
...e,
|
|
3093
3093
|
pubkey: ae(t)
|
|
3094
3094
|
};
|
|
3095
|
-
return n.id =
|
|
3095
|
+
return n.id = De(n), n;
|
|
3096
3096
|
}
|
|
3097
3097
|
function ui(e, t, n) {
|
|
3098
3098
|
return Q(
|
|
@@ -3129,14 +3129,14 @@ function pc(e, t, n) {
|
|
|
3129
3129
|
i.push(st(e, t, s));
|
|
3130
3130
|
}), i;
|
|
3131
3131
|
}
|
|
3132
|
-
function
|
|
3133
|
-
const n =
|
|
3134
|
-
return
|
|
3132
|
+
function mn(e, t) {
|
|
3133
|
+
const n = Wn(e, t);
|
|
3134
|
+
return Wn(n, t);
|
|
3135
3135
|
}
|
|
3136
3136
|
function fi(e, t) {
|
|
3137
3137
|
let n = [];
|
|
3138
3138
|
return e.forEach((r) => {
|
|
3139
|
-
n.push(
|
|
3139
|
+
n.push(mn(r, t));
|
|
3140
3140
|
}), n.sort((r, i) => r.created_at - i.created_at), n;
|
|
3141
3141
|
}
|
|
3142
3142
|
function yc(e, t, n, r) {
|
|
@@ -3161,7 +3161,7 @@ function gc(e, t, n, r, i) {
|
|
|
3161
3161
|
(o) => hi(e, o, n, r, i)
|
|
3162
3162
|
);
|
|
3163
3163
|
}
|
|
3164
|
-
var wc =
|
|
3164
|
+
var wc = mn, bc = fi, vc = {};
|
|
3165
3165
|
H(vc, {
|
|
3166
3166
|
finishRepostEvent: () => mc,
|
|
3167
3167
|
getRepostedEvent: () => Ec,
|
|
@@ -3171,7 +3171,7 @@ function mc(e, t, n, r) {
|
|
|
3171
3171
|
var o;
|
|
3172
3172
|
let i;
|
|
3173
3173
|
const s = [...e.tags ?? [], ["e", t.id, n], ["p", t.pubkey]];
|
|
3174
|
-
return t.kind === Rr ? i =
|
|
3174
|
+
return t.kind === Rr ? i = cn : (i = ln, s.push(["k", String(t.kind)])), Q(
|
|
3175
3175
|
{
|
|
3176
3176
|
kind: i,
|
|
3177
3177
|
tags: s,
|
|
@@ -3182,7 +3182,7 @@ function mc(e, t, n, r) {
|
|
|
3182
3182
|
);
|
|
3183
3183
|
}
|
|
3184
3184
|
function di(e) {
|
|
3185
|
-
if (![
|
|
3185
|
+
if (![cn, ln].includes(e.kind))
|
|
3186
3186
|
return;
|
|
3187
3187
|
let t, n;
|
|
3188
3188
|
for (let r = e.tags.length - 1; r >= 0 && (t === void 0 || n === void 0); r--) {
|
|
@@ -3211,16 +3211,16 @@ function Ec(e, { skipVerification: t } = {}) {
|
|
|
3211
3211
|
}
|
|
3212
3212
|
var xc = {};
|
|
3213
3213
|
H(xc, {
|
|
3214
|
-
NOSTR_URI_REGEX: () =>
|
|
3215
|
-
parse: () =>
|
|
3216
|
-
test: () =>
|
|
3214
|
+
NOSTR_URI_REGEX: () => En,
|
|
3215
|
+
parse: () => Nc,
|
|
3216
|
+
test: () => Kc
|
|
3217
3217
|
});
|
|
3218
|
-
var
|
|
3219
|
-
function Nc(e) {
|
|
3220
|
-
return typeof e == "string" && new RegExp(`^${mn.source}$`).test(e);
|
|
3221
|
-
}
|
|
3218
|
+
var En = new RegExp(`nostr:(${Zr.source})`);
|
|
3222
3219
|
function Kc(e) {
|
|
3223
|
-
|
|
3220
|
+
return typeof e == "string" && new RegExp(`^${En.source}$`).test(e);
|
|
3221
|
+
}
|
|
3222
|
+
function Nc(e) {
|
|
3223
|
+
const t = e.match(new RegExp(`^${En.source}$`));
|
|
3224
3224
|
if (!t)
|
|
3225
3225
|
throw new Error(`Invalid Nostr URI: ${e}`);
|
|
3226
3226
|
return {
|
|
@@ -3239,7 +3239,7 @@ function Ac(e, t, n) {
|
|
|
3239
3239
|
return Q(
|
|
3240
3240
|
{
|
|
3241
3241
|
...e,
|
|
3242
|
-
kind:
|
|
3242
|
+
kind: un,
|
|
3243
3243
|
tags: [...e.tags ?? [], ...r, ["e", t.id], ["p", t.pubkey]],
|
|
3244
3244
|
content: e.content ?? "+"
|
|
3245
3245
|
},
|
|
@@ -3247,7 +3247,7 @@ function Ac(e, t, n) {
|
|
|
3247
3247
|
);
|
|
3248
3248
|
}
|
|
3249
3249
|
function Cc(e) {
|
|
3250
|
-
if (e.kind !==
|
|
3250
|
+
if (e.kind !== un)
|
|
3251
3251
|
return;
|
|
3252
3252
|
let t, n;
|
|
3253
3253
|
for (let r = e.tags.length - 1; r >= 0 && (t === void 0 || n === void 0); r--) {
|
|
@@ -3265,7 +3265,7 @@ var Bc = {};
|
|
|
3265
3265
|
H(Bc, {
|
|
3266
3266
|
parse: () => Ic
|
|
3267
3267
|
});
|
|
3268
|
-
var kc = /\W/m,
|
|
3268
|
+
var kc = /\W/m, Vn = /\W |\W$|$|,| /m;
|
|
3269
3269
|
function* Ic(e) {
|
|
3270
3270
|
const t = e.length;
|
|
3271
3271
|
let n = 0, r = 0;
|
|
@@ -3295,7 +3295,7 @@ function* Ic(e) {
|
|
|
3295
3295
|
continue;
|
|
3296
3296
|
}
|
|
3297
3297
|
} else if (e.substring(i - 5, i) === "https" || e.substring(i - 4, i) === "http") {
|
|
3298
|
-
const s = e.substring(i + 4).match(
|
|
3298
|
+
const s = e.substring(i + 4).match(Vn), o = s ? i + 4 + s.index : t, c = e[i - 1] === "s" ? 5 : 4;
|
|
3299
3299
|
try {
|
|
3300
3300
|
let a = new URL(e.substring(i - c, o));
|
|
3301
3301
|
if (a.hostname.indexOf(".") === -1)
|
|
@@ -3319,7 +3319,7 @@ function* Ic(e) {
|
|
|
3319
3319
|
continue;
|
|
3320
3320
|
}
|
|
3321
3321
|
} else if (e.substring(i - 3, i) === "wss" || e.substring(i - 2, i) === "ws") {
|
|
3322
|
-
const s = e.substring(i + 4).match(
|
|
3322
|
+
const s = e.substring(i + 4).match(Vn), o = s ? i + 4 + s.index : t, c = e[i - 1] === "s" ? 3 : 2;
|
|
3323
3323
|
try {
|
|
3324
3324
|
let a = new URL(e.substring(i - c, o));
|
|
3325
3325
|
if (a.hostname.indexOf(".") === -1)
|
|
@@ -3400,7 +3400,7 @@ var Uc = (e, t) => {
|
|
|
3400
3400
|
return;
|
|
3401
3401
|
return Q(
|
|
3402
3402
|
{
|
|
3403
|
-
kind:
|
|
3403
|
+
kind: Dr,
|
|
3404
3404
|
tags: [["e", e.channel_message_event_id], ...e.tags ?? []],
|
|
3405
3405
|
content: n,
|
|
3406
3406
|
created_at: e.created_at
|
|
@@ -3417,7 +3417,7 @@ var Uc = (e, t) => {
|
|
|
3417
3417
|
return;
|
|
3418
3418
|
return Q(
|
|
3419
3419
|
{
|
|
3420
|
-
kind:
|
|
3420
|
+
kind: qr,
|
|
3421
3421
|
tags: [["p", e.pubkey_to_mute], ...e.tags ?? []],
|
|
3422
3422
|
content: n,
|
|
3423
3423
|
created_at: e.created_at
|
|
@@ -3428,12 +3428,12 @@ var Uc = (e, t) => {
|
|
|
3428
3428
|
H(Oc, {
|
|
3429
3429
|
EMOJI_SHORTCODE_REGEX: () => pi,
|
|
3430
3430
|
matchAll: () => Mc,
|
|
3431
|
-
regex: () =>
|
|
3431
|
+
regex: () => xn,
|
|
3432
3432
|
replaceAll: () => Pc
|
|
3433
3433
|
});
|
|
3434
|
-
var pi = /:(\w+):/,
|
|
3434
|
+
var pi = /:(\w+):/, xn = () => new RegExp(`\\B${pi.source}\\B`, "g");
|
|
3435
3435
|
function* Mc(e) {
|
|
3436
|
-
const t = e.matchAll(
|
|
3436
|
+
const t = e.matchAll(xn());
|
|
3437
3437
|
for (const n of t)
|
|
3438
3438
|
try {
|
|
3439
3439
|
const [r, i] = n;
|
|
@@ -3447,27 +3447,27 @@ function* Mc(e) {
|
|
|
3447
3447
|
}
|
|
3448
3448
|
}
|
|
3449
3449
|
function Pc(e, t) {
|
|
3450
|
-
return e.replaceAll(
|
|
3450
|
+
return e.replaceAll(xn(), (n, r) => t({
|
|
3451
3451
|
shortcode: n,
|
|
3452
3452
|
name: r
|
|
3453
3453
|
}));
|
|
3454
3454
|
}
|
|
3455
3455
|
var Hc = {};
|
|
3456
3456
|
H(Hc, {
|
|
3457
|
-
useFetchImplementation: () =>
|
|
3458
|
-
validateGithub: () =>
|
|
3457
|
+
useFetchImplementation: () => Dc,
|
|
3458
|
+
validateGithub: () => qc
|
|
3459
3459
|
});
|
|
3460
|
-
var
|
|
3460
|
+
var Kn;
|
|
3461
3461
|
try {
|
|
3462
|
-
|
|
3462
|
+
Kn = fetch;
|
|
3463
3463
|
} catch {
|
|
3464
3464
|
}
|
|
3465
|
-
function
|
|
3466
|
-
|
|
3465
|
+
function Dc(e) {
|
|
3466
|
+
Kn = e;
|
|
3467
3467
|
}
|
|
3468
|
-
async function
|
|
3468
|
+
async function qc(e, t, n) {
|
|
3469
3469
|
try {
|
|
3470
|
-
return await (await
|
|
3470
|
+
return await (await Kn(`https://gist.github.com/${t}/${n}/raw`)).text() === `Verifying that I control the following Nostr public key: ${e}`;
|
|
3471
3471
|
} catch {
|
|
3472
3472
|
return !1;
|
|
3473
3473
|
}
|
|
@@ -3478,10 +3478,10 @@ H(jc, {
|
|
|
3478
3478
|
parseConnectionString: () => zc
|
|
3479
3479
|
});
|
|
3480
3480
|
function zc(e) {
|
|
3481
|
-
const {
|
|
3482
|
-
if (!
|
|
3481
|
+
const { host: t, pathname: n, searchParams: r } = new URL(e), i = n || t, s = r.get("relay"), o = r.get("secret");
|
|
3482
|
+
if (!i || !s || !o)
|
|
3483
3483
|
throw new Error("invalid connection string");
|
|
3484
|
-
return { pubkey:
|
|
3484
|
+
return { pubkey: i, relay: s, secret: o };
|
|
3485
3485
|
}
|
|
3486
3486
|
async function Wc(e, t, n) {
|
|
3487
3487
|
const i = Fr(t, e, JSON.stringify({
|
|
@@ -3561,10 +3561,10 @@ function Yc({
|
|
|
3561
3561
|
]
|
|
3562
3562
|
};
|
|
3563
3563
|
if (t && typeof t == "string" && s.tags.push(["e", t]), t && typeof t == "object") {
|
|
3564
|
-
if (
|
|
3564
|
+
if (on(t.kind)) {
|
|
3565
3565
|
const o = ["a", `${t.kind}:${t.pubkey}:`];
|
|
3566
3566
|
s.tags.push(o);
|
|
3567
|
-
} else if (
|
|
3567
|
+
} else if (an(t.kind)) {
|
|
3568
3568
|
let o = t.tags.find(([a, l]) => a === "d" && l);
|
|
3569
3569
|
if (!o)
|
|
3570
3570
|
throw new Error("d tag not found or is empty");
|
|
@@ -3641,7 +3641,7 @@ function eu(e) {
|
|
|
3641
3641
|
var tu = {};
|
|
3642
3642
|
H(tu, {
|
|
3643
3643
|
getToken: () => nu,
|
|
3644
|
-
hashPayload: () =>
|
|
3644
|
+
hashPayload: () => Sn,
|
|
3645
3645
|
unpackEventFromToken: () => gi,
|
|
3646
3646
|
validateEvent: () => xi,
|
|
3647
3647
|
validateEventKind: () => bi,
|
|
@@ -3654,7 +3654,7 @@ H(tu, {
|
|
|
3654
3654
|
var yi = "Nostr ";
|
|
3655
3655
|
async function nu(e, t, n, r = !1, i) {
|
|
3656
3656
|
const s = {
|
|
3657
|
-
kind:
|
|
3657
|
+
kind: fn,
|
|
3658
3658
|
tags: [
|
|
3659
3659
|
["u", e],
|
|
3660
3660
|
["method", t]
|
|
@@ -3662,7 +3662,7 @@ async function nu(e, t, n, r = !1, i) {
|
|
|
3662
3662
|
created_at: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
3663
3663
|
content: ""
|
|
3664
3664
|
};
|
|
3665
|
-
i && s.tags.push(["payload",
|
|
3665
|
+
i && s.tags.push(["payload", Sn(i)]);
|
|
3666
3666
|
const o = await n(s);
|
|
3667
3667
|
return (r ? yi : "") + he.encode(ne.encode(JSON.stringify(o)));
|
|
3668
3668
|
}
|
|
@@ -3687,7 +3687,7 @@ function wi(e) {
|
|
|
3687
3687
|
return e.created_at ? Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3) - e.created_at < 60 : !1;
|
|
3688
3688
|
}
|
|
3689
3689
|
function bi(e) {
|
|
3690
|
-
return e.kind ===
|
|
3690
|
+
return e.kind === fn;
|
|
3691
3691
|
}
|
|
3692
3692
|
function vi(e, t) {
|
|
3693
3693
|
const n = e.tags.find((r) => r[0] === "u");
|
|
@@ -3697,7 +3697,7 @@ function mi(e, t) {
|
|
|
3697
3697
|
const n = e.tags.find((r) => r[0] === "method");
|
|
3698
3698
|
return n ? n.length > 0 && n[1].toLowerCase() === t.toLowerCase() : !1;
|
|
3699
3699
|
}
|
|
3700
|
-
function
|
|
3700
|
+
function Sn(e) {
|
|
3701
3701
|
const t = fe(ne.encode(JSON.stringify(e)));
|
|
3702
3702
|
return P(t);
|
|
3703
3703
|
}
|
|
@@ -3705,7 +3705,7 @@ function Ei(e, t) {
|
|
|
3705
3705
|
const n = e.tags.find((i) => i[0] === "payload");
|
|
3706
3706
|
if (!n)
|
|
3707
3707
|
return !1;
|
|
3708
|
-
const r =
|
|
3708
|
+
const r = Sn(t);
|
|
3709
3709
|
return n.length > 0 && n[1] === r;
|
|
3710
3710
|
}
|
|
3711
3711
|
async function xi(e, t, n, r) {
|
|
@@ -3723,7 +3723,7 @@ async function xi(e, t, n, r) {
|
|
|
3723
3723
|
throw new Error("Invalid nostr event, payload tag does not match request body hash");
|
|
3724
3724
|
return !0;
|
|
3725
3725
|
}
|
|
3726
|
-
const Oe = 1060,
|
|
3726
|
+
const Oe = 1060, Lt = 30078, Zn = 1059, iu = 14, wu = 100, su = 1;
|
|
3727
3727
|
function bu(e) {
|
|
3728
3728
|
return JSON.stringify({
|
|
3729
3729
|
version: su,
|
|
@@ -3838,7 +3838,7 @@ async function* mu(e) {
|
|
|
3838
3838
|
}
|
|
3839
3839
|
}
|
|
3840
3840
|
function Me(e, t = new Uint8Array(32), n = 1) {
|
|
3841
|
-
const r =
|
|
3841
|
+
const r = rn(fe, e, t), i = [];
|
|
3842
3842
|
for (let s = 1; s <= n; s++)
|
|
3843
3843
|
i.push(_r(fe, r, new Uint8Array([s]), 32));
|
|
3844
3844
|
return i;
|
|
@@ -3876,7 +3876,7 @@ class ot {
|
|
|
3876
3876
|
static init(t, n, r, i, s, o) {
|
|
3877
3877
|
const c = ke();
|
|
3878
3878
|
let a, l, f, u;
|
|
3879
|
-
i ? ([a, l] = Me(s,
|
|
3879
|
+
i ? ([a, l] = Me(s, q.getConversationKey(c, n), 2), f = {
|
|
3880
3880
|
publicKey: ae(r),
|
|
3881
3881
|
privateKey: r
|
|
3882
3882
|
}, u = {
|
|
@@ -3933,8 +3933,8 @@ class ot {
|
|
|
3933
3933
|
tags: t.tags || [],
|
|
3934
3934
|
pubkey: t.pubkey || au
|
|
3935
3935
|
};
|
|
3936
|
-
r.tags.some(([l]) => l === "ms") || r.tags.push(["ms", String(n)]), r.id =
|
|
3937
|
-
const [i, s] = this.ratchetEncrypt(JSON.stringify(r)), o =
|
|
3936
|
+
r.tags.some(([l]) => l === "ms") || r.tags.push(["ms", String(n)]), r.id = De(r);
|
|
3937
|
+
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);
|
|
3938
3938
|
return { event: Q({
|
|
3939
3939
|
content: s,
|
|
3940
3940
|
kind: Oe,
|
|
@@ -3965,25 +3965,25 @@ class ot {
|
|
|
3965
3965
|
number: this.state.sendingChainMessageNumber++,
|
|
3966
3966
|
nextPublicKey: this.state.ourNextNostrKey.publicKey,
|
|
3967
3967
|
previousChainLength: this.state.previousSendingChainMessageCount
|
|
3968
|
-
},
|
|
3968
|
+
}, q.encrypt(t, r)];
|
|
3969
3969
|
}
|
|
3970
3970
|
ratchetDecrypt(t, n, r) {
|
|
3971
3971
|
const i = this.trySkippedMessageKeys(t, n, r);
|
|
3972
3972
|
if (i) return i;
|
|
3973
3973
|
this.skipMessageKeys(t.number, r);
|
|
3974
3974
|
const [s, o] = Me(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3975
|
-
return this.state.receivingChainKey = s, this.state.receivingChainMessageNumber++,
|
|
3975
|
+
return this.state.receivingChainKey = s, this.state.receivingChainMessageNumber++, q.decrypt(n, o);
|
|
3976
3976
|
}
|
|
3977
3977
|
ratchetStep() {
|
|
3978
3978
|
this.state.previousSendingChainMessageCount = this.state.sendingChainMessageNumber, this.state.sendingChainMessageNumber = 0, this.state.receivingChainMessageNumber = 0;
|
|
3979
|
-
const t =
|
|
3979
|
+
const t = q.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [n, r] = Me(this.state.rootKey, t, 2);
|
|
3980
3980
|
this.state.receivingChainKey = r, this.state.ourCurrentNostrKey = this.state.ourNextNostrKey;
|
|
3981
3981
|
const i = ke();
|
|
3982
3982
|
this.state.ourNextNostrKey = {
|
|
3983
3983
|
publicKey: ae(i),
|
|
3984
3984
|
privateKey: i
|
|
3985
3985
|
};
|
|
3986
|
-
const s =
|
|
3986
|
+
const s = q.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [o, c] = Me(n, s, 2);
|
|
3987
3987
|
this.state.rootKey = o, this.state.sendingChainKey = c;
|
|
3988
3988
|
}
|
|
3989
3989
|
// 3. MESSAGE KEY FUNCTIONS
|
|
@@ -3996,10 +3996,10 @@ class ot {
|
|
|
3996
3996
|
headerKeys: [],
|
|
3997
3997
|
messageKeys: {}
|
|
3998
3998
|
}, this.state.ourCurrentNostrKey) {
|
|
3999
|
-
const i =
|
|
3999
|
+
const i = q.getConversationKey(this.state.ourCurrentNostrKey.privateKey, n);
|
|
4000
4000
|
this.state.skippedKeys[n].headerKeys.includes(i) || this.state.skippedKeys[n].headerKeys.push(i);
|
|
4001
4001
|
}
|
|
4002
|
-
const r =
|
|
4002
|
+
const r = q.getConversationKey(this.state.ourNextNostrKey.privateKey, n);
|
|
4003
4003
|
this.state.skippedKeys[n].headerKeys.includes(r) || this.state.skippedKeys[n].headerKeys.push(r);
|
|
4004
4004
|
}
|
|
4005
4005
|
for (; this.state.receivingChainMessageNumber < t; ) {
|
|
@@ -4012,28 +4012,28 @@ class ot {
|
|
|
4012
4012
|
const i = this.state.skippedKeys[r];
|
|
4013
4013
|
if (!i) return null;
|
|
4014
4014
|
const s = i.messageKeys[t.number];
|
|
4015
|
-
return s ? (delete i.messageKeys[t.number], Object.keys(i.messageKeys).length === 0 && delete this.state.skippedKeys[r],
|
|
4015
|
+
return s ? (delete i.messageKeys[t.number], Object.keys(i.messageKeys).length === 0 && delete this.state.skippedKeys[r], q.decrypt(n, s)) : null;
|
|
4016
4016
|
}
|
|
4017
4017
|
// 4. NOSTR EVENT HANDLING
|
|
4018
4018
|
decryptHeader(t) {
|
|
4019
4019
|
const n = t.tags[0][1];
|
|
4020
4020
|
if (this.state.ourCurrentNostrKey) {
|
|
4021
|
-
const s =
|
|
4021
|
+
const s = q.getConversationKey(this.state.ourCurrentNostrKey.privateKey, t.pubkey);
|
|
4022
4022
|
try {
|
|
4023
|
-
return [JSON.parse(
|
|
4023
|
+
return [JSON.parse(q.decrypt(n, s)), !1, !1];
|
|
4024
4024
|
} catch {
|
|
4025
4025
|
}
|
|
4026
4026
|
}
|
|
4027
|
-
const r =
|
|
4027
|
+
const r = q.getConversationKey(this.state.ourNextNostrKey.privateKey, t.pubkey);
|
|
4028
4028
|
try {
|
|
4029
|
-
return [JSON.parse(
|
|
4029
|
+
return [JSON.parse(q.decrypt(n, r)), !0, !1];
|
|
4030
4030
|
} catch {
|
|
4031
4031
|
}
|
|
4032
4032
|
const i = this.state.skippedKeys[t.pubkey];
|
|
4033
4033
|
if (i != null && i.headerKeys)
|
|
4034
4034
|
for (const s of i.headerKeys)
|
|
4035
4035
|
try {
|
|
4036
|
-
return [JSON.parse(
|
|
4036
|
+
return [JSON.parse(q.decrypt(n, s)), !1, !0];
|
|
4037
4037
|
} catch {
|
|
4038
4038
|
}
|
|
4039
4039
|
throw new Error("Failed to decrypt header with current and skipped header keys");
|
|
@@ -4050,7 +4050,7 @@ class ot {
|
|
|
4050
4050
|
else if (!((r = this.state.skippedKeys[t.pubkey]) != null && r.messageKeys[i.number]))
|
|
4051
4051
|
return;
|
|
4052
4052
|
const c = this.ratchetDecrypt(i, t.content, t.pubkey), a = JSON.parse(c);
|
|
4053
|
-
if (!pt(a) || a.id !==
|
|
4053
|
+
if (!pt(a) || a.id !== De(a))
|
|
4054
4054
|
return;
|
|
4055
4055
|
this.internalSubscriptions.forEach((l) => l(a, t));
|
|
4056
4056
|
} catch (i) {
|
|
@@ -4079,7 +4079,7 @@ new TextDecoder("utf-8");
|
|
|
4079
4079
|
new TextEncoder();
|
|
4080
4080
|
function Qe(e, t) {
|
|
4081
4081
|
const n = _e.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
4082
|
-
return
|
|
4082
|
+
return rn(fe, n, "nip44-v2");
|
|
4083
4083
|
}
|
|
4084
4084
|
const cu = 2 * 24 * 60 * 60, uu = () => Math.round(Date.now() / 1e3), lu = () => Math.round(uu() - Math.random() * cu);
|
|
4085
4085
|
class Pe {
|
|
@@ -4154,11 +4154,15 @@ class Pe {
|
|
|
4154
4154
|
}
|
|
4155
4155
|
static fromUser(t, n, r) {
|
|
4156
4156
|
const i = {
|
|
4157
|
-
kinds: [
|
|
4157
|
+
kinds: [Lt],
|
|
4158
4158
|
authors: [t],
|
|
4159
4159
|
"#l": ["double-ratchet/invites"]
|
|
4160
4160
|
}, s = /* @__PURE__ */ new Set();
|
|
4161
4161
|
return n(i, (c) => {
|
|
4162
|
+
if (c.pubkey !== t) {
|
|
4163
|
+
console.error("Got invite event from wrong user", c.pubkey, "expected", t);
|
|
4164
|
+
return;
|
|
4165
|
+
}
|
|
4162
4166
|
if (!s.has(c.id)) {
|
|
4163
4167
|
s.add(c.id);
|
|
4164
4168
|
try {
|
|
@@ -4198,7 +4202,7 @@ class Pe {
|
|
|
4198
4202
|
if (!this.deviceId)
|
|
4199
4203
|
throw new Error("Device ID is required");
|
|
4200
4204
|
return {
|
|
4201
|
-
kind:
|
|
4205
|
+
kind: Lt,
|
|
4202
4206
|
pubkey: this.inviter,
|
|
4203
4207
|
content: "",
|
|
4204
4208
|
created_at: Math.floor(Date.now() / 1e3),
|
|
@@ -4210,6 +4214,27 @@ class Pe {
|
|
|
4210
4214
|
]
|
|
4211
4215
|
};
|
|
4212
4216
|
}
|
|
4217
|
+
/**
|
|
4218
|
+
* Creates an "invite tombstone" event that clears the original content and removes the list tag.
|
|
4219
|
+
* Used when the inviter logs out and wants to make the invite invisible to other devices.
|
|
4220
|
+
*/
|
|
4221
|
+
getDeletionEvent() {
|
|
4222
|
+
if (!this.deviceId)
|
|
4223
|
+
throw new Error("Device ID is required");
|
|
4224
|
+
return {
|
|
4225
|
+
kind: Lt,
|
|
4226
|
+
pubkey: this.inviter,
|
|
4227
|
+
content: "",
|
|
4228
|
+
// deliberately empty
|
|
4229
|
+
created_at: Math.floor(Date.now() / 1e3),
|
|
4230
|
+
tags: [
|
|
4231
|
+
["ephemeralKey", this.inviterEphemeralPublicKey],
|
|
4232
|
+
["sharedSecret", this.sharedSecret],
|
|
4233
|
+
["d", "double-ratchet/invites/" + this.deviceId]
|
|
4234
|
+
// same d tag
|
|
4235
|
+
]
|
|
4236
|
+
};
|
|
4237
|
+
}
|
|
4213
4238
|
/**
|
|
4214
4239
|
* Called by the invitee. Accepts the invite and creates a new session with the inviter.
|
|
4215
4240
|
*
|
|
@@ -4227,14 +4252,14 @@ class Pe {
|
|
|
4227
4252
|
* so the inviter can create the session on their side.
|
|
4228
4253
|
*/
|
|
4229
4254
|
async accept(t, n, r) {
|
|
4230
|
-
const i = ke(), s = ae(i), o = this.inviter || this.inviterEphemeralPublicKey, c = j(this.sharedSecret), a = ot.init(t, this.inviterEphemeralPublicKey, i, !0, c, void 0), f = await (typeof r == "function" ? r : (d, y) => Promise.resolve(
|
|
4255
|
+
const i = ke(), s = ae(i), o = this.inviter || this.inviterEphemeralPublicKey, c = j(this.sharedSecret), a = ot.init(t, this.inviterEphemeralPublicKey, i, !0, c, void 0), f = await (typeof r == "function" ? r : (d, y) => Promise.resolve(q.encrypt(d, Qe(r, y))))(s, o), u = {
|
|
4231
4256
|
pubkey: n,
|
|
4232
|
-
content: await
|
|
4257
|
+
content: await q.encrypt(f, c),
|
|
4233
4258
|
created_at: Math.floor(Date.now() / 1e3)
|
|
4234
4259
|
}, p = JSON.stringify(u), w = ke(), g = ae(w), h = {
|
|
4235
4260
|
kind: Zn,
|
|
4236
4261
|
pubkey: g,
|
|
4237
|
-
content:
|
|
4262
|
+
content: q.encrypt(p, Qe(w, this.inviterEphemeralPublicKey)),
|
|
4238
4263
|
created_at: lu(),
|
|
4239
4264
|
tags: [["p", this.inviterEphemeralPublicKey]]
|
|
4240
4265
|
};
|
|
@@ -4251,9 +4276,9 @@ class Pe {
|
|
|
4251
4276
|
try {
|
|
4252
4277
|
if (this.maxUses && this.usedBy.length >= this.maxUses)
|
|
4253
4278
|
return;
|
|
4254
|
-
const o = await
|
|
4279
|
+
const o = await q.decrypt(s.content, Qe(this.inviterEphemeralPrivateKey, s.pubkey)), c = JSON.parse(o), a = j(this.sharedSecret), l = c.pubkey;
|
|
4255
4280
|
this.usedBy.push(l);
|
|
4256
|
-
const f = await
|
|
4281
|
+
const f = await q.decrypt(c.content, a), p = await (typeof t == "function" ? t : (h, d) => Promise.resolve(q.decrypt(h, Qe(t, d))))(f, l), w = s.id, g = ot.init(n, p, this.inviterEphemeralPrivateKey, !1, a, w);
|
|
4257
4282
|
r(g, l);
|
|
4258
4283
|
} catch {
|
|
4259
4284
|
}
|
|
@@ -4262,7 +4287,7 @@ class Pe {
|
|
|
4262
4287
|
}
|
|
4263
4288
|
export {
|
|
4264
4289
|
iu as CHAT_MESSAGE_KIND,
|
|
4265
|
-
|
|
4290
|
+
Lt as INVITE_EVENT_KIND,
|
|
4266
4291
|
Zn as INVITE_RESPONSE_KIND,
|
|
4267
4292
|
Pe as Invite,
|
|
4268
4293
|
wu as MAX_SKIP,
|