nostr-double-ratchet 0.0.27 → 0.0.28
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 +3 -3
- package/dist/Invite.d.ts.map +1 -1
- package/dist/Session.d.ts +1 -1
- package/dist/Session.d.ts.map +1 -1
- package/dist/SessionManager.d.ts +23 -0
- package/dist/SessionManager.d.ts.map +1 -0
- package/dist/UserRecord.d.ts +30 -3
- package/dist/UserRecord.d.ts.map +1 -1
- package/dist/nostr-double-ratchet.es.js +1275 -1184
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/dist/types.d.ts +5 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +19 -17
- package/src/Invite.ts +14 -14
- package/src/Session.ts +9 -21
- package/src/SessionManager.ts +165 -0
- package/src/UserRecord.ts +64 -6
- package/src/types.ts +5 -5
- package/src/utils.ts +12 -12
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var J = (e, t, n) =>
|
|
4
|
-
function
|
|
1
|
+
var Ki = Object.defineProperty;
|
|
2
|
+
var Ni = (e, t, n) => t in e ? Ki(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var J = (e, t, n) => Ni(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
function Bn(e) {
|
|
5
5
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
6
6
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function Gn(e, ...t) {
|
|
9
9
|
if (!(e instanceof Uint8Array))
|
|
10
10
|
throw new Error("Expected Uint8Array");
|
|
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 Si(e) {
|
|
15
15
|
if (typeof e != "function" || typeof e.create != "function")
|
|
16
16
|
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
17
|
-
|
|
17
|
+
Bn(e.outputLen), Bn(e.blockLen);
|
|
18
18
|
}
|
|
19
19
|
function et(e, t = !0) {
|
|
20
20
|
if (e.destroyed)
|
|
@@ -22,70 +22,70 @@ 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
|
|
26
|
-
|
|
25
|
+
function Ai(e, t) {
|
|
26
|
+
Gn(e);
|
|
27
27
|
const n = t.outputLen;
|
|
28
28
|
if (e.length < n)
|
|
29
29
|
throw new Error(`digestInto() expects output buffer of length at least ${n}`);
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const Kt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
32
32
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
33
|
+
const Fn = (e) => e instanceof Uint8Array, Nt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), re = (e, t) => e << 32 - t | e >>> t, Ci = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
34
|
+
if (!Ci)
|
|
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
|
-
function
|
|
42
|
-
if (typeof e == "string" && (e =
|
|
41
|
+
function Vt(e) {
|
|
42
|
+
if (typeof e == "string" && (e = Bi(e)), !Fn(e))
|
|
43
43
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
44
44
|
return e;
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function ki(...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) => {
|
|
50
|
-
if (!
|
|
50
|
+
if (!Fn(r))
|
|
51
51
|
throw new Error("Uint8Array expected");
|
|
52
52
|
t.set(r, n), n += r.length;
|
|
53
53
|
}), t;
|
|
54
54
|
}
|
|
55
|
-
let
|
|
55
|
+
let Jn = class {
|
|
56
56
|
// Safe version that clones internal state
|
|
57
57
|
clone() {
|
|
58
58
|
return this._cloneInto();
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
-
function
|
|
62
|
-
const t = (r) => e().update(
|
|
61
|
+
function _i(e) {
|
|
62
|
+
const t = (r) => e().update(Vt(r)).digest(), n = e();
|
|
63
63
|
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
64
64
|
}
|
|
65
|
-
function
|
|
66
|
-
if (
|
|
67
|
-
return
|
|
65
|
+
function Yn(e = 32) {
|
|
66
|
+
if (Kt && typeof Kt.getRandomValues == "function")
|
|
67
|
+
return Kt.getRandomValues(new Uint8Array(e));
|
|
68
68
|
throw new Error("crypto.getRandomValues must be defined");
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function Ii(e, t, n, r) {
|
|
71
71
|
if (typeof e.setBigUint64 == "function")
|
|
72
72
|
return e.setBigUint64(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 Ui = class extends Jn {
|
|
77
77
|
constructor(t, n, r, i) {
|
|
78
|
-
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view =
|
|
78
|
+
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view = Nt(this.buffer);
|
|
79
79
|
}
|
|
80
80
|
update(t) {
|
|
81
81
|
et(this);
|
|
82
82
|
const { view: n, buffer: r, blockLen: i } = this;
|
|
83
|
-
t =
|
|
83
|
+
t = Vt(t);
|
|
84
84
|
const s = t.length;
|
|
85
85
|
for (let o = 0; o < s; ) {
|
|
86
86
|
const c = Math.min(i - this.pos, s - o);
|
|
87
87
|
if (c === i) {
|
|
88
|
-
const a =
|
|
88
|
+
const a = Nt(t);
|
|
89
89
|
for (; i <= s - o; o += i)
|
|
90
90
|
this.process(a, o);
|
|
91
91
|
continue;
|
|
@@ -95,14 +95,14 @@ let Ci = class extends Wn {
|
|
|
95
95
|
return this.length += t.length, this.roundClean(), this;
|
|
96
96
|
}
|
|
97
97
|
digestInto(t) {
|
|
98
|
-
et(this),
|
|
98
|
+
et(this), Ai(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);
|
|
102
102
|
for (let u = o; u < i; u++)
|
|
103
103
|
n[u] = 0;
|
|
104
|
-
|
|
105
|
-
const c =
|
|
104
|
+
Ii(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
105
|
+
const c = Nt(t), a = this.outputLen;
|
|
106
106
|
if (a % 4)
|
|
107
107
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
108
108
|
const l = a / 4, f = this.get();
|
|
@@ -123,7 +123,7 @@ let Ci = class extends Wn {
|
|
|
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 Li = (e, t, n) => e & t ^ ~e & n, $i = (e, t, n) => e & t ^ e & n ^ t & n, Ri = /* @__PURE__ */ new Uint32Array([
|
|
127
127
|
1116352408,
|
|
128
128
|
1899447441,
|
|
129
129
|
3049323471,
|
|
@@ -198,7 +198,7 @@ const Bi = (e, t, n) => e & t ^ ~e & n, ki = (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 Ti = class extends Ui {
|
|
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 Ii = class extends Ci {
|
|
|
214
214
|
for (let u = 0; u < 16; u++, n += 4)
|
|
215
215
|
ve[u] = t.getUint32(n, !1);
|
|
216
216
|
for (let u = 16; u < 64; u++) {
|
|
217
|
-
const g = ve[u - 15], w = ve[u - 2],
|
|
218
|
-
ve[u] = h + ve[u - 7] +
|
|
217
|
+
const g = ve[u - 15], w = ve[u - 2], y = re(g, 7) ^ re(g, 18) ^ g >>> 3, h = re(w, 17) ^ re(w, 19) ^ w >>> 10;
|
|
218
|
+
ve[u] = h + ve[u - 7] + y + ve[u - 16] | 0;
|
|
219
219
|
}
|
|
220
220
|
let { A: r, B: i, C: s, D: o, E: c, F: a, G: l, H: f } = this;
|
|
221
221
|
for (let u = 0; u < 64; u++) {
|
|
222
|
-
const g = re(c, 6) ^ re(c, 11) ^ re(c, 25), w = f + g +
|
|
222
|
+
const g = re(c, 6) ^ re(c, 11) ^ re(c, 25), w = f + g + Li(c, a, l) + Ri[u] + ve[u] | 0, h = (re(r, 2) ^ re(r, 13) ^ re(r, 22)) + $i(r, i, s) | 0;
|
|
223
223
|
f = l, l = a, a = c, c = o + w | 0, o = s, s = i, i = r, r = w + h | 0;
|
|
224
224
|
}
|
|
225
225
|
r = r + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, l = l + this.G | 0, f = f + this.H | 0, this.set(r, i, s, o, c, a, l, f);
|
|
@@ -231,18 +231,18 @@ let Ii = class extends Ci {
|
|
|
231
231
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
|
|
232
232
|
}
|
|
233
233
|
};
|
|
234
|
-
const
|
|
234
|
+
const $t = /* @__PURE__ */ _i(() => new Ti());
|
|
235
235
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
236
|
-
const
|
|
236
|
+
const Xn = BigInt(0), at = BigInt(1), Oi = BigInt(2), ct = (e) => e instanceof Uint8Array, Mi = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
237
237
|
function De(e) {
|
|
238
|
-
if (!
|
|
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 += Mi[e[n]];
|
|
243
243
|
return t;
|
|
244
244
|
}
|
|
245
|
-
function
|
|
245
|
+
function Qn(e) {
|
|
246
246
|
const t = e.toString(16);
|
|
247
247
|
return t.length & 1 ? `0${t}` : t;
|
|
248
248
|
}
|
|
@@ -270,7 +270,7 @@ function F(e) {
|
|
|
270
270
|
return Zt(De(e));
|
|
271
271
|
}
|
|
272
272
|
function Gt(e) {
|
|
273
|
-
if (!
|
|
273
|
+
if (!ct(e))
|
|
274
274
|
throw new Error("Uint8Array expected");
|
|
275
275
|
return Zt(De(Uint8Array.from(e).reverse()));
|
|
276
276
|
}
|
|
@@ -280,8 +280,8 @@ function Ne(e, t) {
|
|
|
280
280
|
function Ft(e, t) {
|
|
281
281
|
return Ne(e, t).reverse();
|
|
282
282
|
}
|
|
283
|
-
function
|
|
284
|
-
return je(
|
|
283
|
+
function Pi(e) {
|
|
284
|
+
return je(Qn(e));
|
|
285
285
|
}
|
|
286
286
|
function Z(e, t, n) {
|
|
287
287
|
let r;
|
|
@@ -291,7 +291,7 @@ function Z(e, t, n) {
|
|
|
291
291
|
} catch (s) {
|
|
292
292
|
throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${s}`);
|
|
293
293
|
}
|
|
294
|
-
else if (
|
|
294
|
+
else if (ct(t))
|
|
295
295
|
r = Uint8Array.from(t);
|
|
296
296
|
else
|
|
297
297
|
throw new Error(`${e} must be hex string or Uint8Array`);
|
|
@@ -304,12 +304,12 @@ function _e(...e) {
|
|
|
304
304
|
const t = new Uint8Array(e.reduce((r, i) => r + i.length, 0));
|
|
305
305
|
let n = 0;
|
|
306
306
|
return e.forEach((r) => {
|
|
307
|
-
if (!
|
|
307
|
+
if (!ct(r))
|
|
308
308
|
throw new Error("Uint8Array expected");
|
|
309
309
|
t.set(r, n), n += r.length;
|
|
310
310
|
}), t;
|
|
311
311
|
}
|
|
312
|
-
function
|
|
312
|
+
function Hi(e, t) {
|
|
313
313
|
if (e.length !== t.length)
|
|
314
314
|
return !1;
|
|
315
315
|
for (let n = 0; n < e.length; n++)
|
|
@@ -317,33 +317,33 @@ function Ti(e, t) {
|
|
|
317
317
|
return !1;
|
|
318
318
|
return !0;
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function qi(e) {
|
|
321
321
|
if (typeof e != "string")
|
|
322
322
|
throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
|
|
323
323
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
324
324
|
}
|
|
325
|
-
function
|
|
325
|
+
function Di(e) {
|
|
326
326
|
let t;
|
|
327
|
-
for (t = 0; e >
|
|
327
|
+
for (t = 0; e > Xn; e >>= at, t += 1)
|
|
328
328
|
;
|
|
329
329
|
return t;
|
|
330
330
|
}
|
|
331
|
-
function
|
|
332
|
-
return e >> BigInt(t) &
|
|
331
|
+
function ji(e, t) {
|
|
332
|
+
return e >> BigInt(t) & at;
|
|
333
333
|
}
|
|
334
|
-
const
|
|
335
|
-
function
|
|
334
|
+
const zi = (e, t, n) => e | (n ? at : Xn) << BigInt(t), Jt = (e) => (Oi << BigInt(e - 1)) - at, St = (e) => new Uint8Array(e), kn = (e) => Uint8Array.from(e);
|
|
335
|
+
function er(e, t, n) {
|
|
336
336
|
if (typeof e != "number" || e < 2)
|
|
337
337
|
throw new Error("hashLen must be a number");
|
|
338
338
|
if (typeof t != "number" || t < 2)
|
|
339
339
|
throw new Error("qByteLen must be a number");
|
|
340
340
|
if (typeof n != "function")
|
|
341
341
|
throw new Error("hmacFn must be a function");
|
|
342
|
-
let r =
|
|
342
|
+
let r = St(e), i = St(e), s = 0;
|
|
343
343
|
const o = () => {
|
|
344
344
|
r.fill(1), i.fill(0), s = 0;
|
|
345
|
-
}, c = (...u) => n(i, r, ...u), a = (u =
|
|
346
|
-
i = c(
|
|
345
|
+
}, c = (...u) => n(i, r, ...u), a = (u = St()) => {
|
|
346
|
+
i = c(kn([0]), u), r = c(), u.length !== 0 && (i = c(kn([1]), u), r = c());
|
|
347
347
|
}, l = () => {
|
|
348
348
|
if (s++ >= 1e3)
|
|
349
349
|
throw new Error("drbg: tried 1000 values");
|
|
@@ -364,7 +364,7 @@ function Jn(e, t, n) {
|
|
|
364
364
|
return o(), w;
|
|
365
365
|
};
|
|
366
366
|
}
|
|
367
|
-
const
|
|
367
|
+
const Wi = {
|
|
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 Hi = {
|
|
|
377
377
|
};
|
|
378
378
|
function Ye(e, t, n = {}) {
|
|
379
379
|
const r = (i, s, o) => {
|
|
380
|
-
const c =
|
|
380
|
+
const c = Wi[s];
|
|
381
381
|
if (typeof c != "function")
|
|
382
382
|
throw new Error(`Invalid validator "${s}", expected function`);
|
|
383
383
|
const a = e[i];
|
|
@@ -390,73 +390,73 @@ function Ye(e, t, n = {}) {
|
|
|
390
390
|
r(i, s, !0);
|
|
391
391
|
return e;
|
|
392
392
|
}
|
|
393
|
-
const
|
|
393
|
+
const Vi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
394
394
|
__proto__: null,
|
|
395
|
-
bitGet:
|
|
396
|
-
bitLen:
|
|
395
|
+
bitGet: ji,
|
|
396
|
+
bitLen: Di,
|
|
397
397
|
bitMask: Jt,
|
|
398
|
-
bitSet:
|
|
398
|
+
bitSet: zi,
|
|
399
399
|
bytesToHex: De,
|
|
400
400
|
bytesToNumberBE: F,
|
|
401
401
|
bytesToNumberLE: Gt,
|
|
402
402
|
concatBytes: _e,
|
|
403
|
-
createHmacDrbg:
|
|
403
|
+
createHmacDrbg: er,
|
|
404
404
|
ensureBytes: Z,
|
|
405
|
-
equalBytes:
|
|
405
|
+
equalBytes: Hi,
|
|
406
406
|
hexToBytes: je,
|
|
407
407
|
hexToNumber: Zt,
|
|
408
408
|
numberToBytesBE: Ne,
|
|
409
409
|
numberToBytesLE: Ft,
|
|
410
|
-
numberToHexUnpadded:
|
|
411
|
-
numberToVarBytesBE:
|
|
412
|
-
utf8ToBytes:
|
|
410
|
+
numberToHexUnpadded: Qn,
|
|
411
|
+
numberToVarBytesBE: Pi,
|
|
412
|
+
utf8ToBytes: qi,
|
|
413
413
|
validateObject: Ye
|
|
414
414
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
415
415
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
416
|
-
const
|
|
416
|
+
const W = BigInt(0), j = BigInt(1), Ce = BigInt(2), Zi = BigInt(3), Rt = BigInt(4), _n = BigInt(5), In = BigInt(8);
|
|
417
417
|
BigInt(9);
|
|
418
418
|
BigInt(16);
|
|
419
|
-
function
|
|
419
|
+
function V(e, t) {
|
|
420
420
|
const n = e % t;
|
|
421
|
-
return n >=
|
|
421
|
+
return n >= W ? n : t + n;
|
|
422
422
|
}
|
|
423
|
-
function
|
|
424
|
-
if (n <=
|
|
423
|
+
function Gi(e, t, n) {
|
|
424
|
+
if (n <= W || t < W)
|
|
425
425
|
throw new Error("Expected power/modulo > 0");
|
|
426
426
|
if (n === j)
|
|
427
|
-
return
|
|
427
|
+
return W;
|
|
428
428
|
let r = j;
|
|
429
|
-
for (; t >
|
|
429
|
+
for (; t > W; )
|
|
430
430
|
t & j && (r = r * e % n), e = e * e % n, t >>= j;
|
|
431
431
|
return r;
|
|
432
432
|
}
|
|
433
433
|
function Y(e, t, n) {
|
|
434
434
|
let r = e;
|
|
435
|
-
for (; t-- >
|
|
435
|
+
for (; t-- > W; )
|
|
436
436
|
r *= r, r %= n;
|
|
437
437
|
return r;
|
|
438
438
|
}
|
|
439
439
|
function Tt(e, t) {
|
|
440
|
-
if (e ===
|
|
440
|
+
if (e === W || t <= W)
|
|
441
441
|
throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);
|
|
442
|
-
let n =
|
|
443
|
-
for (; n !==
|
|
442
|
+
let n = V(e, t), r = t, i = W, s = j;
|
|
443
|
+
for (; n !== W; ) {
|
|
444
444
|
const c = r / n, a = r % n, l = i - s * c;
|
|
445
445
|
r = n, n = a, i = s, s = l;
|
|
446
446
|
}
|
|
447
447
|
if (r !== j)
|
|
448
448
|
throw new Error("invert: does not exist");
|
|
449
|
-
return
|
|
449
|
+
return V(i, t);
|
|
450
450
|
}
|
|
451
|
-
function
|
|
451
|
+
function Fi(e) {
|
|
452
452
|
const t = (e - j) / Ce;
|
|
453
453
|
let n, r, i;
|
|
454
|
-
for (n = e - j, r = 0; n % Ce ===
|
|
454
|
+
for (n = e - j, 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 - j; i++)
|
|
457
457
|
;
|
|
458
458
|
if (r === 1) {
|
|
459
|
-
const o = (e + j) /
|
|
459
|
+
const o = (e + j) / Rt;
|
|
460
460
|
return function(a, l) {
|
|
461
461
|
const f = a.pow(l, o);
|
|
462
462
|
if (!a.eql(a.sqr(f), l))
|
|
@@ -475,15 +475,15 @@ function zi(e) {
|
|
|
475
475
|
let w = 1;
|
|
476
476
|
for (let h = c.sqr(g); w < l && !c.eql(h, c.ONE); w++)
|
|
477
477
|
h = c.sqr(h);
|
|
478
|
-
const
|
|
479
|
-
f = c.sqr(
|
|
478
|
+
const y = c.pow(f, j << BigInt(l - w - 1));
|
|
479
|
+
f = c.sqr(y), u = c.mul(u, y), g = c.mul(g, f), l = w;
|
|
480
480
|
}
|
|
481
481
|
return u;
|
|
482
482
|
};
|
|
483
483
|
}
|
|
484
|
-
function
|
|
485
|
-
if (e %
|
|
486
|
-
const t = (e + j) /
|
|
484
|
+
function Ji(e) {
|
|
485
|
+
if (e % Rt === Zi) {
|
|
486
|
+
const t = (e + j) / Rt;
|
|
487
487
|
return function(r, i) {
|
|
488
488
|
const s = r.pow(i, t);
|
|
489
489
|
if (!r.eql(r.sqr(s), i))
|
|
@@ -491,8 +491,8 @@ function Vi(e) {
|
|
|
491
491
|
return s;
|
|
492
492
|
};
|
|
493
493
|
}
|
|
494
|
-
if (e %
|
|
495
|
-
const t = (e -
|
|
494
|
+
if (e % In === _n) {
|
|
495
|
+
const t = (e - _n) / In;
|
|
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 Vi(e) {
|
|
|
500
500
|
return l;
|
|
501
501
|
};
|
|
502
502
|
}
|
|
503
|
-
return
|
|
503
|
+
return Fi(e);
|
|
504
504
|
}
|
|
505
|
-
const
|
|
505
|
+
const Yi = [
|
|
506
506
|
"create",
|
|
507
507
|
"isValid",
|
|
508
508
|
"is0",
|
|
@@ -521,64 +521,64 @@ const Wi = [
|
|
|
521
521
|
"mulN",
|
|
522
522
|
"sqrN"
|
|
523
523
|
];
|
|
524
|
-
function
|
|
524
|
+
function Xi(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 = Yi.reduce((r, i) => (r[i] = "function", r), t);
|
|
531
531
|
return Ye(e, n);
|
|
532
532
|
}
|
|
533
|
-
function
|
|
534
|
-
if (n <
|
|
533
|
+
function Qi(e, t, n) {
|
|
534
|
+
if (n < W)
|
|
535
535
|
throw new Error("Expected power > 0");
|
|
536
|
-
if (n ===
|
|
536
|
+
if (n === W)
|
|
537
537
|
return e.ONE;
|
|
538
538
|
if (n === j)
|
|
539
539
|
return t;
|
|
540
540
|
let r = e.ONE, i = t;
|
|
541
|
-
for (; n >
|
|
541
|
+
for (; n > W; )
|
|
542
542
|
n & j && (r = e.mul(r, i)), i = e.sqr(i), n >>= j;
|
|
543
543
|
return r;
|
|
544
544
|
}
|
|
545
|
-
function
|
|
545
|
+
function es(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
|
}
|
|
549
|
-
function
|
|
549
|
+
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
|
|
554
|
-
if (e <=
|
|
553
|
+
function ts(e, t, n = !1, r = {}) {
|
|
554
|
+
if (e <= W)
|
|
555
555
|
throw new Error(`Expected Field ORDER > 0, got ${e}`);
|
|
556
|
-
const { nBitLength: i, nByteLength: s } =
|
|
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 = Ji(e), c = Object.freeze({
|
|
560
560
|
ORDER: e,
|
|
561
561
|
BITS: i,
|
|
562
562
|
BYTES: s,
|
|
563
563
|
MASK: Jt(i),
|
|
564
|
-
ZERO:
|
|
564
|
+
ZERO: W,
|
|
565
565
|
ONE: j,
|
|
566
|
-
create: (a) =>
|
|
566
|
+
create: (a) => V(a, e),
|
|
567
567
|
isValid: (a) => {
|
|
568
568
|
if (typeof a != "bigint")
|
|
569
569
|
throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);
|
|
570
|
-
return
|
|
570
|
+
return W <= a && a < e;
|
|
571
571
|
},
|
|
572
|
-
is0: (a) => a ===
|
|
572
|
+
is0: (a) => a === W,
|
|
573
573
|
isOdd: (a) => (a & j) === j,
|
|
574
|
-
neg: (a) =>
|
|
574
|
+
neg: (a) => V(-a, e),
|
|
575
575
|
eql: (a, l) => a === l,
|
|
576
|
-
sqr: (a) =>
|
|
577
|
-
add: (a, l) =>
|
|
578
|
-
sub: (a, l) =>
|
|
579
|
-
mul: (a, l) =>
|
|
580
|
-
pow: (a, l) =>
|
|
581
|
-
div: (a, l) =>
|
|
576
|
+
sqr: (a) => V(a * a, e),
|
|
577
|
+
add: (a, l) => V(a + l, e),
|
|
578
|
+
sub: (a, l) => V(a - l, e),
|
|
579
|
+
mul: (a, l) => V(a * l, e),
|
|
580
|
+
pow: (a, l) => Qi(c, a, l),
|
|
581
|
+
div: (a, l) => V(a * Tt(l, e), e),
|
|
582
582
|
// Same as above, but doesn't normalize
|
|
583
583
|
sqrN: (a) => a * a,
|
|
584
584
|
addN: (a, l) => a + l,
|
|
@@ -586,7 +586,7 @@ function Ji(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) => es(c, a),
|
|
590
590
|
// TODO: do we really need constant cmov?
|
|
591
591
|
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
592
592
|
cmov: (a, l, f) => f ? l : a,
|
|
@@ -599,26 +599,26 @@ function Ji(e, t, n = !1, r = {}) {
|
|
|
599
599
|
});
|
|
600
600
|
return Object.freeze(c);
|
|
601
601
|
}
|
|
602
|
-
function
|
|
602
|
+
function nr(e) {
|
|
603
603
|
if (typeof e != "bigint")
|
|
604
604
|
throw new Error("field order must be bigint");
|
|
605
605
|
const t = e.toString(2).length;
|
|
606
606
|
return Math.ceil(t / 8);
|
|
607
607
|
}
|
|
608
|
-
function
|
|
609
|
-
const t =
|
|
608
|
+
function rr(e) {
|
|
609
|
+
const t = nr(e);
|
|
610
610
|
return t + Math.ceil(t / 2);
|
|
611
611
|
}
|
|
612
|
-
function
|
|
613
|
-
const r = e.length, i =
|
|
612
|
+
function ns(e, t, n = !1) {
|
|
613
|
+
const r = e.length, i = nr(t), s = rr(t);
|
|
614
614
|
if (r < 16 || r < s || r > 1024)
|
|
615
615
|
throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);
|
|
616
|
-
const o = n ? F(e) : Gt(e), c =
|
|
616
|
+
const o = n ? F(e) : Gt(e), c = V(o, t - j) + j;
|
|
617
617
|
return n ? Ft(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 rs = BigInt(0), At = BigInt(1);
|
|
621
|
+
function is(e, t) {
|
|
622
622
|
const n = (i, s) => {
|
|
623
623
|
const o = s.negate();
|
|
624
624
|
return i ? o : s;
|
|
@@ -631,8 +631,8 @@ function Qi(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 >
|
|
635
|
-
s &
|
|
634
|
+
for (; s > rs; )
|
|
635
|
+
s & At && (o = o.add(c)), c = c.double(), s >>= At;
|
|
636
636
|
return o;
|
|
637
637
|
},
|
|
638
638
|
/**
|
|
@@ -667,12 +667,12 @@ function Qi(e, t) {
|
|
|
667
667
|
const { windows: c, windowSize: a } = r(i);
|
|
668
668
|
let l = e.ZERO, f = e.BASE;
|
|
669
669
|
const u = BigInt(2 ** i - 1), g = 2 ** i, w = BigInt(i);
|
|
670
|
-
for (let
|
|
671
|
-
const h =
|
|
670
|
+
for (let y = 0; y < c; y++) {
|
|
671
|
+
const h = y * a;
|
|
672
672
|
let d = Number(o & u);
|
|
673
|
-
o >>= w, d > a && (d -= g, o +=
|
|
674
|
-
const
|
|
675
|
-
d === 0 ? f = f.add(n(S, s[
|
|
673
|
+
o >>= w, d > a && (d -= g, o += At);
|
|
674
|
+
const p = h, E = h + Math.abs(d) - 1, S = y % 2 !== 0, I = d < 0;
|
|
675
|
+
d === 0 ? f = f.add(n(S, s[p])) : l = l.add(n(I, s[E]));
|
|
676
676
|
}
|
|
677
677
|
return { p: l, f };
|
|
678
678
|
},
|
|
@@ -683,8 +683,8 @@ function Qi(e, t) {
|
|
|
683
683
|
}
|
|
684
684
|
};
|
|
685
685
|
}
|
|
686
|
-
function
|
|
687
|
-
return
|
|
686
|
+
function ir(e) {
|
|
687
|
+
return Xi(e.Fp), Ye(e, {
|
|
688
688
|
n: "bigint",
|
|
689
689
|
h: "bigint",
|
|
690
690
|
Gx: "field",
|
|
@@ -693,14 +693,14 @@ function er(e) {
|
|
|
693
693
|
nBitLength: "isSafeInteger",
|
|
694
694
|
nByteLength: "isSafeInteger"
|
|
695
695
|
}), Object.freeze({
|
|
696
|
-
...
|
|
696
|
+
...tr(e.n, e.nBitLength),
|
|
697
697
|
...e,
|
|
698
698
|
p: e.Fp.ORDER
|
|
699
699
|
});
|
|
700
700
|
}
|
|
701
701
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
702
|
-
function
|
|
703
|
-
const t =
|
|
702
|
+
function ss(e) {
|
|
703
|
+
const t = ir(e);
|
|
704
704
|
Ye(t, {
|
|
705
705
|
a: "field",
|
|
706
706
|
b: "field"
|
|
@@ -722,7 +722,7 @@ function es(e) {
|
|
|
722
722
|
}
|
|
723
723
|
return Object.freeze({ ...t });
|
|
724
724
|
}
|
|
725
|
-
const { bytesToNumberBE:
|
|
725
|
+
const { bytesToNumberBE: os, hexToBytes: as } = Vi, Be = {
|
|
726
726
|
// asn.1 DER encoding utils
|
|
727
727
|
Err: class extends Error {
|
|
728
728
|
constructor(t = "") {
|
|
@@ -740,10 +740,10 @@ const { bytesToNumberBE: ts, hexToBytes: ns } = qi, Be = {
|
|
|
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: os(r), l: e.subarray(n + 2) };
|
|
744
744
|
},
|
|
745
745
|
toSig(e) {
|
|
746
|
-
const { Err: t } = Be, n = typeof e == "string" ?
|
|
746
|
+
const { Err: t } = Be, n = typeof e == "string" ? as(e) : e;
|
|
747
747
|
if (!(n instanceof Uint8Array))
|
|
748
748
|
throw new Error("ui8a expected");
|
|
749
749
|
let r = n.length;
|
|
@@ -763,70 +763,70 @@ const { bytesToNumberBE: ts, hexToBytes: ns } = qi, Be = {
|
|
|
763
763
|
}, r = t(n(e.s)), i = t(n(e.r)), s = r.length / 2, o = i.length / 2, c = n(s), a = n(o);
|
|
764
764
|
return `30${n(o + s + 4)}02${a}${i}02${c}${r}`;
|
|
765
765
|
}
|
|
766
|
-
},
|
|
766
|
+
}, ce = BigInt(0), X = BigInt(1);
|
|
767
767
|
BigInt(2);
|
|
768
|
-
const
|
|
768
|
+
const Un = BigInt(3);
|
|
769
769
|
BigInt(4);
|
|
770
|
-
function
|
|
771
|
-
const t =
|
|
772
|
-
const
|
|
773
|
-
return _e(Uint8Array.from([4]), n.toBytes(
|
|
774
|
-
}), i = t.fromBytes || ((
|
|
775
|
-
const h =
|
|
776
|
-
return { x: d, y };
|
|
770
|
+
function cs(e) {
|
|
771
|
+
const t = ss(e), { Fp: n } = t, r = t.toBytes || ((y, h, d) => {
|
|
772
|
+
const p = h.toAffine();
|
|
773
|
+
return _e(Uint8Array.from([4]), n.toBytes(p.x), n.toBytes(p.y));
|
|
774
|
+
}), i = t.fromBytes || ((y) => {
|
|
775
|
+
const h = y.subarray(1), d = n.fromBytes(h.subarray(0, n.BYTES)), p = n.fromBytes(h.subarray(n.BYTES, 2 * n.BYTES));
|
|
776
|
+
return { x: d, y: p };
|
|
777
777
|
});
|
|
778
|
-
function s(
|
|
779
|
-
const { a: h, b: d } = t,
|
|
780
|
-
return n.add(n.add(E, n.mul(
|
|
778
|
+
function s(y) {
|
|
779
|
+
const { a: h, b: d } = t, p = n.sqr(y), E = n.mul(p, y);
|
|
780
|
+
return n.add(n.add(E, n.mul(y, h)), d);
|
|
781
781
|
}
|
|
782
782
|
if (!n.eql(n.sqr(t.Gy), s(t.Gx)))
|
|
783
783
|
throw new Error("bad generator point: equation left != right");
|
|
784
|
-
function o(
|
|
785
|
-
return typeof
|
|
784
|
+
function o(y) {
|
|
785
|
+
return typeof y == "bigint" && ce < y && y < t.n;
|
|
786
786
|
}
|
|
787
|
-
function c(
|
|
788
|
-
if (!o(
|
|
787
|
+
function c(y) {
|
|
788
|
+
if (!o(y))
|
|
789
789
|
throw new Error("Expected valid bigint: 0 < bigint < curve.n");
|
|
790
790
|
}
|
|
791
|
-
function a(
|
|
792
|
-
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey:
|
|
793
|
-
if (h && typeof
|
|
794
|
-
if (
|
|
791
|
+
function a(y) {
|
|
792
|
+
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey: p, n: E } = t;
|
|
793
|
+
if (h && typeof y != "bigint") {
|
|
794
|
+
if (y instanceof Uint8Array && (y = De(y)), typeof y != "string" || !h.includes(y.length))
|
|
795
795
|
throw new Error("Invalid key");
|
|
796
|
-
|
|
796
|
+
y = y.padStart(d * 2, "0");
|
|
797
797
|
}
|
|
798
798
|
let S;
|
|
799
799
|
try {
|
|
800
|
-
S = typeof
|
|
800
|
+
S = typeof y == "bigint" ? y : F(Z("private key", y, d));
|
|
801
801
|
} catch {
|
|
802
|
-
throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof
|
|
802
|
+
throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof y}`);
|
|
803
803
|
}
|
|
804
|
-
return
|
|
804
|
+
return p && (S = V(S, E)), c(S), S;
|
|
805
805
|
}
|
|
806
806
|
const l = /* @__PURE__ */ new Map();
|
|
807
|
-
function f(
|
|
808
|
-
if (!(
|
|
807
|
+
function f(y) {
|
|
808
|
+
if (!(y instanceof u))
|
|
809
809
|
throw new Error("ProjectivePoint expected");
|
|
810
810
|
}
|
|
811
811
|
class u {
|
|
812
|
-
constructor(h, d,
|
|
813
|
-
if (this.px = h, this.py = d, this.pz =
|
|
812
|
+
constructor(h, d, p) {
|
|
813
|
+
if (this.px = h, this.py = d, this.pz = p, h == null || !n.isValid(h))
|
|
814
814
|
throw new Error("x required");
|
|
815
815
|
if (d == null || !n.isValid(d))
|
|
816
816
|
throw new Error("y required");
|
|
817
|
-
if (
|
|
817
|
+
if (p == null || !n.isValid(p))
|
|
818
818
|
throw new Error("z required");
|
|
819
819
|
}
|
|
820
820
|
// Does not validate if the point is on-curve.
|
|
821
821
|
// Use fromHex instead, or call assertValidity() later.
|
|
822
822
|
static fromAffine(h) {
|
|
823
|
-
const { x: d, y } = h || {};
|
|
824
|
-
if (!h || !n.isValid(d) || !n.isValid(
|
|
823
|
+
const { x: d, y: p } = h || {};
|
|
824
|
+
if (!h || !n.isValid(d) || !n.isValid(p))
|
|
825
825
|
throw new Error("invalid affine point");
|
|
826
826
|
if (h instanceof u)
|
|
827
827
|
throw new Error("projective point not allowed");
|
|
828
828
|
const E = (S) => n.eql(S, n.ZERO);
|
|
829
|
-
return E(d) && E(
|
|
829
|
+
return E(d) && E(p) ? u.ZERO : new u(d, p, n.ONE);
|
|
830
830
|
}
|
|
831
831
|
get x() {
|
|
832
832
|
return this.toAffine().x;
|
|
@@ -841,8 +841,8 @@ function rs(e) {
|
|
|
841
841
|
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
842
842
|
*/
|
|
843
843
|
static normalizeZ(h) {
|
|
844
|
-
const d = n.invertBatch(h.map((
|
|
845
|
-
return h.map((
|
|
844
|
+
const d = n.invertBatch(h.map((p) => p.pz));
|
|
845
|
+
return h.map((p, E) => p.toAffine(d[E])).map(u.fromAffine);
|
|
846
846
|
}
|
|
847
847
|
/**
|
|
848
848
|
* Converts hash string or Uint8Array to Point.
|
|
@@ -870,8 +870,8 @@ function rs(e) {
|
|
|
870
870
|
const { x: h, y: d } = this.toAffine();
|
|
871
871
|
if (!n.isValid(h) || !n.isValid(d))
|
|
872
872
|
throw new Error("bad point: x or y not FE");
|
|
873
|
-
const
|
|
874
|
-
if (!n.eql(
|
|
873
|
+
const p = n.sqr(d), E = s(h);
|
|
874
|
+
if (!n.eql(p, E))
|
|
875
875
|
throw new Error("bad point: equation left != right");
|
|
876
876
|
if (!this.isTorsionFree())
|
|
877
877
|
throw new Error("bad point: not in prime-order subgroup");
|
|
@@ -887,7 +887,7 @@ function rs(e) {
|
|
|
887
887
|
*/
|
|
888
888
|
equals(h) {
|
|
889
889
|
f(h);
|
|
890
|
-
const { px: d, py:
|
|
890
|
+
const { px: d, py: p, pz: E } = this, { px: S, py: I, pz: B } = h, m = n.eql(n.mul(d, B), n.mul(S, E)), x = n.eql(n.mul(p, B), n.mul(I, E));
|
|
891
891
|
return m && x;
|
|
892
892
|
}
|
|
893
893
|
/**
|
|
@@ -901,9 +901,9 @@ function rs(e) {
|
|
|
901
901
|
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
902
902
|
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
903
903
|
double() {
|
|
904
|
-
const { a: h, b: d } = t,
|
|
904
|
+
const { a: h, b: d } = t, p = n.mul(d, Un), { px: E, py: S, pz: I } = this;
|
|
905
905
|
let B = n.ZERO, m = n.ZERO, x = n.ZERO, K = n.mul(E, E), M = n.mul(S, S), _ = n.mul(I, I), A = n.mul(E, S);
|
|
906
|
-
return A = n.add(A, A), x = n.mul(E, I), x = n.add(x, x), B = n.mul(h, x), m = n.mul(
|
|
906
|
+
return A = n.add(A, A), x = n.mul(E, I), x = n.add(x, x), B = n.mul(h, x), m = n.mul(p, _), m = n.add(B, m), B = n.sub(M, m), m = n.add(M, m), m = n.mul(B, m), B = n.mul(A, B), x = n.mul(p, x), _ = n.mul(h, _), A = n.sub(K, _), A = n.mul(h, A), A = n.add(A, x), x = n.add(K, K), K = n.add(x, K), K = n.add(K, _), K = n.mul(K, A), m = n.add(m, K), _ = n.mul(S, I), _ = n.add(_, _), K = n.mul(_, A), B = n.sub(B, K), x = n.mul(_, M), x = n.add(x, x), x = n.add(x, x), new u(B, m, x);
|
|
907
907
|
}
|
|
908
908
|
// Renes-Costello-Batina exception-free addition formula.
|
|
909
909
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
@@ -911,13 +911,13 @@ function rs(e) {
|
|
|
911
911
|
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
912
912
|
add(h) {
|
|
913
913
|
f(h);
|
|
914
|
-
const { px: d, py:
|
|
914
|
+
const { px: d, py: p, pz: E } = this, { px: S, py: I, pz: B } = h;
|
|
915
915
|
let m = n.ZERO, x = n.ZERO, K = n.ZERO;
|
|
916
|
-
const M = t.a, _ = n.mul(t.b,
|
|
917
|
-
let A = n.mul(d, S),
|
|
918
|
-
|
|
916
|
+
const M = t.a, _ = n.mul(t.b, Un);
|
|
917
|
+
let A = n.mul(d, S), R = n.mul(p, I), T = n.mul(E, B), q = n.add(d, p), b = n.add(S, I);
|
|
918
|
+
q = n.mul(q, b), b = n.add(A, R), q = n.sub(q, b), b = n.add(d, E);
|
|
919
919
|
let v = n.add(S, B);
|
|
920
|
-
return b = n.mul(b, v), v = n.add(A,
|
|
920
|
+
return b = n.mul(b, v), v = n.add(A, T), b = n.sub(b, v), v = n.add(p, E), m = n.add(I, B), v = n.mul(v, m), m = n.add(R, T), v = n.sub(v, m), K = n.mul(M, b), m = n.mul(_, T), K = n.add(m, K), m = n.sub(R, K), K = n.add(R, K), x = n.mul(m, K), R = n.add(A, A), R = n.add(R, A), T = n.mul(M, T), b = n.mul(_, 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), m = n.mul(q, m), m = n.sub(m, A), A = n.mul(q, R), K = n.mul(v, K), K = n.add(K, A), new u(m, x, K);
|
|
921
921
|
}
|
|
922
922
|
subtract(h) {
|
|
923
923
|
return this.add(h.negate());
|
|
@@ -927,8 +927,8 @@ function rs(e) {
|
|
|
927
927
|
}
|
|
928
928
|
wNAF(h) {
|
|
929
929
|
return w.wNAFCached(this, l, h, (d) => {
|
|
930
|
-
const
|
|
931
|
-
return d.map((E, S) => E.toAffine(
|
|
930
|
+
const p = n.invertBatch(d.map((E) => E.pz));
|
|
931
|
+
return d.map((E, S) => E.toAffine(p[S])).map(u.fromAffine);
|
|
932
932
|
});
|
|
933
933
|
}
|
|
934
934
|
/**
|
|
@@ -938,17 +938,17 @@ function rs(e) {
|
|
|
938
938
|
*/
|
|
939
939
|
multiplyUnsafe(h) {
|
|
940
940
|
const d = u.ZERO;
|
|
941
|
-
if (h ===
|
|
941
|
+
if (h === ce)
|
|
942
942
|
return d;
|
|
943
943
|
if (c(h), h === X)
|
|
944
944
|
return this;
|
|
945
|
-
const { endo:
|
|
946
|
-
if (!
|
|
945
|
+
const { endo: p } = t;
|
|
946
|
+
if (!p)
|
|
947
947
|
return w.unsafeLadder(this, h);
|
|
948
|
-
let { k1neg: E, k1: S, k2neg: I, k2: B } =
|
|
949
|
-
for (; S >
|
|
948
|
+
let { k1neg: E, k1: S, k2neg: I, k2: B } = p.splitScalar(h), m = d, x = d, K = this;
|
|
949
|
+
for (; S > ce || B > ce; )
|
|
950
950
|
S & X && (m = m.add(K)), B & X && (x = x.add(K)), K = K.double(), S >>= X, B >>= X;
|
|
951
|
-
return E && (m = m.negate()), I && (x = x.negate()), x = new u(n.mul(x.px,
|
|
951
|
+
return E && (m = m.negate()), I && (x = x.negate()), x = new u(n.mul(x.px, p.beta), x.py, x.pz), m.add(x);
|
|
952
952
|
}
|
|
953
953
|
/**
|
|
954
954
|
* Constant time multiplication.
|
|
@@ -961,17 +961,17 @@ function rs(e) {
|
|
|
961
961
|
*/
|
|
962
962
|
multiply(h) {
|
|
963
963
|
c(h);
|
|
964
|
-
let d = h,
|
|
964
|
+
let d = h, p, E;
|
|
965
965
|
const { endo: S } = t;
|
|
966
966
|
if (S) {
|
|
967
967
|
const { k1neg: I, k1: B, k2neg: m, k2: x } = S.splitScalar(d);
|
|
968
968
|
let { p: K, f: M } = this.wNAF(B), { p: _, f: A } = this.wNAF(x);
|
|
969
|
-
K = w.constTimeNegate(I, K), _ = w.constTimeNegate(m, _), _ = new u(n.mul(_.px, S.beta), _.py, _.pz),
|
|
969
|
+
K = w.constTimeNegate(I, K), _ = w.constTimeNegate(m, _), _ = new u(n.mul(_.px, S.beta), _.py, _.pz), p = K.add(_), E = M.add(A);
|
|
970
970
|
} else {
|
|
971
971
|
const { p: I, f: B } = this.wNAF(d);
|
|
972
|
-
|
|
972
|
+
p = I, E = B;
|
|
973
973
|
}
|
|
974
|
-
return u.normalizeZ([
|
|
974
|
+
return u.normalizeZ([p, E])[0];
|
|
975
975
|
}
|
|
976
976
|
/**
|
|
977
977
|
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
@@ -979,17 +979,17 @@ function rs(e) {
|
|
|
979
979
|
* The trick could be useful if both P and Q are not G (not in our case).
|
|
980
980
|
* @returns non-zero affine point
|
|
981
981
|
*/
|
|
982
|
-
multiplyAndAddUnsafe(h, d,
|
|
983
|
-
const E = u.BASE, S = (B, m) => m ===
|
|
982
|
+
multiplyAndAddUnsafe(h, d, p) {
|
|
983
|
+
const E = u.BASE, S = (B, m) => m === ce || m === X || !B.equals(E) ? B.multiplyUnsafe(m) : B.multiply(m), I = S(this, d).add(S(h, p));
|
|
984
984
|
return I.is0() ? void 0 : I;
|
|
985
985
|
}
|
|
986
986
|
// Converts Projective point to affine (x, y) coordinates.
|
|
987
987
|
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
988
988
|
// (x, y, z) ∋ (x=x/z, y=y/z)
|
|
989
989
|
toAffine(h) {
|
|
990
|
-
const { px: d, py:
|
|
990
|
+
const { px: d, py: p, pz: E } = this, S = this.is0();
|
|
991
991
|
h == null && (h = S ? n.ONE : n.inv(E));
|
|
992
|
-
const I = n.mul(d, h), B = n.mul(
|
|
992
|
+
const I = n.mul(d, h), B = n.mul(p, h), m = n.mul(E, h);
|
|
993
993
|
if (S)
|
|
994
994
|
return { x: n.ZERO, y: n.ZERO };
|
|
995
995
|
if (!n.eql(m, n.ONE))
|
|
@@ -1016,7 +1016,7 @@ function rs(e) {
|
|
|
1016
1016
|
}
|
|
1017
1017
|
}
|
|
1018
1018
|
u.BASE = new u(t.Gx, t.Gy, n.ONE), u.ZERO = new u(n.ZERO, n.ONE, n.ZERO);
|
|
1019
|
-
const g = t.nBitLength, w =
|
|
1019
|
+
const g = t.nBitLength, w = is(u, t.endo ? Math.ceil(g / 2) : g);
|
|
1020
1020
|
return {
|
|
1021
1021
|
CURVE: t,
|
|
1022
1022
|
ProjectivePoint: u,
|
|
@@ -1025,8 +1025,8 @@ function rs(e) {
|
|
|
1025
1025
|
isWithinCurveOrder: o
|
|
1026
1026
|
};
|
|
1027
1027
|
}
|
|
1028
|
-
function
|
|
1029
|
-
const t =
|
|
1028
|
+
function us(e) {
|
|
1029
|
+
const t = ir(e);
|
|
1030
1030
|
return Ye(t, {
|
|
1031
1031
|
hash: "hash",
|
|
1032
1032
|
hmac: "function",
|
|
@@ -1037,18 +1037,18 @@ function is(e) {
|
|
|
1037
1037
|
lowS: "boolean"
|
|
1038
1038
|
}), Object.freeze({ lowS: !0, ...t });
|
|
1039
1039
|
}
|
|
1040
|
-
function
|
|
1041
|
-
const t =
|
|
1040
|
+
function ls(e) {
|
|
1041
|
+
const t = us(e), { Fp: n, n: r } = t, i = n.BYTES + 1, s = 2 * n.BYTES + 1;
|
|
1042
1042
|
function o(b) {
|
|
1043
|
-
return
|
|
1043
|
+
return ce < b && b < n.ORDER;
|
|
1044
1044
|
}
|
|
1045
1045
|
function c(b) {
|
|
1046
|
-
return
|
|
1046
|
+
return V(b, r);
|
|
1047
1047
|
}
|
|
1048
1048
|
function a(b) {
|
|
1049
1049
|
return Tt(b, r);
|
|
1050
1050
|
}
|
|
1051
|
-
const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: g } =
|
|
1051
|
+
const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: g } = cs({
|
|
1052
1052
|
...t,
|
|
1053
1053
|
toBytes(b, v, N) {
|
|
1054
1054
|
const k = v.toAffine(), C = n.toBytes(k.x), U = _e;
|
|
@@ -1071,28 +1071,28 @@ function ss(e) {
|
|
|
1071
1071
|
throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`);
|
|
1072
1072
|
}
|
|
1073
1073
|
}), w = (b) => De(Ne(b, t.nByteLength));
|
|
1074
|
-
function
|
|
1074
|
+
function y(b) {
|
|
1075
1075
|
const v = r >> X;
|
|
1076
1076
|
return b > v;
|
|
1077
1077
|
}
|
|
1078
1078
|
function h(b) {
|
|
1079
|
-
return
|
|
1079
|
+
return y(b) ? c(-b) : b;
|
|
1080
1080
|
}
|
|
1081
1081
|
const d = (b, v, N) => F(b.slice(v, N));
|
|
1082
|
-
class
|
|
1082
|
+
class p {
|
|
1083
1083
|
constructor(v, N, k) {
|
|
1084
1084
|
this.r = v, this.s = N, this.recovery = k, this.assertValidity();
|
|
1085
1085
|
}
|
|
1086
1086
|
// pair (bytes of r, bytes of s)
|
|
1087
1087
|
static fromCompact(v) {
|
|
1088
1088
|
const N = t.nByteLength;
|
|
1089
|
-
return v = Z("compactSignature", v, N * 2), new
|
|
1089
|
+
return v = Z("compactSignature", v, N * 2), new p(d(v, 0, N), d(v, N, 2 * N));
|
|
1090
1090
|
}
|
|
1091
1091
|
// DER encoded ECDSA signature
|
|
1092
1092
|
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
1093
1093
|
static fromDER(v) {
|
|
1094
1094
|
const { r: N, s: k } = Be.toSig(Z("DER", v));
|
|
1095
|
-
return new
|
|
1095
|
+
return new p(N, k);
|
|
1096
1096
|
}
|
|
1097
1097
|
assertValidity() {
|
|
1098
1098
|
if (!g(this.r))
|
|
@@ -1101,7 +1101,7 @@ function ss(e) {
|
|
|
1101
1101
|
throw new Error("s must be 0 < s < CURVE.n");
|
|
1102
1102
|
}
|
|
1103
1103
|
addRecoveryBit(v) {
|
|
1104
|
-
return new
|
|
1104
|
+
return new p(this.r, this.s, v);
|
|
1105
1105
|
}
|
|
1106
1106
|
recoverPublicKey(v) {
|
|
1107
1107
|
const { r: N, s: k, recovery: C } = this, U = x(Z("msgHash", v));
|
|
@@ -1110,17 +1110,17 @@ function ss(e) {
|
|
|
1110
1110
|
const O = C === 2 || C === 3 ? N + t.n : N;
|
|
1111
1111
|
if (O >= n.ORDER)
|
|
1112
1112
|
throw new Error("recovery id 2 or 3 invalid");
|
|
1113
|
-
const $ = C & 1 ? "
|
|
1113
|
+
const $ = (C & 1) === 0 ? "02" : "03", ee = l.fromHex($ + w(O)), ge = a(O), Ue = c(-U * ge), Ve = c(k * ge), we = l.BASE.multiplyAndAddUnsafe(ee, Ue, Ve);
|
|
1114
1114
|
if (!we)
|
|
1115
1115
|
throw new Error("point at infinify");
|
|
1116
1116
|
return we.assertValidity(), we;
|
|
1117
1117
|
}
|
|
1118
1118
|
// Signatures should be low-s, to prevent malleability.
|
|
1119
1119
|
hasHighS() {
|
|
1120
|
-
return
|
|
1120
|
+
return y(this.s);
|
|
1121
1121
|
}
|
|
1122
1122
|
normalizeS() {
|
|
1123
|
-
return this.hasHighS() ? new
|
|
1123
|
+
return this.hasHighS() ? new p(this.r, c(-this.s), this.recovery) : this;
|
|
1124
1124
|
}
|
|
1125
1125
|
// DER-encoded
|
|
1126
1126
|
toDERRawBytes() {
|
|
@@ -1151,8 +1151,8 @@ function ss(e) {
|
|
|
1151
1151
|
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
|
1152
1152
|
*/
|
|
1153
1153
|
randomPrivateKey: () => {
|
|
1154
|
-
const b =
|
|
1155
|
-
return
|
|
1154
|
+
const b = rr(t.n);
|
|
1155
|
+
return ns(t.randomBytes(b), t.n);
|
|
1156
1156
|
},
|
|
1157
1157
|
/**
|
|
1158
1158
|
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
|
@@ -1189,7 +1189,7 @@ function ss(e) {
|
|
|
1189
1189
|
function M(b) {
|
|
1190
1190
|
if (typeof b != "bigint")
|
|
1191
1191
|
throw new Error("bigint expected");
|
|
1192
|
-
if (!(
|
|
1192
|
+
if (!(ce <= b && b < K))
|
|
1193
1193
|
throw new Error(`bigint expected < 2^${t.nBitLength}`);
|
|
1194
1194
|
return Ne(b, t.nByteLength);
|
|
1195
1195
|
}
|
|
@@ -1204,29 +1204,29 @@ function ss(e) {
|
|
|
1204
1204
|
const Ae = $ === !0 ? C(n.BYTES) : $;
|
|
1205
1205
|
Ue.push(Z("extraEntropy", Ae));
|
|
1206
1206
|
}
|
|
1207
|
-
const
|
|
1208
|
-
function
|
|
1207
|
+
const Ve = _e(...Ue), we = ee;
|
|
1208
|
+
function xt(Ae) {
|
|
1209
1209
|
const Le = m(Ae);
|
|
1210
1210
|
if (!g(Le))
|
|
1211
1211
|
return;
|
|
1212
|
-
const
|
|
1213
|
-
if (te ===
|
|
1212
|
+
const Sn = a(Le), $e = l.BASE.multiply(Le).toAffine(), te = c($e.x);
|
|
1213
|
+
if (te === ce)
|
|
1214
1214
|
return;
|
|
1215
|
-
const
|
|
1216
|
-
if (
|
|
1215
|
+
const Re = c(Sn * c(we + te * ge));
|
|
1216
|
+
if (Re === ce)
|
|
1217
1217
|
return;
|
|
1218
|
-
let
|
|
1219
|
-
return U &&
|
|
1218
|
+
let An = ($e.x === te ? 0 : 2) | Number($e.y & X), Cn = Re;
|
|
1219
|
+
return U && y(Re) && (Cn = h(Re), An ^= 1), new p(te, Cn, An);
|
|
1220
1220
|
}
|
|
1221
|
-
return { seed:
|
|
1221
|
+
return { seed: Ve, k2sig: xt };
|
|
1222
1222
|
}
|
|
1223
|
-
const A = { lowS: t.lowS, prehash: !1 },
|
|
1224
|
-
function
|
|
1223
|
+
const A = { lowS: t.lowS, prehash: !1 }, R = { lowS: t.lowS, prehash: !1 };
|
|
1224
|
+
function T(b, v, N = A) {
|
|
1225
1225
|
const { seed: k, k2sig: C } = _(b, v, N), U = t;
|
|
1226
|
-
return
|
|
1226
|
+
return er(U.hash.outputLen, U.nByteLength, U.hmac)(k, C);
|
|
1227
1227
|
}
|
|
1228
1228
|
l.BASE._setWindowSize(8);
|
|
1229
|
-
function
|
|
1229
|
+
function q(b, v, N, k = R) {
|
|
1230
1230
|
var $e;
|
|
1231
1231
|
const C = b;
|
|
1232
1232
|
if (v = Z("msgHash", v), N = Z("publicKey", N), "strict" in k)
|
|
@@ -1236,15 +1236,15 @@ function ss(e) {
|
|
|
1236
1236
|
try {
|
|
1237
1237
|
if (typeof C == "string" || C instanceof Uint8Array)
|
|
1238
1238
|
try {
|
|
1239
|
-
$ =
|
|
1239
|
+
$ = p.fromDER(C);
|
|
1240
1240
|
} catch (te) {
|
|
1241
1241
|
if (!(te instanceof Be.Err))
|
|
1242
1242
|
throw te;
|
|
1243
|
-
$ =
|
|
1243
|
+
$ = p.fromCompact(C);
|
|
1244
1244
|
}
|
|
1245
1245
|
else if (typeof C == "object" && typeof C.r == "bigint" && typeof C.s == "bigint") {
|
|
1246
|
-
const { r: te, s:
|
|
1247
|
-
$ = new
|
|
1246
|
+
const { r: te, s: Re } = C;
|
|
1247
|
+
$ = new p(te, Re);
|
|
1248
1248
|
} else
|
|
1249
1249
|
throw new Error("PARSE");
|
|
1250
1250
|
ee = l.fromHex(N);
|
|
@@ -1256,24 +1256,24 @@ function ss(e) {
|
|
|
1256
1256
|
if (U && $.hasHighS())
|
|
1257
1257
|
return !1;
|
|
1258
1258
|
O && (v = t.hash(v));
|
|
1259
|
-
const { r: ge, s: Ue } = $,
|
|
1259
|
+
const { r: ge, s: Ue } = $, Ve = x(v), we = a(Ue), xt = c(Ve * we), Ae = c(ge * we), Le = ($e = l.BASE.multiplyAndAddUnsafe(ee, xt, Ae)) == null ? void 0 : $e.toAffine();
|
|
1260
1260
|
return Le ? c(Le.x) === ge : !1;
|
|
1261
1261
|
}
|
|
1262
1262
|
return {
|
|
1263
1263
|
CURVE: t,
|
|
1264
1264
|
getPublicKey: S,
|
|
1265
1265
|
getSharedSecret: B,
|
|
1266
|
-
sign:
|
|
1267
|
-
verify:
|
|
1266
|
+
sign: T,
|
|
1267
|
+
verify: q,
|
|
1268
1268
|
ProjectivePoint: l,
|
|
1269
|
-
Signature:
|
|
1269
|
+
Signature: p,
|
|
1270
1270
|
utils: E
|
|
1271
1271
|
};
|
|
1272
1272
|
}
|
|
1273
|
-
let
|
|
1273
|
+
let sr = class extends Jn {
|
|
1274
1274
|
constructor(t, n) {
|
|
1275
|
-
super(), this.finished = !1, this.destroyed = !1,
|
|
1276
|
-
const r =
|
|
1275
|
+
super(), this.finished = !1, this.destroyed = !1, Si(t);
|
|
1276
|
+
const r = Vt(n);
|
|
1277
1277
|
if (this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
1278
1278
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
1279
1279
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
@@ -1290,7 +1290,7 @@ let tr = class extends Wn {
|
|
|
1290
1290
|
return et(this), this.iHash.update(t), this;
|
|
1291
1291
|
}
|
|
1292
1292
|
digestInto(t) {
|
|
1293
|
-
et(this),
|
|
1293
|
+
et(this), Gn(t, this.outputLen), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
1294
1294
|
}
|
|
1295
1295
|
digest() {
|
|
1296
1296
|
const t = new Uint8Array(this.oHash.outputLen);
|
|
@@ -1305,32 +1305,32 @@ let tr = class extends Wn {
|
|
|
1305
1305
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
1306
1306
|
}
|
|
1307
1307
|
};
|
|
1308
|
-
const
|
|
1309
|
-
|
|
1308
|
+
const or = (e, t, n) => new sr(e, t).update(n).digest();
|
|
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 fs(e) {
|
|
1312
1312
|
return {
|
|
1313
1313
|
hash: e,
|
|
1314
|
-
hmac: (t, ...n) =>
|
|
1315
|
-
randomBytes:
|
|
1314
|
+
hmac: (t, ...n) => or(e, t, ki(...n)),
|
|
1315
|
+
randomBytes: Yn
|
|
1316
1316
|
};
|
|
1317
1317
|
}
|
|
1318
|
-
function
|
|
1319
|
-
const n = (r) =>
|
|
1318
|
+
function hs(e, t) {
|
|
1319
|
+
const n = (r) => ls({ ...e, ...fs(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
|
-
const
|
|
1324
|
-
function
|
|
1325
|
-
const t =
|
|
1326
|
-
if (!
|
|
1323
|
+
const ut = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), tt = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), ar = BigInt(1), nt = BigInt(2), Ln = (e, t) => (e + t / nt) / t;
|
|
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, g = Y(u, n, t) * f % t, w = Y(g, nt, t) * l % t, y = Y(w, i, t) * w % t, h = Y(y, s, t) * y % t, d = Y(h, c, t) * h % t, p = Y(d, a, t) * d % t, E = Y(p, c, t) * h % t, S = Y(E, n, t) * f % t, I = Y(S, o, t) * y % t, B = Y(I, r, t) * l % t, m = Y(B, nt, t);
|
|
1326
|
+
if (!Ot.eql(Ot.sqr(m), e))
|
|
1327
1327
|
throw new Error("Cannot find square root");
|
|
1328
1328
|
return m;
|
|
1329
1329
|
}
|
|
1330
|
-
const
|
|
1330
|
+
const Ot = ts(ut, void 0, void 0, { sqrt: cr }), Ie = hs({
|
|
1331
1331
|
a: BigInt(0),
|
|
1332
1332
|
b: BigInt(7),
|
|
1333
|
-
Fp:
|
|
1333
|
+
Fp: Ot,
|
|
1334
1334
|
n: tt,
|
|
1335
1335
|
// Base point (x, y) aka generator point
|
|
1336
1336
|
Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
|
|
@@ -1346,92 +1346,92 @@ const Rt = Ji(ct, void 0, void 0, { sqrt: ir }), Ie = as({
|
|
|
1346
1346
|
endo: {
|
|
1347
1347
|
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
1348
1348
|
splitScalar: (e) => {
|
|
1349
|
-
const t = tt, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -
|
|
1350
|
-
let l =
|
|
1349
|
+
const t = tt, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -ar * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), s = n, o = BigInt("0x100000000000000000000000000000000"), c = Ln(s * e, t), a = Ln(-r * e, t);
|
|
1350
|
+
let l = V(e - c * n - a * i, t), f = V(-c * r - a * s, t);
|
|
1351
1351
|
const u = l > o, g = f > o;
|
|
1352
1352
|
if (u && (l = t - l), g && (f = t - f), l > o || f > o)
|
|
1353
1353
|
throw new Error("splitScalar: Endomorphism failed, k=" + e);
|
|
1354
1354
|
return { k1neg: u, k1: l, k2neg: g, k2: f };
|
|
1355
1355
|
}
|
|
1356
1356
|
}
|
|
1357
|
-
},
|
|
1357
|
+
}, $t), lt = BigInt(0), ur = (e) => typeof e == "bigint" && lt < e && e < ut, ds = (e) => typeof e == "bigint" && lt < e && e < tt, $n = {};
|
|
1358
1358
|
function rt(e, ...t) {
|
|
1359
|
-
let n =
|
|
1359
|
+
let n = $n[e];
|
|
1360
1360
|
if (n === void 0) {
|
|
1361
|
-
const r =
|
|
1362
|
-
n = _e(r, r),
|
|
1361
|
+
const r = $t(Uint8Array.from(e, (i) => i.charCodeAt(0)));
|
|
1362
|
+
n = _e(r, r), $n[e] = n;
|
|
1363
1363
|
}
|
|
1364
|
-
return
|
|
1364
|
+
return $t(_e(n, ...t));
|
|
1365
1365
|
}
|
|
1366
|
-
const Yt = (e) => e.toRawBytes(!0).slice(1),
|
|
1366
|
+
const Yt = (e) => e.toRawBytes(!0).slice(1), Mt = (e) => Ne(e, 32), Ct = (e) => V(e, ut), Fe = (e) => V(e, tt), Xt = Ie.ProjectivePoint, ps = (e, t, n) => Xt.BASE.multiplyAndAddUnsafe(e, t, n);
|
|
1367
1367
|
function Pt(e) {
|
|
1368
1368
|
let t = Ie.utils.normPrivateKeyToScalar(e), n = Xt.fromPrivateKey(t);
|
|
1369
1369
|
return { scalar: n.hasEvenY() ? t : Fe(-t), bytes: Yt(n) };
|
|
1370
1370
|
}
|
|
1371
|
-
function
|
|
1372
|
-
if (!
|
|
1371
|
+
function lr(e) {
|
|
1372
|
+
if (!ur(e))
|
|
1373
1373
|
throw new Error("bad x: need 0 < x < p");
|
|
1374
|
-
const t =
|
|
1375
|
-
let r =
|
|
1376
|
-
r % nt !==
|
|
1377
|
-
const i = new Xt(e, r,
|
|
1374
|
+
const t = Ct(e * e), n = Ct(t * e + BigInt(7));
|
|
1375
|
+
let r = cr(n);
|
|
1376
|
+
r % nt !== lt && (r = Ct(-r));
|
|
1377
|
+
const i = new Xt(e, r, ar);
|
|
1378
1378
|
return i.assertValidity(), i;
|
|
1379
1379
|
}
|
|
1380
|
-
function
|
|
1380
|
+
function fr(...e) {
|
|
1381
1381
|
return Fe(F(rt("BIP0340/challenge", ...e)));
|
|
1382
1382
|
}
|
|
1383
|
-
function
|
|
1383
|
+
function ys(e) {
|
|
1384
1384
|
return Pt(e).bytes;
|
|
1385
1385
|
}
|
|
1386
|
-
function
|
|
1387
|
-
const r = Z("message", e), { bytes: i, scalar: s } = Pt(t), o = Z("auxRand", n, 32), c =
|
|
1388
|
-
if (l ===
|
|
1386
|
+
function gs(e, t, n = Yn(32)) {
|
|
1387
|
+
const r = Z("message", e), { bytes: i, scalar: s } = Pt(t), o = Z("auxRand", n, 32), c = Mt(s ^ F(rt("BIP0340/aux", o))), a = rt("BIP0340/nonce", c, i, r), l = Fe(F(a));
|
|
1388
|
+
if (l === lt)
|
|
1389
1389
|
throw new Error("sign failed: k is zero");
|
|
1390
|
-
const { bytes: f, scalar: u } = Pt(l), g =
|
|
1391
|
-
if (w.set(f, 0), w.set(
|
|
1390
|
+
const { bytes: f, scalar: u } = Pt(l), g = fr(f, i, r), w = new Uint8Array(64);
|
|
1391
|
+
if (w.set(f, 0), w.set(Mt(Fe(u + g * s)), 32), !hr(w, r, i))
|
|
1392
1392
|
throw new Error("sign: Invalid signature produced");
|
|
1393
1393
|
return w;
|
|
1394
1394
|
}
|
|
1395
|
-
function
|
|
1395
|
+
function hr(e, t, n) {
|
|
1396
1396
|
const r = Z("signature", e, 64), i = Z("message", t), s = Z("publicKey", n, 32);
|
|
1397
1397
|
try {
|
|
1398
|
-
const o =
|
|
1399
|
-
if (!
|
|
1398
|
+
const o = lr(F(s)), c = F(r.subarray(0, 32));
|
|
1399
|
+
if (!ur(c))
|
|
1400
1400
|
return !1;
|
|
1401
1401
|
const a = F(r.subarray(32, 64));
|
|
1402
|
-
if (!
|
|
1402
|
+
if (!ds(a))
|
|
1403
1403
|
return !1;
|
|
1404
|
-
const l =
|
|
1404
|
+
const l = fr(Mt(c), Yt(o), i), f = ps(o, a, Fe(-l));
|
|
1405
1405
|
return !(!f || !f.hasEvenY() || f.toAffine().x !== c);
|
|
1406
1406
|
} catch {
|
|
1407
1407
|
return !1;
|
|
1408
1408
|
}
|
|
1409
1409
|
}
|
|
1410
1410
|
const Ze = {
|
|
1411
|
-
getPublicKey:
|
|
1412
|
-
sign:
|
|
1413
|
-
verify:
|
|
1411
|
+
getPublicKey: ys,
|
|
1412
|
+
sign: gs,
|
|
1413
|
+
verify: hr,
|
|
1414
1414
|
utils: {
|
|
1415
1415
|
randomPrivateKey: Ie.utils.randomPrivateKey,
|
|
1416
|
-
lift_x:
|
|
1416
|
+
lift_x: lr,
|
|
1417
1417
|
pointToBytes: Yt,
|
|
1418
1418
|
numberToBytesBE: Ne,
|
|
1419
1419
|
bytesToNumberBE: F,
|
|
1420
1420
|
taggedHash: rt,
|
|
1421
|
-
mod:
|
|
1421
|
+
mod: V
|
|
1422
1422
|
}
|
|
1423
|
-
},
|
|
1423
|
+
}, Bt = 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,
|
|
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, ws = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1426
|
+
if (!ws)
|
|
1427
1427
|
throw new Error("Non little-endian hardware is not supported");
|
|
1428
|
-
const
|
|
1429
|
-
function
|
|
1428
|
+
const bs = Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
1429
|
+
function H(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 += bs[e[n]];
|
|
1435
1435
|
return t;
|
|
1436
1436
|
}
|
|
1437
1437
|
function z(e) {
|
|
@@ -1449,17 +1449,17 @@ function z(e) {
|
|
|
1449
1449
|
}
|
|
1450
1450
|
return n;
|
|
1451
1451
|
}
|
|
1452
|
-
function
|
|
1452
|
+
function vs(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 = vs(e)), !Qt(e))
|
|
1459
1459
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
1460
1460
|
return e;
|
|
1461
1461
|
}
|
|
1462
|
-
function
|
|
1462
|
+
function ft(...e) {
|
|
1463
1463
|
const t = new Uint8Array(e.reduce((r, i) => r + i.length, 0));
|
|
1464
1464
|
let n = 0;
|
|
1465
1465
|
return e.forEach((r) => {
|
|
@@ -1468,69 +1468,69 @@ function lt(...e) {
|
|
|
1468
1468
|
t.set(r, n), n += r.length;
|
|
1469
1469
|
}), t;
|
|
1470
1470
|
}
|
|
1471
|
-
class
|
|
1471
|
+
class dr {
|
|
1472
1472
|
// Safe version that clones internal state
|
|
1473
1473
|
clone() {
|
|
1474
1474
|
return this._cloneInto();
|
|
1475
1475
|
}
|
|
1476
1476
|
}
|
|
1477
|
-
function
|
|
1477
|
+
function pr(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
|
|
1482
|
-
if (
|
|
1483
|
-
return
|
|
1481
|
+
function yr(e = 32) {
|
|
1482
|
+
if (Bt && typeof Bt.getRandomValues == "function")
|
|
1483
|
+
return Bt.getRandomValues(new Uint8Array(e));
|
|
1484
1484
|
throw new Error("crypto.getRandomValues must be defined");
|
|
1485
1485
|
}
|
|
1486
|
-
function
|
|
1486
|
+
function Ht(e) {
|
|
1487
1487
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
1488
1488
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
1489
1489
|
}
|
|
1490
|
-
function
|
|
1490
|
+
function ms(e) {
|
|
1491
1491
|
if (typeof e != "boolean")
|
|
1492
1492
|
throw new Error(`Expected boolean, not ${e}`);
|
|
1493
1493
|
}
|
|
1494
|
-
function
|
|
1494
|
+
function gr(e, ...t) {
|
|
1495
1495
|
if (!(e instanceof Uint8Array))
|
|
1496
1496
|
throw new Error("Expected Uint8Array");
|
|
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 Es(e) {
|
|
1501
1501
|
if (typeof e != "function" || typeof e.create != "function")
|
|
1502
1502
|
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
1503
|
-
|
|
1503
|
+
Ht(e.outputLen), Ht(e.blockLen);
|
|
1504
1504
|
}
|
|
1505
|
-
function
|
|
1505
|
+
function xs(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
|
|
1512
|
-
|
|
1511
|
+
function Ks(e, t) {
|
|
1512
|
+
gr(e);
|
|
1513
1513
|
const n = t.outputLen;
|
|
1514
1514
|
if (e.length < n)
|
|
1515
1515
|
throw new Error(`digestInto() expects output buffer of length at least ${n}`);
|
|
1516
1516
|
}
|
|
1517
1517
|
const se = {
|
|
1518
|
-
number:
|
|
1519
|
-
bool:
|
|
1520
|
-
bytes:
|
|
1521
|
-
hash:
|
|
1522
|
-
exists:
|
|
1523
|
-
output:
|
|
1518
|
+
number: Ht,
|
|
1519
|
+
bool: ms,
|
|
1520
|
+
bytes: gr,
|
|
1521
|
+
hash: Es,
|
|
1522
|
+
exists: xs,
|
|
1523
|
+
output: Ks
|
|
1524
1524
|
};
|
|
1525
|
-
function
|
|
1525
|
+
function Ns(e, t, n, r) {
|
|
1526
1526
|
if (typeof e.setBigUint64 == "function")
|
|
1527
1527
|
return e.setBigUint64(t, n, r);
|
|
1528
1528
|
const i = BigInt(32), s = BigInt(4294967295), o = Number(n >> i & s), c = Number(n & s), a = r ? 4 : 0, l = r ? 0 : 4;
|
|
1529
1529
|
e.setUint32(t + a, o, r), e.setUint32(t + l, c, r);
|
|
1530
1530
|
}
|
|
1531
|
-
class
|
|
1531
|
+
class Ss extends dr {
|
|
1532
1532
|
constructor(t, n, r, i) {
|
|
1533
|
-
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view =
|
|
1533
|
+
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view = kt(this.buffer);
|
|
1534
1534
|
}
|
|
1535
1535
|
update(t) {
|
|
1536
1536
|
se.exists(this);
|
|
@@ -1540,7 +1540,7 @@ class ms extends ur {
|
|
|
1540
1540
|
for (let o = 0; o < s; ) {
|
|
1541
1541
|
const c = Math.min(i - this.pos, s - o);
|
|
1542
1542
|
if (c === i) {
|
|
1543
|
-
const a =
|
|
1543
|
+
const a = kt(t);
|
|
1544
1544
|
for (; i <= s - o; o += i)
|
|
1545
1545
|
this.process(a, o);
|
|
1546
1546
|
continue;
|
|
@@ -1556,8 +1556,8 @@ class ms extends ur {
|
|
|
1556
1556
|
n[o++] = 128, this.buffer.subarray(o).fill(0), this.padOffset > i - o && (this.process(r, 0), o = 0);
|
|
1557
1557
|
for (let u = o; u < i; u++)
|
|
1558
1558
|
n[u] = 0;
|
|
1559
|
-
|
|
1560
|
-
const c =
|
|
1559
|
+
Ns(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
1560
|
+
const c = kt(t), a = this.outputLen;
|
|
1561
1561
|
if (a % 4)
|
|
1562
1562
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
1563
1563
|
const l = a / 4, f = this.get();
|
|
@@ -1578,7 +1578,7 @@ class ms extends ur {
|
|
|
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 As = (e, t, n) => e & t ^ ~e & n, Cs = (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 Es = (e, t, n) => e & t ^ ~e & n, xs = (e, t, n) => e & t ^ e & n ^ t & n,
|
|
|
1653
1653
|
528734635,
|
|
1654
1654
|
1541459225
|
|
1655
1655
|
]), Ee = new Uint32Array(64);
|
|
1656
|
-
class
|
|
1656
|
+
class wr extends Ss {
|
|
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 dr extends ms {
|
|
|
1669
1669
|
for (let u = 0; u < 16; u++, n += 4)
|
|
1670
1670
|
Ee[u] = t.getUint32(n, !1);
|
|
1671
1671
|
for (let u = 16; u < 64; u++) {
|
|
1672
|
-
const g = Ee[u - 15], w = Ee[u - 2],
|
|
1673
|
-
Ee[u] = h + Ee[u - 7] +
|
|
1672
|
+
const g = Ee[u - 15], w = Ee[u - 2], y = ie(g, 7) ^ ie(g, 18) ^ g >>> 3, h = ie(w, 17) ^ ie(w, 19) ^ w >>> 10;
|
|
1673
|
+
Ee[u] = h + Ee[u - 7] + y + Ee[u - 16] | 0;
|
|
1674
1674
|
}
|
|
1675
1675
|
let { A: r, B: i, C: s, D: o, E: c, F: a, G: l, H: f } = this;
|
|
1676
1676
|
for (let u = 0; u < 64; u++) {
|
|
1677
|
-
const g = ie(c, 6) ^ ie(c, 11) ^ ie(c, 25), w = f + g +
|
|
1677
|
+
const g = ie(c, 6) ^ ie(c, 11) ^ ie(c, 25), w = f + g + As(c, a, l) + Bs[u] + Ee[u] | 0, h = (ie(r, 2) ^ ie(r, 13) ^ ie(r, 22)) + Cs(r, i, s) | 0;
|
|
1678
1678
|
f = l, l = a, a = c, c = o + w | 0, o = s, s = i, i = r, r = w + h | 0;
|
|
1679
1679
|
}
|
|
1680
1680
|
r = r + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, l = l + this.G | 0, f = f + this.H | 0, this.set(r, i, s, o, c, a, l, f);
|
|
@@ -1686,15 +1686,15 @@ class dr extends ms {
|
|
|
1686
1686
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
|
|
1687
1687
|
}
|
|
1688
1688
|
}
|
|
1689
|
-
class
|
|
1689
|
+
class ks 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 = pr(() => new wr());
|
|
1695
|
+
pr(() => new ks());
|
|
1696
1696
|
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1697
|
-
function
|
|
1697
|
+
function We(e) {
|
|
1698
1698
|
if (!Number.isSafeInteger(e))
|
|
1699
1699
|
throw new Error(`Wrong integer: ${e}`);
|
|
1700
1700
|
}
|
|
@@ -1702,13 +1702,13 @@ 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 pe(e) {
|
|
1706
1706
|
return {
|
|
1707
1707
|
encode: (t) => {
|
|
1708
1708
|
if (!Array.isArray(t) || t.length && typeof t[0] != "number")
|
|
1709
1709
|
throw new Error("alphabet.encode input should be an array of numbers");
|
|
1710
1710
|
return t.map((n) => {
|
|
1711
|
-
if (
|
|
1711
|
+
if (We(n), n < 0 || n >= e.length)
|
|
1712
1712
|
throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${e.length})`);
|
|
1713
1713
|
return e[n];
|
|
1714
1714
|
});
|
|
@@ -1727,7 +1727,7 @@ function ye(e) {
|
|
|
1727
1727
|
}
|
|
1728
1728
|
};
|
|
1729
1729
|
}
|
|
1730
|
-
function
|
|
1730
|
+
function ye(e = "") {
|
|
1731
1731
|
if (typeof e != "string")
|
|
1732
1732
|
throw new Error("join separator should be string");
|
|
1733
1733
|
return {
|
|
@@ -1746,8 +1746,8 @@ function pe(e = "") {
|
|
|
1746
1746
|
}
|
|
1747
1747
|
};
|
|
1748
1748
|
}
|
|
1749
|
-
function
|
|
1750
|
-
if (
|
|
1749
|
+
function ht(e, t = "=") {
|
|
1750
|
+
if (We(e), typeof t != "string")
|
|
1751
1751
|
throw new Error("padding chr should be string");
|
|
1752
1752
|
return {
|
|
1753
1753
|
encode(n) {
|
|
@@ -1776,12 +1776,12 @@ function ft(e, t = "=") {
|
|
|
1776
1776
|
}
|
|
1777
1777
|
};
|
|
1778
1778
|
}
|
|
1779
|
-
function
|
|
1779
|
+
function br(e) {
|
|
1780
1780
|
if (typeof e != "function")
|
|
1781
1781
|
throw new Error("normalize fn should be function");
|
|
1782
1782
|
return { encode: (t) => t, decode: (t) => e(t) };
|
|
1783
1783
|
}
|
|
1784
|
-
function
|
|
1784
|
+
function Rn(e, t, n) {
|
|
1785
1785
|
if (t < 2)
|
|
1786
1786
|
throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);
|
|
1787
1787
|
if (n < 2)
|
|
@@ -1793,7 +1793,7 @@ function Un(e, t, n) {
|
|
|
1793
1793
|
let r = 0;
|
|
1794
1794
|
const i = [], s = Array.from(e);
|
|
1795
1795
|
for (s.forEach((o) => {
|
|
1796
|
-
if (
|
|
1796
|
+
if (We(o), o < 0 || o >= t)
|
|
1797
1797
|
throw new Error(`Wrong integer: ${o}`);
|
|
1798
1798
|
}); ; ) {
|
|
1799
1799
|
let o = 0, c = !0;
|
|
@@ -1814,8 +1814,8 @@ function Un(e, t, n) {
|
|
|
1814
1814
|
i.push(0);
|
|
1815
1815
|
return i.reverse();
|
|
1816
1816
|
}
|
|
1817
|
-
const
|
|
1818
|
-
function
|
|
1817
|
+
const vr = (e, t) => t ? vr(t, e % t) : e, it = (e, t) => e + (t - vr(e, t));
|
|
1818
|
+
function qt(e, t, n, r) {
|
|
1819
1819
|
if (!Array.isArray(e))
|
|
1820
1820
|
throw new Error("convertRadix2: data should be array");
|
|
1821
1821
|
if (t <= 0 || t > 32)
|
|
@@ -1827,7 +1827,7 @@ function Ht(e, t, n, r) {
|
|
|
1827
1827
|
let i = 0, s = 0;
|
|
1828
1828
|
const o = 2 ** n - 1, c = [];
|
|
1829
1829
|
for (const a of e) {
|
|
1830
|
-
if (
|
|
1830
|
+
if (We(a), a >= 2 ** t)
|
|
1831
1831
|
throw new Error(`convertRadix2: invalid data word=${a} from=${t}`);
|
|
1832
1832
|
if (i = i << t | a, s + t > 32)
|
|
1833
1833
|
throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);
|
|
@@ -1841,22 +1841,22 @@ function Ht(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
|
|
1845
|
-
return
|
|
1844
|
+
function _s(e) {
|
|
1845
|
+
return We(e), {
|
|
1846
1846
|
encode: (t) => {
|
|
1847
1847
|
if (!(t instanceof Uint8Array))
|
|
1848
1848
|
throw new Error("radix.encode input should be Uint8Array");
|
|
1849
|
-
return
|
|
1849
|
+
return Rn(Array.from(t), 2 ** 8, e);
|
|
1850
1850
|
},
|
|
1851
1851
|
decode: (t) => {
|
|
1852
1852
|
if (!Array.isArray(t) || t.length && typeof t[0] != "number")
|
|
1853
1853
|
throw new Error("radix.decode input should be array of strings");
|
|
1854
|
-
return Uint8Array.from(
|
|
1854
|
+
return Uint8Array.from(Rn(t, e, 2 ** 8));
|
|
1855
1855
|
}
|
|
1856
1856
|
};
|
|
1857
1857
|
}
|
|
1858
1858
|
function Se(e, t = !1) {
|
|
1859
|
-
if (
|
|
1859
|
+
if (We(e), e <= 0 || e > 32)
|
|
1860
1860
|
throw new Error("radix2: bits should be in (0..32]");
|
|
1861
1861
|
if (it(8, e) > 32 || it(e, 8) > 32)
|
|
1862
1862
|
throw new Error("radix2: carry overflow");
|
|
@@ -1864,16 +1864,16 @@ function Se(e, t = !1) {
|
|
|
1864
1864
|
encode: (n) => {
|
|
1865
1865
|
if (!(n instanceof Uint8Array))
|
|
1866
1866
|
throw new Error("radix2.encode input should be Uint8Array");
|
|
1867
|
-
return
|
|
1867
|
+
return 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
|
}
|
|
1876
|
-
function
|
|
1876
|
+
function Tn(e) {
|
|
1877
1877
|
if (typeof e != "function")
|
|
1878
1878
|
throw new Error("unsafeWrapper fn should be function");
|
|
1879
1879
|
return function(...t) {
|
|
@@ -1883,25 +1883,25 @@ function Ln(e) {
|
|
|
1883
1883
|
}
|
|
1884
1884
|
};
|
|
1885
1885
|
}
|
|
1886
|
-
const
|
|
1887
|
-
de(Se(5),
|
|
1888
|
-
de(Se(5),
|
|
1889
|
-
const he = de(Se(6),
|
|
1886
|
+
const Is = de(Se(4), pe("0123456789ABCDEF"), ye("")), Us = de(Se(5), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), ht(5), ye(""));
|
|
1887
|
+
de(Se(5), pe("0123456789ABCDEFGHIJKLMNOPQRSTUV"), ht(5), ye(""));
|
|
1888
|
+
de(Se(5), pe("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), ye(""), br((e) => e.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
1889
|
+
const he = de(Se(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), ht(6), ye("")), Ls = de(Se(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), ht(6), ye("")), en = (e) => de(_s(58), pe(e), ye("")), Dt = en("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
1890
1890
|
en("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
|
|
1891
1891
|
en("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");
|
|
1892
|
-
const
|
|
1892
|
+
const On = [0, 2, 3, 5, 6, 7, 9, 10, 11], $s = {
|
|
1893
1893
|
encode(e) {
|
|
1894
1894
|
let t = "";
|
|
1895
1895
|
for (let n = 0; n < e.length; n += 8) {
|
|
1896
1896
|
const r = e.subarray(n, n + 8);
|
|
1897
|
-
t +=
|
|
1897
|
+
t += Dt.encode(r).padStart(On[r.length], "1");
|
|
1898
1898
|
}
|
|
1899
1899
|
return t;
|
|
1900
1900
|
},
|
|
1901
1901
|
decode(e) {
|
|
1902
1902
|
let t = [];
|
|
1903
1903
|
for (let n = 0; n < e.length; n += 11) {
|
|
1904
|
-
const r = e.slice(n, n + 11), i =
|
|
1904
|
+
const r = e.slice(n, n + 11), i = On.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,15 +1909,15 @@ const $n = [0, 2, 3, 5, 6, 7, 9, 10, 11], ks = {
|
|
|
1909
1909
|
}
|
|
1910
1910
|
return Uint8Array.from(t);
|
|
1911
1911
|
}
|
|
1912
|
-
},
|
|
1912
|
+
}, jt = de(pe("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), ye("")), Mn = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
1913
1913
|
function Ge(e) {
|
|
1914
1914
|
const t = e >> 25;
|
|
1915
1915
|
let n = (e & 33554431) << 5;
|
|
1916
|
-
for (let r = 0; r <
|
|
1917
|
-
(t >> r & 1) === 1 && (n ^=
|
|
1916
|
+
for (let r = 0; r < Mn.length; r++)
|
|
1917
|
+
(t >> r & 1) === 1 && (n ^= Mn[r]);
|
|
1918
1918
|
return n;
|
|
1919
1919
|
}
|
|
1920
|
-
function
|
|
1920
|
+
function Pn(e, t, n = 1) {
|
|
1921
1921
|
const r = e.length;
|
|
1922
1922
|
let i = 1;
|
|
1923
1923
|
for (let s = 0; s < r; s++) {
|
|
@@ -1933,10 +1933,10 @@ function Rn(e, t, n = 1) {
|
|
|
1933
1933
|
i = Ge(i) ^ s;
|
|
1934
1934
|
for (let s = 0; s < 6; s++)
|
|
1935
1935
|
i = Ge(i);
|
|
1936
|
-
return i ^= n,
|
|
1936
|
+
return i ^= n, jt.encode(qt([i % 2 ** 30], 30, 5, !1));
|
|
1937
1937
|
}
|
|
1938
|
-
function
|
|
1939
|
-
const t = e === "bech32" ? 1 : 734539939, n = Se(5), r = n.decode, i = n.encode, s =
|
|
1938
|
+
function mr(e) {
|
|
1939
|
+
const t = e === "bech32" ? 1 : 734539939, n = Se(5), r = n.decode, i = n.encode, s = Tn(r);
|
|
1940
1940
|
function o(f, u, g = 90) {
|
|
1941
1941
|
if (typeof f != "string")
|
|
1942
1942
|
throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);
|
|
@@ -1945,7 +1945,7 @@ function gr(e) {
|
|
|
1945
1945
|
const w = f.length + 7 + u.length;
|
|
1946
1946
|
if (g !== !1 && w > g)
|
|
1947
1947
|
throw new TypeError(`Length ${w} exceeds limit ${g}`);
|
|
1948
|
-
return f = f.toLowerCase(), `${f}1${
|
|
1948
|
+
return f = f.toLowerCase(), `${f}1${jt.encode(u)}${Pn(f, u, t)}`;
|
|
1949
1949
|
}
|
|
1950
1950
|
function c(f, u = 90) {
|
|
1951
1951
|
if (typeof f != "string")
|
|
@@ -1959,68 +1959,68 @@ function gr(e) {
|
|
|
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
|
-
const
|
|
1962
|
+
const y = f.slice(0, w), h = f.slice(w + 1);
|
|
1963
1963
|
if (h.length < 6)
|
|
1964
1964
|
throw new Error("Data must be at least 6 characters long");
|
|
1965
|
-
const d =
|
|
1966
|
-
if (!h.endsWith(
|
|
1967
|
-
throw new Error(`Invalid checksum in ${f}: expected "${
|
|
1968
|
-
return { prefix:
|
|
1965
|
+
const d = jt.decode(h).slice(0, -6), p = Pn(y, d, t);
|
|
1966
|
+
if (!h.endsWith(p))
|
|
1967
|
+
throw new Error(`Invalid checksum in ${f}: expected "${p}"`);
|
|
1968
|
+
return { prefix: y, words: d };
|
|
1969
1969
|
}
|
|
1970
|
-
const a =
|
|
1970
|
+
const a = Tn(c);
|
|
1971
1971
|
function l(f) {
|
|
1972
1972
|
const { prefix: u, words: g } = c(f, !1);
|
|
1973
1973
|
return { prefix: u, words: g, bytes: r(g) };
|
|
1974
1974
|
}
|
|
1975
1975
|
return { encode: o, decode: c, decodeToBytes: l, decodeUnsafe: a, fromWords: r, fromWordsUnsafe: s, toWords: i };
|
|
1976
1976
|
}
|
|
1977
|
-
const ze =
|
|
1978
|
-
|
|
1979
|
-
const
|
|
1977
|
+
const ze = mr("bech32");
|
|
1978
|
+
mr("bech32m");
|
|
1979
|
+
const Rs = {
|
|
1980
1980
|
encode: (e) => new TextDecoder().decode(e),
|
|
1981
1981
|
decode: (e) => new TextEncoder().encode(e)
|
|
1982
|
-
},
|
|
1982
|
+
}, Ts = de(Se(4), pe("0123456789abcdef"), ye(""), 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:
|
|
1989
|
-
base16:
|
|
1990
|
-
base32:
|
|
1986
|
+
})), Os = {
|
|
1987
|
+
utf8: Rs,
|
|
1988
|
+
hex: Ts,
|
|
1989
|
+
base16: Is,
|
|
1990
|
+
base32: Us,
|
|
1991
1991
|
base64: he,
|
|
1992
|
-
base64url:
|
|
1993
|
-
base58:
|
|
1994
|
-
base58xmr:
|
|
1992
|
+
base64url: Ls,
|
|
1993
|
+
base58: Dt,
|
|
1994
|
+
base58xmr: $s
|
|
1995
1995
|
};
|
|
1996
|
-
`${Object.keys(
|
|
1997
|
-
function
|
|
1996
|
+
`${Object.keys(Os).join(", ")}`;
|
|
1997
|
+
function _t(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 Hn(e) {
|
|
2002
2002
|
if (typeof e != "boolean")
|
|
2003
2003
|
throw new Error(`boolean expected, not ${e}`);
|
|
2004
2004
|
}
|
|
2005
|
-
function
|
|
2005
|
+
function Ms(e) {
|
|
2006
2006
|
return e instanceof Uint8Array || e != null && typeof e == "object" && e.constructor.name === "Uint8Array";
|
|
2007
2007
|
}
|
|
2008
|
-
function
|
|
2009
|
-
if (!
|
|
2008
|
+
function ue(e, ...t) {
|
|
2009
|
+
if (!Ms(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 G = (e) => new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4)),
|
|
2016
|
-
if (
|
|
2015
|
+
const G = (e) => new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4)), Ps = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
2016
|
+
if (!Ps)
|
|
2017
2017
|
throw new Error("Non little-endian hardware is not supported");
|
|
2018
|
-
function
|
|
2018
|
+
function Hs(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);
|
|
2022
2022
|
}
|
|
2023
|
-
function
|
|
2023
|
+
function qs(e, t) {
|
|
2024
2024
|
if (e.length !== t.length)
|
|
2025
2025
|
return !1;
|
|
2026
2026
|
let n = 0;
|
|
@@ -2028,9 +2028,9 @@ function Rs(e, t) {
|
|
|
2028
2028
|
n |= e[r] ^ t[r];
|
|
2029
2029
|
return n === 0;
|
|
2030
2030
|
}
|
|
2031
|
-
const
|
|
2031
|
+
const Ds = /* @__NO_SIDE_EFFECTS__ */ (e, t) => (Object.assign(t, e), t), Ke = 16, js = 283;
|
|
2032
2032
|
function tn(e) {
|
|
2033
|
-
return e << 1 ^
|
|
2033
|
+
return e << 1 ^ js & -(e >> 7);
|
|
2034
2034
|
}
|
|
2035
2035
|
function He(e, t) {
|
|
2036
2036
|
let n = 0;
|
|
@@ -2038,7 +2038,7 @@ function He(e, t) {
|
|
|
2038
2038
|
n ^= e & -(t & 1), e = tn(e);
|
|
2039
2039
|
return n;
|
|
2040
2040
|
}
|
|
2041
|
-
const
|
|
2041
|
+
const zt = /* @__PURE__ */ (() => {
|
|
2042
2042
|
let e = new Uint8Array(256);
|
|
2043
2043
|
for (let n = 0, r = 1; n < 256; n++, r ^= tn(r))
|
|
2044
2044
|
e[n] = r;
|
|
@@ -2049,11 +2049,11 @@ const jt = /* @__PURE__ */ (() => {
|
|
|
2049
2049
|
r |= r << 8, t[e[n]] = (r ^ r >> 4 ^ r >> 5 ^ r >> 6 ^ r >> 7 ^ 99) & 255;
|
|
2050
2050
|
}
|
|
2051
2051
|
return t;
|
|
2052
|
-
})(),
|
|
2053
|
-
function
|
|
2052
|
+
})(), zs = /* @__PURE__ */ zt.map((e, t) => zt.indexOf(t)), Ws = (e) => e << 24 | e >>> 8, It = (e) => e << 8 | e >>> 24;
|
|
2053
|
+
function Er(e, t) {
|
|
2054
2054
|
if (e.length !== 256)
|
|
2055
2055
|
throw new Error("Wrong sbox length");
|
|
2056
|
-
const n = new Uint32Array(256).map((l, f) => t(e[f])), r = n.map(
|
|
2056
|
+
const n = new Uint32Array(256).map((l, f) => t(e[f])), r = n.map(It), i = r.map(It), s = i.map(It), o = new Uint32Array(256 * 256), c = new Uint32Array(256 * 256), a = new Uint16Array(256 * 256);
|
|
2057
2057
|
for (let l = 0; l < 256; l++)
|
|
2058
2058
|
for (let f = 0; f < 256; f++) {
|
|
2059
2059
|
const u = l * 256 + f;
|
|
@@ -2061,14 +2061,14 @@ function wr(e, t) {
|
|
|
2061
2061
|
}
|
|
2062
2062
|
return { sbox: e, sbox2: a, T0: n, T1: r, T2: i, T3: s, T01: o, T23: c };
|
|
2063
2063
|
}
|
|
2064
|
-
const nn = /* @__PURE__ */
|
|
2064
|
+
const nn = /* @__PURE__ */ Er(zt, (e) => He(e, 3) << 24 | e << 16 | e << 8 | He(e, 2)), xr = /* @__PURE__ */ Er(zs, (e) => He(e, 11) << 24 | He(e, 13) << 16 | He(e, 9) << 8 | He(e, 14)), Vs = /* @__PURE__ */ (() => {
|
|
2065
2065
|
const e = new Uint8Array(16);
|
|
2066
2066
|
for (let t = 0, n = 1; t < 16; t++, n = tn(n))
|
|
2067
2067
|
e[t] = n;
|
|
2068
2068
|
return e;
|
|
2069
2069
|
})();
|
|
2070
|
-
function
|
|
2071
|
-
|
|
2070
|
+
function Kr(e) {
|
|
2071
|
+
ue(e);
|
|
2072
2072
|
const t = e.length;
|
|
2073
2073
|
if (![16, 24, 32].includes(t))
|
|
2074
2074
|
throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);
|
|
@@ -2076,12 +2076,12 @@ function vr(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(Ws(a)) ^ Vs[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
|
|
2084
|
-
const t =
|
|
2083
|
+
function Zs(e) {
|
|
2084
|
+
const t = Kr(e), n = t.slice(), r = t.length, { sbox2: i } = nn, { T0: s, T1: o, T2: c, T3: a } = xr;
|
|
2085
2085
|
for (let l = 0; l < r; l += 4)
|
|
2086
2086
|
for (let f = 0; f < 4; f++)
|
|
2087
2087
|
n[l + f] = t[r - l - 4 + f];
|
|
@@ -2098,42 +2098,42 @@ 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 qn(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
|
-
for (let
|
|
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 =
|
|
2106
|
+
for (let y = 0; y < l; y++) {
|
|
2107
|
+
const h = e[a++] ^ xe(o, c, t, n, r, i), d = e[a++] ^ xe(o, c, n, r, i, t), p = e[a++] ^ xe(o, c, r, i, t, n), E = e[a++] ^ xe(o, c, i, t, n, r);
|
|
2108
|
+
t = h, n = d, r = p, i = E;
|
|
2109
2109
|
}
|
|
2110
2110
|
const f = e[a++] ^ oe(s, t, n, r, i), u = e[a++] ^ oe(s, n, r, i, t), g = e[a++] ^ oe(s, r, i, t, n), w = e[a++] ^ oe(s, i, t, n, r);
|
|
2111
2111
|
return { s0: f, s1: u, s2: g, s3: w };
|
|
2112
2112
|
}
|
|
2113
|
-
function
|
|
2114
|
-
const { sbox2: s, T01: o, T23: c } =
|
|
2113
|
+
function Gs(e, t, n, r, i) {
|
|
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
|
-
for (let
|
|
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 =
|
|
2118
|
+
for (let y = 0; y < l; y++) {
|
|
2119
|
+
const h = e[a++] ^ xe(o, c, t, i, r, n), d = e[a++] ^ xe(o, c, n, t, i, r), p = e[a++] ^ xe(o, c, r, n, t, i), E = e[a++] ^ xe(o, c, i, r, n, t);
|
|
2120
|
+
t = h, n = d, r = p, i = E;
|
|
2121
2121
|
}
|
|
2122
2122
|
const f = e[a++] ^ oe(s, t, i, r, n), u = e[a++] ^ oe(s, n, t, i, r), g = e[a++] ^ oe(s, r, n, t, i), w = e[a++] ^ oe(s, i, r, n, t);
|
|
2123
2123
|
return { s0: f, s1: u, s2: g, s3: w };
|
|
2124
2124
|
}
|
|
2125
|
-
function
|
|
2125
|
+
function Nr(e, t) {
|
|
2126
2126
|
if (!t)
|
|
2127
2127
|
return new Uint8Array(e);
|
|
2128
|
-
if (
|
|
2128
|
+
if (ue(t), t.length < e)
|
|
2129
2129
|
throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);
|
|
2130
2130
|
return t;
|
|
2131
2131
|
}
|
|
2132
|
-
function
|
|
2133
|
-
if (
|
|
2132
|
+
function Fs(e) {
|
|
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 Js(e, t, n) {
|
|
2137
2137
|
let r = e.length;
|
|
2138
2138
|
const i = r % Ke;
|
|
2139
2139
|
if (!t && i !== 0)
|
|
@@ -2143,10 +2143,10 @@ function Vs(e, t, n) {
|
|
|
2143
2143
|
let a = Ke - i;
|
|
2144
2144
|
a || (a = Ke), r = r + a;
|
|
2145
2145
|
}
|
|
2146
|
-
const o =
|
|
2146
|
+
const o = Nr(r, n), c = G(o);
|
|
2147
2147
|
return { b: s, o: c, out: o };
|
|
2148
2148
|
}
|
|
2149
|
-
function
|
|
2149
|
+
function Ys(e, t) {
|
|
2150
2150
|
if (!t)
|
|
2151
2151
|
return e;
|
|
2152
2152
|
const n = e.length;
|
|
@@ -2161,7 +2161,7 @@ function Ws(e, t) {
|
|
|
2161
2161
|
throw new Error("aes/pcks5: wrong padding");
|
|
2162
2162
|
return i;
|
|
2163
2163
|
}
|
|
2164
|
-
function
|
|
2164
|
+
function Xs(e) {
|
|
2165
2165
|
const t = new Uint8Array(16), n = G(t);
|
|
2166
2166
|
t.set(e);
|
|
2167
2167
|
const r = Ke - e.length;
|
|
@@ -2169,88 +2169,88 @@ function Zs(e) {
|
|
|
2169
2169
|
t[i] = r;
|
|
2170
2170
|
return n;
|
|
2171
2171
|
}
|
|
2172
|
-
const
|
|
2173
|
-
|
|
2172
|
+
const Sr = /* @__PURE__ */ Ds({ blockSize: 16, nonceLength: 16 }, function(t, n, r = {}) {
|
|
2173
|
+
ue(t), ue(n, 16);
|
|
2174
2174
|
const i = !r.disablePadding;
|
|
2175
2175
|
return {
|
|
2176
2176
|
encrypt: (s, o) => {
|
|
2177
|
-
const c =
|
|
2178
|
-
let g = u[0], w = u[1],
|
|
2177
|
+
const c = Kr(t), { b: a, o: l, out: f } = Js(s, i, o), u = G(n);
|
|
2178
|
+
let g = u[0], w = u[1], y = u[2], h = u[3], d = 0;
|
|
2179
2179
|
for (; d + 4 <= a.length; )
|
|
2180
|
-
g ^= a[d + 0], w ^= a[d + 1],
|
|
2180
|
+
g ^= a[d + 0], w ^= a[d + 1], y ^= a[d + 2], h ^= a[d + 3], { s0: g, s1: w, s2: y, s3: h } = qn(c, g, w, y, h), l[d++] = g, l[d++] = w, l[d++] = y, l[d++] = h;
|
|
2181
2181
|
if (i) {
|
|
2182
|
-
const
|
|
2183
|
-
g ^=
|
|
2182
|
+
const p = Xs(s.subarray(d * 4));
|
|
2183
|
+
g ^= p[0], w ^= p[1], y ^= p[2], h ^= p[3], { s0: g, s1: w, s2: y, s3: h } = qn(c, g, w, y, h), l[d++] = g, l[d++] = w, l[d++] = y, l[d++] = h;
|
|
2184
2184
|
}
|
|
2185
2185
|
return c.fill(0), f;
|
|
2186
2186
|
},
|
|
2187
2187
|
decrypt: (s, o) => {
|
|
2188
|
-
|
|
2189
|
-
const c =
|
|
2190
|
-
let g = a[0], w = a[1],
|
|
2188
|
+
Fs(s);
|
|
2189
|
+
const c = Zs(t), a = G(n), l = Nr(s.length, o), f = G(s), u = G(l);
|
|
2190
|
+
let g = a[0], w = a[1], y = a[2], h = a[3];
|
|
2191
2191
|
for (let d = 0; d + 4 <= f.length; ) {
|
|
2192
|
-
const
|
|
2193
|
-
g = f[d + 0], w = f[d + 1],
|
|
2194
|
-
const { s0: B, s1: m, s2: x, s3: K } =
|
|
2195
|
-
u[d++] = B ^
|
|
2192
|
+
const p = g, E = w, S = y, I = h;
|
|
2193
|
+
g = f[d + 0], w = f[d + 1], y = f[d + 2], h = f[d + 3];
|
|
2194
|
+
const { s0: B, s1: m, s2: x, s3: K } = Gs(c, g, w, y, h);
|
|
2195
|
+
u[d++] = B ^ p, u[d++] = m ^ E, u[d++] = x ^ S, u[d++] = K ^ I;
|
|
2196
2196
|
}
|
|
2197
|
-
return c.fill(0),
|
|
2197
|
+
return c.fill(0), Ys(l, i);
|
|
2198
2198
|
}
|
|
2199
2199
|
};
|
|
2200
|
-
}),
|
|
2201
|
-
|
|
2200
|
+
}), Ar = (e) => Uint8Array.from(e.split("").map((t) => t.charCodeAt(0))), Qs = Ar("expand 16-byte k"), eo = Ar("expand 32-byte k"), to = G(Qs), Cr = G(eo);
|
|
2201
|
+
Cr.slice();
|
|
2202
2202
|
function L(e, t) {
|
|
2203
2203
|
return e << t | e >>> 32 - t;
|
|
2204
2204
|
}
|
|
2205
|
-
function
|
|
2205
|
+
function Wt(e) {
|
|
2206
2206
|
return e.byteOffset % 4 === 0;
|
|
2207
2207
|
}
|
|
2208
|
-
const Xe = 64,
|
|
2209
|
-
function
|
|
2210
|
-
const a = i.length, l = new Uint8Array(Xe), f = G(l), u =
|
|
2211
|
-
for (let
|
|
2212
|
-
if (e(t, n, r, f, o, c), o >=
|
|
2208
|
+
const Xe = 64, no = 16, Br = 2 ** 32 - 1, Dn = new Uint32Array();
|
|
2209
|
+
function ro(e, t, n, r, i, s, o, c) {
|
|
2210
|
+
const a = i.length, l = new Uint8Array(Xe), f = G(l), u = Wt(i) && Wt(s), g = u ? G(i) : Dn, w = u ? G(s) : Dn;
|
|
2211
|
+
for (let y = 0; y < a; o++) {
|
|
2212
|
+
if (e(t, n, r, f, o, c), o >= Br)
|
|
2213
2213
|
throw new Error("arx: counter overflow");
|
|
2214
|
-
const h = Math.min(Xe, a -
|
|
2214
|
+
const h = Math.min(Xe, a - y);
|
|
2215
2215
|
if (u && h === Xe) {
|
|
2216
|
-
const d =
|
|
2217
|
-
if (
|
|
2216
|
+
const d = y / 4;
|
|
2217
|
+
if (y % 4 !== 0)
|
|
2218
2218
|
throw new Error("arx: invalid block position");
|
|
2219
|
-
for (let
|
|
2220
|
-
E = d +
|
|
2221
|
-
|
|
2219
|
+
for (let p = 0, E; p < no; p++)
|
|
2220
|
+
E = d + p, w[E] = g[E] ^ f[p];
|
|
2221
|
+
y += Xe;
|
|
2222
2222
|
continue;
|
|
2223
2223
|
}
|
|
2224
|
-
for (let d = 0,
|
|
2225
|
-
|
|
2226
|
-
|
|
2224
|
+
for (let d = 0, p; d < h; d++)
|
|
2225
|
+
p = y + d, s[p] = i[p] ^ l[d];
|
|
2226
|
+
y += h;
|
|
2227
2227
|
}
|
|
2228
2228
|
}
|
|
2229
|
-
function
|
|
2230
|
-
const { allowShortKeys: n, extendNonceFn: r, counterLength: i, counterRight: s, rounds: o } =
|
|
2229
|
+
function io(e, t) {
|
|
2230
|
+
const { allowShortKeys: n, extendNonceFn: r, counterLength: i, counterRight: s, rounds: o } = Hs({ allowShortKeys: !1, counterLength: 8, counterRight: !1, rounds: 20 }, t);
|
|
2231
2231
|
if (typeof e != "function")
|
|
2232
2232
|
throw new Error("core must be a function");
|
|
2233
|
-
return
|
|
2234
|
-
|
|
2233
|
+
return _t(i), _t(o), Hn(s), Hn(n), (c, a, l, f, u = 0) => {
|
|
2234
|
+
ue(c), ue(a), ue(l);
|
|
2235
2235
|
const g = l.length;
|
|
2236
|
-
if (f || (f = new Uint8Array(g)),
|
|
2236
|
+
if (f || (f = new Uint8Array(g)), ue(f), _t(u), u < 0 || u >= Br)
|
|
2237
2237
|
throw new Error("arx: counter overflow");
|
|
2238
2238
|
if (f.length < g)
|
|
2239
2239
|
throw new Error(`arx: output (${f.length}) is shorter than data (${g})`);
|
|
2240
2240
|
const w = [];
|
|
2241
|
-
let
|
|
2242
|
-
if (
|
|
2243
|
-
h = c.slice(), w.push(h), d =
|
|
2244
|
-
else if (
|
|
2245
|
-
h = new Uint8Array(32), h.set(c), h.set(c, 16), d =
|
|
2241
|
+
let y = c.length, h, d;
|
|
2242
|
+
if (y === 32)
|
|
2243
|
+
h = c.slice(), w.push(h), d = Cr;
|
|
2244
|
+
else if (y === 16 && n)
|
|
2245
|
+
h = new Uint8Array(32), h.set(c), h.set(c, 16), d = to, w.push(h);
|
|
2246
2246
|
else
|
|
2247
|
-
throw new Error(`arx: invalid 32-byte key, got length=${
|
|
2248
|
-
|
|
2249
|
-
const
|
|
2247
|
+
throw new Error(`arx: invalid 32-byte key, got length=${y}`);
|
|
2248
|
+
Wt(a) || (a = a.slice(), w.push(a));
|
|
2249
|
+
const p = G(h);
|
|
2250
2250
|
if (r) {
|
|
2251
2251
|
if (a.length !== 24)
|
|
2252
2252
|
throw new Error("arx: extended nonce must be 24 bytes");
|
|
2253
|
-
r(d,
|
|
2253
|
+
r(d, p, G(a.subarray(0, 16)), p), a = a.subarray(16);
|
|
2254
2254
|
}
|
|
2255
2255
|
const E = 16 - i;
|
|
2256
2256
|
if (E !== a.length)
|
|
@@ -2260,24 +2260,24 @@ function Qs(e, t) {
|
|
|
2260
2260
|
I.set(a, s ? 0 : 12 - a.length), a = I, w.push(a);
|
|
2261
2261
|
}
|
|
2262
2262
|
const S = G(a);
|
|
2263
|
-
for (
|
|
2263
|
+
for (ro(e, d, p, S, l, f, u, o); w.length > 0; )
|
|
2264
2264
|
w.pop().fill(0);
|
|
2265
2265
|
return f;
|
|
2266
2266
|
};
|
|
2267
2267
|
}
|
|
2268
|
-
function
|
|
2269
|
-
let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1], g = t[2], w = t[3],
|
|
2268
|
+
function so(e, t, n, r, i, s = 20) {
|
|
2269
|
+
let o = e[0], c = e[1], a = e[2], l = e[3], f = t[0], u = t[1], g = t[2], w = t[3], y = t[4], h = t[5], d = t[6], p = t[7], E = i, S = n[0], I = n[1], B = n[2], m = o, x = c, K = a, M = l, _ = f, A = u, R = g, T = w, q = y, b = h, v = d, N = p, k = E, C = S, U = I, O = B;
|
|
2270
2270
|
for (let ee = 0; ee < s; ee += 2)
|
|
2271
|
-
m = m + _ | 0, k = L(k ^ m, 16),
|
|
2271
|
+
m = m + _ | 0, k = L(k ^ m, 16), q = q + k | 0, _ = L(_ ^ q, 12), m = m + _ | 0, k = L(k ^ m, 8), q = q + k | 0, _ = L(_ ^ 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, U = L(U ^ K, 16), v = v + U | 0, R = L(R ^ v, 12), K = K + R | 0, U = L(U ^ K, 8), v = v + U | 0, R = L(R ^ v, 7), M = M + T | 0, O = L(O ^ M, 16), N = N + O | 0, T = L(T ^ N, 12), M = M + T | 0, O = L(O ^ M, 8), N = N + O | 0, T = L(T ^ N, 7), m = m + A | 0, O = L(O ^ m, 16), v = v + O | 0, A = L(A ^ v, 12), m = m + A | 0, O = L(O ^ m, 8), v = v + O | 0, A = L(A ^ v, 7), x = x + R | 0, k = L(k ^ x, 16), N = N + k | 0, R = L(R ^ N, 12), x = x + R | 0, k = L(k ^ x, 8), N = N + k | 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 + _ | 0, U = L(U ^ M, 16), b = b + U | 0, _ = L(_ ^ b, 12), M = M + _ | 0, U = L(U ^ M, 8), b = b + U | 0, _ = L(_ ^ b, 7);
|
|
2272
2272
|
let $ = 0;
|
|
2273
|
-
r[$++] = o + m | 0, r[$++] = c + x | 0, r[$++] = a + K | 0, r[$++] = l + M | 0, r[$++] = f + _ | 0, r[$++] = u + A | 0, r[$++] = g +
|
|
2273
|
+
r[$++] = o + m | 0, r[$++] = c + x | 0, r[$++] = a + K | 0, r[$++] = l + M | 0, r[$++] = f + _ | 0, r[$++] = u + A | 0, r[$++] = g + R | 0, r[$++] = w + T | 0, r[$++] = y + q | 0, r[$++] = h + b | 0, r[$++] = d + v | 0, r[$++] = p + N | 0, r[$++] = E + k | 0, r[$++] = S + C | 0, r[$++] = I + U | 0, r[$++] = B + O | 0;
|
|
2274
2274
|
}
|
|
2275
|
-
const
|
|
2275
|
+
const kr = /* @__PURE__ */ io(so, {
|
|
2276
2276
|
counterRight: !1,
|
|
2277
2277
|
counterLength: 4,
|
|
2278
2278
|
allowShortKeys: !1
|
|
2279
2279
|
});
|
|
2280
|
-
class
|
|
2280
|
+
class _r extends dr {
|
|
2281
2281
|
constructor(t, n) {
|
|
2282
2282
|
super(), this.finished = !1, this.destroyed = !1, se.hash(t);
|
|
2283
2283
|
const r = Je(n);
|
|
@@ -2312,61 +2312,65 @@ class Ar extends ur {
|
|
|
2312
2312
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
2313
2313
|
}
|
|
2314
2314
|
}
|
|
2315
|
-
const
|
|
2316
|
-
|
|
2315
|
+
const dt = (e, t, n) => new _r(e, t).update(n).digest();
|
|
2316
|
+
dt.create = (e, t) => new _r(e, t);
|
|
2317
2317
|
function rn(e, t, n) {
|
|
2318
|
-
return se.hash(e), n === void 0 && (n = new Uint8Array(e.outputLen)),
|
|
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]), jn = new Uint8Array();
|
|
2321
|
+
function Ir(e, t, n, r = 32) {
|
|
2322
2322
|
if (se.hash(e), se.number(r), r > 255 * e.outputLen)
|
|
2323
2323
|
throw new Error("Length should be <= 255*HashLen");
|
|
2324
2324
|
const i = Math.ceil(r / e.outputLen);
|
|
2325
|
-
n === void 0 && (n =
|
|
2326
|
-
const s = new Uint8Array(i * e.outputLen), o =
|
|
2325
|
+
n === void 0 && (n = jn);
|
|
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 ? jn : 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 oo = Object.defineProperty, P = (e, t) => {
|
|
2332
2332
|
for (var n in t)
|
|
2333
|
-
|
|
2334
|
-
},
|
|
2335
|
-
function
|
|
2336
|
-
if (!
|
|
2333
|
+
oo(e, n, { get: t[n], enumerable: !0 });
|
|
2334
|
+
}, Te = Symbol("verified"), ao = (e) => e instanceof Object;
|
|
2335
|
+
function pt(e) {
|
|
2336
|
+
if (!ao(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];
|
|
2340
2340
|
if (!Array.isArray(n))
|
|
2341
2341
|
return !1;
|
|
2342
2342
|
for (let r = 0; r < n.length; r++)
|
|
2343
|
-
if (typeof n[r]
|
|
2343
|
+
if (typeof n[r] != "string")
|
|
2344
2344
|
return !1;
|
|
2345
2345
|
}
|
|
2346
2346
|
return !0;
|
|
2347
2347
|
}
|
|
2348
|
-
var
|
|
2349
|
-
|
|
2350
|
-
Queue: () =>
|
|
2351
|
-
QueueNode: () =>
|
|
2348
|
+
var co = {};
|
|
2349
|
+
P(co, {
|
|
2350
|
+
Queue: () => ho,
|
|
2351
|
+
QueueNode: () => Ur,
|
|
2352
2352
|
binarySearch: () => sn,
|
|
2353
|
-
insertEventIntoAscendingList: () =>
|
|
2354
|
-
insertEventIntoDescendingList: () =>
|
|
2355
|
-
normalizeURL: () =>
|
|
2356
|
-
utf8Decoder: () =>
|
|
2353
|
+
insertEventIntoAscendingList: () => fo,
|
|
2354
|
+
insertEventIntoDescendingList: () => lo,
|
|
2355
|
+
normalizeURL: () => uo,
|
|
2356
|
+
utf8Decoder: () => le,
|
|
2357
2357
|
utf8Encoder: () => ne
|
|
2358
2358
|
});
|
|
2359
|
-
var
|
|
2360
|
-
function
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2359
|
+
var le = new TextDecoder("utf-8"), ne = new TextEncoder();
|
|
2360
|
+
function uo(e) {
|
|
2361
|
+
try {
|
|
2362
|
+
e.indexOf("://") === -1 && (e = "wss://" + e);
|
|
2363
|
+
let t = new URL(e);
|
|
2364
|
+
return t.pathname = t.pathname.replace(/\/+/g, "/"), t.pathname.endsWith("/") && (t.pathname = t.pathname.slice(0, -1)), (t.port === "80" && t.protocol === "ws:" || t.port === "443" && t.protocol === "wss:") && (t.port = ""), t.searchParams.sort(), t.hash = "", t.toString();
|
|
2365
|
+
} catch {
|
|
2366
|
+
throw new Error(`Invalid URL: ${e}`);
|
|
2367
|
+
}
|
|
2364
2368
|
}
|
|
2365
|
-
function
|
|
2369
|
+
function lo(e, t) {
|
|
2366
2370
|
const [n, r] = sn(e, (i) => t.id === i.id ? 0 : t.created_at === i.created_at ? -1 : i.created_at - t.created_at);
|
|
2367
2371
|
return r || e.splice(n, 0, t), e;
|
|
2368
2372
|
}
|
|
2369
|
-
function
|
|
2373
|
+
function fo(e, t) {
|
|
2370
2374
|
const [n, r] = sn(e, (i) => t.id === i.id ? 0 : t.created_at === i.created_at ? -1 : t.created_at - i.created_at);
|
|
2371
2375
|
return r || e.splice(n, 0, t), e;
|
|
2372
2376
|
}
|
|
@@ -2380,21 +2384,21 @@ function sn(e, t) {
|
|
|
2380
2384
|
}
|
|
2381
2385
|
return [n, !1];
|
|
2382
2386
|
}
|
|
2383
|
-
var
|
|
2387
|
+
var Ur = class {
|
|
2384
2388
|
constructor(e) {
|
|
2385
2389
|
J(this, "value");
|
|
2386
2390
|
J(this, "next", null);
|
|
2387
2391
|
J(this, "prev", null);
|
|
2388
2392
|
this.value = e;
|
|
2389
2393
|
}
|
|
2390
|
-
},
|
|
2394
|
+
}, ho = class {
|
|
2391
2395
|
constructor() {
|
|
2392
2396
|
J(this, "first");
|
|
2393
2397
|
J(this, "last");
|
|
2394
2398
|
this.first = null, this.last = null;
|
|
2395
2399
|
}
|
|
2396
2400
|
enqueue(e) {
|
|
2397
|
-
const t = new
|
|
2401
|
+
const t = new Ur(e);
|
|
2398
2402
|
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;
|
|
2399
2403
|
}
|
|
2400
2404
|
dequeue() {
|
|
@@ -2405,165 +2409,167 @@ var Br = class {
|
|
|
2405
2409
|
return this.first = null, this.last = null, t.value;
|
|
2406
2410
|
}
|
|
2407
2411
|
const e = this.first;
|
|
2408
|
-
return this.first = e.next, e.value;
|
|
2412
|
+
return this.first = e.next, this.first && (this.first.prev = null), e.value;
|
|
2409
2413
|
}
|
|
2410
|
-
},
|
|
2414
|
+
}, po = class {
|
|
2411
2415
|
generateSecretKey() {
|
|
2412
2416
|
return Ze.utils.randomPrivateKey();
|
|
2413
2417
|
}
|
|
2414
2418
|
getPublicKey(e) {
|
|
2415
|
-
return
|
|
2419
|
+
return H(Ze.getPublicKey(e));
|
|
2416
2420
|
}
|
|
2417
2421
|
finalizeEvent(e, t) {
|
|
2418
2422
|
const n = e;
|
|
2419
|
-
return n.pubkey =
|
|
2423
|
+
return n.pubkey = H(Ze.getPublicKey(t)), n.id = qe(n), n.sig = H(Ze.sign(qe(n), t)), n[Te] = !0, n;
|
|
2420
2424
|
}
|
|
2421
2425
|
verifyEvent(e) {
|
|
2422
|
-
if (typeof e[
|
|
2423
|
-
return e[
|
|
2426
|
+
if (typeof e[Te] == "boolean")
|
|
2427
|
+
return e[Te];
|
|
2424
2428
|
const t = qe(e);
|
|
2425
2429
|
if (t !== e.id)
|
|
2426
|
-
return e[
|
|
2430
|
+
return e[Te] = !1, !1;
|
|
2427
2431
|
try {
|
|
2428
2432
|
const n = Ze.verify(e.sig, t, e.pubkey);
|
|
2429
|
-
return e[
|
|
2433
|
+
return e[Te] = n, n;
|
|
2430
2434
|
} catch {
|
|
2431
|
-
return e[
|
|
2435
|
+
return e[Te] = !1, !1;
|
|
2432
2436
|
}
|
|
2433
2437
|
}
|
|
2434
2438
|
};
|
|
2435
|
-
function
|
|
2436
|
-
if (!
|
|
2439
|
+
function yo(e) {
|
|
2440
|
+
if (!pt(e))
|
|
2437
2441
|
throw new Error("can't serialize event with wrong or missing properties");
|
|
2438
2442
|
return JSON.stringify([0, e.pubkey, e.created_at, e.kind, e.tags, e.content]);
|
|
2439
2443
|
}
|
|
2440
2444
|
function qe(e) {
|
|
2441
|
-
let t = fe(ne.encode(
|
|
2442
|
-
return
|
|
2443
|
-
}
|
|
2444
|
-
var yt = new
|
|
2445
|
-
|
|
2446
|
-
Application: () =>
|
|
2447
|
-
BadgeAward: () =>
|
|
2448
|
-
BadgeDefinition: () =>
|
|
2449
|
-
BlockedRelaysList: () =>
|
|
2450
|
-
BookmarkList: () =>
|
|
2451
|
-
Bookmarksets: () =>
|
|
2452
|
-
Calendar: () =>
|
|
2453
|
-
CalendarEventRSVP: () =>
|
|
2454
|
-
ChannelCreation: () =>
|
|
2455
|
-
ChannelHideMessage: () =>
|
|
2456
|
-
ChannelMessage: () =>
|
|
2457
|
-
ChannelMetadata: () =>
|
|
2458
|
-
ChannelMuteUser: () =>
|
|
2459
|
-
ClassifiedListing: () =>
|
|
2460
|
-
ClientAuth: () =>
|
|
2461
|
-
CommunitiesList: () =>
|
|
2462
|
-
CommunityDefinition: () =>
|
|
2463
|
-
CommunityPostApproval: () =>
|
|
2464
|
-
Contacts: () =>
|
|
2465
|
-
CreateOrUpdateProduct: () =>
|
|
2466
|
-
CreateOrUpdateStall: () =>
|
|
2467
|
-
Curationsets: () =>
|
|
2468
|
-
Date: () =>
|
|
2469
|
-
DirectMessageRelaysList: () =>
|
|
2470
|
-
DraftClassifiedListing: () =>
|
|
2471
|
-
DraftLong: () =>
|
|
2472
|
-
Emojisets: () =>
|
|
2473
|
-
EncryptedDirectMessage: () =>
|
|
2474
|
-
EventDeletion: () =>
|
|
2475
|
-
FileMetadata: () =>
|
|
2476
|
-
FileServerPreference: () =>
|
|
2477
|
-
Followsets: () =>
|
|
2478
|
-
GenericRepost: () =>
|
|
2479
|
-
Genericlists: () =>
|
|
2480
|
-
GiftWrap: () =>
|
|
2481
|
-
HTTPAuth: () =>
|
|
2482
|
-
Handlerinformation: () =>
|
|
2483
|
-
Handlerrecommendation: () =>
|
|
2484
|
-
Highlights: () =>
|
|
2485
|
-
InterestsList: () =>
|
|
2486
|
-
Interestsets: () =>
|
|
2487
|
-
JobFeedback: () =>
|
|
2488
|
-
JobRequest: () =>
|
|
2489
|
-
JobResult: () =>
|
|
2490
|
-
Label: () =>
|
|
2491
|
-
LightningPubRPC: () =>
|
|
2492
|
-
LiveChatMessage: () =>
|
|
2493
|
-
LiveEvent: () =>
|
|
2494
|
-
LongFormArticle: () =>
|
|
2495
|
-
Metadata: () =>
|
|
2496
|
-
Mutelist: () =>
|
|
2497
|
-
NWCWalletInfo: () =>
|
|
2498
|
-
NWCWalletRequest: () =>
|
|
2499
|
-
NWCWalletResponse: () =>
|
|
2500
|
-
NostrConnect: () =>
|
|
2501
|
-
OpenTimestamps: () =>
|
|
2502
|
-
Pinlist: () =>
|
|
2503
|
-
PrivateDirectMessage: () =>
|
|
2504
|
-
ProblemTracker: () =>
|
|
2505
|
-
ProfileBadges: () =>
|
|
2506
|
-
PublicChatsList: () =>
|
|
2507
|
-
Reaction: () =>
|
|
2508
|
-
RecommendRelay: () =>
|
|
2509
|
-
RelayList: () =>
|
|
2510
|
-
Relaysets: () =>
|
|
2511
|
-
Report: () =>
|
|
2512
|
-
Reporting: () =>
|
|
2513
|
-
Repost: () =>
|
|
2514
|
-
Seal: () =>
|
|
2515
|
-
SearchRelaysList: () =>
|
|
2516
|
-
ShortTextNote: () =>
|
|
2517
|
-
Time: () =>
|
|
2518
|
-
UserEmojiList: () =>
|
|
2519
|
-
UserStatuses: () =>
|
|
2520
|
-
Zap: () =>
|
|
2521
|
-
ZapGoal: () =>
|
|
2522
|
-
ZapRequest: () =>
|
|
2523
|
-
classifyKind: () =>
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2445
|
+
let t = fe(ne.encode(yo(e)));
|
|
2446
|
+
return H(t);
|
|
2447
|
+
}
|
|
2448
|
+
var yt = new po(), ke = yt.generateSecretKey, ae = yt.getPublicKey, Q = yt.finalizeEvent, gt = yt.verifyEvent, go = {};
|
|
2449
|
+
P(go, {
|
|
2450
|
+
Application: () => ga,
|
|
2451
|
+
BadgeAward: () => So,
|
|
2452
|
+
BadgeDefinition: () => ua,
|
|
2453
|
+
BlockedRelaysList: () => Zo,
|
|
2454
|
+
BookmarkList: () => zo,
|
|
2455
|
+
Bookmarksets: () => oa,
|
|
2456
|
+
Calendar: () => Ka,
|
|
2457
|
+
CalendarEventRSVP: () => Na,
|
|
2458
|
+
ChannelCreation: () => Mr,
|
|
2459
|
+
ChannelHideMessage: () => qr,
|
|
2460
|
+
ChannelMessage: () => Hr,
|
|
2461
|
+
ChannelMetadata: () => Pr,
|
|
2462
|
+
ChannelMuteUser: () => Dr,
|
|
2463
|
+
ClassifiedListing: () => va,
|
|
2464
|
+
ClientAuth: () => zr,
|
|
2465
|
+
CommunitiesList: () => Wo,
|
|
2466
|
+
CommunityDefinition: () => Ca,
|
|
2467
|
+
CommunityPostApproval: () => Lo,
|
|
2468
|
+
Contacts: () => xo,
|
|
2469
|
+
CreateOrUpdateProduct: () => ha,
|
|
2470
|
+
CreateOrUpdateStall: () => fa,
|
|
2471
|
+
Curationsets: () => aa,
|
|
2472
|
+
Date: () => Ea,
|
|
2473
|
+
DirectMessageRelaysList: () => Yo,
|
|
2474
|
+
DraftClassifiedListing: () => ma,
|
|
2475
|
+
DraftLong: () => pa,
|
|
2476
|
+
Emojisets: () => ya,
|
|
2477
|
+
EncryptedDirectMessage: () => Ko,
|
|
2478
|
+
EventDeletion: () => No,
|
|
2479
|
+
FileMetadata: () => Co,
|
|
2480
|
+
FileServerPreference: () => Xo,
|
|
2481
|
+
Followsets: () => ra,
|
|
2482
|
+
GenericRepost: () => un,
|
|
2483
|
+
Genericlists: () => ia,
|
|
2484
|
+
GiftWrap: () => jr,
|
|
2485
|
+
HTTPAuth: () => ln,
|
|
2486
|
+
Handlerinformation: () => Aa,
|
|
2487
|
+
Handlerrecommendation: () => Sa,
|
|
2488
|
+
Highlights: () => Ho,
|
|
2489
|
+
InterestsList: () => Fo,
|
|
2490
|
+
Interestsets: () => la,
|
|
2491
|
+
JobFeedback: () => To,
|
|
2492
|
+
JobRequest: () => $o,
|
|
2493
|
+
JobResult: () => Ro,
|
|
2494
|
+
Label: () => Uo,
|
|
2495
|
+
LightningPubRPC: () => ea,
|
|
2496
|
+
LiveChatMessage: () => Bo,
|
|
2497
|
+
LiveEvent: () => wa,
|
|
2498
|
+
LongFormArticle: () => da,
|
|
2499
|
+
Metadata: () => mo,
|
|
2500
|
+
Mutelist: () => qo,
|
|
2501
|
+
NWCWalletInfo: () => Qo,
|
|
2502
|
+
NWCWalletRequest: () => Wr,
|
|
2503
|
+
NWCWalletResponse: () => ta,
|
|
2504
|
+
NostrConnect: () => na,
|
|
2505
|
+
OpenTimestamps: () => Ao,
|
|
2506
|
+
Pinlist: () => Do,
|
|
2507
|
+
PrivateDirectMessage: () => Or,
|
|
2508
|
+
ProblemTracker: () => ko,
|
|
2509
|
+
ProfileBadges: () => ca,
|
|
2510
|
+
PublicChatsList: () => Vo,
|
|
2511
|
+
Reaction: () => cn,
|
|
2512
|
+
RecommendRelay: () => Eo,
|
|
2513
|
+
RelayList: () => jo,
|
|
2514
|
+
Relaysets: () => sa,
|
|
2515
|
+
Report: () => _o,
|
|
2516
|
+
Reporting: () => Io,
|
|
2517
|
+
Repost: () => an,
|
|
2518
|
+
Seal: () => Tr,
|
|
2519
|
+
SearchRelaysList: () => Go,
|
|
2520
|
+
ShortTextNote: () => Rr,
|
|
2521
|
+
Time: () => xa,
|
|
2522
|
+
UserEmojiList: () => Jo,
|
|
2523
|
+
UserStatuses: () => ba,
|
|
2524
|
+
Zap: () => Po,
|
|
2525
|
+
ZapGoal: () => Oo,
|
|
2526
|
+
ZapRequest: () => Mo,
|
|
2527
|
+
classifyKind: () => bo,
|
|
2528
|
+
isAddressableKind: () => wt,
|
|
2529
|
+
isEphemeralKind: () => $r,
|
|
2530
|
+
isKind: () => vo,
|
|
2531
|
+
isParameterizedReplaceableKind: () => wo,
|
|
2532
|
+
isRegularKind: () => Lr,
|
|
2533
|
+
isReplaceableKind: () => on
|
|
2529
2534
|
});
|
|
2530
|
-
function
|
|
2535
|
+
function Lr(e) {
|
|
2531
2536
|
return 1e3 <= e && e < 1e4 || [1, 2, 4, 5, 6, 7, 8, 16, 40, 41, 42, 43, 44].includes(e);
|
|
2532
2537
|
}
|
|
2533
|
-
function
|
|
2538
|
+
function on(e) {
|
|
2534
2539
|
return [0, 3].includes(e) || 1e4 <= e && e < 2e4;
|
|
2535
2540
|
}
|
|
2536
|
-
function
|
|
2541
|
+
function $r(e) {
|
|
2537
2542
|
return 2e4 <= e && e < 3e4;
|
|
2538
2543
|
}
|
|
2539
|
-
function
|
|
2544
|
+
function wt(e) {
|
|
2540
2545
|
return 3e4 <= e && e < 4e4;
|
|
2541
2546
|
}
|
|
2542
|
-
|
|
2543
|
-
|
|
2547
|
+
var wo = wt;
|
|
2548
|
+
function bo(e) {
|
|
2549
|
+
return Lr(e) ? "regular" : on(e) ? "replaceable" : $r(e) ? "ephemeral" : wt(e) ? "parameterized" : "unknown";
|
|
2544
2550
|
}
|
|
2545
|
-
function
|
|
2551
|
+
function vo(e, t) {
|
|
2546
2552
|
const n = t instanceof Array ? t : [t];
|
|
2547
|
-
return
|
|
2548
|
-
}
|
|
2549
|
-
var
|
|
2550
|
-
|
|
2551
|
-
getHex64: () =>
|
|
2552
|
-
getInt: () =>
|
|
2553
|
-
getSubscriptionId: () =>
|
|
2554
|
-
matchEventId: () =>
|
|
2555
|
-
matchEventKind: () =>
|
|
2556
|
-
matchEventPubkey: () =>
|
|
2553
|
+
return pt(e) && n.includes(e.kind) || !1;
|
|
2554
|
+
}
|
|
2555
|
+
var mo = 0, Rr = 1, Eo = 2, xo = 3, Ko = 4, No = 5, an = 6, cn = 7, So = 8, Tr = 13, Or = 14, un = 16, Mr = 40, Pr = 41, Hr = 42, qr = 43, Dr = 44, Ao = 1040, jr = 1059, Co = 1063, Bo = 1311, ko = 1971, _o = 1984, Io = 1984, Uo = 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, Go = 10007, Fo = 10015, Jo = 10030, Yo = 10050, Xo = 10096, Qo = 13194, ea = 21e3, zr = 22242, Wr = 23194, ta = 23195, na = 24133, ln = 27235, ra = 3e4, ia = 30001, sa = 30002, oa = 30003, aa = 30004, ca = 30008, ua = 30009, la = 30015, fa = 30017, ha = 30018, da = 30023, pa = 30024, ya = 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, Ba = {};
|
|
2556
|
+
P(Ba, {
|
|
2557
|
+
getHex64: () => fn,
|
|
2558
|
+
getInt: () => Vr,
|
|
2559
|
+
getSubscriptionId: () => ka,
|
|
2560
|
+
matchEventId: () => _a,
|
|
2561
|
+
matchEventKind: () => Ua,
|
|
2562
|
+
matchEventPubkey: () => Ia
|
|
2557
2563
|
});
|
|
2558
|
-
function
|
|
2564
|
+
function fn(e, t) {
|
|
2559
2565
|
let n = t.length + 3, r = e.indexOf(`"${t}":`) + n, i = e.slice(r).indexOf('"') + r + 1;
|
|
2560
2566
|
return e.slice(i, i + 64);
|
|
2561
2567
|
}
|
|
2562
|
-
function
|
|
2568
|
+
function Vr(e, t) {
|
|
2563
2569
|
let n = t.length, r = e.indexOf(`"${t}":`) + n + 3, i = e.slice(r), s = Math.min(i.indexOf(","), i.indexOf("}"));
|
|
2564
2570
|
return parseInt(i.slice(0, s), 10);
|
|
2565
2571
|
}
|
|
2566
|
-
function
|
|
2572
|
+
function ka(e) {
|
|
2567
2573
|
let t = e.slice(0, 22).indexOf('"EVENT"');
|
|
2568
2574
|
if (t === -1)
|
|
2569
2575
|
return null;
|
|
@@ -2576,22 +2582,22 @@ function Aa(e) {
|
|
|
2576
2582
|
let s = r + 1 + i;
|
|
2577
2583
|
return e.slice(r + 1, s);
|
|
2578
2584
|
}
|
|
2579
|
-
function
|
|
2580
|
-
return t ===
|
|
2585
|
+
function _a(e, t) {
|
|
2586
|
+
return t === fn(e, "id");
|
|
2581
2587
|
}
|
|
2582
|
-
function
|
|
2583
|
-
return t ===
|
|
2588
|
+
function Ia(e, t) {
|
|
2589
|
+
return t === fn(e, "pubkey");
|
|
2584
2590
|
}
|
|
2585
|
-
function
|
|
2586
|
-
return t ===
|
|
2591
|
+
function Ua(e, t) {
|
|
2592
|
+
return t === Vr(e, "kind");
|
|
2587
2593
|
}
|
|
2588
|
-
var
|
|
2589
|
-
|
|
2590
|
-
makeAuthEvent: () =>
|
|
2594
|
+
var La = {};
|
|
2595
|
+
P(La, {
|
|
2596
|
+
makeAuthEvent: () => $a
|
|
2591
2597
|
});
|
|
2592
|
-
function
|
|
2598
|
+
function $a(e, t) {
|
|
2593
2599
|
return {
|
|
2594
|
-
kind:
|
|
2600
|
+
kind: zr,
|
|
2595
2601
|
created_at: Math.floor(Date.now() / 1e3),
|
|
2596
2602
|
tags: [
|
|
2597
2603
|
["relay", e],
|
|
@@ -2600,31 +2606,32 @@ function Ia(e, t) {
|
|
|
2600
2606
|
content: ""
|
|
2601
2607
|
};
|
|
2602
2608
|
}
|
|
2603
|
-
var
|
|
2609
|
+
var Ra;
|
|
2604
2610
|
try {
|
|
2605
|
-
|
|
2611
|
+
Ra = WebSocket;
|
|
2606
2612
|
} catch {
|
|
2607
2613
|
}
|
|
2608
|
-
var
|
|
2614
|
+
var Ta;
|
|
2609
2615
|
try {
|
|
2610
|
-
|
|
2616
|
+
Ta = WebSocket;
|
|
2611
2617
|
} catch {
|
|
2612
2618
|
}
|
|
2613
|
-
var
|
|
2614
|
-
|
|
2615
|
-
BECH32_REGEX: () =>
|
|
2616
|
-
Bech32MaxSize: () =>
|
|
2617
|
-
NostrTypeGuard: () =>
|
|
2618
|
-
decode: () =>
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2619
|
+
var Oa = {};
|
|
2620
|
+
P(Oa, {
|
|
2621
|
+
BECH32_REGEX: () => Zr,
|
|
2622
|
+
Bech32MaxSize: () => hn,
|
|
2623
|
+
NostrTypeGuard: () => Ma,
|
|
2624
|
+
decode: () => bt,
|
|
2625
|
+
decodeNostrURI: () => Ha,
|
|
2626
|
+
encodeBytes: () => mt,
|
|
2627
|
+
naddrEncode: () => Va,
|
|
2628
|
+
neventEncode: () => Wa,
|
|
2629
|
+
noteEncode: () => ja,
|
|
2630
|
+
nprofileEncode: () => za,
|
|
2631
|
+
npubEncode: () => Da,
|
|
2632
|
+
nsecEncode: () => qa
|
|
2626
2633
|
});
|
|
2627
|
-
var
|
|
2634
|
+
var Ma = {
|
|
2628
2635
|
isNProfile: (e) => /^nprofile1[a-z\d]+$/.test(e || ""),
|
|
2629
2636
|
isNEvent: (e) => /^nevent1[a-z\d]+$/.test(e || ""),
|
|
2630
2637
|
isNAddr: (e) => /^naddr1[a-z\d]+$/.test(e || ""),
|
|
@@ -2632,17 +2639,24 @@ var Ta = {
|
|
|
2632
2639
|
isNPub: (e) => /^npub1[a-z\d]{58}$/.test(e || ""),
|
|
2633
2640
|
isNote: (e) => /^note1[a-z\d]+$/.test(e || ""),
|
|
2634
2641
|
isNcryptsec: (e) => /^ncryptsec1[a-z\d]+$/.test(e || "")
|
|
2635
|
-
},
|
|
2636
|
-
function
|
|
2642
|
+
}, hn = 5e3, Zr = /[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;
|
|
2643
|
+
function Pa(e) {
|
|
2637
2644
|
const t = new Uint8Array(4);
|
|
2638
2645
|
return t[0] = e >> 24 & 255, t[1] = e >> 16 & 255, t[2] = e >> 8 & 255, t[3] = e & 255, t;
|
|
2639
2646
|
}
|
|
2640
|
-
function
|
|
2647
|
+
function Ha(e) {
|
|
2648
|
+
try {
|
|
2649
|
+
return e.startsWith("nostr:") && (e = e.substring(6)), bt(e);
|
|
2650
|
+
} catch {
|
|
2651
|
+
return { type: "invalid", data: null };
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
function bt(e) {
|
|
2641
2655
|
var i, s, o, c, a, l, f;
|
|
2642
|
-
let { prefix: t, words: n } = ze.decode(e,
|
|
2656
|
+
let { prefix: t, words: n } = ze.decode(e, hn), r = new Uint8Array(ze.fromWords(n));
|
|
2643
2657
|
switch (t) {
|
|
2644
2658
|
case "nprofile": {
|
|
2645
|
-
let u =
|
|
2659
|
+
let u = Lt(r);
|
|
2646
2660
|
if (!((i = u[0]) != null && i[0]))
|
|
2647
2661
|
throw new Error("missing TLV 0 for nprofile");
|
|
2648
2662
|
if (u[0][0].length !== 32)
|
|
@@ -2650,13 +2664,13 @@ function gt(e) {
|
|
|
2650
2664
|
return {
|
|
2651
2665
|
type: "nprofile",
|
|
2652
2666
|
data: {
|
|
2653
|
-
pubkey:
|
|
2654
|
-
relays: u[1] ? u[1].map((g) =>
|
|
2667
|
+
pubkey: H(u[0][0]),
|
|
2668
|
+
relays: u[1] ? u[1].map((g) => le.decode(g)) : []
|
|
2655
2669
|
}
|
|
2656
2670
|
};
|
|
2657
2671
|
}
|
|
2658
2672
|
case "nevent": {
|
|
2659
|
-
let u =
|
|
2673
|
+
let u = Lt(r);
|
|
2660
2674
|
if (!((s = u[0]) != null && s[0]))
|
|
2661
2675
|
throw new Error("missing TLV 0 for nevent");
|
|
2662
2676
|
if (u[0][0].length !== 32)
|
|
@@ -2668,15 +2682,15 @@ function gt(e) {
|
|
|
2668
2682
|
return {
|
|
2669
2683
|
type: "nevent",
|
|
2670
2684
|
data: {
|
|
2671
|
-
id:
|
|
2672
|
-
relays: u[1] ? u[1].map((g) =>
|
|
2673
|
-
author: (o = u[2]) != null && o[0] ?
|
|
2674
|
-
kind: (c = u[3]) != null && c[0] ? parseInt(
|
|
2685
|
+
id: H(u[0][0]),
|
|
2686
|
+
relays: u[1] ? u[1].map((g) => le.decode(g)) : [],
|
|
2687
|
+
author: (o = u[2]) != null && o[0] ? H(u[2][0]) : void 0,
|
|
2688
|
+
kind: (c = u[3]) != null && c[0] ? parseInt(H(u[3][0]), 16) : void 0
|
|
2675
2689
|
}
|
|
2676
2690
|
};
|
|
2677
2691
|
}
|
|
2678
2692
|
case "naddr": {
|
|
2679
|
-
let u =
|
|
2693
|
+
let u = Lt(r);
|
|
2680
2694
|
if (!((a = u[0]) != null && a[0]))
|
|
2681
2695
|
throw new Error("missing TLV 0 for naddr");
|
|
2682
2696
|
if (!((l = u[2]) != null && l[0]))
|
|
@@ -2690,10 +2704,10 @@ function gt(e) {
|
|
|
2690
2704
|
return {
|
|
2691
2705
|
type: "naddr",
|
|
2692
2706
|
data: {
|
|
2693
|
-
identifier:
|
|
2694
|
-
pubkey:
|
|
2695
|
-
kind: parseInt(
|
|
2696
|
-
relays: u[1] ? u[1].map((g) =>
|
|
2707
|
+
identifier: le.decode(u[0][0]),
|
|
2708
|
+
pubkey: H(u[2][0]),
|
|
2709
|
+
kind: parseInt(H(u[3][0]), 16),
|
|
2710
|
+
relays: u[1] ? u[1].map((g) => le.decode(g)) : []
|
|
2697
2711
|
}
|
|
2698
2712
|
};
|
|
2699
2713
|
}
|
|
@@ -2701,12 +2715,12 @@ function gt(e) {
|
|
|
2701
2715
|
return { type: t, data: r };
|
|
2702
2716
|
case "npub":
|
|
2703
2717
|
case "note":
|
|
2704
|
-
return { type: t, data:
|
|
2718
|
+
return { type: t, data: H(r) };
|
|
2705
2719
|
default:
|
|
2706
2720
|
throw new Error(`unknown prefix ${t}`);
|
|
2707
2721
|
}
|
|
2708
2722
|
}
|
|
2709
|
-
function
|
|
2723
|
+
function Lt(e) {
|
|
2710
2724
|
let t = {}, n = e;
|
|
2711
2725
|
for (; n.length > 0; ) {
|
|
2712
2726
|
let r = n[0], i = n[1], s = n.slice(2, 2 + i);
|
|
@@ -2716,98 +2730,98 @@ function Ut(e) {
|
|
|
2716
2730
|
}
|
|
2717
2731
|
return t;
|
|
2718
2732
|
}
|
|
2719
|
-
function
|
|
2720
|
-
return
|
|
2733
|
+
function qa(e) {
|
|
2734
|
+
return mt("nsec", e);
|
|
2721
2735
|
}
|
|
2722
|
-
function
|
|
2723
|
-
return
|
|
2736
|
+
function Da(e) {
|
|
2737
|
+
return mt("npub", z(e));
|
|
2724
2738
|
}
|
|
2725
|
-
function
|
|
2726
|
-
return
|
|
2739
|
+
function ja(e) {
|
|
2740
|
+
return mt("note", z(e));
|
|
2727
2741
|
}
|
|
2728
|
-
function
|
|
2742
|
+
function vt(e, t) {
|
|
2729
2743
|
let n = ze.toWords(t);
|
|
2730
|
-
return ze.encode(e, n,
|
|
2744
|
+
return ze.encode(e, n, hn);
|
|
2731
2745
|
}
|
|
2732
|
-
function
|
|
2733
|
-
return
|
|
2746
|
+
function mt(e, t) {
|
|
2747
|
+
return vt(e, t);
|
|
2734
2748
|
}
|
|
2735
|
-
function
|
|
2736
|
-
let t =
|
|
2749
|
+
function za(e) {
|
|
2750
|
+
let t = dn({
|
|
2737
2751
|
0: [z(e.pubkey)],
|
|
2738
2752
|
1: (e.relays || []).map((n) => ne.encode(n))
|
|
2739
2753
|
});
|
|
2740
|
-
return
|
|
2754
|
+
return vt("nprofile", t);
|
|
2741
2755
|
}
|
|
2742
|
-
function
|
|
2756
|
+
function Wa(e) {
|
|
2743
2757
|
let t;
|
|
2744
|
-
e.kind !== void 0 && (t =
|
|
2745
|
-
let n =
|
|
2758
|
+
e.kind !== void 0 && (t = Pa(e.kind));
|
|
2759
|
+
let n = dn({
|
|
2746
2760
|
0: [z(e.id)],
|
|
2747
2761
|
1: (e.relays || []).map((r) => ne.encode(r)),
|
|
2748
2762
|
2: e.author ? [z(e.author)] : [],
|
|
2749
2763
|
3: t ? [new Uint8Array(t)] : []
|
|
2750
2764
|
});
|
|
2751
|
-
return
|
|
2765
|
+
return vt("nevent", n);
|
|
2752
2766
|
}
|
|
2753
|
-
function
|
|
2767
|
+
function Va(e) {
|
|
2754
2768
|
let t = new ArrayBuffer(4);
|
|
2755
2769
|
new DataView(t).setUint32(0, e.kind, !1);
|
|
2756
|
-
let n =
|
|
2770
|
+
let n = dn({
|
|
2757
2771
|
0: [ne.encode(e.identifier)],
|
|
2758
2772
|
1: (e.relays || []).map((r) => ne.encode(r)),
|
|
2759
2773
|
2: [z(e.pubkey)],
|
|
2760
2774
|
3: [new Uint8Array(t)]
|
|
2761
2775
|
});
|
|
2762
|
-
return
|
|
2776
|
+
return vt("naddr", n);
|
|
2763
2777
|
}
|
|
2764
|
-
function
|
|
2778
|
+
function dn(e) {
|
|
2765
2779
|
let t = [];
|
|
2766
2780
|
return Object.entries(e).reverse().forEach(([n, r]) => {
|
|
2767
2781
|
r.forEach((i) => {
|
|
2768
2782
|
let s = new Uint8Array(i.length + 2);
|
|
2769
2783
|
s.set([parseInt(n)], 0), s.set([i.length], 1), s.set(i, 2), t.push(s);
|
|
2770
2784
|
});
|
|
2771
|
-
}),
|
|
2785
|
+
}), ft(...t);
|
|
2772
2786
|
}
|
|
2773
|
-
var
|
|
2774
|
-
|
|
2775
|
-
decrypt: () =>
|
|
2776
|
-
encrypt: () =>
|
|
2787
|
+
var Za = {};
|
|
2788
|
+
P(Za, {
|
|
2789
|
+
decrypt: () => Ga,
|
|
2790
|
+
encrypt: () => Gr
|
|
2777
2791
|
});
|
|
2778
|
-
|
|
2779
|
-
const r = e instanceof Uint8Array ?
|
|
2780
|
-
let o = Uint8Array.from(
|
|
2792
|
+
function Gr(e, t, n) {
|
|
2793
|
+
const r = e instanceof Uint8Array ? H(e) : e, i = Ie.getSharedSecret(r, "02" + t), s = Fr(i);
|
|
2794
|
+
let o = Uint8Array.from(yr(16)), c = ne.encode(n), a = Sr(s, o).encrypt(c), l = he.encode(new Uint8Array(a)), f = he.encode(new Uint8Array(o.buffer));
|
|
2781
2795
|
return `${l}?iv=${f}`;
|
|
2782
2796
|
}
|
|
2783
|
-
|
|
2784
|
-
const r = e instanceof Uint8Array ?
|
|
2785
|
-
let [i, s] = n.split("?iv="), o = Ie.getSharedSecret(r, "02" + t), c =
|
|
2786
|
-
return
|
|
2797
|
+
function Ga(e, t, n) {
|
|
2798
|
+
const r = e instanceof Uint8Array ? H(e) : e;
|
|
2799
|
+
let [i, s] = n.split("?iv="), o = Ie.getSharedSecret(r, "02" + t), c = Fr(o), a = he.decode(s), l = he.decode(i), f = Sr(c, a).decrypt(l);
|
|
2800
|
+
return le.decode(f);
|
|
2787
2801
|
}
|
|
2788
|
-
function
|
|
2802
|
+
function Fr(e) {
|
|
2789
2803
|
return e.slice(1, 33);
|
|
2790
2804
|
}
|
|
2791
|
-
var
|
|
2792
|
-
|
|
2793
|
-
NIP05_REGEX: () =>
|
|
2794
|
-
isNip05: () =>
|
|
2795
|
-
isValid: () =>
|
|
2796
|
-
queryProfile: () =>
|
|
2797
|
-
searchDomain: () =>
|
|
2798
|
-
useFetchImplementation: () =>
|
|
2805
|
+
var Fa = {};
|
|
2806
|
+
P(Fa, {
|
|
2807
|
+
NIP05_REGEX: () => pn,
|
|
2808
|
+
isNip05: () => Ja,
|
|
2809
|
+
isValid: () => Qa,
|
|
2810
|
+
queryProfile: () => Jr,
|
|
2811
|
+
searchDomain: () => Xa,
|
|
2812
|
+
useFetchImplementation: () => Ya
|
|
2799
2813
|
});
|
|
2800
|
-
var
|
|
2814
|
+
var pn = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/, Ja = (e) => pn.test(e || ""), Et;
|
|
2801
2815
|
try {
|
|
2802
|
-
|
|
2816
|
+
Et = fetch;
|
|
2803
2817
|
} catch {
|
|
2804
2818
|
}
|
|
2805
|
-
function
|
|
2806
|
-
|
|
2819
|
+
function Ya(e) {
|
|
2820
|
+
Et = e;
|
|
2807
2821
|
}
|
|
2808
|
-
async function
|
|
2822
|
+
async function Xa(e, t = "") {
|
|
2809
2823
|
try {
|
|
2810
|
-
const n = `https://${e}/.well-known/nostr.json?name=${t}`, r = await
|
|
2824
|
+
const n = `https://${e}/.well-known/nostr.json?name=${t}`, r = await Et(n, { redirect: "manual" });
|
|
2811
2825
|
if (r.status !== 200)
|
|
2812
2826
|
throw Error("Wrong response code");
|
|
2813
2827
|
return (await r.json()).names;
|
|
@@ -2815,14 +2829,14 @@ async function Ga(e, t = "") {
|
|
|
2815
2829
|
return {};
|
|
2816
2830
|
}
|
|
2817
2831
|
}
|
|
2818
|
-
async function
|
|
2832
|
+
async function Jr(e) {
|
|
2819
2833
|
var i;
|
|
2820
|
-
const t = e.match(
|
|
2834
|
+
const t = e.match(pn);
|
|
2821
2835
|
if (!t)
|
|
2822
2836
|
return null;
|
|
2823
2837
|
const [, n = "_", r] = t;
|
|
2824
2838
|
try {
|
|
2825
|
-
const s = `https://${r}/.well-known/nostr.json?name=${n}`, o = await
|
|
2839
|
+
const s = `https://${r}/.well-known/nostr.json?name=${n}`, o = await Et(s, { redirect: "manual" });
|
|
2826
2840
|
if (o.status !== 200)
|
|
2827
2841
|
throw Error("Wrong response code");
|
|
2828
2842
|
const c = await o.json(), a = c.names[n];
|
|
@@ -2831,15 +2845,15 @@ async function Wr(e) {
|
|
|
2831
2845
|
return null;
|
|
2832
2846
|
}
|
|
2833
2847
|
}
|
|
2834
|
-
async function
|
|
2835
|
-
const n = await
|
|
2848
|
+
async function Qa(e, t) {
|
|
2849
|
+
const n = await Jr(t);
|
|
2836
2850
|
return n ? n.pubkey === e : !1;
|
|
2837
2851
|
}
|
|
2838
|
-
var
|
|
2839
|
-
|
|
2840
|
-
parse: () =>
|
|
2852
|
+
var ec = {};
|
|
2853
|
+
P(ec, {
|
|
2854
|
+
parse: () => tc
|
|
2841
2855
|
});
|
|
2842
|
-
function
|
|
2856
|
+
function tc(e) {
|
|
2843
2857
|
const t = {
|
|
2844
2858
|
reply: void 0,
|
|
2845
2859
|
root: void 0,
|
|
@@ -2906,31 +2920,31 @@ function Ya(e) {
|
|
|
2906
2920
|
}
|
|
2907
2921
|
}), t;
|
|
2908
2922
|
}
|
|
2909
|
-
var
|
|
2910
|
-
|
|
2911
|
-
fetchRelayInformation: () =>
|
|
2912
|
-
useFetchImplementation: () =>
|
|
2923
|
+
var nc = {};
|
|
2924
|
+
P(nc, {
|
|
2925
|
+
fetchRelayInformation: () => ic,
|
|
2926
|
+
useFetchImplementation: () => rc
|
|
2913
2927
|
});
|
|
2914
|
-
var
|
|
2928
|
+
var Yr;
|
|
2915
2929
|
try {
|
|
2916
|
-
|
|
2930
|
+
Yr = fetch;
|
|
2917
2931
|
} catch {
|
|
2918
2932
|
}
|
|
2919
|
-
function
|
|
2920
|
-
|
|
2933
|
+
function rc(e) {
|
|
2934
|
+
Yr = e;
|
|
2921
2935
|
}
|
|
2922
|
-
async function
|
|
2936
|
+
async function ic(e) {
|
|
2923
2937
|
return await (await fetch(e.replace("ws://", "http://").replace("wss://", "https://"), {
|
|
2924
2938
|
headers: { Accept: "application/nostr+json" }
|
|
2925
2939
|
})).json();
|
|
2926
2940
|
}
|
|
2927
|
-
var
|
|
2928
|
-
|
|
2929
|
-
fastEventHash: () =>
|
|
2930
|
-
getPow: () =>
|
|
2931
|
-
minePow: () =>
|
|
2941
|
+
var sc = {};
|
|
2942
|
+
P(sc, {
|
|
2943
|
+
fastEventHash: () => Qr,
|
|
2944
|
+
getPow: () => Xr,
|
|
2945
|
+
minePow: () => oc
|
|
2932
2946
|
});
|
|
2933
|
-
function
|
|
2947
|
+
function Xr(e) {
|
|
2934
2948
|
let t = 0;
|
|
2935
2949
|
for (let n = 0; n < 64; n += 8) {
|
|
2936
2950
|
const r = parseInt(e.substring(n, n + 8), 16);
|
|
@@ -2943,40 +2957,232 @@ function Gr(e) {
|
|
|
2943
2957
|
}
|
|
2944
2958
|
return t;
|
|
2945
2959
|
}
|
|
2946
|
-
function
|
|
2960
|
+
function oc(e, t) {
|
|
2947
2961
|
let n = 0;
|
|
2948
2962
|
const r = e, i = ["nonce", n.toString(), t.toString()];
|
|
2949
2963
|
for (r.tags.push(i); ; ) {
|
|
2950
2964
|
const s = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
2951
|
-
if (s !== r.created_at && (n = 0, r.created_at = s), i[1] = (++n).toString(), r.id =
|
|
2965
|
+
if (s !== r.created_at && (n = 0, r.created_at = s), i[1] = (++n).toString(), r.id = Qr(r), Xr(r.id) >= t)
|
|
2952
2966
|
break;
|
|
2953
2967
|
}
|
|
2954
2968
|
return r;
|
|
2955
2969
|
}
|
|
2956
|
-
function
|
|
2957
|
-
return
|
|
2970
|
+
function Qr(e) {
|
|
2971
|
+
return H(
|
|
2958
2972
|
fe(ne.encode(JSON.stringify([0, e.pubkey, e.created_at, e.kind, e.tags, e.content])))
|
|
2959
2973
|
);
|
|
2960
2974
|
}
|
|
2961
|
-
var
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2975
|
+
var ac = {};
|
|
2976
|
+
P(ac, {
|
|
2977
|
+
unwrapEvent: () => bc,
|
|
2978
|
+
unwrapManyEvents: () => vc,
|
|
2979
|
+
wrapEvent: () => hi,
|
|
2980
|
+
wrapManyEvents: () => wc
|
|
2981
|
+
});
|
|
2982
|
+
var cc = {};
|
|
2983
|
+
P(cc, {
|
|
2984
|
+
createRumor: () => ci,
|
|
2985
|
+
createSeal: () => ui,
|
|
2986
|
+
createWrap: () => li,
|
|
2987
|
+
unwrapEvent: () => vn,
|
|
2988
|
+
unwrapManyEvents: () => fi,
|
|
2989
|
+
wrapEvent: () => st,
|
|
2990
|
+
wrapManyEvents: () => yc
|
|
2991
|
+
});
|
|
2992
|
+
var D = {};
|
|
2993
|
+
P(D, {
|
|
2994
|
+
decrypt: () => bn,
|
|
2995
|
+
encrypt: () => wn,
|
|
2996
|
+
getConversationKey: () => yn,
|
|
2997
|
+
v2: () => dc
|
|
2966
2998
|
});
|
|
2967
|
-
|
|
2999
|
+
var ei = 1, ti = 65535;
|
|
3000
|
+
function yn(e, t) {
|
|
3001
|
+
const n = Ie.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3002
|
+
return rn(fe, n, "nip44-v2");
|
|
3003
|
+
}
|
|
3004
|
+
function ni(e, t) {
|
|
3005
|
+
const n = Ir(fe, e, t, 76);
|
|
3006
|
+
return {
|
|
3007
|
+
chacha_key: n.subarray(0, 32),
|
|
3008
|
+
chacha_nonce: n.subarray(32, 44),
|
|
3009
|
+
hmac_key: n.subarray(44, 76)
|
|
3010
|
+
};
|
|
3011
|
+
}
|
|
3012
|
+
function gn(e) {
|
|
3013
|
+
if (!Number.isSafeInteger(e) || e < 1)
|
|
3014
|
+
throw new Error("expected positive integer");
|
|
3015
|
+
if (e <= 32)
|
|
3016
|
+
return 32;
|
|
3017
|
+
const t = 1 << Math.floor(Math.log2(e - 1)) + 1, n = t <= 256 ? 32 : t / 8;
|
|
3018
|
+
return n * (Math.floor((e - 1) / n) + 1);
|
|
3019
|
+
}
|
|
3020
|
+
function uc(e) {
|
|
3021
|
+
if (!Number.isSafeInteger(e) || e < ei || e > ti)
|
|
3022
|
+
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
|
|
3023
|
+
const t = new Uint8Array(2);
|
|
3024
|
+
return new DataView(t.buffer).setUint16(0, e, !1), t;
|
|
3025
|
+
}
|
|
3026
|
+
function lc(e) {
|
|
3027
|
+
const t = ne.encode(e), n = t.length, r = uc(n), i = new Uint8Array(gn(n) - n);
|
|
3028
|
+
return ft(r, t, i);
|
|
3029
|
+
}
|
|
3030
|
+
function fc(e) {
|
|
3031
|
+
const t = new DataView(e.buffer).getUint16(0), n = e.subarray(2, 2 + t);
|
|
3032
|
+
if (t < ei || t > ti || n.length !== t || e.length !== 2 + gn(t))
|
|
3033
|
+
throw new Error("invalid padding");
|
|
3034
|
+
return le.decode(n);
|
|
3035
|
+
}
|
|
3036
|
+
function ri(e, t, n) {
|
|
3037
|
+
if (n.length !== 32)
|
|
3038
|
+
throw new Error("AAD associated data must be 32 bytes");
|
|
3039
|
+
const r = ft(n, t);
|
|
3040
|
+
return dt(fe, e, r);
|
|
3041
|
+
}
|
|
3042
|
+
function hc(e) {
|
|
3043
|
+
if (typeof e != "string")
|
|
3044
|
+
throw new Error("payload must be a valid string");
|
|
3045
|
+
const t = e.length;
|
|
3046
|
+
if (t < 132 || t > 87472)
|
|
3047
|
+
throw new Error("invalid payload length: " + t);
|
|
3048
|
+
if (e[0] === "#")
|
|
3049
|
+
throw new Error("unknown encryption version");
|
|
3050
|
+
let n;
|
|
3051
|
+
try {
|
|
3052
|
+
n = he.decode(e);
|
|
3053
|
+
} catch (s) {
|
|
3054
|
+
throw new Error("invalid base64: " + s.message);
|
|
3055
|
+
}
|
|
3056
|
+
const r = n.length;
|
|
3057
|
+
if (r < 99 || r > 65603)
|
|
3058
|
+
throw new Error("invalid data length: " + r);
|
|
3059
|
+
const i = n[0];
|
|
3060
|
+
if (i !== 2)
|
|
3061
|
+
throw new Error("unknown encryption version " + i);
|
|
3062
|
+
return {
|
|
3063
|
+
nonce: n.subarray(1, 33),
|
|
3064
|
+
ciphertext: n.subarray(33, -32),
|
|
3065
|
+
mac: n.subarray(-32)
|
|
3066
|
+
};
|
|
3067
|
+
}
|
|
3068
|
+
function wn(e, t, n = yr(32)) {
|
|
3069
|
+
const { chacha_key: r, chacha_nonce: i, hmac_key: s } = ni(t, n), o = lc(e), c = kr(r, i, o), a = ri(s, c, n);
|
|
3070
|
+
return he.encode(ft(new Uint8Array([2]), n, c, a));
|
|
3071
|
+
}
|
|
3072
|
+
function bn(e, t) {
|
|
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
|
+
if (!qs(a, i))
|
|
3075
|
+
throw new Error("invalid MAC");
|
|
3076
|
+
const l = kr(s, o, r);
|
|
3077
|
+
return fc(l);
|
|
3078
|
+
}
|
|
3079
|
+
var dc = {
|
|
3080
|
+
utils: {
|
|
3081
|
+
getConversationKey: yn,
|
|
3082
|
+
calcPaddedLen: gn
|
|
3083
|
+
},
|
|
3084
|
+
encrypt: wn,
|
|
3085
|
+
decrypt: bn
|
|
3086
|
+
}, pc = 2 * 24 * 60 * 60, ii = () => Math.round(Date.now() / 1e3), si = () => Math.round(ii() - Math.random() * pc), oi = (e, t) => yn(e, t), ai = (e, t, n) => wn(JSON.stringify(e), oi(t, n)), zn = (e, t) => JSON.parse(bn(e.content, oi(t, e.pubkey)));
|
|
3087
|
+
function ci(e, t) {
|
|
3088
|
+
const n = {
|
|
3089
|
+
created_at: ii(),
|
|
3090
|
+
content: "",
|
|
3091
|
+
tags: [],
|
|
3092
|
+
...e,
|
|
3093
|
+
pubkey: ae(t)
|
|
3094
|
+
};
|
|
3095
|
+
return n.id = qe(n), n;
|
|
3096
|
+
}
|
|
3097
|
+
function ui(e, t, n) {
|
|
3098
|
+
return Q(
|
|
3099
|
+
{
|
|
3100
|
+
kind: Tr,
|
|
3101
|
+
content: ai(e, t, n),
|
|
3102
|
+
created_at: si(),
|
|
3103
|
+
tags: []
|
|
3104
|
+
},
|
|
3105
|
+
t
|
|
3106
|
+
);
|
|
3107
|
+
}
|
|
3108
|
+
function li(e, t) {
|
|
3109
|
+
const n = ke();
|
|
2968
3110
|
return Q(
|
|
2969
3111
|
{
|
|
2970
|
-
kind:
|
|
2971
|
-
|
|
2972
|
-
|
|
3112
|
+
kind: jr,
|
|
3113
|
+
content: ai(e, n, t),
|
|
3114
|
+
created_at: si(),
|
|
3115
|
+
tags: [["p", t]]
|
|
3116
|
+
},
|
|
3117
|
+
n
|
|
3118
|
+
);
|
|
3119
|
+
}
|
|
3120
|
+
function st(e, t, n) {
|
|
3121
|
+
const r = ci(e, t), i = ui(r, t, n);
|
|
3122
|
+
return li(i, n);
|
|
3123
|
+
}
|
|
3124
|
+
function yc(e, t, n) {
|
|
3125
|
+
if (!n || n.length === 0)
|
|
3126
|
+
throw new Error("At least one recipient is required.");
|
|
3127
|
+
const r = ae(t), i = [st(e, t, r)];
|
|
3128
|
+
return n.forEach((s) => {
|
|
3129
|
+
i.push(st(e, t, s));
|
|
3130
|
+
}), i;
|
|
3131
|
+
}
|
|
3132
|
+
function vn(e, t) {
|
|
3133
|
+
const n = zn(e, t);
|
|
3134
|
+
return zn(n, t);
|
|
3135
|
+
}
|
|
3136
|
+
function fi(e, t) {
|
|
3137
|
+
let n = [];
|
|
3138
|
+
return e.forEach((r) => {
|
|
3139
|
+
n.push(vn(r, t));
|
|
3140
|
+
}), n.sort((r, i) => r.created_at - i.created_at), n;
|
|
3141
|
+
}
|
|
3142
|
+
function gc(e, t, n, r) {
|
|
3143
|
+
const i = {
|
|
3144
|
+
created_at: Math.ceil(Date.now() / 1e3),
|
|
3145
|
+
kind: Or,
|
|
3146
|
+
tags: [],
|
|
3147
|
+
content: t
|
|
3148
|
+
};
|
|
3149
|
+
return (Array.isArray(e) ? e : [e]).forEach(({ publicKey: o, relayUrl: c }) => {
|
|
3150
|
+
i.tags.push(c ? ["p", o, c] : ["p", o]);
|
|
3151
|
+
}), r && i.tags.push(["e", r.eventId, r.relayUrl || "", "reply"]), n && i.tags.push(["subject", n]), i;
|
|
3152
|
+
}
|
|
3153
|
+
function hi(e, t, n, r, i) {
|
|
3154
|
+
const s = gc(t, n, r, i);
|
|
3155
|
+
return st(s, e, t.publicKey);
|
|
3156
|
+
}
|
|
3157
|
+
function wc(e, t, n, r, i) {
|
|
3158
|
+
if (!t || t.length === 0)
|
|
3159
|
+
throw new Error("At least one recipient is required.");
|
|
3160
|
+
return [{ publicKey: ae(e) }, ...t].map(
|
|
3161
|
+
(o) => hi(e, o, n, r, i)
|
|
3162
|
+
);
|
|
3163
|
+
}
|
|
3164
|
+
var bc = vn, vc = fi, mc = {};
|
|
3165
|
+
P(mc, {
|
|
3166
|
+
finishRepostEvent: () => Ec,
|
|
3167
|
+
getRepostedEvent: () => xc,
|
|
3168
|
+
getRepostedEventPointer: () => di
|
|
3169
|
+
});
|
|
3170
|
+
function Ec(e, t, n, r) {
|
|
3171
|
+
var o;
|
|
3172
|
+
let i;
|
|
3173
|
+
const s = [...e.tags ?? [], ["e", t.id, n], ["p", t.pubkey]];
|
|
3174
|
+
return t.kind === Rr ? i = an : (i = un, s.push(["k", String(t.kind)])), Q(
|
|
3175
|
+
{
|
|
3176
|
+
kind: i,
|
|
3177
|
+
tags: s,
|
|
3178
|
+
content: e.content === "" || (o = t.tags) != null && o.find((c) => c[0] === "-") ? "" : JSON.stringify(t),
|
|
2973
3179
|
created_at: e.created_at
|
|
2974
3180
|
},
|
|
2975
3181
|
r
|
|
2976
3182
|
);
|
|
2977
3183
|
}
|
|
2978
|
-
function
|
|
2979
|
-
if (e.kind
|
|
3184
|
+
function di(e) {
|
|
3185
|
+
if (![an, un].includes(e.kind))
|
|
2980
3186
|
return;
|
|
2981
3187
|
let t, n;
|
|
2982
3188
|
for (let r = e.tags.length - 1; r >= 0 && (t === void 0 || n === void 0); r--) {
|
|
@@ -2990,8 +3196,8 @@ function Jr(e) {
|
|
|
2990
3196
|
author: n == null ? void 0 : n[1]
|
|
2991
3197
|
};
|
|
2992
3198
|
}
|
|
2993
|
-
function
|
|
2994
|
-
const n =
|
|
3199
|
+
function xc(e, { skipVerification: t } = {}) {
|
|
3200
|
+
const n = di(e);
|
|
2995
3201
|
if (n === void 0 || e.content === "")
|
|
2996
3202
|
return;
|
|
2997
3203
|
let r;
|
|
@@ -3000,48 +3206,48 @@ function sc(e, { skipVerification: t } = {}) {
|
|
|
3000
3206
|
} catch {
|
|
3001
3207
|
return;
|
|
3002
3208
|
}
|
|
3003
|
-
if (r.id === n.id && !(!t && !
|
|
3209
|
+
if (r.id === n.id && !(!t && !gt(r)))
|
|
3004
3210
|
return r;
|
|
3005
3211
|
}
|
|
3006
|
-
var
|
|
3007
|
-
|
|
3008
|
-
NOSTR_URI_REGEX: () =>
|
|
3009
|
-
parse: () =>
|
|
3010
|
-
test: () =>
|
|
3212
|
+
var Kc = {};
|
|
3213
|
+
P(Kc, {
|
|
3214
|
+
NOSTR_URI_REGEX: () => mn,
|
|
3215
|
+
parse: () => Sc,
|
|
3216
|
+
test: () => Nc
|
|
3011
3217
|
});
|
|
3012
|
-
var
|
|
3013
|
-
function
|
|
3014
|
-
return typeof e == "string" && new RegExp(`^${
|
|
3218
|
+
var mn = new RegExp(`nostr:(${Zr.source})`);
|
|
3219
|
+
function Nc(e) {
|
|
3220
|
+
return typeof e == "string" && new RegExp(`^${mn.source}$`).test(e);
|
|
3015
3221
|
}
|
|
3016
|
-
function
|
|
3017
|
-
const t = e.match(new RegExp(`^${
|
|
3222
|
+
function Sc(e) {
|
|
3223
|
+
const t = e.match(new RegExp(`^${mn.source}$`));
|
|
3018
3224
|
if (!t)
|
|
3019
3225
|
throw new Error(`Invalid Nostr URI: ${e}`);
|
|
3020
3226
|
return {
|
|
3021
3227
|
uri: t[0],
|
|
3022
3228
|
value: t[1],
|
|
3023
|
-
decoded:
|
|
3229
|
+
decoded: bt(t[1])
|
|
3024
3230
|
};
|
|
3025
3231
|
}
|
|
3026
|
-
var
|
|
3027
|
-
|
|
3028
|
-
finishReactionEvent: () =>
|
|
3029
|
-
getReactedEventPointer: () =>
|
|
3232
|
+
var Ac = {};
|
|
3233
|
+
P(Ac, {
|
|
3234
|
+
finishReactionEvent: () => Cc,
|
|
3235
|
+
getReactedEventPointer: () => Bc
|
|
3030
3236
|
});
|
|
3031
|
-
function
|
|
3237
|
+
function Cc(e, t, n) {
|
|
3032
3238
|
const r = t.tags.filter((i) => i.length >= 2 && (i[0] === "e" || i[0] === "p"));
|
|
3033
3239
|
return Q(
|
|
3034
3240
|
{
|
|
3035
3241
|
...e,
|
|
3036
|
-
kind:
|
|
3242
|
+
kind: cn,
|
|
3037
3243
|
tags: [...e.tags ?? [], ...r, ["e", t.id], ["p", t.pubkey]],
|
|
3038
3244
|
content: e.content ?? "+"
|
|
3039
3245
|
},
|
|
3040
3246
|
n
|
|
3041
3247
|
);
|
|
3042
3248
|
}
|
|
3043
|
-
function
|
|
3044
|
-
if (e.kind !==
|
|
3249
|
+
function Bc(e) {
|
|
3250
|
+
if (e.kind !== cn)
|
|
3045
3251
|
return;
|
|
3046
3252
|
let t, n;
|
|
3047
3253
|
for (let r = e.tags.length - 1; r >= 0 && (t === void 0 || n === void 0); r--) {
|
|
@@ -3055,44 +3261,91 @@ function fc(e) {
|
|
|
3055
3261
|
author: n[1]
|
|
3056
3262
|
};
|
|
3057
3263
|
}
|
|
3058
|
-
var
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
regex: () => dn,
|
|
3062
|
-
replaceAll: () => yc
|
|
3264
|
+
var kc = {};
|
|
3265
|
+
P(kc, {
|
|
3266
|
+
parse: () => Ic
|
|
3063
3267
|
});
|
|
3064
|
-
var
|
|
3065
|
-
function*
|
|
3066
|
-
const t = e.
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3268
|
+
var _c = /\W/m, Wn = /\W |\W$|$|,| /m;
|
|
3269
|
+
function* Ic(e) {
|
|
3270
|
+
const t = e.length;
|
|
3271
|
+
let n = 0, r = 0;
|
|
3272
|
+
for (; r < t; ) {
|
|
3273
|
+
let i = e.indexOf(":", r);
|
|
3274
|
+
if (i === -1)
|
|
3275
|
+
break;
|
|
3276
|
+
if (e.substring(i - 5, i) === "nostr") {
|
|
3277
|
+
const s = e.substring(i + 60).match(_c), o = s ? i + 60 + s.index : t;
|
|
3278
|
+
try {
|
|
3279
|
+
let c, { data: a, type: l } = bt(e.substring(i + 1, o));
|
|
3280
|
+
switch (l) {
|
|
3281
|
+
case "npub":
|
|
3282
|
+
c = { pubkey: a };
|
|
3283
|
+
break;
|
|
3284
|
+
case "nsec":
|
|
3285
|
+
case "note":
|
|
3286
|
+
r = o + 1;
|
|
3287
|
+
continue;
|
|
3288
|
+
default:
|
|
3289
|
+
c = a;
|
|
3290
|
+
}
|
|
3291
|
+
n !== i - 5 && (yield { type: "text", text: e.substring(n, i - 5) }), yield { type: "reference", pointer: c }, r = o, n = r;
|
|
3292
|
+
continue;
|
|
3293
|
+
} catch {
|
|
3294
|
+
r = i + 1;
|
|
3295
|
+
continue;
|
|
3296
|
+
}
|
|
3297
|
+
} else if (e.substring(i - 5, i) === "https" || e.substring(i - 4, i) === "http") {
|
|
3298
|
+
const s = e.substring(i + 4).match(Wn), o = s ? i + 4 + s.index : t, c = e[i - 1] === "s" ? 5 : 4;
|
|
3299
|
+
try {
|
|
3300
|
+
let a = new URL(e.substring(i - c, o));
|
|
3301
|
+
if (a.hostname.indexOf(".") === -1)
|
|
3302
|
+
throw new Error("invalid url");
|
|
3303
|
+
if (n !== i - c && (yield { type: "text", text: e.substring(n, i - c) }), a.pathname.endsWith(".png") || a.pathname.endsWith(".jpg") || a.pathname.endsWith(".jpeg") || a.pathname.endsWith(".gif") || a.pathname.endsWith(".webp")) {
|
|
3304
|
+
yield { type: "image", url: a.toString() }, r = o, n = r;
|
|
3305
|
+
continue;
|
|
3306
|
+
}
|
|
3307
|
+
if (a.pathname.endsWith(".mp4") || a.pathname.endsWith(".avi") || a.pathname.endsWith(".webm") || a.pathname.endsWith(".mkv")) {
|
|
3308
|
+
yield { type: "video", url: a.toString() }, r = o, n = r;
|
|
3309
|
+
continue;
|
|
3310
|
+
}
|
|
3311
|
+
if (a.pathname.endsWith(".mp3") || a.pathname.endsWith(".aac") || a.pathname.endsWith(".ogg") || a.pathname.endsWith(".opus")) {
|
|
3312
|
+
yield { type: "audio", url: a.toString() }, r = o, n = r;
|
|
3313
|
+
continue;
|
|
3314
|
+
}
|
|
3315
|
+
yield { type: "url", url: a.toString() }, r = o, n = r;
|
|
3316
|
+
continue;
|
|
3317
|
+
} catch {
|
|
3318
|
+
r = o + 1;
|
|
3319
|
+
continue;
|
|
3320
|
+
}
|
|
3321
|
+
} else if (e.substring(i - 3, i) === "wss" || e.substring(i - 2, i) === "ws") {
|
|
3322
|
+
const s = e.substring(i + 4).match(Wn), o = s ? i + 4 + s.index : t, c = e[i - 1] === "s" ? 3 : 2;
|
|
3323
|
+
try {
|
|
3324
|
+
let a = new URL(e.substring(i - c, o));
|
|
3325
|
+
if (a.hostname.indexOf(".") === -1)
|
|
3326
|
+
throw new Error("invalid ws url");
|
|
3327
|
+
n !== i - c && (yield { type: "text", text: e.substring(n, i - c) }), yield { type: "relay", url: a.toString() }, r = o, n = r;
|
|
3328
|
+
continue;
|
|
3329
|
+
} catch {
|
|
3330
|
+
r = o + 1;
|
|
3331
|
+
continue;
|
|
3332
|
+
}
|
|
3333
|
+
} else {
|
|
3334
|
+
r = i + 1;
|
|
3335
|
+
continue;
|
|
3078
3336
|
}
|
|
3337
|
+
}
|
|
3338
|
+
n !== t && (yield { type: "text", text: e.substring(n) });
|
|
3079
3339
|
}
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
var pc = {};
|
|
3088
|
-
D(pc, {
|
|
3089
|
-
channelCreateEvent: () => gc,
|
|
3090
|
-
channelHideMessageEvent: () => vc,
|
|
3091
|
-
channelMessageEvent: () => bc,
|
|
3092
|
-
channelMetadataEvent: () => wc,
|
|
3093
|
-
channelMuteUserEvent: () => mc
|
|
3340
|
+
var Uc = {};
|
|
3341
|
+
P(Uc, {
|
|
3342
|
+
channelCreateEvent: () => Lc,
|
|
3343
|
+
channelHideMessageEvent: () => Tc,
|
|
3344
|
+
channelMessageEvent: () => Rc,
|
|
3345
|
+
channelMetadataEvent: () => $c,
|
|
3346
|
+
channelMuteUserEvent: () => Oc
|
|
3094
3347
|
});
|
|
3095
|
-
var
|
|
3348
|
+
var Lc = (e, t) => {
|
|
3096
3349
|
let n;
|
|
3097
3350
|
if (typeof e.content == "object")
|
|
3098
3351
|
n = JSON.stringify(e.content);
|
|
@@ -3102,14 +3355,14 @@ var gc = (e, t) => {
|
|
|
3102
3355
|
return;
|
|
3103
3356
|
return Q(
|
|
3104
3357
|
{
|
|
3105
|
-
kind:
|
|
3358
|
+
kind: Mr,
|
|
3106
3359
|
tags: [...e.tags ?? []],
|
|
3107
3360
|
content: n,
|
|
3108
3361
|
created_at: e.created_at
|
|
3109
3362
|
},
|
|
3110
3363
|
t
|
|
3111
3364
|
);
|
|
3112
|
-
},
|
|
3365
|
+
}, $c = (e, t) => {
|
|
3113
3366
|
let n;
|
|
3114
3367
|
if (typeof e.content == "object")
|
|
3115
3368
|
n = JSON.stringify(e.content);
|
|
@@ -3119,25 +3372,25 @@ var gc = (e, t) => {
|
|
|
3119
3372
|
return;
|
|
3120
3373
|
return Q(
|
|
3121
3374
|
{
|
|
3122
|
-
kind:
|
|
3375
|
+
kind: Pr,
|
|
3123
3376
|
tags: [["e", e.channel_create_event_id], ...e.tags ?? []],
|
|
3124
3377
|
content: n,
|
|
3125
3378
|
created_at: e.created_at
|
|
3126
3379
|
},
|
|
3127
3380
|
t
|
|
3128
3381
|
);
|
|
3129
|
-
},
|
|
3382
|
+
}, Rc = (e, t) => {
|
|
3130
3383
|
const n = [["e", e.channel_create_event_id, e.relay_url, "root"]];
|
|
3131
3384
|
return e.reply_to_channel_message_event_id && n.push(["e", e.reply_to_channel_message_event_id, e.relay_url, "reply"]), Q(
|
|
3132
3385
|
{
|
|
3133
|
-
kind:
|
|
3386
|
+
kind: Hr,
|
|
3134
3387
|
tags: [...n, ...e.tags ?? []],
|
|
3135
3388
|
content: e.content,
|
|
3136
3389
|
created_at: e.created_at
|
|
3137
3390
|
},
|
|
3138
3391
|
t
|
|
3139
3392
|
);
|
|
3140
|
-
},
|
|
3393
|
+
}, Tc = (e, t) => {
|
|
3141
3394
|
let n;
|
|
3142
3395
|
if (typeof e.content == "object")
|
|
3143
3396
|
n = JSON.stringify(e.content);
|
|
@@ -3147,14 +3400,14 @@ var gc = (e, t) => {
|
|
|
3147
3400
|
return;
|
|
3148
3401
|
return Q(
|
|
3149
3402
|
{
|
|
3150
|
-
kind:
|
|
3403
|
+
kind: qr,
|
|
3151
3404
|
tags: [["e", e.channel_message_event_id], ...e.tags ?? []],
|
|
3152
3405
|
content: n,
|
|
3153
3406
|
created_at: e.created_at
|
|
3154
3407
|
},
|
|
3155
3408
|
t
|
|
3156
3409
|
);
|
|
3157
|
-
},
|
|
3410
|
+
}, Oc = (e, t) => {
|
|
3158
3411
|
let n;
|
|
3159
3412
|
if (typeof e.content == "object")
|
|
3160
3413
|
n = JSON.stringify(e.content);
|
|
@@ -3164,23 +3417,23 @@ var gc = (e, t) => {
|
|
|
3164
3417
|
return;
|
|
3165
3418
|
return Q(
|
|
3166
3419
|
{
|
|
3167
|
-
kind:
|
|
3420
|
+
kind: Dr,
|
|
3168
3421
|
tags: [["p", e.pubkey_to_mute], ...e.tags ?? []],
|
|
3169
3422
|
content: n,
|
|
3170
3423
|
created_at: e.created_at
|
|
3171
3424
|
},
|
|
3172
3425
|
t
|
|
3173
3426
|
);
|
|
3174
|
-
},
|
|
3175
|
-
|
|
3176
|
-
EMOJI_SHORTCODE_REGEX: () =>
|
|
3177
|
-
matchAll: () =>
|
|
3178
|
-
regex: () =>
|
|
3179
|
-
replaceAll: () =>
|
|
3427
|
+
}, Mc = {};
|
|
3428
|
+
P(Mc, {
|
|
3429
|
+
EMOJI_SHORTCODE_REGEX: () => pi,
|
|
3430
|
+
matchAll: () => Pc,
|
|
3431
|
+
regex: () => En,
|
|
3432
|
+
replaceAll: () => Hc
|
|
3180
3433
|
});
|
|
3181
|
-
var
|
|
3182
|
-
function*
|
|
3183
|
-
const t = e.matchAll(
|
|
3434
|
+
var pi = /:(\w+):/, En = () => new RegExp(`\\B${pi.source}\\B`, "g");
|
|
3435
|
+
function* Pc(e) {
|
|
3436
|
+
const t = e.matchAll(En());
|
|
3184
3437
|
for (const n of t)
|
|
3185
3438
|
try {
|
|
3186
3439
|
const [r, i] = n;
|
|
@@ -3193,186 +3446,99 @@ function* xc(e) {
|
|
|
3193
3446
|
} catch {
|
|
3194
3447
|
}
|
|
3195
3448
|
}
|
|
3196
|
-
function
|
|
3197
|
-
return e.replaceAll(
|
|
3449
|
+
function Hc(e, t) {
|
|
3450
|
+
return e.replaceAll(En(), (n, r) => t({
|
|
3198
3451
|
shortcode: n,
|
|
3199
3452
|
name: r
|
|
3200
3453
|
}));
|
|
3201
3454
|
}
|
|
3202
|
-
var
|
|
3203
|
-
|
|
3204
|
-
useFetchImplementation: () =>
|
|
3205
|
-
validateGithub: () =>
|
|
3455
|
+
var qc = {};
|
|
3456
|
+
P(qc, {
|
|
3457
|
+
useFetchImplementation: () => Dc,
|
|
3458
|
+
validateGithub: () => jc
|
|
3206
3459
|
});
|
|
3207
|
-
var
|
|
3460
|
+
var xn;
|
|
3208
3461
|
try {
|
|
3209
|
-
|
|
3462
|
+
xn = fetch;
|
|
3210
3463
|
} catch {
|
|
3211
3464
|
}
|
|
3212
|
-
function
|
|
3213
|
-
|
|
3465
|
+
function Dc(e) {
|
|
3466
|
+
xn = e;
|
|
3214
3467
|
}
|
|
3215
|
-
async function
|
|
3468
|
+
async function jc(e, t, n) {
|
|
3216
3469
|
try {
|
|
3217
|
-
return await (await
|
|
3470
|
+
return await (await xn(`https://gist.github.com/${t}/${n}/raw`)).text() === `Verifying that I control the following Nostr public key: ${e}`;
|
|
3218
3471
|
} catch {
|
|
3219
3472
|
return !1;
|
|
3220
3473
|
}
|
|
3221
3474
|
}
|
|
3222
|
-
var
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
getConversationKey: () => gn,
|
|
3227
|
-
v2: () => Ic
|
|
3475
|
+
var zc = {};
|
|
3476
|
+
P(zc, {
|
|
3477
|
+
makeNwcRequestEvent: () => Vc,
|
|
3478
|
+
parseConnectionString: () => Wc
|
|
3228
3479
|
});
|
|
3229
|
-
|
|
3230
|
-
function gn(e, t) {
|
|
3231
|
-
const n = Ie.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3232
|
-
return rn(fe, n, "nip44-v2");
|
|
3233
|
-
}
|
|
3234
|
-
function ei(e, t) {
|
|
3235
|
-
const n = Cr(fe, e, t, 76);
|
|
3236
|
-
return {
|
|
3237
|
-
chacha_key: n.subarray(0, 32),
|
|
3238
|
-
chacha_nonce: n.subarray(32, 44),
|
|
3239
|
-
hmac_key: n.subarray(44, 76)
|
|
3240
|
-
};
|
|
3241
|
-
}
|
|
3242
|
-
function wn(e) {
|
|
3243
|
-
if (!Number.isSafeInteger(e) || e < 1)
|
|
3244
|
-
throw new Error("expected positive integer");
|
|
3245
|
-
if (e <= 32)
|
|
3246
|
-
return 32;
|
|
3247
|
-
const t = 1 << Math.floor(Math.log2(e - 1)) + 1, n = t <= 256 ? 32 : t / 8;
|
|
3248
|
-
return n * (Math.floor((e - 1) / n) + 1);
|
|
3249
|
-
}
|
|
3250
|
-
function Cc(e) {
|
|
3251
|
-
if (!Number.isSafeInteger(e) || e < Xr || e > Qr)
|
|
3252
|
-
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
|
|
3253
|
-
const t = new Uint8Array(2);
|
|
3254
|
-
return new DataView(t.buffer).setUint16(0, e, !1), t;
|
|
3255
|
-
}
|
|
3256
|
-
function Bc(e) {
|
|
3257
|
-
const t = ne.encode(e), n = t.length, r = Cc(n), i = new Uint8Array(wn(n) - n);
|
|
3258
|
-
return lt(r, t, i);
|
|
3259
|
-
}
|
|
3260
|
-
function kc(e) {
|
|
3261
|
-
const t = new DataView(e.buffer).getUint16(0), n = e.subarray(2, 2 + t);
|
|
3262
|
-
if (t < Xr || t > Qr || n.length !== t || e.length !== 2 + wn(t))
|
|
3263
|
-
throw new Error("invalid padding");
|
|
3264
|
-
return ue.decode(n);
|
|
3265
|
-
}
|
|
3266
|
-
function ti(e, t, n) {
|
|
3267
|
-
if (n.length !== 32)
|
|
3268
|
-
throw new Error("AAD associated data must be 32 bytes");
|
|
3269
|
-
const r = lt(n, t);
|
|
3270
|
-
return ht(fe, e, r);
|
|
3271
|
-
}
|
|
3272
|
-
function _c(e) {
|
|
3273
|
-
if (typeof e != "string")
|
|
3274
|
-
throw new Error("payload must be a valid string");
|
|
3275
|
-
const t = e.length;
|
|
3276
|
-
if (t < 132 || t > 87472)
|
|
3277
|
-
throw new Error("invalid payload length: " + t);
|
|
3278
|
-
if (e[0] === "#")
|
|
3279
|
-
throw new Error("unknown encryption version");
|
|
3280
|
-
let n;
|
|
3281
|
-
try {
|
|
3282
|
-
n = he.decode(e);
|
|
3283
|
-
} catch (s) {
|
|
3284
|
-
throw new Error("invalid base64: " + s.message);
|
|
3285
|
-
}
|
|
3286
|
-
const r = n.length;
|
|
3287
|
-
if (r < 99 || r > 65603)
|
|
3288
|
-
throw new Error("invalid data length: " + r);
|
|
3289
|
-
const i = n[0];
|
|
3290
|
-
if (i !== 2)
|
|
3291
|
-
throw new Error("unknown encryption version " + i);
|
|
3292
|
-
return {
|
|
3293
|
-
nonce: n.subarray(1, 33),
|
|
3294
|
-
ciphertext: n.subarray(33, -32),
|
|
3295
|
-
mac: n.subarray(-32)
|
|
3296
|
-
};
|
|
3297
|
-
}
|
|
3298
|
-
function bn(e, t, n = fr(32)) {
|
|
3299
|
-
const { chacha_key: r, chacha_nonce: i, hmac_key: s } = ei(t, n), o = Bc(e), c = Sr(r, i, o), a = ti(s, c, n);
|
|
3300
|
-
return he.encode(lt(new Uint8Array([2]), n, c, a));
|
|
3301
|
-
}
|
|
3302
|
-
function vn(e, t) {
|
|
3303
|
-
const { nonce: n, ciphertext: r, mac: i } = _c(e), { chacha_key: s, chacha_nonce: o, hmac_key: c } = ei(t, n), a = ti(c, r, n);
|
|
3304
|
-
if (!Rs(a, i))
|
|
3305
|
-
throw new Error("invalid MAC");
|
|
3306
|
-
const l = Sr(s, o, r);
|
|
3307
|
-
return kc(l);
|
|
3308
|
-
}
|
|
3309
|
-
var Ic = {
|
|
3310
|
-
utils: {
|
|
3311
|
-
getConversationKey: gn,
|
|
3312
|
-
calcPaddedLen: wn
|
|
3313
|
-
},
|
|
3314
|
-
encrypt: bn,
|
|
3315
|
-
decrypt: vn
|
|
3316
|
-
}, Uc = {};
|
|
3317
|
-
D(Uc, {
|
|
3318
|
-
makeNwcRequestEvent: () => $c,
|
|
3319
|
-
parseConnectionString: () => Lc
|
|
3320
|
-
});
|
|
3321
|
-
function Lc(e) {
|
|
3480
|
+
function Wc(e) {
|
|
3322
3481
|
const { pathname: t, searchParams: n } = new URL(e), r = t, i = n.get("relay"), s = n.get("secret");
|
|
3323
3482
|
if (!r || !i || !s)
|
|
3324
3483
|
throw new Error("invalid connection string");
|
|
3325
3484
|
return { pubkey: r, relay: i, secret: s };
|
|
3326
3485
|
}
|
|
3327
|
-
async function
|
|
3328
|
-
const i = await
|
|
3486
|
+
async function Vc(e, t, n) {
|
|
3487
|
+
const i = await Gr(t, e, JSON.stringify({
|
|
3329
3488
|
method: "pay_invoice",
|
|
3330
3489
|
params: {
|
|
3331
3490
|
invoice: n
|
|
3332
3491
|
}
|
|
3333
3492
|
})), s = {
|
|
3334
|
-
kind:
|
|
3493
|
+
kind: Wr,
|
|
3335
3494
|
created_at: Math.round(Date.now() / 1e3),
|
|
3336
3495
|
content: i,
|
|
3337
3496
|
tags: [["p", e]]
|
|
3338
3497
|
};
|
|
3339
3498
|
return Q(s, t);
|
|
3340
3499
|
}
|
|
3341
|
-
var
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3500
|
+
var Zc = {};
|
|
3501
|
+
P(Zc, {
|
|
3502
|
+
normalizeIdentifier: () => Gc
|
|
3503
|
+
});
|
|
3504
|
+
function Gc(e) {
|
|
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
|
+
}
|
|
3507
|
+
var Fc = {};
|
|
3508
|
+
P(Fc, {
|
|
3509
|
+
getZapEndpoint: () => Yc,
|
|
3510
|
+
makeZapReceipt: () => eu,
|
|
3511
|
+
makeZapRequest: () => Xc,
|
|
3512
|
+
useFetchImplementation: () => Jc,
|
|
3513
|
+
validateZapRequest: () => Qc
|
|
3348
3514
|
});
|
|
3349
|
-
var
|
|
3515
|
+
var Kn;
|
|
3350
3516
|
try {
|
|
3351
|
-
|
|
3517
|
+
Kn = fetch;
|
|
3352
3518
|
} catch {
|
|
3353
3519
|
}
|
|
3354
|
-
function
|
|
3355
|
-
|
|
3520
|
+
function Jc(e) {
|
|
3521
|
+
Kn = e;
|
|
3356
3522
|
}
|
|
3357
|
-
async function
|
|
3523
|
+
async function Yc(e) {
|
|
3358
3524
|
try {
|
|
3359
3525
|
let t = "", { lud06: n, lud16: r } = JSON.parse(e.content);
|
|
3360
3526
|
if (n) {
|
|
3361
3527
|
let { words: o } = ze.decode(n, 1e3), c = ze.fromWords(o);
|
|
3362
|
-
t =
|
|
3528
|
+
t = le.decode(c);
|
|
3363
3529
|
} else if (r) {
|
|
3364
3530
|
let [o, c] = r.split("@");
|
|
3365
3531
|
t = new URL(`/.well-known/lnurlp/${o}`, `https://${c}`).toString();
|
|
3366
3532
|
} else
|
|
3367
3533
|
return null;
|
|
3368
|
-
let s = await (await
|
|
3534
|
+
let s = await (await Kn(t)).json();
|
|
3369
3535
|
if (s.allowsNostr && s.nostrPubkey)
|
|
3370
3536
|
return s.callback;
|
|
3371
3537
|
} catch {
|
|
3372
3538
|
}
|
|
3373
3539
|
return null;
|
|
3374
3540
|
}
|
|
3375
|
-
function
|
|
3541
|
+
function Xc({
|
|
3376
3542
|
profile: e,
|
|
3377
3543
|
event: t,
|
|
3378
3544
|
amount: n,
|
|
@@ -3393,18 +3559,30 @@ function Pc({
|
|
|
3393
3559
|
["relays", ...r]
|
|
3394
3560
|
]
|
|
3395
3561
|
};
|
|
3396
|
-
|
|
3562
|
+
if (t && typeof t == "string" && s.tags.push(["e", t]), t && typeof t == "object") {
|
|
3563
|
+
if (on(t.kind)) {
|
|
3564
|
+
const o = ["a", `${t.kind}:${t.pubkey}:`];
|
|
3565
|
+
s.tags.push(o);
|
|
3566
|
+
} else if (wt(t.kind)) {
|
|
3567
|
+
let o = t.tags.find(([a, l]) => a === "d" && l);
|
|
3568
|
+
if (!o)
|
|
3569
|
+
throw new Error("d tag not found or is empty");
|
|
3570
|
+
const c = ["a", `${t.kind}:${t.pubkey}:${o[1]}`];
|
|
3571
|
+
s.tags.push(c);
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3574
|
+
return s;
|
|
3397
3575
|
}
|
|
3398
|
-
function
|
|
3576
|
+
function Qc(e) {
|
|
3399
3577
|
let t;
|
|
3400
3578
|
try {
|
|
3401
3579
|
t = JSON.parse(e);
|
|
3402
3580
|
} catch {
|
|
3403
3581
|
return "Invalid zap request JSON.";
|
|
3404
3582
|
}
|
|
3405
|
-
if (!dt(t))
|
|
3406
|
-
return "Zap request is not a valid Nostr event.";
|
|
3407
3583
|
if (!pt(t))
|
|
3584
|
+
return "Zap request is not a valid Nostr event.";
|
|
3585
|
+
if (!gt(t))
|
|
3408
3586
|
return "Invalid signature on zap request.";
|
|
3409
3587
|
let n = t.tags.find(([s, o]) => s === "p" && o);
|
|
3410
3588
|
if (!n)
|
|
@@ -3414,7 +3592,7 @@ function Mc(e) {
|
|
|
3414
3592
|
let r = t.tags.find(([s, o]) => s === "e" && o);
|
|
3415
3593
|
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.";
|
|
3416
3594
|
}
|
|
3417
|
-
function
|
|
3595
|
+
function eu({
|
|
3418
3596
|
zapRequest: e,
|
|
3419
3597
|
preimage: t,
|
|
3420
3598
|
bolt11: n,
|
|
@@ -3428,89 +3606,23 @@ function Hc({
|
|
|
3428
3606
|
};
|
|
3429
3607
|
return t && o.tags.push(["preimage", t]), o;
|
|
3430
3608
|
}
|
|
3431
|
-
var
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
const n = {
|
|
3444
|
-
created_at: ni(),
|
|
3445
|
-
content: "",
|
|
3446
|
-
tags: [],
|
|
3447
|
-
...e,
|
|
3448
|
-
pubkey: le(t)
|
|
3449
|
-
};
|
|
3450
|
-
return n.id = qe(n), n;
|
|
3451
|
-
}
|
|
3452
|
-
function ai(e, t, n) {
|
|
3453
|
-
return Q(
|
|
3454
|
-
{
|
|
3455
|
-
kind: Lr,
|
|
3456
|
-
content: si(e, t, n),
|
|
3457
|
-
created_at: ri(),
|
|
3458
|
-
tags: []
|
|
3459
|
-
},
|
|
3460
|
-
t
|
|
3461
|
-
);
|
|
3462
|
-
}
|
|
3463
|
-
function ci(e, t) {
|
|
3464
|
-
const n = ke();
|
|
3465
|
-
return Q(
|
|
3466
|
-
{
|
|
3467
|
-
kind: Mr,
|
|
3468
|
-
content: si(e, n, t),
|
|
3469
|
-
created_at: ri(),
|
|
3470
|
-
tags: [["p", t]]
|
|
3471
|
-
},
|
|
3472
|
-
n
|
|
3473
|
-
);
|
|
3474
|
-
}
|
|
3475
|
-
function Vt(e, t, n) {
|
|
3476
|
-
const r = oi(e, t), i = ai(r, t, n);
|
|
3477
|
-
return ci(i, n);
|
|
3478
|
-
}
|
|
3479
|
-
function jc(e, t, n) {
|
|
3480
|
-
if (!n || n.length === 0)
|
|
3481
|
-
throw new Error("At least one recipient is required.");
|
|
3482
|
-
const r = le(t), i = [Vt(e, t, r)];
|
|
3483
|
-
return n.forEach((s) => {
|
|
3484
|
-
i.push(Vt(e, t, s));
|
|
3485
|
-
}), i;
|
|
3486
|
-
}
|
|
3487
|
-
function ui(e, t) {
|
|
3488
|
-
const n = qn(e, t);
|
|
3489
|
-
return qn(n, t);
|
|
3490
|
-
}
|
|
3491
|
-
function zc(e, t) {
|
|
3492
|
-
let n = [];
|
|
3493
|
-
return e.forEach((r) => {
|
|
3494
|
-
n.push(ui(r, t));
|
|
3495
|
-
}), n.sort((r, i) => r.created_at - i.created_at), n;
|
|
3496
|
-
}
|
|
3497
|
-
var Vc = {};
|
|
3498
|
-
D(Vc, {
|
|
3499
|
-
getToken: () => Wc,
|
|
3500
|
-
hashPayload: () => En,
|
|
3501
|
-
unpackEventFromToken: () => fi,
|
|
3502
|
-
validateEvent: () => wi,
|
|
3503
|
-
validateEventKind: () => di,
|
|
3504
|
-
validateEventMethodTag: () => pi,
|
|
3505
|
-
validateEventPayloadTag: () => gi,
|
|
3506
|
-
validateEventTimestamp: () => hi,
|
|
3507
|
-
validateEventUrlTag: () => yi,
|
|
3508
|
-
validateToken: () => Zc
|
|
3609
|
+
var tu = {};
|
|
3610
|
+
P(tu, {
|
|
3611
|
+
getToken: () => nu,
|
|
3612
|
+
hashPayload: () => Nn,
|
|
3613
|
+
unpackEventFromToken: () => gi,
|
|
3614
|
+
validateEvent: () => xi,
|
|
3615
|
+
validateEventKind: () => bi,
|
|
3616
|
+
validateEventMethodTag: () => mi,
|
|
3617
|
+
validateEventPayloadTag: () => Ei,
|
|
3618
|
+
validateEventTimestamp: () => wi,
|
|
3619
|
+
validateEventUrlTag: () => vi,
|
|
3620
|
+
validateToken: () => ru
|
|
3509
3621
|
});
|
|
3510
|
-
var
|
|
3511
|
-
async function
|
|
3622
|
+
var yi = "Nostr ";
|
|
3623
|
+
async function nu(e, t, n, r = !1, i) {
|
|
3512
3624
|
const s = {
|
|
3513
|
-
kind:
|
|
3625
|
+
kind: ln,
|
|
3514
3626
|
tags: [
|
|
3515
3627
|
["u", e],
|
|
3516
3628
|
["method", t]
|
|
@@ -3518,84 +3630,84 @@ async function Wc(e, t, n, r = !1, i) {
|
|
|
3518
3630
|
created_at: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
3519
3631
|
content: ""
|
|
3520
3632
|
};
|
|
3521
|
-
i && s.tags.push(["payload",
|
|
3633
|
+
i && s.tags.push(["payload", Nn(i)]);
|
|
3522
3634
|
const o = await n(s);
|
|
3523
|
-
return (r ?
|
|
3635
|
+
return (r ? yi : "") + he.encode(ne.encode(JSON.stringify(o)));
|
|
3524
3636
|
}
|
|
3525
|
-
async function
|
|
3526
|
-
const r = await
|
|
3637
|
+
async function ru(e, t, n) {
|
|
3638
|
+
const r = await gi(e).catch((s) => {
|
|
3527
3639
|
throw s;
|
|
3528
3640
|
});
|
|
3529
|
-
return await
|
|
3641
|
+
return await xi(r, t, n).catch((s) => {
|
|
3530
3642
|
throw s;
|
|
3531
3643
|
});
|
|
3532
3644
|
}
|
|
3533
|
-
async function
|
|
3645
|
+
async function gi(e) {
|
|
3534
3646
|
if (!e)
|
|
3535
3647
|
throw new Error("Missing token");
|
|
3536
|
-
e = e.replace(
|
|
3537
|
-
const t =
|
|
3648
|
+
e = e.replace(yi, "");
|
|
3649
|
+
const t = le.decode(he.decode(e));
|
|
3538
3650
|
if (!t || t.length === 0 || !t.startsWith("{"))
|
|
3539
3651
|
throw new Error("Invalid token");
|
|
3540
3652
|
return JSON.parse(t);
|
|
3541
3653
|
}
|
|
3542
|
-
function
|
|
3654
|
+
function wi(e) {
|
|
3543
3655
|
return e.created_at ? Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3) - e.created_at < 60 : !1;
|
|
3544
3656
|
}
|
|
3545
|
-
function
|
|
3546
|
-
return e.kind ===
|
|
3657
|
+
function bi(e) {
|
|
3658
|
+
return e.kind === ln;
|
|
3547
3659
|
}
|
|
3548
|
-
function
|
|
3660
|
+
function vi(e, t) {
|
|
3549
3661
|
const n = e.tags.find((r) => r[0] === "u");
|
|
3550
3662
|
return n ? n.length > 0 && n[1] === t : !1;
|
|
3551
3663
|
}
|
|
3552
|
-
function
|
|
3664
|
+
function mi(e, t) {
|
|
3553
3665
|
const n = e.tags.find((r) => r[0] === "method");
|
|
3554
3666
|
return n ? n.length > 0 && n[1].toLowerCase() === t.toLowerCase() : !1;
|
|
3555
3667
|
}
|
|
3556
|
-
function
|
|
3668
|
+
function Nn(e) {
|
|
3557
3669
|
const t = fe(ne.encode(JSON.stringify(e)));
|
|
3558
|
-
return
|
|
3670
|
+
return H(t);
|
|
3559
3671
|
}
|
|
3560
|
-
function
|
|
3672
|
+
function Ei(e, t) {
|
|
3561
3673
|
const n = e.tags.find((i) => i[0] === "payload");
|
|
3562
3674
|
if (!n)
|
|
3563
3675
|
return !1;
|
|
3564
|
-
const r =
|
|
3676
|
+
const r = Nn(t);
|
|
3565
3677
|
return n.length > 0 && n[1] === r;
|
|
3566
3678
|
}
|
|
3567
|
-
async function
|
|
3568
|
-
if (!
|
|
3679
|
+
async function xi(e, t, n, r) {
|
|
3680
|
+
if (!gt(e))
|
|
3569
3681
|
throw new Error("Invalid nostr event, signature invalid");
|
|
3570
|
-
if (!
|
|
3682
|
+
if (!bi(e))
|
|
3571
3683
|
throw new Error("Invalid nostr event, kind invalid");
|
|
3572
|
-
if (!
|
|
3684
|
+
if (!wi(e))
|
|
3573
3685
|
throw new Error("Invalid nostr event, created_at timestamp invalid");
|
|
3574
|
-
if (!
|
|
3686
|
+
if (!vi(e, t))
|
|
3575
3687
|
throw new Error("Invalid nostr event, url tag invalid");
|
|
3576
|
-
if (!
|
|
3688
|
+
if (!mi(e, n))
|
|
3577
3689
|
throw new Error("Invalid nostr event, method tag invalid");
|
|
3578
|
-
if (r && typeof r == "object" && Object.keys(r).length > 0 && !
|
|
3690
|
+
if (r && typeof r == "object" && Object.keys(r).length > 0 && !Ei(e, r))
|
|
3579
3691
|
throw new Error("Invalid nostr event, payload tag does not match request body hash");
|
|
3580
3692
|
return !0;
|
|
3581
3693
|
}
|
|
3582
|
-
const Oe = 1060,
|
|
3583
|
-
function
|
|
3694
|
+
const Oe = 1060, Vn = 30078, Zn = 1059, iu = 14, wu = 100, su = 1;
|
|
3695
|
+
function bu(e) {
|
|
3584
3696
|
return JSON.stringify({
|
|
3585
|
-
version:
|
|
3586
|
-
rootKey:
|
|
3697
|
+
version: su,
|
|
3698
|
+
rootKey: H(e.rootKey),
|
|
3587
3699
|
theirCurrentNostrPublicKey: e.theirCurrentNostrPublicKey,
|
|
3588
3700
|
theirNextNostrPublicKey: e.theirNextNostrPublicKey,
|
|
3589
3701
|
ourCurrentNostrKey: e.ourCurrentNostrKey ? {
|
|
3590
3702
|
publicKey: e.ourCurrentNostrKey.publicKey,
|
|
3591
|
-
privateKey:
|
|
3703
|
+
privateKey: H(e.ourCurrentNostrKey.privateKey)
|
|
3592
3704
|
} : void 0,
|
|
3593
3705
|
ourNextNostrKey: {
|
|
3594
3706
|
publicKey: e.ourNextNostrKey.publicKey,
|
|
3595
|
-
privateKey:
|
|
3707
|
+
privateKey: H(e.ourNextNostrKey.privateKey)
|
|
3596
3708
|
},
|
|
3597
|
-
receivingChainKey: e.receivingChainKey ?
|
|
3598
|
-
sendingChainKey: e.sendingChainKey ?
|
|
3709
|
+
receivingChainKey: e.receivingChainKey ? H(e.receivingChainKey) : void 0,
|
|
3710
|
+
sendingChainKey: e.sendingChainKey ? H(e.sendingChainKey) : void 0,
|
|
3599
3711
|
sendingChainMessageNumber: e.sendingChainMessageNumber,
|
|
3600
3712
|
receivingChainMessageNumber: e.receivingChainMessageNumber,
|
|
3601
3713
|
previousSendingChainMessageCount: e.previousSendingChainMessageCount,
|
|
@@ -3603,11 +3715,11 @@ function cu(e) {
|
|
|
3603
3715
|
Object.entries(e.skippedKeys).map(([t, n]) => [
|
|
3604
3716
|
t,
|
|
3605
3717
|
{
|
|
3606
|
-
headerKeys: n.headerKeys.map((r) =>
|
|
3718
|
+
headerKeys: n.headerKeys.map((r) => H(r)),
|
|
3607
3719
|
messageKeys: Object.fromEntries(
|
|
3608
3720
|
Object.entries(n.messageKeys).map(([r, i]) => [
|
|
3609
3721
|
r,
|
|
3610
|
-
|
|
3722
|
+
H(i)
|
|
3611
3723
|
])
|
|
3612
3724
|
)
|
|
3613
3725
|
}
|
|
@@ -3615,7 +3727,7 @@ function cu(e) {
|
|
|
3615
3727
|
)
|
|
3616
3728
|
});
|
|
3617
3729
|
}
|
|
3618
|
-
function
|
|
3730
|
+
function vu(e) {
|
|
3619
3731
|
const t = JSON.parse(e);
|
|
3620
3732
|
if (!t.version) {
|
|
3621
3733
|
const n = {};
|
|
@@ -3678,7 +3790,7 @@ function uu(e) {
|
|
|
3678
3790
|
)
|
|
3679
3791
|
};
|
|
3680
3792
|
}
|
|
3681
|
-
async function*
|
|
3793
|
+
async function* mu(e) {
|
|
3682
3794
|
const t = [];
|
|
3683
3795
|
let n = null;
|
|
3684
3796
|
const r = e.onEvent((i) => {
|
|
@@ -3693,22 +3805,22 @@ async function* lu(e) {
|
|
|
3693
3805
|
r();
|
|
3694
3806
|
}
|
|
3695
3807
|
}
|
|
3696
|
-
function
|
|
3808
|
+
function Me(e, t = new Uint8Array(32), n = 1) {
|
|
3697
3809
|
const r = rn(fe, e, t), i = [];
|
|
3698
3810
|
for (let s = 1; s <= n; s++)
|
|
3699
|
-
i.push(
|
|
3811
|
+
i.push(Ir(fe, r, new Uint8Array([s]), 32));
|
|
3700
3812
|
return i;
|
|
3701
3813
|
}
|
|
3702
|
-
function
|
|
3814
|
+
function Eu(e, t) {
|
|
3703
3815
|
return `${e}:${t}`;
|
|
3704
3816
|
}
|
|
3705
|
-
function
|
|
3817
|
+
function xu(e) {
|
|
3706
3818
|
var n;
|
|
3707
3819
|
const t = (n = e.tags) == null ? void 0 : n.find((r) => r[0] === "ms");
|
|
3708
3820
|
return t ? parseInt(t[1]) : e.created_at * 1e3;
|
|
3709
3821
|
}
|
|
3710
|
-
const
|
|
3711
|
-
class
|
|
3822
|
+
const ou = 1e3, au = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
3823
|
+
class ot {
|
|
3712
3824
|
// 1. CHANNEL PUBLIC INTERFACE
|
|
3713
3825
|
constructor(t, n) {
|
|
3714
3826
|
J(this, "skippedSubscription");
|
|
@@ -3721,7 +3833,7 @@ class st {
|
|
|
3721
3833
|
}
|
|
3722
3834
|
/**
|
|
3723
3835
|
* Initializes a new secure communication session
|
|
3724
|
-
* @param nostrSubscribe Function to subscribe to Nostr events
|
|
3836
|
+
* @param nostrSubscribe Function to subscribe to Nostr events. Make sure it deduplicates events (doesnt return the same event twice), otherwise you'll see decryption errors!
|
|
3725
3837
|
* @param theirNextNostrPublicKey The public key of the other party
|
|
3726
3838
|
* @param ourCurrentPrivateKey Our current private key for Nostr
|
|
3727
3839
|
* @param isInitiator Whether we are initiating the conversation (true) or responding (false)
|
|
@@ -3732,14 +3844,14 @@ class st {
|
|
|
3732
3844
|
static init(t, n, r, i, s, o) {
|
|
3733
3845
|
const c = ke();
|
|
3734
3846
|
let a, l, f, u;
|
|
3735
|
-
i ? ([a, l] =
|
|
3736
|
-
publicKey:
|
|
3847
|
+
i ? ([a, l] = Me(s, D.getConversationKey(c, n), 2), f = {
|
|
3848
|
+
publicKey: ae(r),
|
|
3737
3849
|
privateKey: r
|
|
3738
3850
|
}, u = {
|
|
3739
|
-
publicKey:
|
|
3851
|
+
publicKey: ae(c),
|
|
3740
3852
|
privateKey: c
|
|
3741
3853
|
}) : (a = s, l = void 0, f = void 0, u = {
|
|
3742
|
-
publicKey:
|
|
3854
|
+
publicKey: ae(r),
|
|
3743
3855
|
privateKey: r
|
|
3744
3856
|
});
|
|
3745
3857
|
const g = {
|
|
@@ -3753,7 +3865,7 @@ class st {
|
|
|
3753
3865
|
receivingChainMessageNumber: 0,
|
|
3754
3866
|
previousSendingChainMessageCount: 0,
|
|
3755
3867
|
skippedKeys: {}
|
|
3756
|
-
}, w = new
|
|
3868
|
+
}, w = new ot(t, g);
|
|
3757
3869
|
return o && (w.name = o), w;
|
|
3758
3870
|
}
|
|
3759
3871
|
/**
|
|
@@ -3766,7 +3878,7 @@ class st {
|
|
|
3766
3878
|
send(t) {
|
|
3767
3879
|
return this.sendEvent({
|
|
3768
3880
|
content: t,
|
|
3769
|
-
kind:
|
|
3881
|
+
kind: iu
|
|
3770
3882
|
});
|
|
3771
3883
|
}
|
|
3772
3884
|
/**
|
|
@@ -3787,10 +3899,10 @@ class st {
|
|
|
3787
3899
|
kind: t.kind || Oe,
|
|
3788
3900
|
created_at: t.created_at || Math.floor(n / 1e3),
|
|
3789
3901
|
tags: t.tags || [],
|
|
3790
|
-
pubkey: t.pubkey ||
|
|
3902
|
+
pubkey: t.pubkey || au
|
|
3791
3903
|
};
|
|
3792
3904
|
r.tags.some(([l]) => l === "ms") || r.tags.push(["ms", String(n)]), r.id = qe(r);
|
|
3793
|
-
const [i, s] = this.ratchetEncrypt(JSON.stringify(r)), o =
|
|
3905
|
+
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);
|
|
3794
3906
|
return { event: Q({
|
|
3795
3907
|
content: s,
|
|
3796
3908
|
kind: Oe,
|
|
@@ -3816,60 +3928,50 @@ class st {
|
|
|
3816
3928
|
}
|
|
3817
3929
|
// 2. RATCHET FUNCTIONS
|
|
3818
3930
|
ratchetEncrypt(t) {
|
|
3819
|
-
const [n, r] =
|
|
3931
|
+
const [n, r] = Me(this.state.sendingChainKey, new Uint8Array([1]), 2);
|
|
3820
3932
|
return this.state.sendingChainKey = n, [{
|
|
3821
3933
|
number: this.state.sendingChainMessageNumber++,
|
|
3822
3934
|
nextPublicKey: this.state.ourNextNostrKey.publicKey,
|
|
3823
3935
|
previousChainLength: this.state.previousSendingChainMessageCount
|
|
3824
|
-
},
|
|
3936
|
+
}, D.encrypt(t, r)];
|
|
3825
3937
|
}
|
|
3826
3938
|
ratchetDecrypt(t, n, r) {
|
|
3827
3939
|
const i = this.trySkippedMessageKeys(t, n, r);
|
|
3828
3940
|
if (i) return i;
|
|
3829
3941
|
this.skipMessageKeys(t.number, r);
|
|
3830
|
-
const [s, o] =
|
|
3831
|
-
this.state.receivingChainKey = s, this.state.receivingChainMessageNumber
|
|
3832
|
-
try {
|
|
3833
|
-
return q.decrypt(n, o);
|
|
3834
|
-
} catch (c) {
|
|
3835
|
-
throw console.error(this.name, "Decryption failed:", c, {
|
|
3836
|
-
messageKey: P(o).slice(0, 4),
|
|
3837
|
-
receivingChainKey: P(this.state.receivingChainKey).slice(0, 4),
|
|
3838
|
-
sendingChainKey: this.state.sendingChainKey && P(this.state.sendingChainKey).slice(0, 4),
|
|
3839
|
-
rootKey: P(this.state.rootKey).slice(0, 4)
|
|
3840
|
-
}), c;
|
|
3841
|
-
}
|
|
3942
|
+
const [s, o] = Me(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3943
|
+
return this.state.receivingChainKey = s, this.state.receivingChainMessageNumber++, D.decrypt(n, o);
|
|
3842
3944
|
}
|
|
3843
3945
|
ratchetStep() {
|
|
3844
3946
|
this.state.previousSendingChainMessageCount = this.state.sendingChainMessageNumber, this.state.sendingChainMessageNumber = 0, this.state.receivingChainMessageNumber = 0;
|
|
3845
|
-
const t =
|
|
3947
|
+
const t = D.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [n, r] = Me(this.state.rootKey, t, 2);
|
|
3846
3948
|
this.state.receivingChainKey = r, this.state.ourCurrentNostrKey = this.state.ourNextNostrKey;
|
|
3847
3949
|
const i = ke();
|
|
3848
3950
|
this.state.ourNextNostrKey = {
|
|
3849
|
-
publicKey:
|
|
3951
|
+
publicKey: ae(i),
|
|
3850
3952
|
privateKey: i
|
|
3851
3953
|
};
|
|
3852
|
-
const s =
|
|
3954
|
+
const s = D.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNextNostrPublicKey), [o, c] = Me(n, s, 2);
|
|
3853
3955
|
this.state.rootKey = o, this.state.sendingChainKey = c;
|
|
3854
3956
|
}
|
|
3855
3957
|
// 3. MESSAGE KEY FUNCTIONS
|
|
3856
3958
|
skipMessageKeys(t, n) {
|
|
3857
3959
|
if (!(t <= this.state.receivingChainMessageNumber)) {
|
|
3858
|
-
if (t > this.state.receivingChainMessageNumber +
|
|
3960
|
+
if (t > this.state.receivingChainMessageNumber + ou)
|
|
3859
3961
|
throw new Error("Too many skipped messages");
|
|
3860
3962
|
if (!this.state.skippedKeys[n]) {
|
|
3861
3963
|
if (this.state.skippedKeys[n] = {
|
|
3862
3964
|
headerKeys: [],
|
|
3863
3965
|
messageKeys: {}
|
|
3864
3966
|
}, this.state.ourCurrentNostrKey) {
|
|
3865
|
-
const i =
|
|
3967
|
+
const i = D.getConversationKey(this.state.ourCurrentNostrKey.privateKey, n);
|
|
3866
3968
|
this.state.skippedKeys[n].headerKeys.includes(i) || this.state.skippedKeys[n].headerKeys.push(i);
|
|
3867
3969
|
}
|
|
3868
|
-
const r =
|
|
3970
|
+
const r = D.getConversationKey(this.state.ourNextNostrKey.privateKey, n);
|
|
3869
3971
|
this.state.skippedKeys[n].headerKeys.includes(r) || this.state.skippedKeys[n].headerKeys.push(r);
|
|
3870
3972
|
}
|
|
3871
3973
|
for (; this.state.receivingChainMessageNumber < t; ) {
|
|
3872
|
-
const [r, i] =
|
|
3974
|
+
const [r, i] = Me(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3873
3975
|
this.state.receivingChainKey = r, this.state.skippedKeys[n].messageKeys[this.state.receivingChainMessageNumber] = i, this.state.receivingChainMessageNumber++;
|
|
3874
3976
|
}
|
|
3875
3977
|
}
|
|
@@ -3878,28 +3980,28 @@ class st {
|
|
|
3878
3980
|
const i = this.state.skippedKeys[r];
|
|
3879
3981
|
if (!i) return null;
|
|
3880
3982
|
const s = i.messageKeys[t.number];
|
|
3881
|
-
return s ? (delete i.messageKeys[t.number], Object.keys(i.messageKeys).length === 0 && delete this.state.skippedKeys[r],
|
|
3983
|
+
return s ? (delete i.messageKeys[t.number], Object.keys(i.messageKeys).length === 0 && delete this.state.skippedKeys[r], D.decrypt(n, s)) : null;
|
|
3882
3984
|
}
|
|
3883
3985
|
// 4. NOSTR EVENT HANDLING
|
|
3884
3986
|
decryptHeader(t) {
|
|
3885
3987
|
const n = t.tags[0][1];
|
|
3886
3988
|
if (this.state.ourCurrentNostrKey) {
|
|
3887
|
-
const s =
|
|
3989
|
+
const s = D.getConversationKey(this.state.ourCurrentNostrKey.privateKey, t.pubkey);
|
|
3888
3990
|
try {
|
|
3889
|
-
return [JSON.parse(
|
|
3991
|
+
return [JSON.parse(D.decrypt(n, s)), !1, !1];
|
|
3890
3992
|
} catch {
|
|
3891
3993
|
}
|
|
3892
3994
|
}
|
|
3893
|
-
const r =
|
|
3995
|
+
const r = D.getConversationKey(this.state.ourNextNostrKey.privateKey, t.pubkey);
|
|
3894
3996
|
try {
|
|
3895
|
-
return [JSON.parse(
|
|
3997
|
+
return [JSON.parse(D.decrypt(n, r)), !0, !1];
|
|
3896
3998
|
} catch {
|
|
3897
3999
|
}
|
|
3898
4000
|
const i = this.state.skippedKeys[t.pubkey];
|
|
3899
4001
|
if (i != null && i.headerKeys)
|
|
3900
4002
|
for (const s of i.headerKeys)
|
|
3901
4003
|
try {
|
|
3902
|
-
return [JSON.parse(
|
|
4004
|
+
return [JSON.parse(D.decrypt(n, s)), !1, !0];
|
|
3903
4005
|
} catch {
|
|
3904
4006
|
}
|
|
3905
4007
|
throw new Error("Failed to decrypt header with current and skipped header keys");
|
|
@@ -3915,15 +4017,7 @@ class st {
|
|
|
3915
4017
|
else if (!((a = this.state.skippedKeys[t.pubkey]) != null && a.messageKeys[n.number]))
|
|
3916
4018
|
return;
|
|
3917
4019
|
const s = this.ratchetDecrypt(n, t.content, t.pubkey), o = JSON.parse(s);
|
|
3918
|
-
|
|
3919
|
-
console.error("Invalid event received", o);
|
|
3920
|
-
return;
|
|
3921
|
-
}
|
|
3922
|
-
if (o.id !== qe(o)) {
|
|
3923
|
-
console.error("Event hash does not match", o);
|
|
3924
|
-
return;
|
|
3925
|
-
}
|
|
3926
|
-
this.internalSubscriptions.forEach((l) => l(o, t));
|
|
4020
|
+
pt(o) && o.id === qe(o) && this.internalSubscriptions.forEach((l) => l(o, t));
|
|
3927
4021
|
}
|
|
3928
4022
|
subscribeToNostrEvents() {
|
|
3929
4023
|
if (this.nostrNextUnsubscribe) return;
|
|
@@ -3947,16 +4041,16 @@ function Qe(e, t) {
|
|
|
3947
4041
|
const n = Ie.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3948
4042
|
return rn(fe, n, "nip44-v2");
|
|
3949
4043
|
}
|
|
3950
|
-
const
|
|
3951
|
-
class
|
|
4044
|
+
const cu = 2 * 24 * 60 * 60, uu = () => Math.round(Date.now() / 1e3), lu = () => Math.round(uu() - Math.random() * cu);
|
|
4045
|
+
class Pe {
|
|
3952
4046
|
constructor(t, n, r, i, s, o, c = []) {
|
|
3953
4047
|
this.inviterEphemeralPublicKey = t, this.sharedSecret = n, this.inviter = r, this.inviterEphemeralPrivateKey = i, this.label = s, this.maxUses = o, this.usedBy = c;
|
|
3954
4048
|
}
|
|
3955
4049
|
static createNew(t, n, r) {
|
|
3956
4050
|
if (!t)
|
|
3957
4051
|
throw new Error("Inviter public key is required");
|
|
3958
|
-
const i = ke(), s =
|
|
3959
|
-
return new
|
|
4052
|
+
const i = ke(), s = ae(i), o = H(ke());
|
|
4053
|
+
return new Pe(
|
|
3960
4054
|
s,
|
|
3961
4055
|
o,
|
|
3962
4056
|
t,
|
|
@@ -3979,7 +4073,7 @@ class Me {
|
|
|
3979
4073
|
const { inviter: o, ephemeralKey: c, sharedSecret: a } = s;
|
|
3980
4074
|
if (!o || !c || !a)
|
|
3981
4075
|
throw new Error("Missing required fields (inviter, ephemeralKey, sharedSecret) in invite data.");
|
|
3982
|
-
return new
|
|
4076
|
+
return new Pe(
|
|
3983
4077
|
c,
|
|
3984
4078
|
a,
|
|
3985
4079
|
o
|
|
@@ -3987,7 +4081,7 @@ class Me {
|
|
|
3987
4081
|
}
|
|
3988
4082
|
static deserialize(t) {
|
|
3989
4083
|
const n = JSON.parse(t);
|
|
3990
|
-
return new
|
|
4084
|
+
return new Pe(
|
|
3991
4085
|
n.inviterEphemeralPublicKey,
|
|
3992
4086
|
n.sharedSecret,
|
|
3993
4087
|
n.inviter,
|
|
@@ -4001,7 +4095,7 @@ class Me {
|
|
|
4001
4095
|
var o, c;
|
|
4002
4096
|
if (!t.sig)
|
|
4003
4097
|
throw new Error("Event is not signed");
|
|
4004
|
-
if (!
|
|
4098
|
+
if (!gt(t))
|
|
4005
4099
|
throw new Error("Event signature is invalid");
|
|
4006
4100
|
const { tags: n } = t;
|
|
4007
4101
|
if (!n)
|
|
@@ -4009,7 +4103,7 @@ class Me {
|
|
|
4009
4103
|
const r = (o = n.find(([a]) => a === "ephemeralKey")) == null ? void 0 : o[1], i = (c = n.find(([a]) => a === "sharedSecret")) == null ? void 0 : c[1], s = t.pubkey;
|
|
4010
4104
|
if (!r || !i)
|
|
4011
4105
|
throw new Error("Invalid invite event: missing session key or sharedSecret");
|
|
4012
|
-
return new
|
|
4106
|
+
return new Pe(
|
|
4013
4107
|
r,
|
|
4014
4108
|
i,
|
|
4015
4109
|
s
|
|
@@ -4017,20 +4111,18 @@ class Me {
|
|
|
4017
4111
|
}
|
|
4018
4112
|
static fromUser(t, n, r) {
|
|
4019
4113
|
const i = {
|
|
4020
|
-
kinds: [
|
|
4114
|
+
kinds: [Vn],
|
|
4021
4115
|
authors: [t],
|
|
4022
|
-
|
|
4023
|
-
"#d": ["double-ratchet/invites/public"]
|
|
4116
|
+
"#l": ["double-ratchet/invites"]
|
|
4024
4117
|
};
|
|
4025
4118
|
let s = 0;
|
|
4026
4119
|
return n(i, (c) => {
|
|
4027
4120
|
if (!(!c.created_at || c.created_at <= s)) {
|
|
4028
4121
|
s = c.created_at;
|
|
4029
4122
|
try {
|
|
4030
|
-
const a =
|
|
4123
|
+
const a = Pe.fromEvent(c);
|
|
4031
4124
|
r(a);
|
|
4032
|
-
} catch
|
|
4033
|
-
console.error("Error processing invite:", a, "event:", c);
|
|
4125
|
+
} catch {
|
|
4034
4126
|
}
|
|
4035
4127
|
}
|
|
4036
4128
|
});
|
|
@@ -4060,16 +4152,18 @@ class Me {
|
|
|
4060
4152
|
}, r = new URL(t);
|
|
4061
4153
|
return r.hash = encodeURIComponent(JSON.stringify(n)), r.toString();
|
|
4062
4154
|
}
|
|
4063
|
-
getEvent() {
|
|
4155
|
+
getEvent(t) {
|
|
4156
|
+
if (!t)
|
|
4157
|
+
throw new Error("Device name is required");
|
|
4064
4158
|
return {
|
|
4065
|
-
kind:
|
|
4159
|
+
kind: Vn,
|
|
4066
4160
|
pubkey: this.inviter,
|
|
4067
4161
|
content: "",
|
|
4068
4162
|
created_at: Math.floor(Date.now() / 1e3),
|
|
4069
4163
|
tags: [
|
|
4070
4164
|
["ephemeralKey", this.inviterEphemeralPublicKey],
|
|
4071
4165
|
["sharedSecret", this.sharedSecret],
|
|
4072
|
-
["d", "double-ratchet/invites/
|
|
4166
|
+
["d", "double-ratchet/invites/" + t],
|
|
4073
4167
|
["l", "double-ratchet/invites"]
|
|
4074
4168
|
]
|
|
4075
4169
|
};
|
|
@@ -4090,15 +4184,15 @@ class Me {
|
|
|
4090
4184
|
* so the inviter can create the session on their side.
|
|
4091
4185
|
*/
|
|
4092
4186
|
async accept(t, n, r) {
|
|
4093
|
-
const i = ke(), s =
|
|
4187
|
+
const i = ke(), s = ae(i), o = this.inviter || this.inviterEphemeralPublicKey, c = z(this.sharedSecret), a = ot.init(t, this.inviterEphemeralPublicKey, i, !0, c, void 0), f = await (typeof r == "function" ? r : (d, p) => Promise.resolve(D.encrypt(d, Qe(r, p))))(s, o), u = {
|
|
4094
4188
|
pubkey: n,
|
|
4095
|
-
content: await
|
|
4189
|
+
content: await D.encrypt(f, c),
|
|
4096
4190
|
created_at: Math.floor(Date.now() / 1e3)
|
|
4097
|
-
}, g = JSON.stringify(u), w = ke(),
|
|
4098
|
-
kind:
|
|
4099
|
-
pubkey:
|
|
4100
|
-
content:
|
|
4101
|
-
created_at:
|
|
4191
|
+
}, g = JSON.stringify(u), w = ke(), y = ae(w), h = {
|
|
4192
|
+
kind: Zn,
|
|
4193
|
+
pubkey: y,
|
|
4194
|
+
content: D.encrypt(g, Qe(w, this.inviterEphemeralPublicKey)),
|
|
4195
|
+
created_at: lu(),
|
|
4102
4196
|
tags: [["p", this.inviterEphemeralPublicKey]]
|
|
4103
4197
|
};
|
|
4104
4198
|
return { session: a, event: Q(h, w) };
|
|
@@ -4107,37 +4201,34 @@ class Me {
|
|
|
4107
4201
|
if (!this.inviterEphemeralPrivateKey)
|
|
4108
4202
|
throw new Error("Inviter session key is not available");
|
|
4109
4203
|
const i = {
|
|
4110
|
-
kinds: [
|
|
4204
|
+
kinds: [Zn],
|
|
4111
4205
|
"#p": [this.inviterEphemeralPublicKey]
|
|
4112
4206
|
};
|
|
4113
4207
|
return n(i, async (s) => {
|
|
4114
4208
|
try {
|
|
4115
|
-
if (this.maxUses && this.usedBy.length >= this.maxUses)
|
|
4116
|
-
console.error("Invite has reached maximum number of uses");
|
|
4209
|
+
if (this.maxUses && this.usedBy.length >= this.maxUses)
|
|
4117
4210
|
return;
|
|
4118
|
-
|
|
4119
|
-
const o = await q.decrypt(s.content, Qe(this.inviterEphemeralPrivateKey, s.pubkey)), c = JSON.parse(o), a = z(this.sharedSecret), l = c.pubkey;
|
|
4211
|
+
const o = await D.decrypt(s.content, Qe(this.inviterEphemeralPrivateKey, s.pubkey)), c = JSON.parse(o), a = z(this.sharedSecret), l = c.pubkey;
|
|
4120
4212
|
this.usedBy.push(l);
|
|
4121
|
-
const f = await
|
|
4122
|
-
r(
|
|
4123
|
-
} catch
|
|
4124
|
-
console.error("Error processing invite message:", o, "event", s);
|
|
4213
|
+
const f = await D.decrypt(c.content, a), g = await (typeof t == "function" ? t : (h, d) => Promise.resolve(D.decrypt(h, Qe(t, d))))(f, l), w = s.id, y = ot.init(n, g, this.inviterEphemeralPrivateKey, !1, a, w);
|
|
4214
|
+
r(y, l);
|
|
4215
|
+
} catch {
|
|
4125
4216
|
}
|
|
4126
4217
|
});
|
|
4127
4218
|
}
|
|
4128
4219
|
}
|
|
4129
4220
|
export {
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4221
|
+
iu as CHAT_MESSAGE_KIND,
|
|
4222
|
+
Vn as INVITE_EVENT_KIND,
|
|
4223
|
+
Zn as INVITE_RESPONSE_KIND,
|
|
4224
|
+
Pe as Invite,
|
|
4225
|
+
wu as MAX_SKIP,
|
|
4135
4226
|
Oe as MESSAGE_EVENT_KIND,
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4227
|
+
ot as Session,
|
|
4228
|
+
mu as createEventStream,
|
|
4229
|
+
vu as deserializeSessionState,
|
|
4230
|
+
xu as getMillisecondTimestamp,
|
|
4231
|
+
Me as kdf,
|
|
4232
|
+
bu as serializeSessionState,
|
|
4233
|
+
Eu as skippedMessageIndexKey
|
|
4143
4234
|
};
|