cairn-p2p 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.cjs CHANGED
@@ -9,14 +9,14 @@ var __esm = (fn, res) => function __init() {
9
9
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
10
  };
11
11
  var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
12
+ for (var name2 in all)
13
+ __defProp(target, name2, { get: all[name2], enumerable: true });
14
14
  };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
15
+ var __copyProps = (to, from3, except, desc) => {
16
+ if (from3 && typeof from3 === "object" || typeof from3 === "function") {
17
+ for (let key of __getOwnPropNames(from3))
18
18
  if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ __defProp(to, key, { get: () => from3[key], enumerable: !(desc = __getOwnPropDesc(from3, key)) || desc.enumerable });
20
20
  }
21
21
  return to;
22
22
  };
@@ -126,6 +126,3419 @@ var init_libp2p_node = __esm({
126
126
  }
127
127
  });
128
128
 
129
+ // node_modules/multiformats/dist/src/bytes.js
130
+ function equals(aa, bb) {
131
+ if (aa === bb) {
132
+ return true;
133
+ }
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
+ function coerce(o) {
145
+ if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
146
+ return o;
147
+ }
148
+ if (o instanceof ArrayBuffer) {
149
+ return new Uint8Array(o);
150
+ }
151
+ if (ArrayBuffer.isView(o)) {
152
+ return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
153
+ }
154
+ throw new Error("Unknown type, must be binary type");
155
+ }
156
+ function fromString(str) {
157
+ return new TextEncoder().encode(str);
158
+ }
159
+ function toString(b) {
160
+ return new TextDecoder().decode(b);
161
+ }
162
+ var empty;
163
+ var init_bytes = __esm({
164
+ "node_modules/multiformats/dist/src/bytes.js"() {
165
+ "use strict";
166
+ empty = new Uint8Array(0);
167
+ }
168
+ });
169
+
170
+ // node_modules/multiformats/dist/src/vendor/base-x.js
171
+ function base(ALPHABET, name2) {
172
+ if (ALPHABET.length >= 255) {
173
+ throw new TypeError("Alphabet too long");
174
+ }
175
+ var BASE_MAP = new Uint8Array(256);
176
+ for (var j = 0; j < BASE_MAP.length; j++) {
177
+ BASE_MAP[j] = 255;
178
+ }
179
+ for (var i = 0; i < ALPHABET.length; i++) {
180
+ var x = ALPHABET.charAt(i);
181
+ var xc = x.charCodeAt(0);
182
+ if (BASE_MAP[xc] !== 255) {
183
+ throw new TypeError(x + " is ambiguous");
184
+ }
185
+ BASE_MAP[xc] = i;
186
+ }
187
+ var BASE = ALPHABET.length;
188
+ var LEADER = ALPHABET.charAt(0);
189
+ var FACTOR = Math.log(BASE) / Math.log(256);
190
+ var iFACTOR = Math.log(256) / Math.log(BASE);
191
+ function encode7(source) {
192
+ if (source instanceof Uint8Array)
193
+ ;
194
+ else if (ArrayBuffer.isView(source)) {
195
+ source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
196
+ } else if (Array.isArray(source)) {
197
+ source = Uint8Array.from(source);
198
+ }
199
+ if (!(source instanceof Uint8Array)) {
200
+ throw new TypeError("Expected Uint8Array");
201
+ }
202
+ if (source.length === 0) {
203
+ return "";
204
+ }
205
+ var zeroes = 0;
206
+ var length2 = 0;
207
+ var pbegin = 0;
208
+ var pend = source.length;
209
+ while (pbegin !== pend && source[pbegin] === 0) {
210
+ pbegin++;
211
+ zeroes++;
212
+ }
213
+ var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
214
+ var b58 = new Uint8Array(size);
215
+ while (pbegin !== pend) {
216
+ var carry = source[pbegin];
217
+ var i2 = 0;
218
+ for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
219
+ carry += 256 * b58[it1] >>> 0;
220
+ b58[it1] = carry % BASE >>> 0;
221
+ carry = carry / BASE >>> 0;
222
+ }
223
+ if (carry !== 0) {
224
+ throw new Error("Non-zero carry");
225
+ }
226
+ length2 = i2;
227
+ pbegin++;
228
+ }
229
+ var it2 = size - length2;
230
+ while (it2 !== size && b58[it2] === 0) {
231
+ it2++;
232
+ }
233
+ var str = LEADER.repeat(zeroes);
234
+ for (; it2 < size; ++it2) {
235
+ str += ALPHABET.charAt(b58[it2]);
236
+ }
237
+ return str;
238
+ }
239
+ function decodeUnsafe(source) {
240
+ if (typeof source !== "string") {
241
+ throw new TypeError("Expected String");
242
+ }
243
+ if (source.length === 0) {
244
+ return new Uint8Array();
245
+ }
246
+ var psz = 0;
247
+ if (source[psz] === " ") {
248
+ return;
249
+ }
250
+ var zeroes = 0;
251
+ var length2 = 0;
252
+ while (source[psz] === LEADER) {
253
+ zeroes++;
254
+ psz++;
255
+ }
256
+ var size = (source.length - psz) * FACTOR + 1 >>> 0;
257
+ var b256 = new Uint8Array(size);
258
+ while (source[psz]) {
259
+ var carry = BASE_MAP[source.charCodeAt(psz)];
260
+ if (carry === 255) {
261
+ return;
262
+ }
263
+ var i2 = 0;
264
+ for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
265
+ carry += BASE * b256[it3] >>> 0;
266
+ b256[it3] = carry % 256 >>> 0;
267
+ carry = carry / 256 >>> 0;
268
+ }
269
+ if (carry !== 0) {
270
+ throw new Error("Non-zero carry");
271
+ }
272
+ length2 = i2;
273
+ psz++;
274
+ }
275
+ if (source[psz] === " ") {
276
+ return;
277
+ }
278
+ var it4 = size - length2;
279
+ while (it4 !== size && b256[it4] === 0) {
280
+ it4++;
281
+ }
282
+ var vch = new Uint8Array(zeroes + (size - it4));
283
+ var j2 = zeroes;
284
+ while (it4 !== size) {
285
+ vch[j2++] = b256[it4++];
286
+ }
287
+ return vch;
288
+ }
289
+ function decode9(string2) {
290
+ var buffer = decodeUnsafe(string2);
291
+ if (buffer) {
292
+ return buffer;
293
+ }
294
+ throw new Error(`Non-${name2} character`);
295
+ }
296
+ return {
297
+ encode: encode7,
298
+ decodeUnsafe,
299
+ decode: decode9
300
+ };
301
+ }
302
+ var src, _brrp__multiformats_scope_baseX, base_x_default;
303
+ var init_base_x = __esm({
304
+ "node_modules/multiformats/dist/src/vendor/base-x.js"() {
305
+ "use strict";
306
+ src = base;
307
+ _brrp__multiformats_scope_baseX = src;
308
+ base_x_default = _brrp__multiformats_scope_baseX;
309
+ }
310
+ });
311
+
312
+ // node_modules/multiformats/dist/src/bases/base.js
313
+ function or(left, right) {
314
+ return new ComposedDecoder({
315
+ ...left.decoders ?? { [left.prefix]: left },
316
+ ...right.decoders ?? { [right.prefix]: right }
317
+ });
318
+ }
319
+ function from({ name: name2, prefix, encode: encode7, decode: decode9 }) {
320
+ return new Codec(name2, prefix, encode7, decode9);
321
+ }
322
+ function baseX({ name: name2, prefix, alphabet: alphabet2 }) {
323
+ const { encode: encode7, decode: decode9 } = base_x_default(alphabet2, name2);
324
+ return from({
325
+ prefix,
326
+ name: name2,
327
+ encode: encode7,
328
+ decode: (text) => coerce(decode9(text))
329
+ });
330
+ }
331
+ function decode3(string2, alphabetIdx, bitsPerChar, name2) {
332
+ let end = string2.length;
333
+ while (string2[end - 1] === "=") {
334
+ --end;
335
+ }
336
+ const out = new Uint8Array(end * bitsPerChar / 8 | 0);
337
+ let bits = 0;
338
+ let buffer = 0;
339
+ let written = 0;
340
+ for (let i = 0; i < end; ++i) {
341
+ const value = alphabetIdx[string2[i]];
342
+ if (value === void 0) {
343
+ throw new SyntaxError(`Non-${name2} character`);
344
+ }
345
+ buffer = buffer << bitsPerChar | value;
346
+ bits += bitsPerChar;
347
+ if (bits >= 8) {
348
+ bits -= 8;
349
+ out[written++] = 255 & buffer >> bits;
350
+ }
351
+ }
352
+ if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
353
+ throw new SyntaxError("Unexpected end of data");
354
+ }
355
+ return out;
356
+ }
357
+ function encode3(data, alphabet2, bitsPerChar) {
358
+ const pad = alphabet2[alphabet2.length - 1] === "=";
359
+ const mask = (1 << bitsPerChar) - 1;
360
+ let out = "";
361
+ let bits = 0;
362
+ let buffer = 0;
363
+ for (let i = 0; i < data.length; ++i) {
364
+ buffer = buffer << 8 | data[i];
365
+ bits += 8;
366
+ while (bits > bitsPerChar) {
367
+ bits -= bitsPerChar;
368
+ out += alphabet2[mask & buffer >> bits];
369
+ }
370
+ }
371
+ if (bits !== 0) {
372
+ out += alphabet2[mask & buffer << bitsPerChar - bits];
373
+ }
374
+ if (pad) {
375
+ while ((out.length * bitsPerChar & 7) !== 0) {
376
+ out += "=";
377
+ }
378
+ }
379
+ return out;
380
+ }
381
+ function createAlphabetIdx(alphabet2) {
382
+ const alphabetIdx = {};
383
+ for (let i = 0; i < alphabet2.length; ++i) {
384
+ alphabetIdx[alphabet2[i]] = i;
385
+ }
386
+ return alphabetIdx;
387
+ }
388
+ function rfc4648({ name: name2, prefix, bitsPerChar, alphabet: alphabet2 }) {
389
+ const alphabetIdx = createAlphabetIdx(alphabet2);
390
+ return from({
391
+ prefix,
392
+ name: name2,
393
+ encode(input) {
394
+ return encode3(input, alphabet2, bitsPerChar);
395
+ },
396
+ decode(input) {
397
+ return decode3(input, alphabetIdx, bitsPerChar, name2);
398
+ }
399
+ });
400
+ }
401
+ var Encoder, Decoder, ComposedDecoder, Codec;
402
+ var init_base = __esm({
403
+ "node_modules/multiformats/dist/src/bases/base.js"() {
404
+ "use strict";
405
+ init_bytes();
406
+ init_base_x();
407
+ Encoder = class {
408
+ name;
409
+ prefix;
410
+ baseEncode;
411
+ constructor(name2, prefix, baseEncode) {
412
+ this.name = name2;
413
+ this.prefix = prefix;
414
+ this.baseEncode = baseEncode;
415
+ }
416
+ encode(bytes) {
417
+ if (bytes instanceof Uint8Array) {
418
+ return `${this.prefix}${this.baseEncode(bytes)}`;
419
+ } else {
420
+ throw Error("Unknown type, must be binary type");
421
+ }
422
+ }
423
+ };
424
+ Decoder = class {
425
+ name;
426
+ prefix;
427
+ baseDecode;
428
+ prefixCodePoint;
429
+ constructor(name2, prefix, baseDecode) {
430
+ this.name = name2;
431
+ this.prefix = prefix;
432
+ const prefixCodePoint = prefix.codePointAt(0);
433
+ if (prefixCodePoint === void 0) {
434
+ throw new Error("Invalid prefix character");
435
+ }
436
+ this.prefixCodePoint = prefixCodePoint;
437
+ this.baseDecode = baseDecode;
438
+ }
439
+ decode(text) {
440
+ if (typeof text === "string") {
441
+ if (text.codePointAt(0) !== this.prefixCodePoint) {
442
+ throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
443
+ }
444
+ return this.baseDecode(text.slice(this.prefix.length));
445
+ } else {
446
+ throw Error("Can only multibase decode strings");
447
+ }
448
+ }
449
+ or(decoder) {
450
+ return or(this, decoder);
451
+ }
452
+ };
453
+ ComposedDecoder = class {
454
+ decoders;
455
+ constructor(decoders2) {
456
+ this.decoders = decoders2;
457
+ }
458
+ or(decoder) {
459
+ return or(this, decoder);
460
+ }
461
+ decode(input) {
462
+ const prefix = input[0];
463
+ const decoder = this.decoders[prefix];
464
+ if (decoder != null) {
465
+ return decoder.decode(input);
466
+ } else {
467
+ throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
468
+ }
469
+ }
470
+ };
471
+ Codec = class {
472
+ name;
473
+ prefix;
474
+ baseEncode;
475
+ baseDecode;
476
+ encoder;
477
+ decoder;
478
+ constructor(name2, prefix, baseEncode, baseDecode) {
479
+ this.name = name2;
480
+ this.prefix = prefix;
481
+ this.baseEncode = baseEncode;
482
+ this.baseDecode = baseDecode;
483
+ this.encoder = new Encoder(name2, prefix, baseEncode);
484
+ this.decoder = new Decoder(name2, prefix, baseDecode);
485
+ }
486
+ encode(input) {
487
+ return this.encoder.encode(input);
488
+ }
489
+ decode(input) {
490
+ return this.decoder.decode(input);
491
+ }
492
+ };
493
+ }
494
+ });
495
+
496
+ // node_modules/multiformats/dist/src/bases/base10.js
497
+ var base10_exports = {};
498
+ __export(base10_exports, {
499
+ base10: () => base10
500
+ });
501
+ var base10;
502
+ var init_base10 = __esm({
503
+ "node_modules/multiformats/dist/src/bases/base10.js"() {
504
+ "use strict";
505
+ init_base();
506
+ base10 = baseX({
507
+ prefix: "9",
508
+ name: "base10",
509
+ alphabet: "0123456789"
510
+ });
511
+ }
512
+ });
513
+
514
+ // node_modules/multiformats/dist/src/bases/base16.js
515
+ var base16_exports = {};
516
+ __export(base16_exports, {
517
+ base16: () => base16,
518
+ base16upper: () => base16upper
519
+ });
520
+ var base16, base16upper;
521
+ var init_base16 = __esm({
522
+ "node_modules/multiformats/dist/src/bases/base16.js"() {
523
+ "use strict";
524
+ init_base();
525
+ base16 = rfc4648({
526
+ prefix: "f",
527
+ name: "base16",
528
+ alphabet: "0123456789abcdef",
529
+ bitsPerChar: 4
530
+ });
531
+ base16upper = rfc4648({
532
+ prefix: "F",
533
+ name: "base16upper",
534
+ alphabet: "0123456789ABCDEF",
535
+ bitsPerChar: 4
536
+ });
537
+ }
538
+ });
539
+
540
+ // node_modules/multiformats/dist/src/bases/base2.js
541
+ var base2_exports = {};
542
+ __export(base2_exports, {
543
+ base2: () => base2
544
+ });
545
+ var base2;
546
+ var init_base2 = __esm({
547
+ "node_modules/multiformats/dist/src/bases/base2.js"() {
548
+ "use strict";
549
+ init_base();
550
+ base2 = rfc4648({
551
+ prefix: "0",
552
+ name: "base2",
553
+ alphabet: "01",
554
+ bitsPerChar: 1
555
+ });
556
+ }
557
+ });
558
+
559
+ // node_modules/multiformats/dist/src/bases/base256emoji.js
560
+ var base256emoji_exports = {};
561
+ __export(base256emoji_exports, {
562
+ base256emoji: () => base256emoji
563
+ });
564
+ function encode4(data) {
565
+ return data.reduce((p, c) => {
566
+ p += alphabetBytesToChars[c];
567
+ return p;
568
+ }, "");
569
+ }
570
+ function decode4(str) {
571
+ const byts = [];
572
+ for (const char of str) {
573
+ const codePoint = char.codePointAt(0);
574
+ if (codePoint == null) {
575
+ throw new Error(`Invalid character: ${char}`);
576
+ }
577
+ const byt = alphabetCharsToBytes[codePoint];
578
+ if (byt == null) {
579
+ throw new Error(`Non-base256emoji character: ${char}`);
580
+ }
581
+ byts.push(byt);
582
+ }
583
+ return new Uint8Array(byts);
584
+ }
585
+ var alphabet, alphabetBytesToChars, alphabetCharsToBytes, base256emoji;
586
+ var init_base256emoji = __esm({
587
+ "node_modules/multiformats/dist/src/bases/base256emoji.js"() {
588
+ "use strict";
589
+ init_base();
590
+ alphabet = Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}");
591
+ alphabetBytesToChars = alphabet.reduce((p, c, i) => {
592
+ p[i] = c;
593
+ return p;
594
+ }, []);
595
+ alphabetCharsToBytes = alphabet.reduce((p, c, i) => {
596
+ const codePoint = c.codePointAt(0);
597
+ if (codePoint == null) {
598
+ throw new Error(`Invalid character: ${c}`);
599
+ }
600
+ p[codePoint] = i;
601
+ return p;
602
+ }, []);
603
+ base256emoji = from({
604
+ prefix: "\u{1F680}",
605
+ name: "base256emoji",
606
+ encode: encode4,
607
+ decode: decode4
608
+ });
609
+ }
610
+ });
611
+
612
+ // node_modules/multiformats/dist/src/bases/base32.js
613
+ var base32_exports = {};
614
+ __export(base32_exports, {
615
+ base32: () => base32,
616
+ base32hex: () => base32hex,
617
+ base32hexpad: () => base32hexpad,
618
+ base32hexpadupper: () => base32hexpadupper,
619
+ base32hexupper: () => base32hexupper,
620
+ base32pad: () => base32pad,
621
+ base32padupper: () => base32padupper,
622
+ base32upper: () => base32upper,
623
+ base32z: () => base32z
624
+ });
625
+ var base32, base32upper, base32pad, base32padupper, base32hex, base32hexupper, base32hexpad, base32hexpadupper, base32z;
626
+ var init_base32 = __esm({
627
+ "node_modules/multiformats/dist/src/bases/base32.js"() {
628
+ "use strict";
629
+ init_base();
630
+ base32 = rfc4648({
631
+ prefix: "b",
632
+ name: "base32",
633
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567",
634
+ bitsPerChar: 5
635
+ });
636
+ base32upper = rfc4648({
637
+ prefix: "B",
638
+ name: "base32upper",
639
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
640
+ bitsPerChar: 5
641
+ });
642
+ base32pad = rfc4648({
643
+ prefix: "c",
644
+ name: "base32pad",
645
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
646
+ bitsPerChar: 5
647
+ });
648
+ base32padupper = rfc4648({
649
+ prefix: "C",
650
+ name: "base32padupper",
651
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
652
+ bitsPerChar: 5
653
+ });
654
+ base32hex = rfc4648({
655
+ prefix: "v",
656
+ name: "base32hex",
657
+ alphabet: "0123456789abcdefghijklmnopqrstuv",
658
+ bitsPerChar: 5
659
+ });
660
+ base32hexupper = rfc4648({
661
+ prefix: "V",
662
+ name: "base32hexupper",
663
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
664
+ bitsPerChar: 5
665
+ });
666
+ base32hexpad = rfc4648({
667
+ prefix: "t",
668
+ name: "base32hexpad",
669
+ alphabet: "0123456789abcdefghijklmnopqrstuv=",
670
+ bitsPerChar: 5
671
+ });
672
+ base32hexpadupper = rfc4648({
673
+ prefix: "T",
674
+ name: "base32hexpadupper",
675
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
676
+ bitsPerChar: 5
677
+ });
678
+ base32z = rfc4648({
679
+ prefix: "h",
680
+ name: "base32z",
681
+ alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
682
+ bitsPerChar: 5
683
+ });
684
+ }
685
+ });
686
+
687
+ // node_modules/multiformats/dist/src/bases/base36.js
688
+ var base36_exports = {};
689
+ __export(base36_exports, {
690
+ base36: () => base36,
691
+ base36upper: () => base36upper
692
+ });
693
+ var base36, base36upper;
694
+ var init_base36 = __esm({
695
+ "node_modules/multiformats/dist/src/bases/base36.js"() {
696
+ "use strict";
697
+ init_base();
698
+ base36 = baseX({
699
+ prefix: "k",
700
+ name: "base36",
701
+ alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
702
+ });
703
+ base36upper = baseX({
704
+ prefix: "K",
705
+ name: "base36upper",
706
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
707
+ });
708
+ }
709
+ });
710
+
711
+ // node_modules/multiformats/dist/src/bases/base58.js
712
+ var base58_exports = {};
713
+ __export(base58_exports, {
714
+ base58btc: () => base58btc,
715
+ base58flickr: () => base58flickr
716
+ });
717
+ var base58btc, base58flickr;
718
+ var init_base58 = __esm({
719
+ "node_modules/multiformats/dist/src/bases/base58.js"() {
720
+ "use strict";
721
+ init_base();
722
+ base58btc = baseX({
723
+ name: "base58btc",
724
+ prefix: "z",
725
+ alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
726
+ });
727
+ base58flickr = baseX({
728
+ name: "base58flickr",
729
+ prefix: "Z",
730
+ alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
731
+ });
732
+ }
733
+ });
734
+
735
+ // node_modules/multiformats/dist/src/bases/base64.js
736
+ var base64_exports = {};
737
+ __export(base64_exports, {
738
+ base64: () => base64,
739
+ base64pad: () => base64pad,
740
+ base64url: () => base64url,
741
+ base64urlpad: () => base64urlpad
742
+ });
743
+ var base64, base64pad, base64url, base64urlpad;
744
+ var init_base64 = __esm({
745
+ "node_modules/multiformats/dist/src/bases/base64.js"() {
746
+ "use strict";
747
+ init_base();
748
+ base64 = rfc4648({
749
+ prefix: "m",
750
+ name: "base64",
751
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
752
+ bitsPerChar: 6
753
+ });
754
+ base64pad = rfc4648({
755
+ prefix: "M",
756
+ name: "base64pad",
757
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
758
+ bitsPerChar: 6
759
+ });
760
+ base64url = rfc4648({
761
+ prefix: "u",
762
+ name: "base64url",
763
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
764
+ bitsPerChar: 6
765
+ });
766
+ base64urlpad = rfc4648({
767
+ prefix: "U",
768
+ name: "base64urlpad",
769
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
770
+ bitsPerChar: 6
771
+ });
772
+ }
773
+ });
774
+
775
+ // node_modules/multiformats/dist/src/bases/base8.js
776
+ var base8_exports = {};
777
+ __export(base8_exports, {
778
+ base8: () => base8
779
+ });
780
+ var base8;
781
+ var init_base8 = __esm({
782
+ "node_modules/multiformats/dist/src/bases/base8.js"() {
783
+ "use strict";
784
+ init_base();
785
+ base8 = rfc4648({
786
+ prefix: "7",
787
+ name: "base8",
788
+ alphabet: "01234567",
789
+ bitsPerChar: 3
790
+ });
791
+ }
792
+ });
793
+
794
+ // node_modules/multiformats/dist/src/bases/identity.js
795
+ var identity_exports = {};
796
+ __export(identity_exports, {
797
+ identity: () => identity
798
+ });
799
+ var identity;
800
+ var init_identity = __esm({
801
+ "node_modules/multiformats/dist/src/bases/identity.js"() {
802
+ "use strict";
803
+ init_bytes();
804
+ init_base();
805
+ identity = from({
806
+ prefix: "\0",
807
+ name: "identity",
808
+ encode: (buf) => toString(buf),
809
+ decode: (str) => fromString(str)
810
+ });
811
+ }
812
+ });
813
+
814
+ // node_modules/multiformats/dist/src/codecs/json.js
815
+ var textEncoder, textDecoder;
816
+ var init_json = __esm({
817
+ "node_modules/multiformats/dist/src/codecs/json.js"() {
818
+ "use strict";
819
+ textEncoder = new TextEncoder();
820
+ textDecoder = new TextDecoder();
821
+ }
822
+ });
823
+
824
+ // node_modules/multiformats/dist/src/codecs/raw.js
825
+ var init_raw = __esm({
826
+ "node_modules/multiformats/dist/src/codecs/raw.js"() {
827
+ "use strict";
828
+ init_bytes();
829
+ }
830
+ });
831
+
832
+ // node_modules/multiformats/dist/src/vendor/varint.js
833
+ function encode5(num, out, offset) {
834
+ out = out || [];
835
+ offset = offset || 0;
836
+ var oldOffset = offset;
837
+ while (num >= INT) {
838
+ out[offset++] = num & 255 | MSB;
839
+ num /= 128;
840
+ }
841
+ while (num & MSBALL) {
842
+ out[offset++] = num & 255 | MSB;
843
+ num >>>= 7;
844
+ }
845
+ out[offset] = num | 0;
846
+ encode5.bytes = offset - oldOffset + 1;
847
+ return out;
848
+ }
849
+ function read(buf, offset) {
850
+ var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
851
+ do {
852
+ if (counter >= l) {
853
+ read.bytes = 0;
854
+ throw new RangeError("Could not decode varint");
855
+ }
856
+ b = buf[counter++];
857
+ res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
858
+ shift += 7;
859
+ } while (b >= MSB$1);
860
+ read.bytes = counter - offset;
861
+ return res;
862
+ }
863
+ var encode_1, MSB, REST, MSBALL, INT, decode5, MSB$1, REST$1, N1, N2, N3, N4, N5, N6, N7, N8, N9, length, varint, _brrp_varint, varint_default;
864
+ var init_varint = __esm({
865
+ "node_modules/multiformats/dist/src/vendor/varint.js"() {
866
+ "use strict";
867
+ encode_1 = encode5;
868
+ MSB = 128;
869
+ REST = 127;
870
+ MSBALL = ~REST;
871
+ INT = Math.pow(2, 31);
872
+ decode5 = read;
873
+ MSB$1 = 128;
874
+ REST$1 = 127;
875
+ N1 = Math.pow(2, 7);
876
+ N2 = Math.pow(2, 14);
877
+ N3 = Math.pow(2, 21);
878
+ N4 = Math.pow(2, 28);
879
+ N5 = Math.pow(2, 35);
880
+ N6 = Math.pow(2, 42);
881
+ N7 = Math.pow(2, 49);
882
+ N8 = Math.pow(2, 56);
883
+ N9 = Math.pow(2, 63);
884
+ length = function(value) {
885
+ 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;
886
+ };
887
+ varint = {
888
+ encode: encode_1,
889
+ decode: decode5,
890
+ encodingLength: length
891
+ };
892
+ _brrp_varint = varint;
893
+ varint_default = _brrp_varint;
894
+ }
895
+ });
896
+
897
+ // node_modules/multiformats/dist/src/varint.js
898
+ function decode6(data, offset = 0) {
899
+ const code2 = varint_default.decode(data, offset);
900
+ return [code2, varint_default.decode.bytes];
901
+ }
902
+ function encodeTo(int, target, offset = 0) {
903
+ varint_default.encode(int, target, offset);
904
+ return target;
905
+ }
906
+ function encodingLength(int) {
907
+ return varint_default.encodingLength(int);
908
+ }
909
+ var init_varint2 = __esm({
910
+ "node_modules/multiformats/dist/src/varint.js"() {
911
+ "use strict";
912
+ init_varint();
913
+ }
914
+ });
915
+
916
+ // node_modules/multiformats/dist/src/hashes/digest.js
917
+ function create(code2, digest2) {
918
+ const size = digest2.byteLength;
919
+ const sizeOffset = encodingLength(code2);
920
+ const digestOffset = sizeOffset + encodingLength(size);
921
+ const bytes = new Uint8Array(digestOffset + size);
922
+ encodeTo(code2, bytes, 0);
923
+ encodeTo(size, bytes, sizeOffset);
924
+ bytes.set(digest2, digestOffset);
925
+ return new Digest(code2, size, digest2, bytes);
926
+ }
927
+ function decode7(multihash) {
928
+ const bytes = coerce(multihash);
929
+ const [code2, sizeOffset] = decode6(bytes);
930
+ const [size, digestOffset] = decode6(bytes.subarray(sizeOffset));
931
+ const digest2 = bytes.subarray(sizeOffset + digestOffset);
932
+ if (digest2.byteLength !== size) {
933
+ throw new Error("Incorrect length");
934
+ }
935
+ return new Digest(code2, size, digest2, bytes);
936
+ }
937
+ function equals2(a, b) {
938
+ if (a === b) {
939
+ return true;
940
+ } else {
941
+ const data = b;
942
+ return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
943
+ }
944
+ }
945
+ var Digest;
946
+ var init_digest = __esm({
947
+ "node_modules/multiformats/dist/src/hashes/digest.js"() {
948
+ "use strict";
949
+ init_bytes();
950
+ init_varint2();
951
+ Digest = class {
952
+ code;
953
+ size;
954
+ digest;
955
+ bytes;
956
+ /**
957
+ * Creates a multihash digest.
958
+ */
959
+ constructor(code2, size, digest2, bytes) {
960
+ this.code = code2;
961
+ this.size = size;
962
+ this.digest = digest2;
963
+ this.bytes = bytes;
964
+ }
965
+ };
966
+ }
967
+ });
968
+
969
+ // node_modules/multiformats/dist/src/hashes/identity.js
970
+ var identity_exports2 = {};
971
+ __export(identity_exports2, {
972
+ identity: () => identity2
973
+ });
974
+ function digest(input, options) {
975
+ if (options?.truncate != null && options.truncate !== input.byteLength) {
976
+ if (options.truncate < 0 || options.truncate > input.byteLength) {
977
+ throw new Error(`Invalid truncate option, must be less than or equal to ${input.byteLength}`);
978
+ }
979
+ input = input.subarray(0, options.truncate);
980
+ }
981
+ return create(code, encode6(input));
982
+ }
983
+ var code, name, encode6, identity2;
984
+ var init_identity2 = __esm({
985
+ "node_modules/multiformats/dist/src/hashes/identity.js"() {
986
+ "use strict";
987
+ init_bytes();
988
+ init_digest();
989
+ code = 0;
990
+ name = "identity";
991
+ encode6 = coerce;
992
+ identity2 = { code, name, encode: encode6, digest };
993
+ }
994
+ });
995
+
996
+ // node_modules/multiformats/dist/src/hashes/hasher.js
997
+ function from2({ name: name2, code: code2, encode: encode7, minDigestLength, maxDigestLength }) {
998
+ return new Hasher(name2, code2, encode7, minDigestLength, maxDigestLength);
999
+ }
1000
+ function createDigest(digest2, code2, truncate) {
1001
+ if (truncate != null && truncate !== digest2.byteLength) {
1002
+ if (truncate > digest2.byteLength) {
1003
+ throw new Error(`Invalid truncate option, must be less than or equal to ${digest2.byteLength}`);
1004
+ }
1005
+ digest2 = digest2.subarray(0, truncate);
1006
+ }
1007
+ return create(code2, digest2);
1008
+ }
1009
+ var DEFAULT_MIN_DIGEST_LENGTH, Hasher;
1010
+ var init_hasher = __esm({
1011
+ "node_modules/multiformats/dist/src/hashes/hasher.js"() {
1012
+ "use strict";
1013
+ init_digest();
1014
+ DEFAULT_MIN_DIGEST_LENGTH = 20;
1015
+ Hasher = class {
1016
+ name;
1017
+ code;
1018
+ encode;
1019
+ minDigestLength;
1020
+ maxDigestLength;
1021
+ constructor(name2, code2, encode7, minDigestLength, maxDigestLength) {
1022
+ this.name = name2;
1023
+ this.code = code2;
1024
+ this.encode = encode7;
1025
+ this.minDigestLength = minDigestLength ?? DEFAULT_MIN_DIGEST_LENGTH;
1026
+ this.maxDigestLength = maxDigestLength;
1027
+ }
1028
+ digest(input, options) {
1029
+ if (options?.truncate != null) {
1030
+ if (options.truncate < this.minDigestLength) {
1031
+ throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);
1032
+ }
1033
+ if (this.maxDigestLength != null && options.truncate > this.maxDigestLength) {
1034
+ throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`);
1035
+ }
1036
+ }
1037
+ if (input instanceof Uint8Array) {
1038
+ const result = this.encode(input);
1039
+ if (result instanceof Uint8Array) {
1040
+ return createDigest(result, this.code, options?.truncate);
1041
+ }
1042
+ return result.then((digest2) => createDigest(digest2, this.code, options?.truncate));
1043
+ } else {
1044
+ throw Error("Unknown type, must be binary type");
1045
+ }
1046
+ }
1047
+ };
1048
+ }
1049
+ });
1050
+
1051
+ // node_modules/multiformats/dist/src/hashes/sha2.js
1052
+ var sha2_exports = {};
1053
+ __export(sha2_exports, {
1054
+ sha256: () => sha2565,
1055
+ sha512: () => sha512
1056
+ });
1057
+ var import_crypto, sha2565, sha512;
1058
+ var init_sha2 = __esm({
1059
+ "node_modules/multiformats/dist/src/hashes/sha2.js"() {
1060
+ "use strict";
1061
+ import_crypto = __toESM(require("crypto"), 1);
1062
+ init_bytes();
1063
+ init_hasher();
1064
+ sha2565 = from2({
1065
+ name: "sha2-256",
1066
+ code: 18,
1067
+ encode: (input) => coerce(import_crypto.default.createHash("sha256").update(input).digest())
1068
+ });
1069
+ sha512 = from2({
1070
+ name: "sha2-512",
1071
+ code: 19,
1072
+ encode: (input) => coerce(import_crypto.default.createHash("sha512").update(input).digest())
1073
+ });
1074
+ }
1075
+ });
1076
+
1077
+ // node_modules/multiformats/dist/src/link/interface.js
1078
+ var init_interface = __esm({
1079
+ "node_modules/multiformats/dist/src/link/interface.js"() {
1080
+ "use strict";
1081
+ }
1082
+ });
1083
+
1084
+ // node_modules/multiformats/dist/src/cid.js
1085
+ function format(link, base3) {
1086
+ const { bytes, version } = link;
1087
+ switch (version) {
1088
+ case 0:
1089
+ return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
1090
+ default:
1091
+ return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
1092
+ }
1093
+ }
1094
+ function baseCache(cid) {
1095
+ const baseCache2 = cache.get(cid);
1096
+ if (baseCache2 == null) {
1097
+ const baseCache3 = /* @__PURE__ */ new Map();
1098
+ cache.set(cid, baseCache3);
1099
+ return baseCache3;
1100
+ }
1101
+ return baseCache2;
1102
+ }
1103
+ function parseCIDtoBytes(source, base3) {
1104
+ switch (source[0]) {
1105
+ // CIDv0 is parsed differently
1106
+ case "Q": {
1107
+ const decoder = base3 ?? base58btc;
1108
+ return [
1109
+ base58btc.prefix,
1110
+ decoder.decode(`${base58btc.prefix}${source}`)
1111
+ ];
1112
+ }
1113
+ case base58btc.prefix: {
1114
+ const decoder = base3 ?? base58btc;
1115
+ return [base58btc.prefix, decoder.decode(source)];
1116
+ }
1117
+ case base32.prefix: {
1118
+ const decoder = base3 ?? base32;
1119
+ return [base32.prefix, decoder.decode(source)];
1120
+ }
1121
+ case base36.prefix: {
1122
+ const decoder = base3 ?? base36;
1123
+ return [base36.prefix, decoder.decode(source)];
1124
+ }
1125
+ default: {
1126
+ if (base3 == null) {
1127
+ throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
1128
+ }
1129
+ return [source[0], base3.decode(source)];
1130
+ }
1131
+ }
1132
+ }
1133
+ function toStringV0(bytes, cache2, base3) {
1134
+ const { prefix } = base3;
1135
+ if (prefix !== base58btc.prefix) {
1136
+ throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
1137
+ }
1138
+ const cid = cache2.get(prefix);
1139
+ if (cid == null) {
1140
+ const cid2 = base3.encode(bytes).slice(1);
1141
+ cache2.set(prefix, cid2);
1142
+ return cid2;
1143
+ } else {
1144
+ return cid;
1145
+ }
1146
+ }
1147
+ function toStringV1(bytes, cache2, base3) {
1148
+ const { prefix } = base3;
1149
+ const cid = cache2.get(prefix);
1150
+ if (cid == null) {
1151
+ const cid2 = base3.encode(bytes);
1152
+ cache2.set(prefix, cid2);
1153
+ return cid2;
1154
+ } else {
1155
+ return cid;
1156
+ }
1157
+ }
1158
+ function encodeCID(version, code2, multihash) {
1159
+ const codeOffset = encodingLength(version);
1160
+ const hashOffset = codeOffset + encodingLength(code2);
1161
+ const bytes = new Uint8Array(hashOffset + multihash.byteLength);
1162
+ encodeTo(version, bytes, 0);
1163
+ encodeTo(code2, bytes, codeOffset);
1164
+ bytes.set(multihash, hashOffset);
1165
+ return bytes;
1166
+ }
1167
+ var cache, CID, DAG_PB_CODE, SHA_256_CODE, cidSymbol;
1168
+ var init_cid = __esm({
1169
+ "node_modules/multiformats/dist/src/cid.js"() {
1170
+ "use strict";
1171
+ init_base32();
1172
+ init_base36();
1173
+ init_base58();
1174
+ init_bytes();
1175
+ init_digest();
1176
+ init_varint2();
1177
+ init_interface();
1178
+ cache = /* @__PURE__ */ new WeakMap();
1179
+ CID = class _CID {
1180
+ code;
1181
+ version;
1182
+ multihash;
1183
+ bytes;
1184
+ "/";
1185
+ /**
1186
+ * @param version - Version of the CID
1187
+ * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
1188
+ * @param multihash - (Multi)hash of the of the content.
1189
+ */
1190
+ constructor(version, code2, multihash, bytes) {
1191
+ this.code = code2;
1192
+ this.version = version;
1193
+ this.multihash = multihash;
1194
+ this.bytes = bytes;
1195
+ this["/"] = bytes;
1196
+ }
1197
+ /**
1198
+ * Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
1199
+ * please either use `CID.asCID(cid)` or switch to new signalling mechanism
1200
+ *
1201
+ * @deprecated
1202
+ */
1203
+ get asCID() {
1204
+ return this;
1205
+ }
1206
+ // ArrayBufferView
1207
+ get byteOffset() {
1208
+ return this.bytes.byteOffset;
1209
+ }
1210
+ // ArrayBufferView
1211
+ get byteLength() {
1212
+ return this.bytes.byteLength;
1213
+ }
1214
+ toV0() {
1215
+ switch (this.version) {
1216
+ case 0: {
1217
+ return this;
1218
+ }
1219
+ case 1: {
1220
+ const { code: code2, multihash } = this;
1221
+ if (code2 !== DAG_PB_CODE) {
1222
+ throw new Error("Cannot convert a non dag-pb CID to CIDv0");
1223
+ }
1224
+ if (multihash.code !== SHA_256_CODE) {
1225
+ throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
1226
+ }
1227
+ return _CID.createV0(multihash);
1228
+ }
1229
+ default: {
1230
+ throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
1231
+ }
1232
+ }
1233
+ }
1234
+ toV1() {
1235
+ switch (this.version) {
1236
+ case 0: {
1237
+ const { code: code2, digest: digest2 } = this.multihash;
1238
+ const multihash = create(code2, digest2);
1239
+ return _CID.createV1(this.code, multihash);
1240
+ }
1241
+ case 1: {
1242
+ return this;
1243
+ }
1244
+ default: {
1245
+ throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
1246
+ }
1247
+ }
1248
+ }
1249
+ equals(other) {
1250
+ return _CID.equals(this, other);
1251
+ }
1252
+ static equals(self, other) {
1253
+ const unknown = other;
1254
+ return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
1255
+ }
1256
+ toString(base3) {
1257
+ return format(this, base3);
1258
+ }
1259
+ toJSON() {
1260
+ return { "/": format(this) };
1261
+ }
1262
+ link() {
1263
+ return this;
1264
+ }
1265
+ [Symbol.toStringTag] = "CID";
1266
+ // Legacy
1267
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
1268
+ return `CID(${this.toString()})`;
1269
+ }
1270
+ /**
1271
+ * Takes any input `value` and returns a `CID` instance if it was
1272
+ * a `CID` otherwise returns `null`. If `value` is instanceof `CID`
1273
+ * it will return value back. If `value` is not instance of this CID
1274
+ * class, but is compatible CID it will return new instance of this
1275
+ * `CID` class. Otherwise returns null.
1276
+ *
1277
+ * This allows two different incompatible versions of CID library to
1278
+ * co-exist and interop as long as binary interface is compatible.
1279
+ */
1280
+ static asCID(input) {
1281
+ if (input == null) {
1282
+ return null;
1283
+ }
1284
+ const value = input;
1285
+ if (value instanceof _CID) {
1286
+ return value;
1287
+ } else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
1288
+ const { version, code: code2, multihash, bytes } = value;
1289
+ return new _CID(version, code2, multihash, bytes ?? encodeCID(version, code2, multihash.bytes));
1290
+ } else if (value[cidSymbol] === true) {
1291
+ const { version, multihash, code: code2 } = value;
1292
+ const digest2 = decode7(multihash);
1293
+ return _CID.create(version, code2, digest2);
1294
+ } else {
1295
+ return null;
1296
+ }
1297
+ }
1298
+ /**
1299
+ * @param version - Version of the CID
1300
+ * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
1301
+ * @param digest - (Multi)hash of the of the content.
1302
+ */
1303
+ static create(version, code2, digest2) {
1304
+ if (typeof code2 !== "number") {
1305
+ throw new Error("String codecs are no longer supported");
1306
+ }
1307
+ if (!(digest2.bytes instanceof Uint8Array)) {
1308
+ throw new Error("Invalid digest");
1309
+ }
1310
+ switch (version) {
1311
+ case 0: {
1312
+ if (code2 !== DAG_PB_CODE) {
1313
+ throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
1314
+ } else {
1315
+ return new _CID(version, code2, digest2, digest2.bytes);
1316
+ }
1317
+ }
1318
+ case 1: {
1319
+ const bytes = encodeCID(version, code2, digest2.bytes);
1320
+ return new _CID(version, code2, digest2, bytes);
1321
+ }
1322
+ default: {
1323
+ throw new Error("Invalid version");
1324
+ }
1325
+ }
1326
+ }
1327
+ /**
1328
+ * Simplified version of `create` for CIDv0.
1329
+ */
1330
+ static createV0(digest2) {
1331
+ return _CID.create(0, DAG_PB_CODE, digest2);
1332
+ }
1333
+ /**
1334
+ * Simplified version of `create` for CIDv1.
1335
+ *
1336
+ * @param code - Content encoding format code.
1337
+ * @param digest - Multihash of the content.
1338
+ */
1339
+ static createV1(code2, digest2) {
1340
+ return _CID.create(1, code2, digest2);
1341
+ }
1342
+ /**
1343
+ * Decoded a CID from its binary representation. The byte array must contain
1344
+ * only the CID with no additional bytes.
1345
+ *
1346
+ * An error will be thrown if the bytes provided do not contain a valid
1347
+ * binary representation of a CID.
1348
+ */
1349
+ static decode(bytes) {
1350
+ const [cid, remainder] = _CID.decodeFirst(bytes);
1351
+ if (remainder.length !== 0) {
1352
+ throw new Error("Incorrect length");
1353
+ }
1354
+ return cid;
1355
+ }
1356
+ /**
1357
+ * Decoded a CID from its binary representation at the beginning of a byte
1358
+ * array.
1359
+ *
1360
+ * Returns an array with the first element containing the CID and the second
1361
+ * element containing the remainder of the original byte array. The remainder
1362
+ * will be a zero-length byte array if the provided bytes only contained a
1363
+ * binary CID representation.
1364
+ */
1365
+ static decodeFirst(bytes) {
1366
+ const specs = _CID.inspectBytes(bytes);
1367
+ const prefixSize = specs.size - specs.multihashSize;
1368
+ const multihashBytes = coerce(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
1369
+ if (multihashBytes.byteLength !== specs.multihashSize) {
1370
+ throw new Error("Incorrect length");
1371
+ }
1372
+ const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
1373
+ const digest2 = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
1374
+ const cid = specs.version === 0 ? _CID.createV0(digest2) : _CID.createV1(specs.codec, digest2);
1375
+ return [cid, bytes.subarray(specs.size)];
1376
+ }
1377
+ /**
1378
+ * Inspect the initial bytes of a CID to determine its properties.
1379
+ *
1380
+ * Involves decoding up to 4 varints. Typically this will require only 4 to 6
1381
+ * bytes but for larger multicodec code values and larger multihash digest
1382
+ * lengths these varints can be quite large. It is recommended that at least
1383
+ * 10 bytes be made available in the `initialBytes` argument for a complete
1384
+ * inspection.
1385
+ */
1386
+ static inspectBytes(initialBytes) {
1387
+ let offset = 0;
1388
+ const next = () => {
1389
+ const [i, length2] = decode6(initialBytes.subarray(offset));
1390
+ offset += length2;
1391
+ return i;
1392
+ };
1393
+ let version = next();
1394
+ let codec = DAG_PB_CODE;
1395
+ if (version === 18) {
1396
+ version = 0;
1397
+ offset = 0;
1398
+ } else {
1399
+ codec = next();
1400
+ }
1401
+ if (version !== 0 && version !== 1) {
1402
+ throw new RangeError(`Invalid CID version ${version}`);
1403
+ }
1404
+ const prefixSize = offset;
1405
+ const multihashCode = next();
1406
+ const digestSize = next();
1407
+ const size = offset + digestSize;
1408
+ const multihashSize = size - prefixSize;
1409
+ return { version, codec, multihashCode, digestSize, multihashSize, size };
1410
+ }
1411
+ /**
1412
+ * Takes cid in a string representation and creates an instance. If `base`
1413
+ * decoder is not provided will use a default from the configuration. It will
1414
+ * throw an error if encoding of the CID is not compatible with supplied (or
1415
+ * a default decoder).
1416
+ */
1417
+ static parse(source, base3) {
1418
+ const [prefix, bytes] = parseCIDtoBytes(source, base3);
1419
+ const cid = _CID.decode(bytes);
1420
+ if (cid.version === 0 && source[0] !== "Q") {
1421
+ throw Error("Version 0 CID string must not include multibase prefix");
1422
+ }
1423
+ baseCache(cid).set(prefix, source);
1424
+ return cid;
1425
+ }
1426
+ };
1427
+ DAG_PB_CODE = 112;
1428
+ SHA_256_CODE = 18;
1429
+ cidSymbol = /* @__PURE__ */ Symbol.for("@ipld/js-cid/CID");
1430
+ }
1431
+ });
1432
+
1433
+ // node_modules/multiformats/dist/src/bases/interface.js
1434
+ var init_interface2 = __esm({
1435
+ "node_modules/multiformats/dist/src/bases/interface.js"() {
1436
+ "use strict";
1437
+ }
1438
+ });
1439
+
1440
+ // node_modules/multiformats/dist/src/hashes/interface.js
1441
+ var init_interface3 = __esm({
1442
+ "node_modules/multiformats/dist/src/hashes/interface.js"() {
1443
+ "use strict";
1444
+ }
1445
+ });
1446
+
1447
+ // node_modules/multiformats/dist/src/codecs/interface.js
1448
+ var init_interface4 = __esm({
1449
+ "node_modules/multiformats/dist/src/codecs/interface.js"() {
1450
+ "use strict";
1451
+ }
1452
+ });
1453
+
1454
+ // node_modules/multiformats/dist/src/block/interface.js
1455
+ var init_interface5 = __esm({
1456
+ "node_modules/multiformats/dist/src/block/interface.js"() {
1457
+ "use strict";
1458
+ }
1459
+ });
1460
+
1461
+ // node_modules/multiformats/dist/src/interface.js
1462
+ var init_interface6 = __esm({
1463
+ "node_modules/multiformats/dist/src/interface.js"() {
1464
+ "use strict";
1465
+ init_interface2();
1466
+ init_interface3();
1467
+ init_interface4();
1468
+ init_interface();
1469
+ init_interface5();
1470
+ }
1471
+ });
1472
+
1473
+ // node_modules/multiformats/dist/src/index.js
1474
+ var init_src = __esm({
1475
+ "node_modules/multiformats/dist/src/index.js"() {
1476
+ "use strict";
1477
+ init_bytes();
1478
+ init_cid();
1479
+ init_digest();
1480
+ init_hasher();
1481
+ init_varint2();
1482
+ init_interface6();
1483
+ }
1484
+ });
1485
+
1486
+ // node_modules/multiformats/dist/src/basics.js
1487
+ var bases, hashes;
1488
+ var init_basics = __esm({
1489
+ "node_modules/multiformats/dist/src/basics.js"() {
1490
+ "use strict";
1491
+ init_base10();
1492
+ init_base16();
1493
+ init_base2();
1494
+ init_base256emoji();
1495
+ init_base32();
1496
+ init_base36();
1497
+ init_base58();
1498
+ init_base64();
1499
+ init_base8();
1500
+ init_identity();
1501
+ init_json();
1502
+ init_raw();
1503
+ init_identity2();
1504
+ init_sha2();
1505
+ init_src();
1506
+ bases = { ...identity_exports, ...base2_exports, ...base8_exports, ...base10_exports, ...base16_exports, ...base32_exports, ...base36_exports, ...base58_exports, ...base64_exports, ...base256emoji_exports };
1507
+ hashes = { ...sha2_exports, ...identity_exports2 };
1508
+ }
1509
+ });
1510
+
1511
+ // node_modules/uint8arrays/dist/src/util/as-uint8array.node.js
1512
+ function asUint8Array(buf) {
1513
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
1514
+ }
1515
+ var init_as_uint8array_node = __esm({
1516
+ "node_modules/uint8arrays/dist/src/util/as-uint8array.node.js"() {
1517
+ "use strict";
1518
+ }
1519
+ });
1520
+
1521
+ // node_modules/uint8arrays/dist/src/alloc.node.js
1522
+ function allocUnsafe(size = 0) {
1523
+ return asUint8Array(import_node_buffer.Buffer.allocUnsafe(size));
1524
+ }
1525
+ var import_node_buffer;
1526
+ var init_alloc_node = __esm({
1527
+ "node_modules/uint8arrays/dist/src/alloc.node.js"() {
1528
+ "use strict";
1529
+ import_node_buffer = require("buffer");
1530
+ init_as_uint8array_node();
1531
+ }
1532
+ });
1533
+
1534
+ // node_modules/uint8arrays/dist/src/util/bases.js
1535
+ function createCodec(name2, prefix, encode7, decode9) {
1536
+ return {
1537
+ name: name2,
1538
+ prefix,
1539
+ encoder: {
1540
+ name: name2,
1541
+ prefix,
1542
+ encode: encode7
1543
+ },
1544
+ decoder: {
1545
+ decode: decode9
1546
+ }
1547
+ };
1548
+ }
1549
+ var string, ascii, BASES, bases_default;
1550
+ var init_bases = __esm({
1551
+ "node_modules/uint8arrays/dist/src/util/bases.js"() {
1552
+ "use strict";
1553
+ init_basics();
1554
+ init_alloc_node();
1555
+ string = createCodec("utf8", "u", (buf) => {
1556
+ const decoder = new TextDecoder("utf8");
1557
+ return "u" + decoder.decode(buf);
1558
+ }, (str) => {
1559
+ const encoder2 = new TextEncoder();
1560
+ return encoder2.encode(str.substring(1));
1561
+ });
1562
+ ascii = createCodec("ascii", "a", (buf) => {
1563
+ let string2 = "a";
1564
+ for (let i = 0; i < buf.length; i++) {
1565
+ string2 += String.fromCharCode(buf[i]);
1566
+ }
1567
+ return string2;
1568
+ }, (str) => {
1569
+ str = str.substring(1);
1570
+ const buf = allocUnsafe(str.length);
1571
+ for (let i = 0; i < str.length; i++) {
1572
+ buf[i] = str.charCodeAt(i);
1573
+ }
1574
+ return buf;
1575
+ });
1576
+ BASES = {
1577
+ utf8: string,
1578
+ "utf-8": string,
1579
+ hex: bases.base16,
1580
+ latin1: ascii,
1581
+ ascii,
1582
+ binary: ascii,
1583
+ ...bases
1584
+ };
1585
+ bases_default = BASES;
1586
+ }
1587
+ });
1588
+
1589
+ // node_modules/uint8arrays/dist/src/to-string.node.js
1590
+ function toString2(array, encoding = "utf8") {
1591
+ const base3 = bases_default[encoding];
1592
+ if (base3 == null) {
1593
+ throw new Error(`Unsupported encoding "${encoding}"`);
1594
+ }
1595
+ if (encoding === "utf8" || encoding === "utf-8") {
1596
+ return import_node_buffer2.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString("utf8");
1597
+ }
1598
+ return base3.encoder.encode(array).substring(1);
1599
+ }
1600
+ var import_node_buffer2;
1601
+ var init_to_string_node = __esm({
1602
+ "node_modules/uint8arrays/dist/src/to-string.node.js"() {
1603
+ "use strict";
1604
+ import_node_buffer2 = require("buffer");
1605
+ init_bases();
1606
+ }
1607
+ });
1608
+
1609
+ // node_modules/@multiformats/multiaddr/dist/src/errors.js
1610
+ var InvalidMultiaddrError, ValidationError, InvalidParametersError, UnknownProtocolError;
1611
+ var init_errors = __esm({
1612
+ "node_modules/@multiformats/multiaddr/dist/src/errors.js"() {
1613
+ "use strict";
1614
+ InvalidMultiaddrError = class extends Error {
1615
+ static name = "InvalidMultiaddrError";
1616
+ name = "InvalidMultiaddrError";
1617
+ };
1618
+ ValidationError = class extends Error {
1619
+ static name = "ValidationError";
1620
+ name = "ValidationError";
1621
+ };
1622
+ InvalidParametersError = class extends Error {
1623
+ static name = "InvalidParametersError";
1624
+ name = "InvalidParametersError";
1625
+ };
1626
+ UnknownProtocolError = class extends Error {
1627
+ static name = "UnknownProtocolError";
1628
+ name = "UnknownProtocolError";
1629
+ };
1630
+ }
1631
+ });
1632
+
1633
+ // node_modules/uint8arrays/dist/src/equals.js
1634
+ function equals3(a, b) {
1635
+ if (a === b) {
1636
+ return true;
1637
+ }
1638
+ if (a.byteLength !== b.byteLength) {
1639
+ return false;
1640
+ }
1641
+ for (let i = 0; i < a.byteLength; i++) {
1642
+ if (a[i] !== b[i]) {
1643
+ return false;
1644
+ }
1645
+ }
1646
+ return true;
1647
+ }
1648
+ var init_equals = __esm({
1649
+ "node_modules/uint8arrays/dist/src/equals.js"() {
1650
+ "use strict";
1651
+ }
1652
+ });
1653
+
1654
+ // node_modules/uint8arrays/dist/src/from-string.node.js
1655
+ function fromString2(string2, encoding = "utf8") {
1656
+ const base3 = bases_default[encoding];
1657
+ if (base3 == null) {
1658
+ throw new Error(`Unsupported encoding "${encoding}"`);
1659
+ }
1660
+ if (encoding === "utf8" || encoding === "utf-8") {
1661
+ return asUint8Array(import_node_buffer3.Buffer.from(string2, "utf-8"));
1662
+ }
1663
+ return base3.decoder.decode(`${base3.prefix}${string2}`);
1664
+ }
1665
+ var import_node_buffer3;
1666
+ var init_from_string_node = __esm({
1667
+ "node_modules/uint8arrays/dist/src/from-string.node.js"() {
1668
+ "use strict";
1669
+ import_node_buffer3 = require("buffer");
1670
+ init_bases();
1671
+ init_as_uint8array_node();
1672
+ }
1673
+ });
1674
+
1675
+ // node_modules/uint8-varint/dist/src/index.js
1676
+ function encodingLength2(value) {
1677
+ if (value < N12) {
1678
+ return 1;
1679
+ }
1680
+ if (value < N22) {
1681
+ return 2;
1682
+ }
1683
+ if (value < N32) {
1684
+ return 3;
1685
+ }
1686
+ if (value < N42) {
1687
+ return 4;
1688
+ }
1689
+ if (value < N52) {
1690
+ return 5;
1691
+ }
1692
+ if (value < N62) {
1693
+ return 6;
1694
+ }
1695
+ if (value < N72) {
1696
+ return 7;
1697
+ }
1698
+ if (Number.MAX_SAFE_INTEGER != null && value > Number.MAX_SAFE_INTEGER) {
1699
+ throw new RangeError("Could not encode varint");
1700
+ }
1701
+ return 8;
1702
+ }
1703
+ function encodeUint8Array(value, buf, offset = 0) {
1704
+ switch (encodingLength2(value)) {
1705
+ case 8: {
1706
+ buf[offset++] = value & 255 | MSB2;
1707
+ value /= 128;
1708
+ }
1709
+ case 7: {
1710
+ buf[offset++] = value & 255 | MSB2;
1711
+ value /= 128;
1712
+ }
1713
+ case 6: {
1714
+ buf[offset++] = value & 255 | MSB2;
1715
+ value /= 128;
1716
+ }
1717
+ case 5: {
1718
+ buf[offset++] = value & 255 | MSB2;
1719
+ value /= 128;
1720
+ }
1721
+ case 4: {
1722
+ buf[offset++] = value & 255 | MSB2;
1723
+ value >>>= 7;
1724
+ }
1725
+ case 3: {
1726
+ buf[offset++] = value & 255 | MSB2;
1727
+ value >>>= 7;
1728
+ }
1729
+ case 2: {
1730
+ buf[offset++] = value & 255 | MSB2;
1731
+ value >>>= 7;
1732
+ }
1733
+ case 1: {
1734
+ buf[offset++] = value & 255;
1735
+ value >>>= 7;
1736
+ break;
1737
+ }
1738
+ default:
1739
+ throw new Error("unreachable");
1740
+ }
1741
+ return buf;
1742
+ }
1743
+ function decodeUint8Array(buf, offset) {
1744
+ let b = buf[offset];
1745
+ let res = 0;
1746
+ res += b & REST2;
1747
+ if (b < MSB2) {
1748
+ return res;
1749
+ }
1750
+ b = buf[offset + 1];
1751
+ res += (b & REST2) << 7;
1752
+ if (b < MSB2) {
1753
+ return res;
1754
+ }
1755
+ b = buf[offset + 2];
1756
+ res += (b & REST2) << 14;
1757
+ if (b < MSB2) {
1758
+ return res;
1759
+ }
1760
+ b = buf[offset + 3];
1761
+ res += (b & REST2) << 21;
1762
+ if (b < MSB2) {
1763
+ return res;
1764
+ }
1765
+ b = buf[offset + 4];
1766
+ res += (b & REST2) * N42;
1767
+ if (b < MSB2) {
1768
+ return res;
1769
+ }
1770
+ b = buf[offset + 5];
1771
+ res += (b & REST2) * N52;
1772
+ if (b < MSB2) {
1773
+ return res;
1774
+ }
1775
+ b = buf[offset + 6];
1776
+ res += (b & REST2) * N62;
1777
+ if (b < MSB2) {
1778
+ return res;
1779
+ }
1780
+ b = buf[offset + 7];
1781
+ res += (b & REST2) * N72;
1782
+ if (b < MSB2) {
1783
+ return res;
1784
+ }
1785
+ throw new RangeError("Could not decode varint");
1786
+ }
1787
+ function decodeUint8ArrayList(buf, offset) {
1788
+ let b = buf.get(offset);
1789
+ let res = 0;
1790
+ res += b & REST2;
1791
+ if (b < MSB2) {
1792
+ return res;
1793
+ }
1794
+ b = buf.get(offset + 1);
1795
+ res += (b & REST2) << 7;
1796
+ if (b < MSB2) {
1797
+ return res;
1798
+ }
1799
+ b = buf.get(offset + 2);
1800
+ res += (b & REST2) << 14;
1801
+ if (b < MSB2) {
1802
+ return res;
1803
+ }
1804
+ b = buf.get(offset + 3);
1805
+ res += (b & REST2) << 21;
1806
+ if (b < MSB2) {
1807
+ return res;
1808
+ }
1809
+ b = buf.get(offset + 4);
1810
+ res += (b & REST2) * N42;
1811
+ if (b < MSB2) {
1812
+ return res;
1813
+ }
1814
+ b = buf.get(offset + 5);
1815
+ res += (b & REST2) * N52;
1816
+ if (b < MSB2) {
1817
+ return res;
1818
+ }
1819
+ b = buf.get(offset + 6);
1820
+ res += (b & REST2) * N62;
1821
+ if (b < MSB2) {
1822
+ return res;
1823
+ }
1824
+ b = buf.get(offset + 7);
1825
+ res += (b & REST2) * N72;
1826
+ if (b < MSB2) {
1827
+ return res;
1828
+ }
1829
+ throw new RangeError("Could not decode varint");
1830
+ }
1831
+ function decode8(buf, offset = 0) {
1832
+ if (buf instanceof Uint8Array) {
1833
+ return decodeUint8Array(buf, offset);
1834
+ } else {
1835
+ return decodeUint8ArrayList(buf, offset);
1836
+ }
1837
+ }
1838
+ var N12, N22, N32, N42, N52, N62, N72, MSB2, REST2;
1839
+ var init_src2 = __esm({
1840
+ "node_modules/uint8-varint/dist/src/index.js"() {
1841
+ "use strict";
1842
+ init_alloc_node();
1843
+ N12 = Math.pow(2, 7);
1844
+ N22 = Math.pow(2, 14);
1845
+ N32 = Math.pow(2, 21);
1846
+ N42 = Math.pow(2, 28);
1847
+ N52 = Math.pow(2, 35);
1848
+ N62 = Math.pow(2, 42);
1849
+ N72 = Math.pow(2, 49);
1850
+ MSB2 = 128;
1851
+ REST2 = 127;
1852
+ }
1853
+ });
1854
+
1855
+ // node_modules/uint8arrays/dist/src/concat.node.js
1856
+ function concat(arrays, length2) {
1857
+ return asUint8Array(import_node_buffer4.Buffer.concat(arrays, length2));
1858
+ }
1859
+ var import_node_buffer4;
1860
+ var init_concat_node = __esm({
1861
+ "node_modules/uint8arrays/dist/src/concat.node.js"() {
1862
+ "use strict";
1863
+ import_node_buffer4 = require("buffer");
1864
+ init_as_uint8array_node();
1865
+ }
1866
+ });
1867
+
1868
+ // node_modules/@chainsafe/is-ip/lib/is-ip.node.js
1869
+ var import_node_net;
1870
+ var init_is_ip_node = __esm({
1871
+ "node_modules/@chainsafe/is-ip/lib/is-ip.node.js"() {
1872
+ "use strict";
1873
+ import_node_net = require("net");
1874
+ }
1875
+ });
1876
+
1877
+ // node_modules/@multiformats/multiaddr/dist/src/constants.js
1878
+ var CODE_IP4, CODE_TCP, CODE_UDP, CODE_DCCP, CODE_IP6, CODE_IP6ZONE, CODE_IPCIDR, CODE_DNS, CODE_DNS4, CODE_DNS6, CODE_DNSADDR, CODE_SCTP, CODE_UDT, CODE_UTP, CODE_UNIX, CODE_P2P, CODE_ONION, CODE_ONION3, CODE_GARLIC64, CODE_GARLIC32, CODE_TLS, CODE_SNI, CODE_NOISE, CODE_QUIC, CODE_QUIC_V1, CODE_WEBTRANSPORT, CODE_CERTHASH, CODE_HTTP, CODE_HTTP_PATH, CODE_HTTPS, CODE_WS, CODE_WSS, CODE_P2P_WEBSOCKET_STAR, CODE_P2P_STARDUST, CODE_P2P_WEBRTC_STAR, CODE_P2P_WEBRTC_DIRECT, CODE_WEBRTC_DIRECT, CODE_WEBRTC, CODE_P2P_CIRCUIT, CODE_MEMORY;
1879
+ var init_constants = __esm({
1880
+ "node_modules/@multiformats/multiaddr/dist/src/constants.js"() {
1881
+ "use strict";
1882
+ CODE_IP4 = 4;
1883
+ CODE_TCP = 6;
1884
+ CODE_UDP = 273;
1885
+ CODE_DCCP = 33;
1886
+ CODE_IP6 = 41;
1887
+ CODE_IP6ZONE = 42;
1888
+ CODE_IPCIDR = 43;
1889
+ CODE_DNS = 53;
1890
+ CODE_DNS4 = 54;
1891
+ CODE_DNS6 = 55;
1892
+ CODE_DNSADDR = 56;
1893
+ CODE_SCTP = 132;
1894
+ CODE_UDT = 301;
1895
+ CODE_UTP = 302;
1896
+ CODE_UNIX = 400;
1897
+ CODE_P2P = 421;
1898
+ CODE_ONION = 444;
1899
+ CODE_ONION3 = 445;
1900
+ CODE_GARLIC64 = 446;
1901
+ CODE_GARLIC32 = 447;
1902
+ CODE_TLS = 448;
1903
+ CODE_SNI = 449;
1904
+ CODE_NOISE = 454;
1905
+ CODE_QUIC = 460;
1906
+ CODE_QUIC_V1 = 461;
1907
+ CODE_WEBTRANSPORT = 465;
1908
+ CODE_CERTHASH = 466;
1909
+ CODE_HTTP = 480;
1910
+ CODE_HTTP_PATH = 481;
1911
+ CODE_HTTPS = 443;
1912
+ CODE_WS = 477;
1913
+ CODE_WSS = 478;
1914
+ CODE_P2P_WEBSOCKET_STAR = 479;
1915
+ CODE_P2P_STARDUST = 277;
1916
+ CODE_P2P_WEBRTC_STAR = 275;
1917
+ CODE_P2P_WEBRTC_DIRECT = 276;
1918
+ CODE_WEBRTC_DIRECT = 280;
1919
+ CODE_WEBRTC = 281;
1920
+ CODE_P2P_CIRCUIT = 290;
1921
+ CODE_MEMORY = 777;
1922
+ }
1923
+ });
1924
+
1925
+ // node_modules/@multiformats/multiaddr/dist/src/utils.js
1926
+ function bytesToString(base3) {
1927
+ return (buf) => {
1928
+ return toString2(buf, base3);
1929
+ };
1930
+ }
1931
+ function stringToBytes(base3) {
1932
+ return (buf) => {
1933
+ return fromString2(buf, base3);
1934
+ };
1935
+ }
1936
+ function bytes2port(buf) {
1937
+ const view = new DataView(buf.buffer);
1938
+ return view.getUint16(buf.byteOffset).toString();
1939
+ }
1940
+ function port2bytes(port) {
1941
+ const buf = new ArrayBuffer(2);
1942
+ const view = new DataView(buf);
1943
+ view.setUint16(0, typeof port === "string" ? parseInt(port) : port);
1944
+ return new Uint8Array(buf);
1945
+ }
1946
+ function onion2bytes(str) {
1947
+ const addr = str.split(":");
1948
+ if (addr.length !== 2) {
1949
+ throw new Error(`failed to parse onion addr: ["'${addr.join('", "')}'"]' does not contain a port number`);
1950
+ }
1951
+ if (addr[0].length !== 16) {
1952
+ throw new Error(`failed to parse onion addr: ${addr[0]} not a Tor onion address.`);
1953
+ }
1954
+ const buf = fromString2(addr[0], "base32");
1955
+ const port = parseInt(addr[1], 10);
1956
+ if (port < 1 || port > 65536) {
1957
+ throw new Error("Port number is not in range(1, 65536)");
1958
+ }
1959
+ const portBuf = port2bytes(port);
1960
+ return concat([buf, portBuf], buf.length + portBuf.length);
1961
+ }
1962
+ function onion32bytes(str) {
1963
+ const addr = str.split(":");
1964
+ if (addr.length !== 2) {
1965
+ throw new Error(`failed to parse onion addr: ["'${addr.join('", "')}'"]' does not contain a port number`);
1966
+ }
1967
+ if (addr[0].length !== 56) {
1968
+ throw new Error(`failed to parse onion addr: ${addr[0]} not a Tor onion3 address.`);
1969
+ }
1970
+ const buf = base32.decode(`b${addr[0]}`);
1971
+ const port = parseInt(addr[1], 10);
1972
+ if (port < 1 || port > 65536) {
1973
+ throw new Error("Port number is not in range(1, 65536)");
1974
+ }
1975
+ const portBuf = port2bytes(port);
1976
+ return concat([buf, portBuf], buf.length + portBuf.length);
1977
+ }
1978
+ function bytes2onion(buf) {
1979
+ const addrBytes = buf.subarray(0, buf.length - 2);
1980
+ const portBytes = buf.subarray(buf.length - 2);
1981
+ const addr = toString2(addrBytes, "base32");
1982
+ const port = bytes2port(portBytes);
1983
+ return `${addr}:${port}`;
1984
+ }
1985
+ function ip6StringToValue(str) {
1986
+ try {
1987
+ const url = new URL(`http://[${str}]`);
1988
+ return url.hostname.substring(1, url.hostname.length - 1);
1989
+ } catch {
1990
+ throw new InvalidMultiaddrError(`Invalid IPv6 address "${str}"`);
1991
+ }
1992
+ }
1993
+ function mb2bytes(mbstr) {
1994
+ return anybaseDecoder.decode(mbstr);
1995
+ }
1996
+ function bytes2mb(base3) {
1997
+ return (buf) => {
1998
+ return base3.encoder.encode(buf);
1999
+ };
2000
+ }
2001
+ var ip4ToBytes, ip6ToBytes, ip4ToString, ip6ToString, decoders, anybaseDecoder;
2002
+ var init_utils = __esm({
2003
+ "node_modules/@multiformats/multiaddr/dist/src/utils.js"() {
2004
+ "use strict";
2005
+ init_is_ip_node();
2006
+ init_base32();
2007
+ init_basics();
2008
+ init_concat_node();
2009
+ init_from_string_node();
2010
+ init_to_string_node();
2011
+ init_errors();
2012
+ ip4ToBytes = function(ip) {
2013
+ ip = ip.toString().trim();
2014
+ const bytes = new Uint8Array(4);
2015
+ ip.split(/\./g).forEach((byte, index) => {
2016
+ const value = parseInt(byte, 10);
2017
+ if (isNaN(value) || value < 0 || value > 255) {
2018
+ throw new InvalidMultiaddrError("Invalid byte value in IP address");
2019
+ }
2020
+ bytes[index] = value;
2021
+ });
2022
+ return bytes;
2023
+ };
2024
+ ip6ToBytes = function(ip) {
2025
+ let offset = 0;
2026
+ ip = ip.toString().trim();
2027
+ const sections = ip.split(":", 8);
2028
+ let i;
2029
+ for (i = 0; i < sections.length; i++) {
2030
+ const isv4 = (0, import_node_net.isIPv4)(sections[i]);
2031
+ let v4Buffer;
2032
+ if (isv4) {
2033
+ v4Buffer = ip4ToBytes(sections[i]);
2034
+ sections[i] = toString2(v4Buffer.subarray(0, 2), "base16");
2035
+ }
2036
+ if (v4Buffer != null && ++i < 8) {
2037
+ sections.splice(i, 0, toString2(v4Buffer.subarray(2, 4), "base16"));
2038
+ }
2039
+ }
2040
+ if (sections[0] === "") {
2041
+ while (sections.length < 8) {
2042
+ sections.unshift("0");
2043
+ }
2044
+ } else if (sections[sections.length - 1] === "") {
2045
+ while (sections.length < 8) {
2046
+ sections.push("0");
2047
+ }
2048
+ } else if (sections.length < 8) {
2049
+ for (i = 0; i < sections.length && sections[i] !== ""; i++) {
2050
+ }
2051
+ const argv = [i, 1];
2052
+ for (i = 9 - sections.length; i > 0; i--) {
2053
+ argv.push("0");
2054
+ }
2055
+ sections.splice.apply(sections, argv);
2056
+ }
2057
+ const bytes = new Uint8Array(offset + 16);
2058
+ for (i = 0; i < sections.length; i++) {
2059
+ if (sections[i] === "") {
2060
+ sections[i] = "0";
2061
+ }
2062
+ const word = parseInt(sections[i], 16);
2063
+ if (isNaN(word) || word < 0 || word > 65535) {
2064
+ throw new InvalidMultiaddrError("Invalid byte value in IP address");
2065
+ }
2066
+ bytes[offset++] = word >> 8 & 255;
2067
+ bytes[offset++] = word & 255;
2068
+ }
2069
+ return bytes;
2070
+ };
2071
+ ip4ToString = function(buf) {
2072
+ if (buf.byteLength !== 4) {
2073
+ throw new InvalidMultiaddrError("IPv4 address was incorrect length");
2074
+ }
2075
+ const result = [];
2076
+ for (let i = 0; i < buf.byteLength; i++) {
2077
+ result.push(buf[i]);
2078
+ }
2079
+ return result.join(".");
2080
+ };
2081
+ ip6ToString = function(buf) {
2082
+ if (buf.byteLength !== 16) {
2083
+ throw new InvalidMultiaddrError("IPv6 address was incorrect length");
2084
+ }
2085
+ const result = [];
2086
+ for (let i = 0; i < buf.byteLength; i += 2) {
2087
+ const byte1 = buf[i];
2088
+ const byte2 = buf[i + 1];
2089
+ const tuple = `${byte1.toString(16).padStart(2, "0")}${byte2.toString(16).padStart(2, "0")}`;
2090
+ result.push(tuple);
2091
+ }
2092
+ const ip = result.join(":");
2093
+ try {
2094
+ const url = new URL(`http://[${ip}]`);
2095
+ return url.hostname.substring(1, url.hostname.length - 1);
2096
+ } catch {
2097
+ throw new InvalidMultiaddrError(`Invalid IPv6 address "${ip}"`);
2098
+ }
2099
+ };
2100
+ decoders = Object.values(bases).map((c) => c.decoder);
2101
+ anybaseDecoder = (function() {
2102
+ let acc = decoders[0].or(decoders[1]);
2103
+ decoders.slice(2).forEach((d) => acc = acc.or(d));
2104
+ return acc;
2105
+ })();
2106
+ }
2107
+ });
2108
+
2109
+ // node_modules/@multiformats/multiaddr/dist/src/validation.js
2110
+ function integer(value) {
2111
+ const int = parseInt(value);
2112
+ if (int.toString() !== value) {
2113
+ throw new ValidationError("Value must be an integer");
2114
+ }
2115
+ }
2116
+ function positive(value) {
2117
+ if (value < 0) {
2118
+ throw new ValidationError("Value must be a positive integer, or zero");
2119
+ }
2120
+ }
2121
+ function maxValue(max) {
2122
+ return (value) => {
2123
+ if (value > max) {
2124
+ throw new ValidationError(`Value must be smaller than or equal to ${max}`);
2125
+ }
2126
+ };
2127
+ }
2128
+ function validate(...funcs) {
2129
+ return (value) => {
2130
+ for (const fn of funcs) {
2131
+ fn(value);
2132
+ }
2133
+ };
2134
+ }
2135
+ var validatePort;
2136
+ var init_validation = __esm({
2137
+ "node_modules/@multiformats/multiaddr/dist/src/validation.js"() {
2138
+ "use strict";
2139
+ init_errors();
2140
+ validatePort = validate(integer, positive, maxValue(65535));
2141
+ }
2142
+ });
2143
+
2144
+ // node_modules/@multiformats/multiaddr/dist/src/registry.js
2145
+ var V, Registry, registry, codecs;
2146
+ var init_registry = __esm({
2147
+ "node_modules/@multiformats/multiaddr/dist/src/registry.js"() {
2148
+ "use strict";
2149
+ init_is_ip_node();
2150
+ init_src();
2151
+ init_base64();
2152
+ init_constants();
2153
+ init_errors();
2154
+ init_utils();
2155
+ init_validation();
2156
+ V = -1;
2157
+ Registry = class {
2158
+ protocolsByCode = /* @__PURE__ */ new Map();
2159
+ protocolsByName = /* @__PURE__ */ new Map();
2160
+ getProtocol(key) {
2161
+ let codec;
2162
+ if (typeof key === "string") {
2163
+ codec = this.protocolsByName.get(key);
2164
+ } else {
2165
+ codec = this.protocolsByCode.get(key);
2166
+ }
2167
+ if (codec == null) {
2168
+ throw new UnknownProtocolError(`Protocol ${key} was unknown`);
2169
+ }
2170
+ return codec;
2171
+ }
2172
+ addProtocol(codec) {
2173
+ this.protocolsByCode.set(codec.code, codec);
2174
+ this.protocolsByName.set(codec.name, codec);
2175
+ codec.aliases?.forEach((alias) => {
2176
+ this.protocolsByName.set(alias, codec);
2177
+ });
2178
+ }
2179
+ removeProtocol(code2) {
2180
+ const codec = this.protocolsByCode.get(code2);
2181
+ if (codec == null) {
2182
+ return;
2183
+ }
2184
+ this.protocolsByCode.delete(codec.code);
2185
+ this.protocolsByName.delete(codec.name);
2186
+ codec.aliases?.forEach((alias) => {
2187
+ this.protocolsByName.delete(alias);
2188
+ });
2189
+ }
2190
+ };
2191
+ registry = new Registry();
2192
+ codecs = [{
2193
+ code: CODE_IP4,
2194
+ name: "ip4",
2195
+ size: 32,
2196
+ valueToBytes: ip4ToBytes,
2197
+ bytesToValue: ip4ToString,
2198
+ validate: (value) => {
2199
+ if (!(0, import_node_net.isIPv4)(value)) {
2200
+ throw new ValidationError(`Invalid IPv4 address "${value}"`);
2201
+ }
2202
+ }
2203
+ }, {
2204
+ code: CODE_TCP,
2205
+ name: "tcp",
2206
+ size: 16,
2207
+ valueToBytes: port2bytes,
2208
+ bytesToValue: bytes2port,
2209
+ validate: validatePort
2210
+ }, {
2211
+ code: CODE_UDP,
2212
+ name: "udp",
2213
+ size: 16,
2214
+ valueToBytes: port2bytes,
2215
+ bytesToValue: bytes2port,
2216
+ validate: validatePort
2217
+ }, {
2218
+ code: CODE_DCCP,
2219
+ name: "dccp",
2220
+ size: 16,
2221
+ valueToBytes: port2bytes,
2222
+ bytesToValue: bytes2port,
2223
+ validate: validatePort
2224
+ }, {
2225
+ code: CODE_IP6,
2226
+ name: "ip6",
2227
+ size: 128,
2228
+ valueToBytes: ip6ToBytes,
2229
+ bytesToValue: ip6ToString,
2230
+ stringToValue: ip6StringToValue,
2231
+ validate: (value) => {
2232
+ if (!(0, import_node_net.isIPv6)(value)) {
2233
+ throw new ValidationError(`Invalid IPv6 address "${value}"`);
2234
+ }
2235
+ }
2236
+ }, {
2237
+ code: CODE_IP6ZONE,
2238
+ name: "ip6zone",
2239
+ size: V
2240
+ }, {
2241
+ code: CODE_IPCIDR,
2242
+ name: "ipcidr",
2243
+ size: 8,
2244
+ bytesToValue: bytesToString("base10"),
2245
+ valueToBytes: stringToBytes("base10")
2246
+ }, {
2247
+ code: CODE_DNS,
2248
+ name: "dns",
2249
+ size: V,
2250
+ resolvable: true
2251
+ }, {
2252
+ code: CODE_DNS4,
2253
+ name: "dns4",
2254
+ size: V,
2255
+ resolvable: true
2256
+ }, {
2257
+ code: CODE_DNS6,
2258
+ name: "dns6",
2259
+ size: V,
2260
+ resolvable: true
2261
+ }, {
2262
+ code: CODE_DNSADDR,
2263
+ name: "dnsaddr",
2264
+ size: V,
2265
+ resolvable: true
2266
+ }, {
2267
+ code: CODE_SCTP,
2268
+ name: "sctp",
2269
+ size: 16,
2270
+ valueToBytes: port2bytes,
2271
+ bytesToValue: bytes2port,
2272
+ validate: validatePort
2273
+ }, {
2274
+ code: CODE_UDT,
2275
+ name: "udt"
2276
+ }, {
2277
+ code: CODE_UTP,
2278
+ name: "utp"
2279
+ }, {
2280
+ code: CODE_UNIX,
2281
+ name: "unix",
2282
+ size: V,
2283
+ path: true,
2284
+ stringToValue: (str) => decodeURIComponent(str),
2285
+ valueToString: (val) => encodeURIComponent(val)
2286
+ }, {
2287
+ code: CODE_P2P,
2288
+ name: "p2p",
2289
+ aliases: ["ipfs"],
2290
+ size: V,
2291
+ bytesToValue: bytesToString("base58btc"),
2292
+ valueToBytes: (val) => {
2293
+ if (val.startsWith("Q") || val.startsWith("1")) {
2294
+ return stringToBytes("base58btc")(val);
2295
+ }
2296
+ return CID.parse(val).multihash.bytes;
2297
+ }
2298
+ }, {
2299
+ code: CODE_ONION,
2300
+ name: "onion",
2301
+ size: 96,
2302
+ bytesToValue: bytes2onion,
2303
+ valueToBytes: onion2bytes
2304
+ }, {
2305
+ code: CODE_ONION3,
2306
+ name: "onion3",
2307
+ size: 296,
2308
+ bytesToValue: bytes2onion,
2309
+ valueToBytes: onion32bytes
2310
+ }, {
2311
+ code: CODE_GARLIC64,
2312
+ name: "garlic64",
2313
+ size: V
2314
+ }, {
2315
+ code: CODE_GARLIC32,
2316
+ name: "garlic32",
2317
+ size: V
2318
+ }, {
2319
+ code: CODE_TLS,
2320
+ name: "tls"
2321
+ }, {
2322
+ code: CODE_SNI,
2323
+ name: "sni",
2324
+ size: V
2325
+ }, {
2326
+ code: CODE_NOISE,
2327
+ name: "noise"
2328
+ }, {
2329
+ code: CODE_QUIC,
2330
+ name: "quic"
2331
+ }, {
2332
+ code: CODE_QUIC_V1,
2333
+ name: "quic-v1"
2334
+ }, {
2335
+ code: CODE_WEBTRANSPORT,
2336
+ name: "webtransport"
2337
+ }, {
2338
+ code: CODE_CERTHASH,
2339
+ name: "certhash",
2340
+ size: V,
2341
+ bytesToValue: bytes2mb(base64url),
2342
+ valueToBytes: mb2bytes
2343
+ }, {
2344
+ code: CODE_HTTP,
2345
+ name: "http"
2346
+ }, {
2347
+ code: CODE_HTTP_PATH,
2348
+ name: "http-path",
2349
+ size: V,
2350
+ stringToValue: (str) => `/${decodeURIComponent(str)}`,
2351
+ valueToString: (val) => encodeURIComponent(val.substring(1))
2352
+ }, {
2353
+ code: CODE_HTTPS,
2354
+ name: "https"
2355
+ }, {
2356
+ code: CODE_WS,
2357
+ name: "ws"
2358
+ }, {
2359
+ code: CODE_WSS,
2360
+ name: "wss"
2361
+ }, {
2362
+ code: CODE_P2P_WEBSOCKET_STAR,
2363
+ name: "p2p-websocket-star"
2364
+ }, {
2365
+ code: CODE_P2P_STARDUST,
2366
+ name: "p2p-stardust"
2367
+ }, {
2368
+ code: CODE_P2P_WEBRTC_STAR,
2369
+ name: "p2p-webrtc-star"
2370
+ }, {
2371
+ code: CODE_P2P_WEBRTC_DIRECT,
2372
+ name: "p2p-webrtc-direct"
2373
+ }, {
2374
+ code: CODE_WEBRTC_DIRECT,
2375
+ name: "webrtc-direct"
2376
+ }, {
2377
+ code: CODE_WEBRTC,
2378
+ name: "webrtc"
2379
+ }, {
2380
+ code: CODE_P2P_CIRCUIT,
2381
+ name: "p2p-circuit"
2382
+ }, {
2383
+ code: CODE_MEMORY,
2384
+ name: "memory",
2385
+ size: V
2386
+ }];
2387
+ codecs.forEach((codec) => {
2388
+ registry.addProtocol(codec);
2389
+ });
2390
+ }
2391
+ });
2392
+
2393
+ // node_modules/@multiformats/multiaddr/dist/src/components.js
2394
+ function bytesToComponents(bytes) {
2395
+ const components = [];
2396
+ let i = 0;
2397
+ while (i < bytes.length) {
2398
+ const code2 = decode8(bytes, i);
2399
+ const codec = registry.getProtocol(code2);
2400
+ const codeLength = encodingLength2(code2);
2401
+ const size = sizeForAddr(codec, bytes, i + codeLength);
2402
+ let sizeLength = 0;
2403
+ if (size > 0 && codec.size === V) {
2404
+ sizeLength = encodingLength2(size);
2405
+ }
2406
+ const componentLength = codeLength + sizeLength + size;
2407
+ const component = {
2408
+ code: code2,
2409
+ name: codec.name,
2410
+ bytes: bytes.subarray(i, i + componentLength)
2411
+ };
2412
+ if (size > 0) {
2413
+ const valueOffset = i + codeLength + sizeLength;
2414
+ const valueBytes = bytes.subarray(valueOffset, valueOffset + size);
2415
+ component.value = codec.bytesToValue?.(valueBytes) ?? toString2(valueBytes);
2416
+ }
2417
+ components.push(component);
2418
+ i += componentLength;
2419
+ }
2420
+ return components;
2421
+ }
2422
+ function componentsToBytes(components) {
2423
+ let length2 = 0;
2424
+ const bytes = [];
2425
+ for (const component of components) {
2426
+ if (component.bytes == null) {
2427
+ const codec = registry.getProtocol(component.code);
2428
+ const codecLength = encodingLength2(component.code);
2429
+ let valueBytes;
2430
+ let valueLength = 0;
2431
+ let valueLengthLength = 0;
2432
+ if (component.value != null) {
2433
+ valueBytes = codec.valueToBytes?.(component.value) ?? fromString2(component.value);
2434
+ valueLength = valueBytes.byteLength;
2435
+ if (codec.size === V) {
2436
+ valueLengthLength = encodingLength2(valueLength);
2437
+ }
2438
+ }
2439
+ const bytes2 = new Uint8Array(codecLength + valueLengthLength + valueLength);
2440
+ let offset = 0;
2441
+ encodeUint8Array(component.code, bytes2, offset);
2442
+ offset += codecLength;
2443
+ if (valueBytes != null) {
2444
+ if (codec.size === V) {
2445
+ encodeUint8Array(valueLength, bytes2, offset);
2446
+ offset += valueLengthLength;
2447
+ }
2448
+ bytes2.set(valueBytes, offset);
2449
+ }
2450
+ component.bytes = bytes2;
2451
+ }
2452
+ bytes.push(component.bytes);
2453
+ length2 += component.bytes.byteLength;
2454
+ }
2455
+ return concat(bytes, length2);
2456
+ }
2457
+ function stringToComponents(string2) {
2458
+ if (string2.charAt(0) !== "/") {
2459
+ throw new InvalidMultiaddrError('String multiaddr must start with "/"');
2460
+ }
2461
+ const components = [];
2462
+ let collecting = "protocol";
2463
+ let value = "";
2464
+ let protocol = "";
2465
+ for (let i = 1; i < string2.length; i++) {
2466
+ const char = string2.charAt(i);
2467
+ if (char !== "/") {
2468
+ if (collecting === "protocol") {
2469
+ protocol += string2.charAt(i);
2470
+ } else {
2471
+ value += string2.charAt(i);
2472
+ }
2473
+ }
2474
+ const ended = i === string2.length - 1;
2475
+ if (char === "/" || ended) {
2476
+ const codec = registry.getProtocol(protocol);
2477
+ if (collecting === "protocol") {
2478
+ if (codec.size == null || codec.size === 0) {
2479
+ components.push({
2480
+ code: codec.code,
2481
+ name: codec.name
2482
+ });
2483
+ value = "";
2484
+ protocol = "";
2485
+ collecting = "protocol";
2486
+ continue;
2487
+ } else if (ended) {
2488
+ throw new InvalidMultiaddrError(`Component ${protocol} was missing value`);
2489
+ }
2490
+ collecting = "value";
2491
+ } else if (collecting === "value") {
2492
+ const component = {
2493
+ code: codec.code,
2494
+ name: codec.name
2495
+ };
2496
+ if (codec.size != null && codec.size !== 0) {
2497
+ if (value === "") {
2498
+ throw new InvalidMultiaddrError(`Component ${protocol} was missing value`);
2499
+ }
2500
+ component.value = codec.stringToValue?.(value) ?? value;
2501
+ }
2502
+ components.push(component);
2503
+ value = "";
2504
+ protocol = "";
2505
+ collecting = "protocol";
2506
+ }
2507
+ }
2508
+ }
2509
+ if (protocol !== "" && value !== "") {
2510
+ throw new InvalidMultiaddrError("Incomplete multiaddr");
2511
+ }
2512
+ return components;
2513
+ }
2514
+ function componentsToString(components) {
2515
+ return `/${components.flatMap((component) => {
2516
+ if (component.value == null) {
2517
+ return component.name;
2518
+ }
2519
+ const codec = registry.getProtocol(component.code);
2520
+ if (codec == null) {
2521
+ throw new InvalidMultiaddrError(`Unknown protocol code ${component.code}`);
2522
+ }
2523
+ return [
2524
+ component.name,
2525
+ codec.valueToString?.(component.value) ?? component.value
2526
+ ];
2527
+ }).join("/")}`;
2528
+ }
2529
+ function sizeForAddr(codec, bytes, offset) {
2530
+ if (codec.size == null || codec.size === 0) {
2531
+ return 0;
2532
+ }
2533
+ if (codec.size > 0) {
2534
+ return codec.size / 8;
2535
+ }
2536
+ return decode8(bytes, offset);
2537
+ }
2538
+ var init_components = __esm({
2539
+ "node_modules/@multiformats/multiaddr/dist/src/components.js"() {
2540
+ "use strict";
2541
+ init_src2();
2542
+ init_concat_node();
2543
+ init_from_string_node();
2544
+ init_to_string_node();
2545
+ init_errors();
2546
+ init_registry();
2547
+ }
2548
+ });
2549
+
2550
+ // node_modules/@multiformats/multiaddr/dist/src/multiaddr.js
2551
+ function toComponents(addr) {
2552
+ if (addr == null) {
2553
+ addr = "/";
2554
+ }
2555
+ if (isMultiaddr(addr)) {
2556
+ return addr.getComponents();
2557
+ }
2558
+ if (addr instanceof Uint8Array) {
2559
+ return bytesToComponents(addr);
2560
+ }
2561
+ if (typeof addr === "string") {
2562
+ addr = addr.replace(/\/(\/)+/, "/").replace(/(\/)+$/, "");
2563
+ if (addr === "") {
2564
+ addr = "/";
2565
+ }
2566
+ return stringToComponents(addr);
2567
+ }
2568
+ if (Array.isArray(addr)) {
2569
+ return addr;
2570
+ }
2571
+ throw new InvalidMultiaddrError("Must be a string, Uint8Array, Component[], or another Multiaddr");
2572
+ }
2573
+ function validate2(addr) {
2574
+ addr.getComponents().forEach((component) => {
2575
+ const codec = registry.getProtocol(component.code);
2576
+ if (component.value == null) {
2577
+ return;
2578
+ }
2579
+ codec.validate?.(component.value);
2580
+ });
2581
+ }
2582
+ var inspect, symbol, DNS_CODES, NoAvailableResolverError, Multiaddr;
2583
+ var init_multiaddr = __esm({
2584
+ "node_modules/@multiformats/multiaddr/dist/src/multiaddr.js"() {
2585
+ "use strict";
2586
+ init_base58();
2587
+ init_cid();
2588
+ init_equals();
2589
+ init_from_string_node();
2590
+ init_to_string_node();
2591
+ init_components();
2592
+ init_constants();
2593
+ init_errors();
2594
+ init_registry();
2595
+ init_src4();
2596
+ inspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
2597
+ symbol = /* @__PURE__ */ Symbol.for("@multiformats/multiaddr");
2598
+ DNS_CODES = [
2599
+ CODE_DNS,
2600
+ CODE_DNS4,
2601
+ CODE_DNS6,
2602
+ CODE_DNSADDR
2603
+ ];
2604
+ NoAvailableResolverError = class extends Error {
2605
+ constructor(message = "No available resolver") {
2606
+ super(message);
2607
+ this.name = "NoAvailableResolverError";
2608
+ }
2609
+ };
2610
+ Multiaddr = class _Multiaddr {
2611
+ [symbol] = true;
2612
+ #components;
2613
+ // cache string representation
2614
+ #string;
2615
+ // cache byte representation
2616
+ #bytes;
2617
+ constructor(addr = "/", options = {}) {
2618
+ this.#components = toComponents(addr);
2619
+ if (options.validate !== false) {
2620
+ validate2(this);
2621
+ }
2622
+ }
2623
+ get bytes() {
2624
+ if (this.#bytes == null) {
2625
+ this.#bytes = componentsToBytes(this.#components);
2626
+ }
2627
+ return this.#bytes;
2628
+ }
2629
+ toString() {
2630
+ if (this.#string == null) {
2631
+ this.#string = componentsToString(this.#components);
2632
+ }
2633
+ return this.#string;
2634
+ }
2635
+ toJSON() {
2636
+ return this.toString();
2637
+ }
2638
+ toOptions() {
2639
+ let family;
2640
+ let transport;
2641
+ let host;
2642
+ let port;
2643
+ let zone = "";
2644
+ for (const { code: code2, name: name2, value } of this.#components) {
2645
+ if (code2 === CODE_IP6ZONE) {
2646
+ zone = `%${value ?? ""}`;
2647
+ }
2648
+ if (DNS_CODES.includes(code2)) {
2649
+ transport = "tcp";
2650
+ port = 443;
2651
+ host = `${value ?? ""}${zone}`;
2652
+ family = code2 === CODE_DNS6 ? 6 : 4;
2653
+ }
2654
+ if (code2 === CODE_TCP || code2 === CODE_UDP) {
2655
+ transport = name2 === "tcp" ? "tcp" : "udp";
2656
+ port = parseInt(value ?? "");
2657
+ }
2658
+ if (code2 === CODE_IP4 || code2 === CODE_IP6) {
2659
+ transport = "tcp";
2660
+ host = `${value ?? ""}${zone}`;
2661
+ family = code2 === CODE_IP6 ? 6 : 4;
2662
+ }
2663
+ }
2664
+ if (family == null || transport == null || host == null || port == null) {
2665
+ throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');
2666
+ }
2667
+ const opts = {
2668
+ family,
2669
+ host,
2670
+ transport,
2671
+ port
2672
+ };
2673
+ return opts;
2674
+ }
2675
+ getComponents() {
2676
+ return [
2677
+ ...this.#components
2678
+ ];
2679
+ }
2680
+ protos() {
2681
+ return this.#components.map(({ code: code2, value }) => {
2682
+ const codec = registry.getProtocol(code2);
2683
+ return {
2684
+ code: code2,
2685
+ size: codec.size ?? 0,
2686
+ name: codec.name,
2687
+ resolvable: Boolean(codec.resolvable),
2688
+ path: Boolean(codec.path)
2689
+ };
2690
+ });
2691
+ }
2692
+ protoCodes() {
2693
+ return this.#components.map(({ code: code2 }) => code2);
2694
+ }
2695
+ protoNames() {
2696
+ return this.#components.map(({ name: name2 }) => name2);
2697
+ }
2698
+ tuples() {
2699
+ return this.#components.map(({ code: code2, value }) => {
2700
+ if (value == null) {
2701
+ return [code2];
2702
+ }
2703
+ const codec = registry.getProtocol(code2);
2704
+ const output = [code2];
2705
+ if (value != null) {
2706
+ output.push(codec.valueToBytes?.(value) ?? fromString2(value));
2707
+ }
2708
+ return output;
2709
+ });
2710
+ }
2711
+ stringTuples() {
2712
+ return this.#components.map(({ code: code2, value }) => {
2713
+ if (value == null) {
2714
+ return [code2];
2715
+ }
2716
+ return [code2, value];
2717
+ });
2718
+ }
2719
+ encapsulate(addr) {
2720
+ const ma = new _Multiaddr(addr);
2721
+ return new _Multiaddr([
2722
+ ...this.#components,
2723
+ ...ma.getComponents()
2724
+ ], {
2725
+ validate: false
2726
+ });
2727
+ }
2728
+ decapsulate(addr) {
2729
+ const addrString = addr.toString();
2730
+ const s = this.toString();
2731
+ const i = s.lastIndexOf(addrString);
2732
+ if (i < 0) {
2733
+ throw new InvalidParametersError(`Address ${this.toString()} does not contain subaddress: ${addr.toString()}`);
2734
+ }
2735
+ return new _Multiaddr(s.slice(0, i), {
2736
+ validate: false
2737
+ });
2738
+ }
2739
+ decapsulateCode(code2) {
2740
+ let index;
2741
+ for (let i = this.#components.length - 1; i > -1; i--) {
2742
+ if (this.#components[i].code === code2) {
2743
+ index = i;
2744
+ break;
2745
+ }
2746
+ }
2747
+ return new _Multiaddr(this.#components.slice(0, index), {
2748
+ validate: false
2749
+ });
2750
+ }
2751
+ getPeerId() {
2752
+ try {
2753
+ let tuples = [];
2754
+ this.#components.forEach(({ code: code2, value }) => {
2755
+ if (code2 === CODE_P2P) {
2756
+ tuples.push([code2, value]);
2757
+ }
2758
+ if (code2 === CODE_P2P_CIRCUIT) {
2759
+ tuples = [];
2760
+ }
2761
+ });
2762
+ const tuple = tuples.pop();
2763
+ if (tuple?.[1] != null) {
2764
+ const peerIdStr = tuple[1];
2765
+ if (peerIdStr[0] === "Q" || peerIdStr[0] === "1") {
2766
+ return toString2(base58btc.decode(`z${peerIdStr}`), "base58btc");
2767
+ }
2768
+ return toString2(CID.parse(peerIdStr).multihash.bytes, "base58btc");
2769
+ }
2770
+ return null;
2771
+ } catch (e) {
2772
+ return null;
2773
+ }
2774
+ }
2775
+ getPath() {
2776
+ for (const component of this.#components) {
2777
+ const codec = registry.getProtocol(component.code);
2778
+ if (!codec.path) {
2779
+ continue;
2780
+ }
2781
+ return component.value ?? null;
2782
+ }
2783
+ return null;
2784
+ }
2785
+ equals(addr) {
2786
+ return equals3(this.bytes, addr.bytes);
2787
+ }
2788
+ async resolve(options) {
2789
+ const resolvableProto = this.protos().find((p) => p.resolvable);
2790
+ if (resolvableProto == null) {
2791
+ return [this];
2792
+ }
2793
+ const resolver = resolvers.get(resolvableProto.name);
2794
+ if (resolver == null) {
2795
+ throw new NoAvailableResolverError(`no available resolver for ${resolvableProto.name}`);
2796
+ }
2797
+ const result = await resolver(this, options);
2798
+ return result.map((str) => multiaddr(str));
2799
+ }
2800
+ nodeAddress() {
2801
+ const options = this.toOptions();
2802
+ if (options.transport !== "tcp" && options.transport !== "udp") {
2803
+ throw new Error(`multiaddr must have a valid format - no protocol with name: "${options.transport}". Must have a valid transport protocol: "{tcp, udp}"`);
2804
+ }
2805
+ return {
2806
+ family: options.family,
2807
+ address: options.host,
2808
+ port: options.port
2809
+ };
2810
+ }
2811
+ isThinWaistAddress() {
2812
+ if (this.#components.length !== 2) {
2813
+ return false;
2814
+ }
2815
+ if (this.#components[0].code !== CODE_IP4 && this.#components[0].code !== CODE_IP6) {
2816
+ return false;
2817
+ }
2818
+ if (this.#components[1].code !== CODE_TCP && this.#components[1].code !== CODE_UDP) {
2819
+ return false;
2820
+ }
2821
+ return true;
2822
+ }
2823
+ /**
2824
+ * Returns Multiaddr as a human-readable string
2825
+ * https://nodejs.org/api/util.html#utilinspectcustom
2826
+ *
2827
+ * @example
2828
+ * ```js
2829
+ * import { multiaddr } from '@multiformats/multiaddr'
2830
+ *
2831
+ * console.info(multiaddr('/ip4/127.0.0.1/tcp/4001'))
2832
+ * // 'Multiaddr(/ip4/127.0.0.1/tcp/4001)'
2833
+ * ```
2834
+ */
2835
+ [inspect]() {
2836
+ return `Multiaddr(${this.toString()})`;
2837
+ }
2838
+ };
2839
+ }
2840
+ });
2841
+
2842
+ // node_modules/@chainsafe/is-ip/lib/parser.js
2843
+ var Parser;
2844
+ var init_parser = __esm({
2845
+ "node_modules/@chainsafe/is-ip/lib/parser.js"() {
2846
+ "use strict";
2847
+ Parser = class {
2848
+ index = 0;
2849
+ input = "";
2850
+ new(input) {
2851
+ this.index = 0;
2852
+ this.input = input;
2853
+ return this;
2854
+ }
2855
+ /** Run a parser, and restore the pre-parse state if it fails. */
2856
+ readAtomically(fn) {
2857
+ const index = this.index;
2858
+ const result = fn();
2859
+ if (result === void 0) {
2860
+ this.index = index;
2861
+ }
2862
+ return result;
2863
+ }
2864
+ /** Run a parser, but fail if the entire input wasn't consumed. Doesn't run atomically. */
2865
+ parseWith(fn) {
2866
+ const result = fn();
2867
+ if (this.index !== this.input.length) {
2868
+ return void 0;
2869
+ }
2870
+ return result;
2871
+ }
2872
+ /** Peek the next character from the input */
2873
+ peekChar() {
2874
+ if (this.index >= this.input.length) {
2875
+ return void 0;
2876
+ }
2877
+ return this.input[this.index];
2878
+ }
2879
+ /** Read the next character from the input */
2880
+ readChar() {
2881
+ if (this.index >= this.input.length) {
2882
+ return void 0;
2883
+ }
2884
+ return this.input[this.index++];
2885
+ }
2886
+ /** Read the next character from the input if it matches the target. */
2887
+ readGivenChar(target) {
2888
+ return this.readAtomically(() => {
2889
+ const char = this.readChar();
2890
+ if (char !== target) {
2891
+ return void 0;
2892
+ }
2893
+ return char;
2894
+ });
2895
+ }
2896
+ /**
2897
+ * Helper for reading separators in an indexed loop. Reads the separator
2898
+ * character iff index > 0, then runs the parser. When used in a loop,
2899
+ * the separator character will only be read on index > 0 (see
2900
+ * readIPv4Addr for an example)
2901
+ */
2902
+ readSeparator(sep, index, inner) {
2903
+ return this.readAtomically(() => {
2904
+ if (index > 0) {
2905
+ if (this.readGivenChar(sep) === void 0) {
2906
+ return void 0;
2907
+ }
2908
+ }
2909
+ return inner();
2910
+ });
2911
+ }
2912
+ /**
2913
+ * Read a number off the front of the input in the given radix, stopping
2914
+ * at the first non-digit character or eof. Fails if the number has more
2915
+ * digits than max_digits or if there is no number.
2916
+ */
2917
+ readNumber(radix, maxDigits, allowZeroPrefix, maxBytes) {
2918
+ return this.readAtomically(() => {
2919
+ let result = 0;
2920
+ let digitCount = 0;
2921
+ const leadingChar = this.peekChar();
2922
+ if (leadingChar === void 0) {
2923
+ return void 0;
2924
+ }
2925
+ const hasLeadingZero = leadingChar === "0";
2926
+ const maxValue2 = 2 ** (8 * maxBytes) - 1;
2927
+ while (true) {
2928
+ const digit = this.readAtomically(() => {
2929
+ const char = this.readChar();
2930
+ if (char === void 0) {
2931
+ return void 0;
2932
+ }
2933
+ const num = Number.parseInt(char, radix);
2934
+ if (Number.isNaN(num)) {
2935
+ return void 0;
2936
+ }
2937
+ return num;
2938
+ });
2939
+ if (digit === void 0) {
2940
+ break;
2941
+ }
2942
+ result *= radix;
2943
+ result += digit;
2944
+ if (result > maxValue2) {
2945
+ return void 0;
2946
+ }
2947
+ digitCount += 1;
2948
+ if (maxDigits !== void 0) {
2949
+ if (digitCount > maxDigits) {
2950
+ return void 0;
2951
+ }
2952
+ }
2953
+ }
2954
+ if (digitCount === 0) {
2955
+ return void 0;
2956
+ } else if (!allowZeroPrefix && hasLeadingZero && digitCount > 1) {
2957
+ return void 0;
2958
+ } else {
2959
+ return result;
2960
+ }
2961
+ });
2962
+ }
2963
+ /** Read an IPv4 address. */
2964
+ readIPv4Addr() {
2965
+ return this.readAtomically(() => {
2966
+ const out = new Uint8Array(4);
2967
+ for (let i = 0; i < out.length; i++) {
2968
+ const ix = this.readSeparator(".", i, () => this.readNumber(10, 3, false, 1));
2969
+ if (ix === void 0) {
2970
+ return void 0;
2971
+ }
2972
+ out[i] = ix;
2973
+ }
2974
+ return out;
2975
+ });
2976
+ }
2977
+ /** Read an IPv6 Address. */
2978
+ readIPv6Addr() {
2979
+ const readGroups = (groups) => {
2980
+ for (let i = 0; i < groups.length / 2; i++) {
2981
+ const ix = i * 2;
2982
+ if (i < groups.length - 3) {
2983
+ const ipv4 = this.readSeparator(":", i, () => this.readIPv4Addr());
2984
+ if (ipv4 !== void 0) {
2985
+ groups[ix] = ipv4[0];
2986
+ groups[ix + 1] = ipv4[1];
2987
+ groups[ix + 2] = ipv4[2];
2988
+ groups[ix + 3] = ipv4[3];
2989
+ return [ix + 4, true];
2990
+ }
2991
+ }
2992
+ const group = this.readSeparator(":", i, () => this.readNumber(16, 4, true, 2));
2993
+ if (group === void 0) {
2994
+ return [ix, false];
2995
+ }
2996
+ groups[ix] = group >> 8;
2997
+ groups[ix + 1] = group & 255;
2998
+ }
2999
+ return [groups.length, false];
3000
+ };
3001
+ return this.readAtomically(() => {
3002
+ const head = new Uint8Array(16);
3003
+ const [headSize, headIp4] = readGroups(head);
3004
+ if (headSize === 16) {
3005
+ return head;
3006
+ }
3007
+ if (headIp4) {
3008
+ return void 0;
3009
+ }
3010
+ if (this.readGivenChar(":") === void 0) {
3011
+ return void 0;
3012
+ }
3013
+ if (this.readGivenChar(":") === void 0) {
3014
+ return void 0;
3015
+ }
3016
+ const tail = new Uint8Array(14);
3017
+ const limit = 16 - (headSize + 2);
3018
+ const [tailSize] = readGroups(tail.subarray(0, limit));
3019
+ head.set(tail.subarray(0, tailSize), 16 - tailSize);
3020
+ return head;
3021
+ });
3022
+ }
3023
+ /** Read an IP Address, either IPv4 or IPv6. */
3024
+ readIPAddr() {
3025
+ return this.readIPv4Addr() ?? this.readIPv6Addr();
3026
+ }
3027
+ };
3028
+ }
3029
+ });
3030
+
3031
+ // node_modules/@chainsafe/is-ip/lib/parse.js
3032
+ function parseIPv4(input) {
3033
+ if (input.length > MAX_IPV4_LENGTH) {
3034
+ return void 0;
3035
+ }
3036
+ return parser.new(input).parseWith(() => parser.readIPv4Addr());
3037
+ }
3038
+ function parseIPv6(input) {
3039
+ if (input.includes("%")) {
3040
+ input = input.split("%")[0];
3041
+ }
3042
+ if (input.length > MAX_IPV6_LENGTH) {
3043
+ return void 0;
3044
+ }
3045
+ return parser.new(input).parseWith(() => parser.readIPv6Addr());
3046
+ }
3047
+ function parseIP(input, mapIPv4ToIPv6 = false) {
3048
+ if (input.includes("%")) {
3049
+ input = input.split("%")[0];
3050
+ }
3051
+ if (input.length > MAX_IPV6_LENGTH) {
3052
+ return void 0;
3053
+ }
3054
+ const addr = parser.new(input).parseWith(() => parser.readIPAddr());
3055
+ if (!addr) {
3056
+ return void 0;
3057
+ }
3058
+ if (mapIPv4ToIPv6 && addr.length === 4) {
3059
+ return Uint8Array.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, addr[0], addr[1], addr[2], addr[3]]);
3060
+ }
3061
+ return addr;
3062
+ }
3063
+ var MAX_IPV6_LENGTH, MAX_IPV4_LENGTH, parser;
3064
+ var init_parse = __esm({
3065
+ "node_modules/@chainsafe/is-ip/lib/parse.js"() {
3066
+ "use strict";
3067
+ init_parser();
3068
+ MAX_IPV6_LENGTH = 45;
3069
+ MAX_IPV4_LENGTH = 15;
3070
+ parser = new Parser();
3071
+ }
3072
+ });
3073
+
3074
+ // node_modules/@chainsafe/netmask/dist/src/util.js
3075
+ function allFF(a, from3, to) {
3076
+ let i = 0;
3077
+ for (const e of a) {
3078
+ if (i < from3)
3079
+ continue;
3080
+ if (i > to)
3081
+ break;
3082
+ if (e !== 255)
3083
+ return false;
3084
+ i++;
3085
+ }
3086
+ return true;
3087
+ }
3088
+ function deepEqual(a, b, from3, to) {
3089
+ let i = 0;
3090
+ for (const e of a) {
3091
+ if (i < from3)
3092
+ continue;
3093
+ if (i > to)
3094
+ break;
3095
+ if (e !== b[i])
3096
+ return false;
3097
+ i++;
3098
+ }
3099
+ return true;
3100
+ }
3101
+ function ipToString(ip) {
3102
+ switch (ip.length) {
3103
+ case IPv4Len: {
3104
+ return ip.join(".");
3105
+ }
3106
+ case IPv6Len: {
3107
+ const result = [];
3108
+ for (let i = 0; i < ip.length; i++) {
3109
+ if (i % 2 === 0) {
3110
+ result.push(ip[i].toString(16).padStart(2, "0") + ip[i + 1].toString(16).padStart(2, "0"));
3111
+ }
3112
+ }
3113
+ return result.join(":");
3114
+ }
3115
+ default: {
3116
+ throw new Error("Invalid ip length");
3117
+ }
3118
+ }
3119
+ }
3120
+ function simpleMaskLength(mask) {
3121
+ let ones = 0;
3122
+ for (let [index, byte] of mask.entries()) {
3123
+ if (byte === 255) {
3124
+ ones += 8;
3125
+ continue;
3126
+ }
3127
+ while ((byte & 128) != 0) {
3128
+ ones++;
3129
+ byte = byte << 1;
3130
+ }
3131
+ if ((byte & 128) != 0) {
3132
+ return -1;
3133
+ }
3134
+ for (let i = index + 1; i < mask.length; i++) {
3135
+ if (mask[i] != 0) {
3136
+ return -1;
3137
+ }
3138
+ }
3139
+ break;
3140
+ }
3141
+ return ones;
3142
+ }
3143
+ function maskToHex(mask) {
3144
+ let hex = "0x";
3145
+ for (const byte of mask) {
3146
+ hex += (byte >> 4).toString(16) + (byte & 15).toString(16);
3147
+ }
3148
+ return hex;
3149
+ }
3150
+ var init_util = __esm({
3151
+ "node_modules/@chainsafe/netmask/dist/src/util.js"() {
3152
+ "use strict";
3153
+ init_ip();
3154
+ }
3155
+ });
3156
+
3157
+ // node_modules/@chainsafe/netmask/dist/src/ip.js
3158
+ function maskIp(ip, mask) {
3159
+ if (mask.length === IPv6Len && ip.length === IPv4Len && allFF(mask, 0, 11)) {
3160
+ mask = mask.slice(12);
3161
+ }
3162
+ if (mask.length === IPv4Len && ip.length === IPv6Len && deepEqual(ip, ipv4Prefix, 0, 11)) {
3163
+ ip = ip.slice(12);
3164
+ }
3165
+ const n = ip.length;
3166
+ if (n != mask.length) {
3167
+ throw new Error("Failed to mask ip");
3168
+ }
3169
+ const out = new Uint8Array(n);
3170
+ for (let i = 0; i < n; i++) {
3171
+ out[i] = ip[i] & mask[i];
3172
+ }
3173
+ return out;
3174
+ }
3175
+ function containsIp(net, ip) {
3176
+ if (typeof ip === "string") {
3177
+ ip = parseIP(ip);
3178
+ }
3179
+ if (ip == null)
3180
+ throw new Error("Invalid ip");
3181
+ if (ip.length !== net.network.length) {
3182
+ return false;
3183
+ }
3184
+ for (let i = 0; i < ip.length; i++) {
3185
+ if ((net.network[i] & net.mask[i]) !== (ip[i] & net.mask[i])) {
3186
+ return false;
3187
+ }
3188
+ }
3189
+ return true;
3190
+ }
3191
+ var IPv4Len, IPv6Len, maxIPv6Octet, ipv4Prefix;
3192
+ var init_ip = __esm({
3193
+ "node_modules/@chainsafe/netmask/dist/src/ip.js"() {
3194
+ "use strict";
3195
+ init_parse();
3196
+ init_util();
3197
+ IPv4Len = 4;
3198
+ IPv6Len = 16;
3199
+ maxIPv6Octet = parseInt("0xFFFF", 16);
3200
+ ipv4Prefix = new Uint8Array([
3201
+ 0,
3202
+ 0,
3203
+ 0,
3204
+ 0,
3205
+ 0,
3206
+ 0,
3207
+ 0,
3208
+ 0,
3209
+ 0,
3210
+ 0,
3211
+ 255,
3212
+ 255
3213
+ ]);
3214
+ }
3215
+ });
3216
+
3217
+ // node_modules/@chainsafe/netmask/dist/src/cidr.js
3218
+ function parseCidr(s) {
3219
+ const [address, maskString] = s.split("/");
3220
+ if (!address || !maskString)
3221
+ throw new Error("Failed to parse given CIDR: " + s);
3222
+ let ipLength = IPv4Len;
3223
+ let ip = parseIPv4(address);
3224
+ if (ip == null) {
3225
+ ipLength = IPv6Len;
3226
+ ip = parseIPv6(address);
3227
+ if (ip == null)
3228
+ throw new Error("Failed to parse given CIDR: " + s);
3229
+ }
3230
+ const m = parseInt(maskString, 10);
3231
+ if (Number.isNaN(m) || String(m).length !== maskString.length || m < 0 || m > ipLength * 8) {
3232
+ throw new Error("Failed to parse given CIDR: " + s);
3233
+ }
3234
+ const mask = cidrMask(m, 8 * ipLength);
3235
+ return {
3236
+ network: maskIp(ip, mask),
3237
+ mask
3238
+ };
3239
+ }
3240
+ function cidrMask(ones, bits) {
3241
+ if (bits !== 8 * IPv4Len && bits !== 8 * IPv6Len)
3242
+ throw new Error("Invalid CIDR mask");
3243
+ if (ones < 0 || ones > bits)
3244
+ throw new Error("Invalid CIDR mask");
3245
+ const l = bits / 8;
3246
+ const m = new Uint8Array(l);
3247
+ for (let i = 0; i < l; i++) {
3248
+ if (ones >= 8) {
3249
+ m[i] = 255;
3250
+ ones -= 8;
3251
+ continue;
3252
+ }
3253
+ m[i] = 255 - (255 >> ones);
3254
+ ones = 0;
3255
+ }
3256
+ return m;
3257
+ }
3258
+ var init_cidr = __esm({
3259
+ "node_modules/@chainsafe/netmask/dist/src/cidr.js"() {
3260
+ "use strict";
3261
+ init_parse();
3262
+ init_ip();
3263
+ }
3264
+ });
3265
+
3266
+ // node_modules/@chainsafe/netmask/dist/src/ipnet.js
3267
+ var IpNet;
3268
+ var init_ipnet = __esm({
3269
+ "node_modules/@chainsafe/netmask/dist/src/ipnet.js"() {
3270
+ "use strict";
3271
+ init_parse();
3272
+ init_cidr();
3273
+ init_ip();
3274
+ init_util();
3275
+ IpNet = class {
3276
+ /**
3277
+ *
3278
+ * @param ipOrCidr either network ip or full cidr address
3279
+ * @param mask in case ipOrCidr is network this can be either mask in decimal format or as ip address
3280
+ */
3281
+ constructor(ipOrCidr, mask) {
3282
+ if (mask == null) {
3283
+ ({ network: this.network, mask: this.mask } = parseCidr(ipOrCidr));
3284
+ } else {
3285
+ const ipResult = parseIP(ipOrCidr);
3286
+ if (ipResult == null) {
3287
+ throw new Error("Failed to parse network");
3288
+ }
3289
+ mask = String(mask);
3290
+ const m = parseInt(mask, 10);
3291
+ if (Number.isNaN(m) || String(m).length !== mask.length || m < 0 || m > ipResult.length * 8) {
3292
+ const maskResult = parseIP(mask);
3293
+ if (maskResult == null) {
3294
+ throw new Error("Failed to parse mask");
3295
+ }
3296
+ this.mask = maskResult;
3297
+ } else {
3298
+ this.mask = cidrMask(m, 8 * ipResult.length);
3299
+ }
3300
+ this.network = maskIp(ipResult, this.mask);
3301
+ }
3302
+ }
3303
+ /**
3304
+ * Checks if netmask contains ip address
3305
+ * @param ip
3306
+ * @returns
3307
+ */
3308
+ contains(ip) {
3309
+ return containsIp({ network: this.network, mask: this.mask }, ip);
3310
+ }
3311
+ /**Serializes back to string format */
3312
+ toString() {
3313
+ const l = simpleMaskLength(this.mask);
3314
+ const mask = l !== -1 ? String(l) : maskToHex(this.mask);
3315
+ return ipToString(this.network) + "/" + mask;
3316
+ }
3317
+ };
3318
+ }
3319
+ });
3320
+
3321
+ // node_modules/@chainsafe/netmask/dist/src/index.js
3322
+ var init_src3 = __esm({
3323
+ "node_modules/@chainsafe/netmask/dist/src/index.js"() {
3324
+ "use strict";
3325
+ init_ipnet();
3326
+ init_util();
3327
+ init_ip();
3328
+ init_ipnet();
3329
+ init_cidr();
3330
+ }
3331
+ });
3332
+
3333
+ // node_modules/@multiformats/multiaddr/dist/src/convert.js
3334
+ function convertToIpNet(multiaddr2) {
3335
+ let mask;
3336
+ let addr;
3337
+ multiaddr2.getComponents().forEach((component) => {
3338
+ if (component.name === "ip4" || component.name === "ip6") {
3339
+ addr = component.value;
3340
+ }
3341
+ if (component.name === "ipcidr") {
3342
+ mask = component.value;
3343
+ }
3344
+ });
3345
+ if (mask == null || addr == null) {
3346
+ throw new Error("Invalid multiaddr");
3347
+ }
3348
+ return new IpNet(addr, mask);
3349
+ }
3350
+ var init_convert = __esm({
3351
+ "node_modules/@multiformats/multiaddr/dist/src/convert.js"() {
3352
+ "use strict";
3353
+ init_src3();
3354
+ init_from_string_node();
3355
+ init_to_string_node();
3356
+ init_registry();
3357
+ }
3358
+ });
3359
+
3360
+ // node_modules/@multiformats/multiaddr/dist/src/filter/multiaddr-filter.js
3361
+ var MultiaddrFilter;
3362
+ var init_multiaddr_filter = __esm({
3363
+ "node_modules/@multiformats/multiaddr/dist/src/filter/multiaddr-filter.js"() {
3364
+ "use strict";
3365
+ init_convert();
3366
+ init_src4();
3367
+ MultiaddrFilter = class {
3368
+ multiaddr;
3369
+ netmask;
3370
+ constructor(input) {
3371
+ this.multiaddr = multiaddr(input);
3372
+ this.netmask = convertToIpNet(this.multiaddr);
3373
+ }
3374
+ contains(input) {
3375
+ if (input == null) {
3376
+ return false;
3377
+ }
3378
+ const m = multiaddr(input);
3379
+ let ip;
3380
+ for (const [code2, value] of m.stringTuples()) {
3381
+ if (code2 === 4 || code2 === 41) {
3382
+ ip = value;
3383
+ break;
3384
+ }
3385
+ }
3386
+ if (ip === void 0) {
3387
+ return false;
3388
+ }
3389
+ return this.netmask.contains(ip);
3390
+ }
3391
+ };
3392
+ }
3393
+ });
3394
+
3395
+ // node_modules/@multiformats/multiaddr/dist/src/index.js
3396
+ var src_exports2 = {};
3397
+ __export(src_exports2, {
3398
+ CODE_CERTHASH: () => CODE_CERTHASH,
3399
+ CODE_DCCP: () => CODE_DCCP,
3400
+ CODE_DNS: () => CODE_DNS,
3401
+ CODE_DNS4: () => CODE_DNS4,
3402
+ CODE_DNS6: () => CODE_DNS6,
3403
+ CODE_DNSADDR: () => CODE_DNSADDR,
3404
+ CODE_GARLIC32: () => CODE_GARLIC32,
3405
+ CODE_GARLIC64: () => CODE_GARLIC64,
3406
+ CODE_HTTP: () => CODE_HTTP,
3407
+ CODE_HTTPS: () => CODE_HTTPS,
3408
+ CODE_HTTP_PATH: () => CODE_HTTP_PATH,
3409
+ CODE_IP4: () => CODE_IP4,
3410
+ CODE_IP6: () => CODE_IP6,
3411
+ CODE_IP6ZONE: () => CODE_IP6ZONE,
3412
+ CODE_IPCIDR: () => CODE_IPCIDR,
3413
+ CODE_MEMORY: () => CODE_MEMORY,
3414
+ CODE_NOISE: () => CODE_NOISE,
3415
+ CODE_ONION: () => CODE_ONION,
3416
+ CODE_ONION3: () => CODE_ONION3,
3417
+ CODE_P2P: () => CODE_P2P,
3418
+ CODE_P2P_CIRCUIT: () => CODE_P2P_CIRCUIT,
3419
+ CODE_P2P_STARDUST: () => CODE_P2P_STARDUST,
3420
+ CODE_P2P_WEBRTC_DIRECT: () => CODE_P2P_WEBRTC_DIRECT,
3421
+ CODE_P2P_WEBRTC_STAR: () => CODE_P2P_WEBRTC_STAR,
3422
+ CODE_P2P_WEBSOCKET_STAR: () => CODE_P2P_WEBSOCKET_STAR,
3423
+ CODE_QUIC: () => CODE_QUIC,
3424
+ CODE_QUIC_V1: () => CODE_QUIC_V1,
3425
+ CODE_SCTP: () => CODE_SCTP,
3426
+ CODE_SNI: () => CODE_SNI,
3427
+ CODE_TCP: () => CODE_TCP,
3428
+ CODE_TLS: () => CODE_TLS,
3429
+ CODE_UDP: () => CODE_UDP,
3430
+ CODE_UDT: () => CODE_UDT,
3431
+ CODE_UNIX: () => CODE_UNIX,
3432
+ CODE_UTP: () => CODE_UTP,
3433
+ CODE_WEBRTC: () => CODE_WEBRTC,
3434
+ CODE_WEBRTC_DIRECT: () => CODE_WEBRTC_DIRECT,
3435
+ CODE_WEBTRANSPORT: () => CODE_WEBTRANSPORT,
3436
+ CODE_WS: () => CODE_WS,
3437
+ CODE_WSS: () => CODE_WSS,
3438
+ MultiaddrFilter: () => MultiaddrFilter,
3439
+ V: () => V,
3440
+ fromNodeAddress: () => fromNodeAddress,
3441
+ fromStringTuples: () => fromStringTuples,
3442
+ fromTuples: () => fromTuples,
3443
+ isMultiaddr: () => isMultiaddr,
3444
+ isName: () => isName,
3445
+ multiaddr: () => multiaddr,
3446
+ protocols: () => protocols,
3447
+ registry: () => registry,
3448
+ resolvers: () => resolvers
3449
+ });
3450
+ function fromNodeAddress(addr, transport) {
3451
+ if (addr == null) {
3452
+ throw new InvalidParametersError("requires node address object");
3453
+ }
3454
+ if (transport == null) {
3455
+ throw new InvalidParametersError("requires transport protocol");
3456
+ }
3457
+ let ip;
3458
+ let host = addr.address;
3459
+ switch (addr.family) {
3460
+ case 4:
3461
+ ip = "ip4";
3462
+ break;
3463
+ case 6:
3464
+ ip = "ip6";
3465
+ if (host.includes("%")) {
3466
+ const parts = host.split("%");
3467
+ if (parts.length !== 2) {
3468
+ throw Error("Multiple ip6 zones in multiaddr");
3469
+ }
3470
+ host = parts[0];
3471
+ const zone = parts[1];
3472
+ ip = `ip6zone/${zone}/ip6`;
3473
+ }
3474
+ break;
3475
+ default:
3476
+ throw Error("Invalid addr family, should be 4 or 6.");
3477
+ }
3478
+ return new Multiaddr("/" + [ip, host, transport, addr.port].join("/"));
3479
+ }
3480
+ function fromTuples(tuples) {
3481
+ return multiaddr(tuples.map(([code2, value]) => {
3482
+ const codec = registry.getProtocol(code2);
3483
+ const component = {
3484
+ code: code2,
3485
+ name: codec.name
3486
+ };
3487
+ if (value != null) {
3488
+ component.value = codec.bytesToValue?.(value) ?? toString2(value);
3489
+ }
3490
+ return component;
3491
+ }));
3492
+ }
3493
+ function fromStringTuples(tuples) {
3494
+ return multiaddr(tuples.map(([code2, value]) => {
3495
+ const codec = registry.getProtocol(code2);
3496
+ const component = {
3497
+ code: code2,
3498
+ name: codec.name
3499
+ };
3500
+ if (value != null) {
3501
+ component.value = value;
3502
+ }
3503
+ return component;
3504
+ }));
3505
+ }
3506
+ function isName(addr) {
3507
+ if (!isMultiaddr(addr)) {
3508
+ return false;
3509
+ }
3510
+ return addr.protos().some((proto) => proto.resolvable);
3511
+ }
3512
+ function isMultiaddr(value) {
3513
+ return Boolean(value?.[symbol]);
3514
+ }
3515
+ function multiaddr(addr) {
3516
+ return new Multiaddr(addr);
3517
+ }
3518
+ function protocols(proto) {
3519
+ const codec = registry.getProtocol(proto);
3520
+ return {
3521
+ code: codec.code,
3522
+ size: codec.size ?? 0,
3523
+ name: codec.name,
3524
+ resolvable: Boolean(codec.resolvable),
3525
+ path: Boolean(codec.path)
3526
+ };
3527
+ }
3528
+ var resolvers;
3529
+ var init_src4 = __esm({
3530
+ "node_modules/@multiformats/multiaddr/dist/src/index.js"() {
3531
+ "use strict";
3532
+ init_to_string_node();
3533
+ init_errors();
3534
+ init_multiaddr();
3535
+ init_registry();
3536
+ init_multiaddr_filter();
3537
+ init_constants();
3538
+ resolvers = /* @__PURE__ */ new Map();
3539
+ }
3540
+ });
3541
+
129
3542
  // src/browser.ts
