@wovin/core 0.0.4 → 0.0.6

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.
Files changed (73) hide show
  1. package/dist/applog/applog-helpers.d.ts +4 -4
  2. package/dist/applog/applog-helpers.d.ts.map +1 -1
  3. package/dist/applog.min.js +1 -1
  4. package/dist/chunk-5Q6PAAMY.min.js +2 -0
  5. package/dist/chunk-5Q6PAAMY.min.js.map +1 -0
  6. package/dist/chunk-BR5DELY4.min.js +2 -0
  7. package/dist/chunk-BR5DELY4.min.js.map +1 -0
  8. package/dist/chunk-D6REGRIL.min.js +2 -0
  9. package/dist/chunk-D6REGRIL.min.js.map +1 -0
  10. package/dist/{chunk-WNS2N7XB.min.js → chunk-IVEP7DZW.min.js} +21 -21
  11. package/dist/{chunk-WNS2N7XB.min.js.map → chunk-IVEP7DZW.min.js.map} +1 -1
  12. package/dist/{chunk-UZUBJLQD.min.js → chunk-J5PGGKKW.min.js} +2 -2
  13. package/dist/{chunk-UZUBJLQD.min.js.map → chunk-J5PGGKKW.min.js.map} +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.min.js +1 -1
  16. package/dist/index.min.js.map +1 -1
  17. package/dist/ipfs/car.d.ts.map +1 -1
  18. package/dist/ipfs.min.js +1 -1
  19. package/dist/mobx/mobx-utils.d.ts +6 -6
  20. package/dist/mobx/mobx-utils.d.ts.map +1 -1
  21. package/dist/pubsub/publication.d.ts +2 -2
  22. package/dist/pubsub/publication.d.ts.map +1 -1
  23. package/dist/pubsub.min.js +1 -1
  24. package/dist/query/basic.d.ts +19 -19
  25. package/dist/query/basic.d.ts.map +1 -1
  26. package/dist/query/divergences.d.ts +5 -5
  27. package/dist/query/divergences.d.ts.map +1 -1
  28. package/dist/query.min.js +1 -1
  29. package/dist/thread/basic.d.ts +36 -0
  30. package/dist/thread/basic.d.ts.map +1 -0
  31. package/dist/thread/filters.d.ts +38 -0
  32. package/dist/thread/filters.d.ts.map +1 -0
  33. package/dist/thread/mapped.d.ts +19 -0
  34. package/dist/thread/mapped.d.ts.map +1 -0
  35. package/dist/thread/writeable.d.ts +17 -0
  36. package/dist/thread/writeable.d.ts.map +1 -0
  37. package/dist/thread.d.ts +5 -0
  38. package/dist/thread.d.ts.map +1 -0
  39. package/dist/thread.min.js +2 -0
  40. package/dist/types/typescript-utils.d.ts +2 -2
  41. package/dist/types/typescript-utils.d.ts.map +1 -1
  42. package/dist/types.min.js +1 -1
  43. package/package.json +4 -4
  44. package/dist/chunk-2UCPKUQK.min.js +0 -1256
  45. package/dist/chunk-2UCPKUQK.min.js.map +0 -1
  46. package/dist/chunk-3HUXODLY.min.js +0 -11940
  47. package/dist/chunk-3HUXODLY.min.js.map +0 -1
  48. package/dist/chunk-KBXBNPCO.min.js +0 -2
  49. package/dist/chunk-KBXBNPCO.min.js.map +0 -1
  50. package/dist/chunk-N7GKIL5T.min.js +0 -120
  51. package/dist/chunk-N7GKIL5T.min.js.map +0 -1
  52. package/dist/chunk-PVULNVU2.min.js +0 -49
  53. package/dist/chunk-PVULNVU2.min.js.map +0 -1
  54. package/dist/chunk-VTXN7J7O.min.js +0 -66
  55. package/dist/chunk-VTXN7J7O.min.js.map +0 -1
  56. package/dist/chunk-W7B2PDHK.min.js +0 -2
  57. package/dist/chunk-W7B2PDHK.min.js.map +0 -1
  58. package/dist/chunk-WCOT2GIF.min.js +0 -2
  59. package/dist/chunk-WCOT2GIF.min.js.map +0 -1
  60. package/dist/chunk-WOD425XV.min.js +0 -4401
  61. package/dist/chunk-WOD425XV.min.js.map +0 -1
  62. package/dist/stream/basic.d.ts +0 -36
  63. package/dist/stream/basic.d.ts.map +0 -1
  64. package/dist/stream/filters.d.ts +0 -38
  65. package/dist/stream/filters.d.ts.map +0 -1
  66. package/dist/stream/mapped.d.ts +0 -19
  67. package/dist/stream/mapped.d.ts.map +0 -1
  68. package/dist/stream/writeable.d.ts +0 -17
  69. package/dist/stream/writeable.d.ts.map +0 -1
  70. package/dist/stream.d.ts +0 -5
  71. package/dist/stream.d.ts.map +0 -1
  72. package/dist/stream.min.js +0 -2
  73. /package/dist/{stream.min.js.map → thread.min.js.map} +0 -0
