nostr-double-ratchet 0.0.34 → 0.0.36
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 +2 -1
- package/dist/Invite.d.ts.map +1 -1
- package/dist/Session.d.ts.map +1 -1
- package/dist/nostr-double-ratchet.es.js +713 -671
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Invite.ts +5 -2
- package/src/Session.ts +35 -18
- package/src/utils.ts +35 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var J = (e, t, n) =>
|
|
1
|
+
var Ni = Object.defineProperty;
|
|
2
|
+
var Si = (e, t, n) => t in e ? Ni(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var J = (e, t, n) => Si(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
4
|
function Bn(e) {
|
|
5
5
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
6
6
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
@@ -11,7 +11,7 @@ function Fn(e, ...t) {
|
|
|
11
11
|
if (t.length > 0 && !t.includes(e.length))
|
|
12
12
|
throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function Ai(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);
|
|
@@ -22,7 +22,7 @@ function et(e, t = !0) {
|
|
|
22
22
|
if (t && e.finished)
|
|
23
23
|
throw new Error("Hash#digest() has already been called");
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function Ci(e, t) {
|
|
26
26
|
Fn(e);
|
|
27
27
|
const n = t.outputLen;
|
|
28
28
|
if (e.length < n)
|
|
@@ -30,20 +30,20 @@ function Ai(e, t) {
|
|
|
30
30
|
}
|
|
31
31
|
const xt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
32
32
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
33
|
-
const Gn = (e) => e instanceof Uint8Array, Kt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), re = (e, t) => e << 32 - t | e >>> t,
|
|
34
|
-
if (!
|
|
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, ki = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
34
|
+
if (!ki)
|
|
35
35
|
throw new Error("Non little-endian hardware is not supported");
|
|
36
|
-
function
|
|
36
|
+
function Bi(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 = Bi(e)), !Gn(e))
|
|
43
43
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
44
44
|
return e;
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function Ii(...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) => {
|
|
@@ -58,7 +58,7 @@ let Jn = class {
|
|
|
58
58
|
return this._cloneInto();
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
-
function
|
|
61
|
+
function Ui(e) {
|
|
62
62
|
const t = (r) => e().update(Vt(r)).digest(), n = e();
|
|
63
63
|
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
64
64
|
}
|
|
@@ -73,7 +73,7 @@ function _i(e, t, n, r) {
|
|
|
73
73
|
const i = BigInt(32), s = BigInt(4294967295), o = Number(n >> i & s), c = Number(n & s), a = r ? 4 : 0, l = r ? 0 : 4;
|
|
74
74
|
e.setUint32(t + a, o, r), e.setUint32(t + l, c, r);
|
|
75
75
|
}
|
|
76
|
-
let
|
|
76
|
+
let Li = class extends Jn {
|
|
77
77
|
constructor(t, n, r, i) {
|
|
78
78
|
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view = Kt(this.buffer);
|
|
79
79
|
}
|
|
@@ -95,7 +95,7 @@ let Ui = class extends Jn {
|
|
|
95
95
|
return this.length += t.length, this.roundClean(), this;
|
|
96
96
|
}
|
|
97
97
|
digestInto(t) {
|
|
98
|
-
et(this),
|
|
98
|
+
et(this), Ci(t, this), this.finished = !0;
|
|
99
99
|
const { buffer: n, view: r, blockLen: i, isLE: s } = this;
|
|
100
100
|
let { pos: o } = this;
|
|
101
101
|
n[o++] = 128, this.buffer.subarray(o).fill(0), this.padOffset > i - o && (this.process(r, 0), o = 0);
|
|
@@ -123,7 +123,7 @@ let Ui = class extends Jn {
|
|
|
123
123
|
return t.length = i, t.pos = c, t.finished = s, t.destroyed = o, i % n && t.buffer.set(r), t;
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
|
-
const
|
|
126
|
+
const $i = (e, t, n) => e & t ^ ~e & n, Ri = (e, t, n) => e & t ^ e & n ^ t & n, Ti = /* @__PURE__ */ new Uint32Array([
|
|
127
127
|
1116352408,
|
|
128
128
|
1899447441,
|
|
129
129
|
3049323471,
|
|
@@ -198,7 +198,7 @@ const Li = (e, t, n) => e & t ^ ~e & n, $i = (e, t, n) => e & t ^ e & n ^ t & n,
|
|
|
198
198
|
528734635,
|
|
199
199
|
1541459225
|
|
200
200
|
]), ve = /* @__PURE__ */ new Uint32Array(64);
|
|
201
|
-
let
|
|
201
|
+
let Oi = class extends Li {
|
|
202
202
|
constructor() {
|
|
203
203
|
super(64, 32, 8, !1), this.A = be[0] | 0, this.B = be[1] | 0, this.C = be[2] | 0, this.D = be[3] | 0, this.E = be[4] | 0, this.F = be[5] | 0, this.G = be[6] | 0, this.H = be[7] | 0;
|
|
204
204
|
}
|
|
@@ -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 p = ve[u - 15], w = ve[u - 2], g = re(p, 7) ^ re(p, 18) ^ p >>> 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 p = re(c, 6) ^ re(c, 11) ^ re(c, 25), w = f + p + $i(c, a, l) + Ti[u] + ve[u] | 0, h = (re(r, 2) ^ re(r, 13) ^ re(r, 22)) + Ri(r, i, s) | 0;
|
|
223
223
|
f = l, l = a, a = c, c = o + w | 0, o = s, s = i, i = r, r = w + h | 0;
|
|
224
224
|
}
|
|
225
225
|
r = r + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, l = l + this.G | 0, f = f + this.H | 0, this.set(r, i, s, o, c, a, l, f);
|
|
@@ -231,15 +231,15 @@ let Ti = class extends Ui {
|
|
|
231
231
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
|
|
232
232
|
}
|
|
233
233
|
};
|
|
234
|
-
const $t = /* @__PURE__ */
|
|
234
|
+
const $t = /* @__PURE__ */ Ui(() => new Oi());
|
|
235
235
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
236
|
-
const Xn = BigInt(0), at = BigInt(1),
|
|
237
|
-
function
|
|
236
|
+
const Xn = BigInt(0), at = BigInt(1), Mi = BigInt(2), ct = (e) => e instanceof Uint8Array, Pi = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
237
|
+
function De(e) {
|
|
238
238
|
if (!ct(e))
|
|
239
239
|
throw new Error("Uint8Array expected");
|
|
240
240
|
let t = "";
|
|
241
241
|
for (let n = 0; n < e.length; n++)
|
|
242
|
-
t +=
|
|
242
|
+
t += Pi[e[n]];
|
|
243
243
|
return t;
|
|
244
244
|
}
|
|
245
245
|
function Qn(e) {
|
|
@@ -267,12 +267,12 @@ function je(e) {
|
|
|
267
267
|
return n;
|
|
268
268
|
}
|
|
269
269
|
function G(e) {
|
|
270
|
-
return Zt(
|
|
270
|
+
return Zt(De(e));
|
|
271
271
|
}
|
|
272
272
|
function Ft(e) {
|
|
273
273
|
if (!ct(e))
|
|
274
274
|
throw new Error("Uint8Array expected");
|
|
275
|
-
return Zt(
|
|
275
|
+
return Zt(De(Uint8Array.from(e).reverse()));
|
|
276
276
|
}
|
|
277
277
|
function Ne(e, t) {
|
|
278
278
|
return je(e.toString(16).padStart(t * 2, "0"));
|
|
@@ -280,7 +280,7 @@ function Ne(e, t) {
|
|
|
280
280
|
function Gt(e, t) {
|
|
281
281
|
return Ne(e, t).reverse();
|
|
282
282
|
}
|
|
283
|
-
function
|
|
283
|
+
function Hi(e) {
|
|
284
284
|
return je(Qn(e));
|
|
285
285
|
}
|
|
286
286
|
function Z(e, t, n) {
|
|
@@ -309,7 +309,7 @@ function Ie(...e) {
|
|
|
309
309
|
t.set(r, n), n += r.length;
|
|
310
310
|
}), t;
|
|
311
311
|
}
|
|
312
|
-
function
|
|
312
|
+
function qi(e, t) {
|
|
313
313
|
if (e.length !== t.length)
|
|
314
314
|
return !1;
|
|
315
315
|
for (let n = 0; n < e.length; n++)
|
|
@@ -322,16 +322,16 @@ function Di(e) {
|
|
|
322
322
|
throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
|
|
323
323
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
324
324
|
}
|
|
325
|
-
function
|
|
325
|
+
function ji(e) {
|
|
326
326
|
let t;
|
|
327
327
|
for (t = 0; e > Xn; e >>= at, t += 1)
|
|
328
328
|
;
|
|
329
329
|
return t;
|
|
330
330
|
}
|
|
331
|
-
function
|
|
331
|
+
function zi(e, t) {
|
|
332
332
|
return e >> BigInt(t) & at;
|
|
333
333
|
}
|
|
334
|
-
const
|
|
334
|
+
const Wi = (e, t, n) => e | (n ? at : Xn) << BigInt(t), Jt = (e) => (Mi << BigInt(e - 1)) - at, Nt = (e) => new Uint8Array(e), In = (e) => Uint8Array.from(e);
|
|
335
335
|
function er(e, t, n) {
|
|
336
336
|
if (typeof e != "number" || e < 2)
|
|
337
337
|
throw new Error("hashLen must be a number");
|
|
@@ -348,23 +348,23 @@ 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 p = [];
|
|
352
352
|
for (; u < t; ) {
|
|
353
353
|
r = c();
|
|
354
354
|
const w = r.slice();
|
|
355
|
-
|
|
355
|
+
p.push(w), u += r.length;
|
|
356
356
|
}
|
|
357
|
-
return Ie(...
|
|
357
|
+
return Ie(...p);
|
|
358
358
|
};
|
|
359
|
-
return (u,
|
|
359
|
+
return (u, p) => {
|
|
360
360
|
o(), a(u);
|
|
361
361
|
let w;
|
|
362
|
-
for (; !(w =
|
|
362
|
+
for (; !(w = p(l())); )
|
|
363
363
|
a();
|
|
364
364
|
return o(), w;
|
|
365
365
|
};
|
|
366
366
|
}
|
|
367
|
-
const
|
|
367
|
+
const Vi = {
|
|
368
368
|
bigint: (e) => typeof e == "bigint",
|
|
369
369
|
function: (e) => typeof e == "function",
|
|
370
370
|
boolean: (e) => typeof e == "boolean",
|
|
@@ -377,7 +377,7 @@ const Wi = {
|
|
|
377
377
|
};
|
|
378
378
|
function Ye(e, t, n = {}) {
|
|
379
379
|
const r = (i, s, o) => {
|
|
380
|
-
const c =
|
|
380
|
+
const c = Vi[s];
|
|
381
381
|
if (typeof c != "function")
|
|
382
382
|
throw new Error(`Invalid validator "${s}", expected function`);
|
|
383
383
|
const a = e[i];
|
|
@@ -390,37 +390,37 @@ function Ye(e, t, n = {}) {
|
|
|
390
390
|
r(i, s, !0);
|
|
391
391
|
return e;
|
|
392
392
|
}
|
|
393
|
-
const
|
|
393
|
+
const Zi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
394
394
|
__proto__: null,
|
|
395
|
-
bitGet:
|
|
396
|
-
bitLen:
|
|
395
|
+
bitGet: zi,
|
|
396
|
+
bitLen: ji,
|
|
397
397
|
bitMask: Jt,
|
|
398
|
-
bitSet:
|
|
399
|
-
bytesToHex:
|
|
398
|
+
bitSet: Wi,
|
|
399
|
+
bytesToHex: De,
|
|
400
400
|
bytesToNumberBE: G,
|
|
401
401
|
bytesToNumberLE: Ft,
|
|
402
402
|
concatBytes: Ie,
|
|
403
403
|
createHmacDrbg: er,
|
|
404
404
|
ensureBytes: Z,
|
|
405
|
-
equalBytes:
|
|
405
|
+
equalBytes: qi,
|
|
406
406
|
hexToBytes: je,
|
|
407
407
|
hexToNumber: Zt,
|
|
408
408
|
numberToBytesBE: Ne,
|
|
409
409
|
numberToBytesLE: Gt,
|
|
410
410
|
numberToHexUnpadded: Qn,
|
|
411
|
-
numberToVarBytesBE:
|
|
411
|
+
numberToVarBytesBE: Hi,
|
|
412
412
|
utf8ToBytes: Di,
|
|
413
413
|
validateObject: Ye
|
|
414
414
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
415
415
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
416
|
-
const W = BigInt(0), z = BigInt(1), Ce = BigInt(2),
|
|
416
|
+
const W = BigInt(0), z = BigInt(1), Ce = BigInt(2), Fi = BigInt(3), Rt = BigInt(4), Un = BigInt(5), _n = BigInt(8);
|
|
417
417
|
BigInt(9);
|
|
418
418
|
BigInt(16);
|
|
419
419
|
function V(e, t) {
|
|
420
420
|
const n = e % t;
|
|
421
421
|
return n >= W ? n : t + n;
|
|
422
422
|
}
|
|
423
|
-
function
|
|
423
|
+
function Gi(e, t, n) {
|
|
424
424
|
if (n <= W || t < W)
|
|
425
425
|
throw new Error("Expected power/modulo > 0");
|
|
426
426
|
if (n === z)
|
|
@@ -448,12 +448,12 @@ function Tt(e, t) {
|
|
|
448
448
|
throw new Error("invert: does not exist");
|
|
449
449
|
return V(i, t);
|
|
450
450
|
}
|
|
451
|
-
function
|
|
451
|
+
function Ji(e) {
|
|
452
452
|
const t = (e - z) / Ce;
|
|
453
453
|
let n, r, i;
|
|
454
454
|
for (n = e - z, r = 0; n % Ce === W; n /= Ce, r++)
|
|
455
455
|
;
|
|
456
|
-
for (i = Ce; i < e &&
|
|
456
|
+
for (i = Ce; i < e && Gi(i, t, e) !== e - z; i++)
|
|
457
457
|
;
|
|
458
458
|
if (r === 1) {
|
|
459
459
|
const o = (e + z) / Rt;
|
|
@@ -468,21 +468,21 @@ 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), p = c.pow(a, n);
|
|
472
|
+
for (; !c.eql(p, c.ONE); ) {
|
|
473
|
+
if (c.eql(p, c.ZERO))
|
|
474
474
|
return c.ZERO;
|
|
475
475
|
let w = 1;
|
|
476
|
-
for (let h = c.sqr(
|
|
476
|
+
for (let h = c.sqr(p); 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), p = c.mul(p, f), l = w;
|
|
480
480
|
}
|
|
481
481
|
return u;
|
|
482
482
|
};
|
|
483
483
|
}
|
|
484
|
-
function
|
|
485
|
-
if (e % Rt ===
|
|
484
|
+
function Yi(e) {
|
|
485
|
+
if (e % Rt === Fi) {
|
|
486
486
|
const t = (e + z) / Rt;
|
|
487
487
|
return function(r, i) {
|
|
488
488
|
const s = r.pow(i, t);
|
|
@@ -491,8 +491,8 @@ function Ji(e) {
|
|
|
491
491
|
return s;
|
|
492
492
|
};
|
|
493
493
|
}
|
|
494
|
-
if (e %
|
|
495
|
-
const t = (e -
|
|
494
|
+
if (e % _n === Un) {
|
|
495
|
+
const t = (e - Un) / _n;
|
|
496
496
|
return function(r, i) {
|
|
497
497
|
const s = r.mul(i, Ce), o = r.pow(s, t), c = r.mul(i, o), a = r.mul(r.mul(c, Ce), o), l = r.mul(c, r.sub(a, r.ONE));
|
|
498
498
|
if (!r.eql(r.sqr(l), i))
|
|
@@ -500,9 +500,9 @@ function Ji(e) {
|
|
|
500
500
|
return l;
|
|
501
501
|
};
|
|
502
502
|
}
|
|
503
|
-
return
|
|
503
|
+
return Ji(e);
|
|
504
504
|
}
|
|
505
|
-
const
|
|
505
|
+
const Xi = [
|
|
506
506
|
"create",
|
|
507
507
|
"isValid",
|
|
508
508
|
"is0",
|
|
@@ -521,16 +521,16 @@ const Yi = [
|
|
|
521
521
|
"mulN",
|
|
522
522
|
"sqrN"
|
|
523
523
|
];
|
|
524
|
-
function
|
|
524
|
+
function Qi(e) {
|
|
525
525
|
const t = {
|
|
526
526
|
ORDER: "bigint",
|
|
527
527
|
MASK: "bigint",
|
|
528
528
|
BYTES: "isSafeInteger",
|
|
529
529
|
BITS: "isSafeInteger"
|
|
530
|
-
}, n =
|
|
530
|
+
}, n = Xi.reduce((r, i) => (r[i] = "function", r), t);
|
|
531
531
|
return Ye(e, n);
|
|
532
532
|
}
|
|
533
|
-
function
|
|
533
|
+
function es(e, t, n) {
|
|
534
534
|
if (n < W)
|
|
535
535
|
throw new Error("Expected power > 0");
|
|
536
536
|
if (n === W)
|
|
@@ -542,7 +542,7 @@ function Qi(e, t, n) {
|
|
|
542
542
|
n & z && (r = e.mul(r, i)), i = e.sqr(i), n >>= z;
|
|
543
543
|
return r;
|
|
544
544
|
}
|
|
545
|
-
function
|
|
545
|
+
function ts(e, t) {
|
|
546
546
|
const n = new Array(t.length), r = t.reduce((s, o, c) => e.is0(o) ? s : (n[c] = s, e.mul(s, o)), e.ONE), i = e.inv(r);
|
|
547
547
|
return t.reduceRight((s, o, c) => e.is0(o) ? s : (n[c] = e.mul(s, n[c]), e.mul(s, o)), i), n;
|
|
548
548
|
}
|
|
@@ -550,13 +550,13 @@ function tr(e, t) {
|
|
|
550
550
|
const n = t !== void 0 ? t : e.toString(2).length, r = Math.ceil(n / 8);
|
|
551
551
|
return { nBitLength: n, nByteLength: r };
|
|
552
552
|
}
|
|
553
|
-
function
|
|
553
|
+
function ns(e, t, n = !1, r = {}) {
|
|
554
554
|
if (e <= W)
|
|
555
555
|
throw new Error(`Expected Field ORDER > 0, got ${e}`);
|
|
556
556
|
const { nBitLength: i, nByteLength: s } = tr(e, t);
|
|
557
557
|
if (s > 2048)
|
|
558
558
|
throw new Error("Field lengths over 2048 bytes are not supported");
|
|
559
|
-
const o =
|
|
559
|
+
const o = Yi(e), c = Object.freeze({
|
|
560
560
|
ORDER: e,
|
|
561
561
|
BITS: i,
|
|
562
562
|
BYTES: s,
|
|
@@ -577,7 +577,7 @@ function ts(e, t, n = !1, r = {}) {
|
|
|
577
577
|
add: (a, l) => V(a + l, e),
|
|
578
578
|
sub: (a, l) => V(a - l, e),
|
|
579
579
|
mul: (a, l) => V(a * l, e),
|
|
580
|
-
pow: (a, l) =>
|
|
580
|
+
pow: (a, l) => es(c, a, l),
|
|
581
581
|
div: (a, l) => V(a * Tt(l, e), e),
|
|
582
582
|
// Same as above, but doesn't normalize
|
|
583
583
|
sqrN: (a) => a * a,
|
|
@@ -586,7 +586,7 @@ function ts(e, t, n = !1, r = {}) {
|
|
|
586
586
|
mulN: (a, l) => a * l,
|
|
587
587
|
inv: (a) => Tt(a, e),
|
|
588
588
|
sqrt: r.sqrt || ((a) => o(c, a)),
|
|
589
|
-
invertBatch: (a) =>
|
|
589
|
+
invertBatch: (a) => ts(c, a),
|
|
590
590
|
// TODO: do we really need constant cmov?
|
|
591
591
|
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
592
592
|
cmov: (a, l, f) => f ? l : a,
|
|
@@ -609,7 +609,7 @@ function rr(e) {
|
|
|
609
609
|
const t = nr(e);
|
|
610
610
|
return t + Math.ceil(t / 2);
|
|
611
611
|
}
|
|
612
|
-
function
|
|
612
|
+
function rs(e, t, n = !1) {
|
|
613
613
|
const r = e.length, i = nr(t), s = rr(t);
|
|
614
614
|
if (r < 16 || r < s || r > 1024)
|
|
615
615
|
throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);
|
|
@@ -617,8 +617,8 @@ function ns(e, t, n = !1) {
|
|
|
617
617
|
return n ? Gt(c, i) : Ne(c, i);
|
|
618
618
|
}
|
|
619
619
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
620
|
-
const
|
|
621
|
-
function
|
|
620
|
+
const is = BigInt(0), St = BigInt(1);
|
|
621
|
+
function ss(e, t) {
|
|
622
622
|
const n = (i, s) => {
|
|
623
623
|
const o = s.negate();
|
|
624
624
|
return i ? o : s;
|
|
@@ -631,7 +631,7 @@ function is(e, t) {
|
|
|
631
631
|
// non-const time multiplication ladder
|
|
632
632
|
unsafeLadder(i, s) {
|
|
633
633
|
let o = e.ZERO, c = i;
|
|
634
|
-
for (; s >
|
|
634
|
+
for (; s > is; )
|
|
635
635
|
s & St && (o = o.add(c)), c = c.double(), s >>= St;
|
|
636
636
|
return o;
|
|
637
637
|
},
|
|
@@ -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 p = 1; p < c; p++)
|
|
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), p = 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 -= p, o += St);
|
|
674
|
+
const y = h, m = h + Math.abs(d) - 1, S = g % 2 !== 0, U = d < 0;
|
|
675
|
+
d === 0 ? f = f.add(n(S, s[y])) : l = l.add(n(U, s[m]));
|
|
676
676
|
}
|
|
677
677
|
return { p: l, f };
|
|
678
678
|
},
|
|
@@ -684,7 +684,7 @@ function is(e, t) {
|
|
|
684
684
|
};
|
|
685
685
|
}
|
|
686
686
|
function ir(e) {
|
|
687
|
-
return
|
|
687
|
+
return Qi(e.Fp), Ye(e, {
|
|
688
688
|
n: "bigint",
|
|
689
689
|
h: "bigint",
|
|
690
690
|
Gx: "field",
|
|
@@ -699,7 +699,7 @@ function ir(e) {
|
|
|
699
699
|
});
|
|
700
700
|
}
|
|
701
701
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
702
|
-
function
|
|
702
|
+
function os(e) {
|
|
703
703
|
const t = ir(e);
|
|
704
704
|
Ye(t, {
|
|
705
705
|
a: "field",
|
|
@@ -722,7 +722,7 @@ function ss(e) {
|
|
|
722
722
|
}
|
|
723
723
|
return Object.freeze({ ...t });
|
|
724
724
|
}
|
|
725
|
-
const { bytesToNumberBE:
|
|
725
|
+
const { bytesToNumberBE: as, hexToBytes: cs } = Zi, ke = {
|
|
726
726
|
// asn.1 DER encoding utils
|
|
727
727
|
Err: class extends Error {
|
|
728
728
|
constructor(t = "") {
|
|
@@ -740,10 +740,10 @@ const { bytesToNumberBE: os, hexToBytes: as } = Vi, ke = {
|
|
|
740
740
|
throw new t("Invalid signature integer: negative");
|
|
741
741
|
if (r[0] === 0 && !(r[1] & 128))
|
|
742
742
|
throw new t("Invalid signature integer: unnecessary leading zero");
|
|
743
|
-
return { d:
|
|
743
|
+
return { d: as(r), l: e.subarray(n + 2) };
|
|
744
744
|
},
|
|
745
745
|
toSig(e) {
|
|
746
|
-
const { Err: t } = ke, n = typeof e == "string" ?
|
|
746
|
+
const { Err: t } = ke, n = typeof e == "string" ? cs(e) : e;
|
|
747
747
|
if (!(n instanceof Uint8Array))
|
|
748
748
|
throw new Error("ui8a expected");
|
|
749
749
|
let r = n.length;
|
|
@@ -767,16 +767,16 @@ const { bytesToNumberBE: os, hexToBytes: as } = Vi, ke = {
|
|
|
767
767
|
BigInt(2);
|
|
768
768
|
const Ln = BigInt(3);
|
|
769
769
|
BigInt(4);
|
|
770
|
-
function
|
|
771
|
-
const t =
|
|
772
|
-
const
|
|
773
|
-
return Ie(Uint8Array.from([4]), n.toBytes(
|
|
770
|
+
function us(e) {
|
|
771
|
+
const t = os(e), { Fp: n } = t, r = t.toBytes || ((g, h, d) => {
|
|
772
|
+
const y = h.toAffine();
|
|
773
|
+
return Ie(Uint8Array.from([4]), n.toBytes(y.x), n.toBytes(y.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)), y = n.fromBytes(h.subarray(n.BYTES, 2 * n.BYTES));
|
|
776
|
+
return { x: d, y };
|
|
777
777
|
});
|
|
778
778
|
function s(g) {
|
|
779
|
-
const { a: h, b: d } = t,
|
|
779
|
+
const { a: h, b: d } = t, y = n.sqr(g), m = n.mul(y, g);
|
|
780
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)))
|
|
@@ -789,9 +789,9 @@ function cs(e) {
|
|
|
789
789
|
throw new Error("Expected valid bigint: 0 < bigint < curve.n");
|
|
790
790
|
}
|
|
791
791
|
function a(g) {
|
|
792
|
-
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey:
|
|
792
|
+
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey: y, n: m } = t;
|
|
793
793
|
if (h && typeof g != "bigint") {
|
|
794
|
-
if (g instanceof Uint8Array && (g =
|
|
794
|
+
if (g instanceof Uint8Array && (g = De(g)), typeof g != "string" || !h.includes(g.length))
|
|
795
795
|
throw new Error("Invalid key");
|
|
796
796
|
g = g.padStart(d * 2, "0");
|
|
797
797
|
}
|
|
@@ -801,7 +801,7 @@ function cs(e) {
|
|
|
801
801
|
} catch {
|
|
802
802
|
throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof g}`);
|
|
803
803
|
}
|
|
804
|
-
return
|
|
804
|
+
return y && (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, y) {
|
|
813
|
+
if (this.px = h, this.py = d, this.pz = y, 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 (y == null || !n.isValid(y))
|
|
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 } = h || {};
|
|
824
|
+
if (!h || !n.isValid(d) || !n.isValid(y))
|
|
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 m = (S) => n.eql(S, n.ZERO);
|
|
829
|
-
return m(d) && m(
|
|
829
|
+
return m(d) && m(y) ? u.ZERO : new u(d, y, 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((y) => y.pz));
|
|
845
|
+
return h.map((y, m) => y.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 y = n.sqr(d), m = s(h);
|
|
874
|
+
if (!n.eql(y, 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,7 +887,7 @@ function cs(e) {
|
|
|
887
887
|
*/
|
|
888
888
|
equals(h) {
|
|
889
889
|
f(h);
|
|
890
|
-
const { px: d, py:
|
|
890
|
+
const { px: d, py: y, pz: m } = this, { px: S, py: U, pz: k } = h, E = n.eql(n.mul(d, k), n.mul(S, m)), x = n.eql(n.mul(y, k), n.mul(U, m));
|
|
891
891
|
return E && x;
|
|
892
892
|
}
|
|
893
893
|
/**
|
|
@@ -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 k = n.ZERO, E = n.ZERO, x = n.ZERO, K = n.mul(m, m), M = n.mul(S, S), I = n.mul(
|
|
906
|
-
return A = n.add(A, A), x = n.mul(m,
|
|
904
|
+
const { a: h, b: d } = t, y = n.mul(d, Ln), { px: m, py: S, pz: U } = 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(U, U), A = n.mul(m, S);
|
|
906
|
+
return A = n.add(A, A), x = n.mul(m, U), x = n.add(x, x), k = n.mul(h, x), E = n.mul(y, 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(y, x), I = n.mul(h, I), A = n.sub(K, I), A = n.mul(h, A), A = n.add(A, x), x = n.add(K, K), K = n.add(x, K), K = n.add(K, I), K = n.mul(K, A), E = n.add(E, K), I = n.mul(S, U), 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:
|
|
914
|
+
const { px: d, py: y, pz: m } = this, { px: S, py: U, pz: k } = h;
|
|
915
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
|
-
|
|
917
|
+
let A = n.mul(d, S), R = n.mul(y, U), T = n.mul(m, k), q = n.add(d, y), b = n.add(S, U);
|
|
918
|
+
q = n.mul(q, b), b = n.add(A, R), q = n.sub(q, b), b = n.add(d, m);
|
|
919
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(
|
|
920
|
+
return b = n.mul(b, v), v = n.add(A, T), b = n.sub(b, v), v = n.add(y, m), E = n.add(U, 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(q, E), E = n.sub(E, A), A = n.mul(q, 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((m, S) => m.toAffine(
|
|
930
|
+
const y = n.invertBatch(d.map((m) => m.pz));
|
|
931
|
+
return d.map((m, S) => m.toAffine(y[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: y } = t;
|
|
946
|
+
if (!y)
|
|
947
947
|
return w.unsafeLadder(this, h);
|
|
948
|
-
let { k1neg: m, k1: S, k2neg:
|
|
948
|
+
let { k1neg: m, k1: S, k2neg: U, k2: k } = y.splitScalar(h), E = d, x = d, K = this;
|
|
949
949
|
for (; S > ce || k > ce; )
|
|
950
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()),
|
|
951
|
+
return m && (E = E.negate()), U && (x = x.negate()), x = new u(n.mul(x.px, y.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, y, m;
|
|
965
965
|
const { endo: S } = t;
|
|
966
966
|
if (S) {
|
|
967
|
-
const { k1neg:
|
|
967
|
+
const { k1neg: U, k1: k, k2neg: E, k2: x } = S.splitScalar(d);
|
|
968
968
|
let { p: K, f: M } = this.wNAF(k), { p: I, f: A } = this.wNAF(x);
|
|
969
|
-
K = w.constTimeNegate(
|
|
969
|
+
K = w.constTimeNegate(U, K), I = w.constTimeNegate(E, I), I = new u(n.mul(I.px, S.beta), I.py, I.pz), y = K.add(I), m = M.add(A);
|
|
970
970
|
} else {
|
|
971
|
-
const { p:
|
|
972
|
-
|
|
971
|
+
const { p: U, f: k } = this.wNAF(d);
|
|
972
|
+
y = U, m = k;
|
|
973
973
|
}
|
|
974
|
-
return u.normalizeZ([
|
|
974
|
+
return u.normalizeZ([y, 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 m = u.BASE, S = (k, E) => E === ce || E === X || !k.equals(m) ? k.multiplyUnsafe(E) : k.multiply(E),
|
|
984
|
-
return
|
|
982
|
+
multiplyAndAddUnsafe(h, d, y) {
|
|
983
|
+
const m = u.BASE, S = (k, E) => E === ce || E === X || !k.equals(m) ? k.multiplyUnsafe(E) : k.multiply(E), U = S(this, d).add(S(h, y));
|
|
984
|
+
return U.is0() ? void 0 : U;
|
|
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: y, pz: m } = this, S = this.is0();
|
|
991
991
|
h == null && (h = S ? n.ONE : n.inv(m));
|
|
992
|
-
const
|
|
992
|
+
const U = n.mul(d, h), k = n.mul(y, h), E = n.mul(m, h);
|
|
993
993
|
if (S)
|
|
994
994
|
return { x: n.ZERO, y: n.ZERO };
|
|
995
995
|
if (!n.eql(E, n.ONE))
|
|
996
996
|
throw new Error("invZ was invalid");
|
|
997
|
-
return { x:
|
|
997
|
+
return { x: U, y: k };
|
|
998
998
|
}
|
|
999
999
|
isTorsionFree() {
|
|
1000
1000
|
const { h, isTorsionFree: d } = t;
|
|
@@ -1012,11 +1012,11 @@ function cs(e) {
|
|
|
1012
1012
|
return this.assertValidity(), r(u, this, h);
|
|
1013
1013
|
}
|
|
1014
1014
|
toHex(h = !0) {
|
|
1015
|
-
return
|
|
1015
|
+
return De(this.toRawBytes(h));
|
|
1016
1016
|
}
|
|
1017
1017
|
}
|
|
1018
1018
|
u.BASE = new u(t.Gx, t.Gy, n.ONE), u.ZERO = new u(n.ZERO, n.ONE, n.ZERO);
|
|
1019
|
-
const
|
|
1019
|
+
const p = t.nBitLength, w = ss(u, t.endo ? Math.ceil(p / 2) : p);
|
|
1020
1020
|
return {
|
|
1021
1021
|
CURVE: t,
|
|
1022
1022
|
ProjectivePoint: u,
|
|
@@ -1025,7 +1025,7 @@ function cs(e) {
|
|
|
1025
1025
|
isWithinCurveOrder: o
|
|
1026
1026
|
};
|
|
1027
1027
|
}
|
|
1028
|
-
function
|
|
1028
|
+
function ls(e) {
|
|
1029
1029
|
const t = ir(e);
|
|
1030
1030
|
return Ye(t, {
|
|
1031
1031
|
hash: "hash",
|
|
@@ -1037,8 +1037,8 @@ function us(e) {
|
|
|
1037
1037
|
lowS: "boolean"
|
|
1038
1038
|
}), Object.freeze({ lowS: !0, ...t });
|
|
1039
1039
|
}
|
|
1040
|
-
function
|
|
1041
|
-
const t =
|
|
1040
|
+
function fs(e) {
|
|
1041
|
+
const t = ls(e), { Fp: n, n: r } = t, i = n.BYTES + 1, s = 2 * n.BYTES + 1;
|
|
1042
1042
|
function o(b) {
|
|
1043
1043
|
return ce < b && b < n.ORDER;
|
|
1044
1044
|
}
|
|
@@ -1048,11 +1048,11 @@ 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: p } = us({
|
|
1052
1052
|
...t,
|
|
1053
1053
|
toBytes(b, v, N) {
|
|
1054
|
-
const B = v.toAffine(), C = n.toBytes(B.x),
|
|
1055
|
-
return N ?
|
|
1054
|
+
const B = v.toAffine(), C = n.toBytes(B.x), _ = Ie;
|
|
1055
|
+
return N ? _(Uint8Array.from([v.hasEvenY() ? 2 : 3]), C) : _(Uint8Array.from([4]), C, n.toBytes(B.y));
|
|
1056
1056
|
},
|
|
1057
1057
|
fromBytes(b) {
|
|
1058
1058
|
const v = b.length, N = b[0], B = b.subarray(1);
|
|
@@ -1060,17 +1060,17 @@ function ls(e) {
|
|
|
1060
1060
|
const C = G(B);
|
|
1061
1061
|
if (!o(C))
|
|
1062
1062
|
throw new Error("Point is not on curve");
|
|
1063
|
-
const
|
|
1064
|
-
let O = n.sqrt(
|
|
1063
|
+
const _ = u(C);
|
|
1064
|
+
let O = n.sqrt(_);
|
|
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(B.subarray(0, n.BYTES)),
|
|
1069
|
-
return { x: C, y:
|
|
1068
|
+
const C = n.fromBytes(B.subarray(0, n.BYTES)), _ = n.fromBytes(B.subarray(n.BYTES, 2 * n.BYTES));
|
|
1069
|
+
return { x: C, y: _ };
|
|
1070
1070
|
} else
|
|
1071
1071
|
throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`);
|
|
1072
1072
|
}
|
|
1073
|
-
}), w = (b) =>
|
|
1073
|
+
}), w = (b) => De(Ne(b, t.nByteLength));
|
|
1074
1074
|
function g(b) {
|
|
1075
1075
|
const v = r >> X;
|
|
1076
1076
|
return b > v;
|
|
@@ -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
|
|
1082
|
+
class y {
|
|
1083
1083
|
constructor(v, N, B) {
|
|
1084
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 y(d(v, 0, N), d(v, N, 2 * N));
|
|
1090
1090
|
}
|
|
1091
1091
|
// DER encoded ECDSA signature
|
|
1092
1092
|
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
1093
1093
|
static fromDER(v) {
|
|
1094
1094
|
const { r: N, s: B } = ke.toSig(Z("DER", v));
|
|
1095
|
-
return new
|
|
1095
|
+
return new y(N, B);
|
|
1096
1096
|
}
|
|
1097
1097
|
assertValidity() {
|
|
1098
|
-
if (!
|
|
1098
|
+
if (!p(this.r))
|
|
1099
1099
|
throw new Error("r must be 0 < r < CURVE.n");
|
|
1100
|
-
if (!
|
|
1100
|
+
if (!p(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 y(this.r, this.s, v);
|
|
1105
1105
|
}
|
|
1106
1106
|
recoverPublicKey(v) {
|
|
1107
|
-
const { r: N, s: B, recovery: C } = this,
|
|
1107
|
+
const { r: N, s: B, recovery: C } = this, _ = 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),
|
|
1113
|
+
const $ = (C & 1) === 0 ? "02" : "03", ee = l.fromHex($ + w(O)), ge = a(O), _e = c(-_ * ge), Ve = c(B * ge), we = l.BASE.multiplyAndAddUnsafe(ee, _e, Ve);
|
|
1114
1114
|
if (!we)
|
|
1115
1115
|
throw new Error("point at infinify");
|
|
1116
1116
|
return we.assertValidity(), we;
|
|
@@ -1120,7 +1120,7 @@ function ls(e) {
|
|
|
1120
1120
|
return g(this.s);
|
|
1121
1121
|
}
|
|
1122
1122
|
normalizeS() {
|
|
1123
|
-
return this.hasHighS() ? new
|
|
1123
|
+
return this.hasHighS() ? new y(this.r, c(-this.s), this.recovery) : this;
|
|
1124
1124
|
}
|
|
1125
1125
|
// DER-encoded
|
|
1126
1126
|
toDERRawBytes() {
|
|
@@ -1152,7 +1152,7 @@ function ls(e) {
|
|
|
1152
1152
|
*/
|
|
1153
1153
|
randomPrivateKey: () => {
|
|
1154
1154
|
const b = rr(t.n);
|
|
1155
|
-
return
|
|
1155
|
+
return rs(t.randomBytes(b), t.n);
|
|
1156
1156
|
},
|
|
1157
1157
|
/**
|
|
1158
1158
|
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
|
@@ -1169,14 +1169,14 @@ function ls(e) {
|
|
|
1169
1169
|
function S(b, v = !0) {
|
|
1170
1170
|
return l.fromPrivateKey(b).toRawBytes(v);
|
|
1171
1171
|
}
|
|
1172
|
-
function
|
|
1172
|
+
function U(b) {
|
|
1173
1173
|
const v = b instanceof Uint8Array, N = typeof b == "string", B = (v || N) && b.length;
|
|
1174
1174
|
return v ? B === i || B === s : N ? B === 2 * i || B === 2 * s : b instanceof l;
|
|
1175
1175
|
}
|
|
1176
1176
|
function k(b, v, N = !0) {
|
|
1177
|
-
if (
|
|
1177
|
+
if (U(b))
|
|
1178
1178
|
throw new Error("first arg must be private key");
|
|
1179
|
-
if (!
|
|
1179
|
+
if (!U(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
|
}
|
|
@@ -1197,17 +1197,17 @@ function ls(e) {
|
|
|
1197
1197
|
if (["recovered", "canonical"].some((Ae) => Ae in N))
|
|
1198
1198
|
throw new Error("sign() legacy options not supported");
|
|
1199
1199
|
const { hash: B, randomBytes: C } = t;
|
|
1200
|
-
let { lowS:
|
|
1201
|
-
|
|
1202
|
-
const ee = x(b), ge = f(v),
|
|
1200
|
+
let { lowS: _, prehash: O, extraEntropy: $ } = N;
|
|
1201
|
+
_ == null && (_ = !0), b = Z("msgHash", b), O && (b = Z("prehashed msgHash", B(b)));
|
|
1202
|
+
const ee = x(b), ge = f(v), _e = [M(ge), M(ee)];
|
|
1203
1203
|
if ($ != null) {
|
|
1204
1204
|
const Ae = $ === !0 ? C(n.BYTES) : $;
|
|
1205
|
-
|
|
1205
|
+
_e.push(Z("extraEntropy", Ae));
|
|
1206
1206
|
}
|
|
1207
|
-
const Ve = Ie(...
|
|
1207
|
+
const Ve = Ie(..._e), we = ee;
|
|
1208
1208
|
function Et(Ae) {
|
|
1209
1209
|
const Le = E(Ae);
|
|
1210
|
-
if (!
|
|
1210
|
+
if (!p(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)
|
|
@@ -1216,35 +1216,35 @@ function ls(e) {
|
|
|
1216
1216
|
if (Re === ce)
|
|
1217
1217
|
return;
|
|
1218
1218
|
let Cn = ($e.x === te ? 0 : 2) | Number($e.y & X), kn = Re;
|
|
1219
|
-
return
|
|
1219
|
+
return _ && g(Re) && (kn = h(Re), Cn ^= 1), new y(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: B, k2sig: C } = I(b, v, N),
|
|
1226
|
-
return er(
|
|
1225
|
+
const { seed: B, k2sig: C } = I(b, v, N), _ = t;
|
|
1226
|
+
return er(_.hash.outputLen, _.nByteLength, _.hmac)(B, C);
|
|
1227
1227
|
}
|
|
1228
1228
|
l.BASE._setWindowSize(8);
|
|
1229
|
-
function
|
|
1229
|
+
function q(b, v, N, B = R) {
|
|
1230
1230
|
var $e;
|
|
1231
1231
|
const C = b;
|
|
1232
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:
|
|
1234
|
+
const { lowS: _, prehash: O } = B;
|
|
1235
1235
|
let $, ee;
|
|
1236
1236
|
try {
|
|
1237
1237
|
if (typeof C == "string" || C instanceof Uint8Array)
|
|
1238
1238
|
try {
|
|
1239
|
-
$ =
|
|
1239
|
+
$ = y.fromDER(C);
|
|
1240
1240
|
} catch (te) {
|
|
1241
1241
|
if (!(te instanceof ke.Err))
|
|
1242
1242
|
throw te;
|
|
1243
|
-
$ =
|
|
1243
|
+
$ = y.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 y(te, Re);
|
|
1248
1248
|
} else
|
|
1249
1249
|
throw new Error("PARSE");
|
|
1250
1250
|
ee = l.fromHex(N);
|
|
@@ -1253,10 +1253,10 @@ function ls(e) {
|
|
|
1253
1253
|
throw new Error("signature must be Signature instance, Uint8Array or hex string");
|
|
1254
1254
|
return !1;
|
|
1255
1255
|
}
|
|
1256
|
-
if (
|
|
1256
|
+
if (_ && $.hasHighS())
|
|
1257
1257
|
return !1;
|
|
1258
1258
|
O && (v = t.hash(v));
|
|
1259
|
-
const { r: ge, s:
|
|
1259
|
+
const { r: ge, s: _e } = $, Ve = x(v), we = a(_e), Et = c(Ve * we), Ae = c(ge * we), Le = ($e = l.BASE.multiplyAndAddUnsafe(ee, Et, Ae)) == null ? void 0 : $e.toAffine();
|
|
1260
1260
|
return Le ? c(Le.x) === ge : !1;
|
|
1261
1261
|
}
|
|
1262
1262
|
return {
|
|
@@ -1264,15 +1264,15 @@ function ls(e) {
|
|
|
1264
1264
|
getPublicKey: S,
|
|
1265
1265
|
getSharedSecret: k,
|
|
1266
1266
|
sign: T,
|
|
1267
|
-
verify:
|
|
1267
|
+
verify: q,
|
|
1268
1268
|
ProjectivePoint: l,
|
|
1269
|
-
Signature:
|
|
1269
|
+
Signature: y,
|
|
1270
1270
|
utils: m
|
|
1271
1271
|
};
|
|
1272
1272
|
}
|
|
1273
1273
|
let sr = class extends Jn {
|
|
1274
1274
|
constructor(t, n) {
|
|
1275
|
-
super(), this.finished = !1, this.destroyed = !1,
|
|
1275
|
+
super(), this.finished = !1, this.destroyed = !1, Ai(t);
|
|
1276
1276
|
const r = Vt(n);
|
|
1277
1277
|
if (this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
1278
1278
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
@@ -1308,26 +1308,26 @@ let sr = class extends Jn {
|
|
|
1308
1308
|
const or = (e, t, n) => new sr(e, t).update(n).digest();
|
|
1309
1309
|
or.create = (e, t) => new sr(e, t);
|
|
1310
1310
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1311
|
-
function
|
|
1311
|
+
function hs(e) {
|
|
1312
1312
|
return {
|
|
1313
1313
|
hash: e,
|
|
1314
|
-
hmac: (t, ...n) => or(e, t,
|
|
1314
|
+
hmac: (t, ...n) => or(e, t, Ii(...n)),
|
|
1315
1315
|
randomBytes: Yn
|
|
1316
1316
|
};
|
|
1317
1317
|
}
|
|
1318
|
-
function
|
|
1319
|
-
const n = (r) =>
|
|
1318
|
+
function ds(e, t) {
|
|
1319
|
+
const n = (r) => fs({ ...e, ...hs(r) });
|
|
1320
1320
|
return Object.freeze({ ...n(t), create: n });
|
|
1321
1321
|
}
|
|
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,
|
|
1325
|
+
const t = ut, n = BigInt(3), r = BigInt(6), i = BigInt(11), s = BigInt(22), o = BigInt(23), c = BigInt(44), a = BigInt(88), l = e * e * e % t, f = l * l * e % t, u = Y(f, n, t) * f % t, p = Y(u, n, t) * f % t, w = Y(p, nt, t) * l % t, g = Y(w, i, t) * w % t, h = Y(g, s, t) * g % t, d = Y(h, c, t) * h % t, y = Y(d, a, t) * d % t, m = Y(y, c, t) * h % t, S = Y(m, n, t) * f % t, U = Y(S, o, t) * g % t, k = Y(U, r, t) * l % t, E = Y(k, nt, t);
|
|
1326
1326
|
if (!Ot.eql(Ot.sqr(E), e))
|
|
1327
1327
|
throw new Error("Cannot find square root");
|
|
1328
1328
|
return E;
|
|
1329
1329
|
}
|
|
1330
|
-
const Ot =
|
|
1330
|
+
const Ot = ns(ut, void 0, void 0, { sqrt: cr }), Ue = ds({
|
|
1331
1331
|
a: BigInt(0),
|
|
1332
1332
|
b: BigInt(7),
|
|
1333
1333
|
Fp: Ot,
|
|
@@ -1348,13 +1348,13 @@ 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, p = f > o;
|
|
1352
|
+
if (u && (l = t - l), p && (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: p, k2: f };
|
|
1355
1355
|
}
|
|
1356
1356
|
}
|
|
1357
|
-
}, $t), lt = BigInt(0), ur = (e) => typeof e == "bigint" && lt < e && e < ut,
|
|
1357
|
+
}, $t), lt = BigInt(0), ur = (e) => typeof e == "bigint" && lt < e && e < ut, ys = (e) => typeof e == "bigint" && lt < e && e < tt, Rn = {};
|
|
1358
1358
|
function rt(e, ...t) {
|
|
1359
1359
|
let n = Rn[e];
|
|
1360
1360
|
if (n === void 0) {
|
|
@@ -1363,9 +1363,9 @@ function rt(e, ...t) {
|
|
|
1363
1363
|
}
|
|
1364
1364
|
return $t(Ie(n, ...t));
|
|
1365
1365
|
}
|
|
1366
|
-
const Yt = (e) => e.toRawBytes(!0).slice(1), Mt = (e) => Ne(e, 32), At = (e) => V(e, ut), Ge = (e) => V(e, tt), Xt =
|
|
1366
|
+
const Yt = (e) => e.toRawBytes(!0).slice(1), Mt = (e) => Ne(e, 32), At = (e) => V(e, ut), Ge = (e) => V(e, tt), Xt = Ue.ProjectivePoint, ps = (e, t, n) => Xt.BASE.multiplyAndAddUnsafe(e, t, n);
|
|
1367
1367
|
function Pt(e) {
|
|
1368
|
-
let t =
|
|
1368
|
+
let t = Ue.utils.normPrivateKeyToScalar(e), n = Xt.fromPrivateKey(t);
|
|
1369
1369
|
return { scalar: n.hasEvenY() ? t : Ge(-t), bytes: Yt(n) };
|
|
1370
1370
|
}
|
|
1371
1371
|
function lr(e) {
|
|
@@ -1380,15 +1380,15 @@ function lr(e) {
|
|
|
1380
1380
|
function fr(...e) {
|
|
1381
1381
|
return Ge(G(rt("BIP0340/challenge", ...e)));
|
|
1382
1382
|
}
|
|
1383
|
-
function
|
|
1383
|
+
function gs(e) {
|
|
1384
1384
|
return Pt(e).bytes;
|
|
1385
1385
|
}
|
|
1386
|
-
function
|
|
1386
|
+
function ws(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), p = fr(f, i, r), w = new Uint8Array(64);
|
|
1391
|
+
if (w.set(f, 0), w.set(Mt(Ge(u + p * s)), 32), !hr(w, r, i))
|
|
1392
1392
|
throw new Error("sign: Invalid signature produced");
|
|
1393
1393
|
return w;
|
|
1394
1394
|
}
|
|
@@ -1399,7 +1399,7 @@ function hr(e, t, n) {
|
|
|
1399
1399
|
if (!ur(c))
|
|
1400
1400
|
return !1;
|
|
1401
1401
|
const a = G(r.subarray(32, 64));
|
|
1402
|
-
if (!
|
|
1402
|
+
if (!ys(a))
|
|
1403
1403
|
return !1;
|
|
1404
1404
|
const l = fr(Mt(c), Yt(o), i), f = ps(o, a, Ge(-l));
|
|
1405
1405
|
return !(!f || !f.hasEvenY() || f.toAffine().x !== c);
|
|
@@ -1408,11 +1408,11 @@ function hr(e, t, n) {
|
|
|
1408
1408
|
}
|
|
1409
1409
|
}
|
|
1410
1410
|
const Ze = {
|
|
1411
|
-
getPublicKey:
|
|
1412
|
-
sign:
|
|
1411
|
+
getPublicKey: gs,
|
|
1412
|
+
sign: ws,
|
|
1413
1413
|
verify: hr,
|
|
1414
1414
|
utils: {
|
|
1415
|
-
randomPrivateKey:
|
|
1415
|
+
randomPrivateKey: Ue.utils.randomPrivateKey,
|
|
1416
1416
|
lift_x: lr,
|
|
1417
1417
|
pointToBytes: Yt,
|
|
1418
1418
|
numberToBytesBE: Ne,
|
|
@@ -1422,16 +1422,16 @@ 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, kt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), ie = (e, t) => e << 32 - t | e >>> t,
|
|
1426
|
-
if (!
|
|
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, bs = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1426
|
+
if (!bs)
|
|
1427
1427
|
throw new Error("Non little-endian hardware is not supported");
|
|
1428
|
-
const
|
|
1428
|
+
const vs = Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
1429
1429
|
function P(e) {
|
|
1430
1430
|
if (!Qt(e))
|
|
1431
1431
|
throw new Error("Uint8Array expected");
|
|
1432
1432
|
let t = "";
|
|
1433
1433
|
for (let n = 0; n < e.length; n++)
|
|
1434
|
-
t +=
|
|
1434
|
+
t += vs[e[n]];
|
|
1435
1435
|
return t;
|
|
1436
1436
|
}
|
|
1437
1437
|
function j(e) {
|
|
@@ -1449,13 +1449,13 @@ function j(e) {
|
|
|
1449
1449
|
}
|
|
1450
1450
|
return n;
|
|
1451
1451
|
}
|
|
1452
|
-
function
|
|
1452
|
+
function ms(e) {
|
|
1453
1453
|
if (typeof e != "string")
|
|
1454
1454
|
throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
|
|
1455
1455
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
1456
1456
|
}
|
|
1457
1457
|
function Je(e) {
|
|
1458
|
-
if (typeof e == "string" && (e =
|
|
1458
|
+
if (typeof e == "string" && (e = ms(e)), !Qt(e))
|
|
1459
1459
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
1460
1460
|
return e;
|
|
1461
1461
|
}
|
|
@@ -1474,11 +1474,11 @@ class dr {
|
|
|
1474
1474
|
return this._cloneInto();
|
|
1475
1475
|
}
|
|
1476
1476
|
}
|
|
1477
|
-
function
|
|
1477
|
+
function yr(e) {
|
|
1478
1478
|
const t = (r) => e().update(Je(r)).digest(), n = e();
|
|
1479
1479
|
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
1480
1480
|
}
|
|
1481
|
-
function
|
|
1481
|
+
function pr(e = 32) {
|
|
1482
1482
|
if (Ct && typeof Ct.getRandomValues == "function")
|
|
1483
1483
|
return Ct.getRandomValues(new Uint8Array(e));
|
|
1484
1484
|
throw new Error("crypto.getRandomValues must be defined");
|
|
@@ -1487,7 +1487,7 @@ function Ht(e) {
|
|
|
1487
1487
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
1488
1488
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
1489
1489
|
}
|
|
1490
|
-
function
|
|
1490
|
+
function Es(e) {
|
|
1491
1491
|
if (typeof e != "boolean")
|
|
1492
1492
|
throw new Error(`Expected boolean, not ${e}`);
|
|
1493
1493
|
}
|
|
@@ -1497,18 +1497,18 @@ function gr(e, ...t) {
|
|
|
1497
1497
|
if (t.length > 0 && !t.includes(e.length))
|
|
1498
1498
|
throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`);
|
|
1499
1499
|
}
|
|
1500
|
-
function
|
|
1500
|
+
function xs(e) {
|
|
1501
1501
|
if (typeof e != "function" || typeof e.create != "function")
|
|
1502
1502
|
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
1503
1503
|
Ht(e.outputLen), Ht(e.blockLen);
|
|
1504
1504
|
}
|
|
1505
|
-
function
|
|
1505
|
+
function Ks(e, t = !0) {
|
|
1506
1506
|
if (e.destroyed)
|
|
1507
1507
|
throw new Error("Hash instance has been destroyed");
|
|
1508
1508
|
if (t && e.finished)
|
|
1509
1509
|
throw new Error("Hash#digest() has already been called");
|
|
1510
1510
|
}
|
|
1511
|
-
function
|
|
1511
|
+
function Ns(e, t) {
|
|
1512
1512
|
gr(e);
|
|
1513
1513
|
const n = t.outputLen;
|
|
1514
1514
|
if (e.length < n)
|
|
@@ -1516,19 +1516,19 @@ function Ks(e, t) {
|
|
|
1516
1516
|
}
|
|
1517
1517
|
const se = {
|
|
1518
1518
|
number: Ht,
|
|
1519
|
-
bool:
|
|
1519
|
+
bool: Es,
|
|
1520
1520
|
bytes: gr,
|
|
1521
|
-
hash:
|
|
1522
|
-
exists:
|
|
1523
|
-
output:
|
|
1521
|
+
hash: xs,
|
|
1522
|
+
exists: Ks,
|
|
1523
|
+
output: Ns
|
|
1524
1524
|
};
|
|
1525
|
-
function
|
|
1525
|
+
function Ss(e, t, n, r) {
|
|
1526
1526
|
if (typeof e.setBigUint64 == "function")
|
|
1527
1527
|
return e.setBigUint64(t, n, r);
|
|
1528
1528
|
const i = BigInt(32), s = BigInt(4294967295), o = Number(n >> i & s), c = Number(n & s), a = r ? 4 : 0, l = r ? 0 : 4;
|
|
1529
1529
|
e.setUint32(t + a, o, r), e.setUint32(t + l, c, r);
|
|
1530
1530
|
}
|
|
1531
|
-
class
|
|
1531
|
+
class As extends dr {
|
|
1532
1532
|
constructor(t, n, r, i) {
|
|
1533
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
|
}
|
|
@@ -1556,7 +1556,7 @@ class Ss extends dr {
|
|
|
1556
1556
|
n[o++] = 128, this.buffer.subarray(o).fill(0), this.padOffset > i - o && (this.process(r, 0), o = 0);
|
|
1557
1557
|
for (let u = o; u < i; u++)
|
|
1558
1558
|
n[u] = 0;
|
|
1559
|
-
|
|
1559
|
+
Ss(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
1560
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");
|
|
@@ -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
|
|
1581
|
+
const Cs = (e, t, n) => e & t ^ ~e & n, ks = (e, t, n) => e & t ^ e & n ^ t & n, Bs = new Uint32Array([
|
|
1582
1582
|
1116352408,
|
|
1583
1583
|
1899447441,
|
|
1584
1584
|
3049323471,
|
|
@@ -1653,7 +1653,7 @@ const As = (e, t, n) => e & t ^ ~e & n, Cs = (e, t, n) => e & t ^ e & n ^ t & n,
|
|
|
1653
1653
|
528734635,
|
|
1654
1654
|
1541459225
|
|
1655
1655
|
]), Ee = new Uint32Array(64);
|
|
1656
|
-
class wr extends
|
|
1656
|
+
class wr extends As {
|
|
1657
1657
|
constructor() {
|
|
1658
1658
|
super(64, 32, 8, !1), this.A = me[0] | 0, this.B = me[1] | 0, this.C = me[2] | 0, this.D = me[3] | 0, this.E = me[4] | 0, this.F = me[5] | 0, this.G = me[6] | 0, this.H = me[7] | 0;
|
|
1659
1659
|
}
|
|
@@ -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 p = Ee[u - 15], w = Ee[u - 2], g = ie(p, 7) ^ ie(p, 18) ^ p >>> 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 p = ie(c, 6) ^ ie(c, 11) ^ ie(c, 25), w = f + p + Cs(c, a, l) + Bs[u] + Ee[u] | 0, h = (ie(r, 2) ^ ie(r, 13) ^ ie(r, 22)) + ks(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 Is 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
|
-
const fe =
|
|
1695
|
-
|
|
1694
|
+
const fe = yr(() => new wr());
|
|
1695
|
+
yr(() => new Is());
|
|
1696
1696
|
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1697
1697
|
function We(e) {
|
|
1698
1698
|
if (!Number.isSafeInteger(e))
|
|
@@ -1702,7 +1702,7 @@ function de(...e) {
|
|
|
1702
1702
|
const t = (i, s) => (o) => i(s(o)), n = Array.from(e).reverse().reduce((i, s) => i ? t(i, s.encode) : s.encode, void 0), r = e.reduce((i, s) => i ? t(i, s.decode) : s.decode, void 0);
|
|
1703
1703
|
return { encode: n, decode: r };
|
|
1704
1704
|
}
|
|
1705
|
-
function
|
|
1705
|
+
function ye(e) {
|
|
1706
1706
|
return {
|
|
1707
1707
|
encode: (t) => {
|
|
1708
1708
|
if (!Array.isArray(t) || t.length && typeof t[0] != "number")
|
|
@@ -1727,7 +1727,7 @@ function pe(e) {
|
|
|
1727
1727
|
}
|
|
1728
1728
|
};
|
|
1729
1729
|
}
|
|
1730
|
-
function
|
|
1730
|
+
function pe(e = "") {
|
|
1731
1731
|
if (typeof e != "string")
|
|
1732
1732
|
throw new Error("join separator should be string");
|
|
1733
1733
|
return {
|
|
@@ -1815,7 +1815,7 @@ function Tn(e, t, n) {
|
|
|
1815
1815
|
return i.reverse();
|
|
1816
1816
|
}
|
|
1817
1817
|
const vr = (e, t) => t ? vr(t, e % t) : e, it = (e, t) => e + (t - vr(e, t));
|
|
1818
|
-
function
|
|
1818
|
+
function qt(e, t, n, r) {
|
|
1819
1819
|
if (!Array.isArray(e))
|
|
1820
1820
|
throw new Error("convertRadix2: data should be array");
|
|
1821
1821
|
if (t <= 0 || t > 32)
|
|
@@ -1841,7 +1841,7 @@ function Dt(e, t, n, r) {
|
|
|
1841
1841
|
throw new Error(`Non-zero padding: ${i}`);
|
|
1842
1842
|
return r && s > 0 && c.push(i >>> 0), c;
|
|
1843
1843
|
}
|
|
1844
|
-
function
|
|
1844
|
+
function Us(e) {
|
|
1845
1845
|
return We(e), {
|
|
1846
1846
|
encode: (t) => {
|
|
1847
1847
|
if (!(t instanceof Uint8Array))
|
|
@@ -1864,12 +1864,12 @@ function Se(e, t = !1) {
|
|
|
1864
1864
|
encode: (n) => {
|
|
1865
1865
|
if (!(n instanceof Uint8Array))
|
|
1866
1866
|
throw new Error("radix2.encode input should be Uint8Array");
|
|
1867
|
-
return
|
|
1867
|
+
return qt(Array.from(n), 8, e, !t);
|
|
1868
1868
|
},
|
|
1869
1869
|
decode: (n) => {
|
|
1870
1870
|
if (!Array.isArray(n) || n.length && typeof n[0] != "number")
|
|
1871
1871
|
throw new Error("radix2.decode input should be array of strings");
|
|
1872
|
-
return Uint8Array.from(
|
|
1872
|
+
return Uint8Array.from(qt(n, e, 8, t));
|
|
1873
1873
|
}
|
|
1874
1874
|
};
|
|
1875
1875
|
}
|
|
@@ -1883,25 +1883,25 @@ function On(e) {
|
|
|
1883
1883
|
}
|
|
1884
1884
|
};
|
|
1885
1885
|
}
|
|
1886
|
-
const _s = de(Se(4),
|
|
1887
|
-
de(Se(5),
|
|
1888
|
-
de(Se(5),
|
|
1889
|
-
const he = de(Se(6),
|
|
1886
|
+
const _s = de(Se(4), ye("0123456789ABCDEF"), pe("")), Ls = de(Se(5), ye("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), ht(5), pe(""));
|
|
1887
|
+
de(Se(5), ye("0123456789ABCDEFGHIJKLMNOPQRSTUV"), ht(5), pe(""));
|
|
1888
|
+
de(Se(5), ye("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), pe(""), br((e) => e.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
1889
|
+
const he = de(Se(6), ye("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), ht(6), pe("")), $s = de(Se(6), ye("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), ht(6), pe("")), en = (e) => de(Us(58), ye(e), pe("")), Dt = en("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
1890
1890
|
en("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
|
|
1891
1891
|
en("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");
|
|
1892
|
-
const Mn = [0, 2, 3, 5, 6, 7, 9, 10, 11],
|
|
1892
|
+
const Mn = [0, 2, 3, 5, 6, 7, 9, 10, 11], Rs = {
|
|
1893
1893
|
encode(e) {
|
|
1894
1894
|
let t = "";
|
|
1895
1895
|
for (let n = 0; n < e.length; n += 8) {
|
|
1896
1896
|
const r = e.subarray(n, n + 8);
|
|
1897
|
-
t +=
|
|
1897
|
+
t += Dt.encode(r).padStart(Mn[r.length], "1");
|
|
1898
1898
|
}
|
|
1899
1899
|
return t;
|
|
1900
1900
|
},
|
|
1901
1901
|
decode(e) {
|
|
1902
1902
|
let t = [];
|
|
1903
1903
|
for (let n = 0; n < e.length; n += 11) {
|
|
1904
|
-
const r = e.slice(n, n + 11), i = Mn.indexOf(r.length), s =
|
|
1904
|
+
const r = e.slice(n, n + 11), i = Mn.indexOf(r.length), s = Dt.decode(r);
|
|
1905
1905
|
for (let o = 0; o < s.length - i; o++)
|
|
1906
1906
|
if (s[o] !== 0)
|
|
1907
1907
|
throw new Error("base58xmr: wrong padding");
|
|
@@ -1909,7 +1909,7 @@ const Mn = [0, 2, 3, 5, 6, 7, 9, 10, 11], $s = {
|
|
|
1909
1909
|
}
|
|
1910
1910
|
return Uint8Array.from(t);
|
|
1911
1911
|
}
|
|
1912
|
-
}, jt = de(
|
|
1912
|
+
}, jt = de(ye("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), pe("")), Pn = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
1913
1913
|
function Fe(e) {
|
|
1914
1914
|
const t = e >> 25;
|
|
1915
1915
|
let n = (e & 33554431) << 5;
|
|
@@ -1933,18 +1933,18 @@ function Hn(e, t, n = 1) {
|
|
|
1933
1933
|
i = Fe(i) ^ s;
|
|
1934
1934
|
for (let s = 0; s < 6; s++)
|
|
1935
1935
|
i = Fe(i);
|
|
1936
|
-
return i ^= n, jt.encode(
|
|
1936
|
+
return i ^= n, jt.encode(qt([i % 2 ** 30], 30, 5, !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, p = 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 (p !== !1 && w > p)
|
|
1947
|
+
throw new TypeError(`Length ${w} exceeds limit ${p}`);
|
|
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,70 +1952,70 @@ 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 p = f.toLowerCase();
|
|
1956
|
+
if (f !== p && f !== f.toUpperCase())
|
|
1957
1957
|
throw new Error("String must be lowercase or uppercase");
|
|
1958
|
-
f =
|
|
1958
|
+
f = p;
|
|
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), y = Hn(g, d, t);
|
|
1966
|
+
if (!h.endsWith(y))
|
|
1967
|
+
throw new Error(`Invalid checksum in ${f}: expected "${y}"`);
|
|
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: p } = c(f, !1);
|
|
1973
|
+
return { prefix: u, words: p, bytes: r(p) };
|
|
1974
1974
|
}
|
|
1975
1975
|
return { encode: o, decode: c, decodeToBytes: l, decodeUnsafe: a, fromWords: r, fromWordsUnsafe: s, toWords: i };
|
|
1976
1976
|
}
|
|
1977
1977
|
const ze = mr("bech32");
|
|
1978
1978
|
mr("bech32m");
|
|
1979
|
-
const
|
|
1979
|
+
const Ts = {
|
|
1980
1980
|
encode: (e) => new TextDecoder().decode(e),
|
|
1981
1981
|
decode: (e) => new TextEncoder().encode(e)
|
|
1982
|
-
},
|
|
1982
|
+
}, Os = de(Se(4), ye("0123456789abcdef"), pe(""), br((e) => {
|
|
1983
1983
|
if (typeof e != "string" || e.length % 2)
|
|
1984
1984
|
throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);
|
|
1985
1985
|
return e.toLowerCase();
|
|
1986
|
-
})),
|
|
1987
|
-
utf8:
|
|
1988
|
-
hex:
|
|
1986
|
+
})), Ms = {
|
|
1987
|
+
utf8: Ts,
|
|
1988
|
+
hex: Os,
|
|
1989
1989
|
base16: _s,
|
|
1990
|
-
base32:
|
|
1990
|
+
base32: Ls,
|
|
1991
1991
|
base64: he,
|
|
1992
|
-
base64url:
|
|
1993
|
-
base58:
|
|
1994
|
-
base58xmr:
|
|
1992
|
+
base64url: $s,
|
|
1993
|
+
base58: Dt,
|
|
1994
|
+
base58xmr: Rs
|
|
1995
1995
|
};
|
|
1996
|
-
`${Object.keys(
|
|
1996
|
+
`${Object.keys(Ms).join(", ")}`;
|
|
1997
1997
|
function Bt(e) {
|
|
1998
1998
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
1999
1999
|
throw new Error(`positive integer expected, not ${e}`);
|
|
2000
2000
|
}
|
|
2001
|
-
function
|
|
2001
|
+
function qn(e) {
|
|
2002
2002
|
if (typeof e != "boolean")
|
|
2003
2003
|
throw new Error(`boolean expected, not ${e}`);
|
|
2004
2004
|
}
|
|
2005
|
-
function
|
|
2005
|
+
function Ps(e) {
|
|
2006
2006
|
return e instanceof Uint8Array || e != null && typeof e == "object" && e.constructor.name === "Uint8Array";
|
|
2007
2007
|
}
|
|
2008
2008
|
function ue(e, ...t) {
|
|
2009
|
-
if (!
|
|
2009
|
+
if (!Ps(e))
|
|
2010
2010
|
throw new Error("Uint8Array expected");
|
|
2011
2011
|
if (t.length > 0 && !t.includes(e.length))
|
|
2012
2012
|
throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`);
|
|
2013
2013
|
}
|
|
2014
2014
|
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
|
|
2015
|
-
const F = (e) => new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4)),
|
|
2016
|
-
if (!
|
|
2015
|
+
const F = (e) => new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4)), Hs = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
2016
|
+
if (!Hs)
|
|
2017
2017
|
throw new Error("Non little-endian hardware is not supported");
|
|
2018
|
-
function
|
|
2018
|
+
function qs(e, t) {
|
|
2019
2019
|
if (t == null || typeof t != "object")
|
|
2020
2020
|
throw new Error("options must be defined");
|
|
2021
2021
|
return Object.assign(e, t);
|
|
@@ -2028,9 +2028,9 @@ function Ds(e, t) {
|
|
|
2028
2028
|
n |= e[r] ^ t[r];
|
|
2029
2029
|
return n === 0;
|
|
2030
2030
|
}
|
|
2031
|
-
const
|
|
2031
|
+
const js = /* @__NO_SIDE_EFFECTS__ */ (e, t) => (Object.assign(t, e), t), Ke = 16, zs = 283;
|
|
2032
2032
|
function tn(e) {
|
|
2033
|
-
return e << 1 ^
|
|
2033
|
+
return e << 1 ^ zs & -(e >> 7);
|
|
2034
2034
|
}
|
|
2035
2035
|
function He(e, t) {
|
|
2036
2036
|
let n = 0;
|
|
@@ -2049,7 +2049,7 @@ const zt = /* @__PURE__ */ (() => {
|
|
|
2049
2049
|
r |= r << 8, t[e[n]] = (r ^ r >> 4 ^ r >> 5 ^ r >> 6 ^ r >> 7 ^ 99) & 255;
|
|
2050
2050
|
}
|
|
2051
2051
|
return t;
|
|
2052
|
-
})(),
|
|
2052
|
+
})(), Ws = /* @__PURE__ */ zt.map((e, t) => zt.indexOf(t)), Vs = (e) => e << 24 | e >>> 8, It = (e) => e << 8 | e >>> 24;
|
|
2053
2053
|
function Er(e, t) {
|
|
2054
2054
|
if (e.length !== 256)
|
|
2055
2055
|
throw new Error("Wrong sbox length");
|
|
@@ -2061,7 +2061,7 @@ function Er(e, t) {
|
|
|
2061
2061
|
}
|
|
2062
2062
|
return { sbox: e, sbox2: a, T0: n, T1: r, T2: i, T3: s, T01: o, T23: c };
|
|
2063
2063
|
}
|
|
2064
|
-
const nn = /* @__PURE__ */ Er(zt, (e) => He(e, 3) << 24 | e << 16 | e << 8 | He(e, 2)), xr = /* @__PURE__ */ Er(
|
|
2064
|
+
const nn = /* @__PURE__ */ Er(zt, (e) => He(e, 3) << 24 | e << 16 | e << 8 | He(e, 2)), xr = /* @__PURE__ */ Er(Ws, (e) => He(e, 11) << 24 | He(e, 13) << 16 | He(e, 9) << 8 | He(e, 14)), Zs = /* @__PURE__ */ (() => {
|
|
2065
2065
|
const e = new Uint8Array(16);
|
|
2066
2066
|
for (let t = 0, n = 1; t < 16; t++, n = tn(n))
|
|
2067
2067
|
e[t] = n;
|
|
@@ -2076,11 +2076,11 @@ function Kr(e) {
|
|
|
2076
2076
|
o.set(r);
|
|
2077
2077
|
for (let c = i; c < o.length; c++) {
|
|
2078
2078
|
let a = o[c - 1];
|
|
2079
|
-
c % i === 0 ? a = s(
|
|
2079
|
+
c % i === 0 ? a = s(Vs(a)) ^ Zs[c / i - 1] : i > 6 && c % i === 4 && (a = s(a)), o[c] = o[c - i] ^ a;
|
|
2080
2080
|
}
|
|
2081
2081
|
return o;
|
|
2082
2082
|
}
|
|
2083
|
-
function
|
|
2083
|
+
function Fs(e) {
|
|
2084
2084
|
const t = Kr(e), n = t.slice(), r = t.length, { sbox2: i } = nn, { T0: s, T1: o, T2: c, T3: a } = xr;
|
|
2085
2085
|
for (let l = 0; l < r; l += 4)
|
|
2086
2086
|
for (let f = 0; f < 4; f++)
|
|
@@ -2098,29 +2098,29 @@ function xe(e, t, n, r, i, s) {
|
|
|
2098
2098
|
function oe(e, t, n, r, i) {
|
|
2099
2099
|
return e[t & 255 | n & 65280] | e[r >>> 16 & 255 | i >>> 16 & 65280] << 16;
|
|
2100
2100
|
}
|
|
2101
|
-
function
|
|
2101
|
+
function Dn(e, t, n, r, i) {
|
|
2102
2102
|
const { sbox2: s, T01: o, T23: c } = nn;
|
|
2103
2103
|
let a = 0;
|
|
2104
2104
|
t ^= e[a++], n ^= e[a++], r ^= e[a++], i ^= e[a++];
|
|
2105
2105
|
const l = e.length / 4 - 2;
|
|
2106
2106
|
for (let g = 0; g < l; g++) {
|
|
2107
|
-
const h = e[a++] ^ xe(o, c, t, n, r, i), d = e[a++] ^ xe(o, c, n, r, i, t),
|
|
2108
|
-
t = h, n = d, r =
|
|
2107
|
+
const h = e[a++] ^ xe(o, c, t, n, r, i), d = e[a++] ^ xe(o, c, n, r, i, t), y = 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 = y, 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), p = e[a++] ^ oe(s, r, i, t, n), w = e[a++] ^ oe(s, i, t, n, r);
|
|
2111
|
+
return { s0: f, s1: u, s2: p, s3: w };
|
|
2112
2112
|
}
|
|
2113
|
-
function
|
|
2113
|
+
function Gs(e, t, n, r, i) {
|
|
2114
2114
|
const { sbox2: s, T01: o, T23: c } = xr;
|
|
2115
2115
|
let a = 0;
|
|
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), y = 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 = y, 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), p = e[a++] ^ oe(s, r, n, t, i), w = e[a++] ^ oe(s, i, r, n, t);
|
|
2123
|
+
return { s0: f, s1: u, s2: p, s3: w };
|
|
2124
2124
|
}
|
|
2125
2125
|
function Nr(e, t) {
|
|
2126
2126
|
if (!t)
|
|
@@ -2129,11 +2129,11 @@ function Nr(e, t) {
|
|
|
2129
2129
|
throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);
|
|
2130
2130
|
return t;
|
|
2131
2131
|
}
|
|
2132
|
-
function
|
|
2132
|
+
function Js(e) {
|
|
2133
2133
|
if (ue(e), e.length % Ke !== 0)
|
|
2134
2134
|
throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Ke}`);
|
|
2135
2135
|
}
|
|
2136
|
-
function
|
|
2136
|
+
function Ys(e, t, n) {
|
|
2137
2137
|
let r = e.length;
|
|
2138
2138
|
const i = r % Ke;
|
|
2139
2139
|
if (!t && i !== 0)
|
|
@@ -2146,7 +2146,7 @@ function Js(e, t, n) {
|
|
|
2146
2146
|
const o = Nr(r, n), c = F(o);
|
|
2147
2147
|
return { b: s, o: c, out: o };
|
|
2148
2148
|
}
|
|
2149
|
-
function
|
|
2149
|
+
function Xs(e, t) {
|
|
2150
2150
|
if (!t)
|
|
2151
2151
|
return e;
|
|
2152
2152
|
const n = e.length;
|
|
@@ -2161,7 +2161,7 @@ function Ys(e, t) {
|
|
|
2161
2161
|
throw new Error("aes/pcks5: wrong padding");
|
|
2162
2162
|
return i;
|
|
2163
2163
|
}
|
|
2164
|
-
function
|
|
2164
|
+
function Qs(e) {
|
|
2165
2165
|
const t = new Uint8Array(16), n = F(t);
|
|
2166
2166
|
t.set(e);
|
|
2167
2167
|
const r = Ke - e.length;
|
|
@@ -2169,35 +2169,35 @@ function Xs(e) {
|
|
|
2169
2169
|
t[i] = r;
|
|
2170
2170
|
return n;
|
|
2171
2171
|
}
|
|
2172
|
-
const Sr = /* @__PURE__ */
|
|
2172
|
+
const Sr = /* @__PURE__ */ js({ blockSize: 16, nonceLength: 16 }, function(t, n, r = {}) {
|
|
2173
2173
|
ue(t), ue(n, 16);
|
|
2174
2174
|
const i = !r.disablePadding;
|
|
2175
2175
|
return {
|
|
2176
2176
|
encrypt: (s, o) => {
|
|
2177
|
-
const c = Kr(t), { b: a, o: l, out: f } =
|
|
2178
|
-
let
|
|
2177
|
+
const c = Kr(t), { b: a, o: l, out: f } = Ys(s, i, o), u = F(n);
|
|
2178
|
+
let p = u[0], w = u[1], g = u[2], h = u[3], d = 0;
|
|
2179
2179
|
for (; d + 4 <= a.length; )
|
|
2180
|
-
|
|
2180
|
+
p ^= a[d + 0], w ^= a[d + 1], g ^= a[d + 2], h ^= a[d + 3], { s0: p, s1: w, s2: g, s3: h } = Dn(c, p, w, g, h), l[d++] = p, l[d++] = w, l[d++] = g, l[d++] = h;
|
|
2181
2181
|
if (i) {
|
|
2182
|
-
const
|
|
2183
|
-
|
|
2182
|
+
const y = Qs(s.subarray(d * 4));
|
|
2183
|
+
p ^= y[0], w ^= y[1], g ^= y[2], h ^= y[3], { s0: p, s1: w, s2: g, s3: h } = Dn(c, p, w, g, h), l[d++] = p, 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
|
-
|
|
2189
|
-
const c =
|
|
2190
|
-
let
|
|
2188
|
+
Js(s);
|
|
2189
|
+
const c = Fs(t), a = F(n), l = Nr(s.length, o), f = F(s), u = F(l);
|
|
2190
|
+
let p = a[0], w = a[1], g = a[2], h = a[3];
|
|
2191
2191
|
for (let d = 0; d + 4 <= f.length; ) {
|
|
2192
|
-
const
|
|
2193
|
-
|
|
2194
|
-
const { s0: k, s1: E, s2: x, s3: K } =
|
|
2195
|
-
u[d++] = k ^
|
|
2192
|
+
const y = p, m = w, S = g, U = h;
|
|
2193
|
+
p = 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 } = Gs(c, p, w, g, h);
|
|
2195
|
+
u[d++] = k ^ y, u[d++] = E ^ m, u[d++] = x ^ S, u[d++] = K ^ U;
|
|
2196
2196
|
}
|
|
2197
|
-
return c.fill(0),
|
|
2197
|
+
return c.fill(0), Xs(l, i);
|
|
2198
2198
|
}
|
|
2199
2199
|
};
|
|
2200
|
-
}), Ar = (e) => Uint8Array.from(e.split("").map((t) => t.charCodeAt(0))),
|
|
2200
|
+
}), Ar = (e) => Uint8Array.from(e.split("").map((t) => t.charCodeAt(0))), eo = Ar("expand 16-byte k"), to = Ar("expand 32-byte k"), no = F(eo), Cr = F(to);
|
|
2201
2201
|
Cr.slice();
|
|
2202
2202
|
function L(e, t) {
|
|
2203
2203
|
return e << t | e >>> 32 - t;
|
|
@@ -2205,9 +2205,9 @@ function L(e, t) {
|
|
|
2205
2205
|
function Wt(e) {
|
|
2206
2206
|
return e.byteOffset % 4 === 0;
|
|
2207
2207
|
}
|
|
2208
|
-
const Xe = 64,
|
|
2209
|
-
function
|
|
2210
|
-
const a = i.length, l = new Uint8Array(Xe), f = F(l), u = Wt(i) && Wt(s),
|
|
2208
|
+
const Xe = 64, ro = 16, kr = 2 ** 32 - 1, jn = new Uint32Array();
|
|
2209
|
+
function io(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), p = u ? F(i) : jn, w = u ? F(s) : jn;
|
|
2211
2211
|
for (let g = 0; g < a; o++) {
|
|
2212
2212
|
if (e(t, n, r, f, o, c), o >= kr)
|
|
2213
2213
|
throw new Error("arx: counter overflow");
|
|
@@ -2216,63 +2216,63 @@ function ro(e, t, n, r, i, s, o, c) {
|
|
|
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
|
-
m = d +
|
|
2219
|
+
for (let y = 0, m; y < ro; y++)
|
|
2220
|
+
m = d + y, w[m] = p[m] ^ f[y];
|
|
2221
2221
|
g += Xe;
|
|
2222
2222
|
continue;
|
|
2223
2223
|
}
|
|
2224
|
-
for (let d = 0,
|
|
2225
|
-
|
|
2224
|
+
for (let d = 0, y; d < h; d++)
|
|
2225
|
+
y = g + d, s[y] = i[y] ^ l[d];
|
|
2226
2226
|
g += h;
|
|
2227
2227
|
}
|
|
2228
2228
|
}
|
|
2229
|
-
function
|
|
2230
|
-
const { allowShortKeys: n, extendNonceFn: r, counterLength: i, counterRight: s, rounds: o } =
|
|
2229
|
+
function so(e, t) {
|
|
2230
|
+
const { allowShortKeys: n, extendNonceFn: r, counterLength: i, counterRight: s, rounds: o } = qs({ 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 Bt(i), Bt(o),
|
|
2233
|
+
return Bt(i), Bt(o), qn(s), qn(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 p = l.length;
|
|
2236
|
+
if (f || (f = new Uint8Array(p)), 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 < p)
|
|
2239
|
+
throw new Error(`arx: output (${f.length}) is shorter than data (${p})`);
|
|
2240
2240
|
const w = [];
|
|
2241
2241
|
let g = c.length, h, d;
|
|
2242
2242
|
if (g === 32)
|
|
2243
2243
|
h = c.slice(), w.push(h), d = Cr;
|
|
2244
2244
|
else if (g === 16 && n)
|
|
2245
|
-
h = new Uint8Array(32), h.set(c), h.set(c, 16), d =
|
|
2245
|
+
h = new Uint8Array(32), h.set(c), h.set(c, 16), d = no, w.push(h);
|
|
2246
2246
|
else
|
|
2247
2247
|
throw new Error(`arx: invalid 32-byte key, got length=${g}`);
|
|
2248
2248
|
Wt(a) || (a = a.slice(), w.push(a));
|
|
2249
|
-
const
|
|
2249
|
+
const y = 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, y, F(a.subarray(0, 16)), y), a = a.subarray(16);
|
|
2254
2254
|
}
|
|
2255
2255
|
const m = 16 - i;
|
|
2256
2256
|
if (m !== a.length)
|
|
2257
2257
|
throw new Error(`arx: nonce must be ${m} or 16 bytes`);
|
|
2258
2258
|
if (m !== 12) {
|
|
2259
|
-
const
|
|
2260
|
-
|
|
2259
|
+
const U = new Uint8Array(12);
|
|
2260
|
+
U.set(a, s ? 0 : 12 - a.length), a = U, w.push(a);
|
|
2261
2261
|
}
|
|
2262
2262
|
const S = F(a);
|
|
2263
|
-
for (
|
|
2263
|
+
for (io(e, d, y, S, l, f, u, o); w.length > 0; )
|
|
2264
2264
|
w.pop().fill(0);
|
|
2265
2265
|
return f;
|
|
2266
2266
|
};
|
|
2267
2267
|
}
|
|
2268
|
-
function
|
|
2269
|
-
let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1],
|
|
2268
|
+
function oo(e, t, n, r, i, s = 20) {
|
|
2269
|
+
let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1], p = t[2], w = t[3], g = t[4], h = t[5], d = t[6], y = t[7], m = i, S = n[0], U = n[1], k = n[2], E = o, x = c, K = a, M = l, I = f, A = u, R = p, T = w, q = g, b = h, v = d, N = y, B = m, C = S, _ = U, O = k;
|
|
2270
2270
|
for (let ee = 0; ee < s; ee += 2)
|
|
2271
|
-
E = E + I | 0, B = L(B ^ E, 16),
|
|
2271
|
+
E = E + I | 0, B = L(B ^ E, 16), q = q + B | 0, I = L(I ^ q, 12), E = E + I | 0, B = L(B ^ E, 8), q = q + B | 0, I = L(I ^ q, 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, _ = L(_ ^ K, 16), v = v + _ | 0, R = L(R ^ v, 12), K = K + R | 0, _ = L(_ ^ K, 8), v = v + _ | 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), q = q + C | 0, T = L(T ^ q, 12), K = K + T | 0, C = L(C ^ K, 8), q = q + C | 0, T = L(T ^ q, 7), M = M + I | 0, _ = L(_ ^ M, 16), b = b + _ | 0, I = L(I ^ b, 12), M = M + I | 0, _ = L(_ ^ M, 8), b = b + _ | 0, I = L(I ^ b, 7);
|
|
2272
2272
|
let $ = 0;
|
|
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[$++] =
|
|
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[$++] = p + R | 0, r[$++] = w + T | 0, r[$++] = g + q | 0, r[$++] = h + b | 0, r[$++] = d + v | 0, r[$++] = y + N | 0, r[$++] = m + B | 0, r[$++] = S + C | 0, r[$++] = U + _ | 0, r[$++] = k + O | 0;
|
|
2274
2274
|
}
|
|
2275
|
-
const Br = /* @__PURE__ */
|
|
2275
|
+
const Br = /* @__PURE__ */ so(oo, {
|
|
2276
2276
|
counterRight: !1,
|
|
2277
2277
|
counterLength: 4,
|
|
2278
2278
|
allowShortKeys: !1
|
|
@@ -2317,23 +2317,23 @@ dt.create = (e, t) => new Ir(e, t);
|
|
|
2317
2317
|
function rn(e, t, n) {
|
|
2318
2318
|
return se.hash(e), n === void 0 && (n = new Uint8Array(e.outputLen)), dt(e, Je(n), Je(t));
|
|
2319
2319
|
}
|
|
2320
|
-
const
|
|
2321
|
-
function
|
|
2320
|
+
const Ut = new Uint8Array([0]), zn = new Uint8Array();
|
|
2321
|
+
function Ur(e, t, n, r = 32) {
|
|
2322
2322
|
if (se.hash(e), se.number(r), r > 255 * e.outputLen)
|
|
2323
2323
|
throw new Error("Length should be <= 255*HashLen");
|
|
2324
2324
|
const i = Math.ceil(r / e.outputLen);
|
|
2325
2325
|
n === void 0 && (n = zn);
|
|
2326
2326
|
const s = new Uint8Array(i * e.outputLen), o = dt.create(e, t), c = o._cloneInto(), a = new Uint8Array(o.outputLen);
|
|
2327
2327
|
for (let l = 0; l < i; l++)
|
|
2328
|
-
|
|
2329
|
-
return o.destroy(), c.destroy(), a.fill(0),
|
|
2328
|
+
Ut[0] = l + 1, c.update(l === 0 ? zn : a).update(n).update(Ut).digestInto(a), s.set(a, e.outputLen * l), o._cloneInto(c);
|
|
2329
|
+
return o.destroy(), c.destroy(), a.fill(0), Ut.fill(0), s.slice(0, r);
|
|
2330
2330
|
}
|
|
2331
|
-
var
|
|
2331
|
+
var ao = Object.defineProperty, H = (e, t) => {
|
|
2332
2332
|
for (var n in t)
|
|
2333
|
-
|
|
2334
|
-
}, Te = Symbol("verified"),
|
|
2335
|
-
function
|
|
2336
|
-
if (!
|
|
2333
|
+
ao(e, n, { get: t[n], enumerable: !0 });
|
|
2334
|
+
}, Te = Symbol("verified"), co = (e) => e instanceof Object;
|
|
2335
|
+
function yt(e) {
|
|
2336
|
+
if (!co(e) || typeof e.kind != "number" || typeof e.content != "string" || typeof e.created_at != "number" || typeof e.pubkey != "string" || !e.pubkey.match(/^[a-f0-9]{64}$/) || !Array.isArray(e.tags))
|
|
2337
2337
|
return !1;
|
|
2338
2338
|
for (let t = 0; t < e.tags.length; t++) {
|
|
2339
2339
|
let n = e.tags[t];
|
|
@@ -2345,21 +2345,21 @@ function pt(e) {
|
|
|
2345
2345
|
}
|
|
2346
2346
|
return !0;
|
|
2347
2347
|
}
|
|
2348
|
-
var
|
|
2349
|
-
H(
|
|
2350
|
-
Queue: () =>
|
|
2351
|
-
QueueNode: () =>
|
|
2348
|
+
var uo = {};
|
|
2349
|
+
H(uo, {
|
|
2350
|
+
Queue: () => yo,
|
|
2351
|
+
QueueNode: () => _r,
|
|
2352
2352
|
binarySearch: () => sn,
|
|
2353
2353
|
bytesToHex: () => P,
|
|
2354
2354
|
hexToBytes: () => j,
|
|
2355
|
-
insertEventIntoAscendingList: () =>
|
|
2356
|
-
insertEventIntoDescendingList: () =>
|
|
2357
|
-
normalizeURL: () =>
|
|
2355
|
+
insertEventIntoAscendingList: () => ho,
|
|
2356
|
+
insertEventIntoDescendingList: () => fo,
|
|
2357
|
+
normalizeURL: () => lo,
|
|
2358
2358
|
utf8Decoder: () => le,
|
|
2359
2359
|
utf8Encoder: () => ne
|
|
2360
2360
|
});
|
|
2361
2361
|
var le = new TextDecoder("utf-8"), ne = new TextEncoder();
|
|
2362
|
-
function
|
|
2362
|
+
function lo(e) {
|
|
2363
2363
|
try {
|
|
2364
2364
|
e.indexOf("://") === -1 && (e = "wss://" + e);
|
|
2365
2365
|
let t = new URL(e);
|
|
@@ -2368,11 +2368,11 @@ function uo(e) {
|
|
|
2368
2368
|
throw new Error(`Invalid URL: ${e}`);
|
|
2369
2369
|
}
|
|
2370
2370
|
}
|
|
2371
|
-
function
|
|
2371
|
+
function fo(e, t) {
|
|
2372
2372
|
const [n, r] = sn(e, (i) => t.id === i.id ? 0 : t.created_at === i.created_at ? -1 : i.created_at - t.created_at);
|
|
2373
2373
|
return r || e.splice(n, 0, t), e;
|
|
2374
2374
|
}
|
|
2375
|
-
function
|
|
2375
|
+
function ho(e, t) {
|
|
2376
2376
|
const [n, r] = sn(e, (i) => t.id === i.id ? 0 : t.created_at === i.created_at ? -1 : t.created_at - i.created_at);
|
|
2377
2377
|
return r || e.splice(n, 0, t), e;
|
|
2378
2378
|
}
|
|
@@ -2386,21 +2386,21 @@ function sn(e, t) {
|
|
|
2386
2386
|
}
|
|
2387
2387
|
return [n, !1];
|
|
2388
2388
|
}
|
|
2389
|
-
var
|
|
2389
|
+
var _r = class {
|
|
2390
2390
|
constructor(e) {
|
|
2391
2391
|
J(this, "value");
|
|
2392
2392
|
J(this, "next", null);
|
|
2393
2393
|
J(this, "prev", null);
|
|
2394
2394
|
this.value = e;
|
|
2395
2395
|
}
|
|
2396
|
-
},
|
|
2396
|
+
}, yo = class {
|
|
2397
2397
|
constructor() {
|
|
2398
2398
|
J(this, "first");
|
|
2399
2399
|
J(this, "last");
|
|
2400
2400
|
this.first = null, this.last = null;
|
|
2401
2401
|
}
|
|
2402
2402
|
enqueue(e) {
|
|
2403
|
-
const t = new
|
|
2403
|
+
const t = new _r(e);
|
|
2404
2404
|
return this.last ? this.last === this.first ? (this.last = t, this.last.prev = this.first, this.first.next = t) : (t.prev = this.last, this.last.next = t, this.last = t) : (this.first = t, this.last = t), !0;
|
|
2405
2405
|
}
|
|
2406
2406
|
dequeue() {
|
|
@@ -2422,12 +2422,12 @@ var Ur = class {
|
|
|
2422
2422
|
}
|
|
2423
2423
|
finalizeEvent(e, t) {
|
|
2424
2424
|
const n = e;
|
|
2425
|
-
return n.pubkey = P(Ze.getPublicKey(t)), n.id =
|
|
2425
|
+
return n.pubkey = P(Ze.getPublicKey(t)), n.id = qe(n), n.sig = P(Ze.sign(qe(n), t)), n[Te] = !0, n;
|
|
2426
2426
|
}
|
|
2427
2427
|
verifyEvent(e) {
|
|
2428
2428
|
if (typeof e[Te] == "boolean")
|
|
2429
2429
|
return e[Te];
|
|
2430
|
-
const t =
|
|
2430
|
+
const t = qe(e);
|
|
2431
2431
|
if (t !== e.id)
|
|
2432
2432
|
return e[Te] = !1, !1;
|
|
2433
2433
|
try {
|
|
@@ -2438,98 +2438,98 @@ var Ur = class {
|
|
|
2438
2438
|
}
|
|
2439
2439
|
}
|
|
2440
2440
|
};
|
|
2441
|
-
function
|
|
2442
|
-
if (!
|
|
2441
|
+
function go(e) {
|
|
2442
|
+
if (!yt(e))
|
|
2443
2443
|
throw new Error("can't serialize event with wrong or missing properties");
|
|
2444
2444
|
return JSON.stringify([0, e.pubkey, e.created_at, e.kind, e.tags, e.content]);
|
|
2445
2445
|
}
|
|
2446
|
-
function
|
|
2447
|
-
let t = fe(ne.encode(
|
|
2446
|
+
function qe(e) {
|
|
2447
|
+
let t = fe(ne.encode(go(e)));
|
|
2448
2448
|
return P(t);
|
|
2449
2449
|
}
|
|
2450
|
-
var
|
|
2451
|
-
H(
|
|
2452
|
-
Application: () =>
|
|
2453
|
-
BadgeAward: () =>
|
|
2454
|
-
BadgeDefinition: () =>
|
|
2455
|
-
BlockedRelaysList: () =>
|
|
2456
|
-
BookmarkList: () =>
|
|
2457
|
-
Bookmarksets: () =>
|
|
2458
|
-
Calendar: () =>
|
|
2459
|
-
CalendarEventRSVP: () =>
|
|
2450
|
+
var pt = new po(), Be = pt.generateSecretKey, ae = pt.getPublicKey, Q = pt.finalizeEvent, gt = pt.verifyEvent, wo = {};
|
|
2451
|
+
H(wo, {
|
|
2452
|
+
Application: () => ga,
|
|
2453
|
+
BadgeAward: () => So,
|
|
2454
|
+
BadgeDefinition: () => ua,
|
|
2455
|
+
BlockedRelaysList: () => Zo,
|
|
2456
|
+
BookmarkList: () => zo,
|
|
2457
|
+
Bookmarksets: () => oa,
|
|
2458
|
+
Calendar: () => Ka,
|
|
2459
|
+
CalendarEventRSVP: () => Na,
|
|
2460
2460
|
ChannelCreation: () => Mr,
|
|
2461
|
-
ChannelHideMessage: () =>
|
|
2461
|
+
ChannelHideMessage: () => qr,
|
|
2462
2462
|
ChannelMessage: () => Hr,
|
|
2463
2463
|
ChannelMetadata: () => Pr,
|
|
2464
|
-
ChannelMuteUser: () =>
|
|
2465
|
-
ClassifiedListing: () =>
|
|
2464
|
+
ChannelMuteUser: () => Dr,
|
|
2465
|
+
ClassifiedListing: () => va,
|
|
2466
2466
|
ClientAuth: () => zr,
|
|
2467
|
-
CommunitiesList: () =>
|
|
2468
|
-
CommunityDefinition: () =>
|
|
2469
|
-
CommunityPostApproval: () =>
|
|
2470
|
-
Contacts: () =>
|
|
2471
|
-
CreateOrUpdateProduct: () =>
|
|
2472
|
-
CreateOrUpdateStall: () =>
|
|
2473
|
-
Curationsets: () =>
|
|
2474
|
-
Date: () =>
|
|
2475
|
-
DirectMessageRelaysList: () =>
|
|
2476
|
-
DraftClassifiedListing: () =>
|
|
2477
|
-
DraftLong: () =>
|
|
2467
|
+
CommunitiesList: () => Wo,
|
|
2468
|
+
CommunityDefinition: () => Ca,
|
|
2469
|
+
CommunityPostApproval: () => Lo,
|
|
2470
|
+
Contacts: () => xo,
|
|
2471
|
+
CreateOrUpdateProduct: () => ha,
|
|
2472
|
+
CreateOrUpdateStall: () => fa,
|
|
2473
|
+
Curationsets: () => aa,
|
|
2474
|
+
Date: () => Ea,
|
|
2475
|
+
DirectMessageRelaysList: () => Yo,
|
|
2476
|
+
DraftClassifiedListing: () => ma,
|
|
2477
|
+
DraftLong: () => ya,
|
|
2478
2478
|
Emojisets: () => pa,
|
|
2479
|
-
EncryptedDirectMessage: () =>
|
|
2480
|
-
EventDeletion: () =>
|
|
2481
|
-
FileMetadata: () =>
|
|
2482
|
-
FileServerPreference: () =>
|
|
2483
|
-
Followsets: () =>
|
|
2479
|
+
EncryptedDirectMessage: () => Ko,
|
|
2480
|
+
EventDeletion: () => No,
|
|
2481
|
+
FileMetadata: () => Co,
|
|
2482
|
+
FileServerPreference: () => Xo,
|
|
2483
|
+
Followsets: () => ra,
|
|
2484
2484
|
GenericRepost: () => ln,
|
|
2485
|
-
Genericlists: () =>
|
|
2485
|
+
Genericlists: () => ia,
|
|
2486
2486
|
GiftWrap: () => jr,
|
|
2487
2487
|
HTTPAuth: () => fn,
|
|
2488
|
-
Handlerinformation: () =>
|
|
2489
|
-
Handlerrecommendation: () =>
|
|
2490
|
-
Highlights: () =>
|
|
2491
|
-
InterestsList: () =>
|
|
2492
|
-
Interestsets: () =>
|
|
2493
|
-
JobFeedback: () =>
|
|
2494
|
-
JobRequest: () =>
|
|
2495
|
-
JobResult: () =>
|
|
2488
|
+
Handlerinformation: () => Aa,
|
|
2489
|
+
Handlerrecommendation: () => Sa,
|
|
2490
|
+
Highlights: () => Ho,
|
|
2491
|
+
InterestsList: () => Go,
|
|
2492
|
+
Interestsets: () => la,
|
|
2493
|
+
JobFeedback: () => To,
|
|
2494
|
+
JobRequest: () => $o,
|
|
2495
|
+
JobResult: () => Ro,
|
|
2496
2496
|
Label: () => _o,
|
|
2497
|
-
LightningPubRPC: () =>
|
|
2498
|
-
LiveChatMessage: () =>
|
|
2499
|
-
LiveEvent: () =>
|
|
2500
|
-
LongFormArticle: () =>
|
|
2501
|
-
Metadata: () =>
|
|
2502
|
-
Mutelist: () =>
|
|
2503
|
-
NWCWalletInfo: () =>
|
|
2497
|
+
LightningPubRPC: () => ea,
|
|
2498
|
+
LiveChatMessage: () => ko,
|
|
2499
|
+
LiveEvent: () => wa,
|
|
2500
|
+
LongFormArticle: () => da,
|
|
2501
|
+
Metadata: () => mo,
|
|
2502
|
+
Mutelist: () => qo,
|
|
2503
|
+
NWCWalletInfo: () => Qo,
|
|
2504
2504
|
NWCWalletRequest: () => Wr,
|
|
2505
|
-
NWCWalletResponse: () =>
|
|
2506
|
-
NostrConnect: () =>
|
|
2507
|
-
OpenTimestamps: () =>
|
|
2505
|
+
NWCWalletResponse: () => ta,
|
|
2506
|
+
NostrConnect: () => na,
|
|
2507
|
+
OpenTimestamps: () => Ao,
|
|
2508
2508
|
Pinlist: () => Do,
|
|
2509
2509
|
PrivateDirectMessage: () => Or,
|
|
2510
|
-
ProblemTracker: () =>
|
|
2511
|
-
ProfileBadges: () =>
|
|
2512
|
-
PublicChatsList: () =>
|
|
2510
|
+
ProblemTracker: () => Bo,
|
|
2511
|
+
ProfileBadges: () => ca,
|
|
2512
|
+
PublicChatsList: () => Vo,
|
|
2513
2513
|
Reaction: () => un,
|
|
2514
|
-
RecommendRelay: () =>
|
|
2515
|
-
RelayList: () =>
|
|
2516
|
-
Relaysets: () =>
|
|
2517
|
-
Report: () =>
|
|
2518
|
-
Reporting: () =>
|
|
2514
|
+
RecommendRelay: () => Eo,
|
|
2515
|
+
RelayList: () => jo,
|
|
2516
|
+
Relaysets: () => sa,
|
|
2517
|
+
Report: () => Io,
|
|
2518
|
+
Reporting: () => Uo,
|
|
2519
2519
|
Repost: () => cn,
|
|
2520
2520
|
Seal: () => Tr,
|
|
2521
|
-
SearchRelaysList: () =>
|
|
2521
|
+
SearchRelaysList: () => Fo,
|
|
2522
2522
|
ShortTextNote: () => Rr,
|
|
2523
|
-
Time: () =>
|
|
2524
|
-
UserEmojiList: () =>
|
|
2525
|
-
UserStatuses: () =>
|
|
2526
|
-
Zap: () =>
|
|
2527
|
-
ZapGoal: () =>
|
|
2528
|
-
ZapRequest: () =>
|
|
2529
|
-
classifyKind: () =>
|
|
2523
|
+
Time: () => xa,
|
|
2524
|
+
UserEmojiList: () => Jo,
|
|
2525
|
+
UserStatuses: () => ba,
|
|
2526
|
+
Zap: () => Po,
|
|
2527
|
+
ZapGoal: () => Oo,
|
|
2528
|
+
ZapRequest: () => Mo,
|
|
2529
|
+
classifyKind: () => bo,
|
|
2530
2530
|
isAddressableKind: () => an,
|
|
2531
2531
|
isEphemeralKind: () => $r,
|
|
2532
|
-
isKind: () =>
|
|
2532
|
+
isKind: () => vo,
|
|
2533
2533
|
isRegularKind: () => Lr,
|
|
2534
2534
|
isReplaceableKind: () => on
|
|
2535
2535
|
});
|
|
@@ -2545,21 +2545,21 @@ function $r(e) {
|
|
|
2545
2545
|
function an(e) {
|
|
2546
2546
|
return 3e4 <= e && e < 4e4;
|
|
2547
2547
|
}
|
|
2548
|
-
function
|
|
2548
|
+
function bo(e) {
|
|
2549
2549
|
return Lr(e) ? "regular" : on(e) ? "replaceable" : $r(e) ? "ephemeral" : an(e) ? "parameterized" : "unknown";
|
|
2550
2550
|
}
|
|
2551
|
-
function
|
|
2551
|
+
function vo(e, t) {
|
|
2552
2552
|
const n = t instanceof Array ? t : [t];
|
|
2553
|
-
return
|
|
2553
|
+
return yt(e) && n.includes(e.kind) || !1;
|
|
2554
2554
|
}
|
|
2555
|
-
var
|
|
2556
|
-
H(
|
|
2555
|
+
var mo = 0, Rr = 1, Eo = 2, xo = 3, Ko = 4, No = 5, cn = 6, un = 7, So = 8, Tr = 13, Or = 14, ln = 16, Mr = 40, Pr = 41, Hr = 42, qr = 43, Dr = 44, Ao = 1040, jr = 1059, Co = 1063, ko = 1311, Bo = 1971, Io = 1984, Uo = 1984, _o = 1985, Lo = 4550, $o = 5999, Ro = 6999, To = 7e3, Oo = 9041, Mo = 9734, Po = 9735, Ho = 9802, qo = 1e4, Do = 10001, jo = 10002, zo = 10003, Wo = 10004, Vo = 10005, Zo = 10006, Fo = 10007, Go = 10015, Jo = 10030, Yo = 10050, Xo = 10096, Qo = 13194, ea = 21e3, zr = 22242, Wr = 23194, ta = 23195, na = 24133, fn = 27235, ra = 3e4, ia = 30001, sa = 30002, oa = 30003, aa = 30004, ca = 30008, ua = 30009, la = 30015, fa = 30017, ha = 30018, da = 30023, ya = 30024, pa = 30030, ga = 30078, wa = 30311, ba = 30315, va = 30402, ma = 30403, Ea = 31922, xa = 31923, Ka = 31924, Na = 31925, Sa = 31989, Aa = 31990, Ca = 34550, ka = {};
|
|
2556
|
+
H(ka, {
|
|
2557
2557
|
getHex64: () => hn,
|
|
2558
2558
|
getInt: () => Vr,
|
|
2559
|
-
getSubscriptionId: () =>
|
|
2560
|
-
matchEventId: () =>
|
|
2559
|
+
getSubscriptionId: () => Ba,
|
|
2560
|
+
matchEventId: () => Ia,
|
|
2561
2561
|
matchEventKind: () => _a,
|
|
2562
|
-
matchEventPubkey: () =>
|
|
2562
|
+
matchEventPubkey: () => Ua
|
|
2563
2563
|
});
|
|
2564
2564
|
function hn(e, t) {
|
|
2565
2565
|
let n = t.length + 3, r = e.indexOf(`"${t}":`) + n, i = e.slice(r).indexOf('"') + r + 1;
|
|
@@ -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 Ba(e) {
|
|
2573
2573
|
let t = e.slice(0, 22).indexOf('"EVENT"');
|
|
2574
2574
|
if (t === -1)
|
|
2575
2575
|
return null;
|
|
@@ -2582,20 +2582,20 @@ function ka(e) {
|
|
|
2582
2582
|
let s = r + 1 + i;
|
|
2583
2583
|
return e.slice(r + 1, s);
|
|
2584
2584
|
}
|
|
2585
|
-
function
|
|
2585
|
+
function Ia(e, t) {
|
|
2586
2586
|
return t === hn(e, "id");
|
|
2587
2587
|
}
|
|
2588
|
-
function
|
|
2588
|
+
function Ua(e, t) {
|
|
2589
2589
|
return t === hn(e, "pubkey");
|
|
2590
2590
|
}
|
|
2591
2591
|
function _a(e, t) {
|
|
2592
2592
|
return t === Vr(e, "kind");
|
|
2593
2593
|
}
|
|
2594
|
-
var
|
|
2595
|
-
H(
|
|
2596
|
-
makeAuthEvent: () =>
|
|
2594
|
+
var La = {};
|
|
2595
|
+
H(La, {
|
|
2596
|
+
makeAuthEvent: () => $a
|
|
2597
2597
|
});
|
|
2598
|
-
function
|
|
2598
|
+
function $a(e, t) {
|
|
2599
2599
|
return {
|
|
2600
2600
|
kind: zr,
|
|
2601
2601
|
created_at: Math.floor(Date.now() / 1e3),
|
|
@@ -2606,32 +2606,32 @@ function La(e, t) {
|
|
|
2606
2606
|
content: ""
|
|
2607
2607
|
};
|
|
2608
2608
|
}
|
|
2609
|
-
var
|
|
2609
|
+
var Ra;
|
|
2610
2610
|
try {
|
|
2611
|
-
|
|
2611
|
+
Ra = WebSocket;
|
|
2612
2612
|
} catch {
|
|
2613
2613
|
}
|
|
2614
|
-
var
|
|
2614
|
+
var Ta;
|
|
2615
2615
|
try {
|
|
2616
|
-
|
|
2616
|
+
Ta = WebSocket;
|
|
2617
2617
|
} catch {
|
|
2618
2618
|
}
|
|
2619
|
-
var
|
|
2620
|
-
H(
|
|
2619
|
+
var Oa = {};
|
|
2620
|
+
H(Oa, {
|
|
2621
2621
|
BECH32_REGEX: () => Zr,
|
|
2622
2622
|
Bech32MaxSize: () => dn,
|
|
2623
|
-
NostrTypeGuard: () =>
|
|
2623
|
+
NostrTypeGuard: () => Ma,
|
|
2624
2624
|
decode: () => wt,
|
|
2625
|
-
decodeNostrURI: () =>
|
|
2625
|
+
decodeNostrURI: () => Ha,
|
|
2626
2626
|
encodeBytes: () => vt,
|
|
2627
|
-
naddrEncode: () =>
|
|
2628
|
-
neventEncode: () =>
|
|
2629
|
-
noteEncode: () =>
|
|
2630
|
-
nprofileEncode: () =>
|
|
2627
|
+
naddrEncode: () => Va,
|
|
2628
|
+
neventEncode: () => Wa,
|
|
2629
|
+
noteEncode: () => ja,
|
|
2630
|
+
nprofileEncode: () => za,
|
|
2631
2631
|
npubEncode: () => Da,
|
|
2632
|
-
nsecEncode: () =>
|
|
2632
|
+
nsecEncode: () => qa
|
|
2633
2633
|
});
|
|
2634
|
-
var
|
|
2634
|
+
var Ma = {
|
|
2635
2635
|
isNProfile: (e) => /^nprofile1[a-z\d]+$/.test(e || ""),
|
|
2636
2636
|
isNEvent: (e) => /^nevent1[a-z\d]+$/.test(e || ""),
|
|
2637
2637
|
isNAddr: (e) => /^naddr1[a-z\d]+$/.test(e || ""),
|
|
@@ -2640,11 +2640,11 @@ var Oa = {
|
|
|
2640
2640
|
isNote: (e) => /^note1[a-z\d]+$/.test(e || ""),
|
|
2641
2641
|
isNcryptsec: (e) => /^ncryptsec1[a-z\d]+$/.test(e || "")
|
|
2642
2642
|
}, dn = 5e3, Zr = /[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;
|
|
2643
|
-
function
|
|
2643
|
+
function Pa(e) {
|
|
2644
2644
|
const t = new Uint8Array(4);
|
|
2645
2645
|
return t[0] = e >> 24 & 255, t[1] = e >> 16 & 255, t[2] = e >> 8 & 255, t[3] = e & 255, t;
|
|
2646
2646
|
}
|
|
2647
|
-
function
|
|
2647
|
+
function Ha(e) {
|
|
2648
2648
|
try {
|
|
2649
2649
|
return e.startsWith("nostr:") && (e = e.substring(6)), wt(e);
|
|
2650
2650
|
} catch {
|
|
@@ -2656,7 +2656,7 @@ function wt(e) {
|
|
|
2656
2656
|
let { prefix: t, words: n } = ze.decode(e, dn), r = new Uint8Array(ze.fromWords(n));
|
|
2657
2657
|
switch (t) {
|
|
2658
2658
|
case "nprofile": {
|
|
2659
|
-
let u =
|
|
2659
|
+
let u = _t(r);
|
|
2660
2660
|
if (!((i = u[0]) != null && i[0]))
|
|
2661
2661
|
throw new Error("missing TLV 0 for nprofile");
|
|
2662
2662
|
if (u[0][0].length !== 32)
|
|
@@ -2665,12 +2665,12 @@ 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((p) => le.decode(p)) : []
|
|
2669
2669
|
}
|
|
2670
2670
|
};
|
|
2671
2671
|
}
|
|
2672
2672
|
case "nevent": {
|
|
2673
|
-
let u =
|
|
2673
|
+
let u = _t(r);
|
|
2674
2674
|
if (!((s = u[0]) != null && s[0]))
|
|
2675
2675
|
throw new Error("missing TLV 0 for nevent");
|
|
2676
2676
|
if (u[0][0].length !== 32)
|
|
@@ -2683,14 +2683,14 @@ 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((p) => le.decode(p)) : [],
|
|
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
|
}
|
|
2690
2690
|
};
|
|
2691
2691
|
}
|
|
2692
2692
|
case "naddr": {
|
|
2693
|
-
let u =
|
|
2693
|
+
let u = _t(r);
|
|
2694
2694
|
if (!((a = u[0]) != null && a[0]))
|
|
2695
2695
|
throw new Error("missing TLV 0 for naddr");
|
|
2696
2696
|
if (!((l = u[2]) != null && l[0]))
|
|
@@ -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((p) => le.decode(p)) : []
|
|
2711
2711
|
}
|
|
2712
2712
|
};
|
|
2713
2713
|
}
|
|
@@ -2720,7 +2720,7 @@ function wt(e) {
|
|
|
2720
2720
|
throw new Error(`unknown prefix ${t}`);
|
|
2721
2721
|
}
|
|
2722
2722
|
}
|
|
2723
|
-
function
|
|
2723
|
+
function _t(e) {
|
|
2724
2724
|
let t = {}, n = e;
|
|
2725
2725
|
for (; n.length > 0; ) {
|
|
2726
2726
|
let r = n[0], i = n[1], s = n.slice(2, 2 + i);
|
|
@@ -2730,13 +2730,13 @@ function Ut(e) {
|
|
|
2730
2730
|
}
|
|
2731
2731
|
return t;
|
|
2732
2732
|
}
|
|
2733
|
-
function
|
|
2733
|
+
function qa(e) {
|
|
2734
2734
|
return vt("nsec", e);
|
|
2735
2735
|
}
|
|
2736
2736
|
function Da(e) {
|
|
2737
2737
|
return vt("npub", j(e));
|
|
2738
2738
|
}
|
|
2739
|
-
function
|
|
2739
|
+
function ja(e) {
|
|
2740
2740
|
return vt("note", j(e));
|
|
2741
2741
|
}
|
|
2742
2742
|
function bt(e, t) {
|
|
@@ -2746,17 +2746,17 @@ function bt(e, t) {
|
|
|
2746
2746
|
function vt(e, t) {
|
|
2747
2747
|
return bt(e, t);
|
|
2748
2748
|
}
|
|
2749
|
-
function
|
|
2750
|
-
let t =
|
|
2749
|
+
function za(e) {
|
|
2750
|
+
let t = yn({
|
|
2751
2751
|
0: [j(e.pubkey)],
|
|
2752
2752
|
1: (e.relays || []).map((n) => ne.encode(n))
|
|
2753
2753
|
});
|
|
2754
2754
|
return bt("nprofile", t);
|
|
2755
2755
|
}
|
|
2756
|
-
function
|
|
2756
|
+
function Wa(e) {
|
|
2757
2757
|
let t;
|
|
2758
|
-
e.kind !== void 0 && (t =
|
|
2759
|
-
let n =
|
|
2758
|
+
e.kind !== void 0 && (t = Pa(e.kind));
|
|
2759
|
+
let n = yn({
|
|
2760
2760
|
0: [j(e.id)],
|
|
2761
2761
|
1: (e.relays || []).map((r) => ne.encode(r)),
|
|
2762
2762
|
2: e.author ? [j(e.author)] : [],
|
|
@@ -2764,10 +2764,10 @@ function za(e) {
|
|
|
2764
2764
|
});
|
|
2765
2765
|
return bt("nevent", n);
|
|
2766
2766
|
}
|
|
2767
|
-
function
|
|
2767
|
+
function Va(e) {
|
|
2768
2768
|
let t = new ArrayBuffer(4);
|
|
2769
2769
|
new DataView(t).setUint32(0, e.kind, !1);
|
|
2770
|
-
let n =
|
|
2770
|
+
let n = yn({
|
|
2771
2771
|
0: [ne.encode(e.identifier)],
|
|
2772
2772
|
1: (e.relays || []).map((r) => ne.encode(r)),
|
|
2773
2773
|
2: [j(e.pubkey)],
|
|
@@ -2775,7 +2775,7 @@ function Wa(e) {
|
|
|
2775
2775
|
});
|
|
2776
2776
|
return bt("naddr", n);
|
|
2777
2777
|
}
|
|
2778
|
-
function
|
|
2778
|
+
function yn(e) {
|
|
2779
2779
|
let t = [];
|
|
2780
2780
|
return Object.entries(e).reverse().forEach(([n, r]) => {
|
|
2781
2781
|
r.forEach((i) => {
|
|
@@ -2784,42 +2784,42 @@ function pn(e) {
|
|
|
2784
2784
|
});
|
|
2785
2785
|
}), ft(...t);
|
|
2786
2786
|
}
|
|
2787
|
-
var
|
|
2788
|
-
H(
|
|
2789
|
-
decrypt: () =>
|
|
2787
|
+
var Za = {};
|
|
2788
|
+
H(Za, {
|
|
2789
|
+
decrypt: () => Fa,
|
|
2790
2790
|
encrypt: () => Fr
|
|
2791
2791
|
});
|
|
2792
2792
|
function Fr(e, t, n) {
|
|
2793
|
-
const r = e instanceof Uint8Array ? P(e) : e, i =
|
|
2794
|
-
let o = Uint8Array.from(
|
|
2793
|
+
const r = e instanceof Uint8Array ? P(e) : e, i = Ue.getSharedSecret(r, "02" + t), s = Gr(i);
|
|
2794
|
+
let o = Uint8Array.from(pr(16)), c = ne.encode(n), a = Sr(s, o).encrypt(c), l = he.encode(new Uint8Array(a)), f = he.encode(new Uint8Array(o.buffer));
|
|
2795
2795
|
return `${l}?iv=${f}`;
|
|
2796
2796
|
}
|
|
2797
|
-
function
|
|
2797
|
+
function Fa(e, t, n) {
|
|
2798
2798
|
const r = e instanceof Uint8Array ? P(e) : e;
|
|
2799
|
-
let [i, s] = n.split("?iv="), o =
|
|
2799
|
+
let [i, s] = n.split("?iv="), o = Ue.getSharedSecret(r, "02" + t), c = Gr(o), a = he.decode(s), l = he.decode(i), f = Sr(c, a).decrypt(l);
|
|
2800
2800
|
return le.decode(f);
|
|
2801
2801
|
}
|
|
2802
2802
|
function Gr(e) {
|
|
2803
2803
|
return e.slice(1, 33);
|
|
2804
2804
|
}
|
|
2805
|
-
var
|
|
2806
|
-
H(
|
|
2807
|
-
NIP05_REGEX: () =>
|
|
2808
|
-
isNip05: () =>
|
|
2809
|
-
isValid: () =>
|
|
2805
|
+
var Ga = {};
|
|
2806
|
+
H(Ga, {
|
|
2807
|
+
NIP05_REGEX: () => pn,
|
|
2808
|
+
isNip05: () => Ja,
|
|
2809
|
+
isValid: () => Qa,
|
|
2810
2810
|
queryProfile: () => Jr,
|
|
2811
|
-
searchDomain: () =>
|
|
2812
|
-
useFetchImplementation: () =>
|
|
2811
|
+
searchDomain: () => Xa,
|
|
2812
|
+
useFetchImplementation: () => Ya
|
|
2813
2813
|
});
|
|
2814
|
-
var
|
|
2814
|
+
var pn = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/, Ja = (e) => pn.test(e || ""), mt;
|
|
2815
2815
|
try {
|
|
2816
2816
|
mt = fetch;
|
|
2817
2817
|
} catch {
|
|
2818
2818
|
}
|
|
2819
|
-
function
|
|
2819
|
+
function Ya(e) {
|
|
2820
2820
|
mt = e;
|
|
2821
2821
|
}
|
|
2822
|
-
async function
|
|
2822
|
+
async function Xa(e, t = "") {
|
|
2823
2823
|
try {
|
|
2824
2824
|
const n = `https://${e}/.well-known/nostr.json?name=${t}`, r = await mt(n, { redirect: "manual" });
|
|
2825
2825
|
if (r.status !== 200)
|
|
@@ -2831,7 +2831,7 @@ async function Ya(e, t = "") {
|
|
|
2831
2831
|
}
|
|
2832
2832
|
async function Jr(e) {
|
|
2833
2833
|
var i;
|
|
2834
|
-
const t = e.match(
|
|
2834
|
+
const t = e.match(pn);
|
|
2835
2835
|
if (!t)
|
|
2836
2836
|
return null;
|
|
2837
2837
|
const [, n = "_", r] = t;
|
|
@@ -2845,15 +2845,15 @@ async function Jr(e) {
|
|
|
2845
2845
|
return null;
|
|
2846
2846
|
}
|
|
2847
2847
|
}
|
|
2848
|
-
async function
|
|
2848
|
+
async function Qa(e, t) {
|
|
2849
2849
|
const n = await Jr(t);
|
|
2850
2850
|
return n ? n.pubkey === e : !1;
|
|
2851
2851
|
}
|
|
2852
|
-
var
|
|
2853
|
-
H(
|
|
2854
|
-
parse: () =>
|
|
2852
|
+
var ec = {};
|
|
2853
|
+
H(ec, {
|
|
2854
|
+
parse: () => tc
|
|
2855
2855
|
});
|
|
2856
|
-
function
|
|
2856
|
+
function tc(e) {
|
|
2857
2857
|
const t = {
|
|
2858
2858
|
reply: void 0,
|
|
2859
2859
|
root: void 0,
|
|
@@ -2920,29 +2920,29 @@ function ec(e) {
|
|
|
2920
2920
|
}
|
|
2921
2921
|
}), t;
|
|
2922
2922
|
}
|
|
2923
|
-
var
|
|
2924
|
-
H(
|
|
2925
|
-
fetchRelayInformation: () =>
|
|
2926
|
-
useFetchImplementation: () =>
|
|
2923
|
+
var nc = {};
|
|
2924
|
+
H(nc, {
|
|
2925
|
+
fetchRelayInformation: () => ic,
|
|
2926
|
+
useFetchImplementation: () => rc
|
|
2927
2927
|
});
|
|
2928
2928
|
var Yr;
|
|
2929
2929
|
try {
|
|
2930
2930
|
Yr = fetch;
|
|
2931
2931
|
} catch {
|
|
2932
2932
|
}
|
|
2933
|
-
function
|
|
2933
|
+
function rc(e) {
|
|
2934
2934
|
Yr = e;
|
|
2935
2935
|
}
|
|
2936
|
-
async function
|
|
2936
|
+
async function ic(e) {
|
|
2937
2937
|
return await (await fetch(e.replace("ws://", "http://").replace("wss://", "https://"), {
|
|
2938
2938
|
headers: { Accept: "application/nostr+json" }
|
|
2939
2939
|
})).json();
|
|
2940
2940
|
}
|
|
2941
|
-
var
|
|
2942
|
-
H(
|
|
2941
|
+
var sc = {};
|
|
2942
|
+
H(sc, {
|
|
2943
2943
|
fastEventHash: () => Qr,
|
|
2944
2944
|
getPow: () => Xr,
|
|
2945
|
-
minePow: () =>
|
|
2945
|
+
minePow: () => oc
|
|
2946
2946
|
});
|
|
2947
2947
|
function Xr(e) {
|
|
2948
2948
|
let t = 0;
|
|
@@ -2957,7 +2957,7 @@ function Xr(e) {
|
|
|
2957
2957
|
}
|
|
2958
2958
|
return t;
|
|
2959
2959
|
}
|
|
2960
|
-
function
|
|
2960
|
+
function oc(e, t) {
|
|
2961
2961
|
let n = 0;
|
|
2962
2962
|
const r = e, i = ["nonce", n.toString(), t.toString()];
|
|
2963
2963
|
for (r.tags.push(i); ; ) {
|
|
@@ -2972,15 +2972,15 @@ function Qr(e) {
|
|
|
2972
2972
|
fe(ne.encode(JSON.stringify([0, e.pubkey, e.created_at, e.kind, e.tags, e.content])))
|
|
2973
2973
|
);
|
|
2974
2974
|
}
|
|
2975
|
-
var oc = {};
|
|
2976
|
-
H(oc, {
|
|
2977
|
-
unwrapEvent: () => wc,
|
|
2978
|
-
unwrapManyEvents: () => bc,
|
|
2979
|
-
wrapEvent: () => hi,
|
|
2980
|
-
wrapManyEvents: () => gc
|
|
2981
|
-
});
|
|
2982
2975
|
var ac = {};
|
|
2983
2976
|
H(ac, {
|
|
2977
|
+
unwrapEvent: () => bc,
|
|
2978
|
+
unwrapManyEvents: () => vc,
|
|
2979
|
+
wrapEvent: () => hi,
|
|
2980
|
+
wrapManyEvents: () => wc
|
|
2981
|
+
});
|
|
2982
|
+
var cc = {};
|
|
2983
|
+
H(cc, {
|
|
2984
2984
|
createRumor: () => ci,
|
|
2985
2985
|
createSeal: () => ui,
|
|
2986
2986
|
createWrap: () => li,
|
|
@@ -2989,20 +2989,20 @@ H(ac, {
|
|
|
2989
2989
|
wrapEvent: () => st,
|
|
2990
2990
|
wrapManyEvents: () => pc
|
|
2991
2991
|
});
|
|
2992
|
-
var
|
|
2993
|
-
H(
|
|
2992
|
+
var D = {};
|
|
2993
|
+
H(D, {
|
|
2994
2994
|
decrypt: () => vn,
|
|
2995
2995
|
encrypt: () => bn,
|
|
2996
2996
|
getConversationKey: () => gn,
|
|
2997
|
-
v2: () =>
|
|
2997
|
+
v2: () => dc
|
|
2998
2998
|
});
|
|
2999
2999
|
var ei = 1, ti = 65535;
|
|
3000
3000
|
function gn(e, t) {
|
|
3001
|
-
const n =
|
|
3001
|
+
const n = Ue.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3002
3002
|
return rn(fe, n, "nip44-v2");
|
|
3003
3003
|
}
|
|
3004
3004
|
function ni(e, t) {
|
|
3005
|
-
const n =
|
|
3005
|
+
const n = Ur(fe, e, t, 76);
|
|
3006
3006
|
return {
|
|
3007
3007
|
chacha_key: n.subarray(0, 32),
|
|
3008
3008
|
chacha_nonce: n.subarray(32, 44),
|
|
@@ -3017,17 +3017,17 @@ function wn(e) {
|
|
|
3017
3017
|
const t = 1 << Math.floor(Math.log2(e - 1)) + 1, n = t <= 256 ? 32 : t / 8;
|
|
3018
3018
|
return n * (Math.floor((e - 1) / n) + 1);
|
|
3019
3019
|
}
|
|
3020
|
-
function
|
|
3020
|
+
function uc(e) {
|
|
3021
3021
|
if (!Number.isSafeInteger(e) || e < ei || e > ti)
|
|
3022
3022
|
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
|
|
3023
3023
|
const t = new Uint8Array(2);
|
|
3024
3024
|
return new DataView(t.buffer).setUint16(0, e, !1), t;
|
|
3025
3025
|
}
|
|
3026
|
-
function
|
|
3027
|
-
const t = ne.encode(e), n = t.length, r =
|
|
3026
|
+
function lc(e) {
|
|
3027
|
+
const t = ne.encode(e), n = t.length, r = uc(n), i = new Uint8Array(wn(n) - n);
|
|
3028
3028
|
return ft(r, t, i);
|
|
3029
3029
|
}
|
|
3030
|
-
function
|
|
3030
|
+
function fc(e) {
|
|
3031
3031
|
const t = new DataView(e.buffer).getUint16(0), n = e.subarray(2, 2 + t);
|
|
3032
3032
|
if (t < ei || t > ti || n.length !== t || e.length !== 2 + wn(t))
|
|
3033
3033
|
throw new Error("invalid padding");
|
|
@@ -3039,7 +3039,7 @@ function ri(e, t, n) {
|
|
|
3039
3039
|
const r = ft(n, t);
|
|
3040
3040
|
return dt(fe, e, r);
|
|
3041
3041
|
}
|
|
3042
|
-
function
|
|
3042
|
+
function hc(e) {
|
|
3043
3043
|
if (typeof e != "string")
|
|
3044
3044
|
throw new Error("payload must be a valid string");
|
|
3045
3045
|
const t = e.length;
|
|
@@ -3065,25 +3065,25 @@ function fc(e) {
|
|
|
3065
3065
|
mac: n.subarray(-32)
|
|
3066
3066
|
};
|
|
3067
3067
|
}
|
|
3068
|
-
function bn(e, t, n =
|
|
3069
|
-
const { chacha_key: r, chacha_nonce: i, hmac_key: s } = ni(t, n), o =
|
|
3068
|
+
function bn(e, t, n = pr(32)) {
|
|
3069
|
+
const { chacha_key: r, chacha_nonce: i, hmac_key: s } = ni(t, n), o = lc(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
|
-
const { nonce: n, ciphertext: r, mac: i } =
|
|
3073
|
+
const { nonce: n, ciphertext: r, mac: i } = hc(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
3076
|
const l = Br(s, o, r);
|
|
3077
|
-
return
|
|
3077
|
+
return fc(l);
|
|
3078
3078
|
}
|
|
3079
|
-
var
|
|
3079
|
+
var dc = {
|
|
3080
3080
|
utils: {
|
|
3081
3081
|
getConversationKey: gn,
|
|
3082
3082
|
calcPaddedLen: wn
|
|
3083
3083
|
},
|
|
3084
3084
|
encrypt: bn,
|
|
3085
3085
|
decrypt: vn
|
|
3086
|
-
},
|
|
3086
|
+
}, yc = 2 * 24 * 60 * 60, ii = () => Math.round(Date.now() / 1e3), si = () => Math.round(ii() - Math.random() * yc), oi = (e, t) => gn(e, t), ai = (e, t, n) => bn(JSON.stringify(e), oi(t, n)), Wn = (e, t) => JSON.parse(vn(e.content, oi(t, e.pubkey)));
|
|
3087
3087
|
function ci(e, t) {
|
|
3088
3088
|
const n = {
|
|
3089
3089
|
created_at: ii(),
|
|
@@ -3092,7 +3092,7 @@ function ci(e, t) {
|
|
|
3092
3092
|
...e,
|
|
3093
3093
|
pubkey: ae(t)
|
|
3094
3094
|
};
|
|
3095
|
-
return n.id =
|
|
3095
|
+
return n.id = qe(n), n;
|
|
3096
3096
|
}
|
|
3097
3097
|
function ui(e, t, n) {
|
|
3098
3098
|
return Q(
|
|
@@ -3139,7 +3139,7 @@ function fi(e, t) {
|
|
|
3139
3139
|
n.push(mn(r, t));
|
|
3140
3140
|
}), n.sort((r, i) => r.created_at - i.created_at), n;
|
|
3141
3141
|
}
|
|
3142
|
-
function
|
|
3142
|
+
function gc(e, t, n, r) {
|
|
3143
3143
|
const i = {
|
|
3144
3144
|
created_at: Math.ceil(Date.now() / 1e3),
|
|
3145
3145
|
kind: Or,
|
|
@@ -3151,23 +3151,23 @@ function yc(e, t, n, r) {
|
|
|
3151
3151
|
}), r && i.tags.push(["e", r.eventId, r.relayUrl || "", "reply"]), n && i.tags.push(["subject", n]), i;
|
|
3152
3152
|
}
|
|
3153
3153
|
function hi(e, t, n, r, i) {
|
|
3154
|
-
const s =
|
|
3154
|
+
const s = gc(t, n, r, i);
|
|
3155
3155
|
return st(s, e, t.publicKey);
|
|
3156
3156
|
}
|
|
3157
|
-
function
|
|
3157
|
+
function wc(e, t, n, r, i) {
|
|
3158
3158
|
if (!t || t.length === 0)
|
|
3159
3159
|
throw new Error("At least one recipient is required.");
|
|
3160
3160
|
return [{ publicKey: ae(e) }, ...t].map(
|
|
3161
3161
|
(o) => hi(e, o, n, r, i)
|
|
3162
3162
|
);
|
|
3163
3163
|
}
|
|
3164
|
-
var
|
|
3165
|
-
H(
|
|
3166
|
-
finishRepostEvent: () =>
|
|
3167
|
-
getRepostedEvent: () =>
|
|
3164
|
+
var bc = mn, vc = fi, mc = {};
|
|
3165
|
+
H(mc, {
|
|
3166
|
+
finishRepostEvent: () => Ec,
|
|
3167
|
+
getRepostedEvent: () => xc,
|
|
3168
3168
|
getRepostedEventPointer: () => di
|
|
3169
3169
|
});
|
|
3170
|
-
function
|
|
3170
|
+
function Ec(e, t, n, r) {
|
|
3171
3171
|
var o;
|
|
3172
3172
|
let i;
|
|
3173
3173
|
const s = [...e.tags ?? [], ["e", t.id, n], ["p", t.pubkey]];
|
|
@@ -3196,7 +3196,7 @@ function di(e) {
|
|
|
3196
3196
|
author: n == null ? void 0 : n[1]
|
|
3197
3197
|
};
|
|
3198
3198
|
}
|
|
3199
|
-
function
|
|
3199
|
+
function xc(e, { skipVerification: t } = {}) {
|
|
3200
3200
|
const n = di(e);
|
|
3201
3201
|
if (n === void 0 || e.content === "")
|
|
3202
3202
|
return;
|
|
@@ -3209,17 +3209,17 @@ function Ec(e, { skipVerification: t } = {}) {
|
|
|
3209
3209
|
if (r.id === n.id && !(!t && !gt(r)))
|
|
3210
3210
|
return r;
|
|
3211
3211
|
}
|
|
3212
|
-
var
|
|
3213
|
-
H(
|
|
3212
|
+
var Kc = {};
|
|
3213
|
+
H(Kc, {
|
|
3214
3214
|
NOSTR_URI_REGEX: () => En,
|
|
3215
|
-
parse: () =>
|
|
3216
|
-
test: () =>
|
|
3215
|
+
parse: () => Sc,
|
|
3216
|
+
test: () => Nc
|
|
3217
3217
|
});
|
|
3218
3218
|
var En = new RegExp(`nostr:(${Zr.source})`);
|
|
3219
|
-
function
|
|
3219
|
+
function Nc(e) {
|
|
3220
3220
|
return typeof e == "string" && new RegExp(`^${En.source}$`).test(e);
|
|
3221
3221
|
}
|
|
3222
|
-
function
|
|
3222
|
+
function Sc(e) {
|
|
3223
3223
|
const t = e.match(new RegExp(`^${En.source}$`));
|
|
3224
3224
|
if (!t)
|
|
3225
3225
|
throw new Error(`Invalid Nostr URI: ${e}`);
|
|
@@ -3229,12 +3229,12 @@ function Nc(e) {
|
|
|
3229
3229
|
decoded: wt(t[1])
|
|
3230
3230
|
};
|
|
3231
3231
|
}
|
|
3232
|
-
var
|
|
3233
|
-
H(
|
|
3234
|
-
finishReactionEvent: () =>
|
|
3235
|
-
getReactedEventPointer: () =>
|
|
3232
|
+
var Ac = {};
|
|
3233
|
+
H(Ac, {
|
|
3234
|
+
finishReactionEvent: () => Cc,
|
|
3235
|
+
getReactedEventPointer: () => kc
|
|
3236
3236
|
});
|
|
3237
|
-
function
|
|
3237
|
+
function Cc(e, t, n) {
|
|
3238
3238
|
const r = t.tags.filter((i) => i.length >= 2 && (i[0] === "e" || i[0] === "p"));
|
|
3239
3239
|
return Q(
|
|
3240
3240
|
{
|
|
@@ -3246,7 +3246,7 @@ function Ac(e, t, n) {
|
|
|
3246
3246
|
n
|
|
3247
3247
|
);
|
|
3248
3248
|
}
|
|
3249
|
-
function
|
|
3249
|
+
function kc(e) {
|
|
3250
3250
|
if (e.kind !== un)
|
|
3251
3251
|
return;
|
|
3252
3252
|
let t, n;
|
|
@@ -3261,12 +3261,12 @@ function Cc(e) {
|
|
|
3261
3261
|
author: n[1]
|
|
3262
3262
|
};
|
|
3263
3263
|
}
|
|
3264
|
-
var
|
|
3265
|
-
H(
|
|
3266
|
-
parse: () =>
|
|
3264
|
+
var Bc = {};
|
|
3265
|
+
H(Bc, {
|
|
3266
|
+
parse: () => Uc
|
|
3267
3267
|
});
|
|
3268
|
-
var
|
|
3269
|
-
function*
|
|
3268
|
+
var Ic = /\W/m, Vn = /\W |\W$|$|,| /m;
|
|
3269
|
+
function* Uc(e) {
|
|
3270
3270
|
const t = e.length;
|
|
3271
3271
|
let n = 0, r = 0;
|
|
3272
3272
|
for (; r < t; ) {
|
|
@@ -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(Ic), 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) {
|
|
@@ -3339,13 +3339,13 @@ function* Ic(e) {
|
|
|
3339
3339
|
}
|
|
3340
3340
|
var _c = {};
|
|
3341
3341
|
H(_c, {
|
|
3342
|
-
channelCreateEvent: () =>
|
|
3343
|
-
channelHideMessageEvent: () =>
|
|
3344
|
-
channelMessageEvent: () =>
|
|
3345
|
-
channelMetadataEvent: () =>
|
|
3346
|
-
channelMuteUserEvent: () =>
|
|
3342
|
+
channelCreateEvent: () => Lc,
|
|
3343
|
+
channelHideMessageEvent: () => Tc,
|
|
3344
|
+
channelMessageEvent: () => Rc,
|
|
3345
|
+
channelMetadataEvent: () => $c,
|
|
3346
|
+
channelMuteUserEvent: () => Oc
|
|
3347
3347
|
});
|
|
3348
|
-
var
|
|
3348
|
+
var Lc = (e, t) => {
|
|
3349
3349
|
let n;
|
|
3350
3350
|
if (typeof e.content == "object")
|
|
3351
3351
|
n = JSON.stringify(e.content);
|
|
@@ -3362,7 +3362,7 @@ var Uc = (e, t) => {
|
|
|
3362
3362
|
},
|
|
3363
3363
|
t
|
|
3364
3364
|
);
|
|
3365
|
-
},
|
|
3365
|
+
}, $c = (e, t) => {
|
|
3366
3366
|
let n;
|
|
3367
3367
|
if (typeof e.content == "object")
|
|
3368
3368
|
n = JSON.stringify(e.content);
|
|
@@ -3379,7 +3379,7 @@ var Uc = (e, t) => {
|
|
|
3379
3379
|
},
|
|
3380
3380
|
t
|
|
3381
3381
|
);
|
|
3382
|
-
},
|
|
3382
|
+
}, Rc = (e, t) => {
|
|
3383
3383
|
const n = [["e", e.channel_create_event_id, e.relay_url, "root"]];
|
|
3384
3384
|
return e.reply_to_channel_message_event_id && n.push(["e", e.reply_to_channel_message_event_id, e.relay_url, "reply"]), Q(
|
|
3385
3385
|
{
|
|
@@ -3390,7 +3390,7 @@ var Uc = (e, t) => {
|
|
|
3390
3390
|
},
|
|
3391
3391
|
t
|
|
3392
3392
|
);
|
|
3393
|
-
},
|
|
3393
|
+
}, Tc = (e, t) => {
|
|
3394
3394
|
let n;
|
|
3395
3395
|
if (typeof e.content == "object")
|
|
3396
3396
|
n = JSON.stringify(e.content);
|
|
@@ -3400,14 +3400,14 @@ var Uc = (e, t) => {
|
|
|
3400
3400
|
return;
|
|
3401
3401
|
return Q(
|
|
3402
3402
|
{
|
|
3403
|
-
kind:
|
|
3403
|
+
kind: qr,
|
|
3404
3404
|
tags: [["e", e.channel_message_event_id], ...e.tags ?? []],
|
|
3405
3405
|
content: n,
|
|
3406
3406
|
created_at: e.created_at
|
|
3407
3407
|
},
|
|
3408
3408
|
t
|
|
3409
3409
|
);
|
|
3410
|
-
},
|
|
3410
|
+
}, Oc = (e, t) => {
|
|
3411
3411
|
let n;
|
|
3412
3412
|
if (typeof e.content == "object")
|
|
3413
3413
|
n = JSON.stringify(e.content);
|
|
@@ -3417,22 +3417,22 @@ var Uc = (e, t) => {
|
|
|
3417
3417
|
return;
|
|
3418
3418
|
return Q(
|
|
3419
3419
|
{
|
|
3420
|
-
kind:
|
|
3420
|
+
kind: Dr,
|
|
3421
3421
|
tags: [["p", e.pubkey_to_mute], ...e.tags ?? []],
|
|
3422
3422
|
content: n,
|
|
3423
3423
|
created_at: e.created_at
|
|
3424
3424
|
},
|
|
3425
3425
|
t
|
|
3426
3426
|
);
|
|
3427
|
-
},
|
|
3428
|
-
H(
|
|
3429
|
-
EMOJI_SHORTCODE_REGEX: () =>
|
|
3430
|
-
matchAll: () =>
|
|
3427
|
+
}, Mc = {};
|
|
3428
|
+
H(Mc, {
|
|
3429
|
+
EMOJI_SHORTCODE_REGEX: () => yi,
|
|
3430
|
+
matchAll: () => Pc,
|
|
3431
3431
|
regex: () => xn,
|
|
3432
|
-
replaceAll: () =>
|
|
3432
|
+
replaceAll: () => Hc
|
|
3433
3433
|
});
|
|
3434
|
-
var
|
|
3435
|
-
function*
|
|
3434
|
+
var yi = /:(\w+):/, xn = () => new RegExp(`\\B${yi.source}\\B`, "g");
|
|
3435
|
+
function* Pc(e) {
|
|
3436
3436
|
const t = e.matchAll(xn());
|
|
3437
3437
|
for (const n of t)
|
|
3438
3438
|
try {
|
|
@@ -3446,16 +3446,16 @@ function* Mc(e) {
|
|
|
3446
3446
|
} catch {
|
|
3447
3447
|
}
|
|
3448
3448
|
}
|
|
3449
|
-
function
|
|
3449
|
+
function Hc(e, t) {
|
|
3450
3450
|
return e.replaceAll(xn(), (n, r) => t({
|
|
3451
3451
|
shortcode: n,
|
|
3452
3452
|
name: r
|
|
3453
3453
|
}));
|
|
3454
3454
|
}
|
|
3455
|
-
var
|
|
3456
|
-
H(
|
|
3455
|
+
var qc = {};
|
|
3456
|
+
H(qc, {
|
|
3457
3457
|
useFetchImplementation: () => Dc,
|
|
3458
|
-
validateGithub: () =>
|
|
3458
|
+
validateGithub: () => jc
|
|
3459
3459
|
});
|
|
3460
3460
|
var Kn;
|
|
3461
3461
|
try {
|
|
@@ -3465,25 +3465,25 @@ try {
|
|
|
3465
3465
|
function Dc(e) {
|
|
3466
3466
|
Kn = e;
|
|
3467
3467
|
}
|
|
3468
|
-
async function
|
|
3468
|
+
async function jc(e, t, n) {
|
|
3469
3469
|
try {
|
|
3470
3470
|
return await (await Kn(`https://gist.github.com/${t}/${n}/raw`)).text() === `Verifying that I control the following Nostr public key: ${e}`;
|
|
3471
3471
|
} catch {
|
|
3472
3472
|
return !1;
|
|
3473
3473
|
}
|
|
3474
3474
|
}
|
|
3475
|
-
var
|
|
3476
|
-
H(
|
|
3477
|
-
makeNwcRequestEvent: () =>
|
|
3478
|
-
parseConnectionString: () =>
|
|
3475
|
+
var zc = {};
|
|
3476
|
+
H(zc, {
|
|
3477
|
+
makeNwcRequestEvent: () => Vc,
|
|
3478
|
+
parseConnectionString: () => Wc
|
|
3479
3479
|
});
|
|
3480
|
-
function
|
|
3480
|
+
function Wc(e) {
|
|
3481
3481
|
const { host: t, pathname: n, searchParams: r } = new URL(e), i = n || t, s = r.get("relay"), o = r.get("secret");
|
|
3482
3482
|
if (!i || !s || !o)
|
|
3483
3483
|
throw new Error("invalid connection string");
|
|
3484
3484
|
return { pubkey: i, relay: s, secret: o };
|
|
3485
3485
|
}
|
|
3486
|
-
async function
|
|
3486
|
+
async function Vc(e, t, n) {
|
|
3487
3487
|
const i = Fr(t, e, JSON.stringify({
|
|
3488
3488
|
method: "pay_invoice",
|
|
3489
3489
|
params: {
|
|
@@ -3497,31 +3497,31 @@ async function Wc(e, t, n) {
|
|
|
3497
3497
|
};
|
|
3498
3498
|
return Q(s, t);
|
|
3499
3499
|
}
|
|
3500
|
-
var
|
|
3501
|
-
H(
|
|
3502
|
-
normalizeIdentifier: () =>
|
|
3500
|
+
var Zc = {};
|
|
3501
|
+
H(Zc, {
|
|
3502
|
+
normalizeIdentifier: () => Fc
|
|
3503
3503
|
});
|
|
3504
|
-
function
|
|
3504
|
+
function Fc(e) {
|
|
3505
3505
|
return e = e.trim().toLowerCase(), e = e.normalize("NFKC"), Array.from(e).map((t) => new RegExp("\\p{Letter}", "u").test(t) || new RegExp("\\p{Number}", "u").test(t) ? t : "-").join("");
|
|
3506
3506
|
}
|
|
3507
|
-
var
|
|
3508
|
-
H(
|
|
3509
|
-
getSatoshisAmountFromBolt11: () =>
|
|
3510
|
-
getZapEndpoint: () =>
|
|
3511
|
-
makeZapReceipt: () =>
|
|
3512
|
-
makeZapRequest: () =>
|
|
3513
|
-
useFetchImplementation: () =>
|
|
3514
|
-
validateZapRequest: () =>
|
|
3507
|
+
var Gc = {};
|
|
3508
|
+
H(Gc, {
|
|
3509
|
+
getSatoshisAmountFromBolt11: () => tu,
|
|
3510
|
+
getZapEndpoint: () => Yc,
|
|
3511
|
+
makeZapReceipt: () => eu,
|
|
3512
|
+
makeZapRequest: () => Xc,
|
|
3513
|
+
useFetchImplementation: () => Jc,
|
|
3514
|
+
validateZapRequest: () => Qc
|
|
3515
3515
|
});
|
|
3516
3516
|
var Nn;
|
|
3517
3517
|
try {
|
|
3518
3518
|
Nn = fetch;
|
|
3519
3519
|
} catch {
|
|
3520
3520
|
}
|
|
3521
|
-
function
|
|
3521
|
+
function Jc(e) {
|
|
3522
3522
|
Nn = e;
|
|
3523
3523
|
}
|
|
3524
|
-
async function
|
|
3524
|
+
async function Yc(e) {
|
|
3525
3525
|
try {
|
|
3526
3526
|
let t = "", { lud06: n, lud16: r } = JSON.parse(e.content);
|
|
3527
3527
|
if (n) {
|
|
@@ -3539,7 +3539,7 @@ async function Jc(e) {
|
|
|
3539
3539
|
}
|
|
3540
3540
|
return null;
|
|
3541
3541
|
}
|
|
3542
|
-
function
|
|
3542
|
+
function Xc(e) {
|
|
3543
3543
|
let t = {
|
|
3544
3544
|
kind: 9734,
|
|
3545
3545
|
created_at: Math.round(Date.now() / 1e3),
|
|
@@ -3565,14 +3565,14 @@ function Yc(e) {
|
|
|
3565
3565
|
}
|
|
3566
3566
|
return t;
|
|
3567
3567
|
}
|
|
3568
|
-
function
|
|
3568
|
+
function Qc(e) {
|
|
3569
3569
|
let t;
|
|
3570
3570
|
try {
|
|
3571
3571
|
t = JSON.parse(e);
|
|
3572
3572
|
} catch {
|
|
3573
3573
|
return "Invalid zap request JSON.";
|
|
3574
3574
|
}
|
|
3575
|
-
if (!
|
|
3575
|
+
if (!yt(t))
|
|
3576
3576
|
return "Zap request is not a valid Nostr event.";
|
|
3577
3577
|
if (!gt(t))
|
|
3578
3578
|
return "Invalid signature on zap request.";
|
|
@@ -3584,7 +3584,7 @@ function Xc(e) {
|
|
|
3584
3584
|
let r = t.tags.find(([s, o]) => s === "e" && o);
|
|
3585
3585
|
return r && !r[1].match(/^[a-f0-9]{64}$/) ? "Zap request 'e' tag is not valid hex." : t.tags.find(([s, o]) => s === "relays" && o) ? null : "Zap request doesn't have a 'relays' tag.";
|
|
3586
3586
|
}
|
|
3587
|
-
function
|
|
3587
|
+
function eu({
|
|
3588
3588
|
zapRequest: e,
|
|
3589
3589
|
preimage: t,
|
|
3590
3590
|
bolt11: n,
|
|
@@ -3598,7 +3598,7 @@ function Qc({
|
|
|
3598
3598
|
};
|
|
3599
3599
|
return t && o.tags.push(["preimage", t]), o;
|
|
3600
3600
|
}
|
|
3601
|
-
function
|
|
3601
|
+
function tu(e) {
|
|
3602
3602
|
if (e.length < 50)
|
|
3603
3603
|
return 0;
|
|
3604
3604
|
e = e.substring(0, 50);
|
|
@@ -3629,9 +3629,9 @@ function eu(e) {
|
|
|
3629
3629
|
return a * 1e8;
|
|
3630
3630
|
}
|
|
3631
3631
|
}
|
|
3632
|
-
var
|
|
3633
|
-
H(
|
|
3634
|
-
getToken: () =>
|
|
3632
|
+
var nu = {};
|
|
3633
|
+
H(nu, {
|
|
3634
|
+
getToken: () => ru,
|
|
3635
3635
|
hashPayload: () => Sn,
|
|
3636
3636
|
unpackEventFromToken: () => gi,
|
|
3637
3637
|
validateEvent: () => xi,
|
|
@@ -3640,10 +3640,10 @@ H(tu, {
|
|
|
3640
3640
|
validateEventPayloadTag: () => Ei,
|
|
3641
3641
|
validateEventTimestamp: () => wi,
|
|
3642
3642
|
validateEventUrlTag: () => vi,
|
|
3643
|
-
validateToken: () =>
|
|
3643
|
+
validateToken: () => iu
|
|
3644
3644
|
});
|
|
3645
|
-
var
|
|
3646
|
-
async function
|
|
3645
|
+
var pi = "Nostr ";
|
|
3646
|
+
async function ru(e, t, n, r = !1, i) {
|
|
3647
3647
|
const s = {
|
|
3648
3648
|
kind: fn,
|
|
3649
3649
|
tags: [
|
|
@@ -3655,9 +3655,9 @@ async function nu(e, t, n, r = !1, i) {
|
|
|
3655
3655
|
};
|
|
3656
3656
|
i && s.tags.push(["payload", Sn(i)]);
|
|
3657
3657
|
const o = await n(s);
|
|
3658
|
-
return (r ?
|
|
3658
|
+
return (r ? pi : "") + he.encode(ne.encode(JSON.stringify(o)));
|
|
3659
3659
|
}
|
|
3660
|
-
async function
|
|
3660
|
+
async function iu(e, t, n) {
|
|
3661
3661
|
const r = await gi(e).catch((s) => {
|
|
3662
3662
|
throw s;
|
|
3663
3663
|
});
|
|
@@ -3668,7 +3668,7 @@ async function ru(e, t, n) {
|
|
|
3668
3668
|
async function gi(e) {
|
|
3669
3669
|
if (!e)
|
|
3670
3670
|
throw new Error("Missing token");
|
|
3671
|
-
e = e.replace(
|
|
3671
|
+
e = e.replace(pi, "");
|
|
3672
3672
|
const t = le.decode(he.decode(e));
|
|
3673
3673
|
if (!t || t.length === 0 || !t.startsWith("{"))
|
|
3674
3674
|
throw new Error("Invalid token");
|
|
@@ -3714,10 +3714,10 @@ async function xi(e, t, n, r) {
|
|
|
3714
3714
|
throw new Error("Invalid nostr event, payload tag does not match request body hash");
|
|
3715
3715
|
return !0;
|
|
3716
3716
|
}
|
|
3717
|
-
const Oe = 1060, Lt = 30078, Zn = 1059,
|
|
3718
|
-
function
|
|
3717
|
+
const Oe = 1060, Lt = 30078, Zn = 1059, su = 14, bu = 100, ou = 1;
|
|
3718
|
+
function vu(e) {
|
|
3719
3719
|
return JSON.stringify({
|
|
3720
|
-
version:
|
|
3720
|
+
version: ou,
|
|
3721
3721
|
rootKey: P(e.rootKey),
|
|
3722
3722
|
theirCurrentNostrPublicKey: e.theirCurrentNostrPublicKey,
|
|
3723
3723
|
theirNextNostrPublicKey: e.theirNextNostrPublicKey,
|
|
@@ -3750,7 +3750,7 @@ function bu(e) {
|
|
|
3750
3750
|
)
|
|
3751
3751
|
});
|
|
3752
3752
|
}
|
|
3753
|
-
function
|
|
3753
|
+
function mu(e) {
|
|
3754
3754
|
const t = JSON.parse(e);
|
|
3755
3755
|
if (!t.version) {
|
|
3756
3756
|
const n = {};
|
|
@@ -3813,7 +3813,38 @@ function vu(e) {
|
|
|
3813
3813
|
)
|
|
3814
3814
|
};
|
|
3815
3815
|
}
|
|
3816
|
-
|
|
3816
|
+
function au(e) {
|
|
3817
|
+
return {
|
|
3818
|
+
rootKey: new Uint8Array(e.rootKey),
|
|
3819
|
+
theirCurrentNostrPublicKey: e.theirCurrentNostrPublicKey,
|
|
3820
|
+
theirNextNostrPublicKey: e.theirNextNostrPublicKey,
|
|
3821
|
+
ourCurrentNostrKey: e.ourCurrentNostrKey ? {
|
|
3822
|
+
publicKey: e.ourCurrentNostrKey.publicKey,
|
|
3823
|
+
privateKey: new Uint8Array(e.ourCurrentNostrKey.privateKey)
|
|
3824
|
+
} : void 0,
|
|
3825
|
+
ourNextNostrKey: {
|
|
3826
|
+
publicKey: e.ourNextNostrKey.publicKey,
|
|
3827
|
+
privateKey: new Uint8Array(e.ourNextNostrKey.privateKey)
|
|
3828
|
+
},
|
|
3829
|
+
receivingChainKey: e.receivingChainKey ? new Uint8Array(e.receivingChainKey) : void 0,
|
|
3830
|
+
sendingChainKey: e.sendingChainKey ? new Uint8Array(e.sendingChainKey) : void 0,
|
|
3831
|
+
sendingChainMessageNumber: e.sendingChainMessageNumber,
|
|
3832
|
+
receivingChainMessageNumber: e.receivingChainMessageNumber,
|
|
3833
|
+
previousSendingChainMessageCount: e.previousSendingChainMessageCount,
|
|
3834
|
+
skippedKeys: Object.fromEntries(
|
|
3835
|
+
Object.entries(e.skippedKeys).map(([t, n]) => [
|
|
3836
|
+
t,
|
|
3837
|
+
{
|
|
3838
|
+
headerKeys: n.headerKeys.map((r) => new Uint8Array(r)),
|
|
3839
|
+
messageKeys: Object.fromEntries(
|
|
3840
|
+
Object.entries(n.messageKeys).map(([r, i]) => [r, new Uint8Array(i)])
|
|
3841
|
+
)
|
|
3842
|
+
}
|
|
3843
|
+
])
|
|
3844
|
+
)
|
|
3845
|
+
};
|
|
3846
|
+
}
|
|
3847
|
+
async function* Eu(e) {
|
|
3817
3848
|
const t = [];
|
|
3818
3849
|
let n = null;
|
|
3819
3850
|
const r = e.onEvent((i) => {
|
|
@@ -3831,18 +3862,18 @@ async function* mu(e) {
|
|
|
3831
3862
|
function Me(e, t = new Uint8Array(32), n = 1) {
|
|
3832
3863
|
const r = rn(fe, e, t), i = [];
|
|
3833
3864
|
for (let s = 1; s <= n; s++)
|
|
3834
|
-
i.push(
|
|
3865
|
+
i.push(Ur(fe, r, new Uint8Array([s]), 32));
|
|
3835
3866
|
return i;
|
|
3836
3867
|
}
|
|
3837
|
-
function
|
|
3868
|
+
function xu(e, t) {
|
|
3838
3869
|
return `${e}:${t}`;
|
|
3839
3870
|
}
|
|
3840
|
-
function
|
|
3871
|
+
function Ku(e) {
|
|
3841
3872
|
var n;
|
|
3842
3873
|
const t = (n = e.tags) == null ? void 0 : n.find((r) => r[0] === "ms");
|
|
3843
3874
|
return t ? parseInt(t[1]) : e.created_at * 1e3;
|
|
3844
3875
|
}
|
|
3845
|
-
const
|
|
3876
|
+
const cu = 1e3, uu = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
3846
3877
|
class ot {
|
|
3847
3878
|
// 1. CHANNEL PUBLIC INTERFACE
|
|
3848
3879
|
constructor(t, n) {
|
|
@@ -3867,7 +3898,7 @@ class ot {
|
|
|
3867
3898
|
static init(t, n, r, i, s, o) {
|
|
3868
3899
|
const c = Be();
|
|
3869
3900
|
let a, l, f, u;
|
|
3870
|
-
i ? ([a, l] = Me(s,
|
|
3901
|
+
i ? ([a, l] = Me(s, D.getConversationKey(c, n), 2), f = {
|
|
3871
3902
|
publicKey: ae(r),
|
|
3872
3903
|
privateKey: r
|
|
3873
3904
|
}, u = {
|
|
@@ -3877,7 +3908,7 @@ class ot {
|
|
|
3877
3908
|
publicKey: ae(r),
|
|
3878
3909
|
privateKey: r
|
|
3879
3910
|
});
|
|
3880
|
-
const
|
|
3911
|
+
const p = {
|
|
3881
3912
|
rootKey: a,
|
|
3882
3913
|
theirNextNostrPublicKey: n,
|
|
3883
3914
|
ourCurrentNostrKey: f,
|
|
@@ -3888,7 +3919,7 @@ class ot {
|
|
|
3888
3919
|
receivingChainMessageNumber: 0,
|
|
3889
3920
|
previousSendingChainMessageCount: 0,
|
|
3890
3921
|
skippedKeys: {}
|
|
3891
|
-
}, w = new ot(t,
|
|
3922
|
+
}, w = new ot(t, p);
|
|
3892
3923
|
return o && (w.name = o), w;
|
|
3893
3924
|
}
|
|
3894
3925
|
/**
|
|
@@ -3901,7 +3932,7 @@ class ot {
|
|
|
3901
3932
|
send(t) {
|
|
3902
3933
|
return this.sendEvent({
|
|
3903
3934
|
content: t,
|
|
3904
|
-
kind:
|
|
3935
|
+
kind: su
|
|
3905
3936
|
});
|
|
3906
3937
|
}
|
|
3907
3938
|
/**
|
|
@@ -3922,10 +3953,10 @@ class ot {
|
|
|
3922
3953
|
kind: t.kind || Oe,
|
|
3923
3954
|
created_at: t.created_at || Math.floor(n / 1e3),
|
|
3924
3955
|
tags: t.tags || [],
|
|
3925
|
-
pubkey: t.pubkey ||
|
|
3956
|
+
pubkey: t.pubkey || uu
|
|
3926
3957
|
};
|
|
3927
|
-
r.tags.some(([l]) => l === "ms") || r.tags.push(["ms", String(n)]), r.id =
|
|
3928
|
-
const [i, s] = this.ratchetEncrypt(JSON.stringify(r)), o =
|
|
3958
|
+
r.tags.some(([l]) => l === "ms") || r.tags.push(["ms", String(n)]), r.id = qe(r);
|
|
3959
|
+
const [i, s] = this.ratchetEncrypt(JSON.stringify(r)), o = D.getConversationKey(this.state.ourCurrentNostrKey.privateKey, this.state.theirNextNostrPublicKey), c = D.encrypt(JSON.stringify(i), o);
|
|
3929
3960
|
return { event: Q({
|
|
3930
3961
|
content: s,
|
|
3931
3962
|
kind: Oe,
|
|
@@ -3956,41 +3987,41 @@ class ot {
|
|
|
3956
3987
|
number: this.state.sendingChainMessageNumber++,
|
|
3957
3988
|
nextPublicKey: this.state.ourNextNostrKey.publicKey,
|
|
3958
3989
|
previousChainLength: this.state.previousSendingChainMessageCount
|
|
3959
|
-
},
|
|
3990
|
+
}, D.encrypt(t, r)];
|
|
3960
3991
|
}
|
|
3961
3992
|
ratchetDecrypt(t, n, r) {
|
|
3962
3993
|
const i = this.trySkippedMessageKeys(t, n, r);
|
|
3963
3994
|
if (i) return i;
|
|
3964
3995
|
this.skipMessageKeys(t.number, r);
|
|
3965
3996
|
const [s, o] = Me(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3966
|
-
return this.state.receivingChainKey = s, this.state.receivingChainMessageNumber++,
|
|
3997
|
+
return this.state.receivingChainKey = s, this.state.receivingChainMessageNumber++, D.decrypt(n, o);
|
|
3967
3998
|
}
|
|
3968
3999
|
ratchetStep() {
|
|
3969
4000
|
this.state.previousSendingChainMessageCount = this.state.sendingChainMessageNumber, this.state.sendingChainMessageNumber = 0, this.state.receivingChainMessageNumber = 0;
|
|
3970
|
-
const t =
|
|
4001
|
+
const t = D.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [n, r] = Me(this.state.rootKey, t, 2);
|
|
3971
4002
|
this.state.receivingChainKey = r, this.state.ourCurrentNostrKey = this.state.ourNextNostrKey;
|
|
3972
4003
|
const i = Be();
|
|
3973
4004
|
this.state.ourNextNostrKey = {
|
|
3974
4005
|
publicKey: ae(i),
|
|
3975
4006
|
privateKey: i
|
|
3976
4007
|
};
|
|
3977
|
-
const s =
|
|
4008
|
+
const s = D.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [o, c] = Me(n, s, 2);
|
|
3978
4009
|
this.state.rootKey = o, this.state.sendingChainKey = c;
|
|
3979
4010
|
}
|
|
3980
4011
|
// 3. MESSAGE KEY FUNCTIONS
|
|
3981
4012
|
skipMessageKeys(t, n) {
|
|
3982
4013
|
if (!(t <= this.state.receivingChainMessageNumber)) {
|
|
3983
|
-
if (t > this.state.receivingChainMessageNumber +
|
|
4014
|
+
if (t > this.state.receivingChainMessageNumber + cu)
|
|
3984
4015
|
throw new Error("Too many skipped messages");
|
|
3985
4016
|
if (!this.state.skippedKeys[n]) {
|
|
3986
4017
|
if (this.state.skippedKeys[n] = {
|
|
3987
4018
|
headerKeys: [],
|
|
3988
4019
|
messageKeys: {}
|
|
3989
4020
|
}, this.state.ourCurrentNostrKey) {
|
|
3990
|
-
const i =
|
|
4021
|
+
const i = D.getConversationKey(this.state.ourCurrentNostrKey.privateKey, n);
|
|
3991
4022
|
this.state.skippedKeys[n].headerKeys.includes(i) || this.state.skippedKeys[n].headerKeys.push(i);
|
|
3992
4023
|
}
|
|
3993
|
-
const r =
|
|
4024
|
+
const r = D.getConversationKey(this.state.ourNextNostrKey.privateKey, n);
|
|
3994
4025
|
this.state.skippedKeys[n].headerKeys.includes(r) || this.state.skippedKeys[n].headerKeys.push(r);
|
|
3995
4026
|
}
|
|
3996
4027
|
for (; this.state.receivingChainMessageNumber < t; ) {
|
|
@@ -4003,51 +4034,59 @@ class ot {
|
|
|
4003
4034
|
const i = this.state.skippedKeys[r];
|
|
4004
4035
|
if (!i) return null;
|
|
4005
4036
|
const s = i.messageKeys[t.number];
|
|
4006
|
-
return s ? (delete i.messageKeys[t.number], Object.keys(i.messageKeys).length === 0 && delete this.state.skippedKeys[r],
|
|
4037
|
+
return s ? (delete i.messageKeys[t.number], Object.keys(i.messageKeys).length === 0 && delete this.state.skippedKeys[r], D.decrypt(n, s)) : null;
|
|
4007
4038
|
}
|
|
4008
4039
|
// 4. NOSTR EVENT HANDLING
|
|
4009
4040
|
decryptHeader(t) {
|
|
4010
4041
|
const n = t.tags[0][1];
|
|
4011
4042
|
if (this.state.ourCurrentNostrKey) {
|
|
4012
|
-
const s =
|
|
4043
|
+
const s = D.getConversationKey(this.state.ourCurrentNostrKey.privateKey, t.pubkey);
|
|
4013
4044
|
try {
|
|
4014
|
-
return [JSON.parse(
|
|
4045
|
+
return [JSON.parse(D.decrypt(n, s)), !1, !1];
|
|
4015
4046
|
} catch {
|
|
4016
4047
|
}
|
|
4017
4048
|
}
|
|
4018
|
-
const r =
|
|
4049
|
+
const r = D.getConversationKey(this.state.ourNextNostrKey.privateKey, t.pubkey);
|
|
4019
4050
|
try {
|
|
4020
|
-
return [JSON.parse(
|
|
4051
|
+
return [JSON.parse(D.decrypt(n, r)), !0, !1];
|
|
4021
4052
|
} catch {
|
|
4022
4053
|
}
|
|
4023
4054
|
const i = this.state.skippedKeys[t.pubkey];
|
|
4024
4055
|
if (i != null && i.headerKeys)
|
|
4025
4056
|
for (const s of i.headerKeys)
|
|
4026
4057
|
try {
|
|
4027
|
-
return [JSON.parse(
|
|
4058
|
+
return [JSON.parse(D.decrypt(n, s)), !1, !0];
|
|
4028
4059
|
} catch {
|
|
4029
4060
|
}
|
|
4030
4061
|
throw new Error("Failed to decrypt header with current and skipped header keys");
|
|
4031
4062
|
}
|
|
4032
4063
|
handleNostrEvent(t) {
|
|
4033
|
-
var
|
|
4064
|
+
var i, s;
|
|
4065
|
+
const n = au(this.state);
|
|
4066
|
+
let r = !1;
|
|
4034
4067
|
try {
|
|
4035
|
-
const [
|
|
4036
|
-
if (!o)
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
(l) => this.handleNostrEvent(l)
|
|
4040
|
-
)), s && (this.skipMessageKeys(i.previousChainLength, t.pubkey), this.ratchetStep());
|
|
4041
|
-
else if (!((r = this.state.skippedKeys[t.pubkey]) != null && r.messageKeys[i.number]))
|
|
4068
|
+
const [o, c, a] = this.decryptHeader(t);
|
|
4069
|
+
if (!a && this.state.theirNextNostrPublicKey !== o.nextPublicKey && (this.state.theirCurrentNostrPublicKey = this.state.theirNextNostrPublicKey, this.state.theirNextNostrPublicKey = o.nextPublicKey, r = !0), !a)
|
|
4070
|
+
c && (this.skipMessageKeys(o.previousChainLength, t.pubkey), this.ratchetStep());
|
|
4071
|
+
else if (!((i = this.state.skippedKeys[t.pubkey]) != null && i.messageKeys[o.number]))
|
|
4042
4072
|
return;
|
|
4043
|
-
const
|
|
4044
|
-
if (!
|
|
4073
|
+
const l = this.ratchetDecrypt(o, t.content, t.pubkey), f = JSON.parse(l);
|
|
4074
|
+
if (!yt(f)) {
|
|
4075
|
+
this.state = n;
|
|
4045
4076
|
return;
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4077
|
+
}
|
|
4078
|
+
if (f.id !== qe(f)) {
|
|
4079
|
+
this.state = n;
|
|
4049
4080
|
return;
|
|
4050
|
-
|
|
4081
|
+
}
|
|
4082
|
+
r && ((s = this.nostrUnsubscribe) == null || s.call(this), this.nostrUnsubscribe = this.nostrNextUnsubscribe, this.nostrNextUnsubscribe = this.nostrSubscribe(
|
|
4083
|
+
{ authors: [this.state.theirNextNostrPublicKey], kinds: [Oe] },
|
|
4084
|
+
(u) => this.handleNostrEvent(u)
|
|
4085
|
+
)), this.internalSubscriptions.forEach((u) => u(f, t));
|
|
4086
|
+
} catch (o) {
|
|
4087
|
+
if (this.state = n, o instanceof Error && (o.message.includes("Failed to decrypt header") || o.message === "invalid MAC"))
|
|
4088
|
+
return;
|
|
4089
|
+
throw o;
|
|
4051
4090
|
}
|
|
4052
4091
|
}
|
|
4053
4092
|
subscribeToNostrEvents() {
|
|
@@ -4069,13 +4108,13 @@ class ot {
|
|
|
4069
4108
|
new TextDecoder("utf-8");
|
|
4070
4109
|
new TextEncoder();
|
|
4071
4110
|
function Qe(e, t) {
|
|
4072
|
-
const n =
|
|
4111
|
+
const n = Ue.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
4073
4112
|
return rn(fe, n, "nip44-v2");
|
|
4074
4113
|
}
|
|
4075
|
-
const
|
|
4114
|
+
const lu = 2 * 24 * 60 * 60, Ki = () => Math.round(Date.now() / 1e3), fu = () => Math.round(Ki() - Math.random() * lu);
|
|
4076
4115
|
class Pe {
|
|
4077
|
-
constructor(t, n, r, i, s, o, c = []) {
|
|
4078
|
-
this.inviterEphemeralPublicKey = t, this.sharedSecret = n, this.inviter = r, this.inviterEphemeralPrivateKey = i, this.deviceId = s, this.maxUses = o, this.usedBy = c;
|
|
4116
|
+
constructor(t, n, r, i, s, o, c = [], a = Ki()) {
|
|
4117
|
+
this.inviterEphemeralPublicKey = t, this.sharedSecret = n, this.inviter = r, this.inviterEphemeralPrivateKey = i, this.deviceId = s, this.maxUses = o, this.usedBy = c, this.createdAt = a;
|
|
4079
4118
|
}
|
|
4080
4119
|
static createNew(t, n, r) {
|
|
4081
4120
|
if (!t)
|
|
@@ -4119,7 +4158,8 @@ class Pe {
|
|
|
4119
4158
|
n.inviterEphemeralPrivateKey ? new Uint8Array(n.inviterEphemeralPrivateKey) : void 0,
|
|
4120
4159
|
n.deviceId,
|
|
4121
4160
|
n.maxUses,
|
|
4122
|
-
n.usedBy
|
|
4161
|
+
n.usedBy,
|
|
4162
|
+
n.createdAt
|
|
4123
4163
|
);
|
|
4124
4164
|
}
|
|
4125
4165
|
static fromEvent(t) {
|
|
@@ -4131,7 +4171,7 @@ class Pe {
|
|
|
4131
4171
|
const { tags: n } = t;
|
|
4132
4172
|
if (!n)
|
|
4133
4173
|
throw new Error("Invalid invite event: missing tags");
|
|
4134
|
-
const r = (a = n.find(([
|
|
4174
|
+
const r = (a = n.find(([p]) => p === "ephemeralKey")) == null ? void 0 : a[1], i = (l = n.find(([p]) => p === "sharedSecret")) == null ? void 0 : l[1], s = t.pubkey, o = (f = n.find(([p]) => p === "d")) == null ? void 0 : f[1], c = (u = o == null ? void 0 : o.split("/")) == null ? void 0 : u[2];
|
|
4135
4175
|
if (!r || !i)
|
|
4136
4176
|
throw new Error("Invalid invite event: missing session key or sharedSecret");
|
|
4137
4177
|
return new Pe(
|
|
@@ -4175,7 +4215,8 @@ class Pe {
|
|
|
4175
4215
|
inviterEphemeralPrivateKey: this.inviterEphemeralPrivateKey ? Array.from(this.inviterEphemeralPrivateKey) : void 0,
|
|
4176
4216
|
deviceId: this.deviceId,
|
|
4177
4217
|
maxUses: this.maxUses,
|
|
4178
|
-
usedBy: this.usedBy
|
|
4218
|
+
usedBy: this.usedBy,
|
|
4219
|
+
createdAt: this.createdAt
|
|
4179
4220
|
});
|
|
4180
4221
|
}
|
|
4181
4222
|
/**
|
|
@@ -4196,7 +4237,7 @@ class Pe {
|
|
|
4196
4237
|
kind: Lt,
|
|
4197
4238
|
pubkey: this.inviter,
|
|
4198
4239
|
content: "",
|
|
4199
|
-
created_at:
|
|
4240
|
+
created_at: this.createdAt,
|
|
4200
4241
|
tags: [
|
|
4201
4242
|
["ephemeralKey", this.inviterEphemeralPublicKey],
|
|
4202
4243
|
["sharedSecret", this.sharedSecret],
|
|
@@ -4244,21 +4285,21 @@ class Pe {
|
|
|
4244
4285
|
* so the inviter can create the session on their side.
|
|
4245
4286
|
*/
|
|
4246
4287
|
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(
|
|
4288
|
+
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(D.encrypt(m, Qe(r, S))), u = JSON.stringify({
|
|
4248
4289
|
sessionKey: o,
|
|
4249
4290
|
deviceId: i
|
|
4250
|
-
}),
|
|
4291
|
+
}), p = await f(u, c), w = {
|
|
4251
4292
|
pubkey: n,
|
|
4252
|
-
content: await
|
|
4293
|
+
content: await D.encrypt(p, a),
|
|
4253
4294
|
created_at: Math.floor(Date.now() / 1e3)
|
|
4254
|
-
}, g = JSON.stringify(w), h = Be(), d = ae(h),
|
|
4295
|
+
}, g = JSON.stringify(w), h = Be(), d = ae(h), y = {
|
|
4255
4296
|
kind: Zn,
|
|
4256
4297
|
pubkey: d,
|
|
4257
|
-
content:
|
|
4258
|
-
created_at:
|
|
4298
|
+
content: D.encrypt(g, Qe(h, this.inviterEphemeralPublicKey)),
|
|
4299
|
+
created_at: fu(),
|
|
4259
4300
|
tags: [["p", this.inviterEphemeralPublicKey]]
|
|
4260
4301
|
};
|
|
4261
|
-
return { session: l, event: Q(
|
|
4302
|
+
return { session: l, event: Q(y, h) };
|
|
4262
4303
|
}
|
|
4263
4304
|
listen(t, n, r) {
|
|
4264
4305
|
if (!this.inviterEphemeralPrivateKey)
|
|
@@ -4271,15 +4312,15 @@ class Pe {
|
|
|
4271
4312
|
try {
|
|
4272
4313
|
if (this.maxUses && this.usedBy.length >= this.maxUses)
|
|
4273
4314
|
return;
|
|
4274
|
-
const o = await
|
|
4315
|
+
const o = await D.decrypt(s.content, Qe(this.inviterEphemeralPrivateKey, s.pubkey)), c = JSON.parse(o), a = j(this.sharedSecret), l = c.pubkey;
|
|
4275
4316
|
this.usedBy.push(l);
|
|
4276
|
-
const f = await
|
|
4317
|
+
const f = await D.decrypt(c.content, a), p = await (typeof t == "function" ? t : (y, m) => Promise.resolve(D.decrypt(y, Qe(t, m))))(f, l);
|
|
4277
4318
|
let w, g;
|
|
4278
4319
|
try {
|
|
4279
|
-
const
|
|
4280
|
-
w =
|
|
4320
|
+
const y = JSON.parse(p);
|
|
4321
|
+
w = y.sessionKey, g = y.deviceId;
|
|
4281
4322
|
} catch {
|
|
4282
|
-
w =
|
|
4323
|
+
w = p;
|
|
4283
4324
|
}
|
|
4284
4325
|
const h = s.id, d = ot.init(n, w, this.inviterEphemeralPrivateKey, !1, a, h);
|
|
4285
4326
|
r(d, l, g);
|
|
@@ -4289,17 +4330,18 @@ class Pe {
|
|
|
4289
4330
|
}
|
|
4290
4331
|
}
|
|
4291
4332
|
export {
|
|
4292
|
-
|
|
4333
|
+
su as CHAT_MESSAGE_KIND,
|
|
4293
4334
|
Lt as INVITE_EVENT_KIND,
|
|
4294
4335
|
Zn as INVITE_RESPONSE_KIND,
|
|
4295
4336
|
Pe as Invite,
|
|
4296
|
-
|
|
4337
|
+
bu as MAX_SKIP,
|
|
4297
4338
|
Oe as MESSAGE_EVENT_KIND,
|
|
4298
4339
|
ot as Session,
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4340
|
+
Eu as createEventStream,
|
|
4341
|
+
au as deepCopyState,
|
|
4342
|
+
mu as deserializeSessionState,
|
|
4343
|
+
Ku as getMillisecondTimestamp,
|
|
4302
4344
|
Me as kdf,
|
|
4303
|
-
|
|
4304
|
-
|
|
4345
|
+
vu as serializeSessionState,
|
|
4346
|
+
xu as skippedMessageIndexKey
|
|
4305
4347
|
};
|