nostr-double-ratchet 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Session.d.ts +2 -1
- package/dist/Session.d.ts.map +1 -1
- package/dist/nostr-double-ratchet.es.js +212 -203
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/package.json +1 -1
- package/src/Session.ts +13 -3
|
@@ -28,9 +28,9 @@ function mi(e, t) {
|
|
|
28
28
|
if (e.length < n)
|
|
29
29
|
throw new Error(`digestInto() expects output buffer of length at least ${n}`);
|
|
30
30
|
}
|
|
31
|
-
const
|
|
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 Vn = (e) => e instanceof Uint8Array,
|
|
33
|
+
const Vn = (e) => e instanceof Uint8Array, St = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), re = (e, t) => e << 32 - t | e >>> t, xi = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
34
34
|
if (!xi)
|
|
35
35
|
throw new Error("Non little-endian hardware is not supported");
|
|
36
36
|
function Si(e) {
|
|
@@ -38,7 +38,7 @@ function Si(e) {
|
|
|
38
38
|
throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
|
|
39
39
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function Zt(e) {
|
|
42
42
|
if (typeof e == "string" && (e = Si(e)), !Vn(e))
|
|
43
43
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
44
44
|
return e;
|
|
@@ -59,12 +59,12 @@ let Wn = class {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
function Ai(e) {
|
|
62
|
-
const t = (r) => e().update(
|
|
62
|
+
const t = (r) => e().update(Zt(r)).digest(), n = e();
|
|
63
63
|
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
64
64
|
}
|
|
65
65
|
function Zn(e = 32) {
|
|
66
|
-
if (
|
|
67
|
-
return
|
|
66
|
+
if (xt && typeof xt.getRandomValues == "function")
|
|
67
|
+
return xt.getRandomValues(new Uint8Array(e));
|
|
68
68
|
throw new Error("crypto.getRandomValues must be defined");
|
|
69
69
|
}
|
|
70
70
|
function Ki(e, t, n, r) {
|
|
@@ -75,17 +75,17 @@ function Ki(e, t, n, r) {
|
|
|
75
75
|
}
|
|
76
76
|
let Ci = class extends Wn {
|
|
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 = St(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 = Zt(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 = St(t);
|
|
89
89
|
for (; i <= s - o; o += i)
|
|
90
90
|
this.process(a, o);
|
|
91
91
|
continue;
|
|
@@ -102,7 +102,7 @@ let Ci = class extends Wn {
|
|
|
102
102
|
for (let u = o; u < i; u++)
|
|
103
103
|
n[u] = 0;
|
|
104
104
|
Ki(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
105
|
-
const c =
|
|
105
|
+
const c = St(t), a = this.outputLen;
|
|
106
106
|
if (a % 4)
|
|
107
107
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
108
108
|
const l = a / 4, f = this.get();
|
|
@@ -231,10 +231,10 @@ let Ui = class extends Ci {
|
|
|
231
231
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
|
|
232
232
|
}
|
|
233
233
|
};
|
|
234
|
-
const
|
|
234
|
+
const $t = /* @__PURE__ */ Ai(() => new Ui());
|
|
235
235
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
236
236
|
const Gn = BigInt(0), ot = BigInt(1), Ii = BigInt(2), at = (e) => e instanceof Uint8Array, Li = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
237
|
-
function
|
|
237
|
+
function De(e) {
|
|
238
238
|
if (!at(e))
|
|
239
239
|
throw new Error("Uint8Array expected");
|
|
240
240
|
let t = "";
|
|
@@ -246,12 +246,12 @@ function Fn(e) {
|
|
|
246
246
|
const t = e.toString(16);
|
|
247
247
|
return t.length & 1 ? `0${t}` : t;
|
|
248
248
|
}
|
|
249
|
-
function
|
|
249
|
+
function Gt(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}`);
|
|
253
253
|
}
|
|
254
|
-
function
|
|
254
|
+
function je(e) {
|
|
255
255
|
if (typeof e != "string")
|
|
256
256
|
throw new Error("hex string expected, got " + typeof e);
|
|
257
257
|
const t = e.length;
|
|
@@ -267,27 +267,27 @@ function De(e) {
|
|
|
267
267
|
return n;
|
|
268
268
|
}
|
|
269
269
|
function F(e) {
|
|
270
|
-
return
|
|
270
|
+
return Gt(De(e));
|
|
271
271
|
}
|
|
272
|
-
function
|
|
272
|
+
function Ft(e) {
|
|
273
273
|
if (!at(e))
|
|
274
274
|
throw new Error("Uint8Array expected");
|
|
275
|
-
return
|
|
275
|
+
return Gt(De(Uint8Array.from(e).reverse()));
|
|
276
276
|
}
|
|
277
277
|
function Ne(e, t) {
|
|
278
|
-
return
|
|
278
|
+
return je(e.toString(16).padStart(t * 2, "0"));
|
|
279
279
|
}
|
|
280
|
-
function
|
|
280
|
+
function Jt(e, t) {
|
|
281
281
|
return Ne(e, t).reverse();
|
|
282
282
|
}
|
|
283
283
|
function $i(e) {
|
|
284
|
-
return
|
|
284
|
+
return je(Fn(e));
|
|
285
285
|
}
|
|
286
286
|
function W(e, t, n) {
|
|
287
287
|
let r;
|
|
288
288
|
if (typeof t == "string")
|
|
289
289
|
try {
|
|
290
|
-
r =
|
|
290
|
+
r = je(t);
|
|
291
291
|
} catch (s) {
|
|
292
292
|
throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${s}`);
|
|
293
293
|
}
|
|
@@ -331,7 +331,7 @@ function Oi(e) {
|
|
|
331
331
|
function Mi(e, t) {
|
|
332
332
|
return e >> BigInt(t) & ot;
|
|
333
333
|
}
|
|
334
|
-
const Pi = (e, t, n) => e | (n ? ot : Gn) << BigInt(t),
|
|
334
|
+
const Pi = (e, t, n) => e | (n ? ot : Gn) << BigInt(t), Yt = (e) => (Ii << BigInt(e - 1)) - ot, Nt = (e) => new Uint8Array(e), Cn = (e) => Uint8Array.from(e);
|
|
335
335
|
function Jn(e, t, n) {
|
|
336
336
|
if (typeof e != "number" || e < 2)
|
|
337
337
|
throw new Error("hashLen must be a number");
|
|
@@ -339,10 +339,10 @@ function Jn(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 =
|
|
345
|
+
}, c = (...u) => n(i, r, ...u), a = (u = Nt()) => {
|
|
346
346
|
i = c(Cn([0]), u), r = c(), u.length !== 0 && (i = c(Cn([1]), u), r = c());
|
|
347
347
|
}, l = () => {
|
|
348
348
|
if (s++ >= 1e3)
|
|
@@ -394,26 +394,26 @@ const qi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
394
394
|
__proto__: null,
|
|
395
395
|
bitGet: Mi,
|
|
396
396
|
bitLen: Oi,
|
|
397
|
-
bitMask:
|
|
397
|
+
bitMask: Yt,
|
|
398
398
|
bitSet: Pi,
|
|
399
|
-
bytesToHex:
|
|
399
|
+
bytesToHex: De,
|
|
400
400
|
bytesToNumberBE: F,
|
|
401
|
-
bytesToNumberLE:
|
|
401
|
+
bytesToNumberLE: Ft,
|
|
402
402
|
concatBytes: Ue,
|
|
403
403
|
createHmacDrbg: Jn,
|
|
404
404
|
ensureBytes: W,
|
|
405
405
|
equalBytes: Ti,
|
|
406
|
-
hexToBytes:
|
|
407
|
-
hexToNumber:
|
|
406
|
+
hexToBytes: je,
|
|
407
|
+
hexToNumber: Gt,
|
|
408
408
|
numberToBytesBE: Ne,
|
|
409
|
-
numberToBytesLE:
|
|
409
|
+
numberToBytesLE: Jt,
|
|
410
410
|
numberToHexUnpadded: Fn,
|
|
411
411
|
numberToVarBytesBE: $i,
|
|
412
412
|
utf8ToBytes: Ri,
|
|
413
413
|
validateObject: Ye
|
|
414
414
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
415
415
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
416
|
-
const z = BigInt(0), j = BigInt(1), Ce = BigInt(2), Di = BigInt(3),
|
|
416
|
+
const z = BigInt(0), j = BigInt(1), Ce = BigInt(2), Di = BigInt(3), Tt = BigInt(4), Bn = BigInt(5), kn = BigInt(8);
|
|
417
417
|
BigInt(9);
|
|
418
418
|
BigInt(16);
|
|
419
419
|
function V(e, t) {
|
|
@@ -436,7 +436,7 @@ function J(e, t, n) {
|
|
|
436
436
|
r *= r, r %= n;
|
|
437
437
|
return r;
|
|
438
438
|
}
|
|
439
|
-
function
|
|
439
|
+
function Rt(e, t) {
|
|
440
440
|
if (e === z || t <= z)
|
|
441
441
|
throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);
|
|
442
442
|
let n = V(e, t), r = t, i = z, s = j;
|
|
@@ -456,7 +456,7 @@ function zi(e) {
|
|
|
456
456
|
for (i = Ce; i < e && ji(i, t, e) !== e - j; i++)
|
|
457
457
|
;
|
|
458
458
|
if (r === 1) {
|
|
459
|
-
const o = (e + j) /
|
|
459
|
+
const o = (e + j) / Tt;
|
|
460
460
|
return function(a, l) {
|
|
461
461
|
const f = a.pow(l, o);
|
|
462
462
|
if (!a.eql(a.sqr(f), l))
|
|
@@ -482,8 +482,8 @@ function zi(e) {
|
|
|
482
482
|
};
|
|
483
483
|
}
|
|
484
484
|
function Vi(e) {
|
|
485
|
-
if (e %
|
|
486
|
-
const t = (e + j) /
|
|
485
|
+
if (e % Tt === Di) {
|
|
486
|
+
const t = (e + j) / Tt;
|
|
487
487
|
return function(r, i) {
|
|
488
488
|
const s = r.pow(i, t);
|
|
489
489
|
if (!r.eql(r.sqr(s), i))
|
|
@@ -560,7 +560,7 @@ function Ji(e, t, n = !1, r = {}) {
|
|
|
560
560
|
ORDER: e,
|
|
561
561
|
BITS: i,
|
|
562
562
|
BYTES: s,
|
|
563
|
-
MASK:
|
|
563
|
+
MASK: Yt(i),
|
|
564
564
|
ZERO: z,
|
|
565
565
|
ONE: j,
|
|
566
566
|
create: (a) => V(a, e),
|
|
@@ -578,23 +578,23 @@ function Ji(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) => Gi(c, a, l),
|
|
581
|
-
div: (a, l) => V(a *
|
|
581
|
+
div: (a, l) => V(a * Rt(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) => Rt(a, e),
|
|
588
588
|
sqrt: r.sqrt || ((a) => o(c, a)),
|
|
589
589
|
invertBatch: (a) => Fi(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 ? Jt(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) : F(a);
|
|
598
598
|
}
|
|
599
599
|
});
|
|
600
600
|
return Object.freeze(c);
|
|
@@ -613,11 +613,11 @@ function Yi(e, t, n = !1) {
|
|
|
613
613
|
const r = e.length, i = Xn(t), s = Qn(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 ? F(e) :
|
|
617
|
-
return n ?
|
|
616
|
+
const o = n ? F(e) : Ft(e), c = V(o, t - j) + j;
|
|
617
|
+
return n ? Jt(c, i) : Ne(c, i);
|
|
618
618
|
}
|
|
619
619
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
620
|
-
const Xi = BigInt(0),
|
|
620
|
+
const Xi = BigInt(0), At = BigInt(1);
|
|
621
621
|
function Qi(e, t) {
|
|
622
622
|
const n = (i, s) => {
|
|
623
623
|
const o = s.negate();
|
|
@@ -632,7 +632,7 @@ function Qi(e, t) {
|
|
|
632
632
|
unsafeLadder(i, s) {
|
|
633
633
|
let o = e.ZERO, c = i;
|
|
634
634
|
for (; s > Xi; )
|
|
635
|
-
s &
|
|
635
|
+
s & At && (o = o.add(c)), c = c.double(), s >>= At;
|
|
636
636
|
return o;
|
|
637
637
|
},
|
|
638
638
|
/**
|
|
@@ -670,7 +670,7 @@ function Qi(e, t) {
|
|
|
670
670
|
for (let p = 0; p < c; p++) {
|
|
671
671
|
const h = p * a;
|
|
672
672
|
let d = Number(o & u);
|
|
673
|
-
o >>= b, d > a && (d -= g, o +=
|
|
673
|
+
o >>= b, d > a && (d -= g, o += At);
|
|
674
674
|
const y = h, m = h + Math.abs(d) - 1, A = p % 2 !== 0, U = d < 0;
|
|
675
675
|
d === 0 ? f = f.add(n(A, s[y])) : l = l.add(n(U, s[m]));
|
|
676
676
|
}
|
|
@@ -791,7 +791,7 @@ function rs(e) {
|
|
|
791
791
|
function a(p) {
|
|
792
792
|
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey: y, n: m } = t;
|
|
793
793
|
if (h && typeof p != "bigint") {
|
|
794
|
-
if (p instanceof Uint8Array && (p =
|
|
794
|
+
if (p instanceof Uint8Array && (p = De(p)), typeof p != "string" || !h.includes(p.length))
|
|
795
795
|
throw new Error("Invalid key");
|
|
796
796
|
p = p.padStart(d * 2, "0");
|
|
797
797
|
}
|
|
@@ -1012,7 +1012,7 @@ function rs(e) {
|
|
|
1012
1012
|
return this.assertValidity(), r(u, this, h);
|
|
1013
1013
|
}
|
|
1014
1014
|
toHex(h = !0) {
|
|
1015
|
-
return
|
|
1015
|
+
return De(this.toRawBytes(h));
|
|
1016
1016
|
}
|
|
1017
1017
|
}
|
|
1018
1018
|
u.BASE = new u(t.Gx, t.Gy, n.ONE), u.ZERO = new u(n.ZERO, n.ONE, n.ZERO);
|
|
@@ -1046,7 +1046,7 @@ function ss(e) {
|
|
|
1046
1046
|
return V(w, r);
|
|
1047
1047
|
}
|
|
1048
1048
|
function a(w) {
|
|
1049
|
-
return
|
|
1049
|
+
return Rt(w, r);
|
|
1050
1050
|
}
|
|
1051
1051
|
const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: g } = rs({
|
|
1052
1052
|
...t,
|
|
@@ -1070,7 +1070,7 @@ function ss(e) {
|
|
|
1070
1070
|
} else
|
|
1071
1071
|
throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`);
|
|
1072
1072
|
}
|
|
1073
|
-
}), b = (w) =>
|
|
1073
|
+
}), b = (w) => De(Ne(w, t.nByteLength));
|
|
1074
1074
|
function p(w) {
|
|
1075
1075
|
const v = r >> Y;
|
|
1076
1076
|
return w > v;
|
|
@@ -1110,7 +1110,7 @@ function ss(e) {
|
|
|
1110
1110
|
const O = C === 2 || C === 3 ? N + t.n : N;
|
|
1111
1111
|
if (O >= n.ORDER)
|
|
1112
1112
|
throw new Error("recovery id 2 or 3 invalid");
|
|
1113
|
-
const $ = C & 1 ? "03" : "02", Q = l.fromHex($ + b(O)), ge = a(O), Le = c(-I * ge),
|
|
1113
|
+
const $ = C & 1 ? "03" : "02", Q = l.fromHex($ + b(O)), ge = a(O), Le = c(-I * ge), We = c(k * ge), we = l.BASE.multiplyAndAddUnsafe(Q, Le, We);
|
|
1114
1114
|
if (!we)
|
|
1115
1115
|
throw new Error("point at infinify");
|
|
1116
1116
|
return we.assertValidity(), we;
|
|
@@ -1124,14 +1124,14 @@ function ss(e) {
|
|
|
1124
1124
|
}
|
|
1125
1125
|
// DER-encoded
|
|
1126
1126
|
toDERRawBytes() {
|
|
1127
|
-
return
|
|
1127
|
+
return je(this.toDERHex());
|
|
1128
1128
|
}
|
|
1129
1129
|
toDERHex() {
|
|
1130
1130
|
return ke.hexFromSig({ r: this.r, s: this.s });
|
|
1131
1131
|
}
|
|
1132
1132
|
// padded bytes of r, then padded bytes of s
|
|
1133
1133
|
toCompactRawBytes() {
|
|
1134
|
-
return
|
|
1134
|
+
return je(this.toCompactHex());
|
|
1135
1135
|
}
|
|
1136
1136
|
toCompactHex() {
|
|
1137
1137
|
return b(this.r) + b(this.s);
|
|
@@ -1185,7 +1185,7 @@ function ss(e) {
|
|
|
1185
1185
|
return N > 0 ? v >> BigInt(N) : v;
|
|
1186
1186
|
}, x = t.bits2int_modN || function(w) {
|
|
1187
1187
|
return c(E(w));
|
|
1188
|
-
}, S =
|
|
1188
|
+
}, S = Yt(t.nBitLength);
|
|
1189
1189
|
function P(w) {
|
|
1190
1190
|
if (typeof w != "bigint")
|
|
1191
1191
|
throw new Error("bigint expected");
|
|
@@ -1204,8 +1204,8 @@ function ss(e) {
|
|
|
1204
1204
|
const Ke = $ === !0 ? C(n.BYTES) : $;
|
|
1205
1205
|
Le.push(W("extraEntropy", Ke));
|
|
1206
1206
|
}
|
|
1207
|
-
const
|
|
1208
|
-
function
|
|
1207
|
+
const We = Ue(...Le), we = Q;
|
|
1208
|
+
function mt(Ke) {
|
|
1209
1209
|
const $e = E(Ke);
|
|
1210
1210
|
if (!g($e))
|
|
1211
1211
|
return;
|
|
@@ -1218,7 +1218,7 @@ function ss(e) {
|
|
|
1218
1218
|
let Nn = (Te.x === ee ? 0 : 2) | Number(Te.y & Y), An = Re;
|
|
1219
1219
|
return I && p(Re) && (An = h(Re), Nn ^= 1), new y(ee, An, Nn);
|
|
1220
1220
|
}
|
|
1221
|
-
return { seed:
|
|
1221
|
+
return { seed: We, k2sig: mt };
|
|
1222
1222
|
}
|
|
1223
1223
|
const K = { lowS: t.lowS, prehash: !1 }, T = { lowS: t.lowS, prehash: !1 };
|
|
1224
1224
|
function R(w, v, N = K) {
|
|
@@ -1256,7 +1256,7 @@ function ss(e) {
|
|
|
1256
1256
|
if (I && $.hasHighS())
|
|
1257
1257
|
return !1;
|
|
1258
1258
|
O && (v = t.hash(v));
|
|
1259
|
-
const { r: ge, s: Le } = $,
|
|
1259
|
+
const { r: ge, s: Le } = $, We = x(v), we = a(Le), mt = c(We * we), Ke = c(ge * we), $e = (Te = l.BASE.multiplyAndAddUnsafe(Q, mt, Ke)) == null ? void 0 : Te.toAffine();
|
|
1260
1260
|
return $e ? c($e.x) === ge : !1;
|
|
1261
1261
|
}
|
|
1262
1262
|
return {
|
|
@@ -1273,7 +1273,7 @@ function ss(e) {
|
|
|
1273
1273
|
let tr = class extends Wn {
|
|
1274
1274
|
constructor(t, n) {
|
|
1275
1275
|
super(), this.finished = !1, this.destroyed = !1, Ei(t);
|
|
1276
|
-
const r =
|
|
1276
|
+
const r = Zt(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;
|
|
@@ -1323,14 +1323,14 @@ function as(e, t) {
|
|
|
1323
1323
|
const ct = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), tt = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), rr = BigInt(1), nt = BigInt(2), Un = (e, t) => (e + t / nt) / t;
|
|
1324
1324
|
function ir(e) {
|
|
1325
1325
|
const t = ct, n = BigInt(3), r = BigInt(6), i = BigInt(11), s = BigInt(22), o = BigInt(23), c = BigInt(44), a = BigInt(88), l = e * e * e % t, f = l * l * e % t, u = J(f, n, t) * f % t, g = J(u, n, t) * f % t, b = J(g, nt, t) * l % t, p = J(b, i, t) * b % t, h = J(p, s, t) * p % t, d = J(h, c, t) * h % t, y = J(d, a, t) * d % t, m = J(y, c, t) * h % t, A = J(m, n, t) * f % t, U = J(A, o, t) * p % t, B = J(U, r, t) * l % t, E = J(B, nt, t);
|
|
1326
|
-
if (!
|
|
1326
|
+
if (!Ot.eql(Ot.sqr(E), e))
|
|
1327
1327
|
throw new Error("Cannot find square root");
|
|
1328
1328
|
return E;
|
|
1329
1329
|
}
|
|
1330
|
-
const
|
|
1330
|
+
const Ot = Ji(ct, void 0, void 0, { sqrt: ir }), Ie = as({
|
|
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"),
|
|
@@ -1354,41 +1354,41 @@ const Rt = Ji(ct, void 0, void 0, { sqrt: ir }), Ie = as({
|
|
|
1354
1354
|
return { k1neg: u, k1: l, k2neg: g, k2: f };
|
|
1355
1355
|
}
|
|
1356
1356
|
}
|
|
1357
|
-
},
|
|
1357
|
+
}, $t), ut = BigInt(0), sr = (e) => typeof e == "bigint" && ut < e && e < ct, cs = (e) => typeof e == "bigint" && ut < e && e < tt, In = {};
|
|
1358
1358
|
function rt(e, ...t) {
|
|
1359
1359
|
let n = In[e];
|
|
1360
1360
|
if (n === void 0) {
|
|
1361
|
-
const r =
|
|
1361
|
+
const r = $t(Uint8Array.from(e, (i) => i.charCodeAt(0)));
|
|
1362
1362
|
n = Ue(r, r), In[e] = n;
|
|
1363
1363
|
}
|
|
1364
|
-
return
|
|
1364
|
+
return $t(Ue(n, ...t));
|
|
1365
1365
|
}
|
|
1366
|
-
const
|
|
1367
|
-
function
|
|
1368
|
-
let t = Ie.utils.normPrivateKeyToScalar(e), n =
|
|
1369
|
-
return { scalar: n.hasEvenY() ? t : Fe(-t), bytes:
|
|
1366
|
+
const Xt = (e) => e.toRawBytes(!0).slice(1), Mt = (e) => Ne(e, 32), Kt = (e) => V(e, ct), Fe = (e) => V(e, tt), Qt = Ie.ProjectivePoint, us = (e, t, n) => Qt.BASE.multiplyAndAddUnsafe(e, t, n);
|
|
1367
|
+
function Pt(e) {
|
|
1368
|
+
let t = Ie.utils.normPrivateKeyToScalar(e), n = Qt.fromPrivateKey(t);
|
|
1369
|
+
return { scalar: n.hasEvenY() ? t : Fe(-t), bytes: Xt(n) };
|
|
1370
1370
|
}
|
|
1371
1371
|
function or(e) {
|
|
1372
1372
|
if (!sr(e))
|
|
1373
1373
|
throw new Error("bad x: need 0 < x < p");
|
|
1374
|
-
const t =
|
|
1374
|
+
const t = Kt(e * e), n = Kt(t * e + BigInt(7));
|
|
1375
1375
|
let r = ir(n);
|
|
1376
|
-
r % nt !== ut && (r =
|
|
1377
|
-
const i = new
|
|
1376
|
+
r % nt !== ut && (r = Kt(-r));
|
|
1377
|
+
const i = new Qt(e, r, rr);
|
|
1378
1378
|
return i.assertValidity(), i;
|
|
1379
1379
|
}
|
|
1380
1380
|
function ar(...e) {
|
|
1381
1381
|
return Fe(F(rt("BIP0340/challenge", ...e)));
|
|
1382
1382
|
}
|
|
1383
1383
|
function ls(e) {
|
|
1384
|
-
return
|
|
1384
|
+
return Pt(e).bytes;
|
|
1385
1385
|
}
|
|
1386
1386
|
function fs(e, t, n = Zn(32)) {
|
|
1387
|
-
const r = W("message", e), { bytes: i, scalar: s } =
|
|
1387
|
+
const r = W("message", e), { bytes: i, scalar: s } = Pt(t), o = W("auxRand", n, 32), c = Mt(s ^ F(rt("BIP0340/aux", o))), a = rt("BIP0340/nonce", c, i, r), l = Fe(F(a));
|
|
1388
1388
|
if (l === ut)
|
|
1389
1389
|
throw new Error("sign failed: k is zero");
|
|
1390
|
-
const { bytes: f, scalar: u } =
|
|
1391
|
-
if (b.set(f, 0), b.set(
|
|
1390
|
+
const { bytes: f, scalar: u } = Pt(l), g = ar(f, i, r), b = new Uint8Array(64);
|
|
1391
|
+
if (b.set(f, 0), b.set(Mt(Fe(u + g * s)), 32), !cr(b, r, i))
|
|
1392
1392
|
throw new Error("sign: Invalid signature produced");
|
|
1393
1393
|
return b;
|
|
1394
1394
|
}
|
|
@@ -1401,33 +1401,33 @@ function cr(e, t, n) {
|
|
|
1401
1401
|
const a = F(r.subarray(32, 64));
|
|
1402
1402
|
if (!cs(a))
|
|
1403
1403
|
return !1;
|
|
1404
|
-
const l = ar(
|
|
1404
|
+
const l = ar(Mt(c), Xt(o), i), f = us(o, a, Fe(-l));
|
|
1405
1405
|
return !(!f || !f.hasEvenY() || f.toAffine().x !== c);
|
|
1406
1406
|
} catch {
|
|
1407
1407
|
return !1;
|
|
1408
1408
|
}
|
|
1409
1409
|
}
|
|
1410
|
-
const
|
|
1410
|
+
const Ze = {
|
|
1411
1411
|
getPublicKey: ls,
|
|
1412
1412
|
sign: fs,
|
|
1413
1413
|
verify: cr,
|
|
1414
1414
|
utils: {
|
|
1415
1415
|
randomPrivateKey: Ie.utils.randomPrivateKey,
|
|
1416
1416
|
lift_x: or,
|
|
1417
|
-
pointToBytes:
|
|
1417
|
+
pointToBytes: Xt,
|
|
1418
1418
|
numberToBytesBE: Ne,
|
|
1419
1419
|
bytesToNumberBE: F,
|
|
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 en = (e) => e instanceof Uint8Array, Bt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), ie = (e, t) => e << 32 - t | e >>> t, hs = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1426
1426
|
if (!hs)
|
|
1427
1427
|
throw new Error("Non little-endian hardware is not supported");
|
|
1428
1428
|
const ds = Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
1429
1429
|
function M(e) {
|
|
1430
|
-
if (!
|
|
1430
|
+
if (!en(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 ps(e) {
|
|
|
1455
1455
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
1456
1456
|
}
|
|
1457
1457
|
function Je(e) {
|
|
1458
|
-
if (typeof e == "string" && (e = ps(e)), !
|
|
1458
|
+
if (typeof e == "string" && (e = ps(e)), !en(e))
|
|
1459
1459
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
1460
1460
|
return e;
|
|
1461
1461
|
}
|
|
@@ -1463,7 +1463,7 @@ function lt(...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 (!en(r))
|
|
1467
1467
|
throw new Error("Uint8Array expected");
|
|
1468
1468
|
t.set(r, n), n += r.length;
|
|
1469
1469
|
}), t;
|
|
@@ -1479,11 +1479,11 @@ function lr(e) {
|
|
|
1479
1479
|
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
1480
1480
|
}
|
|
1481
1481
|
function fr(e = 32) {
|
|
1482
|
-
if (
|
|
1483
|
-
return
|
|
1482
|
+
if (Ct && typeof Ct.getRandomValues == "function")
|
|
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 hr(e, ...t) {
|
|
|
1500
1500
|
function gs(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 ws(e, t = !0) {
|
|
1506
1506
|
if (e.destroyed)
|
|
@@ -1515,7 +1515,7 @@ function bs(e, t) {
|
|
|
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: ys,
|
|
1520
1520
|
bytes: hr,
|
|
1521
1521
|
hash: gs,
|
|
@@ -1530,7 +1530,7 @@ function vs(e, t, n, r) {
|
|
|
1530
1530
|
}
|
|
1531
1531
|
class Es extends ur {
|
|
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 = Bt(this.buffer);
|
|
1534
1534
|
}
|
|
1535
1535
|
update(t) {
|
|
1536
1536
|
se.exists(this);
|
|
@@ -1540,7 +1540,7 @@ class Es extends ur {
|
|
|
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 = Bt(t);
|
|
1544
1544
|
for (; i <= s - o; o += i)
|
|
1545
1545
|
this.process(a, o);
|
|
1546
1546
|
continue;
|
|
@@ -1557,7 +1557,7 @@ class Es extends ur {
|
|
|
1557
1557
|
for (let u = o; u < i; u++)
|
|
1558
1558
|
n[u] = 0;
|
|
1559
1559
|
vs(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
1560
|
-
const c =
|
|
1560
|
+
const c = Bt(t), a = this.outputLen;
|
|
1561
1561
|
if (a % 4)
|
|
1562
1562
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
1563
1563
|
const l = a / 4, f = this.get();
|
|
@@ -1694,7 +1694,7 @@ class Ns extends dr {
|
|
|
1694
1694
|
const fe = lr(() => new dr());
|
|
1695
1695
|
lr(() => new Ns());
|
|
1696
1696
|
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1697
|
-
function
|
|
1697
|
+
function Ve(e) {
|
|
1698
1698
|
if (!Number.isSafeInteger(e))
|
|
1699
1699
|
throw new Error(`Wrong integer: ${e}`);
|
|
1700
1700
|
}
|
|
@@ -1708,7 +1708,7 @@ function pe(e) {
|
|
|
1708
1708
|
if (!Array.isArray(t) || t.length && typeof t[0] != "number")
|
|
1709
1709
|
throw new Error("alphabet.encode input should be an array of numbers");
|
|
1710
1710
|
return t.map((n) => {
|
|
1711
|
-
if (
|
|
1711
|
+
if (Ve(n), n < 0 || n >= e.length)
|
|
1712
1712
|
throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${e.length})`);
|
|
1713
1713
|
return e[n];
|
|
1714
1714
|
});
|
|
@@ -1747,7 +1747,7 @@ function ye(e = "") {
|
|
|
1747
1747
|
};
|
|
1748
1748
|
}
|
|
1749
1749
|
function ft(e, t = "=") {
|
|
1750
|
-
if (
|
|
1750
|
+
if (Ve(e), typeof t != "string")
|
|
1751
1751
|
throw new Error("padding chr should be string");
|
|
1752
1752
|
return {
|
|
1753
1753
|
encode(n) {
|
|
@@ -1793,7 +1793,7 @@ function Ln(e, t, n) {
|
|
|
1793
1793
|
let r = 0;
|
|
1794
1794
|
const i = [], s = Array.from(e);
|
|
1795
1795
|
for (s.forEach((o) => {
|
|
1796
|
-
if (
|
|
1796
|
+
if (Ve(o), o < 0 || o >= t)
|
|
1797
1797
|
throw new Error(`Wrong integer: ${o}`);
|
|
1798
1798
|
}); ; ) {
|
|
1799
1799
|
let o = 0, c = !0;
|
|
@@ -1815,7 +1815,7 @@ function Ln(e, t, n) {
|
|
|
1815
1815
|
return i.reverse();
|
|
1816
1816
|
}
|
|
1817
1817
|
const yr = (e, t) => t ? yr(t, e % t) : e, it = (e, t) => e + (t - yr(e, t));
|
|
1818
|
-
function
|
|
1818
|
+
function qt(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)
|
|
@@ -1827,7 +1827,7 @@ function Ht(e, t, n, r) {
|
|
|
1827
1827
|
let i = 0, s = 0;
|
|
1828
1828
|
const o = 2 ** n - 1, c = [];
|
|
1829
1829
|
for (const a of e) {
|
|
1830
|
-
if (
|
|
1830
|
+
if (Ve(a), a >= 2 ** t)
|
|
1831
1831
|
throw new Error(`convertRadix2: invalid data word=${a} from=${t}`);
|
|
1832
1832
|
if (i = i << t | a, s + t > 32)
|
|
1833
1833
|
throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);
|
|
@@ -1842,7 +1842,7 @@ function Ht(e, t, n, r) {
|
|
|
1842
1842
|
return r && s > 0 && c.push(i >>> 0), c;
|
|
1843
1843
|
}
|
|
1844
1844
|
function As(e) {
|
|
1845
|
-
return
|
|
1845
|
+
return Ve(e), {
|
|
1846
1846
|
encode: (t) => {
|
|
1847
1847
|
if (!(t instanceof Uint8Array))
|
|
1848
1848
|
throw new Error("radix.encode input should be Uint8Array");
|
|
@@ -1856,7 +1856,7 @@ function As(e) {
|
|
|
1856
1856
|
};
|
|
1857
1857
|
}
|
|
1858
1858
|
function Ae(e, t = !1) {
|
|
1859
|
-
if (
|
|
1859
|
+
if (Ve(e), e <= 0 || e > 32)
|
|
1860
1860
|
throw new Error("radix2: bits should be in (0..32]");
|
|
1861
1861
|
if (it(8, e) > 32 || it(e, 8) > 32)
|
|
1862
1862
|
throw new Error("radix2: carry overflow");
|
|
@@ -1864,12 +1864,12 @@ function Ae(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 qt(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(qt(n, e, 8, t));
|
|
1873
1873
|
}
|
|
1874
1874
|
};
|
|
1875
1875
|
}
|
|
@@ -1886,22 +1886,22 @@ function $n(e) {
|
|
|
1886
1886
|
const Ks = de(Ae(4), pe("0123456789ABCDEF"), ye("")), Cs = de(Ae(5), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), ft(5), ye(""));
|
|
1887
1887
|
de(Ae(5), pe("0123456789ABCDEFGHIJKLMNOPQRSTUV"), ft(5), ye(""));
|
|
1888
1888
|
de(Ae(5), pe("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), ye(""), pr((e) => e.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
1889
|
-
const he = de(Ae(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), ft(6), ye("")), Bs = de(Ae(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), ft(6), ye("")),
|
|
1890
|
-
|
|
1891
|
-
|
|
1889
|
+
const he = de(Ae(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), ft(6), ye("")), Bs = de(Ae(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), ft(6), ye("")), tn = (e) => de(As(58), pe(e), ye("")), Dt = tn("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
1890
|
+
tn("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
|
|
1891
|
+
tn("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");
|
|
1892
1892
|
const Tn = [0, 2, 3, 5, 6, 7, 9, 10, 11], ks = {
|
|
1893
1893
|
encode(e) {
|
|
1894
1894
|
let t = "";
|
|
1895
1895
|
for (let n = 0; n < e.length; n += 8) {
|
|
1896
1896
|
const r = e.subarray(n, n + 8);
|
|
1897
|
-
t +=
|
|
1897
|
+
t += Dt.encode(r).padStart(Tn[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 = Tn.indexOf(r.length), s =
|
|
1904
|
+
const r = e.slice(n, n + 11), i = Tn.indexOf(r.length), s = Dt.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,8 +1909,8 @@ const Tn = [0, 2, 3, 5, 6, 7, 9, 10, 11], ks = {
|
|
|
1909
1909
|
}
|
|
1910
1910
|
return Uint8Array.from(t);
|
|
1911
1911
|
}
|
|
1912
|
-
},
|
|
1913
|
-
function
|
|
1912
|
+
}, jt = de(pe("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), ye("")), Rn = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
1913
|
+
function Ge(e) {
|
|
1914
1914
|
const t = e >> 25;
|
|
1915
1915
|
let n = (e & 33554431) << 5;
|
|
1916
1916
|
for (let r = 0; r < Rn.length; r++)
|
|
@@ -1924,16 +1924,16 @@ function On(e, t, n = 1) {
|
|
|
1924
1924
|
const o = e.charCodeAt(s);
|
|
1925
1925
|
if (o < 33 || o > 126)
|
|
1926
1926
|
throw new Error(`Invalid prefix (${e})`);
|
|
1927
|
-
i =
|
|
1927
|
+
i = Ge(i) ^ o >> 5;
|
|
1928
1928
|
}
|
|
1929
|
-
i =
|
|
1929
|
+
i = Ge(i);
|
|
1930
1930
|
for (let s = 0; s < r; s++)
|
|
1931
|
-
i =
|
|
1931
|
+
i = Ge(i) ^ e.charCodeAt(s) & 31;
|
|
1932
1932
|
for (let s of t)
|
|
1933
|
-
i =
|
|
1933
|
+
i = Ge(i) ^ s;
|
|
1934
1934
|
for (let s = 0; s < 6; s++)
|
|
1935
|
-
i =
|
|
1936
|
-
return i ^= n,
|
|
1935
|
+
i = Ge(i);
|
|
1936
|
+
return i ^= n, jt.encode(qt([i % 2 ** 30], 30, 5, !1));
|
|
1937
1937
|
}
|
|
1938
1938
|
function gr(e) {
|
|
1939
1939
|
const t = e === "bech32" ? 1 : 734539939, n = Ae(5), r = n.decode, i = n.encode, s = $n(r);
|
|
@@ -1945,7 +1945,7 @@ function gr(e) {
|
|
|
1945
1945
|
const b = f.length + 7 + u.length;
|
|
1946
1946
|
if (g !== !1 && b > g)
|
|
1947
1947
|
throw new TypeError(`Length ${b} exceeds limit ${g}`);
|
|
1948
|
-
return f = f.toLowerCase(), `${f}1${
|
|
1948
|
+
return f = f.toLowerCase(), `${f}1${jt.encode(u)}${On(f, u, t)}`;
|
|
1949
1949
|
}
|
|
1950
1950
|
function c(f, u = 90) {
|
|
1951
1951
|
if (typeof f != "string")
|
|
@@ -1962,7 +1962,7 @@ function gr(e) {
|
|
|
1962
1962
|
const p = f.slice(0, b), h = f.slice(b + 1);
|
|
1963
1963
|
if (h.length < 6)
|
|
1964
1964
|
throw new Error("Data must be at least 6 characters long");
|
|
1965
|
-
const d =
|
|
1965
|
+
const d = jt.decode(h).slice(0, -6), y = On(p, d, t);
|
|
1966
1966
|
if (!h.endsWith(y))
|
|
1967
1967
|
throw new Error(`Invalid checksum in ${f}: expected "${y}"`);
|
|
1968
1968
|
return { prefix: p, words: d };
|
|
@@ -1974,7 +1974,7 @@ function gr(e) {
|
|
|
1974
1974
|
}
|
|
1975
1975
|
return { encode: o, decode: c, decodeToBytes: l, decodeUnsafe: a, fromWords: r, fromWordsUnsafe: s, toWords: i };
|
|
1976
1976
|
}
|
|
1977
|
-
const
|
|
1977
|
+
const ze = gr("bech32");
|
|
1978
1978
|
gr("bech32m");
|
|
1979
1979
|
const _s = {
|
|
1980
1980
|
encode: (e) => new TextDecoder().decode(e),
|
|
@@ -1990,11 +1990,11 @@ const _s = {
|
|
|
1990
1990
|
base32: Cs,
|
|
1991
1991
|
base64: he,
|
|
1992
1992
|
base64url: Bs,
|
|
1993
|
-
base58:
|
|
1993
|
+
base58: Dt,
|
|
1994
1994
|
base58xmr: ks
|
|
1995
1995
|
};
|
|
1996
1996
|
`${Object.keys(Is).join(", ")}`;
|
|
1997
|
-
function
|
|
1997
|
+
function kt(e) {
|
|
1998
1998
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
1999
1999
|
throw new Error(`positive integer expected, not ${e}`);
|
|
2000
2000
|
}
|
|
@@ -2029,18 +2029,18 @@ function Rs(e, t) {
|
|
|
2029
2029
|
return n === 0;
|
|
2030
2030
|
}
|
|
2031
2031
|
const Os = /* @__NO_SIDE_EFFECTS__ */ (e, t) => (Object.assign(t, e), t), Se = 16, Ms = 283;
|
|
2032
|
-
function
|
|
2032
|
+
function nn(e) {
|
|
2033
2033
|
return e << 1 ^ Ms & -(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 = nn(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 ^= nn(r))
|
|
2044
2044
|
e[n] = r;
|
|
2045
2045
|
const t = new Uint8Array(256);
|
|
2046
2046
|
t[0] = 99;
|
|
@@ -2049,11 +2049,11 @@ const jt = /* @__PURE__ */ (() => {
|
|
|
2049
2049
|
r |= r << 8, t[e[n]] = (r ^ r >> 4 ^ r >> 5 ^ r >> 6 ^ r >> 7 ^ 99) & 255;
|
|
2050
2050
|
}
|
|
2051
2051
|
return t;
|
|
2052
|
-
})(), Ps = /* @__PURE__ */
|
|
2052
|
+
})(), Ps = /* @__PURE__ */ zt.map((e, t) => zt.indexOf(t)), Hs = (e) => e << 24 | e >>> 8, _t = (e) => e << 8 | e >>> 24;
|
|
2053
2053
|
function wr(e, t) {
|
|
2054
2054
|
if (e.length !== 256)
|
|
2055
2055
|
throw new Error("Wrong sbox length");
|
|
2056
|
-
const n = new Uint32Array(256).map((l, f) => t(e[f])), r = n.map(
|
|
2056
|
+
const n = new Uint32Array(256).map((l, f) => t(e[f])), r = n.map(_t), i = r.map(_t), s = i.map(_t), o = new Uint32Array(256 * 256), c = new Uint32Array(256 * 256), a = new Uint16Array(256 * 256);
|
|
2057
2057
|
for (let l = 0; l < 256; l++)
|
|
2058
2058
|
for (let f = 0; f < 256; f++) {
|
|
2059
2059
|
const u = l * 256 + f;
|
|
@@ -2061,9 +2061,9 @@ function wr(e, t) {
|
|
|
2061
2061
|
}
|
|
2062
2062
|
return { sbox: e, sbox2: a, T0: n, T1: r, T2: i, T3: s, T01: o, T23: c };
|
|
2063
2063
|
}
|
|
2064
|
-
const
|
|
2064
|
+
const rn = /* @__PURE__ */ wr(zt, (e) => He(e, 3) << 24 | e << 16 | e << 8 | He(e, 2)), br = /* @__PURE__ */ wr(Ps, (e) => He(e, 11) << 24 | He(e, 13) << 16 | He(e, 9) << 8 | He(e, 14)), qs = /* @__PURE__ */ (() => {
|
|
2065
2065
|
const e = new Uint8Array(16);
|
|
2066
|
-
for (let t = 0, n = 1; t < 16; t++, n =
|
|
2066
|
+
for (let t = 0, n = 1; t < 16; t++, n = nn(n))
|
|
2067
2067
|
e[t] = n;
|
|
2068
2068
|
return e;
|
|
2069
2069
|
})();
|
|
@@ -2072,7 +2072,7 @@ function vr(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 } = rn, r = Z(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 vr(e) {
|
|
|
2081
2081
|
return o;
|
|
2082
2082
|
}
|
|
2083
2083
|
function Ds(e) {
|
|
2084
|
-
const t = vr(e), n = t.slice(), r = t.length, { sbox2: i } =
|
|
2084
|
+
const t = vr(e), n = t.slice(), r = t.length, { sbox2: i } = rn, { T0: s, T1: o, T2: c, T3: a } = br;
|
|
2085
2085
|
for (let l = 0; l < r; l += 4)
|
|
2086
2086
|
for (let f = 0; f < 4; f++)
|
|
2087
2087
|
n[l + f] = t[r - l - 4 + f];
|
|
@@ -2099,7 +2099,7 @@ function oe(e, t, n, r, i) {
|
|
|
2099
2099
|
return e[t & 255 | n & 65280] | e[r >>> 16 & 255 | i >>> 16 & 65280] << 16;
|
|
2100
2100
|
}
|
|
2101
2101
|
function Pn(e, t, n, r, i) {
|
|
2102
|
-
const { sbox2: s, T01: o, T23: c } =
|
|
2102
|
+
const { sbox2: s, T01: o, T23: c } = rn;
|
|
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;
|
|
@@ -2202,12 +2202,12 @@ Sr.slice();
|
|
|
2202
2202
|
function L(e, t) {
|
|
2203
2203
|
return e << t | e >>> 32 - t;
|
|
2204
2204
|
}
|
|
2205
|
-
function
|
|
2205
|
+
function Vt(e) {
|
|
2206
2206
|
return e.byteOffset % 4 === 0;
|
|
2207
2207
|
}
|
|
2208
2208
|
const Xe = 64, Ys = 16, Nr = 2 ** 32 - 1, Hn = new Uint32Array();
|
|
2209
2209
|
function Xs(e, t, n, r, i, s, o, c) {
|
|
2210
|
-
const a = i.length, l = new Uint8Array(Xe), f = Z(l), u =
|
|
2210
|
+
const a = i.length, l = new Uint8Array(Xe), f = Z(l), u = Vt(i) && Vt(s), g = u ? Z(i) : Hn, b = u ? Z(s) : Hn;
|
|
2211
2211
|
for (let p = 0; p < a; o++) {
|
|
2212
2212
|
if (e(t, n, r, f, o, c), o >= Nr)
|
|
2213
2213
|
throw new Error("arx: counter overflow");
|
|
@@ -2230,10 +2230,10 @@ function Qs(e, t) {
|
|
|
2230
2230
|
const { allowShortKeys: n, extendNonceFn: r, counterLength: i, counterRight: s, rounds: o } = Ts({ allowShortKeys: !1, counterLength: 8, counterRight: !1, rounds: 20 }, t);
|
|
2231
2231
|
if (typeof e != "function")
|
|
2232
2232
|
throw new Error("core must be a function");
|
|
2233
|
-
return
|
|
2233
|
+
return kt(i), kt(o), Mn(s), Mn(n), (c, a, l, f, u = 0) => {
|
|
2234
2234
|
ce(c), ce(a), ce(l);
|
|
2235
2235
|
const g = l.length;
|
|
2236
|
-
if (f || (f = new Uint8Array(g)), ce(f),
|
|
2236
|
+
if (f || (f = new Uint8Array(g)), ce(f), kt(u), u < 0 || u >= Nr)
|
|
2237
2237
|
throw new Error("arx: counter overflow");
|
|
2238
2238
|
if (f.length < g)
|
|
2239
2239
|
throw new Error(`arx: output (${f.length}) is shorter than data (${g})`);
|
|
@@ -2245,7 +2245,7 @@ function Qs(e, t) {
|
|
|
2245
2245
|
h = new Uint8Array(32), h.set(c), h.set(c, 16), d = Js, b.push(h);
|
|
2246
2246
|
else
|
|
2247
2247
|
throw new Error(`arx: invalid 32-byte key, got length=${p}`);
|
|
2248
|
-
|
|
2248
|
+
Vt(a) || (a = a.slice(), b.push(a));
|
|
2249
2249
|
const y = Z(h);
|
|
2250
2250
|
if (r) {
|
|
2251
2251
|
if (a.length !== 24)
|
|
@@ -2314,10 +2314,10 @@ class Kr extends ur {
|
|
|
2314
2314
|
}
|
|
2315
2315
|
const ht = (e, t, n) => new Kr(e, t).update(n).digest();
|
|
2316
2316
|
ht.create = (e, t) => new Kr(e, t);
|
|
2317
|
-
function
|
|
2317
|
+
function sn(e, t, n) {
|
|
2318
2318
|
return se.hash(e), n === void 0 && (n = new Uint8Array(e.outputLen)), ht(e, Je(n), Je(t));
|
|
2319
2319
|
}
|
|
2320
|
-
const
|
|
2320
|
+
const Ut = new Uint8Array([0]), qn = new Uint8Array();
|
|
2321
2321
|
function Cr(e, t, n, r = 32) {
|
|
2322
2322
|
if (se.hash(e), se.number(r), r > 255 * e.outputLen)
|
|
2323
2323
|
throw new Error("Length should be <= 255*HashLen");
|
|
@@ -2325,14 +2325,14 @@ function Cr(e, t, n, r = 32) {
|
|
|
2325
2325
|
n === void 0 && (n = qn);
|
|
2326
2326
|
const s = new Uint8Array(i * e.outputLen), o = ht.create(e, t), c = o._cloneInto(), a = new Uint8Array(o.outputLen);
|
|
2327
2327
|
for (let l = 0; l < i; l++)
|
|
2328
|
-
|
|
2329
|
-
return o.destroy(), c.destroy(), a.fill(0),
|
|
2328
|
+
Ut[0] = l + 1, c.update(l === 0 ? qn : a).update(n).update(Ut).digestInto(a), s.set(a, e.outputLen * l), o._cloneInto(c);
|
|
2329
|
+
return o.destroy(), c.destroy(), a.fill(0), Ut.fill(0), s.slice(0, r);
|
|
2330
2330
|
}
|
|
2331
2331
|
var to = Object.defineProperty, D = (e, t) => {
|
|
2332
2332
|
for (var n in t)
|
|
2333
2333
|
to(e, n, { get: t[n], enumerable: !0 });
|
|
2334
2334
|
}, Oe = Symbol("verified"), no = (e) => e instanceof Object;
|
|
2335
|
-
function
|
|
2335
|
+
function dt(e) {
|
|
2336
2336
|
if (!no(e) || typeof e.kind != "number" || typeof e.content != "string" || typeof e.created_at != "number" || typeof e.pubkey != "string" || !e.pubkey.match(/^[a-f0-9]{64}$/) || !Array.isArray(e.tags))
|
|
2337
2337
|
return !1;
|
|
2338
2338
|
for (let t = 0; t < e.tags.length; t++) {
|
|
@@ -2409,23 +2409,23 @@ var Br = class {
|
|
|
2409
2409
|
}
|
|
2410
2410
|
}, co = class {
|
|
2411
2411
|
generateSecretKey() {
|
|
2412
|
-
return
|
|
2412
|
+
return Ze.utils.randomPrivateKey();
|
|
2413
2413
|
}
|
|
2414
2414
|
getPublicKey(e) {
|
|
2415
|
-
return M(
|
|
2415
|
+
return M(Ze.getPublicKey(e));
|
|
2416
2416
|
}
|
|
2417
2417
|
finalizeEvent(e, t) {
|
|
2418
2418
|
const n = e;
|
|
2419
|
-
return n.pubkey = M(
|
|
2419
|
+
return n.pubkey = M(Ze.getPublicKey(t)), n.id = qe(n), n.sig = M(Ze.sign(qe(n), t)), n[Oe] = !0, n;
|
|
2420
2420
|
}
|
|
2421
2421
|
verifyEvent(e) {
|
|
2422
2422
|
if (typeof e[Oe] == "boolean")
|
|
2423
2423
|
return e[Oe];
|
|
2424
|
-
const t =
|
|
2424
|
+
const t = qe(e);
|
|
2425
2425
|
if (t !== e.id)
|
|
2426
2426
|
return e[Oe] = !1, !1;
|
|
2427
2427
|
try {
|
|
2428
|
-
const n =
|
|
2428
|
+
const n = Ze.verify(e.sig, t, e.pubkey);
|
|
2429
2429
|
return e[Oe] = n, n;
|
|
2430
2430
|
} catch {
|
|
2431
2431
|
return e[Oe] = !1, !1;
|
|
@@ -2433,15 +2433,15 @@ var Br = class {
|
|
|
2433
2433
|
}
|
|
2434
2434
|
};
|
|
2435
2435
|
function uo(e) {
|
|
2436
|
-
if (!
|
|
2436
|
+
if (!dt(e))
|
|
2437
2437
|
throw new Error("can't serialize event with wrong or missing properties");
|
|
2438
2438
|
return JSON.stringify([0, e.pubkey, e.created_at, e.kind, e.tags, e.content]);
|
|
2439
2439
|
}
|
|
2440
|
-
function
|
|
2440
|
+
function qe(e) {
|
|
2441
2441
|
let t = fe(ne.encode(uo(e)));
|
|
2442
2442
|
return M(t);
|
|
2443
2443
|
}
|
|
2444
|
-
var
|
|
2444
|
+
var pt = new co(), _e = pt.generateSecretKey, le = pt.getPublicKey, X = pt.finalizeEvent, yt = pt.verifyEvent, lo = {};
|
|
2445
2445
|
D(lo, {
|
|
2446
2446
|
Application: () => da,
|
|
2447
2447
|
BadgeAward: () => Eo,
|
|
@@ -2544,7 +2544,7 @@ function fo(e) {
|
|
|
2544
2544
|
}
|
|
2545
2545
|
function ho(e, t) {
|
|
2546
2546
|
const n = t instanceof Array ? t : [t];
|
|
2547
|
-
return
|
|
2547
|
+
return dt(e) && n.includes(e.kind) || !1;
|
|
2548
2548
|
}
|
|
2549
2549
|
var po = 0, yo = 1, go = 2, wo = 3, bo = 4, vo = 5, an = 6, cn = 7, Eo = 8, Lr = 13, mo = 14, xo = 16, $r = 40, Tr = 41, Rr = 42, Or = 43, Mr = 44, So = 1040, Pr = 1059, No = 1063, Ao = 1311, Ko = 1971, Co = 1984, Bo = 1984, ko = 1985, _o = 4550, Uo = 5999, Io = 6999, Lo = 7e3, $o = 9041, To = 9734, Ro = 9735, Oo = 9802, Mo = 1e4, Po = 10001, Ho = 10002, qo = 10003, Do = 10004, jo = 10005, zo = 10006, Vo = 10007, Wo = 10015, Zo = 10030, Go = 10050, Fo = 10096, Jo = 13194, Yo = 21e3, Hr = 22242, qr = 23194, Xo = 23195, Qo = 24133, un = 27235, ea = 3e4, ta = 30001, na = 30002, ra = 30003, ia = 30004, sa = 30008, oa = 30009, aa = 30015, ca = 30017, ua = 30018, la = 30023, fa = 30024, ha = 30030, da = 30078, pa = 30311, ya = 30315, ga = 30402, wa = 30403, ba = 31922, va = 31923, Ea = 31924, ma = 31925, xa = 31989, Sa = 31990, Na = 34550, Aa = {};
|
|
2550
2550
|
D(Aa, {
|
|
@@ -2615,8 +2615,8 @@ D($a, {
|
|
|
2615
2615
|
BECH32_REGEX: () => jr,
|
|
2616
2616
|
Bech32MaxSize: () => fn,
|
|
2617
2617
|
NostrTypeGuard: () => Ta,
|
|
2618
|
-
decode: () =>
|
|
2619
|
-
encodeBytes: () =>
|
|
2618
|
+
decode: () => gt,
|
|
2619
|
+
encodeBytes: () => bt,
|
|
2620
2620
|
naddrEncode: () => Da,
|
|
2621
2621
|
neventEncode: () => qa,
|
|
2622
2622
|
noteEncode: () => Pa,
|
|
@@ -2637,12 +2637,12 @@ function Ra(e) {
|
|
|
2637
2637
|
const t = new Uint8Array(4);
|
|
2638
2638
|
return t[0] = e >> 24 & 255, t[1] = e >> 16 & 255, t[2] = e >> 8 & 255, t[3] = e & 255, t;
|
|
2639
2639
|
}
|
|
2640
|
-
function
|
|
2640
|
+
function gt(e) {
|
|
2641
2641
|
var i, s, o, c, a, l, f;
|
|
2642
|
-
let { prefix: t, words: n } =
|
|
2642
|
+
let { prefix: t, words: n } = ze.decode(e, fn), r = new Uint8Array(ze.fromWords(n));
|
|
2643
2643
|
switch (t) {
|
|
2644
2644
|
case "nprofile": {
|
|
2645
|
-
let u =
|
|
2645
|
+
let u = It(r);
|
|
2646
2646
|
if (!((i = u[0]) != null && i[0]))
|
|
2647
2647
|
throw new Error("missing TLV 0 for nprofile");
|
|
2648
2648
|
if (u[0][0].length !== 32)
|
|
@@ -2656,7 +2656,7 @@ function yt(e) {
|
|
|
2656
2656
|
};
|
|
2657
2657
|
}
|
|
2658
2658
|
case "nevent": {
|
|
2659
|
-
let u =
|
|
2659
|
+
let u = It(r);
|
|
2660
2660
|
if (!((s = u[0]) != null && s[0]))
|
|
2661
2661
|
throw new Error("missing TLV 0 for nevent");
|
|
2662
2662
|
if (u[0][0].length !== 32)
|
|
@@ -2676,7 +2676,7 @@ function yt(e) {
|
|
|
2676
2676
|
};
|
|
2677
2677
|
}
|
|
2678
2678
|
case "naddr": {
|
|
2679
|
-
let u =
|
|
2679
|
+
let u = It(r);
|
|
2680
2680
|
if (!((a = u[0]) != null && a[0]))
|
|
2681
2681
|
throw new Error("missing TLV 0 for naddr");
|
|
2682
2682
|
if (!((l = u[2]) != null && l[0]))
|
|
@@ -2706,7 +2706,7 @@ function yt(e) {
|
|
|
2706
2706
|
throw new Error(`unknown prefix ${t}`);
|
|
2707
2707
|
}
|
|
2708
2708
|
}
|
|
2709
|
-
function
|
|
2709
|
+
function It(e) {
|
|
2710
2710
|
let t = {}, n = e;
|
|
2711
2711
|
for (; n.length > 0; ) {
|
|
2712
2712
|
let r = n[0], i = n[1], s = n.slice(2, 2 + i);
|
|
@@ -2717,27 +2717,27 @@ function Ut(e) {
|
|
|
2717
2717
|
return t;
|
|
2718
2718
|
}
|
|
2719
2719
|
function Oa(e) {
|
|
2720
|
-
return
|
|
2720
|
+
return bt("nsec", e);
|
|
2721
2721
|
}
|
|
2722
2722
|
function Ma(e) {
|
|
2723
|
-
return
|
|
2723
|
+
return bt("npub", G(e));
|
|
2724
2724
|
}
|
|
2725
2725
|
function Pa(e) {
|
|
2726
|
-
return
|
|
2727
|
-
}
|
|
2728
|
-
function gt(e, t) {
|
|
2729
|
-
let n = je.toWords(t);
|
|
2730
|
-
return je.encode(e, n, fn);
|
|
2726
|
+
return bt("note", G(e));
|
|
2731
2727
|
}
|
|
2732
2728
|
function wt(e, t) {
|
|
2733
|
-
|
|
2729
|
+
let n = ze.toWords(t);
|
|
2730
|
+
return ze.encode(e, n, fn);
|
|
2731
|
+
}
|
|
2732
|
+
function bt(e, t) {
|
|
2733
|
+
return wt(e, t);
|
|
2734
2734
|
}
|
|
2735
2735
|
function Ha(e) {
|
|
2736
2736
|
let t = hn({
|
|
2737
2737
|
0: [G(e.pubkey)],
|
|
2738
2738
|
1: (e.relays || []).map((n) => ne.encode(n))
|
|
2739
2739
|
});
|
|
2740
|
-
return
|
|
2740
|
+
return wt("nprofile", t);
|
|
2741
2741
|
}
|
|
2742
2742
|
function qa(e) {
|
|
2743
2743
|
let t;
|
|
@@ -2748,7 +2748,7 @@ function qa(e) {
|
|
|
2748
2748
|
2: e.author ? [G(e.author)] : [],
|
|
2749
2749
|
3: t ? [new Uint8Array(t)] : []
|
|
2750
2750
|
});
|
|
2751
|
-
return
|
|
2751
|
+
return wt("nevent", n);
|
|
2752
2752
|
}
|
|
2753
2753
|
function Da(e) {
|
|
2754
2754
|
let t = new ArrayBuffer(4);
|
|
@@ -2759,7 +2759,7 @@ function Da(e) {
|
|
|
2759
2759
|
2: [G(e.pubkey)],
|
|
2760
2760
|
3: [new Uint8Array(t)]
|
|
2761
2761
|
});
|
|
2762
|
-
return
|
|
2762
|
+
return wt("naddr", n);
|
|
2763
2763
|
}
|
|
2764
2764
|
function hn(e) {
|
|
2765
2765
|
let t = [];
|
|
@@ -2797,17 +2797,17 @@ D(Va, {
|
|
|
2797
2797
|
searchDomain: () => Ga,
|
|
2798
2798
|
useFetchImplementation: () => Za
|
|
2799
2799
|
});
|
|
2800
|
-
var dn = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/, Wa = (e) => dn.test(e || ""),
|
|
2800
|
+
var dn = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/, Wa = (e) => dn.test(e || ""), vt;
|
|
2801
2801
|
try {
|
|
2802
|
-
|
|
2802
|
+
vt = fetch;
|
|
2803
2803
|
} catch {
|
|
2804
2804
|
}
|
|
2805
2805
|
function Za(e) {
|
|
2806
|
-
|
|
2806
|
+
vt = e;
|
|
2807
2807
|
}
|
|
2808
2808
|
async function Ga(e, t = "") {
|
|
2809
2809
|
try {
|
|
2810
|
-
const n = `https://${e}/.well-known/nostr.json?name=${t}`, r = await
|
|
2810
|
+
const n = `https://${e}/.well-known/nostr.json?name=${t}`, r = await vt(n, { redirect: "manual" });
|
|
2811
2811
|
if (r.status !== 200)
|
|
2812
2812
|
throw Error("Wrong response code");
|
|
2813
2813
|
return (await r.json()).names;
|
|
@@ -2822,7 +2822,7 @@ async function Wr(e) {
|
|
|
2822
2822
|
return null;
|
|
2823
2823
|
const [, n = "_", r] = t;
|
|
2824
2824
|
try {
|
|
2825
|
-
const s = `https://${r}/.well-known/nostr.json?name=${n}`, o = await
|
|
2825
|
+
const s = `https://${r}/.well-known/nostr.json?name=${n}`, o = await vt(s, { redirect: "manual" });
|
|
2826
2826
|
if (o.status !== 200)
|
|
2827
2827
|
throw Error("Wrong response code");
|
|
2828
2828
|
const c = await o.json(), a = c.names[n];
|
|
@@ -3000,27 +3000,27 @@ function sc(e, { skipVerification: t } = {}) {
|
|
|
3000
3000
|
} catch {
|
|
3001
3001
|
return;
|
|
3002
3002
|
}
|
|
3003
|
-
if (r.id === n.id && !(!t && !
|
|
3003
|
+
if (r.id === n.id && !(!t && !yt(r)))
|
|
3004
3004
|
return r;
|
|
3005
3005
|
}
|
|
3006
3006
|
var oc = {};
|
|
3007
3007
|
D(oc, {
|
|
3008
|
-
NOSTR_URI_REGEX: () =>
|
|
3008
|
+
NOSTR_URI_REGEX: () => Et,
|
|
3009
3009
|
parse: () => cc,
|
|
3010
3010
|
test: () => ac
|
|
3011
3011
|
});
|
|
3012
|
-
var
|
|
3012
|
+
var Et = new RegExp(`nostr:(${jr.source})`);
|
|
3013
3013
|
function ac(e) {
|
|
3014
|
-
return typeof e == "string" && new RegExp(`^${
|
|
3014
|
+
return typeof e == "string" && new RegExp(`^${Et.source}$`).test(e);
|
|
3015
3015
|
}
|
|
3016
3016
|
function cc(e) {
|
|
3017
|
-
const t = e.match(new RegExp(`^${
|
|
3017
|
+
const t = e.match(new RegExp(`^${Et.source}$`));
|
|
3018
3018
|
if (!t)
|
|
3019
3019
|
throw new Error(`Invalid Nostr URI: ${e}`);
|
|
3020
3020
|
return {
|
|
3021
3021
|
uri: t[0],
|
|
3022
3022
|
value: t[1],
|
|
3023
|
-
decoded:
|
|
3023
|
+
decoded: gt(t[1])
|
|
3024
3024
|
};
|
|
3025
3025
|
}
|
|
3026
3026
|
var uc = {};
|
|
@@ -3061,7 +3061,7 @@ D(hc, {
|
|
|
3061
3061
|
regex: () => pn,
|
|
3062
3062
|
replaceAll: () => pc
|
|
3063
3063
|
});
|
|
3064
|
-
var pn = () => new RegExp(`\\b${
|
|
3064
|
+
var pn = () => new RegExp(`\\b${Et.source}\\b`, "g");
|
|
3065
3065
|
function* dc(e) {
|
|
3066
3066
|
const t = e.matchAll(pn());
|
|
3067
3067
|
for (const n of t)
|
|
@@ -3070,7 +3070,7 @@ function* dc(e) {
|
|
|
3070
3070
|
yield {
|
|
3071
3071
|
uri: r,
|
|
3072
3072
|
value: i,
|
|
3073
|
-
decoded:
|
|
3073
|
+
decoded: gt(i),
|
|
3074
3074
|
start: n.index,
|
|
3075
3075
|
end: n.index + r.length
|
|
3076
3076
|
};
|
|
@@ -3081,7 +3081,7 @@ function pc(e, t) {
|
|
|
3081
3081
|
return e.replaceAll(pn(), (n, r) => t({
|
|
3082
3082
|
uri: n,
|
|
3083
3083
|
value: r,
|
|
3084
|
-
decoded:
|
|
3084
|
+
decoded: gt(r)
|
|
3085
3085
|
}));
|
|
3086
3086
|
}
|
|
3087
3087
|
var yc = {};
|
|
@@ -3229,7 +3229,7 @@ D(q, {
|
|
|
3229
3229
|
var Xr = 1, Qr = 65535;
|
|
3230
3230
|
function wn(e, t) {
|
|
3231
3231
|
const n = Ie.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3232
|
-
return
|
|
3232
|
+
return sn(fe, n, "nip44-v2");
|
|
3233
3233
|
}
|
|
3234
3234
|
function ei(e, t) {
|
|
3235
3235
|
const n = Cr(fe, e, t, 76);
|
|
@@ -3358,7 +3358,7 @@ async function Oc(e) {
|
|
|
3358
3358
|
try {
|
|
3359
3359
|
let t = "", { lud06: n, lud16: r } = JSON.parse(e.content);
|
|
3360
3360
|
if (n) {
|
|
3361
|
-
let { words: o } =
|
|
3361
|
+
let { words: o } = ze.decode(n, 1e3), c = ze.fromWords(o);
|
|
3362
3362
|
t = ue.decode(c);
|
|
3363
3363
|
} else if (r) {
|
|
3364
3364
|
let [o, c] = r.split("@");
|
|
@@ -3402,9 +3402,9 @@ function Pc(e) {
|
|
|
3402
3402
|
} catch {
|
|
3403
3403
|
return "Invalid zap request JSON.";
|
|
3404
3404
|
}
|
|
3405
|
-
if (!
|
|
3405
|
+
if (!dt(t))
|
|
3406
3406
|
return "Zap request is not a valid Nostr event.";
|
|
3407
|
-
if (!
|
|
3407
|
+
if (!yt(t))
|
|
3408
3408
|
return "Invalid signature on zap request.";
|
|
3409
3409
|
let n = t.tags.find(([s, o]) => s === "p" && o);
|
|
3410
3410
|
if (!n)
|
|
@@ -3435,7 +3435,7 @@ D(qc, {
|
|
|
3435
3435
|
createWrap: () => ci,
|
|
3436
3436
|
unwrapEvent: () => ui,
|
|
3437
3437
|
unwrapManyEvents: () => zc,
|
|
3438
|
-
wrapEvent: () =>
|
|
3438
|
+
wrapEvent: () => Wt,
|
|
3439
3439
|
wrapManyEvents: () => jc
|
|
3440
3440
|
});
|
|
3441
3441
|
var Dc = 2 * 24 * 60 * 60, ni = () => Math.round(Date.now() / 1e3), ri = () => Math.round(ni() - Math.random() * Dc), ii = (e, t) => wn(e, t), si = (e, t, n) => vn(JSON.stringify(e), ii(t, n)), Dn = (e, t) => JSON.parse(En(e.content, ii(t, e.pubkey)));
|
|
@@ -3447,7 +3447,7 @@ function oi(e, t) {
|
|
|
3447
3447
|
...e,
|
|
3448
3448
|
pubkey: le(t)
|
|
3449
3449
|
};
|
|
3450
|
-
return n.id =
|
|
3450
|
+
return n.id = qe(n), n;
|
|
3451
3451
|
}
|
|
3452
3452
|
function ai(e, t, n) {
|
|
3453
3453
|
return X(
|
|
@@ -3472,16 +3472,16 @@ function ci(e, t) {
|
|
|
3472
3472
|
n
|
|
3473
3473
|
);
|
|
3474
3474
|
}
|
|
3475
|
-
function
|
|
3475
|
+
function Wt(e, t, n) {
|
|
3476
3476
|
const r = oi(e, t), i = ai(r, t, n);
|
|
3477
3477
|
return ci(i, n);
|
|
3478
3478
|
}
|
|
3479
3479
|
function jc(e, t, n) {
|
|
3480
3480
|
if (!n || n.length === 0)
|
|
3481
3481
|
throw new Error("At least one recipient is required.");
|
|
3482
|
-
const r = le(t), i = [
|
|
3482
|
+
const r = le(t), i = [Wt(e, t, r)];
|
|
3483
3483
|
return n.forEach((s) => {
|
|
3484
|
-
i.push(
|
|
3484
|
+
i.push(Wt(e, t, s));
|
|
3485
3485
|
}), i;
|
|
3486
3486
|
}
|
|
3487
3487
|
function ui(e, t) {
|
|
@@ -3565,7 +3565,7 @@ function gi(e, t) {
|
|
|
3565
3565
|
return n.length > 0 && n[1] === r;
|
|
3566
3566
|
}
|
|
3567
3567
|
async function wi(e, t, n, r) {
|
|
3568
|
-
if (!
|
|
3568
|
+
if (!yt(e))
|
|
3569
3569
|
throw new Error("Invalid nostr event, signature invalid");
|
|
3570
3570
|
if (!di(e))
|
|
3571
3571
|
throw new Error("Invalid nostr event, kind invalid");
|
|
@@ -3661,12 +3661,12 @@ async function* ou(e) {
|
|
|
3661
3661
|
}
|
|
3662
3662
|
}
|
|
3663
3663
|
function Me(e, t = new Uint8Array(32), n = 1) {
|
|
3664
|
-
const r =
|
|
3664
|
+
const r = sn(fe, e, t), i = [];
|
|
3665
3665
|
for (let s = 1; s <= n; s++)
|
|
3666
3666
|
i.push(Cr(fe, r, new Uint8Array([s]), 32));
|
|
3667
3667
|
return i;
|
|
3668
3668
|
}
|
|
3669
|
-
function
|
|
3669
|
+
function Lt(e, t) {
|
|
3670
3670
|
return `${e}:${t}`;
|
|
3671
3671
|
}
|
|
3672
3672
|
const Fc = 1e3, Jc = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
@@ -3722,7 +3722,8 @@ class st {
|
|
|
3722
3722
|
});
|
|
3723
3723
|
}
|
|
3724
3724
|
/**
|
|
3725
|
-
* Send a Nostr event through the encrypted session
|
|
3725
|
+
* Send a partial Nostr event through the encrypted session.
|
|
3726
|
+
* In addition to chat messages, it could be files, webrtc negotiation or many other types of messages.
|
|
3726
3727
|
* @param event Partial Nostr event to send. Must be unsigned. Id and will be generated if not provided.
|
|
3727
3728
|
* @returns A verified Nostr event containing the encrypted message
|
|
3728
3729
|
* @throws Error if we are not the initiator and trying to send the first message
|
|
@@ -3740,8 +3741,8 @@ class st {
|
|
|
3740
3741
|
tags: t.tags || [],
|
|
3741
3742
|
pubkey: t.pubkey || Jc
|
|
3742
3743
|
};
|
|
3743
|
-
n.tags.some(([a]) => a === "ms") || n.tags.push(["ms", Date.now().toString()]), n.id =
|
|
3744
|
-
const [r, i] = this.ratchetEncrypt(JSON.stringify(
|
|
3744
|
+
n.tags.some(([a]) => a === "ms") || n.tags.push(["ms", Date.now().toString()]), n.id = qe(n);
|
|
3745
|
+
const [r, i] = this.ratchetEncrypt(JSON.stringify(n)), s = q.getConversationKey(this.state.ourCurrentNostrKey.privateKey, this.state.theirNextNostrPublicKey), o = q.encrypt(JSON.stringify(r), s);
|
|
3745
3746
|
return X({
|
|
3746
3747
|
content: i,
|
|
3747
3748
|
kind: Be,
|
|
@@ -3810,7 +3811,7 @@ class st {
|
|
|
3810
3811
|
for (; this.state.receivingChainMessageNumber < t; ) {
|
|
3811
3812
|
const [r, i] = Me(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3812
3813
|
this.state.receivingChainKey = r;
|
|
3813
|
-
const s =
|
|
3814
|
+
const s = Lt(n, this.state.receivingChainMessageNumber);
|
|
3814
3815
|
if (this.state.skippedMessageKeys[s] = i, !this.state.skippedHeaderKeys[n]) {
|
|
3815
3816
|
const o = [];
|
|
3816
3817
|
if (this.state.ourCurrentNostrKey) {
|
|
@@ -3825,7 +3826,7 @@ class st {
|
|
|
3825
3826
|
}
|
|
3826
3827
|
trySkippedMessageKeys(t, n, r) {
|
|
3827
3828
|
var s;
|
|
3828
|
-
const i =
|
|
3829
|
+
const i = Lt(r, t.number);
|
|
3829
3830
|
if (i in this.state.skippedMessageKeys) {
|
|
3830
3831
|
const o = this.state.skippedMessageKeys[i];
|
|
3831
3832
|
return delete this.state.skippedMessageKeys[i], Object.keys(this.state.skippedMessageKeys).some((a) => a.startsWith(`${r}:`)) || (delete this.state.skippedHeaderKeys[r], (s = this.nostrUnsubscribe) == null || s.call(this), this.nostrUnsubscribe = void 0), q.decrypt(n, o);
|
|
@@ -3864,9 +3865,17 @@ class st {
|
|
|
3864
3865
|
{ authors: [this.state.theirNextNostrPublicKey], kinds: [Be] },
|
|
3865
3866
|
(a) => this.handleNostrEvent(a)
|
|
3866
3867
|
)), r && (this.skipMessageKeys(n.previousChainLength, t.pubkey), this.ratchetStep(n.nextPublicKey));
|
|
3867
|
-
else if (!(
|
|
3868
|
+
else if (!(Lt(t.pubkey, n.number) in this.state.skippedMessageKeys))
|
|
3868
3869
|
return;
|
|
3869
3870
|
const s = this.ratchetDecrypt(n, t.content, t.pubkey), o = JSON.parse(s);
|
|
3871
|
+
if (!dt(o)) {
|
|
3872
|
+
console.error("Invalid event received", o);
|
|
3873
|
+
return;
|
|
3874
|
+
}
|
|
3875
|
+
if (o.id !== qe(o)) {
|
|
3876
|
+
console.error("Event hash does not match", o);
|
|
3877
|
+
return;
|
|
3878
|
+
}
|
|
3870
3879
|
this.internalSubscriptions.forEach((a) => a(o, t));
|
|
3871
3880
|
}
|
|
3872
3881
|
subscribeToNostrEvents() {
|
|
@@ -3886,7 +3895,7 @@ new TextDecoder("utf-8");
|
|
|
3886
3895
|
new TextEncoder();
|
|
3887
3896
|
function Qe(e, t) {
|
|
3888
3897
|
const n = Ie.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3889
|
-
return
|
|
3898
|
+
return sn(fe, n, "nip44-v2");
|
|
3890
3899
|
}
|
|
3891
3900
|
class Pe {
|
|
3892
3901
|
constructor(t, n, r, i, s, o, c = []) {
|
|
@@ -3941,7 +3950,7 @@ class Pe {
|
|
|
3941
3950
|
var o, c;
|
|
3942
3951
|
if (!t.sig)
|
|
3943
3952
|
throw new Error("Event is not signed");
|
|
3944
|
-
if (!
|
|
3953
|
+
if (!yt(t))
|
|
3945
3954
|
throw new Error("Event signature is invalid");
|
|
3946
3955
|
const { tags: n } = t, r = (o = n.find(([a]) => a === "ephemeralKey")) == null ? void 0 : o[1], i = (c = n.find(([a]) => a === "sharedSecret")) == null ? void 0 : c[1], s = t.pubkey;
|
|
3947
3956
|
if (!r || !i)
|
|
@@ -4075,5 +4084,5 @@ export {
|
|
|
4075
4084
|
su as deserializeSessionState,
|
|
4076
4085
|
Me as kdf,
|
|
4077
4086
|
iu as serializeSessionState,
|
|
4078
|
-
|
|
4087
|
+
Lt as skippedMessageIndexKey
|
|
4079
4088
|
};
|