nostr-double-ratchet 0.0.10 → 0.0.12
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/README.md +10 -1
- package/dist/Invite.d.ts +8 -8
- package/dist/Invite.d.ts.map +1 -1
- package/dist/{Channel.d.ts → Session.d.ts} +12 -12
- package/dist/{Channel.d.ts.map → Session.d.ts.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/nostr-double-ratchet.es.js +1448 -1343
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/utils.d.ts +5 -5
- package/dist/utils.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/Invite.ts +30 -30
- package/src/{Channel.ts → Session.ts} +14 -14
- package/src/index.ts +1 -1
- package/src/types.ts +3 -3
- package/src/utils.ts +6 -6
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
function
|
|
1
|
+
var bi = Object.defineProperty;
|
|
2
|
+
var vi = (e, t, n) => t in e ? bi(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var te = (e, t, n) => vi(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
function Kn(e) {
|
|
5
5
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
6
6
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function zn(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 mi(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
|
+
Kn(e.outputLen), Kn(e.blockLen);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function et(e, t = !0) {
|
|
20
20
|
if (e.destroyed)
|
|
21
21
|
throw new Error("Hash instance has been destroyed");
|
|
22
22
|
if (t && e.finished)
|
|
23
23
|
throw new Error("Hash#digest() has already been called");
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
25
|
+
function Ei(e, t) {
|
|
26
|
+
zn(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 Et = 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 Vn = (e) => e instanceof Uint8Array, xt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), re = (e, t) => e << 32 - t | e >>> t, xi = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
34
|
+
if (!xi)
|
|
35
35
|
throw new Error("Non little-endian hardware is not supported");
|
|
36
|
-
function
|
|
36
|
+
function Si(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 Wt(e) {
|
|
42
|
+
if (typeof e == "string" && (e = Si(e)), !Vn(e))
|
|
43
43
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
44
44
|
return e;
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function Ai(...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 (!Vn(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 Wn = 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 Ni(e) {
|
|
62
|
+
const t = (r) => e().update(Wt(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 Zn(e = 32) {
|
|
66
|
+
if (Et && typeof Et.getRandomValues == "function")
|
|
67
|
+
return Et.getRandomValues(new Uint8Array(e));
|
|
68
68
|
throw new Error("crypto.getRandomValues must be defined");
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function Ki(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), a = Number(n & s), c = r ? 4 : 0, l = r ? 0 : 4;
|
|
74
74
|
e.setUint32(t + c, o, r), e.setUint32(t + l, a, r);
|
|
75
75
|
}
|
|
76
|
-
let
|
|
76
|
+
let ki = class extends Wn {
|
|
77
77
|
constructor(t, n, r, i) {
|
|
78
|
-
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view =
|
|
78
|
+
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view = xt(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 = Wt(t);
|
|
84
84
|
const s = t.length;
|
|
85
85
|
for (let o = 0; o < s; ) {
|
|
86
86
|
const a = Math.min(i - this.pos, s - o);
|
|
87
87
|
if (a === i) {
|
|
88
|
-
const c =
|
|
88
|
+
const c = xt(t);
|
|
89
89
|
for (; i <= s - o; o += i)
|
|
90
90
|
this.process(c, o);
|
|
91
91
|
continue;
|
|
@@ -95,14 +95,14 @@ let yi = class extends Mn {
|
|
|
95
95
|
return this.length += t.length, this.roundClean(), this;
|
|
96
96
|
}
|
|
97
97
|
digestInto(t) {
|
|
98
|
-
|
|
98
|
+
et(this), Ei(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 a =
|
|
104
|
+
Ki(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
105
|
+
const a = xt(t), c = this.outputLen;
|
|
106
106
|
if (c % 4)
|
|
107
107
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
108
108
|
const l = c / 4, f = this.get();
|
|
@@ -123,7 +123,7 @@ let yi = class extends Mn {
|
|
|
123
123
|
return t.length = i, t.pos = a, t.finished = s, t.destroyed = o, i % n && t.buffer.set(r), t;
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
|
-
const
|
|
126
|
+
const Bi = (e, t, n) => e & t ^ ~e & n, Ci = (e, t, n) => e & t ^ e & n ^ t & n, Ui = /* @__PURE__ */ new Uint32Array([
|
|
127
127
|
1116352408,
|
|
128
128
|
1899447441,
|
|
129
129
|
3049323471,
|
|
@@ -188,7 +188,7 @@ const pi = (e, t, n) => e & t ^ ~e & n, gi = (e, t, n) => e & t ^ e & n ^ t & n,
|
|
|
188
188
|
2756734187,
|
|
189
189
|
3204031479,
|
|
190
190
|
3329325298
|
|
191
|
-
]),
|
|
191
|
+
]), be = /* @__PURE__ */ new Uint32Array([
|
|
192
192
|
1779033703,
|
|
193
193
|
3144134277,
|
|
194
194
|
1013904242,
|
|
@@ -197,10 +197,10 @@ const pi = (e, t, n) => e & t ^ ~e & n, gi = (e, t, n) => e & t ^ e & n ^ t & n,
|
|
|
197
197
|
2600822924,
|
|
198
198
|
528734635,
|
|
199
199
|
1541459225
|
|
200
|
-
]),
|
|
201
|
-
let
|
|
200
|
+
]), ve = /* @__PURE__ */ new Uint32Array(64);
|
|
201
|
+
let _i = class extends ki {
|
|
202
202
|
constructor() {
|
|
203
|
-
super(64, 32, 8, !1), this.A =
|
|
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
|
}
|
|
205
205
|
get() {
|
|
206
206
|
const { A: t, B: n, C: r, D: i, E: s, F: o, G: a, H: c } = this;
|
|
@@ -212,41 +212,41 @@ let bi = class extends yi {
|
|
|
212
212
|
}
|
|
213
213
|
process(t, n) {
|
|
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
|
|
218
|
-
|
|
217
|
+
const g = ve[u - 15], b = ve[u - 2], p = re(g, 7) ^ re(g, 18) ^ g >>> 3, h = re(b, 17) ^ re(b, 19) ^ b >>> 10;
|
|
218
|
+
ve[u] = h + ve[u - 7] + p + ve[u - 16] | 0;
|
|
219
219
|
}
|
|
220
220
|
let { A: r, B: i, C: s, D: o, E: a, F: c, G: l, H: f } = this;
|
|
221
221
|
for (let u = 0; u < 64; u++) {
|
|
222
|
-
const
|
|
223
|
-
f = l, l = c, c = a, a = o +
|
|
222
|
+
const g = re(a, 6) ^ re(a, 11) ^ re(a, 25), b = f + g + Bi(a, c, l) + Ui[u] + ve[u] | 0, h = (re(r, 2) ^ re(r, 13) ^ re(r, 22)) + Ci(r, i, s) | 0;
|
|
223
|
+
f = l, l = c, c = a, a = o + b | 0, o = s, s = i, i = r, r = b + 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, a = a + this.E | 0, c = c + this.F | 0, l = l + this.G | 0, f = f + this.H | 0, this.set(r, i, s, o, a, c, l, f);
|
|
226
226
|
}
|
|
227
227
|
roundClean() {
|
|
228
|
-
|
|
228
|
+
ve.fill(0);
|
|
229
229
|
}
|
|
230
230
|
destroy() {
|
|
231
231
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
|
|
232
232
|
}
|
|
233
233
|
};
|
|
234
|
-
const
|
|
234
|
+
const Lt = /* @__PURE__ */ Ni(() => new _i());
|
|
235
235
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
236
|
-
const
|
|
236
|
+
const Gn = BigInt(0), ot = BigInt(1), Ii = BigInt(2), at = (e) => e instanceof Uint8Array, Li = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
237
237
|
function qe(e) {
|
|
238
|
-
if (!
|
|
238
|
+
if (!at(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 += Li[e[n]];
|
|
243
243
|
return t;
|
|
244
244
|
}
|
|
245
|
-
function
|
|
245
|
+
function Fn(e) {
|
|
246
246
|
const t = e.toString(16);
|
|
247
247
|
return t.length & 1 ? `0${t}` : t;
|
|
248
248
|
}
|
|
249
|
-
function
|
|
249
|
+
function Zt(e) {
|
|
250
250
|
if (typeof e != "string")
|
|
251
251
|
throw new Error("hex string expected, got " + typeof e);
|
|
252
252
|
return BigInt(e === "" ? "0" : `0x${e}`);
|
|
@@ -266,24 +266,24 @@ function De(e) {
|
|
|
266
266
|
}
|
|
267
267
|
return n;
|
|
268
268
|
}
|
|
269
|
-
function
|
|
270
|
-
return
|
|
269
|
+
function F(e) {
|
|
270
|
+
return Zt(qe(e));
|
|
271
271
|
}
|
|
272
|
-
function
|
|
273
|
-
if (!
|
|
272
|
+
function Gt(e) {
|
|
273
|
+
if (!at(e))
|
|
274
274
|
throw new Error("Uint8Array expected");
|
|
275
|
-
return
|
|
275
|
+
return Zt(qe(Uint8Array.from(e).reverse()));
|
|
276
276
|
}
|
|
277
|
-
function
|
|
277
|
+
function Ae(e, t) {
|
|
278
278
|
return De(e.toString(16).padStart(t * 2, "0"));
|
|
279
279
|
}
|
|
280
|
-
function
|
|
281
|
-
return
|
|
280
|
+
function Ft(e, t) {
|
|
281
|
+
return Ae(e, t).reverse();
|
|
282
282
|
}
|
|
283
|
-
function
|
|
284
|
-
return De(
|
|
283
|
+
function $i(e) {
|
|
284
|
+
return De(Fn(e));
|
|
285
285
|
}
|
|
286
|
-
function
|
|
286
|
+
function W(e, t, n) {
|
|
287
287
|
let r;
|
|
288
288
|
if (typeof t == "string")
|
|
289
289
|
try {
|
|
@@ -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 (at(t))
|
|
295
295
|
r = Uint8Array.from(t);
|
|
296
296
|
else
|
|
297
297
|
throw new Error(`${e} must be hex string or Uint8Array`);
|
|
@@ -300,16 +300,16 @@ function Z(e, t, n) {
|
|
|
300
300
|
throw new Error(`${e} expected ${n} bytes, got ${i}`);
|
|
301
301
|
return r;
|
|
302
302
|
}
|
|
303
|
-
function
|
|
303
|
+
function Ue(...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 (!at(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 Ti(e, t) {
|
|
313
313
|
if (e.length !== t.length)
|
|
314
314
|
return !1;
|
|
315
315
|
for (let n = 0; n < e.length; n++)
|
|
@@ -317,54 +317,54 @@ function xi(e, t) {
|
|
|
317
317
|
return !1;
|
|
318
318
|
return !0;
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function Ri(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 Oi(e) {
|
|
326
326
|
let t;
|
|
327
|
-
for (t = 0; e >
|
|
327
|
+
for (t = 0; e > Gn; e >>= ot, t += 1)
|
|
328
328
|
;
|
|
329
329
|
return t;
|
|
330
330
|
}
|
|
331
|
-
function
|
|
332
|
-
return e >> BigInt(t) &
|
|
331
|
+
function Mi(e, t) {
|
|
332
|
+
return e >> BigInt(t) & ot;
|
|
333
333
|
}
|
|
334
|
-
const
|
|
335
|
-
function
|
|
334
|
+
const Hi = (e, t, n) => e | (n ? ot : Gn) << BigInt(t), Jt = (e) => (Ii << BigInt(e - 1)) - ot, St = (e) => new Uint8Array(e), kn = (e) => Uint8Array.from(e);
|
|
335
|
+
function Jn(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
|
-
}, a = (...u) => n(i, r, ...u), c = (u =
|
|
346
|
-
i = a(
|
|
345
|
+
}, a = (...u) => n(i, r, ...u), c = (u = St()) => {
|
|
346
|
+
i = a(kn([0]), u), r = a(), u.length !== 0 && (i = a(kn([1]), u), r = a());
|
|
347
347
|
}, l = () => {
|
|
348
348
|
if (s++ >= 1e3)
|
|
349
349
|
throw new Error("drbg: tried 1000 values");
|
|
350
350
|
let u = 0;
|
|
351
|
-
const
|
|
351
|
+
const g = [];
|
|
352
352
|
for (; u < t; ) {
|
|
353
353
|
r = a();
|
|
354
|
-
const
|
|
355
|
-
|
|
354
|
+
const b = r.slice();
|
|
355
|
+
g.push(b), u += r.length;
|
|
356
356
|
}
|
|
357
|
-
return
|
|
357
|
+
return Ue(...g);
|
|
358
358
|
};
|
|
359
|
-
return (u,
|
|
359
|
+
return (u, g) => {
|
|
360
360
|
o(), c(u);
|
|
361
|
-
let
|
|
362
|
-
for (; !(
|
|
361
|
+
let b;
|
|
362
|
+
for (; !(b = g(l())); )
|
|
363
363
|
c();
|
|
364
|
-
return o(),
|
|
364
|
+
return o(), b;
|
|
365
365
|
};
|
|
366
366
|
}
|
|
367
|
-
const
|
|
367
|
+
const Pi = {
|
|
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 Bi = {
|
|
|
377
377
|
};
|
|
378
378
|
function Je(e, t, n = {}) {
|
|
379
379
|
const r = (i, s, o) => {
|
|
380
|
-
const a =
|
|
380
|
+
const a = Pi[s];
|
|
381
381
|
if (typeof a != "function")
|
|
382
382
|
throw new Error(`Invalid validator "${s}", expected function`);
|
|
383
383
|
const c = e[i];
|
|
@@ -390,73 +390,73 @@ function Je(e, t, n = {}) {
|
|
|
390
390
|
r(i, s, !0);
|
|
391
391
|
return e;
|
|
392
392
|
}
|
|
393
|
-
const
|
|
393
|
+
const qi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
394
394
|
__proto__: null,
|
|
395
|
-
bitGet:
|
|
396
|
-
bitLen:
|
|
395
|
+
bitGet: Mi,
|
|
396
|
+
bitLen: Oi,
|
|
397
397
|
bitMask: Jt,
|
|
398
|
-
bitSet:
|
|
398
|
+
bitSet: Hi,
|
|
399
399
|
bytesToHex: qe,
|
|
400
|
-
bytesToNumberBE:
|
|
401
|
-
bytesToNumberLE:
|
|
402
|
-
concatBytes:
|
|
403
|
-
createHmacDrbg:
|
|
404
|
-
ensureBytes:
|
|
405
|
-
equalBytes:
|
|
400
|
+
bytesToNumberBE: F,
|
|
401
|
+
bytesToNumberLE: Gt,
|
|
402
|
+
concatBytes: Ue,
|
|
403
|
+
createHmacDrbg: Jn,
|
|
404
|
+
ensureBytes: W,
|
|
405
|
+
equalBytes: Ti,
|
|
406
406
|
hexToBytes: De,
|
|
407
|
-
hexToNumber:
|
|
408
|
-
numberToBytesBE:
|
|
409
|
-
numberToBytesLE:
|
|
410
|
-
numberToHexUnpadded:
|
|
411
|
-
numberToVarBytesBE:
|
|
412
|
-
utf8ToBytes:
|
|
407
|
+
hexToNumber: Zt,
|
|
408
|
+
numberToBytesBE: Ae,
|
|
409
|
+
numberToBytesLE: Ft,
|
|
410
|
+
numberToHexUnpadded: Fn,
|
|
411
|
+
numberToVarBytesBE: $i,
|
|
412
|
+
utf8ToBytes: Ri,
|
|
413
413
|
validateObject: Je
|
|
414
414
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
415
415
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
416
|
-
const
|
|
416
|
+
const z = BigInt(0), D = BigInt(1), ke = BigInt(2), Di = BigInt(3), $t = BigInt(4), Bn = BigInt(5), Cn = 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 >= z ? n : t + n;
|
|
422
422
|
}
|
|
423
|
-
function
|
|
424
|
-
if (n <=
|
|
423
|
+
function ji(e, t, n) {
|
|
424
|
+
if (n <= z || t < z)
|
|
425
425
|
throw new Error("Expected power/modulo > 0");
|
|
426
|
-
if (n ===
|
|
427
|
-
return
|
|
428
|
-
let r =
|
|
429
|
-
for (; t >
|
|
430
|
-
t &
|
|
426
|
+
if (n === D)
|
|
427
|
+
return z;
|
|
428
|
+
let r = D;
|
|
429
|
+
for (; t > z; )
|
|
430
|
+
t & D && (r = r * e % n), e = e * e % n, t >>= D;
|
|
431
431
|
return r;
|
|
432
432
|
}
|
|
433
433
|
function J(e, t, n) {
|
|
434
434
|
let r = e;
|
|
435
|
-
for (; t-- >
|
|
435
|
+
for (; t-- > z; )
|
|
436
436
|
r *= r, r %= n;
|
|
437
437
|
return r;
|
|
438
438
|
}
|
|
439
|
-
function
|
|
440
|
-
if (e ===
|
|
439
|
+
function Tt(e, t) {
|
|
440
|
+
if (e === z || t <= z)
|
|
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 = z, s = D;
|
|
443
|
+
for (; n !== z; ) {
|
|
444
444
|
const a = r / n, c = r % n, l = i - s * a;
|
|
445
445
|
r = n, n = c, i = s, s = l;
|
|
446
446
|
}
|
|
447
|
-
if (r !==
|
|
447
|
+
if (r !== D)
|
|
448
448
|
throw new Error("invert: does not exist");
|
|
449
|
-
return
|
|
449
|
+
return V(i, t);
|
|
450
450
|
}
|
|
451
|
-
function
|
|
452
|
-
const t = (e -
|
|
451
|
+
function zi(e) {
|
|
452
|
+
const t = (e - D) / ke;
|
|
453
453
|
let n, r, i;
|
|
454
|
-
for (n = e -
|
|
454
|
+
for (n = e - D, r = 0; n % ke === z; n /= ke, r++)
|
|
455
455
|
;
|
|
456
|
-
for (i =
|
|
456
|
+
for (i = ke; i < e && ji(i, t, e) !== e - D; i++)
|
|
457
457
|
;
|
|
458
458
|
if (r === 1) {
|
|
459
|
-
const o = (e +
|
|
459
|
+
const o = (e + D) / $t;
|
|
460
460
|
return function(c, l) {
|
|
461
461
|
const f = c.pow(l, o);
|
|
462
462
|
if (!c.eql(c.sqr(f), l))
|
|
@@ -464,26 +464,26 @@ function Ii(e) {
|
|
|
464
464
|
return f;
|
|
465
465
|
};
|
|
466
466
|
}
|
|
467
|
-
const s = (n +
|
|
467
|
+
const s = (n + D) / ke;
|
|
468
468
|
return function(a, c) {
|
|
469
469
|
if (a.pow(c, t) === a.neg(a.ONE))
|
|
470
470
|
throw new Error("Cannot find square root");
|
|
471
|
-
let l = r, f = a.pow(a.mul(a.ONE, i), n), u = a.pow(c, s),
|
|
472
|
-
for (; !a.eql(
|
|
473
|
-
if (a.eql(
|
|
471
|
+
let l = r, f = a.pow(a.mul(a.ONE, i), n), u = a.pow(c, s), g = a.pow(c, n);
|
|
472
|
+
for (; !a.eql(g, a.ONE); ) {
|
|
473
|
+
if (a.eql(g, a.ZERO))
|
|
474
474
|
return a.ZERO;
|
|
475
|
-
let
|
|
476
|
-
for (let h = a.sqr(
|
|
475
|
+
let b = 1;
|
|
476
|
+
for (let h = a.sqr(g); b < l && !a.eql(h, a.ONE); b++)
|
|
477
477
|
h = a.sqr(h);
|
|
478
|
-
const
|
|
479
|
-
f = a.sqr(
|
|
478
|
+
const p = a.pow(f, D << BigInt(l - b - 1));
|
|
479
|
+
f = a.sqr(p), u = a.mul(u, p), g = a.mul(g, f), l = b;
|
|
480
480
|
}
|
|
481
481
|
return u;
|
|
482
482
|
};
|
|
483
483
|
}
|
|
484
|
-
function
|
|
485
|
-
if (e % $t ===
|
|
486
|
-
const t = (e +
|
|
484
|
+
function Vi(e) {
|
|
485
|
+
if (e % $t === Di) {
|
|
486
|
+
const t = (e + D) / $t;
|
|
487
487
|
return function(r, i) {
|
|
488
488
|
const s = r.pow(i, t);
|
|
489
489
|
if (!r.eql(r.sqr(s), i))
|
|
@@ -491,18 +491,18 @@ function _i(e) {
|
|
|
491
491
|
return s;
|
|
492
492
|
};
|
|
493
493
|
}
|
|
494
|
-
if (e %
|
|
495
|
-
const t = (e -
|
|
494
|
+
if (e % Cn === Bn) {
|
|
495
|
+
const t = (e - Bn) / Cn;
|
|
496
496
|
return function(r, i) {
|
|
497
|
-
const s = r.mul(i,
|
|
497
|
+
const s = r.mul(i, ke), o = r.pow(s, t), a = r.mul(i, o), c = r.mul(r.mul(a, ke), o), l = r.mul(a, r.sub(c, r.ONE));
|
|
498
498
|
if (!r.eql(r.sqr(l), i))
|
|
499
499
|
throw new Error("Cannot find square root");
|
|
500
500
|
return l;
|
|
501
501
|
};
|
|
502
502
|
}
|
|
503
|
-
return
|
|
503
|
+
return zi(e);
|
|
504
504
|
}
|
|
505
|
-
const
|
|
505
|
+
const Wi = [
|
|
506
506
|
"create",
|
|
507
507
|
"isValid",
|
|
508
508
|
"is0",
|
|
@@ -521,104 +521,104 @@ const Li = [
|
|
|
521
521
|
"mulN",
|
|
522
522
|
"sqrN"
|
|
523
523
|
];
|
|
524
|
-
function
|
|
524
|
+
function Zi(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 = Wi.reduce((r, i) => (r[i] = "function", r), t);
|
|
531
531
|
return Je(e, n);
|
|
532
532
|
}
|
|
533
|
-
function
|
|
534
|
-
if (n <
|
|
533
|
+
function Gi(e, t, n) {
|
|
534
|
+
if (n < z)
|
|
535
535
|
throw new Error("Expected power > 0");
|
|
536
|
-
if (n ===
|
|
536
|
+
if (n === z)
|
|
537
537
|
return e.ONE;
|
|
538
|
-
if (n ===
|
|
538
|
+
if (n === D)
|
|
539
539
|
return t;
|
|
540
540
|
let r = e.ONE, i = t;
|
|
541
|
-
for (; n >
|
|
542
|
-
n &
|
|
541
|
+
for (; n > z; )
|
|
542
|
+
n & D && (r = e.mul(r, i)), i = e.sqr(i), n >>= D;
|
|
543
543
|
return r;
|
|
544
544
|
}
|
|
545
|
-
function
|
|
545
|
+
function Fi(e, t) {
|
|
546
546
|
const n = new Array(t.length), r = t.reduce((s, o, a) => e.is0(o) ? s : (n[a] = s, e.mul(s, o)), e.ONE), i = e.inv(r);
|
|
547
547
|
return t.reduceRight((s, o, a) => e.is0(o) ? s : (n[a] = e.mul(s, n[a]), e.mul(s, o)), i), n;
|
|
548
548
|
}
|
|
549
|
-
function
|
|
549
|
+
function Yn(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 Ji(e, t, n = !1, r = {}) {
|
|
554
|
+
if (e <= z)
|
|
555
555
|
throw new Error(`Expected Field ORDER > 0, got ${e}`);
|
|
556
|
-
const { nBitLength: i, nByteLength: s } =
|
|
556
|
+
const { nBitLength: i, nByteLength: s } = Yn(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 = Vi(e), a = Object.freeze({
|
|
560
560
|
ORDER: e,
|
|
561
561
|
BITS: i,
|
|
562
562
|
BYTES: s,
|
|
563
563
|
MASK: Jt(i),
|
|
564
|
-
ZERO:
|
|
565
|
-
ONE:
|
|
566
|
-
create: (c) =>
|
|
564
|
+
ZERO: z,
|
|
565
|
+
ONE: D,
|
|
566
|
+
create: (c) => V(c, e),
|
|
567
567
|
isValid: (c) => {
|
|
568
568
|
if (typeof c != "bigint")
|
|
569
569
|
throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);
|
|
570
|
-
return
|
|
570
|
+
return z <= c && c < e;
|
|
571
571
|
},
|
|
572
|
-
is0: (c) => c ===
|
|
573
|
-
isOdd: (c) => (c &
|
|
574
|
-
neg: (c) =>
|
|
572
|
+
is0: (c) => c === z,
|
|
573
|
+
isOdd: (c) => (c & D) === D,
|
|
574
|
+
neg: (c) => V(-c, e),
|
|
575
575
|
eql: (c, l) => c === l,
|
|
576
|
-
sqr: (c) =>
|
|
577
|
-
add: (c, l) =>
|
|
578
|
-
sub: (c, l) =>
|
|
579
|
-
mul: (c, l) =>
|
|
580
|
-
pow: (c, l) =>
|
|
581
|
-
div: (c, l) =>
|
|
576
|
+
sqr: (c) => V(c * c, e),
|
|
577
|
+
add: (c, l) => V(c + l, e),
|
|
578
|
+
sub: (c, l) => V(c - l, e),
|
|
579
|
+
mul: (c, l) => V(c * l, e),
|
|
580
|
+
pow: (c, l) => Gi(a, c, l),
|
|
581
|
+
div: (c, l) => V(c * Tt(l, e), e),
|
|
582
582
|
// Same as above, but doesn't normalize
|
|
583
583
|
sqrN: (c) => c * c,
|
|
584
584
|
addN: (c, l) => c + l,
|
|
585
585
|
subN: (c, l) => c - l,
|
|
586
586
|
mulN: (c, l) => c * l,
|
|
587
|
-
inv: (c) =>
|
|
587
|
+
inv: (c) => Tt(c, e),
|
|
588
588
|
sqrt: r.sqrt || ((c) => o(a, c)),
|
|
589
|
-
invertBatch: (c) =>
|
|
589
|
+
invertBatch: (c) => Fi(a, c),
|
|
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: (c, l, f) => f ? l : c,
|
|
593
|
-
toBytes: (c) => n ?
|
|
593
|
+
toBytes: (c) => n ? Ft(c, s) : Ae(c, s),
|
|
594
594
|
fromBytes: (c) => {
|
|
595
595
|
if (c.length !== s)
|
|
596
596
|
throw new Error(`Fp.fromBytes: expected ${s}, got ${c.length}`);
|
|
597
|
-
return n ?
|
|
597
|
+
return n ? Gt(c) : F(c);
|
|
598
598
|
}
|
|
599
599
|
});
|
|
600
600
|
return Object.freeze(a);
|
|
601
601
|
}
|
|
602
|
-
function
|
|
602
|
+
function Xn(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 Qn(e) {
|
|
609
|
+
const t = Xn(e);
|
|
610
610
|
return t + Math.ceil(t / 2);
|
|
611
611
|
}
|
|
612
|
-
function
|
|
613
|
-
const r = e.length, i =
|
|
612
|
+
function Yi(e, t, n = !1) {
|
|
613
|
+
const r = e.length, i = Xn(t), s = Qn(t);
|
|
614
614
|
if (r < 16 || r < s || r > 1024)
|
|
615
615
|
throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);
|
|
616
|
-
const o = n ?
|
|
617
|
-
return n ?
|
|
616
|
+
const o = n ? F(e) : Gt(e), a = V(o, t - D) + D;
|
|
617
|
+
return n ? Ft(a, i) : Ae(a, i);
|
|
618
618
|
}
|
|
619
619
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
620
|
-
const
|
|
621
|
-
function
|
|
620
|
+
const Xi = BigInt(0), At = BigInt(1);
|
|
621
|
+
function Qi(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 Hi(e, t) {
|
|
|
631
631
|
// non-const time multiplication ladder
|
|
632
632
|
unsafeLadder(i, s) {
|
|
633
633
|
let o = e.ZERO, a = i;
|
|
634
|
-
for (; s >
|
|
635
|
-
s &
|
|
634
|
+
for (; s > Xi; )
|
|
635
|
+
s & At && (o = o.add(a)), a = a.double(), s >>= At;
|
|
636
636
|
return o;
|
|
637
637
|
},
|
|
638
638
|
/**
|
|
@@ -650,7 +650,7 @@ function Hi(e, t) {
|
|
|
650
650
|
let l = i, f = l;
|
|
651
651
|
for (let u = 0; u < o; u++) {
|
|
652
652
|
f = l, c.push(f);
|
|
653
|
-
for (let
|
|
653
|
+
for (let g = 1; g < a; g++)
|
|
654
654
|
f = f.add(l), c.push(f);
|
|
655
655
|
l = f.double();
|
|
656
656
|
}
|
|
@@ -666,13 +666,13 @@ function Hi(e, t) {
|
|
|
666
666
|
wNAF(i, s, o) {
|
|
667
667
|
const { windows: a, windowSize: c } = r(i);
|
|
668
668
|
let l = e.ZERO, f = e.BASE;
|
|
669
|
-
const u = BigInt(2 ** i - 1),
|
|
670
|
-
for (let
|
|
671
|
-
const h =
|
|
672
|
-
let
|
|
673
|
-
o >>=
|
|
674
|
-
const
|
|
675
|
-
|
|
669
|
+
const u = BigInt(2 ** i - 1), g = 2 ** i, b = BigInt(i);
|
|
670
|
+
for (let p = 0; p < a; p++) {
|
|
671
|
+
const h = p * c;
|
|
672
|
+
let d = Number(o & u);
|
|
673
|
+
o >>= b, d > c && (d -= g, o += At);
|
|
674
|
+
const y = h, E = h + Math.abs(d) - 1, N = p % 2 !== 0, _ = d < 0;
|
|
675
|
+
d === 0 ? f = f.add(n(N, s[y])) : l = l.add(n(_, s[E]));
|
|
676
676
|
}
|
|
677
677
|
return { p: l, f };
|
|
678
678
|
},
|
|
@@ -683,8 +683,8 @@ function Hi(e, t) {
|
|
|
683
683
|
}
|
|
684
684
|
};
|
|
685
685
|
}
|
|
686
|
-
function
|
|
687
|
-
return
|
|
686
|
+
function er(e) {
|
|
687
|
+
return Zi(e.Fp), Je(e, {
|
|
688
688
|
n: "bigint",
|
|
689
689
|
h: "bigint",
|
|
690
690
|
Gx: "field",
|
|
@@ -693,14 +693,14 @@ function Fn(e) {
|
|
|
693
693
|
nBitLength: "isSafeInteger",
|
|
694
694
|
nByteLength: "isSafeInteger"
|
|
695
695
|
}), Object.freeze({
|
|
696
|
-
...
|
|
696
|
+
...Yn(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 es(e) {
|
|
703
|
+
const t = er(e);
|
|
704
704
|
Je(t, {
|
|
705
705
|
a: "field",
|
|
706
706
|
b: "field"
|
|
@@ -722,7 +722,7 @@ function qi(e) {
|
|
|
722
722
|
}
|
|
723
723
|
return Object.freeze({ ...t });
|
|
724
724
|
}
|
|
725
|
-
const { bytesToNumberBE:
|
|
725
|
+
const { bytesToNumberBE: ts, hexToBytes: ns } = qi, Be = {
|
|
726
726
|
// asn.1 DER encoding utils
|
|
727
727
|
Err: class extends Error {
|
|
728
728
|
constructor(t = "") {
|
|
@@ -740,10 +740,10 @@ const { bytesToNumberBE: Di, hexToBytes: ji } = Ci, 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: ts(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" ? ns(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: Di, hexToBytes: ji } = Ci, Be = {
|
|
|
763
763
|
}, r = t(n(e.s)), i = t(n(e.r)), s = r.length / 2, o = i.length / 2, a = n(s), c = n(o);
|
|
764
764
|
return `30${n(o + s + 4)}02${c}${i}02${a}${r}`;
|
|
765
765
|
}
|
|
766
|
-
},
|
|
766
|
+
}, ae = BigInt(0), Y = 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
|
|
774
|
-
}), i = t.fromBytes || ((
|
|
775
|
-
const h =
|
|
776
|
-
return { x:
|
|
770
|
+
function rs(e) {
|
|
771
|
+
const t = es(e), { Fp: n } = t, r = t.toBytes || ((p, h, d) => {
|
|
772
|
+
const y = h.toAffine();
|
|
773
|
+
return Ue(Uint8Array.from([4]), n.toBytes(y.x), n.toBytes(y.y));
|
|
774
|
+
}), i = t.fromBytes || ((p) => {
|
|
775
|
+
const h = p.subarray(1), d = n.fromBytes(h.subarray(0, n.BYTES)), y = n.fromBytes(h.subarray(n.BYTES, 2 * n.BYTES));
|
|
776
|
+
return { x: d, y };
|
|
777
777
|
});
|
|
778
|
-
function s(
|
|
779
|
-
const { a: h, b:
|
|
780
|
-
return n.add(n.add(E, n.mul(
|
|
778
|
+
function s(p) {
|
|
779
|
+
const { a: h, b: d } = t, y = n.sqr(p), E = n.mul(y, p);
|
|
780
|
+
return n.add(n.add(E, n.mul(p, 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(p) {
|
|
785
|
+
return typeof p == "bigint" && ae < p && p < t.n;
|
|
786
786
|
}
|
|
787
|
-
function a(
|
|
788
|
-
if (!o(
|
|
787
|
+
function a(p) {
|
|
788
|
+
if (!o(p))
|
|
789
789
|
throw new Error("Expected valid bigint: 0 < bigint < curve.n");
|
|
790
790
|
}
|
|
791
|
-
function c(
|
|
792
|
-
const { allowedPrivateKeyLengths: h, nByteLength:
|
|
793
|
-
if (h && typeof
|
|
794
|
-
if (
|
|
791
|
+
function c(p) {
|
|
792
|
+
const { allowedPrivateKeyLengths: h, nByteLength: d, wrapPrivateKey: y, n: E } = t;
|
|
793
|
+
if (h && typeof p != "bigint") {
|
|
794
|
+
if (p instanceof Uint8Array && (p = qe(p)), typeof p != "string" || !h.includes(p.length))
|
|
795
795
|
throw new Error("Invalid key");
|
|
796
|
-
|
|
796
|
+
p = p.padStart(d * 2, "0");
|
|
797
797
|
}
|
|
798
|
-
let
|
|
798
|
+
let N;
|
|
799
799
|
try {
|
|
800
|
-
|
|
800
|
+
N = typeof p == "bigint" ? p : F(W("private key", p, d));
|
|
801
801
|
} catch {
|
|
802
|
-
throw new Error(`private key must be ${
|
|
802
|
+
throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof p}`);
|
|
803
803
|
}
|
|
804
|
-
return
|
|
804
|
+
return y && (N = V(N, E)), a(N), N;
|
|
805
805
|
}
|
|
806
806
|
const l = /* @__PURE__ */ new Map();
|
|
807
|
-
function f(
|
|
808
|
-
if (!(
|
|
807
|
+
function f(p) {
|
|
808
|
+
if (!(p instanceof u))
|
|
809
809
|
throw new Error("ProjectivePoint expected");
|
|
810
810
|
}
|
|
811
811
|
class u {
|
|
812
|
-
constructor(h,
|
|
813
|
-
if (this.px = h, this.py =
|
|
812
|
+
constructor(h, d, y) {
|
|
813
|
+
if (this.px = h, this.py = d, this.pz = y, h == null || !n.isValid(h))
|
|
814
814
|
throw new Error("x required");
|
|
815
|
-
if (
|
|
815
|
+
if (d == null || !n.isValid(d))
|
|
816
816
|
throw new Error("y required");
|
|
817
|
-
if (
|
|
817
|
+
if (y == null || !n.isValid(y))
|
|
818
818
|
throw new Error("z required");
|
|
819
819
|
}
|
|
820
820
|
// Does not validate if the point is on-curve.
|
|
821
821
|
// Use fromHex instead, or call assertValidity() later.
|
|
822
822
|
static fromAffine(h) {
|
|
823
|
-
const { x:
|
|
824
|
-
if (!h || !n.isValid(
|
|
823
|
+
const { x: d, y } = h || {};
|
|
824
|
+
if (!h || !n.isValid(d) || !n.isValid(y))
|
|
825
825
|
throw new Error("invalid affine point");
|
|
826
826
|
if (h instanceof u)
|
|
827
827
|
throw new Error("projective point not allowed");
|
|
828
|
-
const E = (
|
|
829
|
-
return E(
|
|
828
|
+
const E = (N) => n.eql(N, n.ZERO);
|
|
829
|
+
return E(d) && E(y) ? u.ZERO : new u(d, y, n.ONE);
|
|
830
830
|
}
|
|
831
831
|
get x() {
|
|
832
832
|
return this.toAffine().x;
|
|
@@ -841,16 +841,16 @@ function Vi(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
|
|
845
|
-
return h.map((
|
|
844
|
+
const d = n.invertBatch(h.map((y) => y.pz));
|
|
845
|
+
return h.map((y, E) => y.toAffine(d[E])).map(u.fromAffine);
|
|
846
846
|
}
|
|
847
847
|
/**
|
|
848
848
|
* Converts hash string or Uint8Array to Point.
|
|
849
849
|
* @param hex short/long ECDSA hex
|
|
850
850
|
*/
|
|
851
851
|
static fromHex(h) {
|
|
852
|
-
const
|
|
853
|
-
return
|
|
852
|
+
const d = u.fromAffine(i(W("pointHex", h)));
|
|
853
|
+
return d.assertValidity(), d;
|
|
854
854
|
}
|
|
855
855
|
// Multiplies generator point by privateKey.
|
|
856
856
|
static fromPrivateKey(h) {
|
|
@@ -867,11 +867,11 @@ function Vi(e) {
|
|
|
867
867
|
return;
|
|
868
868
|
throw new Error("bad point: ZERO");
|
|
869
869
|
}
|
|
870
|
-
const { x: h, y } = this.toAffine();
|
|
871
|
-
if (!n.isValid(h) || !n.isValid(
|
|
870
|
+
const { x: h, y: d } = this.toAffine();
|
|
871
|
+
if (!n.isValid(h) || !n.isValid(d))
|
|
872
872
|
throw new Error("bad point: x or y not FE");
|
|
873
|
-
const
|
|
874
|
-
if (!n.eql(
|
|
873
|
+
const y = n.sqr(d), E = s(h);
|
|
874
|
+
if (!n.eql(y, 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 Vi(e) {
|
|
|
887
887
|
*/
|
|
888
888
|
equals(h) {
|
|
889
889
|
f(h);
|
|
890
|
-
const { px:
|
|
890
|
+
const { px: d, py: y, pz: E } = this, { px: N, py: _, pz: B } = h, m = n.eql(n.mul(d, B), n.mul(N, E)), x = n.eql(n.mul(y, B), n.mul(_, E));
|
|
891
891
|
return m && x;
|
|
892
892
|
}
|
|
893
893
|
/**
|
|
@@ -901,9 +901,9 @@ function Vi(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:
|
|
905
|
-
let
|
|
906
|
-
return
|
|
904
|
+
const { a: h, b: d } = t, y = n.mul(d, Un), { px: E, py: N, pz: _ } = this;
|
|
905
|
+
let B = n.ZERO, m = n.ZERO, x = n.ZERO, S = n.mul(E, E), H = n.mul(N, N), U = n.mul(_, _), K = n.mul(E, N);
|
|
906
|
+
return K = n.add(K, K), x = n.mul(E, _), x = n.add(x, x), B = n.mul(h, x), m = n.mul(y, U), m = n.add(B, m), B = n.sub(H, m), m = n.add(H, m), m = n.mul(B, m), B = n.mul(K, B), x = n.mul(y, x), U = n.mul(h, U), K = n.sub(S, U), K = n.mul(h, K), K = n.add(K, x), x = n.add(S, S), S = n.add(x, S), S = n.add(S, U), S = n.mul(S, K), m = n.add(m, S), U = n.mul(N, _), U = n.add(U, U), S = n.mul(U, K), B = n.sub(B, S), x = n.mul(U, H), 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 Vi(e) {
|
|
|
911
911
|
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
912
912
|
add(h) {
|
|
913
913
|
f(h);
|
|
914
|
-
const { px:
|
|
914
|
+
const { px: d, py: y, pz: E } = this, { px: N, py: _, pz: B } = h;
|
|
915
915
|
let m = n.ZERO, x = n.ZERO, S = n.ZERO;
|
|
916
|
-
const
|
|
917
|
-
let
|
|
918
|
-
|
|
919
|
-
let v = n.add(
|
|
920
|
-
return
|
|
916
|
+
const H = t.a, U = n.mul(t.b, Un);
|
|
917
|
+
let K = n.mul(d, N), T = n.mul(y, _), R = n.mul(E, B), P = n.add(d, y), w = n.add(N, _);
|
|
918
|
+
P = n.mul(P, w), w = n.add(K, T), P = n.sub(P, w), w = n.add(d, E);
|
|
919
|
+
let v = n.add(N, B);
|
|
920
|
+
return w = n.mul(w, v), v = n.add(K, R), w = n.sub(w, v), v = n.add(y, E), m = n.add(_, B), v = n.mul(v, m), m = n.add(T, R), v = n.sub(v, m), S = n.mul(H, w), m = n.mul(U, R), S = n.add(m, S), m = n.sub(T, S), S = n.add(T, S), x = n.mul(m, S), T = n.add(K, K), T = n.add(T, K), R = n.mul(H, R), w = n.mul(U, w), T = n.add(T, R), R = n.sub(K, R), R = n.mul(H, R), w = n.add(w, R), K = n.mul(T, w), x = n.add(x, K), K = n.mul(v, w), m = n.mul(P, m), m = n.sub(m, K), K = n.mul(P, T), S = n.mul(v, S), S = n.add(S, K), new u(m, x, S);
|
|
921
921
|
}
|
|
922
922
|
subtract(h) {
|
|
923
923
|
return this.add(h.negate());
|
|
@@ -926,9 +926,9 @@ function Vi(e) {
|
|
|
926
926
|
return this.equals(u.ZERO);
|
|
927
927
|
}
|
|
928
928
|
wNAF(h) {
|
|
929
|
-
return
|
|
930
|
-
const
|
|
931
|
-
return
|
|
929
|
+
return b.wNAFCached(this, l, h, (d) => {
|
|
930
|
+
const y = n.invertBatch(d.map((E) => E.pz));
|
|
931
|
+
return d.map((E, N) => E.toAffine(y[N])).map(u.fromAffine);
|
|
932
932
|
});
|
|
933
933
|
}
|
|
934
934
|
/**
|
|
@@ -937,18 +937,18 @@ function Vi(e) {
|
|
|
937
937
|
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
938
938
|
*/
|
|
939
939
|
multiplyUnsafe(h) {
|
|
940
|
-
const
|
|
941
|
-
if (h ===
|
|
942
|
-
return
|
|
940
|
+
const d = u.ZERO;
|
|
941
|
+
if (h === ae)
|
|
942
|
+
return d;
|
|
943
943
|
if (a(h), h === Y)
|
|
944
944
|
return this;
|
|
945
|
-
const { endo:
|
|
946
|
-
if (!
|
|
947
|
-
return
|
|
948
|
-
let { k1neg: E, k1:
|
|
949
|
-
for (;
|
|
950
|
-
|
|
951
|
-
return E && (m = m.negate()),
|
|
945
|
+
const { endo: y } = t;
|
|
946
|
+
if (!y)
|
|
947
|
+
return b.unsafeLadder(this, h);
|
|
948
|
+
let { k1neg: E, k1: N, k2neg: _, k2: B } = y.splitScalar(h), m = d, x = d, S = this;
|
|
949
|
+
for (; N > ae || B > ae; )
|
|
950
|
+
N & Y && (m = m.add(S)), B & Y && (x = x.add(S)), S = S.double(), N >>= Y, B >>= Y;
|
|
951
|
+
return E && (m = m.negate()), _ && (x = x.negate()), x = new u(n.mul(x.px, y.beta), x.py, x.pz), m.add(x);
|
|
952
952
|
}
|
|
953
953
|
/**
|
|
954
954
|
* Constant time multiplication.
|
|
@@ -961,17 +961,17 @@ function Vi(e) {
|
|
|
961
961
|
*/
|
|
962
962
|
multiply(h) {
|
|
963
963
|
a(h);
|
|
964
|
-
let
|
|
965
|
-
const { endo:
|
|
966
|
-
if (
|
|
967
|
-
const { k1neg:
|
|
968
|
-
let { p: S, f:
|
|
969
|
-
S =
|
|
964
|
+
let d = h, y, E;
|
|
965
|
+
const { endo: N } = t;
|
|
966
|
+
if (N) {
|
|
967
|
+
const { k1neg: _, k1: B, k2neg: m, k2: x } = N.splitScalar(d);
|
|
968
|
+
let { p: S, f: H } = this.wNAF(B), { p: U, f: K } = this.wNAF(x);
|
|
969
|
+
S = b.constTimeNegate(_, S), U = b.constTimeNegate(m, U), U = new u(n.mul(U.px, N.beta), U.py, U.pz), y = S.add(U), E = H.add(K);
|
|
970
970
|
} else {
|
|
971
|
-
const { p:
|
|
972
|
-
|
|
971
|
+
const { p: _, f: B } = this.wNAF(d);
|
|
972
|
+
y = _, E = B;
|
|
973
973
|
}
|
|
974
|
-
return u.normalizeZ([
|
|
974
|
+
return u.normalizeZ([y, E])[0];
|
|
975
975
|
}
|
|
976
976
|
/**
|
|
977
977
|
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
@@ -979,34 +979,34 @@ function Vi(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,
|
|
983
|
-
const E = u.BASE,
|
|
984
|
-
return
|
|
982
|
+
multiplyAndAddUnsafe(h, d, y) {
|
|
983
|
+
const E = u.BASE, N = (B, m) => m === ae || m === Y || !B.equals(E) ? B.multiplyUnsafe(m) : B.multiply(m), _ = N(this, d).add(N(h, y));
|
|
984
|
+
return _.is0() ? void 0 : _;
|
|
985
985
|
}
|
|
986
986
|
// Converts Projective point to affine (x, y) coordinates.
|
|
987
987
|
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
988
988
|
// (x, y, z) ∋ (x=x/z, y=y/z)
|
|
989
989
|
toAffine(h) {
|
|
990
|
-
const { px:
|
|
991
|
-
h == null && (h =
|
|
992
|
-
const
|
|
993
|
-
if (
|
|
990
|
+
const { px: d, py: y, pz: E } = this, N = this.is0();
|
|
991
|
+
h == null && (h = N ? n.ONE : n.inv(E));
|
|
992
|
+
const _ = n.mul(d, h), B = n.mul(y, h), m = n.mul(E, h);
|
|
993
|
+
if (N)
|
|
994
994
|
return { x: n.ZERO, y: n.ZERO };
|
|
995
995
|
if (!n.eql(m, n.ONE))
|
|
996
996
|
throw new Error("invZ was invalid");
|
|
997
|
-
return { x:
|
|
997
|
+
return { x: _, y: B };
|
|
998
998
|
}
|
|
999
999
|
isTorsionFree() {
|
|
1000
|
-
const { h, isTorsionFree:
|
|
1000
|
+
const { h, isTorsionFree: d } = t;
|
|
1001
1001
|
if (h === Y)
|
|
1002
1002
|
return !0;
|
|
1003
|
-
if (
|
|
1004
|
-
return
|
|
1003
|
+
if (d)
|
|
1004
|
+
return d(u, this);
|
|
1005
1005
|
throw new Error("isTorsionFree() has not been declared for the elliptic curve");
|
|
1006
1006
|
}
|
|
1007
1007
|
clearCofactor() {
|
|
1008
|
-
const { h, clearCofactor:
|
|
1009
|
-
return h === Y ? this :
|
|
1008
|
+
const { h, clearCofactor: d } = t;
|
|
1009
|
+
return h === Y ? this : d ? d(u, this) : this.multiplyUnsafe(t.h);
|
|
1010
1010
|
}
|
|
1011
1011
|
toRawBytes(h = !0) {
|
|
1012
1012
|
return this.assertValidity(), r(u, this, h);
|
|
@@ -1016,7 +1016,7 @@ function Vi(e) {
|
|
|
1016
1016
|
}
|
|
1017
1017
|
}
|
|
1018
1018
|
u.BASE = new u(t.Gx, t.Gy, n.ONE), u.ZERO = new u(n.ZERO, n.ONE, n.ZERO);
|
|
1019
|
-
const
|
|
1019
|
+
const g = t.nBitLength, b = Qi(u, t.endo ? Math.ceil(g / 2) : g);
|
|
1020
1020
|
return {
|
|
1021
1021
|
CURVE: t,
|
|
1022
1022
|
ProjectivePoint: u,
|
|
@@ -1025,8 +1025,8 @@ function Vi(e) {
|
|
|
1025
1025
|
isWithinCurveOrder: o
|
|
1026
1026
|
};
|
|
1027
1027
|
}
|
|
1028
|
-
function
|
|
1029
|
-
const t =
|
|
1028
|
+
function is(e) {
|
|
1029
|
+
const t = er(e);
|
|
1030
1030
|
return Je(t, {
|
|
1031
1031
|
hash: "hash",
|
|
1032
1032
|
hmac: "function",
|
|
@@ -1037,90 +1037,90 @@ function zi(e) {
|
|
|
1037
1037
|
lowS: "boolean"
|
|
1038
1038
|
}), Object.freeze({ lowS: !0, ...t });
|
|
1039
1039
|
}
|
|
1040
|
-
function
|
|
1041
|
-
const t =
|
|
1042
|
-
function o(
|
|
1043
|
-
return
|
|
1040
|
+
function ss(e) {
|
|
1041
|
+
const t = is(e), { Fp: n, n: r } = t, i = n.BYTES + 1, s = 2 * n.BYTES + 1;
|
|
1042
|
+
function o(w) {
|
|
1043
|
+
return ae < w && w < n.ORDER;
|
|
1044
1044
|
}
|
|
1045
|
-
function a(
|
|
1046
|
-
return
|
|
1045
|
+
function a(w) {
|
|
1046
|
+
return V(w, r);
|
|
1047
1047
|
}
|
|
1048
|
-
function c(
|
|
1049
|
-
return
|
|
1048
|
+
function c(w) {
|
|
1049
|
+
return Tt(w, r);
|
|
1050
1050
|
}
|
|
1051
|
-
const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder:
|
|
1051
|
+
const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: g } = rs({
|
|
1052
1052
|
...t,
|
|
1053
|
-
toBytes(
|
|
1054
|
-
const
|
|
1055
|
-
return A ?
|
|
1053
|
+
toBytes(w, v, A) {
|
|
1054
|
+
const C = v.toAffine(), k = n.toBytes(C.x), I = Ue;
|
|
1055
|
+
return A ? I(Uint8Array.from([v.hasEvenY() ? 2 : 3]), k) : I(Uint8Array.from([4]), k, n.toBytes(C.y));
|
|
1056
1056
|
},
|
|
1057
|
-
fromBytes(
|
|
1058
|
-
const v =
|
|
1057
|
+
fromBytes(w) {
|
|
1058
|
+
const v = w.length, A = w[0], C = w.subarray(1);
|
|
1059
1059
|
if (v === i && (A === 2 || A === 3)) {
|
|
1060
|
-
const
|
|
1061
|
-
if (!o(
|
|
1060
|
+
const k = F(C);
|
|
1061
|
+
if (!o(k))
|
|
1062
1062
|
throw new Error("Point is not on curve");
|
|
1063
|
-
const
|
|
1064
|
-
let O = n.sqrt(
|
|
1065
|
-
const
|
|
1066
|
-
return (A & 1) === 1 !==
|
|
1063
|
+
const I = u(k);
|
|
1064
|
+
let O = n.sqrt(I);
|
|
1065
|
+
const $ = (O & Y) === Y;
|
|
1066
|
+
return (A & 1) === 1 !== $ && (O = n.neg(O)), { x: k, y: O };
|
|
1067
1067
|
} else if (v === s && A === 4) {
|
|
1068
|
-
const
|
|
1069
|
-
return { x:
|
|
1068
|
+
const k = n.fromBytes(C.subarray(0, n.BYTES)), I = n.fromBytes(C.subarray(n.BYTES, 2 * n.BYTES));
|
|
1069
|
+
return { x: k, y: I };
|
|
1070
1070
|
} else
|
|
1071
1071
|
throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`);
|
|
1072
1072
|
}
|
|
1073
|
-
}),
|
|
1074
|
-
function
|
|
1073
|
+
}), b = (w) => qe(Ae(w, t.nByteLength));
|
|
1074
|
+
function p(w) {
|
|
1075
1075
|
const v = r >> Y;
|
|
1076
|
-
return
|
|
1076
|
+
return w > v;
|
|
1077
1077
|
}
|
|
1078
|
-
function h(
|
|
1079
|
-
return
|
|
1078
|
+
function h(w) {
|
|
1079
|
+
return p(w) ? a(-w) : w;
|
|
1080
1080
|
}
|
|
1081
|
-
const
|
|
1082
|
-
class
|
|
1083
|
-
constructor(v, A,
|
|
1084
|
-
this.r = v, this.s = A, this.recovery =
|
|
1081
|
+
const d = (w, v, A) => F(w.slice(v, A));
|
|
1082
|
+
class y {
|
|
1083
|
+
constructor(v, A, C) {
|
|
1084
|
+
this.r = v, this.s = A, this.recovery = C, this.assertValidity();
|
|
1085
1085
|
}
|
|
1086
1086
|
// pair (bytes of r, bytes of s)
|
|
1087
1087
|
static fromCompact(v) {
|
|
1088
1088
|
const A = t.nByteLength;
|
|
1089
|
-
return v =
|
|
1089
|
+
return v = W("compactSignature", v, A * 2), new y(d(v, 0, A), d(v, A, 2 * A));
|
|
1090
1090
|
}
|
|
1091
1091
|
// DER encoded ECDSA signature
|
|
1092
1092
|
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
1093
1093
|
static fromDER(v) {
|
|
1094
|
-
const { r: A, s:
|
|
1095
|
-
return new
|
|
1094
|
+
const { r: A, s: C } = Be.toSig(W("DER", v));
|
|
1095
|
+
return new y(A, C);
|
|
1096
1096
|
}
|
|
1097
1097
|
assertValidity() {
|
|
1098
|
-
if (!
|
|
1098
|
+
if (!g(this.r))
|
|
1099
1099
|
throw new Error("r must be 0 < r < CURVE.n");
|
|
1100
|
-
if (!
|
|
1100
|
+
if (!g(this.s))
|
|
1101
1101
|
throw new Error("s must be 0 < s < CURVE.n");
|
|
1102
1102
|
}
|
|
1103
1103
|
addRecoveryBit(v) {
|
|
1104
|
-
return new
|
|
1104
|
+
return new y(this.r, this.s, v);
|
|
1105
1105
|
}
|
|
1106
1106
|
recoverPublicKey(v) {
|
|
1107
|
-
const { r: A, s:
|
|
1108
|
-
if (
|
|
1107
|
+
const { r: A, s: C, recovery: k } = this, I = x(W("msgHash", v));
|
|
1108
|
+
if (k == null || ![0, 1, 2, 3].includes(k))
|
|
1109
1109
|
throw new Error("recovery id invalid");
|
|
1110
|
-
const O =
|
|
1110
|
+
const O = k === 2 || k === 3 ? A + t.n : A;
|
|
1111
1111
|
if (O >= n.ORDER)
|
|
1112
1112
|
throw new Error("recovery id 2 or 3 invalid");
|
|
1113
|
-
const
|
|
1114
|
-
if (!
|
|
1113
|
+
const $ = k & 1 ? "03" : "02", Q = l.fromHex($ + b(O)), ge = c(O), Ie = a(-I * ge), Ve = a(C * ge), we = l.BASE.multiplyAndAddUnsafe(Q, Ie, Ve);
|
|
1114
|
+
if (!we)
|
|
1115
1115
|
throw new Error("point at infinify");
|
|
1116
|
-
return
|
|
1116
|
+
return we.assertValidity(), we;
|
|
1117
1117
|
}
|
|
1118
1118
|
// Signatures should be low-s, to prevent malleability.
|
|
1119
1119
|
hasHighS() {
|
|
1120
|
-
return
|
|
1120
|
+
return p(this.s);
|
|
1121
1121
|
}
|
|
1122
1122
|
normalizeS() {
|
|
1123
|
-
return this.hasHighS() ? new
|
|
1123
|
+
return this.hasHighS() ? new y(this.r, a(-this.s), this.recovery) : this;
|
|
1124
1124
|
}
|
|
1125
1125
|
// DER-encoded
|
|
1126
1126
|
toDERRawBytes() {
|
|
@@ -1134,13 +1134,13 @@ function Zi(e) {
|
|
|
1134
1134
|
return De(this.toCompactHex());
|
|
1135
1135
|
}
|
|
1136
1136
|
toCompactHex() {
|
|
1137
|
-
return
|
|
1137
|
+
return b(this.r) + b(this.s);
|
|
1138
1138
|
}
|
|
1139
1139
|
}
|
|
1140
1140
|
const E = {
|
|
1141
|
-
isValidPrivateKey(
|
|
1141
|
+
isValidPrivateKey(w) {
|
|
1142
1142
|
try {
|
|
1143
|
-
return f(
|
|
1143
|
+
return f(w), !0;
|
|
1144
1144
|
} catch {
|
|
1145
1145
|
return !1;
|
|
1146
1146
|
}
|
|
@@ -1151,8 +1151,8 @@ function Zi(e) {
|
|
|
1151
1151
|
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
|
1152
1152
|
*/
|
|
1153
1153
|
randomPrivateKey: () => {
|
|
1154
|
-
const
|
|
1155
|
-
return
|
|
1154
|
+
const w = Qn(t.n);
|
|
1155
|
+
return Yi(t.randomBytes(w), t.n);
|
|
1156
1156
|
},
|
|
1157
1157
|
/**
|
|
1158
1158
|
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
|
@@ -1162,118 +1162,118 @@ function Zi(e) {
|
|
|
1162
1162
|
* const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
|
|
1163
1163
|
* fast.multiply(privKey); // much faster ECDH now
|
|
1164
1164
|
*/
|
|
1165
|
-
precompute(
|
|
1166
|
-
return v._setWindowSize(
|
|
1165
|
+
precompute(w = 8, v = l.BASE) {
|
|
1166
|
+
return v._setWindowSize(w), v.multiply(BigInt(3)), v;
|
|
1167
1167
|
}
|
|
1168
1168
|
};
|
|
1169
|
-
function
|
|
1170
|
-
return l.fromPrivateKey(
|
|
1169
|
+
function N(w, v = !0) {
|
|
1170
|
+
return l.fromPrivateKey(w).toRawBytes(v);
|
|
1171
1171
|
}
|
|
1172
|
-
function
|
|
1173
|
-
const v =
|
|
1174
|
-
return v ?
|
|
1172
|
+
function _(w) {
|
|
1173
|
+
const v = w instanceof Uint8Array, A = typeof w == "string", C = (v || A) && w.length;
|
|
1174
|
+
return v ? C === i || C === s : A ? C === 2 * i || C === 2 * s : w instanceof l;
|
|
1175
1175
|
}
|
|
1176
|
-
function
|
|
1177
|
-
if (
|
|
1176
|
+
function B(w, v, A = !0) {
|
|
1177
|
+
if (_(w))
|
|
1178
1178
|
throw new Error("first arg must be private key");
|
|
1179
|
-
if (!
|
|
1179
|
+
if (!_(v))
|
|
1180
1180
|
throw new Error("second arg must be public key");
|
|
1181
|
-
return l.fromHex(v).multiply(f(
|
|
1181
|
+
return l.fromHex(v).multiply(f(w)).toRawBytes(A);
|
|
1182
1182
|
}
|
|
1183
|
-
const m = t.bits2int || function(
|
|
1184
|
-
const v =
|
|
1183
|
+
const m = t.bits2int || function(w) {
|
|
1184
|
+
const v = F(w), A = w.length * 8 - t.nBitLength;
|
|
1185
1185
|
return A > 0 ? v >> BigInt(A) : v;
|
|
1186
|
-
}, x = t.bits2int_modN || function(
|
|
1187
|
-
return a(m(
|
|
1186
|
+
}, x = t.bits2int_modN || function(w) {
|
|
1187
|
+
return a(m(w));
|
|
1188
1188
|
}, S = Jt(t.nBitLength);
|
|
1189
|
-
function
|
|
1190
|
-
if (typeof
|
|
1189
|
+
function H(w) {
|
|
1190
|
+
if (typeof w != "bigint")
|
|
1191
1191
|
throw new Error("bigint expected");
|
|
1192
|
-
if (!(
|
|
1192
|
+
if (!(ae <= w && w < S))
|
|
1193
1193
|
throw new Error(`bigint expected < 2^${t.nBitLength}`);
|
|
1194
|
-
return
|
|
1194
|
+
return Ae(w, t.nByteLength);
|
|
1195
1195
|
}
|
|
1196
|
-
function U(
|
|
1196
|
+
function U(w, v, A = K) {
|
|
1197
1197
|
if (["recovered", "canonical"].some((Ke) => Ke in A))
|
|
1198
1198
|
throw new Error("sign() legacy options not supported");
|
|
1199
|
-
const { hash:
|
|
1200
|
-
let { lowS:
|
|
1201
|
-
|
|
1202
|
-
const
|
|
1203
|
-
if (
|
|
1204
|
-
const Ke =
|
|
1205
|
-
Ie.push(
|
|
1206
|
-
}
|
|
1207
|
-
const
|
|
1208
|
-
function
|
|
1209
|
-
const
|
|
1210
|
-
if (!
|
|
1199
|
+
const { hash: C, randomBytes: k } = t;
|
|
1200
|
+
let { lowS: I, prehash: O, extraEntropy: $ } = A;
|
|
1201
|
+
I == null && (I = !0), w = W("msgHash", w), O && (w = W("prehashed msgHash", C(w)));
|
|
1202
|
+
const Q = x(w), ge = f(v), Ie = [H(ge), H(Q)];
|
|
1203
|
+
if ($ != null) {
|
|
1204
|
+
const Ke = $ === !0 ? k(n.BYTES) : $;
|
|
1205
|
+
Ie.push(W("extraEntropy", Ke));
|
|
1206
|
+
}
|
|
1207
|
+
const Ve = Ue(...Ie), we = Q;
|
|
1208
|
+
function mt(Ke) {
|
|
1209
|
+
const Le = m(Ke);
|
|
1210
|
+
if (!g(Le))
|
|
1211
1211
|
return;
|
|
1212
|
-
const
|
|
1213
|
-
if (
|
|
1212
|
+
const Sn = c(Le), $e = l.BASE.multiply(Le).toAffine(), ee = a($e.x);
|
|
1213
|
+
if (ee === ae)
|
|
1214
1214
|
return;
|
|
1215
|
-
const Te = a(
|
|
1216
|
-
if (Te ===
|
|
1215
|
+
const Te = a(Sn * a(we + ee * ge));
|
|
1216
|
+
if (Te === ae)
|
|
1217
1217
|
return;
|
|
1218
|
-
let
|
|
1219
|
-
return
|
|
1218
|
+
let An = ($e.x === ee ? 0 : 2) | Number($e.y & Y), Nn = Te;
|
|
1219
|
+
return I && p(Te) && (Nn = h(Te), An ^= 1), new y(ee, Nn, An);
|
|
1220
1220
|
}
|
|
1221
|
-
return { seed:
|
|
1221
|
+
return { seed: Ve, k2sig: mt };
|
|
1222
1222
|
}
|
|
1223
|
-
const
|
|
1224
|
-
function R(
|
|
1225
|
-
const { seed:
|
|
1226
|
-
return
|
|
1223
|
+
const K = { lowS: t.lowS, prehash: !1 }, T = { lowS: t.lowS, prehash: !1 };
|
|
1224
|
+
function R(w, v, A = K) {
|
|
1225
|
+
const { seed: C, k2sig: k } = U(w, v, A), I = t;
|
|
1226
|
+
return Jn(I.hash.outputLen, I.nByteLength, I.hmac)(C, k);
|
|
1227
1227
|
}
|
|
1228
1228
|
l.BASE._setWindowSize(8);
|
|
1229
|
-
function
|
|
1230
|
-
var
|
|
1231
|
-
const
|
|
1232
|
-
if (v =
|
|
1229
|
+
function P(w, v, A, C = T) {
|
|
1230
|
+
var $e;
|
|
1231
|
+
const k = w;
|
|
1232
|
+
if (v = W("msgHash", v), A = W("publicKey", A), "strict" in C)
|
|
1233
1233
|
throw new Error("options.strict was renamed to lowS");
|
|
1234
|
-
const { lowS:
|
|
1235
|
-
let
|
|
1234
|
+
const { lowS: I, prehash: O } = C;
|
|
1235
|
+
let $, Q;
|
|
1236
1236
|
try {
|
|
1237
|
-
if (typeof
|
|
1237
|
+
if (typeof k == "string" || k instanceof Uint8Array)
|
|
1238
1238
|
try {
|
|
1239
|
-
|
|
1240
|
-
} catch (
|
|
1241
|
-
if (!(
|
|
1242
|
-
throw
|
|
1243
|
-
|
|
1239
|
+
$ = y.fromDER(k);
|
|
1240
|
+
} catch (ee) {
|
|
1241
|
+
if (!(ee instanceof Be.Err))
|
|
1242
|
+
throw ee;
|
|
1243
|
+
$ = y.fromCompact(k);
|
|
1244
1244
|
}
|
|
1245
|
-
else if (typeof
|
|
1246
|
-
const { r:
|
|
1247
|
-
|
|
1245
|
+
else if (typeof k == "object" && typeof k.r == "bigint" && typeof k.s == "bigint") {
|
|
1246
|
+
const { r: ee, s: Te } = k;
|
|
1247
|
+
$ = new y(ee, Te);
|
|
1248
1248
|
} else
|
|
1249
1249
|
throw new Error("PARSE");
|
|
1250
|
-
|
|
1251
|
-
} catch (
|
|
1252
|
-
if (
|
|
1250
|
+
Q = l.fromHex(A);
|
|
1251
|
+
} catch (ee) {
|
|
1252
|
+
if (ee.message === "PARSE")
|
|
1253
1253
|
throw new Error("signature must be Signature instance, Uint8Array or hex string");
|
|
1254
1254
|
return !1;
|
|
1255
1255
|
}
|
|
1256
|
-
if (
|
|
1256
|
+
if (I && $.hasHighS())
|
|
1257
1257
|
return !1;
|
|
1258
1258
|
O && (v = t.hash(v));
|
|
1259
|
-
const { r:
|
|
1260
|
-
return
|
|
1259
|
+
const { r: ge, s: Ie } = $, Ve = x(v), we = c(Ie), mt = a(Ve * we), Ke = a(ge * we), Le = ($e = l.BASE.multiplyAndAddUnsafe(Q, mt, Ke)) == null ? void 0 : $e.toAffine();
|
|
1260
|
+
return Le ? a(Le.x) === ge : !1;
|
|
1261
1261
|
}
|
|
1262
1262
|
return {
|
|
1263
1263
|
CURVE: t,
|
|
1264
|
-
getPublicKey:
|
|
1265
|
-
getSharedSecret:
|
|
1264
|
+
getPublicKey: N,
|
|
1265
|
+
getSharedSecret: B,
|
|
1266
1266
|
sign: R,
|
|
1267
|
-
verify:
|
|
1267
|
+
verify: P,
|
|
1268
1268
|
ProjectivePoint: l,
|
|
1269
|
-
Signature:
|
|
1269
|
+
Signature: y,
|
|
1270
1270
|
utils: E
|
|
1271
1271
|
};
|
|
1272
1272
|
}
|
|
1273
|
-
let
|
|
1273
|
+
let tr = class extends Wn {
|
|
1274
1274
|
constructor(t, n) {
|
|
1275
|
-
super(), this.finished = !1, this.destroyed = !1,
|
|
1276
|
-
const r =
|
|
1275
|
+
super(), this.finished = !1, this.destroyed = !1, mi(t);
|
|
1276
|
+
const r = Wt(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;
|
|
@@ -1287,10 +1287,10 @@ let Wn = class extends Mn {
|
|
|
1287
1287
|
this.oHash.update(s), s.fill(0);
|
|
1288
1288
|
}
|
|
1289
1289
|
update(t) {
|
|
1290
|
-
return
|
|
1290
|
+
return et(this), this.iHash.update(t), this;
|
|
1291
1291
|
}
|
|
1292
1292
|
digestInto(t) {
|
|
1293
|
-
|
|
1293
|
+
et(this), zn(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,33 +1305,33 @@ let Wn = class extends Mn {
|
|
|
1305
1305
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
1306
1306
|
}
|
|
1307
1307
|
};
|
|
1308
|
-
const
|
|
1309
|
-
|
|
1308
|
+
const nr = (e, t, n) => new tr(e, t).update(n).digest();
|
|
1309
|
+
nr.create = (e, t) => new tr(e, t);
|
|
1310
1310
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1311
|
-
function
|
|
1311
|
+
function os(e) {
|
|
1312
1312
|
return {
|
|
1313
1313
|
hash: e,
|
|
1314
|
-
hmac: (t, ...n) =>
|
|
1315
|
-
randomBytes:
|
|
1314
|
+
hmac: (t, ...n) => nr(e, t, Ai(...n)),
|
|
1315
|
+
randomBytes: Zn
|
|
1316
1316
|
};
|
|
1317
1317
|
}
|
|
1318
|
-
function
|
|
1319
|
-
const n = (r) =>
|
|
1318
|
+
function as(e, t) {
|
|
1319
|
+
const n = (r) => ss({ ...e, ...os(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 ct = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), tt = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), rr = BigInt(1), nt = BigInt(2), _n = (e, t) => (e + t / nt) / t;
|
|
1324
|
+
function ir(e) {
|
|
1325
|
+
const t = ct, n = BigInt(3), r = BigInt(6), i = BigInt(11), s = BigInt(22), o = BigInt(23), a = BigInt(44), c = BigInt(88), l = e * e * e % t, f = l * l * e % t, u = J(f, n, t) * f % t, g = J(u, n, t) * f % t, b = J(g, nt, t) * l % t, p = J(b, i, t) * b % t, h = J(p, s, t) * p % t, d = J(h, a, t) * h % t, y = J(d, c, t) * d % t, E = J(y, a, t) * h % t, N = J(E, n, t) * f % t, _ = J(N, o, t) * p % t, B = J(_, r, t) * l % t, m = J(B, nt, t);
|
|
1326
|
+
if (!Rt.eql(Rt.sqr(m), e))
|
|
1327
1327
|
throw new Error("Cannot find square root");
|
|
1328
1328
|
return m;
|
|
1329
1329
|
}
|
|
1330
|
-
const
|
|
1330
|
+
const Rt = Ji(ct, void 0, void 0, { sqrt: ir }), _e = as({
|
|
1331
1331
|
a: BigInt(0),
|
|
1332
1332
|
b: BigInt(7),
|
|
1333
|
-
Fp:
|
|
1334
|
-
n:
|
|
1333
|
+
Fp: Rt,
|
|
1334
|
+
n: tt,
|
|
1335
1335
|
// Base point (x, y) aka generator point
|
|
1336
1336
|
Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
|
|
1337
1337
|
Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
|
|
@@ -1346,95 +1346,95 @@ const Ot = Oi(ut, void 0, void 0, { sqrt: Yn }), Ue = Wi({
|
|
|
1346
1346
|
endo: {
|
|
1347
1347
|
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
1348
1348
|
splitScalar: (e) => {
|
|
1349
|
-
const t =
|
|
1350
|
-
let l =
|
|
1351
|
-
const u = l > o,
|
|
1352
|
-
if (u && (l = t - l),
|
|
1349
|
+
const t = tt, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -rr * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), s = n, o = BigInt("0x100000000000000000000000000000000"), a = _n(s * e, t), c = _n(-r * e, t);
|
|
1350
|
+
let l = V(e - a * n - c * i, t), f = V(-a * r - c * s, t);
|
|
1351
|
+
const u = l > o, g = f > o;
|
|
1352
|
+
if (u && (l = t - l), g && (f = t - f), l > o || f > o)
|
|
1353
1353
|
throw new Error("splitScalar: Endomorphism failed, k=" + e);
|
|
1354
|
-
return { k1neg: u, k1: l, k2neg:
|
|
1354
|
+
return { k1neg: u, k1: l, k2neg: g, k2: f };
|
|
1355
1355
|
}
|
|
1356
1356
|
}
|
|
1357
|
-
},
|
|
1358
|
-
function
|
|
1359
|
-
let n =
|
|
1357
|
+
}, Lt), ut = BigInt(0), sr = (e) => typeof e == "bigint" && ut < e && e < ct, cs = (e) => typeof e == "bigint" && ut < e && e < tt, In = {};
|
|
1358
|
+
function rt(e, ...t) {
|
|
1359
|
+
let n = In[e];
|
|
1360
1360
|
if (n === void 0) {
|
|
1361
|
-
const r =
|
|
1362
|
-
n =
|
|
1361
|
+
const r = Lt(Uint8Array.from(e, (i) => i.charCodeAt(0)));
|
|
1362
|
+
n = Ue(r, r), In[e] = n;
|
|
1363
1363
|
}
|
|
1364
|
-
return
|
|
1364
|
+
return Lt(Ue(n, ...t));
|
|
1365
1365
|
}
|
|
1366
|
-
const Yt = (e) => e.toRawBytes(!0).slice(1),
|
|
1366
|
+
const Yt = (e) => e.toRawBytes(!0).slice(1), Ot = (e) => Ae(e, 32), Nt = (e) => V(e, ct), Ge = (e) => V(e, tt), Xt = _e.ProjectivePoint, us = (e, t, n) => Xt.BASE.multiplyAndAddUnsafe(e, t, n);
|
|
1367
1367
|
function Mt(e) {
|
|
1368
|
-
let t =
|
|
1369
|
-
return { scalar: n.hasEvenY() ? t :
|
|
1368
|
+
let t = _e.utils.normPrivateKeyToScalar(e), n = Xt.fromPrivateKey(t);
|
|
1369
|
+
return { scalar: n.hasEvenY() ? t : Ge(-t), bytes: Yt(n) };
|
|
1370
1370
|
}
|
|
1371
|
-
function
|
|
1372
|
-
if (!
|
|
1371
|
+
function or(e) {
|
|
1372
|
+
if (!sr(e))
|
|
1373
1373
|
throw new Error("bad x: need 0 < x < p");
|
|
1374
|
-
const t =
|
|
1375
|
-
let r =
|
|
1376
|
-
r %
|
|
1377
|
-
const i = new Xt(e, r,
|
|
1374
|
+
const t = Nt(e * e), n = Nt(t * e + BigInt(7));
|
|
1375
|
+
let r = ir(n);
|
|
1376
|
+
r % nt !== ut && (r = Nt(-r));
|
|
1377
|
+
const i = new Xt(e, r, rr);
|
|
1378
1378
|
return i.assertValidity(), i;
|
|
1379
1379
|
}
|
|
1380
|
-
function
|
|
1381
|
-
return
|
|
1380
|
+
function ar(...e) {
|
|
1381
|
+
return Ge(F(rt("BIP0340/challenge", ...e)));
|
|
1382
1382
|
}
|
|
1383
|
-
function
|
|
1383
|
+
function ls(e) {
|
|
1384
1384
|
return Mt(e).bytes;
|
|
1385
1385
|
}
|
|
1386
|
-
function
|
|
1387
|
-
const r =
|
|
1388
|
-
if (l ===
|
|
1386
|
+
function fs(e, t, n = Zn(32)) {
|
|
1387
|
+
const r = W("message", e), { bytes: i, scalar: s } = Mt(t), o = W("auxRand", n, 32), a = Ot(s ^ F(rt("BIP0340/aux", o))), c = rt("BIP0340/nonce", a, i, r), l = Ge(F(c));
|
|
1388
|
+
if (l === ut)
|
|
1389
1389
|
throw new Error("sign failed: k is zero");
|
|
1390
|
-
const { bytes: f, scalar: u } = Mt(l),
|
|
1391
|
-
if (
|
|
1390
|
+
const { bytes: f, scalar: u } = Mt(l), g = ar(f, i, r), b = new Uint8Array(64);
|
|
1391
|
+
if (b.set(f, 0), b.set(Ot(Ge(u + g * s)), 32), !cr(b, r, i))
|
|
1392
1392
|
throw new Error("sign: Invalid signature produced");
|
|
1393
|
-
return
|
|
1393
|
+
return b;
|
|
1394
1394
|
}
|
|
1395
|
-
function
|
|
1396
|
-
const r =
|
|
1395
|
+
function cr(e, t, n) {
|
|
1396
|
+
const r = W("signature", e, 64), i = W("message", t), s = W("publicKey", n, 32);
|
|
1397
1397
|
try {
|
|
1398
|
-
const o =
|
|
1399
|
-
if (!
|
|
1398
|
+
const o = or(F(s)), a = F(r.subarray(0, 32));
|
|
1399
|
+
if (!sr(a))
|
|
1400
1400
|
return !1;
|
|
1401
|
-
const c =
|
|
1402
|
-
if (!
|
|
1401
|
+
const c = F(r.subarray(32, 64));
|
|
1402
|
+
if (!cs(c))
|
|
1403
1403
|
return !1;
|
|
1404
|
-
const l =
|
|
1404
|
+
const l = ar(Ot(a), Yt(o), i), f = us(o, c, Ge(-l));
|
|
1405
1405
|
return !(!f || !f.hasEvenY() || f.toAffine().x !== a);
|
|
1406
1406
|
} catch {
|
|
1407
1407
|
return !1;
|
|
1408
1408
|
}
|
|
1409
1409
|
}
|
|
1410
|
-
const
|
|
1411
|
-
getPublicKey:
|
|
1412
|
-
sign:
|
|
1413
|
-
verify:
|
|
1410
|
+
const We = {
|
|
1411
|
+
getPublicKey: ls,
|
|
1412
|
+
sign: fs,
|
|
1413
|
+
verify: cr,
|
|
1414
1414
|
utils: {
|
|
1415
|
-
randomPrivateKey:
|
|
1416
|
-
lift_x:
|
|
1415
|
+
randomPrivateKey: _e.utils.randomPrivateKey,
|
|
1416
|
+
lift_x: or,
|
|
1417
1417
|
pointToBytes: Yt,
|
|
1418
|
-
numberToBytesBE:
|
|
1419
|
-
bytesToNumberBE:
|
|
1420
|
-
taggedHash:
|
|
1421
|
-
mod:
|
|
1418
|
+
numberToBytesBE: Ae,
|
|
1419
|
+
bytesToNumberBE: F,
|
|
1420
|
+
taggedHash: rt,
|
|
1421
|
+
mod: V
|
|
1422
1422
|
}
|
|
1423
|
-
},
|
|
1423
|
+
}, Kt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
1424
1424
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1425
|
-
const Qt = (e) => e instanceof Uint8Array, kt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength),
|
|
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, hs = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1426
|
+
if (!hs)
|
|
1427
1427
|
throw new Error("Non little-endian hardware is not supported");
|
|
1428
|
-
const
|
|
1428
|
+
const ds = Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
1429
1429
|
function M(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 += ds[e[n]];
|
|
1435
1435
|
return t;
|
|
1436
1436
|
}
|
|
1437
|
-
function
|
|
1437
|
+
function G(e) {
|
|
1438
1438
|
if (typeof e != "string")
|
|
1439
1439
|
throw new Error("hex string expected, got " + typeof e);
|
|
1440
1440
|
const t = e.length;
|
|
@@ -1449,17 +1449,17 @@ function W(e) {
|
|
|
1449
1449
|
}
|
|
1450
1450
|
return n;
|
|
1451
1451
|
}
|
|
1452
|
-
function
|
|
1452
|
+
function ps(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
|
-
function
|
|
1458
|
-
if (typeof e == "string" && (e =
|
|
1457
|
+
function Fe(e) {
|
|
1458
|
+
if (typeof e == "string" && (e = ps(e)), !Qt(e))
|
|
1459
1459
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
1460
1460
|
return e;
|
|
1461
1461
|
}
|
|
1462
|
-
function
|
|
1462
|
+
function lt(...e) {
|
|
1463
1463
|
const t = new Uint8Array(e.reduce((r, i) => r + i.length, 0));
|
|
1464
1464
|
let n = 0;
|
|
1465
1465
|
return e.forEach((r) => {
|
|
@@ -1468,74 +1468,74 @@ function ht(...e) {
|
|
|
1468
1468
|
t.set(r, n), n += r.length;
|
|
1469
1469
|
}), t;
|
|
1470
1470
|
}
|
|
1471
|
-
class
|
|
1471
|
+
class ur {
|
|
1472
1472
|
// Safe version that clones internal state
|
|
1473
1473
|
clone() {
|
|
1474
1474
|
return this._cloneInto();
|
|
1475
1475
|
}
|
|
1476
1476
|
}
|
|
1477
|
-
function
|
|
1478
|
-
const t = (r) => e().update(
|
|
1477
|
+
function lr(e) {
|
|
1478
|
+
const t = (r) => e().update(Fe(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 fr(e = 32) {
|
|
1482
|
+
if (Kt && typeof Kt.getRandomValues == "function")
|
|
1483
|
+
return Kt.getRandomValues(new Uint8Array(e));
|
|
1484
1484
|
throw new Error("crypto.getRandomValues must be defined");
|
|
1485
1485
|
}
|
|
1486
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 ys(e) {
|
|
1491
1491
|
if (typeof e != "boolean")
|
|
1492
1492
|
throw new Error(`Expected boolean, not ${e}`);
|
|
1493
1493
|
}
|
|
1494
|
-
function
|
|
1494
|
+
function hr(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 gs(e) {
|
|
1501
1501
|
if (typeof e != "function" || typeof e.create != "function")
|
|
1502
1502
|
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
1503
1503
|
Ht(e.outputLen), Ht(e.blockLen);
|
|
1504
1504
|
}
|
|
1505
|
-
function
|
|
1505
|
+
function ws(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 bs(e, t) {
|
|
1512
|
+
hr(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
1518
|
number: Ht,
|
|
1519
|
-
bool:
|
|
1520
|
-
bytes:
|
|
1521
|
-
hash:
|
|
1522
|
-
exists:
|
|
1523
|
-
output:
|
|
1519
|
+
bool: ys,
|
|
1520
|
+
bytes: hr,
|
|
1521
|
+
hash: gs,
|
|
1522
|
+
exists: ws,
|
|
1523
|
+
output: bs
|
|
1524
1524
|
};
|
|
1525
|
-
function
|
|
1525
|
+
function vs(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), a = Number(n & s), c = r ? 4 : 0, l = r ? 0 : 4;
|
|
1529
1529
|
e.setUint32(t + c, o, r), e.setUint32(t + l, a, r);
|
|
1530
1530
|
}
|
|
1531
|
-
class
|
|
1531
|
+
class ms extends ur {
|
|
1532
1532
|
constructor(t, n, r, i) {
|
|
1533
1533
|
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view = kt(this.buffer);
|
|
1534
1534
|
}
|
|
1535
1535
|
update(t) {
|
|
1536
1536
|
se.exists(this);
|
|
1537
1537
|
const { view: n, buffer: r, blockLen: i } = this;
|
|
1538
|
-
t =
|
|
1538
|
+
t = Fe(t);
|
|
1539
1539
|
const s = t.length;
|
|
1540
1540
|
for (let o = 0; o < s; ) {
|
|
1541
1541
|
const a = Math.min(i - this.pos, s - o);
|
|
@@ -1556,7 +1556,7 @@ class as extends nr {
|
|
|
1556
1556
|
n[o++] = 128, this.buffer.subarray(o).fill(0), this.padOffset > i - o && (this.process(r, 0), o = 0);
|
|
1557
1557
|
for (let u = o; u < i; u++)
|
|
1558
1558
|
n[u] = 0;
|
|
1559
|
-
|
|
1559
|
+
vs(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
1560
1560
|
const a = kt(t), c = this.outputLen;
|
|
1561
1561
|
if (c % 4)
|
|
1562
1562
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
@@ -1578,7 +1578,7 @@ class as extends nr {
|
|
|
1578
1578
|
return t.length = i, t.pos = a, t.finished = s, t.destroyed = o, i % n && t.buffer.set(r), t;
|
|
1579
1579
|
}
|
|
1580
1580
|
}
|
|
1581
|
-
const
|
|
1581
|
+
const Es = (e, t, n) => e & t ^ ~e & n, xs = (e, t, n) => e & t ^ e & n ^ t & n, Ss = new Uint32Array([
|
|
1582
1582
|
1116352408,
|
|
1583
1583
|
1899447441,
|
|
1584
1584
|
3049323471,
|
|
@@ -1643,7 +1643,7 @@ const cs = (e, t, n) => e & t ^ ~e & n, ls = (e, t, n) => e & t ^ e & n ^ t & n,
|
|
|
1643
1643
|
2756734187,
|
|
1644
1644
|
3204031479,
|
|
1645
1645
|
3329325298
|
|
1646
|
-
]),
|
|
1646
|
+
]), me = new Uint32Array([
|
|
1647
1647
|
1779033703,
|
|
1648
1648
|
3144134277,
|
|
1649
1649
|
1013904242,
|
|
@@ -1652,10 +1652,10 @@ const cs = (e, t, n) => e & t ^ ~e & n, ls = (e, t, n) => e & t ^ e & n ^ t & n,
|
|
|
1652
1652
|
2600822924,
|
|
1653
1653
|
528734635,
|
|
1654
1654
|
1541459225
|
|
1655
|
-
]),
|
|
1656
|
-
class
|
|
1655
|
+
]), Ee = new Uint32Array(64);
|
|
1656
|
+
class dr extends ms {
|
|
1657
1657
|
constructor() {
|
|
1658
|
-
super(64, 32, 8, !1), this.A =
|
|
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
|
}
|
|
1660
1660
|
get() {
|
|
1661
1661
|
const { A: t, B: n, C: r, D: i, E: s, F: o, G: a, H: c } = this;
|
|
@@ -1667,48 +1667,48 @@ class or extends as {
|
|
|
1667
1667
|
}
|
|
1668
1668
|
process(t, n) {
|
|
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
|
|
1673
|
-
|
|
1672
|
+
const g = Ee[u - 15], b = Ee[u - 2], p = ie(g, 7) ^ ie(g, 18) ^ g >>> 3, h = ie(b, 17) ^ ie(b, 19) ^ b >>> 10;
|
|
1673
|
+
Ee[u] = h + Ee[u - 7] + p + Ee[u - 16] | 0;
|
|
1674
1674
|
}
|
|
1675
1675
|
let { A: r, B: i, C: s, D: o, E: a, F: c, G: l, H: f } = this;
|
|
1676
1676
|
for (let u = 0; u < 64; u++) {
|
|
1677
|
-
const
|
|
1678
|
-
f = l, l = c, c = a, a = o +
|
|
1677
|
+
const g = ie(a, 6) ^ ie(a, 11) ^ ie(a, 25), b = f + g + Es(a, c, l) + Ss[u] + Ee[u] | 0, h = (ie(r, 2) ^ ie(r, 13) ^ ie(r, 22)) + xs(r, i, s) | 0;
|
|
1678
|
+
f = l, l = c, c = a, a = o + b | 0, o = s, s = i, i = r, r = b + 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, a = a + this.E | 0, c = c + this.F | 0, l = l + this.G | 0, f = f + this.H | 0, this.set(r, i, s, o, a, c, l, f);
|
|
1681
1681
|
}
|
|
1682
1682
|
roundClean() {
|
|
1683
|
-
|
|
1683
|
+
Ee.fill(0);
|
|
1684
1684
|
}
|
|
1685
1685
|
destroy() {
|
|
1686
1686
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
|
|
1687
1687
|
}
|
|
1688
1688
|
}
|
|
1689
|
-
class
|
|
1689
|
+
class As extends dr {
|
|
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
|
|
1695
|
-
|
|
1694
|
+
const fe = lr(() => new dr());
|
|
1695
|
+
lr(() => new As());
|
|
1696
1696
|
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1697
|
-
function
|
|
1697
|
+
function ze(e) {
|
|
1698
1698
|
if (!Number.isSafeInteger(e))
|
|
1699
1699
|
throw new Error(`Wrong integer: ${e}`);
|
|
1700
1700
|
}
|
|
1701
|
-
function
|
|
1701
|
+
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 (ze(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 he(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 de(e = "") {
|
|
|
1746
1746
|
}
|
|
1747
1747
|
};
|
|
1748
1748
|
}
|
|
1749
|
-
function
|
|
1750
|
-
if (
|
|
1749
|
+
function ft(e, t = "=") {
|
|
1750
|
+
if (ze(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 dt(e, t = "=") {
|
|
|
1776
1776
|
}
|
|
1777
1777
|
};
|
|
1778
1778
|
}
|
|
1779
|
-
function
|
|
1779
|
+
function pr(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 Ln(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 Bn(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 (ze(o), o < 0 || o >= t)
|
|
1797
1797
|
throw new Error(`Wrong integer: ${o}`);
|
|
1798
1798
|
}); ; ) {
|
|
1799
1799
|
let o = 0, a = !0;
|
|
@@ -1814,20 +1814,20 @@ function Bn(e, t, n) {
|
|
|
1814
1814
|
i.push(0);
|
|
1815
1815
|
return i.reverse();
|
|
1816
1816
|
}
|
|
1817
|
-
const
|
|
1818
|
-
function
|
|
1817
|
+
const yr = (e, t) => t ? yr(t, e % t) : e, it = (e, t) => e + (t - yr(e, t));
|
|
1818
|
+
function Pt(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)
|
|
1822
1822
|
throw new Error(`convertRadix2: wrong from=${t}`);
|
|
1823
1823
|
if (n <= 0 || n > 32)
|
|
1824
1824
|
throw new Error(`convertRadix2: wrong to=${n}`);
|
|
1825
|
-
if (
|
|
1826
|
-
throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${
|
|
1825
|
+
if (it(t, n) > 32)
|
|
1826
|
+
throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${it(t, n)}`);
|
|
1827
1827
|
let i = 0, s = 0;
|
|
1828
1828
|
const o = 2 ** n - 1, a = [];
|
|
1829
1829
|
for (const c of e) {
|
|
1830
|
-
if (
|
|
1830
|
+
if (ze(c), c >= 2 ** t)
|
|
1831
1831
|
throw new Error(`convertRadix2: invalid data word=${c} from=${t}`);
|
|
1832
1832
|
if (i = i << t | c, s + t > 32)
|
|
1833
1833
|
throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);
|
|
@@ -1841,39 +1841,39 @@ function qt(e, t, n, r) {
|
|
|
1841
1841
|
throw new Error(`Non-zero padding: ${i}`);
|
|
1842
1842
|
return r && s > 0 && a.push(i >>> 0), a;
|
|
1843
1843
|
}
|
|
1844
|
-
function
|
|
1845
|
-
return
|
|
1844
|
+
function Ns(e) {
|
|
1845
|
+
return ze(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 Ln(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(Ln(t, e, 2 ** 8));
|
|
1855
1855
|
}
|
|
1856
1856
|
};
|
|
1857
1857
|
}
|
|
1858
|
-
function
|
|
1859
|
-
if (
|
|
1858
|
+
function Ne(e, t = !1) {
|
|
1859
|
+
if (ze(e), e <= 0 || e > 32)
|
|
1860
1860
|
throw new Error("radix2: bits should be in (0..32]");
|
|
1861
|
-
if (
|
|
1861
|
+
if (it(8, e) > 32 || it(e, 8) > 32)
|
|
1862
1862
|
throw new Error("radix2: carry overflow");
|
|
1863
1863
|
return {
|
|
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 Pt(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(Pt(n, e, 8, t));
|
|
1873
1873
|
}
|
|
1874
1874
|
};
|
|
1875
1875
|
}
|
|
1876
|
-
function
|
|
1876
|
+
function $n(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 Cn(e) {
|
|
|
1883
1883
|
}
|
|
1884
1884
|
};
|
|
1885
1885
|
}
|
|
1886
|
-
const
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
const
|
|
1886
|
+
const Ks = de(Ne(4), pe("0123456789ABCDEF"), ye("")), ks = de(Ne(5), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), ft(5), ye(""));
|
|
1887
|
+
de(Ne(5), pe("0123456789ABCDEFGHIJKLMNOPQRSTUV"), ft(5), ye(""));
|
|
1888
|
+
de(Ne(5), pe("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), ye(""), pr((e) => e.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
1889
|
+
const he = de(Ne(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), ft(6), ye("")), Bs = de(Ne(6), pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), ft(6), ye("")), en = (e) => de(Ns(58), pe(e), ye("")), qt = en("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
1890
1890
|
en("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
|
|
1891
1891
|
en("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");
|
|
1892
|
-
const
|
|
1892
|
+
const Tn = [0, 2, 3, 5, 6, 7, 9, 10, 11], Cs = {
|
|
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 += qt.encode(r).padStart(Tn[r.length], "1");
|
|
1898
1898
|
}
|
|
1899
1899
|
return t;
|
|
1900
1900
|
},
|
|
1901
1901
|
decode(e) {
|
|
1902
1902
|
let t = [];
|
|
1903
1903
|
for (let n = 0; n < e.length; n += 11) {
|
|
1904
|
-
const r = e.slice(n, n + 11), i =
|
|
1904
|
+
const r = e.slice(n, n + 11), i = Tn.indexOf(r.length), s = qt.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,118 +1909,118 @@ const kn = [0, 2, 3, 5, 6, 7, 9, 10, 11], gs = {
|
|
|
1909
1909
|
}
|
|
1910
1910
|
return Uint8Array.from(t);
|
|
1911
1911
|
}
|
|
1912
|
-
},
|
|
1913
|
-
function
|
|
1912
|
+
}, Dt = de(pe("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), ye("")), Rn = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
1913
|
+
function Ze(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 < Rn.length; r++)
|
|
1917
|
+
(t >> r & 1) === 1 && (n ^= Rn[r]);
|
|
1918
1918
|
return n;
|
|
1919
1919
|
}
|
|
1920
|
-
function
|
|
1920
|
+
function On(e, t, n = 1) {
|
|
1921
1921
|
const r = e.length;
|
|
1922
1922
|
let i = 1;
|
|
1923
1923
|
for (let s = 0; s < r; s++) {
|
|
1924
1924
|
const o = e.charCodeAt(s);
|
|
1925
1925
|
if (o < 33 || o > 126)
|
|
1926
1926
|
throw new Error(`Invalid prefix (${e})`);
|
|
1927
|
-
i =
|
|
1927
|
+
i = Ze(i) ^ o >> 5;
|
|
1928
1928
|
}
|
|
1929
|
-
i =
|
|
1929
|
+
i = Ze(i);
|
|
1930
1930
|
for (let s = 0; s < r; s++)
|
|
1931
|
-
i =
|
|
1931
|
+
i = Ze(i) ^ e.charCodeAt(s) & 31;
|
|
1932
1932
|
for (let s of t)
|
|
1933
|
-
i =
|
|
1933
|
+
i = Ze(i) ^ s;
|
|
1934
1934
|
for (let s = 0; s < 6; s++)
|
|
1935
|
-
i =
|
|
1936
|
-
return i ^= n,
|
|
1935
|
+
i = Ze(i);
|
|
1936
|
+
return i ^= n, Dt.encode(Pt([i % 2 ** 30], 30, 5, !1));
|
|
1937
1937
|
}
|
|
1938
|
-
function
|
|
1939
|
-
const t = e === "bech32" ? 1 : 734539939, n =
|
|
1940
|
-
function o(f, u,
|
|
1938
|
+
function gr(e) {
|
|
1939
|
+
const t = e === "bech32" ? 1 : 734539939, n = Ne(5), r = n.decode, i = n.encode, s = $n(r);
|
|
1940
|
+
function o(f, u, g = 90) {
|
|
1941
1941
|
if (typeof f != "string")
|
|
1942
1942
|
throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);
|
|
1943
1943
|
if (!Array.isArray(u) || u.length && typeof u[0] != "number")
|
|
1944
1944
|
throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);
|
|
1945
|
-
const
|
|
1946
|
-
if (
|
|
1947
|
-
throw new TypeError(`Length ${
|
|
1948
|
-
return f = f.toLowerCase(), `${f}1${
|
|
1945
|
+
const b = f.length + 7 + u.length;
|
|
1946
|
+
if (g !== !1 && b > g)
|
|
1947
|
+
throw new TypeError(`Length ${b} exceeds limit ${g}`);
|
|
1948
|
+
return f = f.toLowerCase(), `${f}1${Dt.encode(u)}${On(f, u, t)}`;
|
|
1949
1949
|
}
|
|
1950
1950
|
function a(f, u = 90) {
|
|
1951
1951
|
if (typeof f != "string")
|
|
1952
1952
|
throw new Error(`bech32.decode input should be string, not ${typeof f}`);
|
|
1953
1953
|
if (f.length < 8 || u !== !1 && f.length > u)
|
|
1954
1954
|
throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${u})`);
|
|
1955
|
-
const
|
|
1956
|
-
if (f !==
|
|
1955
|
+
const g = f.toLowerCase();
|
|
1956
|
+
if (f !== g && f !== f.toUpperCase())
|
|
1957
1957
|
throw new Error("String must be lowercase or uppercase");
|
|
1958
|
-
f =
|
|
1959
|
-
const
|
|
1960
|
-
if (
|
|
1958
|
+
f = g;
|
|
1959
|
+
const b = f.lastIndexOf("1");
|
|
1960
|
+
if (b === 0 || b === -1)
|
|
1961
1961
|
throw new Error('Letter "1" must be present between prefix and data only');
|
|
1962
|
-
const
|
|
1962
|
+
const p = f.slice(0, b), h = f.slice(b + 1);
|
|
1963
1963
|
if (h.length < 6)
|
|
1964
1964
|
throw new Error("Data must be at least 6 characters long");
|
|
1965
|
-
const
|
|
1966
|
-
if (!h.endsWith(
|
|
1967
|
-
throw new Error(`Invalid checksum in ${f}: expected "${
|
|
1968
|
-
return { prefix:
|
|
1965
|
+
const d = Dt.decode(h).slice(0, -6), y = On(p, d, t);
|
|
1966
|
+
if (!h.endsWith(y))
|
|
1967
|
+
throw new Error(`Invalid checksum in ${f}: expected "${y}"`);
|
|
1968
|
+
return { prefix: p, words: d };
|
|
1969
1969
|
}
|
|
1970
|
-
const c =
|
|
1970
|
+
const c = $n(a);
|
|
1971
1971
|
function l(f) {
|
|
1972
|
-
const { prefix: u, words:
|
|
1973
|
-
return { prefix: u, words:
|
|
1972
|
+
const { prefix: u, words: g } = a(f, !1);
|
|
1973
|
+
return { prefix: u, words: g, bytes: r(g) };
|
|
1974
1974
|
}
|
|
1975
1975
|
return { encode: o, decode: a, decodeToBytes: l, decodeUnsafe: c, fromWords: r, fromWordsUnsafe: s, toWords: i };
|
|
1976
1976
|
}
|
|
1977
|
-
const je =
|
|
1978
|
-
|
|
1979
|
-
const
|
|
1977
|
+
const je = gr("bech32");
|
|
1978
|
+
gr("bech32m");
|
|
1979
|
+
const Us = {
|
|
1980
1980
|
encode: (e) => new TextDecoder().decode(e),
|
|
1981
1981
|
decode: (e) => new TextEncoder().encode(e)
|
|
1982
|
-
},
|
|
1982
|
+
}, _s = de(Ne(4), pe("0123456789abcdef"), ye(""), pr((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:
|
|
1991
|
-
base64:
|
|
1992
|
-
base64url:
|
|
1993
|
-
base58:
|
|
1994
|
-
base58xmr:
|
|
1986
|
+
})), Is = {
|
|
1987
|
+
utf8: Us,
|
|
1988
|
+
hex: _s,
|
|
1989
|
+
base16: Ks,
|
|
1990
|
+
base32: ks,
|
|
1991
|
+
base64: he,
|
|
1992
|
+
base64url: Bs,
|
|
1993
|
+
base58: qt,
|
|
1994
|
+
base58xmr: Cs
|
|
1995
1995
|
};
|
|
1996
|
-
`${Object.keys(
|
|
1997
|
-
function
|
|
1996
|
+
`${Object.keys(Is).join(", ")}`;
|
|
1997
|
+
function Bt(e) {
|
|
1998
1998
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
1999
1999
|
throw new Error(`positive integer expected, not ${e}`);
|
|
2000
2000
|
}
|
|
2001
|
-
function
|
|
2001
|
+
function Mn(e) {
|
|
2002
2002
|
if (typeof e != "boolean")
|
|
2003
2003
|
throw new Error(`boolean expected, not ${e}`);
|
|
2004
2004
|
}
|
|
2005
|
-
function
|
|
2005
|
+
function Ls(e) {
|
|
2006
2006
|
return e instanceof Uint8Array || e != null && typeof e == "object" && e.constructor.name === "Uint8Array";
|
|
2007
2007
|
}
|
|
2008
|
-
function
|
|
2009
|
-
if (!
|
|
2008
|
+
function ce(e, ...t) {
|
|
2009
|
+
if (!Ls(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
|
|
2016
|
-
if (
|
|
2015
|
+
const Z = (e) => new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4)), $s = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
2016
|
+
if (!$s)
|
|
2017
2017
|
throw new Error("Non little-endian hardware is not supported");
|
|
2018
|
-
function
|
|
2018
|
+
function Ts(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 Rs(e, t) {
|
|
2024
2024
|
if (e.length !== t.length)
|
|
2025
2025
|
return !1;
|
|
2026
2026
|
let n = 0;
|
|
@@ -2028,17 +2028,17 @@ function Ss(e, t) {
|
|
|
2028
2028
|
n |= e[r] ^ t[r];
|
|
2029
2029
|
return n === 0;
|
|
2030
2030
|
}
|
|
2031
|
-
const
|
|
2031
|
+
const Os = /* @__NO_SIDE_EFFECTS__ */ (e, t) => (Object.assign(t, e), t), Se = 16, Ms = 283;
|
|
2032
2032
|
function tn(e) {
|
|
2033
|
-
return e << 1 ^
|
|
2033
|
+
return e << 1 ^ Ms & -(e >> 7);
|
|
2034
2034
|
}
|
|
2035
|
-
function
|
|
2035
|
+
function He(e, t) {
|
|
2036
2036
|
let n = 0;
|
|
2037
2037
|
for (; t > 0; t >>= 1)
|
|
2038
2038
|
n ^= e & -(t & 1), e = tn(e);
|
|
2039
2039
|
return n;
|
|
2040
2040
|
}
|
|
2041
|
-
const
|
|
2041
|
+
const jt = /* @__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 Vt = /* @__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
|
+
})(), Hs = /* @__PURE__ */ jt.map((e, t) => jt.indexOf(t)), Ps = (e) => e << 24 | e >>> 8, Ct = (e) => e << 8 | e >>> 24;
|
|
2053
|
+
function wr(e, t) {
|
|
2054
2054
|
if (e.length !== 256)
|
|
2055
2055
|
throw new Error("Wrong sbox length");
|
|
2056
|
-
const n = new Uint32Array(256).map((l, f) => t(e[f])), r = n.map(
|
|
2056
|
+
const n = new Uint32Array(256).map((l, f) => t(e[f])), r = n.map(Ct), i = r.map(Ct), s = i.map(Ct), o = new Uint32Array(256 * 256), a = new Uint32Array(256 * 256), c = 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,27 +2061,27 @@ function ur(e, t) {
|
|
|
2061
2061
|
}
|
|
2062
2062
|
return { sbox: e, sbox2: c, T0: n, T1: r, T2: i, T3: s, T01: o, T23: a };
|
|
2063
2063
|
}
|
|
2064
|
-
const nn = /* @__PURE__ */
|
|
2064
|
+
const nn = /* @__PURE__ */ wr(jt, (e) => He(e, 3) << 24 | e << 16 | e << 8 | He(e, 2)), br = /* @__PURE__ */ wr(Hs, (e) => He(e, 11) << 24 | He(e, 13) << 16 | He(e, 9) << 8 | He(e, 14)), qs = /* @__PURE__ */ (() => {
|
|
2065
2065
|
const e = new Uint8Array(16);
|
|
2066
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 vr(e) {
|
|
2071
|
+
ce(e);
|
|
2072
2072
|
const t = e.length;
|
|
2073
2073
|
if (![16, 24, 32].includes(t))
|
|
2074
2074
|
throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);
|
|
2075
|
-
const { sbox2: n } = nn, r =
|
|
2075
|
+
const { sbox2: n } = nn, r = Z(e), i = r.length, s = (a) => oe(n, a, a, a, a), o = new Uint32Array(t + 28);
|
|
2076
2076
|
o.set(r);
|
|
2077
2077
|
for (let a = i; a < o.length; a++) {
|
|
2078
2078
|
let c = o[a - 1];
|
|
2079
|
-
a % i === 0 ? c = s(
|
|
2079
|
+
a % i === 0 ? c = s(Ps(c)) ^ qs[a / i - 1] : i > 6 && a % i === 4 && (c = s(c)), o[a] = o[a - i] ^ c;
|
|
2080
2080
|
}
|
|
2081
2081
|
return o;
|
|
2082
2082
|
}
|
|
2083
|
-
function
|
|
2084
|
-
const t =
|
|
2083
|
+
function Ds(e) {
|
|
2084
|
+
const t = vr(e), n = t.slice(), r = t.length, { sbox2: i } = nn, { T0: s, T1: o, T2: a, T3: c } = br;
|
|
2085
2085
|
for (let l = 0; l < r; l += 4)
|
|
2086
2086
|
for (let f = 0; f < 4; f++)
|
|
2087
2087
|
n[l + f] = t[r - l - 4 + f];
|
|
@@ -2092,61 +2092,61 @@ function ks(e) {
|
|
|
2092
2092
|
}
|
|
2093
2093
|
return n;
|
|
2094
2094
|
}
|
|
2095
|
-
function
|
|
2095
|
+
function xe(e, t, n, r, i, s) {
|
|
2096
2096
|
return e[n << 8 & 65280 | r >>> 8 & 255] ^ t[i >>> 8 & 65280 | s >>> 24 & 255];
|
|
2097
2097
|
}
|
|
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 Hn(e, t, n, r, i) {
|
|
2102
2102
|
const { sbox2: s, T01: o, T23: a } = nn;
|
|
2103
2103
|
let c = 0;
|
|
2104
2104
|
t ^= e[c++], n ^= e[c++], r ^= e[c++], i ^= e[c++];
|
|
2105
2105
|
const l = e.length / 4 - 2;
|
|
2106
|
-
for (let
|
|
2107
|
-
const h = e[c++] ^
|
|
2108
|
-
t = h, n =
|
|
2106
|
+
for (let p = 0; p < l; p++) {
|
|
2107
|
+
const h = e[c++] ^ xe(o, a, t, n, r, i), d = e[c++] ^ xe(o, a, n, r, i, t), y = e[c++] ^ xe(o, a, r, i, t, n), E = e[c++] ^ xe(o, a, i, t, n, r);
|
|
2108
|
+
t = h, n = d, r = y, i = E;
|
|
2109
2109
|
}
|
|
2110
|
-
const f = e[c++] ^ oe(s, t, n, r, i), u = e[c++] ^ oe(s, n, r, i, t),
|
|
2111
|
-
return { s0: f, s1: u, s2:
|
|
2110
|
+
const f = e[c++] ^ oe(s, t, n, r, i), u = e[c++] ^ oe(s, n, r, i, t), g = e[c++] ^ oe(s, r, i, t, n), b = e[c++] ^ oe(s, i, t, n, r);
|
|
2111
|
+
return { s0: f, s1: u, s2: g, s3: b };
|
|
2112
2112
|
}
|
|
2113
|
-
function
|
|
2114
|
-
const { sbox2: s, T01: o, T23: a } =
|
|
2113
|
+
function js(e, t, n, r, i) {
|
|
2114
|
+
const { sbox2: s, T01: o, T23: a } = br;
|
|
2115
2115
|
let c = 0;
|
|
2116
2116
|
t ^= e[c++], n ^= e[c++], r ^= e[c++], i ^= e[c++];
|
|
2117
2117
|
const l = e.length / 4 - 2;
|
|
2118
|
-
for (let
|
|
2119
|
-
const h = e[c++] ^
|
|
2120
|
-
t = h, n =
|
|
2118
|
+
for (let p = 0; p < l; p++) {
|
|
2119
|
+
const h = e[c++] ^ xe(o, a, t, i, r, n), d = e[c++] ^ xe(o, a, n, t, i, r), y = e[c++] ^ xe(o, a, r, n, t, i), E = e[c++] ^ xe(o, a, i, r, n, t);
|
|
2120
|
+
t = h, n = d, r = y, i = E;
|
|
2121
2121
|
}
|
|
2122
|
-
const f = e[c++] ^ oe(s, t, i, r, n), u = e[c++] ^ oe(s, n, t, i, r),
|
|
2123
|
-
return { s0: f, s1: u, s2:
|
|
2122
|
+
const f = e[c++] ^ oe(s, t, i, r, n), u = e[c++] ^ oe(s, n, t, i, r), g = e[c++] ^ oe(s, r, n, t, i), b = e[c++] ^ oe(s, i, r, n, t);
|
|
2123
|
+
return { s0: f, s1: u, s2: g, s3: b };
|
|
2124
2124
|
}
|
|
2125
|
-
function
|
|
2125
|
+
function mr(e, t) {
|
|
2126
2126
|
if (!t)
|
|
2127
2127
|
return new Uint8Array(e);
|
|
2128
|
-
if (
|
|
2128
|
+
if (ce(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 (
|
|
2134
|
-
throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${
|
|
2132
|
+
function zs(e) {
|
|
2133
|
+
if (ce(e), e.length % Se !== 0)
|
|
2134
|
+
throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Se}`);
|
|
2135
2135
|
}
|
|
2136
|
-
function
|
|
2136
|
+
function Vs(e, t, n) {
|
|
2137
2137
|
let r = e.length;
|
|
2138
|
-
const i = r %
|
|
2138
|
+
const i = r % Se;
|
|
2139
2139
|
if (!t && i !== 0)
|
|
2140
2140
|
throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");
|
|
2141
|
-
const s =
|
|
2141
|
+
const s = Z(e);
|
|
2142
2142
|
if (t) {
|
|
2143
|
-
let c =
|
|
2144
|
-
c || (c =
|
|
2143
|
+
let c = Se - i;
|
|
2144
|
+
c || (c = Se), r = r + c;
|
|
2145
2145
|
}
|
|
2146
|
-
const o =
|
|
2146
|
+
const o = mr(r, n), a = Z(o);
|
|
2147
2147
|
return { b: s, o: a, out: o };
|
|
2148
2148
|
}
|
|
2149
|
-
function
|
|
2149
|
+
function Ws(e, t) {
|
|
2150
2150
|
if (!t)
|
|
2151
2151
|
return e;
|
|
2152
2152
|
const n = e.length;
|
|
@@ -2161,126 +2161,126 @@ function Ls(e, t) {
|
|
|
2161
2161
|
throw new Error("aes/pcks5: wrong padding");
|
|
2162
2162
|
return i;
|
|
2163
2163
|
}
|
|
2164
|
-
function
|
|
2165
|
-
const t = new Uint8Array(16), n =
|
|
2164
|
+
function Zs(e) {
|
|
2165
|
+
const t = new Uint8Array(16), n = Z(t);
|
|
2166
2166
|
t.set(e);
|
|
2167
|
-
const r =
|
|
2168
|
-
for (let i =
|
|
2167
|
+
const r = Se - e.length;
|
|
2168
|
+
for (let i = Se - r; i < Se; i++)
|
|
2169
2169
|
t[i] = r;
|
|
2170
2170
|
return n;
|
|
2171
2171
|
}
|
|
2172
|
-
const
|
|
2173
|
-
|
|
2172
|
+
const Er = /* @__PURE__ */ Os({ blockSize: 16, nonceLength: 16 }, function(t, n, r = {}) {
|
|
2173
|
+
ce(t), ce(n, 16);
|
|
2174
2174
|
const i = !r.disablePadding;
|
|
2175
2175
|
return {
|
|
2176
2176
|
encrypt: (s, o) => {
|
|
2177
|
-
const a =
|
|
2178
|
-
let
|
|
2179
|
-
for (;
|
|
2180
|
-
|
|
2177
|
+
const a = vr(t), { b: c, o: l, out: f } = Vs(s, i, o), u = Z(n);
|
|
2178
|
+
let g = u[0], b = u[1], p = u[2], h = u[3], d = 0;
|
|
2179
|
+
for (; d + 4 <= c.length; )
|
|
2180
|
+
g ^= c[d + 0], b ^= c[d + 1], p ^= c[d + 2], h ^= c[d + 3], { s0: g, s1: b, s2: p, s3: h } = Hn(a, g, b, p, h), l[d++] = g, l[d++] = b, l[d++] = p, l[d++] = h;
|
|
2181
2181
|
if (i) {
|
|
2182
|
-
const
|
|
2183
|
-
|
|
2182
|
+
const y = Zs(s.subarray(d * 4));
|
|
2183
|
+
g ^= y[0], b ^= y[1], p ^= y[2], h ^= y[3], { s0: g, s1: b, s2: p, s3: h } = Hn(a, g, b, p, h), l[d++] = g, l[d++] = b, l[d++] = p, l[d++] = h;
|
|
2184
2184
|
}
|
|
2185
2185
|
return a.fill(0), f;
|
|
2186
2186
|
},
|
|
2187
2187
|
decrypt: (s, o) => {
|
|
2188
|
-
|
|
2189
|
-
const a =
|
|
2190
|
-
let
|
|
2191
|
-
for (let
|
|
2192
|
-
const
|
|
2193
|
-
|
|
2194
|
-
const { s0:
|
|
2195
|
-
u[
|
|
2188
|
+
zs(s);
|
|
2189
|
+
const a = Ds(t), c = Z(n), l = mr(s.length, o), f = Z(s), u = Z(l);
|
|
2190
|
+
let g = c[0], b = c[1], p = c[2], h = c[3];
|
|
2191
|
+
for (let d = 0; d + 4 <= f.length; ) {
|
|
2192
|
+
const y = g, E = b, N = p, _ = h;
|
|
2193
|
+
g = f[d + 0], b = f[d + 1], p = f[d + 2], h = f[d + 3];
|
|
2194
|
+
const { s0: B, s1: m, s2: x, s3: S } = js(a, g, b, p, h);
|
|
2195
|
+
u[d++] = B ^ y, u[d++] = m ^ E, u[d++] = x ^ N, u[d++] = S ^ _;
|
|
2196
2196
|
}
|
|
2197
|
-
return a.fill(0),
|
|
2197
|
+
return a.fill(0), Ws(l, i);
|
|
2198
2198
|
}
|
|
2199
2199
|
};
|
|
2200
|
-
}),
|
|
2201
|
-
|
|
2200
|
+
}), xr = (e) => Uint8Array.from(e.split("").map((t) => t.charCodeAt(0))), Gs = xr("expand 16-byte k"), Fs = xr("expand 32-byte k"), Js = Z(Gs), Sr = Z(Fs);
|
|
2201
|
+
Sr.slice();
|
|
2202
2202
|
function L(e, t) {
|
|
2203
2203
|
return e << t | e >>> 32 - t;
|
|
2204
2204
|
}
|
|
2205
2205
|
function zt(e) {
|
|
2206
2206
|
return e.byteOffset % 4 === 0;
|
|
2207
2207
|
}
|
|
2208
|
-
const
|
|
2209
|
-
function
|
|
2210
|
-
const c = i.length, l = new Uint8Array(
|
|
2211
|
-
for (let
|
|
2212
|
-
if (e(t, n, r, f, o, a), o >=
|
|
2208
|
+
const Ye = 64, Ys = 16, Ar = 2 ** 32 - 1, Pn = new Uint32Array();
|
|
2209
|
+
function Xs(e, t, n, r, i, s, o, a) {
|
|
2210
|
+
const c = i.length, l = new Uint8Array(Ye), f = Z(l), u = zt(i) && zt(s), g = u ? Z(i) : Pn, b = u ? Z(s) : Pn;
|
|
2211
|
+
for (let p = 0; p < c; o++) {
|
|
2212
|
+
if (e(t, n, r, f, o, a), o >= Ar)
|
|
2213
2213
|
throw new Error("arx: counter overflow");
|
|
2214
|
-
const h = Math.min(
|
|
2215
|
-
if (u && h ===
|
|
2216
|
-
const
|
|
2217
|
-
if (
|
|
2214
|
+
const h = Math.min(Ye, c - p);
|
|
2215
|
+
if (u && h === Ye) {
|
|
2216
|
+
const d = p / 4;
|
|
2217
|
+
if (p % 4 !== 0)
|
|
2218
2218
|
throw new Error("arx: invalid block position");
|
|
2219
|
-
for (let
|
|
2220
|
-
E =
|
|
2221
|
-
|
|
2219
|
+
for (let y = 0, E; y < Ys; y++)
|
|
2220
|
+
E = d + y, b[E] = g[E] ^ f[y];
|
|
2221
|
+
p += Ye;
|
|
2222
2222
|
continue;
|
|
2223
2223
|
}
|
|
2224
|
-
for (let
|
|
2225
|
-
|
|
2226
|
-
|
|
2224
|
+
for (let d = 0, y; d < h; d++)
|
|
2225
|
+
y = p + d, s[y] = i[y] ^ l[d];
|
|
2226
|
+
p += h;
|
|
2227
2227
|
}
|
|
2228
2228
|
}
|
|
2229
|
-
function
|
|
2230
|
-
const { allowShortKeys: n, extendNonceFn: r, counterLength: i, counterRight: s, rounds: o } =
|
|
2229
|
+
function Qs(e, t) {
|
|
2230
|
+
const { allowShortKeys: n, extendNonceFn: r, counterLength: i, counterRight: s, rounds: o } = Ts({ allowShortKeys: !1, counterLength: 8, counterRight: !1, rounds: 20 }, t);
|
|
2231
2231
|
if (typeof e != "function")
|
|
2232
2232
|
throw new Error("core must be a function");
|
|
2233
|
-
return
|
|
2234
|
-
|
|
2235
|
-
const
|
|
2236
|
-
if (f || (f = new Uint8Array(
|
|
2233
|
+
return Bt(i), Bt(o), Mn(s), Mn(n), (a, c, l, f, u = 0) => {
|
|
2234
|
+
ce(a), ce(c), ce(l);
|
|
2235
|
+
const g = l.length;
|
|
2236
|
+
if (f || (f = new Uint8Array(g)), ce(f), Bt(u), u < 0 || u >= Ar)
|
|
2237
2237
|
throw new Error("arx: counter overflow");
|
|
2238
|
-
if (f.length <
|
|
2239
|
-
throw new Error(`arx: output (${f.length}) is shorter than data (${
|
|
2240
|
-
const
|
|
2241
|
-
let
|
|
2242
|
-
if (
|
|
2243
|
-
h = a.slice(),
|
|
2244
|
-
else if (
|
|
2245
|
-
h = new Uint8Array(32), h.set(a), h.set(a, 16),
|
|
2238
|
+
if (f.length < g)
|
|
2239
|
+
throw new Error(`arx: output (${f.length}) is shorter than data (${g})`);
|
|
2240
|
+
const b = [];
|
|
2241
|
+
let p = a.length, h, d;
|
|
2242
|
+
if (p === 32)
|
|
2243
|
+
h = a.slice(), b.push(h), d = Sr;
|
|
2244
|
+
else if (p === 16 && n)
|
|
2245
|
+
h = new Uint8Array(32), h.set(a), h.set(a, 16), d = Js, b.push(h);
|
|
2246
2246
|
else
|
|
2247
|
-
throw new Error(`arx: invalid 32-byte key, got length=${
|
|
2248
|
-
zt(c) || (c = c.slice(),
|
|
2249
|
-
const
|
|
2247
|
+
throw new Error(`arx: invalid 32-byte key, got length=${p}`);
|
|
2248
|
+
zt(c) || (c = c.slice(), b.push(c));
|
|
2249
|
+
const y = Z(h);
|
|
2250
2250
|
if (r) {
|
|
2251
2251
|
if (c.length !== 24)
|
|
2252
2252
|
throw new Error("arx: extended nonce must be 24 bytes");
|
|
2253
|
-
r(
|
|
2253
|
+
r(d, y, Z(c.subarray(0, 16)), y), c = c.subarray(16);
|
|
2254
2254
|
}
|
|
2255
2255
|
const E = 16 - i;
|
|
2256
2256
|
if (E !== c.length)
|
|
2257
2257
|
throw new Error(`arx: nonce must be ${E} or 16 bytes`);
|
|
2258
2258
|
if (E !== 12) {
|
|
2259
|
-
const
|
|
2260
|
-
|
|
2259
|
+
const _ = new Uint8Array(12);
|
|
2260
|
+
_.set(c, s ? 0 : 12 - c.length), c = _, b.push(c);
|
|
2261
2261
|
}
|
|
2262
|
-
const
|
|
2263
|
-
for (
|
|
2264
|
-
|
|
2262
|
+
const N = Z(c);
|
|
2263
|
+
for (Xs(e, d, y, N, l, f, u, o); b.length > 0; )
|
|
2264
|
+
b.pop().fill(0);
|
|
2265
2265
|
return f;
|
|
2266
2266
|
};
|
|
2267
2267
|
}
|
|
2268
|
-
function
|
|
2269
|
-
let o = e[0], a = e[1], c = e[2], l = e[3], f = t[0], u = t[1],
|
|
2270
|
-
for (let
|
|
2271
|
-
m = m + U | 0,
|
|
2272
|
-
let
|
|
2273
|
-
r[
|
|
2268
|
+
function eo(e, t, n, r, i, s = 20) {
|
|
2269
|
+
let o = e[0], a = e[1], c = e[2], l = e[3], f = t[0], u = t[1], g = t[2], b = t[3], p = t[4], h = t[5], d = t[6], y = t[7], E = i, N = n[0], _ = n[1], B = n[2], m = o, x = a, S = c, H = l, U = f, K = u, T = g, R = b, P = p, w = h, v = d, A = y, C = E, k = N, I = _, O = B;
|
|
2270
|
+
for (let Q = 0; Q < s; Q += 2)
|
|
2271
|
+
m = m + U | 0, C = L(C ^ m, 16), P = P + C | 0, U = L(U ^ P, 12), m = m + U | 0, C = L(C ^ m, 8), P = P + C | 0, U = L(U ^ P, 7), x = x + K | 0, k = L(k ^ x, 16), w = w + k | 0, K = L(K ^ w, 12), x = x + K | 0, k = L(k ^ x, 8), w = w + k | 0, K = L(K ^ w, 7), S = S + T | 0, I = L(I ^ S, 16), v = v + I | 0, T = L(T ^ v, 12), S = S + T | 0, I = L(I ^ S, 8), v = v + I | 0, T = L(T ^ v, 7), H = H + R | 0, O = L(O ^ H, 16), A = A + O | 0, R = L(R ^ A, 12), H = H + R | 0, O = L(O ^ H, 8), A = A + O | 0, R = L(R ^ A, 7), m = m + K | 0, O = L(O ^ m, 16), v = v + O | 0, K = L(K ^ v, 12), m = m + K | 0, O = L(O ^ m, 8), v = v + O | 0, K = L(K ^ v, 7), x = x + T | 0, C = L(C ^ x, 16), A = A + C | 0, T = L(T ^ A, 12), x = x + T | 0, C = L(C ^ x, 8), A = A + C | 0, T = L(T ^ A, 7), S = S + R | 0, k = L(k ^ S, 16), P = P + k | 0, R = L(R ^ P, 12), S = S + R | 0, k = L(k ^ S, 8), P = P + k | 0, R = L(R ^ P, 7), H = H + U | 0, I = L(I ^ H, 16), w = w + I | 0, U = L(U ^ w, 12), H = H + U | 0, I = L(I ^ H, 8), w = w + I | 0, U = L(U ^ w, 7);
|
|
2272
|
+
let $ = 0;
|
|
2273
|
+
r[$++] = o + m | 0, r[$++] = a + x | 0, r[$++] = c + S | 0, r[$++] = l + H | 0, r[$++] = f + U | 0, r[$++] = u + K | 0, r[$++] = g + T | 0, r[$++] = b + R | 0, r[$++] = p + P | 0, r[$++] = h + w | 0, r[$++] = d + v | 0, r[$++] = y + A | 0, r[$++] = E + C | 0, r[$++] = N + k | 0, r[$++] = _ + I | 0, r[$++] = B + O | 0;
|
|
2274
2274
|
}
|
|
2275
|
-
const
|
|
2275
|
+
const Nr = /* @__PURE__ */ Qs(eo, {
|
|
2276
2276
|
counterRight: !1,
|
|
2277
2277
|
counterLength: 4,
|
|
2278
2278
|
allowShortKeys: !1
|
|
2279
2279
|
});
|
|
2280
|
-
class
|
|
2280
|
+
class Kr extends ur {
|
|
2281
2281
|
constructor(t, n) {
|
|
2282
2282
|
super(), this.finished = !1, this.destroyed = !1, se.hash(t);
|
|
2283
|
-
const r =
|
|
2283
|
+
const r = Fe(n);
|
|
2284
2284
|
if (this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
2285
2285
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
2286
2286
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
@@ -2312,28 +2312,28 @@ class vr extends nr {
|
|
|
2312
2312
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
2313
2313
|
}
|
|
2314
2314
|
}
|
|
2315
|
-
const
|
|
2316
|
-
|
|
2315
|
+
const ht = (e, t, n) => new Kr(e, t).update(n).digest();
|
|
2316
|
+
ht.create = (e, t) => new Kr(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)), ht(e, Fe(n), Fe(t));
|
|
2319
2319
|
}
|
|
2320
|
-
const
|
|
2321
|
-
function
|
|
2320
|
+
const Ut = new Uint8Array([0]), qn = new Uint8Array();
|
|
2321
|
+
function kr(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 = qn);
|
|
2326
|
+
const s = new Uint8Array(i * e.outputLen), o = ht.create(e, t), a = o._cloneInto(), c = new Uint8Array(o.outputLen);
|
|
2327
2327
|
for (let l = 0; l < i; l++)
|
|
2328
|
-
|
|
2329
|
-
return o.destroy(), a.destroy(), c.fill(0),
|
|
2328
|
+
Ut[0] = l + 1, a.update(l === 0 ? qn : c).update(n).update(Ut).digestInto(c), s.set(c, e.outputLen * l), o._cloneInto(a);
|
|
2329
|
+
return o.destroy(), a.destroy(), c.fill(0), Ut.fill(0), s.slice(0, r);
|
|
2330
2330
|
}
|
|
2331
|
-
var
|
|
2331
|
+
var to = Object.defineProperty, q = (e, t) => {
|
|
2332
2332
|
for (var n in t)
|
|
2333
|
-
|
|
2334
|
-
},
|
|
2335
|
-
function
|
|
2336
|
-
if (!
|
|
2333
|
+
to(e, n, { get: t[n], enumerable: !0 });
|
|
2334
|
+
}, Re = Symbol("verified"), no = (e) => e instanceof Object;
|
|
2335
|
+
function sn(e) {
|
|
2336
|
+
if (!no(e) || typeof e.kind != "number" || typeof e.content != "string" || typeof e.created_at != "number" || typeof e.pubkey != "string" || !e.pubkey.match(/^[a-f0-9]{64}$/) || !Array.isArray(e.tags))
|
|
2337
2337
|
return !1;
|
|
2338
2338
|
for (let t = 0; t < e.tags.length; t++) {
|
|
2339
2339
|
let n = e.tags[t];
|
|
@@ -2345,32 +2345,32 @@ function Er(e) {
|
|
|
2345
2345
|
}
|
|
2346
2346
|
return !0;
|
|
2347
2347
|
}
|
|
2348
|
-
var
|
|
2349
|
-
|
|
2350
|
-
Queue: () =>
|
|
2351
|
-
QueueNode: () =>
|
|
2352
|
-
binarySearch: () =>
|
|
2353
|
-
insertEventIntoAscendingList: () =>
|
|
2354
|
-
insertEventIntoDescendingList: () =>
|
|
2355
|
-
normalizeURL: () =>
|
|
2356
|
-
utf8Decoder: () =>
|
|
2357
|
-
utf8Encoder: () =>
|
|
2348
|
+
var ro = {};
|
|
2349
|
+
q(ro, {
|
|
2350
|
+
Queue: () => ao,
|
|
2351
|
+
QueueNode: () => Br,
|
|
2352
|
+
binarySearch: () => on,
|
|
2353
|
+
insertEventIntoAscendingList: () => oo,
|
|
2354
|
+
insertEventIntoDescendingList: () => so,
|
|
2355
|
+
normalizeURL: () => io,
|
|
2356
|
+
utf8Decoder: () => ue,
|
|
2357
|
+
utf8Encoder: () => ne
|
|
2358
2358
|
});
|
|
2359
|
-
var
|
|
2360
|
-
function
|
|
2359
|
+
var ue = new TextDecoder("utf-8"), ne = new TextEncoder();
|
|
2360
|
+
function io(e) {
|
|
2361
2361
|
e.indexOf("://") === -1 && (e = "wss://" + e);
|
|
2362
2362
|
let t = new URL(e);
|
|
2363
2363
|
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();
|
|
2364
2364
|
}
|
|
2365
|
-
function
|
|
2366
|
-
const [n, r] =
|
|
2365
|
+
function so(e, t) {
|
|
2366
|
+
const [n, r] = on(e, (i) => t.id === i.id ? 0 : t.created_at === i.created_at ? -1 : i.created_at - t.created_at);
|
|
2367
2367
|
return r || e.splice(n, 0, t), e;
|
|
2368
2368
|
}
|
|
2369
|
-
function
|
|
2370
|
-
const [n, r] =
|
|
2369
|
+
function oo(e, t) {
|
|
2370
|
+
const [n, r] = on(e, (i) => t.id === i.id ? 0 : t.created_at === i.created_at ? -1 : t.created_at - i.created_at);
|
|
2371
2371
|
return r || e.splice(n, 0, t), e;
|
|
2372
2372
|
}
|
|
2373
|
-
function
|
|
2373
|
+
function on(e, t) {
|
|
2374
2374
|
let n = 0, r = e.length - 1;
|
|
2375
2375
|
for (; n <= r; ) {
|
|
2376
2376
|
const i = Math.floor((n + r) / 2), s = t(e[i]);
|
|
@@ -2380,21 +2380,21 @@ function sn(e, t) {
|
|
|
2380
2380
|
}
|
|
2381
2381
|
return [n, !1];
|
|
2382
2382
|
}
|
|
2383
|
-
var
|
|
2383
|
+
var Br = class {
|
|
2384
2384
|
constructor(e) {
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2385
|
+
te(this, "value");
|
|
2386
|
+
te(this, "next", null);
|
|
2387
|
+
te(this, "prev", null);
|
|
2388
2388
|
this.value = e;
|
|
2389
2389
|
}
|
|
2390
|
-
},
|
|
2390
|
+
}, ao = class {
|
|
2391
2391
|
constructor() {
|
|
2392
|
-
|
|
2393
|
-
|
|
2392
|
+
te(this, "first");
|
|
2393
|
+
te(this, "last");
|
|
2394
2394
|
this.first = null, this.last = null;
|
|
2395
2395
|
}
|
|
2396
2396
|
enqueue(e) {
|
|
2397
|
-
const t = new
|
|
2397
|
+
const t = new Br(e);
|
|
2398
2398
|
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
2399
|
}
|
|
2400
2400
|
dequeue() {
|
|
@@ -2407,155 +2407,163 @@ var xr = class {
|
|
|
2407
2407
|
const e = this.first;
|
|
2408
2408
|
return this.first = e.next, e.value;
|
|
2409
2409
|
}
|
|
2410
|
-
},
|
|
2410
|
+
}, co = class {
|
|
2411
2411
|
generateSecretKey() {
|
|
2412
|
-
return
|
|
2412
|
+
return We.utils.randomPrivateKey();
|
|
2413
2413
|
}
|
|
2414
2414
|
getPublicKey(e) {
|
|
2415
|
-
return M(
|
|
2415
|
+
return M(We.getPublicKey(e));
|
|
2416
2416
|
}
|
|
2417
2417
|
finalizeEvent(e, t) {
|
|
2418
2418
|
const n = e;
|
|
2419
|
-
return n.pubkey = M(
|
|
2419
|
+
return n.pubkey = M(We.getPublicKey(t)), n.id = Qe(n), n.sig = M(We.sign(Qe(n), t)), n[Re] = !0, n;
|
|
2420
2420
|
}
|
|
2421
2421
|
verifyEvent(e) {
|
|
2422
|
-
if (typeof e[
|
|
2423
|
-
return e[
|
|
2424
|
-
const t =
|
|
2422
|
+
if (typeof e[Re] == "boolean")
|
|
2423
|
+
return e[Re];
|
|
2424
|
+
const t = Qe(e);
|
|
2425
2425
|
if (t !== e.id)
|
|
2426
|
-
return e[
|
|
2426
|
+
return e[Re] = !1, !1;
|
|
2427
2427
|
try {
|
|
2428
|
-
const n =
|
|
2429
|
-
return e[
|
|
2428
|
+
const n = We.verify(e.sig, t, e.pubkey);
|
|
2429
|
+
return e[Re] = n, n;
|
|
2430
2430
|
} catch {
|
|
2431
|
-
return e[
|
|
2431
|
+
return e[Re] = !1, !1;
|
|
2432
2432
|
}
|
|
2433
2433
|
}
|
|
2434
2434
|
};
|
|
2435
|
-
function
|
|
2436
|
-
if (!
|
|
2435
|
+
function uo(e) {
|
|
2436
|
+
if (!sn(e))
|
|
2437
2437
|
throw new Error("can't serialize event with wrong or missing properties");
|
|
2438
2438
|
return JSON.stringify([0, e.pubkey, e.created_at, e.kind, e.tags, e.content]);
|
|
2439
2439
|
}
|
|
2440
|
-
function
|
|
2441
|
-
let t =
|
|
2440
|
+
function Qe(e) {
|
|
2441
|
+
let t = fe(ne.encode(uo(e)));
|
|
2442
2442
|
return M(t);
|
|
2443
2443
|
}
|
|
2444
|
-
var
|
|
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
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
EventDeletion: () =>
|
|
2475
|
-
FileMetadata: () =>
|
|
2476
|
-
FileServerPreference: () =>
|
|
2477
|
-
Followsets: () =>
|
|
2478
|
-
GenericRepost: () =>
|
|
2479
|
-
Genericlists: () =>
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2444
|
+
var dt = new co(), Ce = dt.generateSecretKey, le = dt.getPublicKey, X = dt.finalizeEvent, pt = dt.verifyEvent, lo = {};
|
|
2445
|
+
q(lo, {
|
|
2446
|
+
Application: () => da,
|
|
2447
|
+
BadgeAward: () => mo,
|
|
2448
|
+
BadgeDefinition: () => oa,
|
|
2449
|
+
BlockedRelaysList: () => zo,
|
|
2450
|
+
BookmarkList: () => qo,
|
|
2451
|
+
Bookmarksets: () => ra,
|
|
2452
|
+
Calendar: () => ma,
|
|
2453
|
+
CalendarEventRSVP: () => Ea,
|
|
2454
|
+
ChannelCreation: () => $r,
|
|
2455
|
+
ChannelHideMessage: () => Or,
|
|
2456
|
+
ChannelMessage: () => Rr,
|
|
2457
|
+
ChannelMetadata: () => Tr,
|
|
2458
|
+
ChannelMuteUser: () => Mr,
|
|
2459
|
+
ClassifiedListing: () => ga,
|
|
2460
|
+
ClientAuth: () => Pr,
|
|
2461
|
+
CommunitiesList: () => Do,
|
|
2462
|
+
CommunityDefinition: () => Aa,
|
|
2463
|
+
CommunityPostApproval: () => Uo,
|
|
2464
|
+
Contacts: () => wo,
|
|
2465
|
+
CreateOrUpdateProduct: () => ua,
|
|
2466
|
+
CreateOrUpdateStall: () => ca,
|
|
2467
|
+
Curationsets: () => ia,
|
|
2468
|
+
Date: () => ba,
|
|
2469
|
+
DirectMessageRelaysList: () => Go,
|
|
2470
|
+
DraftClassifiedListing: () => wa,
|
|
2471
|
+
DraftLong: () => fa,
|
|
2472
|
+
Emojisets: () => ha,
|
|
2473
|
+
EncryptedDirectMessage: () => bo,
|
|
2474
|
+
EventDeletion: () => vo,
|
|
2475
|
+
FileMetadata: () => Ao,
|
|
2476
|
+
FileServerPreference: () => Fo,
|
|
2477
|
+
Followsets: () => ea,
|
|
2478
|
+
GenericRepost: () => xo,
|
|
2479
|
+
Genericlists: () => ta,
|
|
2480
|
+
GiftWrap: () => Hr,
|
|
2481
|
+
HTTPAuth: () => un,
|
|
2482
|
+
Handlerinformation: () => Sa,
|
|
2483
|
+
Handlerrecommendation: () => xa,
|
|
2484
|
+
Highlights: () => Oo,
|
|
2485
|
+
InterestsList: () => Wo,
|
|
2486
|
+
Interestsets: () => aa,
|
|
2487
|
+
JobFeedback: () => Lo,
|
|
2488
|
+
JobRequest: () => _o,
|
|
2489
|
+
JobResult: () => Io,
|
|
2490
|
+
Label: () => Co,
|
|
2491
|
+
LightningPubRPC: () => Yo,
|
|
2492
|
+
LiveChatMessage: () => No,
|
|
2493
|
+
LiveEvent: () => pa,
|
|
2494
|
+
LongFormArticle: () => la,
|
|
2495
|
+
Metadata: () => po,
|
|
2496
|
+
Mutelist: () => Mo,
|
|
2497
|
+
NWCWalletInfo: () => Jo,
|
|
2498
|
+
NWCWalletRequest: () => qr,
|
|
2499
|
+
NWCWalletResponse: () => Xo,
|
|
2500
|
+
NostrConnect: () => Qo,
|
|
2501
|
+
OpenTimestamps: () => So,
|
|
2502
|
+
Pinlist: () => Ho,
|
|
2503
|
+
PrivateDirectMessage: () => Eo,
|
|
2504
|
+
ProblemTracker: () => Ko,
|
|
2505
|
+
ProfileBadges: () => sa,
|
|
2506
|
+
PublicChatsList: () => jo,
|
|
2507
|
+
Reaction: () => cn,
|
|
2508
|
+
RecommendRelay: () => go,
|
|
2509
|
+
RelayList: () => Po,
|
|
2510
|
+
Relaysets: () => na,
|
|
2511
|
+
Report: () => ko,
|
|
2512
|
+
Reporting: () => Bo,
|
|
2513
|
+
Repost: () => an,
|
|
2514
|
+
Seal: () => Lr,
|
|
2515
|
+
SearchRelaysList: () => Vo,
|
|
2516
|
+
ShortTextNote: () => yo,
|
|
2517
|
+
Time: () => va,
|
|
2518
|
+
UserEmojiList: () => Zo,
|
|
2519
|
+
UserStatuses: () => ya,
|
|
2520
|
+
Zap: () => Ro,
|
|
2521
|
+
ZapGoal: () => $o,
|
|
2522
|
+
ZapRequest: () => To,
|
|
2523
|
+
classifyKind: () => fo,
|
|
2524
|
+
isEphemeralKind: () => _r,
|
|
2525
|
+
isKind: () => ho,
|
|
2526
|
+
isParameterizedReplaceableKind: () => Ir,
|
|
2527
|
+
isRegularKind: () => Cr,
|
|
2528
|
+
isReplaceableKind: () => Ur
|
|
2525
2529
|
});
|
|
2526
|
-
function
|
|
2530
|
+
function Cr(e) {
|
|
2527
2531
|
return 1e3 <= e && e < 1e4 || [1, 2, 4, 5, 6, 7, 8, 16, 40, 41, 42, 43, 44].includes(e);
|
|
2528
2532
|
}
|
|
2529
|
-
function
|
|
2533
|
+
function Ur(e) {
|
|
2530
2534
|
return [0, 3].includes(e) || 1e4 <= e && e < 2e4;
|
|
2531
2535
|
}
|
|
2532
|
-
function
|
|
2536
|
+
function _r(e) {
|
|
2533
2537
|
return 2e4 <= e && e < 3e4;
|
|
2534
2538
|
}
|
|
2535
|
-
function
|
|
2539
|
+
function Ir(e) {
|
|
2536
2540
|
return 3e4 <= e && e < 4e4;
|
|
2537
2541
|
}
|
|
2538
|
-
function
|
|
2539
|
-
return
|
|
2542
|
+
function fo(e) {
|
|
2543
|
+
return Cr(e) ? "regular" : Ur(e) ? "replaceable" : _r(e) ? "ephemeral" : Ir(e) ? "parameterized" : "unknown";
|
|
2540
2544
|
}
|
|
2541
|
-
|
|
2542
|
-
|
|
2545
|
+
function ho(e, t) {
|
|
2546
|
+
const n = t instanceof Array ? t : [t];
|
|
2547
|
+
return sn(e) && n.includes(e.kind) || !1;
|
|
2548
|
+
}
|
|
2549
|
+
var po = 0, yo = 1, go = 2, wo = 3, bo = 4, vo = 5, an = 6, cn = 7, mo = 8, Lr = 13, Eo = 14, xo = 16, $r = 40, Tr = 41, Rr = 42, Or = 43, Mr = 44, So = 1040, Hr = 1059, Ao = 1063, No = 1311, Ko = 1971, ko = 1984, Bo = 1984, Co = 1985, Uo = 4550, _o = 5999, Io = 6999, Lo = 7e3, $o = 9041, To = 9734, Ro = 9735, Oo = 9802, Mo = 1e4, Ho = 10001, Po = 10002, qo = 10003, Do = 10004, jo = 10005, zo = 10006, Vo = 10007, Wo = 10015, Zo = 10030, Go = 10050, Fo = 10096, Jo = 13194, Yo = 21e3, Pr = 22242, qr = 23194, Xo = 23195, Qo = 24133, un = 27235, ea = 3e4, ta = 30001, na = 30002, ra = 30003, ia = 30004, sa = 30008, oa = 30009, aa = 30015, ca = 30017, ua = 30018, la = 30023, fa = 30024, ha = 30030, da = 30078, pa = 30311, ya = 30315, ga = 30402, wa = 30403, ba = 31922, va = 31923, ma = 31924, Ea = 31925, xa = 31989, Sa = 31990, Aa = 34550, Na = {};
|
|
2550
|
+
q(Na, {
|
|
2543
2551
|
getHex64: () => ln,
|
|
2544
|
-
getInt: () =>
|
|
2545
|
-
getSubscriptionId: () =>
|
|
2546
|
-
matchEventId: () =>
|
|
2547
|
-
matchEventKind: () =>
|
|
2548
|
-
matchEventPubkey: () =>
|
|
2552
|
+
getInt: () => Dr,
|
|
2553
|
+
getSubscriptionId: () => Ka,
|
|
2554
|
+
matchEventId: () => ka,
|
|
2555
|
+
matchEventKind: () => Ca,
|
|
2556
|
+
matchEventPubkey: () => Ba
|
|
2549
2557
|
});
|
|
2550
2558
|
function ln(e, t) {
|
|
2551
2559
|
let n = t.length + 3, r = e.indexOf(`"${t}":`) + n, i = e.slice(r).indexOf('"') + r + 1;
|
|
2552
2560
|
return e.slice(i, i + 64);
|
|
2553
2561
|
}
|
|
2554
|
-
function
|
|
2562
|
+
function Dr(e, t) {
|
|
2555
2563
|
let n = t.length, r = e.indexOf(`"${t}":`) + n + 3, i = e.slice(r), s = Math.min(i.indexOf(","), i.indexOf("}"));
|
|
2556
2564
|
return parseInt(i.slice(0, s), 10);
|
|
2557
2565
|
}
|
|
2558
|
-
function
|
|
2566
|
+
function Ka(e) {
|
|
2559
2567
|
let t = e.slice(0, 22).indexOf('"EVENT"');
|
|
2560
2568
|
if (t === -1)
|
|
2561
2569
|
return null;
|
|
@@ -2568,22 +2576,22 @@ function fa(e) {
|
|
|
2568
2576
|
let s = r + 1 + i;
|
|
2569
2577
|
return e.slice(r + 1, s);
|
|
2570
2578
|
}
|
|
2571
|
-
function
|
|
2579
|
+
function ka(e, t) {
|
|
2572
2580
|
return t === ln(e, "id");
|
|
2573
2581
|
}
|
|
2574
|
-
function
|
|
2582
|
+
function Ba(e, t) {
|
|
2575
2583
|
return t === ln(e, "pubkey");
|
|
2576
2584
|
}
|
|
2577
|
-
function
|
|
2578
|
-
return t ===
|
|
2585
|
+
function Ca(e, t) {
|
|
2586
|
+
return t === Dr(e, "kind");
|
|
2579
2587
|
}
|
|
2580
|
-
var
|
|
2581
|
-
|
|
2582
|
-
makeAuthEvent: () =>
|
|
2588
|
+
var Ua = {};
|
|
2589
|
+
q(Ua, {
|
|
2590
|
+
makeAuthEvent: () => _a
|
|
2583
2591
|
});
|
|
2584
|
-
function
|
|
2592
|
+
function _a(e, t) {
|
|
2585
2593
|
return {
|
|
2586
|
-
kind:
|
|
2594
|
+
kind: Pr,
|
|
2587
2595
|
created_at: Math.floor(Date.now() / 1e3),
|
|
2588
2596
|
tags: [
|
|
2589
2597
|
["relay", e],
|
|
@@ -2592,104 +2600,103 @@ function ga(e, t) {
|
|
|
2592
2600
|
content: ""
|
|
2593
2601
|
};
|
|
2594
2602
|
}
|
|
2595
|
-
var
|
|
2603
|
+
var Ia;
|
|
2596
2604
|
try {
|
|
2597
|
-
|
|
2605
|
+
Ia = WebSocket;
|
|
2598
2606
|
} catch {
|
|
2599
2607
|
}
|
|
2600
|
-
var
|
|
2608
|
+
var La;
|
|
2601
2609
|
try {
|
|
2602
|
-
|
|
2610
|
+
La = WebSocket;
|
|
2603
2611
|
} catch {
|
|
2604
2612
|
}
|
|
2605
|
-
var
|
|
2606
|
-
|
|
2607
|
-
BECH32_REGEX: () =>
|
|
2608
|
-
Bech32MaxSize: () =>
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
nsecEncode: () =>
|
|
2613
|
+
var $a = {};
|
|
2614
|
+
q($a, {
|
|
2615
|
+
BECH32_REGEX: () => jr,
|
|
2616
|
+
Bech32MaxSize: () => fn,
|
|
2617
|
+
NostrTypeGuard: () => Ta,
|
|
2618
|
+
decode: () => yt,
|
|
2619
|
+
encodeBytes: () => wt,
|
|
2620
|
+
naddrEncode: () => Da,
|
|
2621
|
+
neventEncode: () => qa,
|
|
2622
|
+
noteEncode: () => Ha,
|
|
2623
|
+
nprofileEncode: () => Pa,
|
|
2624
|
+
npubEncode: () => Ma,
|
|
2625
|
+
nsecEncode: () => Oa
|
|
2618
2626
|
});
|
|
2619
|
-
var
|
|
2620
|
-
|
|
2627
|
+
var Ta = {
|
|
2628
|
+
isNProfile: (e) => /^nprofile1[a-z\d]+$/.test(e || ""),
|
|
2629
|
+
isNEvent: (e) => /^nevent1[a-z\d]+$/.test(e || ""),
|
|
2630
|
+
isNAddr: (e) => /^naddr1[a-z\d]+$/.test(e || ""),
|
|
2631
|
+
isNSec: (e) => /^nsec1[a-z\d]{58}$/.test(e || ""),
|
|
2632
|
+
isNPub: (e) => /^npub1[a-z\d]{58}$/.test(e || ""),
|
|
2633
|
+
isNote: (e) => /^note1[a-z\d]+$/.test(e || ""),
|
|
2634
|
+
isNcryptsec: (e) => /^ncryptsec1[a-z\d]+$/.test(e || "")
|
|
2635
|
+
}, fn = 5e3, jr = /[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;
|
|
2636
|
+
function Ra(e) {
|
|
2621
2637
|
const t = new Uint8Array(4);
|
|
2622
2638
|
return t[0] = e >> 24 & 255, t[1] = e >> 16 & 255, t[2] = e >> 8 & 255, t[3] = e & 255, t;
|
|
2623
2639
|
}
|
|
2624
|
-
function
|
|
2625
|
-
var i, s, o, a, c, l, f
|
|
2626
|
-
let { prefix: t, words: n } = je.decode(e,
|
|
2640
|
+
function yt(e) {
|
|
2641
|
+
var i, s, o, a, c, l, f;
|
|
2642
|
+
let { prefix: t, words: n } = je.decode(e, fn), r = new Uint8Array(je.fromWords(n));
|
|
2627
2643
|
switch (t) {
|
|
2628
2644
|
case "nprofile": {
|
|
2629
|
-
let
|
|
2630
|
-
if (!((i =
|
|
2645
|
+
let u = _t(r);
|
|
2646
|
+
if (!((i = u[0]) != null && i[0]))
|
|
2631
2647
|
throw new Error("missing TLV 0 for nprofile");
|
|
2632
|
-
if (
|
|
2648
|
+
if (u[0][0].length !== 32)
|
|
2633
2649
|
throw new Error("TLV 0 should be 32 bytes");
|
|
2634
2650
|
return {
|
|
2635
2651
|
type: "nprofile",
|
|
2636
2652
|
data: {
|
|
2637
|
-
pubkey: M(
|
|
2638
|
-
relays:
|
|
2653
|
+
pubkey: M(u[0][0]),
|
|
2654
|
+
relays: u[1] ? u[1].map((g) => ue.decode(g)) : []
|
|
2639
2655
|
}
|
|
2640
2656
|
};
|
|
2641
2657
|
}
|
|
2642
2658
|
case "nevent": {
|
|
2643
|
-
let
|
|
2644
|
-
if (!((s =
|
|
2659
|
+
let u = _t(r);
|
|
2660
|
+
if (!((s = u[0]) != null && s[0]))
|
|
2645
2661
|
throw new Error("missing TLV 0 for nevent");
|
|
2646
|
-
if (
|
|
2662
|
+
if (u[0][0].length !== 32)
|
|
2647
2663
|
throw new Error("TLV 0 should be 32 bytes");
|
|
2648
|
-
if (
|
|
2664
|
+
if (u[2] && u[2][0].length !== 32)
|
|
2649
2665
|
throw new Error("TLV 2 should be 32 bytes");
|
|
2650
|
-
if (
|
|
2666
|
+
if (u[3] && u[3][0].length !== 4)
|
|
2651
2667
|
throw new Error("TLV 3 should be 4 bytes");
|
|
2652
2668
|
return {
|
|
2653
2669
|
type: "nevent",
|
|
2654
2670
|
data: {
|
|
2655
|
-
id: M(
|
|
2656
|
-
relays:
|
|
2657
|
-
author: (o =
|
|
2658
|
-
kind: (a =
|
|
2671
|
+
id: M(u[0][0]),
|
|
2672
|
+
relays: u[1] ? u[1].map((g) => ue.decode(g)) : [],
|
|
2673
|
+
author: (o = u[2]) != null && o[0] ? M(u[2][0]) : void 0,
|
|
2674
|
+
kind: (a = u[3]) != null && a[0] ? parseInt(M(u[3][0]), 16) : void 0
|
|
2659
2675
|
}
|
|
2660
2676
|
};
|
|
2661
2677
|
}
|
|
2662
2678
|
case "naddr": {
|
|
2663
|
-
let
|
|
2664
|
-
if (!((c =
|
|
2679
|
+
let u = _t(r);
|
|
2680
|
+
if (!((c = u[0]) != null && c[0]))
|
|
2665
2681
|
throw new Error("missing TLV 0 for naddr");
|
|
2666
|
-
if (!((l =
|
|
2682
|
+
if (!((l = u[2]) != null && l[0]))
|
|
2667
2683
|
throw new Error("missing TLV 2 for naddr");
|
|
2668
|
-
if (
|
|
2684
|
+
if (u[2][0].length !== 32)
|
|
2669
2685
|
throw new Error("TLV 2 should be 32 bytes");
|
|
2670
|
-
if (!((f =
|
|
2686
|
+
if (!((f = u[3]) != null && f[0]))
|
|
2671
2687
|
throw new Error("missing TLV 3 for naddr");
|
|
2672
|
-
if (
|
|
2688
|
+
if (u[3][0].length !== 4)
|
|
2673
2689
|
throw new Error("TLV 3 should be 4 bytes");
|
|
2674
2690
|
return {
|
|
2675
2691
|
type: "naddr",
|
|
2676
2692
|
data: {
|
|
2677
|
-
identifier:
|
|
2678
|
-
pubkey: M(
|
|
2679
|
-
kind: parseInt(M(
|
|
2680
|
-
relays:
|
|
2693
|
+
identifier: ue.decode(u[0][0]),
|
|
2694
|
+
pubkey: M(u[2][0]),
|
|
2695
|
+
kind: parseInt(M(u[3][0]), 16),
|
|
2696
|
+
relays: u[1] ? u[1].map((g) => ue.decode(g)) : []
|
|
2681
2697
|
}
|
|
2682
2698
|
};
|
|
2683
2699
|
}
|
|
2684
|
-
case "nrelay": {
|
|
2685
|
-
let d = Qe(r);
|
|
2686
|
-
if (!((u = d[0]) != null && u[0]))
|
|
2687
|
-
throw new Error("missing TLV 0 for nrelay");
|
|
2688
|
-
return {
|
|
2689
|
-
type: "nrelay",
|
|
2690
|
-
data: ie.decode(d[0][0])
|
|
2691
|
-
};
|
|
2692
|
-
}
|
|
2693
2700
|
case "nsec":
|
|
2694
2701
|
return { type: t, data: r };
|
|
2695
2702
|
case "npub":
|
|
@@ -2699,7 +2706,7 @@ function wt(e) {
|
|
|
2699
2706
|
throw new Error(`unknown prefix ${t}`);
|
|
2700
2707
|
}
|
|
2701
2708
|
}
|
|
2702
|
-
function
|
|
2709
|
+
function _t(e) {
|
|
2703
2710
|
let t = {}, n = e;
|
|
2704
2711
|
for (; n.length > 0; ) {
|
|
2705
2712
|
let r = n[0], i = n[1], s = n.slice(2, 2 + i);
|
|
@@ -2709,227 +2716,258 @@ function Qe(e) {
|
|
|
2709
2716
|
}
|
|
2710
2717
|
return t;
|
|
2711
2718
|
}
|
|
2712
|
-
function
|
|
2713
|
-
return
|
|
2719
|
+
function Oa(e) {
|
|
2720
|
+
return wt("nsec", e);
|
|
2714
2721
|
}
|
|
2715
|
-
function
|
|
2716
|
-
return
|
|
2722
|
+
function Ma(e) {
|
|
2723
|
+
return wt("npub", G(e));
|
|
2717
2724
|
}
|
|
2718
|
-
function
|
|
2719
|
-
return
|
|
2725
|
+
function Ha(e) {
|
|
2726
|
+
return wt("note", G(e));
|
|
2720
2727
|
}
|
|
2721
|
-
function
|
|
2728
|
+
function gt(e, t) {
|
|
2722
2729
|
let n = je.toWords(t);
|
|
2723
|
-
return je.encode(e, n,
|
|
2730
|
+
return je.encode(e, n, fn);
|
|
2724
2731
|
}
|
|
2725
|
-
function
|
|
2726
|
-
return
|
|
2732
|
+
function wt(e, t) {
|
|
2733
|
+
return gt(e, t);
|
|
2727
2734
|
}
|
|
2728
|
-
function
|
|
2729
|
-
let t =
|
|
2730
|
-
0: [
|
|
2731
|
-
1: (e.relays || []).map((n) =>
|
|
2735
|
+
function Pa(e) {
|
|
2736
|
+
let t = hn({
|
|
2737
|
+
0: [G(e.pubkey)],
|
|
2738
|
+
1: (e.relays || []).map((n) => ne.encode(n))
|
|
2732
2739
|
});
|
|
2733
|
-
return
|
|
2740
|
+
return gt("nprofile", t);
|
|
2734
2741
|
}
|
|
2735
|
-
function
|
|
2742
|
+
function qa(e) {
|
|
2736
2743
|
let t;
|
|
2737
|
-
e.kind !== void 0 && (t =
|
|
2738
|
-
let n =
|
|
2739
|
-
0: [
|
|
2740
|
-
1: (e.relays || []).map((r) =>
|
|
2741
|
-
2: e.author ? [
|
|
2744
|
+
e.kind !== void 0 && (t = Ra(e.kind));
|
|
2745
|
+
let n = hn({
|
|
2746
|
+
0: [G(e.id)],
|
|
2747
|
+
1: (e.relays || []).map((r) => ne.encode(r)),
|
|
2748
|
+
2: e.author ? [G(e.author)] : [],
|
|
2742
2749
|
3: t ? [new Uint8Array(t)] : []
|
|
2743
2750
|
});
|
|
2744
|
-
return
|
|
2751
|
+
return gt("nevent", n);
|
|
2745
2752
|
}
|
|
2746
|
-
function
|
|
2753
|
+
function Da(e) {
|
|
2747
2754
|
let t = new ArrayBuffer(4);
|
|
2748
2755
|
new DataView(t).setUint32(0, e.kind, !1);
|
|
2749
|
-
let n =
|
|
2750
|
-
0: [
|
|
2751
|
-
1: (e.relays || []).map((r) =>
|
|
2752
|
-
2: [
|
|
2756
|
+
let n = hn({
|
|
2757
|
+
0: [ne.encode(e.identifier)],
|
|
2758
|
+
1: (e.relays || []).map((r) => ne.encode(r)),
|
|
2759
|
+
2: [G(e.pubkey)],
|
|
2753
2760
|
3: [new Uint8Array(t)]
|
|
2754
2761
|
});
|
|
2755
|
-
return
|
|
2762
|
+
return gt("naddr", n);
|
|
2756
2763
|
}
|
|
2757
|
-
function
|
|
2758
|
-
let t = vt({
|
|
2759
|
-
0: [te.encode(e)]
|
|
2760
|
-
});
|
|
2761
|
-
return Ye("nrelay", t);
|
|
2762
|
-
}
|
|
2763
|
-
function vt(e) {
|
|
2764
|
+
function hn(e) {
|
|
2764
2765
|
let t = [];
|
|
2765
2766
|
return Object.entries(e).reverse().forEach(([n, r]) => {
|
|
2766
2767
|
r.forEach((i) => {
|
|
2767
2768
|
let s = new Uint8Array(i.length + 2);
|
|
2768
2769
|
s.set([parseInt(n)], 0), s.set([i.length], 1), s.set(i, 2), t.push(s);
|
|
2769
2770
|
});
|
|
2770
|
-
}),
|
|
2771
|
+
}), lt(...t);
|
|
2771
2772
|
}
|
|
2772
|
-
var
|
|
2773
|
-
|
|
2774
|
-
decrypt: () =>
|
|
2775
|
-
encrypt: () =>
|
|
2773
|
+
var ja = {};
|
|
2774
|
+
q(ja, {
|
|
2775
|
+
decrypt: () => za,
|
|
2776
|
+
encrypt: () => zr
|
|
2776
2777
|
});
|
|
2777
|
-
async function
|
|
2778
|
-
const r = e instanceof Uint8Array ? M(e) : e, i =
|
|
2779
|
-
let o = Uint8Array.from(
|
|
2778
|
+
async function zr(e, t, n) {
|
|
2779
|
+
const r = e instanceof Uint8Array ? M(e) : e, i = _e.getSharedSecret(r, "02" + t), s = Vr(i);
|
|
2780
|
+
let o = Uint8Array.from(fr(16)), a = ne.encode(n), c = Er(s, o).encrypt(a), l = he.encode(new Uint8Array(c)), f = he.encode(new Uint8Array(o.buffer));
|
|
2780
2781
|
return `${l}?iv=${f}`;
|
|
2781
2782
|
}
|
|
2782
|
-
async function
|
|
2783
|
+
async function za(e, t, n) {
|
|
2783
2784
|
const r = e instanceof Uint8Array ? M(e) : e;
|
|
2784
|
-
let [i, s] = n.split("?iv="), o =
|
|
2785
|
-
return
|
|
2785
|
+
let [i, s] = n.split("?iv="), o = _e.getSharedSecret(r, "02" + t), a = Vr(o), c = he.decode(s), l = he.decode(i), f = Er(a, c).decrypt(l);
|
|
2786
|
+
return ue.decode(f);
|
|
2786
2787
|
}
|
|
2787
|
-
function
|
|
2788
|
+
function Vr(e) {
|
|
2788
2789
|
return e.slice(1, 33);
|
|
2789
2790
|
}
|
|
2790
|
-
var
|
|
2791
|
-
|
|
2792
|
-
NIP05_REGEX: () =>
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2791
|
+
var Va = {};
|
|
2792
|
+
q(Va, {
|
|
2793
|
+
NIP05_REGEX: () => dn,
|
|
2794
|
+
isNip05: () => Wa,
|
|
2795
|
+
isValid: () => Fa,
|
|
2796
|
+
queryProfile: () => Wr,
|
|
2797
|
+
searchDomain: () => Ga,
|
|
2798
|
+
useFetchImplementation: () => Za
|
|
2797
2799
|
});
|
|
2798
|
-
var
|
|
2800
|
+
var dn = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/, Wa = (e) => dn.test(e || ""), bt;
|
|
2799
2801
|
try {
|
|
2800
|
-
|
|
2802
|
+
bt = fetch;
|
|
2801
2803
|
} catch {
|
|
2802
2804
|
}
|
|
2803
|
-
function
|
|
2804
|
-
|
|
2805
|
+
function Za(e) {
|
|
2806
|
+
bt = e;
|
|
2805
2807
|
}
|
|
2806
|
-
async function
|
|
2808
|
+
async function Ga(e, t = "") {
|
|
2807
2809
|
try {
|
|
2808
|
-
const n = `https://${e}/.well-known/nostr.json?name=${t}
|
|
2809
|
-
|
|
2810
|
+
const n = `https://${e}/.well-known/nostr.json?name=${t}`, r = await bt(n, { redirect: "manual" });
|
|
2811
|
+
if (r.status !== 200)
|
|
2812
|
+
throw Error("Wrong response code");
|
|
2813
|
+
return (await r.json()).names;
|
|
2810
2814
|
} catch {
|
|
2811
2815
|
return {};
|
|
2812
2816
|
}
|
|
2813
2817
|
}
|
|
2814
|
-
async function
|
|
2815
|
-
var
|
|
2816
|
-
const t = e.match(
|
|
2818
|
+
async function Wr(e) {
|
|
2819
|
+
var i;
|
|
2820
|
+
const t = e.match(dn);
|
|
2817
2821
|
if (!t)
|
|
2818
2822
|
return null;
|
|
2819
|
-
const [
|
|
2823
|
+
const [, n = "_", r] = t;
|
|
2820
2824
|
try {
|
|
2821
|
-
const
|
|
2822
|
-
|
|
2823
|
-
|
|
2825
|
+
const s = `https://${r}/.well-known/nostr.json?name=${n}`, o = await bt(s, { redirect: "manual" });
|
|
2826
|
+
if (o.status !== 200)
|
|
2827
|
+
throw Error("Wrong response code");
|
|
2828
|
+
const a = await o.json(), c = a.names[n];
|
|
2829
|
+
return c ? { pubkey: c, relays: (i = a.relays) == null ? void 0 : i[c] } : null;
|
|
2824
2830
|
} catch {
|
|
2825
2831
|
return null;
|
|
2826
2832
|
}
|
|
2827
2833
|
}
|
|
2828
|
-
async function
|
|
2829
|
-
|
|
2834
|
+
async function Fa(e, t) {
|
|
2835
|
+
const n = await Wr(t);
|
|
2830
2836
|
return n ? n.pubkey === e : !1;
|
|
2831
2837
|
}
|
|
2832
|
-
var
|
|
2833
|
-
|
|
2834
|
-
parse: () =>
|
|
2838
|
+
var Ja = {};
|
|
2839
|
+
q(Ja, {
|
|
2840
|
+
parse: () => Ya
|
|
2835
2841
|
});
|
|
2836
|
-
function
|
|
2842
|
+
function Ya(e) {
|
|
2837
2843
|
const t = {
|
|
2838
2844
|
reply: void 0,
|
|
2839
2845
|
root: void 0,
|
|
2840
2846
|
mentions: [],
|
|
2841
|
-
profiles: []
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2847
|
+
profiles: [],
|
|
2848
|
+
quotes: []
|
|
2849
|
+
};
|
|
2850
|
+
let n, r;
|
|
2851
|
+
for (let i = e.tags.length - 1; i >= 0; i--) {
|
|
2852
|
+
const s = e.tags[i];
|
|
2853
|
+
if (s[0] === "e" && s[1]) {
|
|
2854
|
+
const [o, a, c, l, f] = s, u = {
|
|
2855
|
+
id: a,
|
|
2856
|
+
relays: c ? [c] : [],
|
|
2857
|
+
author: f
|
|
2858
|
+
};
|
|
2859
|
+
if (l === "root") {
|
|
2860
|
+
t.root = u;
|
|
2861
|
+
continue;
|
|
2862
|
+
}
|
|
2863
|
+
if (l === "reply") {
|
|
2864
|
+
t.reply = u;
|
|
2865
|
+
continue;
|
|
2866
|
+
}
|
|
2867
|
+
if (l === "mention") {
|
|
2868
|
+
t.mentions.push(u);
|
|
2869
|
+
continue;
|
|
2870
|
+
}
|
|
2871
|
+
n ? r = u : n = u, t.mentions.push(u);
|
|
2863
2872
|
continue;
|
|
2864
2873
|
}
|
|
2865
|
-
if (
|
|
2866
|
-
|
|
2867
|
-
|
|
2874
|
+
if (s[0] === "q" && s[1]) {
|
|
2875
|
+
const [o, a, c] = s;
|
|
2876
|
+
t.quotes.push({
|
|
2877
|
+
id: a,
|
|
2878
|
+
relays: c ? [c] : []
|
|
2879
|
+
});
|
|
2868
2880
|
}
|
|
2869
|
-
if (
|
|
2870
|
-
t.
|
|
2881
|
+
if (s[0] === "p" && s[1]) {
|
|
2882
|
+
t.profiles.push({
|
|
2883
|
+
pubkey: s[1],
|
|
2884
|
+
relays: s[2] ? [s[2]] : []
|
|
2885
|
+
});
|
|
2871
2886
|
continue;
|
|
2872
2887
|
}
|
|
2873
|
-
t.mentions.push(l);
|
|
2874
2888
|
}
|
|
2875
|
-
return t
|
|
2889
|
+
return t.root || (t.root = r || n || t.reply), t.reply || (t.reply = n || t.root), [t.reply, t.root].forEach((i) => {
|
|
2890
|
+
if (!i)
|
|
2891
|
+
return;
|
|
2892
|
+
let s = t.mentions.indexOf(i);
|
|
2893
|
+
if (s !== -1 && t.mentions.splice(s, 1), i.author) {
|
|
2894
|
+
let o = t.profiles.find((a) => a.pubkey === i.author);
|
|
2895
|
+
o && o.relays && (i.relays || (i.relays = []), o.relays.forEach((a) => {
|
|
2896
|
+
var c;
|
|
2897
|
+
((c = i.relays) == null ? void 0 : c.indexOf(a)) === -1 && i.relays.push(a);
|
|
2898
|
+
}), o.relays = i.relays);
|
|
2899
|
+
}
|
|
2900
|
+
}), t.mentions.forEach((i) => {
|
|
2901
|
+
if (i.author) {
|
|
2902
|
+
let s = t.profiles.find((o) => o.pubkey === i.author);
|
|
2903
|
+
s && s.relays && (i.relays || (i.relays = []), s.relays.forEach((o) => {
|
|
2904
|
+
i.relays.indexOf(o) === -1 && i.relays.push(o);
|
|
2905
|
+
}), s.relays = i.relays);
|
|
2906
|
+
}
|
|
2907
|
+
}), t;
|
|
2876
2908
|
}
|
|
2877
|
-
var
|
|
2878
|
-
|
|
2879
|
-
fetchRelayInformation: () =>
|
|
2880
|
-
useFetchImplementation: () =>
|
|
2909
|
+
var Xa = {};
|
|
2910
|
+
q(Xa, {
|
|
2911
|
+
fetchRelayInformation: () => ec,
|
|
2912
|
+
useFetchImplementation: () => Qa
|
|
2881
2913
|
});
|
|
2882
|
-
var
|
|
2914
|
+
var Zr;
|
|
2883
2915
|
try {
|
|
2884
|
-
|
|
2916
|
+
Zr = fetch;
|
|
2885
2917
|
} catch {
|
|
2886
2918
|
}
|
|
2887
|
-
function
|
|
2888
|
-
|
|
2919
|
+
function Qa(e) {
|
|
2920
|
+
Zr = e;
|
|
2889
2921
|
}
|
|
2890
|
-
async function
|
|
2922
|
+
async function ec(e) {
|
|
2891
2923
|
return await (await fetch(e.replace("ws://", "http://").replace("wss://", "https://"), {
|
|
2892
2924
|
headers: { Accept: "application/nostr+json" }
|
|
2893
2925
|
})).json();
|
|
2894
2926
|
}
|
|
2895
|
-
var
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2927
|
+
var tc = {};
|
|
2928
|
+
q(tc, {
|
|
2929
|
+
fastEventHash: () => Fr,
|
|
2930
|
+
getPow: () => Gr,
|
|
2931
|
+
minePow: () => nc
|
|
2899
2932
|
});
|
|
2900
|
-
function
|
|
2933
|
+
function Gr(e) {
|
|
2901
2934
|
let t = 0;
|
|
2902
|
-
for (let n = 0; n <
|
|
2903
|
-
const r = parseInt(e
|
|
2935
|
+
for (let n = 0; n < 64; n += 8) {
|
|
2936
|
+
const r = parseInt(e.substring(n, n + 8), 16);
|
|
2904
2937
|
if (r === 0)
|
|
2905
|
-
t +=
|
|
2938
|
+
t += 32;
|
|
2906
2939
|
else {
|
|
2907
|
-
t += Math.clz32(r)
|
|
2940
|
+
t += Math.clz32(r);
|
|
2908
2941
|
break;
|
|
2909
2942
|
}
|
|
2910
2943
|
}
|
|
2911
2944
|
return t;
|
|
2912
2945
|
}
|
|
2913
|
-
function
|
|
2946
|
+
function nc(e, t) {
|
|
2914
2947
|
let n = 0;
|
|
2915
2948
|
const r = e, i = ["nonce", n.toString(), t.toString()];
|
|
2916
2949
|
for (r.tags.push(i); ; ) {
|
|
2917
2950
|
const s = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
2918
|
-
if (s !== r.created_at && (n = 0, r.created_at = s), i[1] = (++n).toString(), r.id =
|
|
2951
|
+
if (s !== r.created_at && (n = 0, r.created_at = s), i[1] = (++n).toString(), r.id = Fr(r), Gr(r.id) >= t)
|
|
2919
2952
|
break;
|
|
2920
2953
|
}
|
|
2921
2954
|
return r;
|
|
2922
2955
|
}
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2956
|
+
function Fr(e) {
|
|
2957
|
+
return M(
|
|
2958
|
+
fe(ne.encode(JSON.stringify([0, e.pubkey, e.created_at, e.kind, e.tags, e.content])))
|
|
2959
|
+
);
|
|
2960
|
+
}
|
|
2961
|
+
var rc = {};
|
|
2962
|
+
q(rc, {
|
|
2963
|
+
finishRepostEvent: () => ic,
|
|
2964
|
+
getRepostedEvent: () => sc,
|
|
2965
|
+
getRepostedEventPointer: () => Jr
|
|
2928
2966
|
});
|
|
2929
|
-
function
|
|
2930
|
-
return
|
|
2967
|
+
function ic(e, t, n, r) {
|
|
2968
|
+
return X(
|
|
2931
2969
|
{
|
|
2932
|
-
kind:
|
|
2970
|
+
kind: an,
|
|
2933
2971
|
tags: [...e.tags ?? [], ["e", t.id, n], ["p", t.pubkey]],
|
|
2934
2972
|
content: e.content === "" ? "" : JSON.stringify(t),
|
|
2935
2973
|
created_at: e.created_at
|
|
@@ -2937,8 +2975,8 @@ function Da(e, t, n, r) {
|
|
|
2937
2975
|
r
|
|
2938
2976
|
);
|
|
2939
2977
|
}
|
|
2940
|
-
function
|
|
2941
|
-
if (e.kind !==
|
|
2978
|
+
function Jr(e) {
|
|
2979
|
+
if (e.kind !== an)
|
|
2942
2980
|
return;
|
|
2943
2981
|
let t, n;
|
|
2944
2982
|
for (let r = e.tags.length - 1; r >= 0 && (t === void 0 || n === void 0); r--) {
|
|
@@ -2952,8 +2990,8 @@ function Dr(e) {
|
|
|
2952
2990
|
author: n == null ? void 0 : n[1]
|
|
2953
2991
|
};
|
|
2954
2992
|
}
|
|
2955
|
-
function
|
|
2956
|
-
const n =
|
|
2993
|
+
function sc(e, { skipVerification: t } = {}) {
|
|
2994
|
+
const n = Jr(e);
|
|
2957
2995
|
if (n === void 0 || e.content === "")
|
|
2958
2996
|
return;
|
|
2959
2997
|
let r;
|
|
@@ -2962,48 +3000,48 @@ function ja(e, { skipVerification: t } = {}) {
|
|
|
2962
3000
|
} catch {
|
|
2963
3001
|
return;
|
|
2964
3002
|
}
|
|
2965
|
-
if (r.id === n.id && !(!t && !
|
|
3003
|
+
if (r.id === n.id && !(!t && !pt(r)))
|
|
2966
3004
|
return r;
|
|
2967
3005
|
}
|
|
2968
|
-
var
|
|
2969
|
-
|
|
2970
|
-
NOSTR_URI_REGEX: () =>
|
|
2971
|
-
parse: () =>
|
|
2972
|
-
test: () =>
|
|
3006
|
+
var oc = {};
|
|
3007
|
+
q(oc, {
|
|
3008
|
+
NOSTR_URI_REGEX: () => vt,
|
|
3009
|
+
parse: () => cc,
|
|
3010
|
+
test: () => ac
|
|
2973
3011
|
});
|
|
2974
|
-
var
|
|
2975
|
-
function
|
|
2976
|
-
return typeof e == "string" && new RegExp(`^${
|
|
3012
|
+
var vt = new RegExp(`nostr:(${jr.source})`);
|
|
3013
|
+
function ac(e) {
|
|
3014
|
+
return typeof e == "string" && new RegExp(`^${vt.source}$`).test(e);
|
|
2977
3015
|
}
|
|
2978
|
-
function
|
|
2979
|
-
const t = e.match(new RegExp(`^${
|
|
3016
|
+
function cc(e) {
|
|
3017
|
+
const t = e.match(new RegExp(`^${vt.source}$`));
|
|
2980
3018
|
if (!t)
|
|
2981
3019
|
throw new Error(`Invalid Nostr URI: ${e}`);
|
|
2982
3020
|
return {
|
|
2983
3021
|
uri: t[0],
|
|
2984
3022
|
value: t[1],
|
|
2985
|
-
decoded:
|
|
3023
|
+
decoded: yt(t[1])
|
|
2986
3024
|
};
|
|
2987
3025
|
}
|
|
2988
|
-
var
|
|
2989
|
-
|
|
2990
|
-
finishReactionEvent: () =>
|
|
2991
|
-
getReactedEventPointer: () =>
|
|
3026
|
+
var uc = {};
|
|
3027
|
+
q(uc, {
|
|
3028
|
+
finishReactionEvent: () => lc,
|
|
3029
|
+
getReactedEventPointer: () => fc
|
|
2992
3030
|
});
|
|
2993
|
-
function
|
|
3031
|
+
function lc(e, t, n) {
|
|
2994
3032
|
const r = t.tags.filter((i) => i.length >= 2 && (i[0] === "e" || i[0] === "p"));
|
|
2995
|
-
return
|
|
3033
|
+
return X(
|
|
2996
3034
|
{
|
|
2997
3035
|
...e,
|
|
2998
|
-
kind:
|
|
3036
|
+
kind: cn,
|
|
2999
3037
|
tags: [...e.tags ?? [], ...r, ["e", t.id], ["p", t.pubkey]],
|
|
3000
3038
|
content: e.content ?? "+"
|
|
3001
3039
|
},
|
|
3002
3040
|
n
|
|
3003
3041
|
);
|
|
3004
3042
|
}
|
|
3005
|
-
function
|
|
3006
|
-
if (e.kind !==
|
|
3043
|
+
function fc(e) {
|
|
3044
|
+
if (e.kind !== cn)
|
|
3007
3045
|
return;
|
|
3008
3046
|
let t, n;
|
|
3009
3047
|
for (let r = e.tags.length - 1; r >= 0 && (t === void 0 || n === void 0); r--) {
|
|
@@ -3017,44 +3055,44 @@ function Ga(e) {
|
|
|
3017
3055
|
author: n[1]
|
|
3018
3056
|
};
|
|
3019
3057
|
}
|
|
3020
|
-
var
|
|
3021
|
-
|
|
3022
|
-
matchAll: () =>
|
|
3023
|
-
regex: () =>
|
|
3024
|
-
replaceAll: () =>
|
|
3058
|
+
var hc = {};
|
|
3059
|
+
q(hc, {
|
|
3060
|
+
matchAll: () => dc,
|
|
3061
|
+
regex: () => pn,
|
|
3062
|
+
replaceAll: () => pc
|
|
3025
3063
|
});
|
|
3026
|
-
var
|
|
3027
|
-
function*
|
|
3028
|
-
const t = e.matchAll(
|
|
3064
|
+
var pn = () => new RegExp(`\\b${vt.source}\\b`, "g");
|
|
3065
|
+
function* dc(e) {
|
|
3066
|
+
const t = e.matchAll(pn());
|
|
3029
3067
|
for (const n of t)
|
|
3030
3068
|
try {
|
|
3031
3069
|
const [r, i] = n;
|
|
3032
3070
|
yield {
|
|
3033
3071
|
uri: r,
|
|
3034
3072
|
value: i,
|
|
3035
|
-
decoded:
|
|
3073
|
+
decoded: yt(i),
|
|
3036
3074
|
start: n.index,
|
|
3037
3075
|
end: n.index + r.length
|
|
3038
3076
|
};
|
|
3039
3077
|
} catch {
|
|
3040
3078
|
}
|
|
3041
3079
|
}
|
|
3042
|
-
function
|
|
3043
|
-
return e.replaceAll(
|
|
3080
|
+
function pc(e, t) {
|
|
3081
|
+
return e.replaceAll(pn(), (n, r) => t({
|
|
3044
3082
|
uri: n,
|
|
3045
3083
|
value: r,
|
|
3046
|
-
decoded:
|
|
3084
|
+
decoded: yt(r)
|
|
3047
3085
|
}));
|
|
3048
3086
|
}
|
|
3049
|
-
var
|
|
3050
|
-
|
|
3051
|
-
channelCreateEvent: () =>
|
|
3052
|
-
channelHideMessageEvent: () =>
|
|
3053
|
-
channelMessageEvent: () =>
|
|
3054
|
-
channelMetadataEvent: () =>
|
|
3055
|
-
channelMuteUserEvent: () =>
|
|
3087
|
+
var yc = {};
|
|
3088
|
+
q(yc, {
|
|
3089
|
+
channelCreateEvent: () => gc,
|
|
3090
|
+
channelHideMessageEvent: () => vc,
|
|
3091
|
+
channelMessageEvent: () => bc,
|
|
3092
|
+
channelMetadataEvent: () => wc,
|
|
3093
|
+
channelMuteUserEvent: () => mc
|
|
3056
3094
|
});
|
|
3057
|
-
var
|
|
3095
|
+
var gc = (e, t) => {
|
|
3058
3096
|
let n;
|
|
3059
3097
|
if (typeof e.content == "object")
|
|
3060
3098
|
n = JSON.stringify(e.content);
|
|
@@ -3062,16 +3100,16 @@ var ec = (e, t) => {
|
|
|
3062
3100
|
n = e.content;
|
|
3063
3101
|
else
|
|
3064
3102
|
return;
|
|
3065
|
-
return
|
|
3103
|
+
return X(
|
|
3066
3104
|
{
|
|
3067
|
-
kind:
|
|
3105
|
+
kind: $r,
|
|
3068
3106
|
tags: [...e.tags ?? []],
|
|
3069
3107
|
content: n,
|
|
3070
3108
|
created_at: e.created_at
|
|
3071
3109
|
},
|
|
3072
3110
|
t
|
|
3073
3111
|
);
|
|
3074
|
-
},
|
|
3112
|
+
}, wc = (e, t) => {
|
|
3075
3113
|
let n;
|
|
3076
3114
|
if (typeof e.content == "object")
|
|
3077
3115
|
n = JSON.stringify(e.content);
|
|
@@ -3079,27 +3117,27 @@ var ec = (e, t) => {
|
|
|
3079
3117
|
n = e.content;
|
|
3080
3118
|
else
|
|
3081
3119
|
return;
|
|
3082
|
-
return
|
|
3120
|
+
return X(
|
|
3083
3121
|
{
|
|
3084
|
-
kind:
|
|
3122
|
+
kind: Tr,
|
|
3085
3123
|
tags: [["e", e.channel_create_event_id], ...e.tags ?? []],
|
|
3086
3124
|
content: n,
|
|
3087
3125
|
created_at: e.created_at
|
|
3088
3126
|
},
|
|
3089
3127
|
t
|
|
3090
3128
|
);
|
|
3091
|
-
},
|
|
3129
|
+
}, bc = (e, t) => {
|
|
3092
3130
|
const n = [["e", e.channel_create_event_id, e.relay_url, "root"]];
|
|
3093
|
-
return e.reply_to_channel_message_event_id && n.push(["e", e.reply_to_channel_message_event_id, e.relay_url, "reply"]),
|
|
3131
|
+
return e.reply_to_channel_message_event_id && n.push(["e", e.reply_to_channel_message_event_id, e.relay_url, "reply"]), X(
|
|
3094
3132
|
{
|
|
3095
|
-
kind:
|
|
3133
|
+
kind: Rr,
|
|
3096
3134
|
tags: [...n, ...e.tags ?? []],
|
|
3097
3135
|
content: e.content,
|
|
3098
3136
|
created_at: e.created_at
|
|
3099
3137
|
},
|
|
3100
3138
|
t
|
|
3101
3139
|
);
|
|
3102
|
-
},
|
|
3140
|
+
}, vc = (e, t) => {
|
|
3103
3141
|
let n;
|
|
3104
3142
|
if (typeof e.content == "object")
|
|
3105
3143
|
n = JSON.stringify(e.content);
|
|
@@ -3107,16 +3145,16 @@ var ec = (e, t) => {
|
|
|
3107
3145
|
n = e.content;
|
|
3108
3146
|
else
|
|
3109
3147
|
return;
|
|
3110
|
-
return
|
|
3148
|
+
return X(
|
|
3111
3149
|
{
|
|
3112
|
-
kind:
|
|
3150
|
+
kind: Or,
|
|
3113
3151
|
tags: [["e", e.channel_message_event_id], ...e.tags ?? []],
|
|
3114
3152
|
content: n,
|
|
3115
3153
|
created_at: e.created_at
|
|
3116
3154
|
},
|
|
3117
3155
|
t
|
|
3118
3156
|
);
|
|
3119
|
-
},
|
|
3157
|
+
}, mc = (e, t) => {
|
|
3120
3158
|
let n;
|
|
3121
3159
|
if (typeof e.content == "object")
|
|
3122
3160
|
n = JSON.stringify(e.content);
|
|
@@ -3124,25 +3162,25 @@ var ec = (e, t) => {
|
|
|
3124
3162
|
n = e.content;
|
|
3125
3163
|
else
|
|
3126
3164
|
return;
|
|
3127
|
-
return
|
|
3165
|
+
return X(
|
|
3128
3166
|
{
|
|
3129
|
-
kind:
|
|
3167
|
+
kind: Mr,
|
|
3130
3168
|
tags: [["p", e.pubkey_to_mute], ...e.tags ?? []],
|
|
3131
3169
|
content: n,
|
|
3132
3170
|
created_at: e.created_at
|
|
3133
3171
|
},
|
|
3134
3172
|
t
|
|
3135
3173
|
);
|
|
3136
|
-
},
|
|
3137
|
-
|
|
3138
|
-
EMOJI_SHORTCODE_REGEX: () =>
|
|
3139
|
-
matchAll: () =>
|
|
3140
|
-
regex: () =>
|
|
3141
|
-
replaceAll: () =>
|
|
3174
|
+
}, Ec = {};
|
|
3175
|
+
q(Ec, {
|
|
3176
|
+
EMOJI_SHORTCODE_REGEX: () => Yr,
|
|
3177
|
+
matchAll: () => xc,
|
|
3178
|
+
regex: () => yn,
|
|
3179
|
+
replaceAll: () => Sc
|
|
3142
3180
|
});
|
|
3143
|
-
var
|
|
3144
|
-
function*
|
|
3145
|
-
const t = e.matchAll(
|
|
3181
|
+
var Yr = /:(\w+):/, yn = () => new RegExp(`\\B${Yr.source}\\B`, "g");
|
|
3182
|
+
function* xc(e) {
|
|
3183
|
+
const t = e.matchAll(yn());
|
|
3146
3184
|
for (const n of t)
|
|
3147
3185
|
try {
|
|
3148
3186
|
const [r, i] = n;
|
|
@@ -3155,53 +3193,53 @@ function* oc(e) {
|
|
|
3155
3193
|
} catch {
|
|
3156
3194
|
}
|
|
3157
3195
|
}
|
|
3158
|
-
function
|
|
3159
|
-
return e.replaceAll(
|
|
3196
|
+
function Sc(e, t) {
|
|
3197
|
+
return e.replaceAll(yn(), (n, r) => t({
|
|
3160
3198
|
shortcode: n,
|
|
3161
3199
|
name: r
|
|
3162
3200
|
}));
|
|
3163
3201
|
}
|
|
3164
|
-
var
|
|
3165
|
-
|
|
3166
|
-
useFetchImplementation: () =>
|
|
3167
|
-
validateGithub: () =>
|
|
3202
|
+
var Ac = {};
|
|
3203
|
+
q(Ac, {
|
|
3204
|
+
useFetchImplementation: () => Nc,
|
|
3205
|
+
validateGithub: () => Kc
|
|
3168
3206
|
});
|
|
3169
|
-
var
|
|
3207
|
+
var gn;
|
|
3170
3208
|
try {
|
|
3171
|
-
|
|
3209
|
+
gn = fetch;
|
|
3172
3210
|
} catch {
|
|
3173
3211
|
}
|
|
3174
|
-
function
|
|
3175
|
-
|
|
3212
|
+
function Nc(e) {
|
|
3213
|
+
gn = e;
|
|
3176
3214
|
}
|
|
3177
|
-
async function
|
|
3215
|
+
async function Kc(e, t, n) {
|
|
3178
3216
|
try {
|
|
3179
|
-
return await (await
|
|
3217
|
+
return await (await gn(`https://gist.github.com/${t}/${n}/raw`)).text() === `Verifying that I control the following Nostr public key: ${e}`;
|
|
3180
3218
|
} catch {
|
|
3181
3219
|
return !1;
|
|
3182
3220
|
}
|
|
3183
3221
|
}
|
|
3184
3222
|
var j = {};
|
|
3185
|
-
|
|
3186
|
-
decrypt: () =>
|
|
3187
|
-
encrypt: () =>
|
|
3188
|
-
getConversationKey: () =>
|
|
3189
|
-
v2: () =>
|
|
3223
|
+
q(j, {
|
|
3224
|
+
decrypt: () => mn,
|
|
3225
|
+
encrypt: () => vn,
|
|
3226
|
+
getConversationKey: () => wn,
|
|
3227
|
+
v2: () => _c
|
|
3190
3228
|
});
|
|
3191
|
-
var
|
|
3192
|
-
function
|
|
3193
|
-
const n =
|
|
3194
|
-
return rn(
|
|
3229
|
+
var Xr = 1, Qr = 65535;
|
|
3230
|
+
function wn(e, t) {
|
|
3231
|
+
const n = _e.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3232
|
+
return rn(fe, n, "nip44-v2");
|
|
3195
3233
|
}
|
|
3196
|
-
function
|
|
3197
|
-
const n =
|
|
3234
|
+
function ei(e, t) {
|
|
3235
|
+
const n = kr(fe, e, t, 76);
|
|
3198
3236
|
return {
|
|
3199
3237
|
chacha_key: n.subarray(0, 32),
|
|
3200
3238
|
chacha_nonce: n.subarray(32, 44),
|
|
3201
3239
|
hmac_key: n.subarray(44, 76)
|
|
3202
3240
|
};
|
|
3203
3241
|
}
|
|
3204
|
-
function
|
|
3242
|
+
function bn(e) {
|
|
3205
3243
|
if (!Number.isSafeInteger(e) || e < 1)
|
|
3206
3244
|
throw new Error("expected positive integer");
|
|
3207
3245
|
if (e <= 32)
|
|
@@ -3209,29 +3247,29 @@ function yn(e) {
|
|
|
3209
3247
|
const t = 1 << Math.floor(Math.log2(e - 1)) + 1, n = t <= 256 ? 32 : t / 8;
|
|
3210
3248
|
return n * (Math.floor((e - 1) / n) + 1);
|
|
3211
3249
|
}
|
|
3212
|
-
function
|
|
3213
|
-
if (!Number.isSafeInteger(e) || e <
|
|
3250
|
+
function kc(e) {
|
|
3251
|
+
if (!Number.isSafeInteger(e) || e < Xr || e > Qr)
|
|
3214
3252
|
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
|
|
3215
3253
|
const t = new Uint8Array(2);
|
|
3216
3254
|
return new DataView(t.buffer).setUint16(0, e, !1), t;
|
|
3217
3255
|
}
|
|
3218
|
-
function
|
|
3219
|
-
const t =
|
|
3220
|
-
return
|
|
3256
|
+
function Bc(e) {
|
|
3257
|
+
const t = ne.encode(e), n = t.length, r = kc(n), i = new Uint8Array(bn(n) - n);
|
|
3258
|
+
return lt(r, t, i);
|
|
3221
3259
|
}
|
|
3222
|
-
function
|
|
3260
|
+
function Cc(e) {
|
|
3223
3261
|
const t = new DataView(e.buffer).getUint16(0), n = e.subarray(2, 2 + t);
|
|
3224
|
-
if (t <
|
|
3262
|
+
if (t < Xr || t > Qr || n.length !== t || e.length !== 2 + bn(t))
|
|
3225
3263
|
throw new Error("invalid padding");
|
|
3226
|
-
return
|
|
3264
|
+
return ue.decode(n);
|
|
3227
3265
|
}
|
|
3228
|
-
function
|
|
3266
|
+
function ti(e, t, n) {
|
|
3229
3267
|
if (n.length !== 32)
|
|
3230
3268
|
throw new Error("AAD associated data must be 32 bytes");
|
|
3231
|
-
const r =
|
|
3232
|
-
return
|
|
3269
|
+
const r = lt(n, t);
|
|
3270
|
+
return ht(fe, e, r);
|
|
3233
3271
|
}
|
|
3234
|
-
function
|
|
3272
|
+
function Uc(e) {
|
|
3235
3273
|
if (typeof e != "string")
|
|
3236
3274
|
throw new Error("payload must be a valid string");
|
|
3237
3275
|
const t = e.length;
|
|
@@ -3241,7 +3279,7 @@ function yc(e) {
|
|
|
3241
3279
|
throw new Error("unknown encryption version");
|
|
3242
3280
|
let n;
|
|
3243
3281
|
try {
|
|
3244
|
-
n =
|
|
3282
|
+
n = he.decode(e);
|
|
3245
3283
|
} catch (s) {
|
|
3246
3284
|
throw new Error("invalid base64: " + s.message);
|
|
3247
3285
|
}
|
|
@@ -3257,84 +3295,84 @@ function yc(e) {
|
|
|
3257
3295
|
mac: n.subarray(-32)
|
|
3258
3296
|
};
|
|
3259
3297
|
}
|
|
3260
|
-
function
|
|
3261
|
-
const { chacha_key: r, chacha_nonce: i, hmac_key: s } =
|
|
3262
|
-
return
|
|
3298
|
+
function vn(e, t, n = fr(32)) {
|
|
3299
|
+
const { chacha_key: r, chacha_nonce: i, hmac_key: s } = ei(t, n), o = Bc(e), a = Nr(r, i, o), c = ti(s, a, n);
|
|
3300
|
+
return he.encode(lt(new Uint8Array([2]), n, a, c));
|
|
3263
3301
|
}
|
|
3264
|
-
function
|
|
3265
|
-
const { nonce: n, ciphertext: r, mac: i } =
|
|
3266
|
-
if (!
|
|
3302
|
+
function mn(e, t) {
|
|
3303
|
+
const { nonce: n, ciphertext: r, mac: i } = Uc(e), { chacha_key: s, chacha_nonce: o, hmac_key: a } = ei(t, n), c = ti(a, r, n);
|
|
3304
|
+
if (!Rs(c, i))
|
|
3267
3305
|
throw new Error("invalid MAC");
|
|
3268
|
-
const l =
|
|
3269
|
-
return
|
|
3306
|
+
const l = Nr(s, o, r);
|
|
3307
|
+
return Cc(l);
|
|
3270
3308
|
}
|
|
3271
|
-
var
|
|
3309
|
+
var _c = {
|
|
3272
3310
|
utils: {
|
|
3273
|
-
getConversationKey:
|
|
3274
|
-
calcPaddedLen:
|
|
3311
|
+
getConversationKey: wn,
|
|
3312
|
+
calcPaddedLen: bn
|
|
3275
3313
|
},
|
|
3276
|
-
encrypt:
|
|
3277
|
-
decrypt:
|
|
3278
|
-
},
|
|
3279
|
-
|
|
3280
|
-
makeNwcRequestEvent: () =>
|
|
3281
|
-
parseConnectionString: () =>
|
|
3314
|
+
encrypt: vn,
|
|
3315
|
+
decrypt: mn
|
|
3316
|
+
}, Ic = {};
|
|
3317
|
+
q(Ic, {
|
|
3318
|
+
makeNwcRequestEvent: () => $c,
|
|
3319
|
+
parseConnectionString: () => Lc
|
|
3282
3320
|
});
|
|
3283
|
-
function
|
|
3321
|
+
function Lc(e) {
|
|
3284
3322
|
const { pathname: t, searchParams: n } = new URL(e), r = t, i = n.get("relay"), s = n.get("secret");
|
|
3285
3323
|
if (!r || !i || !s)
|
|
3286
3324
|
throw new Error("invalid connection string");
|
|
3287
3325
|
return { pubkey: r, relay: i, secret: s };
|
|
3288
3326
|
}
|
|
3289
|
-
async function
|
|
3290
|
-
const i = await
|
|
3327
|
+
async function $c(e, t, n) {
|
|
3328
|
+
const i = await zr(t, e, JSON.stringify({
|
|
3291
3329
|
method: "pay_invoice",
|
|
3292
3330
|
params: {
|
|
3293
3331
|
invoice: n
|
|
3294
3332
|
}
|
|
3295
3333
|
})), s = {
|
|
3296
|
-
kind:
|
|
3334
|
+
kind: qr,
|
|
3297
3335
|
created_at: Math.round(Date.now() / 1e3),
|
|
3298
3336
|
content: i,
|
|
3299
3337
|
tags: [["p", e]]
|
|
3300
3338
|
};
|
|
3301
|
-
return
|
|
3302
|
-
}
|
|
3303
|
-
var
|
|
3304
|
-
|
|
3305
|
-
getZapEndpoint: () =>
|
|
3306
|
-
makeZapReceipt: () =>
|
|
3307
|
-
makeZapRequest: () =>
|
|
3308
|
-
useFetchImplementation: () =>
|
|
3309
|
-
validateZapRequest: () =>
|
|
3339
|
+
return X(s, t);
|
|
3340
|
+
}
|
|
3341
|
+
var Tc = {};
|
|
3342
|
+
q(Tc, {
|
|
3343
|
+
getZapEndpoint: () => Oc,
|
|
3344
|
+
makeZapReceipt: () => Pc,
|
|
3345
|
+
makeZapRequest: () => Mc,
|
|
3346
|
+
useFetchImplementation: () => Rc,
|
|
3347
|
+
validateZapRequest: () => Hc
|
|
3310
3348
|
});
|
|
3311
|
-
var
|
|
3349
|
+
var En;
|
|
3312
3350
|
try {
|
|
3313
|
-
|
|
3351
|
+
En = fetch;
|
|
3314
3352
|
} catch {
|
|
3315
3353
|
}
|
|
3316
|
-
function
|
|
3317
|
-
|
|
3354
|
+
function Rc(e) {
|
|
3355
|
+
En = e;
|
|
3318
3356
|
}
|
|
3319
|
-
async function
|
|
3357
|
+
async function Oc(e) {
|
|
3320
3358
|
try {
|
|
3321
3359
|
let t = "", { lud06: n, lud16: r } = JSON.parse(e.content);
|
|
3322
3360
|
if (n) {
|
|
3323
3361
|
let { words: o } = je.decode(n, 1e3), a = je.fromWords(o);
|
|
3324
|
-
t =
|
|
3362
|
+
t = ue.decode(a);
|
|
3325
3363
|
} else if (r) {
|
|
3326
3364
|
let [o, a] = r.split("@");
|
|
3327
3365
|
t = new URL(`/.well-known/lnurlp/${o}`, `https://${a}`).toString();
|
|
3328
3366
|
} else
|
|
3329
3367
|
return null;
|
|
3330
|
-
let s = await (await
|
|
3368
|
+
let s = await (await En(t)).json();
|
|
3331
3369
|
if (s.allowsNostr && s.nostrPubkey)
|
|
3332
3370
|
return s.callback;
|
|
3333
3371
|
} catch {
|
|
3334
3372
|
}
|
|
3335
3373
|
return null;
|
|
3336
3374
|
}
|
|
3337
|
-
function
|
|
3375
|
+
function Mc({
|
|
3338
3376
|
profile: e,
|
|
3339
3377
|
event: t,
|
|
3340
3378
|
amount: n,
|
|
@@ -3357,16 +3395,16 @@ function xc({
|
|
|
3357
3395
|
};
|
|
3358
3396
|
return t && s.tags.push(["e", t]), s;
|
|
3359
3397
|
}
|
|
3360
|
-
function
|
|
3398
|
+
function Hc(e) {
|
|
3361
3399
|
let t;
|
|
3362
3400
|
try {
|
|
3363
3401
|
t = JSON.parse(e);
|
|
3364
3402
|
} catch {
|
|
3365
3403
|
return "Invalid zap request JSON.";
|
|
3366
3404
|
}
|
|
3367
|
-
if (!
|
|
3405
|
+
if (!sn(t))
|
|
3368
3406
|
return "Zap request is not a valid Nostr event.";
|
|
3369
|
-
if (!
|
|
3407
|
+
if (!pt(t))
|
|
3370
3408
|
return "Invalid signature on zap request.";
|
|
3371
3409
|
let n = t.tags.find(([s, o]) => s === "p" && o);
|
|
3372
3410
|
if (!n)
|
|
@@ -3376,7 +3414,7 @@ function Sc(e) {
|
|
|
3376
3414
|
let r = t.tags.find(([s, o]) => s === "e" && o);
|
|
3377
3415
|
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.";
|
|
3378
3416
|
}
|
|
3379
|
-
function
|
|
3417
|
+
function Pc({
|
|
3380
3418
|
zapRequest: e,
|
|
3381
3419
|
preimage: t,
|
|
3382
3420
|
bolt11: n,
|
|
@@ -3390,23 +3428,89 @@ function Ac({
|
|
|
3390
3428
|
};
|
|
3391
3429
|
return t && o.tags.push(["preimage", t]), o;
|
|
3392
3430
|
}
|
|
3393
|
-
var
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
validateEventTimestamp: () => Qr,
|
|
3403
|
-
validateEventUrlTag: () => ti,
|
|
3404
|
-
validateToken: () => Bc
|
|
3431
|
+
var qc = {};
|
|
3432
|
+
q(qc, {
|
|
3433
|
+
createRumor: () => oi,
|
|
3434
|
+
createSeal: () => ai,
|
|
3435
|
+
createWrap: () => ci,
|
|
3436
|
+
unwrapEvent: () => ui,
|
|
3437
|
+
unwrapManyEvents: () => zc,
|
|
3438
|
+
wrapEvent: () => Vt,
|
|
3439
|
+
wrapManyEvents: () => jc
|
|
3405
3440
|
});
|
|
3406
|
-
var
|
|
3407
|
-
|
|
3441
|
+
var Dc = 2 * 24 * 60 * 60, ni = () => Math.round(Date.now() / 1e3), ri = () => Math.round(ni() - Math.random() * Dc), ii = (e, t) => wn(e, t), si = (e, t, n) => vn(JSON.stringify(e), ii(t, n)), Dn = (e, t) => JSON.parse(mn(e.content, ii(t, e.pubkey)));
|
|
3442
|
+
function oi(e, t) {
|
|
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 X(
|
|
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 = Ce();
|
|
3465
|
+
return X(
|
|
3466
|
+
{
|
|
3467
|
+
kind: Hr,
|
|
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 = Dn(e, t);
|
|
3489
|
+
return Dn(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
|
+
q(Vc, {
|
|
3499
|
+
getToken: () => Wc,
|
|
3500
|
+
hashPayload: () => xn,
|
|
3501
|
+
unpackEventFromToken: () => fi,
|
|
3502
|
+
validateEvent: () => wi,
|
|
3503
|
+
validateEventKind: () => di,
|
|
3504
|
+
validateEventMethodTag: () => yi,
|
|
3505
|
+
validateEventPayloadTag: () => gi,
|
|
3506
|
+
validateEventTimestamp: () => hi,
|
|
3507
|
+
validateEventUrlTag: () => pi,
|
|
3508
|
+
validateToken: () => Zc
|
|
3509
|
+
});
|
|
3510
|
+
var li = "Nostr ";
|
|
3511
|
+
async function Wc(e, t, n, r = !1, i) {
|
|
3408
3512
|
const s = {
|
|
3409
|
-
kind:
|
|
3513
|
+
kind: un,
|
|
3410
3514
|
tags: [
|
|
3411
3515
|
["u", e],
|
|
3412
3516
|
["method", t]
|
|
@@ -3414,70 +3518,70 @@ async function Nc(e, t, n, r = !1, i) {
|
|
|
3414
3518
|
created_at: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
3415
3519
|
content: ""
|
|
3416
3520
|
};
|
|
3417
|
-
i && s.tags.push(["payload",
|
|
3521
|
+
i && s.tags.push(["payload", xn(i)]);
|
|
3418
3522
|
const o = await n(s);
|
|
3419
|
-
return (r ?
|
|
3523
|
+
return (r ? li : "") + he.encode(ne.encode(JSON.stringify(o)));
|
|
3420
3524
|
}
|
|
3421
|
-
async function
|
|
3422
|
-
const r = await
|
|
3525
|
+
async function Zc(e, t, n) {
|
|
3526
|
+
const r = await fi(e).catch((s) => {
|
|
3423
3527
|
throw s;
|
|
3424
3528
|
});
|
|
3425
|
-
return await
|
|
3529
|
+
return await wi(r, t, n).catch((s) => {
|
|
3426
3530
|
throw s;
|
|
3427
3531
|
});
|
|
3428
3532
|
}
|
|
3429
|
-
async function
|
|
3533
|
+
async function fi(e) {
|
|
3430
3534
|
if (!e)
|
|
3431
3535
|
throw new Error("Missing token");
|
|
3432
|
-
e = e.replace(
|
|
3433
|
-
const t =
|
|
3536
|
+
e = e.replace(li, "");
|
|
3537
|
+
const t = ue.decode(he.decode(e));
|
|
3434
3538
|
if (!t || t.length === 0 || !t.startsWith("{"))
|
|
3435
3539
|
throw new Error("Invalid token");
|
|
3436
3540
|
return JSON.parse(t);
|
|
3437
3541
|
}
|
|
3438
|
-
function
|
|
3542
|
+
function hi(e) {
|
|
3439
3543
|
return e.created_at ? Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3) - e.created_at < 60 : !1;
|
|
3440
3544
|
}
|
|
3441
|
-
function
|
|
3442
|
-
return e.kind ===
|
|
3545
|
+
function di(e) {
|
|
3546
|
+
return e.kind === un;
|
|
3443
3547
|
}
|
|
3444
|
-
function
|
|
3548
|
+
function pi(e, t) {
|
|
3445
3549
|
const n = e.tags.find((r) => r[0] === "u");
|
|
3446
3550
|
return n ? n.length > 0 && n[1] === t : !1;
|
|
3447
3551
|
}
|
|
3448
|
-
function
|
|
3552
|
+
function yi(e, t) {
|
|
3449
3553
|
const n = e.tags.find((r) => r[0] === "method");
|
|
3450
3554
|
return n ? n.length > 0 && n[1].toLowerCase() === t.toLowerCase() : !1;
|
|
3451
3555
|
}
|
|
3452
|
-
function
|
|
3453
|
-
const t =
|
|
3556
|
+
function xn(e) {
|
|
3557
|
+
const t = fe(ne.encode(JSON.stringify(e)));
|
|
3454
3558
|
return M(t);
|
|
3455
3559
|
}
|
|
3456
|
-
function
|
|
3560
|
+
function gi(e, t) {
|
|
3457
3561
|
const n = e.tags.find((i) => i[0] === "payload");
|
|
3458
3562
|
if (!n)
|
|
3459
3563
|
return !1;
|
|
3460
|
-
const r =
|
|
3564
|
+
const r = xn(t);
|
|
3461
3565
|
return n.length > 0 && n[1] === r;
|
|
3462
3566
|
}
|
|
3463
|
-
async function
|
|
3464
|
-
if (!
|
|
3567
|
+
async function wi(e, t, n, r) {
|
|
3568
|
+
if (!pt(e))
|
|
3465
3569
|
throw new Error("Invalid nostr event, signature invalid");
|
|
3466
|
-
if (!
|
|
3570
|
+
if (!di(e))
|
|
3467
3571
|
throw new Error("Invalid nostr event, kind invalid");
|
|
3468
|
-
if (!
|
|
3572
|
+
if (!hi(e))
|
|
3469
3573
|
throw new Error("Invalid nostr event, created_at timestamp invalid");
|
|
3470
|
-
if (!
|
|
3574
|
+
if (!pi(e, t))
|
|
3471
3575
|
throw new Error("Invalid nostr event, url tag invalid");
|
|
3472
|
-
if (!
|
|
3576
|
+
if (!yi(e, n))
|
|
3473
3577
|
throw new Error("Invalid nostr event, method tag invalid");
|
|
3474
|
-
if (r && typeof r == "object" && Object.keys(r).length > 0 && !
|
|
3578
|
+
if (r && typeof r == "object" && Object.keys(r).length > 0 && !gi(e, r))
|
|
3475
3579
|
throw new Error("Invalid nostr event, payload tag does not match request body hash");
|
|
3476
3580
|
return !0;
|
|
3477
3581
|
}
|
|
3478
|
-
const
|
|
3479
|
-
var
|
|
3480
|
-
function
|
|
3582
|
+
const Pe = 4, jn = 30078, nu = 100;
|
|
3583
|
+
var Gc = /* @__PURE__ */ ((e) => (e[e.Us = 0] = "Us", e[e.Them = 1] = "Them", e))(Gc || {});
|
|
3584
|
+
function ru(e) {
|
|
3481
3585
|
return JSON.stringify({
|
|
3482
3586
|
rootKey: M(e.rootKey),
|
|
3483
3587
|
theirNostrPublicKey: e.theirNostrPublicKey,
|
|
@@ -3508,39 +3612,39 @@ function Oc(e) {
|
|
|
3508
3612
|
)
|
|
3509
3613
|
});
|
|
3510
3614
|
}
|
|
3511
|
-
function
|
|
3615
|
+
function iu(e) {
|
|
3512
3616
|
const t = JSON.parse(e);
|
|
3513
3617
|
return {
|
|
3514
|
-
rootKey:
|
|
3618
|
+
rootKey: G(t.rootKey),
|
|
3515
3619
|
theirNostrPublicKey: t.theirNostrPublicKey,
|
|
3516
3620
|
ourCurrentNostrKey: t.ourCurrentNostrKey ? {
|
|
3517
3621
|
publicKey: t.ourCurrentNostrKey.publicKey,
|
|
3518
|
-
privateKey:
|
|
3622
|
+
privateKey: G(t.ourCurrentNostrKey.privateKey)
|
|
3519
3623
|
} : void 0,
|
|
3520
3624
|
ourNextNostrKey: {
|
|
3521
3625
|
publicKey: t.ourNextNostrKey.publicKey,
|
|
3522
|
-
privateKey:
|
|
3626
|
+
privateKey: G(t.ourNextNostrKey.privateKey)
|
|
3523
3627
|
},
|
|
3524
|
-
receivingChainKey: t.receivingChainKey ?
|
|
3525
|
-
sendingChainKey: t.sendingChainKey ?
|
|
3628
|
+
receivingChainKey: t.receivingChainKey ? G(t.receivingChainKey) : void 0,
|
|
3629
|
+
sendingChainKey: t.sendingChainKey ? G(t.sendingChainKey) : void 0,
|
|
3526
3630
|
sendingChainMessageNumber: t.sendingChainMessageNumber,
|
|
3527
3631
|
receivingChainMessageNumber: t.receivingChainMessageNumber,
|
|
3528
3632
|
previousSendingChainMessageCount: t.previousSendingChainMessageCount,
|
|
3529
3633
|
skippedMessageKeys: Object.fromEntries(
|
|
3530
3634
|
Object.entries(t.skippedMessageKeys).map(([n, r]) => [
|
|
3531
3635
|
n,
|
|
3532
|
-
|
|
3636
|
+
G(r)
|
|
3533
3637
|
])
|
|
3534
3638
|
),
|
|
3535
3639
|
skippedHeaderKeys: Object.fromEntries(
|
|
3536
3640
|
Object.entries(t.skippedHeaderKeys || {}).map(([n, r]) => [
|
|
3537
3641
|
n,
|
|
3538
|
-
r.map((i) =>
|
|
3642
|
+
r.map((i) => G(i))
|
|
3539
3643
|
])
|
|
3540
3644
|
)
|
|
3541
3645
|
};
|
|
3542
3646
|
}
|
|
3543
|
-
async function*
|
|
3647
|
+
async function* su(e) {
|
|
3544
3648
|
const t = [];
|
|
3545
3649
|
let n = null;
|
|
3546
3650
|
const r = e.onMessage((i) => {
|
|
@@ -3555,41 +3659,41 @@ async function* Mc(e) {
|
|
|
3555
3659
|
r();
|
|
3556
3660
|
}
|
|
3557
3661
|
}
|
|
3558
|
-
function
|
|
3559
|
-
const r = rn(
|
|
3662
|
+
function Oe(e, t = new Uint8Array(32), n = 1) {
|
|
3663
|
+
const r = rn(fe, e, t), i = [];
|
|
3560
3664
|
for (let s = 1; s <= n; s++)
|
|
3561
|
-
i.push(
|
|
3665
|
+
i.push(kr(fe, r, new Uint8Array([s]), 32));
|
|
3562
3666
|
return i;
|
|
3563
3667
|
}
|
|
3564
|
-
function
|
|
3668
|
+
function It(e, t) {
|
|
3565
3669
|
return `${e}:${t}`;
|
|
3566
3670
|
}
|
|
3567
|
-
const
|
|
3568
|
-
class
|
|
3671
|
+
const Fc = 1e3;
|
|
3672
|
+
class st {
|
|
3569
3673
|
// 1. CHANNEL PUBLIC INTERFACE
|
|
3570
3674
|
constructor(t, n) {
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3675
|
+
te(this, "nostrUnsubscribe");
|
|
3676
|
+
te(this, "nostrNextUnsubscribe");
|
|
3677
|
+
te(this, "internalSubscriptions", /* @__PURE__ */ new Map());
|
|
3678
|
+
te(this, "currentInternalSubscriptionId", 0);
|
|
3679
|
+
te(this, "name");
|
|
3576
3680
|
this.nostrSubscribe = t, this.state = n, this.name = Math.random().toString(36).substring(2, 6);
|
|
3577
3681
|
}
|
|
3578
3682
|
/**
|
|
3579
|
-
* Initializes a new secure communication
|
|
3683
|
+
* Initializes a new secure communication session
|
|
3580
3684
|
* @param nostrSubscribe Function to subscribe to Nostr events
|
|
3581
3685
|
* @param theirNostrPublicKey The public key of the other party
|
|
3582
3686
|
* @param ourCurrentPrivateKey Our current private key for Nostr
|
|
3583
3687
|
* @param isInitiator Whether we are initiating the conversation (true) or responding (false)
|
|
3584
3688
|
* @param sharedSecret Initial shared secret for securing the first message chain
|
|
3585
|
-
* @param name Optional name for the
|
|
3586
|
-
* @returns A new
|
|
3689
|
+
* @param name Optional name for the session (for debugging)
|
|
3690
|
+
* @returns A new Session instance
|
|
3587
3691
|
*/
|
|
3588
3692
|
static init(t, n, r, i, s, o) {
|
|
3589
|
-
const a =
|
|
3693
|
+
const a = Ce(), [c, l] = Oe(s, j.getConversationKey(a, n), 2);
|
|
3590
3694
|
let f, u;
|
|
3591
|
-
i ? (f = { publicKey:
|
|
3592
|
-
const
|
|
3695
|
+
i ? (f = { publicKey: le(r), privateKey: r }, u = { publicKey: le(a), privateKey: a }) : u = { publicKey: le(r), privateKey: r };
|
|
3696
|
+
const g = {
|
|
3593
3697
|
rootKey: i ? c : s,
|
|
3594
3698
|
theirNostrPublicKey: n,
|
|
3595
3699
|
ourCurrentNostrKey: f,
|
|
@@ -3601,11 +3705,11 @@ class at {
|
|
|
3601
3705
|
previousSendingChainMessageCount: 0,
|
|
3602
3706
|
skippedMessageKeys: {},
|
|
3603
3707
|
skippedHeaderKeys: {}
|
|
3604
|
-
},
|
|
3605
|
-
return o && (
|
|
3708
|
+
}, b = new st(t, g);
|
|
3709
|
+
return o && (b.name = o), b;
|
|
3606
3710
|
}
|
|
3607
3711
|
/**
|
|
3608
|
-
* Sends an encrypted message through the
|
|
3712
|
+
* Sends an encrypted message through the session
|
|
3609
3713
|
* @param data The plaintext message to send
|
|
3610
3714
|
* @returns A verified Nostr event containing the encrypted message
|
|
3611
3715
|
* @throws Error if we are not the initiator and trying to send the first message
|
|
@@ -3614,15 +3718,15 @@ class at {
|
|
|
3614
3718
|
if (!this.state.theirNostrPublicKey || !this.state.ourCurrentNostrKey)
|
|
3615
3719
|
throw new Error("we are not the initiator, so we can't send the first message");
|
|
3616
3720
|
const [n, r] = this.ratchetEncrypt(t), i = j.getConversationKey(this.state.ourCurrentNostrKey.privateKey, this.state.theirNostrPublicKey), s = j.encrypt(JSON.stringify(n), i);
|
|
3617
|
-
return
|
|
3721
|
+
return X({
|
|
3618
3722
|
content: r,
|
|
3619
|
-
kind:
|
|
3723
|
+
kind: Pe,
|
|
3620
3724
|
tags: [["header", s]],
|
|
3621
3725
|
created_at: Math.floor(Date.now() / 1e3)
|
|
3622
3726
|
}, this.state.ourCurrentNostrKey.privateKey);
|
|
3623
3727
|
}
|
|
3624
3728
|
/**
|
|
3625
|
-
* Subscribes to incoming messages on this
|
|
3729
|
+
* Subscribes to incoming messages on this session
|
|
3626
3730
|
* @param callback Function to be called when a message is received
|
|
3627
3731
|
* @returns Unsubscribe function to stop receiving messages
|
|
3628
3732
|
*/
|
|
@@ -3639,7 +3743,7 @@ class at {
|
|
|
3639
3743
|
}
|
|
3640
3744
|
// 2. RATCHET FUNCTIONS
|
|
3641
3745
|
ratchetEncrypt(t) {
|
|
3642
|
-
const [n, r] =
|
|
3746
|
+
const [n, r] = Oe(this.state.sendingChainKey, new Uint8Array([1]), 2);
|
|
3643
3747
|
return this.state.sendingChainKey = n, [{
|
|
3644
3748
|
number: this.state.sendingChainMessageNumber++,
|
|
3645
3749
|
nextPublicKey: this.state.ourNextNostrKey.publicKey,
|
|
@@ -3651,7 +3755,7 @@ class at {
|
|
|
3651
3755
|
const i = this.trySkippedMessageKeys(t, n, r);
|
|
3652
3756
|
if (i) return i;
|
|
3653
3757
|
this.skipMessageKeys(t.number, r);
|
|
3654
|
-
const [s, o] =
|
|
3758
|
+
const [s, o] = Oe(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3655
3759
|
this.state.receivingChainKey = s, this.state.receivingChainMessageNumber++;
|
|
3656
3760
|
try {
|
|
3657
3761
|
return j.decrypt(n, o);
|
|
@@ -3666,24 +3770,24 @@ class at {
|
|
|
3666
3770
|
}
|
|
3667
3771
|
ratchetStep(t) {
|
|
3668
3772
|
this.state.previousSendingChainMessageCount = this.state.sendingChainMessageNumber, this.state.sendingChainMessageNumber = 0, this.state.receivingChainMessageNumber = 0, this.state.theirNostrPublicKey = t;
|
|
3669
|
-
const n = j.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNostrPublicKey), [r, i] =
|
|
3773
|
+
const n = j.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNostrPublicKey), [r, i] = Oe(this.state.rootKey, n, 2);
|
|
3670
3774
|
this.state.receivingChainKey = i, this.state.ourCurrentNostrKey = this.state.ourNextNostrKey;
|
|
3671
|
-
const s =
|
|
3775
|
+
const s = Ce();
|
|
3672
3776
|
this.state.ourNextNostrKey = {
|
|
3673
|
-
publicKey:
|
|
3777
|
+
publicKey: le(s),
|
|
3674
3778
|
privateKey: s
|
|
3675
3779
|
};
|
|
3676
|
-
const o = j.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNostrPublicKey), [a, c] =
|
|
3780
|
+
const o = j.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNostrPublicKey), [a, c] = Oe(r, o, 2);
|
|
3677
3781
|
this.state.rootKey = a, this.state.sendingChainKey = c;
|
|
3678
3782
|
}
|
|
3679
3783
|
// 3. MESSAGE KEY FUNCTIONS
|
|
3680
3784
|
skipMessageKeys(t, n) {
|
|
3681
|
-
if (this.state.receivingChainMessageNumber +
|
|
3785
|
+
if (this.state.receivingChainMessageNumber + Fc < t)
|
|
3682
3786
|
throw new Error("Too many skipped messages");
|
|
3683
3787
|
for (; this.state.receivingChainMessageNumber < t; ) {
|
|
3684
|
-
const [r, i] =
|
|
3788
|
+
const [r, i] = Oe(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3685
3789
|
this.state.receivingChainKey = r;
|
|
3686
|
-
const s =
|
|
3790
|
+
const s = It(n, this.state.receivingChainMessageNumber);
|
|
3687
3791
|
if (this.state.skippedMessageKeys[s] = i, !this.state.skippedHeaderKeys[n]) {
|
|
3688
3792
|
const o = [];
|
|
3689
3793
|
if (this.state.ourCurrentNostrKey) {
|
|
@@ -3698,7 +3802,7 @@ class at {
|
|
|
3698
3802
|
}
|
|
3699
3803
|
trySkippedMessageKeys(t, n, r) {
|
|
3700
3804
|
var s;
|
|
3701
|
-
const i =
|
|
3805
|
+
const i = It(r, t.number);
|
|
3702
3806
|
if (i in this.state.skippedMessageKeys) {
|
|
3703
3807
|
const o = this.state.skippedMessageKeys[i];
|
|
3704
3808
|
return delete this.state.skippedMessageKeys[i], Object.keys(this.state.skippedMessageKeys).some((c) => c.startsWith(`${r}:`)) || (delete this.state.skippedHeaderKeys[r], (s = this.nostrUnsubscribe) == null || s.call(this), this.nostrUnsubscribe = void 0), j.decrypt(n, o);
|
|
@@ -3734,10 +3838,10 @@ class at {
|
|
|
3734
3838
|
const [n, r, i] = this.decryptHeader(t);
|
|
3735
3839
|
if (!i)
|
|
3736
3840
|
this.state.theirNostrPublicKey !== n.nextPublicKey && (this.state.theirNostrPublicKey = n.nextPublicKey, (o = this.nostrUnsubscribe) == null || o.call(this), this.nostrUnsubscribe = this.nostrNextUnsubscribe, this.nostrNextUnsubscribe = this.nostrSubscribe(
|
|
3737
|
-
{ authors: [this.state.theirNostrPublicKey], kinds: [
|
|
3841
|
+
{ authors: [this.state.theirNostrPublicKey], kinds: [Pe] },
|
|
3738
3842
|
(a) => this.handleNostrEvent(a)
|
|
3739
3843
|
)), r && (this.skipMessageKeys(n.previousChainLength, t.pubkey), this.ratchetStep(n.nextPublicKey));
|
|
3740
|
-
else if (!(
|
|
3844
|
+
else if (!(It(t.pubkey, n.number) in this.state.skippedMessageKeys))
|
|
3741
3845
|
return;
|
|
3742
3846
|
const s = this.ratchetDecrypt(n, t.content, t.pubkey);
|
|
3743
3847
|
this.internalSubscriptions.forEach((a) => a({ id: t.id, data: s, pubkey: n.nextPublicKey, time: n.time }));
|
|
@@ -3745,29 +3849,31 @@ class at {
|
|
|
3745
3849
|
subscribeToNostrEvents() {
|
|
3746
3850
|
if (this.nostrNextUnsubscribe) return;
|
|
3747
3851
|
this.nostrNextUnsubscribe = this.nostrSubscribe(
|
|
3748
|
-
{ authors: [this.state.theirNostrPublicKey], kinds: [
|
|
3852
|
+
{ authors: [this.state.theirNostrPublicKey], kinds: [Pe] },
|
|
3749
3853
|
(n) => this.handleNostrEvent(n)
|
|
3750
3854
|
);
|
|
3751
3855
|
const t = Object.keys(this.state.skippedHeaderKeys);
|
|
3752
3856
|
t.length > 0 && (this.nostrUnsubscribe = this.nostrSubscribe(
|
|
3753
|
-
{ authors: t, kinds: [
|
|
3857
|
+
{ authors: t, kinds: [Pe] },
|
|
3754
3858
|
(n) => this.handleNostrEvent(n)
|
|
3755
3859
|
));
|
|
3756
3860
|
}
|
|
3757
3861
|
}
|
|
3758
3862
|
new TextDecoder("utf-8");
|
|
3759
3863
|
new TextEncoder();
|
|
3760
|
-
function
|
|
3761
|
-
const n =
|
|
3762
|
-
return rn(
|
|
3864
|
+
function Xe(e, t) {
|
|
3865
|
+
const n = _e.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3866
|
+
return rn(fe, n, "nip44-v2");
|
|
3763
3867
|
}
|
|
3764
|
-
class
|
|
3868
|
+
class Me {
|
|
3765
3869
|
constructor(t, n, r, i, s, o, a = []) {
|
|
3766
3870
|
this.inviterSessionPublicKey = t, this.linkSecret = n, this.inviter = r, this.inviterSessionPrivateKey = i, this.label = s, this.maxUses = o, this.usedBy = a;
|
|
3767
3871
|
}
|
|
3768
3872
|
static createNew(t, n, r) {
|
|
3769
|
-
|
|
3770
|
-
|
|
3873
|
+
if (!t)
|
|
3874
|
+
throw new Error("Inviter public key is required");
|
|
3875
|
+
const i = Ce(), s = le(i), o = M(Ce());
|
|
3876
|
+
return new Me(
|
|
3771
3877
|
s,
|
|
3772
3878
|
o,
|
|
3773
3879
|
t,
|
|
@@ -3790,7 +3896,7 @@ class Oe {
|
|
|
3790
3896
|
const { inviter: o, sessionKey: a, linkSecret: c } = s;
|
|
3791
3897
|
if (!o || !a || !c)
|
|
3792
3898
|
throw new Error("Missing required fields (inviter, sessionKey, linkSecret) in invite data.");
|
|
3793
|
-
return new
|
|
3899
|
+
return new Me(
|
|
3794
3900
|
a,
|
|
3795
3901
|
c,
|
|
3796
3902
|
o
|
|
@@ -3798,7 +3904,7 @@ class Oe {
|
|
|
3798
3904
|
}
|
|
3799
3905
|
static deserialize(t) {
|
|
3800
3906
|
const n = JSON.parse(t);
|
|
3801
|
-
return new
|
|
3907
|
+
return new Me(
|
|
3802
3908
|
n.inviterSessionPublicKey,
|
|
3803
3909
|
n.linkSecret,
|
|
3804
3910
|
n.inviter,
|
|
@@ -3812,36 +3918,35 @@ class Oe {
|
|
|
3812
3918
|
var o, a;
|
|
3813
3919
|
if (!t.sig)
|
|
3814
3920
|
throw new Error("Event is not signed");
|
|
3815
|
-
if (!
|
|
3921
|
+
if (!pt(t))
|
|
3816
3922
|
throw new Error("Event signature is invalid");
|
|
3817
3923
|
const { tags: n } = t, r = (o = n.find(([c]) => c === "sessionKey")) == null ? void 0 : o[1], i = (a = n.find(([c]) => c === "linkSecret")) == null ? void 0 : a[1], s = t.pubkey;
|
|
3818
3924
|
if (!r || !i)
|
|
3819
3925
|
throw new Error("Invalid invite event: missing session key or link secret");
|
|
3820
|
-
return new
|
|
3926
|
+
return new Me(
|
|
3821
3927
|
r,
|
|
3822
3928
|
i,
|
|
3823
3929
|
s
|
|
3824
3930
|
);
|
|
3825
3931
|
}
|
|
3826
|
-
static fromUser(t, n) {
|
|
3827
|
-
const
|
|
3828
|
-
kinds: [
|
|
3932
|
+
static fromUser(t, n, r) {
|
|
3933
|
+
const i = {
|
|
3934
|
+
kinds: [jn],
|
|
3829
3935
|
authors: [t],
|
|
3830
3936
|
limit: 1,
|
|
3831
3937
|
"#d": ["nostr-double-ratchet/invite"]
|
|
3832
3938
|
};
|
|
3833
|
-
|
|
3834
|
-
|
|
3939
|
+
let s = 0;
|
|
3940
|
+
return n(i, (a) => {
|
|
3941
|
+
if (!(!a.created_at || a.created_at <= s)) {
|
|
3942
|
+
s = a.created_at;
|
|
3835
3943
|
try {
|
|
3836
|
-
const
|
|
3837
|
-
|
|
3838
|
-
} catch {
|
|
3839
|
-
|
|
3944
|
+
const c = Me.fromEvent(a);
|
|
3945
|
+
r(c);
|
|
3946
|
+
} catch (c) {
|
|
3947
|
+
console.error("Error processing invite:", c, "event:", a);
|
|
3840
3948
|
}
|
|
3841
|
-
}
|
|
3842
|
-
setTimeout(() => {
|
|
3843
|
-
s(), i(void 0);
|
|
3844
|
-
}, 1e4);
|
|
3949
|
+
}
|
|
3845
3950
|
});
|
|
3846
3951
|
}
|
|
3847
3952
|
/**
|
|
@@ -3871,7 +3976,7 @@ class Oe {
|
|
|
3871
3976
|
}
|
|
3872
3977
|
getEvent() {
|
|
3873
3978
|
return {
|
|
3874
|
-
kind:
|
|
3979
|
+
kind: jn,
|
|
3875
3980
|
pubkey: this.inviter,
|
|
3876
3981
|
content: "",
|
|
3877
3982
|
created_at: Math.floor(Date.now() / 1e3),
|
|
@@ -3879,11 +3984,11 @@ class Oe {
|
|
|
3879
3984
|
};
|
|
3880
3985
|
}
|
|
3881
3986
|
/**
|
|
3882
|
-
* Called by the invitee. Accepts the invite and creates a new
|
|
3987
|
+
* Called by the invitee. Accepts the invite and creates a new session with the inviter.
|
|
3883
3988
|
*
|
|
3884
3989
|
* @param inviteeSecretKey - The invitee's secret key or a signing function
|
|
3885
3990
|
* @param nostrSubscribe - A function to subscribe to Nostr events
|
|
3886
|
-
* @returns An object containing the new
|
|
3991
|
+
* @returns An object containing the new session and an event to be published
|
|
3887
3992
|
*
|
|
3888
3993
|
* 1. Inner event: No signature, content encrypted with DH(inviter, invitee).
|
|
3889
3994
|
* Purpose: Authenticate invitee. Contains invitee session key.
|
|
@@ -3891,28 +3996,28 @@ class Oe {
|
|
|
3891
3996
|
* Purpose: Contains inner event. Hides invitee from others who might have the shared Nostr key.
|
|
3892
3997
|
|
|
3893
3998
|
* Note: You need to publish the returned event on Nostr using NDK or another Nostr system of your choice,
|
|
3894
|
-
* so the inviter can create the
|
|
3999
|
+
* so the inviter can create the session on their side.
|
|
3895
4000
|
*/
|
|
3896
4001
|
async accept(t, n, r) {
|
|
3897
|
-
const i =
|
|
4002
|
+
const i = Ce(), s = le(i), o = this.inviter || this.inviterSessionPublicKey, a = G(this.linkSecret), c = st.init(t, this.inviterSessionPublicKey, i, !0, a, void 0), l = Ce(), f = le(l), u = typeof r == "function" ? r : (p, h) => Promise.resolve(j.encrypt(p, Xe(r, h))), g = {
|
|
3898
4003
|
pubkey: n,
|
|
3899
4004
|
tags: [["secret", this.linkSecret]],
|
|
3900
4005
|
content: await u(s, o),
|
|
3901
4006
|
created_at: Math.floor(Date.now() / 1e3)
|
|
3902
|
-
},
|
|
3903
|
-
kind:
|
|
4007
|
+
}, b = {
|
|
4008
|
+
kind: Pe,
|
|
3904
4009
|
pubkey: f,
|
|
3905
|
-
content: j.encrypt(JSON.stringify(
|
|
4010
|
+
content: j.encrypt(JSON.stringify(g), Xe(l, this.inviterSessionPublicKey)),
|
|
3906
4011
|
created_at: Math.floor(Date.now() / 1e3),
|
|
3907
4012
|
tags: [["p", this.inviterSessionPublicKey]]
|
|
3908
4013
|
};
|
|
3909
|
-
return {
|
|
4014
|
+
return { session: c, event: X(b, l) };
|
|
3910
4015
|
}
|
|
3911
4016
|
listen(t, n, r) {
|
|
3912
4017
|
if (!this.inviterSessionPrivateKey)
|
|
3913
4018
|
throw new Error("Inviter session key is not available");
|
|
3914
4019
|
const i = {
|
|
3915
|
-
kinds: [
|
|
4020
|
+
kinds: [Pe],
|
|
3916
4021
|
"#p": [this.inviterSessionPublicKey]
|
|
3917
4022
|
};
|
|
3918
4023
|
return n(i, async (s) => {
|
|
@@ -3921,31 +4026,31 @@ class Oe {
|
|
|
3921
4026
|
console.error("Invite has reached maximum number of uses");
|
|
3922
4027
|
return;
|
|
3923
4028
|
}
|
|
3924
|
-
const o = await j.decrypt(s.content,
|
|
3925
|
-
if (!a.tags || !a.tags.some(([
|
|
4029
|
+
const o = await j.decrypt(s.content, Xe(this.inviterSessionPrivateKey, s.pubkey)), a = JSON.parse(o);
|
|
4030
|
+
if (!a.tags || !a.tags.some(([p, h]) => p === "secret" && h === this.linkSecret)) {
|
|
3926
4031
|
console.error("Invalid secret from event", s);
|
|
3927
4032
|
return;
|
|
3928
4033
|
}
|
|
3929
|
-
const c = typeof t == "function" ? t : (
|
|
4034
|
+
const c = typeof t == "function" ? t : (p, h) => Promise.resolve(j.decrypt(p, Xe(t, h))), l = a.pubkey;
|
|
3930
4035
|
this.usedBy.push(l);
|
|
3931
|
-
const f = await c(a.content, l), u =
|
|
3932
|
-
r(
|
|
4036
|
+
const f = await c(a.content, l), u = G(this.linkSecret), g = s.id, b = st.init(n, f, this.inviterSessionPrivateKey, !1, u, g);
|
|
4037
|
+
r(b, l);
|
|
3933
4038
|
} catch (o) {
|
|
3934
|
-
console.error("Error processing invite message:", o);
|
|
4039
|
+
console.error("Error processing invite message:", o, "event", s);
|
|
3935
4040
|
}
|
|
3936
4041
|
});
|
|
3937
4042
|
}
|
|
3938
4043
|
}
|
|
3939
4044
|
export {
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
4045
|
+
jn as INVITE_EVENT_KIND,
|
|
4046
|
+
Me as Invite,
|
|
4047
|
+
nu as MAX_SKIP,
|
|
4048
|
+
Pe as MESSAGE_EVENT_KIND,
|
|
4049
|
+
Gc as Sender,
|
|
4050
|
+
st as Session,
|
|
4051
|
+
su as createMessageStream,
|
|
4052
|
+
iu as deserializeSessionState,
|
|
4053
|
+
Oe as kdf,
|
|
4054
|
+
ru as serializeSessionState,
|
|
4055
|
+
It as skippedMessageIndexKey
|
|
3951
4056
|
};
|