@tinycloud/operations 0.4.0 → 0.5.0-beta.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.
@@ -4,25 +4,30 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
10
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
11
+ var __commonJS = (cb, mod2) => function __require() {
12
+ return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
13
+ };
14
+ var __copyProps = (to, from2, except, desc) => {
15
+ if (from2 && typeof from2 === "object" || typeof from2 === "function") {
16
+ for (let key of __getOwnPropNames(from2))
13
17
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ __defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
15
19
  }
16
20
  return to;
17
21
  };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
19
23
  // If the importer is in node compatibility mode or this is not an ESM
20
24
  // file that has been converted to a CommonJS file using a Babel-
21
25
  // compatible transform (i.e. "__esModule" has not been set), then set
22
26
  // "default" to the CommonJS "module.exports" for node compatibility.
23
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
- mod
27
+ isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
28
+ mod2
25
29
  ));
30
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
26
31
 
27
32
  // ../../node_modules/ms/index.js
28
33
  var require_ms = __commonJS({
@@ -110,188 +115,3508 @@ var require_ms = __commonJS({
110
115
  if (msAbs >= h) {
111
116
  return Math.round(ms2 / h) + "h";
112
117
  }
113
- if (msAbs >= m) {
114
- return Math.round(ms2 / m) + "m";
118
+ if (msAbs >= m) {
119
+ return Math.round(ms2 / m) + "m";
120
+ }
121
+ if (msAbs >= s) {
122
+ return Math.round(ms2 / s) + "s";
123
+ }
124
+ return ms2 + "ms";
125
+ }
126
+ function fmtLong(ms2) {
127
+ var msAbs = Math.abs(ms2);
128
+ if (msAbs >= d) {
129
+ return plural(ms2, msAbs, d, "day");
130
+ }
131
+ if (msAbs >= h) {
132
+ return plural(ms2, msAbs, h, "hour");
133
+ }
134
+ if (msAbs >= m) {
135
+ return plural(ms2, msAbs, m, "minute");
136
+ }
137
+ if (msAbs >= s) {
138
+ return plural(ms2, msAbs, s, "second");
139
+ }
140
+ return ms2 + " ms";
141
+ }
142
+ function plural(ms2, msAbs, n, name) {
143
+ var isPlural = msAbs >= n * 1.5;
144
+ return Math.round(ms2 / n) + " " + name + (isPlural ? "s" : "");
145
+ }
146
+ }
147
+ });
148
+
149
+ // ../../node_modules/@noble/hashes/esm/_u64.js
150
+ function fromBig(n, le = false) {
151
+ if (le)
152
+ return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
153
+ return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
154
+ }
155
+ function split(lst, le = false) {
156
+ const len = lst.length;
157
+ let Ah = new Uint32Array(len);
158
+ let Al = new Uint32Array(len);
159
+ for (let i = 0; i < len; i++) {
160
+ const { h, l } = fromBig(lst[i], le);
161
+ [Ah[i], Al[i]] = [h, l];
162
+ }
163
+ return [Ah, Al];
164
+ }
165
+ function add(Ah, Al, Bh, Bl) {
166
+ const l = (Al >>> 0) + (Bl >>> 0);
167
+ return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
168
+ }
169
+ var U32_MASK64, _32n, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, add3L, add3H, add4L, add4H, add5L, add5H;
170
+ var init_u64 = __esm({
171
+ "../../node_modules/@noble/hashes/esm/_u64.js"() {
172
+ "use strict";
173
+ U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
174
+ _32n = /* @__PURE__ */ BigInt(32);
175
+ shrSH = (h, _l, s) => h >>> s;
176
+ shrSL = (h, l, s) => h << 32 - s | l >>> s;
177
+ rotrSH = (h, l, s) => h >>> s | l << 32 - s;
178
+ rotrSL = (h, l, s) => h << 32 - s | l >>> s;
179
+ rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
180
+ rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
181
+ add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
182
+ add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
183
+ add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
184
+ add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
185
+ add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
186
+ add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
187
+ }
188
+ });
189
+
190
+ // ../../node_modules/@noble/hashes/esm/cryptoNode.js
191
+ import * as nc from "crypto";
192
+ var crypto2;
193
+ var init_cryptoNode = __esm({
194
+ "../../node_modules/@noble/hashes/esm/cryptoNode.js"() {
195
+ "use strict";
196
+ crypto2 = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && "randomBytes" in nc ? nc : void 0;
197
+ }
198
+ });
199
+
200
+ // ../../node_modules/@noble/hashes/esm/utils.js
201
+ function isBytes(a) {
202
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
203
+ }
204
+ function anumber(n) {
205
+ if (!Number.isSafeInteger(n) || n < 0)
206
+ throw new Error("positive integer expected, got " + n);
207
+ }
208
+ function abytes(b, ...lengths) {
209
+ if (!isBytes(b))
210
+ throw new Error("Uint8Array expected");
211
+ if (lengths.length > 0 && !lengths.includes(b.length))
212
+ throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
213
+ }
214
+ function aexists(instance, checkFinished = true) {
215
+ if (instance.destroyed)
216
+ throw new Error("Hash instance has been destroyed");
217
+ if (checkFinished && instance.finished)
218
+ throw new Error("Hash#digest() has already been called");
219
+ }
220
+ function aoutput(out, instance) {
221
+ abytes(out);
222
+ const min = instance.outputLen;
223
+ if (out.length < min) {
224
+ throw new Error("digestInto() expects output buffer of length at least " + min);
225
+ }
226
+ }
227
+ function u8(arr) {
228
+ return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
229
+ }
230
+ function u32(arr) {
231
+ return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
232
+ }
233
+ function clean(...arrays) {
234
+ for (let i = 0; i < arrays.length; i++) {
235
+ arrays[i].fill(0);
236
+ }
237
+ }
238
+ function createView(arr) {
239
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
240
+ }
241
+ function rotr(word, shift) {
242
+ return word << 32 - shift | word >>> shift;
243
+ }
244
+ function byteSwap(word) {
245
+ return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
246
+ }
247
+ function byteSwap32(arr) {
248
+ for (let i = 0; i < arr.length; i++) {
249
+ arr[i] = byteSwap(arr[i]);
250
+ }
251
+ return arr;
252
+ }
253
+ function bytesToHex(bytes) {
254
+ abytes(bytes);
255
+ if (hasHexBuiltin)
256
+ return bytes.toHex();
257
+ let hex = "";
258
+ for (let i = 0; i < bytes.length; i++) {
259
+ hex += hexes[bytes[i]];
260
+ }
261
+ return hex;
262
+ }
263
+ function asciiToBase16(ch) {
264
+ if (ch >= asciis._0 && ch <= asciis._9)
265
+ return ch - asciis._0;
266
+ if (ch >= asciis.A && ch <= asciis.F)
267
+ return ch - (asciis.A - 10);
268
+ if (ch >= asciis.a && ch <= asciis.f)
269
+ return ch - (asciis.a - 10);
270
+ return;
271
+ }
272
+ function hexToBytes(hex) {
273
+ if (typeof hex !== "string")
274
+ throw new Error("hex string expected, got " + typeof hex);
275
+ if (hasHexBuiltin)
276
+ return Uint8Array.fromHex(hex);
277
+ const hl = hex.length;
278
+ const al = hl / 2;
279
+ if (hl % 2)
280
+ throw new Error("hex string expected, got unpadded hex of length " + hl);
281
+ const array = new Uint8Array(al);
282
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
283
+ const n1 = asciiToBase16(hex.charCodeAt(hi));
284
+ const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
285
+ if (n1 === void 0 || n2 === void 0) {
286
+ const char = hex[hi] + hex[hi + 1];
287
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
288
+ }
289
+ array[ai] = n1 * 16 + n2;
290
+ }
291
+ return array;
292
+ }
293
+ function utf8ToBytes(str) {
294
+ if (typeof str !== "string")
295
+ throw new Error("string expected");
296
+ return new Uint8Array(new TextEncoder().encode(str));
297
+ }
298
+ function toBytes(data) {
299
+ if (typeof data === "string")
300
+ data = utf8ToBytes(data);
301
+ abytes(data);
302
+ return data;
303
+ }
304
+ function concatBytes(...arrays) {
305
+ let sum = 0;
306
+ for (let i = 0; i < arrays.length; i++) {
307
+ const a = arrays[i];
308
+ abytes(a);
309
+ sum += a.length;
310
+ }
311
+ const res = new Uint8Array(sum);
312
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
313
+ const a = arrays[i];
314
+ res.set(a, pad);
315
+ pad += a.length;
316
+ }
317
+ return res;
318
+ }
319
+ function createHasher(hashCons) {
320
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
321
+ const tmp = hashCons();
322
+ hashC.outputLen = tmp.outputLen;
323
+ hashC.blockLen = tmp.blockLen;
324
+ hashC.create = () => hashCons();
325
+ return hashC;
326
+ }
327
+ function createXOFer(hashCons) {
328
+ const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
329
+ const tmp = hashCons({});
330
+ hashC.outputLen = tmp.outputLen;
331
+ hashC.blockLen = tmp.blockLen;
332
+ hashC.create = (opts) => hashCons(opts);
333
+ return hashC;
334
+ }
335
+ function randomBytes(bytesLength = 32) {
336
+ if (crypto2 && typeof crypto2.getRandomValues === "function") {
337
+ return crypto2.getRandomValues(new Uint8Array(bytesLength));
338
+ }
339
+ if (crypto2 && typeof crypto2.randomBytes === "function") {
340
+ return Uint8Array.from(crypto2.randomBytes(bytesLength));
341
+ }
342
+ throw new Error("crypto.getRandomValues must be defined");
343
+ }
344
+ var isLE, swap8IfBE, swap32IfBE, hasHexBuiltin, hexes, asciis, Hash;
345
+ var init_utils = __esm({
346
+ "../../node_modules/@noble/hashes/esm/utils.js"() {
347
+ "use strict";
348
+ init_cryptoNode();
349
+ isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
350
+ swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n);
351
+ swap32IfBE = isLE ? (u) => u : byteSwap32;
352
+ hasHexBuiltin = /* @__PURE__ */ (() => (
353
+ // @ts-ignore
354
+ typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
355
+ ))();
356
+ hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
357
+ asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
358
+ Hash = class {
359
+ };
360
+ }
361
+ });
362
+
363
+ // ../../node_modules/@noble/hashes/esm/_md.js
364
+ function setBigUint64(view, byteOffset, value, isLE2) {
365
+ if (typeof view.setBigUint64 === "function")
366
+ return view.setBigUint64(byteOffset, value, isLE2);
367
+ const _32n2 = BigInt(32);
368
+ const _u32_max = BigInt(4294967295);
369
+ const wh = Number(value >> _32n2 & _u32_max);
370
+ const wl = Number(value & _u32_max);
371
+ const h = isLE2 ? 4 : 0;
372
+ const l = isLE2 ? 0 : 4;
373
+ view.setUint32(byteOffset + h, wh, isLE2);
374
+ view.setUint32(byteOffset + l, wl, isLE2);
375
+ }
376
+ var HashMD, SHA256_IV, SHA512_IV;
377
+ var init_md = __esm({
378
+ "../../node_modules/@noble/hashes/esm/_md.js"() {
379
+ "use strict";
380
+ init_utils();
381
+ HashMD = class extends Hash {
382
+ constructor(blockLen, outputLen, padOffset, isLE2) {
383
+ super();
384
+ this.finished = false;
385
+ this.length = 0;
386
+ this.pos = 0;
387
+ this.destroyed = false;
388
+ this.blockLen = blockLen;
389
+ this.outputLen = outputLen;
390
+ this.padOffset = padOffset;
391
+ this.isLE = isLE2;
392
+ this.buffer = new Uint8Array(blockLen);
393
+ this.view = createView(this.buffer);
394
+ }
395
+ update(data) {
396
+ aexists(this);
397
+ data = toBytes(data);
398
+ abytes(data);
399
+ const { view, buffer, blockLen } = this;
400
+ const len = data.length;
401
+ for (let pos = 0; pos < len; ) {
402
+ const take = Math.min(blockLen - this.pos, len - pos);
403
+ if (take === blockLen) {
404
+ const dataView = createView(data);
405
+ for (; blockLen <= len - pos; pos += blockLen)
406
+ this.process(dataView, pos);
407
+ continue;
408
+ }
409
+ buffer.set(data.subarray(pos, pos + take), this.pos);
410
+ this.pos += take;
411
+ pos += take;
412
+ if (this.pos === blockLen) {
413
+ this.process(view, 0);
414
+ this.pos = 0;
415
+ }
416
+ }
417
+ this.length += data.length;
418
+ this.roundClean();
419
+ return this;
420
+ }
421
+ digestInto(out) {
422
+ aexists(this);
423
+ aoutput(out, this);
424
+ this.finished = true;
425
+ const { buffer, view, blockLen, isLE: isLE2 } = this;
426
+ let { pos } = this;
427
+ buffer[pos++] = 128;
428
+ clean(this.buffer.subarray(pos));
429
+ if (this.padOffset > blockLen - pos) {
430
+ this.process(view, 0);
431
+ pos = 0;
432
+ }
433
+ for (let i = pos; i < blockLen; i++)
434
+ buffer[i] = 0;
435
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
436
+ this.process(view, 0);
437
+ const oview = createView(out);
438
+ const len = this.outputLen;
439
+ if (len % 4)
440
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
441
+ const outLen = len / 4;
442
+ const state = this.get();
443
+ if (outLen > state.length)
444
+ throw new Error("_sha2: outputLen bigger than state");
445
+ for (let i = 0; i < outLen; i++)
446
+ oview.setUint32(4 * i, state[i], isLE2);
447
+ }
448
+ digest() {
449
+ const { buffer, outputLen } = this;
450
+ this.digestInto(buffer);
451
+ const res = buffer.slice(0, outputLen);
452
+ this.destroy();
453
+ return res;
454
+ }
455
+ _cloneInto(to) {
456
+ to || (to = new this.constructor());
457
+ to.set(...this.get());
458
+ const { blockLen, buffer, length: length2, finished, destroyed, pos } = this;
459
+ to.destroyed = destroyed;
460
+ to.finished = finished;
461
+ to.length = length2;
462
+ to.pos = pos;
463
+ if (length2 % blockLen)
464
+ to.buffer.set(buffer);
465
+ return to;
466
+ }
467
+ clone() {
468
+ return this._cloneInto();
469
+ }
470
+ };
471
+ SHA256_IV = /* @__PURE__ */ Uint32Array.from([
472
+ 1779033703,
473
+ 3144134277,
474
+ 1013904242,
475
+ 2773480762,
476
+ 1359893119,
477
+ 2600822924,
478
+ 528734635,
479
+ 1541459225
480
+ ]);
481
+ SHA512_IV = /* @__PURE__ */ Uint32Array.from([
482
+ 1779033703,
483
+ 4089235720,
484
+ 3144134277,
485
+ 2227873595,
486
+ 1013904242,
487
+ 4271175723,
488
+ 2773480762,
489
+ 1595750129,
490
+ 1359893119,
491
+ 2917565137,
492
+ 2600822924,
493
+ 725511199,
494
+ 528734635,
495
+ 4215389547,
496
+ 1541459225,
497
+ 327033209
498
+ ]);
499
+ }
500
+ });
501
+
502
+ // ../../node_modules/@noble/hashes/esm/sha2.js
503
+ var K512, SHA512_Kh, SHA512_Kl, SHA512_W_H, SHA512_W_L, SHA512, sha512;
504
+ var init_sha2 = __esm({
505
+ "../../node_modules/@noble/hashes/esm/sha2.js"() {
506
+ "use strict";
507
+ init_md();
508
+ init_u64();
509
+ init_utils();
510
+ K512 = /* @__PURE__ */ (() => split([
511
+ "0x428a2f98d728ae22",
512
+ "0x7137449123ef65cd",
513
+ "0xb5c0fbcfec4d3b2f",
514
+ "0xe9b5dba58189dbbc",
515
+ "0x3956c25bf348b538",
516
+ "0x59f111f1b605d019",
517
+ "0x923f82a4af194f9b",
518
+ "0xab1c5ed5da6d8118",
519
+ "0xd807aa98a3030242",
520
+ "0x12835b0145706fbe",
521
+ "0x243185be4ee4b28c",
522
+ "0x550c7dc3d5ffb4e2",
523
+ "0x72be5d74f27b896f",
524
+ "0x80deb1fe3b1696b1",
525
+ "0x9bdc06a725c71235",
526
+ "0xc19bf174cf692694",
527
+ "0xe49b69c19ef14ad2",
528
+ "0xefbe4786384f25e3",
529
+ "0x0fc19dc68b8cd5b5",
530
+ "0x240ca1cc77ac9c65",
531
+ "0x2de92c6f592b0275",
532
+ "0x4a7484aa6ea6e483",
533
+ "0x5cb0a9dcbd41fbd4",
534
+ "0x76f988da831153b5",
535
+ "0x983e5152ee66dfab",
536
+ "0xa831c66d2db43210",
537
+ "0xb00327c898fb213f",
538
+ "0xbf597fc7beef0ee4",
539
+ "0xc6e00bf33da88fc2",
540
+ "0xd5a79147930aa725",
541
+ "0x06ca6351e003826f",
542
+ "0x142929670a0e6e70",
543
+ "0x27b70a8546d22ffc",
544
+ "0x2e1b21385c26c926",
545
+ "0x4d2c6dfc5ac42aed",
546
+ "0x53380d139d95b3df",
547
+ "0x650a73548baf63de",
548
+ "0x766a0abb3c77b2a8",
549
+ "0x81c2c92e47edaee6",
550
+ "0x92722c851482353b",
551
+ "0xa2bfe8a14cf10364",
552
+ "0xa81a664bbc423001",
553
+ "0xc24b8b70d0f89791",
554
+ "0xc76c51a30654be30",
555
+ "0xd192e819d6ef5218",
556
+ "0xd69906245565a910",
557
+ "0xf40e35855771202a",
558
+ "0x106aa07032bbd1b8",
559
+ "0x19a4c116b8d2d0c8",
560
+ "0x1e376c085141ab53",
561
+ "0x2748774cdf8eeb99",
562
+ "0x34b0bcb5e19b48a8",
563
+ "0x391c0cb3c5c95a63",
564
+ "0x4ed8aa4ae3418acb",
565
+ "0x5b9cca4f7763e373",
566
+ "0x682e6ff3d6b2b8a3",
567
+ "0x748f82ee5defb2fc",
568
+ "0x78a5636f43172f60",
569
+ "0x84c87814a1f0ab72",
570
+ "0x8cc702081a6439ec",
571
+ "0x90befffa23631e28",
572
+ "0xa4506cebde82bde9",
573
+ "0xbef9a3f7b2c67915",
574
+ "0xc67178f2e372532b",
575
+ "0xca273eceea26619c",
576
+ "0xd186b8c721c0c207",
577
+ "0xeada7dd6cde0eb1e",
578
+ "0xf57d4f7fee6ed178",
579
+ "0x06f067aa72176fba",
580
+ "0x0a637dc5a2c898a6",
581
+ "0x113f9804bef90dae",
582
+ "0x1b710b35131c471b",
583
+ "0x28db77f523047d84",
584
+ "0x32caab7b40c72493",
585
+ "0x3c9ebe0a15c9bebc",
586
+ "0x431d67c49c100d4c",
587
+ "0x4cc5d4becb3e42b6",
588
+ "0x597f299cfc657e2a",
589
+ "0x5fcb6fab3ad6faec",
590
+ "0x6c44198c4a475817"
591
+ ].map((n) => BigInt(n))))();
592
+ SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
593
+ SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
594
+ SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
595
+ SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
596
+ SHA512 = class extends HashMD {
597
+ constructor(outputLen = 64) {
598
+ super(128, outputLen, 16, false);
599
+ this.Ah = SHA512_IV[0] | 0;
600
+ this.Al = SHA512_IV[1] | 0;
601
+ this.Bh = SHA512_IV[2] | 0;
602
+ this.Bl = SHA512_IV[3] | 0;
603
+ this.Ch = SHA512_IV[4] | 0;
604
+ this.Cl = SHA512_IV[5] | 0;
605
+ this.Dh = SHA512_IV[6] | 0;
606
+ this.Dl = SHA512_IV[7] | 0;
607
+ this.Eh = SHA512_IV[8] | 0;
608
+ this.El = SHA512_IV[9] | 0;
609
+ this.Fh = SHA512_IV[10] | 0;
610
+ this.Fl = SHA512_IV[11] | 0;
611
+ this.Gh = SHA512_IV[12] | 0;
612
+ this.Gl = SHA512_IV[13] | 0;
613
+ this.Hh = SHA512_IV[14] | 0;
614
+ this.Hl = SHA512_IV[15] | 0;
615
+ }
616
+ // prettier-ignore
617
+ get() {
618
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
619
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
620
+ }
621
+ // prettier-ignore
622
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
623
+ this.Ah = Ah | 0;
624
+ this.Al = Al | 0;
625
+ this.Bh = Bh | 0;
626
+ this.Bl = Bl | 0;
627
+ this.Ch = Ch | 0;
628
+ this.Cl = Cl | 0;
629
+ this.Dh = Dh | 0;
630
+ this.Dl = Dl | 0;
631
+ this.Eh = Eh | 0;
632
+ this.El = El | 0;
633
+ this.Fh = Fh | 0;
634
+ this.Fl = Fl | 0;
635
+ this.Gh = Gh | 0;
636
+ this.Gl = Gl | 0;
637
+ this.Hh = Hh | 0;
638
+ this.Hl = Hl | 0;
639
+ }
640
+ process(view, offset) {
641
+ for (let i = 0; i < 16; i++, offset += 4) {
642
+ SHA512_W_H[i] = view.getUint32(offset);
643
+ SHA512_W_L[i] = view.getUint32(offset += 4);
644
+ }
645
+ for (let i = 16; i < 80; i++) {
646
+ const W15h = SHA512_W_H[i - 15] | 0;
647
+ const W15l = SHA512_W_L[i - 15] | 0;
648
+ const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
649
+ const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
650
+ const W2h = SHA512_W_H[i - 2] | 0;
651
+ const W2l = SHA512_W_L[i - 2] | 0;
652
+ const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
653
+ const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
654
+ const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
655
+ const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
656
+ SHA512_W_H[i] = SUMh | 0;
657
+ SHA512_W_L[i] = SUMl | 0;
658
+ }
659
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
660
+ for (let i = 0; i < 80; i++) {
661
+ const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
662
+ const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
663
+ const CHIh = Eh & Fh ^ ~Eh & Gh;
664
+ const CHIl = El & Fl ^ ~El & Gl;
665
+ const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
666
+ const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
667
+ const T1l = T1ll | 0;
668
+ const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
669
+ const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
670
+ const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
671
+ const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
672
+ Hh = Gh | 0;
673
+ Hl = Gl | 0;
674
+ Gh = Fh | 0;
675
+ Gl = Fl | 0;
676
+ Fh = Eh | 0;
677
+ Fl = El | 0;
678
+ ({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
679
+ Dh = Ch | 0;
680
+ Dl = Cl | 0;
681
+ Ch = Bh | 0;
682
+ Cl = Bl | 0;
683
+ Bh = Ah | 0;
684
+ Bl = Al | 0;
685
+ const All = add3L(T1l, sigma0l, MAJl);
686
+ Ah = add3H(All, T1h, sigma0h, MAJh);
687
+ Al = All | 0;
688
+ }
689
+ ({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
690
+ ({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
691
+ ({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
692
+ ({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
693
+ ({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
694
+ ({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
695
+ ({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
696
+ ({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
697
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
698
+ }
699
+ roundClean() {
700
+ clean(SHA512_W_H, SHA512_W_L);
701
+ }
702
+ destroy() {
703
+ clean(this.buffer);
704
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
705
+ }
706
+ };
707
+ sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
708
+ }
709
+ });
710
+
711
+ // src/delegation-binding.ts
712
+ import { join as join2 } from "path";
713
+
714
+ // ../sdk-core/src/manifest.ts
715
+ var import_ms = __toESM(require_ms(), 1);
716
+ import { resolveSecretPath, SECRET_NAME_RE } from "@tinycloud/sdk-services";
717
+ var DEFAULT_MANIFEST_SPACE = "applications";
718
+ var SERVICE_SHORT_TO_LONG = Object.freeze({
719
+ kv: "tinycloud.kv",
720
+ sql: "tinycloud.sql",
721
+ duckdb: "tinycloud.duckdb",
722
+ capabilities: "tinycloud.capabilities",
723
+ hooks: "tinycloud.hooks",
724
+ encryption: "tinycloud.encryption",
725
+ delegation: "tinycloud.delegation"
726
+ });
727
+ var SERVICE_LONG_TO_SHORT = Object.freeze(
728
+ Object.fromEntries(
729
+ Object.entries(SERVICE_SHORT_TO_LONG).map(([s, l]) => [l, s])
730
+ )
731
+ );
732
+ function expandActionShortNames(service, actions) {
733
+ return actions.map((a) => {
734
+ if (a.includes("/")) {
735
+ return a;
736
+ }
737
+ return `${service}/${a}`;
738
+ });
739
+ }
740
+
741
+ // ../sdk-core/src/capabilities.ts
742
+ function normalizeSpace(space) {
743
+ if (!space.startsWith("tinycloud:")) {
744
+ return space;
745
+ }
746
+ const lastColon = space.lastIndexOf(":");
747
+ if (lastColon === -1 || lastColon === space.length - 1) {
748
+ return space;
749
+ }
750
+ return space.slice(lastColon + 1);
751
+ }
752
+ function isCapabilitySubset(requested, granted) {
753
+ const missing = [];
754
+ for (const req of requested) {
755
+ const matchingScope = granted.filter(
756
+ (entry) => canonicalizeEntryScopeMatches(req, entry)
757
+ );
758
+ const requestedActions = expandActionShortNames(
759
+ req.service,
760
+ req.actions
761
+ );
762
+ const grantedActions = matchingScope.flatMap(
763
+ (entry) => expandActionShortNames(entry.service, entry.actions)
764
+ );
765
+ const covered = requestedActions.every(
766
+ (requestedAction) => grantedActions.some(
767
+ (grantedAction) => actionContains(grantedAction, requestedAction)
768
+ )
769
+ );
770
+ if (!covered) {
771
+ missing.push(cloneEntry(req));
772
+ }
773
+ }
774
+ return { subset: missing.length === 0, missing };
775
+ }
776
+ function canonicalizeEntryScopeMatches(requested, granted) {
777
+ if (requested.service !== granted.service) {
778
+ return false;
779
+ }
780
+ if (normalizeSpace(requested.space ?? DEFAULT_MANIFEST_SPACE) !== normalizeSpace(granted.space ?? DEFAULT_MANIFEST_SPACE)) {
781
+ return false;
782
+ }
783
+ if (!pathContains(granted.path, requested.path)) {
784
+ return false;
785
+ }
786
+ if (!recapCaveatsEqual(requested.caveats, granted.caveats)) {
787
+ return false;
788
+ }
789
+ return true;
790
+ }
791
+ function recapCaveatsEqual(left, right) {
792
+ return canonicalizeRecapCaveats(left) === canonicalizeRecapCaveats(right);
793
+ }
794
+ function canonicalizeRecapCaveats(caveats) {
795
+ const canonicalize = (value) => {
796
+ if (value === null || typeof value === "boolean" || typeof value === "string") {
797
+ return JSON.stringify(value);
798
+ }
799
+ if (typeof value === "number") {
800
+ if (Number.isFinite(value)) return JSON.stringify(value);
801
+ throw new Error("ReCap caveats must contain only JSON values.");
802
+ }
803
+ if (Array.isArray(value)) return `[${value.map(canonicalize).join(",")}]`;
804
+ if (typeof value === "object") {
805
+ const object = value;
806
+ const prototype = Object.getPrototypeOf(object);
807
+ if (prototype !== Object.prototype && prototype !== null) {
808
+ throw new Error("ReCap caveats must contain only JSON values.");
809
+ }
810
+ return `{${Object.keys(object).sort().map(
811
+ (key) => `${JSON.stringify(key)}:${canonicalize(object[key])}`
812
+ ).join(",")}}`;
813
+ }
814
+ throw new Error("ReCap caveats must contain only JSON values.");
815
+ };
816
+ const branches = (caveats ?? []).map(canonicalize).sort();
817
+ if (branches.length === 0 || branches.length === 1 && branches[0] === "{}") {
818
+ return "[]";
819
+ }
820
+ return `[${branches.join(",")}]`;
821
+ }
822
+ var EXPLICIT_ONLY_ACTIONS = {
823
+ "tinycloud.kv/sync": true,
824
+ "tinycloud.kv/retain": true
825
+ };
826
+ function isExplicitOnlyAction(action) {
827
+ return Object.prototype.hasOwnProperty.call(EXPLICIT_ONLY_ACTIONS, action);
828
+ }
829
+ function actionContains(grantedAction, requestedAction) {
830
+ if (grantedAction === requestedAction) return true;
831
+ if (isExplicitOnlyAction(requestedAction)) return false;
832
+ if (grantedAction === "*") return true;
833
+ if (!grantedAction.endsWith("/*")) return false;
834
+ const service = grantedAction.slice(0, -2);
835
+ return requestedAction === service || requestedAction.startsWith(`${service}/`);
836
+ }
837
+ function pathContains(grantedPath, requestedPath) {
838
+ if (grantedPath === "" || grantedPath === "/") {
839
+ return true;
840
+ }
841
+ if (grantedPath.endsWith("/")) {
842
+ return requestedPath.startsWith(grantedPath);
843
+ }
844
+ return requestedPath === grantedPath;
845
+ }
846
+ function cloneEntry(entry) {
847
+ return {
848
+ service: entry.service,
849
+ ...entry.space !== void 0 ? { space: entry.space } : {},
850
+ path: entry.path,
851
+ actions: [...entry.actions],
852
+ ...entry.caveats !== void 0 ? { caveats: JSON.parse(JSON.stringify(entry.caveats)) } : {},
853
+ ...entry.skipPrefix !== void 0 ? { skipPrefix: entry.skipPrefix } : {},
854
+ ...entry.expiry !== void 0 ? { expiry: entry.expiry } : {}
855
+ };
856
+ }
857
+
858
+ // ../../node_modules/@noble/hashes/esm/blake3.js
859
+ init_md();
860
+ init_u64();
861
+
862
+ // ../../node_modules/@noble/hashes/esm/_blake.js
863
+ init_utils();
864
+ function G1s(a, b, c, d, x) {
865
+ a = a + b + x | 0;
866
+ d = rotr(d ^ a, 16);
867
+ c = c + d | 0;
868
+ b = rotr(b ^ c, 12);
869
+ return { a, b, c, d };
870
+ }
871
+ function G2s(a, b, c, d, x) {
872
+ a = a + b + x | 0;
873
+ d = rotr(d ^ a, 8);
874
+ c = c + d | 0;
875
+ b = rotr(b ^ c, 7);
876
+ return { a, b, c, d };
877
+ }
878
+
879
+ // ../../node_modules/@noble/hashes/esm/blake2.js
880
+ init_utils();
881
+ var BLAKE2 = class extends Hash {
882
+ constructor(blockLen, outputLen) {
883
+ super();
884
+ this.finished = false;
885
+ this.destroyed = false;
886
+ this.length = 0;
887
+ this.pos = 0;
888
+ anumber(blockLen);
889
+ anumber(outputLen);
890
+ this.blockLen = blockLen;
891
+ this.outputLen = outputLen;
892
+ this.buffer = new Uint8Array(blockLen);
893
+ this.buffer32 = u32(this.buffer);
894
+ }
895
+ update(data) {
896
+ aexists(this);
897
+ data = toBytes(data);
898
+ abytes(data);
899
+ const { blockLen, buffer, buffer32 } = this;
900
+ const len = data.length;
901
+ const offset = data.byteOffset;
902
+ const buf = data.buffer;
903
+ for (let pos = 0; pos < len; ) {
904
+ if (this.pos === blockLen) {
905
+ swap32IfBE(buffer32);
906
+ this.compress(buffer32, 0, false);
907
+ swap32IfBE(buffer32);
908
+ this.pos = 0;
909
+ }
910
+ const take = Math.min(blockLen - this.pos, len - pos);
911
+ const dataOffset = offset + pos;
912
+ if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
913
+ const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
914
+ swap32IfBE(data32);
915
+ for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
916
+ this.length += blockLen;
917
+ this.compress(data32, pos32, false);
918
+ }
919
+ swap32IfBE(data32);
920
+ continue;
921
+ }
922
+ buffer.set(data.subarray(pos, pos + take), this.pos);
923
+ this.pos += take;
924
+ this.length += take;
925
+ pos += take;
926
+ }
927
+ return this;
928
+ }
929
+ digestInto(out) {
930
+ aexists(this);
931
+ aoutput(out, this);
932
+ const { pos, buffer32 } = this;
933
+ this.finished = true;
934
+ clean(this.buffer.subarray(pos));
935
+ swap32IfBE(buffer32);
936
+ this.compress(buffer32, 0, true);
937
+ swap32IfBE(buffer32);
938
+ const out32 = u32(out);
939
+ this.get().forEach((v, i) => out32[i] = swap8IfBE(v));
940
+ }
941
+ digest() {
942
+ const { buffer, outputLen } = this;
943
+ this.digestInto(buffer);
944
+ const res = buffer.slice(0, outputLen);
945
+ this.destroy();
946
+ return res;
947
+ }
948
+ _cloneInto(to) {
949
+ const { buffer, length: length2, finished, destroyed, outputLen, pos } = this;
950
+ to || (to = new this.constructor({ dkLen: outputLen }));
951
+ to.set(...this.get());
952
+ to.buffer.set(buffer);
953
+ to.destroyed = destroyed;
954
+ to.finished = finished;
955
+ to.length = length2;
956
+ to.pos = pos;
957
+ to.outputLen = outputLen;
958
+ return to;
959
+ }
960
+ clone() {
961
+ return this._cloneInto();
962
+ }
963
+ };
964
+ function compress(s, offset, msg, rounds, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) {
965
+ let j = 0;
966
+ for (let i = 0; i < rounds; i++) {
967
+ ({ a: v0, b: v4, c: v8, d: v12 } = G1s(v0, v4, v8, v12, msg[offset + s[j++]]));
968
+ ({ a: v0, b: v4, c: v8, d: v12 } = G2s(v0, v4, v8, v12, msg[offset + s[j++]]));
969
+ ({ a: v1, b: v5, c: v9, d: v13 } = G1s(v1, v5, v9, v13, msg[offset + s[j++]]));
970
+ ({ a: v1, b: v5, c: v9, d: v13 } = G2s(v1, v5, v9, v13, msg[offset + s[j++]]));
971
+ ({ a: v2, b: v6, c: v10, d: v14 } = G1s(v2, v6, v10, v14, msg[offset + s[j++]]));
972
+ ({ a: v2, b: v6, c: v10, d: v14 } = G2s(v2, v6, v10, v14, msg[offset + s[j++]]));
973
+ ({ a: v3, b: v7, c: v11, d: v15 } = G1s(v3, v7, v11, v15, msg[offset + s[j++]]));
974
+ ({ a: v3, b: v7, c: v11, d: v15 } = G2s(v3, v7, v11, v15, msg[offset + s[j++]]));
975
+ ({ a: v0, b: v5, c: v10, d: v15 } = G1s(v0, v5, v10, v15, msg[offset + s[j++]]));
976
+ ({ a: v0, b: v5, c: v10, d: v15 } = G2s(v0, v5, v10, v15, msg[offset + s[j++]]));
977
+ ({ a: v1, b: v6, c: v11, d: v12 } = G1s(v1, v6, v11, v12, msg[offset + s[j++]]));
978
+ ({ a: v1, b: v6, c: v11, d: v12 } = G2s(v1, v6, v11, v12, msg[offset + s[j++]]));
979
+ ({ a: v2, b: v7, c: v8, d: v13 } = G1s(v2, v7, v8, v13, msg[offset + s[j++]]));
980
+ ({ a: v2, b: v7, c: v8, d: v13 } = G2s(v2, v7, v8, v13, msg[offset + s[j++]]));
981
+ ({ a: v3, b: v4, c: v9, d: v14 } = G1s(v3, v4, v9, v14, msg[offset + s[j++]]));
982
+ ({ a: v3, b: v4, c: v9, d: v14 } = G2s(v3, v4, v9, v14, msg[offset + s[j++]]));
983
+ }
984
+ return { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 };
985
+ }
986
+
987
+ // ../../node_modules/@noble/hashes/esm/blake3.js
988
+ init_utils();
989
+ var B3_Flags = {
990
+ CHUNK_START: 1,
991
+ CHUNK_END: 2,
992
+ PARENT: 4,
993
+ ROOT: 8,
994
+ KEYED_HASH: 16,
995
+ DERIVE_KEY_CONTEXT: 32,
996
+ DERIVE_KEY_MATERIAL: 64
997
+ };
998
+ var B3_IV = SHA256_IV.slice();
999
+ var B3_SIGMA = /* @__PURE__ */ (() => {
1000
+ const Id = Array.from({ length: 16 }, (_, i) => i);
1001
+ const permute = (arr) => [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8].map((i) => arr[i]);
1002
+ const res = [];
1003
+ for (let i = 0, v = Id; i < 7; i++, v = permute(v))
1004
+ res.push(...v);
1005
+ return Uint8Array.from(res);
1006
+ })();
1007
+ var BLAKE3 = class _BLAKE3 extends BLAKE2 {
1008
+ constructor(opts = {}, flags = 0) {
1009
+ super(64, opts.dkLen === void 0 ? 32 : opts.dkLen);
1010
+ this.chunkPos = 0;
1011
+ this.chunksDone = 0;
1012
+ this.flags = 0 | 0;
1013
+ this.stack = [];
1014
+ this.posOut = 0;
1015
+ this.bufferOut32 = new Uint32Array(16);
1016
+ this.chunkOut = 0;
1017
+ this.enableXOF = true;
1018
+ const { key, context } = opts;
1019
+ const hasContext = context !== void 0;
1020
+ if (key !== void 0) {
1021
+ if (hasContext)
1022
+ throw new Error('Only "key" or "context" can be specified at same time');
1023
+ const k = toBytes(key).slice();
1024
+ abytes(k, 32);
1025
+ this.IV = u32(k);
1026
+ swap32IfBE(this.IV);
1027
+ this.flags = flags | B3_Flags.KEYED_HASH;
1028
+ } else if (hasContext) {
1029
+ const ctx = toBytes(context);
1030
+ const contextKey = new _BLAKE3({ dkLen: 32 }, B3_Flags.DERIVE_KEY_CONTEXT).update(ctx).digest();
1031
+ this.IV = u32(contextKey);
1032
+ swap32IfBE(this.IV);
1033
+ this.flags = flags | B3_Flags.DERIVE_KEY_MATERIAL;
1034
+ } else {
1035
+ this.IV = B3_IV.slice();
1036
+ this.flags = flags;
1037
+ }
1038
+ this.state = this.IV.slice();
1039
+ this.bufferOut = u8(this.bufferOut32);
1040
+ }
1041
+ // Unused
1042
+ get() {
1043
+ return [];
1044
+ }
1045
+ set() {
1046
+ }
1047
+ b2Compress(counter, flags, buf, bufPos = 0) {
1048
+ const { state: s, pos } = this;
1049
+ const { h, l } = fromBig(BigInt(counter), true);
1050
+ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(B3_SIGMA, bufPos, buf, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], B3_IV[0], B3_IV[1], B3_IV[2], B3_IV[3], h, l, pos, flags);
1051
+ s[0] = v0 ^ v8;
1052
+ s[1] = v1 ^ v9;
1053
+ s[2] = v2 ^ v10;
1054
+ s[3] = v3 ^ v11;
1055
+ s[4] = v4 ^ v12;
1056
+ s[5] = v5 ^ v13;
1057
+ s[6] = v6 ^ v14;
1058
+ s[7] = v7 ^ v15;
1059
+ }
1060
+ compress(buf, bufPos = 0, isLast = false) {
1061
+ let flags = this.flags;
1062
+ if (!this.chunkPos)
1063
+ flags |= B3_Flags.CHUNK_START;
1064
+ if (this.chunkPos === 15 || isLast)
1065
+ flags |= B3_Flags.CHUNK_END;
1066
+ if (!isLast)
1067
+ this.pos = this.blockLen;
1068
+ this.b2Compress(this.chunksDone, flags, buf, bufPos);
1069
+ this.chunkPos += 1;
1070
+ if (this.chunkPos === 16 || isLast) {
1071
+ let chunk = this.state;
1072
+ this.state = this.IV.slice();
1073
+ for (let last, chunks = this.chunksDone + 1; isLast || !(chunks & 1); chunks >>= 1) {
1074
+ if (!(last = this.stack.pop()))
1075
+ break;
1076
+ this.buffer32.set(last, 0);
1077
+ this.buffer32.set(chunk, 8);
1078
+ this.pos = this.blockLen;
1079
+ this.b2Compress(0, this.flags | B3_Flags.PARENT, this.buffer32, 0);
1080
+ chunk = this.state;
1081
+ this.state = this.IV.slice();
1082
+ }
1083
+ this.chunksDone++;
1084
+ this.chunkPos = 0;
1085
+ this.stack.push(chunk);
1086
+ }
1087
+ this.pos = 0;
1088
+ }
1089
+ _cloneInto(to) {
1090
+ to = super._cloneInto(to);
1091
+ const { IV, flags, state, chunkPos, posOut, chunkOut, stack, chunksDone } = this;
1092
+ to.state.set(state.slice());
1093
+ to.stack = stack.map((i) => Uint32Array.from(i));
1094
+ to.IV.set(IV);
1095
+ to.flags = flags;
1096
+ to.chunkPos = chunkPos;
1097
+ to.chunksDone = chunksDone;
1098
+ to.posOut = posOut;
1099
+ to.chunkOut = chunkOut;
1100
+ to.enableXOF = this.enableXOF;
1101
+ to.bufferOut32.set(this.bufferOut32);
1102
+ return to;
1103
+ }
1104
+ destroy() {
1105
+ this.destroyed = true;
1106
+ clean(this.state, this.buffer32, this.IV, this.bufferOut32);
1107
+ clean(...this.stack);
1108
+ }
1109
+ // Same as b2Compress, but doesn't modify state and returns 16 u32 array (instead of 8)
1110
+ b2CompressOut() {
1111
+ const { state: s, pos, flags, buffer32, bufferOut32: out32 } = this;
1112
+ const { h, l } = fromBig(BigInt(this.chunkOut++));
1113
+ swap32IfBE(buffer32);
1114
+ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(B3_SIGMA, 0, buffer32, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], B3_IV[0], B3_IV[1], B3_IV[2], B3_IV[3], l, h, pos, flags);
1115
+ out32[0] = v0 ^ v8;
1116
+ out32[1] = v1 ^ v9;
1117
+ out32[2] = v2 ^ v10;
1118
+ out32[3] = v3 ^ v11;
1119
+ out32[4] = v4 ^ v12;
1120
+ out32[5] = v5 ^ v13;
1121
+ out32[6] = v6 ^ v14;
1122
+ out32[7] = v7 ^ v15;
1123
+ out32[8] = s[0] ^ v8;
1124
+ out32[9] = s[1] ^ v9;
1125
+ out32[10] = s[2] ^ v10;
1126
+ out32[11] = s[3] ^ v11;
1127
+ out32[12] = s[4] ^ v12;
1128
+ out32[13] = s[5] ^ v13;
1129
+ out32[14] = s[6] ^ v14;
1130
+ out32[15] = s[7] ^ v15;
1131
+ swap32IfBE(buffer32);
1132
+ swap32IfBE(out32);
1133
+ this.posOut = 0;
1134
+ }
1135
+ finish() {
1136
+ if (this.finished)
1137
+ return;
1138
+ this.finished = true;
1139
+ clean(this.buffer.subarray(this.pos));
1140
+ let flags = this.flags | B3_Flags.ROOT;
1141
+ if (this.stack.length) {
1142
+ flags |= B3_Flags.PARENT;
1143
+ swap32IfBE(this.buffer32);
1144
+ this.compress(this.buffer32, 0, true);
1145
+ swap32IfBE(this.buffer32);
1146
+ this.chunksDone = 0;
1147
+ this.pos = this.blockLen;
1148
+ } else {
1149
+ flags |= (!this.chunkPos ? B3_Flags.CHUNK_START : 0) | B3_Flags.CHUNK_END;
1150
+ }
1151
+ this.flags = flags;
1152
+ this.b2CompressOut();
1153
+ }
1154
+ writeInto(out) {
1155
+ aexists(this, false);
1156
+ abytes(out);
1157
+ this.finish();
1158
+ const { blockLen, bufferOut } = this;
1159
+ for (let pos = 0, len = out.length; pos < len; ) {
1160
+ if (this.posOut >= blockLen)
1161
+ this.b2CompressOut();
1162
+ const take = Math.min(blockLen - this.posOut, len - pos);
1163
+ out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
1164
+ this.posOut += take;
1165
+ pos += take;
1166
+ }
1167
+ return out;
1168
+ }
1169
+ xofInto(out) {
1170
+ if (!this.enableXOF)
1171
+ throw new Error("XOF is not possible after digest call");
1172
+ return this.writeInto(out);
1173
+ }
1174
+ xof(bytes) {
1175
+ anumber(bytes);
1176
+ return this.xofInto(new Uint8Array(bytes));
1177
+ }
1178
+ digestInto(out) {
1179
+ aoutput(out, this);
1180
+ if (this.finished)
1181
+ throw new Error("digest() was already called");
1182
+ this.enableXOF = false;
1183
+ this.writeInto(out);
1184
+ this.destroy();
1185
+ return out;
1186
+ }
1187
+ digest() {
1188
+ return this.digestInto(new Uint8Array(this.outputLen));
1189
+ }
1190
+ };
1191
+ var blake3 = /* @__PURE__ */ createXOFer((opts) => new BLAKE3(opts));
1192
+
1193
+ // ../../node_modules/@noble/curves/esm/ed25519.js
1194
+ init_sha2();
1195
+ init_utils();
1196
+
1197
+ // ../../node_modules/@noble/curves/esm/utils.js
1198
+ init_utils();
1199
+ init_utils();
1200
+ var _0n = /* @__PURE__ */ BigInt(0);
1201
+ var _1n = /* @__PURE__ */ BigInt(1);
1202
+ function _abool2(value, title = "") {
1203
+ if (typeof value !== "boolean") {
1204
+ const prefix = title && `"${title}"`;
1205
+ throw new Error(prefix + "expected boolean, got type=" + typeof value);
1206
+ }
1207
+ return value;
1208
+ }
1209
+ function _abytes2(value, length2, title = "") {
1210
+ const bytes = isBytes(value);
1211
+ const len = value?.length;
1212
+ const needsLen = length2 !== void 0;
1213
+ if (!bytes || needsLen && len !== length2) {
1214
+ const prefix = title && `"${title}" `;
1215
+ const ofLen = needsLen ? ` of length ${length2}` : "";
1216
+ const got = bytes ? `length=${len}` : `type=${typeof value}`;
1217
+ throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
1218
+ }
1219
+ return value;
1220
+ }
1221
+ function hexToNumber(hex) {
1222
+ if (typeof hex !== "string")
1223
+ throw new Error("hex string expected, got " + typeof hex);
1224
+ return hex === "" ? _0n : BigInt("0x" + hex);
1225
+ }
1226
+ function bytesToNumberBE(bytes) {
1227
+ return hexToNumber(bytesToHex(bytes));
1228
+ }
1229
+ function bytesToNumberLE(bytes) {
1230
+ abytes(bytes);
1231
+ return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
1232
+ }
1233
+ function numberToBytesBE(n, len) {
1234
+ return hexToBytes(n.toString(16).padStart(len * 2, "0"));
1235
+ }
1236
+ function numberToBytesLE(n, len) {
1237
+ return numberToBytesBE(n, len).reverse();
1238
+ }
1239
+ function ensureBytes(title, hex, expectedLength) {
1240
+ let res;
1241
+ if (typeof hex === "string") {
1242
+ try {
1243
+ res = hexToBytes(hex);
1244
+ } catch (e) {
1245
+ throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
1246
+ }
1247
+ } else if (isBytes(hex)) {
1248
+ res = Uint8Array.from(hex);
1249
+ } else {
1250
+ throw new Error(title + " must be hex string or Uint8Array");
1251
+ }
1252
+ const len = res.length;
1253
+ if (typeof expectedLength === "number" && len !== expectedLength)
1254
+ throw new Error(title + " of length " + expectedLength + " expected, got " + len);
1255
+ return res;
1256
+ }
1257
+ function equalBytes(a, b) {
1258
+ if (a.length !== b.length)
1259
+ return false;
1260
+ let diff = 0;
1261
+ for (let i = 0; i < a.length; i++)
1262
+ diff |= a[i] ^ b[i];
1263
+ return diff === 0;
1264
+ }
1265
+ function copyBytes(bytes) {
1266
+ return Uint8Array.from(bytes);
1267
+ }
1268
+ var isPosBig = (n) => typeof n === "bigint" && _0n <= n;
1269
+ function inRange(n, min, max) {
1270
+ return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
1271
+ }
1272
+ function aInRange(title, n, min, max) {
1273
+ if (!inRange(n, min, max))
1274
+ throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
1275
+ }
1276
+ function bitLen(n) {
1277
+ let len;
1278
+ for (len = 0; n > _0n; n >>= _1n, len += 1)
1279
+ ;
1280
+ return len;
1281
+ }
1282
+ var bitMask = (n) => (_1n << BigInt(n)) - _1n;
1283
+ function _validateObject(object, fields, optFields = {}) {
1284
+ if (!object || typeof object !== "object")
1285
+ throw new Error("expected valid options object");
1286
+ function checkField(fieldName, expectedType, isOpt) {
1287
+ const val = object[fieldName];
1288
+ if (isOpt && val === void 0)
1289
+ return;
1290
+ const current = typeof val;
1291
+ if (current !== expectedType || val === null)
1292
+ throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
1293
+ }
1294
+ Object.entries(fields).forEach(([k, v]) => checkField(k, v, false));
1295
+ Object.entries(optFields).forEach(([k, v]) => checkField(k, v, true));
1296
+ }
1297
+ var notImplemented = () => {
1298
+ throw new Error("not implemented");
1299
+ };
1300
+ function memoized(fn) {
1301
+ const map = /* @__PURE__ */ new WeakMap();
1302
+ return (arg, ...args) => {
1303
+ const val = map.get(arg);
1304
+ if (val !== void 0)
1305
+ return val;
1306
+ const computed = fn(arg, ...args);
1307
+ map.set(arg, computed);
1308
+ return computed;
1309
+ };
1310
+ }
1311
+
1312
+ // ../../node_modules/@noble/curves/esm/abstract/modular.js
1313
+ var _0n2 = BigInt(0);
1314
+ var _1n2 = BigInt(1);
1315
+ var _2n = /* @__PURE__ */ BigInt(2);
1316
+ var _3n = /* @__PURE__ */ BigInt(3);
1317
+ var _4n = /* @__PURE__ */ BigInt(4);
1318
+ var _5n = /* @__PURE__ */ BigInt(5);
1319
+ var _7n = /* @__PURE__ */ BigInt(7);
1320
+ var _8n = /* @__PURE__ */ BigInt(8);
1321
+ var _9n = /* @__PURE__ */ BigInt(9);
1322
+ var _16n = /* @__PURE__ */ BigInt(16);
1323
+ function mod(a, b) {
1324
+ const result = a % b;
1325
+ return result >= _0n2 ? result : b + result;
1326
+ }
1327
+ function pow2(x, power, modulo) {
1328
+ let res = x;
1329
+ while (power-- > _0n2) {
1330
+ res *= res;
1331
+ res %= modulo;
1332
+ }
1333
+ return res;
1334
+ }
1335
+ function invert(number, modulo) {
1336
+ if (number === _0n2)
1337
+ throw new Error("invert: expected non-zero number");
1338
+ if (modulo <= _0n2)
1339
+ throw new Error("invert: expected positive modulus, got " + modulo);
1340
+ let a = mod(number, modulo);
1341
+ let b = modulo;
1342
+ let x = _0n2, y = _1n2, u = _1n2, v = _0n2;
1343
+ while (a !== _0n2) {
1344
+ const q = b / a;
1345
+ const r = b % a;
1346
+ const m = x - u * q;
1347
+ const n = y - v * q;
1348
+ b = a, a = r, x = u, y = v, u = m, v = n;
1349
+ }
1350
+ const gcd = b;
1351
+ if (gcd !== _1n2)
1352
+ throw new Error("invert: does not exist");
1353
+ return mod(x, modulo);
1354
+ }
1355
+ function assertIsSquare(Fp2, root, n) {
1356
+ if (!Fp2.eql(Fp2.sqr(root), n))
1357
+ throw new Error("Cannot find square root");
1358
+ }
1359
+ function sqrt3mod4(Fp2, n) {
1360
+ const p1div4 = (Fp2.ORDER + _1n2) / _4n;
1361
+ const root = Fp2.pow(n, p1div4);
1362
+ assertIsSquare(Fp2, root, n);
1363
+ return root;
1364
+ }
1365
+ function sqrt5mod8(Fp2, n) {
1366
+ const p5div8 = (Fp2.ORDER - _5n) / _8n;
1367
+ const n2 = Fp2.mul(n, _2n);
1368
+ const v = Fp2.pow(n2, p5div8);
1369
+ const nv = Fp2.mul(n, v);
1370
+ const i = Fp2.mul(Fp2.mul(nv, _2n), v);
1371
+ const root = Fp2.mul(nv, Fp2.sub(i, Fp2.ONE));
1372
+ assertIsSquare(Fp2, root, n);
1373
+ return root;
1374
+ }
1375
+ function sqrt9mod16(P) {
1376
+ const Fp_ = Field(P);
1377
+ const tn = tonelliShanks(P);
1378
+ const c1 = tn(Fp_, Fp_.neg(Fp_.ONE));
1379
+ const c2 = tn(Fp_, c1);
1380
+ const c3 = tn(Fp_, Fp_.neg(c1));
1381
+ const c4 = (P + _7n) / _16n;
1382
+ return (Fp2, n) => {
1383
+ let tv1 = Fp2.pow(n, c4);
1384
+ let tv2 = Fp2.mul(tv1, c1);
1385
+ const tv3 = Fp2.mul(tv1, c2);
1386
+ const tv4 = Fp2.mul(tv1, c3);
1387
+ const e1 = Fp2.eql(Fp2.sqr(tv2), n);
1388
+ const e2 = Fp2.eql(Fp2.sqr(tv3), n);
1389
+ tv1 = Fp2.cmov(tv1, tv2, e1);
1390
+ tv2 = Fp2.cmov(tv4, tv3, e2);
1391
+ const e3 = Fp2.eql(Fp2.sqr(tv2), n);
1392
+ const root = Fp2.cmov(tv1, tv2, e3);
1393
+ assertIsSquare(Fp2, root, n);
1394
+ return root;
1395
+ };
1396
+ }
1397
+ function tonelliShanks(P) {
1398
+ if (P < _3n)
1399
+ throw new Error("sqrt is not defined for small field");
1400
+ let Q = P - _1n2;
1401
+ let S = 0;
1402
+ while (Q % _2n === _0n2) {
1403
+ Q /= _2n;
1404
+ S++;
1405
+ }
1406
+ let Z = _2n;
1407
+ const _Fp = Field(P);
1408
+ while (FpLegendre(_Fp, Z) === 1) {
1409
+ if (Z++ > 1e3)
1410
+ throw new Error("Cannot find square root: probably non-prime P");
1411
+ }
1412
+ if (S === 1)
1413
+ return sqrt3mod4;
1414
+ let cc = _Fp.pow(Z, Q);
1415
+ const Q1div2 = (Q + _1n2) / _2n;
1416
+ return function tonelliSlow(Fp2, n) {
1417
+ if (Fp2.is0(n))
1418
+ return n;
1419
+ if (FpLegendre(Fp2, n) !== 1)
1420
+ throw new Error("Cannot find square root");
1421
+ let M = S;
1422
+ let c = Fp2.mul(Fp2.ONE, cc);
1423
+ let t = Fp2.pow(n, Q);
1424
+ let R = Fp2.pow(n, Q1div2);
1425
+ while (!Fp2.eql(t, Fp2.ONE)) {
1426
+ if (Fp2.is0(t))
1427
+ return Fp2.ZERO;
1428
+ let i = 1;
1429
+ let t_tmp = Fp2.sqr(t);
1430
+ while (!Fp2.eql(t_tmp, Fp2.ONE)) {
1431
+ i++;
1432
+ t_tmp = Fp2.sqr(t_tmp);
1433
+ if (i === M)
1434
+ throw new Error("Cannot find square root");
1435
+ }
1436
+ const exponent = _1n2 << BigInt(M - i - 1);
1437
+ const b = Fp2.pow(c, exponent);
1438
+ M = i;
1439
+ c = Fp2.sqr(b);
1440
+ t = Fp2.mul(t, c);
1441
+ R = Fp2.mul(R, b);
1442
+ }
1443
+ return R;
1444
+ };
1445
+ }
1446
+ function FpSqrt(P) {
1447
+ if (P % _4n === _3n)
1448
+ return sqrt3mod4;
1449
+ if (P % _8n === _5n)
1450
+ return sqrt5mod8;
1451
+ if (P % _16n === _9n)
1452
+ return sqrt9mod16(P);
1453
+ return tonelliShanks(P);
1454
+ }
1455
+ var isNegativeLE = (num, modulo) => (mod(num, modulo) & _1n2) === _1n2;
1456
+ var FIELD_FIELDS = [
1457
+ "create",
1458
+ "isValid",
1459
+ "is0",
1460
+ "neg",
1461
+ "inv",
1462
+ "sqrt",
1463
+ "sqr",
1464
+ "eql",
1465
+ "add",
1466
+ "sub",
1467
+ "mul",
1468
+ "pow",
1469
+ "div",
1470
+ "addN",
1471
+ "subN",
1472
+ "mulN",
1473
+ "sqrN"
1474
+ ];
1475
+ function validateField(field) {
1476
+ const initial = {
1477
+ ORDER: "bigint",
1478
+ MASK: "bigint",
1479
+ BYTES: "number",
1480
+ BITS: "number"
1481
+ };
1482
+ const opts = FIELD_FIELDS.reduce((map, val) => {
1483
+ map[val] = "function";
1484
+ return map;
1485
+ }, initial);
1486
+ _validateObject(field, opts);
1487
+ return field;
1488
+ }
1489
+ function FpPow(Fp2, num, power) {
1490
+ if (power < _0n2)
1491
+ throw new Error("invalid exponent, negatives unsupported");
1492
+ if (power === _0n2)
1493
+ return Fp2.ONE;
1494
+ if (power === _1n2)
1495
+ return num;
1496
+ let p = Fp2.ONE;
1497
+ let d = num;
1498
+ while (power > _0n2) {
1499
+ if (power & _1n2)
1500
+ p = Fp2.mul(p, d);
1501
+ d = Fp2.sqr(d);
1502
+ power >>= _1n2;
1503
+ }
1504
+ return p;
1505
+ }
1506
+ function FpInvertBatch(Fp2, nums, passZero = false) {
1507
+ const inverted = new Array(nums.length).fill(passZero ? Fp2.ZERO : void 0);
1508
+ const multipliedAcc = nums.reduce((acc, num, i) => {
1509
+ if (Fp2.is0(num))
1510
+ return acc;
1511
+ inverted[i] = acc;
1512
+ return Fp2.mul(acc, num);
1513
+ }, Fp2.ONE);
1514
+ const invertedAcc = Fp2.inv(multipliedAcc);
1515
+ nums.reduceRight((acc, num, i) => {
1516
+ if (Fp2.is0(num))
1517
+ return acc;
1518
+ inverted[i] = Fp2.mul(acc, inverted[i]);
1519
+ return Fp2.mul(acc, num);
1520
+ }, invertedAcc);
1521
+ return inverted;
1522
+ }
1523
+ function FpLegendre(Fp2, n) {
1524
+ const p1mod2 = (Fp2.ORDER - _1n2) / _2n;
1525
+ const powered = Fp2.pow(n, p1mod2);
1526
+ const yes = Fp2.eql(powered, Fp2.ONE);
1527
+ const zero = Fp2.eql(powered, Fp2.ZERO);
1528
+ const no = Fp2.eql(powered, Fp2.neg(Fp2.ONE));
1529
+ if (!yes && !zero && !no)
1530
+ throw new Error("invalid Legendre symbol result");
1531
+ return yes ? 1 : zero ? 0 : -1;
1532
+ }
1533
+ function nLength(n, nBitLength) {
1534
+ if (nBitLength !== void 0)
1535
+ anumber(nBitLength);
1536
+ const _nBitLength = nBitLength !== void 0 ? nBitLength : n.toString(2).length;
1537
+ const nByteLength = Math.ceil(_nBitLength / 8);
1538
+ return { nBitLength: _nBitLength, nByteLength };
1539
+ }
1540
+ function Field(ORDER, bitLenOrOpts, isLE2 = false, opts = {}) {
1541
+ if (ORDER <= _0n2)
1542
+ throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
1543
+ let _nbitLength = void 0;
1544
+ let _sqrt = void 0;
1545
+ let modFromBytes = false;
1546
+ let allowedLengths = void 0;
1547
+ if (typeof bitLenOrOpts === "object" && bitLenOrOpts != null) {
1548
+ if (opts.sqrt || isLE2)
1549
+ throw new Error("cannot specify opts in two arguments");
1550
+ const _opts = bitLenOrOpts;
1551
+ if (_opts.BITS)
1552
+ _nbitLength = _opts.BITS;
1553
+ if (_opts.sqrt)
1554
+ _sqrt = _opts.sqrt;
1555
+ if (typeof _opts.isLE === "boolean")
1556
+ isLE2 = _opts.isLE;
1557
+ if (typeof _opts.modFromBytes === "boolean")
1558
+ modFromBytes = _opts.modFromBytes;
1559
+ allowedLengths = _opts.allowedLengths;
1560
+ } else {
1561
+ if (typeof bitLenOrOpts === "number")
1562
+ _nbitLength = bitLenOrOpts;
1563
+ if (opts.sqrt)
1564
+ _sqrt = opts.sqrt;
1565
+ }
1566
+ const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, _nbitLength);
1567
+ if (BYTES > 2048)
1568
+ throw new Error("invalid field: expected ORDER of <= 2048 bytes");
1569
+ let sqrtP;
1570
+ const f = Object.freeze({
1571
+ ORDER,
1572
+ isLE: isLE2,
1573
+ BITS,
1574
+ BYTES,
1575
+ MASK: bitMask(BITS),
1576
+ ZERO: _0n2,
1577
+ ONE: _1n2,
1578
+ allowedLengths,
1579
+ create: (num) => mod(num, ORDER),
1580
+ isValid: (num) => {
1581
+ if (typeof num !== "bigint")
1582
+ throw new Error("invalid field element: expected bigint, got " + typeof num);
1583
+ return _0n2 <= num && num < ORDER;
1584
+ },
1585
+ is0: (num) => num === _0n2,
1586
+ // is valid and invertible
1587
+ isValidNot0: (num) => !f.is0(num) && f.isValid(num),
1588
+ isOdd: (num) => (num & _1n2) === _1n2,
1589
+ neg: (num) => mod(-num, ORDER),
1590
+ eql: (lhs, rhs) => lhs === rhs,
1591
+ sqr: (num) => mod(num * num, ORDER),
1592
+ add: (lhs, rhs) => mod(lhs + rhs, ORDER),
1593
+ sub: (lhs, rhs) => mod(lhs - rhs, ORDER),
1594
+ mul: (lhs, rhs) => mod(lhs * rhs, ORDER),
1595
+ pow: (num, power) => FpPow(f, num, power),
1596
+ div: (lhs, rhs) => mod(lhs * invert(rhs, ORDER), ORDER),
1597
+ // Same as above, but doesn't normalize
1598
+ sqrN: (num) => num * num,
1599
+ addN: (lhs, rhs) => lhs + rhs,
1600
+ subN: (lhs, rhs) => lhs - rhs,
1601
+ mulN: (lhs, rhs) => lhs * rhs,
1602
+ inv: (num) => invert(num, ORDER),
1603
+ sqrt: _sqrt || ((n) => {
1604
+ if (!sqrtP)
1605
+ sqrtP = FpSqrt(ORDER);
1606
+ return sqrtP(f, n);
1607
+ }),
1608
+ toBytes: (num) => isLE2 ? numberToBytesLE(num, BYTES) : numberToBytesBE(num, BYTES),
1609
+ fromBytes: (bytes, skipValidation = true) => {
1610
+ if (allowedLengths) {
1611
+ if (!allowedLengths.includes(bytes.length) || bytes.length > BYTES) {
1612
+ throw new Error("Field.fromBytes: expected " + allowedLengths + " bytes, got " + bytes.length);
1613
+ }
1614
+ const padded = new Uint8Array(BYTES);
1615
+ padded.set(bytes, isLE2 ? 0 : padded.length - bytes.length);
1616
+ bytes = padded;
1617
+ }
1618
+ if (bytes.length !== BYTES)
1619
+ throw new Error("Field.fromBytes: expected " + BYTES + " bytes, got " + bytes.length);
1620
+ let scalar = isLE2 ? bytesToNumberLE(bytes) : bytesToNumberBE(bytes);
1621
+ if (modFromBytes)
1622
+ scalar = mod(scalar, ORDER);
1623
+ if (!skipValidation) {
1624
+ if (!f.isValid(scalar))
1625
+ throw new Error("invalid field element: outside of range 0..ORDER");
1626
+ }
1627
+ return scalar;
1628
+ },
1629
+ // TODO: we don't need it here, move out to separate fn
1630
+ invertBatch: (lst) => FpInvertBatch(f, lst),
1631
+ // We can't move this out because Fp6, Fp12 implement it
1632
+ // and it's unclear what to return in there.
1633
+ cmov: (a, b, c) => c ? b : a
1634
+ });
1635
+ return Object.freeze(f);
1636
+ }
1637
+
1638
+ // ../../node_modules/@noble/curves/esm/abstract/curve.js
1639
+ var _0n3 = BigInt(0);
1640
+ var _1n3 = BigInt(1);
1641
+ function negateCt(condition, item) {
1642
+ const neg = item.negate();
1643
+ return condition ? neg : item;
1644
+ }
1645
+ function normalizeZ(c, points) {
1646
+ const invertedZs = FpInvertBatch(c.Fp, points.map((p) => p.Z));
1647
+ return points.map((p, i) => c.fromAffine(p.toAffine(invertedZs[i])));
1648
+ }
1649
+ function validateW(W, bits) {
1650
+ if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
1651
+ throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W);
1652
+ }
1653
+ function calcWOpts(W, scalarBits) {
1654
+ validateW(W, scalarBits);
1655
+ const windows = Math.ceil(scalarBits / W) + 1;
1656
+ const windowSize = 2 ** (W - 1);
1657
+ const maxNumber = 2 ** W;
1658
+ const mask = bitMask(W);
1659
+ const shiftBy = BigInt(W);
1660
+ return { windows, windowSize, mask, maxNumber, shiftBy };
1661
+ }
1662
+ function calcOffsets(n, window, wOpts) {
1663
+ const { windowSize, mask, maxNumber, shiftBy } = wOpts;
1664
+ let wbits = Number(n & mask);
1665
+ let nextN = n >> shiftBy;
1666
+ if (wbits > windowSize) {
1667
+ wbits -= maxNumber;
1668
+ nextN += _1n3;
1669
+ }
1670
+ const offsetStart = window * windowSize;
1671
+ const offset = offsetStart + Math.abs(wbits) - 1;
1672
+ const isZero = wbits === 0;
1673
+ const isNeg = wbits < 0;
1674
+ const isNegF = window % 2 !== 0;
1675
+ const offsetF = offsetStart;
1676
+ return { nextN, offset, isZero, isNeg, isNegF, offsetF };
1677
+ }
1678
+ function validateMSMPoints(points, c) {
1679
+ if (!Array.isArray(points))
1680
+ throw new Error("array expected");
1681
+ points.forEach((p, i) => {
1682
+ if (!(p instanceof c))
1683
+ throw new Error("invalid point at index " + i);
1684
+ });
1685
+ }
1686
+ function validateMSMScalars(scalars, field) {
1687
+ if (!Array.isArray(scalars))
1688
+ throw new Error("array of scalars expected");
1689
+ scalars.forEach((s, i) => {
1690
+ if (!field.isValid(s))
1691
+ throw new Error("invalid scalar at index " + i);
1692
+ });
1693
+ }
1694
+ var pointPrecomputes = /* @__PURE__ */ new WeakMap();
1695
+ var pointWindowSizes = /* @__PURE__ */ new WeakMap();
1696
+ function getW(P) {
1697
+ return pointWindowSizes.get(P) || 1;
1698
+ }
1699
+ function assert0(n) {
1700
+ if (n !== _0n3)
1701
+ throw new Error("invalid wNAF");
1702
+ }
1703
+ var wNAF = class {
1704
+ // Parametrized with a given Point class (not individual point)
1705
+ constructor(Point, bits) {
1706
+ this.BASE = Point.BASE;
1707
+ this.ZERO = Point.ZERO;
1708
+ this.Fn = Point.Fn;
1709
+ this.bits = bits;
1710
+ }
1711
+ // non-const time multiplication ladder
1712
+ _unsafeLadder(elm, n, p = this.ZERO) {
1713
+ let d = elm;
1714
+ while (n > _0n3) {
1715
+ if (n & _1n3)
1716
+ p = p.add(d);
1717
+ d = d.double();
1718
+ n >>= _1n3;
1719
+ }
1720
+ return p;
1721
+ }
1722
+ /**
1723
+ * Creates a wNAF precomputation window. Used for caching.
1724
+ * Default window size is set by `utils.precompute()` and is equal to 8.
1725
+ * Number of precomputed points depends on the curve size:
1726
+ * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
1727
+ * - 𝑊 is the window size
1728
+ * - 𝑛 is the bitlength of the curve order.
1729
+ * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
1730
+ * @param point Point instance
1731
+ * @param W window size
1732
+ * @returns precomputed point tables flattened to a single array
1733
+ */
1734
+ precomputeWindow(point, W) {
1735
+ const { windows, windowSize } = calcWOpts(W, this.bits);
1736
+ const points = [];
1737
+ let p = point;
1738
+ let base2 = p;
1739
+ for (let window = 0; window < windows; window++) {
1740
+ base2 = p;
1741
+ points.push(base2);
1742
+ for (let i = 1; i < windowSize; i++) {
1743
+ base2 = base2.add(p);
1744
+ points.push(base2);
1745
+ }
1746
+ p = base2.double();
1747
+ }
1748
+ return points;
1749
+ }
1750
+ /**
1751
+ * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
1752
+ * More compact implementation:
1753
+ * https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
1754
+ * @returns real and fake (for const-time) points
1755
+ */
1756
+ wNAF(W, precomputes, n) {
1757
+ if (!this.Fn.isValid(n))
1758
+ throw new Error("invalid scalar");
1759
+ let p = this.ZERO;
1760
+ let f = this.BASE;
1761
+ const wo = calcWOpts(W, this.bits);
1762
+ for (let window = 0; window < wo.windows; window++) {
1763
+ const { nextN, offset, isZero, isNeg, isNegF, offsetF } = calcOffsets(n, window, wo);
1764
+ n = nextN;
1765
+ if (isZero) {
1766
+ f = f.add(negateCt(isNegF, precomputes[offsetF]));
1767
+ } else {
1768
+ p = p.add(negateCt(isNeg, precomputes[offset]));
1769
+ }
1770
+ }
1771
+ assert0(n);
1772
+ return { p, f };
1773
+ }
1774
+ /**
1775
+ * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
1776
+ * @param acc accumulator point to add result of multiplication
1777
+ * @returns point
1778
+ */
1779
+ wNAFUnsafe(W, precomputes, n, acc = this.ZERO) {
1780
+ const wo = calcWOpts(W, this.bits);
1781
+ for (let window = 0; window < wo.windows; window++) {
1782
+ if (n === _0n3)
1783
+ break;
1784
+ const { nextN, offset, isZero, isNeg } = calcOffsets(n, window, wo);
1785
+ n = nextN;
1786
+ if (isZero) {
1787
+ continue;
1788
+ } else {
1789
+ const item = precomputes[offset];
1790
+ acc = acc.add(isNeg ? item.negate() : item);
1791
+ }
1792
+ }
1793
+ assert0(n);
1794
+ return acc;
1795
+ }
1796
+ getPrecomputes(W, point, transform) {
1797
+ let comp = pointPrecomputes.get(point);
1798
+ if (!comp) {
1799
+ comp = this.precomputeWindow(point, W);
1800
+ if (W !== 1) {
1801
+ if (typeof transform === "function")
1802
+ comp = transform(comp);
1803
+ pointPrecomputes.set(point, comp);
1804
+ }
1805
+ }
1806
+ return comp;
1807
+ }
1808
+ cached(point, scalar, transform) {
1809
+ const W = getW(point);
1810
+ return this.wNAF(W, this.getPrecomputes(W, point, transform), scalar);
1811
+ }
1812
+ unsafe(point, scalar, transform, prev) {
1813
+ const W = getW(point);
1814
+ if (W === 1)
1815
+ return this._unsafeLadder(point, scalar, prev);
1816
+ return this.wNAFUnsafe(W, this.getPrecomputes(W, point, transform), scalar, prev);
1817
+ }
1818
+ // We calculate precomputes for elliptic curve point multiplication
1819
+ // using windowed method. This specifies window size and
1820
+ // stores precomputed values. Usually only base point would be precomputed.
1821
+ createCache(P, W) {
1822
+ validateW(W, this.bits);
1823
+ pointWindowSizes.set(P, W);
1824
+ pointPrecomputes.delete(P);
1825
+ }
1826
+ hasCache(elm) {
1827
+ return getW(elm) !== 1;
1828
+ }
1829
+ };
1830
+ function pippenger(c, fieldN, points, scalars) {
1831
+ validateMSMPoints(points, c);
1832
+ validateMSMScalars(scalars, fieldN);
1833
+ const plength = points.length;
1834
+ const slength = scalars.length;
1835
+ if (plength !== slength)
1836
+ throw new Error("arrays of points and scalars must have equal length");
1837
+ const zero = c.ZERO;
1838
+ const wbits = bitLen(BigInt(plength));
1839
+ let windowSize = 1;
1840
+ if (wbits > 12)
1841
+ windowSize = wbits - 3;
1842
+ else if (wbits > 4)
1843
+ windowSize = wbits - 2;
1844
+ else if (wbits > 0)
1845
+ windowSize = 2;
1846
+ const MASK = bitMask(windowSize);
1847
+ const buckets = new Array(Number(MASK) + 1).fill(zero);
1848
+ const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
1849
+ let sum = zero;
1850
+ for (let i = lastBits; i >= 0; i -= windowSize) {
1851
+ buckets.fill(zero);
1852
+ for (let j = 0; j < slength; j++) {
1853
+ const scalar = scalars[j];
1854
+ const wbits2 = Number(scalar >> BigInt(i) & MASK);
1855
+ buckets[wbits2] = buckets[wbits2].add(points[j]);
1856
+ }
1857
+ let resI = zero;
1858
+ for (let j = buckets.length - 1, sumI = zero; j > 0; j--) {
1859
+ sumI = sumI.add(buckets[j]);
1860
+ resI = resI.add(sumI);
1861
+ }
1862
+ sum = sum.add(resI);
1863
+ if (i !== 0)
1864
+ for (let j = 0; j < windowSize; j++)
1865
+ sum = sum.double();
1866
+ }
1867
+ return sum;
1868
+ }
1869
+ function createField(order, field, isLE2) {
1870
+ if (field) {
1871
+ if (field.ORDER !== order)
1872
+ throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
1873
+ validateField(field);
1874
+ return field;
1875
+ } else {
1876
+ return Field(order, { isLE: isLE2 });
1877
+ }
1878
+ }
1879
+ function _createCurveFields(type, CURVE, curveOpts = {}, FpFnLE) {
1880
+ if (FpFnLE === void 0)
1881
+ FpFnLE = type === "edwards";
1882
+ if (!CURVE || typeof CURVE !== "object")
1883
+ throw new Error(`expected valid ${type} CURVE object`);
1884
+ for (const p of ["p", "n", "h"]) {
1885
+ const val = CURVE[p];
1886
+ if (!(typeof val === "bigint" && val > _0n3))
1887
+ throw new Error(`CURVE.${p} must be positive bigint`);
1888
+ }
1889
+ const Fp2 = createField(CURVE.p, curveOpts.Fp, FpFnLE);
1890
+ const Fn2 = createField(CURVE.n, curveOpts.Fn, FpFnLE);
1891
+ const _b = type === "weierstrass" ? "b" : "d";
1892
+ const params = ["Gx", "Gy", "a", _b];
1893
+ for (const p of params) {
1894
+ if (!Fp2.isValid(CURVE[p]))
1895
+ throw new Error(`CURVE.${p} must be valid field element of CURVE.Fp`);
1896
+ }
1897
+ CURVE = Object.freeze(Object.assign({}, CURVE));
1898
+ return { CURVE, Fp: Fp2, Fn: Fn2 };
1899
+ }
1900
+
1901
+ // ../../node_modules/@noble/curves/esm/abstract/edwards.js
1902
+ var _0n4 = BigInt(0);
1903
+ var _1n4 = BigInt(1);
1904
+ var _2n2 = BigInt(2);
1905
+ var _8n2 = BigInt(8);
1906
+ function isEdValidXY(Fp2, CURVE, x, y) {
1907
+ const x2 = Fp2.sqr(x);
1908
+ const y2 = Fp2.sqr(y);
1909
+ const left = Fp2.add(Fp2.mul(CURVE.a, x2), y2);
1910
+ const right = Fp2.add(Fp2.ONE, Fp2.mul(CURVE.d, Fp2.mul(x2, y2)));
1911
+ return Fp2.eql(left, right);
1912
+ }
1913
+ function edwards(params, extraOpts = {}) {
1914
+ const validated = _createCurveFields("edwards", params, extraOpts, extraOpts.FpFnLE);
1915
+ const { Fp: Fp2, Fn: Fn2 } = validated;
1916
+ let CURVE = validated.CURVE;
1917
+ const { h: cofactor } = CURVE;
1918
+ _validateObject(extraOpts, {}, { uvRatio: "function" });
1919
+ const MASK = _2n2 << BigInt(Fn2.BYTES * 8) - _1n4;
1920
+ const modP = (n) => Fp2.create(n);
1921
+ const uvRatio2 = extraOpts.uvRatio || ((u, v) => {
1922
+ try {
1923
+ return { isValid: true, value: Fp2.sqrt(Fp2.div(u, v)) };
1924
+ } catch (e) {
1925
+ return { isValid: false, value: _0n4 };
1926
+ }
1927
+ });
1928
+ if (!isEdValidXY(Fp2, CURVE, CURVE.Gx, CURVE.Gy))
1929
+ throw new Error("bad curve params: generator point");
1930
+ function acoord(title, n, banZero = false) {
1931
+ const min = banZero ? _1n4 : _0n4;
1932
+ aInRange("coordinate " + title, n, min, MASK);
1933
+ return n;
1934
+ }
1935
+ function aextpoint(other) {
1936
+ if (!(other instanceof Point))
1937
+ throw new Error("ExtendedPoint expected");
1938
+ }
1939
+ const toAffineMemo = memoized((p, iz) => {
1940
+ const { X, Y, Z } = p;
1941
+ const is0 = p.is0();
1942
+ if (iz == null)
1943
+ iz = is0 ? _8n2 : Fp2.inv(Z);
1944
+ const x = modP(X * iz);
1945
+ const y = modP(Y * iz);
1946
+ const zz = Fp2.mul(Z, iz);
1947
+ if (is0)
1948
+ return { x: _0n4, y: _1n4 };
1949
+ if (zz !== _1n4)
1950
+ throw new Error("invZ was invalid");
1951
+ return { x, y };
1952
+ });
1953
+ const assertValidMemo = memoized((p) => {
1954
+ const { a, d } = CURVE;
1955
+ if (p.is0())
1956
+ throw new Error("bad point: ZERO");
1957
+ const { X, Y, Z, T } = p;
1958
+ const X2 = modP(X * X);
1959
+ const Y2 = modP(Y * Y);
1960
+ const Z2 = modP(Z * Z);
1961
+ const Z4 = modP(Z2 * Z2);
1962
+ const aX2 = modP(X2 * a);
1963
+ const left = modP(Z2 * modP(aX2 + Y2));
1964
+ const right = modP(Z4 + modP(d * modP(X2 * Y2)));
1965
+ if (left !== right)
1966
+ throw new Error("bad point: equation left != right (1)");
1967
+ const XY = modP(X * Y);
1968
+ const ZT = modP(Z * T);
1969
+ if (XY !== ZT)
1970
+ throw new Error("bad point: equation left != right (2)");
1971
+ return true;
1972
+ });
1973
+ class Point {
1974
+ constructor(X, Y, Z, T) {
1975
+ this.X = acoord("x", X);
1976
+ this.Y = acoord("y", Y);
1977
+ this.Z = acoord("z", Z, true);
1978
+ this.T = acoord("t", T);
1979
+ Object.freeze(this);
1980
+ }
1981
+ static CURVE() {
1982
+ return CURVE;
1983
+ }
1984
+ static fromAffine(p) {
1985
+ if (p instanceof Point)
1986
+ throw new Error("extended point not allowed");
1987
+ const { x, y } = p || {};
1988
+ acoord("x", x);
1989
+ acoord("y", y);
1990
+ return new Point(x, y, _1n4, modP(x * y));
1991
+ }
1992
+ // Uses algo from RFC8032 5.1.3.
1993
+ static fromBytes(bytes, zip215 = false) {
1994
+ const len = Fp2.BYTES;
1995
+ const { a, d } = CURVE;
1996
+ bytes = copyBytes(_abytes2(bytes, len, "point"));
1997
+ _abool2(zip215, "zip215");
1998
+ const normed = copyBytes(bytes);
1999
+ const lastByte = bytes[len - 1];
2000
+ normed[len - 1] = lastByte & ~128;
2001
+ const y = bytesToNumberLE(normed);
2002
+ const max = zip215 ? MASK : Fp2.ORDER;
2003
+ aInRange("point.y", y, _0n4, max);
2004
+ const y2 = modP(y * y);
2005
+ const u = modP(y2 - _1n4);
2006
+ const v = modP(d * y2 - a);
2007
+ let { isValid, value: x } = uvRatio2(u, v);
2008
+ if (!isValid)
2009
+ throw new Error("bad point: invalid y coordinate");
2010
+ const isXOdd = (x & _1n4) === _1n4;
2011
+ const isLastByteOdd = (lastByte & 128) !== 0;
2012
+ if (!zip215 && x === _0n4 && isLastByteOdd)
2013
+ throw new Error("bad point: x=0 and x_0=1");
2014
+ if (isLastByteOdd !== isXOdd)
2015
+ x = modP(-x);
2016
+ return Point.fromAffine({ x, y });
2017
+ }
2018
+ static fromHex(bytes, zip215 = false) {
2019
+ return Point.fromBytes(ensureBytes("point", bytes), zip215);
2020
+ }
2021
+ get x() {
2022
+ return this.toAffine().x;
2023
+ }
2024
+ get y() {
2025
+ return this.toAffine().y;
2026
+ }
2027
+ precompute(windowSize = 8, isLazy = true) {
2028
+ wnaf.createCache(this, windowSize);
2029
+ if (!isLazy)
2030
+ this.multiply(_2n2);
2031
+ return this;
2032
+ }
2033
+ // Useful in fromAffine() - not for fromBytes(), which always created valid points.
2034
+ assertValidity() {
2035
+ assertValidMemo(this);
2036
+ }
2037
+ // Compare one point to another.
2038
+ equals(other) {
2039
+ aextpoint(other);
2040
+ const { X: X1, Y: Y1, Z: Z1 } = this;
2041
+ const { X: X2, Y: Y2, Z: Z2 } = other;
2042
+ const X1Z2 = modP(X1 * Z2);
2043
+ const X2Z1 = modP(X2 * Z1);
2044
+ const Y1Z2 = modP(Y1 * Z2);
2045
+ const Y2Z1 = modP(Y2 * Z1);
2046
+ return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
2047
+ }
2048
+ is0() {
2049
+ return this.equals(Point.ZERO);
2050
+ }
2051
+ negate() {
2052
+ return new Point(modP(-this.X), this.Y, this.Z, modP(-this.T));
2053
+ }
2054
+ // Fast algo for doubling Extended Point.
2055
+ // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
2056
+ // Cost: 4M + 4S + 1*a + 6add + 1*2.
2057
+ double() {
2058
+ const { a } = CURVE;
2059
+ const { X: X1, Y: Y1, Z: Z1 } = this;
2060
+ const A = modP(X1 * X1);
2061
+ const B = modP(Y1 * Y1);
2062
+ const C = modP(_2n2 * modP(Z1 * Z1));
2063
+ const D = modP(a * A);
2064
+ const x1y1 = X1 + Y1;
2065
+ const E = modP(modP(x1y1 * x1y1) - A - B);
2066
+ const G = D + B;
2067
+ const F = G - C;
2068
+ const H = D - B;
2069
+ const X3 = modP(E * F);
2070
+ const Y3 = modP(G * H);
2071
+ const T3 = modP(E * H);
2072
+ const Z3 = modP(F * G);
2073
+ return new Point(X3, Y3, Z3, T3);
2074
+ }
2075
+ // Fast algo for adding 2 Extended Points.
2076
+ // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
2077
+ // Cost: 9M + 1*a + 1*d + 7add.
2078
+ add(other) {
2079
+ aextpoint(other);
2080
+ const { a, d } = CURVE;
2081
+ const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
2082
+ const { X: X2, Y: Y2, Z: Z2, T: T2 } = other;
2083
+ const A = modP(X1 * X2);
2084
+ const B = modP(Y1 * Y2);
2085
+ const C = modP(T1 * d * T2);
2086
+ const D = modP(Z1 * Z2);
2087
+ const E = modP((X1 + Y1) * (X2 + Y2) - A - B);
2088
+ const F = D - C;
2089
+ const G = D + C;
2090
+ const H = modP(B - a * A);
2091
+ const X3 = modP(E * F);
2092
+ const Y3 = modP(G * H);
2093
+ const T3 = modP(E * H);
2094
+ const Z3 = modP(F * G);
2095
+ return new Point(X3, Y3, Z3, T3);
2096
+ }
2097
+ subtract(other) {
2098
+ return this.add(other.negate());
2099
+ }
2100
+ // Constant-time multiplication.
2101
+ multiply(scalar) {
2102
+ if (!Fn2.isValidNot0(scalar))
2103
+ throw new Error("invalid scalar: expected 1 <= sc < curve.n");
2104
+ const { p, f } = wnaf.cached(this, scalar, (p2) => normalizeZ(Point, p2));
2105
+ return normalizeZ(Point, [p, f])[0];
2106
+ }
2107
+ // Non-constant-time multiplication. Uses double-and-add algorithm.
2108
+ // It's faster, but should only be used when you don't care about
2109
+ // an exposed private key e.g. sig verification.
2110
+ // Does NOT allow scalars higher than CURVE.n.
2111
+ // Accepts optional accumulator to merge with multiply (important for sparse scalars)
2112
+ multiplyUnsafe(scalar, acc = Point.ZERO) {
2113
+ if (!Fn2.isValid(scalar))
2114
+ throw new Error("invalid scalar: expected 0 <= sc < curve.n");
2115
+ if (scalar === _0n4)
2116
+ return Point.ZERO;
2117
+ if (this.is0() || scalar === _1n4)
2118
+ return this;
2119
+ return wnaf.unsafe(this, scalar, (p) => normalizeZ(Point, p), acc);
2120
+ }
2121
+ // Checks if point is of small order.
2122
+ // If you add something to small order point, you will have "dirty"
2123
+ // point with torsion component.
2124
+ // Multiplies point by cofactor and checks if the result is 0.
2125
+ isSmallOrder() {
2126
+ return this.multiplyUnsafe(cofactor).is0();
2127
+ }
2128
+ // Multiplies point by curve order and checks if the result is 0.
2129
+ // Returns `false` is the point is dirty.
2130
+ isTorsionFree() {
2131
+ return wnaf.unsafe(this, CURVE.n).is0();
2132
+ }
2133
+ // Converts Extended point to default (x, y) coordinates.
2134
+ // Can accept precomputed Z^-1 - for example, from invertBatch.
2135
+ toAffine(invertedZ) {
2136
+ return toAffineMemo(this, invertedZ);
2137
+ }
2138
+ clearCofactor() {
2139
+ if (cofactor === _1n4)
2140
+ return this;
2141
+ return this.multiplyUnsafe(cofactor);
2142
+ }
2143
+ toBytes() {
2144
+ const { x, y } = this.toAffine();
2145
+ const bytes = Fp2.toBytes(y);
2146
+ bytes[bytes.length - 1] |= x & _1n4 ? 128 : 0;
2147
+ return bytes;
2148
+ }
2149
+ toHex() {
2150
+ return bytesToHex(this.toBytes());
2151
+ }
2152
+ toString() {
2153
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
2154
+ }
2155
+ // TODO: remove
2156
+ get ex() {
2157
+ return this.X;
2158
+ }
2159
+ get ey() {
2160
+ return this.Y;
2161
+ }
2162
+ get ez() {
2163
+ return this.Z;
2164
+ }
2165
+ get et() {
2166
+ return this.T;
2167
+ }
2168
+ static normalizeZ(points) {
2169
+ return normalizeZ(Point, points);
2170
+ }
2171
+ static msm(points, scalars) {
2172
+ return pippenger(Point, Fn2, points, scalars);
2173
+ }
2174
+ _setWindowSize(windowSize) {
2175
+ this.precompute(windowSize);
2176
+ }
2177
+ toRawBytes() {
2178
+ return this.toBytes();
2179
+ }
2180
+ }
2181
+ Point.BASE = new Point(CURVE.Gx, CURVE.Gy, _1n4, modP(CURVE.Gx * CURVE.Gy));
2182
+ Point.ZERO = new Point(_0n4, _1n4, _1n4, _0n4);
2183
+ Point.Fp = Fp2;
2184
+ Point.Fn = Fn2;
2185
+ const wnaf = new wNAF(Point, Fn2.BITS);
2186
+ Point.BASE.precompute(8);
2187
+ return Point;
2188
+ }
2189
+ var PrimeEdwardsPoint = class {
2190
+ constructor(ep) {
2191
+ this.ep = ep;
2192
+ }
2193
+ // Static methods that must be implemented by subclasses
2194
+ static fromBytes(_bytes) {
2195
+ notImplemented();
2196
+ }
2197
+ static fromHex(_hex) {
2198
+ notImplemented();
2199
+ }
2200
+ get x() {
2201
+ return this.toAffine().x;
2202
+ }
2203
+ get y() {
2204
+ return this.toAffine().y;
2205
+ }
2206
+ // Common implementations
2207
+ clearCofactor() {
2208
+ return this;
2209
+ }
2210
+ assertValidity() {
2211
+ this.ep.assertValidity();
2212
+ }
2213
+ toAffine(invertedZ) {
2214
+ return this.ep.toAffine(invertedZ);
2215
+ }
2216
+ toHex() {
2217
+ return bytesToHex(this.toBytes());
2218
+ }
2219
+ toString() {
2220
+ return this.toHex();
2221
+ }
2222
+ isTorsionFree() {
2223
+ return true;
2224
+ }
2225
+ isSmallOrder() {
2226
+ return false;
2227
+ }
2228
+ add(other) {
2229
+ this.assertSame(other);
2230
+ return this.init(this.ep.add(other.ep));
2231
+ }
2232
+ subtract(other) {
2233
+ this.assertSame(other);
2234
+ return this.init(this.ep.subtract(other.ep));
2235
+ }
2236
+ multiply(scalar) {
2237
+ return this.init(this.ep.multiply(scalar));
2238
+ }
2239
+ multiplyUnsafe(scalar) {
2240
+ return this.init(this.ep.multiplyUnsafe(scalar));
2241
+ }
2242
+ double() {
2243
+ return this.init(this.ep.double());
2244
+ }
2245
+ negate() {
2246
+ return this.init(this.ep.negate());
2247
+ }
2248
+ precompute(windowSize, isLazy) {
2249
+ return this.init(this.ep.precompute(windowSize, isLazy));
2250
+ }
2251
+ /** @deprecated use `toBytes` */
2252
+ toRawBytes() {
2253
+ return this.toBytes();
2254
+ }
2255
+ };
2256
+ function eddsa(Point, cHash, eddsaOpts = {}) {
2257
+ if (typeof cHash !== "function")
2258
+ throw new Error('"hash" function param is required');
2259
+ _validateObject(eddsaOpts, {}, {
2260
+ adjustScalarBytes: "function",
2261
+ randomBytes: "function",
2262
+ domain: "function",
2263
+ prehash: "function",
2264
+ mapToCurve: "function"
2265
+ });
2266
+ const { prehash } = eddsaOpts;
2267
+ const { BASE, Fp: Fp2, Fn: Fn2 } = Point;
2268
+ const randomBytes2 = eddsaOpts.randomBytes || randomBytes;
2269
+ const adjustScalarBytes2 = eddsaOpts.adjustScalarBytes || ((bytes) => bytes);
2270
+ const domain = eddsaOpts.domain || ((data, ctx, phflag) => {
2271
+ _abool2(phflag, "phflag");
2272
+ if (ctx.length || phflag)
2273
+ throw new Error("Contexts/pre-hash are not supported");
2274
+ return data;
2275
+ });
2276
+ function modN_LE(hash) {
2277
+ return Fn2.create(bytesToNumberLE(hash));
2278
+ }
2279
+ function getPrivateScalar(key) {
2280
+ const len = lengths.secretKey;
2281
+ key = ensureBytes("private key", key, len);
2282
+ const hashed = ensureBytes("hashed private key", cHash(key), 2 * len);
2283
+ const head = adjustScalarBytes2(hashed.slice(0, len));
2284
+ const prefix = hashed.slice(len, 2 * len);
2285
+ const scalar = modN_LE(head);
2286
+ return { head, prefix, scalar };
2287
+ }
2288
+ function getExtendedPublicKey(secretKey) {
2289
+ const { head, prefix, scalar } = getPrivateScalar(secretKey);
2290
+ const point = BASE.multiply(scalar);
2291
+ const pointBytes = point.toBytes();
2292
+ return { head, prefix, scalar, point, pointBytes };
2293
+ }
2294
+ function getPublicKey(secretKey) {
2295
+ return getExtendedPublicKey(secretKey).pointBytes;
2296
+ }
2297
+ function hashDomainToScalar(context = Uint8Array.of(), ...msgs) {
2298
+ const msg = concatBytes(...msgs);
2299
+ return modN_LE(cHash(domain(msg, ensureBytes("context", context), !!prehash)));
2300
+ }
2301
+ function sign(msg, secretKey, options = {}) {
2302
+ msg = ensureBytes("message", msg);
2303
+ if (prehash)
2304
+ msg = prehash(msg);
2305
+ const { prefix, scalar, pointBytes } = getExtendedPublicKey(secretKey);
2306
+ const r = hashDomainToScalar(options.context, prefix, msg);
2307
+ const R = BASE.multiply(r).toBytes();
2308
+ const k = hashDomainToScalar(options.context, R, pointBytes, msg);
2309
+ const s = Fn2.create(r + k * scalar);
2310
+ if (!Fn2.isValid(s))
2311
+ throw new Error("sign failed: invalid s");
2312
+ const rs = concatBytes(R, Fn2.toBytes(s));
2313
+ return _abytes2(rs, lengths.signature, "result");
2314
+ }
2315
+ const verifyOpts = { zip215: true };
2316
+ function verify(sig, msg, publicKey, options = verifyOpts) {
2317
+ const { context, zip215 } = options;
2318
+ const len = lengths.signature;
2319
+ sig = ensureBytes("signature", sig, len);
2320
+ msg = ensureBytes("message", msg);
2321
+ publicKey = ensureBytes("publicKey", publicKey, lengths.publicKey);
2322
+ if (zip215 !== void 0)
2323
+ _abool2(zip215, "zip215");
2324
+ if (prehash)
2325
+ msg = prehash(msg);
2326
+ const mid = len / 2;
2327
+ const r = sig.subarray(0, mid);
2328
+ const s = bytesToNumberLE(sig.subarray(mid, len));
2329
+ let A, R, SB;
2330
+ try {
2331
+ A = Point.fromBytes(publicKey, zip215);
2332
+ R = Point.fromBytes(r, zip215);
2333
+ SB = BASE.multiplyUnsafe(s);
2334
+ } catch (error) {
2335
+ return false;
2336
+ }
2337
+ if (!zip215 && A.isSmallOrder())
2338
+ return false;
2339
+ const k = hashDomainToScalar(context, R.toBytes(), A.toBytes(), msg);
2340
+ const RkA = R.add(A.multiplyUnsafe(k));
2341
+ return RkA.subtract(SB).clearCofactor().is0();
2342
+ }
2343
+ const _size = Fp2.BYTES;
2344
+ const lengths = {
2345
+ secretKey: _size,
2346
+ publicKey: _size,
2347
+ signature: 2 * _size,
2348
+ seed: _size
2349
+ };
2350
+ function randomSecretKey(seed = randomBytes2(lengths.seed)) {
2351
+ return _abytes2(seed, lengths.seed, "seed");
2352
+ }
2353
+ function keygen(seed) {
2354
+ const secretKey = utils.randomSecretKey(seed);
2355
+ return { secretKey, publicKey: getPublicKey(secretKey) };
2356
+ }
2357
+ function isValidSecretKey(key) {
2358
+ return isBytes(key) && key.length === Fn2.BYTES;
2359
+ }
2360
+ function isValidPublicKey(key, zip215) {
2361
+ try {
2362
+ return !!Point.fromBytes(key, zip215);
2363
+ } catch (error) {
2364
+ return false;
2365
+ }
2366
+ }
2367
+ const utils = {
2368
+ getExtendedPublicKey,
2369
+ randomSecretKey,
2370
+ isValidSecretKey,
2371
+ isValidPublicKey,
2372
+ /**
2373
+ * Converts ed public key to x public key. Uses formula:
2374
+ * - ed25519:
2375
+ * - `(u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)`
2376
+ * - `(x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))`
2377
+ * - ed448:
2378
+ * - `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
2379
+ * - `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
2380
+ */
2381
+ toMontgomery(publicKey) {
2382
+ const { y } = Point.fromBytes(publicKey);
2383
+ const size = lengths.publicKey;
2384
+ const is25519 = size === 32;
2385
+ if (!is25519 && size !== 57)
2386
+ throw new Error("only defined for 25519 and 448");
2387
+ const u = is25519 ? Fp2.div(_1n4 + y, _1n4 - y) : Fp2.div(y - _1n4, y + _1n4);
2388
+ return Fp2.toBytes(u);
2389
+ },
2390
+ toMontgomerySecret(secretKey) {
2391
+ const size = lengths.secretKey;
2392
+ _abytes2(secretKey, size);
2393
+ const hashed = cHash(secretKey.subarray(0, size));
2394
+ return adjustScalarBytes2(hashed).subarray(0, size);
2395
+ },
2396
+ /** @deprecated */
2397
+ randomPrivateKey: randomSecretKey,
2398
+ /** @deprecated */
2399
+ precompute(windowSize = 8, point = Point.BASE) {
2400
+ return point.precompute(windowSize, false);
2401
+ }
2402
+ };
2403
+ return Object.freeze({
2404
+ keygen,
2405
+ getPublicKey,
2406
+ sign,
2407
+ verify,
2408
+ utils,
2409
+ Point,
2410
+ lengths
2411
+ });
2412
+ }
2413
+ function _eddsa_legacy_opts_to_new(c) {
2414
+ const CURVE = {
2415
+ a: c.a,
2416
+ d: c.d,
2417
+ p: c.Fp.ORDER,
2418
+ n: c.n,
2419
+ h: c.h,
2420
+ Gx: c.Gx,
2421
+ Gy: c.Gy
2422
+ };
2423
+ const Fp2 = c.Fp;
2424
+ const Fn2 = Field(CURVE.n, c.nBitLength, true);
2425
+ const curveOpts = { Fp: Fp2, Fn: Fn2, uvRatio: c.uvRatio };
2426
+ const eddsaOpts = {
2427
+ randomBytes: c.randomBytes,
2428
+ adjustScalarBytes: c.adjustScalarBytes,
2429
+ domain: c.domain,
2430
+ prehash: c.prehash,
2431
+ mapToCurve: c.mapToCurve
2432
+ };
2433
+ return { CURVE, curveOpts, hash: c.hash, eddsaOpts };
2434
+ }
2435
+ function _eddsa_new_output_to_legacy(c, eddsa2) {
2436
+ const Point = eddsa2.Point;
2437
+ const legacy = Object.assign({}, eddsa2, {
2438
+ ExtendedPoint: Point,
2439
+ CURVE: c,
2440
+ nBitLength: Point.Fn.BITS,
2441
+ nByteLength: Point.Fn.BYTES
2442
+ });
2443
+ return legacy;
2444
+ }
2445
+ function twistedEdwards(c) {
2446
+ const { CURVE, curveOpts, hash, eddsaOpts } = _eddsa_legacy_opts_to_new(c);
2447
+ const Point = edwards(CURVE, curveOpts);
2448
+ const EDDSA = eddsa(Point, hash, eddsaOpts);
2449
+ return _eddsa_new_output_to_legacy(c, EDDSA);
2450
+ }
2451
+
2452
+ // ../../node_modules/@noble/curves/esm/ed25519.js
2453
+ var _0n5 = /* @__PURE__ */ BigInt(0);
2454
+ var _1n5 = BigInt(1);
2455
+ var _2n3 = BigInt(2);
2456
+ var _3n2 = BigInt(3);
2457
+ var _5n2 = BigInt(5);
2458
+ var _8n3 = BigInt(8);
2459
+ var ed25519_CURVE_p = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed");
2460
+ var ed25519_CURVE = /* @__PURE__ */ (() => ({
2461
+ p: ed25519_CURVE_p,
2462
+ n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
2463
+ h: _8n3,
2464
+ a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
2465
+ d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
2466
+ Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
2467
+ Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
2468
+ }))();
2469
+ function ed25519_pow_2_252_3(x) {
2470
+ const _10n = BigInt(10), _20n = BigInt(20), _40n = BigInt(40), _80n = BigInt(80);
2471
+ const P = ed25519_CURVE_p;
2472
+ const x2 = x * x % P;
2473
+ const b2 = x2 * x % P;
2474
+ const b4 = pow2(b2, _2n3, P) * b2 % P;
2475
+ const b5 = pow2(b4, _1n5, P) * x % P;
2476
+ const b10 = pow2(b5, _5n2, P) * b5 % P;
2477
+ const b20 = pow2(b10, _10n, P) * b10 % P;
2478
+ const b40 = pow2(b20, _20n, P) * b20 % P;
2479
+ const b80 = pow2(b40, _40n, P) * b40 % P;
2480
+ const b160 = pow2(b80, _80n, P) * b80 % P;
2481
+ const b240 = pow2(b160, _80n, P) * b80 % P;
2482
+ const b250 = pow2(b240, _10n, P) * b10 % P;
2483
+ const pow_p_5_8 = pow2(b250, _2n3, P) * x % P;
2484
+ return { pow_p_5_8, b2 };
2485
+ }
2486
+ function adjustScalarBytes(bytes) {
2487
+ bytes[0] &= 248;
2488
+ bytes[31] &= 127;
2489
+ bytes[31] |= 64;
2490
+ return bytes;
2491
+ }
2492
+ var ED25519_SQRT_M1 = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
2493
+ function uvRatio(u, v) {
2494
+ const P = ed25519_CURVE_p;
2495
+ const v3 = mod(v * v * v, P);
2496
+ const v7 = mod(v3 * v3 * v, P);
2497
+ const pow = ed25519_pow_2_252_3(u * v7).pow_p_5_8;
2498
+ let x = mod(u * v3 * pow, P);
2499
+ const vx2 = mod(v * x * x, P);
2500
+ const root1 = x;
2501
+ const root2 = mod(x * ED25519_SQRT_M1, P);
2502
+ const useRoot1 = vx2 === u;
2503
+ const useRoot2 = vx2 === mod(-u, P);
2504
+ const noRoot = vx2 === mod(-u * ED25519_SQRT_M1, P);
2505
+ if (useRoot1)
2506
+ x = root1;
2507
+ if (useRoot2 || noRoot)
2508
+ x = root2;
2509
+ if (isNegativeLE(x, P))
2510
+ x = mod(-x, P);
2511
+ return { isValid: useRoot1 || useRoot2, value: x };
2512
+ }
2513
+ var Fp = /* @__PURE__ */ (() => Field(ed25519_CURVE.p, { isLE: true }))();
2514
+ var Fn = /* @__PURE__ */ (() => Field(ed25519_CURVE.n, { isLE: true }))();
2515
+ var ed25519Defaults = /* @__PURE__ */ (() => ({
2516
+ ...ed25519_CURVE,
2517
+ Fp,
2518
+ hash: sha512,
2519
+ adjustScalarBytes,
2520
+ // dom2
2521
+ // Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
2522
+ // Constant-time, u/√v
2523
+ uvRatio
2524
+ }))();
2525
+ var ed25519 = /* @__PURE__ */ (() => twistedEdwards(ed25519Defaults))();
2526
+ var SQRT_M1 = ED25519_SQRT_M1;
2527
+ var SQRT_AD_MINUS_ONE = /* @__PURE__ */ BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235");
2528
+ var INVSQRT_A_MINUS_D = /* @__PURE__ */ BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578");
2529
+ var ONE_MINUS_D_SQ = /* @__PURE__ */ BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838");
2530
+ var D_MINUS_ONE_SQ = /* @__PURE__ */ BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");
2531
+ var invertSqrt = (number) => uvRatio(_1n5, number);
2532
+ var MAX_255B = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
2533
+ var bytes255ToNumberLE = (bytes) => ed25519.Point.Fp.create(bytesToNumberLE(bytes) & MAX_255B);
2534
+ function calcElligatorRistrettoMap(r0) {
2535
+ const { d } = ed25519_CURVE;
2536
+ const P = ed25519_CURVE_p;
2537
+ const mod2 = (n) => Fp.create(n);
2538
+ const r = mod2(SQRT_M1 * r0 * r0);
2539
+ const Ns = mod2((r + _1n5) * ONE_MINUS_D_SQ);
2540
+ let c = BigInt(-1);
2541
+ const D = mod2((c - d * r) * mod2(r + d));
2542
+ let { isValid: Ns_D_is_sq, value: s } = uvRatio(Ns, D);
2543
+ let s_ = mod2(s * r0);
2544
+ if (!isNegativeLE(s_, P))
2545
+ s_ = mod2(-s_);
2546
+ if (!Ns_D_is_sq)
2547
+ s = s_;
2548
+ if (!Ns_D_is_sq)
2549
+ c = r;
2550
+ const Nt = mod2(c * (r - _1n5) * D_MINUS_ONE_SQ - D);
2551
+ const s2 = s * s;
2552
+ const W0 = mod2((s + s) * D);
2553
+ const W1 = mod2(Nt * SQRT_AD_MINUS_ONE);
2554
+ const W2 = mod2(_1n5 - s2);
2555
+ const W3 = mod2(_1n5 + s2);
2556
+ return new ed25519.Point(mod2(W0 * W3), mod2(W2 * W1), mod2(W1 * W3), mod2(W0 * W2));
2557
+ }
2558
+ function ristretto255_map(bytes) {
2559
+ abytes(bytes, 64);
2560
+ const r1 = bytes255ToNumberLE(bytes.subarray(0, 32));
2561
+ const R1 = calcElligatorRistrettoMap(r1);
2562
+ const r2 = bytes255ToNumberLE(bytes.subarray(32, 64));
2563
+ const R2 = calcElligatorRistrettoMap(r2);
2564
+ return new _RistrettoPoint(R1.add(R2));
2565
+ }
2566
+ var _RistrettoPoint = class __RistrettoPoint extends PrimeEdwardsPoint {
2567
+ constructor(ep) {
2568
+ super(ep);
2569
+ }
2570
+ static fromAffine(ap) {
2571
+ return new __RistrettoPoint(ed25519.Point.fromAffine(ap));
2572
+ }
2573
+ assertSame(other) {
2574
+ if (!(other instanceof __RistrettoPoint))
2575
+ throw new Error("RistrettoPoint expected");
2576
+ }
2577
+ init(ep) {
2578
+ return new __RistrettoPoint(ep);
2579
+ }
2580
+ /** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
2581
+ static hashToCurve(hex) {
2582
+ return ristretto255_map(ensureBytes("ristrettoHash", hex, 64));
2583
+ }
2584
+ static fromBytes(bytes) {
2585
+ abytes(bytes, 32);
2586
+ const { a, d } = ed25519_CURVE;
2587
+ const P = ed25519_CURVE_p;
2588
+ const mod2 = (n) => Fp.create(n);
2589
+ const s = bytes255ToNumberLE(bytes);
2590
+ if (!equalBytes(Fp.toBytes(s), bytes) || isNegativeLE(s, P))
2591
+ throw new Error("invalid ristretto255 encoding 1");
2592
+ const s2 = mod2(s * s);
2593
+ const u1 = mod2(_1n5 + a * s2);
2594
+ const u2 = mod2(_1n5 - a * s2);
2595
+ const u1_2 = mod2(u1 * u1);
2596
+ const u2_2 = mod2(u2 * u2);
2597
+ const v = mod2(a * d * u1_2 - u2_2);
2598
+ const { isValid, value: I } = invertSqrt(mod2(v * u2_2));
2599
+ const Dx = mod2(I * u2);
2600
+ const Dy = mod2(I * Dx * v);
2601
+ let x = mod2((s + s) * Dx);
2602
+ if (isNegativeLE(x, P))
2603
+ x = mod2(-x);
2604
+ const y = mod2(u1 * Dy);
2605
+ const t = mod2(x * y);
2606
+ if (!isValid || isNegativeLE(t, P) || y === _0n5)
2607
+ throw new Error("invalid ristretto255 encoding 2");
2608
+ return new __RistrettoPoint(new ed25519.Point(x, y, _1n5, t));
2609
+ }
2610
+ /**
2611
+ * Converts ristretto-encoded string to ristretto point.
2612
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
2613
+ * @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
2614
+ */
2615
+ static fromHex(hex) {
2616
+ return __RistrettoPoint.fromBytes(ensureBytes("ristrettoHex", hex, 32));
2617
+ }
2618
+ static msm(points, scalars) {
2619
+ return pippenger(__RistrettoPoint, ed25519.Point.Fn, points, scalars);
2620
+ }
2621
+ /**
2622
+ * Encodes ristretto point to Uint8Array.
2623
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode).
2624
+ */
2625
+ toBytes() {
2626
+ let { X, Y, Z, T } = this.ep;
2627
+ const P = ed25519_CURVE_p;
2628
+ const mod2 = (n) => Fp.create(n);
2629
+ const u1 = mod2(mod2(Z + Y) * mod2(Z - Y));
2630
+ const u2 = mod2(X * Y);
2631
+ const u2sq = mod2(u2 * u2);
2632
+ const { value: invsqrt } = invertSqrt(mod2(u1 * u2sq));
2633
+ const D1 = mod2(invsqrt * u1);
2634
+ const D2 = mod2(invsqrt * u2);
2635
+ const zInv = mod2(D1 * D2 * T);
2636
+ let D;
2637
+ if (isNegativeLE(T * zInv, P)) {
2638
+ let _x = mod2(Y * SQRT_M1);
2639
+ let _y = mod2(X * SQRT_M1);
2640
+ X = _x;
2641
+ Y = _y;
2642
+ D = mod2(D1 * INVSQRT_A_MINUS_D);
2643
+ } else {
2644
+ D = D2;
2645
+ }
2646
+ if (isNegativeLE(X * zInv, P))
2647
+ Y = mod2(-Y);
2648
+ let s = mod2((Z - Y) * D);
2649
+ if (isNegativeLE(s, P))
2650
+ s = mod2(-s);
2651
+ return Fp.toBytes(s);
2652
+ }
2653
+ /**
2654
+ * Compares two Ristretto points.
2655
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals).
2656
+ */
2657
+ equals(other) {
2658
+ this.assertSame(other);
2659
+ const { X: X1, Y: Y1 } = this.ep;
2660
+ const { X: X2, Y: Y2 } = other.ep;
2661
+ const mod2 = (n) => Fp.create(n);
2662
+ const one = mod2(X1 * Y2) === mod2(Y1 * X2);
2663
+ const two = mod2(Y1 * Y2) === mod2(X1 * X2);
2664
+ return one || two;
2665
+ }
2666
+ is0() {
2667
+ return this.equals(__RistrettoPoint.ZERO);
2668
+ }
2669
+ };
2670
+ _RistrettoPoint.BASE = /* @__PURE__ */ (() => new _RistrettoPoint(ed25519.Point.BASE))();
2671
+ _RistrettoPoint.ZERO = /* @__PURE__ */ (() => new _RistrettoPoint(ed25519.Point.ZERO))();
2672
+ _RistrettoPoint.Fp = /* @__PURE__ */ (() => Fp)();
2673
+ _RistrettoPoint.Fn = /* @__PURE__ */ (() => Fn)();
2674
+
2675
+ // ../../node_modules/multiformats/dist/src/bytes.js
2676
+ var empty = new Uint8Array(0);
2677
+ function equals(aa, bb) {
2678
+ if (aa === bb) {
2679
+ return true;
2680
+ }
2681
+ if (aa.byteLength !== bb.byteLength) {
2682
+ return false;
2683
+ }
2684
+ for (let ii = 0; ii < aa.byteLength; ii++) {
2685
+ if (aa[ii] !== bb[ii]) {
2686
+ return false;
2687
+ }
2688
+ }
2689
+ return true;
2690
+ }
2691
+ function coerce(o) {
2692
+ if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
2693
+ return o;
2694
+ }
2695
+ if (o instanceof ArrayBuffer) {
2696
+ return new Uint8Array(o);
2697
+ }
2698
+ if (ArrayBuffer.isView(o)) {
2699
+ return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
2700
+ }
2701
+ throw new Error("Unknown type, must be binary type");
2702
+ }
2703
+
2704
+ // ../../node_modules/multiformats/dist/src/vendor/base-x.js
2705
+ function base(ALPHABET, name) {
2706
+ if (ALPHABET.length >= 255) {
2707
+ throw new TypeError("Alphabet too long");
2708
+ }
2709
+ var BASE_MAP = new Uint8Array(256);
2710
+ for (var j = 0; j < BASE_MAP.length; j++) {
2711
+ BASE_MAP[j] = 255;
2712
+ }
2713
+ for (var i = 0; i < ALPHABET.length; i++) {
2714
+ var x = ALPHABET.charAt(i);
2715
+ var xc = x.charCodeAt(0);
2716
+ if (BASE_MAP[xc] !== 255) {
2717
+ throw new TypeError(x + " is ambiguous");
2718
+ }
2719
+ BASE_MAP[xc] = i;
2720
+ }
2721
+ var BASE = ALPHABET.length;
2722
+ var LEADER = ALPHABET.charAt(0);
2723
+ var FACTOR = Math.log(BASE) / Math.log(256);
2724
+ var iFACTOR = Math.log(256) / Math.log(BASE);
2725
+ function encode3(source) {
2726
+ if (source instanceof Uint8Array)
2727
+ ;
2728
+ else if (ArrayBuffer.isView(source)) {
2729
+ source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
2730
+ } else if (Array.isArray(source)) {
2731
+ source = Uint8Array.from(source);
2732
+ }
2733
+ if (!(source instanceof Uint8Array)) {
2734
+ throw new TypeError("Expected Uint8Array");
2735
+ }
2736
+ if (source.length === 0) {
2737
+ return "";
2738
+ }
2739
+ var zeroes = 0;
2740
+ var length2 = 0;
2741
+ var pbegin = 0;
2742
+ var pend = source.length;
2743
+ while (pbegin !== pend && source[pbegin] === 0) {
2744
+ pbegin++;
2745
+ zeroes++;
2746
+ }
2747
+ var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
2748
+ var b58 = new Uint8Array(size);
2749
+ while (pbegin !== pend) {
2750
+ var carry = source[pbegin];
2751
+ var i2 = 0;
2752
+ for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
2753
+ carry += 256 * b58[it1] >>> 0;
2754
+ b58[it1] = carry % BASE >>> 0;
2755
+ carry = carry / BASE >>> 0;
2756
+ }
2757
+ if (carry !== 0) {
2758
+ throw new Error("Non-zero carry");
2759
+ }
2760
+ length2 = i2;
2761
+ pbegin++;
2762
+ }
2763
+ var it2 = size - length2;
2764
+ while (it2 !== size && b58[it2] === 0) {
2765
+ it2++;
2766
+ }
2767
+ var str = LEADER.repeat(zeroes);
2768
+ for (; it2 < size; ++it2) {
2769
+ str += ALPHABET.charAt(b58[it2]);
2770
+ }
2771
+ return str;
2772
+ }
2773
+ function decodeUnsafe(source) {
2774
+ if (typeof source !== "string") {
2775
+ throw new TypeError("Expected String");
2776
+ }
2777
+ if (source.length === 0) {
2778
+ return new Uint8Array();
2779
+ }
2780
+ var psz = 0;
2781
+ if (source[psz] === " ") {
2782
+ return;
2783
+ }
2784
+ var zeroes = 0;
2785
+ var length2 = 0;
2786
+ while (source[psz] === LEADER) {
2787
+ zeroes++;
2788
+ psz++;
2789
+ }
2790
+ var size = (source.length - psz) * FACTOR + 1 >>> 0;
2791
+ var b256 = new Uint8Array(size);
2792
+ while (source[psz]) {
2793
+ var carry = BASE_MAP[source.charCodeAt(psz)];
2794
+ if (carry === 255) {
2795
+ return;
2796
+ }
2797
+ var i2 = 0;
2798
+ for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
2799
+ carry += BASE * b256[it3] >>> 0;
2800
+ b256[it3] = carry % 256 >>> 0;
2801
+ carry = carry / 256 >>> 0;
2802
+ }
2803
+ if (carry !== 0) {
2804
+ throw new Error("Non-zero carry");
2805
+ }
2806
+ length2 = i2;
2807
+ psz++;
2808
+ }
2809
+ if (source[psz] === " ") {
2810
+ return;
2811
+ }
2812
+ var it4 = size - length2;
2813
+ while (it4 !== size && b256[it4] === 0) {
2814
+ it4++;
2815
+ }
2816
+ var vch = new Uint8Array(zeroes + (size - it4));
2817
+ var j2 = zeroes;
2818
+ while (it4 !== size) {
2819
+ vch[j2++] = b256[it4++];
2820
+ }
2821
+ return vch;
2822
+ }
2823
+ function decode5(string) {
2824
+ var buffer = decodeUnsafe(string);
2825
+ if (buffer) {
2826
+ return buffer;
2827
+ }
2828
+ throw new Error(`Non-${name} character`);
2829
+ }
2830
+ return {
2831
+ encode: encode3,
2832
+ decodeUnsafe,
2833
+ decode: decode5
2834
+ };
2835
+ }
2836
+ var src = base;
2837
+ var _brrp__multiformats_scope_baseX = src;
2838
+ var base_x_default = _brrp__multiformats_scope_baseX;
2839
+
2840
+ // ../../node_modules/multiformats/dist/src/bases/base.js
2841
+ var Encoder = class {
2842
+ constructor(name, prefix, baseEncode) {
2843
+ __publicField(this, "name");
2844
+ __publicField(this, "prefix");
2845
+ __publicField(this, "baseEncode");
2846
+ this.name = name;
2847
+ this.prefix = prefix;
2848
+ this.baseEncode = baseEncode;
2849
+ }
2850
+ encode(bytes) {
2851
+ if (bytes instanceof Uint8Array) {
2852
+ return `${this.prefix}${this.baseEncode(bytes)}`;
2853
+ } else {
2854
+ throw Error("Unknown type, must be binary type");
2855
+ }
2856
+ }
2857
+ };
2858
+ var Decoder = class {
2859
+ constructor(name, prefix, baseDecode) {
2860
+ __publicField(this, "name");
2861
+ __publicField(this, "prefix");
2862
+ __publicField(this, "baseDecode");
2863
+ __publicField(this, "prefixCodePoint");
2864
+ this.name = name;
2865
+ this.prefix = prefix;
2866
+ const prefixCodePoint = prefix.codePointAt(0);
2867
+ if (prefixCodePoint === void 0) {
2868
+ throw new Error("Invalid prefix character");
2869
+ }
2870
+ this.prefixCodePoint = prefixCodePoint;
2871
+ this.baseDecode = baseDecode;
2872
+ }
2873
+ decode(text) {
2874
+ if (typeof text === "string") {
2875
+ if (text.codePointAt(0) !== this.prefixCodePoint) {
2876
+ throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
2877
+ }
2878
+ return this.baseDecode(text.slice(this.prefix.length));
2879
+ } else {
2880
+ throw Error("Can only multibase decode strings");
2881
+ }
2882
+ }
2883
+ or(decoder) {
2884
+ return or(this, decoder);
2885
+ }
2886
+ };
2887
+ var ComposedDecoder = class {
2888
+ constructor(decoders) {
2889
+ __publicField(this, "decoders");
2890
+ this.decoders = decoders;
2891
+ }
2892
+ or(decoder) {
2893
+ return or(this, decoder);
2894
+ }
2895
+ decode(input) {
2896
+ const prefix = input[0];
2897
+ const decoder = this.decoders[prefix];
2898
+ if (decoder != null) {
2899
+ return decoder.decode(input);
2900
+ } else {
2901
+ throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
2902
+ }
2903
+ }
2904
+ };
2905
+ function or(left, right) {
2906
+ return new ComposedDecoder({
2907
+ ...left.decoders ?? { [left.prefix]: left },
2908
+ ...right.decoders ?? { [right.prefix]: right }
2909
+ });
2910
+ }
2911
+ var Codec = class {
2912
+ constructor(name, prefix, baseEncode, baseDecode) {
2913
+ __publicField(this, "name");
2914
+ __publicField(this, "prefix");
2915
+ __publicField(this, "baseEncode");
2916
+ __publicField(this, "baseDecode");
2917
+ __publicField(this, "encoder");
2918
+ __publicField(this, "decoder");
2919
+ this.name = name;
2920
+ this.prefix = prefix;
2921
+ this.baseEncode = baseEncode;
2922
+ this.baseDecode = baseDecode;
2923
+ this.encoder = new Encoder(name, prefix, baseEncode);
2924
+ this.decoder = new Decoder(name, prefix, baseDecode);
2925
+ }
2926
+ encode(input) {
2927
+ return this.encoder.encode(input);
2928
+ }
2929
+ decode(input) {
2930
+ return this.decoder.decode(input);
2931
+ }
2932
+ };
2933
+ function from({ name, prefix, encode: encode3, decode: decode5 }) {
2934
+ return new Codec(name, prefix, encode3, decode5);
2935
+ }
2936
+ function baseX({ name, prefix, alphabet }) {
2937
+ const { encode: encode3, decode: decode5 } = base_x_default(alphabet, name);
2938
+ return from({
2939
+ prefix,
2940
+ name,
2941
+ encode: encode3,
2942
+ decode: (text) => coerce(decode5(text))
2943
+ });
2944
+ }
2945
+ function decode(string, alphabetIdx, bitsPerChar, name) {
2946
+ let end = string.length;
2947
+ while (string[end - 1] === "=") {
2948
+ --end;
2949
+ }
2950
+ const out = new Uint8Array(end * bitsPerChar / 8 | 0);
2951
+ let bits = 0;
2952
+ let buffer = 0;
2953
+ let written = 0;
2954
+ for (let i = 0; i < end; ++i) {
2955
+ const value = alphabetIdx[string[i]];
2956
+ if (value === void 0) {
2957
+ throw new SyntaxError(`Non-${name} character`);
2958
+ }
2959
+ buffer = buffer << bitsPerChar | value;
2960
+ bits += bitsPerChar;
2961
+ if (bits >= 8) {
2962
+ bits -= 8;
2963
+ out[written++] = 255 & buffer >> bits;
2964
+ }
2965
+ }
2966
+ if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
2967
+ throw new SyntaxError("Unexpected end of data");
2968
+ }
2969
+ return out;
2970
+ }
2971
+ function encode(data, alphabet, bitsPerChar) {
2972
+ const pad = alphabet[alphabet.length - 1] === "=";
2973
+ const mask = (1 << bitsPerChar) - 1;
2974
+ let out = "";
2975
+ let bits = 0;
2976
+ let buffer = 0;
2977
+ for (let i = 0; i < data.length; ++i) {
2978
+ buffer = buffer << 8 | data[i];
2979
+ bits += 8;
2980
+ while (bits > bitsPerChar) {
2981
+ bits -= bitsPerChar;
2982
+ out += alphabet[mask & buffer >> bits];
2983
+ }
2984
+ }
2985
+ if (bits !== 0) {
2986
+ out += alphabet[mask & buffer << bitsPerChar - bits];
2987
+ }
2988
+ if (pad) {
2989
+ while ((out.length * bitsPerChar & 7) !== 0) {
2990
+ out += "=";
2991
+ }
2992
+ }
2993
+ return out;
2994
+ }
2995
+ function createAlphabetIdx(alphabet) {
2996
+ const alphabetIdx = {};
2997
+ for (let i = 0; i < alphabet.length; ++i) {
2998
+ alphabetIdx[alphabet[i]] = i;
2999
+ }
3000
+ return alphabetIdx;
3001
+ }
3002
+ function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
3003
+ const alphabetIdx = createAlphabetIdx(alphabet);
3004
+ return from({
3005
+ prefix,
3006
+ name,
3007
+ encode(input) {
3008
+ return encode(input, alphabet, bitsPerChar);
3009
+ },
3010
+ decode(input) {
3011
+ return decode(input, alphabetIdx, bitsPerChar, name);
3012
+ }
3013
+ });
3014
+ }
3015
+
3016
+ // ../../node_modules/multiformats/dist/src/bases/base32.js
3017
+ var base32 = rfc4648({
3018
+ prefix: "b",
3019
+ name: "base32",
3020
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567",
3021
+ bitsPerChar: 5
3022
+ });
3023
+ var base32upper = rfc4648({
3024
+ prefix: "B",
3025
+ name: "base32upper",
3026
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
3027
+ bitsPerChar: 5
3028
+ });
3029
+ var base32pad = rfc4648({
3030
+ prefix: "c",
3031
+ name: "base32pad",
3032
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
3033
+ bitsPerChar: 5
3034
+ });
3035
+ var base32padupper = rfc4648({
3036
+ prefix: "C",
3037
+ name: "base32padupper",
3038
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
3039
+ bitsPerChar: 5
3040
+ });
3041
+ var base32hex = rfc4648({
3042
+ prefix: "v",
3043
+ name: "base32hex",
3044
+ alphabet: "0123456789abcdefghijklmnopqrstuv",
3045
+ bitsPerChar: 5
3046
+ });
3047
+ var base32hexupper = rfc4648({
3048
+ prefix: "V",
3049
+ name: "base32hexupper",
3050
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
3051
+ bitsPerChar: 5
3052
+ });
3053
+ var base32hexpad = rfc4648({
3054
+ prefix: "t",
3055
+ name: "base32hexpad",
3056
+ alphabet: "0123456789abcdefghijklmnopqrstuv=",
3057
+ bitsPerChar: 5
3058
+ });
3059
+ var base32hexpadupper = rfc4648({
3060
+ prefix: "T",
3061
+ name: "base32hexpadupper",
3062
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
3063
+ bitsPerChar: 5
3064
+ });
3065
+ var base32z = rfc4648({
3066
+ prefix: "h",
3067
+ name: "base32z",
3068
+ alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
3069
+ bitsPerChar: 5
3070
+ });
3071
+
3072
+ // ../../node_modules/multiformats/dist/src/bases/base36.js
3073
+ var base36 = baseX({
3074
+ prefix: "k",
3075
+ name: "base36",
3076
+ alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
3077
+ });
3078
+ var base36upper = baseX({
3079
+ prefix: "K",
3080
+ name: "base36upper",
3081
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3082
+ });
3083
+
3084
+ // ../../node_modules/multiformats/dist/src/bases/base58.js
3085
+ var base58btc = baseX({
3086
+ name: "base58btc",
3087
+ prefix: "z",
3088
+ alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
3089
+ });
3090
+ var base58flickr = baseX({
3091
+ name: "base58flickr",
3092
+ prefix: "Z",
3093
+ alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
3094
+ });
3095
+
3096
+ // ../../node_modules/multiformats/dist/src/vendor/varint.js
3097
+ var encode_1 = encode2;
3098
+ var MSB = 128;
3099
+ var REST = 127;
3100
+ var MSBALL = ~REST;
3101
+ var INT = Math.pow(2, 31);
3102
+ function encode2(num, out, offset) {
3103
+ out = out || [];
3104
+ offset = offset || 0;
3105
+ var oldOffset = offset;
3106
+ while (num >= INT) {
3107
+ out[offset++] = num & 255 | MSB;
3108
+ num /= 128;
3109
+ }
3110
+ while (num & MSBALL) {
3111
+ out[offset++] = num & 255 | MSB;
3112
+ num >>>= 7;
3113
+ }
3114
+ out[offset] = num | 0;
3115
+ encode2.bytes = offset - oldOffset + 1;
3116
+ return out;
3117
+ }
3118
+ var decode2 = read;
3119
+ var MSB$1 = 128;
3120
+ var REST$1 = 127;
3121
+ function read(buf, offset) {
3122
+ var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
3123
+ do {
3124
+ if (counter >= l) {
3125
+ read.bytes = 0;
3126
+ throw new RangeError("Could not decode varint");
3127
+ }
3128
+ b = buf[counter++];
3129
+ res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
3130
+ shift += 7;
3131
+ } while (b >= MSB$1);
3132
+ read.bytes = counter - offset;
3133
+ return res;
3134
+ }
3135
+ var N1 = Math.pow(2, 7);
3136
+ var N2 = Math.pow(2, 14);
3137
+ var N3 = Math.pow(2, 21);
3138
+ var N4 = Math.pow(2, 28);
3139
+ var N5 = Math.pow(2, 35);
3140
+ var N6 = Math.pow(2, 42);
3141
+ var N7 = Math.pow(2, 49);
3142
+ var N8 = Math.pow(2, 56);
3143
+ var N9 = Math.pow(2, 63);
3144
+ var length = function(value) {
3145
+ return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
3146
+ };
3147
+ var varint = {
3148
+ encode: encode_1,
3149
+ decode: decode2,
3150
+ encodingLength: length
3151
+ };
3152
+ var _brrp_varint = varint;
3153
+ var varint_default = _brrp_varint;
3154
+
3155
+ // ../../node_modules/multiformats/dist/src/varint.js
3156
+ function decode3(data, offset = 0) {
3157
+ const code = varint_default.decode(data, offset);
3158
+ return [code, varint_default.decode.bytes];
3159
+ }
3160
+ function encodeTo(int, target, offset = 0) {
3161
+ varint_default.encode(int, target, offset);
3162
+ return target;
3163
+ }
3164
+ function encodingLength(int) {
3165
+ return varint_default.encodingLength(int);
3166
+ }
3167
+
3168
+ // ../../node_modules/multiformats/dist/src/hashes/digest.js
3169
+ function create(code, digest) {
3170
+ const size = digest.byteLength;
3171
+ const sizeOffset = encodingLength(code);
3172
+ const digestOffset = sizeOffset + encodingLength(size);
3173
+ const bytes = new Uint8Array(digestOffset + size);
3174
+ encodeTo(code, bytes, 0);
3175
+ encodeTo(size, bytes, sizeOffset);
3176
+ bytes.set(digest, digestOffset);
3177
+ return new Digest(code, size, digest, bytes);
3178
+ }
3179
+ function decode4(multihash) {
3180
+ const bytes = coerce(multihash);
3181
+ const [code, sizeOffset] = decode3(bytes);
3182
+ const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
3183
+ const digest = bytes.subarray(sizeOffset + digestOffset);
3184
+ if (digest.byteLength !== size) {
3185
+ throw new Error("Incorrect length");
3186
+ }
3187
+ return new Digest(code, size, digest, bytes);
3188
+ }
3189
+ function equals2(a, b) {
3190
+ if (a === b) {
3191
+ return true;
3192
+ } else {
3193
+ const data = b;
3194
+ return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
3195
+ }
3196
+ }
3197
+ var Digest = class {
3198
+ /**
3199
+ * Creates a multihash digest.
3200
+ */
3201
+ constructor(code, size, digest, bytes) {
3202
+ __publicField(this, "code");
3203
+ __publicField(this, "size");
3204
+ __publicField(this, "digest");
3205
+ __publicField(this, "bytes");
3206
+ this.code = code;
3207
+ this.size = size;
3208
+ this.digest = digest;
3209
+ this.bytes = bytes;
3210
+ }
3211
+ };
3212
+
3213
+ // ../../node_modules/multiformats/dist/src/cid.js
3214
+ function format(link2, base2) {
3215
+ const { bytes, version } = link2;
3216
+ switch (version) {
3217
+ case 0:
3218
+ return toStringV0(bytes, baseCache(link2), base2 ?? base58btc.encoder);
3219
+ default:
3220
+ return toStringV1(bytes, baseCache(link2), base2 ?? base32.encoder);
3221
+ }
3222
+ }
3223
+ var cache = /* @__PURE__ */ new WeakMap();
3224
+ function baseCache(cid) {
3225
+ const baseCache2 = cache.get(cid);
3226
+ if (baseCache2 == null) {
3227
+ const baseCache3 = /* @__PURE__ */ new Map();
3228
+ cache.set(cid, baseCache3);
3229
+ return baseCache3;
3230
+ }
3231
+ return baseCache2;
3232
+ }
3233
+ var _a;
3234
+ var CID = class _CID {
3235
+ /**
3236
+ * @param version - Version of the CID
3237
+ * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
3238
+ * @param multihash - (Multi)hash of the of the content.
3239
+ */
3240
+ constructor(version, code, multihash, bytes) {
3241
+ __publicField(this, "code");
3242
+ __publicField(this, "version");
3243
+ __publicField(this, "multihash");
3244
+ __publicField(this, "bytes");
3245
+ __publicField(this, "/");
3246
+ __publicField(this, _a, "CID");
3247
+ this.code = code;
3248
+ this.version = version;
3249
+ this.multihash = multihash;
3250
+ this.bytes = bytes;
3251
+ this["/"] = bytes;
3252
+ }
3253
+ /**
3254
+ * Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
3255
+ * please either use `CID.asCID(cid)` or switch to new signalling mechanism
3256
+ *
3257
+ * @deprecated
3258
+ */
3259
+ get asCID() {
3260
+ return this;
3261
+ }
3262
+ // ArrayBufferView
3263
+ get byteOffset() {
3264
+ return this.bytes.byteOffset;
3265
+ }
3266
+ // ArrayBufferView
3267
+ get byteLength() {
3268
+ return this.bytes.byteLength;
3269
+ }
3270
+ toV0() {
3271
+ switch (this.version) {
3272
+ case 0: {
3273
+ return this;
3274
+ }
3275
+ case 1: {
3276
+ const { code, multihash } = this;
3277
+ if (code !== DAG_PB_CODE) {
3278
+ throw new Error("Cannot convert a non dag-pb CID to CIDv0");
3279
+ }
3280
+ if (multihash.code !== SHA_256_CODE) {
3281
+ throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
3282
+ }
3283
+ return _CID.createV0(multihash);
115
3284
  }
116
- if (msAbs >= s) {
117
- return Math.round(ms2 / s) + "s";
3285
+ default: {
3286
+ throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
118
3287
  }
119
- return ms2 + "ms";
120
3288
  }
121
- function fmtLong(ms2) {
122
- var msAbs = Math.abs(ms2);
123
- if (msAbs >= d) {
124
- return plural(ms2, msAbs, d, "day");
125
- }
126
- if (msAbs >= h) {
127
- return plural(ms2, msAbs, h, "hour");
3289
+ }
3290
+ toV1() {
3291
+ switch (this.version) {
3292
+ case 0: {
3293
+ const { code, digest } = this.multihash;
3294
+ const multihash = create(code, digest);
3295
+ return _CID.createV1(this.code, multihash);
128
3296
  }
129
- if (msAbs >= m) {
130
- return plural(ms2, msAbs, m, "minute");
3297
+ case 1: {
3298
+ return this;
131
3299
  }
132
- if (msAbs >= s) {
133
- return plural(ms2, msAbs, s, "second");
3300
+ default: {
3301
+ throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
134
3302
  }
135
- return ms2 + " ms";
136
3303
  }
137
- function plural(ms2, msAbs, n, name) {
138
- var isPlural = msAbs >= n * 1.5;
139
- return Math.round(ms2 / n) + " " + name + (isPlural ? "s" : "");
3304
+ }
3305
+ equals(other) {
3306
+ return _CID.equals(this, other);
3307
+ }
3308
+ static equals(self, other) {
3309
+ const unknown = other;
3310
+ return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
3311
+ }
3312
+ toString(base2) {
3313
+ return format(this, base2);
3314
+ }
3315
+ toJSON() {
3316
+ return { "/": format(this) };
3317
+ }
3318
+ link() {
3319
+ return this;
3320
+ }
3321
+ // Legacy
3322
+ [(_a = Symbol.toStringTag, /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom"))]() {
3323
+ return `CID(${this.toString()})`;
3324
+ }
3325
+ /**
3326
+ * Takes any input `value` and returns a `CID` instance if it was
3327
+ * a `CID` otherwise returns `null`. If `value` is instanceof `CID`
3328
+ * it will return value back. If `value` is not instance of this CID
3329
+ * class, but is compatible CID it will return new instance of this
3330
+ * `CID` class. Otherwise returns null.
3331
+ *
3332
+ * This allows two different incompatible versions of CID library to
3333
+ * co-exist and interop as long as binary interface is compatible.
3334
+ */
3335
+ static asCID(input) {
3336
+ if (input == null) {
3337
+ return null;
3338
+ }
3339
+ const value = input;
3340
+ if (value instanceof _CID) {
3341
+ return value;
3342
+ } else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
3343
+ const { version, code, multihash, bytes } = value;
3344
+ return new _CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
3345
+ } else if (value[cidSymbol] === true) {
3346
+ const { version, multihash, code } = value;
3347
+ const digest = decode4(multihash);
3348
+ return _CID.create(version, code, digest);
3349
+ } else {
3350
+ return null;
140
3351
  }
141
3352
  }
142
- });
143
-
144
- // src/delegation-binding.ts
145
- import { join as join2 } from "path";
146
- import * as nodeSdk2 from "@tinycloud/node-sdk";
147
-
148
- // src/artifacts.ts
149
- import { randomUUID as randomUUID2 } from "crypto";
150
- import { z } from "zod";
151
-
152
- // ../sdk-core/src/manifest.ts
153
- var import_ms = __toESM(require_ms(), 1);
154
- import { resolveSecretPath, SECRET_NAME_RE } from "@tinycloud/sdk-services";
155
- var DEFAULT_MANIFEST_SPACE = "applications";
156
- var SERVICE_SHORT_TO_LONG = Object.freeze({
157
- kv: "tinycloud.kv",
158
- sql: "tinycloud.sql",
159
- duckdb: "tinycloud.duckdb",
160
- capabilities: "tinycloud.capabilities",
161
- hooks: "tinycloud.hooks",
162
- encryption: "tinycloud.encryption",
163
- delegation: "tinycloud.delegation"
164
- });
165
- var SERVICE_LONG_TO_SHORT = Object.freeze(
166
- Object.fromEntries(
167
- Object.entries(SERVICE_SHORT_TO_LONG).map(([s, l]) => [l, s])
168
- )
169
- );
170
- function expandActionShortNames(service, actions) {
171
- return actions.map((a) => {
172
- if (a.includes("/")) {
173
- return a;
3353
+ /**
3354
+ * @param version - Version of the CID
3355
+ * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
3356
+ * @param digest - (Multi)hash of the of the content.
3357
+ */
3358
+ static create(version, code, digest) {
3359
+ if (typeof code !== "number") {
3360
+ throw new Error("String codecs are no longer supported");
3361
+ }
3362
+ if (!(digest.bytes instanceof Uint8Array)) {
3363
+ throw new Error("Invalid digest");
3364
+ }
3365
+ switch (version) {
3366
+ case 0: {
3367
+ if (code !== DAG_PB_CODE) {
3368
+ throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
3369
+ } else {
3370
+ return new _CID(version, code, digest, digest.bytes);
3371
+ }
3372
+ }
3373
+ case 1: {
3374
+ const bytes = encodeCID(version, code, digest.bytes);
3375
+ return new _CID(version, code, digest, bytes);
3376
+ }
3377
+ default: {
3378
+ throw new Error("Invalid version");
3379
+ }
174
3380
  }
175
- return `${service}/${a}`;
176
- });
177
- }
178
-
179
- // ../sdk-core/src/capabilities.ts
180
- function normalizeSpace(space) {
181
- if (!space.startsWith("tinycloud:")) {
182
- return space;
183
3381
  }
184
- const lastColon = space.lastIndexOf(":");
185
- if (lastColon === -1 || lastColon === space.length - 1) {
186
- return space;
3382
+ /**
3383
+ * Simplified version of `create` for CIDv0.
3384
+ */
3385
+ static createV0(digest) {
3386
+ return _CID.create(0, DAG_PB_CODE, digest);
187
3387
  }
188
- return space.slice(lastColon + 1);
189
- }
190
- function isCapabilitySubset(requested, granted) {
191
- const missing = [];
192
- for (const req of requested) {
193
- const matchingScope = granted.filter(
194
- (entry) => canonicalizeEntryScopeMatches(req, entry)
195
- );
196
- const requestedActions = expandActionShortNames(
197
- req.service,
198
- req.actions
199
- );
200
- const grantedActions = matchingScope.flatMap(
201
- (entry) => expandActionShortNames(entry.service, entry.actions)
202
- );
203
- const covered = requestedActions.every(
204
- (requestedAction) => grantedActions.some(
205
- (grantedAction) => actionContains(grantedAction, requestedAction)
206
- )
207
- );
208
- if (!covered) {
209
- missing.push(cloneEntry(req));
210
- }
3388
+ /**
3389
+ * Simplified version of `create` for CIDv1.
3390
+ *
3391
+ * @param code - Content encoding format code.
3392
+ * @param digest - Multihash of the content.
3393
+ */
3394
+ static createV1(code, digest) {
3395
+ return _CID.create(1, code, digest);
211
3396
  }
212
- return { subset: missing.length === 0, missing };
213
- }
214
- function canonicalizeEntryScopeMatches(requested, granted) {
215
- if (requested.service !== granted.service) {
216
- return false;
3397
+ /**
3398
+ * Decoded a CID from its binary representation. The byte array must contain
3399
+ * only the CID with no additional bytes.
3400
+ *
3401
+ * An error will be thrown if the bytes provided do not contain a valid
3402
+ * binary representation of a CID.
3403
+ */
3404
+ static decode(bytes) {
3405
+ const [cid, remainder] = _CID.decodeFirst(bytes);
3406
+ if (remainder.length !== 0) {
3407
+ throw new Error("Incorrect length");
3408
+ }
3409
+ return cid;
217
3410
  }
218
- if (normalizeSpace(requested.space ?? DEFAULT_MANIFEST_SPACE) !== normalizeSpace(granted.space ?? DEFAULT_MANIFEST_SPACE)) {
219
- return false;
3411
+ /**
3412
+ * Decoded a CID from its binary representation at the beginning of a byte
3413
+ * array.
3414
+ *
3415
+ * Returns an array with the first element containing the CID and the second
3416
+ * element containing the remainder of the original byte array. The remainder
3417
+ * will be a zero-length byte array if the provided bytes only contained a
3418
+ * binary CID representation.
3419
+ */
3420
+ static decodeFirst(bytes) {
3421
+ const specs = _CID.inspectBytes(bytes);
3422
+ const prefixSize = specs.size - specs.multihashSize;
3423
+ const multihashBytes = coerce(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
3424
+ if (multihashBytes.byteLength !== specs.multihashSize) {
3425
+ throw new Error("Incorrect length");
3426
+ }
3427
+ const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
3428
+ const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
3429
+ const cid = specs.version === 0 ? _CID.createV0(digest) : _CID.createV1(specs.codec, digest);
3430
+ return [cid, bytes.subarray(specs.size)];
220
3431
  }
221
- if (!pathContains(granted.path, requested.path)) {
222
- return false;
3432
+ /**
3433
+ * Inspect the initial bytes of a CID to determine its properties.
3434
+ *
3435
+ * Involves decoding up to 4 varints. Typically this will require only 4 to 6
3436
+ * bytes but for larger multicodec code values and larger multihash digest
3437
+ * lengths these varints can be quite large. It is recommended that at least
3438
+ * 10 bytes be made available in the `initialBytes` argument for a complete
3439
+ * inspection.
3440
+ */
3441
+ static inspectBytes(initialBytes) {
3442
+ let offset = 0;
3443
+ const next = () => {
3444
+ const [i, length2] = decode3(initialBytes.subarray(offset));
3445
+ offset += length2;
3446
+ return i;
3447
+ };
3448
+ let version = next();
3449
+ let codec = DAG_PB_CODE;
3450
+ if (version === 18) {
3451
+ version = 0;
3452
+ offset = 0;
3453
+ } else {
3454
+ codec = next();
3455
+ }
3456
+ if (version !== 0 && version !== 1) {
3457
+ throw new RangeError(`Invalid CID version ${version}`);
3458
+ }
3459
+ const prefixSize = offset;
3460
+ const multihashCode = next();
3461
+ const digestSize = next();
3462
+ const size = offset + digestSize;
3463
+ const multihashSize = size - prefixSize;
3464
+ return { version, codec, multihashCode, digestSize, multihashSize, size };
223
3465
  }
224
- if (!recapCaveatsEqual(requested.caveats, granted.caveats)) {
225
- return false;
3466
+ /**
3467
+ * Takes cid in a string representation and creates an instance. If `base`
3468
+ * decoder is not provided will use a default from the configuration. It will
3469
+ * throw an error if encoding of the CID is not compatible with supplied (or
3470
+ * a default decoder).
3471
+ */
3472
+ static parse(source, base2) {
3473
+ const [prefix, bytes] = parseCIDtoBytes(source, base2);
3474
+ const cid = _CID.decode(bytes);
3475
+ if (cid.version === 0 && source[0] !== "Q") {
3476
+ throw Error("Version 0 CID string must not include multibase prefix");
3477
+ }
3478
+ baseCache(cid).set(prefix, source);
3479
+ return cid;
226
3480
  }
227
- return true;
228
- }
229
- function recapCaveatsEqual(left, right) {
230
- return canonicalizeRecapCaveats(left) === canonicalizeRecapCaveats(right);
231
- }
232
- function canonicalizeRecapCaveats(caveats) {
233
- const canonicalize = (value) => {
234
- if (value === null || typeof value === "boolean" || typeof value === "string") {
235
- return JSON.stringify(value);
3481
+ };
3482
+ function parseCIDtoBytes(source, base2) {
3483
+ switch (source[0]) {
3484
+ // CIDv0 is parsed differently
3485
+ case "Q": {
3486
+ const decoder = base2 ?? base58btc;
3487
+ return [
3488
+ base58btc.prefix,
3489
+ decoder.decode(`${base58btc.prefix}${source}`)
3490
+ ];
236
3491
  }
237
- if (typeof value === "number") {
238
- if (Number.isFinite(value)) return JSON.stringify(value);
239
- throw new Error("ReCap caveats must contain only JSON values.");
3492
+ case base58btc.prefix: {
3493
+ const decoder = base2 ?? base58btc;
3494
+ return [base58btc.prefix, decoder.decode(source)];
240
3495
  }
241
- if (Array.isArray(value)) return `[${value.map(canonicalize).join(",")}]`;
242
- if (typeof value === "object") {
243
- const object = value;
244
- const prototype = Object.getPrototypeOf(object);
245
- if (prototype !== Object.prototype && prototype !== null) {
246
- throw new Error("ReCap caveats must contain only JSON values.");
3496
+ case base32.prefix: {
3497
+ const decoder = base2 ?? base32;
3498
+ return [base32.prefix, decoder.decode(source)];
3499
+ }
3500
+ case base36.prefix: {
3501
+ const decoder = base2 ?? base36;
3502
+ return [base36.prefix, decoder.decode(source)];
3503
+ }
3504
+ default: {
3505
+ if (base2 == null) {
3506
+ throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
247
3507
  }
248
- return `{${Object.keys(object).sort().map(
249
- (key) => `${JSON.stringify(key)}:${canonicalize(object[key])}`
250
- ).join(",")}}`;
3508
+ return [source[0], base2.decode(source)];
251
3509
  }
252
- throw new Error("ReCap caveats must contain only JSON values.");
253
- };
254
- const branches = (caveats ?? []).map(canonicalize).sort();
255
- if (branches.length === 0 || branches.length === 1 && branches[0] === "{}") {
256
- return "[]";
257
3510
  }
258
- return `[${branches.join(",")}]`;
259
- }
260
- var EXPLICIT_ONLY_ACTIONS = {
261
- "tinycloud.kv/sync": true,
262
- "tinycloud.kv/retain": true
263
- };
264
- function isExplicitOnlyAction(action) {
265
- return Object.prototype.hasOwnProperty.call(EXPLICIT_ONLY_ACTIONS, action);
266
- }
267
- function actionContains(grantedAction, requestedAction) {
268
- if (grantedAction === requestedAction) return true;
269
- if (isExplicitOnlyAction(requestedAction)) return false;
270
- if (grantedAction === "*") return true;
271
- if (!grantedAction.endsWith("/*")) return false;
272
- const service = grantedAction.slice(0, -2);
273
- return requestedAction === service || requestedAction.startsWith(`${service}/`);
274
3511
  }
275
- function pathContains(grantedPath, requestedPath) {
276
- if (grantedPath === "" || grantedPath === "/") {
277
- return true;
3512
+ function toStringV0(bytes, cache2, base2) {
3513
+ const { prefix } = base2;
3514
+ if (prefix !== base58btc.prefix) {
3515
+ throw Error(`Cannot string encode V0 in ${base2.name} encoding`);
278
3516
  }
279
- if (grantedPath.endsWith("/")) {
280
- return requestedPath.startsWith(grantedPath);
3517
+ const cid = cache2.get(prefix);
3518
+ if (cid == null) {
3519
+ const cid2 = base2.encode(bytes).slice(1);
3520
+ cache2.set(prefix, cid2);
3521
+ return cid2;
3522
+ } else {
3523
+ return cid;
281
3524
  }
282
- return requestedPath === grantedPath;
283
3525
  }
284
- function cloneEntry(entry) {
285
- return {
286
- service: entry.service,
287
- ...entry.space !== void 0 ? { space: entry.space } : {},
288
- path: entry.path,
289
- actions: [...entry.actions],
290
- ...entry.caveats !== void 0 ? { caveats: JSON.parse(JSON.stringify(entry.caveats)) } : {},
291
- ...entry.skipPrefix !== void 0 ? { skipPrefix: entry.skipPrefix } : {},
292
- ...entry.expiry !== void 0 ? { expiry: entry.expiry } : {}
293
- };
3526
+ function toStringV1(bytes, cache2, base2) {
3527
+ const { prefix } = base2;
3528
+ const cid = cache2.get(prefix);
3529
+ if (cid == null) {
3530
+ const cid2 = base2.encode(bytes);
3531
+ cache2.set(prefix, cid2);
3532
+ return cid2;
3533
+ } else {
3534
+ return cid;
3535
+ }
3536
+ }
3537
+ var DAG_PB_CODE = 112;
3538
+ var SHA_256_CODE = 18;
3539
+ function encodeCID(version, code, multihash) {
3540
+ const codeOffset = encodingLength(version);
3541
+ const hashOffset = codeOffset + encodingLength(code);
3542
+ const bytes = new Uint8Array(hashOffset + multihash.byteLength);
3543
+ encodeTo(version, bytes, 0);
3544
+ encodeTo(code, bytes, codeOffset);
3545
+ bytes.set(multihash, hashOffset);
3546
+ return bytes;
3547
+ }
3548
+ var cidSymbol = /* @__PURE__ */ Symbol.for("@ipld/js-cid/CID");
3549
+
3550
+ // ../sdk-core/src/policy/unified.ts
3551
+ import { z } from "zod";
3552
+ var CompactHeaderSchema = z.object({
3553
+ alg: z.literal("EdDSA"),
3554
+ jwk: z.object({ alg: z.literal("EdDSA"), crv: z.literal("Ed25519"), kty: z.literal("OKP"), x: z.string().min(1) }).strict(),
3555
+ typ: z.literal("JWT"),
3556
+ ucv: z.literal("0.10.0")
3557
+ }).strict();
3558
+ var CompactPayloadSchema = z.object({
3559
+ att: z.record(z.record(z.array(z.unknown()).min(1))),
3560
+ aud: z.string().min(1),
3561
+ exp: z.number().int(),
3562
+ fct: z.array(z.record(z.unknown())).length(1),
3563
+ iss: z.string().min(1),
3564
+ nbf: z.number().int(),
3565
+ nnc: z.string().min(1),
3566
+ prf: z.array(z.string().min(1))
3567
+ }).strict();
3568
+ var MAX_POLICY_ROOT_SECONDS = 31 * 24 * 60 * 60;
3569
+ function isRecordValue(value) {
3570
+ return value !== null && typeof value === "object" && !Array.isArray(value);
294
3571
  }
3572
+ var SignedCompactAttenuationSchema = z.record(z.record(z.array(z.unknown()).min(1)));
3573
+ function parseSignedCompactUcanAttenuation(input, expectedCid) {
3574
+ if (typeof input !== "string" || /\s/.test(input))
3575
+ throw new Error("Authorization must be compact UCAN bytes");
3576
+ const segments = input.split(".");
3577
+ if (segments.length !== 3 || segments.some((segment) => segment.length === 0))
3578
+ throw new Error("Authorization must have three compact segments");
3579
+ const [headerSegment, payloadSegment, signatureSegment] = segments;
3580
+ const headerValue = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(decodeBase64Url(headerSegment)));
3581
+ const payloadValue = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(decodeBase64Url(payloadSegment)));
3582
+ if (!isRecordValue(headerValue) || !isRecordValue(headerValue.jwk) || headerValue.alg !== "EdDSA" || headerValue.typ !== "JWT" || headerValue.ucv !== "0.10.0" || headerValue.jwk.kty !== "OKP" || headerValue.jwk.crv !== "Ed25519" || !isRecordValue(payloadValue) || typeof payloadValue.iss !== "string")
3583
+ throw new Error("Authorization has an invalid signed UCAN header or issuer");
3584
+ const att = SignedCompactAttenuationSchema.parse(payloadValue.att);
3585
+ const principal = payloadValue.iss.split("#", 1)[0];
3586
+ const didMaterial = principal.startsWith("did:key:") ? base58btc.decode(principal.slice("did:key:".length)) : new Uint8Array();
3587
+ const publicKey = didMaterial.length === 34 && didMaterial[0] === 237 && didMaterial[1] === 1 ? didMaterial.slice(2) : new Uint8Array();
3588
+ const jwkKey = typeof headerValue.jwk.x === "string" ? decodeBase64Url(headerValue.jwk.x) : new Uint8Array();
3589
+ if (publicKey.length !== 32 || !equalBytes2(publicKey, jwkKey))
3590
+ throw new Error("compact UCAN JWK does not bind issuer");
3591
+ const signature = decodeBase64Url(signatureSegment);
3592
+ if (!ed25519.verify(signature, new TextEncoder().encode(`${headerSegment}.${payloadSegment}`), publicKey))
3593
+ throw new Error("compact UCAN signature is invalid");
3594
+ if (typeof payloadValue.aud !== "string" || payloadValue.aud.length === 0)
3595
+ throw new Error("compact UCAN signed audience is missing");
3596
+ const cid = CID.createV1(85, create(30, blake3(new TextEncoder().encode(input)))).toString();
3597
+ if (expectedCid !== void 0 && cid !== expectedCid) throw new Error("compact UCAN CID does not match exact Authorization bytes");
3598
+ return { cid, payload: { att, aud: payloadValue.aud } };
3599
+ }
3600
+ function decodeBase64Url(value) {
3601
+ if (!/^[A-Za-z0-9_-]+$/.test(value) || value.length % 4 === 1)
3602
+ throw new Error("value is not canonical base64url");
3603
+ const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
3604
+ const binary = typeof atob === "function" ? atob(normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "=")) : Buffer.from(normalized, "base64").toString("binary");
3605
+ const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
3606
+ const encoded = typeof btoa === "function" ? btoa(String.fromCharCode(...bytes)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_") : Buffer.from(bytes).toString("base64url");
3607
+ if (encoded !== value) throw new Error("value is not canonical base64url");
3608
+ return bytes;
3609
+ }
3610
+ function equalBytes2(left, right) {
3611
+ return left.length === right.length && left.every((byte, index) => byte === right[index]);
3612
+ }
3613
+
3614
+ // src/delegation-binding.ts
3615
+ import * as nodeSdk2 from "@tinycloud/node-sdk";
3616
+
3617
+ // src/artifacts.ts
3618
+ import { randomUUID as randomUUID2 } from "crypto";
3619
+ import { z as z2 } from "zod";
295
3620
 
296
3621
  // src/authority.ts
297
3622
  function evaluateOperationAuthority(granted, required, resolveSpace) {
@@ -413,9 +3738,9 @@ var TEST_LOCK_TURN_PUBLISH_BARRIER_DIR = "TC_TEST_PROFILE_LOCK_TURN_PUBLISH_BARR
413
3738
  var TEST_LOCK_TURN_SETTLE_BARRIER_DIR = "TC_TEST_PROFILE_LOCK_TURN_SETTLE_BARRIER_DIR";
414
3739
  var TEST_LOCK_TURN_COLLECT_BARRIER_DIR = "TC_TEST_PROFILE_LOCK_TURN_COLLECT_BARRIER_DIR";
415
3740
  function processWideContext(key) {
416
- var _a2;
3741
+ var _a3;
417
3742
  const registry = globalThis;
418
- return registry[_a2 = Symbol.for(key)] ?? (registry[_a2] = new AsyncLocalStorage());
3743
+ return registry[_a3 = Symbol.for(key)] ?? (registry[_a3] = new AsyncLocalStorage());
419
3744
  }
420
3745
  var invocationStateRoot = processWideContext("tinycloud.operations.invocationStateRoot.v1");
421
3746
  var heldProfileLocks = processWideContext("tinycloud.operations.heldProfileLocks.v2");
@@ -632,8 +3957,8 @@ async function waitOrTimeOut(profile, deadline, detail) {
632
3957
  await sleep(Math.min(deadline.retryMs, deadline.timeoutMs - (Date.now() - deadline.startedAt)));
633
3958
  }
634
3959
  var TURN = /^(?:0|[1-9][0-9]*)$/;
635
- var _a;
636
- var relinquishedTurns = globalThis[_a = /* @__PURE__ */ Symbol.for("tinycloud.operations.relinquishedProfileTurns.v1")] ?? (globalThis[_a] = /* @__PURE__ */ new Set());
3960
+ var _a2;
3961
+ var relinquishedTurns = globalThis[_a2 = /* @__PURE__ */ Symbol.for("tinycloud.operations.relinquishedProfileTurns.v1")] ?? (globalThis[_a2] = /* @__PURE__ */ new Set());
637
3962
  var MARKER_RETRY_DELAYS_MS = [10, 50, 250];
638
3963
  var SETTLE_RETRY_MS = 1e3;
639
3964
  var SETTLE_RETRIES = 300;
@@ -1085,70 +4410,70 @@ function sleep(milliseconds) {
1085
4410
 
1086
4411
  // src/artifacts.ts
1087
4412
  var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
1088
- var PermissionEntrySchema = z.object({
1089
- service: z.string().min(1),
1090
- space: z.string().min(1).optional(),
1091
- path: z.string(),
1092
- actions: z.array(z.string().min(1)).min(1),
1093
- caveats: z.array(z.record(z.unknown())).optional(),
1094
- skipPrefix: z.boolean().optional(),
1095
- expiry: z.string().min(1).optional(),
1096
- description: z.string().optional()
4413
+ var PermissionEntrySchema = z2.object({
4414
+ service: z2.string().min(1),
4415
+ space: z2.string().min(1).optional(),
4416
+ path: z2.string(),
4417
+ actions: z2.array(z2.string().min(1)).min(1),
4418
+ caveats: z2.array(z2.record(z2.unknown())).optional(),
4419
+ skipPrefix: z2.boolean().optional(),
4420
+ expiry: z2.string().min(1).optional(),
4421
+ description: z2.string().optional()
1097
4422
  }).strict();
1098
- var CommandSchema = z.object({
1099
- argv: z.array(z.string()).min(1),
1100
- cwd: z.string().min(1)
4423
+ var CommandSchema = z2.object({
4424
+ argv: z2.array(z2.string()).min(1),
4425
+ cwd: z2.string().min(1)
1101
4426
  }).strict();
1102
- var LegacyPermissionRequestArtifactSchema = z.object({
1103
- kind: z.literal("tinycloud.auth.request"),
1104
- version: z.literal(1),
1105
- requestId: z.string(),
1106
- sessionDid: z.string().min(1),
1107
- requested: z.array(PermissionEntrySchema),
1108
- requestedExpiry: z.union([z.string(), z.number().finite()]).optional()
4427
+ var LegacyPermissionRequestArtifactSchema = z2.object({
4428
+ kind: z2.literal("tinycloud.auth.request"),
4429
+ version: z2.literal(1),
4430
+ requestId: z2.string(),
4431
+ sessionDid: z2.string().min(1),
4432
+ requested: z2.array(PermissionEntrySchema),
4433
+ requestedExpiry: z2.union([z2.string(), z2.number().finite()]).optional()
1109
4434
  }).strict();
1110
- var PortableDelegationSchema = z.lazy(() => z.object({
1111
- cid: z.string().min(1),
1112
- spaceId: z.string().min(1),
1113
- path: z.string(),
1114
- actions: z.array(z.string().min(1)).min(1),
1115
- delegateDID: z.string().min(1),
1116
- ownerAddress: z.string().min(1),
1117
- chainId: z.number().int().positive(),
1118
- expiry: z.union([z.string().datetime({ offset: true }), z.date()]),
1119
- delegationHeader: z.object({ Authorization: z.string().min(1) }).strict(),
1120
- host: z.string().min(1).optional(),
1121
- disableSubDelegation: z.boolean().optional(),
4435
+ var PortableDelegationSchema = z2.lazy(() => z2.object({
4436
+ cid: z2.string().min(1),
4437
+ spaceId: z2.string().min(1),
4438
+ path: z2.string(),
4439
+ actions: z2.array(z2.string().min(1)).min(1),
4440
+ delegateDID: z2.string().min(1),
4441
+ ownerAddress: z2.string().min(1),
4442
+ chainId: z2.number().int().positive(),
4443
+ expiry: z2.union([z2.string().datetime({ offset: true }), z2.date()]),
4444
+ delegationHeader: z2.object({ Authorization: z2.string().min(1) }).strict(),
4445
+ host: z2.string().min(1).optional(),
4446
+ disableSubDelegation: z2.boolean().optional(),
1122
4447
  publicDelegation: PortableDelegationSchema.optional(),
1123
- resources: z.array(PermissionEntrySchema).optional()
4448
+ resources: z2.array(PermissionEntrySchema).optional()
1124
4449
  }).passthrough());
1125
- var PermissionRequestArtifactSchema = z.object({
1126
- kind: z.literal("tinycloud.auth.request"),
1127
- version: z.literal(1),
1128
- requestId: z.string().min(1),
1129
- createdAt: z.string().datetime({ offset: true }),
1130
- profile: z.string().min(1),
1131
- posture: z.enum(["owner-openkey", "delegate-session", "local-owner-key", "unauthenticated"]),
1132
- operatorType: z.enum(["human", "agent"]),
1133
- host: z.string().min(1),
1134
- sessionDid: z.string().min(1),
1135
- ownerDid: z.string().min(1).optional(),
1136
- spaceId: z.string().min(1).optional(),
1137
- requestedExpiry: z.union([z.string().min(1), z.number().finite()]).optional(),
1138
- requested: z.array(PermissionEntrySchema),
4450
+ var PermissionRequestArtifactSchema = z2.object({
4451
+ kind: z2.literal("tinycloud.auth.request"),
4452
+ version: z2.literal(1),
4453
+ requestId: z2.string().min(1),
4454
+ createdAt: z2.string().datetime({ offset: true }),
4455
+ profile: z2.string().min(1),
4456
+ posture: z2.enum(["owner-openkey", "delegate-session", "local-owner-key", "unauthenticated"]),
4457
+ operatorType: z2.enum(["human", "agent"]),
4458
+ host: z2.string().min(1),
4459
+ sessionDid: z2.string().min(1),
4460
+ ownerDid: z2.string().min(1).optional(),
4461
+ spaceId: z2.string().min(1).optional(),
4462
+ requestedExpiry: z2.union([z2.string().min(1), z2.number().finite()]).optional(),
4463
+ requested: z2.array(PermissionEntrySchema),
1139
4464
  command: CommandSchema.optional()
1140
4465
  }).strict();
1141
- var DelegationImportArtifactSchema = z.object({
1142
- kind: z.literal("tinycloud.auth.delegation"),
1143
- version: z.literal(1),
1144
- requestId: z.string().min(1),
1145
- delegationCid: z.string().min(1).optional(),
4466
+ var DelegationImportArtifactSchema = z2.object({
4467
+ kind: z2.literal("tinycloud.auth.delegation"),
4468
+ version: z2.literal(1),
4469
+ requestId: z2.string().min(1),
4470
+ delegationCid: z2.string().min(1).optional(),
1146
4471
  delegation: PortableDelegationSchema,
1147
4472
  // This field is presentation metadata only. A later import operation obtains
1148
4473
  // effective permissions from validated, installed delegation authority.
1149
- permissions: z.array(PermissionEntrySchema).optional(),
1150
- expiry: z.string().datetime({ offset: true }).optional(),
1151
- prompted: z.boolean().optional()
4474
+ permissions: z2.array(PermissionEntrySchema).optional(),
4475
+ expiry: z2.string().datetime({ offset: true }).optional(),
4476
+ prompted: z2.boolean().optional()
1152
4477
  }).strict();
1153
4478
  var DelegationRequestBindingSchema = PermissionRequestArtifactSchema.pick({ requestId: true, requested: true }).strict();
1154
4479
 
@@ -1170,6 +4495,7 @@ var STORED_GRANT_SKIP_REASONS = [
1170
4495
  "activation_rejected",
1171
4496
  "invalid"
1172
4497
  ];
4498
+ var DELEGATION_CID_PATTERN = "^bafkr4i[a-z2-7]{52}$";
1173
4499
 
1174
4500
  // src/secrets.ts
1175
4501
  import * as nodeSdk from "@tinycloud/node-sdk";
@@ -1273,14 +4599,28 @@ function storedDelegationKind(entry) {
1273
4599
  }
1274
4600
  if ("siweProof" in delegation) return "signed-login";
1275
4601
  if (header.Authorization.includes(".")) return "compact";
1276
- return "authorityRequest" in entry ? "refused" : "other";
4602
+ return "other";
1277
4603
  }
1278
- function replayLimit(entry, migrated) {
4604
+ function replayLimit(entry) {
1279
4605
  const kind = storedDelegationKind(entry);
1280
4606
  if (!isRecord(entry) || kind !== "compact" && kind !== "signed-login") return void 0;
1281
4607
  const binding = DelegationRequestBindingSchema.safeParse(entry.authorityRequest);
1282
- if (binding.success) return binding.data.requested;
1283
- return !migrated && kind === "compact" && !("authorityRequest" in entry) ? "signed" : void 0;
4608
+ return binding.success ? binding.data.requested : void 0;
4609
+ }
4610
+ function withoutBearer(authorization) {
4611
+ return authorization.replace(/^Bearer /i, "");
4612
+ }
4613
+ function storedDelegationSource(entry) {
4614
+ if (!isRecord(entry) || storedDelegationKind(entry) === "refused") return "unknown";
4615
+ if (!("authorityRequest" in entry)) return "legacy";
4616
+ const binding = DelegationRequestBindingSchema.safeParse(entry.authorityRequest);
4617
+ if (!binding.success) return "unknown";
4618
+ const cid = storedCid(entry);
4619
+ if (cid === void 0) return "unknown";
4620
+ if (binding.data.requestId === `cli-grant:${cid}`) return "cli-grant";
4621
+ if (binding.data.requestId === `unbound-import:${cid}`) return "unbound-import";
4622
+ if (binding.data.requestId === `migrated:${cid}`) return "migration";
4623
+ return "request";
1284
4624
  }
1285
4625
  function bindToRequest(record, requested, source, recordedAt = (/* @__PURE__ */ new Date()).toISOString()) {
1286
4626
  return {
@@ -1299,10 +4639,15 @@ async function bindCliGrant(node, record, host) {
1299
4639
  }
1300
4640
  return bindToRequest(record, signed, "cli-grant");
1301
4641
  }
1302
- async function activateUnboundCompactImport(node, delegation, host) {
1303
- const activated = await nodeSdk2.activateValidatedRuntimeDelegation(node, delegation, { host });
4642
+ async function activateUnboundImport(node, delegation, host) {
4643
+ const activated = await nodeSdk2.activateValidatedRuntimeDelegation(node, delegation, {
4644
+ host,
4645
+ authorize: () => {
4646
+ verifyCompactProof(delegation);
4647
+ return true;
4648
+ }
4649
+ });
1304
4650
  return bindToRequest(
1305
- // The record keeps the delegation as imported; replay validates it again.
1306
4651
  { delegation, permissions: [...activated.effectivePermissions] },
1307
4652
  activated.effectivePermissions,
1308
4653
  "unbound-import"
@@ -1330,7 +4675,7 @@ async function prepareStoredDelegationReplay(profile, node, options) {
1330
4675
  const bound = /* @__PURE__ */ new Map();
1331
4676
  const unbound = [];
1332
4677
  for (const entry of await readAdditionalDelegations(profile)) {
1333
- if (!isRecord(entry) || "authorityRequest" in entry || storedDelegationKind(entry) !== "compact") continue;
4678
+ if (!isRecord(entry) || "authorityRequest" in entry || storedDelegationKind(entry) !== "compact" || storedDelegationForAnotherKey(entry, node)) continue;
1334
4679
  const migrated = await migratedRecord(node, entry, options.host, recordedAt);
1335
4680
  if (migrated === void 0) unbound.push(String(storedCid(entry)));
1336
4681
  else bound.set(recordKey(entry), migrated);
@@ -1379,26 +4724,133 @@ var NOT_REPLAYED = { status: "not-replayed" };
1379
4724
  function skipped(reason) {
1380
4725
  return { status: "skipped", reason };
1381
4726
  }
4727
+ async function replayProfileDelegations(profile, node, options) {
4728
+ await prepareStoredDelegationReplay(profile, node, { host: options.host, migrate: options.migrate });
4729
+ const installed = [];
4730
+ const warnings = [];
4731
+ const seen = /* @__PURE__ */ new Set();
4732
+ for (const entry of await readAdditionalDelegations(profile)) {
4733
+ if (storedDelegationForAnotherKey(entry, node)) continue;
4734
+ const replay = await replayStoredDelegation(node, entry, options);
4735
+ if (replay.status === "installed") {
4736
+ if (!seen.has(replay.delegation.cid)) {
4737
+ seen.add(replay.delegation.cid);
4738
+ installed.push(replay.delegation);
4739
+ }
4740
+ } else if (replay.status === "skipped") {
4741
+ const grantCid = verifiedStoredCid(node, entry);
4742
+ warnings.push({
4743
+ code: "STORED_GRANT_SKIPPED",
4744
+ reason: replay.reason,
4745
+ ...grantCid === void 0 ? {} : { grantCid }
4746
+ });
4747
+ }
4748
+ }
4749
+ return { installed, warnings };
4750
+ }
4751
+ function verifiedCompactAudience(node, delegation) {
4752
+ const authorization = delegation.delegationHeader.Authorization;
4753
+ const token = withoutBearer(authorization);
4754
+ if (/^Bearer(?:\s|$)/i.test(token)) return void 0;
4755
+ try {
4756
+ if (node.computeDelegationCid(authorization) !== delegation.cid) return void 0;
4757
+ return parseSignedCompactUcanAttenuation(token, delegation.cid).payload.aud;
4758
+ } catch {
4759
+ return void 0;
4760
+ }
4761
+ }
4762
+ function storedDelegationForAnotherKey(entry, node) {
4763
+ if (storedDelegationKind(entry) !== "compact" || typeof node.sessionDid !== "string") return false;
4764
+ const delegation = normalizeStoredDelegation(entry);
4765
+ if (delegation === void 0) return false;
4766
+ const audience = verifiedCompactAudience(node, delegation);
4767
+ if (audience === void 0) return false;
4768
+ try {
4769
+ return nodeSdk2.principalDidEquals(delegation.delegateDID, audience) && !nodeSdk2.principalDidEquals(audience, node.sessionDid);
4770
+ } catch {
4771
+ return false;
4772
+ }
4773
+ }
4774
+ function verifiedStoredCid(node, entry) {
4775
+ const delegation = isRecord(entry) && isRecord(entry.delegation) ? entry.delegation : void 0;
4776
+ const header = isRecord(delegation?.delegationHeader) ? delegation.delegationHeader : void 0;
4777
+ const cid = delegation?.cid;
4778
+ if (typeof cid !== "string" || typeof header?.Authorization !== "string" || typeof node.computeDelegationCid !== "function") return void 0;
4779
+ try {
4780
+ return node.computeDelegationCid(header.Authorization) === cid && DELEGATION_CID.test(cid) ? cid : void 0;
4781
+ } catch {
4782
+ return void 0;
4783
+ }
4784
+ }
4785
+ var DELEGATION_CID = new RegExp(DELEGATION_CID_PATTERN);
1382
4786
  async function replayStoredDelegation(node, entry, options) {
4787
+ const result = await assess(node, entry, options, { activate: true });
4788
+ return result.status === "verified" ? skipped("invalid") : result;
4789
+ }
4790
+ async function inspectStoredDelegation(entry, options = {}) {
4791
+ const delegation = normalizeStoredDelegation(entry);
4792
+ if (storedDelegationKind(entry) === "refused" || delegation === void 0) {
4793
+ return { local: "refused", reason: "malformed" };
4794
+ }
4795
+ if (delegation.expiry.getTime() <= Date.now()) return { local: "not_checked", because: "expired" };
4796
+ if (options.node === void 0) return { local: "not_checked", because: "no_session" };
4797
+ const result = await assess(options.node, entry, {
4798
+ host: options.host ?? delegation.host ?? "",
4799
+ resolveSpace: options.resolveSpace
4800
+ }, { activate: false });
4801
+ if (result.status === "verified") {
4802
+ return { local: "verified", cid: result.cid, effectivePermissions: result.effectivePermissions, expiry: result.expiry };
4803
+ }
4804
+ if (result.status === "not-replayed") return { local: "not_checked", because: "expired" };
4805
+ return { local: "refused", reason: result.status === "skipped" ? result.reason : "invalid" };
4806
+ }
4807
+ async function assess(node, entry, options, mode) {
1383
4808
  const kind = storedDelegationKind(entry);
1384
4809
  const delegation = normalizeStoredDelegation(entry);
1385
4810
  if (kind === "refused" || delegation === void 0) return skipped("malformed");
1386
4811
  if (delegation.expiry.getTime() <= Date.now()) return NOT_REPLAYED;
1387
4812
  if (kind === "other") return skipped("proof_missing");
1388
- const limit = replayLimit(entry, options.migrated);
4813
+ const limit = replayLimit(entry);
1389
4814
  if (limit === void 0) return skipped("unbound");
4815
+ const authorization = withoutBearer(delegation.delegationHeader.Authorization);
4816
+ if (/^Bearer(?:\s|$)/i.test(authorization)) return skipped("cid_mismatch");
4817
+ const toActivate = authorization === delegation.delegationHeader.Authorization ? delegation : { ...delegation, delegationHeader: { Authorization: authorization }, authHeader: authorization };
1390
4818
  let outsideRequest = false;
1391
- const authorize = limit === "signed" ? () => true : (effective) => {
1392
- outsideRequest = !delegationWithinRequest(limit, effective, options.resolveSpace);
1393
- return !outsideRequest;
1394
- };
4819
+ let effectivePermissions;
1395
4820
  try {
1396
- return {
1397
- status: "installed",
1398
- delegation: await nodeSdk2.activateValidatedRuntimeDelegation(node, delegation, { host: options.host, authorize })
1399
- };
4821
+ const installed = await nodeSdk2.activateValidatedRuntimeDelegation(node, toActivate, {
4822
+ host: options.host,
4823
+ authorize: (effective) => {
4824
+ verifyCompactProof(toActivate);
4825
+ outsideRequest = !delegationWithinRequest(limit, effective, options.resolveSpace);
4826
+ if (outsideRequest) return false;
4827
+ effectivePermissions = effective;
4828
+ return mode.activate;
4829
+ }
4830
+ });
4831
+ return { status: "installed", delegation: installed };
1400
4832
  } catch (error) {
1401
- return skipped(outsideRequest ? "outside_request" : rejectionReason(error));
4833
+ if (outsideRequest) return skipped("outside_request");
4834
+ if (effectivePermissions !== void 0 && !mode.activate) {
4835
+ return { status: "verified", cid: delegation.cid, effectivePermissions, expiry: delegation.expiry };
4836
+ }
4837
+ if (kind === "compact" && rejectionReason(error) === "audience_mismatch") {
4838
+ try {
4839
+ verifyCompactProof(toActivate);
4840
+ } catch {
4841
+ return skipped("proof_invalid");
4842
+ }
4843
+ }
4844
+ return skipped(rejectionReason(error));
4845
+ }
4846
+ }
4847
+ function verifyCompactProof(delegation) {
4848
+ const authorization = delegation.delegationHeader.Authorization;
4849
+ if (!withoutBearer(authorization).includes(".")) return;
4850
+ try {
4851
+ parseSignedCompactUcanAttenuation(withoutBearer(authorization), delegation.cid);
4852
+ } catch {
4853
+ throw new nodeSdk2.RuntimeDelegationRejectedError("proof_invalid", "The compact delegation proof is invalid.");
1402
4854
  }
1403
4855
  }
1404
4856
  function rejectionReason(error) {
@@ -1419,6 +4871,7 @@ async function signedCapabilities(node, delegation, host) {
1419
4871
  // The transport host is not signed authority; check it at replay instead.
1420
4872
  host: delegation.host ?? host,
1421
4873
  authorize: (effective) => {
4874
+ verifyCompactProof(delegation);
1422
4875
  signed = effective;
1423
4876
  return false;
1424
4877
  }
@@ -1451,15 +4904,35 @@ function isRecord(value) {
1451
4904
  }
1452
4905
  export {
1453
4906
  BINDING_NOTES,
1454
- activateUnboundCompactImport,
4907
+ STORED_GRANT_SKIP_REASONS,
4908
+ activateUnboundImport,
1455
4909
  bindCliGrant,
1456
4910
  bindingMigrationPath,
1457
4911
  bindingMigrationRecorded,
4912
+ inspectStoredDelegation,
1458
4913
  mergeDelegationsWithoutRequest,
1459
4914
  operationSpaceResolver,
1460
4915
  prepareStoredDelegationReplay,
1461
4916
  replayLimit,
4917
+ replayProfileDelegations,
1462
4918
  replayStoredDelegation,
1463
- storedDelegationKind
4919
+ storedDelegationForAnotherKey,
4920
+ storedDelegationKind,
4921
+ storedDelegationSource,
4922
+ verifiedCompactAudience,
4923
+ verifiedStoredCid,
4924
+ withoutBearer
1464
4925
  };
4926
+ /*! Bundled license information:
4927
+
4928
+ @noble/hashes/esm/utils.js:
4929
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
4930
+
4931
+ @noble/curves/esm/utils.js:
4932
+ @noble/curves/esm/abstract/modular.js:
4933
+ @noble/curves/esm/abstract/curve.js:
4934
+ @noble/curves/esm/abstract/edwards.js:
4935
+ @noble/curves/esm/ed25519.js:
4936
+ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
4937
+ */
1465
4938
  //# sourceMappingURL=delegation-binding.js.map