@wovin/connect-nftstorage 0.0.3-RC1 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1485 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined")
11
+ return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from2, except, desc) => {
22
+ if (from2 && typeof from2 === "object" || typeof from2 === "function") {
23
+ for (let key of __getOwnPropNames(from2))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+
38
+ // ../../../node_modules/.pnpm/besonders-logger@1.0.0-RC11_3myifxmc6j23mthq5k5h6wvx4a/node_modules/besonders-logger/dist/src/index.mjs
39
+ var __create2 = Object.create;
40
+ var __defProp2 = Object.defineProperty;
41
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
42
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
43
+ var __getProtoOf2 = Object.getPrototypeOf;
44
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
45
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
46
+ var __commonJS2 = (cb, mod) => function __require2() {
47
+ return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
48
+ };
49
+ var __copyProps2 = (to, from2, except, desc) => {
50
+ if (from2 && typeof from2 === "object" || typeof from2 === "function") {
51
+ for (let key of __getOwnPropNames2(from2))
52
+ if (!__hasOwnProp2.call(to, key) && key !== except)
53
+ __defProp2(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc2(from2, key)) || desc.enumerable });
54
+ }
55
+ return to;
56
+ };
57
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
58
+ // If the importer is in node compatibility mode or this is not an ESM
59
+ // file that has been converted to a CommonJS file using a Babel-
60
+ // compatible transform (i.e. "__esModule" has not been set), then set
61
+ // "default" to the CommonJS "module.exports" for node compatibility.
62
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
63
+ mod
64
+ ));
65
+ var __publicField = (obj, key, value) => {
66
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
67
+ return value;
68
+ };
69
+ var require_lib = __commonJS2({
70
+ "../../node_modules/.pnpm/browser-or-node@2.1.1/node_modules/browser-or-node/lib/index.js"(exports) {
71
+ "use strict";
72
+ Object.defineProperty(exports, "__esModule", {
73
+ value: true
74
+ });
75
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
76
+ return typeof obj;
77
+ } : function(obj) {
78
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
79
+ };
80
+ var isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined";
81
+ var isNode2 = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
82
+ var isWebWorker = (typeof self === "undefined" ? "undefined" : _typeof(self)) === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope";
83
+ var isJsDom = typeof window !== "undefined" && window.name === "nodejs" || typeof navigator !== "undefined" && (navigator.userAgent.includes("Node.js") || navigator.userAgent.includes("jsdom"));
84
+ var isDeno = typeof Deno !== "undefined" && typeof Deno.version !== "undefined" && typeof Deno.version.deno !== "undefined";
85
+ exports.isBrowser = isBrowser2;
86
+ exports.isWebWorker = isWebWorker;
87
+ exports.isNode = isNode2;
88
+ exports.isJsDom = isJsDom;
89
+ exports.isDeno = isDeno;
90
+ }
91
+ });
92
+ var require_fast_json_stable_stringify = __commonJS2({
93
+ "../../node_modules/.pnpm/fast-json-stable-stringify@2.1.0/node_modules/fast-json-stable-stringify/index.js"(exports, module) {
94
+ "use strict";
95
+ module.exports = function(data, opts) {
96
+ if (!opts)
97
+ opts = {};
98
+ if (typeof opts === "function")
99
+ opts = { cmp: opts };
100
+ var cycles = typeof opts.cycles === "boolean" ? opts.cycles : false;
101
+ var cmp = opts.cmp && /* @__PURE__ */ function(f) {
102
+ return function(node) {
103
+ return function(a, b) {
104
+ var aobj = { key: a, value: node[a] };
105
+ var bobj = { key: b, value: node[b] };
106
+ return f(aobj, bobj);
107
+ };
108
+ };
109
+ }(opts.cmp);
110
+ var seen = [];
111
+ return function stringify2(node) {
112
+ if (node && node.toJSON && typeof node.toJSON === "function") {
113
+ node = node.toJSON();
114
+ }
115
+ if (node === void 0)
116
+ return;
117
+ if (typeof node == "number")
118
+ return isFinite(node) ? "" + node : "null";
119
+ if (typeof node !== "object")
120
+ return JSON.stringify(node);
121
+ var i, out;
122
+ if (Array.isArray(node)) {
123
+ out = "[";
124
+ for (i = 0; i < node.length; i++) {
125
+ if (i)
126
+ out += ",";
127
+ out += stringify2(node[i]) || "null";
128
+ }
129
+ return out + "]";
130
+ }
131
+ if (node === null)
132
+ return "null";
133
+ if (seen.indexOf(node) !== -1) {
134
+ if (cycles)
135
+ return JSON.stringify("__cycle__");
136
+ throw new TypeError("Converting circular structure to JSON");
137
+ }
138
+ var seenIndex = seen.push(node) - 1;
139
+ var keys = Object.keys(node).sort(cmp && cmp(node));
140
+ out = "";
141
+ for (i = 0; i < keys.length; i++) {
142
+ var key = keys[i];
143
+ var value = stringify2(node[key]);
144
+ if (!value)
145
+ continue;
146
+ if (out)
147
+ out += ",";
148
+ out += JSON.stringify(key) + ":" + value;
149
+ }
150
+ seen.splice(seenIndex, 1);
151
+ return "{" + out + "}";
152
+ }(data);
153
+ };
154
+ }
155
+ });
156
+ var import_browser_or_node = __toESM2(require_lib(), 1);
157
+ var import_fast_json_stable_stringify = __toESM2(require_fast_json_stable_stringify(), 1);
158
+ var TIME_PREFIX_ENABLED = false;
159
+ var PERFORMANCE_PREFIX_ENABLED = false;
160
+ if (import_browser_or_node.isNode) {
161
+ if (process?.env?.LOGGER_TIME_PREFIX)
162
+ TIME_PREFIX_ENABLED = process?.env?.LOGGER_TIME_PREFIX === "true";
163
+ if (process?.env?.LOGGER_PERF_PREFIX)
164
+ PERFORMANCE_PREFIX_ENABLED = process?.env?.LOGGER_PERF_PREFIX === "true";
165
+ }
166
+ var DEFAULT_CONFIG = Object.freeze({
167
+ prefix: void 0,
168
+ time: TIME_PREFIX_ENABLED,
169
+ delta: PERFORMANCE_PREFIX_ENABLED,
170
+ dimDebugOnServer: true,
171
+ printOriginOnServer: true,
172
+ serverInspectOptions: {},
173
+ customFormattersOnServer: true,
174
+ // Depth of stacktrace to show on server
175
+ // - integer saying how many lines
176
+ // - false to disable, true for all
177
+ printStackLinesOnServer: false,
178
+ dim: true
179
+ });
180
+ var StringFormatters = [
181
+ // Format to string (Client console - currently not on server)
182
+ // {
183
+ // match: obj => obj instanceof Model,
184
+ // format: m => {
185
+ // const { displayName } = m
186
+ // return `${m.constructor.name}#${m.ID}${displayName ? `{${displayName}}` : ''}`
187
+ // },
188
+ // },
189
+ ];
190
+ var LoggerTime = class {
191
+ sinceFirst = 0;
192
+ sinceLast = 0;
193
+ time = false;
194
+ delta = false;
195
+ constructor(sinceFirst, sinceLast, time, delta) {
196
+ Object.assign(this, { sinceFirst, sinceLast, time, delta });
197
+ }
198
+ toString() {
199
+ const sinceFirstNum = this.sinceFirst * 1e-3;
200
+ const sinceFirst = sinceFirstNum.toFixed(sinceFirstNum < 5 ? 2 : 1);
201
+ const sinceLast = this.sinceLast < 1e3 ? `${this.sinceLast.toFixed(0)}`.padStart(5, " ") : `${`${(this.sinceLast * 1e-3).toFixed(this.sinceLast < 1e4 ? 1 : 0)}`.padStart(4, " ")}s`;
202
+ return `[${[this.time ? sinceFirst : null, this.delta ? sinceLast : null].join(",")}]`;
203
+ }
204
+ };
205
+ var Style = class {
206
+ constructor(style, string) {
207
+ Object.assign(this, { style, string });
208
+ }
209
+ };
210
+ var formattersEnabled = false;
211
+ var _Logger = class {
212
+ /**
213
+ * This is a clever way to log without the extra check on each log line.
214
+ * Use it like this:
215
+ * ```
216
+ * const { WARN, LOG, DEBUG, VERBOSE } = Logger.setup(Logger.INFO); // eslint-disable-line no-unused-vars
217
+ * LOG('message', data);
218
+ * DEBUG(this.collectionName, '...')
219
+ * if (!VERBOSE.isDisabled) {
220
+ * const verboseStuff = generateVerboseStuff(); // computationally intensive
221
+ * VERBOSE('Here it is:', verboseStuff)
222
+ * }
223
+ * ```
224
+ *
225
+ * @ param {number} level See {@link LVs}
226
+ * @ param {object} config see DEFAULT_CONFIG
227
+ * @ typedef {Function & {isDisabled: boolean, isEnabled: boolean, ...}} LogFunc
228
+ * @ returns {{LOG: LogFunc, VERBOSE: LogFunc, DEBUG: LogFunc, WARN: LogFunc, ERROR: LogFunc}}
229
+ */
230
+ static setup(level = _Logger.INFO, config = {}) {
231
+ config = Object.assign({}, DEFAULT_CONFIG, config);
232
+ if (level > 10)
233
+ console.debug("setup logger", { config });
234
+ const debugLogForStub = this.wrapLog(console.debug, { ...config, dim: config.dimDebugOnServer });
235
+ const stub = (...args) => {
236
+ if (window?.FORCE_DISABLE_LOGLEVEL)
237
+ debugLogForStub(...args);
238
+ };
239
+ stub.isDisabled = true;
240
+ stub.isEnabled = false;
241
+ const groupCollapsed = this.wrapLog(console.groupCollapsed, config);
242
+ const addExtraFxs = (enabled, func) => {
243
+ function group(...args) {
244
+ const functionToWrap = args[args.length - 1];
245
+ if (functionToWrap === stub)
246
+ return functionToWrap();
247
+ groupCollapsed(...args.slice(0, -1));
248
+ const asyncWrapper = async () => {
249
+ try {
250
+ const result = functionToWrap();
251
+ return result instanceof Promise ? await result : result;
252
+ } finally {
253
+ console.groupEnd();
254
+ }
255
+ };
256
+ return asyncWrapper();
257
+ }
258
+ const realFunc = Object.assign(
259
+ func.bind({}),
260
+ // clone function - https://stackoverflow.com/a/6772648
261
+ {
262
+ isEnabled: enabled,
263
+ isDisabled: !enabled,
264
+ group,
265
+ force: func
266
+ }
267
+ );
268
+ if (enabled) {
269
+ return realFunc;
270
+ } else {
271
+ return Object.assign(
272
+ stub.bind({}),
273
+ // clone stub function - https://stackoverflow.com/a/6772648
274
+ {
275
+ isEnabled: enabled,
276
+ isDisabled: !enabled,
277
+ group,
278
+ force: realFunc
279
+ }
280
+ );
281
+ }
282
+ };
283
+ const ERRFX = addExtraFxs(level >= _Logger.ERROR, this.wrapLog(console.error, config));
284
+ const ERROR = (...params) => {
285
+ ERRFX(...params);
286
+ return new Error((0, import_fast_json_stable_stringify.default)(params));
287
+ };
288
+ return {
289
+ ERROR,
290
+ WARN: addExtraFxs(level >= _Logger.WARN, this.wrapLog(console.warn, config)),
291
+ LOG: addExtraFxs(level >= _Logger.INFO, this.wrapLog(console.log, config)),
292
+ DEBUG: addExtraFxs(level >= _Logger.DEBUG, this.wrapLog(console.log, { ...config, dim: config.dimDebugOnServer })),
293
+ // not using console.debug as that requires dev tools verbose to be enabled
294
+ VERBOSE: addExtraFxs(level >= _Logger.VERBOSE, this.wrapLog(console.debug, { ...config, dim: config.dimDebugOnServer }))
295
+ };
296
+ }
297
+ static wrapLog(logFunc, config) {
298
+ if (!import_browser_or_node.isNode) {
299
+ const fixedArgs = [];
300
+ if (config.time || config.delta) {
301
+ const isChrome = import_browser_or_node.isBrowser && navigator.userAgent.includes("Chrome");
302
+ const p = isChrome ? ["", _Logger.timeStr(!!config.time, !!config.delta)] : [];
303
+ fixedArgs.push(...p);
304
+ }
305
+ if (config.prefix) {
306
+ if (formattersEnabled)
307
+ fixedArgs.push(new Style("dim", config.prefix));
308
+ else
309
+ fixedArgs.push(config.prefix);
310
+ }
311
+ return logFunc.bind(console, ...fixedArgs);
312
+ } else {
313
+ return logFunc.bind(console);
314
+ }
315
+ }
316
+ // static log(msg, logPerformance = true) {
317
+ // const p = this.perf();
318
+ // return logPerformance ? `${p} ${msg}` : msg;
319
+ // }
320
+ static timeStr(time, delta, returnAsString = 0) {
321
+ if (!performance.now)
322
+ return void 0;
323
+ const now = performance.now();
324
+ if (!_Logger.firstLog) {
325
+ _Logger.firstLog = now;
326
+ _Logger.lastLog = now;
327
+ }
328
+ const p = new LoggerTime(now - _Logger.firstLog, now - _Logger.lastLog, time, delta);
329
+ _Logger.lastLog = now;
330
+ return returnAsString ? p.toString() : p;
331
+ }
332
+ // (for nodejs) ~ https://stackoverflow.com/a/47296370/1633985
333
+ static getOriginFromStack(stack) {
334
+ let skippedFirst = false;
335
+ for (const line of stack.split("\n")) {
336
+ const matches = line.match(/^\s+at\s+(.*)/);
337
+ if (matches) {
338
+ if (skippedFirst) {
339
+ return matches[1].trim().replace(__dirname, "");
340
+ }
341
+ skippedFirst = true;
342
+ }
343
+ }
344
+ }
345
+ };
346
+ var Logger = _Logger;
347
+ __publicField(Logger, "ERROR", 2);
348
+ __publicField(Logger, "WARN", 4);
349
+ __publicField(Logger, "INFO", 6);
350
+ __publicField(Logger, "LOG", 6);
351
+ __publicField(Logger, "DEBUG", 8);
352
+ __publicField(Logger, "VERBOSE", 10);
353
+ __publicField(Logger, "firstLog", 0);
354
+ __publicField(Logger, "lastLog", 0);
355
+ if (import_browser_or_node.isBrowser) {
356
+ window.devtoolsFormatters = window.devtoolsFormatters ?? [];
357
+ window.devtoolsFormatters.push(
358
+ {
359
+ // Custom formatters
360
+ header: (obj) => {
361
+ if (StringFormatters && StringFormatters.length) {
362
+ for (const formatter of StringFormatters) {
363
+ if (formatter.match(obj))
364
+ return ["span", {}, formatter.format(obj)];
365
+ }
366
+ }
367
+ return null;
368
+ },
369
+ hasBody: () => true
370
+ },
371
+ {
372
+ // Performance object //
373
+ // This is a sneaky way to show performance info withouth any extra calls when logging:
374
+ // LOG(`...`)
375
+ // it would work without this if we would have some way to intercept the call:
376
+ // L.INFO('...') - a getter on L that adds the current time as prefix
377
+ // LOG('...')() - returns the log function with all argumends bound
378
+ // But instead we are adding a custom formatter that replaced the placeholder object of class P with the performance info
379
+ header: (obj) => {
380
+ if (!(obj instanceof LoggerTime))
381
+ return null;
382
+ if (!formattersEnabled)
383
+ formattersEnabled = true;
384
+ const p = Logger.timeStr(obj.time, obj.delta);
385
+ return [
386
+ "span",
387
+ { style: "font-weight: light; color: grey" },
388
+ p?.toString()
389
+ // ['a', { href: 'vscodium://file/home/manu/dev/tamera/bookr/imports/lib/utils/Logger.js' }, 'WOW'],
390
+ ];
391
+ },
392
+ hasBody: () => false
393
+ },
394
+ {
395
+ // Style object
396
+ header: (obj) => {
397
+ if (!(obj instanceof Style))
398
+ return null;
399
+ if (!formattersEnabled)
400
+ formattersEnabled = true;
401
+ return ["span", {
402
+ style: "font-weight: light; color: grey; "
403
+ /* font-style: italic; */
404
+ }, obj.string];
405
+ },
406
+ hasBody: () => false
407
+ }
408
+ );
409
+ } else if (import_browser_or_node.isNode) {
410
+ }
411
+
412
+ // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/vendor/base-x.js
413
+ function base(ALPHABET, name) {
414
+ if (ALPHABET.length >= 255) {
415
+ throw new TypeError("Alphabet too long");
416
+ }
417
+ var BASE_MAP = new Uint8Array(256);
418
+ for (var j = 0; j < BASE_MAP.length; j++) {
419
+ BASE_MAP[j] = 255;
420
+ }
421
+ for (var i = 0; i < ALPHABET.length; i++) {
422
+ var x = ALPHABET.charAt(i);
423
+ var xc = x.charCodeAt(0);
424
+ if (BASE_MAP[xc] !== 255) {
425
+ throw new TypeError(x + " is ambiguous");
426
+ }
427
+ BASE_MAP[xc] = i;
428
+ }
429
+ var BASE = ALPHABET.length;
430
+ var LEADER = ALPHABET.charAt(0);
431
+ var FACTOR = Math.log(BASE) / Math.log(256);
432
+ var iFACTOR = Math.log(256) / Math.log(BASE);
433
+ function encode3(source) {
434
+ if (source instanceof Uint8Array)
435
+ ;
436
+ else if (ArrayBuffer.isView(source)) {
437
+ source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
438
+ } else if (Array.isArray(source)) {
439
+ source = Uint8Array.from(source);
440
+ }
441
+ if (!(source instanceof Uint8Array)) {
442
+ throw new TypeError("Expected Uint8Array");
443
+ }
444
+ if (source.length === 0) {
445
+ return "";
446
+ }
447
+ var zeroes = 0;
448
+ var length2 = 0;
449
+ var pbegin = 0;
450
+ var pend = source.length;
451
+ while (pbegin !== pend && source[pbegin] === 0) {
452
+ pbegin++;
453
+ zeroes++;
454
+ }
455
+ var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
456
+ var b58 = new Uint8Array(size);
457
+ while (pbegin !== pend) {
458
+ var carry = source[pbegin];
459
+ var i2 = 0;
460
+ for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
461
+ carry += 256 * b58[it1] >>> 0;
462
+ b58[it1] = carry % BASE >>> 0;
463
+ carry = carry / BASE >>> 0;
464
+ }
465
+ if (carry !== 0) {
466
+ throw new Error("Non-zero carry");
467
+ }
468
+ length2 = i2;
469
+ pbegin++;
470
+ }
471
+ var it2 = size - length2;
472
+ while (it2 !== size && b58[it2] === 0) {
473
+ it2++;
474
+ }
475
+ var str = LEADER.repeat(zeroes);
476
+ for (; it2 < size; ++it2) {
477
+ str += ALPHABET.charAt(b58[it2]);
478
+ }
479
+ return str;
480
+ }
481
+ function decodeUnsafe(source) {
482
+ if (typeof source !== "string") {
483
+ throw new TypeError("Expected String");
484
+ }
485
+ if (source.length === 0) {
486
+ return new Uint8Array();
487
+ }
488
+ var psz = 0;
489
+ if (source[psz] === " ") {
490
+ return;
491
+ }
492
+ var zeroes = 0;
493
+ var length2 = 0;
494
+ while (source[psz] === LEADER) {
495
+ zeroes++;
496
+ psz++;
497
+ }
498
+ var size = (source.length - psz) * FACTOR + 1 >>> 0;
499
+ var b256 = new Uint8Array(size);
500
+ while (source[psz]) {
501
+ var carry = BASE_MAP[source.charCodeAt(psz)];
502
+ if (carry === 255) {
503
+ return;
504
+ }
505
+ var i2 = 0;
506
+ for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
507
+ carry += BASE * b256[it3] >>> 0;
508
+ b256[it3] = carry % 256 >>> 0;
509
+ carry = carry / 256 >>> 0;
510
+ }
511
+ if (carry !== 0) {
512
+ throw new Error("Non-zero carry");
513
+ }
514
+ length2 = i2;
515
+ psz++;
516
+ }
517
+ if (source[psz] === " ") {
518
+ return;
519
+ }
520
+ var it4 = size - length2;
521
+ while (it4 !== size && b256[it4] === 0) {
522
+ it4++;
523
+ }
524
+ var vch = new Uint8Array(zeroes + (size - it4));
525
+ var j2 = zeroes;
526
+ while (it4 !== size) {
527
+ vch[j2++] = b256[it4++];
528
+ }
529
+ return vch;
530
+ }
531
+ function decode5(string) {
532
+ var buffer = decodeUnsafe(string);
533
+ if (buffer) {
534
+ return buffer;
535
+ }
536
+ throw new Error(`Non-${name} character`);
537
+ }
538
+ return {
539
+ encode: encode3,
540
+ decodeUnsafe,
541
+ decode: decode5
542
+ };
543
+ }
544
+ var src = base;
545
+ var _brrp__multiformats_scope_baseX = src;
546
+ var base_x_default = _brrp__multiformats_scope_baseX;
547
+
548
+ // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bytes.js
549
+ var empty = new Uint8Array(0);
550
+ var equals = (aa, bb) => {
551
+ if (aa === bb)
552
+ return true;
553
+ if (aa.byteLength !== bb.byteLength) {
554
+ return false;
555
+ }
556
+ for (let ii = 0; ii < aa.byteLength; ii++) {
557
+ if (aa[ii] !== bb[ii]) {
558
+ return false;
559
+ }
560
+ }
561
+ return true;
562
+ };
563
+ var coerce = (o) => {
564
+ if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
565
+ return o;
566
+ if (o instanceof ArrayBuffer)
567
+ return new Uint8Array(o);
568
+ if (ArrayBuffer.isView(o)) {
569
+ return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
570
+ }
571
+ throw new Error("Unknown type, must be binary type");
572
+ };
573
+
574
+ // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base.js
575
+ var Encoder = class {
576
+ /**
577
+ * @param {Base} name
578
+ * @param {Prefix} prefix
579
+ * @param {(bytes:Uint8Array) => string} baseEncode
580
+ */
581
+ constructor(name, prefix, baseEncode) {
582
+ this.name = name;
583
+ this.prefix = prefix;
584
+ this.baseEncode = baseEncode;
585
+ }
586
+ /**
587
+ * @param {Uint8Array} bytes
588
+ * @returns {API.Multibase<Prefix>}
589
+ */
590
+ encode(bytes) {
591
+ if (bytes instanceof Uint8Array) {
592
+ return `${this.prefix}${this.baseEncode(bytes)}`;
593
+ } else {
594
+ throw Error("Unknown type, must be binary type");
595
+ }
596
+ }
597
+ };
598
+ var Decoder = class {
599
+ /**
600
+ * @param {Base} name
601
+ * @param {Prefix} prefix
602
+ * @param {(text:string) => Uint8Array} baseDecode
603
+ */
604
+ constructor(name, prefix, baseDecode) {
605
+ this.name = name;
606
+ this.prefix = prefix;
607
+ if (prefix.codePointAt(0) === void 0) {
608
+ throw new Error("Invalid prefix character");
609
+ }
610
+ this.prefixCodePoint = /** @type {number} */
611
+ prefix.codePointAt(0);
612
+ this.baseDecode = baseDecode;
613
+ }
614
+ /**
615
+ * @param {string} text
616
+ */
617
+ decode(text) {
618
+ if (typeof text === "string") {
619
+ if (text.codePointAt(0) !== this.prefixCodePoint) {
620
+ throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
621
+ }
622
+ return this.baseDecode(text.slice(this.prefix.length));
623
+ } else {
624
+ throw Error("Can only multibase decode strings");
625
+ }
626
+ }
627
+ /**
628
+ * @template {string} OtherPrefix
629
+ * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
630
+ * @returns {ComposedDecoder<Prefix|OtherPrefix>}
631
+ */
632
+ or(decoder) {
633
+ return or(this, decoder);
634
+ }
635
+ };
636
+ var ComposedDecoder = class {
637
+ /**
638
+ * @param {Decoders<Prefix>} decoders
639
+ */
640
+ constructor(decoders) {
641
+ this.decoders = decoders;
642
+ }
643
+ /**
644
+ * @template {string} OtherPrefix
645
+ * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
646
+ * @returns {ComposedDecoder<Prefix|OtherPrefix>}
647
+ */
648
+ or(decoder) {
649
+ return or(this, decoder);
650
+ }
651
+ /**
652
+ * @param {string} input
653
+ * @returns {Uint8Array}
654
+ */
655
+ decode(input) {
656
+ const prefix = (
657
+ /** @type {Prefix} */
658
+ input[0]
659
+ );
660
+ const decoder = this.decoders[prefix];
661
+ if (decoder) {
662
+ return decoder.decode(input);
663
+ } else {
664
+ throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
665
+ }
666
+ }
667
+ };
668
+ var or = (left, right) => new ComposedDecoder(
669
+ /** @type {Decoders<L|R>} */
670
+ {
671
+ ...left.decoders || { [
672
+ /** @type API.UnibaseDecoder<L> */
673
+ left.prefix
674
+ ]: left },
675
+ ...right.decoders || { [
676
+ /** @type API.UnibaseDecoder<R> */
677
+ right.prefix
678
+ ]: right }
679
+ }
680
+ );
681
+ var Codec = class {
682
+ /**
683
+ * @param {Base} name
684
+ * @param {Prefix} prefix
685
+ * @param {(bytes:Uint8Array) => string} baseEncode
686
+ * @param {(text:string) => Uint8Array} baseDecode
687
+ */
688
+ constructor(name, prefix, baseEncode, baseDecode) {
689
+ this.name = name;
690
+ this.prefix = prefix;
691
+ this.baseEncode = baseEncode;
692
+ this.baseDecode = baseDecode;
693
+ this.encoder = new Encoder(name, prefix, baseEncode);
694
+ this.decoder = new Decoder(name, prefix, baseDecode);
695
+ }
696
+ /**
697
+ * @param {Uint8Array} input
698
+ */
699
+ encode(input) {
700
+ return this.encoder.encode(input);
701
+ }
702
+ /**
703
+ * @param {string} input
704
+ */
705
+ decode(input) {
706
+ return this.decoder.decode(input);
707
+ }
708
+ };
709
+ var from = ({ name, prefix, encode: encode3, decode: decode5 }) => new Codec(name, prefix, encode3, decode5);
710
+ var baseX = ({ prefix, name, alphabet }) => {
711
+ const { encode: encode3, decode: decode5 } = base_x_default(alphabet, name);
712
+ return from({
713
+ prefix,
714
+ name,
715
+ encode: encode3,
716
+ /**
717
+ * @param {string} text
718
+ */
719
+ decode: (text) => coerce(decode5(text))
720
+ });
721
+ };
722
+ var decode = (string, alphabet, bitsPerChar, name) => {
723
+ const codes = {};
724
+ for (let i = 0; i < alphabet.length; ++i) {
725
+ codes[alphabet[i]] = i;
726
+ }
727
+ let end = string.length;
728
+ while (string[end - 1] === "=") {
729
+ --end;
730
+ }
731
+ const out = new Uint8Array(end * bitsPerChar / 8 | 0);
732
+ let bits = 0;
733
+ let buffer = 0;
734
+ let written = 0;
735
+ for (let i = 0; i < end; ++i) {
736
+ const value = codes[string[i]];
737
+ if (value === void 0) {
738
+ throw new SyntaxError(`Non-${name} character`);
739
+ }
740
+ buffer = buffer << bitsPerChar | value;
741
+ bits += bitsPerChar;
742
+ if (bits >= 8) {
743
+ bits -= 8;
744
+ out[written++] = 255 & buffer >> bits;
745
+ }
746
+ }
747
+ if (bits >= bitsPerChar || 255 & buffer << 8 - bits) {
748
+ throw new SyntaxError("Unexpected end of data");
749
+ }
750
+ return out;
751
+ };
752
+ var encode = (data, alphabet, bitsPerChar) => {
753
+ const pad = alphabet[alphabet.length - 1] === "=";
754
+ const mask = (1 << bitsPerChar) - 1;
755
+ let out = "";
756
+ let bits = 0;
757
+ let buffer = 0;
758
+ for (let i = 0; i < data.length; ++i) {
759
+ buffer = buffer << 8 | data[i];
760
+ bits += 8;
761
+ while (bits > bitsPerChar) {
762
+ bits -= bitsPerChar;
763
+ out += alphabet[mask & buffer >> bits];
764
+ }
765
+ }
766
+ if (bits) {
767
+ out += alphabet[mask & buffer << bitsPerChar - bits];
768
+ }
769
+ if (pad) {
770
+ while (out.length * bitsPerChar & 7) {
771
+ out += "=";
772
+ }
773
+ }
774
+ return out;
775
+ };
776
+ var rfc4648 = ({ name, prefix, bitsPerChar, alphabet }) => {
777
+ return from({
778
+ prefix,
779
+ name,
780
+ encode(input) {
781
+ return encode(input, alphabet, bitsPerChar);
782
+ },
783
+ decode(input) {
784
+ return decode(input, alphabet, bitsPerChar, name);
785
+ }
786
+ });
787
+ };
788
+
789
+ // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base32.js
790
+ var base32 = rfc4648({
791
+ prefix: "b",
792
+ name: "base32",
793
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567",
794
+ bitsPerChar: 5
795
+ });
796
+ var base32upper = rfc4648({
797
+ prefix: "B",
798
+ name: "base32upper",
799
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
800
+ bitsPerChar: 5
801
+ });
802
+ var base32pad = rfc4648({
803
+ prefix: "c",
804
+ name: "base32pad",
805
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
806
+ bitsPerChar: 5
807
+ });
808
+ var base32padupper = rfc4648({
809
+ prefix: "C",
810
+ name: "base32padupper",
811
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
812
+ bitsPerChar: 5
813
+ });
814
+ var base32hex = rfc4648({
815
+ prefix: "v",
816
+ name: "base32hex",
817
+ alphabet: "0123456789abcdefghijklmnopqrstuv",
818
+ bitsPerChar: 5
819
+ });
820
+ var base32hexupper = rfc4648({
821
+ prefix: "V",
822
+ name: "base32hexupper",
823
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
824
+ bitsPerChar: 5
825
+ });
826
+ var base32hexpad = rfc4648({
827
+ prefix: "t",
828
+ name: "base32hexpad",
829
+ alphabet: "0123456789abcdefghijklmnopqrstuv=",
830
+ bitsPerChar: 5
831
+ });
832
+ var base32hexpadupper = rfc4648({
833
+ prefix: "T",
834
+ name: "base32hexpadupper",
835
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
836
+ bitsPerChar: 5
837
+ });
838
+ var base32z = rfc4648({
839
+ prefix: "h",
840
+ name: "base32z",
841
+ alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
842
+ bitsPerChar: 5
843
+ });
844
+
845
+ // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base58.js
846
+ var base58btc = baseX({
847
+ name: "base58btc",
848
+ prefix: "z",
849
+ alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
850
+ });
851
+ var base58flickr = baseX({
852
+ name: "base58flickr",
853
+ prefix: "Z",
854
+ alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
855
+ });
856
+
857
+ // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/vendor/varint.js
858
+ var encode_1 = encode2;
859
+ var MSB = 128;
860
+ var REST = 127;
861
+ var MSBALL = ~REST;
862
+ var INT = Math.pow(2, 31);
863
+ function encode2(num, out, offset) {
864
+ out = out || [];
865
+ offset = offset || 0;
866
+ var oldOffset = offset;
867
+ while (num >= INT) {
868
+ out[offset++] = num & 255 | MSB;
869
+ num /= 128;
870
+ }
871
+ while (num & MSBALL) {
872
+ out[offset++] = num & 255 | MSB;
873
+ num >>>= 7;
874
+ }
875
+ out[offset] = num | 0;
876
+ encode2.bytes = offset - oldOffset + 1;
877
+ return out;
878
+ }
879
+ var decode2 = read;
880
+ var MSB$1 = 128;
881
+ var REST$1 = 127;
882
+ function read(buf, offset) {
883
+ var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
884
+ do {
885
+ if (counter >= l) {
886
+ read.bytes = 0;
887
+ throw new RangeError("Could not decode varint");
888
+ }
889
+ b = buf[counter++];
890
+ res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
891
+ shift += 7;
892
+ } while (b >= MSB$1);
893
+ read.bytes = counter - offset;
894
+ return res;
895
+ }
896
+ var N1 = Math.pow(2, 7);
897
+ var N2 = Math.pow(2, 14);
898
+ var N3 = Math.pow(2, 21);
899
+ var N4 = Math.pow(2, 28);
900
+ var N5 = Math.pow(2, 35);
901
+ var N6 = Math.pow(2, 42);
902
+ var N7 = Math.pow(2, 49);
903
+ var N8 = Math.pow(2, 56);
904
+ var N9 = Math.pow(2, 63);
905
+ var length = function(value) {
906
+ 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;
907
+ };
908
+ var varint = {
909
+ encode: encode_1,
910
+ decode: decode2,
911
+ encodingLength: length
912
+ };
913
+ var _brrp_varint = varint;
914
+ var varint_default = _brrp_varint;
915
+
916
+ // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/varint.js
917
+ var decode3 = (data, offset = 0) => {
918
+ const code = varint_default.decode(data, offset);
919
+ return [code, varint_default.decode.bytes];
920
+ };
921
+ var encodeTo = (int, target, offset = 0) => {
922
+ varint_default.encode(int, target, offset);
923
+ return target;
924
+ };
925
+ var encodingLength = (int) => {
926
+ return varint_default.encodingLength(int);
927
+ };
928
+
929
+ // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/hashes/digest.js
930
+ var create = (code, digest) => {
931
+ const size = digest.byteLength;
932
+ const sizeOffset = encodingLength(code);
933
+ const digestOffset = sizeOffset + encodingLength(size);
934
+ const bytes = new Uint8Array(digestOffset + size);
935
+ encodeTo(code, bytes, 0);
936
+ encodeTo(size, bytes, sizeOffset);
937
+ bytes.set(digest, digestOffset);
938
+ return new Digest(code, size, digest, bytes);
939
+ };
940
+ var decode4 = (multihash) => {
941
+ const bytes = coerce(multihash);
942
+ const [code, sizeOffset] = decode3(bytes);
943
+ const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
944
+ const digest = bytes.subarray(sizeOffset + digestOffset);
945
+ if (digest.byteLength !== size) {
946
+ throw new Error("Incorrect length");
947
+ }
948
+ return new Digest(code, size, digest, bytes);
949
+ };
950
+ var equals2 = (a, b) => {
951
+ if (a === b) {
952
+ return true;
953
+ } else {
954
+ const data = (
955
+ /** @type {{code?:unknown, size?:unknown, bytes?:unknown}} */
956
+ b
957
+ );
958
+ return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
959
+ }
960
+ };
961
+ var Digest = class {
962
+ /**
963
+ * Creates a multihash digest.
964
+ *
965
+ * @param {Code} code
966
+ * @param {Size} size
967
+ * @param {Uint8Array} digest
968
+ * @param {Uint8Array} bytes
969
+ */
970
+ constructor(code, size, digest, bytes) {
971
+ this.code = code;
972
+ this.size = size;
973
+ this.digest = digest;
974
+ this.bytes = bytes;
975
+ }
976
+ };
977
+
978
+ // ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/cid.js
979
+ var format = (link, base2) => {
980
+ const { bytes, version } = link;
981
+ switch (version) {
982
+ case 0:
983
+ return toStringV0(
984
+ bytes,
985
+ baseCache(link),
986
+ /** @type {API.MultibaseEncoder<"z">} */
987
+ base2 || base58btc.encoder
988
+ );
989
+ default:
990
+ return toStringV1(
991
+ bytes,
992
+ baseCache(link),
993
+ /** @type {API.MultibaseEncoder<Prefix>} */
994
+ base2 || base32.encoder
995
+ );
996
+ }
997
+ };
998
+ var cache = /* @__PURE__ */ new WeakMap();
999
+ var baseCache = (cid) => {
1000
+ const baseCache2 = cache.get(cid);
1001
+ if (baseCache2 == null) {
1002
+ const baseCache3 = /* @__PURE__ */ new Map();
1003
+ cache.set(cid, baseCache3);
1004
+ return baseCache3;
1005
+ }
1006
+ return baseCache2;
1007
+ };
1008
+ var CID = class _CID {
1009
+ /**
1010
+ * @param {Version} version - Version of the CID
1011
+ * @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
1012
+ * @param {API.MultihashDigest<Alg>} multihash - (Multi)hash of the of the content.
1013
+ * @param {Uint8Array} bytes
1014
+ */
1015
+ constructor(version, code, multihash, bytes) {
1016
+ this.code = code;
1017
+ this.version = version;
1018
+ this.multihash = multihash;
1019
+ this.bytes = bytes;
1020
+ this["/"] = bytes;
1021
+ }
1022
+ /**
1023
+ * Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
1024
+ * please either use `CID.asCID(cid)` or switch to new signalling mechanism
1025
+ *
1026
+ * @deprecated
1027
+ */
1028
+ get asCID() {
1029
+ return this;
1030
+ }
1031
+ // ArrayBufferView
1032
+ get byteOffset() {
1033
+ return this.bytes.byteOffset;
1034
+ }
1035
+ // ArrayBufferView
1036
+ get byteLength() {
1037
+ return this.bytes.byteLength;
1038
+ }
1039
+ /**
1040
+ * @returns {CID<Data, API.DAG_PB, API.SHA_256, 0>}
1041
+ */
1042
+ toV0() {
1043
+ switch (this.version) {
1044
+ case 0: {
1045
+ return (
1046
+ /** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */
1047
+ this
1048
+ );
1049
+ }
1050
+ case 1: {
1051
+ const { code, multihash } = this;
1052
+ if (code !== DAG_PB_CODE) {
1053
+ throw new Error("Cannot convert a non dag-pb CID to CIDv0");
1054
+ }
1055
+ if (multihash.code !== SHA_256_CODE) {
1056
+ throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
1057
+ }
1058
+ return (
1059
+ /** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */
1060
+ _CID.createV0(
1061
+ /** @type {API.MultihashDigest<API.SHA_256>} */
1062
+ multihash
1063
+ )
1064
+ );
1065
+ }
1066
+ default: {
1067
+ throw Error(
1068
+ `Can not convert CID version ${this.version} to version 0. This is a bug please report`
1069
+ );
1070
+ }
1071
+ }
1072
+ }
1073
+ /**
1074
+ * @returns {CID<Data, Format, Alg, 1>}
1075
+ */
1076
+ toV1() {
1077
+ switch (this.version) {
1078
+ case 0: {
1079
+ const { code, digest } = this.multihash;
1080
+ const multihash = create(code, digest);
1081
+ return (
1082
+ /** @type {CID<Data, Format, Alg, 1>} */
1083
+ _CID.createV1(this.code, multihash)
1084
+ );
1085
+ }
1086
+ case 1: {
1087
+ return (
1088
+ /** @type {CID<Data, Format, Alg, 1>} */
1089
+ this
1090
+ );
1091
+ }
1092
+ default: {
1093
+ throw Error(
1094
+ `Can not convert CID version ${this.version} to version 1. This is a bug please report`
1095
+ );
1096
+ }
1097
+ }
1098
+ }
1099
+ /**
1100
+ * @param {unknown} other
1101
+ * @returns {other is CID<Data, Format, Alg, Version>}
1102
+ */
1103
+ equals(other) {
1104
+ return _CID.equals(this, other);
1105
+ }
1106
+ /**
1107
+ * @template {unknown} Data
1108
+ * @template {number} Format
1109
+ * @template {number} Alg
1110
+ * @template {API.Version} Version
1111
+ * @param {API.Link<Data, Format, Alg, Version>} self
1112
+ * @param {unknown} other
1113
+ * @returns {other is CID}
1114
+ */
1115
+ static equals(self2, other) {
1116
+ const unknown = (
1117
+ /** @type {{code?:unknown, version?:unknown, multihash?:unknown}} */
1118
+ other
1119
+ );
1120
+ return unknown && self2.code === unknown.code && self2.version === unknown.version && equals2(self2.multihash, unknown.multihash);
1121
+ }
1122
+ /**
1123
+ * @param {API.MultibaseEncoder<string>} [base]
1124
+ * @returns {string}
1125
+ */
1126
+ toString(base2) {
1127
+ return format(this, base2);
1128
+ }
1129
+ /**
1130
+ * @returns {API.LinkJSON<this>}
1131
+ */
1132
+ toJSON() {
1133
+ return { "/": format(this) };
1134
+ }
1135
+ link() {
1136
+ return this;
1137
+ }
1138
+ get [Symbol.toStringTag]() {
1139
+ return "CID";
1140
+ }
1141
+ // Legacy
1142
+ [Symbol.for("nodejs.util.inspect.custom")]() {
1143
+ return `CID(${this.toString()})`;
1144
+ }
1145
+ /**
1146
+ * Takes any input `value` and returns a `CID` instance if it was
1147
+ * a `CID` otherwise returns `null`. If `value` is instanceof `CID`
1148
+ * it will return value back. If `value` is not instance of this CID
1149
+ * class, but is compatible CID it will return new instance of this
1150
+ * `CID` class. Otherwise returns null.
1151
+ *
1152
+ * This allows two different incompatible versions of CID library to
1153
+ * co-exist and interop as long as binary interface is compatible.
1154
+ *
1155
+ * @template {unknown} Data
1156
+ * @template {number} Format
1157
+ * @template {number} Alg
1158
+ * @template {API.Version} Version
1159
+ * @template {unknown} U
1160
+ * @param {API.Link<Data, Format, Alg, Version>|U} input
1161
+ * @returns {CID<Data, Format, Alg, Version>|null}
1162
+ */
1163
+ static asCID(input) {
1164
+ if (input == null) {
1165
+ return null;
1166
+ }
1167
+ const value = (
1168
+ /** @type {any} */
1169
+ input
1170
+ );
1171
+ if (value instanceof _CID) {
1172
+ return value;
1173
+ } else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
1174
+ const { version, code, multihash, bytes } = value;
1175
+ return new _CID(
1176
+ version,
1177
+ code,
1178
+ /** @type {API.MultihashDigest<Alg>} */
1179
+ multihash,
1180
+ bytes || encodeCID(version, code, multihash.bytes)
1181
+ );
1182
+ } else if (value[cidSymbol] === true) {
1183
+ const { version, multihash, code } = value;
1184
+ const digest = (
1185
+ /** @type {API.MultihashDigest<Alg>} */
1186
+ decode4(multihash)
1187
+ );
1188
+ return _CID.create(version, code, digest);
1189
+ } else {
1190
+ return null;
1191
+ }
1192
+ }
1193
+ /**
1194
+ *
1195
+ * @template {unknown} Data
1196
+ * @template {number} Format
1197
+ * @template {number} Alg
1198
+ * @template {API.Version} Version
1199
+ * @param {Version} version - Version of the CID
1200
+ * @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
1201
+ * @param {API.MultihashDigest<Alg>} digest - (Multi)hash of the of the content.
1202
+ * @returns {CID<Data, Format, Alg, Version>}
1203
+ */
1204
+ static create(version, code, digest) {
1205
+ if (typeof code !== "number") {
1206
+ throw new Error("String codecs are no longer supported");
1207
+ }
1208
+ if (!(digest.bytes instanceof Uint8Array)) {
1209
+ throw new Error("Invalid digest");
1210
+ }
1211
+ switch (version) {
1212
+ case 0: {
1213
+ if (code !== DAG_PB_CODE) {
1214
+ throw new Error(
1215
+ `Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`
1216
+ );
1217
+ } else {
1218
+ return new _CID(version, code, digest, digest.bytes);
1219
+ }
1220
+ }
1221
+ case 1: {
1222
+ const bytes = encodeCID(version, code, digest.bytes);
1223
+ return new _CID(version, code, digest, bytes);
1224
+ }
1225
+ default: {
1226
+ throw new Error("Invalid version");
1227
+ }
1228
+ }
1229
+ }
1230
+ /**
1231
+ * Simplified version of `create` for CIDv0.
1232
+ *
1233
+ * @template {unknown} [T=unknown]
1234
+ * @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash.
1235
+ * @returns {CID<T, typeof DAG_PB_CODE, typeof SHA_256_CODE, 0>}
1236
+ */
1237
+ static createV0(digest) {
1238
+ return _CID.create(0, DAG_PB_CODE, digest);
1239
+ }
1240
+ /**
1241
+ * Simplified version of `create` for CIDv1.
1242
+ *
1243
+ * @template {unknown} Data
1244
+ * @template {number} Code
1245
+ * @template {number} Alg
1246
+ * @param {Code} code - Content encoding format code.
1247
+ * @param {API.MultihashDigest<Alg>} digest - Miltihash of the content.
1248
+ * @returns {CID<Data, Code, Alg, 1>}
1249
+ */
1250
+ static createV1(code, digest) {
1251
+ return _CID.create(1, code, digest);
1252
+ }
1253
+ /**
1254
+ * Decoded a CID from its binary representation. The byte array must contain
1255
+ * only the CID with no additional bytes.
1256
+ *
1257
+ * An error will be thrown if the bytes provided do not contain a valid
1258
+ * binary representation of a CID.
1259
+ *
1260
+ * @template {unknown} Data
1261
+ * @template {number} Code
1262
+ * @template {number} Alg
1263
+ * @template {API.Version} Ver
1264
+ * @param {API.ByteView<API.Link<Data, Code, Alg, Ver>>} bytes
1265
+ * @returns {CID<Data, Code, Alg, Ver>}
1266
+ */
1267
+ static decode(bytes) {
1268
+ const [cid, remainder] = _CID.decodeFirst(bytes);
1269
+ if (remainder.length) {
1270
+ throw new Error("Incorrect length");
1271
+ }
1272
+ return cid;
1273
+ }
1274
+ /**
1275
+ * Decoded a CID from its binary representation at the beginning of a byte
1276
+ * array.
1277
+ *
1278
+ * Returns an array with the first element containing the CID and the second
1279
+ * element containing the remainder of the original byte array. The remainder
1280
+ * will be a zero-length byte array if the provided bytes only contained a
1281
+ * binary CID representation.
1282
+ *
1283
+ * @template {unknown} T
1284
+ * @template {number} C
1285
+ * @template {number} A
1286
+ * @template {API.Version} V
1287
+ * @param {API.ByteView<API.Link<T, C, A, V>>} bytes
1288
+ * @returns {[CID<T, C, A, V>, Uint8Array]}
1289
+ */
1290
+ static decodeFirst(bytes) {
1291
+ const specs = _CID.inspectBytes(bytes);
1292
+ const prefixSize = specs.size - specs.multihashSize;
1293
+ const multihashBytes = coerce(
1294
+ bytes.subarray(prefixSize, prefixSize + specs.multihashSize)
1295
+ );
1296
+ if (multihashBytes.byteLength !== specs.multihashSize) {
1297
+ throw new Error("Incorrect length");
1298
+ }
1299
+ const digestBytes = multihashBytes.subarray(
1300
+ specs.multihashSize - specs.digestSize
1301
+ );
1302
+ const digest = new Digest(
1303
+ specs.multihashCode,
1304
+ specs.digestSize,
1305
+ digestBytes,
1306
+ multihashBytes
1307
+ );
1308
+ const cid = specs.version === 0 ? _CID.createV0(
1309
+ /** @type {API.MultihashDigest<API.SHA_256>} */
1310
+ digest
1311
+ ) : _CID.createV1(specs.codec, digest);
1312
+ return [
1313
+ /** @type {CID<T, C, A, V>} */
1314
+ cid,
1315
+ bytes.subarray(specs.size)
1316
+ ];
1317
+ }
1318
+ /**
1319
+ * Inspect the initial bytes of a CID to determine its properties.
1320
+ *
1321
+ * Involves decoding up to 4 varints. Typically this will require only 4 to 6
1322
+ * bytes but for larger multicodec code values and larger multihash digest
1323
+ * lengths these varints can be quite large. It is recommended that at least
1324
+ * 10 bytes be made available in the `initialBytes` argument for a complete
1325
+ * inspection.
1326
+ *
1327
+ * @template {unknown} T
1328
+ * @template {number} C
1329
+ * @template {number} A
1330
+ * @template {API.Version} V
1331
+ * @param {API.ByteView<API.Link<T, C, A, V>>} initialBytes
1332
+ * @returns {{ version:V, codec:C, multihashCode:A, digestSize:number, multihashSize:number, size:number }}
1333
+ */
1334
+ static inspectBytes(initialBytes) {
1335
+ let offset = 0;
1336
+ const next = () => {
1337
+ const [i, length2] = decode3(initialBytes.subarray(offset));
1338
+ offset += length2;
1339
+ return i;
1340
+ };
1341
+ let version = (
1342
+ /** @type {V} */
1343
+ next()
1344
+ );
1345
+ let codec = (
1346
+ /** @type {C} */
1347
+ DAG_PB_CODE
1348
+ );
1349
+ if (
1350
+ /** @type {number} */
1351
+ version === 18
1352
+ ) {
1353
+ version = /** @type {V} */
1354
+ 0;
1355
+ offset = 0;
1356
+ } else {
1357
+ codec = /** @type {C} */
1358
+ next();
1359
+ }
1360
+ if (version !== 0 && version !== 1) {
1361
+ throw new RangeError(`Invalid CID version ${version}`);
1362
+ }
1363
+ const prefixSize = offset;
1364
+ const multihashCode = (
1365
+ /** @type {A} */
1366
+ next()
1367
+ );
1368
+ const digestSize = next();
1369
+ const size = offset + digestSize;
1370
+ const multihashSize = size - prefixSize;
1371
+ return { version, codec, multihashCode, digestSize, multihashSize, size };
1372
+ }
1373
+ /**
1374
+ * Takes cid in a string representation and creates an instance. If `base`
1375
+ * decoder is not provided will use a default from the configuration. It will
1376
+ * throw an error if encoding of the CID is not compatible with supplied (or
1377
+ * a default decoder).
1378
+ *
1379
+ * @template {string} Prefix
1380
+ * @template {unknown} Data
1381
+ * @template {number} Code
1382
+ * @template {number} Alg
1383
+ * @template {API.Version} Ver
1384
+ * @param {API.ToString<API.Link<Data, Code, Alg, Ver>, Prefix>} source
1385
+ * @param {API.MultibaseDecoder<Prefix>} [base]
1386
+ * @returns {CID<Data, Code, Alg, Ver>}
1387
+ */
1388
+ static parse(source, base2) {
1389
+ const [prefix, bytes] = parseCIDtoBytes(source, base2);
1390
+ const cid = _CID.decode(bytes);
1391
+ if (cid.version === 0 && source[0] !== "Q") {
1392
+ throw Error("Version 0 CID string must not include multibase prefix");
1393
+ }
1394
+ baseCache(cid).set(prefix, source);
1395
+ return cid;
1396
+ }
1397
+ };
1398
+ var parseCIDtoBytes = (source, base2) => {
1399
+ switch (source[0]) {
1400
+ case "Q": {
1401
+ const decoder = base2 || base58btc;
1402
+ return [
1403
+ /** @type {Prefix} */
1404
+ base58btc.prefix,
1405
+ decoder.decode(`${base58btc.prefix}${source}`)
1406
+ ];
1407
+ }
1408
+ case base58btc.prefix: {
1409
+ const decoder = base2 || base58btc;
1410
+ return [
1411
+ /** @type {Prefix} */
1412
+ base58btc.prefix,
1413
+ decoder.decode(source)
1414
+ ];
1415
+ }
1416
+ case base32.prefix: {
1417
+ const decoder = base2 || base32;
1418
+ return [
1419
+ /** @type {Prefix} */
1420
+ base32.prefix,
1421
+ decoder.decode(source)
1422
+ ];
1423
+ }
1424
+ default: {
1425
+ if (base2 == null) {
1426
+ throw Error(
1427
+ "To parse non base32 or base58btc encoded CID multibase decoder must be provided"
1428
+ );
1429
+ }
1430
+ return [
1431
+ /** @type {Prefix} */
1432
+ source[0],
1433
+ base2.decode(source)
1434
+ ];
1435
+ }
1436
+ }
1437
+ };
1438
+ var toStringV0 = (bytes, cache2, base2) => {
1439
+ const { prefix } = base2;
1440
+ if (prefix !== base58btc.prefix) {
1441
+ throw Error(`Cannot string encode V0 in ${base2.name} encoding`);
1442
+ }
1443
+ const cid = cache2.get(prefix);
1444
+ if (cid == null) {
1445
+ const cid2 = base2.encode(bytes).slice(1);
1446
+ cache2.set(prefix, cid2);
1447
+ return cid2;
1448
+ } else {
1449
+ return cid;
1450
+ }
1451
+ };
1452
+ var toStringV1 = (bytes, cache2, base2) => {
1453
+ const { prefix } = base2;
1454
+ const cid = cache2.get(prefix);
1455
+ if (cid == null) {
1456
+ const cid2 = base2.encode(bytes);
1457
+ cache2.set(prefix, cid2);
1458
+ return cid2;
1459
+ } else {
1460
+ return cid;
1461
+ }
1462
+ };
1463
+ var DAG_PB_CODE = 112;
1464
+ var SHA_256_CODE = 18;
1465
+ var encodeCID = (version, code, multihash) => {
1466
+ const codeOffset = encodingLength(version);
1467
+ const hashOffset = codeOffset + encodingLength(code);
1468
+ const bytes = new Uint8Array(hashOffset + multihash.byteLength);
1469
+ encodeTo(version, bytes, 0);
1470
+ encodeTo(code, bytes, codeOffset);
1471
+ bytes.set(multihash, hashOffset);
1472
+ return bytes;
1473
+ };
1474
+ var cidSymbol = Symbol.for("@ipld/js-cid/CID");
1475
+
1476
+ export {
1477
+ __require,
1478
+ __commonJS,
1479
+ __export,
1480
+ __toESM,
1481
+ Logger,
1482
+ decode4 as decode,
1483
+ CID
1484
+ };
1485
+ //# sourceMappingURL=chunk-Z4SV224X.min.js.map