130
3543
  var browser_exports = {};
131
3544
  __export(browser_exports, {
@@ -198,10 +3611,10 @@ var ErrorBehavior = /* @__PURE__ */ ((ErrorBehavior2) => {
198
3611
  var CairnError = class extends Error {
199
3612
  code;
200
3613
  details;
201
- constructor(code, message, details) {
3614
+ constructor(code2, message, details) {
202
3615
  super(message);
203
3616
  this.name = "CairnError";
204
- this.code = code;
3617
+ this.code = code2;
205
3618
  this.details = details;
206
3619
  }
207
3620
  errorBehavior() {
@@ -369,9 +3782,9 @@ var HKDF_INFO_RENDEZVOUS = encoder.encode("cairn-rendezvous-id-v1");
369
3782
  var HKDF_INFO_SAS = encoder.encode("cairn-sas-derivation-v1");
370
3783
  var HKDF_INFO_CHAIN_KEY = encoder.encode("cairn-chain-key-v1");
371
3784
  var HKDF_INFO_MESSAGE_KEY = encoder.encode("cairn-message-key-v1");
372
- function hkdfSha256(ikm, salt, info, length) {
3785
+ function hkdfSha256(ikm, salt, info, length2) {
373
3786
  try {
374
- return (0, import_hkdf.hkdf)(import_sha2562.sha256, ikm, salt, info, length);
3787
+ return (0, import_hkdf.hkdf)(import_sha2562.sha256, ikm, salt, info, length2);
375
3788
  } catch (e) {
376
3789
  throw new CairnError("CRYPTO", `HKDF-SHA256 error: ${e}`);
377
3790
  }
@@ -445,8 +3858,8 @@ var NoiseXXHandshake = class {
445
3858
  currentKey;
446
3859
  pakeSecret;
447
3860
  cachedResult;
448
- constructor(role, identity, pakeSecret) {
449
- this.localStaticX25519Secret = import_ed25519.ed25519.utils.toMontgomerySecret(identity.secretBytes());
3861
+ constructor(role, identity3, pakeSecret) {
3862
+ this.localStaticX25519Secret = import_ed25519.ed25519.utils.toMontgomerySecret(identity3.secretBytes());
450
3863
  if (PROTOCOL_NAME.length <= 32) {
451
3864
  this.handshakeHash = new Uint8Array(32);
452
3865
  this.handshakeHash.set(PROTOCOL_NAME);
@@ -454,7 +3867,7 @@ var NoiseXXHandshake = class {
454
3867
  this.handshakeHash = (0, import_sha2563.sha256)(PROTOCOL_NAME);
455
3868
  }
456
3869
  this.chainingKey = new Uint8Array(this.handshakeHash);
457
- this.localIdentity = identity;
3870
+ this.localIdentity = identity3;
458
3871
  this.state = role === "initiator" ? "initiator_start" : "responder_wait_msg1";
459
3872
  if (pakeSecret) {
460
3873
  if (pakeSecret.length !== 32) {
@@ -1422,8 +4835,8 @@ var MessageQueue = class {
1422
4835
  var APP_MSG_TYPE_MIN = 61440;
1423
4836
  var APP_MSG_TYPE_MAX = 65535;
1424
4837
  var NodeChannel = class {
1425
- constructor(name) {
1426
- this.name = name;
4838
+ constructor(name2) {
4839
+ this.name = name2;
1427
4840
  }
1428
4841
  _open = true;
1429
4842
  get isOpen() {
@@ -1466,15 +4879,15 @@ var NodeSession = class {
1466
4879
  this._ratchet = ratchet;
1467
4880
  }
1468
4881
  /** Open a named channel. */
1469
- openChannel(name) {
1470
- if (!name) {
4882
+ openChannel(name2) {
4883
+ if (!name2) {
1471
4884
  throw new CairnError("PROTOCOL", "channel name cannot be empty");
1472
4885
  }
1473
- if (name.startsWith("__cairn_")) {
4886
+ if (name2.startsWith("__cairn_")) {
1474
4887
  throw new CairnError("PROTOCOL", "reserved channel name prefix");
1475
4888
  }
1476
- const channel = new NodeChannel(name);
1477
- this._channels.set(name, channel);
4889
+ const channel = new NodeChannel(name2);
4890
+ this._channels.set(name2, channel);
1478
4891
  for (const listener of this._channelListeners) {
1479
4892
  listener(channel);
1480
4893
  }
@@ -1629,6 +5042,8 @@ var Node = class _Node {
1629
5042
  _libp2pNode = null;
1630
5043
  /** Listen addresses reported by the libp2p node. */
1631
5044
  _listenAddresses = [];
5045
+ /** Connection hints from pairing, keyed by peer ID hex string. */
5046
+ _peerHints = /* @__PURE__ */ new Map();
1632
5047
  constructor(config) {
1633
5048
  this._config = config;
1634
5049
  }
@@ -1803,6 +5218,9 @@ var Node = class _Node {
1803
5218
  const payload = consumeQrPayload(data);
1804
5219
  this._runPairingExchange(payload.pakeCredential);
1805
5220
  const remotePeerId = bytesToHex3(payload.peerId);
5221
+ if (payload.hints && payload.hints.length > 0) {
5222
+ this._peerHints.set(remotePeerId, payload.hints);
5223
+ }
1806
5224
  this._completePairing(remotePeerId);
1807
5225
  return remotePeerId;
1808
5226
  }
@@ -1838,8 +5256,28 @@ var Node = class _Node {
1838
5256
  return remotePeerId;
1839
5257
  }
1840
5258
  // --- Connection methods ---
1841
- /** Connect to a paired peer. Performs Noise XX handshake and Double Ratchet init. */
5259
+ /** Connect to a paired peer. Dials via libp2p if transport is started, falls back to in-memory handshake. */
1842
5260
  async connect(peerId, _options) {
5261
+ if (this._libp2pNode && this._peerHints.has(peerId)) {
5262
+ const hints = this._peerHints.get(peerId);
5263
+ const { multiaddr: multiaddr2 } = await Promise.resolve().then(() => (init_src4(), src_exports2));
5264
+ const wsHints = hints.filter((h) => h.hintType === "multiaddr" && h.value.includes("/ws"));
5265
+ const tcpHints = hints.filter((h) => h.hintType === "multiaddr" && h.value.includes("/tcp/") && !h.value.includes("/ws"));
5266
+ const allHints = [...wsHints, ...tcpHints];
5267
+ let connected = false;
5268
+ for (const hint of allHints) {
5269
+ try {
5270
+ const ma = multiaddr2(hint.value);
5271
+ await this._libp2pNode.dial(ma);
5272
+ connected = true;
5273
+ break;
5274
+ } catch {
5275
+ }
5276
+ }
5277
+ if (!connected && allHints.length > 0) {
5278
+ throw new CairnError("TRANSPORT", `failed to connect to peer ${peerId} via any address`);
5279
+ }
5280
+ }
1843
5281
  const handshakeResult = await this._performNoiseHandshake();
1844
5282
  const bobDh = X25519Keypair.generate();
1845
5283
  const ratchet = DoubleRatchet.initSender(handshakeResult.sessionKey, bobDh.publicKeyBytes());
@@ -1921,8 +5359,8 @@ var VALID_TRANSITIONS = [
1921
5359
  ["suspended", "failed"],
1922
5360
  ["reconnected", "connected"]
1923
5361
  ];
1924
- function isValidTransition(from, to) {
1925
- return VALID_TRANSITIONS.some(([f, t]) => f === from && t === to);
5362
+ function isValidTransition(from3, to) {
5363
+ return VALID_TRANSITIONS.some(([f, t]) => f === from3 && t === to);
1926
5364
  }
1927
5365
  var SessionStateMachine = class {
1928
5366
  _sessionId;
@@ -1957,11 +5395,11 @@ var SessionStateMachine = class {
1957
5395
  `invalid session state transition: ${this._state} -> ${to}`
1958
5396
  );
1959
5397
  }
1960
- const from = this._state;
5398
+ const from3 = this._state;
1961
5399
  this._state = to;
1962
5400
  const event = {
1963
5401
  sessionId: this._sessionId,
1964
- fromState: from,
5402
+ fromState: from3,
1965
5403
  toState: to,
1966
5404
  timestamp: Date.now(),
1967
5405
  reason