nostr-double-ratchet 0.0.24 → 0.0.25
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.map +1 -1
- package/dist/nostr-double-ratchet.es.js +200 -200
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Invite.ts +2 -1
- package/src/types.ts +1 -1
|
@@ -214,13 +214,13 @@ let Ii = class extends Ci {
|
|
|
214
214
|
for (let u = 0; u < 16; u++, n += 4)
|
|
215
215
|
ve[u] = t.getUint32(n, !1);
|
|
216
216
|
for (let u = 16; u < 64; u++) {
|
|
217
|
-
const
|
|
217
|
+
const g = ve[u - 15], w = ve[u - 2], y = re(g, 7) ^ re(g, 18) ^ g >>> 3, h = re(w, 17) ^ re(w, 19) ^ w >>> 10;
|
|
218
218
|
ve[u] = h + ve[u - 7] + y + ve[u - 16] | 0;
|
|
219
219
|
}
|
|
220
220
|
let { A: r, B: i, C: s, D: o, E: c, F: a, G: l, H: f } = this;
|
|
221
221
|
for (let u = 0; u < 64; u++) {
|
|
222
|
-
const
|
|
223
|
-
f = l, l = a, a = c, c = o +
|
|
222
|
+
const g = re(c, 6) ^ re(c, 11) ^ re(c, 25), w = f + g + Bi(c, a, l) + _i[u] + ve[u] | 0, h = (re(r, 2) ^ re(r, 13) ^ re(r, 22)) + ki(r, i, s) | 0;
|
|
223
|
+
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);
|
|
226
226
|
}
|
|
@@ -348,20 +348,20 @@ function Jn(e, t, n) {
|
|
|
348
348
|
if (s++ >= 1e3)
|
|
349
349
|
throw new Error("drbg: tried 1000 values");
|
|
350
350
|
let u = 0;
|
|
351
|
-
const
|
|
351
|
+
const g = [];
|
|
352
352
|
for (; u < t; ) {
|
|
353
353
|
r = c();
|
|
354
|
-
const
|
|
355
|
-
|
|
354
|
+
const w = r.slice();
|
|
355
|
+
g.push(w), u += r.length;
|
|
356
356
|
}
|
|
357
|
-
return _e(...
|
|
357
|
+
return _e(...g);
|
|
358
358
|
};
|
|
359
|
-
return (u,
|
|
359
|
+
return (u, g) => {
|
|
360
360
|
o(), a(u);
|
|
361
|
-
let
|
|
362
|
-
for (; !(
|
|
361
|
+
let w;
|
|
362
|
+
for (; !(w = g(l())); )
|
|
363
363
|
a();
|
|
364
|
-
return o(),
|
|
364
|
+
return o(), w;
|
|
365
365
|
};
|
|
366
366
|
}
|
|
367
367
|
const Hi = {
|
|
@@ -468,15 +468,15 @@ function zi(e) {
|
|
|
468
468
|
return function(c, a) {
|
|
469
469
|
if (c.pow(a, t) === c.neg(c.ONE))
|
|
470
470
|
throw new Error("Cannot find square root");
|
|
471
|
-
let l = r, f = c.pow(c.mul(c.ONE, i), n), u = c.pow(a, s),
|
|
472
|
-
for (; !c.eql(
|
|
473
|
-
if (c.eql(
|
|
471
|
+
let l = r, f = c.pow(c.mul(c.ONE, i), n), u = c.pow(a, s), g = c.pow(a, n);
|
|
472
|
+
for (; !c.eql(g, c.ONE); ) {
|
|
473
|
+
if (c.eql(g, c.ZERO))
|
|
474
474
|
return c.ZERO;
|
|
475
|
-
let
|
|
476
|
-
for (let h = c.sqr(
|
|
475
|
+
let w = 1;
|
|
476
|
+
for (let h = c.sqr(g); w < l && !c.eql(h, c.ONE); w++)
|
|
477
477
|
h = c.sqr(h);
|
|
478
|
-
const y = c.pow(f, j << BigInt(l -
|
|
479
|
-
f = c.sqr(y), u = c.mul(u, y),
|
|
478
|
+
const y = c.pow(f, j << BigInt(l - w - 1));
|
|
479
|
+
f = c.sqr(y), u = c.mul(u, y), g = c.mul(g, f), l = w;
|
|
480
480
|
}
|
|
481
481
|
return u;
|
|
482
482
|
};
|
|
@@ -650,7 +650,7 @@ function Qi(e, t) {
|
|
|
650
650
|
let l = i, f = l;
|
|
651
651
|
for (let u = 0; u < o; u++) {
|
|
652
652
|
f = l, a.push(f);
|
|
653
|
-
for (let
|
|
653
|
+
for (let g = 1; g < c; g++)
|
|
654
654
|
f = f.add(l), a.push(f);
|
|
655
655
|
l = f.double();
|
|
656
656
|
}
|
|
@@ -666,13 +666,13 @@ function Qi(e, t) {
|
|
|
666
666
|
wNAF(i, s, o) {
|
|
667
667
|
const { windows: c, windowSize: a } = r(i);
|
|
668
668
|
let l = e.ZERO, f = e.BASE;
|
|
669
|
-
const u = BigInt(2 ** i - 1),
|
|
669
|
+
const u = BigInt(2 ** i - 1), g = 2 ** i, w = BigInt(i);
|
|
670
670
|
for (let y = 0; y < c; y++) {
|
|
671
671
|
const h = y * a;
|
|
672
672
|
let d = Number(o & u);
|
|
673
|
-
o >>=
|
|
674
|
-
const
|
|
675
|
-
d === 0 ? f = f.add(n(S, s[
|
|
673
|
+
o >>= w, d > a && (d -= g, o += St);
|
|
674
|
+
const p = h, E = h + Math.abs(d) - 1, S = y % 2 !== 0, I = d < 0;
|
|
675
|
+
d === 0 ? f = f.add(n(S, s[p])) : l = l.add(n(I, s[E]));
|
|
676
676
|
}
|
|
677
677
|
return { p: l, f };
|
|
678
678
|
},
|
|
@@ -769,14 +769,14 @@ const kn = BigInt(3);
|
|
|
769
769
|
BigInt(4);
|
|
770
770
|
function rs(e) {
|
|
771
771
|
const t = es(e), { Fp: n } = t, r = t.toBytes || ((y, h, d) => {
|
|
772
|
-
const
|
|
773
|
-
return _e(Uint8Array.from([4]), n.toBytes(
|
|
772
|
+
const p = h.toAffine();
|
|
773
|
+
return _e(Uint8Array.from([4]), n.toBytes(p.x), n.toBytes(p.y));
|
|
774
774
|
}), i = t.fromBytes || ((y) => {
|
|
775
|
-
const h = y.subarray(1), d = n.fromBytes(h.subarray(0, n.BYTES)),
|
|
776
|
-
return { x: d, y:
|
|
775
|
+
const h = y.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(y) {
|
|
779
|
-
const { a: h, b: d } = t,
|
|
779
|
+
const { a: h, b: d } = t, p = n.sqr(y), E = n.mul(p, y);
|
|
780
780
|
return n.add(n.add(E, n.mul(y, h)), d);
|
|
781
781
|
}
|
|
782
782
|
if (!n.eql(n.sqr(t.Gy), s(t.Gx)))
|
|
@@ -789,7 +789,7 @@ function rs(e) {
|
|
|
789
789
|
throw new Error("Expected valid bigint: 0 < bigint < curve.n");
|
|
790
790
|
}
|
|
791
791
|
function a(y) {
|
|
792
|
-
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey:
|
|
792
|
+
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey: p, n: E } = t;
|
|
793
793
|
if (h && typeof y != "bigint") {
|
|
794
794
|
if (y instanceof Uint8Array && (y = De(y)), typeof y != "string" || !h.includes(y.length))
|
|
795
795
|
throw new Error("Invalid key");
|
|
@@ -801,7 +801,7 @@ function rs(e) {
|
|
|
801
801
|
} catch {
|
|
802
802
|
throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof y}`);
|
|
803
803
|
}
|
|
804
|
-
return
|
|
804
|
+
return p && (S = W(S, E)), c(S), S;
|
|
805
805
|
}
|
|
806
806
|
const l = /* @__PURE__ */ new Map();
|
|
807
807
|
function f(y) {
|
|
@@ -809,24 +809,24 @@ function rs(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:
|
|
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
828
|
const E = (S) => n.eql(S, n.ZERO);
|
|
829
|
-
return E(d) && E(
|
|
829
|
+
return E(d) && E(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 rs(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, E) => p.toAffine(d[E])).map(u.fromAffine);
|
|
846
846
|
}
|
|
847
847
|
/**
|
|
848
848
|
* Converts hash string or Uint8Array to Point.
|
|
@@ -870,8 +870,8 @@ function rs(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), E = s(h);
|
|
874
|
+
if (!n.eql(p, E))
|
|
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,7 +887,7 @@ function rs(e) {
|
|
|
887
887
|
*/
|
|
888
888
|
equals(h) {
|
|
889
889
|
f(h);
|
|
890
|
-
const { px: d, py:
|
|
890
|
+
const { px: d, py: p, pz: E } = this, { px: S, py: I, pz: B } = h, m = n.eql(n.mul(d, B), n.mul(S, E)), x = n.eql(n.mul(p, B), n.mul(I, E));
|
|
891
891
|
return m && x;
|
|
892
892
|
}
|
|
893
893
|
/**
|
|
@@ -901,9 +901,9 @@ function rs(e) {
|
|
|
901
901
|
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
902
902
|
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
903
903
|
double() {
|
|
904
|
-
const { a: h, b: d } = t,
|
|
904
|
+
const { a: h, b: d } = t, p = n.mul(d, kn), { px: E, py: S, pz: I } = this;
|
|
905
905
|
let B = n.ZERO, m = n.ZERO, x = n.ZERO, K = n.mul(E, E), M = n.mul(S, S), _ = n.mul(I, I), A = n.mul(E, S);
|
|
906
|
-
return A = n.add(A, A), x = n.mul(E, I), x = n.add(x, x), B = n.mul(h, x), m = n.mul(
|
|
906
|
+
return A = n.add(A, A), x = n.mul(E, I), x = n.add(x, x), B = n.mul(h, x), m = n.mul(p, _), m = n.add(B, m), B = n.sub(M, m), m = n.add(M, m), m = n.mul(B, m), B = n.mul(A, B), x = n.mul(p, x), _ = n.mul(h, _), A = n.sub(K, _), A = n.mul(h, A), A = n.add(A, x), x = n.add(K, K), K = n.add(x, K), K = n.add(K, _), K = n.mul(K, A), m = n.add(m, K), _ = n.mul(S, I), _ = n.add(_, _), K = n.mul(_, A), B = n.sub(B, K), x = n.mul(_, M), x = n.add(x, x), x = n.add(x, x), new u(B, m, x);
|
|
907
907
|
}
|
|
908
908
|
// Renes-Costello-Batina exception-free addition formula.
|
|
909
909
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
@@ -911,13 +911,13 @@ function rs(e) {
|
|
|
911
911
|
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
912
912
|
add(h) {
|
|
913
913
|
f(h);
|
|
914
|
-
const { px: d, py:
|
|
914
|
+
const { px: d, py: p, pz: E } = this, { px: S, py: I, pz: B } = h;
|
|
915
915
|
let m = n.ZERO, x = n.ZERO, K = n.ZERO;
|
|
916
916
|
const M = t.a, _ = n.mul(t.b, kn);
|
|
917
|
-
let A = n.mul(d, S), T = n.mul(
|
|
918
|
-
H = n.mul(H,
|
|
917
|
+
let A = n.mul(d, S), T = n.mul(p, I), R = n.mul(E, B), H = n.add(d, p), b = n.add(S, I);
|
|
918
|
+
H = n.mul(H, b), b = n.add(A, T), H = n.sub(H, b), b = n.add(d, E);
|
|
919
919
|
let v = n.add(S, B);
|
|
920
|
-
return
|
|
920
|
+
return b = n.mul(b, v), v = n.add(A, R), b = n.sub(b, v), v = n.add(p, E), m = n.add(I, B), v = n.mul(v, m), m = n.add(T, R), v = n.sub(v, m), K = n.mul(M, b), m = n.mul(_, R), K = n.add(m, K), m = n.sub(T, K), K = n.add(T, K), x = n.mul(m, K), T = n.add(A, A), T = n.add(T, A), R = n.mul(M, R), b = n.mul(_, b), T = n.add(T, R), R = n.sub(A, R), R = n.mul(M, R), b = n.add(b, R), A = n.mul(T, b), x = n.add(x, A), A = n.mul(v, b), m = n.mul(H, m), m = n.sub(m, A), A = n.mul(H, T), K = n.mul(v, K), K = n.add(K, A), new u(m, x, K);
|
|
921
921
|
}
|
|
922
922
|
subtract(h) {
|
|
923
923
|
return this.add(h.negate());
|
|
@@ -926,9 +926,9 @@ function rs(e) {
|
|
|
926
926
|
return this.equals(u.ZERO);
|
|
927
927
|
}
|
|
928
928
|
wNAF(h) {
|
|
929
|
-
return
|
|
930
|
-
const
|
|
931
|
-
return d.map((E, S) => E.toAffine(
|
|
929
|
+
return w.wNAFCached(this, l, h, (d) => {
|
|
930
|
+
const p = n.invertBatch(d.map((E) => E.pz));
|
|
931
|
+
return d.map((E, S) => E.toAffine(p[S])).map(u.fromAffine);
|
|
932
932
|
});
|
|
933
933
|
}
|
|
934
934
|
/**
|
|
@@ -942,13 +942,13 @@ function rs(e) {
|
|
|
942
942
|
return d;
|
|
943
943
|
if (c(h), h === X)
|
|
944
944
|
return this;
|
|
945
|
-
const { endo:
|
|
946
|
-
if (!
|
|
947
|
-
return
|
|
948
|
-
let { k1neg: E, k1: S, k2neg: I, k2: B } =
|
|
945
|
+
const { endo: p } = t;
|
|
946
|
+
if (!p)
|
|
947
|
+
return w.unsafeLadder(this, h);
|
|
948
|
+
let { k1neg: E, k1: S, k2neg: I, k2: B } = p.splitScalar(h), m = d, x = d, K = this;
|
|
949
949
|
for (; S > ae || B > ae; )
|
|
950
950
|
S & X && (m = m.add(K)), B & X && (x = x.add(K)), K = K.double(), S >>= X, B >>= X;
|
|
951
|
-
return E && (m = m.negate()), I && (x = x.negate()), x = new u(n.mul(x.px,
|
|
951
|
+
return E && (m = m.negate()), I && (x = x.negate()), x = new u(n.mul(x.px, p.beta), x.py, x.pz), m.add(x);
|
|
952
952
|
}
|
|
953
953
|
/**
|
|
954
954
|
* Constant time multiplication.
|
|
@@ -961,17 +961,17 @@ function rs(e) {
|
|
|
961
961
|
*/
|
|
962
962
|
multiply(h) {
|
|
963
963
|
c(h);
|
|
964
|
-
let d = h,
|
|
964
|
+
let d = h, p, E;
|
|
965
965
|
const { endo: S } = t;
|
|
966
966
|
if (S) {
|
|
967
967
|
const { k1neg: I, k1: B, k2neg: m, k2: x } = S.splitScalar(d);
|
|
968
968
|
let { p: K, f: M } = this.wNAF(B), { p: _, f: A } = this.wNAF(x);
|
|
969
|
-
K =
|
|
969
|
+
K = w.constTimeNegate(I, K), _ = w.constTimeNegate(m, _), _ = new u(n.mul(_.px, S.beta), _.py, _.pz), p = K.add(_), E = M.add(A);
|
|
970
970
|
} else {
|
|
971
971
|
const { p: I, f: B } = this.wNAF(d);
|
|
972
|
-
|
|
972
|
+
p = I, E = B;
|
|
973
973
|
}
|
|
974
|
-
return u.normalizeZ([
|
|
974
|
+
return u.normalizeZ([p, E])[0];
|
|
975
975
|
}
|
|
976
976
|
/**
|
|
977
977
|
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
@@ -979,17 +979,17 @@ function rs(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 E = u.BASE, S = (B, m) => m === ae || m === X || !B.equals(E) ? B.multiplyUnsafe(m) : B.multiply(m), I = S(this, d).add(S(h,
|
|
982
|
+
multiplyAndAddUnsafe(h, d, p) {
|
|
983
|
+
const E = u.BASE, S = (B, m) => m === ae || m === X || !B.equals(E) ? B.multiplyUnsafe(m) : B.multiply(m), I = S(this, d).add(S(h, p));
|
|
984
984
|
return I.is0() ? void 0 : I;
|
|
985
985
|
}
|
|
986
986
|
// Converts Projective point to affine (x, y) coordinates.
|
|
987
987
|
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
988
988
|
// (x, y, z) ∋ (x=x/z, y=y/z)
|
|
989
989
|
toAffine(h) {
|
|
990
|
-
const { px: d, py:
|
|
990
|
+
const { px: d, py: p, pz: E } = this, S = this.is0();
|
|
991
991
|
h == null && (h = S ? n.ONE : n.inv(E));
|
|
992
|
-
const I = n.mul(d, h), B = n.mul(
|
|
992
|
+
const I = n.mul(d, h), B = n.mul(p, h), m = n.mul(E, h);
|
|
993
993
|
if (S)
|
|
994
994
|
return { x: n.ZERO, y: n.ZERO };
|
|
995
995
|
if (!n.eql(m, n.ONE))
|
|
@@ -1016,7 +1016,7 @@ function rs(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 g = t.nBitLength, w = Qi(u, t.endo ? Math.ceil(g / 2) : g);
|
|
1020
1020
|
return {
|
|
1021
1021
|
CURVE: t,
|
|
1022
1022
|
ProjectivePoint: u,
|
|
@@ -1039,23 +1039,23 @@ function is(e) {
|
|
|
1039
1039
|
}
|
|
1040
1040
|
function ss(e) {
|
|
1041
1041
|
const t = is(e), { Fp: n, n: r } = t, i = n.BYTES + 1, s = 2 * n.BYTES + 1;
|
|
1042
|
-
function o(
|
|
1043
|
-
return ae <
|
|
1042
|
+
function o(b) {
|
|
1043
|
+
return ae < b && b < n.ORDER;
|
|
1044
1044
|
}
|
|
1045
|
-
function c(
|
|
1046
|
-
return W(
|
|
1045
|
+
function c(b) {
|
|
1046
|
+
return W(b, r);
|
|
1047
1047
|
}
|
|
1048
|
-
function a(
|
|
1049
|
-
return Tt(
|
|
1048
|
+
function a(b) {
|
|
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: g } = rs({
|
|
1052
1052
|
...t,
|
|
1053
|
-
toBytes(
|
|
1053
|
+
toBytes(b, v, N) {
|
|
1054
1054
|
const k = v.toAffine(), C = n.toBytes(k.x), U = _e;
|
|
1055
1055
|
return N ? U(Uint8Array.from([v.hasEvenY() ? 2 : 3]), C) : U(Uint8Array.from([4]), C, n.toBytes(k.y));
|
|
1056
1056
|
},
|
|
1057
|
-
fromBytes(
|
|
1058
|
-
const v =
|
|
1057
|
+
fromBytes(b) {
|
|
1058
|
+
const v = b.length, N = b[0], k = b.subarray(1);
|
|
1059
1059
|
if (v === i && (N === 2 || N === 3)) {
|
|
1060
1060
|
const C = F(k);
|
|
1061
1061
|
if (!o(C))
|
|
@@ -1070,38 +1070,38 @@ 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
|
-
}),
|
|
1074
|
-
function y(
|
|
1073
|
+
}), w = (b) => De(Ne(b, t.nByteLength));
|
|
1074
|
+
function y(b) {
|
|
1075
1075
|
const v = r >> X;
|
|
1076
|
-
return
|
|
1076
|
+
return b > v;
|
|
1077
1077
|
}
|
|
1078
|
-
function h(
|
|
1079
|
-
return y(
|
|
1078
|
+
function h(b) {
|
|
1079
|
+
return y(b) ? c(-b) : b;
|
|
1080
1080
|
}
|
|
1081
|
-
const d = (
|
|
1082
|
-
class
|
|
1081
|
+
const d = (b, v, N) => F(b.slice(v, N));
|
|
1082
|
+
class p {
|
|
1083
1083
|
constructor(v, N, k) {
|
|
1084
1084
|
this.r = v, this.s = N, this.recovery = k, this.assertValidity();
|
|
1085
1085
|
}
|
|
1086
1086
|
// pair (bytes of r, bytes of s)
|
|
1087
1087
|
static fromCompact(v) {
|
|
1088
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
1094
|
const { r: N, s: k } = Be.toSig(Z("DER", v));
|
|
1095
|
-
return new
|
|
1095
|
+
return new p(N, k);
|
|
1096
1096
|
}
|
|
1097
1097
|
assertValidity() {
|
|
1098
|
-
if (!
|
|
1098
|
+
if (!g(this.r))
|
|
1099
1099
|
throw new Error("r must be 0 < r < CURVE.n");
|
|
1100
|
-
if (!
|
|
1100
|
+
if (!g(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
1107
|
const { r: N, s: k, recovery: C } = this, U = x(Z("msgHash", 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", ee = l.fromHex($ +
|
|
1113
|
+
const $ = C & 1 ? "03" : "02", ee = l.fromHex($ + w(O)), ge = a(O), Ue = c(-U * ge), We = c(k * ge), we = l.BASE.multiplyAndAddUnsafe(ee, Ue, We);
|
|
1114
1114
|
if (!we)
|
|
1115
1115
|
throw new Error("point at infinify");
|
|
1116
1116
|
return we.assertValidity(), we;
|
|
@@ -1120,7 +1120,7 @@ function ss(e) {
|
|
|
1120
1120
|
return y(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() {
|
|
@@ -1134,13 +1134,13 @@ function ss(e) {
|
|
|
1134
1134
|
return je(this.toCompactHex());
|
|
1135
1135
|
}
|
|
1136
1136
|
toCompactHex() {
|
|
1137
|
-
return
|
|
1137
|
+
return w(this.r) + w(this.s);
|
|
1138
1138
|
}
|
|
1139
1139
|
}
|
|
1140
1140
|
const E = {
|
|
1141
|
-
isValidPrivateKey(
|
|
1141
|
+
isValidPrivateKey(b) {
|
|
1142
1142
|
try {
|
|
1143
|
-
return f(
|
|
1143
|
+
return f(b), !0;
|
|
1144
1144
|
} catch {
|
|
1145
1145
|
return !1;
|
|
1146
1146
|
}
|
|
@@ -1151,8 +1151,8 @@ function ss(e) {
|
|
|
1151
1151
|
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
|
1152
1152
|
*/
|
|
1153
1153
|
randomPrivateKey: () => {
|
|
1154
|
-
const
|
|
1155
|
-
return Yi(t.randomBytes(
|
|
1154
|
+
const b = Qn(t.n);
|
|
1155
|
+
return Yi(t.randomBytes(b), t.n);
|
|
1156
1156
|
},
|
|
1157
1157
|
/**
|
|
1158
1158
|
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
|
@@ -1162,44 +1162,44 @@ function ss(e) {
|
|
|
1162
1162
|
* const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
|
|
1163
1163
|
* fast.multiply(privKey); // much faster ECDH now
|
|
1164
1164
|
*/
|
|
1165
|
-
precompute(
|
|
1166
|
-
return v._setWindowSize(
|
|
1165
|
+
precompute(b = 8, v = l.BASE) {
|
|
1166
|
+
return v._setWindowSize(b), v.multiply(BigInt(3)), v;
|
|
1167
1167
|
}
|
|
1168
1168
|
};
|
|
1169
|
-
function S(
|
|
1170
|
-
return l.fromPrivateKey(
|
|
1169
|
+
function S(b, v = !0) {
|
|
1170
|
+
return l.fromPrivateKey(b).toRawBytes(v);
|
|
1171
1171
|
}
|
|
1172
|
-
function I(
|
|
1173
|
-
const v =
|
|
1174
|
-
return v ? k === i || k === s : N ? k === 2 * i || k === 2 * s :
|
|
1172
|
+
function I(b) {
|
|
1173
|
+
const v = b instanceof Uint8Array, N = typeof b == "string", k = (v || N) && b.length;
|
|
1174
|
+
return v ? k === i || k === s : N ? k === 2 * i || k === 2 * s : b instanceof l;
|
|
1175
1175
|
}
|
|
1176
|
-
function B(
|
|
1177
|
-
if (I(
|
|
1176
|
+
function B(b, v, N = !0) {
|
|
1177
|
+
if (I(b))
|
|
1178
1178
|
throw new Error("first arg must be private key");
|
|
1179
1179
|
if (!I(v))
|
|
1180
1180
|
throw new Error("second arg must be public key");
|
|
1181
|
-
return l.fromHex(v).multiply(f(
|
|
1181
|
+
return l.fromHex(v).multiply(f(b)).toRawBytes(N);
|
|
1182
1182
|
}
|
|
1183
|
-
const m = t.bits2int || function(
|
|
1184
|
-
const v = F(
|
|
1183
|
+
const m = t.bits2int || function(b) {
|
|
1184
|
+
const v = F(b), N = b.length * 8 - t.nBitLength;
|
|
1185
1185
|
return N > 0 ? v >> BigInt(N) : v;
|
|
1186
|
-
}, x = t.bits2int_modN || function(
|
|
1187
|
-
return c(m(
|
|
1186
|
+
}, x = t.bits2int_modN || function(b) {
|
|
1187
|
+
return c(m(b));
|
|
1188
1188
|
}, K = Jt(t.nBitLength);
|
|
1189
|
-
function M(
|
|
1190
|
-
if (typeof
|
|
1189
|
+
function M(b) {
|
|
1190
|
+
if (typeof b != "bigint")
|
|
1191
1191
|
throw new Error("bigint expected");
|
|
1192
|
-
if (!(ae <=
|
|
1192
|
+
if (!(ae <= b && b < K))
|
|
1193
1193
|
throw new Error(`bigint expected < 2^${t.nBitLength}`);
|
|
1194
|
-
return Ne(
|
|
1194
|
+
return Ne(b, t.nByteLength);
|
|
1195
1195
|
}
|
|
1196
|
-
function _(
|
|
1196
|
+
function _(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
1199
|
const { hash: k, randomBytes: C } = t;
|
|
1200
1200
|
let { lowS: U, prehash: O, extraEntropy: $ } = N;
|
|
1201
|
-
U == null && (U = !0),
|
|
1202
|
-
const ee = x(
|
|
1201
|
+
U == null && (U = !0), b = Z("msgHash", b), O && (b = Z("prehashed msgHash", k(b)));
|
|
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) : $;
|
|
1205
1205
|
Ue.push(Z("extraEntropy", Ae));
|
|
@@ -1207,7 +1207,7 @@ function ss(e) {
|
|
|
1207
1207
|
const We = _e(...Ue), we = ee;
|
|
1208
1208
|
function Et(Ae) {
|
|
1209
1209
|
const Le = m(Ae);
|
|
1210
|
-
if (!
|
|
1210
|
+
if (!g(Le))
|
|
1211
1211
|
return;
|
|
1212
1212
|
const xn = a(Le), $e = l.BASE.multiply(Le).toAffine(), te = c($e.x);
|
|
1213
1213
|
if (te === ae)
|
|
@@ -1216,19 +1216,19 @@ function ss(e) {
|
|
|
1216
1216
|
if (Te === ae)
|
|
1217
1217
|
return;
|
|
1218
1218
|
let Kn = ($e.x === te ? 0 : 2) | Number($e.y & X), Nn = Te;
|
|
1219
|
-
return U && y(Te) && (Nn = h(Te), Kn ^= 1), new
|
|
1219
|
+
return U && y(Te) && (Nn = h(Te), Kn ^= 1), new p(te, Nn, Kn);
|
|
1220
1220
|
}
|
|
1221
1221
|
return { seed: We, k2sig: Et };
|
|
1222
1222
|
}
|
|
1223
1223
|
const A = { lowS: t.lowS, prehash: !1 }, T = { lowS: t.lowS, prehash: !1 };
|
|
1224
|
-
function R(
|
|
1225
|
-
const { seed: k, k2sig: C } = _(
|
|
1224
|
+
function R(b, v, N = A) {
|
|
1225
|
+
const { seed: k, k2sig: C } = _(b, v, N), U = t;
|
|
1226
1226
|
return Jn(U.hash.outputLen, U.nByteLength, U.hmac)(k, C);
|
|
1227
1227
|
}
|
|
1228
1228
|
l.BASE._setWindowSize(8);
|
|
1229
|
-
function H(
|
|
1229
|
+
function H(b, v, N, k = T) {
|
|
1230
1230
|
var $e;
|
|
1231
|
-
const C =
|
|
1231
|
+
const C = b;
|
|
1232
1232
|
if (v = Z("msgHash", v), N = Z("publicKey", N), "strict" in k)
|
|
1233
1233
|
throw new Error("options.strict was renamed to lowS");
|
|
1234
1234
|
const { lowS: U, prehash: O } = k;
|
|
@@ -1236,15 +1236,15 @@ function ss(e) {
|
|
|
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
1241
|
if (!(te instanceof Be.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: Te } = C;
|
|
1247
|
-
$ = new
|
|
1247
|
+
$ = new p(te, Te);
|
|
1248
1248
|
} else
|
|
1249
1249
|
throw new Error("PARSE");
|
|
1250
1250
|
ee = l.fromHex(N);
|
|
@@ -1266,7 +1266,7 @@ function ss(e) {
|
|
|
1266
1266
|
sign: R,
|
|
1267
1267
|
verify: H,
|
|
1268
1268
|
ProjectivePoint: l,
|
|
1269
|
-
Signature:
|
|
1269
|
+
Signature: p,
|
|
1270
1270
|
utils: E
|
|
1271
1271
|
};
|
|
1272
1272
|
}
|
|
@@ -1322,7 +1322,7 @@ function as(e, t) {
|
|
|
1322
1322
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1323
1323
|
const ct = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), tt = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), rr = BigInt(1), nt = BigInt(2), _n = (e, t) => (e + t / nt) / t;
|
|
1324
1324
|
function ir(e) {
|
|
1325
|
-
const t = ct, n = BigInt(3), r = BigInt(6), i = BigInt(11), s = BigInt(22), o = BigInt(23), c = BigInt(44), a = BigInt(88), l = e * e * e % t, f = l * l * e % t, u = Y(f, n, t) * f % t,
|
|
1325
|
+
const t = ct, n = BigInt(3), r = BigInt(6), i = BigInt(11), s = BigInt(22), o = BigInt(23), c = BigInt(44), a = BigInt(88), l = e * e * e % t, f = l * l * e % t, u = Y(f, n, t) * f % t, g = Y(u, n, t) * f % t, w = Y(g, nt, t) * l % t, y = Y(w, i, t) * w % t, h = Y(y, s, t) * y % t, d = Y(h, c, t) * h % t, p = Y(d, a, t) * d % t, E = Y(p, c, t) * h % t, S = Y(E, n, t) * f % t, I = Y(S, o, t) * y % t, B = Y(I, r, t) * l % t, m = Y(B, nt, t);
|
|
1326
1326
|
if (!Rt.eql(Rt.sqr(m), e))
|
|
1327
1327
|
throw new Error("Cannot find square root");
|
|
1328
1328
|
return m;
|
|
@@ -1348,10 +1348,10 @@ const Rt = Ji(ct, void 0, void 0, { sqrt: ir }), Ie = as({
|
|
|
1348
1348
|
splitScalar: (e) => {
|
|
1349
1349
|
const t = tt, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -rr * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), s = n, o = BigInt("0x100000000000000000000000000000000"), c = _n(s * e, t), a = _n(-r * e, t);
|
|
1350
1350
|
let l = W(e - c * n - a * i, t), f = W(-c * r - a * s, t);
|
|
1351
|
-
const u = l > o,
|
|
1352
|
-
if (u && (l = t - l),
|
|
1351
|
+
const u = l > o, g = f > o;
|
|
1352
|
+
if (u && (l = t - l), g && (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: g, k2: f };
|
|
1355
1355
|
}
|
|
1356
1356
|
}
|
|
1357
1357
|
}, Lt), ut = BigInt(0), sr = (e) => typeof e == "bigint" && ut < e && e < ct, cs = (e) => typeof e == "bigint" && ut < e && e < tt, In = {};
|
|
@@ -1387,10 +1387,10 @@ function fs(e, t, n = Zn(32)) {
|
|
|
1387
1387
|
const r = Z("message", e), { bytes: i, scalar: s } = Pt(t), o = Z("auxRand", n, 32), c = Ot(s ^ F(rt("BIP0340/aux", o))), a = rt("BIP0340/nonce", c, i, r), l = Fe(F(a));
|
|
1388
1388
|
if (l === ut)
|
|
1389
1389
|
throw new Error("sign failed: k is zero");
|
|
1390
|
-
const { bytes: f, scalar: u } = Pt(l),
|
|
1391
|
-
if (
|
|
1390
|
+
const { bytes: f, scalar: u } = Pt(l), g = ar(f, i, r), w = new Uint8Array(64);
|
|
1391
|
+
if (w.set(f, 0), w.set(Ot(Fe(u + g * s)), 32), !cr(w, r, i))
|
|
1392
1392
|
throw new Error("sign: Invalid signature produced");
|
|
1393
|
-
return
|
|
1393
|
+
return w;
|
|
1394
1394
|
}
|
|
1395
1395
|
function cr(e, t, n) {
|
|
1396
1396
|
const r = Z("signature", e, 64), i = Z("message", t), s = Z("publicKey", n, 32);
|
|
@@ -1669,13 +1669,13 @@ class dr extends ms {
|
|
|
1669
1669
|
for (let u = 0; u < 16; u++, n += 4)
|
|
1670
1670
|
Ee[u] = t.getUint32(n, !1);
|
|
1671
1671
|
for (let u = 16; u < 64; u++) {
|
|
1672
|
-
const
|
|
1672
|
+
const g = Ee[u - 15], w = Ee[u - 2], y = ie(g, 7) ^ ie(g, 18) ^ g >>> 3, h = ie(w, 17) ^ ie(w, 19) ^ w >>> 10;
|
|
1673
1673
|
Ee[u] = h + Ee[u - 7] + y + Ee[u - 16] | 0;
|
|
1674
1674
|
}
|
|
1675
1675
|
let { A: r, B: i, C: s, D: o, E: c, F: a, G: l, H: f } = this;
|
|
1676
1676
|
for (let u = 0; u < 64; u++) {
|
|
1677
|
-
const
|
|
1678
|
-
f = l, l = a, a = c, c = o +
|
|
1677
|
+
const g = ie(c, 6) ^ ie(c, 11) ^ ie(c, 25), w = f + g + Es(c, a, l) + Ks[u] + Ee[u] | 0, h = (ie(r, 2) ^ ie(r, 13) ^ ie(r, 22)) + xs(r, i, s) | 0;
|
|
1678
|
+
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);
|
|
1681
1681
|
}
|
|
@@ -1937,14 +1937,14 @@ function Rn(e, t, n = 1) {
|
|
|
1937
1937
|
}
|
|
1938
1938
|
function gr(e) {
|
|
1939
1939
|
const t = e === "bech32" ? 1 : 734539939, n = Se(5), r = n.decode, i = n.encode, s = Ln(r);
|
|
1940
|
-
function o(f, u,
|
|
1940
|
+
function o(f, u, g = 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
|
-
const
|
|
1946
|
-
if (
|
|
1947
|
-
throw new TypeError(`Length ${
|
|
1945
|
+
const w = f.length + 7 + u.length;
|
|
1946
|
+
if (g !== !1 && w > g)
|
|
1947
|
+
throw new TypeError(`Length ${w} exceeds limit ${g}`);
|
|
1948
1948
|
return f = f.toLowerCase(), `${f}1${Dt.encode(u)}${Rn(f, u, t)}`;
|
|
1949
1949
|
}
|
|
1950
1950
|
function c(f, u = 90) {
|
|
@@ -1952,25 +1952,25 @@ function gr(e) {
|
|
|
1952
1952
|
throw new Error(`bech32.decode input should be string, not ${typeof f}`);
|
|
1953
1953
|
if (f.length < 8 || u !== !1 && f.length > u)
|
|
1954
1954
|
throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${u})`);
|
|
1955
|
-
const
|
|
1956
|
-
if (f !==
|
|
1955
|
+
const g = f.toLowerCase();
|
|
1956
|
+
if (f !== g && f !== f.toUpperCase())
|
|
1957
1957
|
throw new Error("String must be lowercase or uppercase");
|
|
1958
|
-
f =
|
|
1959
|
-
const
|
|
1960
|
-
if (
|
|
1958
|
+
f = g;
|
|
1959
|
+
const w = f.lastIndexOf("1");
|
|
1960
|
+
if (w === 0 || w === -1)
|
|
1961
1961
|
throw new Error('Letter "1" must be present between prefix and data only');
|
|
1962
|
-
const y = f.slice(0,
|
|
1962
|
+
const y = 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 = Dt.decode(h).slice(0, -6),
|
|
1966
|
-
if (!h.endsWith(
|
|
1967
|
-
throw new Error(`Invalid checksum in ${f}: expected "${
|
|
1965
|
+
const d = Dt.decode(h).slice(0, -6), p = Rn(y, d, t);
|
|
1966
|
+
if (!h.endsWith(p))
|
|
1967
|
+
throw new Error(`Invalid checksum in ${f}: expected "${p}"`);
|
|
1968
1968
|
return { prefix: y, words: d };
|
|
1969
1969
|
}
|
|
1970
1970
|
const a = Ln(c);
|
|
1971
1971
|
function l(f) {
|
|
1972
|
-
const { prefix: u, words:
|
|
1973
|
-
return { prefix: u, words:
|
|
1972
|
+
const { prefix: u, words: g } = c(f, !1);
|
|
1973
|
+
return { prefix: u, words: g, bytes: r(g) };
|
|
1974
1974
|
}
|
|
1975
1975
|
return { encode: o, decode: c, decodeToBytes: l, decodeUnsafe: a, fromWords: r, fromWordsUnsafe: s, toWords: i };
|
|
1976
1976
|
}
|
|
@@ -2104,11 +2104,11 @@ function Pn(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 y = 0; y < l; y++) {
|
|
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), E = e[a++] ^ xe(o, c, i, t, n, r);
|
|
2108
|
+
t = h, n = d, r = p, i = E;
|
|
2109
2109
|
}
|
|
2110
|
-
const f = e[a++] ^ oe(s, t, n, r, i), u = e[a++] ^ oe(s, n, r, i, t),
|
|
2111
|
-
return { s0: f, s1: u, s2:
|
|
2110
|
+
const f = e[a++] ^ oe(s, t, n, r, i), u = e[a++] ^ oe(s, n, r, i, t), g = e[a++] ^ oe(s, r, i, t, n), w = e[a++] ^ oe(s, i, t, n, r);
|
|
2111
|
+
return { s0: f, s1: u, s2: g, s3: w };
|
|
2112
2112
|
}
|
|
2113
2113
|
function js(e, t, n, r, i) {
|
|
2114
2114
|
const { sbox2: s, T01: o, T23: c } = br;
|
|
@@ -2116,11 +2116,11 @@ function js(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 y = 0; y < l; y++) {
|
|
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), E = e[a++] ^ xe(o, c, i, r, n, t);
|
|
2120
|
+
t = h, n = d, r = p, i = E;
|
|
2121
2121
|
}
|
|
2122
|
-
const f = e[a++] ^ oe(s, t, i, r, n), u = e[a++] ^ oe(s, n, t, i, r),
|
|
2123
|
-
return { s0: f, s1: u, s2:
|
|
2122
|
+
const f = e[a++] ^ oe(s, t, i, r, n), u = e[a++] ^ oe(s, n, t, i, r), g = e[a++] ^ oe(s, r, n, t, i), w = e[a++] ^ oe(s, i, r, n, t);
|
|
2123
|
+
return { s0: f, s1: u, s2: g, s3: w };
|
|
2124
2124
|
}
|
|
2125
2125
|
function mr(e, t) {
|
|
2126
2126
|
if (!t)
|
|
@@ -2175,24 +2175,24 @@ const Er = /* @__PURE__ */ Os({ blockSize: 16, nonceLength: 16 }, function(t, n,
|
|
|
2175
2175
|
return {
|
|
2176
2176
|
encrypt: (s, o) => {
|
|
2177
2177
|
const c = vr(t), { b: a, o: l, out: f } = Vs(s, i, o), u = G(n);
|
|
2178
|
-
let
|
|
2178
|
+
let g = u[0], w = u[1], y = u[2], h = u[3], d = 0;
|
|
2179
2179
|
for (; d + 4 <= a.length; )
|
|
2180
|
-
|
|
2180
|
+
g ^= a[d + 0], w ^= a[d + 1], y ^= a[d + 2], h ^= a[d + 3], { s0: g, s1: w, s2: y, s3: h } = Pn(c, g, w, y, h), l[d++] = g, l[d++] = w, l[d++] = y, l[d++] = h;
|
|
2181
2181
|
if (i) {
|
|
2182
|
-
const
|
|
2183
|
-
|
|
2182
|
+
const p = Zs(s.subarray(d * 4));
|
|
2183
|
+
g ^= p[0], w ^= p[1], y ^= p[2], h ^= p[3], { s0: g, s1: w, s2: y, s3: h } = Pn(c, g, w, y, h), l[d++] = g, l[d++] = w, l[d++] = y, l[d++] = h;
|
|
2184
2184
|
}
|
|
2185
2185
|
return c.fill(0), f;
|
|
2186
2186
|
},
|
|
2187
2187
|
decrypt: (s, o) => {
|
|
2188
2188
|
zs(s);
|
|
2189
2189
|
const c = Ds(t), a = G(n), l = mr(s.length, o), f = G(s), u = G(l);
|
|
2190
|
-
let
|
|
2190
|
+
let g = a[0], w = a[1], y = a[2], h = a[3];
|
|
2191
2191
|
for (let d = 0; d + 4 <= f.length; ) {
|
|
2192
|
-
const
|
|
2193
|
-
|
|
2194
|
-
const { s0: B, s1: m, s2: x, s3: K } = js(c,
|
|
2195
|
-
u[d++] = B ^
|
|
2192
|
+
const p = g, E = w, S = y, I = h;
|
|
2193
|
+
g = f[d + 0], w = f[d + 1], y = f[d + 2], h = f[d + 3];
|
|
2194
|
+
const { s0: B, s1: m, s2: x, s3: K } = js(c, g, w, y, h);
|
|
2195
|
+
u[d++] = B ^ p, u[d++] = m ^ E, u[d++] = x ^ S, u[d++] = K ^ I;
|
|
2196
2196
|
}
|
|
2197
2197
|
return c.fill(0), Ws(l, i);
|
|
2198
2198
|
}
|
|
@@ -2207,7 +2207,7 @@ function zt(e) {
|
|
|
2207
2207
|
}
|
|
2208
2208
|
const Xe = 64, Ys = 16, Nr = 2 ** 32 - 1, Mn = new Uint32Array();
|
|
2209
2209
|
function Xs(e, t, n, r, i, s, o, c) {
|
|
2210
|
-
const a = i.length, l = new Uint8Array(Xe), f = G(l), u = zt(i) && zt(s),
|
|
2210
|
+
const a = i.length, l = new Uint8Array(Xe), f = G(l), u = zt(i) && zt(s), g = u ? G(i) : Mn, w = u ? G(s) : Mn;
|
|
2211
2211
|
for (let y = 0; y < a; o++) {
|
|
2212
2212
|
if (e(t, n, r, f, o, c), o >= Nr)
|
|
2213
2213
|
throw new Error("arx: counter overflow");
|
|
@@ -2216,13 +2216,13 @@ function Xs(e, t, n, r, i, s, o, c) {
|
|
|
2216
2216
|
const d = y / 4;
|
|
2217
2217
|
if (y % 4 !== 0)
|
|
2218
2218
|
throw new Error("arx: invalid block position");
|
|
2219
|
-
for (let
|
|
2220
|
-
E = d +
|
|
2219
|
+
for (let p = 0, E; p < Ys; p++)
|
|
2220
|
+
E = d + p, w[E] = g[E] ^ f[p];
|
|
2221
2221
|
y += Xe;
|
|
2222
2222
|
continue;
|
|
2223
2223
|
}
|
|
2224
|
-
for (let d = 0,
|
|
2225
|
-
|
|
2224
|
+
for (let d = 0, p; d < h; d++)
|
|
2225
|
+
p = y + d, s[p] = i[p] ^ l[d];
|
|
2226
2226
|
y += h;
|
|
2227
2227
|
}
|
|
2228
2228
|
}
|
|
@@ -2232,45 +2232,45 @@ function Qs(e, t) {
|
|
|
2232
2232
|
throw new Error("core must be a function");
|
|
2233
2233
|
return kt(i), kt(o), On(s), On(n), (c, a, l, f, u = 0) => {
|
|
2234
2234
|
ce(c), ce(a), ce(l);
|
|
2235
|
-
const
|
|
2236
|
-
if (f || (f = new Uint8Array(
|
|
2235
|
+
const g = l.length;
|
|
2236
|
+
if (f || (f = new Uint8Array(g)), ce(f), kt(u), u < 0 || u >= Nr)
|
|
2237
2237
|
throw new Error("arx: counter overflow");
|
|
2238
|
-
if (f.length <
|
|
2239
|
-
throw new Error(`arx: output (${f.length}) is shorter than data (${
|
|
2240
|
-
const
|
|
2238
|
+
if (f.length < g)
|
|
2239
|
+
throw new Error(`arx: output (${f.length}) is shorter than data (${g})`);
|
|
2240
|
+
const w = [];
|
|
2241
2241
|
let y = c.length, h, d;
|
|
2242
2242
|
if (y === 32)
|
|
2243
|
-
h = c.slice(),
|
|
2243
|
+
h = c.slice(), w.push(h), d = Kr;
|
|
2244
2244
|
else if (y === 16 && n)
|
|
2245
|
-
h = new Uint8Array(32), h.set(c), h.set(c, 16), d = Js,
|
|
2245
|
+
h = new Uint8Array(32), h.set(c), h.set(c, 16), d = Js, w.push(h);
|
|
2246
2246
|
else
|
|
2247
2247
|
throw new Error(`arx: invalid 32-byte key, got length=${y}`);
|
|
2248
|
-
zt(a) || (a = a.slice(),
|
|
2249
|
-
const
|
|
2248
|
+
zt(a) || (a = a.slice(), w.push(a));
|
|
2249
|
+
const p = G(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, G(a.subarray(0, 16)), p), a = a.subarray(16);
|
|
2254
2254
|
}
|
|
2255
2255
|
const E = 16 - i;
|
|
2256
2256
|
if (E !== a.length)
|
|
2257
2257
|
throw new Error(`arx: nonce must be ${E} or 16 bytes`);
|
|
2258
2258
|
if (E !== 12) {
|
|
2259
2259
|
const I = new Uint8Array(12);
|
|
2260
|
-
I.set(a, s ? 0 : 12 - a.length), a = I,
|
|
2260
|
+
I.set(a, s ? 0 : 12 - a.length), a = I, w.push(a);
|
|
2261
2261
|
}
|
|
2262
2262
|
const S = G(a);
|
|
2263
|
-
for (Xs(e, d,
|
|
2264
|
-
|
|
2263
|
+
for (Xs(e, d, p, S, l, f, u, o); w.length > 0; )
|
|
2264
|
+
w.pop().fill(0);
|
|
2265
2265
|
return f;
|
|
2266
2266
|
};
|
|
2267
2267
|
}
|
|
2268
2268
|
function eo(e, t, n, r, i, s = 20) {
|
|
2269
|
-
let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1],
|
|
2269
|
+
let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1], g = t[2], w = t[3], y = t[4], h = t[5], d = t[6], p = t[7], E = i, S = n[0], I = n[1], B = n[2], m = o, x = c, K = a, M = l, _ = f, A = u, T = g, R = w, H = y, b = h, v = d, N = p, k = E, C = S, U = I, O = B;
|
|
2270
2270
|
for (let ee = 0; ee < s; ee += 2)
|
|
2271
|
-
m = m + _ | 0, k = L(k ^ m, 16), H = H + k | 0, _ = L(_ ^ H, 12), m = m + _ | 0, k = L(k ^ m, 8), H = H + k | 0, _ = L(_ ^ H, 7), x = x + A | 0, C = L(C ^ x, 16),
|
|
2271
|
+
m = m + _ | 0, k = L(k ^ m, 16), H = H + k | 0, _ = L(_ ^ H, 12), m = m + _ | 0, k = L(k ^ m, 8), H = H + k | 0, _ = L(_ ^ H, 7), x = x + A | 0, C = L(C ^ x, 16), 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 + T | 0, U = L(U ^ K, 16), v = v + U | 0, T = L(T ^ v, 12), K = K + T | 0, U = L(U ^ K, 8), v = v + U | 0, T = L(T ^ v, 7), M = M + R | 0, O = L(O ^ M, 16), N = N + O | 0, R = L(R ^ N, 12), M = M + R | 0, O = L(O ^ M, 8), N = N + O | 0, R = L(R ^ N, 7), m = m + A | 0, O = L(O ^ m, 16), v = v + O | 0, A = L(A ^ v, 12), m = m + A | 0, O = L(O ^ m, 8), v = v + O | 0, A = L(A ^ v, 7), x = x + T | 0, k = L(k ^ x, 16), N = N + k | 0, T = L(T ^ N, 12), x = x + T | 0, k = L(k ^ x, 8), N = N + k | 0, T = L(T ^ N, 7), K = K + R | 0, C = L(C ^ K, 16), H = H + C | 0, R = L(R ^ H, 12), K = K + R | 0, C = L(C ^ K, 8), H = H + C | 0, R = L(R ^ H, 7), M = M + _ | 0, U = L(U ^ M, 16), b = b + U | 0, _ = L(_ ^ b, 12), M = M + _ | 0, U = L(U ^ M, 8), b = b + U | 0, _ = L(_ ^ b, 7);
|
|
2272
2272
|
let $ = 0;
|
|
2273
|
-
r[$++] = o + m | 0, r[$++] = c + x | 0, r[$++] = a + K | 0, r[$++] = l + M | 0, r[$++] = f + _ | 0, r[$++] = u + A | 0, r[$++] =
|
|
2273
|
+
r[$++] = o + m | 0, r[$++] = c + x | 0, r[$++] = a + K | 0, r[$++] = l + M | 0, r[$++] = f + _ | 0, r[$++] = u + A | 0, r[$++] = g + T | 0, r[$++] = w + R | 0, r[$++] = y + H | 0, r[$++] = h + b | 0, r[$++] = d + v | 0, r[$++] = p + N | 0, r[$++] = E + k | 0, r[$++] = S + C | 0, r[$++] = I + U | 0, r[$++] = B + O | 0;
|
|
2274
2274
|
}
|
|
2275
2275
|
const Sr = /* @__PURE__ */ Qs(eo, {
|
|
2276
2276
|
counterRight: !1,
|
|
@@ -2651,7 +2651,7 @@ function gt(e) {
|
|
|
2651
2651
|
type: "nprofile",
|
|
2652
2652
|
data: {
|
|
2653
2653
|
pubkey: P(u[0][0]),
|
|
2654
|
-
relays: u[1] ? u[1].map((
|
|
2654
|
+
relays: u[1] ? u[1].map((g) => ue.decode(g)) : []
|
|
2655
2655
|
}
|
|
2656
2656
|
};
|
|
2657
2657
|
}
|
|
@@ -2669,7 +2669,7 @@ function gt(e) {
|
|
|
2669
2669
|
type: "nevent",
|
|
2670
2670
|
data: {
|
|
2671
2671
|
id: P(u[0][0]),
|
|
2672
|
-
relays: u[1] ? u[1].map((
|
|
2672
|
+
relays: u[1] ? u[1].map((g) => ue.decode(g)) : [],
|
|
2673
2673
|
author: (o = u[2]) != null && o[0] ? P(u[2][0]) : void 0,
|
|
2674
2674
|
kind: (c = u[3]) != null && c[0] ? parseInt(P(u[3][0]), 16) : void 0
|
|
2675
2675
|
}
|
|
@@ -2693,7 +2693,7 @@ function gt(e) {
|
|
|
2693
2693
|
identifier: ue.decode(u[0][0]),
|
|
2694
2694
|
pubkey: P(u[2][0]),
|
|
2695
2695
|
kind: parseInt(P(u[3][0]), 16),
|
|
2696
|
-
relays: u[1] ? u[1].map((
|
|
2696
|
+
relays: u[1] ? u[1].map((g) => ue.decode(g)) : []
|
|
2697
2697
|
}
|
|
2698
2698
|
};
|
|
2699
2699
|
}
|
|
@@ -3579,7 +3579,7 @@ async function wi(e, t, n, r) {
|
|
|
3579
3579
|
throw new Error("Invalid nostr event, payload tag does not match request body hash");
|
|
3580
3580
|
return !0;
|
|
3581
3581
|
}
|
|
3582
|
-
const Oe =
|
|
3582
|
+
const Oe = 1060, Dn = 30078, jn = 1059, Gc = 14, au = 100, Fc = 1;
|
|
3583
3583
|
function cu(e) {
|
|
3584
3584
|
return JSON.stringify({
|
|
3585
3585
|
version: Fc,
|
|
@@ -3733,7 +3733,7 @@ class st {
|
|
|
3733
3733
|
const c = ke(), [a, l] = Pe(s, q.getConversationKey(c, n), 2);
|
|
3734
3734
|
let f, u;
|
|
3735
3735
|
i ? (f = { publicKey: le(r), privateKey: r }, u = { publicKey: le(c), privateKey: c }) : u = { publicKey: le(r), privateKey: r };
|
|
3736
|
-
const
|
|
3736
|
+
const g = {
|
|
3737
3737
|
rootKey: i ? a : s,
|
|
3738
3738
|
theirNextNostrPublicKey: n,
|
|
3739
3739
|
ourCurrentNostrKey: f,
|
|
@@ -3744,8 +3744,8 @@ class st {
|
|
|
3744
3744
|
receivingChainMessageNumber: 0,
|
|
3745
3745
|
previousSendingChainMessageCount: 0,
|
|
3746
3746
|
skippedKeys: {}
|
|
3747
|
-
},
|
|
3748
|
-
return o && (
|
|
3747
|
+
}, w = new st(t, g);
|
|
3748
|
+
return o && (w.name = o), w;
|
|
3749
3749
|
}
|
|
3750
3750
|
/**
|
|
3751
3751
|
* Sends a text message through the encrypted session.
|
|
@@ -4079,18 +4079,18 @@ class Me {
|
|
|
4079
4079
|
* so the inviter can create the session on their side.
|
|
4080
4080
|
*/
|
|
4081
4081
|
async accept(t, n, r) {
|
|
4082
|
-
const i = ke(), s = le(i), o = this.inviter || this.inviterEphemeralPublicKey, c = z(this.sharedSecret), a = st.init(t, this.inviterEphemeralPublicKey, i, !0, c, void 0), f = await (typeof r == "function" ? r : (
|
|
4082
|
+
const i = ke(), s = le(i), o = this.inviter || this.inviterEphemeralPublicKey, c = z(this.sharedSecret), a = st.init(t, this.inviterEphemeralPublicKey, i, !0, c, void 0), f = await (typeof r == "function" ? r : (d, p) => Promise.resolve(q.encrypt(d, Qe(r, p))))(s, o), u = {
|
|
4083
4083
|
pubkey: n,
|
|
4084
4084
|
content: await q.encrypt(f, c),
|
|
4085
4085
|
created_at: Math.floor(Date.now() / 1e3)
|
|
4086
|
-
},
|
|
4086
|
+
}, g = JSON.stringify(u), w = ke(), y = le(w), h = {
|
|
4087
4087
|
kind: jn,
|
|
4088
|
-
pubkey:
|
|
4089
|
-
content: q.encrypt(
|
|
4088
|
+
pubkey: y,
|
|
4089
|
+
content: q.encrypt(g, Qe(w, this.inviterEphemeralPublicKey)),
|
|
4090
4090
|
created_at: eu(),
|
|
4091
4091
|
tags: [["p", this.inviterEphemeralPublicKey]]
|
|
4092
4092
|
};
|
|
4093
|
-
return { session: a, event: Q(
|
|
4093
|
+
return { session: a, event: Q(h, w) };
|
|
4094
4094
|
}
|
|
4095
4095
|
listen(t, n, r) {
|
|
4096
4096
|
if (!this.inviterEphemeralPrivateKey)
|
|
@@ -4107,7 +4107,7 @@ class Me {
|
|
|
4107
4107
|
}
|
|
4108
4108
|
const o = await q.decrypt(s.content, Qe(this.inviterEphemeralPrivateKey, s.pubkey)), c = JSON.parse(o), a = z(this.sharedSecret), l = c.pubkey;
|
|
4109
4109
|
this.usedBy.push(l);
|
|
4110
|
-
const f = await q.decrypt(c.content, a),
|
|
4110
|
+
const f = await q.decrypt(c.content, a), g = await (typeof t == "function" ? t : (h, d) => Promise.resolve(q.decrypt(h, Qe(t, d))))(f, l), w = s.id, y = st.init(n, g, this.inviterEphemeralPrivateKey, !1, a, w);
|
|
4111
4111
|
r(y, l);
|
|
4112
4112
|
} catch (o) {
|
|
4113
4113
|
console.error("Error processing invite message:", o, "event", s);
|