nostr-double-ratchet 0.0.33 → 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/dist/Invite.d.ts +4 -3
- package/dist/Invite.d.ts.map +1 -1
- package/dist/nostr-double-ratchet.es.js +255 -252
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/package.json +1 -1
- package/src/Invite.ts +22 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var Ki = Object.defineProperty;
|
|
2
2
|
var Ni = (e, t, n) => t in e ? Ki(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
3
|
var J = (e, t, n) => Ni(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
-
function
|
|
4
|
+
function Bn(e) {
|
|
5
5
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
6
6
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
7
7
|
}
|
|
@@ -14,7 +14,7 @@ function Fn(e, ...t) {
|
|
|
14
14
|
function Si(e) {
|
|
15
15
|
if (typeof e != "function" || typeof e.create != "function")
|
|
16
16
|
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
17
|
-
|
|
17
|
+
Bn(e.outputLen), Bn(e.blockLen);
|
|
18
18
|
}
|
|
19
19
|
function et(e, t = !0) {
|
|
20
20
|
if (e.destroyed)
|
|
@@ -33,17 +33,17 @@ const xt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.
|
|
|
33
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
41
|
function Vt(e) {
|
|
42
|
-
if (typeof e == "string" && (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) => {
|
|
@@ -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);
|
|
@@ -348,18 +348,18 @@ function er(e, t, n) {
|
|
|
348
348
|
if (s++ >= 1e3)
|
|
349
349
|
throw new Error("drbg: tried 1000 values");
|
|
350
350
|
let u = 0;
|
|
351
|
-
const
|
|
351
|
+
const 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
|
};
|
|
@@ -468,15 +468,15 @@ 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
|
};
|
|
@@ -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 };
|
|
@@ -769,15 +769,15 @@ 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,7 +789,7 @@ 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
794
|
if (g instanceof Uint8Array && (g = qe(g)), typeof g != "string" || !h.includes(g.length))
|
|
795
795
|
throw new Error("Invalid key");
|
|
@@ -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
|
|
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
916
|
const M = t.a, I = n.mul(t.b, Ln);
|
|
917
|
-
let A = n.mul(d, S), R = n.mul(
|
|
918
|
-
D = n.mul(D, b), b = n.add(A, R), D = n.sub(D, b), b = n.add(d,
|
|
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(
|
|
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: K, f: M } = this.wNAF(
|
|
969
|
-
K = w.constTimeNegate(_, K), I = w.constTimeNegate(
|
|
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;
|
|
@@ -1016,7 +1016,7 @@ function cs(e) {
|
|
|
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,
|
|
@@ -1048,16 +1048,16 @@ function ls(e) {
|
|
|
1048
1048
|
function a(b) {
|
|
1049
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
1053
|
toBytes(b, v, N) {
|
|
1054
|
-
const
|
|
1055
|
-
return N ? U(Uint8Array.from([v.hasEvenY() ? 2 : 3]), C) : U(Uint8Array.from([4]), C, n.toBytes(
|
|
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, N = b[0],
|
|
1058
|
+
const v = b.length, N = b[0], B = b.subarray(1);
|
|
1059
1059
|
if (v === i && (N === 2 || N === 3)) {
|
|
1060
|
-
const C = G(
|
|
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);
|
|
@@ -1065,7 +1065,7 @@ function ls(e) {
|
|
|
1065
1065
|
const $ = (O & X) === X;
|
|
1066
1066
|
return (N & 1) === 1 !== $ && (O = n.neg(O)), { x: C, y: O };
|
|
1067
1067
|
} else if (v === s && N === 4) {
|
|
1068
|
-
const C = n.fromBytes(
|
|
1068
|
+
const C = n.fromBytes(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`);
|
|
@@ -1079,38 +1079,38 @@ function ls(e) {
|
|
|
1079
1079
|
return g(b) ? c(-b) : b;
|
|
1080
1080
|
}
|
|
1081
1081
|
const d = (b, v, N) => G(b.slice(v, N));
|
|
1082
|
-
class
|
|
1083
|
-
constructor(v, N,
|
|
1084
|
-
this.r = v, this.s = N, this.recovery =
|
|
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
1088
|
const N = t.nByteLength;
|
|
1089
|
-
return v = Z("compactSignature", v, N * 2), new
|
|
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: N, s:
|
|
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: N, s:
|
|
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
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,21 +1170,21 @@ function ls(e) {
|
|
|
1170
1170
|
return l.fromPrivateKey(b).toRawBytes(v);
|
|
1171
1171
|
}
|
|
1172
1172
|
function _(b) {
|
|
1173
|
-
const v = b instanceof Uint8Array, N = typeof b == "string",
|
|
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
1181
|
return l.fromHex(v).multiply(f(b)).toRawBytes(N);
|
|
1182
1182
|
}
|
|
1183
|
-
const
|
|
1183
|
+
const E = t.bits2int || function(b) {
|
|
1184
1184
|
const v = G(b), N = b.length * 8 - t.nBitLength;
|
|
1185
1185
|
return N > 0 ? v >> BigInt(N) : v;
|
|
1186
1186
|
}, x = t.bits2int_modN || function(b) {
|
|
1187
|
-
return c(
|
|
1187
|
+
return c(E(b));
|
|
1188
1188
|
}, K = Jt(t.nBitLength);
|
|
1189
1189
|
function M(b) {
|
|
1190
1190
|
if (typeof b != "bigint")
|
|
@@ -1196,9 +1196,9 @@ function ls(e) {
|
|
|
1196
1196
|
function I(b, v, N = A) {
|
|
1197
1197
|
if (["recovered", "canonical"].some((Ae) => Ae in N))
|
|
1198
1198
|
throw new Error("sign() legacy options not supported");
|
|
1199
|
-
const { hash:
|
|
1199
|
+
const { hash: B, randomBytes: C } = t;
|
|
1200
1200
|
let { lowS: U, prehash: O, extraEntropy: $ } = N;
|
|
1201
|
-
U == null && (U = !0), b = Z("msgHash", b), O && (b = Z("prehashed msgHash",
|
|
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,8 +1206,8 @@ 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
1212
|
const An = a(Le), $e = l.BASE.multiply(Le).toAffine(), te = c($e.x);
|
|
1213
1213
|
if (te === ce)
|
|
@@ -1215,36 +1215,36 @@ function ls(e) {
|
|
|
1215
1215
|
const Re = c(An * c(we + te * ge));
|
|
1216
1216
|
if (Re === ce)
|
|
1217
1217
|
return;
|
|
1218
|
-
let Cn = ($e.x === te ? 0 : 2) | Number($e.y & X),
|
|
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
1224
|
function T(b, v, N = A) {
|
|
1225
|
-
const { seed:
|
|
1226
|
-
return er(U.hash.outputLen, U.nByteLength, U.hmac)(
|
|
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 D(b, v, N,
|
|
1229
|
+
function D(b, v, N, B = R) {
|
|
1230
1230
|
var $e;
|
|
1231
1231
|
const C = b;
|
|
1232
|
-
if (v = Z("msgHash", v), N = Z("publicKey", N), "strict" in
|
|
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
1250
|
ee = l.fromHex(N);
|
|
@@ -1262,12 +1262,12 @@ function ls(e) {
|
|
|
1262
1262
|
return {
|
|
1263
1263
|
CURVE: t,
|
|
1264
1264
|
getPublicKey: S,
|
|
1265
|
-
getSharedSecret:
|
|
1265
|
+
getSharedSecret: k,
|
|
1266
1266
|
sign: T,
|
|
1267
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 {
|
|
@@ -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
|
}
|
|
@@ -1322,10 +1322,10 @@ function hs(e, t) {
|
|
|
1322
1322
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1323
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 (!Ot.eql(Ot.sqr(
|
|
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
1330
|
const Ot = ts(ut, void 0, void 0, { sqrt: cr }), _e = hs({
|
|
1331
1331
|
a: BigInt(0),
|
|
@@ -1348,10 +1348,10 @@ const Ot = ts(ut, void 0, void 0, { sqrt: cr }), _e = hs({
|
|
|
1348
1348
|
splitScalar: (e) => {
|
|
1349
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 = {};
|
|
@@ -1387,8 +1387,8 @@ function gs(e, t, n = Yn(32)) {
|
|
|
1387
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 } = Pt(l),
|
|
1391
|
-
if (w.set(f, 0), w.set(Mt(Ge(u +
|
|
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
|
}
|
|
@@ -1422,7 +1422,7 @@ const Ze = {
|
|
|
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 Qt = (e) => e instanceof Uint8Array,
|
|
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"));
|
|
@@ -1530,7 +1530,7 @@ function Ns(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;
|
|
@@ -1557,7 +1557,7 @@ class Ss extends dr {
|
|
|
1557
1557
|
for (let u = o; u < i; u++)
|
|
1558
1558
|
n[u] = 0;
|
|
1559
1559
|
Ns(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
1560
|
-
const c =
|
|
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))
|
|
@@ -1937,14 +1937,14 @@ function Hn(e, t, n = 1) {
|
|
|
1937
1937
|
}
|
|
1938
1938
|
function mr(e) {
|
|
1939
1939
|
const t = e === "bech32" ? 1 : 734539939, n = Se(5), r = n.decode, i = n.encode, s = On(r);
|
|
1940
|
-
function o(f, u,
|
|
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 ${
|
|
1946
|
+
if (y !== !1 && w > y)
|
|
1947
|
+
throw new TypeError(`Length ${w} exceeds limit ${y}`);
|
|
1948
1948
|
return f = f.toLowerCase(), `${f}1${jt.encode(u)}${Hn(f, u, t)}`;
|
|
1949
1949
|
}
|
|
1950
1950
|
function c(f, u = 90) {
|
|
@@ -1952,25 +1952,25 @@ function mr(e) {
|
|
|
1952
1952
|
throw new Error(`bech32.decode input should be string, not ${typeof f}`);
|
|
1953
1953
|
if (f.length < 8 || u !== !1 && f.length > u)
|
|
1954
1954
|
throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${u})`);
|
|
1955
|
-
const
|
|
1956
|
-
if (f !==
|
|
1955
|
+
const 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 = jt.decode(h).slice(0, -6),
|
|
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
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,7 +1994,7 @@ 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
|
}
|
|
@@ -2104,11 +2104,11 @@ function qn(e, t, n, r, i) {
|
|
|
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,11 +2116,11 @@ 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
2125
|
function Nr(e, t) {
|
|
2126
2126
|
if (!t)
|
|
@@ -2175,24 +2175,24 @@ const Sr = /* @__PURE__ */ qs({ blockSize: 16, nonceLength: 16 }, function(t, n,
|
|
|
2175
2175
|
return {
|
|
2176
2176
|
encrypt: (s, o) => {
|
|
2177
2177
|
const c = Kr(t), { b: a, o: l, out: f } = Js(s, i, o), u = F(n);
|
|
2178
|
-
let
|
|
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
2189
|
const c = Zs(t), a = F(n), l = Nr(s.length, o), f = F(s), u = F(l);
|
|
2190
|
-
let
|
|
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
|
}
|
|
@@ -2205,24 +2205,24 @@ function L(e, t) {
|
|
|
2205
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 = Wt(i) && Wt(s),
|
|
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)
|
|
@@ -2246,33 +2246,33 @@ function io(e, t) {
|
|
|
2246
2246
|
else
|
|
2247
2247
|
throw new Error(`arx: invalid 32-byte key, got length=${g}`);
|
|
2248
2248
|
Wt(a) || (a = a.slice(), w.push(a));
|
|
2249
|
-
const
|
|
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
|
|
@@ -2447,7 +2447,7 @@ 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
2453
|
BadgeAward: () => No,
|
|
@@ -2507,14 +2507,14 @@ H(go, {
|
|
|
2507
2507
|
OpenTimestamps: () => So,
|
|
2508
2508
|
Pinlist: () => Do,
|
|
2509
2509
|
PrivateDirectMessage: () => Or,
|
|
2510
|
-
ProblemTracker: () =>
|
|
2510
|
+
ProblemTracker: () => ko,
|
|
2511
2511
|
ProfileBadges: () => aa,
|
|
2512
2512
|
PublicChatsList: () => Wo,
|
|
2513
2513
|
Reaction: () => un,
|
|
2514
2514
|
RecommendRelay: () => mo,
|
|
2515
2515
|
RelayList: () => qo,
|
|
2516
2516
|
Relaysets: () => ia,
|
|
2517
|
-
Report: () =>
|
|
2517
|
+
Report: () => Bo,
|
|
2518
2518
|
Reporting: () => Io,
|
|
2519
2519
|
Repost: () => cn,
|
|
2520
2520
|
Seal: () => Tr,
|
|
@@ -2552,12 +2552,12 @@ 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, 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,
|
|
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
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
|
});
|
|
@@ -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,7 +2582,7 @@ function Ba(e) {
|
|
|
2582
2582
|
let s = r + 1 + i;
|
|
2583
2583
|
return e.slice(r + 1, s);
|
|
2584
2584
|
}
|
|
2585
|
-
function
|
|
2585
|
+
function Ba(e, t) {
|
|
2586
2586
|
return t === hn(e, "id");
|
|
2587
2587
|
}
|
|
2588
2588
|
function Ia(e, t) {
|
|
@@ -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
|
}
|
|
@@ -3066,14 +3066,14 @@ function fc(e) {
|
|
|
3066
3066
|
};
|
|
3067
3067
|
}
|
|
3068
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 =
|
|
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
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
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 = {
|
|
@@ -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,
|
|
@@ -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) {
|
|
@@ -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 (on(
|
|
3565
|
-
const
|
|
3566
|
-
|
|
3567
|
-
} else if (an(
|
|
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;
|
|
@@ -3874,7 +3865,7 @@ 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
3870
|
i ? ([a, l] = Me(s, q.getConversationKey(c, n), 2), f = {
|
|
3880
3871
|
publicKey: ae(r),
|
|
@@ -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
|
/**
|
|
@@ -3978,7 +3969,7 @@ class ot {
|
|
|
3978
3969
|
this.state.previousSendingChainMessageCount = this.state.sendingChainMessageNumber, this.state.sendingChainMessageNumber = 0, this.state.receivingChainMessageNumber = 0;
|
|
3979
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
|
|
@@ -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(
|
|
@@ -4241,29 +4232,33 @@ class Pe {
|
|
|
4241
4232
|
* @param nostrSubscribe - A function to subscribe to Nostr events
|
|
4242
4233
|
* @param inviteePublicKey - The invitee's public key
|
|
4243
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
|
|
4244
4236
|
* @returns An object containing the new session and an event to be published
|
|
4245
4237
|
*
|
|
4246
4238
|
* 1. Inner event: No signature, content encrypted with DH(inviter, invitee).
|
|
4247
|
-
* Purpose: Authenticate invitee. Contains invitee session key.
|
|
4239
|
+
* Purpose: Authenticate invitee. Contains invitee session key and deviceId.
|
|
4248
4240
|
* 2. Envelope: No signature, content encrypted with DH(inviter, random key).
|
|
4249
4241
|
* Purpose: Contains inner event. Hides invitee from others who might have the shared Nostr key.
|
|
4250
4242
|
|
|
4251
4243
|
* Note: You need to publish the returned event on Nostr using NDK or another Nostr system of your choice,
|
|
4252
4244
|
* so the inviter can create the session on their side.
|
|
4253
4245
|
*/
|
|
4254
|
-
async accept(t, n, r) {
|
|
4255
|
-
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 = {
|
|
4256
4251
|
pubkey: n,
|
|
4257
|
-
content: await q.encrypt(
|
|
4252
|
+
content: await q.encrypt(y, a),
|
|
4258
4253
|
created_at: Math.floor(Date.now() / 1e3)
|
|
4259
|
-
},
|
|
4254
|
+
}, g = JSON.stringify(w), h = Be(), d = ae(h), p = {
|
|
4260
4255
|
kind: Zn,
|
|
4261
|
-
pubkey:
|
|
4262
|
-
content: q.encrypt(
|
|
4256
|
+
pubkey: d,
|
|
4257
|
+
content: q.encrypt(g, Qe(h, this.inviterEphemeralPublicKey)),
|
|
4263
4258
|
created_at: lu(),
|
|
4264
4259
|
tags: [["p", this.inviterEphemeralPublicKey]]
|
|
4265
4260
|
};
|
|
4266
|
-
return { session:
|
|
4261
|
+
return { session: l, event: Q(p, h) };
|
|
4267
4262
|
}
|
|
4268
4263
|
listen(t, n, r) {
|
|
4269
4264
|
if (!this.inviterEphemeralPrivateKey)
|
|
@@ -4278,8 +4273,16 @@ class Pe {
|
|
|
4278
4273
|
return;
|
|
4279
4274
|
const o = await q.decrypt(s.content, Qe(this.inviterEphemeralPrivateKey, s.pubkey)), c = JSON.parse(o), a = j(this.sharedSecret), l = c.pubkey;
|
|
4280
4275
|
this.usedBy.push(l);
|
|
4281
|
-
const f = await q.decrypt(c.content, a),
|
|
4282
|
-
|
|
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);
|
|
4283
4286
|
} catch {
|
|
4284
4287
|
}
|
|
4285
4288
|
});
|