@fireproof/core 0.10.0-dev → 0.10.1-dev

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