nostr-double-ratchet 0.0.6 → 0.0.8
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 +2 -1
- package/dist/Channel.d.ts +4 -0
- package/dist/Channel.d.ts.map +1 -1
- package/dist/{InviteLink.d.ts → Invite.d.ts} +10 -7
- package/dist/Invite.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/nostr-double-ratchet.es.js +1227 -1145
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/dist/types.d.ts +7 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/Channel.ts +73 -33
- package/src/{InviteLink.ts → Invite.ts} +73 -13
- package/src/index.ts +1 -1
- package/src/types.ts +9 -9
- package/src/utils.ts +12 -0
- package/dist/InviteLink.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var ee = (e, t, n) =>
|
|
4
|
-
function
|
|
1
|
+
var si = Object.defineProperty;
|
|
2
|
+
var ai = (e, t, n) => t in e ? si(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var ee = (e, t, n) => ai(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
function mn(e) {
|
|
5
5
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
6
6
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
7
7
|
}
|
|
@@ -11,10 +11,10 @@ function Pn(e, ...t) {
|
|
|
11
11
|
if (t.length > 0 && !t.includes(e.length))
|
|
12
12
|
throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function ci(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
|
+
mn(e.outputLen), mn(e.blockLen);
|
|
18
18
|
}
|
|
19
19
|
function rt(e, t = !0) {
|
|
20
20
|
if (e.destroyed)
|
|
@@ -22,94 +22,94 @@ function rt(e, t = !0) {
|
|
|
22
22
|
if (t && e.finished)
|
|
23
23
|
throw new Error("Hash#digest() has already been called");
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function li(e, t) {
|
|
26
26
|
Pn(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 At = 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 Mn = (e) => e instanceof Uint8Array, Kt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), ne = (e, t) => e << 32 - t | e >>> t, ui = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
34
|
+
if (!ui)
|
|
35
35
|
throw new Error("Non little-endian hardware is not supported");
|
|
36
|
-
function
|
|
36
|
+
function fi(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 Ft(e) {
|
|
42
|
+
if (typeof e == "string" && (e = fi(e)), !Mn(e))
|
|
43
43
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
44
44
|
return e;
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function hi(...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 (!Mn(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 Hn = 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 di(e) {
|
|
62
|
+
const t = (r) => e().update(Ft(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 qn(e = 32) {
|
|
66
|
+
if (At && typeof At.getRandomValues == "function")
|
|
67
|
+
return At.getRandomValues(new Uint8Array(e));
|
|
68
68
|
throw new Error("crypto.getRandomValues must be defined");
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function yi(e, t, n, r) {
|
|
71
71
|
if (typeof e.setBigUint64 == "function")
|
|
72
72
|
return e.setBigUint64(t, n, r);
|
|
73
|
-
const i = BigInt(32), o = BigInt(4294967295), s = Number(n >> i & o),
|
|
74
|
-
e.setUint32(t +
|
|
73
|
+
const i = BigInt(32), o = BigInt(4294967295), s = Number(n >> i & o), a = Number(n & o), c = r ? 4 : 0, l = r ? 0 : 4;
|
|
74
|
+
e.setUint32(t + c, s, r), e.setUint32(t + l, a, r);
|
|
75
75
|
}
|
|
76
|
-
let
|
|
76
|
+
let pi = class extends Hn {
|
|
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 = Kt(this.buffer);
|
|
79
79
|
}
|
|
80
80
|
update(t) {
|
|
81
81
|
rt(this);
|
|
82
82
|
const { view: n, buffer: r, blockLen: i } = this;
|
|
83
|
-
t =
|
|
83
|
+
t = Ft(t);
|
|
84
84
|
const o = t.length;
|
|
85
85
|
for (let s = 0; s < o; ) {
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
const
|
|
86
|
+
const a = Math.min(i - this.pos, o - s);
|
|
87
|
+
if (a === i) {
|
|
88
|
+
const c = Kt(t);
|
|
89
89
|
for (; i <= o - s; s += i)
|
|
90
|
-
this.process(
|
|
90
|
+
this.process(c, s);
|
|
91
91
|
continue;
|
|
92
92
|
}
|
|
93
|
-
r.set(t.subarray(s, s +
|
|
93
|
+
r.set(t.subarray(s, s + a), this.pos), this.pos += a, s += a, this.pos === i && (this.process(n, 0), this.pos = 0);
|
|
94
94
|
}
|
|
95
95
|
return this.length += t.length, this.roundClean(), this;
|
|
96
96
|
}
|
|
97
97
|
digestInto(t) {
|
|
98
|
-
rt(this),
|
|
98
|
+
rt(this), li(t, this), this.finished = !0;
|
|
99
99
|
const { buffer: n, view: r, blockLen: i, isLE: o } = this;
|
|
100
100
|
let { pos: s } = this;
|
|
101
101
|
n[s++] = 128, this.buffer.subarray(s).fill(0), this.padOffset > i - s && (this.process(r, 0), s = 0);
|
|
102
102
|
for (let u = s; u < i; u++)
|
|
103
103
|
n[u] = 0;
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
104
|
+
yi(r, i - 8, BigInt(this.length * 8), o), this.process(r, 0);
|
|
105
|
+
const a = Kt(t), c = this.outputLen;
|
|
106
|
+
if (c % 4)
|
|
107
107
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
108
|
-
const l =
|
|
108
|
+
const l = c / 4, f = this.get();
|
|
109
109
|
if (l > f.length)
|
|
110
110
|
throw new Error("_sha2: outputLen bigger than state");
|
|
111
111
|
for (let u = 0; u < l; u++)
|
|
112
|
-
|
|
112
|
+
a.setUint32(4 * u, f[u], o);
|
|
113
113
|
}
|
|
114
114
|
digest() {
|
|
115
115
|
const { buffer: t, outputLen: n } = this;
|
|
@@ -119,11 +119,11 @@ let yi = class extends Mn {
|
|
|
119
119
|
}
|
|
120
120
|
_cloneInto(t) {
|
|
121
121
|
t || (t = new this.constructor()), t.set(...this.get());
|
|
122
|
-
const { blockLen: n, buffer: r, length: i, finished: o, destroyed: s, pos:
|
|
123
|
-
return t.length = i, t.pos =
|
|
122
|
+
const { blockLen: n, buffer: r, length: i, finished: o, destroyed: s, pos: a } = this;
|
|
123
|
+
return t.length = i, t.pos = a, t.finished = o, t.destroyed = s, i % n && t.buffer.set(r), t;
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
|
-
const
|
|
126
|
+
const gi = (e, t, n) => e & t ^ ~e & n, wi = (e, t, n) => e & t ^ e & n ^ t & n, bi = /* @__PURE__ */ new Uint32Array([
|
|
127
127
|
1116352408,
|
|
128
128
|
1899447441,
|
|
129
129
|
3049323471,
|
|
@@ -198,17 +198,17 @@ const pi = (e, t, n) => e & t ^ ~e & n, gi = (e, t, n) => e & t ^ e & n ^ t & n,
|
|
|
198
198
|
528734635,
|
|
199
199
|
1541459225
|
|
200
200
|
]), we = /* @__PURE__ */ new Uint32Array(64);
|
|
201
|
-
let
|
|
201
|
+
let vi = class extends pi {
|
|
202
202
|
constructor() {
|
|
203
203
|
super(64, 32, 8, !1), this.A = ge[0] | 0, this.B = ge[1] | 0, this.C = ge[2] | 0, this.D = ge[3] | 0, this.E = ge[4] | 0, this.F = ge[5] | 0, this.G = ge[6] | 0, this.H = ge[7] | 0;
|
|
204
204
|
}
|
|
205
205
|
get() {
|
|
206
|
-
const { A: t, B: n, C: r, D: i, E: o, F: s, G:
|
|
207
|
-
return [t, n, r, i, o, s,
|
|
206
|
+
const { A: t, B: n, C: r, D: i, E: o, F: s, G: a, H: c } = this;
|
|
207
|
+
return [t, n, r, i, o, s, a, c];
|
|
208
208
|
}
|
|
209
209
|
// prettier-ignore
|
|
210
|
-
set(t, n, r, i, o, s,
|
|
211
|
-
this.A = t | 0, this.B = n | 0, this.C = r | 0, this.D = i | 0, this.E = o | 0, this.F = s | 0, this.G =
|
|
210
|
+
set(t, n, r, i, o, s, a, c) {
|
|
211
|
+
this.A = t | 0, this.B = n | 0, this.C = r | 0, this.D = i | 0, this.E = o | 0, this.F = s | 0, this.G = a | 0, this.H = c | 0;
|
|
212
212
|
}
|
|
213
213
|
process(t, n) {
|
|
214
214
|
for (let u = 0; u < 16; u++, n += 4)
|
|
@@ -217,12 +217,12 @@ let bi = class extends yi {
|
|
|
217
217
|
const d = we[u - 15], p = we[u - 2], g = ne(d, 7) ^ ne(d, 18) ^ d >>> 3, h = ne(p, 17) ^ ne(p, 19) ^ p >>> 10;
|
|
218
218
|
we[u] = h + we[u - 7] + g + we[u - 16] | 0;
|
|
219
219
|
}
|
|
220
|
-
let { A: r, B: i, C: o, D: s, E:
|
|
220
|
+
let { A: r, B: i, C: o, D: s, E: a, F: c, G: l, H: f } = this;
|
|
221
221
|
for (let u = 0; u < 64; u++) {
|
|
222
|
-
const d = ne(
|
|
223
|
-
f = l, l =
|
|
222
|
+
const d = ne(a, 6) ^ ne(a, 11) ^ ne(a, 25), p = f + d + gi(a, c, l) + bi[u] + we[u] | 0, h = (ne(r, 2) ^ ne(r, 13) ^ ne(r, 22)) + wi(r, i, o) | 0;
|
|
223
|
+
f = l, l = c, c = a, a = s + p | 0, s = o, o = i, i = r, r = p + h | 0;
|
|
224
224
|
}
|
|
225
|
-
r = r + this.A | 0, i = i + this.B | 0, o = o + this.C | 0, s = s + this.D | 0,
|
|
225
|
+
r = r + this.A | 0, i = i + this.B | 0, o = o + this.C | 0, s = s + 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, o, s, a, c, l, f);
|
|
226
226
|
}
|
|
227
227
|
roundClean() {
|
|
228
228
|
we.fill(0);
|
|
@@ -231,27 +231,27 @@ let bi = class extends yi {
|
|
|
231
231
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
|
|
232
232
|
}
|
|
233
233
|
};
|
|
234
|
-
const
|
|
234
|
+
const $t = /* @__PURE__ */ di(() => new vi());
|
|
235
235
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
236
|
-
const
|
|
237
|
-
function
|
|
236
|
+
const Dn = BigInt(0), lt = BigInt(1), Ei = BigInt(2), ut = (e) => e instanceof Uint8Array, mi = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
237
|
+
function qe(e) {
|
|
238
238
|
if (!ut(e))
|
|
239
239
|
throw new Error("Uint8Array expected");
|
|
240
240
|
let t = "";
|
|
241
241
|
for (let n = 0; n < e.length; n++)
|
|
242
|
-
t +=
|
|
242
|
+
t += mi[e[n]];
|
|
243
243
|
return t;
|
|
244
244
|
}
|
|
245
|
-
function
|
|
245
|
+
function jn(e) {
|
|
246
246
|
const t = e.toString(16);
|
|
247
247
|
return t.length & 1 ? `0${t}` : t;
|
|
248
248
|
}
|
|
249
|
-
function
|
|
249
|
+
function Wt(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}`);
|
|
253
253
|
}
|
|
254
|
-
function
|
|
254
|
+
function De(e) {
|
|
255
255
|
if (typeof e != "string")
|
|
256
256
|
throw new Error("hex string expected, got " + typeof e);
|
|
257
257
|
const t = e.length;
|
|
@@ -267,27 +267,27 @@ function qe(e) {
|
|
|
267
267
|
return n;
|
|
268
268
|
}
|
|
269
269
|
function G(e) {
|
|
270
|
-
return
|
|
270
|
+
return Wt(qe(e));
|
|
271
271
|
}
|
|
272
|
-
function
|
|
272
|
+
function Gt(e) {
|
|
273
273
|
if (!ut(e))
|
|
274
274
|
throw new Error("Uint8Array expected");
|
|
275
|
-
return
|
|
275
|
+
return Wt(qe(Uint8Array.from(e).reverse()));
|
|
276
276
|
}
|
|
277
277
|
function xe(e, t) {
|
|
278
|
-
return
|
|
278
|
+
return De(e.toString(16).padStart(t * 2, "0"));
|
|
279
279
|
}
|
|
280
|
-
function
|
|
280
|
+
function Jt(e, t) {
|
|
281
281
|
return xe(e, t).reverse();
|
|
282
282
|
}
|
|
283
|
-
function
|
|
284
|
-
return
|
|
283
|
+
function xi(e) {
|
|
284
|
+
return De(jn(e));
|
|
285
285
|
}
|
|
286
286
|
function Z(e, t, n) {
|
|
287
287
|
let r;
|
|
288
288
|
if (typeof t == "string")
|
|
289
289
|
try {
|
|
290
|
-
r =
|
|
290
|
+
r = De(t);
|
|
291
291
|
} catch (o) {
|
|
292
292
|
throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${o}`);
|
|
293
293
|
}
|
|
@@ -300,7 +300,7 @@ 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 Be(...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) => {
|
|
@@ -309,7 +309,7 @@ function Ie(...e) {
|
|
|
309
309
|
t.set(r, n), n += r.length;
|
|
310
310
|
}), t;
|
|
311
311
|
}
|
|
312
|
-
function
|
|
312
|
+
function Si(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 Ai(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 Ki(e) {
|
|
326
326
|
let t;
|
|
327
|
-
for (t = 0; e >
|
|
327
|
+
for (t = 0; e > Dn; e >>= lt, t += 1)
|
|
328
328
|
;
|
|
329
329
|
return t;
|
|
330
330
|
}
|
|
331
|
-
function
|
|
331
|
+
function Ni(e, t) {
|
|
332
332
|
return e >> BigInt(t) & lt;
|
|
333
333
|
}
|
|
334
|
-
const
|
|
335
|
-
function
|
|
334
|
+
const Ci = (e, t, n) => e | (n ? lt : Dn) << BigInt(t), Yt = (e) => (Ei << BigInt(e - 1)) - lt, Nt = (e) => new Uint8Array(e), xn = (e) => Uint8Array.from(e);
|
|
335
|
+
function Vn(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 = Nt(e), i = Nt(e), o = 0;
|
|
343
343
|
const s = () => {
|
|
344
344
|
r.fill(1), i.fill(0), o = 0;
|
|
345
|
-
},
|
|
346
|
-
i =
|
|
345
|
+
}, a = (...u) => n(i, r, ...u), c = (u = Nt()) => {
|
|
346
|
+
i = a(xn([0]), u), r = a(), u.length !== 0 && (i = a(xn([1]), u), r = a());
|
|
347
347
|
}, l = () => {
|
|
348
348
|
if (o++ >= 1e3)
|
|
349
349
|
throw new Error("drbg: tried 1000 values");
|
|
350
350
|
let u = 0;
|
|
351
351
|
const d = [];
|
|
352
352
|
for (; u < t; ) {
|
|
353
|
-
r =
|
|
353
|
+
r = a();
|
|
354
354
|
const p = r.slice();
|
|
355
355
|
d.push(p), u += r.length;
|
|
356
356
|
}
|
|
357
|
-
return
|
|
357
|
+
return Be(...d);
|
|
358
358
|
};
|
|
359
359
|
return (u, d) => {
|
|
360
|
-
s(),
|
|
360
|
+
s(), c(u);
|
|
361
361
|
let p;
|
|
362
362
|
for (; !(p = d(l())); )
|
|
363
|
-
|
|
363
|
+
c();
|
|
364
364
|
return s(), p;
|
|
365
365
|
};
|
|
366
366
|
}
|
|
367
|
-
const
|
|
367
|
+
const ki = {
|
|
368
368
|
bigint: (e) => typeof e == "bigint",
|
|
369
369
|
function: (e) => typeof e == "function",
|
|
370
370
|
boolean: (e) => typeof e == "boolean",
|
|
@@ -375,14 +375,14 @@ const Bi = {
|
|
|
375
375
|
field: (e, t) => t.Fp.isValid(e),
|
|
376
376
|
hash: (e) => typeof e == "function" && Number.isSafeInteger(e.outputLen)
|
|
377
377
|
};
|
|
378
|
-
function
|
|
378
|
+
function Ye(e, t, n = {}) {
|
|
379
379
|
const r = (i, o, s) => {
|
|
380
|
-
const
|
|
381
|
-
if (typeof
|
|
380
|
+
const a = ki[o];
|
|
381
|
+
if (typeof a != "function")
|
|
382
382
|
throw new Error(`Invalid validator "${o}", expected function`);
|
|
383
|
-
const
|
|
384
|
-
if (!(s &&
|
|
385
|
-
throw new Error(`Invalid param ${String(i)}=${
|
|
383
|
+
const c = e[i];
|
|
384
|
+
if (!(s && c === void 0) && !a(c, e))
|
|
385
|
+
throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${o}`);
|
|
386
386
|
};
|
|
387
387
|
for (const [i, o] of Object.entries(t))
|
|
388
388
|
r(i, o, !1);
|
|
@@ -390,100 +390,100 @@ function Je(e, t, n = {}) {
|
|
|
390
390
|
r(i, o, !0);
|
|
391
391
|
return e;
|
|
392
392
|
}
|
|
393
|
-
const
|
|
393
|
+
const Bi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
394
394
|
__proto__: null,
|
|
395
|
-
bitGet:
|
|
396
|
-
bitLen:
|
|
397
|
-
bitMask:
|
|
398
|
-
bitSet:
|
|
399
|
-
bytesToHex:
|
|
395
|
+
bitGet: Ni,
|
|
396
|
+
bitLen: Ki,
|
|
397
|
+
bitMask: Yt,
|
|
398
|
+
bitSet: Ci,
|
|
399
|
+
bytesToHex: qe,
|
|
400
400
|
bytesToNumberBE: G,
|
|
401
|
-
bytesToNumberLE:
|
|
402
|
-
concatBytes:
|
|
403
|
-
createHmacDrbg:
|
|
401
|
+
bytesToNumberLE: Gt,
|
|
402
|
+
concatBytes: Be,
|
|
403
|
+
createHmacDrbg: Vn,
|
|
404
404
|
ensureBytes: Z,
|
|
405
|
-
equalBytes:
|
|
406
|
-
hexToBytes:
|
|
407
|
-
hexToNumber:
|
|
405
|
+
equalBytes: Si,
|
|
406
|
+
hexToBytes: De,
|
|
407
|
+
hexToNumber: Wt,
|
|
408
408
|
numberToBytesBE: xe,
|
|
409
|
-
numberToBytesLE:
|
|
410
|
-
numberToHexUnpadded:
|
|
411
|
-
numberToVarBytesBE:
|
|
412
|
-
utf8ToBytes:
|
|
413
|
-
validateObject:
|
|
409
|
+
numberToBytesLE: Jt,
|
|
410
|
+
numberToHexUnpadded: jn,
|
|
411
|
+
numberToVarBytesBE: xi,
|
|
412
|
+
utf8ToBytes: Ai,
|
|
413
|
+
validateObject: Ye
|
|
414
414
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
415
415
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
416
|
-
const
|
|
416
|
+
const V = BigInt(0), q = BigInt(1), Ne = BigInt(2), Ui = BigInt(3), Rt = BigInt(4), Sn = BigInt(5), An = BigInt(8);
|
|
417
417
|
BigInt(9);
|
|
418
418
|
BigInt(16);
|
|
419
|
-
function
|
|
419
|
+
function z(e, t) {
|
|
420
420
|
const n = e % t;
|
|
421
|
-
return n >=
|
|
421
|
+
return n >= V ? n : t + n;
|
|
422
422
|
}
|
|
423
|
-
function
|
|
424
|
-
if (n <=
|
|
423
|
+
function Ii(e, t, n) {
|
|
424
|
+
if (n <= V || t < V)
|
|
425
425
|
throw new Error("Expected power/modulo > 0");
|
|
426
426
|
if (n === q)
|
|
427
|
-
return
|
|
427
|
+
return V;
|
|
428
428
|
let r = q;
|
|
429
|
-
for (; t >
|
|
429
|
+
for (; t > V; )
|
|
430
430
|
t & q && (r = r * e % n), e = e * e % n, t >>= q;
|
|
431
431
|
return r;
|
|
432
432
|
}
|
|
433
433
|
function J(e, t, n) {
|
|
434
434
|
let r = e;
|
|
435
|
-
for (; t-- >
|
|
435
|
+
for (; t-- > V; )
|
|
436
436
|
r *= r, r %= n;
|
|
437
437
|
return r;
|
|
438
438
|
}
|
|
439
|
-
function
|
|
440
|
-
if (e ===
|
|
439
|
+
function Ot(e, t) {
|
|
440
|
+
if (e === V || t <= V)
|
|
441
441
|
throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);
|
|
442
|
-
let n =
|
|
443
|
-
for (; n !==
|
|
444
|
-
const
|
|
445
|
-
r = n, n =
|
|
442
|
+
let n = z(e, t), r = t, i = V, o = q;
|
|
443
|
+
for (; n !== V; ) {
|
|
444
|
+
const a = r / n, c = r % n, l = i - o * a;
|
|
445
|
+
r = n, n = c, i = o, o = l;
|
|
446
446
|
}
|
|
447
447
|
if (r !== q)
|
|
448
448
|
throw new Error("invert: does not exist");
|
|
449
|
-
return
|
|
449
|
+
return z(i, t);
|
|
450
450
|
}
|
|
451
|
-
function
|
|
451
|
+
function _i(e) {
|
|
452
452
|
const t = (e - q) / Ne;
|
|
453
453
|
let n, r, i;
|
|
454
|
-
for (n = e - q, r = 0; n % Ne ===
|
|
454
|
+
for (n = e - q, r = 0; n % Ne === V; n /= Ne, r++)
|
|
455
455
|
;
|
|
456
|
-
for (i = Ne; i < e &&
|
|
456
|
+
for (i = Ne; i < e && Ii(i, t, e) !== e - q; i++)
|
|
457
457
|
;
|
|
458
458
|
if (r === 1) {
|
|
459
|
-
const s = (e + q) /
|
|
460
|
-
return function(
|
|
461
|
-
const f =
|
|
462
|
-
if (!
|
|
459
|
+
const s = (e + q) / Rt;
|
|
460
|
+
return function(c, l) {
|
|
461
|
+
const f = c.pow(l, s);
|
|
462
|
+
if (!c.eql(c.sqr(f), l))
|
|
463
463
|
throw new Error("Cannot find square root");
|
|
464
464
|
return f;
|
|
465
465
|
};
|
|
466
466
|
}
|
|
467
467
|
const o = (n + q) / Ne;
|
|
468
|
-
return function(
|
|
469
|
-
if (
|
|
468
|
+
return function(a, c) {
|
|
469
|
+
if (a.pow(c, t) === a.neg(a.ONE))
|
|
470
470
|
throw new Error("Cannot find square root");
|
|
471
|
-
let l = r, f =
|
|
472
|
-
for (; !
|
|
473
|
-
if (
|
|
474
|
-
return
|
|
471
|
+
let l = r, f = a.pow(a.mul(a.ONE, i), n), u = a.pow(c, o), d = a.pow(c, n);
|
|
472
|
+
for (; !a.eql(d, a.ONE); ) {
|
|
473
|
+
if (a.eql(d, a.ZERO))
|
|
474
|
+
return a.ZERO;
|
|
475
475
|
let p = 1;
|
|
476
|
-
for (let h =
|
|
477
|
-
h =
|
|
478
|
-
const g =
|
|
479
|
-
f =
|
|
476
|
+
for (let h = a.sqr(d); p < l && !a.eql(h, a.ONE); p++)
|
|
477
|
+
h = a.sqr(h);
|
|
478
|
+
const g = a.pow(f, q << BigInt(l - p - 1));
|
|
479
|
+
f = a.sqr(g), u = a.mul(u, g), d = a.mul(d, f), l = p;
|
|
480
480
|
}
|
|
481
481
|
return u;
|
|
482
482
|
};
|
|
483
483
|
}
|
|
484
|
-
function
|
|
485
|
-
if (e %
|
|
486
|
-
const t = (e + q) /
|
|
484
|
+
function Li(e) {
|
|
485
|
+
if (e % Rt === Ui) {
|
|
486
|
+
const t = (e + q) / Rt;
|
|
487
487
|
return function(r, i) {
|
|
488
488
|
const o = r.pow(i, t);
|
|
489
489
|
if (!r.eql(r.sqr(o), i))
|
|
@@ -491,18 +491,18 @@ function _i(e) {
|
|
|
491
491
|
return o;
|
|
492
492
|
};
|
|
493
493
|
}
|
|
494
|
-
if (e %
|
|
495
|
-
const t = (e -
|
|
494
|
+
if (e % An === Sn) {
|
|
495
|
+
const t = (e - Sn) / An;
|
|
496
496
|
return function(r, i) {
|
|
497
|
-
const o = r.mul(i, Ne), s = r.pow(o, t),
|
|
497
|
+
const o = r.mul(i, Ne), s = r.pow(o, t), a = r.mul(i, s), c = r.mul(r.mul(a, Ne), s), 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 _i(e);
|
|
504
504
|
}
|
|
505
|
-
const
|
|
505
|
+
const Ti = [
|
|
506
506
|
"create",
|
|
507
507
|
"isValid",
|
|
508
508
|
"is0",
|
|
@@ -527,98 +527,98 @@ function $i(e) {
|
|
|
527
527
|
MASK: "bigint",
|
|
528
528
|
BYTES: "isSafeInteger",
|
|
529
529
|
BITS: "isSafeInteger"
|
|
530
|
-
}, n =
|
|
531
|
-
return
|
|
530
|
+
}, n = Ti.reduce((r, i) => (r[i] = "function", r), t);
|
|
531
|
+
return Ye(e, n);
|
|
532
532
|
}
|
|
533
|
-
function
|
|
534
|
-
if (n <
|
|
533
|
+
function Ri(e, t, n) {
|
|
534
|
+
if (n < V)
|
|
535
535
|
throw new Error("Expected power > 0");
|
|
536
|
-
if (n ===
|
|
536
|
+
if (n === V)
|
|
537
537
|
return e.ONE;
|
|
538
538
|
if (n === q)
|
|
539
539
|
return t;
|
|
540
540
|
let r = e.ONE, i = t;
|
|
541
|
-
for (; n >
|
|
541
|
+
for (; n > V; )
|
|
542
542
|
n & q && (r = e.mul(r, i)), i = e.sqr(i), n >>= q;
|
|
543
543
|
return r;
|
|
544
544
|
}
|
|
545
|
-
function
|
|
546
|
-
const n = new Array(t.length), r = t.reduce((o, s,
|
|
547
|
-
return t.reduceRight((o, s,
|
|
545
|
+
function Oi(e, t) {
|
|
546
|
+
const n = new Array(t.length), r = t.reduce((o, s, a) => e.is0(s) ? o : (n[a] = o, e.mul(o, s)), e.ONE), i = e.inv(r);
|
|
547
|
+
return t.reduceRight((o, s, a) => e.is0(s) ? o : (n[a] = e.mul(o, n[a]), e.mul(o, s)), i), n;
|
|
548
548
|
}
|
|
549
549
|
function zn(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
553
|
function Pi(e, t, n = !1, r = {}) {
|
|
554
|
-
if (e <=
|
|
554
|
+
if (e <= V)
|
|
555
555
|
throw new Error(`Expected Field ORDER > 0, got ${e}`);
|
|
556
556
|
const { nBitLength: i, nByteLength: o } = zn(e, t);
|
|
557
557
|
if (o > 2048)
|
|
558
558
|
throw new Error("Field lengths over 2048 bytes are not supported");
|
|
559
|
-
const s =
|
|
559
|
+
const s = Li(e), a = Object.freeze({
|
|
560
560
|
ORDER: e,
|
|
561
561
|
BITS: i,
|
|
562
562
|
BYTES: o,
|
|
563
|
-
MASK:
|
|
564
|
-
ZERO:
|
|
563
|
+
MASK: Yt(i),
|
|
564
|
+
ZERO: V,
|
|
565
565
|
ONE: q,
|
|
566
|
-
create: (
|
|
567
|
-
isValid: (
|
|
568
|
-
if (typeof
|
|
569
|
-
throw new Error(`Invalid field element: expected bigint, got ${typeof
|
|
570
|
-
return
|
|
566
|
+
create: (c) => z(c, e),
|
|
567
|
+
isValid: (c) => {
|
|
568
|
+
if (typeof c != "bigint")
|
|
569
|
+
throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);
|
|
570
|
+
return V <= c && c < e;
|
|
571
571
|
},
|
|
572
|
-
is0: (
|
|
573
|
-
isOdd: (
|
|
574
|
-
neg: (
|
|
575
|
-
eql: (
|
|
576
|
-
sqr: (
|
|
577
|
-
add: (
|
|
578
|
-
sub: (
|
|
579
|
-
mul: (
|
|
580
|
-
pow: (
|
|
581
|
-
div: (
|
|
572
|
+
is0: (c) => c === V,
|
|
573
|
+
isOdd: (c) => (c & q) === q,
|
|
574
|
+
neg: (c) => z(-c, e),
|
|
575
|
+
eql: (c, l) => c === l,
|
|
576
|
+
sqr: (c) => z(c * c, e),
|
|
577
|
+
add: (c, l) => z(c + l, e),
|
|
578
|
+
sub: (c, l) => z(c - l, e),
|
|
579
|
+
mul: (c, l) => z(c * l, e),
|
|
580
|
+
pow: (c, l) => Ri(a, c, l),
|
|
581
|
+
div: (c, l) => z(c * Ot(l, e), e),
|
|
582
582
|
// Same as above, but doesn't normalize
|
|
583
|
-
sqrN: (
|
|
584
|
-
addN: (
|
|
585
|
-
subN: (
|
|
586
|
-
mulN: (
|
|
587
|
-
inv: (
|
|
588
|
-
sqrt: r.sqrt || ((
|
|
589
|
-
invertBatch: (
|
|
583
|
+
sqrN: (c) => c * c,
|
|
584
|
+
addN: (c, l) => c + l,
|
|
585
|
+
subN: (c, l) => c - l,
|
|
586
|
+
mulN: (c, l) => c * l,
|
|
587
|
+
inv: (c) => Ot(c, e),
|
|
588
|
+
sqrt: r.sqrt || ((c) => s(a, c)),
|
|
589
|
+
invertBatch: (c) => Oi(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
|
-
cmov: (
|
|
593
|
-
toBytes: (
|
|
594
|
-
fromBytes: (
|
|
595
|
-
if (
|
|
596
|
-
throw new Error(`Fp.fromBytes: expected ${o}, got ${
|
|
597
|
-
return n ?
|
|
592
|
+
cmov: (c, l, f) => f ? l : c,
|
|
593
|
+
toBytes: (c) => n ? Jt(c, o) : xe(c, o),
|
|
594
|
+
fromBytes: (c) => {
|
|
595
|
+
if (c.length !== o)
|
|
596
|
+
throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);
|
|
597
|
+
return n ? Gt(c) : G(c);
|
|
598
598
|
}
|
|
599
599
|
});
|
|
600
|
-
return Object.freeze(
|
|
600
|
+
return Object.freeze(a);
|
|
601
601
|
}
|
|
602
|
-
function
|
|
602
|
+
function Zn(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 Fn(e) {
|
|
609
|
+
const t = Zn(e);
|
|
610
610
|
return t + Math.ceil(t / 2);
|
|
611
611
|
}
|
|
612
|
-
function
|
|
613
|
-
const r = e.length, i =
|
|
612
|
+
function Mi(e, t, n = !1) {
|
|
613
|
+
const r = e.length, i = Zn(t), o = Fn(t);
|
|
614
614
|
if (r < 16 || r < o || r > 1024)
|
|
615
615
|
throw new Error(`expected ${o}-1024 bytes of input, got ${r}`);
|
|
616
|
-
const s = n ? G(e) :
|
|
617
|
-
return n ?
|
|
616
|
+
const s = n ? G(e) : Gt(e), a = z(s, t - q) + q;
|
|
617
|
+
return n ? Jt(a, i) : xe(a, i);
|
|
618
618
|
}
|
|
619
619
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
620
|
-
const
|
|
621
|
-
function
|
|
620
|
+
const Hi = BigInt(0), Ct = BigInt(1);
|
|
621
|
+
function qi(e, t) {
|
|
622
622
|
const n = (i, o) => {
|
|
623
623
|
const s = o.negate();
|
|
624
624
|
return i ? s : o;
|
|
@@ -630,9 +630,9 @@ function Hi(e, t) {
|
|
|
630
630
|
constTimeNegate: n,
|
|
631
631
|
// non-const time multiplication ladder
|
|
632
632
|
unsafeLadder(i, o) {
|
|
633
|
-
let s = e.ZERO,
|
|
634
|
-
for (; o >
|
|
635
|
-
o &
|
|
633
|
+
let s = e.ZERO, a = i;
|
|
634
|
+
for (; o > Hi; )
|
|
635
|
+
o & Ct && (s = s.add(a)), a = a.double(), o >>= Ct;
|
|
636
636
|
return s;
|
|
637
637
|
},
|
|
638
638
|
/**
|
|
@@ -646,15 +646,15 @@ function Hi(e, t) {
|
|
|
646
646
|
* @returns precomputed point tables flattened to a single array
|
|
647
647
|
*/
|
|
648
648
|
precomputeWindow(i, o) {
|
|
649
|
-
const { windows: s, windowSize:
|
|
649
|
+
const { windows: s, windowSize: a } = r(o), c = [];
|
|
650
650
|
let l = i, f = l;
|
|
651
651
|
for (let u = 0; u < s; u++) {
|
|
652
|
-
f = l,
|
|
653
|
-
for (let d = 1; d <
|
|
654
|
-
f = f.add(l),
|
|
652
|
+
f = l, c.push(f);
|
|
653
|
+
for (let d = 1; d < a; d++)
|
|
654
|
+
f = f.add(l), c.push(f);
|
|
655
655
|
l = f.double();
|
|
656
656
|
}
|
|
657
|
-
return
|
|
657
|
+
return c;
|
|
658
658
|
},
|
|
659
659
|
/**
|
|
660
660
|
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
@@ -664,27 +664,27 @@ function Hi(e, t) {
|
|
|
664
664
|
* @returns real and fake (for const-time) points
|
|
665
665
|
*/
|
|
666
666
|
wNAF(i, o, s) {
|
|
667
|
-
const { windows:
|
|
667
|
+
const { windows: a, windowSize: c } = r(i);
|
|
668
668
|
let l = e.ZERO, f = e.BASE;
|
|
669
669
|
const u = BigInt(2 ** i - 1), d = 2 ** i, p = BigInt(i);
|
|
670
|
-
for (let g = 0; g <
|
|
671
|
-
const h = g *
|
|
670
|
+
for (let g = 0; g < a; g++) {
|
|
671
|
+
const h = g * c;
|
|
672
672
|
let y = Number(s & u);
|
|
673
|
-
s >>= p, y >
|
|
674
|
-
const w = h, m = h + Math.abs(y) - 1, K = g % 2 !== 0,
|
|
675
|
-
y === 0 ? f = f.add(n(K, o[w])) : l = l.add(n(
|
|
673
|
+
s >>= p, y > c && (y -= d, s += Ct);
|
|
674
|
+
const w = h, m = h + Math.abs(y) - 1, K = g % 2 !== 0, I = y < 0;
|
|
675
|
+
y === 0 ? f = f.add(n(K, o[w])) : l = l.add(n(I, o[m]));
|
|
676
676
|
}
|
|
677
677
|
return { p: l, f };
|
|
678
678
|
},
|
|
679
|
-
wNAFCached(i, o, s,
|
|
680
|
-
const
|
|
679
|
+
wNAFCached(i, o, s, a) {
|
|
680
|
+
const c = i._WINDOW_SIZE || 1;
|
|
681
681
|
let l = o.get(i);
|
|
682
|
-
return l || (l = this.precomputeWindow(i,
|
|
682
|
+
return l || (l = this.precomputeWindow(i, c), c !== 1 && o.set(i, a(l))), this.wNAF(c, l, s);
|
|
683
683
|
}
|
|
684
684
|
};
|
|
685
685
|
}
|
|
686
|
-
function
|
|
687
|
-
return $i(e.Fp),
|
|
686
|
+
function Wn(e) {
|
|
687
|
+
return $i(e.Fp), Ye(e, {
|
|
688
688
|
n: "bigint",
|
|
689
689
|
h: "bigint",
|
|
690
690
|
Gx: "field",
|
|
@@ -699,9 +699,9 @@ function Fn(e) {
|
|
|
699
699
|
});
|
|
700
700
|
}
|
|
701
701
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
702
|
-
function
|
|
703
|
-
const t =
|
|
704
|
-
|
|
702
|
+
function Di(e) {
|
|
703
|
+
const t = Wn(e);
|
|
704
|
+
Ye(t, {
|
|
705
705
|
a: "field",
|
|
706
706
|
b: "field"
|
|
707
707
|
}, {
|
|
@@ -722,7 +722,7 @@ function qi(e) {
|
|
|
722
722
|
}
|
|
723
723
|
return Object.freeze({ ...t });
|
|
724
724
|
}
|
|
725
|
-
const { bytesToNumberBE:
|
|
725
|
+
const { bytesToNumberBE: ji, hexToBytes: Vi } = Bi, Ce = {
|
|
726
726
|
// asn.1 DER encoding utils
|
|
727
727
|
Err: class extends Error {
|
|
728
728
|
constructor(t = "") {
|
|
@@ -730,7 +730,7 @@ const { bytesToNumberBE: Di, hexToBytes: ji } = Ci, Be = {
|
|
|
730
730
|
}
|
|
731
731
|
},
|
|
732
732
|
_parseInt(e) {
|
|
733
|
-
const { Err: t } =
|
|
733
|
+
const { Err: t } = Ce;
|
|
734
734
|
if (e.length < 2 || e[0] !== 2)
|
|
735
735
|
throw new t("Invalid signature integer tag");
|
|
736
736
|
const n = e[1], r = e.subarray(2, n + 2);
|
|
@@ -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: ji(r), l: e.subarray(n + 2) };
|
|
744
744
|
},
|
|
745
745
|
toSig(e) {
|
|
746
|
-
const { Err: t } =
|
|
746
|
+
const { Err: t } = Ce, n = typeof e == "string" ? Vi(e) : e;
|
|
747
747
|
if (!(n instanceof Uint8Array))
|
|
748
748
|
throw new Error("ui8a expected");
|
|
749
749
|
let r = n.length;
|
|
@@ -751,8 +751,8 @@ const { bytesToNumberBE: Di, hexToBytes: ji } = Ci, Be = {
|
|
|
751
751
|
throw new t("Invalid signature tag");
|
|
752
752
|
if (n[1] !== r - 2)
|
|
753
753
|
throw new t("Invalid signature: incorrect length");
|
|
754
|
-
const { d: i, l: o } =
|
|
755
|
-
if (
|
|
754
|
+
const { d: i, l: o } = Ce._parseInt(n.subarray(2)), { d: s, l: a } = Ce._parseInt(o);
|
|
755
|
+
if (a.length)
|
|
756
756
|
throw new t("Invalid signature: left bytes after parsing");
|
|
757
757
|
return { r: i, s };
|
|
758
758
|
},
|
|
@@ -760,17 +760,17 @@ const { bytesToNumberBE: Di, hexToBytes: ji } = Ci, Be = {
|
|
|
760
760
|
const t = (l) => Number.parseInt(l[0], 16) & 8 ? "00" + l : l, n = (l) => {
|
|
761
761
|
const f = l.toString(16);
|
|
762
762
|
return f.length & 1 ? `0${f}` : f;
|
|
763
|
-
}, r = t(n(e.s)), i = t(n(e.r)), o = r.length / 2, s = i.length / 2,
|
|
764
|
-
return `30${n(s + o + 4)}02${
|
|
763
|
+
}, r = t(n(e.s)), i = t(n(e.r)), o = r.length / 2, s = i.length / 2, a = n(o), c = n(s);
|
|
764
|
+
return `30${n(s + o + 4)}02${c}${i}02${a}${r}`;
|
|
765
765
|
}
|
|
766
766
|
}, ce = BigInt(0), Y = BigInt(1);
|
|
767
767
|
BigInt(2);
|
|
768
|
-
const
|
|
768
|
+
const Kn = BigInt(3);
|
|
769
769
|
BigInt(4);
|
|
770
770
|
function zi(e) {
|
|
771
|
-
const t =
|
|
771
|
+
const t = Di(e), { Fp: n } = t, r = t.toBytes || ((g, h, y) => {
|
|
772
772
|
const w = h.toAffine();
|
|
773
|
-
return
|
|
773
|
+
return Be(Uint8Array.from([4]), n.toBytes(w.x), n.toBytes(w.y));
|
|
774
774
|
}), i = t.fromBytes || ((g) => {
|
|
775
775
|
const h = g.subarray(1), y = n.fromBytes(h.subarray(0, n.BYTES)), w = n.fromBytes(h.subarray(n.BYTES, 2 * n.BYTES));
|
|
776
776
|
return { x: y, y: w };
|
|
@@ -784,14 +784,14 @@ function zi(e) {
|
|
|
784
784
|
function s(g) {
|
|
785
785
|
return typeof g == "bigint" && ce < g && g < t.n;
|
|
786
786
|
}
|
|
787
|
-
function
|
|
787
|
+
function a(g) {
|
|
788
788
|
if (!s(g))
|
|
789
789
|
throw new Error("Expected valid bigint: 0 < bigint < curve.n");
|
|
790
790
|
}
|
|
791
|
-
function
|
|
791
|
+
function c(g) {
|
|
792
792
|
const { allowedPrivateKeyLengths: h, nByteLength: y, wrapPrivateKey: w, n: m } = t;
|
|
793
793
|
if (h && typeof g != "bigint") {
|
|
794
|
-
if (g instanceof Uint8Array && (g =
|
|
794
|
+
if (g instanceof Uint8Array && (g = qe(g)), typeof g != "string" || !h.includes(g.length))
|
|
795
795
|
throw new Error("Invalid key");
|
|
796
796
|
g = g.padStart(y * 2, "0");
|
|
797
797
|
}
|
|
@@ -801,7 +801,7 @@ function zi(e) {
|
|
|
801
801
|
} catch {
|
|
802
802
|
throw new Error(`private key must be ${y} bytes, hex or bigint, not ${typeof g}`);
|
|
803
803
|
}
|
|
804
|
-
return w && (K =
|
|
804
|
+
return w && (K = z(K, m)), a(K), K;
|
|
805
805
|
}
|
|
806
806
|
const l = /* @__PURE__ */ new Map();
|
|
807
807
|
function f(g) {
|
|
@@ -854,7 +854,7 @@ function zi(e) {
|
|
|
854
854
|
}
|
|
855
855
|
// Multiplies generator point by privateKey.
|
|
856
856
|
static fromPrivateKey(h) {
|
|
857
|
-
return u.BASE.multiply(
|
|
857
|
+
return u.BASE.multiply(c(h));
|
|
858
858
|
}
|
|
859
859
|
// "Private method", don't use it directly
|
|
860
860
|
_setWindowSize(h) {
|
|
@@ -887,7 +887,7 @@ function zi(e) {
|
|
|
887
887
|
*/
|
|
888
888
|
equals(h) {
|
|
889
889
|
f(h);
|
|
890
|
-
const { px: y, py: w, pz: m } = this, { px: K, py:
|
|
890
|
+
const { px: y, py: w, pz: m } = this, { px: K, py: I, pz: k } = h, E = n.eql(n.mul(y, k), n.mul(K, m)), x = n.eql(n.mul(w, k), n.mul(I, m));
|
|
891
891
|
return E && x;
|
|
892
892
|
}
|
|
893
893
|
/**
|
|
@@ -901,9 +901,9 @@ function zi(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: y } = t, w = n.mul(y,
|
|
905
|
-
let
|
|
906
|
-
return N = n.add(N, N), x = n.mul(m,
|
|
904
|
+
const { a: h, b: y } = t, w = n.mul(y, Kn), { px: m, py: K, pz: I } = this;
|
|
905
|
+
let k = n.ZERO, E = n.ZERO, x = n.ZERO, S = n.mul(m, m), P = n.mul(K, K), U = n.mul(I, I), N = n.mul(m, K);
|
|
906
|
+
return N = n.add(N, N), x = n.mul(m, I), x = n.add(x, x), k = n.mul(h, x), E = n.mul(w, U), E = n.add(k, E), k = n.sub(P, E), E = n.add(P, E), E = n.mul(k, E), k = n.mul(N, k), x = n.mul(w, x), U = n.mul(h, U), N = n.sub(S, U), N = n.mul(h, N), N = n.add(N, x), x = n.add(S, S), S = n.add(x, S), S = n.add(S, U), S = n.mul(S, N), E = n.add(E, S), U = n.mul(K, I), U = n.add(U, U), S = n.mul(U, N), k = n.sub(k, S), x = n.mul(U, P), x = n.add(x, x), x = n.add(x, x), new u(k, E, x);
|
|
907
907
|
}
|
|
908
908
|
// Renes-Costello-Batina exception-free addition formula.
|
|
909
909
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
@@ -911,13 +911,13 @@ function zi(e) {
|
|
|
911
911
|
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
912
912
|
add(h) {
|
|
913
913
|
f(h);
|
|
914
|
-
const { px: y, py: w, pz: m } = this, { px: K, py:
|
|
914
|
+
const { px: y, py: w, pz: m } = this, { px: K, py: I, pz: k } = h;
|
|
915
915
|
let E = n.ZERO, x = n.ZERO, S = n.ZERO;
|
|
916
|
-
const
|
|
917
|
-
let N = n.mul(y, K),
|
|
918
|
-
H = n.mul(H, b), b = n.add(N,
|
|
919
|
-
let v = n.add(K,
|
|
920
|
-
return b = n.mul(b, v), v = n.add(N, R), b = n.sub(b, v), v = n.add(w, m), E = n.add(
|
|
916
|
+
const P = t.a, U = n.mul(t.b, Kn);
|
|
917
|
+
let N = n.mul(y, K), $ = n.mul(w, I), R = n.mul(m, k), H = n.add(y, w), b = n.add(K, I);
|
|
918
|
+
H = n.mul(H, b), b = n.add(N, $), H = n.sub(H, b), b = n.add(y, m);
|
|
919
|
+
let v = n.add(K, k);
|
|
920
|
+
return b = n.mul(b, v), v = n.add(N, R), b = n.sub(b, v), v = n.add(w, m), E = n.add(I, k), v = n.mul(v, E), E = n.add($, R), v = n.sub(v, E), S = n.mul(P, b), E = n.mul(U, R), S = n.add(E, S), E = n.sub($, S), S = n.add($, S), x = n.mul(E, S), $ = n.add(N, N), $ = n.add($, N), R = n.mul(P, R), b = n.mul(U, b), $ = n.add($, R), R = n.sub(N, R), R = n.mul(P, R), b = n.add(b, R), N = n.mul($, b), x = n.add(x, N), N = n.mul(v, b), E = n.mul(H, E), E = n.sub(E, N), N = n.mul(H, $), S = n.mul(v, S), S = n.add(S, N), new u(E, x, S);
|
|
921
921
|
}
|
|
922
922
|
subtract(h) {
|
|
923
923
|
return this.add(h.negate());
|
|
@@ -940,15 +940,15 @@ function zi(e) {
|
|
|
940
940
|
const y = u.ZERO;
|
|
941
941
|
if (h === ce)
|
|
942
942
|
return y;
|
|
943
|
-
if (
|
|
943
|
+
if (a(h), h === Y)
|
|
944
944
|
return this;
|
|
945
945
|
const { endo: w } = t;
|
|
946
946
|
if (!w)
|
|
947
947
|
return p.unsafeLadder(this, h);
|
|
948
|
-
let { k1neg: m, k1: K, k2neg:
|
|
949
|
-
for (; K > ce ||
|
|
950
|
-
K & Y && (E = E.add(S)),
|
|
951
|
-
return m && (E = E.negate()),
|
|
948
|
+
let { k1neg: m, k1: K, k2neg: I, k2: k } = w.splitScalar(h), E = y, x = y, S = this;
|
|
949
|
+
for (; K > ce || k > ce; )
|
|
950
|
+
K & Y && (E = E.add(S)), k & Y && (x = x.add(S)), S = S.double(), K >>= Y, k >>= Y;
|
|
951
|
+
return m && (E = E.negate()), I && (x = x.negate()), x = new u(n.mul(x.px, w.beta), x.py, x.pz), E.add(x);
|
|
952
952
|
}
|
|
953
953
|
/**
|
|
954
954
|
* Constant time multiplication.
|
|
@@ -960,16 +960,16 @@ function zi(e) {
|
|
|
960
960
|
* @returns New point
|
|
961
961
|
*/
|
|
962
962
|
multiply(h) {
|
|
963
|
-
|
|
963
|
+
a(h);
|
|
964
964
|
let y = h, w, m;
|
|
965
965
|
const { endo: K } = t;
|
|
966
966
|
if (K) {
|
|
967
|
-
const { k1neg:
|
|
968
|
-
let { p: S, f:
|
|
969
|
-
S = p.constTimeNegate(
|
|
967
|
+
const { k1neg: I, k1: k, k2neg: E, k2: x } = K.splitScalar(y);
|
|
968
|
+
let { p: S, f: P } = this.wNAF(k), { p: U, f: N } = this.wNAF(x);
|
|
969
|
+
S = p.constTimeNegate(I, S), U = p.constTimeNegate(E, U), U = new u(n.mul(U.px, K.beta), U.py, U.pz), w = S.add(U), m = P.add(N);
|
|
970
970
|
} else {
|
|
971
|
-
const { p:
|
|
972
|
-
w =
|
|
971
|
+
const { p: I, f: k } = this.wNAF(y);
|
|
972
|
+
w = I, m = k;
|
|
973
973
|
}
|
|
974
974
|
return u.normalizeZ([w, m])[0];
|
|
975
975
|
}
|
|
@@ -980,8 +980,8 @@ function zi(e) {
|
|
|
980
980
|
* @returns non-zero affine point
|
|
981
981
|
*/
|
|
982
982
|
multiplyAndAddUnsafe(h, y, w) {
|
|
983
|
-
const m = u.BASE, K = (
|
|
984
|
-
return
|
|
983
|
+
const m = u.BASE, K = (k, E) => E === ce || E === Y || !k.equals(m) ? k.multiplyUnsafe(E) : k.multiply(E), I = K(this, y).add(K(h, w));
|
|
984
|
+
return I.is0() ? void 0 : I;
|
|
985
985
|
}
|
|
986
986
|
// Converts Projective point to affine (x, y) coordinates.
|
|
987
987
|
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
@@ -989,12 +989,12 @@ function zi(e) {
|
|
|
989
989
|
toAffine(h) {
|
|
990
990
|
const { px: y, py: w, pz: m } = this, K = this.is0();
|
|
991
991
|
h == null && (h = K ? n.ONE : n.inv(m));
|
|
992
|
-
const
|
|
992
|
+
const I = n.mul(y, h), k = n.mul(w, h), E = n.mul(m, h);
|
|
993
993
|
if (K)
|
|
994
994
|
return { x: n.ZERO, y: n.ZERO };
|
|
995
995
|
if (!n.eql(E, n.ONE))
|
|
996
996
|
throw new Error("invZ was invalid");
|
|
997
|
-
return { x:
|
|
997
|
+
return { x: I, y: k };
|
|
998
998
|
}
|
|
999
999
|
isTorsionFree() {
|
|
1000
1000
|
const { h, isTorsionFree: y } = t;
|
|
@@ -1012,22 +1012,22 @@ function zi(e) {
|
|
|
1012
1012
|
return this.assertValidity(), r(u, this, h);
|
|
1013
1013
|
}
|
|
1014
1014
|
toHex(h = !0) {
|
|
1015
|
-
return
|
|
1015
|
+
return qe(this.toRawBytes(h));
|
|
1016
1016
|
}
|
|
1017
1017
|
}
|
|
1018
1018
|
u.BASE = new u(t.Gx, t.Gy, n.ONE), u.ZERO = new u(n.ZERO, n.ONE, n.ZERO);
|
|
1019
|
-
const d = t.nBitLength, p =
|
|
1019
|
+
const d = t.nBitLength, p = qi(u, t.endo ? Math.ceil(d / 2) : d);
|
|
1020
1020
|
return {
|
|
1021
1021
|
CURVE: t,
|
|
1022
1022
|
ProjectivePoint: u,
|
|
1023
|
-
normPrivateKeyToScalar:
|
|
1023
|
+
normPrivateKeyToScalar: c,
|
|
1024
1024
|
weierstrassEquation: o,
|
|
1025
1025
|
isWithinCurveOrder: s
|
|
1026
1026
|
};
|
|
1027
1027
|
}
|
|
1028
|
-
function
|
|
1029
|
-
const t =
|
|
1030
|
-
return
|
|
1028
|
+
function Zi(e) {
|
|
1029
|
+
const t = Wn(e);
|
|
1030
|
+
return Ye(t, {
|
|
1031
1031
|
hash: "hash",
|
|
1032
1032
|
hmac: "function",
|
|
1033
1033
|
randomBytes: "function"
|
|
@@ -1037,51 +1037,51 @@ function Vi(e) {
|
|
|
1037
1037
|
lowS: "boolean"
|
|
1038
1038
|
}), Object.freeze({ lowS: !0, ...t });
|
|
1039
1039
|
}
|
|
1040
|
-
function
|
|
1041
|
-
const t =
|
|
1040
|
+
function Fi(e) {
|
|
1041
|
+
const t = Zi(e), { Fp: n, n: r } = t, i = n.BYTES + 1, o = 2 * n.BYTES + 1;
|
|
1042
1042
|
function s(b) {
|
|
1043
1043
|
return ce < b && b < n.ORDER;
|
|
1044
1044
|
}
|
|
1045
|
-
function c(b) {
|
|
1046
|
-
return V(b, r);
|
|
1047
|
-
}
|
|
1048
1045
|
function a(b) {
|
|
1049
|
-
return
|
|
1046
|
+
return z(b, r);
|
|
1047
|
+
}
|
|
1048
|
+
function c(b) {
|
|
1049
|
+
return Ot(b, r);
|
|
1050
1050
|
}
|
|
1051
1051
|
const { ProjectivePoint: l, normPrivateKeyToScalar: f, weierstrassEquation: u, isWithinCurveOrder: d } = zi({
|
|
1052
1052
|
...t,
|
|
1053
1053
|
toBytes(b, v, A) {
|
|
1054
|
-
const
|
|
1055
|
-
return A ? _(Uint8Array.from([v.hasEvenY() ? 2 : 3]),
|
|
1054
|
+
const B = v.toAffine(), C = n.toBytes(B.x), _ = Be;
|
|
1055
|
+
return A ? _(Uint8Array.from([v.hasEvenY() ? 2 : 3]), C) : _(Uint8Array.from([4]), C, n.toBytes(B.y));
|
|
1056
1056
|
},
|
|
1057
1057
|
fromBytes(b) {
|
|
1058
|
-
const v = b.length, A = b[0],
|
|
1058
|
+
const v = b.length, A = b[0], B = b.subarray(1);
|
|
1059
1059
|
if (v === i && (A === 2 || A === 3)) {
|
|
1060
|
-
const
|
|
1061
|
-
if (!s(
|
|
1060
|
+
const C = G(B);
|
|
1061
|
+
if (!s(C))
|
|
1062
1062
|
throw new Error("Point is not on curve");
|
|
1063
|
-
const _ = u(
|
|
1064
|
-
let
|
|
1065
|
-
const
|
|
1066
|
-
return (A & 1) === 1 !==
|
|
1063
|
+
const _ = u(C);
|
|
1064
|
+
let O = n.sqrt(_);
|
|
1065
|
+
const T = (O & Y) === Y;
|
|
1066
|
+
return (A & 1) === 1 !== T && (O = n.neg(O)), { x: C, y: O };
|
|
1067
1067
|
} else if (v === o && A === 4) {
|
|
1068
|
-
const
|
|
1069
|
-
return { x:
|
|
1068
|
+
const C = n.fromBytes(B.subarray(0, n.BYTES)), _ = n.fromBytes(B.subarray(n.BYTES, 2 * n.BYTES));
|
|
1069
|
+
return { x: C, y: _ };
|
|
1070
1070
|
} else
|
|
1071
1071
|
throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`);
|
|
1072
1072
|
}
|
|
1073
|
-
}), p = (b) =>
|
|
1073
|
+
}), p = (b) => qe(xe(b, t.nByteLength));
|
|
1074
1074
|
function g(b) {
|
|
1075
1075
|
const v = r >> Y;
|
|
1076
1076
|
return b > v;
|
|
1077
1077
|
}
|
|
1078
1078
|
function h(b) {
|
|
1079
|
-
return g(b) ?
|
|
1079
|
+
return g(b) ? a(-b) : b;
|
|
1080
1080
|
}
|
|
1081
1081
|
const y = (b, v, A) => G(b.slice(v, A));
|
|
1082
1082
|
class w {
|
|
1083
|
-
constructor(v, A,
|
|
1084
|
-
this.r = v, this.s = A, this.recovery =
|
|
1083
|
+
constructor(v, A, B) {
|
|
1084
|
+
this.r = v, this.s = A, this.recovery = B, this.assertValidity();
|
|
1085
1085
|
}
|
|
1086
1086
|
// pair (bytes of r, bytes of s)
|
|
1087
1087
|
static fromCompact(v) {
|
|
@@ -1091,8 +1091,8 @@ function Zi(e) {
|
|
|
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 w(A,
|
|
1094
|
+
const { r: A, s: B } = Ce.toSig(Z("DER", v));
|
|
1095
|
+
return new w(A, B);
|
|
1096
1096
|
}
|
|
1097
1097
|
assertValidity() {
|
|
1098
1098
|
if (!d(this.r))
|
|
@@ -1104,13 +1104,13 @@ function Zi(e) {
|
|
|
1104
1104
|
return new w(this.r, this.s, v);
|
|
1105
1105
|
}
|
|
1106
1106
|
recoverPublicKey(v) {
|
|
1107
|
-
const { r: A, s:
|
|
1108
|
-
if (
|
|
1107
|
+
const { r: A, s: B, recovery: C } = this, _ = x(Z("msgHash", v));
|
|
1108
|
+
if (C == null || ![0, 1, 2, 3].includes(C))
|
|
1109
1109
|
throw new Error("recovery id invalid");
|
|
1110
|
-
const
|
|
1111
|
-
if (
|
|
1110
|
+
const O = C === 2 || C === 3 ? A + t.n : A;
|
|
1111
|
+
if (O >= n.ORDER)
|
|
1112
1112
|
throw new Error("recovery id 2 or 3 invalid");
|
|
1113
|
-
const
|
|
1113
|
+
const T = C & 1 ? "03" : "02", X = l.fromHex(T + p(O)), ye = c(O), Ie = a(-_ * ye), ze = a(B * ye), pe = l.BASE.multiplyAndAddUnsafe(X, Ie, ze);
|
|
1114
1114
|
if (!pe)
|
|
1115
1115
|
throw new Error("point at infinify");
|
|
1116
1116
|
return pe.assertValidity(), pe;
|
|
@@ -1120,18 +1120,18 @@ function Zi(e) {
|
|
|
1120
1120
|
return g(this.s);
|
|
1121
1121
|
}
|
|
1122
1122
|
normalizeS() {
|
|
1123
|
-
return this.hasHighS() ? new w(this.r,
|
|
1123
|
+
return this.hasHighS() ? new w(this.r, a(-this.s), this.recovery) : this;
|
|
1124
1124
|
}
|
|
1125
1125
|
// DER-encoded
|
|
1126
1126
|
toDERRawBytes() {
|
|
1127
|
-
return
|
|
1127
|
+
return De(this.toDERHex());
|
|
1128
1128
|
}
|
|
1129
1129
|
toDERHex() {
|
|
1130
|
-
return
|
|
1130
|
+
return Ce.hexFromSig({ r: this.r, s: this.s });
|
|
1131
1131
|
}
|
|
1132
1132
|
// padded bytes of r, then padded bytes of s
|
|
1133
1133
|
toCompactRawBytes() {
|
|
1134
|
-
return
|
|
1134
|
+
return De(this.toCompactHex());
|
|
1135
1135
|
}
|
|
1136
1136
|
toCompactHex() {
|
|
1137
1137
|
return p(this.r) + p(this.s);
|
|
@@ -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 b =
|
|
1155
|
-
return
|
|
1154
|
+
const b = Fn(t.n);
|
|
1155
|
+
return Mi(t.randomBytes(b), t.n);
|
|
1156
1156
|
},
|
|
1157
1157
|
/**
|
|
1158
1158
|
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
|
@@ -1169,14 +1169,14 @@ function Zi(e) {
|
|
|
1169
1169
|
function K(b, v = !0) {
|
|
1170
1170
|
return l.fromPrivateKey(b).toRawBytes(v);
|
|
1171
1171
|
}
|
|
1172
|
-
function
|
|
1173
|
-
const v = b instanceof Uint8Array, A = typeof b == "string",
|
|
1174
|
-
return v ?
|
|
1172
|
+
function I(b) {
|
|
1173
|
+
const v = b instanceof Uint8Array, A = typeof b == "string", B = (v || A) && b.length;
|
|
1174
|
+
return v ? B === i || B === o : A ? B === 2 * i || B === 2 * o : b instanceof l;
|
|
1175
1175
|
}
|
|
1176
|
-
function
|
|
1177
|
-
if (
|
|
1176
|
+
function k(b, v, A = !0) {
|
|
1177
|
+
if (I(b))
|
|
1178
1178
|
throw new Error("first arg must be private key");
|
|
1179
|
-
if (!
|
|
1179
|
+
if (!I(v))
|
|
1180
1180
|
throw new Error("second arg must be public key");
|
|
1181
1181
|
return l.fromHex(v).multiply(f(b)).toRawBytes(A);
|
|
1182
1182
|
}
|
|
@@ -1184,9 +1184,9 @@ function Zi(e) {
|
|
|
1184
1184
|
const v = G(b), A = b.length * 8 - t.nBitLength;
|
|
1185
1185
|
return A > 0 ? v >> BigInt(A) : v;
|
|
1186
1186
|
}, x = t.bits2int_modN || function(b) {
|
|
1187
|
-
return
|
|
1188
|
-
}, S =
|
|
1189
|
-
function
|
|
1187
|
+
return a(E(b));
|
|
1188
|
+
}, S = Yt(t.nBitLength);
|
|
1189
|
+
function P(b) {
|
|
1190
1190
|
if (typeof b != "bigint")
|
|
1191
1191
|
throw new Error("bigint expected");
|
|
1192
1192
|
if (!(ce <= b && b < S))
|
|
@@ -1196,55 +1196,55 @@ function Zi(e) {
|
|
|
1196
1196
|
function U(b, v, A = N) {
|
|
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: _, prehash:
|
|
1201
|
-
_ == null && (_ = !0), b = Z("msgHash", b),
|
|
1202
|
-
const X = x(b), ye = f(v),
|
|
1203
|
-
if (
|
|
1204
|
-
const Ke =
|
|
1205
|
-
|
|
1206
|
-
}
|
|
1207
|
-
const ze =
|
|
1208
|
-
function
|
|
1199
|
+
const { hash: B, randomBytes: C } = t;
|
|
1200
|
+
let { lowS: _, prehash: O, extraEntropy: T } = A;
|
|
1201
|
+
_ == null && (_ = !0), b = Z("msgHash", b), O && (b = Z("prehashed msgHash", B(b)));
|
|
1202
|
+
const X = x(b), ye = f(v), Ie = [P(ye), P(X)];
|
|
1203
|
+
if (T != null) {
|
|
1204
|
+
const Ke = T === !0 ? C(n.BYTES) : T;
|
|
1205
|
+
Ie.push(Z("extraEntropy", Ke));
|
|
1206
|
+
}
|
|
1207
|
+
const ze = Be(...Ie), pe = X;
|
|
1208
|
+
function St(Ke) {
|
|
1209
1209
|
const _e = E(Ke);
|
|
1210
1210
|
if (!d(_e))
|
|
1211
1211
|
return;
|
|
1212
|
-
const
|
|
1212
|
+
const bn = c(_e), Le = l.BASE.multiply(_e).toAffine(), Q = a(Le.x);
|
|
1213
1213
|
if (Q === ce)
|
|
1214
1214
|
return;
|
|
1215
|
-
const
|
|
1216
|
-
if (
|
|
1215
|
+
const Te = a(bn * a(pe + Q * ye));
|
|
1216
|
+
if (Te === ce)
|
|
1217
1217
|
return;
|
|
1218
|
-
let
|
|
1219
|
-
return _ && g(
|
|
1218
|
+
let vn = (Le.x === Q ? 0 : 2) | Number(Le.y & Y), En = Te;
|
|
1219
|
+
return _ && g(Te) && (En = h(Te), vn ^= 1), new w(Q, En, vn);
|
|
1220
1220
|
}
|
|
1221
|
-
return { seed: ze, k2sig:
|
|
1221
|
+
return { seed: ze, k2sig: St };
|
|
1222
1222
|
}
|
|
1223
|
-
const N = { lowS: t.lowS, prehash: !1 },
|
|
1223
|
+
const N = { lowS: t.lowS, prehash: !1 }, $ = { lowS: t.lowS, prehash: !1 };
|
|
1224
1224
|
function R(b, v, A = N) {
|
|
1225
|
-
const { seed:
|
|
1226
|
-
return
|
|
1225
|
+
const { seed: B, k2sig: C } = U(b, v, A), _ = t;
|
|
1226
|
+
return Vn(_.hash.outputLen, _.nByteLength, _.hmac)(B, C);
|
|
1227
1227
|
}
|
|
1228
1228
|
l.BASE._setWindowSize(8);
|
|
1229
|
-
function H(b, v, A,
|
|
1229
|
+
function H(b, v, A, B = $) {
|
|
1230
1230
|
var Le;
|
|
1231
|
-
const
|
|
1232
|
-
if (v = Z("msgHash", v), A = Z("publicKey", A), "strict" in
|
|
1231
|
+
const C = b;
|
|
1232
|
+
if (v = Z("msgHash", v), A = Z("publicKey", A), "strict" in B)
|
|
1233
1233
|
throw new Error("options.strict was renamed to lowS");
|
|
1234
|
-
const { lowS: _, prehash:
|
|
1235
|
-
let
|
|
1234
|
+
const { lowS: _, prehash: O } = B;
|
|
1235
|
+
let T, X;
|
|
1236
1236
|
try {
|
|
1237
|
-
if (typeof
|
|
1237
|
+
if (typeof C == "string" || C instanceof Uint8Array)
|
|
1238
1238
|
try {
|
|
1239
|
-
|
|
1239
|
+
T = w.fromDER(C);
|
|
1240
1240
|
} catch (Q) {
|
|
1241
|
-
if (!(Q instanceof
|
|
1241
|
+
if (!(Q instanceof Ce.Err))
|
|
1242
1242
|
throw Q;
|
|
1243
|
-
|
|
1243
|
+
T = w.fromCompact(C);
|
|
1244
1244
|
}
|
|
1245
|
-
else if (typeof
|
|
1246
|
-
const { r: Q, s:
|
|
1247
|
-
|
|
1245
|
+
else if (typeof C == "object" && typeof C.r == "bigint" && typeof C.s == "bigint") {
|
|
1246
|
+
const { r: Q, s: Te } = C;
|
|
1247
|
+
T = new w(Q, Te);
|
|
1248
1248
|
} else
|
|
1249
1249
|
throw new Error("PARSE");
|
|
1250
1250
|
X = l.fromHex(A);
|
|
@@ -1253,16 +1253,16 @@ function Zi(e) {
|
|
|
1253
1253
|
throw new Error("signature must be Signature instance, Uint8Array or hex string");
|
|
1254
1254
|
return !1;
|
|
1255
1255
|
}
|
|
1256
|
-
if (_ &&
|
|
1256
|
+
if (_ && T.hasHighS())
|
|
1257
1257
|
return !1;
|
|
1258
|
-
|
|
1259
|
-
const { r: ye, s:
|
|
1260
|
-
return _e ?
|
|
1258
|
+
O && (v = t.hash(v));
|
|
1259
|
+
const { r: ye, s: Ie } = T, ze = x(v), pe = c(Ie), St = a(ze * pe), Ke = a(ye * pe), _e = (Le = l.BASE.multiplyAndAddUnsafe(X, St, Ke)) == null ? void 0 : Le.toAffine();
|
|
1260
|
+
return _e ? a(_e.x) === ye : !1;
|
|
1261
1261
|
}
|
|
1262
1262
|
return {
|
|
1263
1263
|
CURVE: t,
|
|
1264
1264
|
getPublicKey: K,
|
|
1265
|
-
getSharedSecret:
|
|
1265
|
+
getSharedSecret: k,
|
|
1266
1266
|
sign: R,
|
|
1267
1267
|
verify: H,
|
|
1268
1268
|
ProjectivePoint: l,
|
|
@@ -1270,10 +1270,10 @@ function Zi(e) {
|
|
|
1270
1270
|
utils: m
|
|
1271
1271
|
};
|
|
1272
1272
|
}
|
|
1273
|
-
let
|
|
1273
|
+
let Gn = class extends Hn {
|
|
1274
1274
|
constructor(t, n) {
|
|
1275
|
-
super(), this.finished = !1, this.destroyed = !1,
|
|
1276
|
-
const r =
|
|
1275
|
+
super(), this.finished = !1, this.destroyed = !1, ci(t);
|
|
1276
|
+
const r = Ft(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;
|
|
@@ -1298,39 +1298,39 @@ let Wn = class extends Mn {
|
|
|
1298
1298
|
}
|
|
1299
1299
|
_cloneInto(t) {
|
|
1300
1300
|
t || (t = Object.create(Object.getPrototypeOf(this), {}));
|
|
1301
|
-
const { oHash: n, iHash: r, finished: i, destroyed: o, blockLen: s, outputLen:
|
|
1302
|
-
return t = t, t.finished = i, t.destroyed = o, t.blockLen = s, t.outputLen =
|
|
1301
|
+
const { oHash: n, iHash: r, finished: i, destroyed: o, blockLen: s, outputLen: a } = this;
|
|
1302
|
+
return t = t, t.finished = i, t.destroyed = o, t.blockLen = s, t.outputLen = a, t.oHash = n._cloneInto(t.oHash), t.iHash = r._cloneInto(t.iHash), t;
|
|
1303
1303
|
}
|
|
1304
1304
|
destroy() {
|
|
1305
1305
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
1306
1306
|
}
|
|
1307
1307
|
};
|
|
1308
|
-
const
|
|
1309
|
-
|
|
1308
|
+
const Jn = (e, t, n) => new Gn(e, t).update(n).digest();
|
|
1309
|
+
Jn.create = (e, t) => new Gn(e, t);
|
|
1310
1310
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1311
|
-
function
|
|
1311
|
+
function Wi(e) {
|
|
1312
1312
|
return {
|
|
1313
1313
|
hash: e,
|
|
1314
|
-
hmac: (t, ...n) =>
|
|
1315
|
-
randomBytes:
|
|
1314
|
+
hmac: (t, ...n) => Jn(e, t, hi(...n)),
|
|
1315
|
+
randomBytes: qn
|
|
1316
1316
|
};
|
|
1317
1317
|
}
|
|
1318
|
-
function
|
|
1319
|
-
const n = (r) =>
|
|
1318
|
+
function Gi(e, t) {
|
|
1319
|
+
const n = (r) => Fi({ ...e, ...Wi(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 ft = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), it = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
|
|
1324
|
-
function
|
|
1325
|
-
const t = ft, n = BigInt(3), r = BigInt(6), i = BigInt(11), o = BigInt(22), s = BigInt(23),
|
|
1326
|
-
if (!
|
|
1323
|
+
const ft = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), it = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), Yn = BigInt(1), ot = BigInt(2), Nn = (e, t) => (e + t / ot) / t;
|
|
1324
|
+
function Xn(e) {
|
|
1325
|
+
const t = ft, n = BigInt(3), r = BigInt(6), i = BigInt(11), o = BigInt(22), s = 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, d = J(u, n, t) * f % t, p = J(d, ot, t) * l % t, g = J(p, i, t) * p % t, h = J(g, o, t) * g % t, y = J(h, a, t) * h % t, w = J(y, c, t) * y % t, m = J(w, a, t) * h % t, K = J(m, n, t) * f % t, I = J(K, s, t) * g % t, k = J(I, r, t) * l % t, E = J(k, ot, t);
|
|
1326
|
+
if (!Pt.eql(Pt.sqr(E), e))
|
|
1327
1327
|
throw new Error("Cannot find square root");
|
|
1328
1328
|
return E;
|
|
1329
1329
|
}
|
|
1330
|
-
const
|
|
1330
|
+
const Pt = Pi(ft, void 0, void 0, { sqrt: Xn }), Ue = Gi({
|
|
1331
1331
|
a: BigInt(0),
|
|
1332
1332
|
b: BigInt(7),
|
|
1333
|
-
Fp:
|
|
1333
|
+
Fp: Pt,
|
|
1334
1334
|
n: it,
|
|
1335
1335
|
// Base point (x, y) aka generator point
|
|
1336
1336
|
Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
|
|
@@ -1346,92 +1346,92 @@ const Rt = Pi(ft, void 0, void 0, { sqrt: Yn }), Ue = Wi({
|
|
|
1346
1346
|
endo: {
|
|
1347
1347
|
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
1348
1348
|
splitScalar: (e) => {
|
|
1349
|
-
const t = it, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -
|
|
1350
|
-
let l =
|
|
1349
|
+
const t = it, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -Yn * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), o = n, s = BigInt("0x100000000000000000000000000000000"), a = Nn(o * e, t), c = Nn(-r * e, t);
|
|
1350
|
+
let l = z(e - a * n - c * i, t), f = z(-a * r - c * o, t);
|
|
1351
1351
|
const u = l > s, d = f > s;
|
|
1352
1352
|
if (u && (l = t - l), d && (f = t - f), l > s || f > s)
|
|
1353
1353
|
throw new Error("splitScalar: Endomorphism failed, k=" + e);
|
|
1354
1354
|
return { k1neg: u, k1: l, k2neg: d, k2: f };
|
|
1355
1355
|
}
|
|
1356
1356
|
}
|
|
1357
|
-
},
|
|
1357
|
+
}, $t), ht = BigInt(0), Qn = (e) => typeof e == "bigint" && ht < e && e < ft, Ji = (e) => typeof e == "bigint" && ht < e && e < it, Cn = {};
|
|
1358
1358
|
function st(e, ...t) {
|
|
1359
|
-
let n =
|
|
1359
|
+
let n = Cn[e];
|
|
1360
1360
|
if (n === void 0) {
|
|
1361
|
-
const r =
|
|
1362
|
-
n =
|
|
1361
|
+
const r = $t(Uint8Array.from(e, (i) => i.charCodeAt(0)));
|
|
1362
|
+
n = Be(r, r), Cn[e] = n;
|
|
1363
1363
|
}
|
|
1364
|
-
return
|
|
1364
|
+
return $t(Be(n, ...t));
|
|
1365
1365
|
}
|
|
1366
|
-
const
|
|
1367
|
-
function
|
|
1368
|
-
let t = Ue.utils.normPrivateKeyToScalar(e), n =
|
|
1369
|
-
return { scalar: n.hasEvenY() ? t :
|
|
1366
|
+
const Xt = (e) => e.toRawBytes(!0).slice(1), Mt = (e) => xe(e, 32), kt = (e) => z(e, ft), Ge = (e) => z(e, it), Qt = Ue.ProjectivePoint, Yi = (e, t, n) => Qt.BASE.multiplyAndAddUnsafe(e, t, n);
|
|
1367
|
+
function Ht(e) {
|
|
1368
|
+
let t = Ue.utils.normPrivateKeyToScalar(e), n = Qt.fromPrivateKey(t);
|
|
1369
|
+
return { scalar: n.hasEvenY() ? t : Ge(-t), bytes: Xt(n) };
|
|
1370
1370
|
}
|
|
1371
|
-
function
|
|
1372
|
-
if (!
|
|
1371
|
+
function er(e) {
|
|
1372
|
+
if (!Qn(e))
|
|
1373
1373
|
throw new Error("bad x: need 0 < x < p");
|
|
1374
|
-
const t =
|
|
1375
|
-
let r =
|
|
1376
|
-
r % ot !== ht && (r =
|
|
1377
|
-
const i = new
|
|
1374
|
+
const t = kt(e * e), n = kt(t * e + BigInt(7));
|
|
1375
|
+
let r = Xn(n);
|
|
1376
|
+
r % ot !== ht && (r = kt(-r));
|
|
1377
|
+
const i = new Qt(e, r, Yn);
|
|
1378
1378
|
return i.assertValidity(), i;
|
|
1379
1379
|
}
|
|
1380
|
-
function
|
|
1381
|
-
return
|
|
1380
|
+
function tr(...e) {
|
|
1381
|
+
return Ge(G(st("BIP0340/challenge", ...e)));
|
|
1382
1382
|
}
|
|
1383
|
-
function
|
|
1384
|
-
return
|
|
1383
|
+
function Xi(e) {
|
|
1384
|
+
return Ht(e).bytes;
|
|
1385
1385
|
}
|
|
1386
|
-
function
|
|
1387
|
-
const r = Z("message", e), { bytes: i, scalar: o } =
|
|
1386
|
+
function Qi(e, t, n = qn(32)) {
|
|
1387
|
+
const r = Z("message", e), { bytes: i, scalar: o } = Ht(t), s = Z("auxRand", n, 32), a = Mt(o ^ G(st("BIP0340/aux", s))), c = st("BIP0340/nonce", a, i, r), l = Ge(G(c));
|
|
1388
1388
|
if (l === ht)
|
|
1389
1389
|
throw new Error("sign failed: k is zero");
|
|
1390
|
-
const { bytes: f, scalar: u } =
|
|
1391
|
-
if (p.set(f, 0), p.set(
|
|
1390
|
+
const { bytes: f, scalar: u } = Ht(l), d = tr(f, i, r), p = new Uint8Array(64);
|
|
1391
|
+
if (p.set(f, 0), p.set(Mt(Ge(u + d * o)), 32), !nr(p, r, i))
|
|
1392
1392
|
throw new Error("sign: Invalid signature produced");
|
|
1393
1393
|
return p;
|
|
1394
1394
|
}
|
|
1395
|
-
function
|
|
1395
|
+
function nr(e, t, n) {
|
|
1396
1396
|
const r = Z("signature", e, 64), i = Z("message", t), o = Z("publicKey", n, 32);
|
|
1397
1397
|
try {
|
|
1398
|
-
const s =
|
|
1399
|
-
if (!
|
|
1398
|
+
const s = er(G(o)), a = G(r.subarray(0, 32));
|
|
1399
|
+
if (!Qn(a))
|
|
1400
1400
|
return !1;
|
|
1401
|
-
const
|
|
1402
|
-
if (!
|
|
1401
|
+
const c = G(r.subarray(32, 64));
|
|
1402
|
+
if (!Ji(c))
|
|
1403
1403
|
return !1;
|
|
1404
|
-
const l =
|
|
1405
|
-
return !(!f || !f.hasEvenY() || f.toAffine().x !==
|
|
1404
|
+
const l = tr(Mt(a), Xt(s), i), f = Yi(s, c, Ge(-l));
|
|
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 Ze = {
|
|
1411
|
+
getPublicKey: Xi,
|
|
1412
|
+
sign: Qi,
|
|
1413
|
+
verify: nr,
|
|
1414
1414
|
utils: {
|
|
1415
1415
|
randomPrivateKey: Ue.utils.randomPrivateKey,
|
|
1416
|
-
lift_x:
|
|
1417
|
-
pointToBytes:
|
|
1416
|
+
lift_x: er,
|
|
1417
|
+
pointToBytes: Xt,
|
|
1418
1418
|
numberToBytesBE: xe,
|
|
1419
1419
|
bytesToNumberBE: G,
|
|
1420
1420
|
taggedHash: st,
|
|
1421
|
-
mod:
|
|
1421
|
+
mod: z
|
|
1422
1422
|
}
|
|
1423
|
-
},
|
|
1423
|
+
}, Bt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
1424
1424
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1425
|
-
const
|
|
1426
|
-
if (!
|
|
1425
|
+
const en = (e) => e instanceof Uint8Array, Ut = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), re = (e, t) => e << 32 - t | e >>> t, eo = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1426
|
+
if (!eo)
|
|
1427
1427
|
throw new Error("Non little-endian hardware is not supported");
|
|
1428
|
-
const
|
|
1428
|
+
const to = Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
1429
1429
|
function M(e) {
|
|
1430
|
-
if (!
|
|
1430
|
+
if (!en(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 += to[e[n]];
|
|
1435
1435
|
return t;
|
|
1436
1436
|
}
|
|
1437
1437
|
function W(e) {
|
|
@@ -1449,13 +1449,13 @@ function W(e) {
|
|
|
1449
1449
|
}
|
|
1450
1450
|
return n;
|
|
1451
1451
|
}
|
|
1452
|
-
function
|
|
1452
|
+
function no(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 Je(e) {
|
|
1458
|
+
if (typeof e == "string" && (e = no(e)), !en(e))
|
|
1459
1459
|
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
1460
1460
|
return e;
|
|
1461
1461
|
}
|
|
@@ -1463,89 +1463,89 @@ function dt(...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) => {
|
|
1466
|
-
if (!
|
|
1466
|
+
if (!en(r))
|
|
1467
1467
|
throw new Error("Uint8Array expected");
|
|
1468
1468
|
t.set(r, n), n += r.length;
|
|
1469
1469
|
}), t;
|
|
1470
1470
|
}
|
|
1471
|
-
class
|
|
1471
|
+
class rr {
|
|
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 ir(e) {
|
|
1478
|
+
const t = (r) => e().update(Je(r)).digest(), n = e();
|
|
1479
1479
|
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
1480
1480
|
}
|
|
1481
|
-
function
|
|
1482
|
-
if (
|
|
1483
|
-
return
|
|
1481
|
+
function or(e = 32) {
|
|
1482
|
+
if (Bt && typeof Bt.getRandomValues == "function")
|
|
1483
|
+
return Bt.getRandomValues(new Uint8Array(e));
|
|
1484
1484
|
throw new Error("crypto.getRandomValues must be defined");
|
|
1485
1485
|
}
|
|
1486
|
-
function
|
|
1486
|
+
function qt(e) {
|
|
1487
1487
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
1488
1488
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
1489
1489
|
}
|
|
1490
|
-
function
|
|
1490
|
+
function ro(e) {
|
|
1491
1491
|
if (typeof e != "boolean")
|
|
1492
1492
|
throw new Error(`Expected boolean, not ${e}`);
|
|
1493
1493
|
}
|
|
1494
|
-
function
|
|
1494
|
+
function sr(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 io(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
|
+
qt(e.outputLen), qt(e.blockLen);
|
|
1504
1504
|
}
|
|
1505
|
-
function
|
|
1505
|
+
function oo(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 so(e, t) {
|
|
1512
|
+
sr(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 oe = {
|
|
1518
|
-
number:
|
|
1519
|
-
bool:
|
|
1520
|
-
bytes:
|
|
1521
|
-
hash:
|
|
1522
|
-
exists:
|
|
1523
|
-
output:
|
|
1518
|
+
number: qt,
|
|
1519
|
+
bool: ro,
|
|
1520
|
+
bytes: sr,
|
|
1521
|
+
hash: io,
|
|
1522
|
+
exists: oo,
|
|
1523
|
+
output: so
|
|
1524
1524
|
};
|
|
1525
|
-
function
|
|
1525
|
+
function ao(e, t, n, r) {
|
|
1526
1526
|
if (typeof e.setBigUint64 == "function")
|
|
1527
1527
|
return e.setBigUint64(t, n, r);
|
|
1528
|
-
const i = BigInt(32), o = BigInt(4294967295), s = Number(n >> i & o),
|
|
1529
|
-
e.setUint32(t +
|
|
1528
|
+
const i = BigInt(32), o = BigInt(4294967295), s = Number(n >> i & o), a = Number(n & o), c = r ? 4 : 0, l = r ? 0 : 4;
|
|
1529
|
+
e.setUint32(t + c, s, r), e.setUint32(t + l, a, r);
|
|
1530
1530
|
}
|
|
1531
|
-
class
|
|
1531
|
+
class co extends rr {
|
|
1532
1532
|
constructor(t, n, r, i) {
|
|
1533
|
-
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view =
|
|
1533
|
+
super(), this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view = Ut(this.buffer);
|
|
1534
1534
|
}
|
|
1535
1535
|
update(t) {
|
|
1536
1536
|
oe.exists(this);
|
|
1537
1537
|
const { view: n, buffer: r, blockLen: i } = this;
|
|
1538
|
-
t =
|
|
1538
|
+
t = Je(t);
|
|
1539
1539
|
const o = t.length;
|
|
1540
1540
|
for (let s = 0; s < o; ) {
|
|
1541
|
-
const
|
|
1542
|
-
if (
|
|
1543
|
-
const
|
|
1541
|
+
const a = Math.min(i - this.pos, o - s);
|
|
1542
|
+
if (a === i) {
|
|
1543
|
+
const c = Ut(t);
|
|
1544
1544
|
for (; i <= o - s; s += i)
|
|
1545
|
-
this.process(
|
|
1545
|
+
this.process(c, s);
|
|
1546
1546
|
continue;
|
|
1547
1547
|
}
|
|
1548
|
-
r.set(t.subarray(s, s +
|
|
1548
|
+
r.set(t.subarray(s, s + a), this.pos), this.pos += a, s += a, this.pos === i && (this.process(n, 0), this.pos = 0);
|
|
1549
1549
|
}
|
|
1550
1550
|
return this.length += t.length, this.roundClean(), this;
|
|
1551
1551
|
}
|
|
@@ -1556,15 +1556,15 @@ class ao extends nr {
|
|
|
1556
1556
|
n[s++] = 128, this.buffer.subarray(s).fill(0), this.padOffset > i - s && (this.process(r, 0), s = 0);
|
|
1557
1557
|
for (let u = s; u < i; u++)
|
|
1558
1558
|
n[u] = 0;
|
|
1559
|
-
|
|
1560
|
-
const
|
|
1561
|
-
if (
|
|
1559
|
+
ao(r, i - 8, BigInt(this.length * 8), o), this.process(r, 0);
|
|
1560
|
+
const a = Ut(t), c = this.outputLen;
|
|
1561
|
+
if (c % 4)
|
|
1562
1562
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
1563
|
-
const l =
|
|
1563
|
+
const l = c / 4, f = this.get();
|
|
1564
1564
|
if (l > f.length)
|
|
1565
1565
|
throw new Error("_sha2: outputLen bigger than state");
|
|
1566
1566
|
for (let u = 0; u < l; u++)
|
|
1567
|
-
|
|
1567
|
+
a.setUint32(4 * u, f[u], o);
|
|
1568
1568
|
}
|
|
1569
1569
|
digest() {
|
|
1570
1570
|
const { buffer: t, outputLen: n } = this;
|
|
@@ -1574,11 +1574,11 @@ class ao extends nr {
|
|
|
1574
1574
|
}
|
|
1575
1575
|
_cloneInto(t) {
|
|
1576
1576
|
t || (t = new this.constructor()), t.set(...this.get());
|
|
1577
|
-
const { blockLen: n, buffer: r, length: i, finished: o, destroyed: s, pos:
|
|
1578
|
-
return t.length = i, t.pos =
|
|
1577
|
+
const { blockLen: n, buffer: r, length: i, finished: o, destroyed: s, pos: a } = this;
|
|
1578
|
+
return t.length = i, t.pos = a, t.finished = o, t.destroyed = s, i % n && t.buffer.set(r), t;
|
|
1579
1579
|
}
|
|
1580
1580
|
}
|
|
1581
|
-
const
|
|
1581
|
+
const lo = (e, t, n) => e & t ^ ~e & n, uo = (e, t, n) => e & t ^ e & n ^ t & n, fo = new Uint32Array([
|
|
1582
1582
|
1116352408,
|
|
1583
1583
|
1899447441,
|
|
1584
1584
|
3049323471,
|
|
@@ -1653,17 +1653,17 @@ const co = (e, t, n) => e & t ^ ~e & n, lo = (e, t, n) => e & t ^ e & n ^ t & n,
|
|
|
1653
1653
|
528734635,
|
|
1654
1654
|
1541459225
|
|
1655
1655
|
]), ve = new Uint32Array(64);
|
|
1656
|
-
class
|
|
1656
|
+
class ar extends co {
|
|
1657
1657
|
constructor() {
|
|
1658
1658
|
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;
|
|
1659
1659
|
}
|
|
1660
1660
|
get() {
|
|
1661
|
-
const { A: t, B: n, C: r, D: i, E: o, F: s, G:
|
|
1662
|
-
return [t, n, r, i, o, s,
|
|
1661
|
+
const { A: t, B: n, C: r, D: i, E: o, F: s, G: a, H: c } = this;
|
|
1662
|
+
return [t, n, r, i, o, s, a, c];
|
|
1663
1663
|
}
|
|
1664
1664
|
// prettier-ignore
|
|
1665
|
-
set(t, n, r, i, o, s,
|
|
1666
|
-
this.A = t | 0, this.B = n | 0, this.C = r | 0, this.D = i | 0, this.E = o | 0, this.F = s | 0, this.G =
|
|
1665
|
+
set(t, n, r, i, o, s, a, c) {
|
|
1666
|
+
this.A = t | 0, this.B = n | 0, this.C = r | 0, this.D = i | 0, this.E = o | 0, this.F = s | 0, this.G = a | 0, this.H = c | 0;
|
|
1667
1667
|
}
|
|
1668
1668
|
process(t, n) {
|
|
1669
1669
|
for (let u = 0; u < 16; u++, n += 4)
|
|
@@ -1672,12 +1672,12 @@ class sr extends ao {
|
|
|
1672
1672
|
const d = ve[u - 15], p = ve[u - 2], g = re(d, 7) ^ re(d, 18) ^ d >>> 3, h = re(p, 17) ^ re(p, 19) ^ p >>> 10;
|
|
1673
1673
|
ve[u] = h + ve[u - 7] + g + ve[u - 16] | 0;
|
|
1674
1674
|
}
|
|
1675
|
-
let { A: r, B: i, C: o, D: s, E:
|
|
1675
|
+
let { A: r, B: i, C: o, D: s, E: a, F: c, G: l, H: f } = this;
|
|
1676
1676
|
for (let u = 0; u < 64; u++) {
|
|
1677
|
-
const d = re(
|
|
1678
|
-
f = l, l =
|
|
1677
|
+
const d = re(a, 6) ^ re(a, 11) ^ re(a, 25), p = f + d + lo(a, c, l) + fo[u] + ve[u] | 0, h = (re(r, 2) ^ re(r, 13) ^ re(r, 22)) + uo(r, i, o) | 0;
|
|
1678
|
+
f = l, l = c, c = a, a = s + p | 0, s = o, o = i, i = r, r = p + h | 0;
|
|
1679
1679
|
}
|
|
1680
|
-
r = r + this.A | 0, i = i + this.B | 0, o = o + this.C | 0, s = s + this.D | 0,
|
|
1680
|
+
r = r + this.A | 0, i = i + this.B | 0, o = o + this.C | 0, s = s + 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, o, s, a, c, l, f);
|
|
1681
1681
|
}
|
|
1682
1682
|
roundClean() {
|
|
1683
1683
|
ve.fill(0);
|
|
@@ -1686,15 +1686,15 @@ class sr extends ao {
|
|
|
1686
1686
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
|
|
1687
1687
|
}
|
|
1688
1688
|
}
|
|
1689
|
-
class
|
|
1689
|
+
class ho extends ar {
|
|
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 Se =
|
|
1695
|
-
|
|
1694
|
+
const Se = ir(() => new ar());
|
|
1695
|
+
ir(() => new ho());
|
|
1696
1696
|
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1697
|
-
function
|
|
1697
|
+
function Ve(e) {
|
|
1698
1698
|
if (!Number.isSafeInteger(e))
|
|
1699
1699
|
throw new Error(`Wrong integer: ${e}`);
|
|
1700
1700
|
}
|
|
@@ -1708,7 +1708,7 @@ function he(e) {
|
|
|
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 (Ve(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
|
});
|
|
@@ -1747,7 +1747,7 @@ function de(e = "") {
|
|
|
1747
1747
|
};
|
|
1748
1748
|
}
|
|
1749
1749
|
function yt(e, t = "=") {
|
|
1750
|
-
if (
|
|
1750
|
+
if (Ve(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 yt(e, t = "=") {
|
|
|
1776
1776
|
}
|
|
1777
1777
|
};
|
|
1778
1778
|
}
|
|
1779
|
-
function
|
|
1779
|
+
function cr(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 kn(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,29 +1793,29 @@ function Bn(e, t, n) {
|
|
|
1793
1793
|
let r = 0;
|
|
1794
1794
|
const i = [], o = Array.from(e);
|
|
1795
1795
|
for (o.forEach((s) => {
|
|
1796
|
-
if (
|
|
1796
|
+
if (Ve(s), s < 0 || s >= t)
|
|
1797
1797
|
throw new Error(`Wrong integer: ${s}`);
|
|
1798
1798
|
}); ; ) {
|
|
1799
|
-
let s = 0,
|
|
1800
|
-
for (let
|
|
1801
|
-
const l = o[
|
|
1799
|
+
let s = 0, a = !0;
|
|
1800
|
+
for (let c = r; c < o.length; c++) {
|
|
1801
|
+
const l = o[c], f = t * s + l;
|
|
1802
1802
|
if (!Number.isSafeInteger(f) || t * s / t !== s || f - l !== t * s)
|
|
1803
1803
|
throw new Error("convertRadix: carry overflow");
|
|
1804
|
-
if (s = f % n, o[
|
|
1804
|
+
if (s = f % n, o[c] = Math.floor(f / n), !Number.isSafeInteger(o[c]) || o[c] * n + s !== f)
|
|
1805
1805
|
throw new Error("convertRadix: carry overflow");
|
|
1806
|
-
if (
|
|
1807
|
-
o[
|
|
1806
|
+
if (a)
|
|
1807
|
+
o[c] ? a = !1 : r = c;
|
|
1808
1808
|
else continue;
|
|
1809
1809
|
}
|
|
1810
|
-
if (i.push(s),
|
|
1810
|
+
if (i.push(s), a)
|
|
1811
1811
|
break;
|
|
1812
1812
|
}
|
|
1813
1813
|
for (let s = 0; s < e.length - 1 && e[s] === 0; s++)
|
|
1814
1814
|
i.push(0);
|
|
1815
1815
|
return i.reverse();
|
|
1816
1816
|
}
|
|
1817
|
-
const
|
|
1818
|
-
function
|
|
1817
|
+
const lr = (e, t) => t ? lr(t, e % t) : e, at = (e, t) => e + (t - lr(e, t));
|
|
1818
|
+
function Dt(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)
|
|
@@ -1825,38 +1825,38 @@ function Ht(e, t, n, r) {
|
|
|
1825
1825
|
if (at(t, n) > 32)
|
|
1826
1826
|
throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${at(t, n)}`);
|
|
1827
1827
|
let i = 0, o = 0;
|
|
1828
|
-
const s = 2 ** n - 1,
|
|
1829
|
-
for (const
|
|
1830
|
-
if (
|
|
1831
|
-
throw new Error(`convertRadix2: invalid data word=${
|
|
1832
|
-
if (i = i << t |
|
|
1828
|
+
const s = 2 ** n - 1, a = [];
|
|
1829
|
+
for (const c of e) {
|
|
1830
|
+
if (Ve(c), c >= 2 ** t)
|
|
1831
|
+
throw new Error(`convertRadix2: invalid data word=${c} from=${t}`);
|
|
1832
|
+
if (i = i << t | c, o + t > 32)
|
|
1833
1833
|
throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);
|
|
1834
1834
|
for (o += t; o >= n; o -= n)
|
|
1835
|
-
|
|
1835
|
+
a.push((i >> o - n & s) >>> 0);
|
|
1836
1836
|
i &= 2 ** o - 1;
|
|
1837
1837
|
}
|
|
1838
1838
|
if (i = i << n - o & s, !r && o >= t)
|
|
1839
1839
|
throw new Error("Excess padding");
|
|
1840
1840
|
if (!r && i)
|
|
1841
1841
|
throw new Error(`Non-zero padding: ${i}`);
|
|
1842
|
-
return r && o > 0 &&
|
|
1842
|
+
return r && o > 0 && a.push(i >>> 0), a;
|
|
1843
1843
|
}
|
|
1844
|
-
function
|
|
1845
|
-
return
|
|
1844
|
+
function yo(e) {
|
|
1845
|
+
return Ve(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 kn(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(kn(t, e, 2 ** 8));
|
|
1855
1855
|
}
|
|
1856
1856
|
};
|
|
1857
1857
|
}
|
|
1858
1858
|
function Ae(e, t = !1) {
|
|
1859
|
-
if (
|
|
1859
|
+
if (Ve(e), e <= 0 || e > 32)
|
|
1860
1860
|
throw new Error("radix2: bits should be in (0..32]");
|
|
1861
1861
|
if (at(8, e) > 32 || at(e, 8) > 32)
|
|
1862
1862
|
throw new Error("radix2: carry overflow");
|
|
@@ -1864,16 +1864,16 @@ function Ae(e, t = !1) {
|
|
|
1864
1864
|
encode: (n) => {
|
|
1865
1865
|
if (!(n instanceof Uint8Array))
|
|
1866
1866
|
throw new Error("radix2.encode input should be Uint8Array");
|
|
1867
|
-
return
|
|
1867
|
+
return Dt(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(Dt(n, e, 8, t));
|
|
1873
1873
|
}
|
|
1874
1874
|
};
|
|
1875
1875
|
}
|
|
1876
|
-
function
|
|
1876
|
+
function Bn(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
|
|
1886
|
+
const po = fe(Ae(4), he("0123456789ABCDEF"), de("")), go = fe(Ae(5), he("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), yt(5), de(""));
|
|
1887
1887
|
fe(Ae(5), he("0123456789ABCDEFGHIJKLMNOPQRSTUV"), yt(5), de(""));
|
|
1888
|
-
fe(Ae(5), he("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), de(""),
|
|
1889
|
-
const ue = fe(Ae(6), he("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), yt(6), de("")),
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
const
|
|
1888
|
+
fe(Ae(5), he("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), de(""), cr((e) => e.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
1889
|
+
const ue = fe(Ae(6), he("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), yt(6), de("")), wo = fe(Ae(6), he("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), yt(6), de("")), tn = (e) => fe(yo(58), he(e), de("")), jt = tn("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
1890
|
+
tn("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
|
|
1891
|
+
tn("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");
|
|
1892
|
+
const Un = [0, 2, 3, 5, 6, 7, 9, 10, 11], bo = {
|
|
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 += jt.encode(r).padStart(Un[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 = Un.indexOf(r.length), o = jt.decode(r);
|
|
1905
1905
|
for (let s = 0; s < o.length - i; s++)
|
|
1906
1906
|
if (o[s] !== 0)
|
|
1907
1907
|
throw new Error("base58xmr: wrong padding");
|
|
@@ -1909,34 +1909,34 @@ const In = [0, 2, 3, 5, 6, 7, 9, 10, 11], wo = {
|
|
|
1909
1909
|
}
|
|
1910
1910
|
return Uint8Array.from(t);
|
|
1911
1911
|
}
|
|
1912
|
-
},
|
|
1913
|
-
function
|
|
1912
|
+
}, Vt = fe(he("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), de("")), In = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
1913
|
+
function Fe(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 < In.length; r++)
|
|
1917
|
+
(t >> r & 1) === 1 && (n ^= In[r]);
|
|
1918
1918
|
return n;
|
|
1919
1919
|
}
|
|
1920
|
-
function
|
|
1920
|
+
function _n(e, t, n = 1) {
|
|
1921
1921
|
const r = e.length;
|
|
1922
1922
|
let i = 1;
|
|
1923
1923
|
for (let o = 0; o < r; o++) {
|
|
1924
1924
|
const s = e.charCodeAt(o);
|
|
1925
1925
|
if (s < 33 || s > 126)
|
|
1926
1926
|
throw new Error(`Invalid prefix (${e})`);
|
|
1927
|
-
i =
|
|
1927
|
+
i = Fe(i) ^ s >> 5;
|
|
1928
1928
|
}
|
|
1929
|
-
i =
|
|
1929
|
+
i = Fe(i);
|
|
1930
1930
|
for (let o = 0; o < r; o++)
|
|
1931
|
-
i =
|
|
1931
|
+
i = Fe(i) ^ e.charCodeAt(o) & 31;
|
|
1932
1932
|
for (let o of t)
|
|
1933
|
-
i =
|
|
1933
|
+
i = Fe(i) ^ o;
|
|
1934
1934
|
for (let o = 0; o < 6; o++)
|
|
1935
|
-
i =
|
|
1936
|
-
return i ^= n,
|
|
1935
|
+
i = Fe(i);
|
|
1936
|
+
return i ^= n, Vt.encode(Dt([i % 2 ** 30], 30, 5, !1));
|
|
1937
1937
|
}
|
|
1938
|
-
function
|
|
1939
|
-
const t = e === "bech32" ? 1 : 734539939, n = Ae(5), r = n.decode, i = n.encode, o =
|
|
1938
|
+
function ur(e) {
|
|
1939
|
+
const t = e === "bech32" ? 1 : 734539939, n = Ae(5), r = n.decode, i = n.encode, o = Bn(r);
|
|
1940
1940
|
function s(f, u, d = 90) {
|
|
1941
1941
|
if (typeof f != "string")
|
|
1942
1942
|
throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);
|
|
@@ -1945,9 +1945,9 @@ function lr(e) {
|
|
|
1945
1945
|
const p = f.length + 7 + u.length;
|
|
1946
1946
|
if (d !== !1 && p > d)
|
|
1947
1947
|
throw new TypeError(`Length ${p} exceeds limit ${d}`);
|
|
1948
|
-
return f = f.toLowerCase(), `${f}1${
|
|
1948
|
+
return f = f.toLowerCase(), `${f}1${Vt.encode(u)}${_n(f, u, t)}`;
|
|
1949
1949
|
}
|
|
1950
|
-
function
|
|
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)
|
|
@@ -1962,65 +1962,65 @@ function lr(e) {
|
|
|
1962
1962
|
const g = f.slice(0, p), h = f.slice(p + 1);
|
|
1963
1963
|
if (h.length < 6)
|
|
1964
1964
|
throw new Error("Data must be at least 6 characters long");
|
|
1965
|
-
const y =
|
|
1965
|
+
const y = Vt.decode(h).slice(0, -6), w = _n(g, y, t);
|
|
1966
1966
|
if (!h.endsWith(w))
|
|
1967
1967
|
throw new Error(`Invalid checksum in ${f}: expected "${w}"`);
|
|
1968
1968
|
return { prefix: g, words: y };
|
|
1969
1969
|
}
|
|
1970
|
-
const
|
|
1970
|
+
const c = Bn(a);
|
|
1971
1971
|
function l(f) {
|
|
1972
|
-
const { prefix: u, words: d } =
|
|
1972
|
+
const { prefix: u, words: d } = a(f, !1);
|
|
1973
1973
|
return { prefix: u, words: d, bytes: r(d) };
|
|
1974
1974
|
}
|
|
1975
|
-
return { encode: s, decode:
|
|
1975
|
+
return { encode: s, decode: a, decodeToBytes: l, decodeUnsafe: c, fromWords: r, fromWordsUnsafe: o, toWords: i };
|
|
1976
1976
|
}
|
|
1977
|
-
const
|
|
1978
|
-
|
|
1979
|
-
const
|
|
1977
|
+
const je = ur("bech32");
|
|
1978
|
+
ur("bech32m");
|
|
1979
|
+
const vo = {
|
|
1980
1980
|
encode: (e) => new TextDecoder().decode(e),
|
|
1981
1981
|
decode: (e) => new TextEncoder().encode(e)
|
|
1982
|
-
},
|
|
1982
|
+
}, Eo = fe(Ae(4), he("0123456789abcdef"), de(""), cr((e) => {
|
|
1983
1983
|
if (typeof e != "string" || e.length % 2)
|
|
1984
1984
|
throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);
|
|
1985
1985
|
return e.toLowerCase();
|
|
1986
|
-
})),
|
|
1987
|
-
utf8:
|
|
1988
|
-
hex:
|
|
1989
|
-
base16:
|
|
1990
|
-
base32:
|
|
1986
|
+
})), mo = {
|
|
1987
|
+
utf8: vo,
|
|
1988
|
+
hex: Eo,
|
|
1989
|
+
base16: po,
|
|
1990
|
+
base32: go,
|
|
1991
1991
|
base64: ue,
|
|
1992
|
-
base64url:
|
|
1993
|
-
base58:
|
|
1994
|
-
base58xmr:
|
|
1992
|
+
base64url: wo,
|
|
1993
|
+
base58: jt,
|
|
1994
|
+
base58xmr: bo
|
|
1995
1995
|
};
|
|
1996
|
-
`${Object.keys(
|
|
1997
|
-
function
|
|
1996
|
+
`${Object.keys(mo).join(", ")}`;
|
|
1997
|
+
function It(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 Ln(e) {
|
|
2002
2002
|
if (typeof e != "boolean")
|
|
2003
2003
|
throw new Error(`boolean expected, not ${e}`);
|
|
2004
2004
|
}
|
|
2005
|
-
function
|
|
2005
|
+
function xo(e) {
|
|
2006
2006
|
return e instanceof Uint8Array || e != null && typeof e == "object" && e.constructor.name === "Uint8Array";
|
|
2007
2007
|
}
|
|
2008
2008
|
function le(e, ...t) {
|
|
2009
|
-
if (!
|
|
2009
|
+
if (!xo(e))
|
|
2010
2010
|
throw new Error("Uint8Array expected");
|
|
2011
2011
|
if (t.length > 0 && !t.includes(e.length))
|
|
2012
2012
|
throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`);
|
|
2013
2013
|
}
|
|
2014
2014
|
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
|
|
2015
|
-
const F = (e) => new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4)),
|
|
2016
|
-
if (!
|
|
2015
|
+
const F = (e) => new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4)), So = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
2016
|
+
if (!So)
|
|
2017
2017
|
throw new Error("Non little-endian hardware is not supported");
|
|
2018
|
-
function
|
|
2018
|
+
function Ao(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 Ko(e, t) {
|
|
2024
2024
|
if (e.length !== t.length)
|
|
2025
2025
|
return !1;
|
|
2026
2026
|
let n = 0;
|
|
@@ -2028,19 +2028,19 @@ function Ao(e, t) {
|
|
|
2028
2028
|
n |= e[r] ^ t[r];
|
|
2029
2029
|
return n === 0;
|
|
2030
2030
|
}
|
|
2031
|
-
const
|
|
2032
|
-
function
|
|
2033
|
-
return e << 1 ^
|
|
2031
|
+
const No = /* @__NO_SIDE_EFFECTS__ */ (e, t) => (Object.assign(t, e), t), me = 16, Co = 283;
|
|
2032
|
+
function nn(e) {
|
|
2033
|
+
return e << 1 ^ Co & -(e >> 7);
|
|
2034
2034
|
}
|
|
2035
2035
|
function Pe(e, t) {
|
|
2036
2036
|
let n = 0;
|
|
2037
2037
|
for (; t > 0; t >>= 1)
|
|
2038
|
-
n ^= e & -(t & 1), e =
|
|
2038
|
+
n ^= e & -(t & 1), e = nn(e);
|
|
2039
2039
|
return n;
|
|
2040
2040
|
}
|
|
2041
|
-
const
|
|
2041
|
+
const zt = /* @__PURE__ */ (() => {
|
|
2042
2042
|
let e = new Uint8Array(256);
|
|
2043
|
-
for (let n = 0, r = 1; n < 256; n++, r ^=
|
|
2043
|
+
for (let n = 0, r = 1; n < 256; n++, r ^= nn(r))
|
|
2044
2044
|
e[n] = r;
|
|
2045
2045
|
const t = new Uint8Array(256);
|
|
2046
2046
|
t[0] = 99;
|
|
@@ -2049,46 +2049,46 @@ const jt = /* @__PURE__ */ (() => {
|
|
|
2049
2049
|
r |= r << 8, t[e[n]] = (r ^ r >> 4 ^ r >> 5 ^ r >> 6 ^ r >> 7 ^ 99) & 255;
|
|
2050
2050
|
}
|
|
2051
2051
|
return t;
|
|
2052
|
-
})(),
|
|
2053
|
-
function
|
|
2052
|
+
})(), ko = /* @__PURE__ */ zt.map((e, t) => zt.indexOf(t)), Bo = (e) => e << 24 | e >>> 8, _t = (e) => e << 8 | e >>> 24;
|
|
2053
|
+
function fr(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(_t), i = r.map(_t), o = i.map(_t), s = 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;
|
|
2060
|
-
s[u] = n[l] ^ r[f],
|
|
2060
|
+
s[u] = n[l] ^ r[f], a[u] = i[l] ^ o[f], c[u] = e[l] << 8 | e[f];
|
|
2061
2061
|
}
|
|
2062
|
-
return { sbox: e, sbox2:
|
|
2062
|
+
return { sbox: e, sbox2: c, T0: n, T1: r, T2: i, T3: o, T01: s, T23: a };
|
|
2063
2063
|
}
|
|
2064
|
-
const
|
|
2064
|
+
const rn = /* @__PURE__ */ fr(zt, (e) => Pe(e, 3) << 24 | e << 16 | e << 8 | Pe(e, 2)), hr = /* @__PURE__ */ fr(ko, (e) => Pe(e, 11) << 24 | Pe(e, 13) << 16 | Pe(e, 9) << 8 | Pe(e, 14)), Uo = /* @__PURE__ */ (() => {
|
|
2065
2065
|
const e = new Uint8Array(16);
|
|
2066
|
-
for (let t = 0, n = 1; t < 16; t++, n =
|
|
2066
|
+
for (let t = 0, n = 1; t < 16; t++, n = nn(n))
|
|
2067
2067
|
e[t] = n;
|
|
2068
2068
|
return e;
|
|
2069
2069
|
})();
|
|
2070
|
-
function
|
|
2070
|
+
function dr(e) {
|
|
2071
2071
|
le(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 } =
|
|
2075
|
+
const { sbox2: n } = rn, r = F(e), i = r.length, o = (a) => se(n, a, a, a, a), s = new Uint32Array(t + 28);
|
|
2076
2076
|
s.set(r);
|
|
2077
|
-
for (let
|
|
2078
|
-
let
|
|
2079
|
-
|
|
2077
|
+
for (let a = i; a < s.length; a++) {
|
|
2078
|
+
let c = s[a - 1];
|
|
2079
|
+
a % i === 0 ? c = o(Bo(c)) ^ Uo[a / i - 1] : i > 6 && a % i === 4 && (c = o(c)), s[a] = s[a - i] ^ c;
|
|
2080
2080
|
}
|
|
2081
2081
|
return s;
|
|
2082
2082
|
}
|
|
2083
|
-
function
|
|
2084
|
-
const t =
|
|
2083
|
+
function Io(e) {
|
|
2084
|
+
const t = dr(e), n = t.slice(), r = t.length, { sbox2: i } = rn, { T0: o, T1: s, T2: a, T3: c } = hr;
|
|
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];
|
|
2088
2088
|
t.fill(0);
|
|
2089
2089
|
for (let l = 4; l < r - 4; l++) {
|
|
2090
2090
|
const f = n[l], u = se(i, f, f, f, f);
|
|
2091
|
-
n[l] = o[u & 255] ^ s[u >>> 8 & 255] ^
|
|
2091
|
+
n[l] = o[u & 255] ^ s[u >>> 8 & 255] ^ a[u >>> 16 & 255] ^ c[u >>> 24];
|
|
2092
2092
|
}
|
|
2093
2093
|
return n;
|
|
2094
2094
|
}
|
|
@@ -2098,53 +2098,53 @@ function Ee(e, t, n, r, i, o) {
|
|
|
2098
2098
|
function se(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
|
|
2102
|
-
const { sbox2: o, T01: s, T23:
|
|
2103
|
-
let
|
|
2104
|
-
t ^= e[
|
|
2101
|
+
function Tn(e, t, n, r, i) {
|
|
2102
|
+
const { sbox2: o, T01: s, T23: a } = rn;
|
|
2103
|
+
let c = 0;
|
|
2104
|
+
t ^= e[c++], n ^= e[c++], r ^= e[c++], i ^= e[c++];
|
|
2105
2105
|
const l = e.length / 4 - 2;
|
|
2106
2106
|
for (let g = 0; g < l; g++) {
|
|
2107
|
-
const h = e[
|
|
2107
|
+
const h = e[c++] ^ Ee(s, a, t, n, r, i), y = e[c++] ^ Ee(s, a, n, r, i, t), w = e[c++] ^ Ee(s, a, r, i, t, n), m = e[c++] ^ Ee(s, a, i, t, n, r);
|
|
2108
2108
|
t = h, n = y, r = w, i = m;
|
|
2109
2109
|
}
|
|
2110
|
-
const f = e[
|
|
2110
|
+
const f = e[c++] ^ se(o, t, n, r, i), u = e[c++] ^ se(o, n, r, i, t), d = e[c++] ^ se(o, r, i, t, n), p = e[c++] ^ se(o, i, t, n, r);
|
|
2111
2111
|
return { s0: f, s1: u, s2: d, s3: p };
|
|
2112
2112
|
}
|
|
2113
|
-
function
|
|
2114
|
-
const { sbox2: o, T01: s, T23:
|
|
2115
|
-
let
|
|
2116
|
-
t ^= e[
|
|
2113
|
+
function _o(e, t, n, r, i) {
|
|
2114
|
+
const { sbox2: o, T01: s, T23: a } = hr;
|
|
2115
|
+
let c = 0;
|
|
2116
|
+
t ^= e[c++], n ^= e[c++], r ^= e[c++], i ^= e[c++];
|
|
2117
2117
|
const l = e.length / 4 - 2;
|
|
2118
2118
|
for (let g = 0; g < l; g++) {
|
|
2119
|
-
const h = e[
|
|
2119
|
+
const h = e[c++] ^ Ee(s, a, t, i, r, n), y = e[c++] ^ Ee(s, a, n, t, i, r), w = e[c++] ^ Ee(s, a, r, n, t, i), m = e[c++] ^ Ee(s, a, i, r, n, t);
|
|
2120
2120
|
t = h, n = y, r = w, i = m;
|
|
2121
2121
|
}
|
|
2122
|
-
const f = e[
|
|
2122
|
+
const f = e[c++] ^ se(o, t, i, r, n), u = e[c++] ^ se(o, n, t, i, r), d = e[c++] ^ se(o, r, n, t, i), p = e[c++] ^ se(o, i, r, n, t);
|
|
2123
2123
|
return { s0: f, s1: u, s2: d, s3: p };
|
|
2124
2124
|
}
|
|
2125
|
-
function
|
|
2125
|
+
function yr(e, t) {
|
|
2126
2126
|
if (!t)
|
|
2127
2127
|
return new Uint8Array(e);
|
|
2128
2128
|
if (le(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
|
|
2132
|
+
function Lo(e) {
|
|
2133
2133
|
if (le(e), e.length % me !== 0)
|
|
2134
2134
|
throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${me}`);
|
|
2135
2135
|
}
|
|
2136
|
-
function
|
|
2136
|
+
function To(e, t, n) {
|
|
2137
2137
|
let r = e.length;
|
|
2138
2138
|
const i = r % me;
|
|
2139
2139
|
if (!t && i !== 0)
|
|
2140
2140
|
throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");
|
|
2141
2141
|
const o = F(e);
|
|
2142
2142
|
if (t) {
|
|
2143
|
-
let
|
|
2144
|
-
|
|
2143
|
+
let c = me - i;
|
|
2144
|
+
c || (c = me), r = r + c;
|
|
2145
2145
|
}
|
|
2146
|
-
const s =
|
|
2147
|
-
return { b: o, o:
|
|
2146
|
+
const s = yr(r, n), a = F(s);
|
|
2147
|
+
return { b: o, o: a, out: s };
|
|
2148
2148
|
}
|
|
2149
2149
|
function $o(e, t) {
|
|
2150
2150
|
if (!t)
|
|
@@ -2161,7 +2161,7 @@ function $o(e, t) {
|
|
|
2161
2161
|
throw new Error("aes/pcks5: wrong padding");
|
|
2162
2162
|
return i;
|
|
2163
2163
|
}
|
|
2164
|
-
function
|
|
2164
|
+
function Ro(e) {
|
|
2165
2165
|
const t = new Uint8Array(16), n = F(t);
|
|
2166
2166
|
t.set(e);
|
|
2167
2167
|
const r = me - e.length;
|
|
@@ -2169,56 +2169,56 @@ function To(e) {
|
|
|
2169
2169
|
t[i] = r;
|
|
2170
2170
|
return n;
|
|
2171
2171
|
}
|
|
2172
|
-
const
|
|
2172
|
+
const pr = /* @__PURE__ */ No({ blockSize: 16, nonceLength: 16 }, function(t, n, r = {}) {
|
|
2173
2173
|
le(t), le(n, 16);
|
|
2174
2174
|
const i = !r.disablePadding;
|
|
2175
2175
|
return {
|
|
2176
2176
|
encrypt: (o, s) => {
|
|
2177
|
-
const
|
|
2177
|
+
const a = dr(t), { b: c, o: l, out: f } = To(o, i, s), u = F(n);
|
|
2178
2178
|
let d = u[0], p = u[1], g = u[2], h = u[3], y = 0;
|
|
2179
|
-
for (; y + 4 <=
|
|
2180
|
-
d ^=
|
|
2179
|
+
for (; y + 4 <= c.length; )
|
|
2180
|
+
d ^= c[y + 0], p ^= c[y + 1], g ^= c[y + 2], h ^= c[y + 3], { s0: d, s1: p, s2: g, s3: h } = Tn(a, d, p, g, h), l[y++] = d, l[y++] = p, l[y++] = g, l[y++] = h;
|
|
2181
2181
|
if (i) {
|
|
2182
|
-
const w =
|
|
2183
|
-
d ^= w[0], p ^= w[1], g ^= w[2], h ^= w[3], { s0: d, s1: p, s2: g, s3: h } =
|
|
2182
|
+
const w = Ro(o.subarray(y * 4));
|
|
2183
|
+
d ^= w[0], p ^= w[1], g ^= w[2], h ^= w[3], { s0: d, s1: p, s2: g, s3: h } = Tn(a, d, p, g, h), l[y++] = d, l[y++] = p, l[y++] = g, l[y++] = h;
|
|
2184
2184
|
}
|
|
2185
|
-
return
|
|
2185
|
+
return a.fill(0), f;
|
|
2186
2186
|
},
|
|
2187
2187
|
decrypt: (o, s) => {
|
|
2188
|
-
|
|
2189
|
-
const
|
|
2190
|
-
let d =
|
|
2188
|
+
Lo(o);
|
|
2189
|
+
const a = Io(t), c = F(n), l = yr(o.length, s), f = F(o), u = F(l);
|
|
2190
|
+
let d = c[0], p = c[1], g = c[2], h = c[3];
|
|
2191
2191
|
for (let y = 0; y + 4 <= f.length; ) {
|
|
2192
|
-
const w = d, m = p, K = g,
|
|
2192
|
+
const w = d, m = p, K = g, I = h;
|
|
2193
2193
|
d = f[y + 0], p = f[y + 1], g = f[y + 2], h = f[y + 3];
|
|
2194
|
-
const { s0:
|
|
2195
|
-
u[y++] =
|
|
2194
|
+
const { s0: k, s1: E, s2: x, s3: S } = _o(a, d, p, g, h);
|
|
2195
|
+
u[y++] = k ^ w, u[y++] = E ^ m, u[y++] = x ^ K, u[y++] = S ^ I;
|
|
2196
2196
|
}
|
|
2197
|
-
return
|
|
2197
|
+
return a.fill(0), $o(l, i);
|
|
2198
2198
|
}
|
|
2199
2199
|
};
|
|
2200
|
-
}),
|
|
2201
|
-
|
|
2200
|
+
}), gr = (e) => Uint8Array.from(e.split("").map((t) => t.charCodeAt(0))), Oo = gr("expand 16-byte k"), Po = gr("expand 32-byte k"), Mo = F(Oo), wr = F(Po);
|
|
2201
|
+
wr.slice();
|
|
2202
2202
|
function L(e, t) {
|
|
2203
2203
|
return e << t | e >>> 32 - t;
|
|
2204
2204
|
}
|
|
2205
|
-
function
|
|
2205
|
+
function Zt(e) {
|
|
2206
2206
|
return e.byteOffset % 4 === 0;
|
|
2207
2207
|
}
|
|
2208
|
-
const
|
|
2209
|
-
function
|
|
2210
|
-
const
|
|
2211
|
-
for (let g = 0; g <
|
|
2212
|
-
if (e(t, n, r, f, s,
|
|
2208
|
+
const Qe = 64, Ho = 16, br = 2 ** 32 - 1, $n = new Uint32Array();
|
|
2209
|
+
function qo(e, t, n, r, i, o, s, a) {
|
|
2210
|
+
const c = i.length, l = new Uint8Array(Qe), f = F(l), u = Zt(i) && Zt(o), d = u ? F(i) : $n, p = u ? F(o) : $n;
|
|
2211
|
+
for (let g = 0; g < c; s++) {
|
|
2212
|
+
if (e(t, n, r, f, s, a), s >= br)
|
|
2213
2213
|
throw new Error("arx: counter overflow");
|
|
2214
|
-
const h = Math.min(
|
|
2215
|
-
if (u && h ===
|
|
2214
|
+
const h = Math.min(Qe, c - g);
|
|
2215
|
+
if (u && h === Qe) {
|
|
2216
2216
|
const y = g / 4;
|
|
2217
2217
|
if (g % 4 !== 0)
|
|
2218
2218
|
throw new Error("arx: invalid block position");
|
|
2219
|
-
for (let w = 0, m; w <
|
|
2219
|
+
for (let w = 0, m; w < Ho; w++)
|
|
2220
2220
|
m = y + w, p[m] = d[m] ^ f[w];
|
|
2221
|
-
g +=
|
|
2221
|
+
g += Qe;
|
|
2222
2222
|
continue;
|
|
2223
2223
|
}
|
|
2224
2224
|
for (let y = 0, w; y < h; y++)
|
|
@@ -2226,61 +2226,61 @@ function Ho(e, t, n, r, i, o, s, c) {
|
|
|
2226
2226
|
g += h;
|
|
2227
2227
|
}
|
|
2228
2228
|
}
|
|
2229
|
-
function
|
|
2230
|
-
const { allowShortKeys: n, extendNonceFn: r, counterLength: i, counterRight: o, rounds: s } =
|
|
2229
|
+
function Do(e, t) {
|
|
2230
|
+
const { allowShortKeys: n, extendNonceFn: r, counterLength: i, counterRight: o, rounds: s } = Ao({ 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
|
-
le(
|
|
2233
|
+
return It(i), It(s), Ln(o), Ln(n), (a, c, l, f, u = 0) => {
|
|
2234
|
+
le(a), le(c), le(l);
|
|
2235
2235
|
const d = l.length;
|
|
2236
|
-
if (f || (f = new Uint8Array(d)), le(f),
|
|
2236
|
+
if (f || (f = new Uint8Array(d)), le(f), It(u), u < 0 || u >= br)
|
|
2237
2237
|
throw new Error("arx: counter overflow");
|
|
2238
2238
|
if (f.length < d)
|
|
2239
2239
|
throw new Error(`arx: output (${f.length}) is shorter than data (${d})`);
|
|
2240
2240
|
const p = [];
|
|
2241
|
-
let g =
|
|
2241
|
+
let g = a.length, h, y;
|
|
2242
2242
|
if (g === 32)
|
|
2243
|
-
h =
|
|
2243
|
+
h = a.slice(), p.push(h), y = wr;
|
|
2244
2244
|
else if (g === 16 && n)
|
|
2245
|
-
h = new Uint8Array(32), h.set(
|
|
2245
|
+
h = new Uint8Array(32), h.set(a), h.set(a, 16), y = Mo, p.push(h);
|
|
2246
2246
|
else
|
|
2247
2247
|
throw new Error(`arx: invalid 32-byte key, got length=${g}`);
|
|
2248
|
-
|
|
2248
|
+
Zt(c) || (c = c.slice(), p.push(c));
|
|
2249
2249
|
const w = F(h);
|
|
2250
2250
|
if (r) {
|
|
2251
|
-
if (
|
|
2251
|
+
if (c.length !== 24)
|
|
2252
2252
|
throw new Error("arx: extended nonce must be 24 bytes");
|
|
2253
|
-
r(y, w, F(
|
|
2253
|
+
r(y, w, F(c.subarray(0, 16)), w), c = c.subarray(16);
|
|
2254
2254
|
}
|
|
2255
2255
|
const m = 16 - i;
|
|
2256
|
-
if (m !==
|
|
2256
|
+
if (m !== c.length)
|
|
2257
2257
|
throw new Error(`arx: nonce must be ${m} or 16 bytes`);
|
|
2258
2258
|
if (m !== 12) {
|
|
2259
|
-
const
|
|
2260
|
-
|
|
2259
|
+
const I = new Uint8Array(12);
|
|
2260
|
+
I.set(c, o ? 0 : 12 - c.length), c = I, p.push(c);
|
|
2261
2261
|
}
|
|
2262
|
-
const K = F(
|
|
2263
|
-
for (
|
|
2262
|
+
const K = F(c);
|
|
2263
|
+
for (qo(e, y, w, K, l, f, u, s); p.length > 0; )
|
|
2264
2264
|
p.pop().fill(0);
|
|
2265
2265
|
return f;
|
|
2266
2266
|
};
|
|
2267
2267
|
}
|
|
2268
|
-
function
|
|
2269
|
-
let s = e[0],
|
|
2268
|
+
function jo(e, t, n, r, i, o = 20) {
|
|
2269
|
+
let s = e[0], a = e[1], c = e[2], l = e[3], f = t[0], u = t[1], d = t[2], p = t[3], g = t[4], h = t[5], y = t[6], w = t[7], m = i, K = n[0], I = n[1], k = n[2], E = s, x = a, S = c, P = l, U = f, N = u, $ = d, R = p, H = g, b = h, v = y, A = w, B = m, C = K, _ = I, O = k;
|
|
2270
2270
|
for (let X = 0; X < o; X += 2)
|
|
2271
|
-
E = E + U | 0,
|
|
2272
|
-
let
|
|
2273
|
-
r[
|
|
2271
|
+
E = E + U | 0, B = L(B ^ E, 16), H = H + B | 0, U = L(U ^ H, 12), E = E + U | 0, B = L(B ^ E, 8), H = H + B | 0, U = L(U ^ H, 7), x = x + N | 0, C = L(C ^ x, 16), b = b + C | 0, N = L(N ^ b, 12), x = x + N | 0, C = L(C ^ x, 8), b = b + C | 0, N = L(N ^ b, 7), S = S + $ | 0, _ = L(_ ^ S, 16), v = v + _ | 0, $ = L($ ^ v, 12), S = S + $ | 0, _ = L(_ ^ S, 8), v = v + _ | 0, $ = L($ ^ v, 7), P = P + R | 0, O = L(O ^ P, 16), A = A + O | 0, R = L(R ^ A, 12), P = P + R | 0, O = L(O ^ P, 8), A = A + O | 0, R = L(R ^ A, 7), E = E + N | 0, O = L(O ^ E, 16), v = v + O | 0, N = L(N ^ v, 12), E = E + N | 0, O = L(O ^ E, 8), v = v + O | 0, N = L(N ^ v, 7), x = x + $ | 0, B = L(B ^ x, 16), A = A + B | 0, $ = L($ ^ A, 12), x = x + $ | 0, B = L(B ^ x, 8), A = A + B | 0, $ = L($ ^ A, 7), S = S + R | 0, C = L(C ^ S, 16), H = H + C | 0, R = L(R ^ H, 12), S = S + R | 0, C = L(C ^ S, 8), H = H + C | 0, R = L(R ^ H, 7), P = P + U | 0, _ = L(_ ^ P, 16), b = b + _ | 0, U = L(U ^ b, 12), P = P + U | 0, _ = L(_ ^ P, 8), b = b + _ | 0, U = L(U ^ b, 7);
|
|
2272
|
+
let T = 0;
|
|
2273
|
+
r[T++] = s + E | 0, r[T++] = a + x | 0, r[T++] = c + S | 0, r[T++] = l + P | 0, r[T++] = f + U | 0, r[T++] = u + N | 0, r[T++] = d + $ | 0, r[T++] = p + R | 0, r[T++] = g + H | 0, r[T++] = h + b | 0, r[T++] = y + v | 0, r[T++] = w + A | 0, r[T++] = m + B | 0, r[T++] = K + C | 0, r[T++] = I + _ | 0, r[T++] = k + O | 0;
|
|
2274
2274
|
}
|
|
2275
|
-
const
|
|
2275
|
+
const vr = /* @__PURE__ */ Do(jo, {
|
|
2276
2276
|
counterRight: !1,
|
|
2277
2277
|
counterLength: 4,
|
|
2278
2278
|
allowShortKeys: !1
|
|
2279
2279
|
});
|
|
2280
|
-
class
|
|
2280
|
+
class Er extends rr {
|
|
2281
2281
|
constructor(t, n) {
|
|
2282
2282
|
super(), this.finished = !1, this.destroyed = !1, oe.hash(t);
|
|
2283
|
-
const r =
|
|
2283
|
+
const r = Je(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;
|
|
@@ -2305,34 +2305,34 @@ class vr extends nr {
|
|
|
2305
2305
|
}
|
|
2306
2306
|
_cloneInto(t) {
|
|
2307
2307
|
t || (t = Object.create(Object.getPrototypeOf(this), {}));
|
|
2308
|
-
const { oHash: n, iHash: r, finished: i, destroyed: o, blockLen: s, outputLen:
|
|
2309
|
-
return t = t, t.finished = i, t.destroyed = o, t.blockLen = s, t.outputLen =
|
|
2308
|
+
const { oHash: n, iHash: r, finished: i, destroyed: o, blockLen: s, outputLen: a } = this;
|
|
2309
|
+
return t = t, t.finished = i, t.destroyed = o, t.blockLen = s, t.outputLen = a, t.oHash = n._cloneInto(t.oHash), t.iHash = r._cloneInto(t.iHash), t;
|
|
2310
2310
|
}
|
|
2311
2311
|
destroy() {
|
|
2312
2312
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
2313
2313
|
}
|
|
2314
2314
|
}
|
|
2315
|
-
const pt = (e, t, n) => new
|
|
2316
|
-
pt.create = (e, t) => new
|
|
2317
|
-
function
|
|
2318
|
-
return oe.hash(e), n === void 0 && (n = new Uint8Array(e.outputLen)), pt(e,
|
|
2315
|
+
const pt = (e, t, n) => new Er(e, t).update(n).digest();
|
|
2316
|
+
pt.create = (e, t) => new Er(e, t);
|
|
2317
|
+
function on(e, t, n) {
|
|
2318
|
+
return oe.hash(e), n === void 0 && (n = new Uint8Array(e.outputLen)), pt(e, Je(n), Je(t));
|
|
2319
2319
|
}
|
|
2320
|
-
const
|
|
2321
|
-
function
|
|
2320
|
+
const Lt = new Uint8Array([0]), Rn = new Uint8Array();
|
|
2321
|
+
function mr(e, t, n, r = 32) {
|
|
2322
2322
|
if (oe.hash(e), oe.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 o = new Uint8Array(i * e.outputLen), s = pt.create(e, t),
|
|
2325
|
+
n === void 0 && (n = Rn);
|
|
2326
|
+
const o = new Uint8Array(i * e.outputLen), s = pt.create(e, t), a = s._cloneInto(), c = new Uint8Array(s.outputLen);
|
|
2327
2327
|
for (let l = 0; l < i; l++)
|
|
2328
|
-
|
|
2329
|
-
return s.destroy(),
|
|
2328
|
+
Lt[0] = l + 1, a.update(l === 0 ? Rn : c).update(n).update(Lt).digestInto(c), o.set(c, e.outputLen * l), s._cloneInto(a);
|
|
2329
|
+
return s.destroy(), a.destroy(), c.fill(0), Lt.fill(0), o.slice(0, r);
|
|
2330
2330
|
}
|
|
2331
|
-
var
|
|
2331
|
+
var Vo = Object.defineProperty, D = (e, t) => {
|
|
2332
2332
|
for (var n in t)
|
|
2333
|
-
|
|
2334
|
-
},
|
|
2335
|
-
function
|
|
2333
|
+
Vo(e, n, { get: t[n], enumerable: !0 });
|
|
2334
|
+
}, $e = Symbol("verified"), zo = (e) => e instanceof Object;
|
|
2335
|
+
function xr(e) {
|
|
2336
2336
|
if (!zo(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++) {
|
|
@@ -2345,32 +2345,32 @@ function mr(e) {
|
|
|
2345
2345
|
}
|
|
2346
2346
|
return !0;
|
|
2347
2347
|
}
|
|
2348
|
-
var
|
|
2349
|
-
D(
|
|
2350
|
-
Queue: () =>
|
|
2351
|
-
QueueNode: () =>
|
|
2352
|
-
binarySearch: () =>
|
|
2353
|
-
insertEventIntoAscendingList: () =>
|
|
2354
|
-
insertEventIntoDescendingList: () =>
|
|
2355
|
-
normalizeURL: () =>
|
|
2348
|
+
var Zo = {};
|
|
2349
|
+
D(Zo, {
|
|
2350
|
+
Queue: () => Jo,
|
|
2351
|
+
QueueNode: () => Sr,
|
|
2352
|
+
binarySearch: () => sn,
|
|
2353
|
+
insertEventIntoAscendingList: () => Go,
|
|
2354
|
+
insertEventIntoDescendingList: () => Wo,
|
|
2355
|
+
normalizeURL: () => Fo,
|
|
2356
2356
|
utf8Decoder: () => ie,
|
|
2357
2357
|
utf8Encoder: () => te
|
|
2358
2358
|
});
|
|
2359
2359
|
var ie = new TextDecoder("utf-8"), te = new TextEncoder();
|
|
2360
|
-
function
|
|
2360
|
+
function Fo(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 Wo(e, t) {
|
|
2366
|
+
const [n, r] = sn(e, (i) => t.id === i.id ? 0 : t.created_at === i.created_at ? -1 : i.created_at - t.created_at);
|
|
2367
2367
|
return r || e.splice(n, 0, t), e;
|
|
2368
2368
|
}
|
|
2369
|
-
function
|
|
2370
|
-
const [n, r] =
|
|
2369
|
+
function Go(e, t) {
|
|
2370
|
+
const [n, r] = sn(e, (i) => t.id === i.id ? 0 : t.created_at === i.created_at ? -1 : t.created_at - i.created_at);
|
|
2371
2371
|
return r || e.splice(n, 0, t), e;
|
|
2372
2372
|
}
|
|
2373
|
-
function
|
|
2373
|
+
function sn(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), o = t(e[i]);
|
|
@@ -2380,21 +2380,21 @@ function rn(e, t) {
|
|
|
2380
2380
|
}
|
|
2381
2381
|
return [n, !1];
|
|
2382
2382
|
}
|
|
2383
|
-
var
|
|
2383
|
+
var Sr = class {
|
|
2384
2384
|
constructor(e) {
|
|
2385
2385
|
ee(this, "value");
|
|
2386
2386
|
ee(this, "next", null);
|
|
2387
2387
|
ee(this, "prev", null);
|
|
2388
2388
|
this.value = e;
|
|
2389
2389
|
}
|
|
2390
|
-
},
|
|
2390
|
+
}, Jo = class {
|
|
2391
2391
|
constructor() {
|
|
2392
2392
|
ee(this, "first");
|
|
2393
2393
|
ee(this, "last");
|
|
2394
2394
|
this.first = null, this.last = null;
|
|
2395
2395
|
}
|
|
2396
2396
|
enqueue(e) {
|
|
2397
|
-
const t = new
|
|
2397
|
+
const t = new Sr(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,147 +2407,147 @@ var xr = class {
|
|
|
2407
2407
|
const e = this.first;
|
|
2408
2408
|
return this.first = e.next, e.value;
|
|
2409
2409
|
}
|
|
2410
|
-
},
|
|
2410
|
+
}, Yo = class {
|
|
2411
2411
|
generateSecretKey() {
|
|
2412
|
-
return
|
|
2412
|
+
return Ze.utils.randomPrivateKey();
|
|
2413
2413
|
}
|
|
2414
2414
|
getPublicKey(e) {
|
|
2415
|
-
return M(
|
|
2415
|
+
return M(Ze.getPublicKey(e));
|
|
2416
2416
|
}
|
|
2417
2417
|
finalizeEvent(e, t) {
|
|
2418
2418
|
const n = e;
|
|
2419
|
-
return n.pubkey = M(
|
|
2419
|
+
return n.pubkey = M(Ze.getPublicKey(t)), n.id = nt(n), n.sig = M(Ze.sign(nt(n), t)), n[$e] = !0, n;
|
|
2420
2420
|
}
|
|
2421
2421
|
verifyEvent(e) {
|
|
2422
|
-
if (typeof e[
|
|
2423
|
-
return e[
|
|
2424
|
-
const t =
|
|
2422
|
+
if (typeof e[$e] == "boolean")
|
|
2423
|
+
return e[$e];
|
|
2424
|
+
const t = nt(e);
|
|
2425
2425
|
if (t !== e.id)
|
|
2426
|
-
return e[
|
|
2426
|
+
return e[$e] = !1, !1;
|
|
2427
2427
|
try {
|
|
2428
|
-
const n =
|
|
2429
|
-
return e[
|
|
2428
|
+
const n = Ze.verify(e.sig, t, e.pubkey);
|
|
2429
|
+
return e[$e] = n, n;
|
|
2430
2430
|
} catch {
|
|
2431
|
-
return e[
|
|
2431
|
+
return e[$e] = !1, !1;
|
|
2432
2432
|
}
|
|
2433
2433
|
}
|
|
2434
2434
|
};
|
|
2435
|
-
function
|
|
2436
|
-
if (!
|
|
2435
|
+
function Xo(e) {
|
|
2436
|
+
if (!xr(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 = Se(te.encode(
|
|
2440
|
+
function nt(e) {
|
|
2441
|
+
let t = Se(te.encode(Xo(e)));
|
|
2442
2442
|
return M(t);
|
|
2443
2443
|
}
|
|
2444
|
-
var gt = new
|
|
2445
|
-
D(
|
|
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
|
-
DraftClassifiedListing: () =>
|
|
2470
|
-
DraftLong: () =>
|
|
2471
|
-
Emojisets: () =>
|
|
2472
|
-
EncryptedDirectMessage: () =>
|
|
2473
|
-
EncryptedDirectMessages: () =>
|
|
2474
|
-
EventDeletion: () =>
|
|
2475
|
-
FileMetadata: () =>
|
|
2444
|
+
var gt = new Yo(), Me = gt.generateSecretKey, ke = gt.getPublicKey, ae = gt.finalizeEvent, wt = gt.verifyEvent, Qo = {};
|
|
2445
|
+
D(Qo, {
|
|
2446
|
+
Application: () => Qs,
|
|
2447
|
+
BadgeAward: () => cs,
|
|
2448
|
+
BadgeDefinition: () => Zs,
|
|
2449
|
+
BlockedRelaysList: () => Is,
|
|
2450
|
+
BookmarkList: () => ks,
|
|
2451
|
+
Bookmarksets: () => js,
|
|
2452
|
+
Calendar: () => sa,
|
|
2453
|
+
CalendarEventRSVP: () => aa,
|
|
2454
|
+
ChannelCreation: () => kr,
|
|
2455
|
+
ChannelHideMessage: () => Ir,
|
|
2456
|
+
ChannelMessage: () => Ur,
|
|
2457
|
+
ChannelMetadata: () => Br,
|
|
2458
|
+
ChannelMuteUser: () => _r,
|
|
2459
|
+
ClassifiedListing: () => na,
|
|
2460
|
+
ClientAuth: () => Lr,
|
|
2461
|
+
CommunitiesList: () => Bs,
|
|
2462
|
+
CommunityDefinition: () => ua,
|
|
2463
|
+
CommunityPostApproval: () => ws,
|
|
2464
|
+
Contacts: () => is,
|
|
2465
|
+
CreateOrUpdateProduct: () => Gs,
|
|
2466
|
+
CreateOrUpdateStall: () => Ws,
|
|
2467
|
+
Curationsets: () => Vs,
|
|
2468
|
+
Date: () => ia,
|
|
2469
|
+
DraftClassifiedListing: () => ra,
|
|
2470
|
+
DraftLong: () => Ys,
|
|
2471
|
+
Emojisets: () => Xs,
|
|
2472
|
+
EncryptedDirectMessage: () => os,
|
|
2473
|
+
EncryptedDirectMessages: () => ss,
|
|
2474
|
+
EventDeletion: () => as,
|
|
2475
|
+
FileMetadata: () => fs,
|
|
2476
2476
|
FileServerPreference: () => $s,
|
|
2477
|
-
Followsets: () =>
|
|
2478
|
-
GenericRepost: () =>
|
|
2479
|
-
Genericlists: () =>
|
|
2480
|
-
HTTPAuth: () =>
|
|
2481
|
-
Handlerinformation: () =>
|
|
2482
|
-
Handlerrecommendation: () =>
|
|
2483
|
-
Highlights: () =>
|
|
2484
|
-
InterestsList: () =>
|
|
2485
|
-
Interestsets: () =>
|
|
2486
|
-
JobFeedback: () =>
|
|
2487
|
-
JobRequest: () =>
|
|
2488
|
-
JobResult: () =>
|
|
2489
|
-
Label: () =>
|
|
2490
|
-
LightningPubRPC: () =>
|
|
2491
|
-
LiveChatMessage: () =>
|
|
2492
|
-
LiveEvent: () =>
|
|
2493
|
-
LongFormArticle: () =>
|
|
2494
|
-
Metadata: () =>
|
|
2495
|
-
Mutelist: () =>
|
|
2496
|
-
NWCWalletInfo: () =>
|
|
2497
|
-
NWCWalletRequest: () =>
|
|
2477
|
+
Followsets: () => Hs,
|
|
2478
|
+
GenericRepost: () => ls,
|
|
2479
|
+
Genericlists: () => qs,
|
|
2480
|
+
HTTPAuth: () => ln,
|
|
2481
|
+
Handlerinformation: () => la,
|
|
2482
|
+
Handlerrecommendation: () => ca,
|
|
2483
|
+
Highlights: () => As,
|
|
2484
|
+
InterestsList: () => Ls,
|
|
2485
|
+
Interestsets: () => Fs,
|
|
2486
|
+
JobFeedback: () => Es,
|
|
2487
|
+
JobRequest: () => bs,
|
|
2488
|
+
JobResult: () => vs,
|
|
2489
|
+
Label: () => gs,
|
|
2490
|
+
LightningPubRPC: () => Os,
|
|
2491
|
+
LiveChatMessage: () => hs,
|
|
2492
|
+
LiveEvent: () => ea,
|
|
2493
|
+
LongFormArticle: () => Js,
|
|
2494
|
+
Metadata: () => ts,
|
|
2495
|
+
Mutelist: () => Ks,
|
|
2496
|
+
NWCWalletInfo: () => Rs,
|
|
2497
|
+
NWCWalletRequest: () => Tr,
|
|
2498
2498
|
NWCWalletResponse: () => Ps,
|
|
2499
|
-
NostrConnect: () =>
|
|
2500
|
-
OpenTimestamps: () =>
|
|
2501
|
-
Pinlist: () =>
|
|
2502
|
-
ProblemTracker: () =>
|
|
2499
|
+
NostrConnect: () => Ms,
|
|
2500
|
+
OpenTimestamps: () => us,
|
|
2501
|
+
Pinlist: () => Ns,
|
|
2502
|
+
ProblemTracker: () => ds,
|
|
2503
2503
|
ProfileBadges: () => zs,
|
|
2504
|
-
PublicChatsList: () =>
|
|
2505
|
-
Reaction: () =>
|
|
2506
|
-
RecommendRelay: () =>
|
|
2507
|
-
RelayList: () =>
|
|
2508
|
-
Relaysets: () =>
|
|
2509
|
-
Report: () =>
|
|
2510
|
-
Reporting: () =>
|
|
2511
|
-
Repost: () =>
|
|
2512
|
-
SearchRelaysList: () =>
|
|
2513
|
-
ShortTextNote: () =>
|
|
2514
|
-
Time: () =>
|
|
2515
|
-
UserEmojiList: () =>
|
|
2516
|
-
UserStatuses: () =>
|
|
2517
|
-
Zap: () =>
|
|
2518
|
-
ZapGoal: () =>
|
|
2519
|
-
ZapRequest: () =>
|
|
2520
|
-
classifyKind: () =>
|
|
2521
|
-
isEphemeralKind: () =>
|
|
2522
|
-
isParameterizedReplaceableKind: () =>
|
|
2523
|
-
isRegularKind: () =>
|
|
2524
|
-
isReplaceableKind: () =>
|
|
2504
|
+
PublicChatsList: () => Us,
|
|
2505
|
+
Reaction: () => cn,
|
|
2506
|
+
RecommendRelay: () => rs,
|
|
2507
|
+
RelayList: () => Cs,
|
|
2508
|
+
Relaysets: () => Ds,
|
|
2509
|
+
Report: () => ys,
|
|
2510
|
+
Reporting: () => ps,
|
|
2511
|
+
Repost: () => an,
|
|
2512
|
+
SearchRelaysList: () => _s,
|
|
2513
|
+
ShortTextNote: () => ns,
|
|
2514
|
+
Time: () => oa,
|
|
2515
|
+
UserEmojiList: () => Ts,
|
|
2516
|
+
UserStatuses: () => ta,
|
|
2517
|
+
Zap: () => Ss,
|
|
2518
|
+
ZapGoal: () => ms,
|
|
2519
|
+
ZapRequest: () => xs,
|
|
2520
|
+
classifyKind: () => es,
|
|
2521
|
+
isEphemeralKind: () => Nr,
|
|
2522
|
+
isParameterizedReplaceableKind: () => Cr,
|
|
2523
|
+
isRegularKind: () => Ar,
|
|
2524
|
+
isReplaceableKind: () => Kr
|
|
2525
2525
|
});
|
|
2526
|
-
function
|
|
2526
|
+
function Ar(e) {
|
|
2527
2527
|
return 1e3 <= e && e < 1e4 || [1, 2, 4, 5, 6, 7, 8, 16, 40, 41, 42, 43, 44].includes(e);
|
|
2528
2528
|
}
|
|
2529
|
-
function
|
|
2529
|
+
function Kr(e) {
|
|
2530
2530
|
return [0, 3].includes(e) || 1e4 <= e && e < 2e4;
|
|
2531
2531
|
}
|
|
2532
|
-
function
|
|
2532
|
+
function Nr(e) {
|
|
2533
2533
|
return 2e4 <= e && e < 3e4;
|
|
2534
2534
|
}
|
|
2535
|
-
function
|
|
2535
|
+
function Cr(e) {
|
|
2536
2536
|
return 3e4 <= e && e < 4e4;
|
|
2537
2537
|
}
|
|
2538
|
-
function
|
|
2539
|
-
return
|
|
2538
|
+
function es(e) {
|
|
2539
|
+
return Ar(e) ? "regular" : Kr(e) ? "replaceable" : Nr(e) ? "ephemeral" : Cr(e) ? "parameterized" : "unknown";
|
|
2540
2540
|
}
|
|
2541
|
-
var
|
|
2542
|
-
D(
|
|
2543
|
-
getHex64: () =>
|
|
2541
|
+
var ts = 0, ns = 1, rs = 2, is = 3, os = 4, ss = 4, as = 5, an = 6, cn = 7, cs = 8, ls = 16, kr = 40, Br = 41, Ur = 42, Ir = 43, _r = 44, us = 1040, fs = 1063, hs = 1311, ds = 1971, ys = 1984, ps = 1984, gs = 1985, ws = 4550, bs = 5999, vs = 6999, Es = 7e3, ms = 9041, xs = 9734, Ss = 9735, As = 9802, Ks = 1e4, Ns = 10001, Cs = 10002, ks = 10003, Bs = 10004, Us = 10005, Is = 10006, _s = 10007, Ls = 10015, Ts = 10030, $s = 10096, Rs = 13194, Os = 21e3, Lr = 22242, Tr = 23194, Ps = 23195, Ms = 24133, ln = 27235, Hs = 3e4, qs = 30001, Ds = 30002, js = 30003, Vs = 30004, zs = 30008, Zs = 30009, Fs = 30015, Ws = 30017, Gs = 30018, Js = 30023, Ys = 30024, Xs = 30030, Qs = 30078, ea = 30311, ta = 30315, na = 30402, ra = 30403, ia = 31922, oa = 31923, sa = 31924, aa = 31925, ca = 31989, la = 31990, ua = 34550, fa = {};
|
|
2542
|
+
D(fa, {
|
|
2543
|
+
getHex64: () => un,
|
|
2544
2544
|
getInt: () => $r,
|
|
2545
|
-
getSubscriptionId: () =>
|
|
2546
|
-
matchEventId: () =>
|
|
2547
|
-
matchEventKind: () =>
|
|
2548
|
-
matchEventPubkey: () =>
|
|
2545
|
+
getSubscriptionId: () => ha,
|
|
2546
|
+
matchEventId: () => da,
|
|
2547
|
+
matchEventKind: () => pa,
|
|
2548
|
+
matchEventPubkey: () => ya
|
|
2549
2549
|
});
|
|
2550
|
-
function
|
|
2550
|
+
function un(e, t) {
|
|
2551
2551
|
let n = t.length + 3, r = e.indexOf(`"${t}":`) + n, i = e.slice(r).indexOf('"') + r + 1;
|
|
2552
2552
|
return e.slice(i, i + 64);
|
|
2553
2553
|
}
|
|
@@ -2555,7 +2555,7 @@ function $r(e, t) {
|
|
|
2555
2555
|
let n = t.length, r = e.indexOf(`"${t}":`) + n + 3, i = e.slice(r), o = Math.min(i.indexOf(","), i.indexOf("}"));
|
|
2556
2556
|
return parseInt(i.slice(0, o), 10);
|
|
2557
2557
|
}
|
|
2558
|
-
function
|
|
2558
|
+
function ha(e) {
|
|
2559
2559
|
let t = e.slice(0, 22).indexOf('"EVENT"');
|
|
2560
2560
|
if (t === -1)
|
|
2561
2561
|
return null;
|
|
@@ -2568,22 +2568,22 @@ function fa(e) {
|
|
|
2568
2568
|
let o = r + 1 + i;
|
|
2569
2569
|
return e.slice(r + 1, o);
|
|
2570
2570
|
}
|
|
2571
|
-
function ha(e, t) {
|
|
2572
|
-
return t === ln(e, "id");
|
|
2573
|
-
}
|
|
2574
2571
|
function da(e, t) {
|
|
2575
|
-
return t ===
|
|
2572
|
+
return t === un(e, "id");
|
|
2576
2573
|
}
|
|
2577
2574
|
function ya(e, t) {
|
|
2575
|
+
return t === un(e, "pubkey");
|
|
2576
|
+
}
|
|
2577
|
+
function pa(e, t) {
|
|
2578
2578
|
return t === $r(e, "kind");
|
|
2579
2579
|
}
|
|
2580
|
-
var
|
|
2581
|
-
D(
|
|
2582
|
-
makeAuthEvent: () =>
|
|
2580
|
+
var ga = {};
|
|
2581
|
+
D(ga, {
|
|
2582
|
+
makeAuthEvent: () => wa
|
|
2583
2583
|
});
|
|
2584
|
-
function
|
|
2584
|
+
function wa(e, t) {
|
|
2585
2585
|
return {
|
|
2586
|
-
kind:
|
|
2586
|
+
kind: Lr,
|
|
2587
2587
|
created_at: Math.floor(Date.now() / 1e3),
|
|
2588
2588
|
tags: [
|
|
2589
2589
|
["relay", e],
|
|
@@ -2592,41 +2592,41 @@ function ga(e, t) {
|
|
|
2592
2592
|
content: ""
|
|
2593
2593
|
};
|
|
2594
2594
|
}
|
|
2595
|
-
var
|
|
2595
|
+
var ba;
|
|
2596
2596
|
try {
|
|
2597
|
-
|
|
2597
|
+
ba = WebSocket;
|
|
2598
2598
|
} catch {
|
|
2599
2599
|
}
|
|
2600
|
-
var
|
|
2600
|
+
var va;
|
|
2601
2601
|
try {
|
|
2602
|
-
|
|
2602
|
+
va = WebSocket;
|
|
2603
2603
|
} catch {
|
|
2604
2604
|
}
|
|
2605
|
-
var
|
|
2606
|
-
D(
|
|
2607
|
-
BECH32_REGEX: () =>
|
|
2608
|
-
Bech32MaxSize: () =>
|
|
2609
|
-
decode: () =>
|
|
2610
|
-
encodeBytes: () =>
|
|
2611
|
-
naddrEncode: () =>
|
|
2612
|
-
neventEncode: () =>
|
|
2613
|
-
noteEncode: () =>
|
|
2614
|
-
nprofileEncode: () =>
|
|
2615
|
-
npubEncode: () =>
|
|
2616
|
-
nrelayEncode: () =>
|
|
2617
|
-
nsecEncode: () =>
|
|
2605
|
+
var We = {};
|
|
2606
|
+
D(We, {
|
|
2607
|
+
BECH32_REGEX: () => Rr,
|
|
2608
|
+
Bech32MaxSize: () => fn,
|
|
2609
|
+
decode: () => bt,
|
|
2610
|
+
encodeBytes: () => vt,
|
|
2611
|
+
naddrEncode: () => Na,
|
|
2612
|
+
neventEncode: () => Ka,
|
|
2613
|
+
noteEncode: () => Sa,
|
|
2614
|
+
nprofileEncode: () => Aa,
|
|
2615
|
+
npubEncode: () => xa,
|
|
2616
|
+
nrelayEncode: () => Ca,
|
|
2617
|
+
nsecEncode: () => ma
|
|
2618
2618
|
});
|
|
2619
|
-
var
|
|
2620
|
-
function
|
|
2619
|
+
var fn = 5e3, Rr = /[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;
|
|
2620
|
+
function Ea(e) {
|
|
2621
2621
|
const t = new Uint8Array(4);
|
|
2622
2622
|
return t[0] = e >> 24 & 255, t[1] = e >> 16 & 255, t[2] = e >> 8 & 255, t[3] = e & 255, t;
|
|
2623
2623
|
}
|
|
2624
|
-
function
|
|
2625
|
-
var i, o, s,
|
|
2626
|
-
let { prefix: t, words: n } =
|
|
2624
|
+
function bt(e) {
|
|
2625
|
+
var i, o, s, a, c, l, f, u;
|
|
2626
|
+
let { prefix: t, words: n } = je.decode(e, fn), r = new Uint8Array(je.fromWords(n));
|
|
2627
2627
|
switch (t) {
|
|
2628
2628
|
case "nprofile": {
|
|
2629
|
-
let d =
|
|
2629
|
+
let d = et(r);
|
|
2630
2630
|
if (!((i = d[0]) != null && i[0]))
|
|
2631
2631
|
throw new Error("missing TLV 0 for nprofile");
|
|
2632
2632
|
if (d[0][0].length !== 32)
|
|
@@ -2640,7 +2640,7 @@ function wt(e) {
|
|
|
2640
2640
|
};
|
|
2641
2641
|
}
|
|
2642
2642
|
case "nevent": {
|
|
2643
|
-
let d =
|
|
2643
|
+
let d = et(r);
|
|
2644
2644
|
if (!((o = d[0]) != null && o[0]))
|
|
2645
2645
|
throw new Error("missing TLV 0 for nevent");
|
|
2646
2646
|
if (d[0][0].length !== 32)
|
|
@@ -2655,13 +2655,13 @@ function wt(e) {
|
|
|
2655
2655
|
id: M(d[0][0]),
|
|
2656
2656
|
relays: d[1] ? d[1].map((p) => ie.decode(p)) : [],
|
|
2657
2657
|
author: (s = d[2]) != null && s[0] ? M(d[2][0]) : void 0,
|
|
2658
|
-
kind: (
|
|
2658
|
+
kind: (a = d[3]) != null && a[0] ? parseInt(M(d[3][0]), 16) : void 0
|
|
2659
2659
|
}
|
|
2660
2660
|
};
|
|
2661
2661
|
}
|
|
2662
2662
|
case "naddr": {
|
|
2663
|
-
let d =
|
|
2664
|
-
if (!((
|
|
2663
|
+
let d = et(r);
|
|
2664
|
+
if (!((c = d[0]) != null && c[0]))
|
|
2665
2665
|
throw new Error("missing TLV 0 for naddr");
|
|
2666
2666
|
if (!((l = d[2]) != null && l[0]))
|
|
2667
2667
|
throw new Error("missing TLV 2 for naddr");
|
|
@@ -2682,7 +2682,7 @@ function wt(e) {
|
|
|
2682
2682
|
};
|
|
2683
2683
|
}
|
|
2684
2684
|
case "nrelay": {
|
|
2685
|
-
let d =
|
|
2685
|
+
let d = et(r);
|
|
2686
2686
|
if (!((u = d[0]) != null && u[0]))
|
|
2687
2687
|
throw new Error("missing TLV 0 for nrelay");
|
|
2688
2688
|
return {
|
|
@@ -2699,7 +2699,7 @@ function wt(e) {
|
|
|
2699
2699
|
throw new Error(`unknown prefix ${t}`);
|
|
2700
2700
|
}
|
|
2701
2701
|
}
|
|
2702
|
-
function
|
|
2702
|
+
function et(e) {
|
|
2703
2703
|
let t = {}, n = e;
|
|
2704
2704
|
for (; n.length > 0; ) {
|
|
2705
2705
|
let r = n[0], i = n[1], o = n.slice(2, 2 + i);
|
|
@@ -2709,58 +2709,58 @@ function Qe(e) {
|
|
|
2709
2709
|
}
|
|
2710
2710
|
return t;
|
|
2711
2711
|
}
|
|
2712
|
-
function Ea(e) {
|
|
2713
|
-
return bt("nsec", e);
|
|
2714
|
-
}
|
|
2715
2712
|
function ma(e) {
|
|
2716
|
-
return
|
|
2713
|
+
return vt("nsec", e);
|
|
2717
2714
|
}
|
|
2718
2715
|
function xa(e) {
|
|
2719
|
-
return
|
|
2716
|
+
return vt("npub", W(e));
|
|
2720
2717
|
}
|
|
2721
|
-
function
|
|
2722
|
-
|
|
2723
|
-
return De.encode(e, n, un);
|
|
2718
|
+
function Sa(e) {
|
|
2719
|
+
return vt("note", W(e));
|
|
2724
2720
|
}
|
|
2725
|
-
function
|
|
2726
|
-
|
|
2721
|
+
function Xe(e, t) {
|
|
2722
|
+
let n = je.toWords(t);
|
|
2723
|
+
return je.encode(e, n, fn);
|
|
2727
2724
|
}
|
|
2728
|
-
function
|
|
2729
|
-
|
|
2725
|
+
function vt(e, t) {
|
|
2726
|
+
return Xe(e, t);
|
|
2727
|
+
}
|
|
2728
|
+
function Aa(e) {
|
|
2729
|
+
let t = Et({
|
|
2730
2730
|
0: [W(e.pubkey)],
|
|
2731
2731
|
1: (e.relays || []).map((n) => te.encode(n))
|
|
2732
2732
|
});
|
|
2733
|
-
return
|
|
2733
|
+
return Xe("nprofile", t);
|
|
2734
2734
|
}
|
|
2735
|
-
function
|
|
2735
|
+
function Ka(e) {
|
|
2736
2736
|
let t;
|
|
2737
|
-
e.kind !== void 0 && (t =
|
|
2738
|
-
let n =
|
|
2737
|
+
e.kind !== void 0 && (t = Ea(e.kind));
|
|
2738
|
+
let n = Et({
|
|
2739
2739
|
0: [W(e.id)],
|
|
2740
2740
|
1: (e.relays || []).map((r) => te.encode(r)),
|
|
2741
2741
|
2: e.author ? [W(e.author)] : [],
|
|
2742
2742
|
3: t ? [new Uint8Array(t)] : []
|
|
2743
2743
|
});
|
|
2744
|
-
return
|
|
2744
|
+
return Xe("nevent", n);
|
|
2745
2745
|
}
|
|
2746
|
-
function
|
|
2746
|
+
function Na(e) {
|
|
2747
2747
|
let t = new ArrayBuffer(4);
|
|
2748
2748
|
new DataView(t).setUint32(0, e.kind, !1);
|
|
2749
|
-
let n =
|
|
2749
|
+
let n = Et({
|
|
2750
2750
|
0: [te.encode(e.identifier)],
|
|
2751
2751
|
1: (e.relays || []).map((r) => te.encode(r)),
|
|
2752
2752
|
2: [W(e.pubkey)],
|
|
2753
2753
|
3: [new Uint8Array(t)]
|
|
2754
2754
|
});
|
|
2755
|
-
return
|
|
2755
|
+
return Xe("naddr", n);
|
|
2756
2756
|
}
|
|
2757
|
-
function
|
|
2758
|
-
let t =
|
|
2757
|
+
function Ca(e) {
|
|
2758
|
+
let t = Et({
|
|
2759
2759
|
0: [te.encode(e)]
|
|
2760
2760
|
});
|
|
2761
|
-
return
|
|
2761
|
+
return Xe("nrelay", t);
|
|
2762
2762
|
}
|
|
2763
|
-
function
|
|
2763
|
+
function Et(e) {
|
|
2764
2764
|
let t = [];
|
|
2765
2765
|
return Object.entries(e).reverse().forEach(([n, r]) => {
|
|
2766
2766
|
r.forEach((i) => {
|
|
@@ -2769,68 +2769,68 @@ function vt(e) {
|
|
|
2769
2769
|
});
|
|
2770
2770
|
}), dt(...t);
|
|
2771
2771
|
}
|
|
2772
|
-
var
|
|
2773
|
-
D(
|
|
2774
|
-
decrypt: () =>
|
|
2775
|
-
encrypt: () =>
|
|
2772
|
+
var ka = {};
|
|
2773
|
+
D(ka, {
|
|
2774
|
+
decrypt: () => Ba,
|
|
2775
|
+
encrypt: () => Or
|
|
2776
2776
|
});
|
|
2777
|
-
async function
|
|
2777
|
+
async function Or(e, t, n) {
|
|
2778
2778
|
const r = e instanceof Uint8Array ? M(e) : e, i = Ue.getSharedSecret(r, "02" + t), o = Pr(i);
|
|
2779
|
-
let s = Uint8Array.from(
|
|
2779
|
+
let s = Uint8Array.from(or(16)), a = te.encode(n), c = pr(o, s).encrypt(a), l = ue.encode(new Uint8Array(c)), f = ue.encode(new Uint8Array(s.buffer));
|
|
2780
2780
|
return `${l}?iv=${f}`;
|
|
2781
2781
|
}
|
|
2782
|
-
async function
|
|
2782
|
+
async function Ba(e, t, n) {
|
|
2783
2783
|
const r = e instanceof Uint8Array ? M(e) : e;
|
|
2784
|
-
let [i, o] = n.split("?iv="), s = Ue.getSharedSecret(r, "02" + t),
|
|
2784
|
+
let [i, o] = n.split("?iv="), s = Ue.getSharedSecret(r, "02" + t), a = Pr(s), c = ue.decode(o), l = ue.decode(i), f = pr(a, c).decrypt(l);
|
|
2785
2785
|
return ie.decode(f);
|
|
2786
2786
|
}
|
|
2787
2787
|
function Pr(e) {
|
|
2788
2788
|
return e.slice(1, 33);
|
|
2789
2789
|
}
|
|
2790
|
-
var
|
|
2791
|
-
D(
|
|
2792
|
-
NIP05_REGEX: () =>
|
|
2793
|
-
isValid: () =>
|
|
2794
|
-
queryProfile: () =>
|
|
2795
|
-
searchDomain: () =>
|
|
2796
|
-
useFetchImplementation: () =>
|
|
2790
|
+
var Ua = {};
|
|
2791
|
+
D(Ua, {
|
|
2792
|
+
NIP05_REGEX: () => Mr,
|
|
2793
|
+
isValid: () => La,
|
|
2794
|
+
queryProfile: () => Hr,
|
|
2795
|
+
searchDomain: () => _a,
|
|
2796
|
+
useFetchImplementation: () => Ia
|
|
2797
2797
|
});
|
|
2798
|
-
var
|
|
2798
|
+
var Mr = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/, mt;
|
|
2799
2799
|
try {
|
|
2800
|
-
|
|
2800
|
+
mt = fetch;
|
|
2801
2801
|
} catch {
|
|
2802
2802
|
}
|
|
2803
|
-
function
|
|
2804
|
-
|
|
2803
|
+
function Ia(e) {
|
|
2804
|
+
mt = e;
|
|
2805
2805
|
}
|
|
2806
|
-
async function
|
|
2806
|
+
async function _a(e, t = "") {
|
|
2807
2807
|
try {
|
|
2808
2808
|
const n = `https://${e}/.well-known/nostr.json?name=${t}`;
|
|
2809
|
-
return (await (await
|
|
2809
|
+
return (await (await mt(n, { redirect: "error" })).json()).names;
|
|
2810
2810
|
} catch {
|
|
2811
2811
|
return {};
|
|
2812
2812
|
}
|
|
2813
2813
|
}
|
|
2814
|
-
async function
|
|
2814
|
+
async function Hr(e) {
|
|
2815
2815
|
var o;
|
|
2816
|
-
const t = e.match(
|
|
2816
|
+
const t = e.match(Mr);
|
|
2817
2817
|
if (!t)
|
|
2818
2818
|
return null;
|
|
2819
2819
|
const [n, r = "_", i] = t;
|
|
2820
2820
|
try {
|
|
2821
|
-
const s = `https://${i}/.well-known/nostr.json?name=${r}`,
|
|
2822
|
-
let
|
|
2823
|
-
return
|
|
2821
|
+
const s = `https://${i}/.well-known/nostr.json?name=${r}`, a = await (await mt(s, { redirect: "error" })).json();
|
|
2822
|
+
let c = a.names[r];
|
|
2823
|
+
return c ? { pubkey: c, relays: (o = a.relays) == null ? void 0 : o[c] } : null;
|
|
2824
2824
|
} catch {
|
|
2825
2825
|
return null;
|
|
2826
2826
|
}
|
|
2827
2827
|
}
|
|
2828
|
-
async function
|
|
2829
|
-
let n = await
|
|
2828
|
+
async function La(e, t) {
|
|
2829
|
+
let n = await Hr(t);
|
|
2830
2830
|
return n ? n.pubkey === e : !1;
|
|
2831
2831
|
}
|
|
2832
|
-
var
|
|
2833
|
-
D(
|
|
2832
|
+
var Ta = {};
|
|
2833
|
+
D(Ta, {
|
|
2834
2834
|
parse: () => $a
|
|
2835
2835
|
});
|
|
2836
2836
|
function $a(e) {
|
|
@@ -2846,19 +2846,19 @@ function $a(e) {
|
|
|
2846
2846
|
relays: r[2] ? [r[2]] : []
|
|
2847
2847
|
});
|
|
2848
2848
|
for (let r = 0; r < n.length; r++) {
|
|
2849
|
-
const i = n[r], [o, s,
|
|
2849
|
+
const i = n[r], [o, s, a, c] = i, l = {
|
|
2850
2850
|
id: s,
|
|
2851
|
-
relays:
|
|
2851
|
+
relays: a ? [a] : []
|
|
2852
2852
|
}, f = r === 0, u = r === n.length - 1;
|
|
2853
|
-
if (
|
|
2853
|
+
if (c === "root") {
|
|
2854
2854
|
t.root = l;
|
|
2855
2855
|
continue;
|
|
2856
2856
|
}
|
|
2857
|
-
if (
|
|
2857
|
+
if (c === "reply") {
|
|
2858
2858
|
t.reply = l;
|
|
2859
2859
|
continue;
|
|
2860
2860
|
}
|
|
2861
|
-
if (
|
|
2861
|
+
if (c === "mention") {
|
|
2862
2862
|
t.mentions.push(l);
|
|
2863
2863
|
continue;
|
|
2864
2864
|
}
|
|
@@ -2874,30 +2874,30 @@ function $a(e) {
|
|
|
2874
2874
|
}
|
|
2875
2875
|
return t;
|
|
2876
2876
|
}
|
|
2877
|
-
var
|
|
2878
|
-
D(
|
|
2877
|
+
var Ra = {};
|
|
2878
|
+
D(Ra, {
|
|
2879
2879
|
fetchRelayInformation: () => Pa,
|
|
2880
|
-
useFetchImplementation: () =>
|
|
2880
|
+
useFetchImplementation: () => Oa
|
|
2881
2881
|
});
|
|
2882
|
-
var
|
|
2882
|
+
var qr;
|
|
2883
2883
|
try {
|
|
2884
|
-
|
|
2884
|
+
qr = fetch;
|
|
2885
2885
|
} catch {
|
|
2886
2886
|
}
|
|
2887
|
-
function
|
|
2888
|
-
|
|
2887
|
+
function Oa(e) {
|
|
2888
|
+
qr = e;
|
|
2889
2889
|
}
|
|
2890
2890
|
async function Pa(e) {
|
|
2891
2891
|
return await (await fetch(e.replace("ws://", "http://").replace("wss://", "https://"), {
|
|
2892
2892
|
headers: { Accept: "application/nostr+json" }
|
|
2893
2893
|
})).json();
|
|
2894
2894
|
}
|
|
2895
|
-
var
|
|
2896
|
-
D(
|
|
2897
|
-
getPow: () =>
|
|
2898
|
-
minePow: () =>
|
|
2895
|
+
var Ma = {};
|
|
2896
|
+
D(Ma, {
|
|
2897
|
+
getPow: () => Dr,
|
|
2898
|
+
minePow: () => Ha
|
|
2899
2899
|
});
|
|
2900
|
-
function
|
|
2900
|
+
function Dr(e) {
|
|
2901
2901
|
let t = 0;
|
|
2902
2902
|
for (let n = 0; n < e.length; n++) {
|
|
2903
2903
|
const r = parseInt(e[n], 16);
|
|
@@ -2910,26 +2910,26 @@ function qr(e) {
|
|
|
2910
2910
|
}
|
|
2911
2911
|
return t;
|
|
2912
2912
|
}
|
|
2913
|
-
function
|
|
2913
|
+
function Ha(e, t) {
|
|
2914
2914
|
let n = 0;
|
|
2915
2915
|
const r = e, i = ["nonce", n.toString(), t.toString()];
|
|
2916
2916
|
for (r.tags.push(i); ; ) {
|
|
2917
2917
|
const o = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
2918
|
-
if (o !== r.created_at && (n = 0, r.created_at = o), i[1] = (++n).toString(), r.id =
|
|
2918
|
+
if (o !== r.created_at && (n = 0, r.created_at = o), i[1] = (++n).toString(), r.id = nt(r), Dr(r.id) >= t)
|
|
2919
2919
|
break;
|
|
2920
2920
|
}
|
|
2921
2921
|
return r;
|
|
2922
2922
|
}
|
|
2923
|
-
var
|
|
2924
|
-
D(
|
|
2925
|
-
finishRepostEvent: () =>
|
|
2926
|
-
getRepostedEvent: () =>
|
|
2927
|
-
getRepostedEventPointer: () =>
|
|
2923
|
+
var qa = {};
|
|
2924
|
+
D(qa, {
|
|
2925
|
+
finishRepostEvent: () => Da,
|
|
2926
|
+
getRepostedEvent: () => ja,
|
|
2927
|
+
getRepostedEventPointer: () => jr
|
|
2928
2928
|
});
|
|
2929
|
-
function
|
|
2929
|
+
function Da(e, t, n, r) {
|
|
2930
2930
|
return ae(
|
|
2931
2931
|
{
|
|
2932
|
-
kind:
|
|
2932
|
+
kind: an,
|
|
2933
2933
|
tags: [...e.tags ?? [], ["e", t.id, n], ["p", t.pubkey]],
|
|
2934
2934
|
content: e.content === "" ? "" : JSON.stringify(t),
|
|
2935
2935
|
created_at: e.created_at
|
|
@@ -2937,8 +2937,8 @@ function qa(e, t, n, r) {
|
|
|
2937
2937
|
r
|
|
2938
2938
|
);
|
|
2939
2939
|
}
|
|
2940
|
-
function
|
|
2941
|
-
if (e.kind !==
|
|
2940
|
+
function jr(e) {
|
|
2941
|
+
if (e.kind !== an)
|
|
2942
2942
|
return;
|
|
2943
2943
|
let t, n;
|
|
2944
2944
|
for (let r = e.tags.length - 1; r >= 0 && (t === void 0 || n === void 0); r--) {
|
|
@@ -2952,8 +2952,8 @@ function Dr(e) {
|
|
|
2952
2952
|
author: n == null ? void 0 : n[1]
|
|
2953
2953
|
};
|
|
2954
2954
|
}
|
|
2955
|
-
function
|
|
2956
|
-
const n =
|
|
2955
|
+
function ja(e, { skipVerification: t } = {}) {
|
|
2956
|
+
const n = jr(e);
|
|
2957
2957
|
if (n === void 0 || e.content === "")
|
|
2958
2958
|
return;
|
|
2959
2959
|
let r;
|
|
@@ -2962,48 +2962,48 @@ function Da(e, { skipVerification: t } = {}) {
|
|
|
2962
2962
|
} catch {
|
|
2963
2963
|
return;
|
|
2964
2964
|
}
|
|
2965
|
-
if (r.id === n.id && !(!t && !
|
|
2965
|
+
if (r.id === n.id && !(!t && !wt(r)))
|
|
2966
2966
|
return r;
|
|
2967
2967
|
}
|
|
2968
|
-
var
|
|
2969
|
-
D(
|
|
2970
|
-
NOSTR_URI_REGEX: () =>
|
|
2971
|
-
parse: () =>
|
|
2968
|
+
var Va = {};
|
|
2969
|
+
D(Va, {
|
|
2970
|
+
NOSTR_URI_REGEX: () => xt,
|
|
2971
|
+
parse: () => Za,
|
|
2972
2972
|
test: () => za
|
|
2973
2973
|
});
|
|
2974
|
-
var
|
|
2974
|
+
var xt = new RegExp(`nostr:(${Rr.source})`);
|
|
2975
2975
|
function za(e) {
|
|
2976
|
-
return typeof e == "string" && new RegExp(`^${
|
|
2976
|
+
return typeof e == "string" && new RegExp(`^${xt.source}$`).test(e);
|
|
2977
2977
|
}
|
|
2978
|
-
function
|
|
2979
|
-
const t = e.match(new RegExp(`^${
|
|
2978
|
+
function Za(e) {
|
|
2979
|
+
const t = e.match(new RegExp(`^${xt.source}$`));
|
|
2980
2980
|
if (!t)
|
|
2981
2981
|
throw new Error(`Invalid Nostr URI: ${e}`);
|
|
2982
2982
|
return {
|
|
2983
2983
|
uri: t[0],
|
|
2984
2984
|
value: t[1],
|
|
2985
|
-
decoded:
|
|
2985
|
+
decoded: bt(t[1])
|
|
2986
2986
|
};
|
|
2987
2987
|
}
|
|
2988
|
-
var
|
|
2989
|
-
D(
|
|
2990
|
-
finishReactionEvent: () =>
|
|
2991
|
-
getReactedEventPointer: () =>
|
|
2988
|
+
var Fa = {};
|
|
2989
|
+
D(Fa, {
|
|
2990
|
+
finishReactionEvent: () => Wa,
|
|
2991
|
+
getReactedEventPointer: () => Ga
|
|
2992
2992
|
});
|
|
2993
|
-
function
|
|
2993
|
+
function Wa(e, t, n) {
|
|
2994
2994
|
const r = t.tags.filter((i) => i.length >= 2 && (i[0] === "e" || i[0] === "p"));
|
|
2995
2995
|
return ae(
|
|
2996
2996
|
{
|
|
2997
2997
|
...e,
|
|
2998
|
-
kind:
|
|
2998
|
+
kind: cn,
|
|
2999
2999
|
tags: [...e.tags ?? [], ...r, ["e", t.id], ["p", t.pubkey]],
|
|
3000
3000
|
content: e.content ?? "+"
|
|
3001
3001
|
},
|
|
3002
3002
|
n
|
|
3003
3003
|
);
|
|
3004
3004
|
}
|
|
3005
|
-
function
|
|
3006
|
-
if (e.kind !==
|
|
3005
|
+
function Ga(e) {
|
|
3006
|
+
if (e.kind !== cn)
|
|
3007
3007
|
return;
|
|
3008
3008
|
let t, n;
|
|
3009
3009
|
for (let r = e.tags.length - 1; r >= 0 && (t === void 0 || n === void 0); r--) {
|
|
@@ -3017,44 +3017,44 @@ function Wa(e) {
|
|
|
3017
3017
|
author: n[1]
|
|
3018
3018
|
};
|
|
3019
3019
|
}
|
|
3020
|
-
var
|
|
3021
|
-
D(
|
|
3022
|
-
matchAll: () =>
|
|
3023
|
-
regex: () =>
|
|
3024
|
-
replaceAll: () =>
|
|
3020
|
+
var Ja = {};
|
|
3021
|
+
D(Ja, {
|
|
3022
|
+
matchAll: () => Ya,
|
|
3023
|
+
regex: () => hn,
|
|
3024
|
+
replaceAll: () => Xa
|
|
3025
3025
|
});
|
|
3026
|
-
var
|
|
3027
|
-
function*
|
|
3028
|
-
const t = e.matchAll(
|
|
3026
|
+
var hn = () => new RegExp(`\\b${xt.source}\\b`, "g");
|
|
3027
|
+
function* Ya(e) {
|
|
3028
|
+
const t = e.matchAll(hn());
|
|
3029
3029
|
for (const n of t)
|
|
3030
3030
|
try {
|
|
3031
3031
|
const [r, i] = n;
|
|
3032
3032
|
yield {
|
|
3033
3033
|
uri: r,
|
|
3034
3034
|
value: i,
|
|
3035
|
-
decoded:
|
|
3035
|
+
decoded: bt(i),
|
|
3036
3036
|
start: n.index,
|
|
3037
3037
|
end: n.index + r.length
|
|
3038
3038
|
};
|
|
3039
3039
|
} catch {
|
|
3040
3040
|
}
|
|
3041
3041
|
}
|
|
3042
|
-
function
|
|
3043
|
-
return e.replaceAll(
|
|
3042
|
+
function Xa(e, t) {
|
|
3043
|
+
return e.replaceAll(hn(), (n, r) => t({
|
|
3044
3044
|
uri: n,
|
|
3045
3045
|
value: r,
|
|
3046
|
-
decoded:
|
|
3046
|
+
decoded: bt(r)
|
|
3047
3047
|
}));
|
|
3048
3048
|
}
|
|
3049
|
-
var
|
|
3050
|
-
D(
|
|
3051
|
-
channelCreateEvent: () =>
|
|
3052
|
-
channelHideMessageEvent: () =>
|
|
3053
|
-
channelMessageEvent: () =>
|
|
3054
|
-
channelMetadataEvent: () =>
|
|
3055
|
-
channelMuteUserEvent: () =>
|
|
3049
|
+
var Qa = {};
|
|
3050
|
+
D(Qa, {
|
|
3051
|
+
channelCreateEvent: () => ec,
|
|
3052
|
+
channelHideMessageEvent: () => rc,
|
|
3053
|
+
channelMessageEvent: () => nc,
|
|
3054
|
+
channelMetadataEvent: () => tc,
|
|
3055
|
+
channelMuteUserEvent: () => ic
|
|
3056
3056
|
});
|
|
3057
|
-
var
|
|
3057
|
+
var ec = (e, t) => {
|
|
3058
3058
|
let n;
|
|
3059
3059
|
if (typeof e.content == "object")
|
|
3060
3060
|
n = JSON.stringify(e.content);
|
|
@@ -3064,14 +3064,14 @@ var Qa = (e, t) => {
|
|
|
3064
3064
|
return;
|
|
3065
3065
|
return ae(
|
|
3066
3066
|
{
|
|
3067
|
-
kind:
|
|
3067
|
+
kind: kr,
|
|
3068
3068
|
tags: [...e.tags ?? []],
|
|
3069
3069
|
content: n,
|
|
3070
3070
|
created_at: e.created_at
|
|
3071
3071
|
},
|
|
3072
3072
|
t
|
|
3073
3073
|
);
|
|
3074
|
-
},
|
|
3074
|
+
}, tc = (e, t) => {
|
|
3075
3075
|
let n;
|
|
3076
3076
|
if (typeof e.content == "object")
|
|
3077
3077
|
n = JSON.stringify(e.content);
|
|
@@ -3081,25 +3081,25 @@ var Qa = (e, t) => {
|
|
|
3081
3081
|
return;
|
|
3082
3082
|
return ae(
|
|
3083
3083
|
{
|
|
3084
|
-
kind:
|
|
3084
|
+
kind: Br,
|
|
3085
3085
|
tags: [["e", e.channel_create_event_id], ...e.tags ?? []],
|
|
3086
3086
|
content: n,
|
|
3087
3087
|
created_at: e.created_at
|
|
3088
3088
|
},
|
|
3089
3089
|
t
|
|
3090
3090
|
);
|
|
3091
|
-
},
|
|
3091
|
+
}, nc = (e, t) => {
|
|
3092
3092
|
const n = [["e", e.channel_create_event_id, e.relay_url, "root"]];
|
|
3093
3093
|
return e.reply_to_channel_message_event_id && n.push(["e", e.reply_to_channel_message_event_id, e.relay_url, "reply"]), ae(
|
|
3094
3094
|
{
|
|
3095
|
-
kind:
|
|
3095
|
+
kind: Ur,
|
|
3096
3096
|
tags: [...n, ...e.tags ?? []],
|
|
3097
3097
|
content: e.content,
|
|
3098
3098
|
created_at: e.created_at
|
|
3099
3099
|
},
|
|
3100
3100
|
t
|
|
3101
3101
|
);
|
|
3102
|
-
},
|
|
3102
|
+
}, rc = (e, t) => {
|
|
3103
3103
|
let n;
|
|
3104
3104
|
if (typeof e.content == "object")
|
|
3105
3105
|
n = JSON.stringify(e.content);
|
|
@@ -3109,14 +3109,14 @@ var Qa = (e, t) => {
|
|
|
3109
3109
|
return;
|
|
3110
3110
|
return ae(
|
|
3111
3111
|
{
|
|
3112
|
-
kind:
|
|
3112
|
+
kind: Ir,
|
|
3113
3113
|
tags: [["e", e.channel_message_event_id], ...e.tags ?? []],
|
|
3114
3114
|
content: n,
|
|
3115
3115
|
created_at: e.created_at
|
|
3116
3116
|
},
|
|
3117
3117
|
t
|
|
3118
3118
|
);
|
|
3119
|
-
},
|
|
3119
|
+
}, ic = (e, t) => {
|
|
3120
3120
|
let n;
|
|
3121
3121
|
if (typeof e.content == "object")
|
|
3122
3122
|
n = JSON.stringify(e.content);
|
|
@@ -3126,23 +3126,23 @@ var Qa = (e, t) => {
|
|
|
3126
3126
|
return;
|
|
3127
3127
|
return ae(
|
|
3128
3128
|
{
|
|
3129
|
-
kind:
|
|
3129
|
+
kind: _r,
|
|
3130
3130
|
tags: [["p", e.pubkey_to_mute], ...e.tags ?? []],
|
|
3131
3131
|
content: n,
|
|
3132
3132
|
created_at: e.created_at
|
|
3133
3133
|
},
|
|
3134
3134
|
t
|
|
3135
3135
|
);
|
|
3136
|
-
},
|
|
3137
|
-
D(
|
|
3138
|
-
EMOJI_SHORTCODE_REGEX: () =>
|
|
3139
|
-
matchAll: () =>
|
|
3140
|
-
regex: () =>
|
|
3141
|
-
replaceAll: () =>
|
|
3136
|
+
}, oc = {};
|
|
3137
|
+
D(oc, {
|
|
3138
|
+
EMOJI_SHORTCODE_REGEX: () => Vr,
|
|
3139
|
+
matchAll: () => sc,
|
|
3140
|
+
regex: () => dn,
|
|
3141
|
+
replaceAll: () => ac
|
|
3142
3142
|
});
|
|
3143
|
-
var
|
|
3144
|
-
function*
|
|
3145
|
-
const t = e.matchAll(
|
|
3143
|
+
var Vr = /:(\w+):/, dn = () => new RegExp(`\\B${Vr.source}\\B`, "g");
|
|
3144
|
+
function* sc(e) {
|
|
3145
|
+
const t = e.matchAll(dn());
|
|
3146
3146
|
for (const n of t)
|
|
3147
3147
|
try {
|
|
3148
3148
|
const [r, i] = n;
|
|
@@ -3155,53 +3155,53 @@ function* oc(e) {
|
|
|
3155
3155
|
} catch {
|
|
3156
3156
|
}
|
|
3157
3157
|
}
|
|
3158
|
-
function
|
|
3159
|
-
return e.replaceAll(
|
|
3158
|
+
function ac(e, t) {
|
|
3159
|
+
return e.replaceAll(dn(), (n, r) => t({
|
|
3160
3160
|
shortcode: n,
|
|
3161
3161
|
name: r
|
|
3162
3162
|
}));
|
|
3163
3163
|
}
|
|
3164
|
-
var
|
|
3165
|
-
D(
|
|
3166
|
-
useFetchImplementation: () =>
|
|
3167
|
-
validateGithub: () =>
|
|
3164
|
+
var cc = {};
|
|
3165
|
+
D(cc, {
|
|
3166
|
+
useFetchImplementation: () => lc,
|
|
3167
|
+
validateGithub: () => uc
|
|
3168
3168
|
});
|
|
3169
|
-
var
|
|
3169
|
+
var yn;
|
|
3170
3170
|
try {
|
|
3171
|
-
|
|
3171
|
+
yn = fetch;
|
|
3172
3172
|
} catch {
|
|
3173
3173
|
}
|
|
3174
|
-
function
|
|
3175
|
-
|
|
3174
|
+
function lc(e) {
|
|
3175
|
+
yn = e;
|
|
3176
3176
|
}
|
|
3177
|
-
async function
|
|
3177
|
+
async function uc(e, t, n) {
|
|
3178
3178
|
try {
|
|
3179
|
-
return await (await
|
|
3179
|
+
return await (await yn(`https://gist.github.com/${t}/${n}/raw`)).text() === `Verifying that I control the following Nostr public key: ${e}`;
|
|
3180
3180
|
} catch {
|
|
3181
3181
|
return !1;
|
|
3182
3182
|
}
|
|
3183
3183
|
}
|
|
3184
|
-
var
|
|
3185
|
-
D(
|
|
3186
|
-
decrypt: () =>
|
|
3187
|
-
encrypt: () =>
|
|
3188
|
-
getConversationKey: () =>
|
|
3189
|
-
v2: () =>
|
|
3184
|
+
var j = {};
|
|
3185
|
+
D(j, {
|
|
3186
|
+
decrypt: () => Yr,
|
|
3187
|
+
encrypt: () => Jr,
|
|
3188
|
+
getConversationKey: () => Fr,
|
|
3189
|
+
v2: () => pc
|
|
3190
3190
|
});
|
|
3191
|
-
var zr = 1,
|
|
3192
|
-
function
|
|
3191
|
+
var zr = 1, Zr = 65535;
|
|
3192
|
+
function Fr(e, t) {
|
|
3193
3193
|
const n = Ue.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3194
|
-
return
|
|
3194
|
+
return on(Se, n, "nip44-v2");
|
|
3195
3195
|
}
|
|
3196
|
-
function
|
|
3197
|
-
const n =
|
|
3196
|
+
function Wr(e, t) {
|
|
3197
|
+
const n = mr(Se, e, t, 76);
|
|
3198
3198
|
return {
|
|
3199
3199
|
chacha_key: n.subarray(0, 32),
|
|
3200
3200
|
chacha_nonce: n.subarray(32, 44),
|
|
3201
3201
|
hmac_key: n.subarray(44, 76)
|
|
3202
3202
|
};
|
|
3203
3203
|
}
|
|
3204
|
-
function
|
|
3204
|
+
function pn(e) {
|
|
3205
3205
|
if (!Number.isSafeInteger(e) || e < 1)
|
|
3206
3206
|
throw new Error("expected positive integer");
|
|
3207
3207
|
if (e <= 32)
|
|
@@ -3209,29 +3209,29 @@ function yn(e) {
|
|
|
3209
3209
|
const t = 1 << Math.floor(Math.log2(e - 1)) + 1, n = t <= 256 ? 32 : t / 8;
|
|
3210
3210
|
return n * (Math.floor((e - 1) / n) + 1);
|
|
3211
3211
|
}
|
|
3212
|
-
function
|
|
3213
|
-
if (!Number.isSafeInteger(e) || e < zr || e >
|
|
3212
|
+
function fc(e) {
|
|
3213
|
+
if (!Number.isSafeInteger(e) || e < zr || e > Zr)
|
|
3214
3214
|
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
|
|
3215
3215
|
const t = new Uint8Array(2);
|
|
3216
3216
|
return new DataView(t.buffer).setUint16(0, e, !1), t;
|
|
3217
3217
|
}
|
|
3218
|
-
function
|
|
3219
|
-
const t = te.encode(e), n = t.length, r =
|
|
3218
|
+
function hc(e) {
|
|
3219
|
+
const t = te.encode(e), n = t.length, r = fc(n), i = new Uint8Array(pn(n) - n);
|
|
3220
3220
|
return dt(r, t, i);
|
|
3221
3221
|
}
|
|
3222
|
-
function
|
|
3222
|
+
function dc(e) {
|
|
3223
3223
|
const t = new DataView(e.buffer).getUint16(0), n = e.subarray(2, 2 + t);
|
|
3224
|
-
if (t < zr || t >
|
|
3224
|
+
if (t < zr || t > Zr || n.length !== t || e.length !== 2 + pn(t))
|
|
3225
3225
|
throw new Error("invalid padding");
|
|
3226
3226
|
return ie.decode(n);
|
|
3227
3227
|
}
|
|
3228
|
-
function
|
|
3228
|
+
function Gr(e, t, n) {
|
|
3229
3229
|
if (n.length !== 32)
|
|
3230
3230
|
throw new Error("AAD associated data must be 32 bytes");
|
|
3231
3231
|
const r = dt(n, t);
|
|
3232
3232
|
return pt(Se, e, r);
|
|
3233
3233
|
}
|
|
3234
|
-
function
|
|
3234
|
+
function yc(e) {
|
|
3235
3235
|
if (typeof e != "string")
|
|
3236
3236
|
throw new Error("payload must be a valid string");
|
|
3237
3237
|
const t = e.length;
|
|
@@ -3257,84 +3257,84 @@ function dc(e) {
|
|
|
3257
3257
|
mac: n.subarray(-32)
|
|
3258
3258
|
};
|
|
3259
3259
|
}
|
|
3260
|
-
function
|
|
3261
|
-
const { chacha_key: r, chacha_nonce: i, hmac_key: o } =
|
|
3262
|
-
return ue.encode(dt(new Uint8Array([2]), n,
|
|
3260
|
+
function Jr(e, t, n = or(32)) {
|
|
3261
|
+
const { chacha_key: r, chacha_nonce: i, hmac_key: o } = Wr(t, n), s = hc(e), a = vr(r, i, s), c = Gr(o, a, n);
|
|
3262
|
+
return ue.encode(dt(new Uint8Array([2]), n, a, c));
|
|
3263
3263
|
}
|
|
3264
|
-
function
|
|
3265
|
-
const { nonce: n, ciphertext: r, mac: i } =
|
|
3266
|
-
if (!
|
|
3264
|
+
function Yr(e, t) {
|
|
3265
|
+
const { nonce: n, ciphertext: r, mac: i } = yc(e), { chacha_key: o, chacha_nonce: s, hmac_key: a } = Wr(t, n), c = Gr(a, r, n);
|
|
3266
|
+
if (!Ko(c, i))
|
|
3267
3267
|
throw new Error("invalid MAC");
|
|
3268
|
-
const l =
|
|
3269
|
-
return
|
|
3268
|
+
const l = vr(o, s, r);
|
|
3269
|
+
return dc(l);
|
|
3270
3270
|
}
|
|
3271
|
-
var
|
|
3271
|
+
var pc = {
|
|
3272
3272
|
utils: {
|
|
3273
|
-
getConversationKey:
|
|
3274
|
-
calcPaddedLen:
|
|
3273
|
+
getConversationKey: Fr,
|
|
3274
|
+
calcPaddedLen: pn
|
|
3275
3275
|
},
|
|
3276
|
-
encrypt:
|
|
3277
|
-
decrypt:
|
|
3278
|
-
},
|
|
3279
|
-
D(
|
|
3280
|
-
makeNwcRequestEvent: () =>
|
|
3281
|
-
parseConnectionString: () =>
|
|
3276
|
+
encrypt: Jr,
|
|
3277
|
+
decrypt: Yr
|
|
3278
|
+
}, gc = {};
|
|
3279
|
+
D(gc, {
|
|
3280
|
+
makeNwcRequestEvent: () => bc,
|
|
3281
|
+
parseConnectionString: () => wc
|
|
3282
3282
|
});
|
|
3283
|
-
function
|
|
3283
|
+
function wc(e) {
|
|
3284
3284
|
const { pathname: t, searchParams: n } = new URL(e), r = t, i = n.get("relay"), o = n.get("secret");
|
|
3285
3285
|
if (!r || !i || !o)
|
|
3286
3286
|
throw new Error("invalid connection string");
|
|
3287
3287
|
return { pubkey: r, relay: i, secret: o };
|
|
3288
3288
|
}
|
|
3289
|
-
async function
|
|
3290
|
-
const i = await
|
|
3289
|
+
async function bc(e, t, n) {
|
|
3290
|
+
const i = await Or(t, e, JSON.stringify({
|
|
3291
3291
|
method: "pay_invoice",
|
|
3292
3292
|
params: {
|
|
3293
3293
|
invoice: n
|
|
3294
3294
|
}
|
|
3295
3295
|
})), o = {
|
|
3296
|
-
kind:
|
|
3296
|
+
kind: Tr,
|
|
3297
3297
|
created_at: Math.round(Date.now() / 1e3),
|
|
3298
3298
|
content: i,
|
|
3299
3299
|
tags: [["p", e]]
|
|
3300
3300
|
};
|
|
3301
3301
|
return ae(o, t);
|
|
3302
3302
|
}
|
|
3303
|
-
var
|
|
3304
|
-
D(
|
|
3305
|
-
getZapEndpoint: () =>
|
|
3306
|
-
makeZapReceipt: () =>
|
|
3307
|
-
makeZapRequest: () =>
|
|
3308
|
-
useFetchImplementation: () =>
|
|
3309
|
-
validateZapRequest: () =>
|
|
3303
|
+
var vc = {};
|
|
3304
|
+
D(vc, {
|
|
3305
|
+
getZapEndpoint: () => mc,
|
|
3306
|
+
makeZapReceipt: () => Ac,
|
|
3307
|
+
makeZapRequest: () => xc,
|
|
3308
|
+
useFetchImplementation: () => Ec,
|
|
3309
|
+
validateZapRequest: () => Sc
|
|
3310
3310
|
});
|
|
3311
|
-
var
|
|
3311
|
+
var gn;
|
|
3312
3312
|
try {
|
|
3313
|
-
|
|
3313
|
+
gn = fetch;
|
|
3314
3314
|
} catch {
|
|
3315
3315
|
}
|
|
3316
|
-
function
|
|
3317
|
-
|
|
3316
|
+
function Ec(e) {
|
|
3317
|
+
gn = e;
|
|
3318
3318
|
}
|
|
3319
|
-
async function
|
|
3319
|
+
async function mc(e) {
|
|
3320
3320
|
try {
|
|
3321
3321
|
let t = "", { lud06: n, lud16: r } = JSON.parse(e.content);
|
|
3322
3322
|
if (n) {
|
|
3323
|
-
let { words: s } =
|
|
3324
|
-
t = ie.decode(
|
|
3323
|
+
let { words: s } = je.decode(n, 1e3), a = je.fromWords(s);
|
|
3324
|
+
t = ie.decode(a);
|
|
3325
3325
|
} else if (r) {
|
|
3326
|
-
let [s,
|
|
3327
|
-
t = new URL(`/.well-known/lnurlp/${s}`, `https://${
|
|
3326
|
+
let [s, a] = r.split("@");
|
|
3327
|
+
t = new URL(`/.well-known/lnurlp/${s}`, `https://${a}`).toString();
|
|
3328
3328
|
} else
|
|
3329
3329
|
return null;
|
|
3330
|
-
let o = await (await
|
|
3330
|
+
let o = await (await gn(t)).json();
|
|
3331
3331
|
if (o.allowsNostr && o.nostrPubkey)
|
|
3332
3332
|
return o.callback;
|
|
3333
3333
|
} catch {
|
|
3334
3334
|
}
|
|
3335
3335
|
return null;
|
|
3336
3336
|
}
|
|
3337
|
-
function
|
|
3337
|
+
function xc({
|
|
3338
3338
|
profile: e,
|
|
3339
3339
|
event: t,
|
|
3340
3340
|
amount: n,
|
|
@@ -3357,16 +3357,16 @@ function mc({
|
|
|
3357
3357
|
};
|
|
3358
3358
|
return t && o.tags.push(["e", t]), o;
|
|
3359
3359
|
}
|
|
3360
|
-
function
|
|
3360
|
+
function Sc(e) {
|
|
3361
3361
|
let t;
|
|
3362
3362
|
try {
|
|
3363
3363
|
t = JSON.parse(e);
|
|
3364
3364
|
} catch {
|
|
3365
3365
|
return "Invalid zap request JSON.";
|
|
3366
3366
|
}
|
|
3367
|
-
if (!
|
|
3367
|
+
if (!xr(t))
|
|
3368
3368
|
return "Zap request is not a valid Nostr event.";
|
|
3369
|
-
if (!
|
|
3369
|
+
if (!wt(t))
|
|
3370
3370
|
return "Invalid signature on zap request.";
|
|
3371
3371
|
let n = t.tags.find(([o, s]) => o === "p" && s);
|
|
3372
3372
|
if (!n)
|
|
@@ -3376,13 +3376,13 @@ function xc(e) {
|
|
|
3376
3376
|
let r = t.tags.find(([o, s]) => o === "e" && s);
|
|
3377
3377
|
return r && !r[1].match(/^[a-f0-9]{64}$/) ? "Zap request 'e' tag is not valid hex." : t.tags.find(([o, s]) => o === "relays" && s) ? null : "Zap request doesn't have a 'relays' tag.";
|
|
3378
3378
|
}
|
|
3379
|
-
function
|
|
3379
|
+
function Ac({
|
|
3380
3380
|
zapRequest: e,
|
|
3381
3381
|
preimage: t,
|
|
3382
3382
|
bolt11: n,
|
|
3383
3383
|
paidAt: r
|
|
3384
3384
|
}) {
|
|
3385
|
-
let i = JSON.parse(e), o = i.tags.filter(([
|
|
3385
|
+
let i = JSON.parse(e), o = i.tags.filter(([a]) => a === "e" || a === "p" || a === "a"), s = {
|
|
3386
3386
|
kind: 9735,
|
|
3387
3387
|
created_at: Math.round(r.getTime() / 1e3),
|
|
3388
3388
|
content: "",
|
|
@@ -3390,23 +3390,23 @@ function Sc({
|
|
|
3390
3390
|
};
|
|
3391
3391
|
return t && s.tags.push(["preimage", t]), s;
|
|
3392
3392
|
}
|
|
3393
|
-
var
|
|
3394
|
-
D(
|
|
3395
|
-
getToken: () =>
|
|
3396
|
-
hashPayload: () =>
|
|
3397
|
-
unpackEventFromToken: () =>
|
|
3398
|
-
validateEvent: () =>
|
|
3399
|
-
validateEventKind: () =>
|
|
3400
|
-
validateEventMethodTag: () =>
|
|
3401
|
-
validateEventPayloadTag: () =>
|
|
3402
|
-
validateEventTimestamp: () =>
|
|
3403
|
-
validateEventUrlTag: () =>
|
|
3404
|
-
validateToken: () =>
|
|
3393
|
+
var Kc = {};
|
|
3394
|
+
D(Kc, {
|
|
3395
|
+
getToken: () => Nc,
|
|
3396
|
+
hashPayload: () => wn,
|
|
3397
|
+
unpackEventFromToken: () => Qr,
|
|
3398
|
+
validateEvent: () => oi,
|
|
3399
|
+
validateEventKind: () => ti,
|
|
3400
|
+
validateEventMethodTag: () => ri,
|
|
3401
|
+
validateEventPayloadTag: () => ii,
|
|
3402
|
+
validateEventTimestamp: () => ei,
|
|
3403
|
+
validateEventUrlTag: () => ni,
|
|
3404
|
+
validateToken: () => Cc
|
|
3405
3405
|
});
|
|
3406
|
-
var
|
|
3407
|
-
async function
|
|
3406
|
+
var Xr = "Nostr ";
|
|
3407
|
+
async function Nc(e, t, n, r = !1, i) {
|
|
3408
3408
|
const o = {
|
|
3409
|
-
kind:
|
|
3409
|
+
kind: ln,
|
|
3410
3410
|
tags: [
|
|
3411
3411
|
["u", e],
|
|
3412
3412
|
["method", t]
|
|
@@ -3414,70 +3414,70 @@ async function Kc(e, t, n, r = !1, i) {
|
|
|
3414
3414
|
created_at: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
3415
3415
|
content: ""
|
|
3416
3416
|
};
|
|
3417
|
-
i && o.tags.push(["payload",
|
|
3417
|
+
i && o.tags.push(["payload", wn(i)]);
|
|
3418
3418
|
const s = await n(o);
|
|
3419
|
-
return (r ?
|
|
3419
|
+
return (r ? Xr : "") + ue.encode(te.encode(JSON.stringify(s)));
|
|
3420
3420
|
}
|
|
3421
|
-
async function
|
|
3422
|
-
const r = await
|
|
3421
|
+
async function Cc(e, t, n) {
|
|
3422
|
+
const r = await Qr(e).catch((o) => {
|
|
3423
3423
|
throw o;
|
|
3424
3424
|
});
|
|
3425
|
-
return await
|
|
3425
|
+
return await oi(r, t, n).catch((o) => {
|
|
3426
3426
|
throw o;
|
|
3427
3427
|
});
|
|
3428
3428
|
}
|
|
3429
|
-
async function
|
|
3429
|
+
async function Qr(e) {
|
|
3430
3430
|
if (!e)
|
|
3431
3431
|
throw new Error("Missing token");
|
|
3432
|
-
e = e.replace(
|
|
3432
|
+
e = e.replace(Xr, "");
|
|
3433
3433
|
const t = ie.decode(ue.decode(e));
|
|
3434
3434
|
if (!t || t.length === 0 || !t.startsWith("{"))
|
|
3435
3435
|
throw new Error("Invalid token");
|
|
3436
3436
|
return JSON.parse(t);
|
|
3437
3437
|
}
|
|
3438
|
-
function
|
|
3438
|
+
function ei(e) {
|
|
3439
3439
|
return e.created_at ? Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3) - e.created_at < 60 : !1;
|
|
3440
3440
|
}
|
|
3441
|
-
function
|
|
3442
|
-
return e.kind ===
|
|
3441
|
+
function ti(e) {
|
|
3442
|
+
return e.kind === ln;
|
|
3443
3443
|
}
|
|
3444
|
-
function
|
|
3444
|
+
function ni(e, t) {
|
|
3445
3445
|
const n = e.tags.find((r) => r[0] === "u");
|
|
3446
3446
|
return n ? n.length > 0 && n[1] === t : !1;
|
|
3447
3447
|
}
|
|
3448
|
-
function
|
|
3448
|
+
function ri(e, t) {
|
|
3449
3449
|
const n = e.tags.find((r) => r[0] === "method");
|
|
3450
3450
|
return n ? n.length > 0 && n[1].toLowerCase() === t.toLowerCase() : !1;
|
|
3451
3451
|
}
|
|
3452
|
-
function
|
|
3452
|
+
function wn(e) {
|
|
3453
3453
|
const t = Se(te.encode(JSON.stringify(e)));
|
|
3454
3454
|
return M(t);
|
|
3455
3455
|
}
|
|
3456
|
-
function
|
|
3456
|
+
function ii(e, t) {
|
|
3457
3457
|
const n = e.tags.find((i) => i[0] === "payload");
|
|
3458
3458
|
if (!n)
|
|
3459
3459
|
return !1;
|
|
3460
|
-
const r =
|
|
3460
|
+
const r = wn(t);
|
|
3461
3461
|
return n.length > 0 && n[1] === r;
|
|
3462
3462
|
}
|
|
3463
|
-
async function
|
|
3464
|
-
if (!
|
|
3463
|
+
async function oi(e, t, n, r) {
|
|
3464
|
+
if (!wt(e))
|
|
3465
3465
|
throw new Error("Invalid nostr event, signature invalid");
|
|
3466
|
-
if (!
|
|
3466
|
+
if (!ti(e))
|
|
3467
3467
|
throw new Error("Invalid nostr event, kind invalid");
|
|
3468
|
-
if (!
|
|
3468
|
+
if (!ei(e))
|
|
3469
3469
|
throw new Error("Invalid nostr event, created_at timestamp invalid");
|
|
3470
|
-
if (!
|
|
3470
|
+
if (!ni(e, t))
|
|
3471
3471
|
throw new Error("Invalid nostr event, url tag invalid");
|
|
3472
|
-
if (!
|
|
3472
|
+
if (!ri(e, n))
|
|
3473
3473
|
throw new Error("Invalid nostr event, method tag invalid");
|
|
3474
|
-
if (r && typeof r == "object" && Object.keys(r).length > 0 && !
|
|
3474
|
+
if (r && typeof r == "object" && Object.keys(r).length > 0 && !ii(e, r))
|
|
3475
3475
|
throw new Error("Invalid nostr event, payload tag does not match request body hash");
|
|
3476
3476
|
return !0;
|
|
3477
3477
|
}
|
|
3478
|
-
const
|
|
3479
|
-
var
|
|
3480
|
-
function
|
|
3478
|
+
const He = 4, On = 30078, Rc = 100;
|
|
3479
|
+
var kc = /* @__PURE__ */ ((e) => (e[e.Us = 0] = "Us", e[e.Them = 1] = "Them", e))(kc || {});
|
|
3480
|
+
function Oc(e) {
|
|
3481
3481
|
return JSON.stringify({
|
|
3482
3482
|
rootKey: M(e.rootKey),
|
|
3483
3483
|
theirNostrPublicKey: e.theirNostrPublicKey,
|
|
@@ -3499,6 +3499,12 @@ function Rc(e) {
|
|
|
3499
3499
|
t,
|
|
3500
3500
|
M(n)
|
|
3501
3501
|
])
|
|
3502
|
+
),
|
|
3503
|
+
skippedHeaderKeys: Object.fromEntries(
|
|
3504
|
+
Object.entries(e.skippedHeaderKeys).map(([t, n]) => [
|
|
3505
|
+
t,
|
|
3506
|
+
n.map((r) => M(r))
|
|
3507
|
+
])
|
|
3502
3508
|
)
|
|
3503
3509
|
});
|
|
3504
3510
|
}
|
|
@@ -3525,10 +3531,16 @@ function Pc(e) {
|
|
|
3525
3531
|
n,
|
|
3526
3532
|
W(r)
|
|
3527
3533
|
])
|
|
3534
|
+
),
|
|
3535
|
+
skippedHeaderKeys: Object.fromEntries(
|
|
3536
|
+
Object.entries(t.skippedHeaderKeys || {}).map(([n, r]) => [
|
|
3537
|
+
n,
|
|
3538
|
+
r.map((i) => W(i))
|
|
3539
|
+
])
|
|
3528
3540
|
)
|
|
3529
3541
|
};
|
|
3530
3542
|
}
|
|
3531
|
-
async function*
|
|
3543
|
+
async function* Mc(e) {
|
|
3532
3544
|
const t = [];
|
|
3533
3545
|
let n = null;
|
|
3534
3546
|
const r = e.onMessage((i) => {
|
|
@@ -3544,15 +3556,15 @@ async function* Oc(e) {
|
|
|
3544
3556
|
}
|
|
3545
3557
|
}
|
|
3546
3558
|
function Re(e, t = new Uint8Array(32), n = 1) {
|
|
3547
|
-
const r =
|
|
3559
|
+
const r = on(Se, e, t), i = [];
|
|
3548
3560
|
for (let o = 1; o <= n; o++)
|
|
3549
|
-
i.push(
|
|
3561
|
+
i.push(mr(Se, r, new Uint8Array([o]), 32));
|
|
3550
3562
|
return i;
|
|
3551
3563
|
}
|
|
3552
|
-
function
|
|
3564
|
+
function Tt(e, t) {
|
|
3553
3565
|
return `${e}:${t}`;
|
|
3554
3566
|
}
|
|
3555
|
-
const
|
|
3567
|
+
const Bc = 1e3;
|
|
3556
3568
|
class ct {
|
|
3557
3569
|
// 1. CHANNEL PUBLIC INTERFACE
|
|
3558
3570
|
constructor(t, n) {
|
|
@@ -3574,11 +3586,11 @@ class ct {
|
|
|
3574
3586
|
* @returns A new Channel instance
|
|
3575
3587
|
*/
|
|
3576
3588
|
static init(t, n, r, i, o, s) {
|
|
3577
|
-
const
|
|
3589
|
+
const a = Me(), [c, l] = Re(o, j.getConversationKey(a, n), 2);
|
|
3578
3590
|
let f, u;
|
|
3579
|
-
i ? (f = { publicKey:
|
|
3591
|
+
i ? (f = { publicKey: ke(r), privateKey: r }, u = { publicKey: ke(a), privateKey: a }) : u = { publicKey: ke(r), privateKey: r };
|
|
3580
3592
|
const d = {
|
|
3581
|
-
rootKey: i ?
|
|
3593
|
+
rootKey: i ? c : o,
|
|
3582
3594
|
theirNostrPublicKey: n,
|
|
3583
3595
|
ourCurrentNostrKey: f,
|
|
3584
3596
|
ourNextNostrKey: u,
|
|
@@ -3587,7 +3599,8 @@ class ct {
|
|
|
3587
3599
|
sendingChainMessageNumber: 0,
|
|
3588
3600
|
receivingChainMessageNumber: 0,
|
|
3589
3601
|
previousSendingChainMessageCount: 0,
|
|
3590
|
-
skippedMessageKeys: {}
|
|
3602
|
+
skippedMessageKeys: {},
|
|
3603
|
+
skippedHeaderKeys: {}
|
|
3591
3604
|
}, p = new ct(t, d);
|
|
3592
3605
|
return s && (p.name = s), p;
|
|
3593
3606
|
}
|
|
@@ -3600,10 +3613,10 @@ class ct {
|
|
|
3600
3613
|
send(t) {
|
|
3601
3614
|
if (!this.state.theirNostrPublicKey || !this.state.ourCurrentNostrKey)
|
|
3602
3615
|
throw new Error("we are not the initiator, so we can't send the first message");
|
|
3603
|
-
const [n, r] = this.ratchetEncrypt(t), i =
|
|
3616
|
+
const [n, r] = this.ratchetEncrypt(t), i = j.getConversationKey(this.state.ourCurrentNostrKey.privateKey, this.state.theirNostrPublicKey), o = j.encrypt(JSON.stringify(n), i);
|
|
3604
3617
|
return ae({
|
|
3605
3618
|
content: r,
|
|
3606
|
-
kind:
|
|
3619
|
+
kind: He,
|
|
3607
3620
|
tags: [["header", o]],
|
|
3608
3621
|
created_at: Math.floor(Date.now() / 1e3)
|
|
3609
3622
|
}, this.state.ourCurrentNostrKey.privateKey);
|
|
@@ -3617,6 +3630,13 @@ class ct {
|
|
|
3617
3630
|
const n = this.currentInternalSubscriptionId++;
|
|
3618
3631
|
return this.internalSubscriptions.set(n, t), this.subscribeToNostrEvents(), () => this.internalSubscriptions.delete(n);
|
|
3619
3632
|
}
|
|
3633
|
+
/**
|
|
3634
|
+
* Stop listening to incoming messages
|
|
3635
|
+
*/
|
|
3636
|
+
close() {
|
|
3637
|
+
var t, n;
|
|
3638
|
+
(t = this.nostrUnsubscribe) == null || t.call(this), (n = this.nostrNextUnsubscribe) == null || n.call(this);
|
|
3639
|
+
}
|
|
3620
3640
|
// 2. RATCHET FUNCTIONS
|
|
3621
3641
|
ratchetEncrypt(t) {
|
|
3622
3642
|
const [n, r] = Re(this.state.sendingChainKey, new Uint8Array([1]), 2);
|
|
@@ -3625,7 +3645,7 @@ class ct {
|
|
|
3625
3645
|
nextPublicKey: this.state.ourNextNostrKey.publicKey,
|
|
3626
3646
|
time: Date.now(),
|
|
3627
3647
|
previousChainLength: this.state.previousSendingChainMessageCount
|
|
3628
|
-
},
|
|
3648
|
+
}, j.encrypt(t, r)];
|
|
3629
3649
|
}
|
|
3630
3650
|
ratchetDecrypt(t, n, r) {
|
|
3631
3651
|
const i = this.trySkippedMessageKeys(t, n, r);
|
|
@@ -3634,44 +3654,54 @@ class ct {
|
|
|
3634
3654
|
const [o, s] = Re(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3635
3655
|
this.state.receivingChainKey = o, this.state.receivingChainMessageNumber++;
|
|
3636
3656
|
try {
|
|
3637
|
-
return
|
|
3638
|
-
} catch (
|
|
3639
|
-
throw console.error(this.name, "Decryption failed:",
|
|
3657
|
+
return j.decrypt(n, s);
|
|
3658
|
+
} catch (a) {
|
|
3659
|
+
throw console.error(this.name, "Decryption failed:", a, {
|
|
3640
3660
|
messageKey: M(s).slice(0, 4),
|
|
3641
3661
|
receivingChainKey: M(this.state.receivingChainKey).slice(0, 4),
|
|
3642
3662
|
sendingChainKey: this.state.sendingChainKey && M(this.state.sendingChainKey).slice(0, 4),
|
|
3643
3663
|
rootKey: M(this.state.rootKey).slice(0, 4)
|
|
3644
|
-
}),
|
|
3664
|
+
}), a;
|
|
3645
3665
|
}
|
|
3646
3666
|
}
|
|
3647
3667
|
ratchetStep(t) {
|
|
3648
3668
|
this.state.previousSendingChainMessageCount = this.state.sendingChainMessageNumber, this.state.sendingChainMessageNumber = 0, this.state.receivingChainMessageNumber = 0, this.state.theirNostrPublicKey = t;
|
|
3649
|
-
const n =
|
|
3669
|
+
const n = j.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNostrPublicKey), [r, i] = Re(this.state.rootKey, n, 2);
|
|
3650
3670
|
this.state.receivingChainKey = i, this.state.ourCurrentNostrKey = this.state.ourNextNostrKey;
|
|
3651
|
-
const o =
|
|
3671
|
+
const o = Me();
|
|
3652
3672
|
this.state.ourNextNostrKey = {
|
|
3653
|
-
publicKey:
|
|
3673
|
+
publicKey: ke(o),
|
|
3654
3674
|
privateKey: o
|
|
3655
3675
|
};
|
|
3656
|
-
const s =
|
|
3657
|
-
this.state.rootKey =
|
|
3676
|
+
const s = j.getConversationKey(this.state.ourNextNostrKey.privateKey, this.state.theirNostrPublicKey), [a, c] = Re(r, s, 2);
|
|
3677
|
+
this.state.rootKey = a, this.state.sendingChainKey = c;
|
|
3658
3678
|
}
|
|
3659
3679
|
// 3. MESSAGE KEY FUNCTIONS
|
|
3660
3680
|
skipMessageKeys(t, n) {
|
|
3661
|
-
if (this.state.receivingChainMessageNumber +
|
|
3681
|
+
if (this.state.receivingChainMessageNumber + Bc < t)
|
|
3662
3682
|
throw new Error("Too many skipped messages");
|
|
3663
3683
|
for (; this.state.receivingChainMessageNumber < t; ) {
|
|
3664
3684
|
const [r, i] = Re(this.state.receivingChainKey, new Uint8Array([1]), 2);
|
|
3665
3685
|
this.state.receivingChainKey = r;
|
|
3666
|
-
const o =
|
|
3667
|
-
this.state.skippedMessageKeys[o] = i, this.state.
|
|
3686
|
+
const o = Tt(n, this.state.receivingChainMessageNumber);
|
|
3687
|
+
if (this.state.skippedMessageKeys[o] = i, !this.state.skippedHeaderKeys[n]) {
|
|
3688
|
+
const s = [];
|
|
3689
|
+
if (this.state.ourCurrentNostrKey) {
|
|
3690
|
+
const c = j.getConversationKey(this.state.ourCurrentNostrKey.privateKey, n);
|
|
3691
|
+
s.push(c);
|
|
3692
|
+
}
|
|
3693
|
+
const a = j.getConversationKey(this.state.ourNextNostrKey.privateKey, n);
|
|
3694
|
+
s.push(a), this.state.skippedHeaderKeys[n] = s;
|
|
3695
|
+
}
|
|
3696
|
+
this.state.receivingChainMessageNumber++;
|
|
3668
3697
|
}
|
|
3669
3698
|
}
|
|
3670
3699
|
trySkippedMessageKeys(t, n, r) {
|
|
3671
|
-
|
|
3700
|
+
var o;
|
|
3701
|
+
const i = Tt(r, t.number);
|
|
3672
3702
|
if (i in this.state.skippedMessageKeys) {
|
|
3673
|
-
const
|
|
3674
|
-
return delete this.state.skippedMessageKeys[i],
|
|
3703
|
+
const s = this.state.skippedMessageKeys[i];
|
|
3704
|
+
return delete this.state.skippedMessageKeys[i], Object.keys(this.state.skippedMessageKeys).some((c) => c.startsWith(`${r}:`)) || (delete this.state.skippedHeaderKeys[r], (o = this.nostrUnsubscribe) == null || o.call(this), this.nostrUnsubscribe = void 0), j.decrypt(n, s);
|
|
3675
3705
|
}
|
|
3676
3706
|
return null;
|
|
3677
3707
|
}
|
|
@@ -3679,59 +3709,65 @@ class ct {
|
|
|
3679
3709
|
decryptHeader(t) {
|
|
3680
3710
|
const n = t.tags[0][1];
|
|
3681
3711
|
if (this.state.ourCurrentNostrKey) {
|
|
3682
|
-
const
|
|
3712
|
+
const o = j.getConversationKey(this.state.ourCurrentNostrKey.privateKey, t.pubkey);
|
|
3683
3713
|
try {
|
|
3684
|
-
return [JSON.parse(
|
|
3714
|
+
return [JSON.parse(j.decrypt(n, o)), !1, !1];
|
|
3685
3715
|
} catch {
|
|
3686
3716
|
}
|
|
3687
3717
|
}
|
|
3688
|
-
const r =
|
|
3718
|
+
const r = j.getConversationKey(this.state.ourNextNostrKey.privateKey, t.pubkey);
|
|
3689
3719
|
try {
|
|
3690
|
-
return [JSON.parse(
|
|
3720
|
+
return [JSON.parse(j.decrypt(n, r)), !0, !1];
|
|
3691
3721
|
} catch {
|
|
3692
3722
|
}
|
|
3693
|
-
|
|
3723
|
+
const i = this.state.skippedHeaderKeys[t.pubkey];
|
|
3724
|
+
if (i)
|
|
3725
|
+
for (const o of i)
|
|
3726
|
+
try {
|
|
3727
|
+
return [JSON.parse(j.decrypt(n, o)), !1, !0];
|
|
3728
|
+
} catch {
|
|
3729
|
+
}
|
|
3730
|
+
throw new Error("Failed to decrypt header with current and skipped header keys");
|
|
3694
3731
|
}
|
|
3695
3732
|
handleNostrEvent(t) {
|
|
3696
|
-
var
|
|
3697
|
-
const [n, r] = this.decryptHeader(t);
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3733
|
+
var s;
|
|
3734
|
+
const [n, r, i] = this.decryptHeader(t);
|
|
3735
|
+
if (!i)
|
|
3736
|
+
this.state.theirNostrPublicKey !== n.nextPublicKey && (this.state.theirNostrPublicKey = n.nextPublicKey, (s = this.nostrUnsubscribe) == null || s.call(this), this.nostrUnsubscribe = this.nostrNextUnsubscribe, this.nostrNextUnsubscribe = this.nostrSubscribe(
|
|
3737
|
+
{ authors: [this.state.theirNostrPublicKey], kinds: [He] },
|
|
3738
|
+
(a) => this.handleNostrEvent(a)
|
|
3739
|
+
)), r && (this.skipMessageKeys(n.previousChainLength, t.pubkey), this.ratchetStep(n.nextPublicKey));
|
|
3740
|
+
else if (!(Tt(t.pubkey, n.number) in this.state.skippedMessageKeys))
|
|
3741
|
+
return;
|
|
3742
|
+
const o = this.ratchetDecrypt(n, t.content, t.pubkey);
|
|
3743
|
+
this.internalSubscriptions.forEach((a) => a({ id: t.id, data: o, pubkey: n.nextPublicKey, time: n.time }));
|
|
3704
3744
|
}
|
|
3705
3745
|
subscribeToNostrEvents() {
|
|
3706
3746
|
if (this.nostrNextUnsubscribe) return;
|
|
3707
3747
|
this.nostrNextUnsubscribe = this.nostrSubscribe(
|
|
3708
|
-
{ authors: [this.state.theirNostrPublicKey], kinds: [
|
|
3748
|
+
{ authors: [this.state.theirNostrPublicKey], kinds: [He] },
|
|
3709
3749
|
(n) => this.handleNostrEvent(n)
|
|
3710
3750
|
);
|
|
3711
|
-
const t =
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
r !== this.state.theirNostrPublicKey && t.add(r);
|
|
3715
|
-
}
|
|
3716
|
-
t.size > 0 && (this.nostrUnsubscribe = this.nostrSubscribe(
|
|
3717
|
-
{ authors: Array.from(t), kinds: [Me] },
|
|
3751
|
+
const t = Object.keys(this.state.skippedHeaderKeys);
|
|
3752
|
+
t.length > 0 && (this.nostrUnsubscribe = this.nostrSubscribe(
|
|
3753
|
+
{ authors: t, kinds: [He] },
|
|
3718
3754
|
(n) => this.handleNostrEvent(n)
|
|
3719
3755
|
));
|
|
3720
3756
|
}
|
|
3721
3757
|
}
|
|
3722
3758
|
new TextDecoder("utf-8");
|
|
3723
3759
|
new TextEncoder();
|
|
3724
|
-
function
|
|
3760
|
+
function tt(e, t) {
|
|
3725
3761
|
const n = Ue.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3726
|
-
return
|
|
3762
|
+
return on(Se, n, "nip44-v2");
|
|
3727
3763
|
}
|
|
3728
|
-
class
|
|
3729
|
-
constructor(t, n, r, i, o, s,
|
|
3730
|
-
this.inviterSessionPublicKey = t, this.linkSecret = n, this.inviter = r, this.inviterSessionPrivateKey = i, this.label = o, this.maxUses = s, this.usedBy =
|
|
3764
|
+
class Oe {
|
|
3765
|
+
constructor(t, n, r, i, o, s, a = []) {
|
|
3766
|
+
this.inviterSessionPublicKey = t, this.linkSecret = n, this.inviter = r, this.inviterSessionPrivateKey = i, this.label = o, this.maxUses = s, this.usedBy = a;
|
|
3731
3767
|
}
|
|
3732
3768
|
static createNew(t, n, r) {
|
|
3733
|
-
const i =
|
|
3734
|
-
return new
|
|
3769
|
+
const i = Me(), o = ke(i), s = M(Me());
|
|
3770
|
+
return new Oe(
|
|
3735
3771
|
o,
|
|
3736
3772
|
s,
|
|
3737
3773
|
t,
|
|
@@ -3751,23 +3787,23 @@ class nt {
|
|
|
3751
3787
|
} catch (u) {
|
|
3752
3788
|
throw new Error("Invite data in URL hash is not valid JSON: " + u);
|
|
3753
3789
|
}
|
|
3754
|
-
const { inviter: s, sessionKey:
|
|
3755
|
-
if (!s || !
|
|
3790
|
+
const { inviter: s, sessionKey: a, linkSecret: c } = o;
|
|
3791
|
+
if (!s || !a || !c)
|
|
3756
3792
|
throw new Error("Missing required fields (inviter, sessionKey, linkSecret) in invite data.");
|
|
3757
|
-
const l =
|
|
3793
|
+
const l = We.decode(s), f = We.decode(a);
|
|
3758
3794
|
if (typeof l.data != "string")
|
|
3759
3795
|
throw new Error("Decoded inviter is not a string");
|
|
3760
3796
|
if (typeof f.data != "string")
|
|
3761
3797
|
throw new Error("Decoded session key is not a string");
|
|
3762
|
-
return new
|
|
3798
|
+
return new Oe(
|
|
3763
3799
|
f.data,
|
|
3764
|
-
|
|
3800
|
+
c,
|
|
3765
3801
|
l.data
|
|
3766
3802
|
);
|
|
3767
3803
|
}
|
|
3768
3804
|
static deserialize(t) {
|
|
3769
3805
|
const n = JSON.parse(t);
|
|
3770
|
-
return new
|
|
3806
|
+
return new Oe(
|
|
3771
3807
|
n.inviterSessionPublicKey,
|
|
3772
3808
|
n.linkSecret,
|
|
3773
3809
|
n.inviter,
|
|
@@ -3777,6 +3813,42 @@ class nt {
|
|
|
3777
3813
|
n.usedBy
|
|
3778
3814
|
);
|
|
3779
3815
|
}
|
|
3816
|
+
static fromEvent(t) {
|
|
3817
|
+
var s, a;
|
|
3818
|
+
if (!t.sig)
|
|
3819
|
+
throw new Error("Event is not signed");
|
|
3820
|
+
if (!wt(t))
|
|
3821
|
+
throw new Error("Event signature is invalid");
|
|
3822
|
+
const { tags: n } = t, r = (s = n.find(([c]) => c === "sessionKey")) == null ? void 0 : s[1], i = (a = n.find(([c]) => c === "linkSecret")) == null ? void 0 : a[1], o = t.pubkey;
|
|
3823
|
+
if (!r || !i)
|
|
3824
|
+
throw new Error("Invalid invite event: missing session key or link secret");
|
|
3825
|
+
return new Oe(
|
|
3826
|
+
r,
|
|
3827
|
+
i,
|
|
3828
|
+
o
|
|
3829
|
+
);
|
|
3830
|
+
}
|
|
3831
|
+
static fromUser(t, n) {
|
|
3832
|
+
const r = {
|
|
3833
|
+
kinds: [On],
|
|
3834
|
+
pubkey: t,
|
|
3835
|
+
limit: 1,
|
|
3836
|
+
"#d": ["nostr-double-ratchet/invite"]
|
|
3837
|
+
};
|
|
3838
|
+
return new Promise((i) => {
|
|
3839
|
+
const o = n(r, (s) => {
|
|
3840
|
+
try {
|
|
3841
|
+
const a = Oe.fromEvent(s);
|
|
3842
|
+
o(), i(a);
|
|
3843
|
+
} catch {
|
|
3844
|
+
o(), i(void 0);
|
|
3845
|
+
}
|
|
3846
|
+
});
|
|
3847
|
+
setTimeout(() => {
|
|
3848
|
+
o(), i(void 0);
|
|
3849
|
+
}, 1e4);
|
|
3850
|
+
});
|
|
3851
|
+
}
|
|
3780
3852
|
serialize() {
|
|
3781
3853
|
return JSON.stringify({
|
|
3782
3854
|
inviterSessionPublicKey: this.inviterSessionPublicKey,
|
|
@@ -3790,12 +3862,21 @@ class nt {
|
|
|
3790
3862
|
}
|
|
3791
3863
|
getUrl(t = "https://iris.to") {
|
|
3792
3864
|
const n = {
|
|
3793
|
-
inviter:
|
|
3794
|
-
sessionKey:
|
|
3865
|
+
inviter: We.npubEncode(this.inviter),
|
|
3866
|
+
sessionKey: We.npubEncode(this.inviterSessionPublicKey),
|
|
3795
3867
|
linkSecret: this.linkSecret
|
|
3796
3868
|
}, r = new URL(t);
|
|
3797
3869
|
return r.hash = encodeURIComponent(JSON.stringify(n)), console.log("url", r.toString()), r.toString();
|
|
3798
3870
|
}
|
|
3871
|
+
getEvent() {
|
|
3872
|
+
return {
|
|
3873
|
+
kind: On,
|
|
3874
|
+
pubkey: this.inviter,
|
|
3875
|
+
content: "",
|
|
3876
|
+
created_at: Math.floor(Date.now() / 1e3),
|
|
3877
|
+
tags: [["sessionKey", this.inviterSessionPublicKey], ["linkSecret", this.linkSecret], ["d", "nostr-double-ratchet/invite"]]
|
|
3878
|
+
};
|
|
3879
|
+
}
|
|
3799
3880
|
/**
|
|
3800
3881
|
* Accepts the invite and creates a new channel with the inviter.
|
|
3801
3882
|
*
|
|
@@ -3811,37 +3892,37 @@ class nt {
|
|
|
3811
3892
|
* Note: You need to publish the returned event on Nostr using NDK or another Nostr system of your choice,
|
|
3812
3893
|
* so the inviter can create the channel on their side.
|
|
3813
3894
|
*/
|
|
3814
|
-
async
|
|
3815
|
-
const i =
|
|
3895
|
+
async accept(t, n, r) {
|
|
3896
|
+
const i = Me(), o = ke(i), s = this.inviter || this.inviterSessionPublicKey, a = W(this.linkSecret), c = ct.init(t, this.inviterSessionPublicKey, i, !0, a, void 0), l = Me(), f = ke(l), u = typeof r == "function" ? r : (g, h) => Promise.resolve(j.encrypt(g, tt(r, h))), d = {
|
|
3816
3897
|
pubkey: n,
|
|
3817
3898
|
tags: [["secret", this.linkSecret]],
|
|
3818
3899
|
content: await u(o, s),
|
|
3819
3900
|
created_at: Math.floor(Date.now() / 1e3)
|
|
3820
3901
|
}, p = {
|
|
3821
|
-
kind:
|
|
3902
|
+
kind: He,
|
|
3822
3903
|
pubkey: f,
|
|
3823
|
-
content:
|
|
3904
|
+
content: j.encrypt(JSON.stringify(d), tt(l, this.inviterSessionPublicKey)),
|
|
3824
3905
|
created_at: Math.floor(Date.now() / 1e3),
|
|
3825
3906
|
tags: [["p", this.inviterSessionPublicKey]]
|
|
3826
3907
|
};
|
|
3827
|
-
return { channel:
|
|
3908
|
+
return { channel: c, event: ae(p, l) };
|
|
3828
3909
|
}
|
|
3829
3910
|
listen(t, n, r) {
|
|
3830
3911
|
if (!this.inviterSessionPrivateKey)
|
|
3831
3912
|
throw new Error("Inviter session key is not available");
|
|
3832
3913
|
const i = {
|
|
3833
|
-
kinds: [
|
|
3914
|
+
kinds: [He],
|
|
3834
3915
|
"#p": [this.inviterSessionPublicKey]
|
|
3835
3916
|
};
|
|
3836
3917
|
return n(i, async (o) => {
|
|
3837
3918
|
try {
|
|
3838
|
-
const s = await
|
|
3839
|
-
if (!
|
|
3919
|
+
const s = await j.decrypt(o.content, tt(this.inviterSessionPrivateKey, o.pubkey)), a = JSON.parse(s);
|
|
3920
|
+
if (!a.tags || !a.tags.some(([p, g]) => p === "secret" && g === this.linkSecret)) {
|
|
3840
3921
|
console.error("Invalid secret from event", o);
|
|
3841
3922
|
return;
|
|
3842
3923
|
}
|
|
3843
|
-
const l = await (typeof t == "function" ? t : (p, g) => Promise.resolve(
|
|
3844
|
-
r(d,
|
|
3924
|
+
const l = await (typeof t == "function" ? t : (p, g) => Promise.resolve(j.decrypt(p, tt(t, g))))(a.content, a.pubkey), f = W(this.linkSecret), u = o.id, d = ct.init(n, l, this.inviterSessionPrivateKey, !1, f, u);
|
|
3925
|
+
r(d, a.pubkey);
|
|
3845
3926
|
} catch (s) {
|
|
3846
3927
|
console.error("Error processing invite message:", s);
|
|
3847
3928
|
}
|
|
@@ -3850,13 +3931,14 @@ class nt {
|
|
|
3850
3931
|
}
|
|
3851
3932
|
export {
|
|
3852
3933
|
ct as Channel,
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3934
|
+
On as INVITE_EVENT_KIND,
|
|
3935
|
+
Oe as Invite,
|
|
3936
|
+
Rc as MAX_SKIP,
|
|
3937
|
+
He as MESSAGE_EVENT_KIND,
|
|
3938
|
+
kc as Sender,
|
|
3939
|
+
Mc as createMessageStream,
|
|
3858
3940
|
Pc as deserializeChannelState,
|
|
3859
3941
|
Re as kdf,
|
|
3860
|
-
|
|
3861
|
-
|
|
3942
|
+
Oc as serializeChannelState,
|
|
3943
|
+
Tt as skippedMessageIndexKey
|
|
3862
3944
|
};
|