nostr-double-ratchet 0.0.1
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/LICENSE +21 -0
- package/README.md +4 -0
- package/data/profileData.json +1 -0
- package/data/profileIndex.json +1 -0
- package/data/socialGraph.json +1 -0
- package/dist/Channel.d.ts +24 -0
- package/dist/Channel.d.ts.map +1 -0
- package/dist/InviteLink.d.ts +51 -0
- package/dist/InviteLink.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/nostr-double-ratchet.es.js +3760 -0
- package/dist/nostr-double-ratchet.umd.js +1 -0
- package/dist/types.d.ts +58 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +68 -0
- package/src/Channel.ts +143 -0
- package/src/InviteLink.ts +192 -0
- package/src/index.ts +4 -0
- package/src/types.ts +68 -0
- package/src/utils.ts +91 -0
|
@@ -0,0 +1,3760 @@
|
|
|
1
|
+
var oi = Object.defineProperty;
|
|
2
|
+
var si = (e, t, n) => t in e ? oi(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var Q = (e, t, n) => si(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
function mn(e) {
|
|
5
|
+
if (!Number.isSafeInteger(e) || e < 0)
|
|
6
|
+
throw new Error(`Wrong positive integer: ${e}`);
|
|
7
|
+
}
|
|
8
|
+
function Pn(e, ...t) {
|
|
9
|
+
if (!(e instanceof Uint8Array))
|
|
10
|
+
throw new Error("Expected Uint8Array");
|
|
11
|
+
if (t.length > 0 && !t.includes(e.length))
|
|
12
|
+
throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`);
|
|
13
|
+
}
|
|
14
|
+
function ai(e) {
|
|
15
|
+
if (typeof e != "function" || typeof e.create != "function")
|
|
16
|
+
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
17
|
+
mn(e.outputLen), mn(e.blockLen);
|
|
18
|
+
}
|
|
19
|
+
function it(e, t = !0) {
|
|
20
|
+
if (e.destroyed)
|
|
21
|
+
throw new Error("Hash instance has been destroyed");
|
|
22
|
+
if (t && e.finished)
|
|
23
|
+
throw new Error("Hash#digest() has already been called");
|
|
24
|
+
}
|
|
25
|
+
function ci(e, t) {
|
|
26
|
+
Pn(e);
|
|
27
|
+
const n = t.outputLen;
|
|
28
|
+
if (e.length < n)
|
|
29
|
+
throw new Error(`digestInto() expects output buffer of length at least ${n}`);
|
|
30
|
+
}
|
|
31
|
+
const Bt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
32
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
33
|
+
const On = (e) => e instanceof Uint8Array, Nt = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), te = (e, t) => e << 32 - t | e >>> t, ui = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
34
|
+
if (!ui)
|
|
35
|
+
throw new Error("Non little-endian hardware is not supported");
|
|
36
|
+
function li(e) {
|
|
37
|
+
if (typeof e != "string")
|
|
38
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
|
|
39
|
+
return new Uint8Array(new TextEncoder().encode(e));
|
|
40
|
+
}
|
|
41
|
+
function Zt(e) {
|
|
42
|
+
if (typeof e == "string" && (e = li(e)), !On(e))
|
|
43
|
+
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
44
|
+
return e;
|
|
45
|
+
}
|
|
46
|
+
function fi(...e) {
|
|
47
|
+
const t = new Uint8Array(e.reduce((r, i) => r + i.length, 0));
|
|
48
|
+
let n = 0;
|
|
49
|
+
return e.forEach((r) => {
|
|
50
|
+
if (!On(r))
|
|
51
|
+
throw new Error("Uint8Array expected");
|
|
52
|
+
t.set(r, n), n += r.length;
|
|
53
|
+
}), t;
|
|
54
|
+
}
|
|
55
|
+
let Hn = class {
|
|
56
|
+
// Safe version that clones internal state
|
|
57
|
+
clone() {
|
|
58
|
+
return this._cloneInto();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
function hi(e) {
|
|
62
|
+
const t = (r) => e().update(Zt(r)).digest(), n = e();
|
|
63
|
+
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
64
|
+
}
|
|
65
|
+
function Mn(e = 32) {
|
|
66
|
+
if (Bt && typeof Bt.getRandomValues == "function")
|
|
67
|
+
return Bt.getRandomValues(new Uint8Array(e));
|
|
68
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
69
|
+
}
|
|
70
|
+
function di(e, t, n, r) {
|
|
71
|
+
if (typeof e.setBigUint64 == "function")
|
|
72
|
+
return e.setBigUint64(t, n, r);
|
|
73
|
+
const i = BigInt(32), o = BigInt(4294967295), s = Number(n >> i & o), c = Number(n & o), a = r ? 4 : 0, u = r ? 0 : 4;
|
|
74
|
+
e.setUint32(t + a, s, r), e.setUint32(t + u, c, r);
|
|
75
|
+
}
|
|
76
|
+
let gi = class extends Hn {
|
|
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 = Nt(this.buffer);
|
|
79
|
+
}
|
|
80
|
+
update(t) {
|
|
81
|
+
it(this);
|
|
82
|
+
const { view: n, buffer: r, blockLen: i } = this;
|
|
83
|
+
t = Zt(t);
|
|
84
|
+
const o = t.length;
|
|
85
|
+
for (let s = 0; s < o; ) {
|
|
86
|
+
const c = Math.min(i - this.pos, o - s);
|
|
87
|
+
if (c === i) {
|
|
88
|
+
const a = Nt(t);
|
|
89
|
+
for (; i <= o - s; s += i)
|
|
90
|
+
this.process(a, s);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
r.set(t.subarray(s, s + c), this.pos), this.pos += c, s += c, this.pos === i && (this.process(n, 0), this.pos = 0);
|
|
94
|
+
}
|
|
95
|
+
return this.length += t.length, this.roundClean(), this;
|
|
96
|
+
}
|
|
97
|
+
digestInto(t) {
|
|
98
|
+
it(this), ci(t, this), this.finished = !0;
|
|
99
|
+
const { buffer: n, view: r, blockLen: i, isLE: o } = this;
|
|
100
|
+
let { pos: s } = this;
|
|
101
|
+
n[s++] = 128, this.buffer.subarray(s).fill(0), this.padOffset > i - s && (this.process(r, 0), s = 0);
|
|
102
|
+
for (let l = s; l < i; l++)
|
|
103
|
+
n[l] = 0;
|
|
104
|
+
di(r, i - 8, BigInt(this.length * 8), o), this.process(r, 0);
|
|
105
|
+
const c = Nt(t), a = this.outputLen;
|
|
106
|
+
if (a % 4)
|
|
107
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
108
|
+
const u = a / 4, f = this.get();
|
|
109
|
+
if (u > f.length)
|
|
110
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
111
|
+
for (let l = 0; l < u; l++)
|
|
112
|
+
c.setUint32(4 * l, f[l], o);
|
|
113
|
+
}
|
|
114
|
+
digest() {
|
|
115
|
+
const { buffer: t, outputLen: n } = this;
|
|
116
|
+
this.digestInto(t);
|
|
117
|
+
const r = t.slice(0, n);
|
|
118
|
+
return this.destroy(), r;
|
|
119
|
+
}
|
|
120
|
+
_cloneInto(t) {
|
|
121
|
+
t || (t = new this.constructor()), t.set(...this.get());
|
|
122
|
+
const { blockLen: n, buffer: r, length: i, finished: o, destroyed: s, pos: c } = this;
|
|
123
|
+
return t.length = i, t.pos = c, t.finished = o, t.destroyed = s, i % n && t.buffer.set(r), t;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const pi = (e, t, n) => e & t ^ ~e & n, yi = (e, t, n) => e & t ^ e & n ^ t & n, wi = /* @__PURE__ */ new Uint32Array([
|
|
127
|
+
1116352408,
|
|
128
|
+
1899447441,
|
|
129
|
+
3049323471,
|
|
130
|
+
3921009573,
|
|
131
|
+
961987163,
|
|
132
|
+
1508970993,
|
|
133
|
+
2453635748,
|
|
134
|
+
2870763221,
|
|
135
|
+
3624381080,
|
|
136
|
+
310598401,
|
|
137
|
+
607225278,
|
|
138
|
+
1426881987,
|
|
139
|
+
1925078388,
|
|
140
|
+
2162078206,
|
|
141
|
+
2614888103,
|
|
142
|
+
3248222580,
|
|
143
|
+
3835390401,
|
|
144
|
+
4022224774,
|
|
145
|
+
264347078,
|
|
146
|
+
604807628,
|
|
147
|
+
770255983,
|
|
148
|
+
1249150122,
|
|
149
|
+
1555081692,
|
|
150
|
+
1996064986,
|
|
151
|
+
2554220882,
|
|
152
|
+
2821834349,
|
|
153
|
+
2952996808,
|
|
154
|
+
3210313671,
|
|
155
|
+
3336571891,
|
|
156
|
+
3584528711,
|
|
157
|
+
113926993,
|
|
158
|
+
338241895,
|
|
159
|
+
666307205,
|
|
160
|
+
773529912,
|
|
161
|
+
1294757372,
|
|
162
|
+
1396182291,
|
|
163
|
+
1695183700,
|
|
164
|
+
1986661051,
|
|
165
|
+
2177026350,
|
|
166
|
+
2456956037,
|
|
167
|
+
2730485921,
|
|
168
|
+
2820302411,
|
|
169
|
+
3259730800,
|
|
170
|
+
3345764771,
|
|
171
|
+
3516065817,
|
|
172
|
+
3600352804,
|
|
173
|
+
4094571909,
|
|
174
|
+
275423344,
|
|
175
|
+
430227734,
|
|
176
|
+
506948616,
|
|
177
|
+
659060556,
|
|
178
|
+
883997877,
|
|
179
|
+
958139571,
|
|
180
|
+
1322822218,
|
|
181
|
+
1537002063,
|
|
182
|
+
1747873779,
|
|
183
|
+
1955562222,
|
|
184
|
+
2024104815,
|
|
185
|
+
2227730452,
|
|
186
|
+
2361852424,
|
|
187
|
+
2428436474,
|
|
188
|
+
2756734187,
|
|
189
|
+
3204031479,
|
|
190
|
+
3329325298
|
|
191
|
+
]), be = /* @__PURE__ */ new Uint32Array([
|
|
192
|
+
1779033703,
|
|
193
|
+
3144134277,
|
|
194
|
+
1013904242,
|
|
195
|
+
2773480762,
|
|
196
|
+
1359893119,
|
|
197
|
+
2600822924,
|
|
198
|
+
528734635,
|
|
199
|
+
1541459225
|
|
200
|
+
]), ve = /* @__PURE__ */ new Uint32Array(64);
|
|
201
|
+
let bi = class extends gi {
|
|
202
|
+
constructor() {
|
|
203
|
+
super(64, 32, 8, !1), this.A = be[0] | 0, this.B = be[1] | 0, this.C = be[2] | 0, this.D = be[3] | 0, this.E = be[4] | 0, this.F = be[5] | 0, this.G = be[6] | 0, this.H = be[7] | 0;
|
|
204
|
+
}
|
|
205
|
+
get() {
|
|
206
|
+
const { A: t, B: n, C: r, D: i, E: o, F: s, G: c, H: a } = this;
|
|
207
|
+
return [t, n, r, i, o, s, c, a];
|
|
208
|
+
}
|
|
209
|
+
// prettier-ignore
|
|
210
|
+
set(t, n, r, i, o, s, c, a) {
|
|
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 = c | 0, this.H = a | 0;
|
|
212
|
+
}
|
|
213
|
+
process(t, n) {
|
|
214
|
+
for (let l = 0; l < 16; l++, n += 4)
|
|
215
|
+
ve[l] = t.getUint32(n, !1);
|
|
216
|
+
for (let l = 16; l < 64; l++) {
|
|
217
|
+
const d = ve[l - 15], w = ve[l - 2], y = te(d, 7) ^ te(d, 18) ^ d >>> 3, h = te(w, 17) ^ te(w, 19) ^ w >>> 10;
|
|
218
|
+
ve[l] = h + ve[l - 7] + y + ve[l - 16] | 0;
|
|
219
|
+
}
|
|
220
|
+
let { A: r, B: i, C: o, D: s, E: c, F: a, G: u, H: f } = this;
|
|
221
|
+
for (let l = 0; l < 64; l++) {
|
|
222
|
+
const d = te(c, 6) ^ te(c, 11) ^ te(c, 25), w = f + d + pi(c, a, u) + wi[l] + ve[l] | 0, h = (te(r, 2) ^ te(r, 13) ^ te(r, 22)) + yi(r, i, o) | 0;
|
|
223
|
+
f = u, u = a, a = c, c = s + w | 0, s = o, o = i, i = r, r = w + h | 0;
|
|
224
|
+
}
|
|
225
|
+
r = r + this.A | 0, i = i + this.B | 0, o = o + this.C | 0, s = s + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, u = u + this.G | 0, f = f + this.H | 0, this.set(r, i, o, s, c, a, u, f);
|
|
226
|
+
}
|
|
227
|
+
roundClean() {
|
|
228
|
+
ve.fill(0);
|
|
229
|
+
}
|
|
230
|
+
destroy() {
|
|
231
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
const $t = /* @__PURE__ */ hi(() => new bi());
|
|
235
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
236
|
+
const qn = BigInt(0), ft = BigInt(1), vi = BigInt(2), ht = (e) => e instanceof Uint8Array, xi = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
237
|
+
function Me(e) {
|
|
238
|
+
if (!ht(e))
|
|
239
|
+
throw new Error("Uint8Array expected");
|
|
240
|
+
let t = "";
|
|
241
|
+
for (let n = 0; n < e.length; n++)
|
|
242
|
+
t += xi[e[n]];
|
|
243
|
+
return t;
|
|
244
|
+
}
|
|
245
|
+
function Dn(e) {
|
|
246
|
+
const t = e.toString(16);
|
|
247
|
+
return t.length & 1 ? `0${t}` : t;
|
|
248
|
+
}
|
|
249
|
+
function Ft(e) {
|
|
250
|
+
if (typeof e != "string")
|
|
251
|
+
throw new Error("hex string expected, got " + typeof e);
|
|
252
|
+
return BigInt(e === "" ? "0" : `0x${e}`);
|
|
253
|
+
}
|
|
254
|
+
function qe(e) {
|
|
255
|
+
if (typeof e != "string")
|
|
256
|
+
throw new Error("hex string expected, got " + typeof e);
|
|
257
|
+
const t = e.length;
|
|
258
|
+
if (t % 2)
|
|
259
|
+
throw new Error("padded hex string expected, got unpadded hex of length " + t);
|
|
260
|
+
const n = new Uint8Array(t / 2);
|
|
261
|
+
for (let r = 0; r < n.length; r++) {
|
|
262
|
+
const i = r * 2, o = e.slice(i, i + 2), s = Number.parseInt(o, 16);
|
|
263
|
+
if (Number.isNaN(s) || s < 0)
|
|
264
|
+
throw new Error("Invalid byte sequence");
|
|
265
|
+
n[r] = s;
|
|
266
|
+
}
|
|
267
|
+
return n;
|
|
268
|
+
}
|
|
269
|
+
function F(e) {
|
|
270
|
+
return Ft(Me(e));
|
|
271
|
+
}
|
|
272
|
+
function Wt(e) {
|
|
273
|
+
if (!ht(e))
|
|
274
|
+
throw new Error("Uint8Array expected");
|
|
275
|
+
return Ft(Me(Uint8Array.from(e).reverse()));
|
|
276
|
+
}
|
|
277
|
+
function Be(e, t) {
|
|
278
|
+
return qe(e.toString(16).padStart(t * 2, "0"));
|
|
279
|
+
}
|
|
280
|
+
function Gt(e, t) {
|
|
281
|
+
return Be(e, t).reverse();
|
|
282
|
+
}
|
|
283
|
+
function mi(e) {
|
|
284
|
+
return qe(Dn(e));
|
|
285
|
+
}
|
|
286
|
+
function z(e, t, n) {
|
|
287
|
+
let r;
|
|
288
|
+
if (typeof t == "string")
|
|
289
|
+
try {
|
|
290
|
+
r = qe(t);
|
|
291
|
+
} catch (o) {
|
|
292
|
+
throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${o}`);
|
|
293
|
+
}
|
|
294
|
+
else if (ht(t))
|
|
295
|
+
r = Uint8Array.from(t);
|
|
296
|
+
else
|
|
297
|
+
throw new Error(`${e} must be hex string or Uint8Array`);
|
|
298
|
+
const i = r.length;
|
|
299
|
+
if (typeof n == "number" && i !== n)
|
|
300
|
+
throw new Error(`${e} expected ${n} bytes, got ${i}`);
|
|
301
|
+
return r;
|
|
302
|
+
}
|
|
303
|
+
function _e(...e) {
|
|
304
|
+
const t = new Uint8Array(e.reduce((r, i) => r + i.length, 0));
|
|
305
|
+
let n = 0;
|
|
306
|
+
return e.forEach((r) => {
|
|
307
|
+
if (!ht(r))
|
|
308
|
+
throw new Error("Uint8Array expected");
|
|
309
|
+
t.set(r, n), n += r.length;
|
|
310
|
+
}), t;
|
|
311
|
+
}
|
|
312
|
+
function Ei(e, t) {
|
|
313
|
+
if (e.length !== t.length)
|
|
314
|
+
return !1;
|
|
315
|
+
for (let n = 0; n < e.length; n++)
|
|
316
|
+
if (e[n] !== t[n])
|
|
317
|
+
return !1;
|
|
318
|
+
return !0;
|
|
319
|
+
}
|
|
320
|
+
function Ai(e) {
|
|
321
|
+
if (typeof e != "string")
|
|
322
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
|
|
323
|
+
return new Uint8Array(new TextEncoder().encode(e));
|
|
324
|
+
}
|
|
325
|
+
function Si(e) {
|
|
326
|
+
let t;
|
|
327
|
+
for (t = 0; e > qn; e >>= ft, t += 1)
|
|
328
|
+
;
|
|
329
|
+
return t;
|
|
330
|
+
}
|
|
331
|
+
function Bi(e, t) {
|
|
332
|
+
return e >> BigInt(t) & ft;
|
|
333
|
+
}
|
|
334
|
+
const Ni = (e, t, n) => e | (n ? ft : qn) << BigInt(t), Jt = (e) => (vi << BigInt(e - 1)) - ft, Ct = (e) => new Uint8Array(e), En = (e) => Uint8Array.from(e);
|
|
335
|
+
function jn(e, t, n) {
|
|
336
|
+
if (typeof e != "number" || e < 2)
|
|
337
|
+
throw new Error("hashLen must be a number");
|
|
338
|
+
if (typeof t != "number" || t < 2)
|
|
339
|
+
throw new Error("qByteLen must be a number");
|
|
340
|
+
if (typeof n != "function")
|
|
341
|
+
throw new Error("hmacFn must be a function");
|
|
342
|
+
let r = Ct(e), i = Ct(e), o = 0;
|
|
343
|
+
const s = () => {
|
|
344
|
+
r.fill(1), i.fill(0), o = 0;
|
|
345
|
+
}, c = (...l) => n(i, r, ...l), a = (l = Ct()) => {
|
|
346
|
+
i = c(En([0]), l), r = c(), l.length !== 0 && (i = c(En([1]), l), r = c());
|
|
347
|
+
}, u = () => {
|
|
348
|
+
if (o++ >= 1e3)
|
|
349
|
+
throw new Error("drbg: tried 1000 values");
|
|
350
|
+
let l = 0;
|
|
351
|
+
const d = [];
|
|
352
|
+
for (; l < t; ) {
|
|
353
|
+
r = c();
|
|
354
|
+
const w = r.slice();
|
|
355
|
+
d.push(w), l += r.length;
|
|
356
|
+
}
|
|
357
|
+
return _e(...d);
|
|
358
|
+
};
|
|
359
|
+
return (l, d) => {
|
|
360
|
+
s(), a(l);
|
|
361
|
+
let w;
|
|
362
|
+
for (; !(w = d(u())); )
|
|
363
|
+
a();
|
|
364
|
+
return s(), w;
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
const Ci = {
|
|
368
|
+
bigint: (e) => typeof e == "bigint",
|
|
369
|
+
function: (e) => typeof e == "function",
|
|
370
|
+
boolean: (e) => typeof e == "boolean",
|
|
371
|
+
string: (e) => typeof e == "string",
|
|
372
|
+
stringOrUint8Array: (e) => typeof e == "string" || e instanceof Uint8Array,
|
|
373
|
+
isSafeInteger: (e) => Number.isSafeInteger(e),
|
|
374
|
+
array: (e) => Array.isArray(e),
|
|
375
|
+
field: (e, t) => t.Fp.isValid(e),
|
|
376
|
+
hash: (e) => typeof e == "function" && Number.isSafeInteger(e.outputLen)
|
|
377
|
+
};
|
|
378
|
+
function Ye(e, t, n = {}) {
|
|
379
|
+
const r = (i, o, s) => {
|
|
380
|
+
const c = Ci[o];
|
|
381
|
+
if (typeof c != "function")
|
|
382
|
+
throw new Error(`Invalid validator "${o}", expected function`);
|
|
383
|
+
const a = e[i];
|
|
384
|
+
if (!(s && a === void 0) && !c(a, e))
|
|
385
|
+
throw new Error(`Invalid param ${String(i)}=${a} (${typeof a}), expected ${o}`);
|
|
386
|
+
};
|
|
387
|
+
for (const [i, o] of Object.entries(t))
|
|
388
|
+
r(i, o, !1);
|
|
389
|
+
for (const [i, o] of Object.entries(n))
|
|
390
|
+
r(i, o, !0);
|
|
391
|
+
return e;
|
|
392
|
+
}
|
|
393
|
+
const Ui = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
394
|
+
__proto__: null,
|
|
395
|
+
bitGet: Bi,
|
|
396
|
+
bitLen: Si,
|
|
397
|
+
bitMask: Jt,
|
|
398
|
+
bitSet: Ni,
|
|
399
|
+
bytesToHex: Me,
|
|
400
|
+
bytesToNumberBE: F,
|
|
401
|
+
bytesToNumberLE: Wt,
|
|
402
|
+
concatBytes: _e,
|
|
403
|
+
createHmacDrbg: jn,
|
|
404
|
+
ensureBytes: z,
|
|
405
|
+
equalBytes: Ei,
|
|
406
|
+
hexToBytes: qe,
|
|
407
|
+
hexToNumber: Ft,
|
|
408
|
+
numberToBytesBE: Be,
|
|
409
|
+
numberToBytesLE: Gt,
|
|
410
|
+
numberToHexUnpadded: Dn,
|
|
411
|
+
numberToVarBytesBE: mi,
|
|
412
|
+
utf8ToBytes: Ai,
|
|
413
|
+
validateObject: Ye
|
|
414
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
415
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
416
|
+
const j = BigInt(0), M = BigInt(1), Ie = BigInt(2), Ii = BigInt(3), Rt = BigInt(4), An = BigInt(5), Sn = BigInt(8);
|
|
417
|
+
BigInt(9);
|
|
418
|
+
BigInt(16);
|
|
419
|
+
function V(e, t) {
|
|
420
|
+
const n = e % t;
|
|
421
|
+
return n >= j ? n : t + n;
|
|
422
|
+
}
|
|
423
|
+
function Ki(e, t, n) {
|
|
424
|
+
if (n <= j || t < j)
|
|
425
|
+
throw new Error("Expected power/modulo > 0");
|
|
426
|
+
if (n === M)
|
|
427
|
+
return j;
|
|
428
|
+
let r = M;
|
|
429
|
+
for (; t > j; )
|
|
430
|
+
t & M && (r = r * e % n), e = e * e % n, t >>= M;
|
|
431
|
+
return r;
|
|
432
|
+
}
|
|
433
|
+
function G(e, t, n) {
|
|
434
|
+
let r = e;
|
|
435
|
+
for (; t-- > j; )
|
|
436
|
+
r *= r, r %= n;
|
|
437
|
+
return r;
|
|
438
|
+
}
|
|
439
|
+
function Pt(e, t) {
|
|
440
|
+
if (e === j || t <= j)
|
|
441
|
+
throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);
|
|
442
|
+
let n = V(e, t), r = t, i = j, o = M;
|
|
443
|
+
for (; n !== j; ) {
|
|
444
|
+
const c = r / n, a = r % n, u = i - o * c;
|
|
445
|
+
r = n, n = a, i = o, o = u;
|
|
446
|
+
}
|
|
447
|
+
if (r !== M)
|
|
448
|
+
throw new Error("invert: does not exist");
|
|
449
|
+
return V(i, t);
|
|
450
|
+
}
|
|
451
|
+
function _i(e) {
|
|
452
|
+
const t = (e - M) / Ie;
|
|
453
|
+
let n, r, i;
|
|
454
|
+
for (n = e - M, r = 0; n % Ie === j; n /= Ie, r++)
|
|
455
|
+
;
|
|
456
|
+
for (i = Ie; i < e && Ki(i, t, e) !== e - M; i++)
|
|
457
|
+
;
|
|
458
|
+
if (r === 1) {
|
|
459
|
+
const s = (e + M) / Rt;
|
|
460
|
+
return function(a, u) {
|
|
461
|
+
const f = a.pow(u, s);
|
|
462
|
+
if (!a.eql(a.sqr(f), u))
|
|
463
|
+
throw new Error("Cannot find square root");
|
|
464
|
+
return f;
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
const o = (n + M) / Ie;
|
|
468
|
+
return function(c, a) {
|
|
469
|
+
if (c.pow(a, t) === c.neg(c.ONE))
|
|
470
|
+
throw new Error("Cannot find square root");
|
|
471
|
+
let u = r, f = c.pow(c.mul(c.ONE, i), n), l = c.pow(a, o), d = c.pow(a, n);
|
|
472
|
+
for (; !c.eql(d, c.ONE); ) {
|
|
473
|
+
if (c.eql(d, c.ZERO))
|
|
474
|
+
return c.ZERO;
|
|
475
|
+
let w = 1;
|
|
476
|
+
for (let h = c.sqr(d); w < u && !c.eql(h, c.ONE); w++)
|
|
477
|
+
h = c.sqr(h);
|
|
478
|
+
const y = c.pow(f, M << BigInt(u - w - 1));
|
|
479
|
+
f = c.sqr(y), l = c.mul(l, y), d = c.mul(d, f), u = w;
|
|
480
|
+
}
|
|
481
|
+
return l;
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function Li(e) {
|
|
485
|
+
if (e % Rt === Ii) {
|
|
486
|
+
const t = (e + M) / Rt;
|
|
487
|
+
return function(r, i) {
|
|
488
|
+
const o = r.pow(i, t);
|
|
489
|
+
if (!r.eql(r.sqr(o), i))
|
|
490
|
+
throw new Error("Cannot find square root");
|
|
491
|
+
return o;
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
if (e % Sn === An) {
|
|
495
|
+
const t = (e - An) / Sn;
|
|
496
|
+
return function(r, i) {
|
|
497
|
+
const o = r.mul(i, Ie), s = r.pow(o, t), c = r.mul(i, s), a = r.mul(r.mul(c, Ie), s), u = r.mul(c, r.sub(a, r.ONE));
|
|
498
|
+
if (!r.eql(r.sqr(u), i))
|
|
499
|
+
throw new Error("Cannot find square root");
|
|
500
|
+
return u;
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
return _i(e);
|
|
504
|
+
}
|
|
505
|
+
const ki = [
|
|
506
|
+
"create",
|
|
507
|
+
"isValid",
|
|
508
|
+
"is0",
|
|
509
|
+
"neg",
|
|
510
|
+
"inv",
|
|
511
|
+
"sqrt",
|
|
512
|
+
"sqr",
|
|
513
|
+
"eql",
|
|
514
|
+
"add",
|
|
515
|
+
"sub",
|
|
516
|
+
"mul",
|
|
517
|
+
"pow",
|
|
518
|
+
"div",
|
|
519
|
+
"addN",
|
|
520
|
+
"subN",
|
|
521
|
+
"mulN",
|
|
522
|
+
"sqrN"
|
|
523
|
+
];
|
|
524
|
+
function Ti(e) {
|
|
525
|
+
const t = {
|
|
526
|
+
ORDER: "bigint",
|
|
527
|
+
MASK: "bigint",
|
|
528
|
+
BYTES: "isSafeInteger",
|
|
529
|
+
BITS: "isSafeInteger"
|
|
530
|
+
}, n = ki.reduce((r, i) => (r[i] = "function", r), t);
|
|
531
|
+
return Ye(e, n);
|
|
532
|
+
}
|
|
533
|
+
function $i(e, t, n) {
|
|
534
|
+
if (n < j)
|
|
535
|
+
throw new Error("Expected power > 0");
|
|
536
|
+
if (n === j)
|
|
537
|
+
return e.ONE;
|
|
538
|
+
if (n === M)
|
|
539
|
+
return t;
|
|
540
|
+
let r = e.ONE, i = t;
|
|
541
|
+
for (; n > j; )
|
|
542
|
+
n & M && (r = e.mul(r, i)), i = e.sqr(i), n >>= M;
|
|
543
|
+
return r;
|
|
544
|
+
}
|
|
545
|
+
function Ri(e, t) {
|
|
546
|
+
const n = new Array(t.length), r = t.reduce((o, s, c) => e.is0(s) ? o : (n[c] = o, e.mul(o, s)), e.ONE), i = e.inv(r);
|
|
547
|
+
return t.reduceRight((o, s, c) => e.is0(s) ? o : (n[c] = e.mul(o, n[c]), e.mul(o, s)), i), n;
|
|
548
|
+
}
|
|
549
|
+
function Vn(e, t) {
|
|
550
|
+
const n = t !== void 0 ? t : e.toString(2).length, r = Math.ceil(n / 8);
|
|
551
|
+
return { nBitLength: n, nByteLength: r };
|
|
552
|
+
}
|
|
553
|
+
function Pi(e, t, n = !1, r = {}) {
|
|
554
|
+
if (e <= j)
|
|
555
|
+
throw new Error(`Expected Field ORDER > 0, got ${e}`);
|
|
556
|
+
const { nBitLength: i, nByteLength: o } = Vn(e, t);
|
|
557
|
+
if (o > 2048)
|
|
558
|
+
throw new Error("Field lengths over 2048 bytes are not supported");
|
|
559
|
+
const s = Li(e), c = Object.freeze({
|
|
560
|
+
ORDER: e,
|
|
561
|
+
BITS: i,
|
|
562
|
+
BYTES: o,
|
|
563
|
+
MASK: Jt(i),
|
|
564
|
+
ZERO: j,
|
|
565
|
+
ONE: M,
|
|
566
|
+
create: (a) => V(a, e),
|
|
567
|
+
isValid: (a) => {
|
|
568
|
+
if (typeof a != "bigint")
|
|
569
|
+
throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);
|
|
570
|
+
return j <= a && a < e;
|
|
571
|
+
},
|
|
572
|
+
is0: (a) => a === j,
|
|
573
|
+
isOdd: (a) => (a & M) === M,
|
|
574
|
+
neg: (a) => V(-a, e),
|
|
575
|
+
eql: (a, u) => a === u,
|
|
576
|
+
sqr: (a) => V(a * a, e),
|
|
577
|
+
add: (a, u) => V(a + u, e),
|
|
578
|
+
sub: (a, u) => V(a - u, e),
|
|
579
|
+
mul: (a, u) => V(a * u, e),
|
|
580
|
+
pow: (a, u) => $i(c, a, u),
|
|
581
|
+
div: (a, u) => V(a * Pt(u, e), e),
|
|
582
|
+
// Same as above, but doesn't normalize
|
|
583
|
+
sqrN: (a) => a * a,
|
|
584
|
+
addN: (a, u) => a + u,
|
|
585
|
+
subN: (a, u) => a - u,
|
|
586
|
+
mulN: (a, u) => a * u,
|
|
587
|
+
inv: (a) => Pt(a, e),
|
|
588
|
+
sqrt: r.sqrt || ((a) => s(c, a)),
|
|
589
|
+
invertBatch: (a) => Ri(c, a),
|
|
590
|
+
// TODO: do we really need constant cmov?
|
|
591
|
+
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
592
|
+
cmov: (a, u, f) => f ? u : a,
|
|
593
|
+
toBytes: (a) => n ? Gt(a, o) : Be(a, o),
|
|
594
|
+
fromBytes: (a) => {
|
|
595
|
+
if (a.length !== o)
|
|
596
|
+
throw new Error(`Fp.fromBytes: expected ${o}, got ${a.length}`);
|
|
597
|
+
return n ? Wt(a) : F(a);
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
return Object.freeze(c);
|
|
601
|
+
}
|
|
602
|
+
function zn(e) {
|
|
603
|
+
if (typeof e != "bigint")
|
|
604
|
+
throw new Error("field order must be bigint");
|
|
605
|
+
const t = e.toString(2).length;
|
|
606
|
+
return Math.ceil(t / 8);
|
|
607
|
+
}
|
|
608
|
+
function Zn(e) {
|
|
609
|
+
const t = zn(e);
|
|
610
|
+
return t + Math.ceil(t / 2);
|
|
611
|
+
}
|
|
612
|
+
function Oi(e, t, n = !1) {
|
|
613
|
+
const r = e.length, i = zn(t), o = Zn(t);
|
|
614
|
+
if (r < 16 || r < o || r > 1024)
|
|
615
|
+
throw new Error(`expected ${o}-1024 bytes of input, got ${r}`);
|
|
616
|
+
const s = n ? F(e) : Wt(e), c = V(s, t - M) + M;
|
|
617
|
+
return n ? Gt(c, i) : Be(c, i);
|
|
618
|
+
}
|
|
619
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
620
|
+
const Hi = BigInt(0), Ut = BigInt(1);
|
|
621
|
+
function Mi(e, t) {
|
|
622
|
+
const n = (i, o) => {
|
|
623
|
+
const s = o.negate();
|
|
624
|
+
return i ? s : o;
|
|
625
|
+
}, r = (i) => {
|
|
626
|
+
const o = Math.ceil(t / i) + 1, s = 2 ** (i - 1);
|
|
627
|
+
return { windows: o, windowSize: s };
|
|
628
|
+
};
|
|
629
|
+
return {
|
|
630
|
+
constTimeNegate: n,
|
|
631
|
+
// non-const time multiplication ladder
|
|
632
|
+
unsafeLadder(i, o) {
|
|
633
|
+
let s = e.ZERO, c = i;
|
|
634
|
+
for (; o > Hi; )
|
|
635
|
+
o & Ut && (s = s.add(c)), c = c.double(), o >>= Ut;
|
|
636
|
+
return s;
|
|
637
|
+
},
|
|
638
|
+
/**
|
|
639
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
640
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
641
|
+
* Number of precomputed points depends on the curve size:
|
|
642
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
643
|
+
* - 𝑊 is the window size
|
|
644
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
645
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
646
|
+
* @returns precomputed point tables flattened to a single array
|
|
647
|
+
*/
|
|
648
|
+
precomputeWindow(i, o) {
|
|
649
|
+
const { windows: s, windowSize: c } = r(o), a = [];
|
|
650
|
+
let u = i, f = u;
|
|
651
|
+
for (let l = 0; l < s; l++) {
|
|
652
|
+
f = u, a.push(f);
|
|
653
|
+
for (let d = 1; d < c; d++)
|
|
654
|
+
f = f.add(u), a.push(f);
|
|
655
|
+
u = f.double();
|
|
656
|
+
}
|
|
657
|
+
return a;
|
|
658
|
+
},
|
|
659
|
+
/**
|
|
660
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
661
|
+
* @param W window size
|
|
662
|
+
* @param precomputes precomputed tables
|
|
663
|
+
* @param n scalar (we don't check here, but should be less than curve order)
|
|
664
|
+
* @returns real and fake (for const-time) points
|
|
665
|
+
*/
|
|
666
|
+
wNAF(i, o, s) {
|
|
667
|
+
const { windows: c, windowSize: a } = r(i);
|
|
668
|
+
let u = e.ZERO, f = e.BASE;
|
|
669
|
+
const l = BigInt(2 ** i - 1), d = 2 ** i, w = BigInt(i);
|
|
670
|
+
for (let y = 0; y < c; y++) {
|
|
671
|
+
const h = y * a;
|
|
672
|
+
let g = Number(s & l);
|
|
673
|
+
s >>= w, g > a && (g -= d, s += Ut);
|
|
674
|
+
const p = h, m = h + Math.abs(g) - 1, B = y % 2 !== 0, _ = g < 0;
|
|
675
|
+
g === 0 ? f = f.add(n(B, o[p])) : u = u.add(n(_, o[m]));
|
|
676
|
+
}
|
|
677
|
+
return { p: u, f };
|
|
678
|
+
},
|
|
679
|
+
wNAFCached(i, o, s, c) {
|
|
680
|
+
const a = i._WINDOW_SIZE || 1;
|
|
681
|
+
let u = o.get(i);
|
|
682
|
+
return u || (u = this.precomputeWindow(i, a), a !== 1 && o.set(i, c(u))), this.wNAF(a, u, s);
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
function Fn(e) {
|
|
687
|
+
return Ti(e.Fp), Ye(e, {
|
|
688
|
+
n: "bigint",
|
|
689
|
+
h: "bigint",
|
|
690
|
+
Gx: "field",
|
|
691
|
+
Gy: "field"
|
|
692
|
+
}, {
|
|
693
|
+
nBitLength: "isSafeInteger",
|
|
694
|
+
nByteLength: "isSafeInteger"
|
|
695
|
+
}), Object.freeze({
|
|
696
|
+
...Vn(e.n, e.nBitLength),
|
|
697
|
+
...e,
|
|
698
|
+
p: e.Fp.ORDER
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
702
|
+
function qi(e) {
|
|
703
|
+
const t = Fn(e);
|
|
704
|
+
Ye(t, {
|
|
705
|
+
a: "field",
|
|
706
|
+
b: "field"
|
|
707
|
+
}, {
|
|
708
|
+
allowedPrivateKeyLengths: "array",
|
|
709
|
+
wrapPrivateKey: "boolean",
|
|
710
|
+
isTorsionFree: "function",
|
|
711
|
+
clearCofactor: "function",
|
|
712
|
+
allowInfinityPoint: "boolean",
|
|
713
|
+
fromBytes: "function",
|
|
714
|
+
toBytes: "function"
|
|
715
|
+
});
|
|
716
|
+
const { endo: n, Fp: r, a: i } = t;
|
|
717
|
+
if (n) {
|
|
718
|
+
if (!r.eql(i, r.ZERO))
|
|
719
|
+
throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");
|
|
720
|
+
if (typeof n != "object" || typeof n.beta != "bigint" || typeof n.splitScalar != "function")
|
|
721
|
+
throw new Error("Expected endomorphism with beta: bigint and splitScalar: function");
|
|
722
|
+
}
|
|
723
|
+
return Object.freeze({ ...t });
|
|
724
|
+
}
|
|
725
|
+
const { bytesToNumberBE: Di, hexToBytes: ji } = Ui, Ke = {
|
|
726
|
+
// asn.1 DER encoding utils
|
|
727
|
+
Err: class extends Error {
|
|
728
|
+
constructor(t = "") {
|
|
729
|
+
super(t);
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
_parseInt(e) {
|
|
733
|
+
const { Err: t } = Ke;
|
|
734
|
+
if (e.length < 2 || e[0] !== 2)
|
|
735
|
+
throw new t("Invalid signature integer tag");
|
|
736
|
+
const n = e[1], r = e.subarray(2, n + 2);
|
|
737
|
+
if (!n || r.length !== n)
|
|
738
|
+
throw new t("Invalid signature integer: wrong length");
|
|
739
|
+
if (r[0] & 128)
|
|
740
|
+
throw new t("Invalid signature integer: negative");
|
|
741
|
+
if (r[0] === 0 && !(r[1] & 128))
|
|
742
|
+
throw new t("Invalid signature integer: unnecessary leading zero");
|
|
743
|
+
return { d: Di(r), l: e.subarray(n + 2) };
|
|
744
|
+
},
|
|
745
|
+
toSig(e) {
|
|
746
|
+
const { Err: t } = Ke, n = typeof e == "string" ? ji(e) : e;
|
|
747
|
+
if (!(n instanceof Uint8Array))
|
|
748
|
+
throw new Error("ui8a expected");
|
|
749
|
+
let r = n.length;
|
|
750
|
+
if (r < 2 || n[0] != 48)
|
|
751
|
+
throw new t("Invalid signature tag");
|
|
752
|
+
if (n[1] !== r - 2)
|
|
753
|
+
throw new t("Invalid signature: incorrect length");
|
|
754
|
+
const { d: i, l: o } = Ke._parseInt(n.subarray(2)), { d: s, l: c } = Ke._parseInt(o);
|
|
755
|
+
if (c.length)
|
|
756
|
+
throw new t("Invalid signature: left bytes after parsing");
|
|
757
|
+
return { r: i, s };
|
|
758
|
+
},
|
|
759
|
+
hexFromSig(e) {
|
|
760
|
+
const t = (u) => Number.parseInt(u[0], 16) & 8 ? "00" + u : u, n = (u) => {
|
|
761
|
+
const f = u.toString(16);
|
|
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, c = n(o), a = n(s);
|
|
764
|
+
return `30${n(s + o + 4)}02${a}${i}02${c}${r}`;
|
|
765
|
+
}
|
|
766
|
+
}, ue = BigInt(0), J = BigInt(1);
|
|
767
|
+
BigInt(2);
|
|
768
|
+
const Bn = BigInt(3);
|
|
769
|
+
BigInt(4);
|
|
770
|
+
function Vi(e) {
|
|
771
|
+
const t = qi(e), { Fp: n } = t, r = t.toBytes || ((y, h, g) => {
|
|
772
|
+
const p = h.toAffine();
|
|
773
|
+
return _e(Uint8Array.from([4]), n.toBytes(p.x), n.toBytes(p.y));
|
|
774
|
+
}), i = t.fromBytes || ((y) => {
|
|
775
|
+
const h = y.subarray(1), g = n.fromBytes(h.subarray(0, n.BYTES)), p = n.fromBytes(h.subarray(n.BYTES, 2 * n.BYTES));
|
|
776
|
+
return { x: g, y: p };
|
|
777
|
+
});
|
|
778
|
+
function o(y) {
|
|
779
|
+
const { a: h, b: g } = t, p = n.sqr(y), m = n.mul(p, y);
|
|
780
|
+
return n.add(n.add(m, n.mul(y, h)), g);
|
|
781
|
+
}
|
|
782
|
+
if (!n.eql(n.sqr(t.Gy), o(t.Gx)))
|
|
783
|
+
throw new Error("bad generator point: equation left != right");
|
|
784
|
+
function s(y) {
|
|
785
|
+
return typeof y == "bigint" && ue < y && y < t.n;
|
|
786
|
+
}
|
|
787
|
+
function c(y) {
|
|
788
|
+
if (!s(y))
|
|
789
|
+
throw new Error("Expected valid bigint: 0 < bigint < curve.n");
|
|
790
|
+
}
|
|
791
|
+
function a(y) {
|
|
792
|
+
const { allowedPrivateKeyLengths: h, nByteLength: g, wrapPrivateKey: p, n: m } = t;
|
|
793
|
+
if (h && typeof y != "bigint") {
|
|
794
|
+
if (y instanceof Uint8Array && (y = Me(y)), typeof y != "string" || !h.includes(y.length))
|
|
795
|
+
throw new Error("Invalid key");
|
|
796
|
+
y = y.padStart(g * 2, "0");
|
|
797
|
+
}
|
|
798
|
+
let B;
|
|
799
|
+
try {
|
|
800
|
+
B = typeof y == "bigint" ? y : F(z("private key", y, g));
|
|
801
|
+
} catch {
|
|
802
|
+
throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof y}`);
|
|
803
|
+
}
|
|
804
|
+
return p && (B = V(B, m)), c(B), B;
|
|
805
|
+
}
|
|
806
|
+
const u = /* @__PURE__ */ new Map();
|
|
807
|
+
function f(y) {
|
|
808
|
+
if (!(y instanceof l))
|
|
809
|
+
throw new Error("ProjectivePoint expected");
|
|
810
|
+
}
|
|
811
|
+
class l {
|
|
812
|
+
constructor(h, g, p) {
|
|
813
|
+
if (this.px = h, this.py = g, this.pz = p, h == null || !n.isValid(h))
|
|
814
|
+
throw new Error("x required");
|
|
815
|
+
if (g == null || !n.isValid(g))
|
|
816
|
+
throw new Error("y required");
|
|
817
|
+
if (p == null || !n.isValid(p))
|
|
818
|
+
throw new Error("z required");
|
|
819
|
+
}
|
|
820
|
+
// Does not validate if the point is on-curve.
|
|
821
|
+
// Use fromHex instead, or call assertValidity() later.
|
|
822
|
+
static fromAffine(h) {
|
|
823
|
+
const { x: g, y: p } = h || {};
|
|
824
|
+
if (!h || !n.isValid(g) || !n.isValid(p))
|
|
825
|
+
throw new Error("invalid affine point");
|
|
826
|
+
if (h instanceof l)
|
|
827
|
+
throw new Error("projective point not allowed");
|
|
828
|
+
const m = (B) => n.eql(B, n.ZERO);
|
|
829
|
+
return m(g) && m(p) ? l.ZERO : new l(g, p, n.ONE);
|
|
830
|
+
}
|
|
831
|
+
get x() {
|
|
832
|
+
return this.toAffine().x;
|
|
833
|
+
}
|
|
834
|
+
get y() {
|
|
835
|
+
return this.toAffine().y;
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Takes a bunch of Projective Points but executes only one
|
|
839
|
+
* inversion on all of them. Inversion is very slow operation,
|
|
840
|
+
* so this improves performance massively.
|
|
841
|
+
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
842
|
+
*/
|
|
843
|
+
static normalizeZ(h) {
|
|
844
|
+
const g = n.invertBatch(h.map((p) => p.pz));
|
|
845
|
+
return h.map((p, m) => p.toAffine(g[m])).map(l.fromAffine);
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Converts hash string or Uint8Array to Point.
|
|
849
|
+
* @param hex short/long ECDSA hex
|
|
850
|
+
*/
|
|
851
|
+
static fromHex(h) {
|
|
852
|
+
const g = l.fromAffine(i(z("pointHex", h)));
|
|
853
|
+
return g.assertValidity(), g;
|
|
854
|
+
}
|
|
855
|
+
// Multiplies generator point by privateKey.
|
|
856
|
+
static fromPrivateKey(h) {
|
|
857
|
+
return l.BASE.multiply(a(h));
|
|
858
|
+
}
|
|
859
|
+
// "Private method", don't use it directly
|
|
860
|
+
_setWindowSize(h) {
|
|
861
|
+
this._WINDOW_SIZE = h, u.delete(this);
|
|
862
|
+
}
|
|
863
|
+
// A point on curve is valid if it conforms to equation.
|
|
864
|
+
assertValidity() {
|
|
865
|
+
if (this.is0()) {
|
|
866
|
+
if (t.allowInfinityPoint && !n.is0(this.py))
|
|
867
|
+
return;
|
|
868
|
+
throw new Error("bad point: ZERO");
|
|
869
|
+
}
|
|
870
|
+
const { x: h, y: g } = this.toAffine();
|
|
871
|
+
if (!n.isValid(h) || !n.isValid(g))
|
|
872
|
+
throw new Error("bad point: x or y not FE");
|
|
873
|
+
const p = n.sqr(g), m = o(h);
|
|
874
|
+
if (!n.eql(p, m))
|
|
875
|
+
throw new Error("bad point: equation left != right");
|
|
876
|
+
if (!this.isTorsionFree())
|
|
877
|
+
throw new Error("bad point: not in prime-order subgroup");
|
|
878
|
+
}
|
|
879
|
+
hasEvenY() {
|
|
880
|
+
const { y: h } = this.toAffine();
|
|
881
|
+
if (n.isOdd)
|
|
882
|
+
return !n.isOdd(h);
|
|
883
|
+
throw new Error("Field doesn't support isOdd");
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* Compare one point to another.
|
|
887
|
+
*/
|
|
888
|
+
equals(h) {
|
|
889
|
+
f(h);
|
|
890
|
+
const { px: g, py: p, pz: m } = this, { px: B, py: _, pz: U } = h, x = n.eql(n.mul(g, U), n.mul(B, m)), E = n.eql(n.mul(p, U), n.mul(_, m));
|
|
891
|
+
return x && E;
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Flips point to one corresponding to (x, -y) in Affine coordinates.
|
|
895
|
+
*/
|
|
896
|
+
negate() {
|
|
897
|
+
return new l(this.px, n.neg(this.py), this.pz);
|
|
898
|
+
}
|
|
899
|
+
// Renes-Costello-Batina exception-free doubling formula.
|
|
900
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
901
|
+
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
902
|
+
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
903
|
+
double() {
|
|
904
|
+
const { a: h, b: g } = t, p = n.mul(g, Bn), { px: m, py: B, pz: _ } = this;
|
|
905
|
+
let U = n.ZERO, x = n.ZERO, E = n.ZERO, A = n.mul(m, m), O = n.mul(B, B), K = n.mul(_, _), N = n.mul(m, B);
|
|
906
|
+
return N = n.add(N, N), E = n.mul(m, _), E = n.add(E, E), U = n.mul(h, E), x = n.mul(p, K), x = n.add(U, x), U = n.sub(O, x), x = n.add(O, x), x = n.mul(U, x), U = n.mul(N, U), E = n.mul(p, E), K = n.mul(h, K), N = n.sub(A, K), N = n.mul(h, N), N = n.add(N, E), E = n.add(A, A), A = n.add(E, A), A = n.add(A, K), A = n.mul(A, N), x = n.add(x, A), K = n.mul(B, _), K = n.add(K, K), A = n.mul(K, N), U = n.sub(U, A), E = n.mul(K, O), E = n.add(E, E), E = n.add(E, E), new l(U, x, E);
|
|
907
|
+
}
|
|
908
|
+
// Renes-Costello-Batina exception-free addition formula.
|
|
909
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
910
|
+
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
911
|
+
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
912
|
+
add(h) {
|
|
913
|
+
f(h);
|
|
914
|
+
const { px: g, py: p, pz: m } = this, { px: B, py: _, pz: U } = h;
|
|
915
|
+
let x = n.ZERO, E = n.ZERO, A = n.ZERO;
|
|
916
|
+
const O = t.a, K = n.mul(t.b, Bn);
|
|
917
|
+
let N = n.mul(g, B), $ = n.mul(p, _), R = n.mul(m, U), H = n.add(g, p), b = n.add(B, _);
|
|
918
|
+
H = n.mul(H, b), b = n.add(N, $), H = n.sub(H, b), b = n.add(g, m);
|
|
919
|
+
let v = n.add(B, U);
|
|
920
|
+
return b = n.mul(b, v), v = n.add(N, R), b = n.sub(b, v), v = n.add(p, m), x = n.add(_, U), v = n.mul(v, x), x = n.add($, R), v = n.sub(v, x), A = n.mul(O, b), x = n.mul(K, R), A = n.add(x, A), x = n.sub($, A), A = n.add($, A), E = n.mul(x, A), $ = n.add(N, N), $ = n.add($, N), R = n.mul(O, R), b = n.mul(K, b), $ = n.add($, R), R = n.sub(N, R), R = n.mul(O, R), b = n.add(b, R), N = n.mul($, b), E = n.add(E, N), N = n.mul(v, b), x = n.mul(H, x), x = n.sub(x, N), N = n.mul(H, $), A = n.mul(v, A), A = n.add(A, N), new l(x, E, A);
|
|
921
|
+
}
|
|
922
|
+
subtract(h) {
|
|
923
|
+
return this.add(h.negate());
|
|
924
|
+
}
|
|
925
|
+
is0() {
|
|
926
|
+
return this.equals(l.ZERO);
|
|
927
|
+
}
|
|
928
|
+
wNAF(h) {
|
|
929
|
+
return w.wNAFCached(this, u, h, (g) => {
|
|
930
|
+
const p = n.invertBatch(g.map((m) => m.pz));
|
|
931
|
+
return g.map((m, B) => m.toAffine(p[B])).map(l.fromAffine);
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
936
|
+
* It's faster, but should only be used when you don't care about
|
|
937
|
+
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
938
|
+
*/
|
|
939
|
+
multiplyUnsafe(h) {
|
|
940
|
+
const g = l.ZERO;
|
|
941
|
+
if (h === ue)
|
|
942
|
+
return g;
|
|
943
|
+
if (c(h), h === J)
|
|
944
|
+
return this;
|
|
945
|
+
const { endo: p } = t;
|
|
946
|
+
if (!p)
|
|
947
|
+
return w.unsafeLadder(this, h);
|
|
948
|
+
let { k1neg: m, k1: B, k2neg: _, k2: U } = p.splitScalar(h), x = g, E = g, A = this;
|
|
949
|
+
for (; B > ue || U > ue; )
|
|
950
|
+
B & J && (x = x.add(A)), U & J && (E = E.add(A)), A = A.double(), B >>= J, U >>= J;
|
|
951
|
+
return m && (x = x.negate()), _ && (E = E.negate()), E = new l(n.mul(E.px, p.beta), E.py, E.pz), x.add(E);
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Constant time multiplication.
|
|
955
|
+
* Uses wNAF method. Windowed method may be 10% faster,
|
|
956
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
957
|
+
* Uses precomputes when available.
|
|
958
|
+
* Uses endomorphism for Koblitz curves.
|
|
959
|
+
* @param scalar by which the point would be multiplied
|
|
960
|
+
* @returns New point
|
|
961
|
+
*/
|
|
962
|
+
multiply(h) {
|
|
963
|
+
c(h);
|
|
964
|
+
let g = h, p, m;
|
|
965
|
+
const { endo: B } = t;
|
|
966
|
+
if (B) {
|
|
967
|
+
const { k1neg: _, k1: U, k2neg: x, k2: E } = B.splitScalar(g);
|
|
968
|
+
let { p: A, f: O } = this.wNAF(U), { p: K, f: N } = this.wNAF(E);
|
|
969
|
+
A = w.constTimeNegate(_, A), K = w.constTimeNegate(x, K), K = new l(n.mul(K.px, B.beta), K.py, K.pz), p = A.add(K), m = O.add(N);
|
|
970
|
+
} else {
|
|
971
|
+
const { p: _, f: U } = this.wNAF(g);
|
|
972
|
+
p = _, m = U;
|
|
973
|
+
}
|
|
974
|
+
return l.normalizeZ([p, m])[0];
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
978
|
+
* Not using Strauss-Shamir trick: precomputation tables are faster.
|
|
979
|
+
* The trick could be useful if both P and Q are not G (not in our case).
|
|
980
|
+
* @returns non-zero affine point
|
|
981
|
+
*/
|
|
982
|
+
multiplyAndAddUnsafe(h, g, p) {
|
|
983
|
+
const m = l.BASE, B = (U, x) => x === ue || x === J || !U.equals(m) ? U.multiplyUnsafe(x) : U.multiply(x), _ = B(this, g).add(B(h, p));
|
|
984
|
+
return _.is0() ? void 0 : _;
|
|
985
|
+
}
|
|
986
|
+
// Converts Projective point to affine (x, y) coordinates.
|
|
987
|
+
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
988
|
+
// (x, y, z) ∋ (x=x/z, y=y/z)
|
|
989
|
+
toAffine(h) {
|
|
990
|
+
const { px: g, py: p, pz: m } = this, B = this.is0();
|
|
991
|
+
h == null && (h = B ? n.ONE : n.inv(m));
|
|
992
|
+
const _ = n.mul(g, h), U = n.mul(p, h), x = n.mul(m, h);
|
|
993
|
+
if (B)
|
|
994
|
+
return { x: n.ZERO, y: n.ZERO };
|
|
995
|
+
if (!n.eql(x, n.ONE))
|
|
996
|
+
throw new Error("invZ was invalid");
|
|
997
|
+
return { x: _, y: U };
|
|
998
|
+
}
|
|
999
|
+
isTorsionFree() {
|
|
1000
|
+
const { h, isTorsionFree: g } = t;
|
|
1001
|
+
if (h === J)
|
|
1002
|
+
return !0;
|
|
1003
|
+
if (g)
|
|
1004
|
+
return g(l, this);
|
|
1005
|
+
throw new Error("isTorsionFree() has not been declared for the elliptic curve");
|
|
1006
|
+
}
|
|
1007
|
+
clearCofactor() {
|
|
1008
|
+
const { h, clearCofactor: g } = t;
|
|
1009
|
+
return h === J ? this : g ? g(l, this) : this.multiplyUnsafe(t.h);
|
|
1010
|
+
}
|
|
1011
|
+
toRawBytes(h = !0) {
|
|
1012
|
+
return this.assertValidity(), r(l, this, h);
|
|
1013
|
+
}
|
|
1014
|
+
toHex(h = !0) {
|
|
1015
|
+
return Me(this.toRawBytes(h));
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
l.BASE = new l(t.Gx, t.Gy, n.ONE), l.ZERO = new l(n.ZERO, n.ONE, n.ZERO);
|
|
1019
|
+
const d = t.nBitLength, w = Mi(l, t.endo ? Math.ceil(d / 2) : d);
|
|
1020
|
+
return {
|
|
1021
|
+
CURVE: t,
|
|
1022
|
+
ProjectivePoint: l,
|
|
1023
|
+
normPrivateKeyToScalar: a,
|
|
1024
|
+
weierstrassEquation: o,
|
|
1025
|
+
isWithinCurveOrder: s
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
function zi(e) {
|
|
1029
|
+
const t = Fn(e);
|
|
1030
|
+
return Ye(t, {
|
|
1031
|
+
hash: "hash",
|
|
1032
|
+
hmac: "function",
|
|
1033
|
+
randomBytes: "function"
|
|
1034
|
+
}, {
|
|
1035
|
+
bits2int: "function",
|
|
1036
|
+
bits2int_modN: "function",
|
|
1037
|
+
lowS: "boolean"
|
|
1038
|
+
}), Object.freeze({ lowS: !0, ...t });
|
|
1039
|
+
}
|
|
1040
|
+
function Zi(e) {
|
|
1041
|
+
const t = zi(e), { Fp: n, n: r } = t, i = n.BYTES + 1, o = 2 * n.BYTES + 1;
|
|
1042
|
+
function s(b) {
|
|
1043
|
+
return ue < b && b < n.ORDER;
|
|
1044
|
+
}
|
|
1045
|
+
function c(b) {
|
|
1046
|
+
return V(b, r);
|
|
1047
|
+
}
|
|
1048
|
+
function a(b) {
|
|
1049
|
+
return Pt(b, r);
|
|
1050
|
+
}
|
|
1051
|
+
const { ProjectivePoint: u, normPrivateKeyToScalar: f, weierstrassEquation: l, isWithinCurveOrder: d } = Vi({
|
|
1052
|
+
...t,
|
|
1053
|
+
toBytes(b, v, S) {
|
|
1054
|
+
const I = v.toAffine(), C = n.toBytes(I.x), L = _e;
|
|
1055
|
+
return S ? L(Uint8Array.from([v.hasEvenY() ? 2 : 3]), C) : L(Uint8Array.from([4]), C, n.toBytes(I.y));
|
|
1056
|
+
},
|
|
1057
|
+
fromBytes(b) {
|
|
1058
|
+
const v = b.length, S = b[0], I = b.subarray(1);
|
|
1059
|
+
if (v === i && (S === 2 || S === 3)) {
|
|
1060
|
+
const C = F(I);
|
|
1061
|
+
if (!s(C))
|
|
1062
|
+
throw new Error("Point is not on curve");
|
|
1063
|
+
const L = l(C);
|
|
1064
|
+
let P = n.sqrt(L);
|
|
1065
|
+
const T = (P & J) === J;
|
|
1066
|
+
return (S & 1) === 1 !== T && (P = n.neg(P)), { x: C, y: P };
|
|
1067
|
+
} else if (v === o && S === 4) {
|
|
1068
|
+
const C = n.fromBytes(I.subarray(0, n.BYTES)), L = n.fromBytes(I.subarray(n.BYTES, 2 * n.BYTES));
|
|
1069
|
+
return { x: C, y: L };
|
|
1070
|
+
} else
|
|
1071
|
+
throw new Error(`Point of length ${v} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`);
|
|
1072
|
+
}
|
|
1073
|
+
}), w = (b) => Me(Be(b, t.nByteLength));
|
|
1074
|
+
function y(b) {
|
|
1075
|
+
const v = r >> J;
|
|
1076
|
+
return b > v;
|
|
1077
|
+
}
|
|
1078
|
+
function h(b) {
|
|
1079
|
+
return y(b) ? c(-b) : b;
|
|
1080
|
+
}
|
|
1081
|
+
const g = (b, v, S) => F(b.slice(v, S));
|
|
1082
|
+
class p {
|
|
1083
|
+
constructor(v, S, I) {
|
|
1084
|
+
this.r = v, this.s = S, this.recovery = I, this.assertValidity();
|
|
1085
|
+
}
|
|
1086
|
+
// pair (bytes of r, bytes of s)
|
|
1087
|
+
static fromCompact(v) {
|
|
1088
|
+
const S = t.nByteLength;
|
|
1089
|
+
return v = z("compactSignature", v, S * 2), new p(g(v, 0, S), g(v, S, 2 * S));
|
|
1090
|
+
}
|
|
1091
|
+
// DER encoded ECDSA signature
|
|
1092
|
+
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
1093
|
+
static fromDER(v) {
|
|
1094
|
+
const { r: S, s: I } = Ke.toSig(z("DER", v));
|
|
1095
|
+
return new p(S, I);
|
|
1096
|
+
}
|
|
1097
|
+
assertValidity() {
|
|
1098
|
+
if (!d(this.r))
|
|
1099
|
+
throw new Error("r must be 0 < r < CURVE.n");
|
|
1100
|
+
if (!d(this.s))
|
|
1101
|
+
throw new Error("s must be 0 < s < CURVE.n");
|
|
1102
|
+
}
|
|
1103
|
+
addRecoveryBit(v) {
|
|
1104
|
+
return new p(this.r, this.s, v);
|
|
1105
|
+
}
|
|
1106
|
+
recoverPublicKey(v) {
|
|
1107
|
+
const { r: S, s: I, recovery: C } = this, L = E(z("msgHash", v));
|
|
1108
|
+
if (C == null || ![0, 1, 2, 3].includes(C))
|
|
1109
|
+
throw new Error("recovery id invalid");
|
|
1110
|
+
const P = C === 2 || C === 3 ? S + t.n : S;
|
|
1111
|
+
if (P >= n.ORDER)
|
|
1112
|
+
throw new Error("recovery id 2 or 3 invalid");
|
|
1113
|
+
const T = C & 1 ? "03" : "02", Y = u.fromHex(T + w(P)), ye = a(P), ke = c(-L * ye), Ve = c(I * ye), we = u.BASE.multiplyAndAddUnsafe(Y, ke, Ve);
|
|
1114
|
+
if (!we)
|
|
1115
|
+
throw new Error("point at infinify");
|
|
1116
|
+
return we.assertValidity(), we;
|
|
1117
|
+
}
|
|
1118
|
+
// Signatures should be low-s, to prevent malleability.
|
|
1119
|
+
hasHighS() {
|
|
1120
|
+
return y(this.s);
|
|
1121
|
+
}
|
|
1122
|
+
normalizeS() {
|
|
1123
|
+
return this.hasHighS() ? new p(this.r, c(-this.s), this.recovery) : this;
|
|
1124
|
+
}
|
|
1125
|
+
// DER-encoded
|
|
1126
|
+
toDERRawBytes() {
|
|
1127
|
+
return qe(this.toDERHex());
|
|
1128
|
+
}
|
|
1129
|
+
toDERHex() {
|
|
1130
|
+
return Ke.hexFromSig({ r: this.r, s: this.s });
|
|
1131
|
+
}
|
|
1132
|
+
// padded bytes of r, then padded bytes of s
|
|
1133
|
+
toCompactRawBytes() {
|
|
1134
|
+
return qe(this.toCompactHex());
|
|
1135
|
+
}
|
|
1136
|
+
toCompactHex() {
|
|
1137
|
+
return w(this.r) + w(this.s);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
const m = {
|
|
1141
|
+
isValidPrivateKey(b) {
|
|
1142
|
+
try {
|
|
1143
|
+
return f(b), !0;
|
|
1144
|
+
} catch {
|
|
1145
|
+
return !1;
|
|
1146
|
+
}
|
|
1147
|
+
},
|
|
1148
|
+
normPrivateKeyToScalar: f,
|
|
1149
|
+
/**
|
|
1150
|
+
* Produces cryptographically secure private key from random of size
|
|
1151
|
+
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
|
1152
|
+
*/
|
|
1153
|
+
randomPrivateKey: () => {
|
|
1154
|
+
const b = Zn(t.n);
|
|
1155
|
+
return Oi(t.randomBytes(b), t.n);
|
|
1156
|
+
},
|
|
1157
|
+
/**
|
|
1158
|
+
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
|
1159
|
+
* Allows to massively speed-up `point.multiply(scalar)`.
|
|
1160
|
+
* @returns cached point
|
|
1161
|
+
* @example
|
|
1162
|
+
* const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
|
|
1163
|
+
* fast.multiply(privKey); // much faster ECDH now
|
|
1164
|
+
*/
|
|
1165
|
+
precompute(b = 8, v = u.BASE) {
|
|
1166
|
+
return v._setWindowSize(b), v.multiply(BigInt(3)), v;
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
function B(b, v = !0) {
|
|
1170
|
+
return u.fromPrivateKey(b).toRawBytes(v);
|
|
1171
|
+
}
|
|
1172
|
+
function _(b) {
|
|
1173
|
+
const v = b instanceof Uint8Array, S = typeof b == "string", I = (v || S) && b.length;
|
|
1174
|
+
return v ? I === i || I === o : S ? I === 2 * i || I === 2 * o : b instanceof u;
|
|
1175
|
+
}
|
|
1176
|
+
function U(b, v, S = !0) {
|
|
1177
|
+
if (_(b))
|
|
1178
|
+
throw new Error("first arg must be private key");
|
|
1179
|
+
if (!_(v))
|
|
1180
|
+
throw new Error("second arg must be public key");
|
|
1181
|
+
return u.fromHex(v).multiply(f(b)).toRawBytes(S);
|
|
1182
|
+
}
|
|
1183
|
+
const x = t.bits2int || function(b) {
|
|
1184
|
+
const v = F(b), S = b.length * 8 - t.nBitLength;
|
|
1185
|
+
return S > 0 ? v >> BigInt(S) : v;
|
|
1186
|
+
}, E = t.bits2int_modN || function(b) {
|
|
1187
|
+
return c(x(b));
|
|
1188
|
+
}, A = Jt(t.nBitLength);
|
|
1189
|
+
function O(b) {
|
|
1190
|
+
if (typeof b != "bigint")
|
|
1191
|
+
throw new Error("bigint expected");
|
|
1192
|
+
if (!(ue <= b && b < A))
|
|
1193
|
+
throw new Error(`bigint expected < 2^${t.nBitLength}`);
|
|
1194
|
+
return Be(b, t.nByteLength);
|
|
1195
|
+
}
|
|
1196
|
+
function K(b, v, S = N) {
|
|
1197
|
+
if (["recovered", "canonical"].some((Ue) => Ue in S))
|
|
1198
|
+
throw new Error("sign() legacy options not supported");
|
|
1199
|
+
const { hash: I, randomBytes: C } = t;
|
|
1200
|
+
let { lowS: L, prehash: P, extraEntropy: T } = S;
|
|
1201
|
+
L == null && (L = !0), b = z("msgHash", b), P && (b = z("prehashed msgHash", I(b)));
|
|
1202
|
+
const Y = E(b), ye = f(v), ke = [O(ye), O(Y)];
|
|
1203
|
+
if (T != null) {
|
|
1204
|
+
const Ue = T === !0 ? C(n.BYTES) : T;
|
|
1205
|
+
ke.push(z("extraEntropy", Ue));
|
|
1206
|
+
}
|
|
1207
|
+
const Ve = _e(...ke), we = Y;
|
|
1208
|
+
function St(Ue) {
|
|
1209
|
+
const Te = x(Ue);
|
|
1210
|
+
if (!d(Te))
|
|
1211
|
+
return;
|
|
1212
|
+
const bn = a(Te), $e = u.BASE.multiply(Te).toAffine(), X = c($e.x);
|
|
1213
|
+
if (X === ue)
|
|
1214
|
+
return;
|
|
1215
|
+
const Re = c(bn * c(we + X * ye));
|
|
1216
|
+
if (Re === ue)
|
|
1217
|
+
return;
|
|
1218
|
+
let vn = ($e.x === X ? 0 : 2) | Number($e.y & J), xn = Re;
|
|
1219
|
+
return L && y(Re) && (xn = h(Re), vn ^= 1), new p(X, xn, vn);
|
|
1220
|
+
}
|
|
1221
|
+
return { seed: Ve, k2sig: St };
|
|
1222
|
+
}
|
|
1223
|
+
const N = { lowS: t.lowS, prehash: !1 }, $ = { lowS: t.lowS, prehash: !1 };
|
|
1224
|
+
function R(b, v, S = N) {
|
|
1225
|
+
const { seed: I, k2sig: C } = K(b, v, S), L = t;
|
|
1226
|
+
return jn(L.hash.outputLen, L.nByteLength, L.hmac)(I, C);
|
|
1227
|
+
}
|
|
1228
|
+
u.BASE._setWindowSize(8);
|
|
1229
|
+
function H(b, v, S, I = $) {
|
|
1230
|
+
var $e;
|
|
1231
|
+
const C = b;
|
|
1232
|
+
if (v = z("msgHash", v), S = z("publicKey", S), "strict" in I)
|
|
1233
|
+
throw new Error("options.strict was renamed to lowS");
|
|
1234
|
+
const { lowS: L, prehash: P } = I;
|
|
1235
|
+
let T, Y;
|
|
1236
|
+
try {
|
|
1237
|
+
if (typeof C == "string" || C instanceof Uint8Array)
|
|
1238
|
+
try {
|
|
1239
|
+
T = p.fromDER(C);
|
|
1240
|
+
} catch (X) {
|
|
1241
|
+
if (!(X instanceof Ke.Err))
|
|
1242
|
+
throw X;
|
|
1243
|
+
T = p.fromCompact(C);
|
|
1244
|
+
}
|
|
1245
|
+
else if (typeof C == "object" && typeof C.r == "bigint" && typeof C.s == "bigint") {
|
|
1246
|
+
const { r: X, s: Re } = C;
|
|
1247
|
+
T = new p(X, Re);
|
|
1248
|
+
} else
|
|
1249
|
+
throw new Error("PARSE");
|
|
1250
|
+
Y = u.fromHex(S);
|
|
1251
|
+
} catch (X) {
|
|
1252
|
+
if (X.message === "PARSE")
|
|
1253
|
+
throw new Error("signature must be Signature instance, Uint8Array or hex string");
|
|
1254
|
+
return !1;
|
|
1255
|
+
}
|
|
1256
|
+
if (L && T.hasHighS())
|
|
1257
|
+
return !1;
|
|
1258
|
+
P && (v = t.hash(v));
|
|
1259
|
+
const { r: ye, s: ke } = T, Ve = E(v), we = a(ke), St = c(Ve * we), Ue = c(ye * we), Te = ($e = u.BASE.multiplyAndAddUnsafe(Y, St, Ue)) == null ? void 0 : $e.toAffine();
|
|
1260
|
+
return Te ? c(Te.x) === ye : !1;
|
|
1261
|
+
}
|
|
1262
|
+
return {
|
|
1263
|
+
CURVE: t,
|
|
1264
|
+
getPublicKey: B,
|
|
1265
|
+
getSharedSecret: U,
|
|
1266
|
+
sign: R,
|
|
1267
|
+
verify: H,
|
|
1268
|
+
ProjectivePoint: u,
|
|
1269
|
+
Signature: p,
|
|
1270
|
+
utils: m
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
let Wn = class extends Hn {
|
|
1274
|
+
constructor(t, n) {
|
|
1275
|
+
super(), this.finished = !1, this.destroyed = !1, ai(t);
|
|
1276
|
+
const r = Zt(n);
|
|
1277
|
+
if (this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
1278
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
1279
|
+
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
1280
|
+
const i = this.blockLen, o = new Uint8Array(i);
|
|
1281
|
+
o.set(r.length > i ? t.create().update(r).digest() : r);
|
|
1282
|
+
for (let s = 0; s < o.length; s++)
|
|
1283
|
+
o[s] ^= 54;
|
|
1284
|
+
this.iHash.update(o), this.oHash = t.create();
|
|
1285
|
+
for (let s = 0; s < o.length; s++)
|
|
1286
|
+
o[s] ^= 106;
|
|
1287
|
+
this.oHash.update(o), o.fill(0);
|
|
1288
|
+
}
|
|
1289
|
+
update(t) {
|
|
1290
|
+
return it(this), this.iHash.update(t), this;
|
|
1291
|
+
}
|
|
1292
|
+
digestInto(t) {
|
|
1293
|
+
it(this), Pn(t, this.outputLen), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
1294
|
+
}
|
|
1295
|
+
digest() {
|
|
1296
|
+
const t = new Uint8Array(this.oHash.outputLen);
|
|
1297
|
+
return this.digestInto(t), t;
|
|
1298
|
+
}
|
|
1299
|
+
_cloneInto(t) {
|
|
1300
|
+
t || (t = Object.create(Object.getPrototypeOf(this), {}));
|
|
1301
|
+
const { oHash: n, iHash: r, finished: i, destroyed: o, blockLen: s, outputLen: c } = this;
|
|
1302
|
+
return t = t, t.finished = i, t.destroyed = o, t.blockLen = s, t.outputLen = c, t.oHash = n._cloneInto(t.oHash), t.iHash = r._cloneInto(t.iHash), t;
|
|
1303
|
+
}
|
|
1304
|
+
destroy() {
|
|
1305
|
+
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1308
|
+
const Gn = (e, t, n) => new Wn(e, t).update(n).digest();
|
|
1309
|
+
Gn.create = (e, t) => new Wn(e, t);
|
|
1310
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1311
|
+
function Fi(e) {
|
|
1312
|
+
return {
|
|
1313
|
+
hash: e,
|
|
1314
|
+
hmac: (t, ...n) => Gn(e, t, fi(...n)),
|
|
1315
|
+
randomBytes: Mn
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
function Wi(e, t) {
|
|
1319
|
+
const n = (r) => Zi({ ...e, ...Fi(r) });
|
|
1320
|
+
return Object.freeze({ ...n(t), create: n });
|
|
1321
|
+
}
|
|
1322
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1323
|
+
const dt = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), ot = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), Jn = BigInt(1), st = BigInt(2), Nn = (e, t) => (e + t / st) / t;
|
|
1324
|
+
function Yn(e) {
|
|
1325
|
+
const t = dt, n = BigInt(3), r = BigInt(6), i = BigInt(11), o = BigInt(22), s = BigInt(23), c = BigInt(44), a = BigInt(88), u = e * e * e % t, f = u * u * e % t, l = G(f, n, t) * f % t, d = G(l, n, t) * f % t, w = G(d, st, t) * u % t, y = G(w, i, t) * w % t, h = G(y, o, t) * y % t, g = G(h, c, t) * h % t, p = G(g, a, t) * g % t, m = G(p, c, t) * h % t, B = G(m, n, t) * f % t, _ = G(B, s, t) * y % t, U = G(_, r, t) * u % t, x = G(U, st, t);
|
|
1326
|
+
if (!Ot.eql(Ot.sqr(x), e))
|
|
1327
|
+
throw new Error("Cannot find square root");
|
|
1328
|
+
return x;
|
|
1329
|
+
}
|
|
1330
|
+
const Ot = Pi(dt, void 0, void 0, { sqrt: Yn }), Le = Wi({
|
|
1331
|
+
a: BigInt(0),
|
|
1332
|
+
b: BigInt(7),
|
|
1333
|
+
Fp: Ot,
|
|
1334
|
+
n: ot,
|
|
1335
|
+
// Base point (x, y) aka generator point
|
|
1336
|
+
Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
|
|
1337
|
+
Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
|
|
1338
|
+
h: BigInt(1),
|
|
1339
|
+
lowS: !0,
|
|
1340
|
+
/**
|
|
1341
|
+
* secp256k1 belongs to Koblitz curves: it has efficiently computable endomorphism.
|
|
1342
|
+
* Endomorphism uses 2x less RAM, speeds up precomputation by 2x and ECDH / key recovery by 20%.
|
|
1343
|
+
* For precomputed wNAF it trades off 1/2 init time & 1/3 ram for 20% perf hit.
|
|
1344
|
+
* Explanation: https://gist.github.com/paulmillr/eb670806793e84df628a7c434a873066
|
|
1345
|
+
*/
|
|
1346
|
+
endo: {
|
|
1347
|
+
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
1348
|
+
splitScalar: (e) => {
|
|
1349
|
+
const t = ot, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -Jn * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), o = n, s = BigInt("0x100000000000000000000000000000000"), c = Nn(o * e, t), a = Nn(-r * e, t);
|
|
1350
|
+
let u = V(e - c * n - a * i, t), f = V(-c * r - a * o, t);
|
|
1351
|
+
const l = u > s, d = f > s;
|
|
1352
|
+
if (l && (u = t - u), d && (f = t - f), u > s || f > s)
|
|
1353
|
+
throw new Error("splitScalar: Endomorphism failed, k=" + e);
|
|
1354
|
+
return { k1neg: l, k1: u, k2neg: d, k2: f };
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
}, $t), gt = BigInt(0), Xn = (e) => typeof e == "bigint" && gt < e && e < dt, Gi = (e) => typeof e == "bigint" && gt < e && e < ot, Cn = {};
|
|
1358
|
+
function at(e, ...t) {
|
|
1359
|
+
let n = Cn[e];
|
|
1360
|
+
if (n === void 0) {
|
|
1361
|
+
const r = $t(Uint8Array.from(e, (i) => i.charCodeAt(0)));
|
|
1362
|
+
n = _e(r, r), Cn[e] = n;
|
|
1363
|
+
}
|
|
1364
|
+
return $t(_e(n, ...t));
|
|
1365
|
+
}
|
|
1366
|
+
const Yt = (e) => e.toRawBytes(!0).slice(1), Ht = (e) => Be(e, 32), It = (e) => V(e, dt), Ge = (e) => V(e, ot), Xt = Le.ProjectivePoint, Ji = (e, t, n) => Xt.BASE.multiplyAndAddUnsafe(e, t, n);
|
|
1367
|
+
function Mt(e) {
|
|
1368
|
+
let t = Le.utils.normPrivateKeyToScalar(e), n = Xt.fromPrivateKey(t);
|
|
1369
|
+
return { scalar: n.hasEvenY() ? t : Ge(-t), bytes: Yt(n) };
|
|
1370
|
+
}
|
|
1371
|
+
function Qn(e) {
|
|
1372
|
+
if (!Xn(e))
|
|
1373
|
+
throw new Error("bad x: need 0 < x < p");
|
|
1374
|
+
const t = It(e * e), n = It(t * e + BigInt(7));
|
|
1375
|
+
let r = Yn(n);
|
|
1376
|
+
r % st !== gt && (r = It(-r));
|
|
1377
|
+
const i = new Xt(e, r, Jn);
|
|
1378
|
+
return i.assertValidity(), i;
|
|
1379
|
+
}
|
|
1380
|
+
function er(...e) {
|
|
1381
|
+
return Ge(F(at("BIP0340/challenge", ...e)));
|
|
1382
|
+
}
|
|
1383
|
+
function Yi(e) {
|
|
1384
|
+
return Mt(e).bytes;
|
|
1385
|
+
}
|
|
1386
|
+
function Xi(e, t, n = Mn(32)) {
|
|
1387
|
+
const r = z("message", e), { bytes: i, scalar: o } = Mt(t), s = z("auxRand", n, 32), c = Ht(o ^ F(at("BIP0340/aux", s))), a = at("BIP0340/nonce", c, i, r), u = Ge(F(a));
|
|
1388
|
+
if (u === gt)
|
|
1389
|
+
throw new Error("sign failed: k is zero");
|
|
1390
|
+
const { bytes: f, scalar: l } = Mt(u), d = er(f, i, r), w = new Uint8Array(64);
|
|
1391
|
+
if (w.set(f, 0), w.set(Ht(Ge(l + d * o)), 32), !tr(w, r, i))
|
|
1392
|
+
throw new Error("sign: Invalid signature produced");
|
|
1393
|
+
return w;
|
|
1394
|
+
}
|
|
1395
|
+
function tr(e, t, n) {
|
|
1396
|
+
const r = z("signature", e, 64), i = z("message", t), o = z("publicKey", n, 32);
|
|
1397
|
+
try {
|
|
1398
|
+
const s = Qn(F(o)), c = F(r.subarray(0, 32));
|
|
1399
|
+
if (!Xn(c))
|
|
1400
|
+
return !1;
|
|
1401
|
+
const a = F(r.subarray(32, 64));
|
|
1402
|
+
if (!Gi(a))
|
|
1403
|
+
return !1;
|
|
1404
|
+
const u = er(Ht(c), Yt(s), i), f = Ji(s, a, Ge(-u));
|
|
1405
|
+
return !(!f || !f.hasEvenY() || f.toAffine().x !== c);
|
|
1406
|
+
} catch {
|
|
1407
|
+
return !1;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
const ze = {
|
|
1411
|
+
getPublicKey: Yi,
|
|
1412
|
+
sign: Xi,
|
|
1413
|
+
verify: tr,
|
|
1414
|
+
utils: {
|
|
1415
|
+
randomPrivateKey: Le.utils.randomPrivateKey,
|
|
1416
|
+
lift_x: Qn,
|
|
1417
|
+
pointToBytes: Yt,
|
|
1418
|
+
numberToBytesBE: Be,
|
|
1419
|
+
bytesToNumberBE: F,
|
|
1420
|
+
taggedHash: at,
|
|
1421
|
+
mod: V
|
|
1422
|
+
}
|
|
1423
|
+
}, Kt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
1424
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1425
|
+
const Qt = (e) => e instanceof Uint8Array, _t = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), ne = (e, t) => e << 32 - t | e >>> t, Qi = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1426
|
+
if (!Qi)
|
|
1427
|
+
throw new Error("Non little-endian hardware is not supported");
|
|
1428
|
+
const eo = Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
1429
|
+
function D(e) {
|
|
1430
|
+
if (!Qt(e))
|
|
1431
|
+
throw new Error("Uint8Array expected");
|
|
1432
|
+
let t = "";
|
|
1433
|
+
for (let n = 0; n < e.length; n++)
|
|
1434
|
+
t += eo[e[n]];
|
|
1435
|
+
return t;
|
|
1436
|
+
}
|
|
1437
|
+
function W(e) {
|
|
1438
|
+
if (typeof e != "string")
|
|
1439
|
+
throw new Error("hex string expected, got " + typeof e);
|
|
1440
|
+
const t = e.length;
|
|
1441
|
+
if (t % 2)
|
|
1442
|
+
throw new Error("padded hex string expected, got unpadded hex of length " + t);
|
|
1443
|
+
const n = new Uint8Array(t / 2);
|
|
1444
|
+
for (let r = 0; r < n.length; r++) {
|
|
1445
|
+
const i = r * 2, o = e.slice(i, i + 2), s = Number.parseInt(o, 16);
|
|
1446
|
+
if (Number.isNaN(s) || s < 0)
|
|
1447
|
+
throw new Error("Invalid byte sequence");
|
|
1448
|
+
n[r] = s;
|
|
1449
|
+
}
|
|
1450
|
+
return n;
|
|
1451
|
+
}
|
|
1452
|
+
function to(e) {
|
|
1453
|
+
if (typeof e != "string")
|
|
1454
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
|
|
1455
|
+
return new Uint8Array(new TextEncoder().encode(e));
|
|
1456
|
+
}
|
|
1457
|
+
function Je(e) {
|
|
1458
|
+
if (typeof e == "string" && (e = to(e)), !Qt(e))
|
|
1459
|
+
throw new Error(`expected Uint8Array, got ${typeof e}`);
|
|
1460
|
+
return e;
|
|
1461
|
+
}
|
|
1462
|
+
function pt(...e) {
|
|
1463
|
+
const t = new Uint8Array(e.reduce((r, i) => r + i.length, 0));
|
|
1464
|
+
let n = 0;
|
|
1465
|
+
return e.forEach((r) => {
|
|
1466
|
+
if (!Qt(r))
|
|
1467
|
+
throw new Error("Uint8Array expected");
|
|
1468
|
+
t.set(r, n), n += r.length;
|
|
1469
|
+
}), t;
|
|
1470
|
+
}
|
|
1471
|
+
class nr {
|
|
1472
|
+
// Safe version that clones internal state
|
|
1473
|
+
clone() {
|
|
1474
|
+
return this._cloneInto();
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
function rr(e) {
|
|
1478
|
+
const t = (r) => e().update(Je(r)).digest(), n = e();
|
|
1479
|
+
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
1480
|
+
}
|
|
1481
|
+
function ir(e = 32) {
|
|
1482
|
+
if (Kt && typeof Kt.getRandomValues == "function")
|
|
1483
|
+
return Kt.getRandomValues(new Uint8Array(e));
|
|
1484
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
1485
|
+
}
|
|
1486
|
+
function qt(e) {
|
|
1487
|
+
if (!Number.isSafeInteger(e) || e < 0)
|
|
1488
|
+
throw new Error(`Wrong positive integer: ${e}`);
|
|
1489
|
+
}
|
|
1490
|
+
function no(e) {
|
|
1491
|
+
if (typeof e != "boolean")
|
|
1492
|
+
throw new Error(`Expected boolean, not ${e}`);
|
|
1493
|
+
}
|
|
1494
|
+
function or(e, ...t) {
|
|
1495
|
+
if (!(e instanceof Uint8Array))
|
|
1496
|
+
throw new Error("Expected Uint8Array");
|
|
1497
|
+
if (t.length > 0 && !t.includes(e.length))
|
|
1498
|
+
throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`);
|
|
1499
|
+
}
|
|
1500
|
+
function ro(e) {
|
|
1501
|
+
if (typeof e != "function" || typeof e.create != "function")
|
|
1502
|
+
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
1503
|
+
qt(e.outputLen), qt(e.blockLen);
|
|
1504
|
+
}
|
|
1505
|
+
function io(e, t = !0) {
|
|
1506
|
+
if (e.destroyed)
|
|
1507
|
+
throw new Error("Hash instance has been destroyed");
|
|
1508
|
+
if (t && e.finished)
|
|
1509
|
+
throw new Error("Hash#digest() has already been called");
|
|
1510
|
+
}
|
|
1511
|
+
function oo(e, t) {
|
|
1512
|
+
or(e);
|
|
1513
|
+
const n = t.outputLen;
|
|
1514
|
+
if (e.length < n)
|
|
1515
|
+
throw new Error(`digestInto() expects output buffer of length at least ${n}`);
|
|
1516
|
+
}
|
|
1517
|
+
const ie = {
|
|
1518
|
+
number: qt,
|
|
1519
|
+
bool: no,
|
|
1520
|
+
bytes: or,
|
|
1521
|
+
hash: ro,
|
|
1522
|
+
exists: io,
|
|
1523
|
+
output: oo
|
|
1524
|
+
};
|
|
1525
|
+
function so(e, t, n, r) {
|
|
1526
|
+
if (typeof e.setBigUint64 == "function")
|
|
1527
|
+
return e.setBigUint64(t, n, r);
|
|
1528
|
+
const i = BigInt(32), o = BigInt(4294967295), s = Number(n >> i & o), c = Number(n & o), a = r ? 4 : 0, u = r ? 0 : 4;
|
|
1529
|
+
e.setUint32(t + a, s, r), e.setUint32(t + u, c, r);
|
|
1530
|
+
}
|
|
1531
|
+
class ao extends nr {
|
|
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 = _t(this.buffer);
|
|
1534
|
+
}
|
|
1535
|
+
update(t) {
|
|
1536
|
+
ie.exists(this);
|
|
1537
|
+
const { view: n, buffer: r, blockLen: i } = this;
|
|
1538
|
+
t = Je(t);
|
|
1539
|
+
const o = t.length;
|
|
1540
|
+
for (let s = 0; s < o; ) {
|
|
1541
|
+
const c = Math.min(i - this.pos, o - s);
|
|
1542
|
+
if (c === i) {
|
|
1543
|
+
const a = _t(t);
|
|
1544
|
+
for (; i <= o - s; s += i)
|
|
1545
|
+
this.process(a, s);
|
|
1546
|
+
continue;
|
|
1547
|
+
}
|
|
1548
|
+
r.set(t.subarray(s, s + c), this.pos), this.pos += c, s += c, this.pos === i && (this.process(n, 0), this.pos = 0);
|
|
1549
|
+
}
|
|
1550
|
+
return this.length += t.length, this.roundClean(), this;
|
|
1551
|
+
}
|
|
1552
|
+
digestInto(t) {
|
|
1553
|
+
ie.exists(this), ie.output(t, this), this.finished = !0;
|
|
1554
|
+
const { buffer: n, view: r, blockLen: i, isLE: o } = this;
|
|
1555
|
+
let { pos: s } = this;
|
|
1556
|
+
n[s++] = 128, this.buffer.subarray(s).fill(0), this.padOffset > i - s && (this.process(r, 0), s = 0);
|
|
1557
|
+
for (let l = s; l < i; l++)
|
|
1558
|
+
n[l] = 0;
|
|
1559
|
+
so(r, i - 8, BigInt(this.length * 8), o), this.process(r, 0);
|
|
1560
|
+
const c = _t(t), a = this.outputLen;
|
|
1561
|
+
if (a % 4)
|
|
1562
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
1563
|
+
const u = a / 4, f = this.get();
|
|
1564
|
+
if (u > f.length)
|
|
1565
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
1566
|
+
for (let l = 0; l < u; l++)
|
|
1567
|
+
c.setUint32(4 * l, f[l], o);
|
|
1568
|
+
}
|
|
1569
|
+
digest() {
|
|
1570
|
+
const { buffer: t, outputLen: n } = this;
|
|
1571
|
+
this.digestInto(t);
|
|
1572
|
+
const r = t.slice(0, n);
|
|
1573
|
+
return this.destroy(), r;
|
|
1574
|
+
}
|
|
1575
|
+
_cloneInto(t) {
|
|
1576
|
+
t || (t = new this.constructor()), t.set(...this.get());
|
|
1577
|
+
const { blockLen: n, buffer: r, length: i, finished: o, destroyed: s, pos: c } = this;
|
|
1578
|
+
return t.length = i, t.pos = c, t.finished = o, t.destroyed = s, i % n && t.buffer.set(r), t;
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
const co = (e, t, n) => e & t ^ ~e & n, uo = (e, t, n) => e & t ^ e & n ^ t & n, lo = new Uint32Array([
|
|
1582
|
+
1116352408,
|
|
1583
|
+
1899447441,
|
|
1584
|
+
3049323471,
|
|
1585
|
+
3921009573,
|
|
1586
|
+
961987163,
|
|
1587
|
+
1508970993,
|
|
1588
|
+
2453635748,
|
|
1589
|
+
2870763221,
|
|
1590
|
+
3624381080,
|
|
1591
|
+
310598401,
|
|
1592
|
+
607225278,
|
|
1593
|
+
1426881987,
|
|
1594
|
+
1925078388,
|
|
1595
|
+
2162078206,
|
|
1596
|
+
2614888103,
|
|
1597
|
+
3248222580,
|
|
1598
|
+
3835390401,
|
|
1599
|
+
4022224774,
|
|
1600
|
+
264347078,
|
|
1601
|
+
604807628,
|
|
1602
|
+
770255983,
|
|
1603
|
+
1249150122,
|
|
1604
|
+
1555081692,
|
|
1605
|
+
1996064986,
|
|
1606
|
+
2554220882,
|
|
1607
|
+
2821834349,
|
|
1608
|
+
2952996808,
|
|
1609
|
+
3210313671,
|
|
1610
|
+
3336571891,
|
|
1611
|
+
3584528711,
|
|
1612
|
+
113926993,
|
|
1613
|
+
338241895,
|
|
1614
|
+
666307205,
|
|
1615
|
+
773529912,
|
|
1616
|
+
1294757372,
|
|
1617
|
+
1396182291,
|
|
1618
|
+
1695183700,
|
|
1619
|
+
1986661051,
|
|
1620
|
+
2177026350,
|
|
1621
|
+
2456956037,
|
|
1622
|
+
2730485921,
|
|
1623
|
+
2820302411,
|
|
1624
|
+
3259730800,
|
|
1625
|
+
3345764771,
|
|
1626
|
+
3516065817,
|
|
1627
|
+
3600352804,
|
|
1628
|
+
4094571909,
|
|
1629
|
+
275423344,
|
|
1630
|
+
430227734,
|
|
1631
|
+
506948616,
|
|
1632
|
+
659060556,
|
|
1633
|
+
883997877,
|
|
1634
|
+
958139571,
|
|
1635
|
+
1322822218,
|
|
1636
|
+
1537002063,
|
|
1637
|
+
1747873779,
|
|
1638
|
+
1955562222,
|
|
1639
|
+
2024104815,
|
|
1640
|
+
2227730452,
|
|
1641
|
+
2361852424,
|
|
1642
|
+
2428436474,
|
|
1643
|
+
2756734187,
|
|
1644
|
+
3204031479,
|
|
1645
|
+
3329325298
|
|
1646
|
+
]), xe = new Uint32Array([
|
|
1647
|
+
1779033703,
|
|
1648
|
+
3144134277,
|
|
1649
|
+
1013904242,
|
|
1650
|
+
2773480762,
|
|
1651
|
+
1359893119,
|
|
1652
|
+
2600822924,
|
|
1653
|
+
528734635,
|
|
1654
|
+
1541459225
|
|
1655
|
+
]), me = new Uint32Array(64);
|
|
1656
|
+
class sr extends ao {
|
|
1657
|
+
constructor() {
|
|
1658
|
+
super(64, 32, 8, !1), this.A = xe[0] | 0, this.B = xe[1] | 0, this.C = xe[2] | 0, this.D = xe[3] | 0, this.E = xe[4] | 0, this.F = xe[5] | 0, this.G = xe[6] | 0, this.H = xe[7] | 0;
|
|
1659
|
+
}
|
|
1660
|
+
get() {
|
|
1661
|
+
const { A: t, B: n, C: r, D: i, E: o, F: s, G: c, H: a } = this;
|
|
1662
|
+
return [t, n, r, i, o, s, c, a];
|
|
1663
|
+
}
|
|
1664
|
+
// prettier-ignore
|
|
1665
|
+
set(t, n, r, i, o, s, c, a) {
|
|
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 = c | 0, this.H = a | 0;
|
|
1667
|
+
}
|
|
1668
|
+
process(t, n) {
|
|
1669
|
+
for (let l = 0; l < 16; l++, n += 4)
|
|
1670
|
+
me[l] = t.getUint32(n, !1);
|
|
1671
|
+
for (let l = 16; l < 64; l++) {
|
|
1672
|
+
const d = me[l - 15], w = me[l - 2], y = ne(d, 7) ^ ne(d, 18) ^ d >>> 3, h = ne(w, 17) ^ ne(w, 19) ^ w >>> 10;
|
|
1673
|
+
me[l] = h + me[l - 7] + y + me[l - 16] | 0;
|
|
1674
|
+
}
|
|
1675
|
+
let { A: r, B: i, C: o, D: s, E: c, F: a, G: u, H: f } = this;
|
|
1676
|
+
for (let l = 0; l < 64; l++) {
|
|
1677
|
+
const d = ne(c, 6) ^ ne(c, 11) ^ ne(c, 25), w = f + d + co(c, a, u) + lo[l] + me[l] | 0, h = (ne(r, 2) ^ ne(r, 13) ^ ne(r, 22)) + uo(r, i, o) | 0;
|
|
1678
|
+
f = u, u = a, a = c, c = s + w | 0, s = o, o = i, i = r, r = w + h | 0;
|
|
1679
|
+
}
|
|
1680
|
+
r = r + this.A | 0, i = i + this.B | 0, o = o + this.C | 0, s = s + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, u = u + this.G | 0, f = f + this.H | 0, this.set(r, i, o, s, c, a, u, f);
|
|
1681
|
+
}
|
|
1682
|
+
roundClean() {
|
|
1683
|
+
me.fill(0);
|
|
1684
|
+
}
|
|
1685
|
+
destroy() {
|
|
1686
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
class fo extends sr {
|
|
1690
|
+
constructor() {
|
|
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
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
const Ne = rr(() => new sr());
|
|
1695
|
+
rr(() => new fo());
|
|
1696
|
+
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1697
|
+
function je(e) {
|
|
1698
|
+
if (!Number.isSafeInteger(e))
|
|
1699
|
+
throw new Error(`Wrong integer: ${e}`);
|
|
1700
|
+
}
|
|
1701
|
+
function de(...e) {
|
|
1702
|
+
const t = (i, o) => (s) => i(o(s)), n = Array.from(e).reverse().reduce((i, o) => i ? t(i, o.encode) : o.encode, void 0), r = e.reduce((i, o) => i ? t(i, o.decode) : o.decode, void 0);
|
|
1703
|
+
return { encode: n, decode: r };
|
|
1704
|
+
}
|
|
1705
|
+
function ge(e) {
|
|
1706
|
+
return {
|
|
1707
|
+
encode: (t) => {
|
|
1708
|
+
if (!Array.isArray(t) || t.length && typeof t[0] != "number")
|
|
1709
|
+
throw new Error("alphabet.encode input should be an array of numbers");
|
|
1710
|
+
return t.map((n) => {
|
|
1711
|
+
if (je(n), n < 0 || n >= e.length)
|
|
1712
|
+
throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${e.length})`);
|
|
1713
|
+
return e[n];
|
|
1714
|
+
});
|
|
1715
|
+
},
|
|
1716
|
+
decode: (t) => {
|
|
1717
|
+
if (!Array.isArray(t) || t.length && typeof t[0] != "string")
|
|
1718
|
+
throw new Error("alphabet.decode input should be array of strings");
|
|
1719
|
+
return t.map((n) => {
|
|
1720
|
+
if (typeof n != "string")
|
|
1721
|
+
throw new Error(`alphabet.decode: not string element=${n}`);
|
|
1722
|
+
const r = e.indexOf(n);
|
|
1723
|
+
if (r === -1)
|
|
1724
|
+
throw new Error(`Unknown letter: "${n}". Allowed: ${e}`);
|
|
1725
|
+
return r;
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
function pe(e = "") {
|
|
1731
|
+
if (typeof e != "string")
|
|
1732
|
+
throw new Error("join separator should be string");
|
|
1733
|
+
return {
|
|
1734
|
+
encode: (t) => {
|
|
1735
|
+
if (!Array.isArray(t) || t.length && typeof t[0] != "string")
|
|
1736
|
+
throw new Error("join.encode input should be array of strings");
|
|
1737
|
+
for (let n of t)
|
|
1738
|
+
if (typeof n != "string")
|
|
1739
|
+
throw new Error(`join.encode: non-string input=${n}`);
|
|
1740
|
+
return t.join(e);
|
|
1741
|
+
},
|
|
1742
|
+
decode: (t) => {
|
|
1743
|
+
if (typeof t != "string")
|
|
1744
|
+
throw new Error("join.decode input should be string");
|
|
1745
|
+
return t.split(e);
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
function yt(e, t = "=") {
|
|
1750
|
+
if (je(e), typeof t != "string")
|
|
1751
|
+
throw new Error("padding chr should be string");
|
|
1752
|
+
return {
|
|
1753
|
+
encode(n) {
|
|
1754
|
+
if (!Array.isArray(n) || n.length && typeof n[0] != "string")
|
|
1755
|
+
throw new Error("padding.encode input should be array of strings");
|
|
1756
|
+
for (let r of n)
|
|
1757
|
+
if (typeof r != "string")
|
|
1758
|
+
throw new Error(`padding.encode: non-string input=${r}`);
|
|
1759
|
+
for (; n.length * e % 8; )
|
|
1760
|
+
n.push(t);
|
|
1761
|
+
return n;
|
|
1762
|
+
},
|
|
1763
|
+
decode(n) {
|
|
1764
|
+
if (!Array.isArray(n) || n.length && typeof n[0] != "string")
|
|
1765
|
+
throw new Error("padding.encode input should be array of strings");
|
|
1766
|
+
for (let i of n)
|
|
1767
|
+
if (typeof i != "string")
|
|
1768
|
+
throw new Error(`padding.decode: non-string input=${i}`);
|
|
1769
|
+
let r = n.length;
|
|
1770
|
+
if (r * e % 8)
|
|
1771
|
+
throw new Error("Invalid padding: string should have whole number of bytes");
|
|
1772
|
+
for (; r > 0 && n[r - 1] === t; r--)
|
|
1773
|
+
if (!((r - 1) * e % 8))
|
|
1774
|
+
throw new Error("Invalid padding: string has too much padding");
|
|
1775
|
+
return n.slice(0, r);
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1779
|
+
function ar(e) {
|
|
1780
|
+
if (typeof e != "function")
|
|
1781
|
+
throw new Error("normalize fn should be function");
|
|
1782
|
+
return { encode: (t) => t, decode: (t) => e(t) };
|
|
1783
|
+
}
|
|
1784
|
+
function Un(e, t, n) {
|
|
1785
|
+
if (t < 2)
|
|
1786
|
+
throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);
|
|
1787
|
+
if (n < 2)
|
|
1788
|
+
throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);
|
|
1789
|
+
if (!Array.isArray(e))
|
|
1790
|
+
throw new Error("convertRadix: data should be array");
|
|
1791
|
+
if (!e.length)
|
|
1792
|
+
return [];
|
|
1793
|
+
let r = 0;
|
|
1794
|
+
const i = [], o = Array.from(e);
|
|
1795
|
+
for (o.forEach((s) => {
|
|
1796
|
+
if (je(s), s < 0 || s >= t)
|
|
1797
|
+
throw new Error(`Wrong integer: ${s}`);
|
|
1798
|
+
}); ; ) {
|
|
1799
|
+
let s = 0, c = !0;
|
|
1800
|
+
for (let a = r; a < o.length; a++) {
|
|
1801
|
+
const u = o[a], f = t * s + u;
|
|
1802
|
+
if (!Number.isSafeInteger(f) || t * s / t !== s || f - u !== t * s)
|
|
1803
|
+
throw new Error("convertRadix: carry overflow");
|
|
1804
|
+
if (s = f % n, o[a] = Math.floor(f / n), !Number.isSafeInteger(o[a]) || o[a] * n + s !== f)
|
|
1805
|
+
throw new Error("convertRadix: carry overflow");
|
|
1806
|
+
if (c)
|
|
1807
|
+
o[a] ? c = !1 : r = a;
|
|
1808
|
+
else continue;
|
|
1809
|
+
}
|
|
1810
|
+
if (i.push(s), c)
|
|
1811
|
+
break;
|
|
1812
|
+
}
|
|
1813
|
+
for (let s = 0; s < e.length - 1 && e[s] === 0; s++)
|
|
1814
|
+
i.push(0);
|
|
1815
|
+
return i.reverse();
|
|
1816
|
+
}
|
|
1817
|
+
const cr = (e, t) => t ? cr(t, e % t) : e, ct = (e, t) => e + (t - cr(e, t));
|
|
1818
|
+
function Dt(e, t, n, r) {
|
|
1819
|
+
if (!Array.isArray(e))
|
|
1820
|
+
throw new Error("convertRadix2: data should be array");
|
|
1821
|
+
if (t <= 0 || t > 32)
|
|
1822
|
+
throw new Error(`convertRadix2: wrong from=${t}`);
|
|
1823
|
+
if (n <= 0 || n > 32)
|
|
1824
|
+
throw new Error(`convertRadix2: wrong to=${n}`);
|
|
1825
|
+
if (ct(t, n) > 32)
|
|
1826
|
+
throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${ct(t, n)}`);
|
|
1827
|
+
let i = 0, o = 0;
|
|
1828
|
+
const s = 2 ** n - 1, c = [];
|
|
1829
|
+
for (const a of e) {
|
|
1830
|
+
if (je(a), a >= 2 ** t)
|
|
1831
|
+
throw new Error(`convertRadix2: invalid data word=${a} from=${t}`);
|
|
1832
|
+
if (i = i << t | a, o + t > 32)
|
|
1833
|
+
throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);
|
|
1834
|
+
for (o += t; o >= n; o -= n)
|
|
1835
|
+
c.push((i >> o - n & s) >>> 0);
|
|
1836
|
+
i &= 2 ** o - 1;
|
|
1837
|
+
}
|
|
1838
|
+
if (i = i << n - o & s, !r && o >= t)
|
|
1839
|
+
throw new Error("Excess padding");
|
|
1840
|
+
if (!r && i)
|
|
1841
|
+
throw new Error(`Non-zero padding: ${i}`);
|
|
1842
|
+
return r && o > 0 && c.push(i >>> 0), c;
|
|
1843
|
+
}
|
|
1844
|
+
function ho(e) {
|
|
1845
|
+
return je(e), {
|
|
1846
|
+
encode: (t) => {
|
|
1847
|
+
if (!(t instanceof Uint8Array))
|
|
1848
|
+
throw new Error("radix.encode input should be Uint8Array");
|
|
1849
|
+
return Un(Array.from(t), 2 ** 8, e);
|
|
1850
|
+
},
|
|
1851
|
+
decode: (t) => {
|
|
1852
|
+
if (!Array.isArray(t) || t.length && typeof t[0] != "number")
|
|
1853
|
+
throw new Error("radix.decode input should be array of strings");
|
|
1854
|
+
return Uint8Array.from(Un(t, e, 2 ** 8));
|
|
1855
|
+
}
|
|
1856
|
+
};
|
|
1857
|
+
}
|
|
1858
|
+
function Ce(e, t = !1) {
|
|
1859
|
+
if (je(e), e <= 0 || e > 32)
|
|
1860
|
+
throw new Error("radix2: bits should be in (0..32]");
|
|
1861
|
+
if (ct(8, e) > 32 || ct(e, 8) > 32)
|
|
1862
|
+
throw new Error("radix2: carry overflow");
|
|
1863
|
+
return {
|
|
1864
|
+
encode: (n) => {
|
|
1865
|
+
if (!(n instanceof Uint8Array))
|
|
1866
|
+
throw new Error("radix2.encode input should be Uint8Array");
|
|
1867
|
+
return Dt(Array.from(n), 8, e, !t);
|
|
1868
|
+
},
|
|
1869
|
+
decode: (n) => {
|
|
1870
|
+
if (!Array.isArray(n) || n.length && typeof n[0] != "number")
|
|
1871
|
+
throw new Error("radix2.decode input should be array of strings");
|
|
1872
|
+
return Uint8Array.from(Dt(n, e, 8, t));
|
|
1873
|
+
}
|
|
1874
|
+
};
|
|
1875
|
+
}
|
|
1876
|
+
function In(e) {
|
|
1877
|
+
if (typeof e != "function")
|
|
1878
|
+
throw new Error("unsafeWrapper fn should be function");
|
|
1879
|
+
return function(...t) {
|
|
1880
|
+
try {
|
|
1881
|
+
return e.apply(null, t);
|
|
1882
|
+
} catch {
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1886
|
+
const go = de(Ce(4), ge("0123456789ABCDEF"), pe("")), po = de(Ce(5), ge("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), yt(5), pe(""));
|
|
1887
|
+
de(Ce(5), ge("0123456789ABCDEFGHIJKLMNOPQRSTUV"), yt(5), pe(""));
|
|
1888
|
+
de(Ce(5), ge("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), pe(""), ar((e) => e.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
1889
|
+
const he = de(Ce(6), ge("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), yt(6), pe("")), yo = de(Ce(6), ge("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), yt(6), pe("")), en = (e) => de(ho(58), ge(e), pe("")), ut = en("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
1890
|
+
en("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
|
|
1891
|
+
en("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");
|
|
1892
|
+
const Kn = [0, 2, 3, 5, 6, 7, 9, 10, 11], wo = {
|
|
1893
|
+
encode(e) {
|
|
1894
|
+
let t = "";
|
|
1895
|
+
for (let n = 0; n < e.length; n += 8) {
|
|
1896
|
+
const r = e.subarray(n, n + 8);
|
|
1897
|
+
t += ut.encode(r).padStart(Kn[r.length], "1");
|
|
1898
|
+
}
|
|
1899
|
+
return t;
|
|
1900
|
+
},
|
|
1901
|
+
decode(e) {
|
|
1902
|
+
let t = [];
|
|
1903
|
+
for (let n = 0; n < e.length; n += 11) {
|
|
1904
|
+
const r = e.slice(n, n + 11), i = Kn.indexOf(r.length), o = ut.decode(r);
|
|
1905
|
+
for (let s = 0; s < o.length - i; s++)
|
|
1906
|
+
if (o[s] !== 0)
|
|
1907
|
+
throw new Error("base58xmr: wrong padding");
|
|
1908
|
+
t = t.concat(Array.from(o.slice(o.length - i)));
|
|
1909
|
+
}
|
|
1910
|
+
return Uint8Array.from(t);
|
|
1911
|
+
}
|
|
1912
|
+
}, jt = de(ge("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), pe("")), _n = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
1913
|
+
function Ze(e) {
|
|
1914
|
+
const t = e >> 25;
|
|
1915
|
+
let n = (e & 33554431) << 5;
|
|
1916
|
+
for (let r = 0; r < _n.length; r++)
|
|
1917
|
+
(t >> r & 1) === 1 && (n ^= _n[r]);
|
|
1918
|
+
return n;
|
|
1919
|
+
}
|
|
1920
|
+
function Ln(e, t, n = 1) {
|
|
1921
|
+
const r = e.length;
|
|
1922
|
+
let i = 1;
|
|
1923
|
+
for (let o = 0; o < r; o++) {
|
|
1924
|
+
const s = e.charCodeAt(o);
|
|
1925
|
+
if (s < 33 || s > 126)
|
|
1926
|
+
throw new Error(`Invalid prefix (${e})`);
|
|
1927
|
+
i = Ze(i) ^ s >> 5;
|
|
1928
|
+
}
|
|
1929
|
+
i = Ze(i);
|
|
1930
|
+
for (let o = 0; o < r; o++)
|
|
1931
|
+
i = Ze(i) ^ e.charCodeAt(o) & 31;
|
|
1932
|
+
for (let o of t)
|
|
1933
|
+
i = Ze(i) ^ o;
|
|
1934
|
+
for (let o = 0; o < 6; o++)
|
|
1935
|
+
i = Ze(i);
|
|
1936
|
+
return i ^= n, jt.encode(Dt([i % 2 ** 30], 30, 5, !1));
|
|
1937
|
+
}
|
|
1938
|
+
function ur(e) {
|
|
1939
|
+
const t = e === "bech32" ? 1 : 734539939, n = Ce(5), r = n.decode, i = n.encode, o = In(r);
|
|
1940
|
+
function s(f, l, d = 90) {
|
|
1941
|
+
if (typeof f != "string")
|
|
1942
|
+
throw new Error(`bech32.encode prefix should be string, not ${typeof f}`);
|
|
1943
|
+
if (!Array.isArray(l) || l.length && typeof l[0] != "number")
|
|
1944
|
+
throw new Error(`bech32.encode words should be array of numbers, not ${typeof l}`);
|
|
1945
|
+
const w = f.length + 7 + l.length;
|
|
1946
|
+
if (d !== !1 && w > d)
|
|
1947
|
+
throw new TypeError(`Length ${w} exceeds limit ${d}`);
|
|
1948
|
+
return f = f.toLowerCase(), `${f}1${jt.encode(l)}${Ln(f, l, t)}`;
|
|
1949
|
+
}
|
|
1950
|
+
function c(f, l = 90) {
|
|
1951
|
+
if (typeof f != "string")
|
|
1952
|
+
throw new Error(`bech32.decode input should be string, not ${typeof f}`);
|
|
1953
|
+
if (f.length < 8 || l !== !1 && f.length > l)
|
|
1954
|
+
throw new TypeError(`Wrong string length: ${f.length} (${f}). Expected (8..${l})`);
|
|
1955
|
+
const d = f.toLowerCase();
|
|
1956
|
+
if (f !== d && f !== f.toUpperCase())
|
|
1957
|
+
throw new Error("String must be lowercase or uppercase");
|
|
1958
|
+
f = d;
|
|
1959
|
+
const w = f.lastIndexOf("1");
|
|
1960
|
+
if (w === 0 || w === -1)
|
|
1961
|
+
throw new Error('Letter "1" must be present between prefix and data only');
|
|
1962
|
+
const y = f.slice(0, w), h = f.slice(w + 1);
|
|
1963
|
+
if (h.length < 6)
|
|
1964
|
+
throw new Error("Data must be at least 6 characters long");
|
|
1965
|
+
const g = jt.decode(h).slice(0, -6), p = Ln(y, g, t);
|
|
1966
|
+
if (!h.endsWith(p))
|
|
1967
|
+
throw new Error(`Invalid checksum in ${f}: expected "${p}"`);
|
|
1968
|
+
return { prefix: y, words: g };
|
|
1969
|
+
}
|
|
1970
|
+
const a = In(c);
|
|
1971
|
+
function u(f) {
|
|
1972
|
+
const { prefix: l, words: d } = c(f, !1);
|
|
1973
|
+
return { prefix: l, words: d, bytes: r(d) };
|
|
1974
|
+
}
|
|
1975
|
+
return { encode: s, decode: c, decodeToBytes: u, decodeUnsafe: a, fromWords: r, fromWordsUnsafe: o, toWords: i };
|
|
1976
|
+
}
|
|
1977
|
+
const De = ur("bech32");
|
|
1978
|
+
ur("bech32m");
|
|
1979
|
+
const bo = {
|
|
1980
|
+
encode: (e) => new TextDecoder().decode(e),
|
|
1981
|
+
decode: (e) => new TextEncoder().encode(e)
|
|
1982
|
+
}, vo = de(Ce(4), ge("0123456789abcdef"), pe(""), ar((e) => {
|
|
1983
|
+
if (typeof e != "string" || e.length % 2)
|
|
1984
|
+
throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);
|
|
1985
|
+
return e.toLowerCase();
|
|
1986
|
+
})), xo = {
|
|
1987
|
+
utf8: bo,
|
|
1988
|
+
hex: vo,
|
|
1989
|
+
base16: go,
|
|
1990
|
+
base32: po,
|
|
1991
|
+
base64: he,
|
|
1992
|
+
base64url: yo,
|
|
1993
|
+
base58: ut,
|
|
1994
|
+
base58xmr: wo
|
|
1995
|
+
};
|
|
1996
|
+
`${Object.keys(xo).join(", ")}`;
|
|
1997
|
+
function Lt(e) {
|
|
1998
|
+
if (!Number.isSafeInteger(e) || e < 0)
|
|
1999
|
+
throw new Error(`positive integer expected, not ${e}`);
|
|
2000
|
+
}
|
|
2001
|
+
function kn(e) {
|
|
2002
|
+
if (typeof e != "boolean")
|
|
2003
|
+
throw new Error(`boolean expected, not ${e}`);
|
|
2004
|
+
}
|
|
2005
|
+
function mo(e) {
|
|
2006
|
+
return e instanceof Uint8Array || e != null && typeof e == "object" && e.constructor.name === "Uint8Array";
|
|
2007
|
+
}
|
|
2008
|
+
function le(e, ...t) {
|
|
2009
|
+
if (!mo(e))
|
|
2010
|
+
throw new Error("Uint8Array expected");
|
|
2011
|
+
if (t.length > 0 && !t.includes(e.length))
|
|
2012
|
+
throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`);
|
|
2013
|
+
}
|
|
2014
|
+
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
|
|
2015
|
+
const Z = (e) => new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4)), Eo = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
2016
|
+
if (!Eo)
|
|
2017
|
+
throw new Error("Non little-endian hardware is not supported");
|
|
2018
|
+
function Ao(e, t) {
|
|
2019
|
+
if (t == null || typeof t != "object")
|
|
2020
|
+
throw new Error("options must be defined");
|
|
2021
|
+
return Object.assign(e, t);
|
|
2022
|
+
}
|
|
2023
|
+
function So(e, t) {
|
|
2024
|
+
if (e.length !== t.length)
|
|
2025
|
+
return !1;
|
|
2026
|
+
let n = 0;
|
|
2027
|
+
for (let r = 0; r < e.length; r++)
|
|
2028
|
+
n |= e[r] ^ t[r];
|
|
2029
|
+
return n === 0;
|
|
2030
|
+
}
|
|
2031
|
+
const Bo = /* @__NO_SIDE_EFFECTS__ */ (e, t) => (Object.assign(t, e), t), Se = 16, No = 283;
|
|
2032
|
+
function tn(e) {
|
|
2033
|
+
return e << 1 ^ No & -(e >> 7);
|
|
2034
|
+
}
|
|
2035
|
+
function Oe(e, t) {
|
|
2036
|
+
let n = 0;
|
|
2037
|
+
for (; t > 0; t >>= 1)
|
|
2038
|
+
n ^= e & -(t & 1), e = tn(e);
|
|
2039
|
+
return n;
|
|
2040
|
+
}
|
|
2041
|
+
const Vt = /* @__PURE__ */ (() => {
|
|
2042
|
+
let e = new Uint8Array(256);
|
|
2043
|
+
for (let n = 0, r = 1; n < 256; n++, r ^= tn(r))
|
|
2044
|
+
e[n] = r;
|
|
2045
|
+
const t = new Uint8Array(256);
|
|
2046
|
+
t[0] = 99;
|
|
2047
|
+
for (let n = 0; n < 255; n++) {
|
|
2048
|
+
let r = e[255 - n];
|
|
2049
|
+
r |= r << 8, t[e[n]] = (r ^ r >> 4 ^ r >> 5 ^ r >> 6 ^ r >> 7 ^ 99) & 255;
|
|
2050
|
+
}
|
|
2051
|
+
return t;
|
|
2052
|
+
})(), Co = /* @__PURE__ */ Vt.map((e, t) => Vt.indexOf(t)), Uo = (e) => e << 24 | e >>> 8, kt = (e) => e << 8 | e >>> 24;
|
|
2053
|
+
function lr(e, t) {
|
|
2054
|
+
if (e.length !== 256)
|
|
2055
|
+
throw new Error("Wrong sbox length");
|
|
2056
|
+
const n = new Uint32Array(256).map((u, f) => t(e[f])), r = n.map(kt), i = r.map(kt), o = i.map(kt), s = new Uint32Array(256 * 256), c = new Uint32Array(256 * 256), a = new Uint16Array(256 * 256);
|
|
2057
|
+
for (let u = 0; u < 256; u++)
|
|
2058
|
+
for (let f = 0; f < 256; f++) {
|
|
2059
|
+
const l = u * 256 + f;
|
|
2060
|
+
s[l] = n[u] ^ r[f], c[l] = i[u] ^ o[f], a[l] = e[u] << 8 | e[f];
|
|
2061
|
+
}
|
|
2062
|
+
return { sbox: e, sbox2: a, T0: n, T1: r, T2: i, T3: o, T01: s, T23: c };
|
|
2063
|
+
}
|
|
2064
|
+
const nn = /* @__PURE__ */ lr(Vt, (e) => Oe(e, 3) << 24 | e << 16 | e << 8 | Oe(e, 2)), fr = /* @__PURE__ */ lr(Co, (e) => Oe(e, 11) << 24 | Oe(e, 13) << 16 | Oe(e, 9) << 8 | Oe(e, 14)), Io = /* @__PURE__ */ (() => {
|
|
2065
|
+
const e = new Uint8Array(16);
|
|
2066
|
+
for (let t = 0, n = 1; t < 16; t++, n = tn(n))
|
|
2067
|
+
e[t] = n;
|
|
2068
|
+
return e;
|
|
2069
|
+
})();
|
|
2070
|
+
function hr(e) {
|
|
2071
|
+
le(e);
|
|
2072
|
+
const t = e.length;
|
|
2073
|
+
if (![16, 24, 32].includes(t))
|
|
2074
|
+
throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);
|
|
2075
|
+
const { sbox2: n } = nn, r = Z(e), i = r.length, o = (c) => oe(n, c, c, c, c), s = new Uint32Array(t + 28);
|
|
2076
|
+
s.set(r);
|
|
2077
|
+
for (let c = i; c < s.length; c++) {
|
|
2078
|
+
let a = s[c - 1];
|
|
2079
|
+
c % i === 0 ? a = o(Uo(a)) ^ Io[c / i - 1] : i > 6 && c % i === 4 && (a = o(a)), s[c] = s[c - i] ^ a;
|
|
2080
|
+
}
|
|
2081
|
+
return s;
|
|
2082
|
+
}
|
|
2083
|
+
function Ko(e) {
|
|
2084
|
+
const t = hr(e), n = t.slice(), r = t.length, { sbox2: i } = nn, { T0: o, T1: s, T2: c, T3: a } = fr;
|
|
2085
|
+
for (let u = 0; u < r; u += 4)
|
|
2086
|
+
for (let f = 0; f < 4; f++)
|
|
2087
|
+
n[u + f] = t[r - u - 4 + f];
|
|
2088
|
+
t.fill(0);
|
|
2089
|
+
for (let u = 4; u < r - 4; u++) {
|
|
2090
|
+
const f = n[u], l = oe(i, f, f, f, f);
|
|
2091
|
+
n[u] = o[l & 255] ^ s[l >>> 8 & 255] ^ c[l >>> 16 & 255] ^ a[l >>> 24];
|
|
2092
|
+
}
|
|
2093
|
+
return n;
|
|
2094
|
+
}
|
|
2095
|
+
function Ae(e, t, n, r, i, o) {
|
|
2096
|
+
return e[n << 8 & 65280 | r >>> 8 & 255] ^ t[i >>> 8 & 65280 | o >>> 24 & 255];
|
|
2097
|
+
}
|
|
2098
|
+
function oe(e, t, n, r, i) {
|
|
2099
|
+
return e[t & 255 | n & 65280] | e[r >>> 16 & 255 | i >>> 16 & 65280] << 16;
|
|
2100
|
+
}
|
|
2101
|
+
function Tn(e, t, n, r, i) {
|
|
2102
|
+
const { sbox2: o, T01: s, T23: c } = nn;
|
|
2103
|
+
let a = 0;
|
|
2104
|
+
t ^= e[a++], n ^= e[a++], r ^= e[a++], i ^= e[a++];
|
|
2105
|
+
const u = e.length / 4 - 2;
|
|
2106
|
+
for (let y = 0; y < u; y++) {
|
|
2107
|
+
const h = e[a++] ^ Ae(s, c, t, n, r, i), g = e[a++] ^ Ae(s, c, n, r, i, t), p = e[a++] ^ Ae(s, c, r, i, t, n), m = e[a++] ^ Ae(s, c, i, t, n, r);
|
|
2108
|
+
t = h, n = g, r = p, i = m;
|
|
2109
|
+
}
|
|
2110
|
+
const f = e[a++] ^ oe(o, t, n, r, i), l = e[a++] ^ oe(o, n, r, i, t), d = e[a++] ^ oe(o, r, i, t, n), w = e[a++] ^ oe(o, i, t, n, r);
|
|
2111
|
+
return { s0: f, s1: l, s2: d, s3: w };
|
|
2112
|
+
}
|
|
2113
|
+
function _o(e, t, n, r, i) {
|
|
2114
|
+
const { sbox2: o, T01: s, T23: c } = fr;
|
|
2115
|
+
let a = 0;
|
|
2116
|
+
t ^= e[a++], n ^= e[a++], r ^= e[a++], i ^= e[a++];
|
|
2117
|
+
const u = e.length / 4 - 2;
|
|
2118
|
+
for (let y = 0; y < u; y++) {
|
|
2119
|
+
const h = e[a++] ^ Ae(s, c, t, i, r, n), g = e[a++] ^ Ae(s, c, n, t, i, r), p = e[a++] ^ Ae(s, c, r, n, t, i), m = e[a++] ^ Ae(s, c, i, r, n, t);
|
|
2120
|
+
t = h, n = g, r = p, i = m;
|
|
2121
|
+
}
|
|
2122
|
+
const f = e[a++] ^ oe(o, t, i, r, n), l = e[a++] ^ oe(o, n, t, i, r), d = e[a++] ^ oe(o, r, n, t, i), w = e[a++] ^ oe(o, i, r, n, t);
|
|
2123
|
+
return { s0: f, s1: l, s2: d, s3: w };
|
|
2124
|
+
}
|
|
2125
|
+
function dr(e, t) {
|
|
2126
|
+
if (!t)
|
|
2127
|
+
return new Uint8Array(e);
|
|
2128
|
+
if (le(t), t.length < e)
|
|
2129
|
+
throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);
|
|
2130
|
+
return t;
|
|
2131
|
+
}
|
|
2132
|
+
function Lo(e) {
|
|
2133
|
+
if (le(e), e.length % Se !== 0)
|
|
2134
|
+
throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Se}`);
|
|
2135
|
+
}
|
|
2136
|
+
function ko(e, t, n) {
|
|
2137
|
+
let r = e.length;
|
|
2138
|
+
const i = r % Se;
|
|
2139
|
+
if (!t && i !== 0)
|
|
2140
|
+
throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");
|
|
2141
|
+
const o = Z(e);
|
|
2142
|
+
if (t) {
|
|
2143
|
+
let a = Se - i;
|
|
2144
|
+
a || (a = Se), r = r + a;
|
|
2145
|
+
}
|
|
2146
|
+
const s = dr(r, n), c = Z(s);
|
|
2147
|
+
return { b: o, o: c, out: s };
|
|
2148
|
+
}
|
|
2149
|
+
function To(e, t) {
|
|
2150
|
+
if (!t)
|
|
2151
|
+
return e;
|
|
2152
|
+
const n = e.length;
|
|
2153
|
+
if (!n)
|
|
2154
|
+
throw new Error("aes/pcks5: empty ciphertext not allowed");
|
|
2155
|
+
const r = e[n - 1];
|
|
2156
|
+
if (r <= 0 || r > 16)
|
|
2157
|
+
throw new Error(`aes/pcks5: wrong padding byte: ${r}`);
|
|
2158
|
+
const i = e.subarray(0, -r);
|
|
2159
|
+
for (let o = 0; o < r; o++)
|
|
2160
|
+
if (e[n - o - 1] !== r)
|
|
2161
|
+
throw new Error("aes/pcks5: wrong padding");
|
|
2162
|
+
return i;
|
|
2163
|
+
}
|
|
2164
|
+
function $o(e) {
|
|
2165
|
+
const t = new Uint8Array(16), n = Z(t);
|
|
2166
|
+
t.set(e);
|
|
2167
|
+
const r = Se - e.length;
|
|
2168
|
+
for (let i = Se - r; i < Se; i++)
|
|
2169
|
+
t[i] = r;
|
|
2170
|
+
return n;
|
|
2171
|
+
}
|
|
2172
|
+
const gr = /* @__PURE__ */ Bo({ blockSize: 16, nonceLength: 16 }, function(t, n, r = {}) {
|
|
2173
|
+
le(t), le(n, 16);
|
|
2174
|
+
const i = !r.disablePadding;
|
|
2175
|
+
return {
|
|
2176
|
+
encrypt: (o, s) => {
|
|
2177
|
+
const c = hr(t), { b: a, o: u, out: f } = ko(o, i, s), l = Z(n);
|
|
2178
|
+
let d = l[0], w = l[1], y = l[2], h = l[3], g = 0;
|
|
2179
|
+
for (; g + 4 <= a.length; )
|
|
2180
|
+
d ^= a[g + 0], w ^= a[g + 1], y ^= a[g + 2], h ^= a[g + 3], { s0: d, s1: w, s2: y, s3: h } = Tn(c, d, w, y, h), u[g++] = d, u[g++] = w, u[g++] = y, u[g++] = h;
|
|
2181
|
+
if (i) {
|
|
2182
|
+
const p = $o(o.subarray(g * 4));
|
|
2183
|
+
d ^= p[0], w ^= p[1], y ^= p[2], h ^= p[3], { s0: d, s1: w, s2: y, s3: h } = Tn(c, d, w, y, h), u[g++] = d, u[g++] = w, u[g++] = y, u[g++] = h;
|
|
2184
|
+
}
|
|
2185
|
+
return c.fill(0), f;
|
|
2186
|
+
},
|
|
2187
|
+
decrypt: (o, s) => {
|
|
2188
|
+
Lo(o);
|
|
2189
|
+
const c = Ko(t), a = Z(n), u = dr(o.length, s), f = Z(o), l = Z(u);
|
|
2190
|
+
let d = a[0], w = a[1], y = a[2], h = a[3];
|
|
2191
|
+
for (let g = 0; g + 4 <= f.length; ) {
|
|
2192
|
+
const p = d, m = w, B = y, _ = h;
|
|
2193
|
+
d = f[g + 0], w = f[g + 1], y = f[g + 2], h = f[g + 3];
|
|
2194
|
+
const { s0: U, s1: x, s2: E, s3: A } = _o(c, d, w, y, h);
|
|
2195
|
+
l[g++] = U ^ p, l[g++] = x ^ m, l[g++] = E ^ B, l[g++] = A ^ _;
|
|
2196
|
+
}
|
|
2197
|
+
return c.fill(0), To(u, i);
|
|
2198
|
+
}
|
|
2199
|
+
};
|
|
2200
|
+
}), pr = (e) => Uint8Array.from(e.split("").map((t) => t.charCodeAt(0))), Ro = pr("expand 16-byte k"), Po = pr("expand 32-byte k"), Oo = Z(Ro), yr = Z(Po);
|
|
2201
|
+
yr.slice();
|
|
2202
|
+
function k(e, t) {
|
|
2203
|
+
return e << t | e >>> 32 - t;
|
|
2204
|
+
}
|
|
2205
|
+
function zt(e) {
|
|
2206
|
+
return e.byteOffset % 4 === 0;
|
|
2207
|
+
}
|
|
2208
|
+
const Qe = 64, Ho = 16, wr = 2 ** 32 - 1, $n = new Uint32Array();
|
|
2209
|
+
function Mo(e, t, n, r, i, o, s, c) {
|
|
2210
|
+
const a = i.length, u = new Uint8Array(Qe), f = Z(u), l = zt(i) && zt(o), d = l ? Z(i) : $n, w = l ? Z(o) : $n;
|
|
2211
|
+
for (let y = 0; y < a; s++) {
|
|
2212
|
+
if (e(t, n, r, f, s, c), s >= wr)
|
|
2213
|
+
throw new Error("arx: counter overflow");
|
|
2214
|
+
const h = Math.min(Qe, a - y);
|
|
2215
|
+
if (l && h === Qe) {
|
|
2216
|
+
const g = y / 4;
|
|
2217
|
+
if (y % 4 !== 0)
|
|
2218
|
+
throw new Error("arx: invalid block position");
|
|
2219
|
+
for (let p = 0, m; p < Ho; p++)
|
|
2220
|
+
m = g + p, w[m] = d[m] ^ f[p];
|
|
2221
|
+
y += Qe;
|
|
2222
|
+
continue;
|
|
2223
|
+
}
|
|
2224
|
+
for (let g = 0, p; g < h; g++)
|
|
2225
|
+
p = y + g, o[p] = i[p] ^ u[g];
|
|
2226
|
+
y += h;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
function qo(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
|
+
if (typeof e != "function")
|
|
2232
|
+
throw new Error("core must be a function");
|
|
2233
|
+
return Lt(i), Lt(s), kn(o), kn(n), (c, a, u, f, l = 0) => {
|
|
2234
|
+
le(c), le(a), le(u);
|
|
2235
|
+
const d = u.length;
|
|
2236
|
+
if (f || (f = new Uint8Array(d)), le(f), Lt(l), l < 0 || l >= wr)
|
|
2237
|
+
throw new Error("arx: counter overflow");
|
|
2238
|
+
if (f.length < d)
|
|
2239
|
+
throw new Error(`arx: output (${f.length}) is shorter than data (${d})`);
|
|
2240
|
+
const w = [];
|
|
2241
|
+
let y = c.length, h, g;
|
|
2242
|
+
if (y === 32)
|
|
2243
|
+
h = c.slice(), w.push(h), g = yr;
|
|
2244
|
+
else if (y === 16 && n)
|
|
2245
|
+
h = new Uint8Array(32), h.set(c), h.set(c, 16), g = Oo, w.push(h);
|
|
2246
|
+
else
|
|
2247
|
+
throw new Error(`arx: invalid 32-byte key, got length=${y}`);
|
|
2248
|
+
zt(a) || (a = a.slice(), w.push(a));
|
|
2249
|
+
const p = Z(h);
|
|
2250
|
+
if (r) {
|
|
2251
|
+
if (a.length !== 24)
|
|
2252
|
+
throw new Error("arx: extended nonce must be 24 bytes");
|
|
2253
|
+
r(g, p, Z(a.subarray(0, 16)), p), a = a.subarray(16);
|
|
2254
|
+
}
|
|
2255
|
+
const m = 16 - i;
|
|
2256
|
+
if (m !== a.length)
|
|
2257
|
+
throw new Error(`arx: nonce must be ${m} or 16 bytes`);
|
|
2258
|
+
if (m !== 12) {
|
|
2259
|
+
const _ = new Uint8Array(12);
|
|
2260
|
+
_.set(a, o ? 0 : 12 - a.length), a = _, w.push(a);
|
|
2261
|
+
}
|
|
2262
|
+
const B = Z(a);
|
|
2263
|
+
for (Mo(e, g, p, B, u, f, l, s); w.length > 0; )
|
|
2264
|
+
w.pop().fill(0);
|
|
2265
|
+
return f;
|
|
2266
|
+
};
|
|
2267
|
+
}
|
|
2268
|
+
function Do(e, t, n, r, i, o = 20) {
|
|
2269
|
+
let s = e[0], c = e[1], a = e[2], u = e[3], f = t[0], l = t[1], d = t[2], w = t[3], y = t[4], h = t[5], g = t[6], p = t[7], m = i, B = n[0], _ = n[1], U = n[2], x = s, E = c, A = a, O = u, K = f, N = l, $ = d, R = w, H = y, b = h, v = g, S = p, I = m, C = B, L = _, P = U;
|
|
2270
|
+
for (let Y = 0; Y < o; Y += 2)
|
|
2271
|
+
x = x + K | 0, I = k(I ^ x, 16), H = H + I | 0, K = k(K ^ H, 12), x = x + K | 0, I = k(I ^ x, 8), H = H + I | 0, K = k(K ^ H, 7), E = E + N | 0, C = k(C ^ E, 16), b = b + C | 0, N = k(N ^ b, 12), E = E + N | 0, C = k(C ^ E, 8), b = b + C | 0, N = k(N ^ b, 7), A = A + $ | 0, L = k(L ^ A, 16), v = v + L | 0, $ = k($ ^ v, 12), A = A + $ | 0, L = k(L ^ A, 8), v = v + L | 0, $ = k($ ^ v, 7), O = O + R | 0, P = k(P ^ O, 16), S = S + P | 0, R = k(R ^ S, 12), O = O + R | 0, P = k(P ^ O, 8), S = S + P | 0, R = k(R ^ S, 7), x = x + N | 0, P = k(P ^ x, 16), v = v + P | 0, N = k(N ^ v, 12), x = x + N | 0, P = k(P ^ x, 8), v = v + P | 0, N = k(N ^ v, 7), E = E + $ | 0, I = k(I ^ E, 16), S = S + I | 0, $ = k($ ^ S, 12), E = E + $ | 0, I = k(I ^ E, 8), S = S + I | 0, $ = k($ ^ S, 7), A = A + R | 0, C = k(C ^ A, 16), H = H + C | 0, R = k(R ^ H, 12), A = A + R | 0, C = k(C ^ A, 8), H = H + C | 0, R = k(R ^ H, 7), O = O + K | 0, L = k(L ^ O, 16), b = b + L | 0, K = k(K ^ b, 12), O = O + K | 0, L = k(L ^ O, 8), b = b + L | 0, K = k(K ^ b, 7);
|
|
2272
|
+
let T = 0;
|
|
2273
|
+
r[T++] = s + x | 0, r[T++] = c + E | 0, r[T++] = a + A | 0, r[T++] = u + O | 0, r[T++] = f + K | 0, r[T++] = l + N | 0, r[T++] = d + $ | 0, r[T++] = w + R | 0, r[T++] = y + H | 0, r[T++] = h + b | 0, r[T++] = g + v | 0, r[T++] = p + S | 0, r[T++] = m + I | 0, r[T++] = B + C | 0, r[T++] = _ + L | 0, r[T++] = U + P | 0;
|
|
2274
|
+
}
|
|
2275
|
+
const br = /* @__PURE__ */ qo(Do, {
|
|
2276
|
+
counterRight: !1,
|
|
2277
|
+
counterLength: 4,
|
|
2278
|
+
allowShortKeys: !1
|
|
2279
|
+
});
|
|
2280
|
+
class vr extends nr {
|
|
2281
|
+
constructor(t, n) {
|
|
2282
|
+
super(), this.finished = !1, this.destroyed = !1, ie.hash(t);
|
|
2283
|
+
const r = Je(n);
|
|
2284
|
+
if (this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
2285
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
2286
|
+
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
2287
|
+
const i = this.blockLen, o = new Uint8Array(i);
|
|
2288
|
+
o.set(r.length > i ? t.create().update(r).digest() : r);
|
|
2289
|
+
for (let s = 0; s < o.length; s++)
|
|
2290
|
+
o[s] ^= 54;
|
|
2291
|
+
this.iHash.update(o), this.oHash = t.create();
|
|
2292
|
+
for (let s = 0; s < o.length; s++)
|
|
2293
|
+
o[s] ^= 106;
|
|
2294
|
+
this.oHash.update(o), o.fill(0);
|
|
2295
|
+
}
|
|
2296
|
+
update(t) {
|
|
2297
|
+
return ie.exists(this), this.iHash.update(t), this;
|
|
2298
|
+
}
|
|
2299
|
+
digestInto(t) {
|
|
2300
|
+
ie.exists(this), ie.bytes(t, this.outputLen), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
2301
|
+
}
|
|
2302
|
+
digest() {
|
|
2303
|
+
const t = new Uint8Array(this.oHash.outputLen);
|
|
2304
|
+
return this.digestInto(t), t;
|
|
2305
|
+
}
|
|
2306
|
+
_cloneInto(t) {
|
|
2307
|
+
t || (t = Object.create(Object.getPrototypeOf(this), {}));
|
|
2308
|
+
const { oHash: n, iHash: r, finished: i, destroyed: o, blockLen: s, outputLen: c } = this;
|
|
2309
|
+
return t = t, t.finished = i, t.destroyed = o, t.blockLen = s, t.outputLen = c, t.oHash = n._cloneInto(t.oHash), t.iHash = r._cloneInto(t.iHash), t;
|
|
2310
|
+
}
|
|
2311
|
+
destroy() {
|
|
2312
|
+
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
const wt = (e, t, n) => new vr(e, t).update(n).digest();
|
|
2316
|
+
wt.create = (e, t) => new vr(e, t);
|
|
2317
|
+
function rn(e, t, n) {
|
|
2318
|
+
return ie.hash(e), n === void 0 && (n = new Uint8Array(e.outputLen)), wt(e, Je(n), Je(t));
|
|
2319
|
+
}
|
|
2320
|
+
const Tt = new Uint8Array([0]), Rn = new Uint8Array();
|
|
2321
|
+
function xr(e, t, n, r = 32) {
|
|
2322
|
+
if (ie.hash(e), ie.number(r), r > 255 * e.outputLen)
|
|
2323
|
+
throw new Error("Length should be <= 255*HashLen");
|
|
2324
|
+
const i = Math.ceil(r / e.outputLen);
|
|
2325
|
+
n === void 0 && (n = Rn);
|
|
2326
|
+
const o = new Uint8Array(i * e.outputLen), s = wt.create(e, t), c = s._cloneInto(), a = new Uint8Array(s.outputLen);
|
|
2327
|
+
for (let u = 0; u < i; u++)
|
|
2328
|
+
Tt[0] = u + 1, c.update(u === 0 ? Rn : a).update(n).update(Tt).digestInto(a), o.set(a, e.outputLen * u), s._cloneInto(c);
|
|
2329
|
+
return s.destroy(), c.destroy(), a.fill(0), Tt.fill(0), o.slice(0, r);
|
|
2330
|
+
}
|
|
2331
|
+
var jo = Object.defineProperty, q = (e, t) => {
|
|
2332
|
+
for (var n in t)
|
|
2333
|
+
jo(e, n, { get: t[n], enumerable: !0 });
|
|
2334
|
+
}, Pe = Symbol("verified"), Vo = (e) => e instanceof Object;
|
|
2335
|
+
function mr(e) {
|
|
2336
|
+
if (!Vo(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
|
+
return !1;
|
|
2338
|
+
for (let t = 0; t < e.tags.length; t++) {
|
|
2339
|
+
let n = e.tags[t];
|
|
2340
|
+
if (!Array.isArray(n))
|
|
2341
|
+
return !1;
|
|
2342
|
+
for (let r = 0; r < n.length; r++)
|
|
2343
|
+
if (typeof n[r] == "object")
|
|
2344
|
+
return !1;
|
|
2345
|
+
}
|
|
2346
|
+
return !0;
|
|
2347
|
+
}
|
|
2348
|
+
var zo = {};
|
|
2349
|
+
q(zo, {
|
|
2350
|
+
Queue: () => Go,
|
|
2351
|
+
QueueNode: () => Er,
|
|
2352
|
+
binarySearch: () => on,
|
|
2353
|
+
insertEventIntoAscendingList: () => Wo,
|
|
2354
|
+
insertEventIntoDescendingList: () => Fo,
|
|
2355
|
+
normalizeURL: () => Zo,
|
|
2356
|
+
utf8Decoder: () => re,
|
|
2357
|
+
utf8Encoder: () => ee
|
|
2358
|
+
});
|
|
2359
|
+
var re = new TextDecoder("utf-8"), ee = new TextEncoder();
|
|
2360
|
+
function Zo(e) {
|
|
2361
|
+
e.indexOf("://") === -1 && (e = "wss://" + e);
|
|
2362
|
+
let t = new URL(e);
|
|
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
|
+
}
|
|
2365
|
+
function Fo(e, t) {
|
|
2366
|
+
const [n, r] = on(e, (i) => t.id === i.id ? 0 : t.created_at === i.created_at ? -1 : i.created_at - t.created_at);
|
|
2367
|
+
return r || e.splice(n, 0, t), e;
|
|
2368
|
+
}
|
|
2369
|
+
function Wo(e, t) {
|
|
2370
|
+
const [n, r] = on(e, (i) => t.id === i.id ? 0 : t.created_at === i.created_at ? -1 : t.created_at - i.created_at);
|
|
2371
|
+
return r || e.splice(n, 0, t), e;
|
|
2372
|
+
}
|
|
2373
|
+
function on(e, t) {
|
|
2374
|
+
let n = 0, r = e.length - 1;
|
|
2375
|
+
for (; n <= r; ) {
|
|
2376
|
+
const i = Math.floor((n + r) / 2), o = t(e[i]);
|
|
2377
|
+
if (o === 0)
|
|
2378
|
+
return [i, !0];
|
|
2379
|
+
o < 0 ? r = i - 1 : n = i + 1;
|
|
2380
|
+
}
|
|
2381
|
+
return [n, !1];
|
|
2382
|
+
}
|
|
2383
|
+
var Er = class {
|
|
2384
|
+
constructor(e) {
|
|
2385
|
+
Q(this, "value");
|
|
2386
|
+
Q(this, "next", null);
|
|
2387
|
+
Q(this, "prev", null);
|
|
2388
|
+
this.value = e;
|
|
2389
|
+
}
|
|
2390
|
+
}, Go = class {
|
|
2391
|
+
constructor() {
|
|
2392
|
+
Q(this, "first");
|
|
2393
|
+
Q(this, "last");
|
|
2394
|
+
this.first = null, this.last = null;
|
|
2395
|
+
}
|
|
2396
|
+
enqueue(e) {
|
|
2397
|
+
const t = new Er(e);
|
|
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
|
+
}
|
|
2400
|
+
dequeue() {
|
|
2401
|
+
if (!this.first)
|
|
2402
|
+
return null;
|
|
2403
|
+
if (this.first === this.last) {
|
|
2404
|
+
const t = this.first;
|
|
2405
|
+
return this.first = null, this.last = null, t.value;
|
|
2406
|
+
}
|
|
2407
|
+
const e = this.first;
|
|
2408
|
+
return this.first = e.next, e.value;
|
|
2409
|
+
}
|
|
2410
|
+
}, Jo = class {
|
|
2411
|
+
generateSecretKey() {
|
|
2412
|
+
return ze.utils.randomPrivateKey();
|
|
2413
|
+
}
|
|
2414
|
+
getPublicKey(e) {
|
|
2415
|
+
return D(ze.getPublicKey(e));
|
|
2416
|
+
}
|
|
2417
|
+
finalizeEvent(e, t) {
|
|
2418
|
+
const n = e;
|
|
2419
|
+
return n.pubkey = D(ze.getPublicKey(t)), n.id = nt(n), n.sig = D(ze.sign(nt(n), t)), n[Pe] = !0, n;
|
|
2420
|
+
}
|
|
2421
|
+
verifyEvent(e) {
|
|
2422
|
+
if (typeof e[Pe] == "boolean")
|
|
2423
|
+
return e[Pe];
|
|
2424
|
+
const t = nt(e);
|
|
2425
|
+
if (t !== e.id)
|
|
2426
|
+
return e[Pe] = !1, !1;
|
|
2427
|
+
try {
|
|
2428
|
+
const n = ze.verify(e.sig, t, e.pubkey);
|
|
2429
|
+
return e[Pe] = n, n;
|
|
2430
|
+
} catch {
|
|
2431
|
+
return e[Pe] = !1, !1;
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
};
|
|
2435
|
+
function Yo(e) {
|
|
2436
|
+
if (!mr(e))
|
|
2437
|
+
throw new Error("can't serialize event with wrong or missing properties");
|
|
2438
|
+
return JSON.stringify([0, e.pubkey, e.created_at, e.kind, e.tags, e.content]);
|
|
2439
|
+
}
|
|
2440
|
+
function nt(e) {
|
|
2441
|
+
let t = Ne(ee.encode(Yo(e)));
|
|
2442
|
+
return D(t);
|
|
2443
|
+
}
|
|
2444
|
+
var bt = new Jo(), He = bt.generateSecretKey, Ee = bt.getPublicKey, se = bt.finalizeEvent, sn = bt.verifyEvent, Xo = {};
|
|
2445
|
+
q(Xo, {
|
|
2446
|
+
Application: () => Xs,
|
|
2447
|
+
BadgeAward: () => as,
|
|
2448
|
+
BadgeDefinition: () => zs,
|
|
2449
|
+
BlockedRelaysList: () => Ks,
|
|
2450
|
+
BookmarkList: () => Cs,
|
|
2451
|
+
Bookmarksets: () => Ds,
|
|
2452
|
+
Calendar: () => oa,
|
|
2453
|
+
CalendarEventRSVP: () => sa,
|
|
2454
|
+
ChannelCreation: () => Cr,
|
|
2455
|
+
ChannelHideMessage: () => Kr,
|
|
2456
|
+
ChannelMessage: () => Ir,
|
|
2457
|
+
ChannelMetadata: () => Ur,
|
|
2458
|
+
ChannelMuteUser: () => _r,
|
|
2459
|
+
ClassifiedListing: () => ta,
|
|
2460
|
+
ClientAuth: () => Lr,
|
|
2461
|
+
CommunitiesList: () => Us,
|
|
2462
|
+
CommunityDefinition: () => ua,
|
|
2463
|
+
CommunityPostApproval: () => ys,
|
|
2464
|
+
Contacts: () => rs,
|
|
2465
|
+
CreateOrUpdateProduct: () => Ws,
|
|
2466
|
+
CreateOrUpdateStall: () => Fs,
|
|
2467
|
+
Curationsets: () => js,
|
|
2468
|
+
Date: () => ra,
|
|
2469
|
+
DraftClassifiedListing: () => na,
|
|
2470
|
+
DraftLong: () => Js,
|
|
2471
|
+
Emojisets: () => Ys,
|
|
2472
|
+
EncryptedDirectMessage: () => is,
|
|
2473
|
+
EncryptedDirectMessages: () => os,
|
|
2474
|
+
EventDeletion: () => ss,
|
|
2475
|
+
FileMetadata: () => ls,
|
|
2476
|
+
FileServerPreference: () => Ts,
|
|
2477
|
+
Followsets: () => Hs,
|
|
2478
|
+
GenericRepost: () => cs,
|
|
2479
|
+
Genericlists: () => Ms,
|
|
2480
|
+
HTTPAuth: () => un,
|
|
2481
|
+
Handlerinformation: () => ca,
|
|
2482
|
+
Handlerrecommendation: () => aa,
|
|
2483
|
+
Highlights: () => As,
|
|
2484
|
+
InterestsList: () => Ls,
|
|
2485
|
+
Interestsets: () => Zs,
|
|
2486
|
+
JobFeedback: () => vs,
|
|
2487
|
+
JobRequest: () => ws,
|
|
2488
|
+
JobResult: () => bs,
|
|
2489
|
+
Label: () => ps,
|
|
2490
|
+
LightningPubRPC: () => Rs,
|
|
2491
|
+
LiveChatMessage: () => fs,
|
|
2492
|
+
LiveEvent: () => Qs,
|
|
2493
|
+
LongFormArticle: () => Gs,
|
|
2494
|
+
Metadata: () => es,
|
|
2495
|
+
Mutelist: () => Ss,
|
|
2496
|
+
NWCWalletInfo: () => $s,
|
|
2497
|
+
NWCWalletRequest: () => kr,
|
|
2498
|
+
NWCWalletResponse: () => Ps,
|
|
2499
|
+
NostrConnect: () => Os,
|
|
2500
|
+
OpenTimestamps: () => us,
|
|
2501
|
+
Pinlist: () => Bs,
|
|
2502
|
+
ProblemTracker: () => hs,
|
|
2503
|
+
ProfileBadges: () => Vs,
|
|
2504
|
+
PublicChatsList: () => Is,
|
|
2505
|
+
Reaction: () => cn,
|
|
2506
|
+
RecommendRelay: () => ns,
|
|
2507
|
+
RelayList: () => Ns,
|
|
2508
|
+
Relaysets: () => qs,
|
|
2509
|
+
Report: () => ds,
|
|
2510
|
+
Reporting: () => gs,
|
|
2511
|
+
Repost: () => an,
|
|
2512
|
+
SearchRelaysList: () => _s,
|
|
2513
|
+
ShortTextNote: () => ts,
|
|
2514
|
+
Time: () => ia,
|
|
2515
|
+
UserEmojiList: () => ks,
|
|
2516
|
+
UserStatuses: () => ea,
|
|
2517
|
+
Zap: () => Es,
|
|
2518
|
+
ZapGoal: () => xs,
|
|
2519
|
+
ZapRequest: () => ms,
|
|
2520
|
+
classifyKind: () => Qo,
|
|
2521
|
+
isEphemeralKind: () => Br,
|
|
2522
|
+
isParameterizedReplaceableKind: () => Nr,
|
|
2523
|
+
isRegularKind: () => Ar,
|
|
2524
|
+
isReplaceableKind: () => Sr
|
|
2525
|
+
});
|
|
2526
|
+
function Ar(e) {
|
|
2527
|
+
return 1e3 <= e && e < 1e4 || [1, 2, 4, 5, 6, 7, 8, 16, 40, 41, 42, 43, 44].includes(e);
|
|
2528
|
+
}
|
|
2529
|
+
function Sr(e) {
|
|
2530
|
+
return [0, 3].includes(e) || 1e4 <= e && e < 2e4;
|
|
2531
|
+
}
|
|
2532
|
+
function Br(e) {
|
|
2533
|
+
return 2e4 <= e && e < 3e4;
|
|
2534
|
+
}
|
|
2535
|
+
function Nr(e) {
|
|
2536
|
+
return 3e4 <= e && e < 4e4;
|
|
2537
|
+
}
|
|
2538
|
+
function Qo(e) {
|
|
2539
|
+
return Ar(e) ? "regular" : Sr(e) ? "replaceable" : Br(e) ? "ephemeral" : Nr(e) ? "parameterized" : "unknown";
|
|
2540
|
+
}
|
|
2541
|
+
var es = 0, ts = 1, ns = 2, rs = 3, is = 4, os = 4, ss = 5, an = 6, cn = 7, as = 8, cs = 16, Cr = 40, Ur = 41, Ir = 42, Kr = 43, _r = 44, us = 1040, ls = 1063, fs = 1311, hs = 1971, ds = 1984, gs = 1984, ps = 1985, ys = 4550, ws = 5999, bs = 6999, vs = 7e3, xs = 9041, ms = 9734, Es = 9735, As = 9802, Ss = 1e4, Bs = 10001, Ns = 10002, Cs = 10003, Us = 10004, Is = 10005, Ks = 10006, _s = 10007, Ls = 10015, ks = 10030, Ts = 10096, $s = 13194, Rs = 21e3, Lr = 22242, kr = 23194, Ps = 23195, Os = 24133, un = 27235, Hs = 3e4, Ms = 30001, qs = 30002, Ds = 30003, js = 30004, Vs = 30008, zs = 30009, Zs = 30015, Fs = 30017, Ws = 30018, Gs = 30023, Js = 30024, Ys = 30030, Xs = 30078, Qs = 30311, ea = 30315, ta = 30402, na = 30403, ra = 31922, ia = 31923, oa = 31924, sa = 31925, aa = 31989, ca = 31990, ua = 34550, la = {};
|
|
2542
|
+
q(la, {
|
|
2543
|
+
getHex64: () => ln,
|
|
2544
|
+
getInt: () => Tr,
|
|
2545
|
+
getSubscriptionId: () => fa,
|
|
2546
|
+
matchEventId: () => ha,
|
|
2547
|
+
matchEventKind: () => ga,
|
|
2548
|
+
matchEventPubkey: () => da
|
|
2549
|
+
});
|
|
2550
|
+
function ln(e, t) {
|
|
2551
|
+
let n = t.length + 3, r = e.indexOf(`"${t}":`) + n, i = e.slice(r).indexOf('"') + r + 1;
|
|
2552
|
+
return e.slice(i, i + 64);
|
|
2553
|
+
}
|
|
2554
|
+
function Tr(e, t) {
|
|
2555
|
+
let n = t.length, r = e.indexOf(`"${t}":`) + n + 3, i = e.slice(r), o = Math.min(i.indexOf(","), i.indexOf("}"));
|
|
2556
|
+
return parseInt(i.slice(0, o), 10);
|
|
2557
|
+
}
|
|
2558
|
+
function fa(e) {
|
|
2559
|
+
let t = e.slice(0, 22).indexOf('"EVENT"');
|
|
2560
|
+
if (t === -1)
|
|
2561
|
+
return null;
|
|
2562
|
+
let n = e.slice(t + 7 + 1).indexOf('"');
|
|
2563
|
+
if (n === -1)
|
|
2564
|
+
return null;
|
|
2565
|
+
let r = t + 7 + 1 + n, i = e.slice(r + 1, 80).indexOf('"');
|
|
2566
|
+
if (i === -1)
|
|
2567
|
+
return null;
|
|
2568
|
+
let o = r + 1 + i;
|
|
2569
|
+
return e.slice(r + 1, o);
|
|
2570
|
+
}
|
|
2571
|
+
function ha(e, t) {
|
|
2572
|
+
return t === ln(e, "id");
|
|
2573
|
+
}
|
|
2574
|
+
function da(e, t) {
|
|
2575
|
+
return t === ln(e, "pubkey");
|
|
2576
|
+
}
|
|
2577
|
+
function ga(e, t) {
|
|
2578
|
+
return t === Tr(e, "kind");
|
|
2579
|
+
}
|
|
2580
|
+
var pa = {};
|
|
2581
|
+
q(pa, {
|
|
2582
|
+
makeAuthEvent: () => ya
|
|
2583
|
+
});
|
|
2584
|
+
function ya(e, t) {
|
|
2585
|
+
return {
|
|
2586
|
+
kind: Lr,
|
|
2587
|
+
created_at: Math.floor(Date.now() / 1e3),
|
|
2588
|
+
tags: [
|
|
2589
|
+
["relay", e],
|
|
2590
|
+
["challenge", t]
|
|
2591
|
+
],
|
|
2592
|
+
content: ""
|
|
2593
|
+
};
|
|
2594
|
+
}
|
|
2595
|
+
var wa;
|
|
2596
|
+
try {
|
|
2597
|
+
wa = WebSocket;
|
|
2598
|
+
} catch {
|
|
2599
|
+
}
|
|
2600
|
+
var ba;
|
|
2601
|
+
try {
|
|
2602
|
+
ba = WebSocket;
|
|
2603
|
+
} catch {
|
|
2604
|
+
}
|
|
2605
|
+
var Fe = {};
|
|
2606
|
+
q(Fe, {
|
|
2607
|
+
BECH32_REGEX: () => $r,
|
|
2608
|
+
Bech32MaxSize: () => fn,
|
|
2609
|
+
decode: () => vt,
|
|
2610
|
+
encodeBytes: () => xt,
|
|
2611
|
+
naddrEncode: () => Ba,
|
|
2612
|
+
neventEncode: () => Sa,
|
|
2613
|
+
noteEncode: () => Ea,
|
|
2614
|
+
nprofileEncode: () => Aa,
|
|
2615
|
+
npubEncode: () => ma,
|
|
2616
|
+
nrelayEncode: () => Na,
|
|
2617
|
+
nsecEncode: () => xa
|
|
2618
|
+
});
|
|
2619
|
+
var fn = 5e3, $r = /[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;
|
|
2620
|
+
function va(e) {
|
|
2621
|
+
const t = new Uint8Array(4);
|
|
2622
|
+
return t[0] = e >> 24 & 255, t[1] = e >> 16 & 255, t[2] = e >> 8 & 255, t[3] = e & 255, t;
|
|
2623
|
+
}
|
|
2624
|
+
function vt(e) {
|
|
2625
|
+
var i, o, s, c, a, u, f, l;
|
|
2626
|
+
let { prefix: t, words: n } = De.decode(e, fn), r = new Uint8Array(De.fromWords(n));
|
|
2627
|
+
switch (t) {
|
|
2628
|
+
case "nprofile": {
|
|
2629
|
+
let d = et(r);
|
|
2630
|
+
if (!((i = d[0]) != null && i[0]))
|
|
2631
|
+
throw new Error("missing TLV 0 for nprofile");
|
|
2632
|
+
if (d[0][0].length !== 32)
|
|
2633
|
+
throw new Error("TLV 0 should be 32 bytes");
|
|
2634
|
+
return {
|
|
2635
|
+
type: "nprofile",
|
|
2636
|
+
data: {
|
|
2637
|
+
pubkey: D(d[0][0]),
|
|
2638
|
+
relays: d[1] ? d[1].map((w) => re.decode(w)) : []
|
|
2639
|
+
}
|
|
2640
|
+
};
|
|
2641
|
+
}
|
|
2642
|
+
case "nevent": {
|
|
2643
|
+
let d = et(r);
|
|
2644
|
+
if (!((o = d[0]) != null && o[0]))
|
|
2645
|
+
throw new Error("missing TLV 0 for nevent");
|
|
2646
|
+
if (d[0][0].length !== 32)
|
|
2647
|
+
throw new Error("TLV 0 should be 32 bytes");
|
|
2648
|
+
if (d[2] && d[2][0].length !== 32)
|
|
2649
|
+
throw new Error("TLV 2 should be 32 bytes");
|
|
2650
|
+
if (d[3] && d[3][0].length !== 4)
|
|
2651
|
+
throw new Error("TLV 3 should be 4 bytes");
|
|
2652
|
+
return {
|
|
2653
|
+
type: "nevent",
|
|
2654
|
+
data: {
|
|
2655
|
+
id: D(d[0][0]),
|
|
2656
|
+
relays: d[1] ? d[1].map((w) => re.decode(w)) : [],
|
|
2657
|
+
author: (s = d[2]) != null && s[0] ? D(d[2][0]) : void 0,
|
|
2658
|
+
kind: (c = d[3]) != null && c[0] ? parseInt(D(d[3][0]), 16) : void 0
|
|
2659
|
+
}
|
|
2660
|
+
};
|
|
2661
|
+
}
|
|
2662
|
+
case "naddr": {
|
|
2663
|
+
let d = et(r);
|
|
2664
|
+
if (!((a = d[0]) != null && a[0]))
|
|
2665
|
+
throw new Error("missing TLV 0 for naddr");
|
|
2666
|
+
if (!((u = d[2]) != null && u[0]))
|
|
2667
|
+
throw new Error("missing TLV 2 for naddr");
|
|
2668
|
+
if (d[2][0].length !== 32)
|
|
2669
|
+
throw new Error("TLV 2 should be 32 bytes");
|
|
2670
|
+
if (!((f = d[3]) != null && f[0]))
|
|
2671
|
+
throw new Error("missing TLV 3 for naddr");
|
|
2672
|
+
if (d[3][0].length !== 4)
|
|
2673
|
+
throw new Error("TLV 3 should be 4 bytes");
|
|
2674
|
+
return {
|
|
2675
|
+
type: "naddr",
|
|
2676
|
+
data: {
|
|
2677
|
+
identifier: re.decode(d[0][0]),
|
|
2678
|
+
pubkey: D(d[2][0]),
|
|
2679
|
+
kind: parseInt(D(d[3][0]), 16),
|
|
2680
|
+
relays: d[1] ? d[1].map((w) => re.decode(w)) : []
|
|
2681
|
+
}
|
|
2682
|
+
};
|
|
2683
|
+
}
|
|
2684
|
+
case "nrelay": {
|
|
2685
|
+
let d = et(r);
|
|
2686
|
+
if (!((l = d[0]) != null && l[0]))
|
|
2687
|
+
throw new Error("missing TLV 0 for nrelay");
|
|
2688
|
+
return {
|
|
2689
|
+
type: "nrelay",
|
|
2690
|
+
data: re.decode(d[0][0])
|
|
2691
|
+
};
|
|
2692
|
+
}
|
|
2693
|
+
case "nsec":
|
|
2694
|
+
return { type: t, data: r };
|
|
2695
|
+
case "npub":
|
|
2696
|
+
case "note":
|
|
2697
|
+
return { type: t, data: D(r) };
|
|
2698
|
+
default:
|
|
2699
|
+
throw new Error(`unknown prefix ${t}`);
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
function et(e) {
|
|
2703
|
+
let t = {}, n = e;
|
|
2704
|
+
for (; n.length > 0; ) {
|
|
2705
|
+
let r = n[0], i = n[1], o = n.slice(2, 2 + i);
|
|
2706
|
+
if (n = n.slice(2 + i), o.length < i)
|
|
2707
|
+
throw new Error(`not enough data to read on TLV ${r}`);
|
|
2708
|
+
t[r] = t[r] || [], t[r].push(o);
|
|
2709
|
+
}
|
|
2710
|
+
return t;
|
|
2711
|
+
}
|
|
2712
|
+
function xa(e) {
|
|
2713
|
+
return xt("nsec", e);
|
|
2714
|
+
}
|
|
2715
|
+
function ma(e) {
|
|
2716
|
+
return xt("npub", W(e));
|
|
2717
|
+
}
|
|
2718
|
+
function Ea(e) {
|
|
2719
|
+
return xt("note", W(e));
|
|
2720
|
+
}
|
|
2721
|
+
function Xe(e, t) {
|
|
2722
|
+
let n = De.toWords(t);
|
|
2723
|
+
return De.encode(e, n, fn);
|
|
2724
|
+
}
|
|
2725
|
+
function xt(e, t) {
|
|
2726
|
+
return Xe(e, t);
|
|
2727
|
+
}
|
|
2728
|
+
function Aa(e) {
|
|
2729
|
+
let t = mt({
|
|
2730
|
+
0: [W(e.pubkey)],
|
|
2731
|
+
1: (e.relays || []).map((n) => ee.encode(n))
|
|
2732
|
+
});
|
|
2733
|
+
return Xe("nprofile", t);
|
|
2734
|
+
}
|
|
2735
|
+
function Sa(e) {
|
|
2736
|
+
let t;
|
|
2737
|
+
e.kind !== void 0 && (t = va(e.kind));
|
|
2738
|
+
let n = mt({
|
|
2739
|
+
0: [W(e.id)],
|
|
2740
|
+
1: (e.relays || []).map((r) => ee.encode(r)),
|
|
2741
|
+
2: e.author ? [W(e.author)] : [],
|
|
2742
|
+
3: t ? [new Uint8Array(t)] : []
|
|
2743
|
+
});
|
|
2744
|
+
return Xe("nevent", n);
|
|
2745
|
+
}
|
|
2746
|
+
function Ba(e) {
|
|
2747
|
+
let t = new ArrayBuffer(4);
|
|
2748
|
+
new DataView(t).setUint32(0, e.kind, !1);
|
|
2749
|
+
let n = mt({
|
|
2750
|
+
0: [ee.encode(e.identifier)],
|
|
2751
|
+
1: (e.relays || []).map((r) => ee.encode(r)),
|
|
2752
|
+
2: [W(e.pubkey)],
|
|
2753
|
+
3: [new Uint8Array(t)]
|
|
2754
|
+
});
|
|
2755
|
+
return Xe("naddr", n);
|
|
2756
|
+
}
|
|
2757
|
+
function Na(e) {
|
|
2758
|
+
let t = mt({
|
|
2759
|
+
0: [ee.encode(e)]
|
|
2760
|
+
});
|
|
2761
|
+
return Xe("nrelay", t);
|
|
2762
|
+
}
|
|
2763
|
+
function mt(e) {
|
|
2764
|
+
let t = [];
|
|
2765
|
+
return Object.entries(e).reverse().forEach(([n, r]) => {
|
|
2766
|
+
r.forEach((i) => {
|
|
2767
|
+
let o = new Uint8Array(i.length + 2);
|
|
2768
|
+
o.set([parseInt(n)], 0), o.set([i.length], 1), o.set(i, 2), t.push(o);
|
|
2769
|
+
});
|
|
2770
|
+
}), pt(...t);
|
|
2771
|
+
}
|
|
2772
|
+
var Ca = {};
|
|
2773
|
+
q(Ca, {
|
|
2774
|
+
decrypt: () => Ua,
|
|
2775
|
+
encrypt: () => Rr
|
|
2776
|
+
});
|
|
2777
|
+
async function Rr(e, t, n) {
|
|
2778
|
+
const r = e instanceof Uint8Array ? D(e) : e, i = Le.getSharedSecret(r, "02" + t), o = Pr(i);
|
|
2779
|
+
let s = Uint8Array.from(ir(16)), c = ee.encode(n), a = gr(o, s).encrypt(c), u = he.encode(new Uint8Array(a)), f = he.encode(new Uint8Array(s.buffer));
|
|
2780
|
+
return `${u}?iv=${f}`;
|
|
2781
|
+
}
|
|
2782
|
+
async function Ua(e, t, n) {
|
|
2783
|
+
const r = e instanceof Uint8Array ? D(e) : e;
|
|
2784
|
+
let [i, o] = n.split("?iv="), s = Le.getSharedSecret(r, "02" + t), c = Pr(s), a = he.decode(o), u = he.decode(i), f = gr(c, a).decrypt(u);
|
|
2785
|
+
return re.decode(f);
|
|
2786
|
+
}
|
|
2787
|
+
function Pr(e) {
|
|
2788
|
+
return e.slice(1, 33);
|
|
2789
|
+
}
|
|
2790
|
+
var Ia = {};
|
|
2791
|
+
q(Ia, {
|
|
2792
|
+
NIP05_REGEX: () => Or,
|
|
2793
|
+
isValid: () => La,
|
|
2794
|
+
queryProfile: () => Hr,
|
|
2795
|
+
searchDomain: () => _a,
|
|
2796
|
+
useFetchImplementation: () => Ka
|
|
2797
|
+
});
|
|
2798
|
+
var Or = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/, Et;
|
|
2799
|
+
try {
|
|
2800
|
+
Et = fetch;
|
|
2801
|
+
} catch {
|
|
2802
|
+
}
|
|
2803
|
+
function Ka(e) {
|
|
2804
|
+
Et = e;
|
|
2805
|
+
}
|
|
2806
|
+
async function _a(e, t = "") {
|
|
2807
|
+
try {
|
|
2808
|
+
const n = `https://${e}/.well-known/nostr.json?name=${t}`;
|
|
2809
|
+
return (await (await Et(n, { redirect: "error" })).json()).names;
|
|
2810
|
+
} catch {
|
|
2811
|
+
return {};
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
async function Hr(e) {
|
|
2815
|
+
var o;
|
|
2816
|
+
const t = e.match(Or);
|
|
2817
|
+
if (!t)
|
|
2818
|
+
return null;
|
|
2819
|
+
const [n, r = "_", i] = t;
|
|
2820
|
+
try {
|
|
2821
|
+
const s = `https://${i}/.well-known/nostr.json?name=${r}`, c = await (await Et(s, { redirect: "error" })).json();
|
|
2822
|
+
let a = c.names[r];
|
|
2823
|
+
return a ? { pubkey: a, relays: (o = c.relays) == null ? void 0 : o[a] } : null;
|
|
2824
|
+
} catch {
|
|
2825
|
+
return null;
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
async function La(e, t) {
|
|
2829
|
+
let n = await Hr(t);
|
|
2830
|
+
return n ? n.pubkey === e : !1;
|
|
2831
|
+
}
|
|
2832
|
+
var ka = {};
|
|
2833
|
+
q(ka, {
|
|
2834
|
+
parse: () => Ta
|
|
2835
|
+
});
|
|
2836
|
+
function Ta(e) {
|
|
2837
|
+
const t = {
|
|
2838
|
+
reply: void 0,
|
|
2839
|
+
root: void 0,
|
|
2840
|
+
mentions: [],
|
|
2841
|
+
profiles: []
|
|
2842
|
+
}, n = [];
|
|
2843
|
+
for (const r of e.tags)
|
|
2844
|
+
r[0] === "e" && r[1] && n.push(r), r[0] === "p" && r[1] && t.profiles.push({
|
|
2845
|
+
pubkey: r[1],
|
|
2846
|
+
relays: r[2] ? [r[2]] : []
|
|
2847
|
+
});
|
|
2848
|
+
for (let r = 0; r < n.length; r++) {
|
|
2849
|
+
const i = n[r], [o, s, c, a] = i, u = {
|
|
2850
|
+
id: s,
|
|
2851
|
+
relays: c ? [c] : []
|
|
2852
|
+
}, f = r === 0, l = r === n.length - 1;
|
|
2853
|
+
if (a === "root") {
|
|
2854
|
+
t.root = u;
|
|
2855
|
+
continue;
|
|
2856
|
+
}
|
|
2857
|
+
if (a === "reply") {
|
|
2858
|
+
t.reply = u;
|
|
2859
|
+
continue;
|
|
2860
|
+
}
|
|
2861
|
+
if (a === "mention") {
|
|
2862
|
+
t.mentions.push(u);
|
|
2863
|
+
continue;
|
|
2864
|
+
}
|
|
2865
|
+
if (f) {
|
|
2866
|
+
t.root = u;
|
|
2867
|
+
continue;
|
|
2868
|
+
}
|
|
2869
|
+
if (l) {
|
|
2870
|
+
t.reply = u;
|
|
2871
|
+
continue;
|
|
2872
|
+
}
|
|
2873
|
+
t.mentions.push(u);
|
|
2874
|
+
}
|
|
2875
|
+
return t;
|
|
2876
|
+
}
|
|
2877
|
+
var $a = {};
|
|
2878
|
+
q($a, {
|
|
2879
|
+
fetchRelayInformation: () => Pa,
|
|
2880
|
+
useFetchImplementation: () => Ra
|
|
2881
|
+
});
|
|
2882
|
+
var Mr;
|
|
2883
|
+
try {
|
|
2884
|
+
Mr = fetch;
|
|
2885
|
+
} catch {
|
|
2886
|
+
}
|
|
2887
|
+
function Ra(e) {
|
|
2888
|
+
Mr = e;
|
|
2889
|
+
}
|
|
2890
|
+
async function Pa(e) {
|
|
2891
|
+
return await (await fetch(e.replace("ws://", "http://").replace("wss://", "https://"), {
|
|
2892
|
+
headers: { Accept: "application/nostr+json" }
|
|
2893
|
+
})).json();
|
|
2894
|
+
}
|
|
2895
|
+
var Oa = {};
|
|
2896
|
+
q(Oa, {
|
|
2897
|
+
getPow: () => qr,
|
|
2898
|
+
minePow: () => Ha
|
|
2899
|
+
});
|
|
2900
|
+
function qr(e) {
|
|
2901
|
+
let t = 0;
|
|
2902
|
+
for (let n = 0; n < e.length; n++) {
|
|
2903
|
+
const r = parseInt(e[n], 16);
|
|
2904
|
+
if (r === 0)
|
|
2905
|
+
t += 4;
|
|
2906
|
+
else {
|
|
2907
|
+
t += Math.clz32(r) - 28;
|
|
2908
|
+
break;
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
return t;
|
|
2912
|
+
}
|
|
2913
|
+
function Ha(e, t) {
|
|
2914
|
+
let n = 0;
|
|
2915
|
+
const r = e, i = ["nonce", n.toString(), t.toString()];
|
|
2916
|
+
for (r.tags.push(i); ; ) {
|
|
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 = nt(r), qr(r.id) >= t)
|
|
2919
|
+
break;
|
|
2920
|
+
}
|
|
2921
|
+
return r;
|
|
2922
|
+
}
|
|
2923
|
+
var Ma = {};
|
|
2924
|
+
q(Ma, {
|
|
2925
|
+
finishRepostEvent: () => qa,
|
|
2926
|
+
getRepostedEvent: () => Da,
|
|
2927
|
+
getRepostedEventPointer: () => Dr
|
|
2928
|
+
});
|
|
2929
|
+
function qa(e, t, n, r) {
|
|
2930
|
+
return se(
|
|
2931
|
+
{
|
|
2932
|
+
kind: an,
|
|
2933
|
+
tags: [...e.tags ?? [], ["e", t.id, n], ["p", t.pubkey]],
|
|
2934
|
+
content: e.content === "" ? "" : JSON.stringify(t),
|
|
2935
|
+
created_at: e.created_at
|
|
2936
|
+
},
|
|
2937
|
+
r
|
|
2938
|
+
);
|
|
2939
|
+
}
|
|
2940
|
+
function Dr(e) {
|
|
2941
|
+
if (e.kind !== an)
|
|
2942
|
+
return;
|
|
2943
|
+
let t, n;
|
|
2944
|
+
for (let r = e.tags.length - 1; r >= 0 && (t === void 0 || n === void 0); r--) {
|
|
2945
|
+
const i = e.tags[r];
|
|
2946
|
+
i.length >= 2 && (i[0] === "e" && t === void 0 ? t = i : i[0] === "p" && n === void 0 && (n = i));
|
|
2947
|
+
}
|
|
2948
|
+
if (t !== void 0)
|
|
2949
|
+
return {
|
|
2950
|
+
id: t[1],
|
|
2951
|
+
relays: [t[2], n == null ? void 0 : n[2]].filter((r) => typeof r == "string"),
|
|
2952
|
+
author: n == null ? void 0 : n[1]
|
|
2953
|
+
};
|
|
2954
|
+
}
|
|
2955
|
+
function Da(e, { skipVerification: t } = {}) {
|
|
2956
|
+
const n = Dr(e);
|
|
2957
|
+
if (n === void 0 || e.content === "")
|
|
2958
|
+
return;
|
|
2959
|
+
let r;
|
|
2960
|
+
try {
|
|
2961
|
+
r = JSON.parse(e.content);
|
|
2962
|
+
} catch {
|
|
2963
|
+
return;
|
|
2964
|
+
}
|
|
2965
|
+
if (r.id === n.id && !(!t && !sn(r)))
|
|
2966
|
+
return r;
|
|
2967
|
+
}
|
|
2968
|
+
var ja = {};
|
|
2969
|
+
q(ja, {
|
|
2970
|
+
NOSTR_URI_REGEX: () => At,
|
|
2971
|
+
parse: () => za,
|
|
2972
|
+
test: () => Va
|
|
2973
|
+
});
|
|
2974
|
+
var At = new RegExp(`nostr:(${$r.source})`);
|
|
2975
|
+
function Va(e) {
|
|
2976
|
+
return typeof e == "string" && new RegExp(`^${At.source}$`).test(e);
|
|
2977
|
+
}
|
|
2978
|
+
function za(e) {
|
|
2979
|
+
const t = e.match(new RegExp(`^${At.source}$`));
|
|
2980
|
+
if (!t)
|
|
2981
|
+
throw new Error(`Invalid Nostr URI: ${e}`);
|
|
2982
|
+
return {
|
|
2983
|
+
uri: t[0],
|
|
2984
|
+
value: t[1],
|
|
2985
|
+
decoded: vt(t[1])
|
|
2986
|
+
};
|
|
2987
|
+
}
|
|
2988
|
+
var Za = {};
|
|
2989
|
+
q(Za, {
|
|
2990
|
+
finishReactionEvent: () => Fa,
|
|
2991
|
+
getReactedEventPointer: () => Wa
|
|
2992
|
+
});
|
|
2993
|
+
function Fa(e, t, n) {
|
|
2994
|
+
const r = t.tags.filter((i) => i.length >= 2 && (i[0] === "e" || i[0] === "p"));
|
|
2995
|
+
return se(
|
|
2996
|
+
{
|
|
2997
|
+
...e,
|
|
2998
|
+
kind: cn,
|
|
2999
|
+
tags: [...e.tags ?? [], ...r, ["e", t.id], ["p", t.pubkey]],
|
|
3000
|
+
content: e.content ?? "+"
|
|
3001
|
+
},
|
|
3002
|
+
n
|
|
3003
|
+
);
|
|
3004
|
+
}
|
|
3005
|
+
function Wa(e) {
|
|
3006
|
+
if (e.kind !== cn)
|
|
3007
|
+
return;
|
|
3008
|
+
let t, n;
|
|
3009
|
+
for (let r = e.tags.length - 1; r >= 0 && (t === void 0 || n === void 0); r--) {
|
|
3010
|
+
const i = e.tags[r];
|
|
3011
|
+
i.length >= 2 && (i[0] === "e" && t === void 0 ? t = i : i[0] === "p" && n === void 0 && (n = i));
|
|
3012
|
+
}
|
|
3013
|
+
if (!(t === void 0 || n === void 0))
|
|
3014
|
+
return {
|
|
3015
|
+
id: t[1],
|
|
3016
|
+
relays: [t[2], n[2]].filter((r) => r !== void 0),
|
|
3017
|
+
author: n[1]
|
|
3018
|
+
};
|
|
3019
|
+
}
|
|
3020
|
+
var Ga = {};
|
|
3021
|
+
q(Ga, {
|
|
3022
|
+
matchAll: () => Ja,
|
|
3023
|
+
regex: () => hn,
|
|
3024
|
+
replaceAll: () => Ya
|
|
3025
|
+
});
|
|
3026
|
+
var hn = () => new RegExp(`\\b${At.source}\\b`, "g");
|
|
3027
|
+
function* Ja(e) {
|
|
3028
|
+
const t = e.matchAll(hn());
|
|
3029
|
+
for (const n of t)
|
|
3030
|
+
try {
|
|
3031
|
+
const [r, i] = n;
|
|
3032
|
+
yield {
|
|
3033
|
+
uri: r,
|
|
3034
|
+
value: i,
|
|
3035
|
+
decoded: vt(i),
|
|
3036
|
+
start: n.index,
|
|
3037
|
+
end: n.index + r.length
|
|
3038
|
+
};
|
|
3039
|
+
} catch {
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
function Ya(e, t) {
|
|
3043
|
+
return e.replaceAll(hn(), (n, r) => t({
|
|
3044
|
+
uri: n,
|
|
3045
|
+
value: r,
|
|
3046
|
+
decoded: vt(r)
|
|
3047
|
+
}));
|
|
3048
|
+
}
|
|
3049
|
+
var Xa = {};
|
|
3050
|
+
q(Xa, {
|
|
3051
|
+
channelCreateEvent: () => Qa,
|
|
3052
|
+
channelHideMessageEvent: () => nc,
|
|
3053
|
+
channelMessageEvent: () => tc,
|
|
3054
|
+
channelMetadataEvent: () => ec,
|
|
3055
|
+
channelMuteUserEvent: () => rc
|
|
3056
|
+
});
|
|
3057
|
+
var Qa = (e, t) => {
|
|
3058
|
+
let n;
|
|
3059
|
+
if (typeof e.content == "object")
|
|
3060
|
+
n = JSON.stringify(e.content);
|
|
3061
|
+
else if (typeof e.content == "string")
|
|
3062
|
+
n = e.content;
|
|
3063
|
+
else
|
|
3064
|
+
return;
|
|
3065
|
+
return se(
|
|
3066
|
+
{
|
|
3067
|
+
kind: Cr,
|
|
3068
|
+
tags: [...e.tags ?? []],
|
|
3069
|
+
content: n,
|
|
3070
|
+
created_at: e.created_at
|
|
3071
|
+
},
|
|
3072
|
+
t
|
|
3073
|
+
);
|
|
3074
|
+
}, ec = (e, t) => {
|
|
3075
|
+
let n;
|
|
3076
|
+
if (typeof e.content == "object")
|
|
3077
|
+
n = JSON.stringify(e.content);
|
|
3078
|
+
else if (typeof e.content == "string")
|
|
3079
|
+
n = e.content;
|
|
3080
|
+
else
|
|
3081
|
+
return;
|
|
3082
|
+
return se(
|
|
3083
|
+
{
|
|
3084
|
+
kind: Ur,
|
|
3085
|
+
tags: [["e", e.channel_create_event_id], ...e.tags ?? []],
|
|
3086
|
+
content: n,
|
|
3087
|
+
created_at: e.created_at
|
|
3088
|
+
},
|
|
3089
|
+
t
|
|
3090
|
+
);
|
|
3091
|
+
}, tc = (e, t) => {
|
|
3092
|
+
const n = [["e", e.channel_create_event_id, e.relay_url, "root"]];
|
|
3093
|
+
return e.reply_to_channel_message_event_id && n.push(["e", e.reply_to_channel_message_event_id, e.relay_url, "reply"]), se(
|
|
3094
|
+
{
|
|
3095
|
+
kind: Ir,
|
|
3096
|
+
tags: [...n, ...e.tags ?? []],
|
|
3097
|
+
content: e.content,
|
|
3098
|
+
created_at: e.created_at
|
|
3099
|
+
},
|
|
3100
|
+
t
|
|
3101
|
+
);
|
|
3102
|
+
}, nc = (e, t) => {
|
|
3103
|
+
let n;
|
|
3104
|
+
if (typeof e.content == "object")
|
|
3105
|
+
n = JSON.stringify(e.content);
|
|
3106
|
+
else if (typeof e.content == "string")
|
|
3107
|
+
n = e.content;
|
|
3108
|
+
else
|
|
3109
|
+
return;
|
|
3110
|
+
return se(
|
|
3111
|
+
{
|
|
3112
|
+
kind: Kr,
|
|
3113
|
+
tags: [["e", e.channel_message_event_id], ...e.tags ?? []],
|
|
3114
|
+
content: n,
|
|
3115
|
+
created_at: e.created_at
|
|
3116
|
+
},
|
|
3117
|
+
t
|
|
3118
|
+
);
|
|
3119
|
+
}, rc = (e, t) => {
|
|
3120
|
+
let n;
|
|
3121
|
+
if (typeof e.content == "object")
|
|
3122
|
+
n = JSON.stringify(e.content);
|
|
3123
|
+
else if (typeof e.content == "string")
|
|
3124
|
+
n = e.content;
|
|
3125
|
+
else
|
|
3126
|
+
return;
|
|
3127
|
+
return se(
|
|
3128
|
+
{
|
|
3129
|
+
kind: _r,
|
|
3130
|
+
tags: [["p", e.pubkey_to_mute], ...e.tags ?? []],
|
|
3131
|
+
content: n,
|
|
3132
|
+
created_at: e.created_at
|
|
3133
|
+
},
|
|
3134
|
+
t
|
|
3135
|
+
);
|
|
3136
|
+
}, ic = {};
|
|
3137
|
+
q(ic, {
|
|
3138
|
+
EMOJI_SHORTCODE_REGEX: () => jr,
|
|
3139
|
+
matchAll: () => oc,
|
|
3140
|
+
regex: () => dn,
|
|
3141
|
+
replaceAll: () => sc
|
|
3142
|
+
});
|
|
3143
|
+
var jr = /:(\w+):/, dn = () => new RegExp(`\\B${jr.source}\\B`, "g");
|
|
3144
|
+
function* oc(e) {
|
|
3145
|
+
const t = e.matchAll(dn());
|
|
3146
|
+
for (const n of t)
|
|
3147
|
+
try {
|
|
3148
|
+
const [r, i] = n;
|
|
3149
|
+
yield {
|
|
3150
|
+
shortcode: r,
|
|
3151
|
+
name: i,
|
|
3152
|
+
start: n.index,
|
|
3153
|
+
end: n.index + r.length
|
|
3154
|
+
};
|
|
3155
|
+
} catch {
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
function sc(e, t) {
|
|
3159
|
+
return e.replaceAll(dn(), (n, r) => t({
|
|
3160
|
+
shortcode: n,
|
|
3161
|
+
name: r
|
|
3162
|
+
}));
|
|
3163
|
+
}
|
|
3164
|
+
var ac = {};
|
|
3165
|
+
q(ac, {
|
|
3166
|
+
useFetchImplementation: () => cc,
|
|
3167
|
+
validateGithub: () => uc
|
|
3168
|
+
});
|
|
3169
|
+
var gn;
|
|
3170
|
+
try {
|
|
3171
|
+
gn = fetch;
|
|
3172
|
+
} catch {
|
|
3173
|
+
}
|
|
3174
|
+
function cc(e) {
|
|
3175
|
+
gn = e;
|
|
3176
|
+
}
|
|
3177
|
+
async function uc(e, t, n) {
|
|
3178
|
+
try {
|
|
3179
|
+
return await (await gn(`https://gist.github.com/${t}/${n}/raw`)).text() === `Verifying that I control the following Nostr public key: ${e}`;
|
|
3180
|
+
} catch {
|
|
3181
|
+
return !1;
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
var fe = {};
|
|
3185
|
+
q(fe, {
|
|
3186
|
+
decrypt: () => Jr,
|
|
3187
|
+
encrypt: () => Gr,
|
|
3188
|
+
getConversationKey: () => Zr,
|
|
3189
|
+
v2: () => gc
|
|
3190
|
+
});
|
|
3191
|
+
var Vr = 1, zr = 65535;
|
|
3192
|
+
function Zr(e, t) {
|
|
3193
|
+
const n = Le.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3194
|
+
return rn(Ne, n, "nip44-v2");
|
|
3195
|
+
}
|
|
3196
|
+
function Fr(e, t) {
|
|
3197
|
+
const n = xr(Ne, e, t, 76);
|
|
3198
|
+
return {
|
|
3199
|
+
chacha_key: n.subarray(0, 32),
|
|
3200
|
+
chacha_nonce: n.subarray(32, 44),
|
|
3201
|
+
hmac_key: n.subarray(44, 76)
|
|
3202
|
+
};
|
|
3203
|
+
}
|
|
3204
|
+
function pn(e) {
|
|
3205
|
+
if (!Number.isSafeInteger(e) || e < 1)
|
|
3206
|
+
throw new Error("expected positive integer");
|
|
3207
|
+
if (e <= 32)
|
|
3208
|
+
return 32;
|
|
3209
|
+
const t = 1 << Math.floor(Math.log2(e - 1)) + 1, n = t <= 256 ? 32 : t / 8;
|
|
3210
|
+
return n * (Math.floor((e - 1) / n) + 1);
|
|
3211
|
+
}
|
|
3212
|
+
function lc(e) {
|
|
3213
|
+
if (!Number.isSafeInteger(e) || e < Vr || e > zr)
|
|
3214
|
+
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
|
|
3215
|
+
const t = new Uint8Array(2);
|
|
3216
|
+
return new DataView(t.buffer).setUint16(0, e, !1), t;
|
|
3217
|
+
}
|
|
3218
|
+
function fc(e) {
|
|
3219
|
+
const t = ee.encode(e), n = t.length, r = lc(n), i = new Uint8Array(pn(n) - n);
|
|
3220
|
+
return pt(r, t, i);
|
|
3221
|
+
}
|
|
3222
|
+
function hc(e) {
|
|
3223
|
+
const t = new DataView(e.buffer).getUint16(0), n = e.subarray(2, 2 + t);
|
|
3224
|
+
if (t < Vr || t > zr || n.length !== t || e.length !== 2 + pn(t))
|
|
3225
|
+
throw new Error("invalid padding");
|
|
3226
|
+
return re.decode(n);
|
|
3227
|
+
}
|
|
3228
|
+
function Wr(e, t, n) {
|
|
3229
|
+
if (n.length !== 32)
|
|
3230
|
+
throw new Error("AAD associated data must be 32 bytes");
|
|
3231
|
+
const r = pt(n, t);
|
|
3232
|
+
return wt(Ne, e, r);
|
|
3233
|
+
}
|
|
3234
|
+
function dc(e) {
|
|
3235
|
+
if (typeof e != "string")
|
|
3236
|
+
throw new Error("payload must be a valid string");
|
|
3237
|
+
const t = e.length;
|
|
3238
|
+
if (t < 132 || t > 87472)
|
|
3239
|
+
throw new Error("invalid payload length: " + t);
|
|
3240
|
+
if (e[0] === "#")
|
|
3241
|
+
throw new Error("unknown encryption version");
|
|
3242
|
+
let n;
|
|
3243
|
+
try {
|
|
3244
|
+
n = he.decode(e);
|
|
3245
|
+
} catch (o) {
|
|
3246
|
+
throw new Error("invalid base64: " + o.message);
|
|
3247
|
+
}
|
|
3248
|
+
const r = n.length;
|
|
3249
|
+
if (r < 99 || r > 65603)
|
|
3250
|
+
throw new Error("invalid data length: " + r);
|
|
3251
|
+
const i = n[0];
|
|
3252
|
+
if (i !== 2)
|
|
3253
|
+
throw new Error("unknown encryption version " + i);
|
|
3254
|
+
return {
|
|
3255
|
+
nonce: n.subarray(1, 33),
|
|
3256
|
+
ciphertext: n.subarray(33, -32),
|
|
3257
|
+
mac: n.subarray(-32)
|
|
3258
|
+
};
|
|
3259
|
+
}
|
|
3260
|
+
function Gr(e, t, n = ir(32)) {
|
|
3261
|
+
const { chacha_key: r, chacha_nonce: i, hmac_key: o } = Fr(t, n), s = fc(e), c = br(r, i, s), a = Wr(o, c, n);
|
|
3262
|
+
return he.encode(pt(new Uint8Array([2]), n, c, a));
|
|
3263
|
+
}
|
|
3264
|
+
function Jr(e, t) {
|
|
3265
|
+
const { nonce: n, ciphertext: r, mac: i } = dc(e), { chacha_key: o, chacha_nonce: s, hmac_key: c } = Fr(t, n), a = Wr(c, r, n);
|
|
3266
|
+
if (!So(a, i))
|
|
3267
|
+
throw new Error("invalid MAC");
|
|
3268
|
+
const u = br(o, s, r);
|
|
3269
|
+
return hc(u);
|
|
3270
|
+
}
|
|
3271
|
+
var gc = {
|
|
3272
|
+
utils: {
|
|
3273
|
+
getConversationKey: Zr,
|
|
3274
|
+
calcPaddedLen: pn
|
|
3275
|
+
},
|
|
3276
|
+
encrypt: Gr,
|
|
3277
|
+
decrypt: Jr
|
|
3278
|
+
}, pc = {};
|
|
3279
|
+
q(pc, {
|
|
3280
|
+
makeNwcRequestEvent: () => wc,
|
|
3281
|
+
parseConnectionString: () => yc
|
|
3282
|
+
});
|
|
3283
|
+
function yc(e) {
|
|
3284
|
+
const { pathname: t, searchParams: n } = new URL(e), r = t, i = n.get("relay"), o = n.get("secret");
|
|
3285
|
+
if (!r || !i || !o)
|
|
3286
|
+
throw new Error("invalid connection string");
|
|
3287
|
+
return { pubkey: r, relay: i, secret: o };
|
|
3288
|
+
}
|
|
3289
|
+
async function wc(e, t, n) {
|
|
3290
|
+
const i = await Rr(t, e, JSON.stringify({
|
|
3291
|
+
method: "pay_invoice",
|
|
3292
|
+
params: {
|
|
3293
|
+
invoice: n
|
|
3294
|
+
}
|
|
3295
|
+
})), o = {
|
|
3296
|
+
kind: kr,
|
|
3297
|
+
created_at: Math.round(Date.now() / 1e3),
|
|
3298
|
+
content: i,
|
|
3299
|
+
tags: [["p", e]]
|
|
3300
|
+
};
|
|
3301
|
+
return se(o, t);
|
|
3302
|
+
}
|
|
3303
|
+
var bc = {};
|
|
3304
|
+
q(bc, {
|
|
3305
|
+
getZapEndpoint: () => xc,
|
|
3306
|
+
makeZapReceipt: () => Ac,
|
|
3307
|
+
makeZapRequest: () => mc,
|
|
3308
|
+
useFetchImplementation: () => vc,
|
|
3309
|
+
validateZapRequest: () => Ec
|
|
3310
|
+
});
|
|
3311
|
+
var yn;
|
|
3312
|
+
try {
|
|
3313
|
+
yn = fetch;
|
|
3314
|
+
} catch {
|
|
3315
|
+
}
|
|
3316
|
+
function vc(e) {
|
|
3317
|
+
yn = e;
|
|
3318
|
+
}
|
|
3319
|
+
async function xc(e) {
|
|
3320
|
+
try {
|
|
3321
|
+
let t = "", { lud06: n, lud16: r } = JSON.parse(e.content);
|
|
3322
|
+
if (n) {
|
|
3323
|
+
let { words: s } = De.decode(n, 1e3), c = De.fromWords(s);
|
|
3324
|
+
t = re.decode(c);
|
|
3325
|
+
} else if (r) {
|
|
3326
|
+
let [s, c] = r.split("@");
|
|
3327
|
+
t = new URL(`/.well-known/lnurlp/${s}`, `https://${c}`).toString();
|
|
3328
|
+
} else
|
|
3329
|
+
return null;
|
|
3330
|
+
let o = await (await yn(t)).json();
|
|
3331
|
+
if (o.allowsNostr && o.nostrPubkey)
|
|
3332
|
+
return o.callback;
|
|
3333
|
+
} catch {
|
|
3334
|
+
}
|
|
3335
|
+
return null;
|
|
3336
|
+
}
|
|
3337
|
+
function mc({
|
|
3338
|
+
profile: e,
|
|
3339
|
+
event: t,
|
|
3340
|
+
amount: n,
|
|
3341
|
+
relays: r,
|
|
3342
|
+
comment: i = ""
|
|
3343
|
+
}) {
|
|
3344
|
+
if (!n)
|
|
3345
|
+
throw new Error("amount not given");
|
|
3346
|
+
if (!e)
|
|
3347
|
+
throw new Error("profile not given");
|
|
3348
|
+
let o = {
|
|
3349
|
+
kind: 9734,
|
|
3350
|
+
created_at: Math.round(Date.now() / 1e3),
|
|
3351
|
+
content: i,
|
|
3352
|
+
tags: [
|
|
3353
|
+
["p", e],
|
|
3354
|
+
["amount", n.toString()],
|
|
3355
|
+
["relays", ...r]
|
|
3356
|
+
]
|
|
3357
|
+
};
|
|
3358
|
+
return t && o.tags.push(["e", t]), o;
|
|
3359
|
+
}
|
|
3360
|
+
function Ec(e) {
|
|
3361
|
+
let t;
|
|
3362
|
+
try {
|
|
3363
|
+
t = JSON.parse(e);
|
|
3364
|
+
} catch {
|
|
3365
|
+
return "Invalid zap request JSON.";
|
|
3366
|
+
}
|
|
3367
|
+
if (!mr(t))
|
|
3368
|
+
return "Zap request is not a valid Nostr event.";
|
|
3369
|
+
if (!sn(t))
|
|
3370
|
+
return "Invalid signature on zap request.";
|
|
3371
|
+
let n = t.tags.find(([o, s]) => o === "p" && s);
|
|
3372
|
+
if (!n)
|
|
3373
|
+
return "Zap request doesn't have a 'p' tag.";
|
|
3374
|
+
if (!n[1].match(/^[a-f0-9]{64}$/))
|
|
3375
|
+
return "Zap request 'p' tag is not valid hex.";
|
|
3376
|
+
let r = t.tags.find(([o, s]) => o === "e" && s);
|
|
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
|
+
}
|
|
3379
|
+
function Ac({
|
|
3380
|
+
zapRequest: e,
|
|
3381
|
+
preimage: t,
|
|
3382
|
+
bolt11: n,
|
|
3383
|
+
paidAt: r
|
|
3384
|
+
}) {
|
|
3385
|
+
let i = JSON.parse(e), o = i.tags.filter(([c]) => c === "e" || c === "p" || c === "a"), s = {
|
|
3386
|
+
kind: 9735,
|
|
3387
|
+
created_at: Math.round(r.getTime() / 1e3),
|
|
3388
|
+
content: "",
|
|
3389
|
+
tags: [...o, ["P", i.pubkey], ["bolt11", n], ["description", e]]
|
|
3390
|
+
};
|
|
3391
|
+
return t && s.tags.push(["preimage", t]), s;
|
|
3392
|
+
}
|
|
3393
|
+
var Sc = {};
|
|
3394
|
+
q(Sc, {
|
|
3395
|
+
getToken: () => Bc,
|
|
3396
|
+
hashPayload: () => wn,
|
|
3397
|
+
unpackEventFromToken: () => Xr,
|
|
3398
|
+
validateEvent: () => ii,
|
|
3399
|
+
validateEventKind: () => ei,
|
|
3400
|
+
validateEventMethodTag: () => ni,
|
|
3401
|
+
validateEventPayloadTag: () => ri,
|
|
3402
|
+
validateEventTimestamp: () => Qr,
|
|
3403
|
+
validateEventUrlTag: () => ti,
|
|
3404
|
+
validateToken: () => Nc
|
|
3405
|
+
});
|
|
3406
|
+
var Yr = "Nostr ";
|
|
3407
|
+
async function Bc(e, t, n, r = !1, i) {
|
|
3408
|
+
const o = {
|
|
3409
|
+
kind: un,
|
|
3410
|
+
tags: [
|
|
3411
|
+
["u", e],
|
|
3412
|
+
["method", t]
|
|
3413
|
+
],
|
|
3414
|
+
created_at: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
3415
|
+
content: ""
|
|
3416
|
+
};
|
|
3417
|
+
i && o.tags.push(["payload", wn(i)]);
|
|
3418
|
+
const s = await n(o);
|
|
3419
|
+
return (r ? Yr : "") + he.encode(ee.encode(JSON.stringify(s)));
|
|
3420
|
+
}
|
|
3421
|
+
async function Nc(e, t, n) {
|
|
3422
|
+
const r = await Xr(e).catch((o) => {
|
|
3423
|
+
throw o;
|
|
3424
|
+
});
|
|
3425
|
+
return await ii(r, t, n).catch((o) => {
|
|
3426
|
+
throw o;
|
|
3427
|
+
});
|
|
3428
|
+
}
|
|
3429
|
+
async function Xr(e) {
|
|
3430
|
+
if (!e)
|
|
3431
|
+
throw new Error("Missing token");
|
|
3432
|
+
e = e.replace(Yr, "");
|
|
3433
|
+
const t = re.decode(he.decode(e));
|
|
3434
|
+
if (!t || t.length === 0 || !t.startsWith("{"))
|
|
3435
|
+
throw new Error("Invalid token");
|
|
3436
|
+
return JSON.parse(t);
|
|
3437
|
+
}
|
|
3438
|
+
function Qr(e) {
|
|
3439
|
+
return e.created_at ? Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3) - e.created_at < 60 : !1;
|
|
3440
|
+
}
|
|
3441
|
+
function ei(e) {
|
|
3442
|
+
return e.kind === un;
|
|
3443
|
+
}
|
|
3444
|
+
function ti(e, t) {
|
|
3445
|
+
const n = e.tags.find((r) => r[0] === "u");
|
|
3446
|
+
return n ? n.length > 0 && n[1] === t : !1;
|
|
3447
|
+
}
|
|
3448
|
+
function ni(e, t) {
|
|
3449
|
+
const n = e.tags.find((r) => r[0] === "method");
|
|
3450
|
+
return n ? n.length > 0 && n[1].toLowerCase() === t.toLowerCase() : !1;
|
|
3451
|
+
}
|
|
3452
|
+
function wn(e) {
|
|
3453
|
+
const t = Ne(ee.encode(JSON.stringify(e)));
|
|
3454
|
+
return D(t);
|
|
3455
|
+
}
|
|
3456
|
+
function ri(e, t) {
|
|
3457
|
+
const n = e.tags.find((i) => i[0] === "payload");
|
|
3458
|
+
if (!n)
|
|
3459
|
+
return !1;
|
|
3460
|
+
const r = wn(t);
|
|
3461
|
+
return n.length > 0 && n[1] === r;
|
|
3462
|
+
}
|
|
3463
|
+
async function ii(e, t, n, r) {
|
|
3464
|
+
if (!sn(e))
|
|
3465
|
+
throw new Error("Invalid nostr event, signature invalid");
|
|
3466
|
+
if (!ei(e))
|
|
3467
|
+
throw new Error("Invalid nostr event, kind invalid");
|
|
3468
|
+
if (!Qr(e))
|
|
3469
|
+
throw new Error("Invalid nostr event, created_at timestamp invalid");
|
|
3470
|
+
if (!ti(e, t))
|
|
3471
|
+
throw new Error("Invalid nostr event, url tag invalid");
|
|
3472
|
+
if (!ni(e, n))
|
|
3473
|
+
throw new Error("Invalid nostr event, method tag invalid");
|
|
3474
|
+
if (r && typeof r == "object" && Object.keys(r).length > 0 && !ri(e, r))
|
|
3475
|
+
throw new Error("Invalid nostr event, payload tag does not match request body hash");
|
|
3476
|
+
return !0;
|
|
3477
|
+
}
|
|
3478
|
+
const We = 4, Tc = 100;
|
|
3479
|
+
var ae = /* @__PURE__ */ ((e) => (e[e.Us = 0] = "Us", e[e.Them = 1] = "Them", e))(ae || {}), ce = /* @__PURE__ */ ((e) => (e[e.Current = 0] = "Current", e[e.Next = 1] = "Next", e))(ce || {});
|
|
3480
|
+
function $c(e) {
|
|
3481
|
+
return JSON.stringify({
|
|
3482
|
+
theirCurrentNostrPublicKey: e.theirCurrentNostrPublicKey,
|
|
3483
|
+
ourCurrentNostrKey: {
|
|
3484
|
+
publicKey: e.ourCurrentNostrKey.publicKey,
|
|
3485
|
+
privateKey: D(e.ourCurrentNostrKey.privateKey)
|
|
3486
|
+
},
|
|
3487
|
+
ourNextNostrKey: {
|
|
3488
|
+
publicKey: e.ourNextNostrKey.publicKey,
|
|
3489
|
+
privateKey: D(e.ourNextNostrKey.privateKey)
|
|
3490
|
+
},
|
|
3491
|
+
receivingChainKey: D(e.receivingChainKey),
|
|
3492
|
+
nextReceivingChainKey: D(e.nextReceivingChainKey),
|
|
3493
|
+
sendingChainKey: D(e.sendingChainKey),
|
|
3494
|
+
sendingChainMessageNumber: e.sendingChainMessageNumber,
|
|
3495
|
+
receivingChainMessageNumber: e.receivingChainMessageNumber,
|
|
3496
|
+
previousSendingChainMessageCount: e.previousSendingChainMessageCount,
|
|
3497
|
+
skippedMessageKeys: Object.fromEntries(
|
|
3498
|
+
Object.entries(e.skippedMessageKeys).map(([t, n]) => [
|
|
3499
|
+
t,
|
|
3500
|
+
D(n)
|
|
3501
|
+
])
|
|
3502
|
+
)
|
|
3503
|
+
});
|
|
3504
|
+
}
|
|
3505
|
+
function Rc(e) {
|
|
3506
|
+
const t = JSON.parse(e);
|
|
3507
|
+
return {
|
|
3508
|
+
theirCurrentNostrPublicKey: t.theirCurrentNostrPublicKey,
|
|
3509
|
+
ourCurrentNostrKey: {
|
|
3510
|
+
publicKey: t.ourCurrentNostrKey.publicKey,
|
|
3511
|
+
privateKey: W(t.ourCurrentNostrKey.privateKey)
|
|
3512
|
+
},
|
|
3513
|
+
ourNextNostrKey: {
|
|
3514
|
+
publicKey: t.ourNextNostrKey.publicKey,
|
|
3515
|
+
privateKey: W(t.ourNextNostrKey.privateKey)
|
|
3516
|
+
},
|
|
3517
|
+
receivingChainKey: W(t.receivingChainKey),
|
|
3518
|
+
nextReceivingChainKey: W(t.nextReceivingChainKey),
|
|
3519
|
+
sendingChainKey: W(t.sendingChainKey),
|
|
3520
|
+
sendingChainMessageNumber: t.sendingChainMessageNumber,
|
|
3521
|
+
receivingChainMessageNumber: t.receivingChainMessageNumber,
|
|
3522
|
+
previousSendingChainMessageCount: t.previousSendingChainMessageCount,
|
|
3523
|
+
skippedMessageKeys: Object.fromEntries(
|
|
3524
|
+
Object.entries(t.skippedMessageKeys).map(([n, r]) => [
|
|
3525
|
+
n,
|
|
3526
|
+
W(r)
|
|
3527
|
+
])
|
|
3528
|
+
)
|
|
3529
|
+
};
|
|
3530
|
+
}
|
|
3531
|
+
async function* Pc(e) {
|
|
3532
|
+
const t = [];
|
|
3533
|
+
let n = null;
|
|
3534
|
+
const r = e.onMessage((i) => {
|
|
3535
|
+
n ? (n(i), n = null) : t.push(i);
|
|
3536
|
+
});
|
|
3537
|
+
try {
|
|
3538
|
+
for (; ; )
|
|
3539
|
+
t.length > 0 ? yield t.shift() : yield new Promise((i) => {
|
|
3540
|
+
n = i;
|
|
3541
|
+
});
|
|
3542
|
+
} finally {
|
|
3543
|
+
r();
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
function Cc(e, t = new Uint8Array(32)) {
|
|
3547
|
+
const n = rn(Ne, e, t);
|
|
3548
|
+
return xr(Ne, n, new Uint8Array([1]), 32);
|
|
3549
|
+
}
|
|
3550
|
+
class lt {
|
|
3551
|
+
constructor(t, n) {
|
|
3552
|
+
Q(this, "nostrUnsubscribe");
|
|
3553
|
+
Q(this, "nostrNextUnsubscribe");
|
|
3554
|
+
Q(this, "currentInternalSubscriptionId", 0);
|
|
3555
|
+
Q(this, "internalSubscriptions", /* @__PURE__ */ new Map());
|
|
3556
|
+
Q(this, "name", Math.random().toString(36).substring(2, 6));
|
|
3557
|
+
this.nostrSubscribe = t, this.state = n, this.name = Math.random().toString(36).substring(2, 6);
|
|
3558
|
+
}
|
|
3559
|
+
/**
|
|
3560
|
+
* To preserve forward secrecy, do not use long-term keys for channel initialization. Use e.g. InviteLink to exchange session keys.
|
|
3561
|
+
*/
|
|
3562
|
+
static init(t, n, r, i) {
|
|
3563
|
+
const o = He(), s = {
|
|
3564
|
+
theirCurrentNostrPublicKey: n,
|
|
3565
|
+
ourCurrentNostrKey: { publicKey: Ee(r), privateKey: r },
|
|
3566
|
+
ourNextNostrKey: { publicKey: Ee(o), privateKey: o },
|
|
3567
|
+
receivingChainKey: new Uint8Array(),
|
|
3568
|
+
nextReceivingChainKey: new Uint8Array(),
|
|
3569
|
+
sendingChainKey: new Uint8Array(),
|
|
3570
|
+
sendingChainMessageNumber: 0,
|
|
3571
|
+
receivingChainMessageNumber: 0,
|
|
3572
|
+
previousSendingChainMessageCount: 0,
|
|
3573
|
+
skippedMessageKeys: {}
|
|
3574
|
+
}, c = new lt(t, s);
|
|
3575
|
+
return c.updateTheirCurrentNostrPublicKey(n), i && (c.name = i), c;
|
|
3576
|
+
}
|
|
3577
|
+
updateTheirCurrentNostrPublicKey(t) {
|
|
3578
|
+
this.state.theirCurrentNostrPublicKey = t, this.state.previousSendingChainMessageCount = this.state.sendingChainMessageNumber, this.state.sendingChainMessageNumber = 0, this.state.receivingChainMessageNumber = 0, this.state.receivingChainKey = this.getNostrSenderKeypair(ae.Them, ce.Current).privateKey, this.state.nextReceivingChainKey = this.getNostrSenderKeypair(ae.Them, ce.Next).privateKey, this.state.sendingChainKey = this.getNostrSenderKeypair(ae.Us, ce.Current).privateKey;
|
|
3579
|
+
}
|
|
3580
|
+
rotateOurCurrentNostrKey() {
|
|
3581
|
+
this.state.ourCurrentNostrKey = this.state.ourNextNostrKey;
|
|
3582
|
+
const t = He();
|
|
3583
|
+
this.state.ourNextNostrKey = {
|
|
3584
|
+
publicKey: Ee(t),
|
|
3585
|
+
privateKey: t
|
|
3586
|
+
};
|
|
3587
|
+
}
|
|
3588
|
+
getNostrSenderKeypair(t, n) {
|
|
3589
|
+
if (t === ae.Us && n === ce.Next)
|
|
3590
|
+
throw new Error("We don't have their next key");
|
|
3591
|
+
const r = n === ce.Current ? this.state.ourCurrentNostrKey.privateKey : this.state.ourNextNostrKey.privateKey, i = this.state.theirCurrentNostrPublicKey, o = t === ae.Us ? Ee(r) : i, s = Cc(fe.getConversationKey(r, i), W(o));
|
|
3592
|
+
return {
|
|
3593
|
+
publicKey: Ee(s),
|
|
3594
|
+
privateKey: s
|
|
3595
|
+
};
|
|
3596
|
+
}
|
|
3597
|
+
nostrSubscribeNext() {
|
|
3598
|
+
const t = this.getNostrSenderKeypair(ae.Them, ce.Next).publicKey, n = this.state.nextReceivingChainKey;
|
|
3599
|
+
this.nostrNextUnsubscribe = this.nostrSubscribe({ authors: [t], kinds: [We] }, (r) => {
|
|
3600
|
+
var o;
|
|
3601
|
+
const i = JSON.parse(fe.decrypt(r.content, n));
|
|
3602
|
+
i.nextPublicKey !== this.state.theirCurrentNostrPublicKey && (this.rotateOurCurrentNostrKey(), this.updateTheirCurrentNostrPublicKey(i.nextPublicKey), (o = this.nostrUnsubscribe) == null || o.call(this), this.nostrUnsubscribe = this.nostrNextUnsubscribe, this.nostrSubscribeNext()), this.internalSubscriptions.forEach((s) => s({ id: r.id, data: i.data, pubkey: i.nextPublicKey, time: i.time }));
|
|
3603
|
+
});
|
|
3604
|
+
}
|
|
3605
|
+
subscribeToNostrEvents() {
|
|
3606
|
+
if (this.nostrUnsubscribe)
|
|
3607
|
+
return;
|
|
3608
|
+
const t = this.getNostrSenderKeypair(ae.Them, ce.Current).publicKey, n = this.state.receivingChainKey;
|
|
3609
|
+
this.nostrUnsubscribe = this.nostrSubscribe({ authors: [t], kinds: [We] }, (r) => {
|
|
3610
|
+
const i = JSON.parse(fe.decrypt(r.content, n));
|
|
3611
|
+
i.nextPublicKey !== this.state.theirCurrentNostrPublicKey && this.updateTheirCurrentNostrPublicKey(i.nextPublicKey), this.internalSubscriptions.forEach((o) => o({ id: r.id, data: i.data, pubkey: i.nextPublicKey, time: i.time }));
|
|
3612
|
+
}), this.nostrSubscribeNext();
|
|
3613
|
+
}
|
|
3614
|
+
onMessage(t) {
|
|
3615
|
+
const n = this.currentInternalSubscriptionId++;
|
|
3616
|
+
return this.internalSubscriptions.set(n, t), this.subscribeToNostrEvents(), () => this.internalSubscriptions.delete(n);
|
|
3617
|
+
}
|
|
3618
|
+
send(t) {
|
|
3619
|
+
const n = {
|
|
3620
|
+
number: this.state.sendingChainMessageNumber,
|
|
3621
|
+
data: t,
|
|
3622
|
+
nextPublicKey: this.state.ourNextNostrKey.publicKey,
|
|
3623
|
+
time: Date.now()
|
|
3624
|
+
};
|
|
3625
|
+
this.state.sendingChainMessageNumber++;
|
|
3626
|
+
const r = this.getNostrSenderKeypair(ae.Us, ce.Current).privateKey, i = fe.encrypt(JSON.stringify(n), this.state.sendingChainKey);
|
|
3627
|
+
return se({
|
|
3628
|
+
content: i,
|
|
3629
|
+
kind: We,
|
|
3630
|
+
tags: [],
|
|
3631
|
+
created_at: Math.floor(Date.now() / 1e3)
|
|
3632
|
+
}, r);
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3635
|
+
new TextDecoder("utf-8");
|
|
3636
|
+
new TextEncoder();
|
|
3637
|
+
function tt(e, t) {
|
|
3638
|
+
const n = Le.getSharedSecret(e, "02" + t).subarray(1, 33);
|
|
3639
|
+
return rn(Ne, n, "nip44-v2");
|
|
3640
|
+
}
|
|
3641
|
+
class rt {
|
|
3642
|
+
constructor(t, n, r, i, o, s, c = []) {
|
|
3643
|
+
this.inviterSessionPublicKey = t, this.linkSecret = n, this.inviter = r, this.inviterSessionPrivateKey = i, this.label = o, this.maxUses = s, this.usedBy = c;
|
|
3644
|
+
}
|
|
3645
|
+
static createNew(t, n, r) {
|
|
3646
|
+
const i = He(), o = Ee(i), s = ut.encode(He()).slice(8, 40);
|
|
3647
|
+
return new rt(
|
|
3648
|
+
o,
|
|
3649
|
+
s,
|
|
3650
|
+
t,
|
|
3651
|
+
i,
|
|
3652
|
+
n,
|
|
3653
|
+
r
|
|
3654
|
+
);
|
|
3655
|
+
}
|
|
3656
|
+
static fromUrl(t) {
|
|
3657
|
+
const n = new URL(t), r = n.pathname.slice(1), i = n.searchParams.get("s"), o = n.hash.slice(1);
|
|
3658
|
+
if (!r)
|
|
3659
|
+
throw new Error("Inviter not found in the URL");
|
|
3660
|
+
if (!i)
|
|
3661
|
+
throw new Error("Session key not found in the URL");
|
|
3662
|
+
const s = Fe.decode(r), c = Fe.decode(i);
|
|
3663
|
+
if (typeof s.data != "string")
|
|
3664
|
+
throw new Error("Decoded inviter is not a string");
|
|
3665
|
+
if (typeof c.data != "string")
|
|
3666
|
+
throw new Error("Decoded session key is not a string");
|
|
3667
|
+
const a = s.data, u = c.data;
|
|
3668
|
+
return new rt(u, o, a);
|
|
3669
|
+
}
|
|
3670
|
+
static deserialize(t) {
|
|
3671
|
+
const n = JSON.parse(t);
|
|
3672
|
+
return new rt(
|
|
3673
|
+
n.inviterSessionPublicKey,
|
|
3674
|
+
n.linkSecret,
|
|
3675
|
+
n.inviter,
|
|
3676
|
+
n.inviterSessionPrivateKey ? new Uint8Array(n.inviterSessionPrivateKey) : void 0,
|
|
3677
|
+
n.label,
|
|
3678
|
+
n.maxUses,
|
|
3679
|
+
n.usedBy
|
|
3680
|
+
);
|
|
3681
|
+
}
|
|
3682
|
+
serialize() {
|
|
3683
|
+
return JSON.stringify({
|
|
3684
|
+
inviterSessionPublicKey: this.inviterSessionPublicKey,
|
|
3685
|
+
linkSecret: this.linkSecret,
|
|
3686
|
+
inviter: this.inviter,
|
|
3687
|
+
inviterSessionPrivateKey: this.inviterSessionPrivateKey ? Array.from(this.inviterSessionPrivateKey) : void 0,
|
|
3688
|
+
label: this.label,
|
|
3689
|
+
maxUses: this.maxUses,
|
|
3690
|
+
usedBy: this.usedBy
|
|
3691
|
+
});
|
|
3692
|
+
}
|
|
3693
|
+
getUrl(t = "https://iris.to") {
|
|
3694
|
+
const n = new URL(`${t}/${Fe.npubEncode(this.inviter)}`);
|
|
3695
|
+
return n.searchParams.set("s", Fe.npubEncode(this.inviterSessionPublicKey)), n.hash = this.linkSecret, n.toString();
|
|
3696
|
+
}
|
|
3697
|
+
/**
|
|
3698
|
+
* Accepts the invite and creates a new channel with the inviter.
|
|
3699
|
+
*
|
|
3700
|
+
* @param inviteeSecretKey - The invitee's secret key or a signing function
|
|
3701
|
+
* @param nostrSubscribe - A function to subscribe to Nostr events
|
|
3702
|
+
* @returns An object containing the new channel and an event to be published
|
|
3703
|
+
*
|
|
3704
|
+
* 1. Inner event: No signature, content encrypted with DH(inviter, invitee).
|
|
3705
|
+
* Purpose: Authenticate invitee. Contains invitee session key.
|
|
3706
|
+
* 2. Envelope: No signature, content encrypted with DH(inviter, random key).
|
|
3707
|
+
* Purpose: Contains inner event. Hides invitee from others who might have the shared Nostr key.
|
|
3708
|
+
|
|
3709
|
+
* Note: You need to publish the returned event on Nostr using NDK or another Nostr system of your choice,
|
|
3710
|
+
* so the inviter can create the channel on their side.
|
|
3711
|
+
*/
|
|
3712
|
+
async acceptInvite(t, n, r) {
|
|
3713
|
+
const i = He(), o = Ee(i), s = this.inviter || this.inviterSessionPublicKey, c = lt.init(t, this.inviterSessionPublicKey, i), a = He(), u = Ee(a), f = typeof r == "function" ? r : (w, y) => Promise.resolve(fe.encrypt(w, tt(r, y))), l = {
|
|
3714
|
+
pubkey: n,
|
|
3715
|
+
tags: [["secret", this.linkSecret]],
|
|
3716
|
+
content: await f(o, s),
|
|
3717
|
+
created_at: Math.floor(Date.now() / 1e3)
|
|
3718
|
+
}, d = {
|
|
3719
|
+
kind: We,
|
|
3720
|
+
pubkey: u,
|
|
3721
|
+
content: fe.encrypt(JSON.stringify(l), tt(a, this.inviterSessionPublicKey)),
|
|
3722
|
+
created_at: Math.floor(Date.now() / 1e3),
|
|
3723
|
+
tags: [["p", this.inviterSessionPublicKey]]
|
|
3724
|
+
};
|
|
3725
|
+
return { channel: c, event: se(d, a) };
|
|
3726
|
+
}
|
|
3727
|
+
listen(t, n, r) {
|
|
3728
|
+
if (!this.inviterSessionPrivateKey)
|
|
3729
|
+
throw new Error("Inviter session key is not available");
|
|
3730
|
+
const i = {
|
|
3731
|
+
kinds: [We],
|
|
3732
|
+
"#p": [this.inviterSessionPublicKey]
|
|
3733
|
+
};
|
|
3734
|
+
return n(i, async (o) => {
|
|
3735
|
+
try {
|
|
3736
|
+
const s = await fe.decrypt(o.content, tt(this.inviterSessionPrivateKey, o.pubkey)), c = JSON.parse(s);
|
|
3737
|
+
if (!c.tags || !c.tags.some(([l, d]) => l === "secret" && d === this.linkSecret)) {
|
|
3738
|
+
console.error("Invalid secret from event", o);
|
|
3739
|
+
return;
|
|
3740
|
+
}
|
|
3741
|
+
const u = await (typeof t == "function" ? t : (l, d) => Promise.resolve(fe.decrypt(l, tt(t, d))))(c.content, c.pubkey), f = lt.init(n, u, this.inviterSessionPrivateKey);
|
|
3742
|
+
r(f, c.pubkey);
|
|
3743
|
+
} catch (s) {
|
|
3744
|
+
console.error("Error processing invite message:", s);
|
|
3745
|
+
}
|
|
3746
|
+
});
|
|
3747
|
+
}
|
|
3748
|
+
}
|
|
3749
|
+
export {
|
|
3750
|
+
lt as Channel,
|
|
3751
|
+
We as EVENT_KIND,
|
|
3752
|
+
rt as InviteLink,
|
|
3753
|
+
ce as KeyType,
|
|
3754
|
+
Tc as MAX_SKIP,
|
|
3755
|
+
ae as Sender,
|
|
3756
|
+
Pc as createMessageStream,
|
|
3757
|
+
Rc as deserializeChannelState,
|
|
3758
|
+
Cc as kdf,
|
|
3759
|
+
$c as serializeChannelState
|
|
3760
|
+
};
|