@fireproof/core 0.10.0-dev → 0.10.2-dev

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