@tinycloud/sdk-core 2.7.0-beta.3 → 2.7.0

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.
@@ -1,16 +1,929 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __export = (target, all) => {
4
+ for (var name2 in all)
5
+ __defProp(target, name2, { get: all[name2], enumerable: true });
6
+ };
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+
1
9
  // src/requester/index.ts
2
- import { bytesToHex as bytesToHex3, sha256 as sha2563 } from "viem";
10
+ import { bytesToHex as bytesToHex3, sha256 as sha2564 } from "viem";
3
11
  import { blake3 } from "@noble/hashes/blake3";
4
- import { CID } from "multiformats/cid";
5
- import { create as createDigest } from "multiformats/hashes/digest";
12
+
13
+ // ../../node_modules/multiformats/dist/src/bases/base32.js
14
+ var base32_exports = {};
15
+ __export(base32_exports, {
16
+ base32: () => base32,
17
+ base32hex: () => base32hex,
18
+ base32hexpad: () => base32hexpad,
19
+ base32hexpadupper: () => base32hexpadupper,
20
+ base32hexupper: () => base32hexupper,
21
+ base32pad: () => base32pad,
22
+ base32padupper: () => base32padupper,
23
+ base32upper: () => base32upper,
24
+ base32z: () => base32z
25
+ });
26
+
27
+ // ../../node_modules/multiformats/dist/src/bytes.js
28
+ var empty = new Uint8Array(0);
29
+ function equals(aa, bb) {
30
+ if (aa === bb) {
31
+ return true;
32
+ }
33
+ if (aa.byteLength !== bb.byteLength) {
34
+ return false;
35
+ }
36
+ for (let ii = 0; ii < aa.byteLength; ii++) {
37
+ if (aa[ii] !== bb[ii]) {
38
+ return false;
39
+ }
40
+ }
41
+ return true;
42
+ }
43
+ function coerce(o) {
44
+ if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
45
+ return o;
46
+ }
47
+ if (o instanceof ArrayBuffer) {
48
+ return new Uint8Array(o);
49
+ }
50
+ if (ArrayBuffer.isView(o)) {
51
+ return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
52
+ }
53
+ throw new Error("Unknown type, must be binary type");
54
+ }
55
+ function fromString(str) {
56
+ return new TextEncoder().encode(str);
57
+ }
58
+ function toString(b) {
59
+ return new TextDecoder().decode(b);
60
+ }
61
+
62
+ // ../../node_modules/multiformats/dist/src/vendor/base-x.js
63
+ function base(ALPHABET, name2) {
64
+ if (ALPHABET.length >= 255) {
65
+ throw new TypeError("Alphabet too long");
66
+ }
67
+ var BASE_MAP = new Uint8Array(256);
68
+ for (var j = 0; j < BASE_MAP.length; j++) {
69
+ BASE_MAP[j] = 255;
70
+ }
71
+ for (var i = 0; i < ALPHABET.length; i++) {
72
+ var x = ALPHABET.charAt(i);
73
+ var xc = x.charCodeAt(0);
74
+ if (BASE_MAP[xc] !== 255) {
75
+ throw new TypeError(x + " is ambiguous");
76
+ }
77
+ BASE_MAP[xc] = i;
78
+ }
79
+ var BASE = ALPHABET.length;
80
+ var LEADER = ALPHABET.charAt(0);
81
+ var FACTOR = Math.log(BASE) / Math.log(256);
82
+ var iFACTOR = Math.log(256) / Math.log(BASE);
83
+ function encode5(source) {
84
+ if (source instanceof Uint8Array)
85
+ ;
86
+ else if (ArrayBuffer.isView(source)) {
87
+ source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
88
+ } else if (Array.isArray(source)) {
89
+ source = Uint8Array.from(source);
90
+ }
91
+ if (!(source instanceof Uint8Array)) {
92
+ throw new TypeError("Expected Uint8Array");
93
+ }
94
+ if (source.length === 0) {
95
+ return "";
96
+ }
97
+ var zeroes = 0;
98
+ var length2 = 0;
99
+ var pbegin = 0;
100
+ var pend = source.length;
101
+ while (pbegin !== pend && source[pbegin] === 0) {
102
+ pbegin++;
103
+ zeroes++;
104
+ }
105
+ var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
106
+ var b58 = new Uint8Array(size);
107
+ while (pbegin !== pend) {
108
+ var carry = source[pbegin];
109
+ var i2 = 0;
110
+ for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
111
+ carry += 256 * b58[it1] >>> 0;
112
+ b58[it1] = carry % BASE >>> 0;
113
+ carry = carry / BASE >>> 0;
114
+ }
115
+ if (carry !== 0) {
116
+ throw new Error("Non-zero carry");
117
+ }
118
+ length2 = i2;
119
+ pbegin++;
120
+ }
121
+ var it2 = size - length2;
122
+ while (it2 !== size && b58[it2] === 0) {
123
+ it2++;
124
+ }
125
+ var str = LEADER.repeat(zeroes);
126
+ for (; it2 < size; ++it2) {
127
+ str += ALPHABET.charAt(b58[it2]);
128
+ }
129
+ return str;
130
+ }
131
+ function decodeUnsafe(source) {
132
+ if (typeof source !== "string") {
133
+ throw new TypeError("Expected String");
134
+ }
135
+ if (source.length === 0) {
136
+ return new Uint8Array();
137
+ }
138
+ var psz = 0;
139
+ if (source[psz] === " ") {
140
+ return;
141
+ }
142
+ var zeroes = 0;
143
+ var length2 = 0;
144
+ while (source[psz] === LEADER) {
145
+ zeroes++;
146
+ psz++;
147
+ }
148
+ var size = (source.length - psz) * FACTOR + 1 >>> 0;
149
+ var b256 = new Uint8Array(size);
150
+ while (source[psz]) {
151
+ var carry = BASE_MAP[source.charCodeAt(psz)];
152
+ if (carry === 255) {
153
+ return;
154
+ }
155
+ var i2 = 0;
156
+ for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
157
+ carry += BASE * b256[it3] >>> 0;
158
+ b256[it3] = carry % 256 >>> 0;
159
+ carry = carry / 256 >>> 0;
160
+ }
161
+ if (carry !== 0) {
162
+ throw new Error("Non-zero carry");
163
+ }
164
+ length2 = i2;
165
+ psz++;
166
+ }
167
+ if (source[psz] === " ") {
168
+ return;
169
+ }
170
+ var it4 = size - length2;
171
+ while (it4 !== size && b256[it4] === 0) {
172
+ it4++;
173
+ }
174
+ var vch = new Uint8Array(zeroes + (size - it4));
175
+ var j2 = zeroes;
176
+ while (it4 !== size) {
177
+ vch[j2++] = b256[it4++];
178
+ }
179
+ return vch;
180
+ }
181
+ function decode6(string) {
182
+ var buffer = decodeUnsafe(string);
183
+ if (buffer) {
184
+ return buffer;
185
+ }
186
+ throw new Error(`Non-${name2} character`);
187
+ }
188
+ return {
189
+ encode: encode5,
190
+ decodeUnsafe,
191
+ decode: decode6
192
+ };
193
+ }
194
+ var src = base;
195
+ var _brrp__multiformats_scope_baseX = src;
196
+ var base_x_default = _brrp__multiformats_scope_baseX;
197
+
198
+ // ../../node_modules/multiformats/dist/src/bases/base.js
199
+ var Encoder = class {
200
+ constructor(name2, prefix, baseEncode) {
201
+ __publicField(this, "name");
202
+ __publicField(this, "prefix");
203
+ __publicField(this, "baseEncode");
204
+ this.name = name2;
205
+ this.prefix = prefix;
206
+ this.baseEncode = baseEncode;
207
+ }
208
+ encode(bytes) {
209
+ if (bytes instanceof Uint8Array) {
210
+ return `${this.prefix}${this.baseEncode(bytes)}`;
211
+ } else {
212
+ throw Error("Unknown type, must be binary type");
213
+ }
214
+ }
215
+ };
216
+ var Decoder = class {
217
+ constructor(name2, prefix, baseDecode) {
218
+ __publicField(this, "name");
219
+ __publicField(this, "prefix");
220
+ __publicField(this, "baseDecode");
221
+ __publicField(this, "prefixCodePoint");
222
+ this.name = name2;
223
+ this.prefix = prefix;
224
+ const prefixCodePoint = prefix.codePointAt(0);
225
+ if (prefixCodePoint === void 0) {
226
+ throw new Error("Invalid prefix character");
227
+ }
228
+ this.prefixCodePoint = prefixCodePoint;
229
+ this.baseDecode = baseDecode;
230
+ }
231
+ decode(text) {
232
+ if (typeof text === "string") {
233
+ if (text.codePointAt(0) !== this.prefixCodePoint) {
234
+ throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
235
+ }
236
+ return this.baseDecode(text.slice(this.prefix.length));
237
+ } else {
238
+ throw Error("Can only multibase decode strings");
239
+ }
240
+ }
241
+ or(decoder) {
242
+ return or(this, decoder);
243
+ }
244
+ };
245
+ var ComposedDecoder = class {
246
+ constructor(decoders) {
247
+ __publicField(this, "decoders");
248
+ this.decoders = decoders;
249
+ }
250
+ or(decoder) {
251
+ return or(this, decoder);
252
+ }
253
+ decode(input) {
254
+ const prefix = input[0];
255
+ const decoder = this.decoders[prefix];
256
+ if (decoder != null) {
257
+ return decoder.decode(input);
258
+ } else {
259
+ throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
260
+ }
261
+ }
262
+ };
263
+ function or(left, right) {
264
+ return new ComposedDecoder({
265
+ ...left.decoders ?? { [left.prefix]: left },
266
+ ...right.decoders ?? { [right.prefix]: right }
267
+ });
268
+ }
269
+ var Codec = class {
270
+ constructor(name2, prefix, baseEncode, baseDecode) {
271
+ __publicField(this, "name");
272
+ __publicField(this, "prefix");
273
+ __publicField(this, "baseEncode");
274
+ __publicField(this, "baseDecode");
275
+ __publicField(this, "encoder");
276
+ __publicField(this, "decoder");
277
+ this.name = name2;
278
+ this.prefix = prefix;
279
+ this.baseEncode = baseEncode;
280
+ this.baseDecode = baseDecode;
281
+ this.encoder = new Encoder(name2, prefix, baseEncode);
282
+ this.decoder = new Decoder(name2, prefix, baseDecode);
283
+ }
284
+ encode(input) {
285
+ return this.encoder.encode(input);
286
+ }
287
+ decode(input) {
288
+ return this.decoder.decode(input);
289
+ }
290
+ };
291
+ function from({ name: name2, prefix, encode: encode5, decode: decode6 }) {
292
+ return new Codec(name2, prefix, encode5, decode6);
293
+ }
294
+ function baseX({ name: name2, prefix, alphabet: alphabet2 }) {
295
+ const { encode: encode5, decode: decode6 } = base_x_default(alphabet2, name2);
296
+ return from({
297
+ prefix,
298
+ name: name2,
299
+ encode: encode5,
300
+ decode: (text) => coerce(decode6(text))
301
+ });
302
+ }
303
+ function decode(string, alphabetIdx, bitsPerChar, name2) {
304
+ let end = string.length;
305
+ while (string[end - 1] === "=") {
306
+ --end;
307
+ }
308
+ const out = new Uint8Array(end * bitsPerChar / 8 | 0);
309
+ let bits = 0;
310
+ let buffer = 0;
311
+ let written = 0;
312
+ for (let i = 0; i < end; ++i) {
313
+ const value = alphabetIdx[string[i]];
314
+ if (value === void 0) {
315
+ throw new SyntaxError(`Non-${name2} character`);
316
+ }
317
+ buffer = buffer << bitsPerChar | value;
318
+ bits += bitsPerChar;
319
+ if (bits >= 8) {
320
+ bits -= 8;
321
+ out[written++] = 255 & buffer >> bits;
322
+ }
323
+ }
324
+ if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
325
+ throw new SyntaxError("Unexpected end of data");
326
+ }
327
+ return out;
328
+ }
329
+ function encode(data, alphabet2, bitsPerChar) {
330
+ const pad = alphabet2[alphabet2.length - 1] === "=";
331
+ const mask = (1 << bitsPerChar) - 1;
332
+ let out = "";
333
+ let bits = 0;
334
+ let buffer = 0;
335
+ for (let i = 0; i < data.length; ++i) {
336
+ buffer = buffer << 8 | data[i];
337
+ bits += 8;
338
+ while (bits > bitsPerChar) {
339
+ bits -= bitsPerChar;
340
+ out += alphabet2[mask & buffer >> bits];
341
+ }
342
+ }
343
+ if (bits !== 0) {
344
+ out += alphabet2[mask & buffer << bitsPerChar - bits];
345
+ }
346
+ if (pad) {
347
+ while ((out.length * bitsPerChar & 7) !== 0) {
348
+ out += "=";
349
+ }
350
+ }
351
+ return out;
352
+ }
353
+ function createAlphabetIdx(alphabet2) {
354
+ const alphabetIdx = {};
355
+ for (let i = 0; i < alphabet2.length; ++i) {
356
+ alphabetIdx[alphabet2[i]] = i;
357
+ }
358
+ return alphabetIdx;
359
+ }
360
+ function rfc4648({ name: name2, prefix, bitsPerChar, alphabet: alphabet2 }) {
361
+ const alphabetIdx = createAlphabetIdx(alphabet2);
362
+ return from({
363
+ prefix,
364
+ name: name2,
365
+ encode(input) {
366
+ return encode(input, alphabet2, bitsPerChar);
367
+ },
368
+ decode(input) {
369
+ return decode(input, alphabetIdx, bitsPerChar, name2);
370
+ }
371
+ });
372
+ }
373
+
374
+ // ../../node_modules/multiformats/dist/src/bases/base32.js
375
+ var base32 = rfc4648({
376
+ prefix: "b",
377
+ name: "base32",
378
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567",
379
+ bitsPerChar: 5
380
+ });
381
+ var base32upper = rfc4648({
382
+ prefix: "B",
383
+ name: "base32upper",
384
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
385
+ bitsPerChar: 5
386
+ });
387
+ var base32pad = rfc4648({
388
+ prefix: "c",
389
+ name: "base32pad",
390
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
391
+ bitsPerChar: 5
392
+ });
393
+ var base32padupper = rfc4648({
394
+ prefix: "C",
395
+ name: "base32padupper",
396
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
397
+ bitsPerChar: 5
398
+ });
399
+ var base32hex = rfc4648({
400
+ prefix: "v",
401
+ name: "base32hex",
402
+ alphabet: "0123456789abcdefghijklmnopqrstuv",
403
+ bitsPerChar: 5
404
+ });
405
+ var base32hexupper = rfc4648({
406
+ prefix: "V",
407
+ name: "base32hexupper",
408
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
409
+ bitsPerChar: 5
410
+ });
411
+ var base32hexpad = rfc4648({
412
+ prefix: "t",
413
+ name: "base32hexpad",
414
+ alphabet: "0123456789abcdefghijklmnopqrstuv=",
415
+ bitsPerChar: 5
416
+ });
417
+ var base32hexpadupper = rfc4648({
418
+ prefix: "T",
419
+ name: "base32hexpadupper",
420
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
421
+ bitsPerChar: 5
422
+ });
423
+ var base32z = rfc4648({
424
+ prefix: "h",
425
+ name: "base32z",
426
+ alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
427
+ bitsPerChar: 5
428
+ });
429
+
430
+ // ../../node_modules/multiformats/dist/src/bases/base36.js
431
+ var base36_exports = {};
432
+ __export(base36_exports, {
433
+ base36: () => base36,
434
+ base36upper: () => base36upper
435
+ });
436
+ var base36 = baseX({
437
+ prefix: "k",
438
+ name: "base36",
439
+ alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
440
+ });
441
+ var base36upper = baseX({
442
+ prefix: "K",
443
+ name: "base36upper",
444
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
445
+ });
446
+
447
+ // ../../node_modules/multiformats/dist/src/bases/base58.js
448
+ var base58_exports = {};
449
+ __export(base58_exports, {
450
+ base58btc: () => base58btc,
451
+ base58flickr: () => base58flickr
452
+ });
453
+ var base58btc = baseX({
454
+ name: "base58btc",
455
+ prefix: "z",
456
+ alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
457
+ });
458
+ var base58flickr = baseX({
459
+ name: "base58flickr",
460
+ prefix: "Z",
461
+ alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
462
+ });
463
+
464
+ // ../../node_modules/multiformats/dist/src/vendor/varint.js
465
+ var encode_1 = encode2;
466
+ var MSB = 128;
467
+ var REST = 127;
468
+ var MSBALL = ~REST;
469
+ var INT = Math.pow(2, 31);
470
+ function encode2(num, out, offset) {
471
+ out = out || [];
472
+ offset = offset || 0;
473
+ var oldOffset = offset;
474
+ while (num >= INT) {
475
+ out[offset++] = num & 255 | MSB;
476
+ num /= 128;
477
+ }
478
+ while (num & MSBALL) {
479
+ out[offset++] = num & 255 | MSB;
480
+ num >>>= 7;
481
+ }
482
+ out[offset] = num | 0;
483
+ encode2.bytes = offset - oldOffset + 1;
484
+ return out;
485
+ }
486
+ var decode2 = read;
487
+ var MSB$1 = 128;
488
+ var REST$1 = 127;
489
+ function read(buf, offset) {
490
+ var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
491
+ do {
492
+ if (counter >= l) {
493
+ read.bytes = 0;
494
+ throw new RangeError("Could not decode varint");
495
+ }
496
+ b = buf[counter++];
497
+ res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
498
+ shift += 7;
499
+ } while (b >= MSB$1);
500
+ read.bytes = counter - offset;
501
+ return res;
502
+ }
503
+ var N1 = Math.pow(2, 7);
504
+ var N2 = Math.pow(2, 14);
505
+ var N3 = Math.pow(2, 21);
506
+ var N4 = Math.pow(2, 28);
507
+ var N5 = Math.pow(2, 35);
508
+ var N6 = Math.pow(2, 42);
509
+ var N7 = Math.pow(2, 49);
510
+ var N8 = Math.pow(2, 56);
511
+ var N9 = Math.pow(2, 63);
512
+ var length = function(value) {
513
+ 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;
514
+ };
515
+ var varint = {
516
+ encode: encode_1,
517
+ decode: decode2,
518
+ encodingLength: length
519
+ };
520
+ var _brrp_varint = varint;
521
+ var varint_default = _brrp_varint;
522
+
523
+ // ../../node_modules/multiformats/dist/src/varint.js
524
+ function decode3(data, offset = 0) {
525
+ const code2 = varint_default.decode(data, offset);
526
+ return [code2, varint_default.decode.bytes];
527
+ }
528
+ function encodeTo(int, target, offset = 0) {
529
+ varint_default.encode(int, target, offset);
530
+ return target;
531
+ }
532
+ function encodingLength(int) {
533
+ return varint_default.encodingLength(int);
534
+ }
535
+
536
+ // ../../node_modules/multiformats/dist/src/hashes/digest.js
537
+ function create(code2, digest2) {
538
+ const size = digest2.byteLength;
539
+ const sizeOffset = encodingLength(code2);
540
+ const digestOffset = sizeOffset + encodingLength(size);
541
+ const bytes = new Uint8Array(digestOffset + size);
542
+ encodeTo(code2, bytes, 0);
543
+ encodeTo(size, bytes, sizeOffset);
544
+ bytes.set(digest2, digestOffset);
545
+ return new Digest(code2, size, digest2, bytes);
546
+ }
547
+ function decode4(multihash) {
548
+ const bytes = coerce(multihash);
549
+ const [code2, sizeOffset] = decode3(bytes);
550
+ const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
551
+ const digest2 = bytes.subarray(sizeOffset + digestOffset);
552
+ if (digest2.byteLength !== size) {
553
+ throw new Error("Incorrect length");
554
+ }
555
+ return new Digest(code2, size, digest2, bytes);
556
+ }
557
+ function equals2(a, b) {
558
+ if (a === b) {
559
+ return true;
560
+ } else {
561
+ const data = b;
562
+ return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
563
+ }
564
+ }
565
+ var Digest = class {
566
+ /**
567
+ * Creates a multihash digest.
568
+ */
569
+ constructor(code2, size, digest2, bytes) {
570
+ __publicField(this, "code");
571
+ __publicField(this, "size");
572
+ __publicField(this, "digest");
573
+ __publicField(this, "bytes");
574
+ this.code = code2;
575
+ this.size = size;
576
+ this.digest = digest2;
577
+ this.bytes = bytes;
578
+ }
579
+ };
580
+
581
+ // ../../node_modules/multiformats/dist/src/cid.js
582
+ function format(link, base3) {
583
+ const { bytes, version } = link;
584
+ switch (version) {
585
+ case 0:
586
+ return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
587
+ default:
588
+ return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
589
+ }
590
+ }
591
+ var cache = /* @__PURE__ */ new WeakMap();
592
+ function baseCache(cid) {
593
+ const baseCache2 = cache.get(cid);
594
+ if (baseCache2 == null) {
595
+ const baseCache3 = /* @__PURE__ */ new Map();
596
+ cache.set(cid, baseCache3);
597
+ return baseCache3;
598
+ }
599
+ return baseCache2;
600
+ }
601
+ var _a;
602
+ var CID = class _CID {
603
+ /**
604
+ * @param version - Version of the CID
605
+ * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
606
+ * @param multihash - (Multi)hash of the of the content.
607
+ */
608
+ constructor(version, code2, multihash, bytes) {
609
+ __publicField(this, "code");
610
+ __publicField(this, "version");
611
+ __publicField(this, "multihash");
612
+ __publicField(this, "bytes");
613
+ __publicField(this, "/");
614
+ __publicField(this, _a, "CID");
615
+ this.code = code2;
616
+ this.version = version;
617
+ this.multihash = multihash;
618
+ this.bytes = bytes;
619
+ this["/"] = bytes;
620
+ }
621
+ /**
622
+ * Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
623
+ * please either use `CID.asCID(cid)` or switch to new signalling mechanism
624
+ *
625
+ * @deprecated
626
+ */
627
+ get asCID() {
628
+ return this;
629
+ }
630
+ // ArrayBufferView
631
+ get byteOffset() {
632
+ return this.bytes.byteOffset;
633
+ }
634
+ // ArrayBufferView
635
+ get byteLength() {
636
+ return this.bytes.byteLength;
637
+ }
638
+ toV0() {
639
+ switch (this.version) {
640
+ case 0: {
641
+ return this;
642
+ }
643
+ case 1: {
644
+ const { code: code2, multihash } = this;
645
+ if (code2 !== DAG_PB_CODE) {
646
+ throw new Error("Cannot convert a non dag-pb CID to CIDv0");
647
+ }
648
+ if (multihash.code !== SHA_256_CODE) {
649
+ throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
650
+ }
651
+ return _CID.createV0(multihash);
652
+ }
653
+ default: {
654
+ throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
655
+ }
656
+ }
657
+ }
658
+ toV1() {
659
+ switch (this.version) {
660
+ case 0: {
661
+ const { code: code2, digest: digest2 } = this.multihash;
662
+ const multihash = create(code2, digest2);
663
+ return _CID.createV1(this.code, multihash);
664
+ }
665
+ case 1: {
666
+ return this;
667
+ }
668
+ default: {
669
+ throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
670
+ }
671
+ }
672
+ }
673
+ equals(other) {
674
+ return _CID.equals(this, other);
675
+ }
676
+ static equals(self, other) {
677
+ const unknown = other;
678
+ return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
679
+ }
680
+ toString(base3) {
681
+ return format(this, base3);
682
+ }
683
+ toJSON() {
684
+ return { "/": format(this) };
685
+ }
686
+ link() {
687
+ return this;
688
+ }
689
+ // Legacy
690
+ [(_a = Symbol.toStringTag, /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom"))]() {
691
+ return `CID(${this.toString()})`;
692
+ }
693
+ /**
694
+ * Takes any input `value` and returns a `CID` instance if it was
695
+ * a `CID` otherwise returns `null`. If `value` is instanceof `CID`
696
+ * it will return value back. If `value` is not instance of this CID
697
+ * class, but is compatible CID it will return new instance of this
698
+ * `CID` class. Otherwise returns null.
699
+ *
700
+ * This allows two different incompatible versions of CID library to
701
+ * co-exist and interop as long as binary interface is compatible.
702
+ */
703
+ static asCID(input) {
704
+ if (input == null) {
705
+ return null;
706
+ }
707
+ const value = input;
708
+ if (value instanceof _CID) {
709
+ return value;
710
+ } else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
711
+ const { version, code: code2, multihash, bytes } = value;
712
+ return new _CID(version, code2, multihash, bytes ?? encodeCID(version, code2, multihash.bytes));
713
+ } else if (value[cidSymbol] === true) {
714
+ const { version, multihash, code: code2 } = value;
715
+ const digest2 = decode4(multihash);
716
+ return _CID.create(version, code2, digest2);
717
+ } else {
718
+ return null;
719
+ }
720
+ }
721
+ /**
722
+ * @param version - Version of the CID
723
+ * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
724
+ * @param digest - (Multi)hash of the of the content.
725
+ */
726
+ static create(version, code2, digest2) {
727
+ if (typeof code2 !== "number") {
728
+ throw new Error("String codecs are no longer supported");
729
+ }
730
+ if (!(digest2.bytes instanceof Uint8Array)) {
731
+ throw new Error("Invalid digest");
732
+ }
733
+ switch (version) {
734
+ case 0: {
735
+ if (code2 !== DAG_PB_CODE) {
736
+ throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
737
+ } else {
738
+ return new _CID(version, code2, digest2, digest2.bytes);
739
+ }
740
+ }
741
+ case 1: {
742
+ const bytes = encodeCID(version, code2, digest2.bytes);
743
+ return new _CID(version, code2, digest2, bytes);
744
+ }
745
+ default: {
746
+ throw new Error("Invalid version");
747
+ }
748
+ }
749
+ }
750
+ /**
751
+ * Simplified version of `create` for CIDv0.
752
+ */
753
+ static createV0(digest2) {
754
+ return _CID.create(0, DAG_PB_CODE, digest2);
755
+ }
756
+ /**
757
+ * Simplified version of `create` for CIDv1.
758
+ *
759
+ * @param code - Content encoding format code.
760
+ * @param digest - Multihash of the content.
761
+ */
762
+ static createV1(code2, digest2) {
763
+ return _CID.create(1, code2, digest2);
764
+ }
765
+ /**
766
+ * Decoded a CID from its binary representation. The byte array must contain
767
+ * only the CID with no additional bytes.
768
+ *
769
+ * An error will be thrown if the bytes provided do not contain a valid
770
+ * binary representation of a CID.
771
+ */
772
+ static decode(bytes) {
773
+ const [cid, remainder] = _CID.decodeFirst(bytes);
774
+ if (remainder.length !== 0) {
775
+ throw new Error("Incorrect length");
776
+ }
777
+ return cid;
778
+ }
779
+ /**
780
+ * Decoded a CID from its binary representation at the beginning of a byte
781
+ * array.
782
+ *
783
+ * Returns an array with the first element containing the CID and the second
784
+ * element containing the remainder of the original byte array. The remainder
785
+ * will be a zero-length byte array if the provided bytes only contained a
786
+ * binary CID representation.
787
+ */
788
+ static decodeFirst(bytes) {
789
+ const specs = _CID.inspectBytes(bytes);
790
+ const prefixSize = specs.size - specs.multihashSize;
791
+ const multihashBytes = coerce(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
792
+ if (multihashBytes.byteLength !== specs.multihashSize) {
793
+ throw new Error("Incorrect length");
794
+ }
795
+ const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
796
+ const digest2 = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
797
+ const cid = specs.version === 0 ? _CID.createV0(digest2) : _CID.createV1(specs.codec, digest2);
798
+ return [cid, bytes.subarray(specs.size)];
799
+ }
800
+ /**
801
+ * Inspect the initial bytes of a CID to determine its properties.
802
+ *
803
+ * Involves decoding up to 4 varints. Typically this will require only 4 to 6
804
+ * bytes but for larger multicodec code values and larger multihash digest
805
+ * lengths these varints can be quite large. It is recommended that at least
806
+ * 10 bytes be made available in the `initialBytes` argument for a complete
807
+ * inspection.
808
+ */
809
+ static inspectBytes(initialBytes) {
810
+ let offset = 0;
811
+ const next = () => {
812
+ const [i, length2] = decode3(initialBytes.subarray(offset));
813
+ offset += length2;
814
+ return i;
815
+ };
816
+ let version = next();
817
+ let codec = DAG_PB_CODE;
818
+ if (version === 18) {
819
+ version = 0;
820
+ offset = 0;
821
+ } else {
822
+ codec = next();
823
+ }
824
+ if (version !== 0 && version !== 1) {
825
+ throw new RangeError(`Invalid CID version ${version}`);
826
+ }
827
+ const prefixSize = offset;
828
+ const multihashCode = next();
829
+ const digestSize = next();
830
+ const size = offset + digestSize;
831
+ const multihashSize = size - prefixSize;
832
+ return { version, codec, multihashCode, digestSize, multihashSize, size };
833
+ }
834
+ /**
835
+ * Takes cid in a string representation and creates an instance. If `base`
836
+ * decoder is not provided will use a default from the configuration. It will
837
+ * throw an error if encoding of the CID is not compatible with supplied (or
838
+ * a default decoder).
839
+ */
840
+ static parse(source, base3) {
841
+ const [prefix, bytes] = parseCIDtoBytes(source, base3);
842
+ const cid = _CID.decode(bytes);
843
+ if (cid.version === 0 && source[0] !== "Q") {
844
+ throw Error("Version 0 CID string must not include multibase prefix");
845
+ }
846
+ baseCache(cid).set(prefix, source);
847
+ return cid;
848
+ }
849
+ };
850
+ function parseCIDtoBytes(source, base3) {
851
+ switch (source[0]) {
852
+ // CIDv0 is parsed differently
853
+ case "Q": {
854
+ const decoder = base3 ?? base58btc;
855
+ return [
856
+ base58btc.prefix,
857
+ decoder.decode(`${base58btc.prefix}${source}`)
858
+ ];
859
+ }
860
+ case base58btc.prefix: {
861
+ const decoder = base3 ?? base58btc;
862
+ return [base58btc.prefix, decoder.decode(source)];
863
+ }
864
+ case base32.prefix: {
865
+ const decoder = base3 ?? base32;
866
+ return [base32.prefix, decoder.decode(source)];
867
+ }
868
+ case base36.prefix: {
869
+ const decoder = base3 ?? base36;
870
+ return [base36.prefix, decoder.decode(source)];
871
+ }
872
+ default: {
873
+ if (base3 == null) {
874
+ throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
875
+ }
876
+ return [source[0], base3.decode(source)];
877
+ }
878
+ }
879
+ }
880
+ function toStringV0(bytes, cache2, base3) {
881
+ const { prefix } = base3;
882
+ if (prefix !== base58btc.prefix) {
883
+ throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
884
+ }
885
+ const cid = cache2.get(prefix);
886
+ if (cid == null) {
887
+ const cid2 = base3.encode(bytes).slice(1);
888
+ cache2.set(prefix, cid2);
889
+ return cid2;
890
+ } else {
891
+ return cid;
892
+ }
893
+ }
894
+ function toStringV1(bytes, cache2, base3) {
895
+ const { prefix } = base3;
896
+ const cid = cache2.get(prefix);
897
+ if (cid == null) {
898
+ const cid2 = base3.encode(bytes);
899
+ cache2.set(prefix, cid2);
900
+ return cid2;
901
+ } else {
902
+ return cid;
903
+ }
904
+ }
905
+ var DAG_PB_CODE = 112;
906
+ var SHA_256_CODE = 18;
907
+ function encodeCID(version, code2, multihash) {
908
+ const codeOffset = encodingLength(version);
909
+ const hashOffset = codeOffset + encodingLength(code2);
910
+ const bytes = new Uint8Array(hashOffset + multihash.byteLength);
911
+ encodeTo(version, bytes, 0);
912
+ encodeTo(code2, bytes, codeOffset);
913
+ bytes.set(multihash, hashOffset);
914
+ return bytes;
915
+ }
916
+ var cidSymbol = /* @__PURE__ */ Symbol.for("@ipld/js-cid/CID");
917
+
918
+ // src/requester/index.ts
6
919
  import { z } from "zod";
7
920
 
8
921
  // src/policy/errors.ts
9
922
  var SignedObjectProfileError = class extends Error {
10
- constructor(code, message) {
923
+ constructor(code2, message) {
11
924
  super(message);
12
925
  this.name = "SignedObjectProfileError";
13
- this.code = code;
926
+ this.code = code2;
14
927
  }
15
928
  };
16
929
  var SignedObjectSchemaError = class extends SignedObjectProfileError {
@@ -199,35 +1112,33 @@ function assertNoSymbolKeys(input, path) {
199
1112
  );
200
1113
  }
201
1114
  }
202
- function isArrayIndexKey(key, length) {
1115
+ function isArrayIndexKey(key, length2) {
203
1116
  if (!/^(0|[1-9]\d*)$/.test(key)) {
204
1117
  return false;
205
1118
  }
206
1119
  const index = Number(key);
207
- return Number.isSafeInteger(index) && index >= 0 && index < length;
1120
+ return Number.isSafeInteger(index) && index >= 0 && index < length2;
208
1121
  }
209
1122
  function serializeObject(value) {
210
- const keys = Object.keys(value).sort(compareCodePoints);
1123
+ const keys = Object.keys(value).sort(compareUtf16CodeUnits);
211
1124
  const parts = keys.map((key) => `${JSON.stringify(key)}:${serialize(value[key])}`);
212
1125
  return `{${parts.join(",")}}`;
213
1126
  }
214
- function compareCodePoints(a, b) {
215
- const left = Array.from(a);
216
- const right = Array.from(b);
217
- const max = Math.min(left.length, right.length);
1127
+ function compareUtf16CodeUnits(a, b) {
1128
+ const max = Math.min(a.length, b.length);
218
1129
  for (let index = 0; index < max; index++) {
219
- const leftPoint = left[index].codePointAt(0) ?? 0;
220
- const rightPoint = right[index].codePointAt(0) ?? 0;
221
- if (leftPoint !== rightPoint) {
222
- return leftPoint - rightPoint;
1130
+ const leftCodeUnit = a.charCodeAt(index);
1131
+ const rightCodeUnit = b.charCodeAt(index);
1132
+ if (leftCodeUnit !== rightCodeUnit) {
1133
+ return leftCodeUnit - rightCodeUnit;
223
1134
  }
224
1135
  }
225
- return left.length - right.length;
1136
+ return a.length - b.length;
226
1137
  }
227
1138
  function assertUnicodeScalarString(value, path) {
228
1139
  for (let index = 0; index < value.length; index++) {
229
- const code = value.charCodeAt(index);
230
- if (code >= 55296 && code <= 56319) {
1140
+ const code2 = value.charCodeAt(index);
1141
+ if (code2 >= 55296 && code2 <= 56319) {
231
1142
  const next = value.charCodeAt(index + 1);
232
1143
  if (Number.isNaN(next) || next < 56320 || next > 57343) {
233
1144
  throw new SignedObjectCanonicalizationError(
@@ -237,7 +1148,7 @@ function assertUnicodeScalarString(value, path) {
237
1148
  index++;
238
1149
  continue;
239
1150
  }
240
- if (code >= 56320 && code <= 57343) {
1151
+ if (code2 >= 56320 && code2 <= 57343) {
241
1152
  throw new SignedObjectCanonicalizationError(
242
1153
  `${path} contains a lone low surrogate`
243
1154
  );
@@ -250,10 +1161,10 @@ import { CAPABILITY_REGISTRY } from "@tinycloud/bootstrap";
250
1161
  import { bytesToHex, sha256 } from "viem";
251
1162
  var textEncoder = new TextEncoder();
252
1163
  var PolicyCapabilityError = class extends Error {
253
- constructor(code, message) {
1164
+ constructor(code2, message) {
254
1165
  super(message);
255
1166
  this.name = "PolicyCapabilityError";
256
- this.code = code;
1167
+ this.code = code2;
257
1168
  }
258
1169
  };
259
1170
  var objectHasOwn2 = Object.hasOwn ?? Object.prototype.hasOwnProperty.call.bind(
@@ -379,23 +1290,23 @@ function assertExactKeys(object, allowed, path) {
379
1290
  }
380
1291
  }
381
1292
  }
382
- function requiredValue(object, key, path, code) {
1293
+ function requiredValue(object, key, path, code2) {
383
1294
  if (!hasOwn(object, key)) {
384
- throw new PolicyCapabilityError(code, `${path}.${key} is required`);
1295
+ throw new PolicyCapabilityError(code2, `${path}.${key} is required`);
385
1296
  }
386
1297
  return object[key];
387
1298
  }
388
- function requiredString(object, key, path, code) {
389
- const value = requiredValue(object, key, path, code);
1299
+ function requiredString(object, key, path, code2) {
1300
+ const value = requiredValue(object, key, path, code2);
390
1301
  if (typeof value !== "string" || value.length === 0) {
391
- throw new PolicyCapabilityError(code, `${path}.${key} must be a non-empty string`);
1302
+ throw new PolicyCapabilityError(code2, `${path}.${key} must be a non-empty string`);
392
1303
  }
393
1304
  return value;
394
1305
  }
395
- function requiredArray(object, key, path, code) {
396
- const value = requiredValue(object, key, path, code);
1306
+ function requiredArray(object, key, path, code2) {
1307
+ const value = requiredValue(object, key, path, code2);
397
1308
  if (!Array.isArray(value)) {
398
- throw new PolicyCapabilityError(code, `${path}.${key} must be an array`);
1309
+ throw new PolicyCapabilityError(code2, `${path}.${key} must be an array`);
399
1310
  }
400
1311
  return value;
401
1312
  }
@@ -626,8 +1537,249 @@ function hasOwn(object, key) {
626
1537
 
627
1538
  // src/policy/signed-object.ts
628
1539
  import { ed25519 } from "@noble/curves/ed25519";
629
- import { bases } from "multiformats/basics";
630
- import { bytesToHex as bytesToHex2, sha256 as sha2562, verifyMessage } from "viem";
1540
+
1541
+ // ../../node_modules/multiformats/dist/src/bases/base10.js
1542
+ var base10_exports = {};
1543
+ __export(base10_exports, {
1544
+ base10: () => base10
1545
+ });
1546
+ var base10 = baseX({
1547
+ prefix: "9",
1548
+ name: "base10",
1549
+ alphabet: "0123456789"
1550
+ });
1551
+
1552
+ // ../../node_modules/multiformats/dist/src/bases/base16.js
1553
+ var base16_exports = {};
1554
+ __export(base16_exports, {
1555
+ base16: () => base16,
1556
+ base16upper: () => base16upper
1557
+ });
1558
+ var base16 = rfc4648({
1559
+ prefix: "f",
1560
+ name: "base16",
1561
+ alphabet: "0123456789abcdef",
1562
+ bitsPerChar: 4
1563
+ });
1564
+ var base16upper = rfc4648({
1565
+ prefix: "F",
1566
+ name: "base16upper",
1567
+ alphabet: "0123456789ABCDEF",
1568
+ bitsPerChar: 4
1569
+ });
1570
+
1571
+ // ../../node_modules/multiformats/dist/src/bases/base2.js
1572
+ var base2_exports = {};
1573
+ __export(base2_exports, {
1574
+ base2: () => base2
1575
+ });
1576
+ var base2 = rfc4648({
1577
+ prefix: "0",
1578
+ name: "base2",
1579
+ alphabet: "01",
1580
+ bitsPerChar: 1
1581
+ });
1582
+
1583
+ // ../../node_modules/multiformats/dist/src/bases/base256emoji.js
1584
+ var base256emoji_exports = {};
1585
+ __export(base256emoji_exports, {
1586
+ base256emoji: () => base256emoji
1587
+ });
1588
+ var alphabet = Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}");
1589
+ var alphabetBytesToChars = alphabet.reduce((p, c, i) => {
1590
+ p[i] = c;
1591
+ return p;
1592
+ }, []);
1593
+ var alphabetCharsToBytes = alphabet.reduce((p, c, i) => {
1594
+ const codePoint = c.codePointAt(0);
1595
+ if (codePoint == null) {
1596
+ throw new Error(`Invalid character: ${c}`);
1597
+ }
1598
+ p[codePoint] = i;
1599
+ return p;
1600
+ }, []);
1601
+ function encode3(data) {
1602
+ return data.reduce((p, c) => {
1603
+ p += alphabetBytesToChars[c];
1604
+ return p;
1605
+ }, "");
1606
+ }
1607
+ function decode5(str) {
1608
+ const byts = [];
1609
+ for (const char of str) {
1610
+ const codePoint = char.codePointAt(0);
1611
+ if (codePoint == null) {
1612
+ throw new Error(`Invalid character: ${char}`);
1613
+ }
1614
+ const byt = alphabetCharsToBytes[codePoint];
1615
+ if (byt == null) {
1616
+ throw new Error(`Non-base256emoji character: ${char}`);
1617
+ }
1618
+ byts.push(byt);
1619
+ }
1620
+ return new Uint8Array(byts);
1621
+ }
1622
+ var base256emoji = from({
1623
+ prefix: "\u{1F680}",
1624
+ name: "base256emoji",
1625
+ encode: encode3,
1626
+ decode: decode5
1627
+ });
1628
+
1629
+ // ../../node_modules/multiformats/dist/src/bases/base64.js
1630
+ var base64_exports = {};
1631
+ __export(base64_exports, {
1632
+ base64: () => base64,
1633
+ base64pad: () => base64pad,
1634
+ base64url: () => base64url,
1635
+ base64urlpad: () => base64urlpad
1636
+ });
1637
+ var base64 = rfc4648({
1638
+ prefix: "m",
1639
+ name: "base64",
1640
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
1641
+ bitsPerChar: 6
1642
+ });
1643
+ var base64pad = rfc4648({
1644
+ prefix: "M",
1645
+ name: "base64pad",
1646
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
1647
+ bitsPerChar: 6
1648
+ });
1649
+ var base64url = rfc4648({
1650
+ prefix: "u",
1651
+ name: "base64url",
1652
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
1653
+ bitsPerChar: 6
1654
+ });
1655
+ var base64urlpad = rfc4648({
1656
+ prefix: "U",
1657
+ name: "base64urlpad",
1658
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
1659
+ bitsPerChar: 6
1660
+ });
1661
+
1662
+ // ../../node_modules/multiformats/dist/src/bases/base8.js
1663
+ var base8_exports = {};
1664
+ __export(base8_exports, {
1665
+ base8: () => base8
1666
+ });
1667
+ var base8 = rfc4648({
1668
+ prefix: "7",
1669
+ name: "base8",
1670
+ alphabet: "01234567",
1671
+ bitsPerChar: 3
1672
+ });
1673
+
1674
+ // ../../node_modules/multiformats/dist/src/bases/identity.js
1675
+ var identity_exports = {};
1676
+ __export(identity_exports, {
1677
+ identity: () => identity
1678
+ });
1679
+ var identity = from({
1680
+ prefix: "\0",
1681
+ name: "identity",
1682
+ encode: (buf) => toString(buf),
1683
+ decode: (str) => fromString(str)
1684
+ });
1685
+
1686
+ // ../../node_modules/multiformats/dist/src/codecs/json.js
1687
+ var textEncoder2 = new TextEncoder();
1688
+ var textDecoder = new TextDecoder();
1689
+
1690
+ // ../../node_modules/multiformats/dist/src/hashes/identity.js
1691
+ var identity_exports2 = {};
1692
+ __export(identity_exports2, {
1693
+ identity: () => identity2
1694
+ });
1695
+ var code = 0;
1696
+ var name = "identity";
1697
+ var encode4 = coerce;
1698
+ function digest(input, options) {
1699
+ if (options?.truncate != null && options.truncate !== input.byteLength) {
1700
+ if (options.truncate < 0 || options.truncate > input.byteLength) {
1701
+ throw new Error(`Invalid truncate option, must be less than or equal to ${input.byteLength}`);
1702
+ }
1703
+ input = input.subarray(0, options.truncate);
1704
+ }
1705
+ return create(code, encode4(input));
1706
+ }
1707
+ var identity2 = { code, name, encode: encode4, digest };
1708
+
1709
+ // ../../node_modules/multiformats/dist/src/hashes/sha2.js
1710
+ var sha2_exports = {};
1711
+ __export(sha2_exports, {
1712
+ sha256: () => sha2562,
1713
+ sha512: () => sha512
1714
+ });
1715
+ import crypto from "crypto";
1716
+
1717
+ // ../../node_modules/multiformats/dist/src/hashes/hasher.js
1718
+ var DEFAULT_MIN_DIGEST_LENGTH = 20;
1719
+ function from2({ name: name2, code: code2, encode: encode5, minDigestLength, maxDigestLength }) {
1720
+ return new Hasher(name2, code2, encode5, minDigestLength, maxDigestLength);
1721
+ }
1722
+ var Hasher = class {
1723
+ constructor(name2, code2, encode5, minDigestLength, maxDigestLength) {
1724
+ __publicField(this, "name");
1725
+ __publicField(this, "code");
1726
+ __publicField(this, "encode");
1727
+ __publicField(this, "minDigestLength");
1728
+ __publicField(this, "maxDigestLength");
1729
+ this.name = name2;
1730
+ this.code = code2;
1731
+ this.encode = encode5;
1732
+ this.minDigestLength = minDigestLength ?? DEFAULT_MIN_DIGEST_LENGTH;
1733
+ this.maxDigestLength = maxDigestLength;
1734
+ }
1735
+ digest(input, options) {
1736
+ if (options?.truncate != null) {
1737
+ if (options.truncate < this.minDigestLength) {
1738
+ throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);
1739
+ }
1740
+ if (this.maxDigestLength != null && options.truncate > this.maxDigestLength) {
1741
+ throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`);
1742
+ }
1743
+ }
1744
+ if (input instanceof Uint8Array) {
1745
+ const result = this.encode(input);
1746
+ if (result instanceof Uint8Array) {
1747
+ return createDigest(result, this.code, options?.truncate);
1748
+ }
1749
+ return result.then((digest2) => createDigest(digest2, this.code, options?.truncate));
1750
+ } else {
1751
+ throw Error("Unknown type, must be binary type");
1752
+ }
1753
+ }
1754
+ };
1755
+ function createDigest(digest2, code2, truncate) {
1756
+ if (truncate != null && truncate !== digest2.byteLength) {
1757
+ if (truncate > digest2.byteLength) {
1758
+ throw new Error(`Invalid truncate option, must be less than or equal to ${digest2.byteLength}`);
1759
+ }
1760
+ digest2 = digest2.subarray(0, truncate);
1761
+ }
1762
+ return create(code2, digest2);
1763
+ }
1764
+
1765
+ // ../../node_modules/multiformats/dist/src/hashes/sha2.js
1766
+ var sha2562 = from2({
1767
+ name: "sha2-256",
1768
+ code: 18,
1769
+ encode: (input) => coerce(crypto.createHash("sha256").update(input).digest())
1770
+ });
1771
+ var sha512 = from2({
1772
+ name: "sha2-512",
1773
+ code: 19,
1774
+ encode: (input) => coerce(crypto.createHash("sha512").update(input).digest())
1775
+ });
1776
+
1777
+ // ../../node_modules/multiformats/dist/src/basics.js
1778
+ var bases = { ...identity_exports, ...base2_exports, ...base8_exports, ...base10_exports, ...base16_exports, ...base32_exports, ...base36_exports, ...base58_exports, ...base64_exports, ...base256emoji_exports };
1779
+ var hashes = { ...sha2_exports, ...identity_exports2 };
1780
+
1781
+ // src/policy/signed-object.ts
1782
+ import { bytesToHex as bytesToHex2, sha256 as sha2563, verifyMessage } from "viem";
631
1783
 
632
1784
  // src/identity.ts
633
1785
  import { getAddress, isAddress } from "viem";
@@ -694,7 +1846,7 @@ var DESCRIPTORS = {
694
1846
  domain: POLICY_ENGINE_RECORD_SCHEMA
695
1847
  }
696
1848
  };
697
- var textEncoder2 = new TextEncoder();
1849
+ var textEncoder3 = new TextEncoder();
698
1850
  var BASE32_ALPHABET = "abcdefghijklmnopqrstuvwxyz234567";
699
1851
  var BASE64URL_RE = /^[A-Za-z0-9_-]+$/;
700
1852
  var objectHasOwn3 = Object.hasOwn ?? Object.prototype.hasOwnProperty.call.bind(
@@ -1006,9 +2158,9 @@ function validateAudit(input, path) {
1006
2158
  }
1007
2159
  function materialForUnsigned(unsigned, descriptor) {
1008
2160
  const jcs = jcsCanonicalize(unsigned);
1009
- const jcsBytes = textEncoder2.encode(jcs);
1010
- const digest = sha256Bytes(concatBytes(textEncoder2.encode(`${descriptor.domain}\0`), jcsBytes));
1011
- const id = `${descriptor.idPrefix}${base32LowerNoPad(digest)}`;
2161
+ const jcsBytes = textEncoder3.encode(jcs);
2162
+ const digest2 = sha256Bytes(concatBytes(textEncoder3.encode(`${descriptor.domain}\0`), jcsBytes));
2163
+ const id = `${descriptor.idPrefix}${base32LowerNoPad(digest2)}`;
1012
2164
  return {
1013
2165
  kind: descriptor.kind,
1014
2166
  idField: descriptor.idField,
@@ -1017,8 +2169,8 @@ function materialForUnsigned(unsigned, descriptor) {
1017
2169
  unsigned,
1018
2170
  jcs,
1019
2171
  jcsBytes,
1020
- digest,
1021
- digestHex: bytesToHex2(digest).slice(2)
2172
+ digest: digest2,
2173
+ digestHex: bytesToHex2(digest2).slice(2)
1022
2174
  };
1023
2175
  }
1024
2176
  function assertIdMatches(signed, material, descriptor) {
@@ -1044,12 +2196,12 @@ function assertSigningKeyBindingForVerify(signed, signature) {
1044
2196
  );
1045
2197
  }
1046
2198
  }
1047
- async function verifySignature(signature, digest) {
2199
+ async function verifySignature(signature, digest2) {
1048
2200
  if (signature.suite === ED25519_JCS_SIGNATURE_SUITE) {
1049
2201
  const publicKey = ed25519PublicKeyFromDidKey(signature.signerDid);
1050
2202
  const signatureBytes = decodeSignatureValue(signature.value, signature.suite);
1051
2203
  try {
1052
- return ed25519.verify(signatureBytes, digest, publicKey);
2204
+ return ed25519.verify(signatureBytes, digest2, publicKey);
1053
2205
  } catch {
1054
2206
  throw new SignatureVerificationError("Ed25519 signature verification failed");
1055
2207
  }
@@ -1060,7 +2212,7 @@ async function verifySignature(signature, digest) {
1060
2212
  try {
1061
2213
  return verifyMessage({
1062
2214
  address: pkh.address,
1063
- message: { raw: digest },
2215
+ message: { raw: digest2 },
1064
2216
  signature: bytesToHex2(signatureBytes)
1065
2217
  });
1066
2218
  } catch {
@@ -1252,7 +2404,7 @@ function assertSupportedSignatureSuite(suite) {
1252
2404
  }
1253
2405
  }
1254
2406
  function sha256Bytes(bytes) {
1255
- return sha2562(bytes, "bytes");
2407
+ return sha2563(bytes, "bytes");
1256
2408
  }
1257
2409
  function concatBytes(left, right) {
1258
2410
  const output = new Uint8Array(left.length + right.length);
@@ -1278,20 +2430,20 @@ function base32LowerNoPad(bytes) {
1278
2430
  return output;
1279
2431
  }
1280
2432
  function base64UrlEncode(bytes) {
1281
- const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
2433
+ const alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
1282
2434
  let output = "";
1283
2435
  for (let index = 0; index < bytes.length; index += 3) {
1284
2436
  const a = bytes[index];
1285
2437
  const b = bytes[index + 1];
1286
2438
  const c = bytes[index + 2];
1287
2439
  const triplet = a << 16 | (b ?? 0) << 8 | (c ?? 0);
1288
- output += alphabet[triplet >> 18 & 63];
1289
- output += alphabet[triplet >> 12 & 63];
2440
+ output += alphabet2[triplet >> 18 & 63];
2441
+ output += alphabet2[triplet >> 12 & 63];
1290
2442
  if (index + 1 < bytes.length) {
1291
- output += alphabet[triplet >> 6 & 63];
2443
+ output += alphabet2[triplet >> 6 & 63];
1292
2444
  }
1293
2445
  if (index + 2 < bytes.length) {
1294
- output += alphabet[triplet & 63];
2446
+ output += alphabet2[triplet & 63];
1295
2447
  }
1296
2448
  }
1297
2449
  return output;
@@ -1300,12 +2452,12 @@ function base64UrlDecode(value) {
1300
2452
  if (value.length % 4 === 1) {
1301
2453
  throw new SignatureMaterialError("signature value is not canonical base64url");
1302
2454
  }
1303
- const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
2455
+ const alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
1304
2456
  const bytes = [];
1305
2457
  let buffer = 0;
1306
2458
  let bits = 0;
1307
2459
  for (const char of value) {
1308
- const index = alphabet.indexOf(char);
2460
+ const index = alphabet2.indexOf(char);
1309
2461
  if (index < 0) {
1310
2462
  throw new SignatureMaterialError("signature value is not base64url");
1311
2463
  }
@@ -1329,10 +2481,10 @@ var OWNER_NODE_ENDPOINT_SCHEMA = "xyz.tinycloud.exchange/owner-node-endpoint/v1"
1329
2481
  var POLICY_VERSION_V0 = "v0";
1330
2482
  var W3C_VC_CREDENTIAL_VERIFIER = "w3c.vc/credential/v1";
1331
2483
  var PolicyAuthoringError = class extends Error {
1332
- constructor(code, message) {
2484
+ constructor(code2, message) {
1333
2485
  super(message);
1334
2486
  this.name = "PolicyAuthoringError";
1335
- this.code = code;
2487
+ this.code = code2;
1336
2488
  }
1337
2489
  };
1338
2490
  async function verifyPolicyEngineRecordForRequester(options) {
@@ -1443,11 +2595,11 @@ async function verifyPolicyEngineRecordForRequester(options) {
1443
2595
  }
1444
2596
  return verified;
1445
2597
  }
1446
- function expectObject2(input, path, code) {
2598
+ function expectObject2(input, path, code2) {
1447
2599
  try {
1448
2600
  const normalized = normalizeJson(input);
1449
2601
  if (normalized === null || typeof normalized !== "object" || Array.isArray(normalized)) {
1450
- throw new PolicyAuthoringError(code, `${path} must be an object`);
2602
+ throw new PolicyAuthoringError(code2, `${path} must be an object`);
1451
2603
  }
1452
2604
  return normalized;
1453
2605
  } catch (error) {
@@ -1455,7 +2607,7 @@ function expectObject2(input, path, code) {
1455
2607
  throw error;
1456
2608
  }
1457
2609
  throw new PolicyAuthoringError(
1458
- code,
2610
+ code2,
1459
2611
  error instanceof Error ? error.message : String(error)
1460
2612
  );
1461
2613
  }
@@ -1490,14 +2642,14 @@ function requiredString3(object, key, path) {
1490
2642
  }
1491
2643
  return value;
1492
2644
  }
1493
- function fieldString(object, key, path, code) {
2645
+ function fieldString(object, key, path, code2) {
1494
2646
  if (!hasOwn3(object, key)) {
1495
- throw new PolicyAuthoringError(code, `${path}.${key} is required`);
2647
+ throw new PolicyAuthoringError(code2, `${path}.${key} is required`);
1496
2648
  }
1497
2649
  const value = object[key];
1498
2650
  if (typeof value !== "string" || value.length === 0) {
1499
2651
  throw new PolicyAuthoringError(
1500
- code,
2652
+ code2,
1501
2653
  `${path}.${key} must be a non-empty string`
1502
2654
  );
1503
2655
  }
@@ -1603,10 +2755,10 @@ var POLICY_ENGINE_GRANT_PRESENTATION_DENIAL_CODES = [
1603
2755
  "rate-limited"
1604
2756
  ];
1605
2757
  var TranscriptRequesterError = class extends Error {
1606
- constructor(code, message, state = "invalid", denialCode, status) {
2758
+ constructor(code2, message, state = "invalid", denialCode, status) {
1607
2759
  super(message);
1608
2760
  this.name = "TranscriptRequesterError";
1609
- this.code = code;
2761
+ this.code = code2;
1610
2762
  this.state = state;
1611
2763
  this.denialCode = denialCode;
1612
2764
  this.status = status;
@@ -2380,23 +3532,23 @@ async function verifyRecordBeforeEgress(bootstrap, options) {
2380
3532
  requiredEvidenceVerifier: W3C_VC_CREDENTIAL_VERIFIER
2381
3533
  });
2382
3534
  } catch (error) {
2383
- const code = errorCodeForRecordFailure(error);
3535
+ const code2 = errorCodeForRecordFailure(error);
2384
3536
  throw new TranscriptRequesterError(
2385
- code,
3537
+ code2,
2386
3538
  error instanceof Error ? error.message : String(error),
2387
3539
  "bootstrap-invalid"
2388
3540
  );
2389
3541
  }
2390
3542
  }
2391
3543
  function errorCodeForRecordFailure(error) {
2392
- const code = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
2393
- if (code === "policy-engine-record-signature-invalid") {
3544
+ const code2 = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
3545
+ if (code2 === "policy-engine-record-signature-invalid") {
2394
3546
  return "requester-engine-record-signature-invalid";
2395
3547
  }
2396
- if (code === "policy-engine-record-owner-mismatch") {
3548
+ if (code2 === "policy-engine-record-owner-mismatch") {
2397
3549
  return "requester-engine-record-owner-mismatch";
2398
3550
  }
2399
- if (code === "policy-engine-record-audience-mismatch") {
3551
+ if (code2 === "policy-engine-record-audience-mismatch") {
2400
3552
  return "requester-engine-record-audience-mismatch";
2401
3553
  }
2402
3554
  return "requester-engine-record-invalid";
@@ -2449,7 +3601,7 @@ function requestedCapabilitiesHash(capabilities) {
2449
3601
  const bytes = new Uint8Array(domain.length + body.length);
2450
3602
  bytes.set(domain, 0);
2451
3603
  bytes.set(body, domain.length);
2452
- return bytesToHex3(sha2563(bytes, "bytes")).slice(2);
3604
+ return bytesToHex3(sha2564(bytes, "bytes")).slice(2);
2453
3605
  }
2454
3606
  function normalizeWireDelegation(delegation) {
2455
3607
  const signed = delegationAuthorityFromCompactJws(delegation.encoded);
@@ -2696,16 +3848,16 @@ function nodeErrorMessage(body) {
2696
3848
  if (typeof body === "string") return body;
2697
3849
  if (body !== null && typeof body === "object") {
2698
3850
  const record = body;
2699
- const code = typeof record.code === "string" ? record.code : void 0;
3851
+ const code2 = typeof record.code === "string" ? record.code : void 0;
2700
3852
  const message = typeof record.message === "string" ? record.message : void 0;
2701
- if (code !== void 0)
2702
- return message === void 0 ? code : `${code}: ${message}`;
3853
+ if (code2 !== void 0)
3854
+ return message === void 0 ? code2 : `${code2}: ${message}`;
2703
3855
  }
2704
3856
  return "native node refusal";
2705
3857
  }
2706
3858
  function deriveDelegationCid(encoded) {
2707
- const digest = createDigest(30, blake3(new TextEncoder().encode(encoded)));
2708
- return CID.createV1(85, digest).toString();
3859
+ const digest2 = create(30, blake3(new TextEncoder().encode(encoded)));
3860
+ return CID.createV1(85, digest2).toString();
2709
3861
  }
2710
3862
  function headersRecord(headers) {
2711
3863
  return Array.isArray(headers) ? Object.fromEntries(headers) : headers;
@@ -2816,21 +3968,21 @@ function errorForDenial(denial, status) {
2816
3968
  );
2817
3969
  }
2818
3970
  function retryDelay(attempt, random) {
2819
- const base = Math.min(REQUESTER_ENGINE_RETRY_MAX_DELAY_MS, 50 * 2 ** attempt);
3971
+ const base3 = Math.min(REQUESTER_ENGINE_RETRY_MAX_DELAY_MS, 50 * 2 ** attempt);
2820
3972
  return Math.min(
2821
3973
  REQUESTER_ENGINE_RETRY_MAX_DELAY_MS,
2822
- Math.floor(base * (0.5 + random))
3974
+ Math.floor(base3 * (0.5 + random))
2823
3975
  );
2824
3976
  }
2825
3977
  function trimTrailingSlash(value) {
2826
3978
  return value.endsWith("/") ? value.slice(0, -1) : value;
2827
3979
  }
2828
- function normalizeExternal(input, code) {
3980
+ function normalizeExternal(input, code2) {
2829
3981
  try {
2830
3982
  return normalizeJson(input);
2831
3983
  } catch (error) {
2832
3984
  throw new TranscriptRequesterError(
2833
- code,
3985
+ code2,
2834
3986
  error instanceof Error ? error.message : String(error)
2835
3987
  );
2836
3988
  }