@@ -1,4401 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
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;
9
- };
10
- var __export = (target, all) => {
11
- for (var name2 in all)
12
- __defProp(target, name2, { get: all[name2], enumerable: true });
13
- };
14
- var __copyProps = (to, from3, except, desc) => {
15
- if (from3 && typeof from3 === "object" || typeof from3 === "function") {
16
- for (let key of __getOwnPropNames(from3))
17
- if (!__hasOwnProp.call(to, key) && key !== except)
18
- __defProp(to, key, { get: () => from3[key], enumerable: !(desc = __getOwnPropDesc(from3, key)) || desc.enumerable });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
- mod
29
- ));
30
-
31
- // ../../../node_modules/.pnpm/@ipld+dag-json@10.1.5/node_modules/@ipld/dag-json/src/index.js
32
- var src_exports = {};
33
- __export(src_exports, {
34
- code: () => code,
35
- decode: () => decode7,
36
- encode: () => encode5,
37
- format: () => format2,
38
- name: () => name,
39
- parse: () => parse,
40
- stringify: () => format2
41
- });
42
-
43
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/is.js
44
- var typeofs = [
45
- "string",
46
- "number",
47
- "bigint",
48
- "symbol"
49
- ];
50
- var objectTypeNames = [
51
- "Function",
52
- "Generator",
53
- "AsyncGenerator",
54
- "GeneratorFunction",
55
- "AsyncGeneratorFunction",
56
- "AsyncFunction",
57
- "Observable",
58
- "Array",
59
- "Buffer",
60
- "Object",
61
- "RegExp",
62
- "Date",
63
- "Error",
64
- "Map",
65
- "Set",
66
- "WeakMap",
67
- "WeakSet",
68
- "ArrayBuffer",
69
- "SharedArrayBuffer",
70
- "DataView",
71
- "Promise",
72
- "URL",
73
- "HTMLElement",
74
- "Int8Array",
75
- "Uint8Array",
76
- "Uint8ClampedArray",
77
- "Int16Array",
78
- "Uint16Array",
79
- "Int32Array",
80
- "Uint32Array",
81
- "Float32Array",
82
- "Float64Array",
83
- "BigInt64Array",
84
- "BigUint64Array"
85
- ];
86
- function is(value) {
87
- if (value === null) {
88
- return "null";
89
- }
90
- if (value === void 0) {
91
- return "undefined";
92
- }
93
- if (value === true || value === false) {
94
- return "boolean";
95
- }
96
- const typeOf = typeof value;
97
- if (typeofs.includes(typeOf)) {
98
- return typeOf;
99
- }
100
- if (typeOf === "function") {
101
- return "Function";
102
- }
103
- if (Array.isArray(value)) {
104
- return "Array";
105
- }
106
- if (isBuffer(value)) {
107
- return "Buffer";
108
- }
109
- const objectType = getObjectType(value);
110
- if (objectType) {
111
- return objectType;
112
- }
113
- return "Object";
114
- }
115
- function isBuffer(value) {
116
- return value && value.constructor && value.constructor.isBuffer && value.constructor.isBuffer.call(null, value);
117
- }
118
- function getObjectType(value) {
119
- const objectTypeName = Object.prototype.toString.call(value).slice(8, -1);
120
- if (objectTypeNames.includes(objectTypeName)) {
121
- return objectTypeName;
122
- }
123
- return void 0;
124
- }
125
-
126
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/token.js
127
- var Type = class {
128
- /**
129
- * @param {number} major
130
- * @param {string} name
131
- * @param {boolean} terminal
132
- */
133
- constructor(major, name2, terminal) {
134
- this.major = major;
135
- this.majorEncoded = major << 5;
136
- this.name = name2;
137
- this.terminal = terminal;
138
- }
139
- /* c8 ignore next 3 */
140
- toString() {
141
- return `Type[${this.major}].${this.name}`;
142
- }
143
- /**
144
- * @param {Type} typ
145
- * @returns {number}
146
- */
147
- compare(typ) {
148
- return this.major < typ.major ? -1 : this.major > typ.major ? 1 : 0;
149
- }
150
- };
151
- Type.uint = new Type(0, "uint", true);
152
- Type.negint = new Type(1, "negint", true);
153
- Type.bytes = new Type(2, "bytes", true);
154
- Type.string = new Type(3, "string", true);
155
- Type.array = new Type(4, "array", false);
156
- Type.map = new Type(5, "map", false);
157
- Type.tag = new Type(6, "tag", false);
158
- Type.float = new Type(7, "float", true);
159
- Type.false = new Type(7, "false", true);
160
- Type.true = new Type(7, "true", true);
161
- Type.null = new Type(7, "null", true);
162
- Type.undefined = new Type(7, "undefined", true);
163
- Type.break = new Type(7, "break", true);
164
- var Token = class {
165
- /**
166
- * @param {Type} type
167
- * @param {any} [value]
168
- * @param {number} [encodedLength]
169
- */
170
- constructor(type, value, encodedLength) {
171
- this.type = type;
172
- this.value = value;
173
- this.encodedLength = encodedLength;
174
- this.encodedBytes = void 0;
175
- this.byteValue = void 0;
176
- }
177
- /* c8 ignore next 3 */
178
- toString() {
179
- return `Token[${this.type}].${this.value}`;
180
- }
181
- };
182
-
183
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/byte-utils.js
184
- var useBuffer = globalThis.process && // @ts-ignore
185
- !globalThis.process.browser && // @ts-ignore
186
- globalThis.Buffer && // @ts-ignore
187
- typeof globalThis.Buffer.isBuffer === "function";
188
- var textDecoder = new TextDecoder();
189
- var textEncoder = new TextEncoder();
190
- function isBuffer2(buf2) {
191
- return useBuffer && globalThis.Buffer.isBuffer(buf2);
192
- }
193
- function asU8A(buf2) {
194
- if (!(buf2 instanceof Uint8Array)) {
195
- return Uint8Array.from(buf2);
196
- }
197
- return isBuffer2(buf2) ? new Uint8Array(buf2.buffer, buf2.byteOffset, buf2.byteLength) : buf2;
198
- }
199
- var toString = useBuffer ? (
200
- // eslint-disable-line operator-linebreak
201
- /**
202
- * @param {Uint8Array} bytes
203
- * @param {number} start
204
- * @param {number} end
205
- */
206
- (bytes2, start, end) => {
207
- return end - start > 64 ? (
208
- // eslint-disable-line operator-linebreak
209
- // @ts-ignore
210
- globalThis.Buffer.from(bytes2.subarray(start, end)).toString("utf8")
211
- ) : utf8Slice(bytes2, start, end);
212
- }
213
- ) : (
214
- // eslint-disable-line operator-linebreak
215
- /**
216
- * @param {Uint8Array} bytes
217
- * @param {number} start
218
- * @param {number} end
219
- */
220
- (bytes2, start, end) => {
221
- return end - start > 64 ? textDecoder.decode(bytes2.subarray(start, end)) : utf8Slice(bytes2, start, end);
222
- }
223
- );
224
- var fromString = useBuffer ? (
225
- // eslint-disable-line operator-linebreak
226
- /**
227
- * @param {string} string
228
- */
229
- (string) => {
230
- return string.length > 64 ? (
231
- // eslint-disable-line operator-linebreak
232
- // @ts-ignore
233
- globalThis.Buffer.from(string)
234
- ) : utf8ToBytes(string);
235
- }
236
- ) : (
237
- // eslint-disable-line operator-linebreak
238
- /**
239
- * @param {string} string
240
- */
241
- (string) => {
242
- return string.length > 64 ? textEncoder.encode(string) : utf8ToBytes(string);
243
- }
244
- );
245
- var fromArray = (arr) => {
246
- return Uint8Array.from(arr);
247
- };
248
- var slice = useBuffer ? (
249
- // eslint-disable-line operator-linebreak
250
- /**
251
- * @param {Uint8Array} bytes
252
- * @param {number} start
253
- * @param {number} end
254
- */
255
- (bytes2, start, end) => {
256
- if (isBuffer2(bytes2)) {
257
- return new Uint8Array(bytes2.subarray(start, end));
258
- }
259
- return bytes2.slice(start, end);
260
- }
261
- ) : (
262
- // eslint-disable-line operator-linebreak
263
- /**
264
- * @param {Uint8Array} bytes
265
- * @param {number} start
266
- * @param {number} end
267
- */
268
- (bytes2, start, end) => {
269
- return bytes2.slice(start, end);
270
- }
271
- );
272
- var concat = useBuffer ? (
273
- // eslint-disable-line operator-linebreak
274
- /**
275
- * @param {Uint8Array[]} chunks
276
- * @param {number} length
277
- * @returns {Uint8Array}
278
- */
279
- (chunks, length2) => {
280
- chunks = chunks.map((c) => c instanceof Uint8Array ? c : (
281
- // eslint-disable-line operator-linebreak
282
- // @ts-ignore
283
- globalThis.Buffer.from(c)
284
- ));
285
- return asU8A(globalThis.Buffer.concat(chunks, length2));
286
- }
287
- ) : (
288
- // eslint-disable-line operator-linebreak
289
- /**
290
- * @param {Uint8Array[]} chunks
291
- * @param {number} length
292
- * @returns {Uint8Array}
293
- */
294
- (chunks, length2) => {
295
- const out = new Uint8Array(length2);
296
- let off = 0;
297
- for (let b of chunks) {
298
- if (off + b.length > out.length) {
299
- b = b.subarray(0, out.length - off);
300
- }
301
- out.set(b, off);
302
- off += b.length;
303
- }
304
- return out;
305
- }
306
- );
307
- var alloc = useBuffer ? (
308
- // eslint-disable-line operator-linebreak
309
- /**
310
- * @param {number} size
311
- * @returns {Uint8Array}
312
- */
313
- (size) => {
314
- return globalThis.Buffer.allocUnsafe(size);
315
- }
316
- ) : (
317
- // eslint-disable-line operator-linebreak
318
- /**
319
- * @param {number} size
320
- * @returns {Uint8Array}
321
- */
322
- (size) => {
323
- return new Uint8Array(size);
324
- }
325
- );
326
- function compare(b1, b2) {
327
- if (isBuffer2(b1) && isBuffer2(b2)) {
328
- return b1.compare(b2);
329
- }
330
- for (let i = 0; i < b1.length; i++) {
331
- if (b1[i] === b2[i]) {
332
- continue;
333
- }
334
- return b1[i] < b2[i] ? -1 : 1;
335
- }
336
- return 0;
337
- }
338
- function utf8ToBytes(str) {
339
- const out = [];
340
- let p = 0;
341
- for (let i = 0; i < str.length; i++) {
342
- let c = str.charCodeAt(i);
343
- if (c < 128) {
344
- out[p++] = c;
345
- } else if (c < 2048) {
346
- out[p++] = c >> 6 | 192;
347
- out[p++] = c & 63 | 128;
348
- } else if ((c & 64512) === 55296 && i + 1 < str.length && (str.charCodeAt(i + 1) & 64512) === 56320) {
349
- c = 65536 + ((c & 1023) << 10) + (str.charCodeAt(++i) & 1023);
350
- out[p++] = c >> 18 | 240;
351
- out[p++] = c >> 12 & 63 | 128;
352
- out[p++] = c >> 6 & 63 | 128;
353
- out[p++] = c & 63 | 128;
354
- } else {
355
- out[p++] = c >> 12 | 224;
356
- out[p++] = c >> 6 & 63 | 128;
357
- out[p++] = c & 63 | 128;
358
- }
359
- }
360
- return out;
361
- }
362
- function utf8Slice(buf2, offset, end) {
363
- const res = [];
364
- while (offset < end) {
365
- const firstByte = buf2[offset];
366
- let codePoint = null;
367
- let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
368
- if (offset + bytesPerSequence <= end) {
369
- let secondByte, thirdByte, fourthByte, tempCodePoint;
370
- switch (bytesPerSequence) {
371
- case 1:
372
- if (firstByte < 128) {
373
- codePoint = firstByte;
374
- }
375
- break;
376
- case 2:
377
- secondByte = buf2[offset + 1];
378
- if ((secondByte & 192) === 128) {
379
- tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
380
- if (tempCodePoint > 127) {
381
- codePoint = tempCodePoint;
382
- }
383
- }
384
- break;
385
- case 3:
386
- secondByte = buf2[offset + 1];
387
- thirdByte = buf2[offset + 2];
388
- if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
389
- tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
390
- if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
391
- codePoint = tempCodePoint;
392
- }
393
- }
394
- break;
395
- case 4:
396
- secondByte = buf2[offset + 1];
397
- thirdByte = buf2[offset + 2];
398
- fourthByte = buf2[offset + 3];
399
- if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
400
- tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
401
- if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
402
- codePoint = tempCodePoint;
403
- }
404
- }
405
- }
406
- }
407
- if (codePoint === null) {
408
- codePoint = 65533;
409
- bytesPerSequence = 1;
410
- } else if (codePoint > 65535) {
411
- codePoint -= 65536;
412
- res.push(codePoint >>> 10 & 1023 | 55296);
413
- codePoint = 56320 | codePoint & 1023;
414
- }
415
- res.push(codePoint);
416
- offset += bytesPerSequence;
417
- }
418
- return decodeCodePointsArray(res);
419
- }
420
- var MAX_ARGUMENTS_LENGTH = 4096;
421
- function decodeCodePointsArray(codePoints) {
422
- const len = codePoints.length;
423
- if (len <= MAX_ARGUMENTS_LENGTH) {
424
- return String.fromCharCode.apply(String, codePoints);
425
- }
426
- let res = "";
427
- let i = 0;
428
- while (i < len) {
429
- res += String.fromCharCode.apply(
430
- String,
431
- codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
432
- );
433
- }
434
- return res;
435
- }
436
-
437
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/bl.js
438
- var defaultChunkSize = 256;
439
- var Bl = class {
440
- /**
441
- * @param {number} [chunkSize]
442
- */
443
- constructor(chunkSize = defaultChunkSize) {
444
- this.chunkSize = chunkSize;
445
- this.cursor = 0;
446
- this.maxCursor = -1;
447
- this.chunks = [];
448
- this._initReuseChunk = null;
449
- }
450
- reset() {
451
- this.cursor = 0;
452
- this.maxCursor = -1;
453
- if (this.chunks.length) {
454
- this.chunks = [];
455
- }
456
- if (this._initReuseChunk !== null) {
457
- this.chunks.push(this._initReuseChunk);
458
- this.maxCursor = this._initReuseChunk.length - 1;
459
- }
460
- }
461
- /**
462
- * @param {Uint8Array|number[]} bytes
463
- */
464
- push(bytes2) {
465
- let topChunk = this.chunks[this.chunks.length - 1];
466
- const newMax = this.cursor + bytes2.length;
467
- if (newMax <= this.maxCursor + 1) {
468
- const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1;
469
- topChunk.set(bytes2, chunkPos);
470
- } else {
471
- if (topChunk) {
472
- const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1;
473
- if (chunkPos < topChunk.length) {
474
- this.chunks[this.chunks.length - 1] = topChunk.subarray(0, chunkPos);
475
- this.maxCursor = this.cursor - 1;
476
- }
477
- }
478
- if (bytes2.length < 64 && bytes2.length < this.chunkSize) {
479
- topChunk = alloc(this.chunkSize);
480
- this.chunks.push(topChunk);
481
- this.maxCursor += topChunk.length;
482
- if (this._initReuseChunk === null) {
483
- this._initReuseChunk = topChunk;
484
- }
485
- topChunk.set(bytes2, 0);
486
- } else {
487
- this.chunks.push(bytes2);
488
- this.maxCursor += bytes2.length;
489
- }
490
- }
491
- this.cursor += bytes2.length;
492
- }
493
- /**
494
- * @param {boolean} [reset]
495
- * @returns {Uint8Array}
496
- */
497
- toBytes(reset = false) {
498
- let byts;
499
- if (this.chunks.length === 1) {
500
- const chunk = this.chunks[0];
501
- if (reset && this.cursor > chunk.length / 2) {
502
- byts = this.cursor === chunk.length ? chunk : chunk.subarray(0, this.cursor);
503
- this._initReuseChunk = null;
504
- this.chunks = [];
505
- } else {
506
- byts = slice(chunk, 0, this.cursor);
507
- }
508
- } else {
509
- byts = concat(this.chunks, this.cursor);
510
- }
511
- if (reset) {
512
- this.reset();
513
- }
514
- return byts;
515
- }
516
- };
517
-
518
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/common.js
519
- var decodeErrPrefix = "CBOR decode error:";
520
- var encodeErrPrefix = "CBOR encode error:";
521
- var uintMinorPrefixBytes = [];
522
- uintMinorPrefixBytes[23] = 1;
523
- uintMinorPrefixBytes[24] = 2;
524
- uintMinorPrefixBytes[25] = 3;
525
- uintMinorPrefixBytes[26] = 5;
526
- uintMinorPrefixBytes[27] = 9;
527
- function assertEnoughData(data, pos, need) {
528
- if (data.length - pos < need) {
529
- throw new Error(`${decodeErrPrefix} not enough data for type`);
530
- }
531
- }
532
-
533
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/0uint.js
534
- var uintBoundaries = [24, 256, 65536, 4294967296, BigInt("18446744073709551616")];
535
- function readUint8(data, offset, options) {
536
- assertEnoughData(data, offset, 1);
537
- const value = data[offset];
538
- if (options.strict === true && value < uintBoundaries[0]) {
539
- throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);
540
- }
541
- return value;
542
- }
543
- function readUint16(data, offset, options) {
544
- assertEnoughData(data, offset, 2);
545
- const value = data[offset] << 8 | data[offset + 1];
546
- if (options.strict === true && value < uintBoundaries[1]) {
547
- throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);
548
- }
549
- return value;
550
- }
551
- function readUint32(data, offset, options) {
552
- assertEnoughData(data, offset, 4);
553
- const value = data[offset] * 16777216 + (data[offset + 1] << 16) + (data[offset + 2] << 8) + data[offset + 3];
554
- if (options.strict === true && value < uintBoundaries[2]) {
555
- throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);
556
- }
557
- return value;
558
- }
559
- function readUint64(data, offset, options) {
560
- assertEnoughData(data, offset, 8);
561
- const hi = data[offset] * 16777216 + (data[offset + 1] << 16) + (data[offset + 2] << 8) + data[offset + 3];
562
- const lo = data[offset + 4] * 16777216 + (data[offset + 5] << 16) + (data[offset + 6] << 8) + data[offset + 7];
563
- const value = (BigInt(hi) << BigInt(32)) + BigInt(lo);
564
- if (options.strict === true && value < uintBoundaries[3]) {
565
- throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);
566
- }
567
- if (value <= Number.MAX_SAFE_INTEGER) {
568
- return Number(value);
569
- }
570
- if (options.allowBigInt === true) {
571
- return value;
572
- }
573
- throw new Error(`${decodeErrPrefix} integers outside of the safe integer range are not supported`);
574
- }
575
- function decodeUint8(data, pos, _minor, options) {
576
- return new Token(Type.uint, readUint8(data, pos + 1, options), 2);
577
- }
578
- function decodeUint16(data, pos, _minor, options) {
579
- return new Token(Type.uint, readUint16(data, pos + 1, options), 3);
580
- }
581
- function decodeUint32(data, pos, _minor, options) {
582
- return new Token(Type.uint, readUint32(data, pos + 1, options), 5);
583
- }
584
- function decodeUint64(data, pos, _minor, options) {
585
- return new Token(Type.uint, readUint64(data, pos + 1, options), 9);
586
- }
587
- function encodeUint(buf2, token) {
588
- return encodeUintValue(buf2, 0, token.value);
589
- }
590
- function encodeUintValue(buf2, major, uint) {
591
- if (uint < uintBoundaries[0]) {
592
- const nuint = Number(uint);
593
- buf2.push([major | nuint]);
594
- } else if (uint < uintBoundaries[1]) {
595
- const nuint = Number(uint);
596
- buf2.push([major | 24, nuint]);
597
- } else if (uint < uintBoundaries[2]) {
598
- const nuint = Number(uint);
599
- buf2.push([major | 25, nuint >>> 8, nuint & 255]);
600
- } else if (uint < uintBoundaries[3]) {
601
- const nuint = Number(uint);
602
- buf2.push([major | 26, nuint >>> 24 & 255, nuint >>> 16 & 255, nuint >>> 8 & 255, nuint & 255]);
603
- } else {
604
- const buint = BigInt(uint);
605
- if (buint < uintBoundaries[4]) {
606
- const set = [major | 27, 0, 0, 0, 0, 0, 0, 0];
607
- let lo = Number(buint & BigInt(4294967295));
608
- let hi = Number(buint >> BigInt(32) & BigInt(4294967295));
609
- set[8] = lo & 255;
610
- lo = lo >> 8;
611
- set[7] = lo & 255;
612
- lo = lo >> 8;
613
- set[6] = lo & 255;
614
- lo = lo >> 8;
615
- set[5] = lo & 255;
616
- set[4] = hi & 255;
617
- hi = hi >> 8;
618
- set[3] = hi & 255;
619
- hi = hi >> 8;
620
- set[2] = hi & 255;
621
- hi = hi >> 8;
622
- set[1] = hi & 255;
623
- buf2.push(set);
624
- } else {
625
- throw new Error(`${decodeErrPrefix} encountered BigInt larger than allowable range`);
626
- }
627
- }
628
- }
629
- encodeUint.encodedSize = function encodedSize(token) {
630
- return encodeUintValue.encodedSize(token.value);
631
- };
632
- encodeUintValue.encodedSize = function encodedSize2(uint) {
633
- if (uint < uintBoundaries[0]) {
634
- return 1;
635
- }
636
- if (uint < uintBoundaries[1]) {
637
- return 2;
638
- }
639
- if (uint < uintBoundaries[2]) {
640
- return 3;
641
- }
642
- if (uint < uintBoundaries[3]) {
643
- return 5;
644
- }
645
- return 9;
646
- };
647
- encodeUint.compareTokens = function compareTokens(tok1, tok2) {
648
- return tok1.value < tok2.value ? -1 : tok1.value > tok2.value ? 1 : (
649
- /* c8 ignore next */
650
- 0
651
- );
652
- };
653
-
654
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/1negint.js
655
- function decodeNegint8(data, pos, _minor, options) {
656
- return new Token(Type.negint, -1 - readUint8(data, pos + 1, options), 2);
657
- }
658
- function decodeNegint16(data, pos, _minor, options) {
659
- return new Token(Type.negint, -1 - readUint16(data, pos + 1, options), 3);
660
- }
661
- function decodeNegint32(data, pos, _minor, options) {
662
- return new Token(Type.negint, -1 - readUint32(data, pos + 1, options), 5);
663
- }
664
- var neg1b = BigInt(-1);
665
- var pos1b = BigInt(1);
666
- function decodeNegint64(data, pos, _minor, options) {
667
- const int = readUint64(data, pos + 1, options);
668
- if (typeof int !== "bigint") {
669
- const value = -1 - int;
670
- if (value >= Number.MIN_SAFE_INTEGER) {
671
- return new Token(Type.negint, value, 9);
672
- }
673
- }
674
- if (options.allowBigInt !== true) {
675
- throw new Error(`${decodeErrPrefix} integers outside of the safe integer range are not supported`);
676
- }
677
- return new Token(Type.negint, neg1b - BigInt(int), 9);
678
- }
679
- function encodeNegint(buf2, token) {
680
- const negint = token.value;
681
- const unsigned = typeof negint === "bigint" ? negint * neg1b - pos1b : negint * -1 - 1;
682
- encodeUintValue(buf2, token.type.majorEncoded, unsigned);
683
- }
684
- encodeNegint.encodedSize = function encodedSize3(token) {
685
- const negint = token.value;
686
- const unsigned = typeof negint === "bigint" ? negint * neg1b - pos1b : negint * -1 - 1;
687
- if (unsigned < uintBoundaries[0]) {
688
- return 1;
689
- }
690
- if (unsigned < uintBoundaries[1]) {
691
- return 2;
692
- }
693
- if (unsigned < uintBoundaries[2]) {
694
- return 3;
695
- }
696
- if (unsigned < uintBoundaries[3]) {
697
- return 5;
698
- }
699
- return 9;
700
- };
701
- encodeNegint.compareTokens = function compareTokens2(tok1, tok2) {
702
- return tok1.value < tok2.value ? 1 : tok1.value > tok2.value ? -1 : (
703
- /* c8 ignore next */
704
- 0
705
- );
706
- };
707
-
708
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/2bytes.js
709
- function toToken(data, pos, prefix, length2) {
710
- assertEnoughData(data, pos, prefix + length2);
711
- const buf2 = slice(data, pos + prefix, pos + prefix + length2);
712
- return new Token(Type.bytes, buf2, prefix + length2);
713
- }
714
- function decodeBytesCompact(data, pos, minor, _options) {
715
- return toToken(data, pos, 1, minor);
716
- }
717
- function decodeBytes8(data, pos, _minor, options) {
718
- return toToken(data, pos, 2, readUint8(data, pos + 1, options));
719
- }
720
- function decodeBytes16(data, pos, _minor, options) {
721
- return toToken(data, pos, 3, readUint16(data, pos + 1, options));
722
- }
723
- function decodeBytes32(data, pos, _minor, options) {
724
- return toToken(data, pos, 5, readUint32(data, pos + 1, options));
725
- }
726
- function decodeBytes64(data, pos, _minor, options) {
727
- const l = readUint64(data, pos + 1, options);
728
- if (typeof l === "bigint") {
729
- throw new Error(`${decodeErrPrefix} 64-bit integer bytes lengths not supported`);
730
- }
731
- return toToken(data, pos, 9, l);
732
- }
733
- function tokenBytes(token) {
734
- if (token.encodedBytes === void 0) {
735
- token.encodedBytes = token.type === Type.string ? fromString(token.value) : token.value;
736
- }
737
- return token.encodedBytes;
738
- }
739
- function encodeBytes(buf2, token) {
740
- const bytes2 = tokenBytes(token);
741
- encodeUintValue(buf2, token.type.majorEncoded, bytes2.length);
742
- buf2.push(bytes2);
743
- }
744
- encodeBytes.encodedSize = function encodedSize4(token) {
745
- const bytes2 = tokenBytes(token);
746
- return encodeUintValue.encodedSize(bytes2.length) + bytes2.length;
747
- };
748
- encodeBytes.compareTokens = function compareTokens3(tok1, tok2) {
749
- return compareBytes(tokenBytes(tok1), tokenBytes(tok2));
750
- };
751
- function compareBytes(b1, b2) {
752
- return b1.length < b2.length ? -1 : b1.length > b2.length ? 1 : compare(b1, b2);
753
- }
754
-
755
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/3string.js
756
- function toToken2(data, pos, prefix, length2, options) {
757
- const totLength = prefix + length2;
758
- assertEnoughData(data, pos, totLength);
759
- const tok = new Token(Type.string, toString(data, pos + prefix, pos + totLength), totLength);
760
- if (options.retainStringBytes === true) {
761
- tok.byteValue = slice(data, pos + prefix, pos + totLength);
762
- }
763
- return tok;
764
- }
765
- function decodeStringCompact(data, pos, minor, options) {
766
- return toToken2(data, pos, 1, minor, options);
767
- }
768
- function decodeString8(data, pos, _minor, options) {
769
- return toToken2(data, pos, 2, readUint8(data, pos + 1, options), options);
770
- }
771
- function decodeString16(data, pos, _minor, options) {
772
- return toToken2(data, pos, 3, readUint16(data, pos + 1, options), options);
773
- }
774
- function decodeString32(data, pos, _minor, options) {
775
- return toToken2(data, pos, 5, readUint32(data, pos + 1, options), options);
776
- }
777
- function decodeString64(data, pos, _minor, options) {
778
- const l = readUint64(data, pos + 1, options);
779
- if (typeof l === "bigint") {
780
- throw new Error(`${decodeErrPrefix} 64-bit integer string lengths not supported`);
781
- }
782
- return toToken2(data, pos, 9, l, options);
783
- }
784
- var encodeString = encodeBytes;
785
-
786
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/4array.js
787
- function toToken3(_data, _pos, prefix, length2) {
788
- return new Token(Type.array, length2, prefix);
789
- }
790
- function decodeArrayCompact(data, pos, minor, _options) {
791
- return toToken3(data, pos, 1, minor);
792
- }
793
- function decodeArray8(data, pos, _minor, options) {
794
- return toToken3(data, pos, 2, readUint8(data, pos + 1, options));
795
- }
796
- function decodeArray16(data, pos, _minor, options) {
797
- return toToken3(data, pos, 3, readUint16(data, pos + 1, options));
798
- }
799
- function decodeArray32(data, pos, _minor, options) {
800
- return toToken3(data, pos, 5, readUint32(data, pos + 1, options));
801
- }
802
- function decodeArray64(data, pos, _minor, options) {
803
- const l = readUint64(data, pos + 1, options);
804
- if (typeof l === "bigint") {
805
- throw new Error(`${decodeErrPrefix} 64-bit integer array lengths not supported`);
806
- }
807
- return toToken3(data, pos, 9, l);
808
- }
809
- function decodeArrayIndefinite(data, pos, _minor, options) {
810
- if (options.allowIndefinite === false) {
811
- throw new Error(`${decodeErrPrefix} indefinite length items not allowed`);
812
- }
813
- return toToken3(data, pos, 1, Infinity);
814
- }
815
- function encodeArray(buf2, token) {
816
- encodeUintValue(buf2, Type.array.majorEncoded, token.value);
817
- }
818
- encodeArray.compareTokens = encodeUint.compareTokens;
819
- encodeArray.encodedSize = function encodedSize5(token) {
820
- return encodeUintValue.encodedSize(token.value);
821
- };
822
-
823
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/5map.js
824
- function toToken4(_data, _pos, prefix, length2) {
825
- return new Token(Type.map, length2, prefix);
826
- }
827
- function decodeMapCompact(data, pos, minor, _options) {
828
- return toToken4(data, pos, 1, minor);
829
- }
830
- function decodeMap8(data, pos, _minor, options) {
831
- return toToken4(data, pos, 2, readUint8(data, pos + 1, options));
832
- }
833
- function decodeMap16(data, pos, _minor, options) {
834
- return toToken4(data, pos, 3, readUint16(data, pos + 1, options));
835
- }
836
- function decodeMap32(data, pos, _minor, options) {
837
- return toToken4(data, pos, 5, readUint32(data, pos + 1, options));
838
- }
839
- function decodeMap64(data, pos, _minor, options) {
840
- const l = readUint64(data, pos + 1, options);
841
- if (typeof l === "bigint") {
842
- throw new Error(`${decodeErrPrefix} 64-bit integer map lengths not supported`);
843
- }
844
- return toToken4(data, pos, 9, l);
845
- }
846
- function decodeMapIndefinite(data, pos, _minor, options) {
847
- if (options.allowIndefinite === false) {
848
- throw new Error(`${decodeErrPrefix} indefinite length items not allowed`);
849
- }
850
- return toToken4(data, pos, 1, Infinity);
851
- }
852
- function encodeMap(buf2, token) {
853
- encodeUintValue(buf2, Type.map.majorEncoded, token.value);
854
- }
855
- encodeMap.compareTokens = encodeUint.compareTokens;
856
- encodeMap.encodedSize = function encodedSize6(token) {
857
- return encodeUintValue.encodedSize(token.value);
858
- };
859
-
860
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/6tag.js
861
- function decodeTagCompact(_data, _pos, minor, _options) {
862
- return new Token(Type.tag, minor, 1);
863
- }
864
- function decodeTag8(data, pos, _minor, options) {
865
- return new Token(Type.tag, readUint8(data, pos + 1, options), 2);
866
- }
867
- function decodeTag16(data, pos, _minor, options) {
868
- return new Token(Type.tag, readUint16(data, pos + 1, options), 3);
869
- }
870
- function decodeTag32(data, pos, _minor, options) {
871
- return new Token(Type.tag, readUint32(data, pos + 1, options), 5);
872
- }
873
- function decodeTag64(data, pos, _minor, options) {
874
- return new Token(Type.tag, readUint64(data, pos + 1, options), 9);
875
- }
876
- function encodeTag(buf2, token) {
877
- encodeUintValue(buf2, Type.tag.majorEncoded, token.value);
878
- }
879
- encodeTag.compareTokens = encodeUint.compareTokens;
880
- encodeTag.encodedSize = function encodedSize7(token) {
881
- return encodeUintValue.encodedSize(token.value);
882
- };
883
-
884
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/7float.js
885
- var MINOR_FALSE = 20;
886
- var MINOR_TRUE = 21;
887
- var MINOR_NULL = 22;
888
- var MINOR_UNDEFINED = 23;
889
- function decodeUndefined(_data, _pos, _minor, options) {
890
- if (options.allowUndefined === false) {
891
- throw new Error(`${decodeErrPrefix} undefined values are not supported`);
892
- } else if (options.coerceUndefinedToNull === true) {
893
- return new Token(Type.null, null, 1);
894
- }
895
- return new Token(Type.undefined, void 0, 1);
896
- }
897
- function decodeBreak(_data, _pos, _minor, options) {
898
- if (options.allowIndefinite === false) {
899
- throw new Error(`${decodeErrPrefix} indefinite length items not allowed`);
900
- }
901
- return new Token(Type.break, void 0, 1);
902
- }
903
- function createToken(value, bytes2, options) {
904
- if (options) {
905
- if (options.allowNaN === false && Number.isNaN(value)) {
906
- throw new Error(`${decodeErrPrefix} NaN values are not supported`);
907
- }
908
- if (options.allowInfinity === false && (value === Infinity || value === -Infinity)) {
909
- throw new Error(`${decodeErrPrefix} Infinity values are not supported`);
910
- }
911
- }
912
- return new Token(Type.float, value, bytes2);
913
- }
914
- function decodeFloat16(data, pos, _minor, options) {
915
- return createToken(readFloat16(data, pos + 1), 3, options);
916
- }
917
- function decodeFloat32(data, pos, _minor, options) {
918
- return createToken(readFloat32(data, pos + 1), 5, options);
919
- }
920
- function decodeFloat64(data, pos, _minor, options) {
921
- return createToken(readFloat64(data, pos + 1), 9, options);
922
- }
923
- function encodeFloat(buf2, token, options) {
924
- const float = token.value;
925
- if (float === false) {
926
- buf2.push([Type.float.majorEncoded | MINOR_FALSE]);
927
- } else if (float === true) {
928
- buf2.push([Type.float.majorEncoded | MINOR_TRUE]);
929
- } else if (float === null) {
930
- buf2.push([Type.float.majorEncoded | MINOR_NULL]);
931
- } else if (float === void 0) {
932
- buf2.push([Type.float.majorEncoded | MINOR_UNDEFINED]);
933
- } else {
934
- let decoded;
935
- let success = false;
936
- if (!options || options.float64 !== true) {
937
- encodeFloat16(float);
938
- decoded = readFloat16(ui8a, 1);
939
- if (float === decoded || Number.isNaN(float)) {
940
- ui8a[0] = 249;
941
- buf2.push(ui8a.slice(0, 3));
942
- success = true;
943
- } else {
944
- encodeFloat32(float);
945
- decoded = readFloat32(ui8a, 1);
946
- if (float === decoded) {
947
- ui8a[0] = 250;
948
- buf2.push(ui8a.slice(0, 5));
949
- success = true;
950
- }
951
- }
952
- }
953
- if (!success) {
954
- encodeFloat64(float);
955
- decoded = readFloat64(ui8a, 1);
956
- ui8a[0] = 251;
957
- buf2.push(ui8a.slice(0, 9));
958
- }
959
- }
960
- }
961
- encodeFloat.encodedSize = function encodedSize8(token, options) {
962
- const float = token.value;
963
- if (float === false || float === true || float === null || float === void 0) {
964
- return 1;
965
- }
966
- if (!options || options.float64 !== true) {
967
- encodeFloat16(float);
968
- let decoded = readFloat16(ui8a, 1);
969
- if (float === decoded || Number.isNaN(float)) {
970
- return 3;
971
- }
972
- encodeFloat32(float);
973
- decoded = readFloat32(ui8a, 1);
974
- if (float === decoded) {
975
- return 5;
976
- }
977
- }
978
- return 9;
979
- };
980
- var buffer = new ArrayBuffer(9);
981
- var dataView = new DataView(buffer, 1);
982
- var ui8a = new Uint8Array(buffer, 0);
983
- function encodeFloat16(inp) {
984
- if (inp === Infinity) {
985
- dataView.setUint16(0, 31744, false);
986
- } else if (inp === -Infinity) {
987
- dataView.setUint16(0, 64512, false);
988
- } else if (Number.isNaN(inp)) {
989
- dataView.setUint16(0, 32256, false);
990
- } else {
991
- dataView.setFloat32(0, inp);
992
- const valu32 = dataView.getUint32(0);
993
- const exponent = (valu32 & 2139095040) >> 23;
994
- const mantissa = valu32 & 8388607;
995
- if (exponent === 255) {
996
- dataView.setUint16(0, 31744, false);
997
- } else if (exponent === 0) {
998
- dataView.setUint16(0, (inp & 2147483648) >> 16 | mantissa >> 13, false);
999
- } else {
1000
- const logicalExponent = exponent - 127;
1001
- if (logicalExponent < -24) {
1002
- dataView.setUint16(0, 0);
1003
- } else if (logicalExponent < -14) {
1004
- dataView.setUint16(0, (valu32 & 2147483648) >> 16 | /* sign bit */
1005
- 1 << 24 + logicalExponent, false);
1006
- } else {
1007
- dataView.setUint16(0, (valu32 & 2147483648) >> 16 | logicalExponent + 15 << 10 | mantissa >> 13, false);
1008
- }
1009
- }
1010
- }
1011
- }
1012
- function readFloat16(ui8a2, pos) {
1013
- if (ui8a2.length - pos < 2) {
1014
- throw new Error(`${decodeErrPrefix} not enough data for float16`);
1015
- }
1016
- const half = (ui8a2[pos] << 8) + ui8a2[pos + 1];
1017
- if (half === 31744) {
1018
- return Infinity;
1019
- }
1020
- if (half === 64512) {
1021
- return -Infinity;
1022
- }
1023
- if (half === 32256) {
1024
- return NaN;
1025
- }
1026
- const exp = half >> 10 & 31;
1027
- const mant = half & 1023;
1028
- let val;
1029
- if (exp === 0) {
1030
- val = mant * 2 ** -24;
1031
- } else if (exp !== 31) {
1032
- val = (mant + 1024) * 2 ** (exp - 25);
1033
- } else {
1034
- val = mant === 0 ? Infinity : NaN;
1035
- }
1036
- return half & 32768 ? -val : val;
1037
- }
1038
- function encodeFloat32(inp) {
1039
- dataView.setFloat32(0, inp, false);
1040
- }
1041
- function readFloat32(ui8a2, pos) {
1042
- if (ui8a2.length - pos < 4) {
1043
- throw new Error(`${decodeErrPrefix} not enough data for float32`);
1044
- }
1045
- const offset = (ui8a2.byteOffset || 0) + pos;
1046
- return new DataView(ui8a2.buffer, offset, 4).getFloat32(0, false);
1047
- }
1048
- function encodeFloat64(inp) {
1049
- dataView.setFloat64(0, inp, false);
1050
- }
1051
- function readFloat64(ui8a2, pos) {
1052
- if (ui8a2.length - pos < 8) {
1053
- throw new Error(`${decodeErrPrefix} not enough data for float64`);
1054
- }
1055
- const offset = (ui8a2.byteOffset || 0) + pos;
1056
- return new DataView(ui8a2.buffer, offset, 8).getFloat64(0, false);
1057
- }
1058
- encodeFloat.compareTokens = encodeUint.compareTokens;
1059
-
1060
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/jump.js
1061
- function invalidMinor(data, pos, minor) {
1062
- throw new Error(`${decodeErrPrefix} encountered invalid minor (${minor}) for major ${data[pos] >>> 5}`);
1063
- }
1064
- function errorer(msg) {
1065
- return () => {
1066
- throw new Error(`${decodeErrPrefix} ${msg}`);
1067
- };
1068
- }
1069
- var jump = [];
1070
- for (let i = 0; i <= 23; i++) {
1071
- jump[i] = invalidMinor;
1072
- }
1073
- jump[24] = decodeUint8;
1074
- jump[25] = decodeUint16;
1075
- jump[26] = decodeUint32;
1076
- jump[27] = decodeUint64;
1077
- jump[28] = invalidMinor;
1078
- jump[29] = invalidMinor;
1079
- jump[30] = invalidMinor;
1080
- jump[31] = invalidMinor;
1081
- for (let i = 32; i <= 55; i++) {
1082
- jump[i] = invalidMinor;
1083
- }
1084
- jump[56] = decodeNegint8;
1085
- jump[57] = decodeNegint16;
1086
- jump[58] = decodeNegint32;
1087
- jump[59] = decodeNegint64;
1088
- jump[60] = invalidMinor;
1089
- jump[61] = invalidMinor;
1090
- jump[62] = invalidMinor;
1091
- jump[63] = invalidMinor;
1092
- for (let i = 64; i <= 87; i++) {
1093
- jump[i] = decodeBytesCompact;
1094
- }
1095
- jump[88] = decodeBytes8;
1096
- jump[89] = decodeBytes16;
1097
- jump[90] = decodeBytes32;
1098
- jump[91] = decodeBytes64;
1099
- jump[92] = invalidMinor;
1100
- jump[93] = invalidMinor;
1101
- jump[94] = invalidMinor;
1102
- jump[95] = errorer("indefinite length bytes/strings are not supported");
1103
- for (let i = 96; i <= 119; i++) {
1104
- jump[i] = decodeStringCompact;
1105
- }
1106
- jump[120] = decodeString8;
1107
- jump[121] = decodeString16;
1108
- jump[122] = decodeString32;
1109
- jump[123] = decodeString64;
1110
- jump[124] = invalidMinor;
1111
- jump[125] = invalidMinor;
1112
- jump[126] = invalidMinor;
1113
- jump[127] = errorer("indefinite length bytes/strings are not supported");
1114
- for (let i = 128; i <= 151; i++) {
1115
- jump[i] = decodeArrayCompact;
1116
- }
1117
- jump[152] = decodeArray8;
1118
- jump[153] = decodeArray16;
1119
- jump[154] = decodeArray32;
1120
- jump[155] = decodeArray64;
1121
- jump[156] = invalidMinor;
1122
- jump[157] = invalidMinor;
1123
- jump[158] = invalidMinor;
1124
- jump[159] = decodeArrayIndefinite;
1125
- for (let i = 160; i <= 183; i++) {
1126
- jump[i] = decodeMapCompact;
1127
- }
1128
- jump[184] = decodeMap8;
1129
- jump[185] = decodeMap16;
1130
- jump[186] = decodeMap32;
1131
- jump[187] = decodeMap64;
1132
- jump[188] = invalidMinor;
1133
- jump[189] = invalidMinor;
1134
- jump[190] = invalidMinor;
1135
- jump[191] = decodeMapIndefinite;
1136
- for (let i = 192; i <= 215; i++) {
1137
- jump[i] = decodeTagCompact;
1138
- }
1139
- jump[216] = decodeTag8;
1140
- jump[217] = decodeTag16;
1141
- jump[218] = decodeTag32;
1142
- jump[219] = decodeTag64;
1143
- jump[220] = invalidMinor;
1144
- jump[221] = invalidMinor;
1145
- jump[222] = invalidMinor;
1146
- jump[223] = invalidMinor;
1147
- for (let i = 224; i <= 243; i++) {
1148
- jump[i] = errorer("simple values are not supported");
1149
- }
1150
- jump[244] = invalidMinor;
1151
- jump[245] = invalidMinor;
1152
- jump[246] = invalidMinor;
1153
- jump[247] = decodeUndefined;
1154
- jump[248] = errorer("simple values are not supported");
1155
- jump[249] = decodeFloat16;
1156
- jump[250] = decodeFloat32;
1157
- jump[251] = decodeFloat64;
1158
- jump[252] = invalidMinor;
1159
- jump[253] = invalidMinor;
1160
- jump[254] = invalidMinor;
1161
- jump[255] = decodeBreak;
1162
- var quick = [];
1163
- for (let i = 0; i < 24; i++) {
1164
- quick[i] = new Token(Type.uint, i, 1);
1165
- }
1166
- for (let i = -1; i >= -24; i--) {
1167
- quick[31 - i] = new Token(Type.negint, i, 1);
1168
- }
1169
- quick[64] = new Token(Type.bytes, new Uint8Array(0), 1);
1170
- quick[96] = new Token(Type.string, "", 1);
1171
- quick[128] = new Token(Type.array, 0, 1);
1172
- quick[160] = new Token(Type.map, 0, 1);
1173
- quick[244] = new Token(Type.false, false, 1);
1174
- quick[245] = new Token(Type.true, true, 1);
1175
- quick[246] = new Token(Type.null, null, 1);
1176
- function quickEncodeToken(token) {
1177
- switch (token.type) {
1178
- case Type.false:
1179
- return fromArray([244]);
1180
- case Type.true:
1181
- return fromArray([245]);
1182
- case Type.null:
1183
- return fromArray([246]);
1184
- case Type.bytes:
1185
- if (!token.value.length) {
1186
- return fromArray([64]);
1187
- }
1188
- return;
1189
- case Type.string:
1190
- if (token.value === "") {
1191
- return fromArray([96]);
1192
- }
1193
- return;
1194
- case Type.array:
1195
- if (token.value === 0) {
1196
- return fromArray([128]);
1197
- }
1198
- return;
1199
- case Type.map:
1200
- if (token.value === 0) {
1201
- return fromArray([160]);
1202
- }
1203
- return;
1204
- case Type.uint:
1205
- if (token.value < 24) {
1206
- return fromArray([Number(token.value)]);
1207
- }
1208
- return;
1209
- case Type.negint:
1210
- if (token.value >= -24) {
1211
- return fromArray([31 - Number(token.value)]);
1212
- }
1213
- }
1214
- }
1215
-
1216
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/encode.js
1217
- var defaultEncodeOptions = {
1218
- float64: false,
1219
- mapSorter,
1220
- quickEncodeToken
1221
- };
1222
- function makeCborEncoders() {
1223
- const encoders = [];
1224
- encoders[Type.uint.major] = encodeUint;
1225
- encoders[Type.negint.major] = encodeNegint;
1226
- encoders[Type.bytes.major] = encodeBytes;
1227
- encoders[Type.string.major] = encodeString;
1228
- encoders[Type.array.major] = encodeArray;
1229
- encoders[Type.map.major] = encodeMap;
1230
- encoders[Type.tag.major] = encodeTag;
1231
- encoders[Type.float.major] = encodeFloat;
1232
- return encoders;
1233
- }
1234
- var cborEncoders = makeCborEncoders();
1235
- var buf = new Bl();
1236
- var Ref = class _Ref {
1237
- /**
1238
- * @param {object|any[]} obj
1239
- * @param {Reference|undefined} parent
1240
- */
1241
- constructor(obj, parent) {
1242
- this.obj = obj;
1243
- this.parent = parent;
1244
- }
1245
- /**
1246
- * @param {object|any[]} obj
1247
- * @returns {boolean}
1248
- */
1249
- includes(obj) {
1250
- let p = this;
1251
- do {
1252
- if (p.obj === obj) {
1253
- return true;
1254
- }
1255
- } while (p = p.parent);
1256
- return false;
1257
- }
1258
- /**
1259
- * @param {Reference|undefined} stack
1260
- * @param {object|any[]} obj
1261
- * @returns {Reference}
1262
- */
1263
- static createCheck(stack, obj) {
1264
- if (stack && stack.includes(obj)) {
1265
- throw new Error(`${encodeErrPrefix} object contains circular references`);
1266
- }
1267
- return new _Ref(obj, stack);
1268
- }
1269
- };
1270
- var simpleTokens = {
1271
- null: new Token(Type.null, null),
1272
- undefined: new Token(Type.undefined, void 0),
1273
- true: new Token(Type.true, true),
1274
- false: new Token(Type.false, false),
1275
- emptyArray: new Token(Type.array, 0),
1276
- emptyMap: new Token(Type.map, 0)
1277
- };
1278
- var typeEncoders = {
1279
- /**
1280
- * @param {any} obj
1281
- * @param {string} _typ
1282
- * @param {EncodeOptions} _options
1283
- * @param {Reference} [_refStack]
1284
- * @returns {TokenOrNestedTokens}
1285
- */
1286
- number(obj, _typ, _options, _refStack) {
1287
- if (!Number.isInteger(obj) || !Number.isSafeInteger(obj)) {
1288
- return new Token(Type.float, obj);
1289
- } else if (obj >= 0) {
1290
- return new Token(Type.uint, obj);
1291
- } else {
1292
- return new Token(Type.negint, obj);
1293
- }
1294
- },
1295
- /**
1296
- * @param {any} obj
1297
- * @param {string} _typ
1298
- * @param {EncodeOptions} _options
1299
- * @param {Reference} [_refStack]
1300
- * @returns {TokenOrNestedTokens}
1301
- */
1302
- bigint(obj, _typ, _options, _refStack) {
1303
- if (obj >= BigInt(0)) {
1304
- return new Token(Type.uint, obj);
1305
- } else {
1306
- return new Token(Type.negint, obj);
1307
- }
1308
- },
1309
- /**
1310
- * @param {any} obj
1311
- * @param {string} _typ
1312
- * @param {EncodeOptions} _options
1313
- * @param {Reference} [_refStack]
1314
- * @returns {TokenOrNestedTokens}
1315
- */
1316
- Uint8Array(obj, _typ, _options, _refStack) {
1317
- return new Token(Type.bytes, obj);
1318
- },
1319
- /**
1320
- * @param {any} obj
1321
- * @param {string} _typ
1322
- * @param {EncodeOptions} _options
1323
- * @param {Reference} [_refStack]
1324
- * @returns {TokenOrNestedTokens}
1325
- */
1326
- string(obj, _typ, _options, _refStack) {
1327
- return new Token(Type.string, obj);
1328
- },
1329
- /**
1330
- * @param {any} obj
1331
- * @param {string} _typ
1332
- * @param {EncodeOptions} _options
1333
- * @param {Reference} [_refStack]
1334
- * @returns {TokenOrNestedTokens}
1335
- */
1336
- boolean(obj, _typ, _options, _refStack) {
1337
- return obj ? simpleTokens.true : simpleTokens.false;
1338
- },
1339
- /**
1340
- * @param {any} _obj
1341
- * @param {string} _typ
1342
- * @param {EncodeOptions} _options
1343
- * @param {Reference} [_refStack]
1344
- * @returns {TokenOrNestedTokens}
1345
- */
1346
- null(_obj, _typ, _options, _refStack) {
1347
- return simpleTokens.null;
1348
- },
1349
- /**
1350
- * @param {any} _obj
1351
- * @param {string} _typ
1352
- * @param {EncodeOptions} _options
1353
- * @param {Reference} [_refStack]
1354
- * @returns {TokenOrNestedTokens}
1355
- */
1356
- undefined(_obj, _typ, _options, _refStack) {
1357
- return simpleTokens.undefined;
1358
- },
1359
- /**
1360
- * @param {any} obj
1361
- * @param {string} _typ
1362
- * @param {EncodeOptions} _options
1363
- * @param {Reference} [_refStack]
1364
- * @returns {TokenOrNestedTokens}
1365
- */
1366
- ArrayBuffer(obj, _typ, _options, _refStack) {
1367
- return new Token(Type.bytes, new Uint8Array(obj));
1368
- },
1369
- /**
1370
- * @param {any} obj
1371
- * @param {string} _typ
1372
- * @param {EncodeOptions} _options
1373
- * @param {Reference} [_refStack]
1374
- * @returns {TokenOrNestedTokens}
1375
- */
1376
- DataView(obj, _typ, _options, _refStack) {
1377
- return new Token(Type.bytes, new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength));
1378
- },
1379
- /**
1380
- * @param {any} obj
1381
- * @param {string} _typ
1382
- * @param {EncodeOptions} options
1383
- * @param {Reference} [refStack]
1384
- * @returns {TokenOrNestedTokens}
1385
- */
1386
- Array(obj, _typ, options, refStack) {
1387
- if (!obj.length) {
1388
- if (options.addBreakTokens === true) {
1389
- return [simpleTokens.emptyArray, new Token(Type.break)];
1390
- }
1391
- return simpleTokens.emptyArray;
1392
- }
1393
- refStack = Ref.createCheck(refStack, obj);
1394
- const entries = [];
1395
- let i = 0;
1396
- for (const e of obj) {
1397
- entries[i++] = objectToTokens(e, options, refStack);
1398
- }
1399
- if (options.addBreakTokens) {
1400
- return [new Token(Type.array, obj.length), entries, new Token(Type.break)];
1401
- }
1402
- return [new Token(Type.array, obj.length), entries];
1403
- },
1404
- /**
1405
- * @param {any} obj
1406
- * @param {string} typ
1407
- * @param {EncodeOptions} options
1408
- * @param {Reference} [refStack]
1409
- * @returns {TokenOrNestedTokens}
1410
- */
1411
- Object(obj, typ, options, refStack) {
1412
- const isMap = typ !== "Object";
1413
- const keys = isMap ? obj.keys() : Object.keys(obj);
1414
- const length2 = isMap ? obj.size : keys.length;
1415
- if (!length2) {
1416
- if (options.addBreakTokens === true) {
1417
- return [simpleTokens.emptyMap, new Token(Type.break)];
1418
- }
1419
- return simpleTokens.emptyMap;
1420
- }
1421
- refStack = Ref.createCheck(refStack, obj);
1422
- const entries = [];
1423
- let i = 0;
1424
- for (const key of keys) {
1425
- entries[i++] = [
1426
- objectToTokens(key, options, refStack),
1427
- objectToTokens(isMap ? obj.get(key) : obj[key], options, refStack)
1428
- ];
1429
- }
1430
- sortMapEntries(entries, options);
1431
- if (options.addBreakTokens) {
1432
- return [new Token(Type.map, length2), entries, new Token(Type.break)];
1433
- }
1434
- return [new Token(Type.map, length2), entries];
1435
- }
1436
- };
1437
- typeEncoders.Map = typeEncoders.Object;
1438
- typeEncoders.Buffer = typeEncoders.Uint8Array;
1439
- for (const typ of "Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" ")) {
1440
- typeEncoders[`${typ}Array`] = typeEncoders.DataView;
1441
- }
1442
- function objectToTokens(obj, options = {}, refStack) {
1443
- const typ = is(obj);
1444
- const customTypeEncoder = options && options.typeEncoders && /** @type {OptionalTypeEncoder} */
1445
- options.typeEncoders[typ] || typeEncoders[typ];
1446
- if (typeof customTypeEncoder === "function") {
1447
- const tokens = customTypeEncoder(obj, typ, options, refStack);
1448
- if (tokens != null) {
1449
- return tokens;
1450
- }
1451
- }
1452
- const typeEncoder = typeEncoders[typ];
1453
- if (!typeEncoder) {
1454
- throw new Error(`${encodeErrPrefix} unsupported type: ${typ}`);
1455
- }
1456
- return typeEncoder(obj, typ, options, refStack);
1457
- }
1458
- function sortMapEntries(entries, options) {
1459
- if (options.mapSorter) {
1460
- entries.sort(options.mapSorter);
1461
- }
1462
- }
1463
- function mapSorter(e1, e2) {
1464
- const keyToken1 = Array.isArray(e1[0]) ? e1[0][0] : e1[0];
1465
- const keyToken2 = Array.isArray(e2[0]) ? e2[0][0] : e2[0];
1466
- if (keyToken1.type !== keyToken2.type) {
1467
- return keyToken1.type.compare(keyToken2.type);
1468
- }
1469
- const major = keyToken1.type.major;
1470
- const tcmp = cborEncoders[major].compareTokens(keyToken1, keyToken2);
1471
- if (tcmp === 0) {
1472
- console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone");
1473
- }
1474
- return tcmp;
1475
- }
1476
- function tokensToEncoded(buf2, tokens, encoders, options) {
1477
- if (Array.isArray(tokens)) {
1478
- for (const token of tokens) {
1479
- tokensToEncoded(buf2, token, encoders, options);
1480
- }
1481
- } else {
1482
- encoders[tokens.type.major](buf2, tokens, options);
1483
- }
1484
- }
1485
- function encodeCustom(data, encoders, options) {
1486
- const tokens = objectToTokens(data, options);
1487
- if (!Array.isArray(tokens) && options.quickEncodeToken) {
1488
- const quickBytes = options.quickEncodeToken(tokens);
1489
- if (quickBytes) {
1490
- return quickBytes;
1491
- }
1492
- const encoder = encoders[tokens.type.major];
1493
- if (encoder.encodedSize) {
1494
- const size = encoder.encodedSize(tokens, options);
1495
- const buf2 = new Bl(size);
1496
- encoder(buf2, tokens, options);
1497
- if (buf2.chunks.length !== 1) {
1498
- throw new Error(`Unexpected error: pre-calculated length for ${tokens} was wrong`);
1499
- }
1500
- return asU8A(buf2.chunks[0]);
1501
- }
1502
- }
1503
- buf.reset();
1504
- tokensToEncoded(buf, tokens, encoders, options);
1505
- return buf.toBytes(true);
1506
- }
1507
- function encode(data, options) {
1508
- options = Object.assign({}, defaultEncodeOptions, options);
1509
- return encodeCustom(data, cborEncoders, options);
1510
- }
1511
-
1512
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/decode.js
1513
- var defaultDecodeOptions = {
1514
- strict: false,
1515
- allowIndefinite: true,
1516
- allowUndefined: true,
1517
- allowBigInt: true
1518
- };
1519
- var Tokeniser = class {
1520
- /**
1521
- * @param {Uint8Array} data
1522
- * @param {DecodeOptions} options
1523
- */
1524
- constructor(data, options = {}) {
1525
- this._pos = 0;
1526
- this.data = data;
1527
- this.options = options;
1528
- }
1529
- pos() {
1530
- return this._pos;
1531
- }
1532
- done() {
1533
- return this._pos >= this.data.length;
1534
- }
1535
- next() {
1536
- const byt = this.data[this._pos];
1537
- let token = quick[byt];
1538
- if (token === void 0) {
1539
- const decoder = jump[byt];
1540
- if (!decoder) {
1541
- throw new Error(`${decodeErrPrefix} no decoder for major type ${byt >>> 5} (byte 0x${byt.toString(16).padStart(2, "0")})`);
1542
- }
1543
- const minor = byt & 31;
1544
- token = decoder(this.data, this._pos, minor, this.options);
1545
- }
1546
- this._pos += token.encodedLength;
1547
- return token;
1548
- }
1549
- };
1550
- var DONE = Symbol.for("DONE");
1551
- var BREAK = Symbol.for("BREAK");
1552
- function tokenToArray(token, tokeniser, options) {
1553
- const arr = [];
1554
- for (let i = 0; i < token.value; i++) {
1555
- const value = tokensToObject(tokeniser, options);
1556
- if (value === BREAK) {
1557
- if (token.value === Infinity) {
1558
- break;
1559
- }
1560
- throw new Error(`${decodeErrPrefix} got unexpected break to lengthed array`);
1561
- }
1562
- if (value === DONE) {
1563
- throw new Error(`${decodeErrPrefix} found array but not enough entries (got ${i}, expected ${token.value})`);
1564
- }
1565
- arr[i] = value;
1566
- }
1567
- return arr;
1568
- }
1569
- function tokenToMap(token, tokeniser, options) {
1570
- const useMaps = options.useMaps === true;
1571
- const obj = useMaps ? void 0 : {};
1572
- const m = useMaps ? /* @__PURE__ */ new Map() : void 0;
1573
- for (let i = 0; i < token.value; i++) {
1574
- const key = tokensToObject(tokeniser, options);
1575
- if (key === BREAK) {
1576
- if (token.value === Infinity) {
1577
- break;
1578
- }
1579
- throw new Error(`${decodeErrPrefix} got unexpected break to lengthed map`);
1580
- }
1581
- if (key === DONE) {
1582
- throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no key], expected ${token.value})`);
1583
- }
1584
- if (useMaps !== true && typeof key !== "string") {
1585
- throw new Error(`${decodeErrPrefix} non-string keys not supported (got ${typeof key})`);
1586
- }
1587
- if (options.rejectDuplicateMapKeys === true) {
1588
- if (useMaps && m.has(key) || !useMaps && key in obj) {
1589
- throw new Error(`${decodeErrPrefix} found repeat map key "${key}"`);
1590
- }
1591
- }
1592
- const value = tokensToObject(tokeniser, options);
1593
- if (value === DONE) {
1594
- throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no value], expected ${token.value})`);
1595
- }
1596
- if (useMaps) {
1597
- m.set(key, value);
1598
- } else {
1599
- obj[key] = value;
1600
- }
1601
- }
1602
- return useMaps ? m : obj;
1603
- }
1604
- function tokensToObject(tokeniser, options) {
1605
- if (tokeniser.done()) {
1606
- return DONE;
1607
- }
1608
- const token = tokeniser.next();
1609
- if (token.type === Type.break) {
1610
- return BREAK;
1611
- }
1612
- if (token.type.terminal) {
1613
- return token.value;
1614
- }
1615
- if (token.type === Type.array) {
1616
- return tokenToArray(token, tokeniser, options);
1617
- }
1618
- if (token.type === Type.map) {
1619
- return tokenToMap(token, tokeniser, options);
1620
- }
1621
- if (token.type === Type.tag) {
1622
- if (options.tags && typeof options.tags[token.value] === "function") {
1623
- const tagged = tokensToObject(tokeniser, options);
1624
- return options.tags[token.value](tagged);
1625
- }
1626
- throw new Error(`${decodeErrPrefix} tag not supported (${token.value})`);
1627
- }
1628
- throw new Error("unsupported");
1629
- }
1630
- function decodeFirst(data, options) {
1631
- if (!(data instanceof Uint8Array)) {
1632
- throw new Error(`${decodeErrPrefix} data to decode must be a Uint8Array`);
1633
- }
1634
- options = Object.assign({}, defaultDecodeOptions, options);
1635
- const tokeniser = options.tokenizer || new Tokeniser(data, options);
1636
- const decoded = tokensToObject(tokeniser, options);
1637
- if (decoded === DONE) {
1638
- throw new Error(`${decodeErrPrefix} did not find any content to decode`);
1639
- }
1640
- if (decoded === BREAK) {
1641
- throw new Error(`${decodeErrPrefix} got unexpected break`);
1642
- }
1643
- return [decoded, data.subarray(tokeniser.pos())];
1644
- }
1645
- function decode(data, options) {
1646
- const [decoded, remainder] = decodeFirst(data, options);
1647
- if (remainder.length > 0) {
1648
- throw new Error(`${decodeErrPrefix} too many terminals, data makes no sense`);
1649
- }
1650
- return decoded;
1651
- }
1652
-
1653
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/json/encode.js
1654
- var JSONEncoder = class extends Array {
1655
- constructor() {
1656
- super();
1657
- this.inRecursive = [];
1658
- }
1659
- /**
1660
- * @param {Bl} buf
1661
- */
1662
- prefix(buf2) {
1663
- const recurs = this.inRecursive[this.inRecursive.length - 1];
1664
- if (recurs) {
1665
- if (recurs.type === Type.array) {
1666
- recurs.elements++;
1667
- if (recurs.elements !== 1) {
1668
- buf2.push([44]);
1669
- }
1670
- }
1671
- if (recurs.type === Type.map) {
1672
- recurs.elements++;
1673
- if (recurs.elements !== 1) {
1674
- if (recurs.elements % 2 === 1) {
1675
- buf2.push([44]);
1676
- } else {
1677
- buf2.push([58]);
1678
- }
1679
- }
1680
- }
1681
- }
1682
- }
1683
- /**
1684
- * @param {Bl} buf
1685
- * @param {Token} token
1686
- */
1687
- [Type.uint.major](buf2, token) {
1688
- this.prefix(buf2);
1689
- const is2 = String(token.value);
1690
- const isa = [];
1691
- for (let i = 0; i < is2.length; i++) {
1692
- isa[i] = is2.charCodeAt(i);
1693
- }
1694
- buf2.push(isa);
1695
- }
1696
- /**
1697
- * @param {Bl} buf
1698
- * @param {Token} token
1699
- */
1700
- [Type.negint.major](buf2, token) {
1701
- this[Type.uint.major](buf2, token);
1702
- }
1703
- /**
1704
- * @param {Bl} _buf
1705
- * @param {Token} _token
1706
- */
1707
- [Type.bytes.major](_buf, _token) {
1708
- throw new Error(`${encodeErrPrefix} unsupported type: Uint8Array`);
1709
- }
1710
- /**
1711
- * @param {Bl} buf
1712
- * @param {Token} token
1713
- */
1714
- [Type.string.major](buf2, token) {
1715
- this.prefix(buf2);
1716
- const byts = fromString(JSON.stringify(token.value));
1717
- buf2.push(byts.length > 32 ? asU8A(byts) : byts);
1718
- }
1719
- /**
1720
- * @param {Bl} buf
1721
- * @param {Token} _token
1722
- */
1723
- [Type.array.major](buf2, _token) {
1724
- this.prefix(buf2);
1725
- this.inRecursive.push({ type: Type.array, elements: 0 });
1726
- buf2.push([91]);
1727
- }
1728
- /**
1729
- * @param {Bl} buf
1730
- * @param {Token} _token
1731
- */
1732
- [Type.map.major](buf2, _token) {
1733
- this.prefix(buf2);
1734
- this.inRecursive.push({ type: Type.map, elements: 0 });
1735
- buf2.push([123]);
1736
- }
1737
- /**
1738
- * @param {Bl} _buf
1739
- * @param {Token} _token
1740
- */
1741
- [Type.tag.major](_buf, _token) {
1742
- }
1743
- /**
1744
- * @param {Bl} buf
1745
- * @param {Token} token
1746
- */
1747
- [Type.float.major](buf2, token) {
1748
- if (token.type.name === "break") {
1749
- const recurs = this.inRecursive.pop();
1750
- if (recurs) {
1751
- if (recurs.type === Type.array) {
1752
- buf2.push([93]);
1753
- } else if (recurs.type === Type.map) {
1754
- buf2.push([125]);
1755
- } else {
1756
- throw new Error("Unexpected recursive type; this should not happen!");
1757
- }
1758
- return;
1759
- }
1760
- throw new Error("Unexpected break; this should not happen!");
1761
- }
1762
- if (token.value === void 0) {
1763
- throw new Error(`${encodeErrPrefix} unsupported type: undefined`);
1764
- }
1765
- this.prefix(buf2);
1766
- if (token.type.name === "true") {
1767
- buf2.push([116, 114, 117, 101]);
1768
- return;
1769
- } else if (token.type.name === "false") {
1770
- buf2.push([102, 97, 108, 115, 101]);
1771
- return;
1772
- } else if (token.type.name === "null") {
1773
- buf2.push([110, 117, 108, 108]);
1774
- return;
1775
- }
1776
- const is2 = String(token.value);
1777
- const isa = [];
1778
- let dp = false;
1779
- for (let i = 0; i < is2.length; i++) {
1780
- isa[i] = is2.charCodeAt(i);
1781
- if (!dp && (isa[i] === 46 || isa[i] === 101 || isa[i] === 69)) {
1782
- dp = true;
1783
- }
1784
- }
1785
- if (!dp) {
1786
- isa.push(46);
1787
- isa.push(48);
1788
- }
1789
- buf2.push(isa);
1790
- }
1791
- };
1792
- function mapSorter2(e1, e2) {
1793
- if (Array.isArray(e1[0]) || Array.isArray(e2[0])) {
1794
- throw new Error(`${encodeErrPrefix} complex map keys are not supported`);
1795
- }
1796
- const keyToken1 = e1[0];
1797
- const keyToken2 = e2[0];
1798
- if (keyToken1.type !== Type.string || keyToken2.type !== Type.string) {
1799
- throw new Error(`${encodeErrPrefix} non-string map keys are not supported`);
1800
- }
1801
- if (keyToken1 < keyToken2) {
1802
- return -1;
1803
- }
1804
- if (keyToken1 > keyToken2) {
1805
- return 1;
1806
- }
1807
- throw new Error(`${encodeErrPrefix} unexpected duplicate map keys, this is not supported`);
1808
- }
1809
- var defaultEncodeOptions2 = { addBreakTokens: true, mapSorter: mapSorter2 };
1810
- function encode2(data, options) {
1811
- options = Object.assign({}, defaultEncodeOptions2, options);
1812
- return encodeCustom(data, new JSONEncoder(), options);
1813
- }
1814
-
1815
- // ../../../node_modules/.pnpm/cborg@4.0.3/node_modules/cborg/lib/json/decode.js
1816
- var Tokenizer = class {
1817
- /**
1818
- * @param {Uint8Array} data
1819
- * @param {DecodeOptions} options
1820
- */
1821
- constructor(data, options = {}) {
1822
- this._pos = 0;
1823
- this.data = data;
1824
- this.options = options;
1825
- this.modeStack = ["value"];
1826
- this.lastToken = "";
1827
- }
1828
- pos() {
1829
- return this._pos;
1830
- }
1831
- /**
1832
- * @returns {boolean}
1833
- */
1834
- done() {
1835
- return this._pos >= this.data.length;
1836
- }
1837
- /**
1838
- * @returns {number}
1839
- */
1840
- ch() {
1841
- return this.data[this._pos];
1842
- }
1843
- /**
1844
- * @returns {string}
1845
- */
1846
- currentMode() {
1847
- return this.modeStack[this.modeStack.length - 1];
1848
- }
1849
- skipWhitespace() {
1850
- let c = this.ch();
1851
- while (c === 32 || c === 9 || c === 13 || c === 10) {
1852
- c = this.data[++this._pos];
1853
- }
1854
- }
1855
- /**
1856
- * @param {number[]} str
1857
- */
1858
- expect(str) {
1859
- if (this.data.length - this._pos < str.length) {
1860
- throw new Error(`${decodeErrPrefix} unexpected end of input at position ${this._pos}`);
1861
- }
1862
- for (let i = 0; i < str.length; i++) {
1863
- if (this.data[this._pos++] !== str[i]) {
1864
- throw new Error(`${decodeErrPrefix} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...str)}'`);
1865
- }
1866
- }
1867
- }
1868
- parseNumber() {
1869
- const startPos = this._pos;
1870
- let negative = false;
1871
- let float = false;
1872
- const swallow = (chars) => {
1873
- while (!this.done()) {
1874
- const ch = this.ch();
1875
- if (chars.includes(ch)) {
1876
- this._pos++;
1877
- } else {
1878
- break;
1879
- }
1880
- }
1881
- };
1882
- if (this.ch() === 45) {
1883
- negative = true;
1884
- this._pos++;
1885
- }
1886
- if (this.ch() === 48) {
1887
- this._pos++;
1888
- if (this.ch() === 46) {
1889
- this._pos++;
1890
- float = true;
1891
- } else {
1892
- return new Token(Type.uint, 0, this._pos - startPos);
1893
- }
1894
- }
1895
- swallow([48, 49, 50, 51, 52, 53, 54, 55, 56, 57]);
1896
- if (negative && this._pos === startPos + 1) {
1897
- throw new Error(`${decodeErrPrefix} unexpected token at position ${this._pos}`);
1898
- }
1899
- if (!this.done() && this.ch() === 46) {
1900
- if (float) {
1901
- throw new Error(`${decodeErrPrefix} unexpected token at position ${this._pos}`);
1902
- }
1903
- float = true;
1904
- this._pos++;
1905
- swallow([48, 49, 50, 51, 52, 53, 54, 55, 56, 57]);
1906
- }
1907
- if (!this.done() && (this.ch() === 101 || this.ch() === 69)) {
1908
- float = true;
1909
- this._pos++;
1910
- if (!this.done() && (this.ch() === 43 || this.ch() === 45)) {
1911
- this._pos++;
1912
- }
1913
- swallow([48, 49, 50, 51, 52, 53, 54, 55, 56, 57]);
1914
- }
1915
- const numStr = String.fromCharCode.apply(null, this.data.subarray(startPos, this._pos));
1916
- const num = parseFloat(numStr);
1917
- if (float) {
1918
- return new Token(Type.float, num, this._pos - startPos);
1919
- }
1920
- if (this.options.allowBigInt !== true || Number.isSafeInteger(num)) {
1921
- return new Token(num >= 0 ? Type.uint : Type.negint, num, this._pos - startPos);
1922
- }
1923
- return new Token(num >= 0 ? Type.uint : Type.negint, BigInt(numStr), this._pos - startPos);
1924
- }
1925
- /**
1926
- * @returns {Token}
1927
- */
1928
- parseString() {
1929
- if (this.ch() !== 34) {
1930
- throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}; this shouldn't happen`);
1931
- }
1932
- this._pos++;
1933
- for (let i = this._pos, l = 0; i < this.data.length && l < 65536; i++, l++) {
1934
- const ch = this.data[i];
1935
- if (ch === 92 || ch < 32 || ch >= 128) {
1936
- break;
1937
- }
1938
- if (ch === 34) {
1939
- const str = String.fromCharCode.apply(null, this.data.subarray(this._pos, i));
1940
- this._pos = i + 1;
1941
- return new Token(Type.string, str, l);
1942
- }
1943
- }
1944
- const startPos = this._pos;
1945
- const chars = [];
1946
- const readu4 = () => {
1947
- if (this._pos + 4 >= this.data.length) {
1948
- throw new Error(`${decodeErrPrefix} unexpected end of unicode escape sequence at position ${this._pos}`);
1949
- }
1950
- let u4 = 0;
1951
- for (let i = 0; i < 4; i++) {
1952
- let ch = this.ch();
1953
- if (ch >= 48 && ch <= 57) {
1954
- ch -= 48;
1955
- } else if (ch >= 97 && ch <= 102) {
1956
- ch = ch - 97 + 10;
1957
- } else if (ch >= 65 && ch <= 70) {
1958
- ch = ch - 65 + 10;
1959
- } else {
1960
- throw new Error(`${decodeErrPrefix} unexpected unicode escape character at position ${this._pos}`);
1961
- }
1962
- u4 = u4 * 16 + ch;
1963
- this._pos++;
1964
- }
1965
- return u4;
1966
- };
1967
- const readUtf8Char = () => {
1968
- const firstByte = this.ch();
1969
- let codePoint = null;
1970
- let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
1971
- if (this._pos + bytesPerSequence > this.data.length) {
1972
- throw new Error(`${decodeErrPrefix} unexpected unicode sequence at position ${this._pos}`);
1973
- }
1974
- let secondByte, thirdByte, fourthByte, tempCodePoint;
1975
- switch (bytesPerSequence) {
1976
- case 1:
1977
- if (firstByte < 128) {
1978
- codePoint = firstByte;
1979
- }
1980
- break;
1981
- case 2:
1982
- secondByte = this.data[this._pos + 1];
1983
- if ((secondByte & 192) === 128) {
1984
- tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
1985
- if (tempCodePoint > 127) {
1986
- codePoint = tempCodePoint;
1987
- }
1988
- }
1989
- break;
1990
- case 3:
1991
- secondByte = this.data[this._pos + 1];
1992
- thirdByte = this.data[this._pos + 2];
1993
- if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
1994
- tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
1995
- if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
1996
- codePoint = tempCodePoint;
1997
- }
1998
- }
1999
- break;
2000
- case 4:
2001
- secondByte = this.data[this._pos + 1];
2002
- thirdByte = this.data[this._pos + 2];
2003
- fourthByte = this.data[this._pos + 3];
2004
- if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
2005
- tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
2006
- if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
2007
- codePoint = tempCodePoint;
2008
- }
2009
- }
2010
- }
2011
- if (codePoint === null) {
2012
- codePoint = 65533;
2013
- bytesPerSequence = 1;
2014
- } else if (codePoint > 65535) {
2015
- codePoint -= 65536;
2016
- chars.push(codePoint >>> 10 & 1023 | 55296);
2017
- codePoint = 56320 | codePoint & 1023;
2018
- }
2019
- chars.push(codePoint);
2020
- this._pos += bytesPerSequence;
2021
- };
2022
- while (!this.done()) {
2023
- const ch = this.ch();
2024
- let ch1;
2025
- switch (ch) {
2026
- case 92:
2027
- this._pos++;
2028
- if (this.done()) {
2029
- throw new Error(`${decodeErrPrefix} unexpected string termination at position ${this._pos}`);
2030
- }
2031
- ch1 = this.ch();
2032
- this._pos++;
2033
- switch (ch1) {
2034
- case 34:
2035
- case 39:
2036
- case 92:
2037
- case 47:
2038
- chars.push(ch1);
2039
- break;
2040
- case 98:
2041
- chars.push(8);
2042
- break;
2043
- case 116:
2044
- chars.push(9);
2045
- break;
2046
- case 110:
2047
- chars.push(10);
2048
- break;
2049
- case 102:
2050
- chars.push(12);
2051
- break;
2052
- case 114:
2053
- chars.push(13);
2054
- break;
2055
- case 117:
2056
- chars.push(readu4());
2057
- break;
2058
- default:
2059
- throw new Error(`${decodeErrPrefix} unexpected string escape character at position ${this._pos}`);
2060
- }
2061
- break;
2062
- case 34:
2063
- this._pos++;
2064
- return new Token(Type.string, decodeCodePointsArray(chars), this._pos - startPos);
2065
- default:
2066
- if (ch < 32) {
2067
- throw new Error(`${decodeErrPrefix} invalid control character at position ${this._pos}`);
2068
- } else if (ch < 128) {
2069
- chars.push(ch);
2070
- this._pos++;
2071
- } else {
2072
- readUtf8Char();
2073
- }
2074
- }
2075
- }
2076
- throw new Error(`${decodeErrPrefix} unexpected end of string at position ${this._pos}`);
2077
- }
2078
- /**
2079
- * @returns {Token}
2080
- */
2081
- parseValue() {
2082
- switch (this.ch()) {
2083
- case 123:
2084
- this.modeStack.push("obj-start");
2085
- this._pos++;
2086
- return new Token(Type.map, Infinity, 1);
2087
- case 91:
2088
- this.modeStack.push("array-start");
2089
- this._pos++;
2090
- return new Token(Type.array, Infinity, 1);
2091
- case 34: {
2092
- return this.parseString();
2093
- }
2094
- case 110:
2095
- this.expect([110, 117, 108, 108]);
2096
- return new Token(Type.null, null, 4);
2097
- case 102:
2098
- this.expect([102, 97, 108, 115, 101]);
2099
- return new Token(Type.false, false, 5);
2100
- case 116:
2101
- this.expect([116, 114, 117, 101]);
2102
- return new Token(Type.true, true, 4);
2103
- case 45:
2104
- case 48:
2105
- case 49:
2106
- case 50:
2107
- case 51:
2108
- case 52:
2109
- case 53:
2110
- case 54:
2111
- case 55:
2112
- case 56:
2113
- case 57:
2114
- return this.parseNumber();
2115
- default:
2116
- throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}`);
2117
- }
2118
- }
2119
- /**
2120
- * @returns {Token}
2121
- */
2122
- next() {
2123
- this.skipWhitespace();
2124
- switch (this.currentMode()) {
2125
- case "value":
2126
- this.modeStack.pop();
2127
- return this.parseValue();
2128
- case "array-value": {
2129
- this.modeStack.pop();
2130
- if (this.ch() === 93) {
2131
- this._pos++;
2132
- this.skipWhitespace();
2133
- return new Token(Type.break, void 0, 1);
2134
- }
2135
- if (this.ch() !== 44) {
2136
- throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);
2137
- }
2138
- this._pos++;
2139
- this.modeStack.push("array-value");
2140
- this.skipWhitespace();
2141
- return this.parseValue();
2142
- }
2143
- case "array-start": {
2144
- this.modeStack.pop();
2145
- if (this.ch() === 93) {
2146
- this._pos++;
2147
- this.skipWhitespace();
2148
- return new Token(Type.break, void 0, 1);
2149
- }
2150
- this.modeStack.push("array-value");
2151
- this.skipWhitespace();
2152
- return this.parseValue();
2153
- }
2154
- case "obj-key":
2155
- if (this.ch() === 125) {
2156
- this.modeStack.pop();
2157
- this._pos++;
2158
- this.skipWhitespace();
2159
- return new Token(Type.break, void 0, 1);
2160
- }
2161
- if (this.ch() !== 44) {
2162
- throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);
2163
- }
2164
- this._pos++;
2165
- this.skipWhitespace();
2166
- case "obj-start": {
2167
- this.modeStack.pop();
2168
- if (this.ch() === 125) {
2169
- this._pos++;
2170
- this.skipWhitespace();
2171
- return new Token(Type.break, void 0, 1);
2172
- }
2173
- const token = this.parseString();
2174
- this.skipWhitespace();
2175
- if (this.ch() !== 58) {
2176
- throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);
2177
- }
2178
- this._pos++;
2179
- this.modeStack.push("obj-value");
2180
- return token;
2181
- }
2182
- case "obj-value": {
2183
- this.modeStack.pop();
2184
- this.modeStack.push("obj-key");
2185
- this.skipWhitespace();
2186
- return this.parseValue();
2187
- }
2188
- default:
2189
- throw new Error(`${decodeErrPrefix} unexpected parse state at position ${this._pos}; this shouldn't happen`);
2190
- }
2191
- }
2192
- };
2193
- function decode2(data, options) {
2194
- options = Object.assign({ tokenizer: new Tokenizer(data, options) }, options);
2195
- return decode(data, options);
2196
- }
2197
-
2198
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bytes.js
2199
- var empty = new Uint8Array(0);
2200
- var equals = (aa, bb) => {
2201
- if (aa === bb)
2202
- return true;
2203
- if (aa.byteLength !== bb.byteLength) {
2204
- return false;
2205
- }
2206
- for (let ii = 0; ii < aa.byteLength; ii++) {
2207
- if (aa[ii] !== bb[ii]) {
2208
- return false;
2209
- }
2210
- }
2211
- return true;
2212
- };
2213
- var coerce = (o) => {
2214
- if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
2215
- return o;
2216
- if (o instanceof ArrayBuffer)
2217
- return new Uint8Array(o);
2218
- if (ArrayBuffer.isView(o)) {
2219
- return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
2220
- }
2221
- throw new Error("Unknown type, must be binary type");
2222
- };
2223
-
2224
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/vendor/base-x.js
2225
- function base(ALPHABET, name2) {
2226
- if (ALPHABET.length >= 255) {
2227
- throw new TypeError("Alphabet too long");
2228
- }
2229
- var BASE_MAP = new Uint8Array(256);
2230
- for (var j = 0; j < BASE_MAP.length; j++) {
2231
- BASE_MAP[j] = 255;
2232
- }
2233
- for (var i = 0; i < ALPHABET.length; i++) {
2234
- var x = ALPHABET.charAt(i);
2235
- var xc = x.charCodeAt(0);
2236
- if (BASE_MAP[xc] !== 255) {
2237
- throw new TypeError(x + " is ambiguous");
2238
- }
2239
- BASE_MAP[xc] = i;
2240
- }
2241
- var BASE = ALPHABET.length;
2242
- var LEADER = ALPHABET.charAt(0);
2243
- var FACTOR = Math.log(BASE) / Math.log(256);
2244
- var iFACTOR = Math.log(256) / Math.log(BASE);
2245
- function encode7(source) {
2246
- if (source instanceof Uint8Array)
2247
- ;
2248
- else if (ArrayBuffer.isView(source)) {
2249
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
2250
- } else if (Array.isArray(source)) {
2251
- source = Uint8Array.from(source);
2252
- }
2253
- if (!(source instanceof Uint8Array)) {
2254
- throw new TypeError("Expected Uint8Array");
2255
- }
2256
- if (source.length === 0) {
2257
- return "";
2258
- }
2259
- var zeroes = 0;
2260
- var length2 = 0;
2261
- var pbegin = 0;
2262
- var pend = source.length;
2263
- while (pbegin !== pend && source[pbegin] === 0) {
2264
- pbegin++;
2265
- zeroes++;
2266
- }
2267
- var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
2268
- var b58 = new Uint8Array(size);
2269
- while (pbegin !== pend) {
2270
- var carry = source[pbegin];
2271
- var i2 = 0;
2272
- for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
2273
- carry += 256 * b58[it1] >>> 0;
2274
- b58[it1] = carry % BASE >>> 0;
2275
- carry = carry / BASE >>> 0;
2276
- }
2277
- if (carry !== 0) {
2278
- throw new Error("Non-zero carry");
2279
- }
2280
- length2 = i2;
2281
- pbegin++;
2282
- }
2283
- var it2 = size - length2;
2284
- while (it2 !== size && b58[it2] === 0) {
2285
- it2++;
2286
- }
2287
- var str = LEADER.repeat(zeroes);
2288
- for (; it2 < size; ++it2) {
2289
- str += ALPHABET.charAt(b58[it2]);
2290
- }
2291
- return str;
2292
- }
2293
- function decodeUnsafe(source) {
2294
- if (typeof source !== "string") {
2295
- throw new TypeError("Expected String");
2296
- }
2297
- if (source.length === 0) {
2298
- return new Uint8Array();
2299
- }
2300
- var psz = 0;
2301
- if (source[psz] === " ") {
2302
- return;
2303
- }
2304
- var zeroes = 0;
2305
- var length2 = 0;
2306
- while (source[psz] === LEADER) {
2307
- zeroes++;
2308
- psz++;
2309
- }
2310
- var size = (source.length - psz) * FACTOR + 1 >>> 0;
2311
- var b256 = new Uint8Array(size);
2312
- while (source[psz]) {
2313
- var carry = BASE_MAP[source.charCodeAt(psz)];
2314
- if (carry === 255) {
2315
- return;
2316
- }
2317
- var i2 = 0;
2318
- for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
2319
- carry += BASE * b256[it3] >>> 0;
2320
- b256[it3] = carry % 256 >>> 0;
2321
- carry = carry / 256 >>> 0;
2322
- }
2323
- if (carry !== 0) {
2324
- throw new Error("Non-zero carry");
2325
- }
2326
- length2 = i2;
2327
- psz++;
2328
- }
2329
- if (source[psz] === " ") {
2330
- return;
2331
- }
2332
- var it4 = size - length2;
2333
- while (it4 !== size && b256[it4] === 0) {
2334
- it4++;
2335
- }
2336
- var vch = new Uint8Array(zeroes + (size - it4));
2337
- var j2 = zeroes;
2338
- while (it4 !== size) {
2339
- vch[j2++] = b256[it4++];
2340
- }
2341
- return vch;
2342
- }
2343
- function decode8(string) {
2344
- var buffer2 = decodeUnsafe(string);
2345
- if (buffer2) {
2346
- return buffer2;
2347
- }
2348
- throw new Error(`Non-${name2} character`);
2349
- }
2350
- return {
2351
- encode: encode7,
2352
- decodeUnsafe,
2353
- decode: decode8
2354
- };
2355
- }
2356
- var src = base;
2357
- var _brrp__multiformats_scope_baseX = src;
2358
- var base_x_default = _brrp__multiformats_scope_baseX;
2359
-
2360
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base.js
2361
- var Encoder = class {
2362
- /**
2363
- * @param {Base} name
2364
- * @param {Prefix} prefix
2365
- * @param {(bytes:Uint8Array) => string} baseEncode
2366
- */
2367
- constructor(name2, prefix, baseEncode) {
2368
- this.name = name2;
2369
- this.prefix = prefix;
2370
- this.baseEncode = baseEncode;
2371
- }
2372
- /**
2373
- * @param {Uint8Array} bytes
2374
- * @returns {API.Multibase<Prefix>}
2375
- */
2376
- encode(bytes2) {
2377
- if (bytes2 instanceof Uint8Array) {
2378
- return `${this.prefix}${this.baseEncode(bytes2)}`;
2379
- } else {
2380
- throw Error("Unknown type, must be binary type");
2381
- }
2382
- }
2383
- };
2384
- var Decoder = class {
2385
- /**
2386
- * @param {Base} name
2387
- * @param {Prefix} prefix
2388
- * @param {(text:string) => Uint8Array} baseDecode
2389
- */
2390
- constructor(name2, prefix, baseDecode) {
2391
- this.name = name2;
2392
- this.prefix = prefix;
2393
- if (prefix.codePointAt(0) === void 0) {
2394
- throw new Error("Invalid prefix character");
2395
- }
2396
- this.prefixCodePoint = /** @type {number} */
2397
- prefix.codePointAt(0);
2398
- this.baseDecode = baseDecode;
2399
- }
2400
- /**
2401
- * @param {string} text
2402
- */
2403
- decode(text) {
2404
- if (typeof text === "string") {
2405
- if (text.codePointAt(0) !== this.prefixCodePoint) {
2406
- throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
2407
- }
2408
- return this.baseDecode(text.slice(this.prefix.length));
2409
- } else {
2410
- throw Error("Can only multibase decode strings");
2411
- }
2412
- }
2413
- /**
2414
- * @template {string} OtherPrefix
2415
- * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
2416
- * @returns {ComposedDecoder<Prefix|OtherPrefix>}
2417
- */
2418
- or(decoder) {
2419
- return or(this, decoder);
2420
- }
2421
- };
2422
- var ComposedDecoder = class {
2423
- /**
2424
- * @param {Decoders<Prefix>} decoders
2425
- */
2426
- constructor(decoders) {
2427
- this.decoders = decoders;
2428
- }
2429
- /**
2430
- * @template {string} OtherPrefix
2431
- * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
2432
- * @returns {ComposedDecoder<Prefix|OtherPrefix>}
2433
- */
2434
- or(decoder) {
2435
- return or(this, decoder);
2436
- }
2437
- /**
2438
- * @param {string} input
2439
- * @returns {Uint8Array}
2440
- */
2441
- decode(input) {
2442
- const prefix = (
2443
- /** @type {Prefix} */
2444
- input[0]
2445
- );
2446
- const decoder = this.decoders[prefix];
2447
- if (decoder) {
2448
- return decoder.decode(input);
2449
- } else {
2450
- throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
2451
- }
2452
- }
2453
- };
2454
- var or = (left, right) => new ComposedDecoder(
2455
- /** @type {Decoders<L|R>} */
2456
- {
2457
- ...left.decoders || { [
2458
- /** @type API.UnibaseDecoder<L> */
2459
- left.prefix
2460
- ]: left },
2461
- ...right.decoders || { [
2462
- /** @type API.UnibaseDecoder<R> */
2463
- right.prefix
2464
- ]: right }
2465
- }
2466
- );
2467
- var Codec = class {
2468
- /**
2469
- * @param {Base} name
2470
- * @param {Prefix} prefix
2471
- * @param {(bytes:Uint8Array) => string} baseEncode
2472
- * @param {(text:string) => Uint8Array} baseDecode
2473
- */
2474
- constructor(name2, prefix, baseEncode, baseDecode) {
2475
- this.name = name2;
2476
- this.prefix = prefix;
2477
- this.baseEncode = baseEncode;
2478
- this.baseDecode = baseDecode;
2479
- this.encoder = new Encoder(name2, prefix, baseEncode);
2480
- this.decoder = new Decoder(name2, prefix, baseDecode);
2481
- }
2482
- /**
2483
- * @param {Uint8Array} input
2484
- */
2485
- encode(input) {
2486
- return this.encoder.encode(input);
2487
- }
2488
- /**
2489
- * @param {string} input
2490
- */
2491
- decode(input) {
2492
- return this.decoder.decode(input);
2493
- }
2494
- };
2495
- var from = ({ name: name2, prefix, encode: encode7, decode: decode8 }) => new Codec(name2, prefix, encode7, decode8);
2496
- var baseX = ({ prefix, name: name2, alphabet }) => {
2497
- const { encode: encode7, decode: decode8 } = base_x_default(alphabet, name2);
2498
- return from({
2499
- prefix,
2500
- name: name2,
2501
- encode: encode7,
2502
- /**
2503
- * @param {string} text
2504
- */
2505
- decode: (text) => coerce(decode8(text))
2506
- });
2507
- };
2508
- var decode3 = (string, alphabet, bitsPerChar, name2) => {
2509
- const codes = {};
2510
- for (let i = 0; i < alphabet.length; ++i) {
2511
- codes[alphabet[i]] = i;
2512
- }
2513
- let end = string.length;
2514
- while (string[end - 1] === "=") {
2515
- --end;
2516
- }
2517
- const out = new Uint8Array(end * bitsPerChar / 8 | 0);
2518
- let bits = 0;
2519
- let buffer2 = 0;
2520
- let written = 0;
2521
- for (let i = 0; i < end; ++i) {
2522
- const value = codes[string[i]];
2523
- if (value === void 0) {
2524
- throw new SyntaxError(`Non-${name2} character`);
2525
- }
2526
- buffer2 = buffer2 << bitsPerChar | value;
2527
- bits += bitsPerChar;
2528
- if (bits >= 8) {
2529
- bits -= 8;
2530
- out[written++] = 255 & buffer2 >> bits;
2531
- }
2532
- }
2533
- if (bits >= bitsPerChar || 255 & buffer2 << 8 - bits) {
2534
- throw new SyntaxError("Unexpected end of data");
2535
- }
2536
- return out;
2537
- };
2538
- var encode3 = (data, alphabet, bitsPerChar) => {
2539
- const pad = alphabet[alphabet.length - 1] === "=";
2540
- const mask = (1 << bitsPerChar) - 1;
2541
- let out = "";
2542
- let bits = 0;
2543
- let buffer2 = 0;
2544
- for (let i = 0; i < data.length; ++i) {
2545
- buffer2 = buffer2 << 8 | data[i];
2546
- bits += 8;
2547
- while (bits > bitsPerChar) {
2548
- bits -= bitsPerChar;
2549
- out += alphabet[mask & buffer2 >> bits];
2550
- }
2551
- }
2552
- if (bits) {
2553
- out += alphabet[mask & buffer2 << bitsPerChar - bits];
2554
- }
2555
- if (pad) {
2556
- while (out.length * bitsPerChar & 7) {
2557
- out += "=";
2558
- }
2559
- }
2560
- return out;
2561
- };
2562
- var rfc4648 = ({ name: name2, prefix, bitsPerChar, alphabet }) => {
2563
- return from({
2564
- prefix,
2565
- name: name2,
2566
- encode(input) {
2567
- return encode3(input, alphabet, bitsPerChar);
2568
- },
2569
- decode(input) {
2570
- return decode3(input, alphabet, bitsPerChar, name2);
2571
- }
2572
- });
2573
- };
2574
-
2575
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base32.js
2576
- var base32 = rfc4648({
2577
- prefix: "b",
2578
- name: "base32",
2579
- alphabet: "abcdefghijklmnopqrstuvwxyz234567",
2580
- bitsPerChar: 5
2581
- });
2582
- var base32upper = rfc4648({
2583
- prefix: "B",
2584
- name: "base32upper",
2585
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
2586
- bitsPerChar: 5
2587
- });
2588
- var base32pad = rfc4648({
2589
- prefix: "c",
2590
- name: "base32pad",
2591
- alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
2592
- bitsPerChar: 5
2593
- });
2594
- var base32padupper = rfc4648({
2595
- prefix: "C",
2596
- name: "base32padupper",
2597
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
2598
- bitsPerChar: 5
2599
- });
2600
- var base32hex = rfc4648({
2601
- prefix: "v",
2602
- name: "base32hex",
2603
- alphabet: "0123456789abcdefghijklmnopqrstuv",
2604
- bitsPerChar: 5
2605
- });
2606
- var base32hexupper = rfc4648({
2607
- prefix: "V",
2608
- name: "base32hexupper",
2609
- alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
2610
- bitsPerChar: 5
2611
- });
2612
- var base32hexpad = rfc4648({
2613
- prefix: "t",
2614
- name: "base32hexpad",
2615
- alphabet: "0123456789abcdefghijklmnopqrstuv=",
2616
- bitsPerChar: 5
2617
- });
2618
- var base32hexpadupper = rfc4648({
2619
- prefix: "T",
2620
- name: "base32hexpadupper",
2621
- alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
2622
- bitsPerChar: 5
2623
- });
2624
- var base32z = rfc4648({
2625
- prefix: "h",
2626
- name: "base32z",
2627
- alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
2628
- bitsPerChar: 5
2629
- });
2630
-
2631
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base58.js
2632
- var base58btc = baseX({
2633
- name: "base58btc",
2634
- prefix: "z",
2635
- alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
2636
- });
2637
- var base58flickr = baseX({
2638
- name: "base58flickr",
2639
- prefix: "Z",
2640
- alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
2641
- });
2642
-
2643
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/hashes/digest.js
2644
- var digest_exports = {};
2645
- __export(digest_exports, {
2646
- Digest: () => Digest,
2647
- create: () => create,
2648
- decode: () => decode6,
2649
- equals: () => equals2
2650
- });
2651
-
2652
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/vendor/varint.js
2653
- var encode_1 = encode4;
2654
- var MSB = 128;
2655
- var REST = 127;
2656
- var MSBALL = ~REST;
2657
- var INT = Math.pow(2, 31);
2658
- function encode4(num, out, offset) {
2659
- out = out || [];
2660
- offset = offset || 0;
2661
- var oldOffset = offset;
2662
- while (num >= INT) {
2663
- out[offset++] = num & 255 | MSB;
2664
- num /= 128;
2665
- }
2666
- while (num & MSBALL) {
2667
- out[offset++] = num & 255 | MSB;
2668
- num >>>= 7;
2669
- }
2670
- out[offset] = num | 0;
2671
- encode4.bytes = offset - oldOffset + 1;
2672
- return out;
2673
- }
2674
- var decode4 = read;
2675
- var MSB$1 = 128;
2676
- var REST$1 = 127;
2677
- function read(buf2, offset) {
2678
- var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf2.length;
2679
- do {
2680
- if (counter >= l) {
2681
- read.bytes = 0;
2682
- throw new RangeError("Could not decode varint");
2683
- }
2684
- b = buf2[counter++];
2685
- res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
2686
- shift += 7;
2687
- } while (b >= MSB$1);
2688
- read.bytes = counter - offset;
2689
- return res;
2690
- }
2691
- var N1 = Math.pow(2, 7);
2692
- var N2 = Math.pow(2, 14);
2693
- var N3 = Math.pow(2, 21);
2694
- var N4 = Math.pow(2, 28);
2695
- var N5 = Math.pow(2, 35);
2696
- var N6 = Math.pow(2, 42);
2697
- var N7 = Math.pow(2, 49);
2698
- var N8 = Math.pow(2, 56);
2699
- var N9 = Math.pow(2, 63);
2700
- var length = function(value) {
2701
- 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;
2702
- };
2703
- var varint = {
2704
- encode: encode_1,
2705
- decode: decode4,
2706
- encodingLength: length
2707
- };
2708
- var _brrp_varint = varint;
2709
- var varint_default = _brrp_varint;
2710
-
2711
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/varint.js
2712
- var decode5 = (data, offset = 0) => {
2713
- const code2 = varint_default.decode(data, offset);
2714
- return [code2, varint_default.decode.bytes];
2715
- };
2716
- var encodeTo = (int, target, offset = 0) => {
2717
- varint_default.encode(int, target, offset);
2718
- return target;
2719
- };
2720
- var encodingLength = (int) => {
2721
- return varint_default.encodingLength(int);
2722
- };
2723
-
2724
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/hashes/digest.js
2725
- var create = (code2, digest) => {
2726
- const size = digest.byteLength;
2727
- const sizeOffset = encodingLength(code2);
2728
- const digestOffset = sizeOffset + encodingLength(size);
2729
- const bytes2 = new Uint8Array(digestOffset + size);
2730
- encodeTo(code2, bytes2, 0);
2731
- encodeTo(size, bytes2, sizeOffset);
2732
- bytes2.set(digest, digestOffset);
2733
- return new Digest(code2, size, digest, bytes2);
2734
- };
2735
- var decode6 = (multihash) => {
2736
- const bytes2 = coerce(multihash);
2737
- const [code2, sizeOffset] = decode5(bytes2);
2738
- const [size, digestOffset] = decode5(bytes2.subarray(sizeOffset));
2739
- const digest = bytes2.subarray(sizeOffset + digestOffset);
2740
- if (digest.byteLength !== size) {
2741
- throw new Error("Incorrect length");
2742
- }
2743
- return new Digest(code2, size, digest, bytes2);
2744
- };
2745
- var equals2 = (a, b) => {
2746
- if (a === b) {
2747
- return true;
2748
- } else {
2749
- const data = (
2750
- /** @type {{code?:unknown, size?:unknown, bytes?:unknown}} */
2751
- b
2752
- );
2753
- return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
2754
- }
2755
- };
2756
- var Digest = class {
2757
- /**
2758
- * Creates a multihash digest.
2759
- *
2760
- * @param {Code} code
2761
- * @param {Size} size
2762
- * @param {Uint8Array} digest
2763
- * @param {Uint8Array} bytes
2764
- */
2765
- constructor(code2, size, digest, bytes2) {
2766
- this.code = code2;
2767
- this.size = size;
2768
- this.digest = digest;
2769
- this.bytes = bytes2;
2770
- }
2771
- };
2772
-
2773
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/cid.js
2774
- var format = (link, base2) => {
2775
- const { bytes: bytes2, version } = link;
2776
- switch (version) {
2777
- case 0:
2778
- return toStringV0(
2779
- bytes2,
2780
- baseCache(link),
2781
- /** @type {API.MultibaseEncoder<"z">} */
2782
- base2 || base58btc.encoder
2783
- );
2784
- default:
2785
- return toStringV1(
2786
- bytes2,
2787
- baseCache(link),
2788
- /** @type {API.MultibaseEncoder<Prefix>} */
2789
- base2 || base32.encoder
2790
- );
2791
- }
2792
- };
2793
- var cache = /* @__PURE__ */ new WeakMap();
2794
- var baseCache = (cid) => {
2795
- const baseCache2 = cache.get(cid);
2796
- if (baseCache2 == null) {
2797
- const baseCache3 = /* @__PURE__ */ new Map();
2798
- cache.set(cid, baseCache3);
2799
- return baseCache3;
2800
- }
2801
- return baseCache2;
2802
- };
2803
- var CID = class _CID {
2804
- /**
2805
- * @param {Version} version - Version of the CID
2806
- * @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
2807
- * @param {API.MultihashDigest<Alg>} multihash - (Multi)hash of the of the content.
2808
- * @param {Uint8Array} bytes
2809
- */
2810
- constructor(version, code2, multihash, bytes2) {
2811
- this.code = code2;
2812
- this.version = version;
2813
- this.multihash = multihash;
2814
- this.bytes = bytes2;
2815
- this["/"] = bytes2;
2816
- }
2817
- /**
2818
- * Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
2819
- * please either use `CID.asCID(cid)` or switch to new signalling mechanism
2820
- *
2821
- * @deprecated
2822
- */
2823
- get asCID() {
2824
- return this;
2825
- }
2826
- // ArrayBufferView
2827
- get byteOffset() {
2828
- return this.bytes.byteOffset;
2829
- }
2830
- // ArrayBufferView
2831
- get byteLength() {
2832
- return this.bytes.byteLength;
2833
- }
2834
- /**
2835
- * @returns {CID<Data, API.DAG_PB, API.SHA_256, 0>}
2836
- */
2837
- toV0() {
2838
- switch (this.version) {
2839
- case 0: {
2840
- return (
2841
- /** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */
2842
- this
2843
- );
2844
- }
2845
- case 1: {
2846
- const { code: code2, multihash } = this;
2847
- if (code2 !== DAG_PB_CODE) {
2848
- throw new Error("Cannot convert a non dag-pb CID to CIDv0");
2849
- }
2850
- if (multihash.code !== SHA_256_CODE) {
2851
- throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
2852
- }
2853
- return (
2854
- /** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */
2855
- _CID.createV0(
2856
- /** @type {API.MultihashDigest<API.SHA_256>} */
2857
- multihash
2858
- )
2859
- );
2860
- }
2861
- default: {
2862
- throw Error(
2863
- `Can not convert CID version ${this.version} to version 0. This is a bug please report`
2864
- );
2865
- }
2866
- }
2867
- }
2868
- /**
2869
- * @returns {CID<Data, Format, Alg, 1>}
2870
- */
2871
- toV1() {
2872
- switch (this.version) {
2873
- case 0: {
2874
- const { code: code2, digest } = this.multihash;
2875
- const multihash = create(code2, digest);
2876
- return (
2877
- /** @type {CID<Data, Format, Alg, 1>} */
2878
- _CID.createV1(this.code, multihash)
2879
- );
2880
- }
2881
- case 1: {
2882
- return (
2883
- /** @type {CID<Data, Format, Alg, 1>} */
2884
- this
2885
- );
2886
- }
2887
- default: {
2888
- throw Error(
2889
- `Can not convert CID version ${this.version} to version 1. This is a bug please report`
2890
- );
2891
- }
2892
- }
2893
- }
2894
- /**
2895
- * @param {unknown} other
2896
- * @returns {other is CID<Data, Format, Alg, Version>}
2897
- */
2898
- equals(other) {
2899
- return _CID.equals(this, other);
2900
- }
2901
- /**
2902
- * @template {unknown} Data
2903
- * @template {number} Format
2904
- * @template {number} Alg
2905
- * @template {API.Version} Version
2906
- * @param {API.Link<Data, Format, Alg, Version>} self
2907
- * @param {unknown} other
2908
- * @returns {other is CID}
2909
- */
2910
- static equals(self2, other) {
2911
- const unknown = (
2912
- /** @type {{code?:unknown, version?:unknown, multihash?:unknown}} */
2913
- other
2914
- );
2915
- return unknown && self2.code === unknown.code && self2.version === unknown.version && equals2(self2.multihash, unknown.multihash);
2916
- }
2917
- /**
2918
- * @param {API.MultibaseEncoder<string>} [base]
2919
- * @returns {string}
2920
- */
2921
- toString(base2) {
2922
- return format(this, base2);
2923
- }
2924
- /**
2925
- * @returns {API.LinkJSON<this>}
2926
- */
2927
- toJSON() {
2928
- return { "/": format(this) };
2929
- }
2930
- link() {
2931
- return this;
2932
- }
2933
- get [Symbol.toStringTag]() {
2934
- return "CID";
2935
- }
2936
- // Legacy
2937
- [Symbol.for("nodejs.util.inspect.custom")]() {
2938
- return `CID(${this.toString()})`;
2939
- }
2940
- /**
2941
- * Takes any input `value` and returns a `CID` instance if it was
2942
- * a `CID` otherwise returns `null`. If `value` is instanceof `CID`
2943
- * it will return value back. If `value` is not instance of this CID
2944
- * class, but is compatible CID it will return new instance of this
2945
- * `CID` class. Otherwise returns null.
2946
- *
2947
- * This allows two different incompatible versions of CID library to
2948
- * co-exist and interop as long as binary interface is compatible.
2949
- *
2950
- * @template {unknown} Data
2951
- * @template {number} Format
2952
- * @template {number} Alg
2953
- * @template {API.Version} Version
2954
- * @template {unknown} U
2955
- * @param {API.Link<Data, Format, Alg, Version>|U} input
2956
- * @returns {CID<Data, Format, Alg, Version>|null}
2957
- */
2958
- static asCID(input) {
2959
- if (input == null) {
2960
- return null;
2961
- }
2962
- const value = (
2963
- /** @type {any} */
2964
- input
2965
- );
2966
- if (value instanceof _CID) {
2967
- return value;
2968
- } else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
2969
- const { version, code: code2, multihash, bytes: bytes2 } = value;
2970
- return new _CID(
2971
- version,
2972
- code2,
2973
- /** @type {API.MultihashDigest<Alg>} */
2974
- multihash,
2975
- bytes2 || encodeCID(version, code2, multihash.bytes)
2976
- );
2977
- } else if (value[cidSymbol] === true) {
2978
- const { version, multihash, code: code2 } = value;
2979
- const digest = (
2980
- /** @type {API.MultihashDigest<Alg>} */
2981
- decode6(multihash)
2982
- );
2983
- return _CID.create(version, code2, digest);
2984
- } else {
2985
- return null;
2986
- }
2987
- }
2988
- /**
2989
- *
2990
- * @template {unknown} Data
2991
- * @template {number} Format
2992
- * @template {number} Alg
2993
- * @template {API.Version} Version
2994
- * @param {Version} version - Version of the CID
2995
- * @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
2996
- * @param {API.MultihashDigest<Alg>} digest - (Multi)hash of the of the content.
2997
- * @returns {CID<Data, Format, Alg, Version>}
2998
- */
2999
- static create(version, code2, digest) {
3000
- if (typeof code2 !== "number") {
3001
- throw new Error("String codecs are no longer supported");
3002
- }
3003
- if (!(digest.bytes instanceof Uint8Array)) {
3004
- throw new Error("Invalid digest");
3005
- }
3006
- switch (version) {
3007
- case 0: {
3008
- if (code2 !== DAG_PB_CODE) {
3009
- throw new Error(
3010
- `Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`
3011
- );
3012
- } else {
3013
- return new _CID(version, code2, digest, digest.bytes);
3014
- }
3015
- }
3016
- case 1: {
3017
- const bytes2 = encodeCID(version, code2, digest.bytes);
3018
- return new _CID(version, code2, digest, bytes2);
3019
- }
3020
- default: {
3021
- throw new Error("Invalid version");
3022
- }
3023
- }
3024
- }
3025
- /**
3026
- * Simplified version of `create` for CIDv0.
3027
- *
3028
- * @template {unknown} [T=unknown]
3029
- * @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash.
3030
- * @returns {CID<T, typeof DAG_PB_CODE, typeof SHA_256_CODE, 0>}
3031
- */
3032
- static createV0(digest) {
3033
- return _CID.create(0, DAG_PB_CODE, digest);
3034
- }
3035
- /**
3036
- * Simplified version of `create` for CIDv1.
3037
- *
3038
- * @template {unknown} Data
3039
- * @template {number} Code
3040
- * @template {number} Alg
3041
- * @param {Code} code - Content encoding format code.
3042
- * @param {API.MultihashDigest<Alg>} digest - Miltihash of the content.
3043
- * @returns {CID<Data, Code, Alg, 1>}
3044
- */
3045
- static createV1(code2, digest) {
3046
- return _CID.create(1, code2, digest);
3047
- }
3048
- /**
3049
- * Decoded a CID from its binary representation. The byte array must contain
3050
- * only the CID with no additional bytes.
3051
- *
3052
- * An error will be thrown if the bytes provided do not contain a valid
3053
- * binary representation of a CID.
3054
- *
3055
- * @template {unknown} Data
3056
- * @template {number} Code
3057
- * @template {number} Alg
3058
- * @template {API.Version} Ver
3059
- * @param {API.ByteView<API.Link<Data, Code, Alg, Ver>>} bytes
3060
- * @returns {CID<Data, Code, Alg, Ver>}
3061
- */
3062
- static decode(bytes2) {
3063
- const [cid, remainder] = _CID.decodeFirst(bytes2);
3064
- if (remainder.length) {
3065
- throw new Error("Incorrect length");
3066
- }
3067
- return cid;
3068
- }
3069
- /**
3070
- * Decoded a CID from its binary representation at the beginning of a byte
3071
- * array.
3072
- *
3073
- * Returns an array with the first element containing the CID and the second
3074
- * element containing the remainder of the original byte array. The remainder
3075
- * will be a zero-length byte array if the provided bytes only contained a
3076
- * binary CID representation.
3077
- *
3078
- * @template {unknown} T
3079
- * @template {number} C
3080
- * @template {number} A
3081
- * @template {API.Version} V
3082
- * @param {API.ByteView<API.Link<T, C, A, V>>} bytes
3083
- * @returns {[CID<T, C, A, V>, Uint8Array]}
3084
- */
3085
- static decodeFirst(bytes2) {
3086
- const specs = _CID.inspectBytes(bytes2);
3087
- const prefixSize = specs.size - specs.multihashSize;
3088
- const multihashBytes = coerce(
3089
- bytes2.subarray(prefixSize, prefixSize + specs.multihashSize)
3090
- );
3091
- if (multihashBytes.byteLength !== specs.multihashSize) {
3092
- throw new Error("Incorrect length");
3093
- }
3094
- const digestBytes = multihashBytes.subarray(
3095
- specs.multihashSize - specs.digestSize
3096
- );
3097
- const digest = new Digest(
3098
- specs.multihashCode,
3099
- specs.digestSize,
3100
- digestBytes,
3101
- multihashBytes
3102
- );
3103
- const cid = specs.version === 0 ? _CID.createV0(
3104
- /** @type {API.MultihashDigest<API.SHA_256>} */
3105
- digest
3106
- ) : _CID.createV1(specs.codec, digest);
3107
- return [
3108
- /** @type {CID<T, C, A, V>} */
3109
- cid,
3110
- bytes2.subarray(specs.size)
3111
- ];
3112
- }
3113
- /**
3114
- * Inspect the initial bytes of a CID to determine its properties.
3115
- *
3116
- * Involves decoding up to 4 varints. Typically this will require only 4 to 6
3117
- * bytes but for larger multicodec code values and larger multihash digest
3118
- * lengths these varints can be quite large. It is recommended that at least
3119
- * 10 bytes be made available in the `initialBytes` argument for a complete
3120
- * inspection.
3121
- *
3122
- * @template {unknown} T
3123
- * @template {number} C
3124
- * @template {number} A
3125
- * @template {API.Version} V
3126
- * @param {API.ByteView<API.Link<T, C, A, V>>} initialBytes
3127
- * @returns {{ version:V, codec:C, multihashCode:A, digestSize:number, multihashSize:number, size:number }}
3128
- */
3129
- static inspectBytes(initialBytes) {
3130
- let offset = 0;
3131
- const next = () => {
3132
- const [i, length2] = decode5(initialBytes.subarray(offset));
3133
- offset += length2;
3134
- return i;
3135
- };
3136
- let version = (
3137
- /** @type {V} */
3138
- next()
3139
- );
3140
- let codec = (
3141
- /** @type {C} */
3142
- DAG_PB_CODE
3143
- );
3144
- if (
3145
- /** @type {number} */
3146
- version === 18
3147
- ) {
3148
- version = /** @type {V} */
3149
- 0;
3150
- offset = 0;
3151
- } else {
3152
- codec = /** @type {C} */
3153
- next();
3154
- }
3155
- if (version !== 0 && version !== 1) {
3156
- throw new RangeError(`Invalid CID version ${version}`);
3157
- }
3158
- const prefixSize = offset;
3159
- const multihashCode = (
3160
- /** @type {A} */
3161
- next()
3162
- );
3163
- const digestSize = next();
3164
- const size = offset + digestSize;
3165
- const multihashSize = size - prefixSize;
3166
- return { version, codec, multihashCode, digestSize, multihashSize, size };
3167
- }
3168
- /**
3169
- * Takes cid in a string representation and creates an instance. If `base`
3170
- * decoder is not provided will use a default from the configuration. It will
3171
- * throw an error if encoding of the CID is not compatible with supplied (or
3172
- * a default decoder).
3173
- *
3174
- * @template {string} Prefix
3175
- * @template {unknown} Data
3176
- * @template {number} Code
3177
- * @template {number} Alg
3178
- * @template {API.Version} Ver
3179
- * @param {API.ToString<API.Link<Data, Code, Alg, Ver>, Prefix>} source
3180
- * @param {API.MultibaseDecoder<Prefix>} [base]
3181
- * @returns {CID<Data, Code, Alg, Ver>}
3182
- */
3183
- static parse(source, base2) {
3184
- const [prefix, bytes2] = parseCIDtoBytes(source, base2);
3185
- const cid = _CID.decode(bytes2);
3186
- if (cid.version === 0 && source[0] !== "Q") {
3187
- throw Error("Version 0 CID string must not include multibase prefix");
3188
- }
3189
- baseCache(cid).set(prefix, source);
3190
- return cid;
3191
- }
3192
- };
3193
- var parseCIDtoBytes = (source, base2) => {
3194
- switch (source[0]) {
3195
- case "Q": {
3196
- const decoder = base2 || base58btc;
3197
- return [
3198
- /** @type {Prefix} */
3199
- base58btc.prefix,
3200
- decoder.decode(`${base58btc.prefix}${source}`)
3201
- ];
3202
- }
3203
- case base58btc.prefix: {
3204
- const decoder = base2 || base58btc;
3205
- return [
3206
- /** @type {Prefix} */
3207
- base58btc.prefix,
3208
- decoder.decode(source)
3209
- ];
3210
- }
3211
- case base32.prefix: {
3212
- const decoder = base2 || base32;
3213
- return [
3214
- /** @type {Prefix} */
3215
- base32.prefix,
3216
- decoder.decode(source)
3217
- ];
3218
- }
3219
- default: {
3220
- if (base2 == null) {
3221
- throw Error(
3222
- "To parse non base32 or base58btc encoded CID multibase decoder must be provided"
3223
- );
3224
- }
3225
- return [
3226
- /** @type {Prefix} */
3227
- source[0],
3228
- base2.decode(source)
3229
- ];
3230
- }
3231
- }
3232
- };
3233
- var toStringV0 = (bytes2, cache2, base2) => {
3234
- const { prefix } = base2;
3235
- if (prefix !== base58btc.prefix) {
3236
- throw Error(`Cannot string encode V0 in ${base2.name} encoding`);
3237
- }
3238
- const cid = cache2.get(prefix);
3239
- if (cid == null) {
3240
- const cid2 = base2.encode(bytes2).slice(1);
3241
- cache2.set(prefix, cid2);
3242
- return cid2;
3243
- } else {
3244
- return cid;
3245
- }
3246
- };
3247
- var toStringV1 = (bytes2, cache2, base2) => {
3248
- const { prefix } = base2;
3249
- const cid = cache2.get(prefix);
3250
- if (cid == null) {
3251
- const cid2 = base2.encode(bytes2);
3252
- cache2.set(prefix, cid2);
3253
- return cid2;
3254
- } else {
3255
- return cid;
3256
- }
3257
- };
3258
- var DAG_PB_CODE = 112;
3259
- var SHA_256_CODE = 18;
3260
- var encodeCID = (version, code2, multihash) => {
3261
- const codeOffset = encodingLength(version);
3262
- const hashOffset = codeOffset + encodingLength(code2);
3263
- const bytes2 = new Uint8Array(hashOffset + multihash.byteLength);
3264
- encodeTo(version, bytes2, 0);
3265
- encodeTo(code2, bytes2, codeOffset);
3266
- bytes2.set(multihash, hashOffset);
3267
- return bytes2;
3268
- };
3269
- var cidSymbol = Symbol.for("@ipld/js-cid/CID");
3270
-
3271
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/hashes/hasher.js
3272
- var from2 = ({ name: name2, code: code2, encode: encode7 }) => new Hasher(name2, code2, encode7);
3273
- var Hasher = class {
3274
- /**
3275
- *
3276
- * @param {Name} name
3277
- * @param {Code} code
3278
- * @param {(input: Uint8Array) => Await<Uint8Array>} encode
3279
- */
3280
- constructor(name2, code2, encode7) {
3281
- this.name = name2;
3282
- this.code = code2;
3283
- this.encode = encode7;
3284
- }
3285
- /**
3286
- * @param {Uint8Array} input
3287
- * @returns {Await<Digest.Digest<Code, number>>}
3288
- */
3289
- digest(input) {
3290
- if (input instanceof Uint8Array) {
3291
- const result = this.encode(input);
3292
- return result instanceof Uint8Array ? create(this.code, result) : result.then((digest) => create(this.code, digest));
3293
- } else {
3294
- throw Error("Unknown type, must be binary type");
3295
- }
3296
- }
3297
- };
3298
-
3299
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base64.js
3300
- var base64 = rfc4648({
3301
- prefix: "m",
3302
- name: "base64",
3303
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
3304
- bitsPerChar: 6
3305
- });
3306
- var base64pad = rfc4648({
3307
- prefix: "M",
3308
- name: "base64pad",
3309
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
3310
- bitsPerChar: 6
3311
- });
3312
- var base64url = rfc4648({
3313
- prefix: "u",
3314
- name: "base64url",
3315
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
3316
- bitsPerChar: 6
3317
- });
3318
- var base64urlpad = rfc4648({
3319
- prefix: "U",
3320
- name: "base64urlpad",
3321
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
3322
- bitsPerChar: 6
3323
- });
3324
-
3325
- // ../../../node_modules/.pnpm/@ipld+dag-json@10.1.5/node_modules/@ipld/dag-json/src/index.js
3326
- function cidEncoder(obj) {
3327
- if (obj.asCID !== obj && obj["/"] !== obj.bytes) {
3328
- return null;
3329
- }
3330
- const cid = CID.asCID(obj);
3331
- if (!cid) {
3332
- return null;
3333
- }
3334
- const cidString = cid.toString();
3335
- return [
3336
- new Token(Type.map, Infinity, 1),
3337
- new Token(Type.string, "/", 1),
3338
- // key
3339
- new Token(Type.string, cidString, cidString.length),
3340
- // value
3341
- new Token(Type.break, void 0, 1)
3342
- ];
3343
- }
3344
- function bytesEncoder(bytes2) {
3345
- const bytesString = base64.encode(bytes2).slice(1);
3346
- return [
3347
- new Token(Type.map, Infinity, 1),
3348
- new Token(Type.string, "/", 1),
3349
- // key
3350
- new Token(Type.map, Infinity, 1),
3351
- // value
3352
- new Token(Type.string, "bytes", 5),
3353
- // inner key
3354
- new Token(Type.string, bytesString, bytesString.length),
3355
- // inner value
3356
- new Token(Type.break, void 0, 1),
3357
- new Token(Type.break, void 0, 1)
3358
- ];
3359
- }
3360
- function taBytesEncoder(obj) {
3361
- return bytesEncoder(new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength));
3362
- }
3363
- function abBytesEncoder(ab) {
3364
- return bytesEncoder(new Uint8Array(ab));
3365
- }
3366
- function undefinedEncoder() {
3367
- throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded");
3368
- }
3369
- function numberEncoder(num) {
3370
- if (Number.isNaN(num)) {
3371
- throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");
3372
- }
3373
- if (num === Infinity || num === -Infinity) {
3374
- throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");
3375
- }
3376
- return null;
3377
- }
3378
- var encodeOptions = {
3379
- typeEncoders: {
3380
- Object: cidEncoder,
3381
- Buffer: bytesEncoder,
3382
- Uint8Array: bytesEncoder,
3383
- Int8Array: taBytesEncoder,
3384
- Uint16Array: taBytesEncoder,
3385
- Int16Array: taBytesEncoder,
3386
- Uint32Array: taBytesEncoder,
3387
- Int32Array: taBytesEncoder,
3388
- Float32Array: taBytesEncoder,
3389
- Float64Array: taBytesEncoder,
3390
- Uint8ClampedArray: taBytesEncoder,
3391
- BigInt64Array: taBytesEncoder,
3392
- BigUint64Array: taBytesEncoder,
3393
- DataView: taBytesEncoder,
3394
- ArrayBuffer: abBytesEncoder,
3395
- undefined: undefinedEncoder,
3396
- number: numberEncoder
3397
- }
3398
- };
3399
- var DagJsonTokenizer = class extends Tokenizer {
3400
- /**
3401
- * @param {Uint8Array} data
3402
- * @param {object} [options]
3403
- */
3404
- constructor(data, options) {
3405
- super(data, options);
3406
- this.tokenBuffer = [];
3407
- }
3408
- /**
3409
- * @returns {boolean}
3410
- */
3411
- done() {
3412
- return this.tokenBuffer.length === 0 && super.done();
3413
- }
3414
- /**
3415
- * @returns {Token}
3416
- */
3417
- _next() {
3418
- if (this.tokenBuffer.length > 0) {
3419
- return this.tokenBuffer.pop();
3420
- }
3421
- return super.next();
3422
- }
3423
- /**
3424
- * Implements rules outlined in https://github.com/ipld/specs/pull/356
3425
- *
3426
- * @returns {Token}
3427
- */
3428
- next() {
3429
- const token = this._next();
3430
- if (token.type === Type.map) {
3431
- const keyToken = this._next();
3432
- if (keyToken.type === Type.string && keyToken.value === "/") {
3433
- const valueToken = this._next();
3434
- if (valueToken.type === Type.string) {
3435
- const breakToken = this._next();
3436
- if (breakToken.type !== Type.break) {
3437
- throw new Error("Invalid encoded CID form");
3438
- }
3439
- this.tokenBuffer.push(valueToken);
3440
- return new Token(Type.tag, 42, 0);
3441
- }
3442
- if (valueToken.type === Type.map) {
3443
- const innerKeyToken = this._next();
3444
- if (innerKeyToken.type === Type.string && innerKeyToken.value === "bytes") {
3445
- const innerValueToken = this._next();
3446
- if (innerValueToken.type === Type.string) {
3447
- for (let i = 0; i < 2; i++) {
3448
- const breakToken = this._next();
3449
- if (breakToken.type !== Type.break) {
3450
- throw new Error("Invalid encoded Bytes form");
3451
- }
3452
- }
3453
- const bytes2 = base64.decode(`m${innerValueToken.value}`);
3454
- return new Token(Type.bytes, bytes2, innerValueToken.value.length);
3455
- }
3456
- this.tokenBuffer.push(innerValueToken);
3457
- }
3458
- this.tokenBuffer.push(innerKeyToken);
3459
- }
3460
- this.tokenBuffer.push(valueToken);
3461
- }
3462
- this.tokenBuffer.push(keyToken);
3463
- }
3464
- return token;
3465
- }
3466
- };
3467
- var decodeOptions = {
3468
- allowIndefinite: false,
3469
- allowUndefined: false,
3470
- allowNaN: false,
3471
- allowInfinity: false,
3472
- allowBigInt: true,
3473
- // this will lead to BigInt for ints outside of
3474
- // safe-integer range, which may surprise users
3475
- strict: true,
3476
- useMaps: false,
3477
- rejectDuplicateMapKeys: true,
3478
- /** @type {import('cborg').TagDecoder[]} */
3479
- tags: []
3480
- };
3481
- decodeOptions.tags[42] = CID.parse;
3482
- var name = "dag-json";
3483
- var code = 297;
3484
- var encode5 = (node) => encode2(node, encodeOptions);
3485
- var decode7 = (data) => {
3486
- const options = Object.assign(decodeOptions, { tokenizer: new DagJsonTokenizer(data, decodeOptions) });
3487
- return decode2(data, options);
3488
- };
3489
- var format2 = (node) => utf8Decoder.decode(encode5(node));
3490
- var utf8Decoder = new TextDecoder();
3491
- var parse = (data) => decode7(utf8Encoder.encode(data));
3492
- var utf8Encoder = new TextEncoder();
3493
-
3494
- // ../../../node_modules/.pnpm/@noble+hashes@1.3.2/node_modules/@noble/hashes/esm/_assert.js
3495
- function bytes(b, ...lengths) {
3496
- if (!(b instanceof Uint8Array))
3497
- throw new Error("Expected Uint8Array");
3498
- if (lengths.length > 0 && !lengths.includes(b.length))
3499
- throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
3500
- }
3501
- function exists(instance, checkFinished = true) {
3502
- if (instance.destroyed)
3503
- throw new Error("Hash instance has been destroyed");
3504
- if (checkFinished && instance.finished)
3505
- throw new Error("Hash#digest() has already been called");
3506
- }
3507
- function output(out, instance) {
3508
- bytes(out);
3509
- const min = instance.outputLen;
3510
- if (out.length < min) {
3511
- throw new Error(`digestInto() expects output buffer of length at least ${min}`);
3512
- }
3513
- }
3514
-
3515
- // ../../../node_modules/.pnpm/@noble+hashes@1.3.2/node_modules/@noble/hashes/esm/utils.js
3516
- var u8a = (a) => a instanceof Uint8Array;
3517
- var createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
3518
- var rotr = (word, shift) => word << 32 - shift | word >>> shift;
3519
- var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
3520
- if (!isLE)
3521
- throw new Error("Non little-endian hardware is not supported");
3522
- function utf8ToBytes2(str) {
3523
- if (typeof str !== "string")
3524
- throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
3525
- return new Uint8Array(new TextEncoder().encode(str));
3526
- }
3527
- function toBytes(data) {
3528
- if (typeof data === "string")
3529
- data = utf8ToBytes2(data);
3530
- if (!u8a(data))
3531
- throw new Error(`expected Uint8Array, got ${typeof data}`);
3532
- return data;
3533
- }
3534
- var Hash = class {
3535
- // Safe version that clones internal state
3536
- clone() {
3537
- return this._cloneInto();
3538
- }
3539
- };
3540
- var toStr = {}.toString;
3541
- function wrapConstructor(hashCons) {
3542
- const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
3543
- const tmp = hashCons();
3544
- hashC.outputLen = tmp.outputLen;
3545
- hashC.blockLen = tmp.blockLen;
3546
- hashC.create = () => hashCons();
3547
- return hashC;
3548
- }
3549
-
3550
- // ../../../node_modules/.pnpm/@noble+hashes@1.3.2/node_modules/@noble/hashes/esm/_sha2.js
3551
- function setBigUint64(view, byteOffset, value, isLE2) {
3552
- if (typeof view.setBigUint64 === "function")
3553
- return view.setBigUint64(byteOffset, value, isLE2);
3554
- const _32n = BigInt(32);
3555
- const _u32_max = BigInt(4294967295);
3556
- const wh = Number(value >> _32n & _u32_max);
3557
- const wl = Number(value & _u32_max);
3558
- const h = isLE2 ? 4 : 0;
3559
- const l = isLE2 ? 0 : 4;
3560
- view.setUint32(byteOffset + h, wh, isLE2);
3561
- view.setUint32(byteOffset + l, wl, isLE2);
3562
- }
3563
- var SHA2 = class extends Hash {
3564
- constructor(blockLen, outputLen, padOffset, isLE2) {
3565
- super();
3566
- this.blockLen = blockLen;
3567
- this.outputLen = outputLen;
3568
- this.padOffset = padOffset;
3569
- this.isLE = isLE2;
3570
- this.finished = false;
3571
- this.length = 0;
3572
- this.pos = 0;
3573
- this.destroyed = false;
3574
- this.buffer = new Uint8Array(blockLen);
3575
- this.view = createView(this.buffer);
3576
- }
3577
- update(data) {
3578
- exists(this);
3579
- const { view, buffer: buffer2, blockLen } = this;
3580
- data = toBytes(data);
3581
- const len = data.length;
3582
- for (let pos = 0; pos < len; ) {
3583
- const take = Math.min(blockLen - this.pos, len - pos);
3584
- if (take === blockLen) {
3585
- const dataView2 = createView(data);
3586
- for (; blockLen <= len - pos; pos += blockLen)
3587
- this.process(dataView2, pos);
3588
- continue;
3589
- }
3590
- buffer2.set(data.subarray(pos, pos + take), this.pos);
3591
- this.pos += take;
3592
- pos += take;
3593
- if (this.pos === blockLen) {
3594
- this.process(view, 0);
3595
- this.pos = 0;
3596
- }
3597
- }
3598
- this.length += data.length;
3599
- this.roundClean();
3600
- return this;
3601
- }
3602
- digestInto(out) {
3603
- exists(this);
3604
- output(out, this);
3605
- this.finished = true;
3606
- const { buffer: buffer2, view, blockLen, isLE: isLE2 } = this;
3607
- let { pos } = this;
3608
- buffer2[pos++] = 128;
3609
- this.buffer.subarray(pos).fill(0);
3610
- if (this.padOffset > blockLen - pos) {
3611
- this.process(view, 0);
3612
- pos = 0;
3613
- }
3614
- for (let i = pos; i < blockLen; i++)
3615
- buffer2[i] = 0;
3616
- setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
3617
- this.process(view, 0);
3618
- const oview = createView(out);
3619
- const len = this.outputLen;
3620
- if (len % 4)
3621
- throw new Error("_sha2: outputLen should be aligned to 32bit");
3622
- const outLen = len / 4;
3623
- const state = this.get();
3624
- if (outLen > state.length)
3625
- throw new Error("_sha2: outputLen bigger than state");
3626
- for (let i = 0; i < outLen; i++)
3627
- oview.setUint32(4 * i, state[i], isLE2);
3628
- }
3629
- digest() {
3630
- const { buffer: buffer2, outputLen } = this;
3631
- this.digestInto(buffer2);
3632
- const res = buffer2.slice(0, outputLen);
3633
- this.destroy();
3634
- return res;
3635
- }
3636
- _cloneInto(to) {
3637
- to || (to = new this.constructor());
3638
- to.set(...this.get());
3639
- const { blockLen, buffer: buffer2, length: length2, finished, destroyed, pos } = this;
3640
- to.length = length2;
3641
- to.pos = pos;
3642
- to.finished = finished;
3643
- to.destroyed = destroyed;
3644
- if (length2 % blockLen)
3645
- to.buffer.set(buffer2);
3646
- return to;
3647
- }
3648
- };
3649
-
3650
- // ../../../node_modules/.pnpm/@noble+hashes@1.3.2/node_modules/@noble/hashes/esm/sha256.js
3651
- var Chi = (a, b, c) => a & b ^ ~a & c;
3652
- var Maj = (a, b, c) => a & b ^ a & c ^ b & c;
3653
- var SHA256_K = /* @__PURE__ */ new Uint32Array([
3654
- 1116352408,
3655
- 1899447441,
3656
- 3049323471,
3657
- 3921009573,
3658
- 961987163,
3659
- 1508970993,
3660
- 2453635748,
3661
- 2870763221,
3662
- 3624381080,
3663
- 310598401,
3664
- 607225278,
3665
- 1426881987,
3666
- 1925078388,
3667
- 2162078206,
3668
- 2614888103,
3669
- 3248222580,
3670
- 3835390401,
3671
- 4022224774,
3672
- 264347078,
3673
- 604807628,
3674
- 770255983,
3675
- 1249150122,
3676
- 1555081692,
3677
- 1996064986,
3678
- 2554220882,
3679
- 2821834349,
3680
- 2952996808,
3681
- 3210313671,
3682
- 3336571891,
3683
- 3584528711,
3684
- 113926993,
3685
- 338241895,
3686
- 666307205,
3687
- 773529912,
3688
- 1294757372,
3689
- 1396182291,
3690
- 1695183700,
3691
- 1986661051,
3692
- 2177026350,
3693
- 2456956037,
3694
- 2730485921,
3695
- 2820302411,
3696
- 3259730800,
3697
- 3345764771,
3698
- 3516065817,
3699
- 3600352804,
3700
- 4094571909,
3701
- 275423344,
3702
- 430227734,
3703
- 506948616,
3704
- 659060556,
3705
- 883997877,
3706
- 958139571,
3707
- 1322822218,
3708
- 1537002063,
3709
- 1747873779,
3710
- 1955562222,
3711
- 2024104815,
3712
- 2227730452,
3713
- 2361852424,
3714
- 2428436474,
3715
- 2756734187,
3716
- 3204031479,
3717
- 3329325298
3718
- ]);
3719
- var IV = /* @__PURE__ */ new Uint32Array([
3720
- 1779033703,
3721
- 3144134277,
3722
- 1013904242,
3723
- 2773480762,
3724
- 1359893119,
3725
- 2600822924,
3726
- 528734635,
3727
- 1541459225
3728
- ]);
3729
- var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
3730
- var SHA256 = class extends SHA2 {
3731
- constructor() {
3732
- super(64, 32, 8, false);
3733
- this.A = IV[0] | 0;
3734
- this.B = IV[1] | 0;
3735
- this.C = IV[2] | 0;
3736
- this.D = IV[3] | 0;
3737
- this.E = IV[4] | 0;
3738
- this.F = IV[5] | 0;
3739
- this.G = IV[6] | 0;
3740
- this.H = IV[7] | 0;
3741
- }
3742
- get() {
3743
- const { A, B, C, D, E, F, G, H } = this;
3744
- return [A, B, C, D, E, F, G, H];
3745
- }
3746
- // prettier-ignore
3747
- set(A, B, C, D, E, F, G, H) {
3748
- this.A = A | 0;
3749
- this.B = B | 0;
3750
- this.C = C | 0;
3751
- this.D = D | 0;
3752
- this.E = E | 0;
3753
- this.F = F | 0;
3754
- this.G = G | 0;
3755
- this.H = H | 0;
3756
- }
3757
- process(view, offset) {
3758
- for (let i = 0; i < 16; i++, offset += 4)
3759
- SHA256_W[i] = view.getUint32(offset, false);
3760
- for (let i = 16; i < 64; i++) {
3761
- const W15 = SHA256_W[i - 15];
3762
- const W2 = SHA256_W[i - 2];
3763
- const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
3764
- const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
3765
- SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
3766
- }
3767
- let { A, B, C, D, E, F, G, H } = this;
3768
- for (let i = 0; i < 64; i++) {
3769
- const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
3770
- const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
3771
- const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
3772
- const T2 = sigma0 + Maj(A, B, C) | 0;
3773
- H = G;
3774
- G = F;
3775
- F = E;
3776
- E = D + T1 | 0;
3777
- D = C;
3778
- C = B;
3779
- B = A;
3780
- A = T1 + T2 | 0;
3781
- }
3782
- A = A + this.A | 0;
3783
- B = B + this.B | 0;
3784
- C = C + this.C | 0;
3785
- D = D + this.D | 0;
3786
- E = E + this.E | 0;
3787
- F = F + this.F | 0;
3788
- G = G + this.G | 0;
3789
- H = H + this.H | 0;
3790
- this.set(A, B, C, D, E, F, G, H);
3791
- }
3792
- roundClean() {
3793
- SHA256_W.fill(0);
3794
- }
3795
- destroy() {
3796
- this.set(0, 0, 0, 0, 0, 0, 0, 0);
3797
- this.buffer.fill(0);
3798
- }
3799
- };
3800
- var sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
3801
-
3802
- // ../../../node_modules/.pnpm/besonders-logger@1.0.0-RC11_3myifxmc6j23mthq5k5h6wvx4a/node_modules/besonders-logger/dist/src/index.mjs
3803
- var __create2 = Object.create;
3804
- var __defProp2 = Object.defineProperty;
3805
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
3806
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
3807
- var __getProtoOf2 = Object.getPrototypeOf;
3808
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
3809
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3810
- var __commonJS2 = (cb, mod) => function __require() {
3811
- return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
3812
- };
3813
- var __copyProps2 = (to, from3, except, desc) => {
3814
- if (from3 && typeof from3 === "object" || typeof from3 === "function") {
3815
- for (let key of __getOwnPropNames2(from3))
3816
- if (!__hasOwnProp2.call(to, key) && key !== except)
3817
- __defProp2(to, key, { get: () => from3[key], enumerable: !(desc = __getOwnPropDesc2(from3, key)) || desc.enumerable });
3818
- }
3819
- return to;
3820
- };
3821
- var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
3822
- // If the importer is in node compatibility mode or this is not an ESM
3823
- // file that has been converted to a CommonJS file using a Babel-
3824
- // compatible transform (i.e. "__esModule" has not been set), then set
3825
- // "default" to the CommonJS "module.exports" for node compatibility.
3826
- isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
3827
- mod
3828
- ));
3829
- var __publicField = (obj, key, value) => {
3830
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
3831
- return value;
3832
- };
3833
- var require_lib = __commonJS2({
3834
- "../../node_modules/.pnpm/browser-or-node@2.1.1/node_modules/browser-or-node/lib/index.js"(exports) {
3835
- "use strict";
3836
- Object.defineProperty(exports, "__esModule", {
3837
- value: true
3838
- });
3839
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
3840
- return typeof obj;
3841
- } : function(obj) {
3842
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
3843
- };
3844
- var isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined";
3845
- var isNode2 = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
3846
- var isWebWorker = (typeof self === "undefined" ? "undefined" : _typeof(self)) === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope";
3847
- var isJsDom = typeof window !== "undefined" && window.name === "nodejs" || typeof navigator !== "undefined" && (navigator.userAgent.includes("Node.js") || navigator.userAgent.includes("jsdom"));
3848
- var isDeno = typeof Deno !== "undefined" && typeof Deno.version !== "undefined" && typeof Deno.version.deno !== "undefined";
3849
- exports.isBrowser = isBrowser2;
3850
- exports.isWebWorker = isWebWorker;
3851
- exports.isNode = isNode2;
3852
- exports.isJsDom = isJsDom;
3853
- exports.isDeno = isDeno;
3854
- }
3855
- });
3856
- var require_fast_json_stable_stringify = __commonJS2({
3857
- "../../node_modules/.pnpm/fast-json-stable-stringify@2.1.0/node_modules/fast-json-stable-stringify/index.js"(exports, module) {
3858
- "use strict";
3859
- module.exports = function(data, opts) {
3860
- if (!opts)
3861
- opts = {};
3862
- if (typeof opts === "function")
3863
- opts = { cmp: opts };
3864
- var cycles = typeof opts.cycles === "boolean" ? opts.cycles : false;
3865
- var cmp = opts.cmp && /* @__PURE__ */ function(f) {
3866
- return function(node) {
3867
- return function(a, b) {
3868
- var aobj = { key: a, value: node[a] };
3869
- var bobj = { key: b, value: node[b] };
3870
- return f(aobj, bobj);
3871
- };
3872
- };
3873
- }(opts.cmp);
3874
- var seen = [];
3875
- return function stringify2(node) {
3876
- if (node && node.toJSON && typeof node.toJSON === "function") {
3877
- node = node.toJSON();
3878
- }
3879
- if (node === void 0)
3880
- return;
3881
- if (typeof node == "number")
3882
- return isFinite(node) ? "" + node : "null";
3883
- if (typeof node !== "object")
3884
- return JSON.stringify(node);
3885
- var i, out;
3886
- if (Array.isArray(node)) {
3887
- out = "[";
3888
- for (i = 0; i < node.length; i++) {
3889
- if (i)
3890
- out += ",";
3891
- out += stringify2(node[i]) || "null";
3892
- }
3893
- return out + "]";
3894
- }
3895
- if (node === null)
3896
- return "null";
3897
- if (seen.indexOf(node) !== -1) {
3898
- if (cycles)
3899
- return JSON.stringify("__cycle__");
3900
- throw new TypeError("Converting circular structure to JSON");
3901
- }
3902
- var seenIndex = seen.push(node) - 1;
3903
- var keys = Object.keys(node).sort(cmp && cmp(node));
3904
- out = "";
3905
- for (i = 0; i < keys.length; i++) {
3906
- var key = keys[i];
3907
- var value = stringify2(node[key]);
3908
- if (!value)
3909
- continue;
3910
- if (out)
3911
- out += ",";
3912
- out += JSON.stringify(key) + ":" + value;
3913
- }
3914
- seen.splice(seenIndex, 1);
3915
- return "{" + out + "}";
3916
- }(data);
3917
- };
3918
- }
3919
- });
3920
- var import_browser_or_node = __toESM2(require_lib(), 1);
3921
- var import_fast_json_stable_stringify = __toESM2(require_fast_json_stable_stringify(), 1);
3922
- var TIME_PREFIX_ENABLED = false;
3923
- var PERFORMANCE_PREFIX_ENABLED = false;
3924
- if (import_browser_or_node.isNode) {
3925
- if (process?.env?.LOGGER_TIME_PREFIX)
3926
- TIME_PREFIX_ENABLED = process?.env?.LOGGER_TIME_PREFIX === "true";
3927
- if (process?.env?.LOGGER_PERF_PREFIX)
3928
- PERFORMANCE_PREFIX_ENABLED = process?.env?.LOGGER_PERF_PREFIX === "true";
3929
- }
3930
- var DEFAULT_CONFIG = Object.freeze({
3931
- prefix: void 0,
3932
- time: TIME_PREFIX_ENABLED,
3933
- delta: PERFORMANCE_PREFIX_ENABLED,
3934
- dimDebugOnServer: true,
3935
- printOriginOnServer: true,
3936
- serverInspectOptions: {},
3937
- customFormattersOnServer: true,
3938
- // Depth of stacktrace to show on server
3939
- // - integer saying how many lines
3940
- // - false to disable, true for all
3941
- printStackLinesOnServer: false,
3942
- dim: true
3943
- });
3944
- var StringFormatters = [
3945
- // Format to string (Client console - currently not on server)
3946
- // {
3947
- // match: obj => obj instanceof Model,
3948
- // format: m => {
3949
- // const { displayName } = m
3950
- // return `${m.constructor.name}#${m.ID}${displayName ? `{${displayName}}` : ''}`
3951
- // },
3952
- // },
3953
- ];
3954
- var LoggerTime = class {
3955
- sinceFirst = 0;
3956
- sinceLast = 0;
3957
- time = false;
3958
- delta = false;
3959
- constructor(sinceFirst, sinceLast, time, delta) {
3960
- Object.assign(this, { sinceFirst, sinceLast, time, delta });
3961
- }
3962
- toString() {
3963
- const sinceFirstNum = this.sinceFirst * 1e-3;
3964
- const sinceFirst = sinceFirstNum.toFixed(sinceFirstNum < 5 ? 2 : 1);
3965
- const sinceLast = this.sinceLast < 1e3 ? `${this.sinceLast.toFixed(0)}`.padStart(5, " ") : `${`${(this.sinceLast * 1e-3).toFixed(this.sinceLast < 1e4 ? 1 : 0)}`.padStart(4, " ")}s`;
3966
- return `[${[this.time ? sinceFirst : null, this.delta ? sinceLast : null].join(",")}]`;
3967
- }
3968
- };
3969
- var Style = class {
3970
- constructor(style, string) {
3971
- Object.assign(this, { style, string });
3972
- }
3973
- };
3974
- var formattersEnabled = false;
3975
- var _Logger = class {
3976
- /**
3977
- * This is a clever way to log without the extra check on each log line.
3978
- * Use it like this:
3979
- * ```
3980
- * const { WARN, LOG, DEBUG, VERBOSE } = Logger.setup(Logger.INFO); // eslint-disable-line no-unused-vars
3981
- * LOG('message', data);
3982
- * DEBUG(this.collectionName, '...')
3983
- * if (!VERBOSE.isDisabled) {
3984
- * const verboseStuff = generateVerboseStuff(); // computationally intensive
3985
- * VERBOSE('Here it is:', verboseStuff)
3986
- * }
3987
- * ```
3988
- *
3989
- * @ param {number} level See {@link LVs}
3990
- * @ param {object} config see DEFAULT_CONFIG
3991
- * @ typedef {Function & {isDisabled: boolean, isEnabled: boolean, ...}} LogFunc
3992
- * @ returns {{LOG: LogFunc, VERBOSE: LogFunc, DEBUG: LogFunc, WARN: LogFunc, ERROR: LogFunc}}
3993
- */
3994
- static setup(level = _Logger.INFO, config = {}) {
3995
- config = Object.assign({}, DEFAULT_CONFIG, config);
3996
- if (level > 10)
3997
- console.debug("setup logger", { config });
3998
- const debugLogForStub = this.wrapLog(console.debug, { ...config, dim: config.dimDebugOnServer });
3999
- const stub = (...args) => {
4000
- if (window?.FORCE_DISABLE_LOGLEVEL)
4001
- debugLogForStub(...args);
4002
- };
4003
- stub.isDisabled = true;
4004
- stub.isEnabled = false;
4005
- const groupCollapsed = this.wrapLog(console.groupCollapsed, config);
4006
- const addExtraFxs = (enabled, func) => {
4007
- function group(...args) {
4008
- const functionToWrap = args[args.length - 1];
4009
- if (functionToWrap === stub)
4010
- return functionToWrap();
4011
- groupCollapsed(...args.slice(0, -1));
4012
- const asyncWrapper = async () => {
4013
- try {
4014
- const result = functionToWrap();
4015
- return result instanceof Promise ? await result : result;
4016
- } finally {
4017
- console.groupEnd();
4018
- }
4019
- };
4020
- return asyncWrapper();
4021
- }
4022
- const realFunc = Object.assign(
4023
- func.bind({}),
4024
- // clone function - https://stackoverflow.com/a/6772648
4025
- {
4026
- isEnabled: enabled,
4027
- isDisabled: !enabled,
4028
- group,
4029
- force: func
4030
- }
4031
- );
4032
- if (enabled) {
4033
- return realFunc;
4034
- } else {
4035
- return Object.assign(
4036
- stub.bind({}),
4037
- // clone stub function - https://stackoverflow.com/a/6772648
4038
- {
4039
- isEnabled: enabled,
4040
- isDisabled: !enabled,
4041
- group,
4042
- force: realFunc
4043
- }
4044
- );
4045
- }
4046
- };
4047
- const ERRFX = addExtraFxs(level >= _Logger.ERROR, this.wrapLog(console.error, config));
4048
- const ERROR2 = (...params) => {
4049
- ERRFX(...params);
4050
- return new Error((0, import_fast_json_stable_stringify.default)(params));
4051
- };
4052
- return {
4053
- ERROR: ERROR2,
4054
- WARN: addExtraFxs(level >= _Logger.WARN, this.wrapLog(console.warn, config)),
4055
- LOG: addExtraFxs(level >= _Logger.INFO, this.wrapLog(console.log, config)),
4056
- DEBUG: addExtraFxs(level >= _Logger.DEBUG, this.wrapLog(console.log, { ...config, dim: config.dimDebugOnServer })),
4057
- // not using console.debug as that requires dev tools verbose to be enabled
4058
- VERBOSE: addExtraFxs(level >= _Logger.VERBOSE, this.wrapLog(console.debug, { ...config, dim: config.dimDebugOnServer }))
4059
- };
4060
- }
4061
- static wrapLog(logFunc, config) {
4062
- if (!import_browser_or_node.isNode) {
4063
- const fixedArgs = [];
4064
- if (config.time || config.delta) {
4065
- const isChrome = import_browser_or_node.isBrowser && navigator.userAgent.includes("Chrome");
4066
- const p = isChrome ? ["", _Logger.timeStr(!!config.time, !!config.delta)] : [];
4067
- fixedArgs.push(...p);
4068
- }
4069
- if (config.prefix) {
4070
- if (formattersEnabled)
4071
- fixedArgs.push(new Style("dim", config.prefix));
4072
- else
4073
- fixedArgs.push(config.prefix);
4074
- }
4075
- return logFunc.bind(console, ...fixedArgs);
4076
- } else {
4077
- return logFunc.bind(console);
4078
- }
4079
- }
4080
- // static log(msg, logPerformance = true) {
4081
- // const p = this.perf();
4082
- // return logPerformance ? `${p} ${msg}` : msg;
4083
- // }
4084
- static timeStr(time, delta, returnAsString = 0) {
4085
- if (!performance.now)
4086
- return void 0;
4087
- const now = performance.now();
4088
- if (!_Logger.firstLog) {
4089
- _Logger.firstLog = now;
4090
- _Logger.lastLog = now;
4091
- }
4092
- const p = new LoggerTime(now - _Logger.firstLog, now - _Logger.lastLog, time, delta);
4093
- _Logger.lastLog = now;
4094
- return returnAsString ? p.toString() : p;
4095
- }
4096
- // (for nodejs) ~ https://stackoverflow.com/a/47296370/1633985
4097
- static getOriginFromStack(stack) {
4098
- let skippedFirst = false;
4099
- for (const line of stack.split("\n")) {
4100
- const matches = line.match(/^\s+at\s+(.*)/);
4101
- if (matches) {
4102
- if (skippedFirst) {
4103
- return matches[1].trim().replace(__dirname, "");
4104
- }
4105
- skippedFirst = true;
4106
- }
4107
- }
4108
- }
4109
- };
4110
- var Logger = _Logger;
4111
- __publicField(Logger, "ERROR", 2);
4112
- __publicField(Logger, "WARN", 4);
4113
- __publicField(Logger, "INFO", 6);
4114
- __publicField(Logger, "LOG", 6);
4115
- __publicField(Logger, "DEBUG", 8);
4116
- __publicField(Logger, "VERBOSE", 10);
4117
- __publicField(Logger, "firstLog", 0);
4118
- __publicField(Logger, "lastLog", 0);
4119
- if (import_browser_or_node.isBrowser) {
4120
- window.devtoolsFormatters = window.devtoolsFormatters ?? [];
4121
- window.devtoolsFormatters.push(
4122
- {
4123
- // Custom formatters
4124
- header: (obj) => {
4125
- if (StringFormatters && StringFormatters.length) {
4126
- for (const formatter of StringFormatters) {
4127
- if (formatter.match(obj))
4128
- return ["span", {}, formatter.format(obj)];
4129
- }
4130
- }
4131
- return null;
4132
- },
4133
- hasBody: () => true
4134
- },
4135
- {
4136
- // Performance object //
4137
- // This is a sneaky way to show performance info withouth any extra calls when logging:
4138
- // LOG(`...`)
4139
- // it would work without this if we would have some way to intercept the call:
4140
- // L.INFO('...') - a getter on L that adds the current time as prefix
4141
- // LOG('...')() - returns the log function with all argumends bound
4142
- // But instead we are adding a custom formatter that replaced the placeholder object of class P with the performance info
4143
- header: (obj) => {
4144
- if (!(obj instanceof LoggerTime))
4145
- return null;
4146
- if (!formattersEnabled)
4147
- formattersEnabled = true;
4148
- const p = Logger.timeStr(obj.time, obj.delta);
4149
- return [
4150
- "span",
4151
- { style: "font-weight: light; color: grey" },
4152
- p?.toString()
4153
- // ['a', { href: 'vscodium://file/home/manu/dev/tamera/bookr/imports/lib/utils/Logger.js' }, 'WOW'],
4154
- ];
4155
- },
4156
- hasBody: () => false
4157
- },
4158
- {
4159
- // Style object
4160
- header: (obj) => {
4161
- if (!(obj instanceof Style))
4162
- return null;
4163
- if (!formattersEnabled)
4164
- formattersEnabled = true;
4165
- return ["span", {
4166
- style: "font-weight: light; color: grey; "
4167
- /* font-style: italic; */
4168
- }, obj.string];
4169
- },
4170
- hasBody: () => false
4171
- }
4172
- );
4173
- } else if (import_browser_or_node.isNode) {
4174
- }
4175
-
4176
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/block.js
4177
- function readonly({ enumerable = true, configurable = false } = {}) {
4178
- return { enumerable, configurable, writable: false };
4179
- }
4180
- function* linksWithin(path, value) {
4181
- if (value != null && typeof value === "object") {
4182
- if (Array.isArray(value)) {
4183
- for (const [index, element] of value.entries()) {
4184
- const elementPath = [...path, index];
4185
- const cid = CID.asCID(element);
4186
- if (cid) {
4187
- yield [elementPath.join("/"), cid];
4188
- } else if (typeof element === "object") {
4189
- yield* links(element, elementPath);
4190
- }
4191
- }
4192
- } else {
4193
- const cid = CID.asCID(value);
4194
- if (cid) {
4195
- yield [path.join("/"), cid];
4196
- } else {
4197
- yield* links(value, path);
4198
- }
4199
- }
4200
- }
4201
- }
4202
- function* links(source, base2) {
4203
- if (source == null || source instanceof Uint8Array) {
4204
- return;
4205
- }
4206
- const cid = CID.asCID(source);
4207
- if (cid) {
4208
- yield [base2.join("/"), cid];
4209
- }
4210
- for (const [key, value] of Object.entries(source)) {
4211
- const path = (
4212
- /** @type {[string|number, string]} */
4213
- [...base2, key]
4214
- );
4215
- yield* linksWithin(path, value);
4216
- }
4217
- }
4218
- function* treeWithin(path, value) {
4219
- if (Array.isArray(value)) {
4220
- for (const [index, element] of value.entries()) {
4221
- const elementPath = [...path, index];
4222
- yield elementPath.join("/");
4223
- if (typeof element === "object" && !CID.asCID(element)) {
4224
- yield* tree(element, elementPath);
4225
- }
4226
- }
4227
- } else {
4228
- yield* tree(value, path);
4229
- }
4230
- }
4231
- function* tree(source, base2) {
4232
- if (source == null || typeof source !== "object") {
4233
- return;
4234
- }
4235
- for (const [key, value] of Object.entries(source)) {
4236
- const path = (
4237
- /** @type {[string|number, string]} */
4238
- [...base2, key]
4239
- );
4240
- yield path.join("/");
4241
- if (value != null && !(value instanceof Uint8Array) && typeof value === "object" && !CID.asCID(value)) {
4242
- yield* treeWithin(path, value);
4243
- }
4244
- }
4245
- }
4246
- function get(source, path) {
4247
- let node = (
4248
- /** @type {Record<string, any>} */
4249
- source
4250
- );
4251
- for (const [index, key] of path.entries()) {
4252
- node = node[key];
4253
- if (node == null) {
4254
- throw new Error(`Object has no property at ${path.slice(0, index + 1).map((part) => `[${JSON.stringify(part)}]`).join("")}`);
4255
- }
4256
- const cid = CID.asCID(node);
4257
- if (cid) {
4258
- return { value: cid, remaining: path.slice(index + 1).join("/") };
4259
- }
4260
- }
4261
- return { value: node };
4262
- }
4263
- var Block = class {
4264
- /**
4265
- * @param {object} options
4266
- * @param {CID<T, C, A, V>} options.cid
4267
- * @param {API.ByteView<T>} options.bytes
4268
- * @param {T} options.value
4269
- */
4270
- constructor({ cid, bytes: bytes2, value }) {
4271
- if (!cid || !bytes2 || typeof value === "undefined") {
4272
- throw new Error("Missing required argument");
4273
- }
4274
- this.cid = cid;
4275
- this.bytes = bytes2;
4276
- this.value = value;
4277
- this.asBlock = this;
4278
- Object.defineProperties(this, {
4279
- cid: readonly(),
4280
- bytes: readonly(),
4281
- value: readonly(),
4282
- asBlock: readonly()
4283
- });
4284
- }
4285
- links() {
4286
- return links(this.value, []);
4287
- }
4288
- tree() {
4289
- return tree(this.value, []);
4290
- }
4291
- /**
4292
- *
4293
- * @param {string} [path]
4294
- * @returns {API.BlockCursorView<unknown>}
4295
- */
4296
- get(path = "/") {
4297
- return get(this.value, path.split("/").filter(Boolean));
4298
- }
4299
- };
4300
- async function encode6({ value, codec, hasher }) {
4301
- if (typeof value === "undefined")
4302
- throw new Error('Missing required argument "value"');
4303
- if (!codec || !hasher)
4304
- throw new Error("Missing required argument: codec or hasher");
4305
- const bytes2 = codec.encode(value);
4306
- const hash = await hasher.digest(bytes2);
4307
- const cid = CID.create(
4308
- 1,
4309
- codec.code,
4310
- hash
4311
- );
4312
- return new Block({ value, bytes: bytes2, cid });
4313
- }
4314
-
4315
- // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/hashes/sha2-browser.js
4316
- var sha = (name2) => (
4317
- /**
4318
- * @param {Uint8Array} data
4319
- */
4320
- async (data) => new Uint8Array(await crypto.subtle.digest(name2, data))
4321
- );
4322
- var sha2562 = from2({
4323
- name: "sha2-256",
4324
- code: 18,
4325
- encode: sha("SHA-256")
4326
- });
4327
- var sha512 = from2({
4328
- name: "sha2-512",
4329
- code: 19,
4330
- encode: sha("SHA-512")
4331
- });
4332
-
4333
- // src/ipfs/ipfs-utils.ts
4334
- var { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.INFO);
4335
- function prepareForPub(log, without = ["cid"]) {
4336
- const logWithout = {};
4337
- for (let [key, val] of Object.entries(log)) {
4338
- if (val === void 0) {
4339
- WARN(`log.${key} is undefined, which is not allowed - encoding as null`, log);
4340
- val = null;
4341
- }
4342
- if (!without.includes(key)) {
4343
- logWithout[key] = val && key === "pv" ? CID.parse(val) : val;
4344
- } else {
4345
- VERBOSE("excluding app log", { key, val });
4346
- }
4347
- }
4348
- return logWithout;
4349
- }
4350
- function encodeApplogAndGetCid(log) {
4351
- return getCidSync(encodeApplog(log).bytes);
4352
- }
4353
- function encodeApplog(log) {
4354
- return encodeBlock(prepareForPub(log));
4355
- }
4356
- function getCidSync(bytes2) {
4357
- const hash = sha256(bytes2);
4358
- const digest = digest_exports.create(sha2562.code, hash);
4359
- const cid = CID.create(1, code, digest);
4360
- VERBOSE(`[getCidSync]`, { bytes: bytes2, hash, digest, cid });
4361
- return cid;
4362
- }
4363
- function encodeBlock(jsonObject) {
4364
- DEBUG("[encodeBlock]", jsonObject);
4365
- const byteView = encode5(jsonObject);
4366
- return { bytes: byteView, cid: getCidSync(byteView) };
4367
- }
4368
- async function encodeBlockOriginal(jsonObject) {
4369
- const encoded = await encode6({ value: jsonObject, codec: src_exports, hasher: sha2562 });
4370
- const syncVariant = encodeBlock(jsonObject);
4371
- if (syncVariant.cid.toString() !== encoded.cid.toString()) {
4372
- ERROR(`[encodeBlockOriginal] sync cid mismatch`, { jsonObject, encoded, syncVariant });
4373
- }
4374
- return encoded;
4375
- }
4376
-
4377
- export {
4378
- __commonJS,
4379
- __toESM,
4380
- Logger,
4381
- Type,
4382
- Token,
4383
- makeCborEncoders,
4384
- encode,
4385
- decode,
4386
- decode6 as decode2,
4387
- CID,
4388
- decode7 as decode3,
4389
- prepareForPub,
4390
- encodeApplogAndGetCid,
4391
- encodeApplog,
4392
- getCidSync,
4393
- encodeBlock,
4394
- encodeBlockOriginal
4395
- };
4396
- /*! Bundled license information:
4397
-
4398
- @noble/hashes/esm/utils.js:
4399
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
4400
- */
4401
- //# sourceMappingURL=chunk-WOD425XV.min.js.map