nostr-double-ratchet 0.0.32 → 0.0.34
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 +9 -3
- package/dist/Invite.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 +563 -535
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/package.json +4 -4
- package/src/Invite.ts +47 -5
- package/src/UserRecord.ts +235 -146
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var J = (e, t, n) =>
|
|
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
4
|
function Bn(e) {
|
|
5
5
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
6
6
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
@@ -30,20 +30,20 @@ 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
|
-
function
|
|
36
|
+
function ki(e) {
|
|
37
37
|
if (typeof e != "string")
|
|
38
38
|
throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
|
|
39
39
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
if (typeof e == "string" && (e =
|
|
41
|
+
function Vt(e) {
|
|
42
|
+
if (typeof e == "string" && (e = ki(e)), !Gn(e))
|
|
43
43
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
44
44
|
return e;
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function Bi(...e) {
|
|
47
47
|
const t = new Uint8Array(e.reduce((r, i) => r + i.length, 0));
|
|
48
48
|
let n = 0;
|
|
49
49
|
return e.forEach((r) => {
|
|
@@ -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();
|
|
@@ -214,12 +214,12 @@ let Ti = class extends Ui {
|
|
|
214
214
|
for (let u = 0; u < 16; u++, n += 4)
|
|
215
215
|
ve[u] = t.getUint32(n, !1);
|
|
216
216
|
for (let u = 16; u < 64; u++) {
|
|
217
|
-
const
|
|
217
|
+
const y = ve[u - 15], w = ve[u - 2], g = re(y, 7) ^ re(y, 18) ^ y >>> 3, h = re(w, 17) ^ re(w, 19) ^ w >>> 10;
|
|
218
218
|
ve[u] = h + ve[u - 7] + g + ve[u - 16] | 0;
|
|
219
219
|
}
|
|
220
220
|
let { A: r, B: i, C: s, D: o, E: c, F: a, G: l, H: f } = this;
|
|
221
221
|
for (let u = 0; u < 64; u++) {
|
|
222
|
-
const
|
|
222
|
+
const y = re(c, 6) ^ re(c, 11) ^ re(c, 25), w = f + y + Li(c, a, l) + Ri[u] + ve[u] | 0, h = (re(r, 2) ^ re(r, 13) ^ re(r, 22)) + $i(r, i, s) | 0;
|
|
223
223
|
f = l, l = a, a = c, c = o + w | 0, o = s, s = i, i = r, r = w + h | 0;
|
|
224
224
|
}
|
|
225
225
|
r = r + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, l = l + this.G | 0, f = f + this.H | 0, this.set(r, i, s, o, c, a, l, f);
|
|
@@ -231,10 +231,10 @@ let 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,27 +339,27 @@ 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");
|
|
350
350
|
let u = 0;
|
|
351
|
-
const
|
|
351
|
+
const y = [];
|
|
352
352
|
for (; u < t; ) {
|
|
353
353
|
r = c();
|
|
354
354
|
const w = r.slice();
|
|
355
|
-
|
|
355
|
+
y.push(w), u += r.length;
|
|
356
356
|
}
|
|
357
|
-
return Ie(...
|
|
357
|
+
return Ie(...y);
|
|
358
358
|
};
|
|
359
|
-
return (u,
|
|
359
|
+
return (u, y) => {
|
|
360
360
|
o(), a(u);
|
|
361
361
|
let w;
|
|
362
|
-
for (; !(w =
|
|
362
|
+
for (; !(w = y(l())); )
|
|
363
363
|
a();
|
|
364
364
|
return o(), w;
|
|
365
365
|
};
|
|
@@ -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))
|
|
@@ -468,22 +468,22 @@ function Gi(e) {
|
|
|
468
468
|
return function(c, a) {
|
|
469
469
|
if (c.pow(a, t) === c.neg(c.ONE))
|
|
470
470
|
throw new Error("Cannot find square root");
|
|
471
|
-
let l = r, f = c.pow(c.mul(c.ONE, i), n), u = c.pow(a, s),
|
|
472
|
-
for (; !c.eql(
|
|
473
|
-
if (c.eql(
|
|
471
|
+
let l = r, f = c.pow(c.mul(c.ONE, i), n), u = c.pow(a, s), y = c.pow(a, n);
|
|
472
|
+
for (; !c.eql(y, c.ONE); ) {
|
|
473
|
+
if (c.eql(y, c.ZERO))
|
|
474
474
|
return c.ZERO;
|
|
475
475
|
let w = 1;
|
|
476
|
-
for (let h = c.sqr(
|
|
476
|
+
for (let h = c.sqr(y); w < l && !c.eql(h, c.ONE); w++)
|
|
477
477
|
h = c.sqr(h);
|
|
478
478
|
const g = c.pow(f, z << BigInt(l - w - 1));
|
|
479
|
-
f = c.sqr(g), u = c.mul(u, g),
|
|
479
|
+
f = c.sqr(g), u = c.mul(u, g), y = c.mul(y, f), l = w;
|
|
480
480
|
}
|
|
481
481
|
return u;
|
|
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);
|
|
@@ -650,7 +650,7 @@ function is(e, t) {
|
|
|
650
650
|
let l = i, f = l;
|
|
651
651
|
for (let u = 0; u < o; u++) {
|
|
652
652
|
f = l, a.push(f);
|
|
653
|
-
for (let
|
|
653
|
+
for (let y = 1; y < c; y++)
|
|
654
654
|
f = f.add(l), a.push(f);
|
|
655
655
|
l = f.double();
|
|
656
656
|
}
|
|
@@ -666,13 +666,13 @@ function is(e, t) {
|
|
|
666
666
|
wNAF(i, s, o) {
|
|
667
667
|
const { windows: c, windowSize: a } = r(i);
|
|
668
668
|
let l = e.ZERO, f = e.BASE;
|
|
669
|
-
const u = BigInt(2 ** i - 1),
|
|
669
|
+
const u = BigInt(2 ** i - 1), y = 2 ** i, w = BigInt(i);
|
|
670
670
|
for (let g = 0; g < c; g++) {
|
|
671
671
|
const h = g * a;
|
|
672
672
|
let d = Number(o & u);
|
|
673
|
-
o >>= w, d > a && (d -=
|
|
674
|
-
const
|
|
675
|
-
d === 0 ? f = f.add(n(S, s[
|
|
673
|
+
o >>= w, d > a && (d -= y, o += St);
|
|
674
|
+
const p = h, m = h + Math.abs(d) - 1, S = g % 2 !== 0, _ = d < 0;
|
|
675
|
+
d === 0 ? f = f.add(n(S, s[p])) : l = l.add(n(_, s[m]));
|
|
676
676
|
}
|
|
677
677
|
return { p: l, f };
|
|
678
678
|
},
|
|
@@ -722,7 +722,7 @@ function ss(e) {
|
|
|
722
722
|
}
|
|
723
723
|
return Object.freeze({ ...t });
|
|
724
724
|
}
|
|
725
|
-
const { bytesToNumberBE: os, hexToBytes: as } = Vi,
|
|
725
|
+
const { bytesToNumberBE: os, hexToBytes: as } = Vi, ke = {
|
|
726
726
|
// asn.1 DER encoding utils
|
|
727
727
|
Err: class extends Error {
|
|
728
728
|
constructor(t = "") {
|
|
@@ -730,7 +730,7 @@ const { bytesToNumberBE: os, hexToBytes: as } = Vi, Be = {
|
|
|
730
730
|
}
|
|
731
731
|
},
|
|
732
732
|
_parseInt(e) {
|
|
733
|
-
const { Err: t } =
|
|
733
|
+
const { Err: t } = ke;
|
|
734
734
|
if (e.length < 2 || e[0] !== 2)
|
|
735
735
|
throw new t("Invalid signature integer tag");
|
|
736
736
|
const n = e[1], r = e.subarray(2, n + 2);
|
|
@@ -743,7 +743,7 @@ const { bytesToNumberBE: os, hexToBytes: as } = Vi, Be = {
|
|
|
743
743
|
return { d: os(r), l: e.subarray(n + 2) };
|
|
744
744
|
},
|
|
745
745
|
toSig(e) {
|
|
746
|
-
const { Err: t } =
|
|
746
|
+
const { Err: t } = ke, n = typeof e == "string" ? as(e) : e;
|
|
747
747
|
if (!(n instanceof Uint8Array))
|
|
748
748
|
throw new Error("ui8a expected");
|
|
749
749
|
let r = n.length;
|
|
@@ -751,7 +751,7 @@ const { bytesToNumberBE: os, hexToBytes: as } = Vi, Be = {
|
|
|
751
751
|
throw new t("Invalid signature tag");
|
|
752
752
|
if (n[1] !== r - 2)
|
|
753
753
|
throw new t("Invalid signature: incorrect length");
|
|
754
|
-
const { d: i, l: s } =
|
|
754
|
+
const { d: i, l: s } = ke._parseInt(n.subarray(2)), { d: o, l: c } = ke._parseInt(s);
|
|
755
755
|
if (c.length)
|
|
756
756
|
throw new t("Invalid signature: left bytes after parsing");
|
|
757
757
|
return { r: i, s: o };
|
|
@@ -765,19 +765,19 @@ 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) => {
|
|
772
|
-
const
|
|
773
|
-
return Ie(Uint8Array.from([4]), n.toBytes(
|
|
772
|
+
const p = h.toAffine();
|
|
773
|
+
return Ie(Uint8Array.from([4]), n.toBytes(p.x), n.toBytes(p.y));
|
|
774
774
|
}), i = t.fromBytes || ((g) => {
|
|
775
|
-
const h = g.subarray(1), d = n.fromBytes(h.subarray(0, n.BYTES)),
|
|
776
|
-
return { x: d, y };
|
|
775
|
+
const h = g.subarray(1), d = n.fromBytes(h.subarray(0, n.BYTES)), p = n.fromBytes(h.subarray(n.BYTES, 2 * n.BYTES));
|
|
776
|
+
return { x: d, y: p };
|
|
777
777
|
});
|
|
778
778
|
function s(g) {
|
|
779
|
-
const { a: h, b: d } = t,
|
|
780
|
-
return n.add(n.add(
|
|
779
|
+
const { a: h, b: d } = t, p = n.sqr(g), m = n.mul(p, g);
|
|
780
|
+
return n.add(n.add(m, n.mul(g, h)), d);
|
|
781
781
|
}
|
|
782
782
|
if (!n.eql(n.sqr(t.Gy), s(t.Gx)))
|
|
783
783
|
throw new Error("bad generator point: equation left != right");
|
|
@@ -789,9 +789,9 @@ function cs(e) {
|
|
|
789
789
|
throw new Error("Expected valid bigint: 0 < bigint < curve.n");
|
|
790
790
|
}
|
|
791
791
|
function a(g) {
|
|
792
|
-
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey:
|
|
792
|
+
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey: p, n: m } = 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
|
}
|
|
@@ -801,7 +801,7 @@ function cs(e) {
|
|
|
801
801
|
} catch {
|
|
802
802
|
throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof g}`);
|
|
803
803
|
}
|
|
804
|
-
return
|
|
804
|
+
return p && (S = V(S, m)), c(S), S;
|
|
805
805
|
}
|
|
806
806
|
const l = /* @__PURE__ */ new Map();
|
|
807
807
|
function f(g) {
|
|
@@ -809,24 +809,24 @@ function cs(e) {
|
|
|
809
809
|
throw new Error("ProjectivePoint expected");
|
|
810
810
|
}
|
|
811
811
|
class u {
|
|
812
|
-
constructor(h, d,
|
|
813
|
-
if (this.px = h, this.py = d, this.pz =
|
|
812
|
+
constructor(h, d, p) {
|
|
813
|
+
if (this.px = h, this.py = d, this.pz = p, h == null || !n.isValid(h))
|
|
814
814
|
throw new Error("x required");
|
|
815
815
|
if (d == null || !n.isValid(d))
|
|
816
816
|
throw new Error("y required");
|
|
817
|
-
if (
|
|
817
|
+
if (p == null || !n.isValid(p))
|
|
818
818
|
throw new Error("z required");
|
|
819
819
|
}
|
|
820
820
|
// Does not validate if the point is on-curve.
|
|
821
821
|
// Use fromHex instead, or call assertValidity() later.
|
|
822
822
|
static fromAffine(h) {
|
|
823
|
-
const { x: d, y } = h || {};
|
|
824
|
-
if (!h || !n.isValid(d) || !n.isValid(
|
|
823
|
+
const { x: d, y: p } = h || {};
|
|
824
|
+
if (!h || !n.isValid(d) || !n.isValid(p))
|
|
825
825
|
throw new Error("invalid affine point");
|
|
826
826
|
if (h instanceof u)
|
|
827
827
|
throw new Error("projective point not allowed");
|
|
828
|
-
const
|
|
829
|
-
return
|
|
828
|
+
const m = (S) => n.eql(S, n.ZERO);
|
|
829
|
+
return m(d) && m(p) ? u.ZERO : new u(d, p, n.ONE);
|
|
830
830
|
}
|
|
831
831
|
get x() {
|
|
832
832
|
return this.toAffine().x;
|
|
@@ -841,8 +841,8 @@ function cs(e) {
|
|
|
841
841
|
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
842
842
|
*/
|
|
843
843
|
static normalizeZ(h) {
|
|
844
|
-
const d = n.invertBatch(h.map((
|
|
845
|
-
return h.map((
|
|
844
|
+
const d = n.invertBatch(h.map((p) => p.pz));
|
|
845
|
+
return h.map((p, m) => p.toAffine(d[m])).map(u.fromAffine);
|
|
846
846
|
}
|
|
847
847
|
/**
|
|
848
848
|
* Converts hash string or Uint8Array to Point.
|
|
@@ -870,8 +870,8 @@ function cs(e) {
|
|
|
870
870
|
const { x: h, y: d } = this.toAffine();
|
|
871
871
|
if (!n.isValid(h) || !n.isValid(d))
|
|
872
872
|
throw new Error("bad point: x or y not FE");
|
|
873
|
-
const
|
|
874
|
-
if (!n.eql(
|
|
873
|
+
const p = n.sqr(d), m = s(h);
|
|
874
|
+
if (!n.eql(p, m))
|
|
875
875
|
throw new Error("bad point: equation left != right");
|
|
876
876
|
if (!this.isTorsionFree())
|
|
877
877
|
throw new Error("bad point: not in prime-order subgroup");
|
|
@@ -887,8 +887,8 @@ function cs(e) {
|
|
|
887
887
|
*/
|
|
888
888
|
equals(h) {
|
|
889
889
|
f(h);
|
|
890
|
-
const { px: d, py:
|
|
891
|
-
return
|
|
890
|
+
const { px: d, py: p, pz: m } = this, { px: S, py: _, pz: k } = h, E = n.eql(n.mul(d, k), n.mul(S, m)), x = n.eql(n.mul(p, k), n.mul(_, m));
|
|
891
|
+
return E && x;
|
|
892
892
|
}
|
|
893
893
|
/**
|
|
894
894
|
* Flips point to one corresponding to (x, -y) in Affine coordinates.
|
|
@@ -901,9 +901,9 @@ function cs(e) {
|
|
|
901
901
|
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
902
902
|
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
903
903
|
double() {
|
|
904
|
-
const { a: h, b: d } = t,
|
|
905
|
-
let
|
|
906
|
-
return A = n.add(A, A), x = n.mul(
|
|
904
|
+
const { a: h, b: d } = t, p = n.mul(d, Ln), { px: m, py: S, pz: _ } = this;
|
|
905
|
+
let k = n.ZERO, E = n.ZERO, x = n.ZERO, K = n.mul(m, m), M = n.mul(S, S), I = n.mul(_, _), A = n.mul(m, S);
|
|
906
|
+
return A = n.add(A, A), x = n.mul(m, _), x = n.add(x, x), k = n.mul(h, x), E = n.mul(p, I), E = n.add(k, E), k = n.sub(M, E), E = n.add(M, E), E = n.mul(k, E), k = n.mul(A, k), x = n.mul(p, x), I = n.mul(h, I), A = n.sub(K, I), A = n.mul(h, A), A = n.add(A, x), x = n.add(K, K), K = n.add(x, K), K = n.add(K, I), K = n.mul(K, A), E = n.add(E, K), I = n.mul(S, _), I = n.add(I, I), K = n.mul(I, A), k = n.sub(k, K), x = n.mul(I, M), x = n.add(x, x), x = n.add(x, x), new u(k, E, x);
|
|
907
907
|
}
|
|
908
908
|
// Renes-Costello-Batina exception-free addition formula.
|
|
909
909
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
@@ -911,13 +911,13 @@ function cs(e) {
|
|
|
911
911
|
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
912
912
|
add(h) {
|
|
913
913
|
f(h);
|
|
914
|
-
const { px: d, py:
|
|
915
|
-
let
|
|
916
|
-
const M = t.a, I = n.mul(t.b,
|
|
917
|
-
let A = n.mul(d, S), R = n.mul(
|
|
918
|
-
|
|
919
|
-
let v = n.add(S,
|
|
920
|
-
return b = n.mul(b, v), v = n.add(A, T), b = n.sub(b, v), v = n.add(
|
|
914
|
+
const { px: d, py: p, pz: m } = this, { px: S, py: _, pz: k } = h;
|
|
915
|
+
let E = 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(p, _), T = n.mul(m, k), D = n.add(d, p), b = n.add(S, _);
|
|
918
|
+
D = n.mul(D, b), b = n.add(A, R), D = n.sub(D, b), b = n.add(d, m);
|
|
919
|
+
let v = n.add(S, k);
|
|
920
|
+
return b = n.mul(b, v), v = n.add(A, T), b = n.sub(b, v), v = n.add(p, m), E = n.add(_, k), v = n.mul(v, E), E = n.add(R, T), v = n.sub(v, E), K = n.mul(M, b), E = n.mul(I, T), K = n.add(E, K), E = n.sub(R, K), K = n.add(R, K), x = n.mul(E, K), R = n.add(A, A), R = n.add(R, A), T = n.mul(M, T), b = n.mul(I, b), R = n.add(R, T), T = n.sub(A, T), T = n.mul(M, T), b = n.add(b, T), A = n.mul(R, b), x = n.add(x, A), A = n.mul(v, b), E = n.mul(D, E), E = n.sub(E, A), A = n.mul(D, R), K = n.mul(v, K), K = n.add(K, A), new u(E, x, K);
|
|
921
921
|
}
|
|
922
922
|
subtract(h) {
|
|
923
923
|
return this.add(h.negate());
|
|
@@ -927,8 +927,8 @@ function cs(e) {
|
|
|
927
927
|
}
|
|
928
928
|
wNAF(h) {
|
|
929
929
|
return w.wNAFCached(this, l, h, (d) => {
|
|
930
|
-
const
|
|
931
|
-
return d.map((
|
|
930
|
+
const p = n.invertBatch(d.map((m) => m.pz));
|
|
931
|
+
return d.map((m, S) => m.toAffine(p[S])).map(u.fromAffine);
|
|
932
932
|
});
|
|
933
933
|
}
|
|
934
934
|
/**
|
|
@@ -942,13 +942,13 @@ function cs(e) {
|
|
|
942
942
|
return d;
|
|
943
943
|
if (c(h), h === X)
|
|
944
944
|
return this;
|
|
945
|
-
const { endo:
|
|
946
|
-
if (!
|
|
945
|
+
const { endo: p } = t;
|
|
946
|
+
if (!p)
|
|
947
947
|
return w.unsafeLadder(this, h);
|
|
948
|
-
let { k1neg:
|
|
949
|
-
for (; S > ce ||
|
|
950
|
-
S & X && (
|
|
951
|
-
return
|
|
948
|
+
let { k1neg: m, k1: S, k2neg: _, k2: k } = p.splitScalar(h), E = d, x = d, K = this;
|
|
949
|
+
for (; S > ce || k > ce; )
|
|
950
|
+
S & X && (E = E.add(K)), k & X && (x = x.add(K)), K = K.double(), S >>= X, k >>= X;
|
|
951
|
+
return m && (E = E.negate()), _ && (x = x.negate()), x = new u(n.mul(x.px, p.beta), x.py, x.pz), E.add(x);
|
|
952
952
|
}
|
|
953
953
|
/**
|
|
954
954
|
* Constant time multiplication.
|
|
@@ -961,17 +961,17 @@ function cs(e) {
|
|
|
961
961
|
*/
|
|
962
962
|
multiply(h) {
|
|
963
963
|
c(h);
|
|
964
|
-
let d = h,
|
|
964
|
+
let d = h, p, m;
|
|
965
965
|
const { endo: S } = t;
|
|
966
966
|
if (S) {
|
|
967
|
-
const { k1neg: _, k1:
|
|
968
|
-
let { p:
|
|
969
|
-
|
|
967
|
+
const { k1neg: _, k1: k, k2neg: E, k2: x } = S.splitScalar(d);
|
|
968
|
+
let { p: K, f: M } = this.wNAF(k), { p: I, f: A } = this.wNAF(x);
|
|
969
|
+
K = w.constTimeNegate(_, K), I = w.constTimeNegate(E, I), I = new u(n.mul(I.px, S.beta), I.py, I.pz), p = K.add(I), m = M.add(A);
|
|
970
970
|
} else {
|
|
971
|
-
const { p: _, f:
|
|
972
|
-
|
|
971
|
+
const { p: _, f: k } = this.wNAF(d);
|
|
972
|
+
p = _, m = k;
|
|
973
973
|
}
|
|
974
|
-
return u.normalizeZ([
|
|
974
|
+
return u.normalizeZ([p, m])[0];
|
|
975
975
|
}
|
|
976
976
|
/**
|
|
977
977
|
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
@@ -979,22 +979,22 @@ function cs(e) {
|
|
|
979
979
|
* The trick could be useful if both P and Q are not G (not in our case).
|
|
980
980
|
* @returns non-zero affine point
|
|
981
981
|
*/
|
|
982
|
-
multiplyAndAddUnsafe(h, d,
|
|
983
|
-
const
|
|
982
|
+
multiplyAndAddUnsafe(h, d, p) {
|
|
983
|
+
const m = u.BASE, S = (k, E) => E === ce || E === X || !k.equals(m) ? k.multiplyUnsafe(E) : k.multiply(E), _ = S(this, d).add(S(h, p));
|
|
984
984
|
return _.is0() ? void 0 : _;
|
|
985
985
|
}
|
|
986
986
|
// Converts Projective point to affine (x, y) coordinates.
|
|
987
987
|
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
988
988
|
// (x, y, z) ∋ (x=x/z, y=y/z)
|
|
989
989
|
toAffine(h) {
|
|
990
|
-
const { px: d, py:
|
|
991
|
-
h == null && (h = S ? n.ONE : n.inv(
|
|
992
|
-
const _ = n.mul(d, h),
|
|
990
|
+
const { px: d, py: p, pz: m } = this, S = this.is0();
|
|
991
|
+
h == null && (h = S ? n.ONE : n.inv(m));
|
|
992
|
+
const _ = n.mul(d, h), k = n.mul(p, h), E = n.mul(m, h);
|
|
993
993
|
if (S)
|
|
994
994
|
return { x: n.ZERO, y: n.ZERO };
|
|
995
|
-
if (!n.eql(
|
|
995
|
+
if (!n.eql(E, n.ONE))
|
|
996
996
|
throw new Error("invZ was invalid");
|
|
997
|
-
return { x: _, y:
|
|
997
|
+
return { x: _, y: k };
|
|
998
998
|
}
|
|
999
999
|
isTorsionFree() {
|
|
1000
1000
|
const { h, isTorsionFree: d } = t;
|
|
@@ -1012,11 +1012,11 @@ 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);
|
|
1019
|
-
const
|
|
1019
|
+
const y = t.nBitLength, w = is(u, t.endo ? Math.ceil(y / 2) : y);
|
|
1020
1020
|
return {
|
|
1021
1021
|
CURVE: t,
|
|
1022
1022
|
ProjectivePoint: u,
|
|
@@ -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
|
-
const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder:
|
|
1051
|
+
const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: y } = cs({
|
|
1052
1052
|
...t,
|
|
1053
|
-
toBytes(b, v,
|
|
1054
|
-
const
|
|
1055
|
-
return
|
|
1053
|
+
toBytes(b, v, N) {
|
|
1054
|
+
const B = v.toAffine(), C = n.toBytes(B.x), U = Ie;
|
|
1055
|
+
return N ? U(Uint8Array.from([v.hasEvenY() ? 2 : 3]), C) : U(Uint8Array.from([4]), C, n.toBytes(B.y));
|
|
1056
1056
|
},
|
|
1057
1057
|
fromBytes(b) {
|
|
1058
|
-
const v = b.length,
|
|
1059
|
-
if (v === i && (
|
|
1060
|
-
const C = G(
|
|
1058
|
+
const v = b.length, N = b[0], B = b.subarray(1);
|
|
1059
|
+
if (v === i && (N === 2 || N === 3)) {
|
|
1060
|
+
const C = G(B);
|
|
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 &&
|
|
1068
|
-
const C = n.fromBytes(
|
|
1066
|
+
return (N & 1) === 1 !== $ && (O = n.neg(O)), { x: C, y: O };
|
|
1067
|
+
} else if (v === s && N === 4) {
|
|
1068
|
+
const C = n.fromBytes(B.subarray(0, n.BYTES)), U = n.fromBytes(B.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,39 +1078,39 @@ function ls(e) {
|
|
|
1078
1078
|
function h(b) {
|
|
1079
1079
|
return g(b) ? c(-b) : b;
|
|
1080
1080
|
}
|
|
1081
|
-
const d = (b, v,
|
|
1082
|
-
class
|
|
1083
|
-
constructor(v,
|
|
1084
|
-
this.r = v, this.s =
|
|
1081
|
+
const d = (b, v, N) => G(b.slice(v, N));
|
|
1082
|
+
class p {
|
|
1083
|
+
constructor(v, N, B) {
|
|
1084
|
+
this.r = v, this.s = N, this.recovery = B, this.assertValidity();
|
|
1085
1085
|
}
|
|
1086
1086
|
// pair (bytes of r, bytes of s)
|
|
1087
1087
|
static fromCompact(v) {
|
|
1088
|
-
const
|
|
1089
|
-
return v = Z("compactSignature", v,
|
|
1088
|
+
const N = t.nByteLength;
|
|
1089
|
+
return v = Z("compactSignature", v, N * 2), new p(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
|
|
1094
|
+
const { r: N, s: B } = ke.toSig(Z("DER", v));
|
|
1095
|
+
return new p(N, B);
|
|
1096
1096
|
}
|
|
1097
1097
|
assertValidity() {
|
|
1098
|
-
if (!
|
|
1098
|
+
if (!y(this.r))
|
|
1099
1099
|
throw new Error("r must be 0 < r < CURVE.n");
|
|
1100
|
-
if (!
|
|
1100
|
+
if (!y(this.s))
|
|
1101
1101
|
throw new Error("s must be 0 < s < CURVE.n");
|
|
1102
1102
|
}
|
|
1103
1103
|
addRecoveryBit(v) {
|
|
1104
|
-
return new
|
|
1104
|
+
return new p(this.r, this.s, v);
|
|
1105
1105
|
}
|
|
1106
1106
|
recoverPublicKey(v) {
|
|
1107
|
-
const { r:
|
|
1107
|
+
const { r: N, s: B, 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
|
-
const $ = (C & 1) === 0 ? "02" : "03", ee = l.fromHex($ + w(O)), ge = a(O), Ue = c(-U * ge), Ve = c(
|
|
1113
|
+
const $ = (C & 1) === 0 ? "02" : "03", ee = l.fromHex($ + w(O)), ge = a(O), Ue = c(-U * ge), Ve = c(B * ge), we = l.BASE.multiplyAndAddUnsafe(ee, Ue, Ve);
|
|
1114
1114
|
if (!we)
|
|
1115
1115
|
throw new Error("point at infinify");
|
|
1116
1116
|
return we.assertValidity(), we;
|
|
@@ -1120,14 +1120,14 @@ function ls(e) {
|
|
|
1120
1120
|
return g(this.s);
|
|
1121
1121
|
}
|
|
1122
1122
|
normalizeS() {
|
|
1123
|
-
return this.hasHighS() ? new
|
|
1123
|
+
return this.hasHighS() ? new p(this.r, c(-this.s), this.recovery) : this;
|
|
1124
1124
|
}
|
|
1125
1125
|
// DER-encoded
|
|
1126
1126
|
toDERRawBytes() {
|
|
1127
1127
|
return je(this.toDERHex());
|
|
1128
1128
|
}
|
|
1129
1129
|
toDERHex() {
|
|
1130
|
-
return
|
|
1130
|
+
return ke.hexFromSig({ r: this.r, s: this.s });
|
|
1131
1131
|
}
|
|
1132
1132
|
// padded bytes of r, then padded bytes of s
|
|
1133
1133
|
toCompactRawBytes() {
|
|
@@ -1137,7 +1137,7 @@ function ls(e) {
|
|
|
1137
1137
|
return w(this.r) + w(this.s);
|
|
1138
1138
|
}
|
|
1139
1139
|
}
|
|
1140
|
-
const
|
|
1140
|
+
const m = {
|
|
1141
1141
|
isValidPrivateKey(b) {
|
|
1142
1142
|
try {
|
|
1143
1143
|
return f(b), !0;
|
|
@@ -1170,35 +1170,35 @@ 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 ?
|
|
1173
|
+
const v = b instanceof Uint8Array, N = typeof b == "string", B = (v || N) && b.length;
|
|
1174
|
+
return v ? B === i || B === s : N ? B === 2 * i || B === 2 * s : b instanceof l;
|
|
1175
1175
|
}
|
|
1176
|
-
function
|
|
1176
|
+
function k(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
|
-
const
|
|
1184
|
-
const v = G(b),
|
|
1185
|
-
return
|
|
1183
|
+
const E = t.bits2int || function(b) {
|
|
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
|
-
return c(
|
|
1188
|
-
},
|
|
1187
|
+
return c(E(b));
|
|
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
|
-
const { hash:
|
|
1200
|
-
let { lowS: U, prehash: O, extraEntropy: $ } =
|
|
1201
|
-
U == null && (U = !0), b = Z("msgHash", b), O && (b = Z("prehashed msgHash",
|
|
1199
|
+
const { hash: B, randomBytes: C } = t;
|
|
1200
|
+
let { lowS: U, prehash: O, extraEntropy: $ } = N;
|
|
1201
|
+
U == null && (U = !0), b = Z("msgHash", b), O && (b = Z("prehashed msgHash", B(b)));
|
|
1202
1202
|
const ee = x(b), ge = f(v), Ue = [M(ge), M(ee)];
|
|
1203
1203
|
if ($ != null) {
|
|
1204
1204
|
const Ae = $ === !0 ? C(n.BYTES) : $;
|
|
@@ -1206,48 +1206,48 @@ function ls(e) {
|
|
|
1206
1206
|
}
|
|
1207
1207
|
const Ve = Ie(...Ue), we = ee;
|
|
1208
1208
|
function Et(Ae) {
|
|
1209
|
-
const Le =
|
|
1210
|
-
if (!
|
|
1209
|
+
const Le = E(Ae);
|
|
1210
|
+
if (!y(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), kn = Re;
|
|
1219
|
+
return U && g(Re) && (kn = h(Re), Cn ^= 1), new p(te, kn, Cn);
|
|
1220
1220
|
}
|
|
1221
1221
|
return { seed: Ve, k2sig: Et };
|
|
1222
1222
|
}
|
|
1223
1223
|
const A = { lowS: t.lowS, prehash: !1 }, R = { lowS: t.lowS, prehash: !1 };
|
|
1224
|
-
function T(b, v,
|
|
1225
|
-
const { seed:
|
|
1226
|
-
return er(U.hash.outputLen, U.nByteLength, U.hmac)(
|
|
1224
|
+
function T(b, v, N = A) {
|
|
1225
|
+
const { seed: B, k2sig: C } = I(b, v, N), U = t;
|
|
1226
|
+
return er(U.hash.outputLen, U.nByteLength, U.hmac)(B, C);
|
|
1227
1227
|
}
|
|
1228
1228
|
l.BASE._setWindowSize(8);
|
|
1229
|
-
function
|
|
1229
|
+
function D(b, v, N, B = 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 B)
|
|
1233
1233
|
throw new Error("options.strict was renamed to lowS");
|
|
1234
|
-
const { lowS: U, prehash: O } =
|
|
1234
|
+
const { lowS: U, prehash: O } = B;
|
|
1235
1235
|
let $, ee;
|
|
1236
1236
|
try {
|
|
1237
1237
|
if (typeof C == "string" || C instanceof Uint8Array)
|
|
1238
1238
|
try {
|
|
1239
|
-
$ =
|
|
1239
|
+
$ = p.fromDER(C);
|
|
1240
1240
|
} catch (te) {
|
|
1241
|
-
if (!(te instanceof
|
|
1241
|
+
if (!(te instanceof ke.Err))
|
|
1242
1242
|
throw te;
|
|
1243
|
-
$ =
|
|
1243
|
+
$ = p.fromCompact(C);
|
|
1244
1244
|
}
|
|
1245
1245
|
else if (typeof C == "object" && typeof C.r == "bigint" && typeof C.s == "bigint") {
|
|
1246
1246
|
const { r: te, s: Re } = C;
|
|
1247
|
-
$ = new
|
|
1247
|
+
$ = new p(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");
|
|
@@ -1262,18 +1262,18 @@ function ls(e) {
|
|
|
1262
1262
|
return {
|
|
1263
1263
|
CURVE: t,
|
|
1264
1264
|
getPublicKey: S,
|
|
1265
|
-
getSharedSecret:
|
|
1265
|
+
getSharedSecret: k,
|
|
1266
1266
|
sign: T,
|
|
1267
|
-
verify:
|
|
1267
|
+
verify: D,
|
|
1268
1268
|
ProjectivePoint: l,
|
|
1269
|
-
Signature:
|
|
1270
|
-
utils:
|
|
1269
|
+
Signature: p,
|
|
1270
|
+
utils: m
|
|
1271
1271
|
};
|
|
1272
1272
|
}
|
|
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;
|
|
@@ -1311,7 +1311,7 @@ or.create = (e, t) => new sr(e, t);
|
|
|
1311
1311
|
function fs(e) {
|
|
1312
1312
|
return {
|
|
1313
1313
|
hash: e,
|
|
1314
|
-
hmac: (t, ...n) => or(e, t,
|
|
1314
|
+
hmac: (t, ...n) => or(e, t, Bi(...n)),
|
|
1315
1315
|
randomBytes: Yn
|
|
1316
1316
|
};
|
|
1317
1317
|
}
|
|
@@ -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
|
-
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,
|
|
1326
|
-
if (!
|
|
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, y = Y(u, n, t) * f % t, w = Y(y, 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, p = Y(d, a, t) * d % t, m = Y(p, c, t) * h % t, S = Y(m, n, t) * f % t, _ = Y(S, o, t) * g % t, k = Y(_, r, t) * l % t, E = Y(k, nt, t);
|
|
1326
|
+
if (!Ot.eql(Ot.sqr(E), e))
|
|
1327
1327
|
throw new Error("Cannot find square root");
|
|
1328
|
-
return
|
|
1328
|
+
return E;
|
|
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,27 +1346,27 @@ 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
|
-
const u = l > o,
|
|
1352
|
-
if (u && (l = t - l),
|
|
1351
|
+
const u = l > o, y = f > o;
|
|
1352
|
+
if (u && (l = t - l), y && (f = t - f), l > o || f > o)
|
|
1353
1353
|
throw new Error("splitScalar: Endomorphism failed, k=" + e);
|
|
1354
|
-
return { k1neg: u, k1: l, k2neg:
|
|
1354
|
+
return { k1neg: u, k1: l, k2neg: y, 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), y = fr(f, i, r), w = new Uint8Array(64);
|
|
1391
|
+
if (w.set(f, 0), w.set(Mt(Ge(u + y * 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, kt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), ie = (e, t) => e << 32 - t | e >>> t, ws = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1426
1426
|
if (!ws)
|
|
1427
1427
|
throw new Error("Non little-endian hardware is not supported");
|
|
1428
1428
|
const bs = Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
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;
|
|
@@ -1530,7 +1530,7 @@ function Ks(e, t, n, r) {
|
|
|
1530
1530
|
}
|
|
1531
1531
|
class Ss extends dr {
|
|
1532
1532
|
constructor(t, n, r, i) {
|
|
1533
|
-
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view =
|
|
1533
|
+
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view = kt(this.buffer);
|
|
1534
1534
|
}
|
|
1535
1535
|
update(t) {
|
|
1536
1536
|
se.exists(this);
|
|
@@ -1540,7 +1540,7 @@ class Ss extends dr {
|
|
|
1540
1540
|
for (let o = 0; o < s; ) {
|
|
1541
1541
|
const c = Math.min(i - this.pos, s - o);
|
|
1542
1542
|
if (c === i) {
|
|
1543
|
-
const a =
|
|
1543
|
+
const a = kt(t);
|
|
1544
1544
|
for (; i <= s - o; o += i)
|
|
1545
1545
|
this.process(a, o);
|
|
1546
1546
|
continue;
|
|
@@ -1556,8 +1556,8 @@ 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
|
-
|
|
1560
|
-
const c =
|
|
1559
|
+
Ns(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
1560
|
+
const c = kt(t), a = this.outputLen;
|
|
1561
1561
|
if (a % 4)
|
|
1562
1562
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
1563
1563
|
const l = a / 4, f = this.get();
|
|
@@ -1578,7 +1578,7 @@ class Ss extends dr {
|
|
|
1578
1578
|
return t.length = i, t.pos = c, t.finished = s, t.destroyed = o, i % n && t.buffer.set(r), t;
|
|
1579
1579
|
}
|
|
1580
1580
|
}
|
|
1581
|
-
const As = (e, t, n) => e & t ^ ~e & n, Cs = (e, t, n) => e & t ^ e & n ^ t & n,
|
|
1581
|
+
const As = (e, t, n) => e & t ^ ~e & n, Cs = (e, t, n) => e & t ^ e & n ^ t & n, ks = new Uint32Array([
|
|
1582
1582
|
1116352408,
|
|
1583
1583
|
1899447441,
|
|
1584
1584
|
3049323471,
|
|
@@ -1669,12 +1669,12 @@ class wr extends Ss {
|
|
|
1669
1669
|
for (let u = 0; u < 16; u++, n += 4)
|
|
1670
1670
|
Ee[u] = t.getUint32(n, !1);
|
|
1671
1671
|
for (let u = 16; u < 64; u++) {
|
|
1672
|
-
const
|
|
1672
|
+
const y = Ee[u - 15], w = Ee[u - 2], g = ie(y, 7) ^ ie(y, 18) ^ y >>> 3, h = ie(w, 17) ^ ie(w, 19) ^ w >>> 10;
|
|
1673
1673
|
Ee[u] = h + Ee[u - 7] + g + Ee[u - 16] | 0;
|
|
1674
1674
|
}
|
|
1675
1675
|
let { A: r, B: i, C: s, D: o, E: c, F: a, G: l, H: f } = this;
|
|
1676
1676
|
for (let u = 0; u < 64; u++) {
|
|
1677
|
-
const
|
|
1677
|
+
const y = ie(c, 6) ^ ie(c, 11) ^ ie(c, 25), w = f + y + As(c, a, l) + ks[u] + Ee[u] | 0, h = (ie(r, 2) ^ ie(r, 13) ^ ie(r, 22)) + Cs(r, i, s) | 0;
|
|
1678
1678
|
f = l, l = a, a = c, c = o + w | 0, o = s, s = i, i = r, r = w + h | 0;
|
|
1679
1679
|
}
|
|
1680
1680
|
r = r + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, l = l + this.G | 0, f = f + this.H | 0, this.set(r, i, s, o, c, a, l, f);
|
|
@@ -1686,13 +1686,13 @@ class wr extends Ss {
|
|
|
1686
1686
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
|
|
1687
1687
|
}
|
|
1688
1688
|
}
|
|
1689
|
-
class
|
|
1689
|
+
class Bs extends wr {
|
|
1690
1690
|
constructor() {
|
|
1691
1691
|
super(), this.A = -1056596264, this.B = 914150663, this.C = 812702999, this.D = -150054599, this.E = -4191439, this.F = 1750603025, this.G = 1694076839, this.H = -1090891868, this.outputLen = 28;
|
|
1692
1692
|
}
|
|
1693
1693
|
}
|
|
1694
1694
|
const fe = pr(() => new wr());
|
|
1695
|
-
pr(() => new
|
|
1695
|
+
pr(() => new Bs());
|
|
1696
1696
|
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1697
1697
|
function We(e) {
|
|
1698
1698
|
if (!Number.isSafeInteger(e))
|
|
@@ -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,44 +1933,44 @@ 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 =
|
|
1940
|
-
function o(f, u,
|
|
1939
|
+
const t = e === "bech32" ? 1 : 734539939, n = Se(5), r = n.decode, i = n.encode, s = On(r);
|
|
1940
|
+
function o(f, u, y = 90) {
|
|
1941
1941
|
if (typeof f != "string")
|
|
1942
1942
|
throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);
|
|
1943
1943
|
if (!Array.isArray(u) || u.length && typeof u[0] != "number")
|
|
1944
1944
|
throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);
|
|
1945
1945
|
const w = f.length + 7 + u.length;
|
|
1946
|
-
if (
|
|
1947
|
-
throw new TypeError(`Length ${w} exceeds limit ${
|
|
1948
|
-
return f = f.toLowerCase(), `${f}1${
|
|
1946
|
+
if (y !== !1 && w > y)
|
|
1947
|
+
throw new TypeError(`Length ${w} exceeds limit ${y}`);
|
|
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")
|
|
1952
1952
|
throw new Error(`bech32.decode input should be string, not ${typeof f}`);
|
|
1953
1953
|
if (f.length < 8 || u !== !1 && f.length > u)
|
|
1954
1954
|
throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${u})`);
|
|
1955
|
-
const
|
|
1956
|
-
if (f !==
|
|
1955
|
+
const y = f.toLowerCase();
|
|
1956
|
+
if (f !== y && f !== f.toUpperCase())
|
|
1957
1957
|
throw new Error("String must be lowercase or uppercase");
|
|
1958
|
-
f =
|
|
1958
|
+
f = y;
|
|
1959
1959
|
const w = f.lastIndexOf("1");
|
|
1960
1960
|
if (w === 0 || w === -1)
|
|
1961
1961
|
throw new Error('Letter "1" must be present between prefix and data only');
|
|
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 =
|
|
1966
|
-
if (!h.endsWith(
|
|
1967
|
-
throw new Error(`Invalid checksum in ${f}: expected "${
|
|
1965
|
+
const d = jt.decode(h).slice(0, -6), p = Hn(g, d, t);
|
|
1966
|
+
if (!h.endsWith(p))
|
|
1967
|
+
throw new Error(`Invalid checksum in ${f}: expected "${p}"`);
|
|
1968
1968
|
return { prefix: g, words: d };
|
|
1969
1969
|
}
|
|
1970
|
-
const a =
|
|
1970
|
+
const a = On(c);
|
|
1971
1971
|
function l(f) {
|
|
1972
|
-
const { prefix: u, words:
|
|
1973
|
-
return { prefix: u, words:
|
|
1972
|
+
const { prefix: u, words: y } = c(f, !1);
|
|
1973
|
+
return { prefix: u, words: y, bytes: r(y) };
|
|
1974
1974
|
}
|
|
1975
1975
|
return { encode: o, decode: c, decodeToBytes: l, decodeUnsafe: a, fromWords: r, fromWordsUnsafe: s, toWords: i };
|
|
1976
1976
|
}
|
|
@@ -1994,11 +1994,11 @@ const Rs = {
|
|
|
1994
1994
|
base58xmr: $s
|
|
1995
1995
|
};
|
|
1996
1996
|
`${Object.keys(Os).join(", ")}`;
|
|
1997
|
-
function
|
|
1997
|
+
function Bt(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,16 +2099,16 @@ 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;
|
|
2106
2106
|
for (let g = 0; g < l; g++) {
|
|
2107
|
-
const h = e[a++] ^ xe(o, c, t, n, r, i), d = e[a++] ^ xe(o, c, n, r, i, t),
|
|
2108
|
-
t = h, n = d, r =
|
|
2107
|
+
const h = e[a++] ^ xe(o, c, t, n, r, i), d = e[a++] ^ xe(o, c, n, r, i, t), p = e[a++] ^ xe(o, c, r, i, t, n), m = e[a++] ^ xe(o, c, i, t, n, r);
|
|
2108
|
+
t = h, n = d, r = p, i = m;
|
|
2109
2109
|
}
|
|
2110
|
-
const f = e[a++] ^ oe(s, t, n, r, i), u = e[a++] ^ oe(s, n, r, i, t),
|
|
2111
|
-
return { s0: f, s1: u, s2:
|
|
2110
|
+
const f = e[a++] ^ oe(s, t, n, r, i), u = e[a++] ^ oe(s, n, r, i, t), y = e[a++] ^ oe(s, r, i, t, n), w = e[a++] ^ oe(s, i, t, n, r);
|
|
2111
|
+
return { s0: f, s1: u, s2: y, s3: w };
|
|
2112
2112
|
}
|
|
2113
2113
|
function Fs(e, t, n, r, i) {
|
|
2114
2114
|
const { sbox2: s, T01: o, T23: c } = xr;
|
|
@@ -2116,13 +2116,13 @@ function Fs(e, t, n, r, i) {
|
|
|
2116
2116
|
t ^= e[a++], n ^= e[a++], r ^= e[a++], i ^= e[a++];
|
|
2117
2117
|
const l = e.length / 4 - 2;
|
|
2118
2118
|
for (let g = 0; g < l; g++) {
|
|
2119
|
-
const h = e[a++] ^ xe(o, c, t, i, r, n), d = e[a++] ^ xe(o, c, n, t, i, r),
|
|
2120
|
-
t = h, n = d, r =
|
|
2119
|
+
const h = e[a++] ^ xe(o, c, t, i, r, n), d = e[a++] ^ xe(o, c, n, t, i, r), p = e[a++] ^ xe(o, c, r, n, t, i), m = e[a++] ^ xe(o, c, i, r, n, t);
|
|
2120
|
+
t = h, n = d, r = p, i = m;
|
|
2121
2121
|
}
|
|
2122
|
-
const f = e[a++] ^ oe(s, t, i, r, n), u = e[a++] ^ oe(s, n, t, i, r),
|
|
2123
|
-
return { s0: f, s1: u, s2:
|
|
2122
|
+
const f = e[a++] ^ oe(s, t, i, r, n), u = e[a++] ^ oe(s, n, t, i, r), y = e[a++] ^ oe(s, r, n, t, i), w = e[a++] ^ oe(s, i, r, n, t);
|
|
2123
|
+
return { s0: f, s1: u, s2: y, 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,35 +2164,35 @@ 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 =
|
|
2178
|
-
let
|
|
2177
|
+
const c = Kr(t), { b: a, o: l, out: f } = Js(s, i, o), u = F(n);
|
|
2178
|
+
let y = u[0], w = u[1], g = u[2], h = u[3], d = 0;
|
|
2179
2179
|
for (; d + 4 <= a.length; )
|
|
2180
|
-
|
|
2180
|
+
y ^= a[d + 0], w ^= a[d + 1], g ^= a[d + 2], h ^= a[d + 3], { s0: y, s1: w, s2: g, s3: h } = qn(c, y, w, g, h), l[d++] = y, l[d++] = w, l[d++] = g, l[d++] = h;
|
|
2181
2181
|
if (i) {
|
|
2182
|
-
const
|
|
2183
|
-
|
|
2182
|
+
const p = Xs(s.subarray(d * 4));
|
|
2183
|
+
y ^= p[0], w ^= p[1], g ^= p[2], h ^= p[3], { s0: y, s1: w, s2: g, s3: h } = qn(c, y, w, g, h), l[d++] = y, l[d++] = w, l[d++] = g, l[d++] = h;
|
|
2184
2184
|
}
|
|
2185
2185
|
return c.fill(0), f;
|
|
2186
2186
|
},
|
|
2187
2187
|
decrypt: (s, o) => {
|
|
2188
2188
|
Gs(s);
|
|
2189
|
-
const c = Zs(t), a = F(n), l =
|
|
2190
|
-
let
|
|
2189
|
+
const c = Zs(t), a = F(n), l = Nr(s.length, o), f = F(s), u = F(l);
|
|
2190
|
+
let y = a[0], w = a[1], g = a[2], h = a[3];
|
|
2191
2191
|
for (let d = 0; d + 4 <= f.length; ) {
|
|
2192
|
-
const
|
|
2193
|
-
|
|
2194
|
-
const { s0:
|
|
2195
|
-
u[d++] =
|
|
2192
|
+
const p = y, m = w, S = g, _ = h;
|
|
2193
|
+
y = f[d + 0], w = f[d + 1], g = f[d + 2], h = f[d + 3];
|
|
2194
|
+
const { s0: k, s1: E, s2: x, s3: K } = Fs(c, y, w, g, h);
|
|
2195
|
+
u[d++] = k ^ p, u[d++] = E ^ m, u[d++] = x ^ S, u[d++] = K ^ _;
|
|
2196
2196
|
}
|
|
2197
2197
|
return c.fill(0), Ys(l, i);
|
|
2198
2198
|
}
|
|
@@ -2202,27 +2202,27 @@ 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,
|
|
2208
|
+
const Xe = 64, no = 16, kr = 2 ** 32 - 1, jn = new Uint32Array();
|
|
2209
2209
|
function ro(e, t, n, r, i, s, o, c) {
|
|
2210
|
-
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), y = u ? F(i) : jn, w = u ? F(s) : jn;
|
|
2211
2211
|
for (let g = 0; g < a; o++) {
|
|
2212
|
-
if (e(t, n, r, f, o, c), o >=
|
|
2212
|
+
if (e(t, n, r, f, o, c), o >= kr)
|
|
2213
2213
|
throw new Error("arx: counter overflow");
|
|
2214
2214
|
const h = Math.min(Xe, a - g);
|
|
2215
2215
|
if (u && h === Xe) {
|
|
2216
2216
|
const d = g / 4;
|
|
2217
2217
|
if (g % 4 !== 0)
|
|
2218
2218
|
throw new Error("arx: invalid block position");
|
|
2219
|
-
for (let
|
|
2220
|
-
|
|
2219
|
+
for (let p = 0, m; p < no; p++)
|
|
2220
|
+
m = d + p, w[m] = y[m] ^ f[p];
|
|
2221
2221
|
g += Xe;
|
|
2222
2222
|
continue;
|
|
2223
2223
|
}
|
|
2224
|
-
for (let d = 0,
|
|
2225
|
-
|
|
2224
|
+
for (let d = 0, p; d < h; d++)
|
|
2225
|
+
p = g + d, s[p] = i[p] ^ l[d];
|
|
2226
2226
|
g += h;
|
|
2227
2227
|
}
|
|
2228
2228
|
}
|
|
@@ -2230,13 +2230,13 @@ 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
|
|
2233
|
+
return Bt(i), Bt(o), Dn(s), Dn(n), (c, a, l, f, u = 0) => {
|
|
2234
2234
|
ue(c), ue(a), ue(l);
|
|
2235
|
-
const
|
|
2236
|
-
if (f || (f = new Uint8Array(
|
|
2235
|
+
const y = l.length;
|
|
2236
|
+
if (f || (f = new Uint8Array(y)), ue(f), Bt(u), u < 0 || u >= kr)
|
|
2237
2237
|
throw new Error("arx: counter overflow");
|
|
2238
|
-
if (f.length <
|
|
2239
|
-
throw new Error(`arx: output (${f.length}) is shorter than data (${
|
|
2238
|
+
if (f.length < y)
|
|
2239
|
+
throw new Error(`arx: output (${f.length}) is shorter than data (${y})`);
|
|
2240
2240
|
const w = [];
|
|
2241
2241
|
let g = c.length, h, d;
|
|
2242
2242
|
if (g === 32)
|
|
@@ -2245,34 +2245,34 @@ 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
|
-
|
|
2249
|
-
const
|
|
2248
|
+
Wt(a) || (a = a.slice(), w.push(a));
|
|
2249
|
+
const p = F(h);
|
|
2250
2250
|
if (r) {
|
|
2251
2251
|
if (a.length !== 24)
|
|
2252
2252
|
throw new Error("arx: extended nonce must be 24 bytes");
|
|
2253
|
-
r(d,
|
|
2253
|
+
r(d, p, F(a.subarray(0, 16)), p), a = a.subarray(16);
|
|
2254
2254
|
}
|
|
2255
|
-
const
|
|
2256
|
-
if (
|
|
2257
|
-
throw new Error(`arx: nonce must be ${
|
|
2258
|
-
if (
|
|
2255
|
+
const m = 16 - i;
|
|
2256
|
+
if (m !== a.length)
|
|
2257
|
+
throw new Error(`arx: nonce must be ${m} or 16 bytes`);
|
|
2258
|
+
if (m !== 12) {
|
|
2259
2259
|
const _ = new Uint8Array(12);
|
|
2260
2260
|
_.set(a, s ? 0 : 12 - a.length), a = _, w.push(a);
|
|
2261
2261
|
}
|
|
2262
2262
|
const S = F(a);
|
|
2263
|
-
for (ro(e, d,
|
|
2263
|
+
for (ro(e, d, p, S, l, f, u, o); w.length > 0; )
|
|
2264
2264
|
w.pop().fill(0);
|
|
2265
2265
|
return f;
|
|
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],
|
|
2269
|
+
let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1], y = t[2], w = t[3], g = t[4], h = t[5], d = t[6], p = t[7], m = i, S = n[0], _ = n[1], k = n[2], E = o, x = c, K = a, M = l, I = f, A = u, R = y, T = w, D = g, b = h, v = d, N = p, B = m, C = S, U = _, O = k;
|
|
2270
2270
|
for (let ee = 0; ee < s; ee += 2)
|
|
2271
|
-
|
|
2271
|
+
E = E + I | 0, B = L(B ^ E, 16), D = D + B | 0, I = L(I ^ D, 12), E = E + I | 0, B = L(B ^ E, 8), D = D + B | 0, I = L(I ^ D, 7), x = x + A | 0, C = L(C ^ x, 16), b = b + C | 0, A = L(A ^ b, 12), x = x + A | 0, C = L(C ^ x, 8), b = b + C | 0, A = L(A ^ b, 7), K = K + R | 0, 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), E = E + A | 0, O = L(O ^ E, 16), v = v + O | 0, A = L(A ^ v, 12), E = E + A | 0, O = L(O ^ E, 8), v = v + O | 0, A = L(A ^ v, 7), x = x + R | 0, B = L(B ^ x, 16), N = N + B | 0, R = L(R ^ N, 12), x = x + R | 0, B = L(B ^ x, 8), N = N + B | 0, R = L(R ^ N, 7), K = K + T | 0, C = L(C ^ K, 16), D = D + C | 0, T = L(T ^ D, 12), K = K + T | 0, C = L(C ^ K, 8), D = D + C | 0, T = L(T ^ D, 7), M = M + I | 0, 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 +
|
|
2273
|
+
r[$++] = o + E | 0, r[$++] = c + x | 0, r[$++] = a + K | 0, r[$++] = l + M | 0, r[$++] = f + I | 0, r[$++] = u + A | 0, r[$++] = y + R | 0, r[$++] = w + T | 0, r[$++] = g + D | 0, r[$++] = h + b | 0, r[$++] = d + v | 0, r[$++] = p + N | 0, r[$++] = m + B | 0, r[$++] = S + C | 0, r[$++] = _ + U | 0, r[$++] = k + O | 0;
|
|
2274
2274
|
}
|
|
2275
|
-
const
|
|
2275
|
+
const Br = /* @__PURE__ */ io(so, {
|
|
2276
2276
|
counterRight: !1,
|
|
2277
2277
|
counterLength: 4,
|
|
2278
2278
|
allowShortKeys: !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
|
-
var yt = new po(),
|
|
2450
|
+
var yt = new po(), Be = 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
|
-
ProblemTracker: () =>
|
|
2510
|
+
ProblemTracker: () => ko,
|
|
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
|
-
Report: () =>
|
|
2517
|
+
Report: () => Bo,
|
|
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, ko = 1971, Bo = 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
|
-
getSubscriptionId: () =>
|
|
2560
|
-
matchEventId: () =>
|
|
2559
|
+
getSubscriptionId: () => ka,
|
|
2560
|
+
matchEventId: () => Ba,
|
|
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
|
}
|
|
@@ -2569,7 +2569,7 @@ function Vr(e, t) {
|
|
|
2569
2569
|
let n = t.length, r = e.indexOf(`"${t}":`) + n + 3, i = e.slice(r), s = Math.min(i.indexOf(","), i.indexOf("}"));
|
|
2570
2570
|
return parseInt(i.slice(0, s), 10);
|
|
2571
2571
|
}
|
|
2572
|
-
function
|
|
2572
|
+
function ka(e) {
|
|
2573
2573
|
let t = e.slice(0, 22).indexOf('"EVENT"');
|
|
2574
2574
|
if (t === -1)
|
|
2575
2575
|
return null;
|
|
@@ -2582,11 +2582,11 @@ function Ba(e) {
|
|
|
2582
2582
|
let s = r + 1 + i;
|
|
2583
2583
|
return e.slice(r + 1, s);
|
|
2584
2584
|
}
|
|
2585
|
-
function
|
|
2586
|
-
return t ===
|
|
2585
|
+
function Ba(e, 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);
|
|
@@ -2665,7 +2665,7 @@ function wt(e) {
|
|
|
2665
2665
|
type: "nprofile",
|
|
2666
2666
|
data: {
|
|
2667
2667
|
pubkey: P(u[0][0]),
|
|
2668
|
-
relays: u[1] ? u[1].map((
|
|
2668
|
+
relays: u[1] ? u[1].map((y) => le.decode(y)) : []
|
|
2669
2669
|
}
|
|
2670
2670
|
};
|
|
2671
2671
|
}
|
|
@@ -2683,7 +2683,7 @@ function wt(e) {
|
|
|
2683
2683
|
type: "nevent",
|
|
2684
2684
|
data: {
|
|
2685
2685
|
id: P(u[0][0]),
|
|
2686
|
-
relays: u[1] ? u[1].map((
|
|
2686
|
+
relays: u[1] ? u[1].map((y) => le.decode(y)) : [],
|
|
2687
2687
|
author: (o = u[2]) != null && o[0] ? P(u[2][0]) : void 0,
|
|
2688
2688
|
kind: (c = u[3]) != null && c[0] ? parseInt(P(u[3][0]), 16) : void 0
|
|
2689
2689
|
}
|
|
@@ -2707,7 +2707,7 @@ function wt(e) {
|
|
|
2707
2707
|
identifier: le.decode(u[0][0]),
|
|
2708
2708
|
pubkey: P(u[2][0]),
|
|
2709
2709
|
kind: parseInt(P(u[3][0]), 16),
|
|
2710
|
-
relays: u[1] ? u[1].map((
|
|
2710
|
+
relays: u[1] ? u[1].map((y) => le.decode(y)) : []
|
|
2711
2711
|
}
|
|
2712
2712
|
};
|
|
2713
2713
|
}
|
|
@@ -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
|
|
3069
|
-
const { chacha_key: r, chacha_nonce: i, hmac_key: s } = ni(t, n), o = uc(e), c =
|
|
3068
|
+
function bn(e, t, n = yr(32)) {
|
|
3069
|
+
const { chacha_key: r, chacha_nonce: i, hmac_key: s } = ni(t, n), o = uc(e), c = Br(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
|
-
const l =
|
|
3076
|
+
const l = Br(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(
|
|
@@ -3106,7 +3106,7 @@ function ui(e, t, n) {
|
|
|
3106
3106
|
);
|
|
3107
3107
|
}
|
|
3108
3108
|
function li(e, t) {
|
|
3109
|
-
const n =
|
|
3109
|
+
const n = Be();
|
|
3110
3110
|
return Q(
|
|
3111
3111
|
{
|
|
3112
3112
|
kind: jr,
|
|
@@ -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--) {
|
|
@@ -3261,11 +3261,11 @@ function Cc(e) {
|
|
|
3261
3261
|
author: n[1]
|
|
3262
3262
|
};
|
|
3263
3263
|
}
|
|
3264
|
-
var
|
|
3265
|
-
H(
|
|
3264
|
+
var kc = {};
|
|
3265
|
+
H(kc, {
|
|
3266
3266
|
parse: () => Ic
|
|
3267
3267
|
});
|
|
3268
|
-
var
|
|
3268
|
+
var Bc = /\W/m, Vn = /\W |\W$|$|,| /m;
|
|
3269
3269
|
function* Ic(e) {
|
|
3270
3270
|
const t = e.length;
|
|
3271
3271
|
let n = 0, r = 0;
|
|
@@ -3274,7 +3274,7 @@ function* Ic(e) {
|
|
|
3274
3274
|
if (i === -1)
|
|
3275
3275
|
break;
|
|
3276
3276
|
if (e.substring(i - 5, i) === "nostr") {
|
|
3277
|
-
const s = e.substring(i + 60).match(
|
|
3277
|
+
const s = e.substring(i + 60).match(Bc), o = s ? i + 60 + s.index : t;
|
|
3278
3278
|
try {
|
|
3279
3279
|
let c, { data: a, type: l } = wt(e.substring(i + 1, o));
|
|
3280
3280
|
switch (l) {
|
|
@@ -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({
|
|
@@ -3539,40 +3539,31 @@ async function Jc(e) {
|
|
|
3539
3539
|
}
|
|
3540
3540
|
return null;
|
|
3541
3541
|
}
|
|
3542
|
-
function Yc({
|
|
3543
|
-
|
|
3544
|
-
event: t,
|
|
3545
|
-
amount: n,
|
|
3546
|
-
relays: r,
|
|
3547
|
-
comment: i = ""
|
|
3548
|
-
}) {
|
|
3549
|
-
if (!n)
|
|
3550
|
-
throw new Error("amount not given");
|
|
3551
|
-
if (!e)
|
|
3552
|
-
throw new Error("profile not given");
|
|
3553
|
-
let s = {
|
|
3542
|
+
function Yc(e) {
|
|
3543
|
+
let t = {
|
|
3554
3544
|
kind: 9734,
|
|
3555
3545
|
created_at: Math.round(Date.now() / 1e3),
|
|
3556
|
-
content:
|
|
3546
|
+
content: e.comment || "",
|
|
3557
3547
|
tags: [
|
|
3558
|
-
["p", e],
|
|
3559
|
-
["amount",
|
|
3560
|
-
["relays", ...
|
|
3548
|
+
["p", "pubkey" in e ? e.pubkey : e.event.pubkey],
|
|
3549
|
+
["amount", e.amount.toString()],
|
|
3550
|
+
["relays", ...e.relays]
|
|
3561
3551
|
]
|
|
3562
3552
|
};
|
|
3563
|
-
if (
|
|
3564
|
-
if (
|
|
3565
|
-
const
|
|
3566
|
-
|
|
3567
|
-
} else if (
|
|
3568
|
-
let
|
|
3569
|
-
if (!
|
|
3553
|
+
if ("event" in e) {
|
|
3554
|
+
if (t.tags.push(["e", e.event.id]), on(e.event.kind)) {
|
|
3555
|
+
const n = ["a", `${e.event.kind}:${e.event.pubkey}:`];
|
|
3556
|
+
t.tags.push(n);
|
|
3557
|
+
} else if (an(e.event.kind)) {
|
|
3558
|
+
let n = e.event.tags.find(([i, s]) => i === "d" && s);
|
|
3559
|
+
if (!n)
|
|
3570
3560
|
throw new Error("d tag not found or is empty");
|
|
3571
|
-
const
|
|
3572
|
-
|
|
3561
|
+
const r = ["a", `${e.event.kind}:${e.event.pubkey}:${n[1]}`];
|
|
3562
|
+
t.tags.push(r);
|
|
3573
3563
|
}
|
|
3564
|
+
t.tags.push(["k", e.event.kind.toString()]);
|
|
3574
3565
|
}
|
|
3575
|
-
return
|
|
3566
|
+
return t;
|
|
3576
3567
|
}
|
|
3577
3568
|
function Xc(e) {
|
|
3578
3569
|
let t;
|
|
@@ -3641,7 +3632,7 @@ function eu(e) {
|
|
|
3641
3632
|
var tu = {};
|
|
3642
3633
|
H(tu, {
|
|
3643
3634
|
getToken: () => nu,
|
|
3644
|
-
hashPayload: () =>
|
|
3635
|
+
hashPayload: () => Sn,
|
|
3645
3636
|
unpackEventFromToken: () => gi,
|
|
3646
3637
|
validateEvent: () => xi,
|
|
3647
3638
|
validateEventKind: () => bi,
|
|
@@ -3654,7 +3645,7 @@ H(tu, {
|
|
|
3654
3645
|
var yi = "Nostr ";
|
|
3655
3646
|
async function nu(e, t, n, r = !1, i) {
|
|
3656
3647
|
const s = {
|
|
3657
|
-
kind:
|
|
3648
|
+
kind: fn,
|
|
3658
3649
|
tags: [
|
|
3659
3650
|
["u", e],
|
|
3660
3651
|
["method", t]
|
|
@@ -3662,7 +3653,7 @@ async function nu(e, t, n, r = !1, i) {
|
|
|
3662
3653
|
created_at: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
3663
3654
|
content: ""
|
|
3664
3655
|
};
|
|
3665
|
-
i && s.tags.push(["payload",
|
|
3656
|
+
i && s.tags.push(["payload", Sn(i)]);
|
|
3666
3657
|
const o = await n(s);
|
|
3667
3658
|
return (r ? yi : "") + he.encode(ne.encode(JSON.stringify(o)));
|
|
3668
3659
|
}
|
|
@@ -3687,7 +3678,7 @@ function wi(e) {
|
|
|
3687
3678
|
return e.created_at ? Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3) - e.created_at < 60 : !1;
|
|
3688
3679
|
}
|
|
3689
3680
|
function bi(e) {
|
|
3690
|
-
return e.kind ===
|
|
3681
|
+
return e.kind === fn;
|
|
3691
3682
|
}
|
|
3692
3683
|
function vi(e, t) {
|
|
3693
3684
|
const n = e.tags.find((r) => r[0] === "u");
|
|
@@ -3697,7 +3688,7 @@ function mi(e, t) {
|
|
|
3697
3688
|
const n = e.tags.find((r) => r[0] === "method");
|
|
3698
3689
|
return n ? n.length > 0 && n[1].toLowerCase() === t.toLowerCase() : !1;
|
|
3699
3690
|
}
|
|
3700
|
-
function
|
|
3691
|
+
function Sn(e) {
|
|
3701
3692
|
const t = fe(ne.encode(JSON.stringify(e)));
|
|
3702
3693
|
return P(t);
|
|
3703
3694
|
}
|
|
@@ -3705,7 +3696,7 @@ function Ei(e, t) {
|
|
|
3705
3696
|
const n = e.tags.find((i) => i[0] === "payload");
|
|
3706
3697
|
if (!n)
|
|
3707
3698
|
return !1;
|
|
3708
|
-
const r =
|
|
3699
|
+
const r = Sn(t);
|
|
3709
3700
|
return n.length > 0 && n[1] === r;
|
|
3710
3701
|
}
|
|
3711
3702
|
async function xi(e, t, n, r) {
|
|
@@ -3723,7 +3714,7 @@ async function xi(e, t, n, r) {
|
|
|
3723
3714
|
throw new Error("Invalid nostr event, payload tag does not match request body hash");
|
|
3724
3715
|
return !0;
|
|
3725
3716
|
}
|
|
3726
|
-
const Oe = 1060,
|
|
3717
|
+
const Oe = 1060, Lt = 30078, Zn = 1059, iu = 14, wu = 100, su = 1;
|
|
3727
3718
|
function bu(e) {
|
|
3728
3719
|
return JSON.stringify({
|
|
3729
3720
|
version: su,
|
|
@@ -3838,7 +3829,7 @@ async function* mu(e) {
|
|
|
3838
3829
|
}
|
|
3839
3830
|
}
|
|
3840
3831
|
function Me(e, t = new Uint8Array(32), n = 1) {
|
|
3841
|
-
const r =
|
|
3832
|
+
const r = rn(fe, e, t), i = [];
|
|
3842
3833
|
for (let s = 1; s <= n; s++)
|
|
3843
3834
|
i.push(_r(fe, r, new Uint8Array([s]), 32));
|
|
3844
3835
|
return i;
|
|
@@ -3874,9 +3865,9 @@ class ot {
|
|
|
3874
3865
|
* @returns A new Session instance
|
|
3875
3866
|
*/
|
|
3876
3867
|
static init(t, n, r, i, s, o) {
|
|
3877
|
-
const c =
|
|
3868
|
+
const c = Be();
|
|
3878
3869
|
let a, l, f, u;
|
|
3879
|
-
i ? ([a, l] = Me(s,
|
|
3870
|
+
i ? ([a, l] = Me(s, q.getConversationKey(c, n), 2), f = {
|
|
3880
3871
|
publicKey: ae(r),
|
|
3881
3872
|
privateKey: r
|
|
3882
3873
|
}, u = {
|
|
@@ -3886,7 +3877,7 @@ class ot {
|
|
|
3886
3877
|
publicKey: ae(r),
|
|
3887
3878
|
privateKey: r
|
|
3888
3879
|
});
|
|
3889
|
-
const
|
|
3880
|
+
const y = {
|
|
3890
3881
|
rootKey: a,
|
|
3891
3882
|
theirNextNostrPublicKey: n,
|
|
3892
3883
|
ourCurrentNostrKey: f,
|
|
@@ -3897,7 +3888,7 @@ class ot {
|
|
|
3897
3888
|
receivingChainMessageNumber: 0,
|
|
3898
3889
|
previousSendingChainMessageCount: 0,
|
|
3899
3890
|
skippedKeys: {}
|
|
3900
|
-
}, w = new ot(t,
|
|
3891
|
+
}, w = new ot(t, y);
|
|
3901
3892
|
return o && (w.name = o), w;
|
|
3902
3893
|
}
|
|
3903
3894
|
/**
|
|
@@ -3933,8 +3924,8 @@ class ot {
|
|
|
3933
3924
|
tags: t.tags || [],
|
|
3934
3925
|
pubkey: t.pubkey || au
|
|
3935
3926
|
};
|
|
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 =
|
|
3927
|
+
r.tags.some(([l]) => l === "ms") || r.tags.push(["ms", String(n)]), r.id = De(r);
|
|
3928
|
+
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
3929
|
return { event: Q({
|
|
3939
3930
|
content: s,
|
|
3940
3931
|
kind: Oe,
|
|
@@ -3965,25 +3956,25 @@ class ot {
|
|
|
3965
3956
|
number: this.state.sendingChainMessageNumber++,
|
|
3966
3957
|
nextPublicKey: this.state.ourNextNostrKey.publicKey,
|
|
3967
3958
|
previousChainLength: this.state.previousSendingChainMessageCount
|
|
3968
|
-
},
|
|
3959
|
+
}, q.encrypt(t, r)];
|
|
3969
3960
|
}
|
|
3970
3961
|
ratchetDecrypt(t, n, r) {
|
|
3971
3962
|
const i = this.trySkippedMessageKeys(t, n, r);
|
|
3972
3963
|
if (i) return i;
|
|
3973
3964
|
this.skipMessageKeys(t.number, r);
|
|
3974
3965
|
const [s, o] = Me(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3975
|
-
return this.state.receivingChainKey = s, this.state.receivingChainMessageNumber++,
|
|
3966
|
+
return this.state.receivingChainKey = s, this.state.receivingChainMessageNumber++, q.decrypt(n, o);
|
|
3976
3967
|
}
|
|
3977
3968
|
ratchetStep() {
|
|
3978
3969
|
this.state.previousSendingChainMessageCount = this.state.sendingChainMessageNumber, this.state.sendingChainMessageNumber = 0, this.state.receivingChainMessageNumber = 0;
|
|
3979
|
-
const t =
|
|
3970
|
+
const t = q.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [n, r] = Me(this.state.rootKey, t, 2);
|
|
3980
3971
|
this.state.receivingChainKey = r, this.state.ourCurrentNostrKey = this.state.ourNextNostrKey;
|
|
3981
|
-
const i =
|
|
3972
|
+
const i = Be();
|
|
3982
3973
|
this.state.ourNextNostrKey = {
|
|
3983
3974
|
publicKey: ae(i),
|
|
3984
3975
|
privateKey: i
|
|
3985
3976
|
};
|
|
3986
|
-
const s =
|
|
3977
|
+
const s = q.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [o, c] = Me(n, s, 2);
|
|
3987
3978
|
this.state.rootKey = o, this.state.sendingChainKey = c;
|
|
3988
3979
|
}
|
|
3989
3980
|
// 3. MESSAGE KEY FUNCTIONS
|
|
@@ -3996,10 +3987,10 @@ class ot {
|
|
|
3996
3987
|
headerKeys: [],
|
|
3997
3988
|
messageKeys: {}
|
|
3998
3989
|
}, this.state.ourCurrentNostrKey) {
|
|
3999
|
-
const i =
|
|
3990
|
+
const i = q.getConversationKey(this.state.ourCurrentNostrKey.privateKey, n);
|
|
4000
3991
|
this.state.skippedKeys[n].headerKeys.includes(i) || this.state.skippedKeys[n].headerKeys.push(i);
|
|
4001
3992
|
}
|
|
4002
|
-
const r =
|
|
3993
|
+
const r = q.getConversationKey(this.state.ourNextNostrKey.privateKey, n);
|
|
4003
3994
|
this.state.skippedKeys[n].headerKeys.includes(r) || this.state.skippedKeys[n].headerKeys.push(r);
|
|
4004
3995
|
}
|
|
4005
3996
|
for (; this.state.receivingChainMessageNumber < t; ) {
|
|
@@ -4012,28 +4003,28 @@ class ot {
|
|
|
4012
4003
|
const i = this.state.skippedKeys[r];
|
|
4013
4004
|
if (!i) return null;
|
|
4014
4005
|
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],
|
|
4006
|
+
return s ? (delete i.messageKeys[t.number], Object.keys(i.messageKeys).length === 0 && delete this.state.skippedKeys[r], q.decrypt(n, s)) : null;
|
|
4016
4007
|
}
|
|
4017
4008
|
// 4. NOSTR EVENT HANDLING
|
|
4018
4009
|
decryptHeader(t) {
|
|
4019
4010
|
const n = t.tags[0][1];
|
|
4020
4011
|
if (this.state.ourCurrentNostrKey) {
|
|
4021
|
-
const s =
|
|
4012
|
+
const s = q.getConversationKey(this.state.ourCurrentNostrKey.privateKey, t.pubkey);
|
|
4022
4013
|
try {
|
|
4023
|
-
return [JSON.parse(
|
|
4014
|
+
return [JSON.parse(q.decrypt(n, s)), !1, !1];
|
|
4024
4015
|
} catch {
|
|
4025
4016
|
}
|
|
4026
4017
|
}
|
|
4027
|
-
const r =
|
|
4018
|
+
const r = q.getConversationKey(this.state.ourNextNostrKey.privateKey, t.pubkey);
|
|
4028
4019
|
try {
|
|
4029
|
-
return [JSON.parse(
|
|
4020
|
+
return [JSON.parse(q.decrypt(n, r)), !0, !1];
|
|
4030
4021
|
} catch {
|
|
4031
4022
|
}
|
|
4032
4023
|
const i = this.state.skippedKeys[t.pubkey];
|
|
4033
4024
|
if (i != null && i.headerKeys)
|
|
4034
4025
|
for (const s of i.headerKeys)
|
|
4035
4026
|
try {
|
|
4036
|
-
return [JSON.parse(
|
|
4027
|
+
return [JSON.parse(q.decrypt(n, s)), !1, !0];
|
|
4037
4028
|
} catch {
|
|
4038
4029
|
}
|
|
4039
4030
|
throw new Error("Failed to decrypt header with current and skipped header keys");
|
|
@@ -4050,7 +4041,7 @@ class ot {
|
|
|
4050
4041
|
else if (!((r = this.state.skippedKeys[t.pubkey]) != null && r.messageKeys[i.number]))
|
|
4051
4042
|
return;
|
|
4052
4043
|
const c = this.ratchetDecrypt(i, t.content, t.pubkey), a = JSON.parse(c);
|
|
4053
|
-
if (!pt(a) || a.id !==
|
|
4044
|
+
if (!pt(a) || a.id !== De(a))
|
|
4054
4045
|
return;
|
|
4055
4046
|
this.internalSubscriptions.forEach((l) => l(a, t));
|
|
4056
4047
|
} catch (i) {
|
|
@@ -4079,7 +4070,7 @@ new TextDecoder("utf-8");
|
|
|
4079
4070
|
new TextEncoder();
|
|
4080
4071
|
function Qe(e, t) {
|
|
4081
4072
|
const n = _e.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
4082
|
-
return
|
|
4073
|
+
return rn(fe, n, "nip44-v2");
|
|
4083
4074
|
}
|
|
4084
4075
|
const cu = 2 * 24 * 60 * 60, uu = () => Math.round(Date.now() / 1e3), lu = () => Math.round(uu() - Math.random() * cu);
|
|
4085
4076
|
class Pe {
|
|
@@ -4089,7 +4080,7 @@ class Pe {
|
|
|
4089
4080
|
static createNew(t, n, r) {
|
|
4090
4081
|
if (!t)
|
|
4091
4082
|
throw new Error("Inviter public key is required");
|
|
4092
|
-
const i =
|
|
4083
|
+
const i = Be(), s = ae(i), o = P(Be());
|
|
4093
4084
|
return new Pe(
|
|
4094
4085
|
s,
|
|
4095
4086
|
o,
|
|
@@ -4140,7 +4131,7 @@ class Pe {
|
|
|
4140
4131
|
const { tags: n } = t;
|
|
4141
4132
|
if (!n)
|
|
4142
4133
|
throw new Error("Invalid invite event: missing tags");
|
|
4143
|
-
const r = (a = n.find(([
|
|
4134
|
+
const r = (a = n.find(([y]) => y === "ephemeralKey")) == null ? void 0 : a[1], i = (l = n.find(([y]) => y === "sharedSecret")) == null ? void 0 : l[1], s = t.pubkey, o = (f = n.find(([y]) => y === "d")) == null ? void 0 : f[1], c = (u = o == null ? void 0 : o.split("/")) == null ? void 0 : u[2];
|
|
4144
4135
|
if (!r || !i)
|
|
4145
4136
|
throw new Error("Invalid invite event: missing session key or sharedSecret");
|
|
4146
4137
|
return new Pe(
|
|
@@ -4154,11 +4145,15 @@ class Pe {
|
|
|
4154
4145
|
}
|
|
4155
4146
|
static fromUser(t, n, r) {
|
|
4156
4147
|
const i = {
|
|
4157
|
-
kinds: [
|
|
4148
|
+
kinds: [Lt],
|
|
4158
4149
|
authors: [t],
|
|
4159
4150
|
"#l": ["double-ratchet/invites"]
|
|
4160
4151
|
}, s = /* @__PURE__ */ new Set();
|
|
4161
4152
|
return n(i, (c) => {
|
|
4153
|
+
if (c.pubkey !== t) {
|
|
4154
|
+
console.error("Got invite event from wrong user", c.pubkey, "expected", t);
|
|
4155
|
+
return;
|
|
4156
|
+
}
|
|
4162
4157
|
if (!s.has(c.id)) {
|
|
4163
4158
|
s.add(c.id);
|
|
4164
4159
|
try {
|
|
@@ -4198,7 +4193,7 @@ class Pe {
|
|
|
4198
4193
|
if (!this.deviceId)
|
|
4199
4194
|
throw new Error("Device ID is required");
|
|
4200
4195
|
return {
|
|
4201
|
-
kind:
|
|
4196
|
+
kind: Lt,
|
|
4202
4197
|
pubkey: this.inviter,
|
|
4203
4198
|
content: "",
|
|
4204
4199
|
created_at: Math.floor(Date.now() / 1e3),
|
|
@@ -4210,35 +4205,60 @@ class Pe {
|
|
|
4210
4205
|
]
|
|
4211
4206
|
};
|
|
4212
4207
|
}
|
|
4208
|
+
/**
|
|
4209
|
+
* Creates an "invite tombstone" event that clears the original content and removes the list tag.
|
|
4210
|
+
* Used when the inviter logs out and wants to make the invite invisible to other devices.
|
|
4211
|
+
*/
|
|
4212
|
+
getDeletionEvent() {
|
|
4213
|
+
if (!this.deviceId)
|
|
4214
|
+
throw new Error("Device ID is required");
|
|
4215
|
+
return {
|
|
4216
|
+
kind: Lt,
|
|
4217
|
+
pubkey: this.inviter,
|
|
4218
|
+
content: "",
|
|
4219
|
+
// deliberately empty
|
|
4220
|
+
created_at: Math.floor(Date.now() / 1e3),
|
|
4221
|
+
tags: [
|
|
4222
|
+
["ephemeralKey", this.inviterEphemeralPublicKey],
|
|
4223
|
+
["sharedSecret", this.sharedSecret],
|
|
4224
|
+
["d", "double-ratchet/invites/" + this.deviceId]
|
|
4225
|
+
// same d tag
|
|
4226
|
+
]
|
|
4227
|
+
};
|
|
4228
|
+
}
|
|
4213
4229
|
/**
|
|
4214
4230
|
* Called by the invitee. Accepts the invite and creates a new session with the inviter.
|
|
4215
4231
|
*
|
|
4216
4232
|
* @param nostrSubscribe - A function to subscribe to Nostr events
|
|
4217
4233
|
* @param inviteePublicKey - The invitee's public key
|
|
4218
4234
|
* @param encryptor - The invitee's secret key or a signing/encrypt function
|
|
4235
|
+
* @param deviceId - Optional device ID to identify the invitee's device
|
|
4219
4236
|
* @returns An object containing the new session and an event to be published
|
|
4220
4237
|
*
|
|
4221
4238
|
* 1. Inner event: No signature, content encrypted with DH(inviter, invitee).
|
|
4222
|
-
* Purpose: Authenticate invitee. Contains invitee session key.
|
|
4239
|
+
* Purpose: Authenticate invitee. Contains invitee session key and deviceId.
|
|
4223
4240
|
* 2. Envelope: No signature, content encrypted with DH(inviter, random key).
|
|
4224
4241
|
* Purpose: Contains inner event. Hides invitee from others who might have the shared Nostr key.
|
|
4225
4242
|
|
|
4226
4243
|
* Note: You need to publish the returned event on Nostr using NDK or another Nostr system of your choice,
|
|
4227
4244
|
* so the inviter can create the session on their side.
|
|
4228
4245
|
*/
|
|
4229
|
-
async accept(t, n, r) {
|
|
4230
|
-
const
|
|
4246
|
+
async accept(t, n, r, i) {
|
|
4247
|
+
const s = Be(), o = ae(s), c = this.inviter || this.inviterEphemeralPublicKey, a = j(this.sharedSecret), l = ot.init(t, this.inviterEphemeralPublicKey, s, !0, a, void 0), f = typeof r == "function" ? r : (m, S) => Promise.resolve(q.encrypt(m, Qe(r, S))), u = JSON.stringify({
|
|
4248
|
+
sessionKey: o,
|
|
4249
|
+
deviceId: i
|
|
4250
|
+
}), y = await f(u, c), w = {
|
|
4231
4251
|
pubkey: n,
|
|
4232
|
-
content: await
|
|
4252
|
+
content: await q.encrypt(y, a),
|
|
4233
4253
|
created_at: Math.floor(Date.now() / 1e3)
|
|
4234
|
-
},
|
|
4254
|
+
}, g = JSON.stringify(w), h = Be(), d = ae(h), p = {
|
|
4235
4255
|
kind: Zn,
|
|
4236
|
-
pubkey:
|
|
4237
|
-
content:
|
|
4256
|
+
pubkey: d,
|
|
4257
|
+
content: q.encrypt(g, Qe(h, this.inviterEphemeralPublicKey)),
|
|
4238
4258
|
created_at: lu(),
|
|
4239
4259
|
tags: [["p", this.inviterEphemeralPublicKey]]
|
|
4240
4260
|
};
|
|
4241
|
-
return { session:
|
|
4261
|
+
return { session: l, event: Q(p, h) };
|
|
4242
4262
|
}
|
|
4243
4263
|
listen(t, n, r) {
|
|
4244
4264
|
if (!this.inviterEphemeralPrivateKey)
|
|
@@ -4251,10 +4271,18 @@ class Pe {
|
|
|
4251
4271
|
try {
|
|
4252
4272
|
if (this.maxUses && this.usedBy.length >= this.maxUses)
|
|
4253
4273
|
return;
|
|
4254
|
-
const o = await
|
|
4274
|
+
const o = await q.decrypt(s.content, Qe(this.inviterEphemeralPrivateKey, s.pubkey)), c = JSON.parse(o), a = j(this.sharedSecret), l = c.pubkey;
|
|
4255
4275
|
this.usedBy.push(l);
|
|
4256
|
-
const f = await
|
|
4257
|
-
|
|
4276
|
+
const f = await q.decrypt(c.content, a), y = await (typeof t == "function" ? t : (p, m) => Promise.resolve(q.decrypt(p, Qe(t, m))))(f, l);
|
|
4277
|
+
let w, g;
|
|
4278
|
+
try {
|
|
4279
|
+
const p = JSON.parse(y);
|
|
4280
|
+
w = p.sessionKey, g = p.deviceId;
|
|
4281
|
+
} catch {
|
|
4282
|
+
w = y;
|
|
4283
|
+
}
|
|
4284
|
+
const h = s.id, d = ot.init(n, w, this.inviterEphemeralPrivateKey, !1, a, h);
|
|
4285
|
+
r(d, l, g);
|
|
4258
4286
|
} catch {
|
|
4259
4287
|
}
|
|
4260
4288
|
});
|
|
@@ -4262,7 +4290,7 @@ class Pe {
|
|
|
4262
4290
|
}
|
|
4263
4291
|
export {
|
|
4264
4292
|
iu as CHAT_MESSAGE_KIND,
|
|
4265
|
-
|
|
4293
|
+
Lt as INVITE_EVENT_KIND,
|
|
4266
4294
|
Zn as INVITE_RESPONSE_KIND,
|
|
4267
4295
|
Pe as Invite,
|
|
4268
4296
|
wu as MAX_SKIP,
|