@waku/enr 0.0.16 → 0.0.18

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/bundle/index.js CHANGED
@@ -22,7 +22,7 @@ function asUint8Array(buf) {
22
22
  // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
23
23
  // Distributed under the MIT software license, see the accompanying
24
24
  // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
25
- function base (ALPHABET, name) {
25
+ function base$1 (ALPHABET, name) {
26
26
  if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
27
27
  var BASE_MAP = new Uint8Array(256);
28
28
  for (var j = 0; j < BASE_MAP.length; j++) {
@@ -139,9 +139,9 @@ function base (ALPHABET, name) {
139
139
  decode: decode
140
140
  }
141
141
  }
142
- var src = base;
142
+ var src$1 = base$1;
143
143
 
144
- var _brrp__multiformats_scope_baseX = src;
144
+ var _brrp__multiformats_scope_baseX$1 = src$1;
145
145
 
146
146
  /**
147
147
  * @param {Uint8Array} aa
@@ -166,7 +166,7 @@ const equals$2 = (aa, bb) => {
166
166
  * @param {ArrayBufferView|ArrayBuffer|Uint8Array} o
167
167
  * @returns {Uint8Array}
168
168
  */
169
- const coerce = o => {
169
+ const coerce$1 = o => {
170
170
  if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array') return o
171
171
  if (o instanceof ArrayBuffer) return new Uint8Array(o)
172
172
  if (ArrayBuffer.isView(o)) {
@@ -179,7 +179,7 @@ const coerce = o => {
179
179
  * @param {string} str
180
180
  * @returns {Uint8Array}
181
181
  */
182
- const fromString$2 = str => (new TextEncoder()).encode(str);
182
+ const fromString$1 = str => (new TextEncoder()).encode(str);
183
183
 
184
184
  /**
185
185
  * @param {Uint8Array} b
@@ -198,7 +198,7 @@ const toString$2 = b => (new TextDecoder()).decode(b);
198
198
  * @implements {API.MultibaseEncoder<Prefix>}
199
199
  * @implements {API.BaseEncoder}
200
200
  */
201
- class Encoder {
201
+ let Encoder$1 = class Encoder {
202
202
  /**
203
203
  * @param {Base} name
204
204
  * @param {Prefix} prefix
@@ -221,7 +221,7 @@ class Encoder {
221
221
  throw Error('Unknown type, must be binary type')
222
222
  }
223
223
  }
224
- }
224
+ };
225
225
 
226
226
  /**
227
227
  * @template {string} Prefix
@@ -238,7 +238,7 @@ class Encoder {
238
238
  * @implements {API.UnibaseDecoder<Prefix>}
239
239
  * @implements {API.BaseDecoder}
240
240
  */
241
- class Decoder {
241
+ let Decoder$1 = class Decoder {
242
242
  /**
243
243
  * @param {Base} name
244
244
  * @param {Prefix} prefix
@@ -276,9 +276,9 @@ class Decoder {
276
276
  * @returns {ComposedDecoder<Prefix|OtherPrefix>}
277
277
  */
278
278
  or (decoder) {
279
- return or(this, decoder)
279
+ return or$1(this, decoder)
280
280
  }
281
- }
281
+ };
282
282
 
283
283
  /**
284
284
  * @template {string} Prefix
@@ -290,7 +290,7 @@ class Decoder {
290
290
  * @implements {API.MultibaseDecoder<Prefix>}
291
291
  * @implements {API.CombobaseDecoder<Prefix>}
292
292
  */
293
- class ComposedDecoder {
293
+ let ComposedDecoder$1 = class ComposedDecoder {
294
294
  /**
295
295
  * @param {Decoders<Prefix>} decoders
296
296
  */
@@ -304,7 +304,7 @@ class ComposedDecoder {
304
304
  * @returns {ComposedDecoder<Prefix|OtherPrefix>}
305
305
  */
306
306
  or (decoder) {
307
- return or(this, decoder)
307
+ return or$1(this, decoder)
308
308
  }
309
309
 
310
310
  /**
@@ -320,7 +320,7 @@ class ComposedDecoder {
320
320
  throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)
321
321
  }
322
322
  }
323
- }
323
+ };
324
324
 
325
325
  /**
326
326
  * @template {string} L
@@ -329,7 +329,7 @@ class ComposedDecoder {
329
329
  * @param {API.UnibaseDecoder<R>|API.CombobaseDecoder<R>} right
330
330
  * @returns {ComposedDecoder<L|R>}
331
331
  */
332
- const or = (left, right) => new ComposedDecoder(/** @type {Decoders<L|R>} */({
332
+ const or$1 = (left, right) => new ComposedDecoder$1(/** @type {Decoders<L|R>} */({
333
333
  ...(left.decoders || { [/** @type API.UnibaseDecoder<L> */(left).prefix]: left }),
334
334
  ...(right.decoders || { [/** @type API.UnibaseDecoder<R> */(right).prefix]: right })
335
335
  }));
@@ -345,7 +345,7 @@ const or = (left, right) => new ComposedDecoder(/** @type {Decoders<L|R>} */({
345
345
  * @implements {API.BaseEncoder}
346
346
  * @implements {API.BaseDecoder}
347
347
  */
348
- class Codec {
348
+ let Codec$1 = class Codec {
349
349
  /**
350
350
  * @param {Base} name
351
351
  * @param {Prefix} prefix
@@ -357,8 +357,8 @@ class Codec {
357
357
  this.prefix = prefix;
358
358
  this.baseEncode = baseEncode;
359
359
  this.baseDecode = baseDecode;
360
- this.encoder = new Encoder(name, prefix, baseEncode);
361
- this.decoder = new Decoder(name, prefix, baseDecode);
360
+ this.encoder = new Encoder$1(name, prefix, baseEncode);
361
+ this.decoder = new Decoder$1(name, prefix, baseDecode);
362
362
  }
363
363
 
364
364
  /**
@@ -374,7 +374,7 @@ class Codec {
374
374
  decode (input) {
375
375
  return this.decoder.decode(input)
376
376
  }
377
- }
377
+ };
378
378
 
379
379
  /**
380
380
  * @template {string} Base
@@ -386,8 +386,8 @@ class Codec {
386
386
  * @param {(input:string) => Uint8Array} options.decode
387
387
  * @returns {Codec<Base, Prefix>}
388
388
  */
389
- const from$1 = ({ name, prefix, encode, decode }) =>
390
- new Codec(name, prefix, encode, decode);
389
+ const from$3 = ({ name, prefix, encode, decode }) =>
390
+ new Codec$1(name, prefix, encode, decode);
391
391
 
392
392
  /**
393
393
  * @template {string} Base
@@ -398,16 +398,16 @@ const from$1 = ({ name, prefix, encode, decode }) =>
398
398
  * @param {string} options.alphabet
399
399
  * @returns {Codec<Base, Prefix>}
400
400
  */
401
- const baseX = ({ prefix, name, alphabet }) => {
402
- const { encode, decode } = _brrp__multiformats_scope_baseX(alphabet, name);
403
- return from$1({
401
+ const baseX$1 = ({ prefix, name, alphabet }) => {
402
+ const { encode, decode } = _brrp__multiformats_scope_baseX$1(alphabet, name);
403
+ return from$3({
404
404
  prefix,
405
405
  name,
406
406
  encode,
407
407
  /**
408
408
  * @param {string} text
409
409
  */
410
- decode: text => coerce(decode(text))
410
+ decode: text => coerce$1(decode(text))
411
411
  })
412
412
  };
413
413
 
@@ -418,7 +418,7 @@ const baseX = ({ prefix, name, alphabet }) => {
418
418
  * @param {string} name
419
419
  * @returns {Uint8Array}
420
420
  */
421
- const decode$6 = (string, alphabet, bitsPerChar, name) => {
421
+ const decode$8 = (string, alphabet, bitsPerChar, name) => {
422
422
  // Build the character lookup table:
423
423
  /** @type {Record<string, number>} */
424
424
  const codes = {};
@@ -471,7 +471,7 @@ const decode$6 = (string, alphabet, bitsPerChar, name) => {
471
471
  * @param {number} bitsPerChar
472
472
  * @returns {string}
473
473
  */
474
- const encode$5 = (data, alphabet, bitsPerChar) => {
474
+ const encode$8 = (data, alphabet, bitsPerChar) => {
475
475
  const pad = alphabet[alphabet.length - 1] === '=';
476
476
  const mask = (1 << bitsPerChar) - 1;
477
477
  let out = '';
@@ -516,62 +516,20 @@ const encode$5 = (data, alphabet, bitsPerChar) => {
516
516
  * @param {string} options.alphabet
517
517
  * @param {number} options.bitsPerChar
518
518
  */
519
- const rfc4648 = ({ name, prefix, bitsPerChar, alphabet }) => {
520
- return from$1({
519
+ const rfc4648$1 = ({ name, prefix, bitsPerChar, alphabet }) => {
520
+ return from$3({
521
521
  prefix,
522
522
  name,
523
523
  encode (input) {
524
- return encode$5(input, alphabet, bitsPerChar)
524
+ return encode$8(input, alphabet, bitsPerChar)
525
525
  },
526
526
  decode (input) {
527
- return decode$6(input, alphabet, bitsPerChar, name)
527
+ return decode$8(input, alphabet, bitsPerChar, name)
528
528
  }
529
529
  })
530
530
  };
531
531
 
532
- // @ts-check
533
-
534
- const identity$1 = from$1({
535
- prefix: '\x00',
536
- name: 'identity',
537
- encode: (buf) => toString$2(buf),
538
- decode: (str) => fromString$2(str)
539
- });
540
-
541
- var identityBase = /*#__PURE__*/Object.freeze({
542
- __proto__: null,
543
- identity: identity$1
544
- });
545
-
546
- // @ts-check
547
-
548
- const base2 = rfc4648({
549
- prefix: '0',
550
- name: 'base2',
551
- alphabet: '01',
552
- bitsPerChar: 1
553
- });
554
-
555
- var base2$1 = /*#__PURE__*/Object.freeze({
556
- __proto__: null,
557
- base2: base2
558
- });
559
-
560
- // @ts-check
561
-
562
- const base8 = rfc4648({
563
- prefix: '7',
564
- name: 'base8',
565
- alphabet: '01234567',
566
- bitsPerChar: 3
567
- });
568
-
569
- var base8$1 = /*#__PURE__*/Object.freeze({
570
- __proto__: null,
571
- base8: base8
572
- });
573
-
574
- const base10 = baseX({
532
+ const base10 = baseX$1({
575
533
  prefix: '9',
576
534
  name: 'base10',
577
535
  alphabet: '0123456789'
@@ -584,14 +542,15 @@ var base10$1 = /*#__PURE__*/Object.freeze({
584
542
 
585
543
  // @ts-check
586
544
 
587
- const base16 = rfc4648({
545
+
546
+ const base16 = rfc4648$1({
588
547
  prefix: 'f',
589
548
  name: 'base16',
590
549
  alphabet: '0123456789abcdef',
591
550
  bitsPerChar: 4
592
551
  });
593
552
 
594
- const base16upper = rfc4648({
553
+ const base16upper = rfc4648$1({
595
554
  prefix: 'F',
596
555
  name: 'base16upper',
597
556
  alphabet: '0123456789ABCDEF',
@@ -604,63 +563,121 @@ var base16$1 = /*#__PURE__*/Object.freeze({
604
563
  base16upper: base16upper
605
564
  });
606
565
 
607
- const base32 = rfc4648({
566
+ // @ts-check
567
+
568
+
569
+ const base2 = rfc4648$1({
570
+ prefix: '0',
571
+ name: 'base2',
572
+ alphabet: '01',
573
+ bitsPerChar: 1
574
+ });
575
+
576
+ var base2$1 = /*#__PURE__*/Object.freeze({
577
+ __proto__: null,
578
+ base2: base2
579
+ });
580
+
581
+ const alphabet = Array.from('🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂');
582
+ const alphabetBytesToChars = /** @type {string[]} */ (alphabet.reduce((p, c, i) => { p[i] = c; return p }, /** @type {string[]} */([])));
583
+ const alphabetCharsToBytes = /** @type {number[]} */ (alphabet.reduce((p, c, i) => { p[/** @type {number} */ (c.codePointAt(0))] = i; return p }, /** @type {number[]} */([])));
584
+
585
+ /**
586
+ * @param {Uint8Array} data
587
+ * @returns {string}
588
+ */
589
+ function encode$7 (data) {
590
+ return data.reduce((p, c) => {
591
+ p += alphabetBytesToChars[c];
592
+ return p
593
+ }, '')
594
+ }
595
+
596
+ /**
597
+ * @param {string} str
598
+ * @returns {Uint8Array}
599
+ */
600
+ function decode$7 (str) {
601
+ const byts = [];
602
+ for (const char of str) {
603
+ const byt = alphabetCharsToBytes[/** @type {number} */ (char.codePointAt(0))];
604
+ if (byt === undefined) {
605
+ throw new Error(`Non-base256emoji character: ${char}`)
606
+ }
607
+ byts.push(byt);
608
+ }
609
+ return new Uint8Array(byts)
610
+ }
611
+
612
+ const base256emoji = from$3({
613
+ prefix: '🚀',
614
+ name: 'base256emoji',
615
+ encode: encode$7,
616
+ decode: decode$7
617
+ });
618
+
619
+ var base256emoji$1 = /*#__PURE__*/Object.freeze({
620
+ __proto__: null,
621
+ base256emoji: base256emoji
622
+ });
623
+
624
+ const base32 = rfc4648$1({
608
625
  prefix: 'b',
609
626
  name: 'base32',
610
627
  alphabet: 'abcdefghijklmnopqrstuvwxyz234567',
611
628
  bitsPerChar: 5
612
629
  });
613
630
 
614
- const base32upper = rfc4648({
631
+ const base32upper = rfc4648$1({
615
632
  prefix: 'B',
616
633
  name: 'base32upper',
617
634
  alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
618
635
  bitsPerChar: 5
619
636
  });
620
637
 
621
- const base32pad = rfc4648({
638
+ const base32pad = rfc4648$1({
622
639
  prefix: 'c',
623
640
  name: 'base32pad',
624
641
  alphabet: 'abcdefghijklmnopqrstuvwxyz234567=',
625
642
  bitsPerChar: 5
626
643
  });
627
644
 
628
- const base32padupper = rfc4648({
645
+ const base32padupper = rfc4648$1({
629
646
  prefix: 'C',
630
647
  name: 'base32padupper',
631
648
  alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=',
632
649
  bitsPerChar: 5
633
650
  });
634
651
 
635
- const base32hex = rfc4648({
652
+ const base32hex = rfc4648$1({
636
653
  prefix: 'v',
637
654
  name: 'base32hex',
638
655
  alphabet: '0123456789abcdefghijklmnopqrstuv',
639
656
  bitsPerChar: 5
640
657
  });
641
658
 
642
- const base32hexupper = rfc4648({
659
+ const base32hexupper = rfc4648$1({
643
660
  prefix: 'V',
644
661
  name: 'base32hexupper',
645
662
  alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV',
646
663
  bitsPerChar: 5
647
664
  });
648
665
 
649
- const base32hexpad = rfc4648({
666
+ const base32hexpad = rfc4648$1({
650
667
  prefix: 't',
651
668
  name: 'base32hexpad',
652
669
  alphabet: '0123456789abcdefghijklmnopqrstuv=',
653
670
  bitsPerChar: 5
654
671
  });
655
672
 
656
- const base32hexpadupper = rfc4648({
673
+ const base32hexpadupper = rfc4648$1({
657
674
  prefix: 'T',
658
675
  name: 'base32hexpadupper',
659
676
  alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV=',
660
677
  bitsPerChar: 5
661
678
  });
662
679
 
663
- const base32z = rfc4648({
680
+ const base32z = rfc4648$1({
664
681
  prefix: 'h',
665
682
  name: 'base32z',
666
683
  alphabet: 'ybndrfg8ejkmcpqxot1uwisza345h769',
@@ -680,13 +697,13 @@ var base32$1 = /*#__PURE__*/Object.freeze({
680
697
  base32z: base32z
681
698
  });
682
699
 
683
- const base36 = baseX({
700
+ const base36 = baseX$1({
684
701
  prefix: 'k',
685
702
  name: 'base36',
686
703
  alphabet: '0123456789abcdefghijklmnopqrstuvwxyz'
687
704
  });
688
705
 
689
- const base36upper = baseX({
706
+ const base36upper = baseX$1({
690
707
  prefix: 'K',
691
708
  name: 'base36upper',
692
709
  alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -698,13 +715,13 @@ var base36$1 = /*#__PURE__*/Object.freeze({
698
715
  base36upper: base36upper
699
716
  });
700
717
 
701
- const base58btc = baseX({
718
+ const base58btc$1 = baseX$1({
702
719
  name: 'base58btc',
703
720
  prefix: 'z',
704
721
  alphabet: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
705
722
  });
706
723
 
707
- const base58flickr = baseX({
724
+ const base58flickr = baseX$1({
708
725
  name: 'base58flickr',
709
726
  prefix: 'Z',
710
727
  alphabet: '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
@@ -712,119 +729,117 @@ const base58flickr = baseX({
712
729
 
713
730
  var base58 = /*#__PURE__*/Object.freeze({
714
731
  __proto__: null,
715
- base58btc: base58btc,
732
+ base58btc: base58btc$1,
716
733
  base58flickr: base58flickr
717
734
  });
718
735
 
719
736
  // @ts-check
720
737
 
721
- const base64$2 = rfc4648({
738
+
739
+ const base64$3 = rfc4648$1({
722
740
  prefix: 'm',
723
741
  name: 'base64',
724
742
  alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
725
743
  bitsPerChar: 6
726
744
  });
727
745
 
728
- const base64pad = rfc4648({
746
+ const base64pad = rfc4648$1({
729
747
  prefix: 'M',
730
748
  name: 'base64pad',
731
749
  alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
732
750
  bitsPerChar: 6
733
751
  });
734
752
 
735
- const base64url = rfc4648({
753
+ const base64url = rfc4648$1({
736
754
  prefix: 'u',
737
755
  name: 'base64url',
738
756
  alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
739
757
  bitsPerChar: 6
740
758
  });
741
759
 
742
- const base64urlpad = rfc4648({
760
+ const base64urlpad = rfc4648$1({
743
761
  prefix: 'U',
744
762
  name: 'base64urlpad',
745
763
  alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=',
746
764
  bitsPerChar: 6
747
765
  });
748
766
 
749
- var base64$3 = /*#__PURE__*/Object.freeze({
767
+ var base64$4 = /*#__PURE__*/Object.freeze({
750
768
  __proto__: null,
751
- base64: base64$2,
769
+ base64: base64$3,
752
770
  base64pad: base64pad,
753
771
  base64url: base64url,
754
772
  base64urlpad: base64urlpad
755
773
  });
756
774
 
757
- const alphabet = Array.from('🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂');
758
- const alphabetBytesToChars = /** @type {string[]} */ (alphabet.reduce((p, c, i) => { p[i] = c; return p }, /** @type {string[]} */([])));
759
- const alphabetCharsToBytes = /** @type {number[]} */ (alphabet.reduce((p, c, i) => { p[/** @type {number} */ (c.codePointAt(0))] = i; return p }, /** @type {number[]} */([])));
775
+ // @ts-check
760
776
 
761
- /**
762
- * @param {Uint8Array} data
763
- * @returns {string}
764
- */
765
- function encode$4 (data) {
766
- return data.reduce((p, c) => {
767
- p += alphabetBytesToChars[c];
768
- return p
769
- }, '')
770
- }
771
777
 
772
- /**
773
- * @param {string} str
774
- * @returns {Uint8Array}
775
- */
776
- function decode$5 (str) {
777
- const byts = [];
778
- for (const char of str) {
779
- const byt = alphabetCharsToBytes[/** @type {number} */ (char.codePointAt(0))];
780
- if (byt === undefined) {
781
- throw new Error(`Non-base256emoji character: ${char}`)
782
- }
783
- byts.push(byt);
784
- }
785
- return new Uint8Array(byts)
786
- }
778
+ const base8 = rfc4648$1({
779
+ prefix: '7',
780
+ name: 'base8',
781
+ alphabet: '01234567',
782
+ bitsPerChar: 3
783
+ });
787
784
 
788
- const base256emoji = from$1({
789
- prefix: '🚀',
790
- name: 'base256emoji',
791
- encode: encode$4,
792
- decode: decode$5
785
+ var base8$1 = /*#__PURE__*/Object.freeze({
786
+ __proto__: null,
787
+ base8: base8
793
788
  });
794
789
 
795
- var base256emoji$1 = /*#__PURE__*/Object.freeze({
790
+ // @ts-check
791
+
792
+
793
+ const identity$2 = from$3({
794
+ prefix: '\x00',
795
+ name: 'identity',
796
+ encode: (buf) => toString$2(buf),
797
+ decode: (str) => fromString$1(str)
798
+ });
799
+
800
+ var identityBase = /*#__PURE__*/Object.freeze({
796
801
  __proto__: null,
797
- base256emoji: base256emoji
802
+ identity: identity$2
798
803
  });
799
804
 
800
- var encode_1$1 = encode$3;
805
+ // @ts-check
806
+
807
+ /**
808
+ * @template T
809
+ * @typedef {import('./interface.js').ByteView<T>} ByteView
810
+ */
811
+
812
+ new TextEncoder();
813
+ new TextDecoder();
814
+
815
+ var encode_1$1 = encode$6;
801
816
 
802
- var MSB$2 = 0x80
803
- , REST$2 = 0x7F
804
- , MSBALL$1 = ~REST$2
817
+ var MSB$3 = 0x80
818
+ , REST$3 = 0x7F
819
+ , MSBALL$1 = ~REST$3
805
820
  , INT$1 = Math.pow(2, 31);
806
821
 
807
- function encode$3(num, out, offset) {
822
+ function encode$6(num, out, offset) {
808
823
  out = out || [];
809
824
  offset = offset || 0;
810
825
  var oldOffset = offset;
811
826
 
812
827
  while(num >= INT$1) {
813
- out[offset++] = (num & 0xFF) | MSB$2;
828
+ out[offset++] = (num & 0xFF) | MSB$3;
814
829
  num /= 128;
815
830
  }
816
831
  while(num & MSBALL$1) {
817
- out[offset++] = (num & 0xFF) | MSB$2;
832
+ out[offset++] = (num & 0xFF) | MSB$3;
818
833
  num >>>= 7;
819
834
  }
820
835
  out[offset] = num | 0;
821
836
 
822
- encode$3.bytes = offset - oldOffset + 1;
837
+ encode$6.bytes = offset - oldOffset + 1;
823
838
 
824
839
  return out
825
840
  }
826
841
 
827
- var decode$4 = read$1;
842
+ var decode$6 = read$1;
828
843
 
829
844
  var MSB$1$1 = 0x80
830
845
  , REST$1$1 = 0x7F;
@@ -854,47 +869,47 @@ function read$1(buf, offset) {
854
869
  return res
855
870
  }
856
871
 
857
- var N1$1 = Math.pow(2, 7);
858
- var N2$1 = Math.pow(2, 14);
859
- var N3$1 = Math.pow(2, 21);
860
- var N4$1 = Math.pow(2, 28);
861
- var N5$1 = Math.pow(2, 35);
862
- var N6$1 = Math.pow(2, 42);
863
- var N7$1 = Math.pow(2, 49);
872
+ var N1$2 = Math.pow(2, 7);
873
+ var N2$2 = Math.pow(2, 14);
874
+ var N3$2 = Math.pow(2, 21);
875
+ var N4$2 = Math.pow(2, 28);
876
+ var N5$2 = Math.pow(2, 35);
877
+ var N6$2 = Math.pow(2, 42);
878
+ var N7$2 = Math.pow(2, 49);
864
879
  var N8$1 = Math.pow(2, 56);
865
880
  var N9$1 = Math.pow(2, 63);
866
881
 
867
882
  var length$1 = function (value) {
868
883
  return (
869
- value < N1$1 ? 1
870
- : value < N2$1 ? 2
871
- : value < N3$1 ? 3
872
- : value < N4$1 ? 4
873
- : value < N5$1 ? 5
874
- : value < N6$1 ? 6
875
- : value < N7$1 ? 7
884
+ value < N1$2 ? 1
885
+ : value < N2$2 ? 2
886
+ : value < N3$2 ? 3
887
+ : value < N4$2 ? 4
888
+ : value < N5$2 ? 5
889
+ : value < N6$2 ? 6
890
+ : value < N7$2 ? 7
876
891
  : value < N8$1 ? 8
877
892
  : value < N9$1 ? 9
878
893
  : 10
879
894
  )
880
895
  };
881
896
 
882
- var varint$2 = {
897
+ var varint$1 = {
883
898
  encode: encode_1$1
884
- , decode: decode$4
899
+ , decode: decode$6
885
900
  , encodingLength: length$1
886
901
  };
887
902
 
888
- var _brrp_varint = varint$2;
903
+ var _brrp_varint$1 = varint$1;
889
904
 
890
905
  /**
891
906
  * @param {Uint8Array} data
892
907
  * @param {number} [offset=0]
893
908
  * @returns {[number, number]}
894
909
  */
895
- const decode$3 = (data, offset = 0) => {
896
- const code = _brrp_varint.decode(data, offset);
897
- return [code, _brrp_varint.decode.bytes]
910
+ const decode$5 = (data, offset = 0) => {
911
+ const code = _brrp_varint$1.decode(data, offset);
912
+ return [code, _brrp_varint$1.decode.bytes]
898
913
  };
899
914
 
900
915
  /**
@@ -902,8 +917,8 @@ const decode$3 = (data, offset = 0) => {
902
917
  * @param {Uint8Array} target
903
918
  * @param {number} [offset=0]
904
919
  */
905
- const encodeTo = (int, target, offset = 0) => {
906
- _brrp_varint.encode(int, target, offset);
920
+ const encodeTo$1 = (int, target, offset = 0) => {
921
+ _brrp_varint$1.encode(int, target, offset);
907
922
  return target
908
923
  };
909
924
 
@@ -911,8 +926,8 @@ const encodeTo = (int, target, offset = 0) => {
911
926
  * @param {number} int
912
927
  * @returns {number}
913
928
  */
914
- const encodingLength = (int) => {
915
- return _brrp_varint.encodingLength(int)
929
+ const encodingLength$2 = (int) => {
930
+ return _brrp_varint$1.encodingLength(int)
916
931
  };
917
932
 
918
933
  /**
@@ -922,17 +937,17 @@ const encodingLength = (int) => {
922
937
  * @param {Code} code
923
938
  * @param {Uint8Array} digest
924
939
  */
925
- const create$3 = (code, digest) => {
940
+ const create$4 = (code, digest) => {
926
941
  const size = digest.byteLength;
927
- const sizeOffset = encodingLength(code);
928
- const digestOffset = sizeOffset + encodingLength(size);
942
+ const sizeOffset = encodingLength$2(code);
943
+ const digestOffset = sizeOffset + encodingLength$2(size);
929
944
 
930
945
  const bytes = new Uint8Array(digestOffset + size);
931
- encodeTo(code, bytes, 0);
932
- encodeTo(size, bytes, sizeOffset);
946
+ encodeTo$1(code, bytes, 0);
947
+ encodeTo$1(size, bytes, sizeOffset);
933
948
  bytes.set(digest, digestOffset);
934
949
 
935
- return new Digest(code, size, digest, bytes)
950
+ return new Digest$1(code, size, digest, bytes)
936
951
  };
937
952
 
938
953
  /**
@@ -941,17 +956,17 @@ const create$3 = (code, digest) => {
941
956
  * @param {Uint8Array} multihash
942
957
  * @returns {MultihashDigest}
943
958
  */
944
- const decode$2 = (multihash) => {
945
- const bytes = coerce(multihash);
946
- const [code, sizeOffset] = decode$3(bytes);
947
- const [size, digestOffset] = decode$3(bytes.subarray(sizeOffset));
959
+ const decode$4 = (multihash) => {
960
+ const bytes = coerce$1(multihash);
961
+ const [code, sizeOffset] = decode$5(bytes);
962
+ const [size, digestOffset] = decode$5(bytes.subarray(sizeOffset));
948
963
  const digest = bytes.subarray(sizeOffset + digestOffset);
949
964
 
950
965
  if (digest.byteLength !== size) {
951
966
  throw new Error('Incorrect length')
952
967
  }
953
968
 
954
- return new Digest(code, size, digest, bytes)
969
+ return new Digest$1(code, size, digest, bytes)
955
970
  };
956
971
 
957
972
  /**
@@ -987,7 +1002,7 @@ const equals$1 = (a, b) => {
987
1002
  * @class
988
1003
  * @implements {MultihashDigest}
989
1004
  */
990
- class Digest {
1005
+ let Digest$1 = class Digest {
991
1006
  /**
992
1007
  * Creates a multihash digest.
993
1008
  *
@@ -1002,7 +1017,21 @@ class Digest {
1002
1017
  this.digest = digest;
1003
1018
  this.bytes = bytes;
1004
1019
  }
1005
- }
1020
+ };
1021
+
1022
+ const code$1 = 0x0;
1023
+ const name$1 = 'identity';
1024
+
1025
+ /** @type {(input:Uint8Array) => Uint8Array} */
1026
+ const encode$5 = coerce$1;
1027
+
1028
+ /**
1029
+ * @param {Uint8Array} input
1030
+ * @returns {Digest.Digest<typeof code, number>}
1031
+ */
1032
+ const digest$1 = (input) => create$4(code$1, encode$5(input));
1033
+
1034
+ const identity$1 = { code: code$1, name: name$1, encode: encode$5, digest: digest$1 };
1006
1035
 
1007
1036
  /**
1008
1037
  * @template {string} Name
@@ -1012,7 +1041,7 @@ class Digest {
1012
1041
  * @param {Code} options.code
1013
1042
  * @param {(input: Uint8Array) => Await<Uint8Array>} options.encode
1014
1043
  */
1015
- const from = ({ name, code, encode }) => new Hasher(name, code, encode);
1044
+ const from$2 = ({ name, code, encode }) => new Hasher$1(name, code, encode);
1016
1045
 
1017
1046
  /**
1018
1047
  * Hasher represents a hashing algorithm implementation that produces as
@@ -1023,7 +1052,7 @@ const from = ({ name, code, encode }) => new Hasher(name, code, encode);
1023
1052
  * @class
1024
1053
  * @implements {MultihashHasher<Code>}
1025
1054
  */
1026
- class Hasher {
1055
+ let Hasher$1 = class Hasher {
1027
1056
  /**
1028
1057
  *
1029
1058
  * @param {Name} name
@@ -1044,15 +1073,15 @@ class Hasher {
1044
1073
  if (input instanceof Uint8Array) {
1045
1074
  const result = this.encode(input);
1046
1075
  return result instanceof Uint8Array
1047
- ? create$3(this.code, result)
1076
+ ? create$4(this.code, result)
1048
1077
  /* c8 ignore next 1 */
1049
- : result.then(digest => create$3(this.code, digest))
1078
+ : result.then(digest => create$4(this.code, digest))
1050
1079
  } else {
1051
1080
  throw Error('Unknown type, must be binary type')
1052
1081
  /* c8 ignore next 1 */
1053
1082
  }
1054
1083
  }
1055
- }
1084
+ };
1056
1085
 
1057
1086
  /**
1058
1087
  * @template {number} Alg
@@ -1066,45 +1095,22 @@ class Hasher {
1066
1095
 
1067
1096
  /* global crypto */
1068
1097
 
1098
+
1069
1099
  /**
1070
1100
  * @param {AlgorithmIdentifier} name
1071
1101
  */
1072
- const sha = name =>
1102
+ const sha$1 = name =>
1073
1103
  /**
1074
1104
  * @param {Uint8Array} data
1075
1105
  */
1076
1106
  async data => new Uint8Array(await crypto.subtle.digest(name, data));
1077
1107
 
1078
- const sha256$1 = from({
1108
+ const sha256$2 = from$2({
1079
1109
  name: 'sha2-256',
1080
1110
  code: 0x12,
1081
- encode: sha('SHA-256')
1111
+ encode: sha$1('SHA-256')
1082
1112
  });
1083
1113
 
1084
- const code = 0x0;
1085
- const name = 'identity';
1086
-
1087
- /** @type {(input:Uint8Array) => Uint8Array} */
1088
- const encode$2 = coerce;
1089
-
1090
- /**
1091
- * @param {Uint8Array} input
1092
- * @returns {Digest.Digest<typeof code, number>}
1093
- */
1094
- const digest = (input) => create$3(code, encode$2(input));
1095
-
1096
- const identity = { code, name, encode: encode$2, digest };
1097
-
1098
- // @ts-check
1099
-
1100
- /**
1101
- * @template T
1102
- * @typedef {import('./interface.js').ByteView<T>} ByteView
1103
- */
1104
-
1105
- new TextEncoder();
1106
- new TextDecoder();
1107
-
1108
1114
  /**
1109
1115
  * @template {API.Link<unknown, number, number, API.Version>} T
1110
1116
  * @template {string} Prefix
@@ -1119,7 +1125,7 @@ const format = (link, base) => {
1119
1125
  return toStringV0(
1120
1126
  bytes,
1121
1127
  baseCache(link),
1122
- /** @type {API.MultibaseEncoder<"z">} */ (base) || base58btc.encoder
1128
+ /** @type {API.MultibaseEncoder<"z">} */ (base) || base58btc$1.encoder
1123
1129
  )
1124
1130
  default:
1125
1131
  return toStringV1(
@@ -1161,7 +1167,6 @@ class CID {
1161
1167
  * @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
1162
1168
  * @param {API.MultihashDigest<Alg>} multihash - (Multi)hash of the of the content.
1163
1169
  * @param {Uint8Array} bytes
1164
- *
1165
1170
  */
1166
1171
  constructor (version, code, multihash, bytes) {
1167
1172
  /** @readonly */
@@ -1240,7 +1245,7 @@ class CID {
1240
1245
  switch (this.version) {
1241
1246
  case 0: {
1242
1247
  const { code, digest } = this.multihash;
1243
- const multihash = create$3(code, digest);
1248
+ const multihash = create$4(code, digest);
1244
1249
  return /** @type {CID<Data, Format, Alg, 1>} */ (
1245
1250
  CID.createV1(this.code, multihash)
1246
1251
  )
@@ -1294,6 +1299,9 @@ class CID {
1294
1299
  return format(this, base)
1295
1300
  }
1296
1301
 
1302
+ /**
1303
+ * @returns {API.LinkJSON<this>}
1304
+ */
1297
1305
  toJSON () {
1298
1306
  return { '/': format(this) }
1299
1307
  }
@@ -1359,7 +1367,7 @@ class CID {
1359
1367
  const { version, multihash, code } = value;
1360
1368
  const digest =
1361
1369
  /** @type {API.MultihashDigest<Alg>} */
1362
- (decode$2(multihash));
1370
+ (decode$4(multihash));
1363
1371
  return CID.create(version, code, digest)
1364
1372
  } else {
1365
1373
  // Otherwise value is not a CID (or an incompatible version of it) in
@@ -1474,7 +1482,7 @@ class CID {
1474
1482
  static decodeFirst (bytes) {
1475
1483
  const specs = CID.inspectBytes(bytes);
1476
1484
  const prefixSize = specs.size - specs.multihashSize;
1477
- const multihashBytes = coerce(
1485
+ const multihashBytes = coerce$1(
1478
1486
  bytes.subarray(prefixSize, prefixSize + specs.multihashSize)
1479
1487
  );
1480
1488
  if (multihashBytes.byteLength !== specs.multihashSize) {
@@ -1483,7 +1491,7 @@ class CID {
1483
1491
  const digestBytes = multihashBytes.subarray(
1484
1492
  specs.multihashSize - specs.digestSize
1485
1493
  );
1486
- const digest = new Digest(
1494
+ const digest = new Digest$1(
1487
1495
  specs.multihashCode,
1488
1496
  specs.digestSize,
1489
1497
  digestBytes,
@@ -1515,7 +1523,7 @@ class CID {
1515
1523
  static inspectBytes (initialBytes) {
1516
1524
  let offset = 0;
1517
1525
  const next = () => {
1518
- const [i, length] = decode$3(initialBytes.subarray(offset));
1526
+ const [i, length] = decode$5(initialBytes.subarray(offset));
1519
1527
  offset += length;
1520
1528
  return i
1521
1529
  };
@@ -1588,15 +1596,15 @@ const parseCIDtoBytes = (source, base) => {
1588
1596
  switch (source[0]) {
1589
1597
  // CIDv0 is parsed differently
1590
1598
  case 'Q': {
1591
- const decoder = base || base58btc;
1599
+ const decoder = base || base58btc$1;
1592
1600
  return [
1593
- /** @type {Prefix} */ (base58btc.prefix),
1594
- decoder.decode(`${base58btc.prefix}${source}`)
1601
+ /** @type {Prefix} */ (base58btc$1.prefix),
1602
+ decoder.decode(`${base58btc$1.prefix}${source}`)
1595
1603
  ]
1596
1604
  }
1597
- case base58btc.prefix: {
1598
- const decoder = base || base58btc;
1599
- return [/** @type {Prefix} */(base58btc.prefix), decoder.decode(source)]
1605
+ case base58btc$1.prefix: {
1606
+ const decoder = base || base58btc$1;
1607
+ return [/** @type {Prefix} */(base58btc$1.prefix), decoder.decode(source)]
1600
1608
  }
1601
1609
  case base32.prefix: {
1602
1610
  const decoder = base || base32;
@@ -1621,7 +1629,7 @@ const parseCIDtoBytes = (source, base) => {
1621
1629
  */
1622
1630
  const toStringV0 = (bytes, cache, base) => {
1623
1631
  const { prefix } = base;
1624
- if (prefix !== base58btc.prefix) {
1632
+ if (prefix !== base58btc$1.prefix) {
1625
1633
  throw Error(`Cannot string encode V0 in ${base.name} encoding`)
1626
1634
  }
1627
1635
 
@@ -1663,11 +1671,11 @@ const SHA_256_CODE = 0x12;
1663
1671
  * @returns {Uint8Array}
1664
1672
  */
1665
1673
  const encodeCID = (version, code, multihash) => {
1666
- const codeOffset = encodingLength(version);
1667
- const hashOffset = codeOffset + encodingLength(code);
1674
+ const codeOffset = encodingLength$2(version);
1675
+ const hashOffset = codeOffset + encodingLength$2(code);
1668
1676
  const bytes = new Uint8Array(hashOffset + multihash.byteLength);
1669
- encodeTo(version, bytes, 0);
1670
- encodeTo(code, bytes, codeOffset);
1677
+ encodeTo$1(version, bytes, 0);
1678
+ encodeTo$1(code, bytes, codeOffset);
1671
1679
  bytes.set(multihash, hashOffset);
1672
1680
  return bytes
1673
1681
  };
@@ -1676,7 +1684,8 @@ const cidSymbol = Symbol.for('@ipld/js-cid/CID');
1676
1684
 
1677
1685
  // @ts-check
1678
1686
 
1679
- const bases = { ...identityBase, ...base2$1, ...base8$1, ...base10$1, ...base16$1, ...base32$1, ...base36$1, ...base58, ...base64$3, ...base256emoji$1 };
1687
+
1688
+ const bases = { ...identityBase, ...base2$1, ...base8$1, ...base10$1, ...base16$1, ...base32$1, ...base36$1, ...base58, ...base64$4, ...base256emoji$1 };
1680
1689
 
1681
1690
  /**
1682
1691
  * Where possible returns a Uint8Array of the requested size that references
@@ -1742,7 +1751,7 @@ const BASES = {
1742
1751
  *
1743
1752
  * Also `ascii` which is similar to node's 'binary' encoding.
1744
1753
  */
1745
- function fromString$1(string, encoding = 'utf8') {
1754
+ function fromString(string, encoding = 'utf8') {
1746
1755
  const base = BASES[encoding];
1747
1756
  if (base == null) {
1748
1757
  throw new Error(`Unsupported encoding "${encoding}"`);
@@ -1781,7 +1790,7 @@ function toString$1(array, encoding = 'utf8') {
1781
1790
  function hexToBytes$2(hex) {
1782
1791
  if (typeof hex === "string") {
1783
1792
  const _hex = hex.replace(/^0x/i, "");
1784
- return fromString$1(_hex.toLowerCase(), "base16");
1793
+ return fromString(_hex.toLowerCase(), "base16");
1785
1794
  }
1786
1795
  return hex;
1787
1796
  }
@@ -1796,7 +1805,7 @@ const bytesToUtf8 = (b) => toString$1(b, "utf8");
1796
1805
  /**
1797
1806
  * Encode utf-8 string to byte array.
1798
1807
  */
1799
- const utf8ToBytes = (s) => fromString$1(s, "utf8");
1808
+ const utf8ToBytes = (s) => fromString(s, "utf8");
1800
1809
  /**
1801
1810
  * Concatenate using Uint8Arrays as `Buffer` has a different behavior with `DataView`
1802
1811
  */
@@ -2868,10 +2877,7 @@ function getAugmentedNamespace(n) {
2868
2877
  if (typeof f == "function") {
2869
2878
  var a = function a () {
2870
2879
  if (this instanceof a) {
2871
- var args = [null];
2872
- args.push.apply(args, arguments);
2873
- var Ctor = Function.bind.apply(f, args);
2874
- return new Ctor();
2880
+ return Reflect.construct(f, arguments, this.constructor);
2875
2881
  }
2876
2882
  return f.apply(this, arguments);
2877
2883
  };
@@ -2895,9 +2901,9 @@ var sha3$1 = {exports: {}};
2895
2901
  /**
2896
2902
  * [js-sha3]{@link https://github.com/emn178/js-sha3}
2897
2903
  *
2898
- * @version 0.8.0
2904
+ * @version 0.9.2
2899
2905
  * @author Chen, Yi-Cyuan [emn178@gmail.com]
2900
- * @copyright Chen, Yi-Cyuan 2015-2018
2906
+ * @copyright Chen, Yi-Cyuan 2015-2023
2901
2907
  * @license MIT
2902
2908
  */
2903
2909
 
@@ -2940,17 +2946,40 @@ var sha3$1 = {exports: {}};
2940
2946
  '256': 136
2941
2947
  };
2942
2948
 
2943
- if (root.JS_SHA3_NO_NODE_JS || !Array.isArray) {
2944
- Array.isArray = function (obj) {
2945
- return Object.prototype.toString.call(obj) === '[object Array]';
2946
- };
2947
- }
2948
2949
 
2949
- if (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
2950
- ArrayBuffer.isView = function (obj) {
2951
- return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
2952
- };
2953
- }
2950
+ var isArray = root.JS_SHA3_NO_NODE_JS || !Array.isArray
2951
+ ? function (obj) {
2952
+ return Object.prototype.toString.call(obj) === '[object Array]';
2953
+ }
2954
+ : Array.isArray;
2955
+
2956
+ var isView = (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView))
2957
+ ? function (obj) {
2958
+ return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
2959
+ }
2960
+ : ArrayBuffer.isView;
2961
+
2962
+ // [message: string, isString: bool]
2963
+ var formatMessage = function (message) {
2964
+ var type = typeof message;
2965
+ if (type === 'string') {
2966
+ return [message, true];
2967
+ }
2968
+ if (type !== 'object' || message === null) {
2969
+ throw new Error(INPUT_ERROR);
2970
+ }
2971
+ if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
2972
+ return [new Uint8Array(message), false];
2973
+ }
2974
+ if (!isArray(message) && !isView(message)) {
2975
+ throw new Error(INPUT_ERROR);
2976
+ }
2977
+ return [message, false];
2978
+ };
2979
+
2980
+ var empty = function (message) {
2981
+ return formatMessage(message)[0].length === 0;
2982
+ };
2954
2983
 
2955
2984
  var createOutputMethod = function (bits, padding, outputType) {
2956
2985
  return function (message) {
@@ -3010,7 +3039,7 @@ var sha3$1 = {exports: {}};
3010
3039
  var w = CSHAKE_BYTEPAD[bits];
3011
3040
  var method = createCshakeOutputMethod(bits, padding, 'hex');
3012
3041
  method.create = function (outputBits, n, s) {
3013
- if (!n && !s) {
3042
+ if (empty(n) && empty(s)) {
3014
3043
  return methods['shake' + bits].create(outputBits);
3015
3044
  } else {
3016
3045
  return new Keccak(bits, padding, outputBits).bytepad([n, s], w);
@@ -3082,23 +3111,9 @@ var sha3$1 = {exports: {}};
3082
3111
  if (this.finalized) {
3083
3112
  throw new Error(FINALIZE_ERROR);
3084
3113
  }
3085
- var notString, type = typeof message;
3086
- if (type !== 'string') {
3087
- if (type === 'object') {
3088
- if (message === null) {
3089
- throw new Error(INPUT_ERROR);
3090
- } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
3091
- message = new Uint8Array(message);
3092
- } else if (!Array.isArray(message)) {
3093
- if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
3094
- throw new Error(INPUT_ERROR);
3095
- }
3096
- }
3097
- } else {
3098
- throw new Error(INPUT_ERROR);
3099
- }
3100
- notString = true;
3101
- }
3114
+ var result = formatMessage(message);
3115
+ message = result[0];
3116
+ var isString = result[1];
3102
3117
  var blocks = this.blocks, byteCount = this.byteCount, length = message.length,
3103
3118
  blockCount = this.blockCount, index = 0, s = this.s, i, code;
3104
3119
 
@@ -3110,11 +3125,7 @@ var sha3$1 = {exports: {}};
3110
3125
  blocks[i] = 0;
3111
3126
  }
3112
3127
  }
3113
- if (notString) {
3114
- for (i = this.start; index < length && i < byteCount; ++index) {
3115
- blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
3116
- }
3117
- } else {
3128
+ if (isString) {
3118
3129
  for (i = this.start; index < length && i < byteCount; ++index) {
3119
3130
  code = message.charCodeAt(index);
3120
3131
  if (code < 0x80) {
@@ -3134,6 +3145,10 @@ var sha3$1 = {exports: {}};
3134
3145
  blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
3135
3146
  }
3136
3147
  }
3148
+ } else {
3149
+ for (i = this.start; index < length && i < byteCount; ++index) {
3150
+ blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
3151
+ }
3137
3152
  }
3138
3153
  this.lastByteIndex = i;
3139
3154
  if (i >= byteCount) {
@@ -3172,27 +3187,11 @@ var sha3$1 = {exports: {}};
3172
3187
  };
3173
3188
 
3174
3189
  Keccak.prototype.encodeString = function (str) {
3175
- var notString, type = typeof str;
3176
- if (type !== 'string') {
3177
- if (type === 'object') {
3178
- if (str === null) {
3179
- throw new Error(INPUT_ERROR);
3180
- } else if (ARRAY_BUFFER && str.constructor === ArrayBuffer) {
3181
- str = new Uint8Array(str);
3182
- } else if (!Array.isArray(str)) {
3183
- if (!ARRAY_BUFFER || !ArrayBuffer.isView(str)) {
3184
- throw new Error(INPUT_ERROR);
3185
- }
3186
- }
3187
- } else {
3188
- throw new Error(INPUT_ERROR);
3189
- }
3190
- notString = true;
3191
- }
3190
+ var result = formatMessage(str);
3191
+ str = result[0];
3192
+ var isString = result[1];
3192
3193
  var bytes = 0, length = str.length;
3193
- if (notString) {
3194
- bytes = length;
3195
- } else {
3194
+ if (isString) {
3196
3195
  for (var i = 0; i < str.length; ++i) {
3197
3196
  var code = str.charCodeAt(i);
3198
3197
  if (code < 0x80) {
@@ -3206,6 +3205,8 @@ var sha3$1 = {exports: {}};
3206
3205
  bytes += 4;
3207
3206
  }
3208
3207
  }
3208
+ } else {
3209
+ bytes = length;
3209
3210
  }
3210
3211
  bytes += this.encode(bytes * 8);
3211
3212
  this.update(str);
@@ -3217,7 +3218,7 @@ var sha3$1 = {exports: {}};
3217
3218
  for (var i = 0; i < strs.length; ++i) {
3218
3219
  bytes += this.encodeString(strs[i]);
3219
3220
  }
3220
- var paddingBytes = w - bytes % w;
3221
+ var paddingBytes = (w - bytes % w) % w;
3221
3222
  var zeros = [];
3222
3223
  zeros.length = paddingBytes;
3223
3224
  this.update(zeros);
@@ -3559,7 +3560,7 @@ var sha3 = /*@__PURE__*/getDefaultExportFromCjs(sha3Exports);
3559
3560
  async function sign$2(message, privateKey) {
3560
3561
  const [signature, recoveryId] = await sign$3(message, privateKey, {
3561
3562
  recovered: true,
3562
- der: false,
3563
+ der: false
3563
3564
  });
3564
3565
  return concat$1([signature, new Uint8Array([recoveryId])], signature.length + 1);
3565
3566
  }
@@ -4308,6 +4309,281 @@ var common = setup;
4308
4309
  var browserExports = browser.exports;
4309
4310
  var debug = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
4310
4311
 
4312
+ /**
4313
+ * When this error is thrown it means an operation was aborted,
4314
+ * usually in response to the `abort` event being emitted by an
4315
+ * AbortSignal.
4316
+ */
4317
+ let CodeError$1 = class CodeError extends Error {
4318
+ code;
4319
+ props;
4320
+ constructor(message, code, props) {
4321
+ super(message);
4322
+ this.code = code;
4323
+ this.name = props?.name ?? 'CodeError';
4324
+ this.props = props ?? {}; // eslint-disable-line @typescript-eslint/consistent-type-assertions
4325
+ }
4326
+ };
4327
+
4328
+ /**
4329
+ * Returns true if the two passed Uint8Arrays have the same content
4330
+ */
4331
+ function equals(a, b) {
4332
+ if (a === b) {
4333
+ return true;
4334
+ }
4335
+ if (a.byteLength !== b.byteLength) {
4336
+ return false;
4337
+ }
4338
+ for (let i = 0; i < a.byteLength; i++) {
4339
+ if (a[i] !== b[i]) {
4340
+ return false;
4341
+ }
4342
+ }
4343
+ return true;
4344
+ }
4345
+
4346
+ /* eslint-disable no-fallthrough */
4347
+ const N1$1 = Math.pow(2, 7);
4348
+ const N2$1 = Math.pow(2, 14);
4349
+ const N3$1 = Math.pow(2, 21);
4350
+ const N4$1 = Math.pow(2, 28);
4351
+ const N5$1 = Math.pow(2, 35);
4352
+ const N6$1 = Math.pow(2, 42);
4353
+ const N7$1 = Math.pow(2, 49);
4354
+ /** Most significant bit of a byte */
4355
+ const MSB$2 = 0x80;
4356
+ /** Rest of the bits in a byte */
4357
+ const REST$2 = 0x7f;
4358
+ function encodingLength$1(value) {
4359
+ if (value < N1$1) {
4360
+ return 1;
4361
+ }
4362
+ if (value < N2$1) {
4363
+ return 2;
4364
+ }
4365
+ if (value < N3$1) {
4366
+ return 3;
4367
+ }
4368
+ if (value < N4$1) {
4369
+ return 4;
4370
+ }
4371
+ if (value < N5$1) {
4372
+ return 5;
4373
+ }
4374
+ if (value < N6$1) {
4375
+ return 6;
4376
+ }
4377
+ if (value < N7$1) {
4378
+ return 7;
4379
+ }
4380
+ if (Number.MAX_SAFE_INTEGER != null && value > Number.MAX_SAFE_INTEGER) {
4381
+ throw new RangeError('Could not encode varint');
4382
+ }
4383
+ return 8;
4384
+ }
4385
+ function encodeUint8Array(value, buf, offset = 0) {
4386
+ switch (encodingLength$1(value)) {
4387
+ case 8: {
4388
+ buf[offset++] = (value & 0xFF) | MSB$2;
4389
+ value /= 128;
4390
+ }
4391
+ case 7: {
4392
+ buf[offset++] = (value & 0xFF) | MSB$2;
4393
+ value /= 128;
4394
+ }
4395
+ case 6: {
4396
+ buf[offset++] = (value & 0xFF) | MSB$2;
4397
+ value /= 128;
4398
+ }
4399
+ case 5: {
4400
+ buf[offset++] = (value & 0xFF) | MSB$2;
4401
+ value /= 128;
4402
+ }
4403
+ case 4: {
4404
+ buf[offset++] = (value & 0xFF) | MSB$2;
4405
+ value >>>= 7;
4406
+ }
4407
+ case 3: {
4408
+ buf[offset++] = (value & 0xFF) | MSB$2;
4409
+ value >>>= 7;
4410
+ }
4411
+ case 2: {
4412
+ buf[offset++] = (value & 0xFF) | MSB$2;
4413
+ value >>>= 7;
4414
+ }
4415
+ case 1: {
4416
+ buf[offset++] = (value & 0xFF);
4417
+ value >>>= 7;
4418
+ break;
4419
+ }
4420
+ default: throw new Error('unreachable');
4421
+ }
4422
+ return buf;
4423
+ }
4424
+ function encodeUint8ArrayList(value, buf, offset = 0) {
4425
+ switch (encodingLength$1(value)) {
4426
+ case 8: {
4427
+ buf.set(offset++, (value & 0xFF) | MSB$2);
4428
+ value /= 128;
4429
+ }
4430
+ case 7: {
4431
+ buf.set(offset++, (value & 0xFF) | MSB$2);
4432
+ value /= 128;
4433
+ }
4434
+ case 6: {
4435
+ buf.set(offset++, (value & 0xFF) | MSB$2);
4436
+ value /= 128;
4437
+ }
4438
+ case 5: {
4439
+ buf.set(offset++, (value & 0xFF) | MSB$2);
4440
+ value /= 128;
4441
+ }
4442
+ case 4: {
4443
+ buf.set(offset++, (value & 0xFF) | MSB$2);
4444
+ value >>>= 7;
4445
+ }
4446
+ case 3: {
4447
+ buf.set(offset++, (value & 0xFF) | MSB$2);
4448
+ value >>>= 7;
4449
+ }
4450
+ case 2: {
4451
+ buf.set(offset++, (value & 0xFF) | MSB$2);
4452
+ value >>>= 7;
4453
+ }
4454
+ case 1: {
4455
+ buf.set(offset++, (value & 0xFF));
4456
+ value >>>= 7;
4457
+ break;
4458
+ }
4459
+ default: throw new Error('unreachable');
4460
+ }
4461
+ return buf;
4462
+ }
4463
+ function decodeUint8Array(buf, offset) {
4464
+ let b = buf[offset];
4465
+ let res = 0;
4466
+ res += b & REST$2;
4467
+ if (b < MSB$2) {
4468
+ return res;
4469
+ }
4470
+ b = buf[offset + 1];
4471
+ res += (b & REST$2) << 7;
4472
+ if (b < MSB$2) {
4473
+ return res;
4474
+ }
4475
+ b = buf[offset + 2];
4476
+ res += (b & REST$2) << 14;
4477
+ if (b < MSB$2) {
4478
+ return res;
4479
+ }
4480
+ b = buf[offset + 3];
4481
+ res += (b & REST$2) << 21;
4482
+ if (b < MSB$2) {
4483
+ return res;
4484
+ }
4485
+ b = buf[offset + 4];
4486
+ res += (b & REST$2) * N4$1;
4487
+ if (b < MSB$2) {
4488
+ return res;
4489
+ }
4490
+ b = buf[offset + 5];
4491
+ res += (b & REST$2) * N5$1;
4492
+ if (b < MSB$2) {
4493
+ return res;
4494
+ }
4495
+ b = buf[offset + 6];
4496
+ res += (b & REST$2) * N6$1;
4497
+ if (b < MSB$2) {
4498
+ return res;
4499
+ }
4500
+ b = buf[offset + 7];
4501
+ res += (b & REST$2) * N7$1;
4502
+ if (b < MSB$2) {
4503
+ return res;
4504
+ }
4505
+ throw new RangeError('Could not decode varint');
4506
+ }
4507
+ function decodeUint8ArrayList(buf, offset) {
4508
+ let b = buf.get(offset);
4509
+ let res = 0;
4510
+ res += b & REST$2;
4511
+ if (b < MSB$2) {
4512
+ return res;
4513
+ }
4514
+ b = buf.get(offset + 1);
4515
+ res += (b & REST$2) << 7;
4516
+ if (b < MSB$2) {
4517
+ return res;
4518
+ }
4519
+ b = buf.get(offset + 2);
4520
+ res += (b & REST$2) << 14;
4521
+ if (b < MSB$2) {
4522
+ return res;
4523
+ }
4524
+ b = buf.get(offset + 3);
4525
+ res += (b & REST$2) << 21;
4526
+ if (b < MSB$2) {
4527
+ return res;
4528
+ }
4529
+ b = buf.get(offset + 4);
4530
+ res += (b & REST$2) * N4$1;
4531
+ if (b < MSB$2) {
4532
+ return res;
4533
+ }
4534
+ b = buf.get(offset + 5);
4535
+ res += (b & REST$2) * N5$1;
4536
+ if (b < MSB$2) {
4537
+ return res;
4538
+ }
4539
+ b = buf.get(offset + 6);
4540
+ res += (b & REST$2) * N6$1;
4541
+ if (b < MSB$2) {
4542
+ return res;
4543
+ }
4544
+ b = buf.get(offset + 7);
4545
+ res += (b & REST$2) * N7$1;
4546
+ if (b < MSB$2) {
4547
+ return res;
4548
+ }
4549
+ throw new RangeError('Could not decode varint');
4550
+ }
4551
+ function encode$4(value, buf, offset = 0) {
4552
+ if (buf == null) {
4553
+ buf = allocUnsafe(encodingLength$1(value));
4554
+ }
4555
+ if (buf instanceof Uint8Array) {
4556
+ return encodeUint8Array(value, buf, offset);
4557
+ }
4558
+ else {
4559
+ return encodeUint8ArrayList(value, buf, offset);
4560
+ }
4561
+ }
4562
+ function decode$3(buf, offset = 0) {
4563
+ if (buf instanceof Uint8Array) {
4564
+ return decodeUint8Array(buf, offset);
4565
+ }
4566
+ else {
4567
+ return decodeUint8ArrayList(buf, offset);
4568
+ }
4569
+ }
4570
+
4571
+ /**
4572
+ * Returns a new Uint8Array created by concatenating the passed ArrayLikes
4573
+ */
4574
+ function concat(arrays, length) {
4575
+ if (length == null) {
4576
+ length = arrays.reduce((acc, curr) => acc + curr.length, 0);
4577
+ }
4578
+ const output = allocUnsafe(length);
4579
+ let offset = 0;
4580
+ for (const arr of arrays) {
4581
+ output.set(arr, offset);
4582
+ offset += arr.length;
4583
+ }
4584
+ return asUint8Array(output);
4585
+ }
4586
+
4311
4587
  /* eslint-disable @typescript-eslint/no-unsafe-return */
4312
4588
  class Parser {
4313
4589
  index = 0;
@@ -4522,6 +4798,10 @@ function parseIPv4(input) {
4522
4798
  }
4523
4799
  /** Parse `input` into IPv6 bytes. */
4524
4800
  function parseIPv6(input) {
4801
+ // strip zone index if it is present
4802
+ if (input.includes("%")) {
4803
+ input = input.split("%")[0];
4804
+ }
4525
4805
  if (input.length > MAX_IPV6_LENGTH) {
4526
4806
  return undefined;
4527
4807
  }
@@ -4529,6 +4809,10 @@ function parseIPv6(input) {
4529
4809
  }
4530
4810
  /** Parse `input` into IPv4 or IPv6 bytes. */
4531
4811
  function parseIP(input) {
4812
+ // strip zone index if it is present
4813
+ if (input.includes("%")) {
4814
+ input = input.split("%")[0];
4815
+ }
4532
4816
  if (input.length > MAX_IPV6_LENGTH) {
4533
4817
  return undefined;
4534
4818
  }
@@ -4719,116 +5003,6 @@ function getProtocol(proto) {
4719
5003
  throw new Error(`invalid protocol id type: ${typeof proto}`);
4720
5004
  }
4721
5005
 
4722
- var encode_1 = encode$1;
4723
-
4724
- var MSB$1 = 0x80
4725
- , REST$1 = 0x7F
4726
- , MSBALL = ~REST$1
4727
- , INT = Math.pow(2, 31);
4728
-
4729
- function encode$1(num, out, offset) {
4730
- if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
4731
- encode$1.bytes = 0;
4732
- throw new RangeError('Could not encode varint')
4733
- }
4734
- out = out || [];
4735
- offset = offset || 0;
4736
- var oldOffset = offset;
4737
-
4738
- while(num >= INT) {
4739
- out[offset++] = (num & 0xFF) | MSB$1;
4740
- num /= 128;
4741
- }
4742
- while(num & MSBALL) {
4743
- out[offset++] = (num & 0xFF) | MSB$1;
4744
- num >>>= 7;
4745
- }
4746
- out[offset] = num | 0;
4747
-
4748
- encode$1.bytes = offset - oldOffset + 1;
4749
-
4750
- return out
4751
- }
4752
-
4753
- var decode$1 = read;
4754
-
4755
- var MSB = 0x80
4756
- , REST = 0x7F;
4757
-
4758
- function read(buf, offset) {
4759
- var res = 0
4760
- , offset = offset || 0
4761
- , shift = 0
4762
- , counter = offset
4763
- , b
4764
- , l = buf.length;
4765
-
4766
- do {
4767
- if (counter >= l || shift > 49) {
4768
- read.bytes = 0;
4769
- throw new RangeError('Could not decode varint')
4770
- }
4771
- b = buf[counter++];
4772
- res += shift < 28
4773
- ? (b & REST) << shift
4774
- : (b & REST) * Math.pow(2, shift);
4775
- shift += 7;
4776
- } while (b >= MSB)
4777
-
4778
- read.bytes = counter - offset;
4779
-
4780
- return res
4781
- }
4782
-
4783
- var N1 = Math.pow(2, 7);
4784
- var N2 = Math.pow(2, 14);
4785
- var N3 = Math.pow(2, 21);
4786
- var N4 = Math.pow(2, 28);
4787
- var N5 = Math.pow(2, 35);
4788
- var N6 = Math.pow(2, 42);
4789
- var N7 = Math.pow(2, 49);
4790
- var N8 = Math.pow(2, 56);
4791
- var N9 = Math.pow(2, 63);
4792
-
4793
- var length = function (value) {
4794
- return (
4795
- value < N1 ? 1
4796
- : value < N2 ? 2
4797
- : value < N3 ? 3
4798
- : value < N4 ? 4
4799
- : value < N5 ? 5
4800
- : value < N6 ? 6
4801
- : value < N7 ? 7
4802
- : value < N8 ? 8
4803
- : value < N9 ? 9
4804
- : 10
4805
- )
4806
- };
4807
-
4808
- var varint = {
4809
- encode: encode_1
4810
- , decode: decode$1
4811
- , encodingLength: length
4812
- };
4813
-
4814
- var varint$1 = /*@__PURE__*/getDefaultExportFromCjs(varint);
4815
-
4816
- /**
4817
- * Returns a new Uint8Array created by concatenating the passed ArrayLikes
4818
- */
4819
- function concat(arrays, length) {
4820
- if (length == null) {
4821
- length = arrays.reduce((acc, curr) => acc + curr.length, 0);
4822
- }
4823
- const output = allocUnsafe(length);
4824
- let offset = 0;
4825
- for (const arr of arrays) {
4826
- output.set(arr, offset);
4827
- offset += arr.length;
4828
- }
4829
- return asUint8Array(output);
4830
- }
4831
-
4832
5006
  /**
4833
5007
  * @packageDocumentation
4834
5008
  *
@@ -4904,7 +5078,7 @@ function convertToBytes(proto, str) {
4904
5078
  case 466: // certhash
4905
5079
  return mb2bytes(str);
4906
5080
  default:
4907
- return fromString$1(str, 'base16'); // no clue. convert from hex
5081
+ return fromString(str, 'base16'); // no clue. convert from hex
4908
5082
  }
4909
5083
  }
4910
5084
  const decoders = Object.values(bases).map((c) => c.decoder);
@@ -4940,13 +5114,13 @@ function bytes2port(buf) {
4940
5114
  return view.getUint16(buf.byteOffset);
4941
5115
  }
4942
5116
  function str2bytes(str) {
4943
- const buf = fromString$1(str);
4944
- const size = Uint8Array.from(varint$1.encode(buf.length));
5117
+ const buf = fromString(str);
5118
+ const size = Uint8Array.from(encode$4(buf.length));
4945
5119
  return concat([size, buf], size.length + buf.length);
4946
5120
  }
4947
5121
  function bytes2str(buf) {
4948
- const size = varint$1.decode(buf);
4949
- buf = buf.slice(varint$1.decode.bytes);
5122
+ const size = decode$3(buf);
5123
+ buf = buf.slice(encodingLength$1(size));
4950
5124
  if (buf.length !== size) {
4951
5125
  throw new Error('inconsistent lengths');
4952
5126
  }
@@ -4955,23 +5129,23 @@ function bytes2str(buf) {
4955
5129
  function mh2bytes(hash) {
4956
5130
  let mh;
4957
5131
  if (hash[0] === 'Q' || hash[0] === '1') {
4958
- mh = decode$2(base58btc.decode(`z${hash}`)).bytes;
5132
+ mh = decode$4(base58btc$1.decode(`z${hash}`)).bytes;
4959
5133
  }
4960
5134
  else {
4961
5135
  mh = CID.parse(hash).multihash.bytes;
4962
5136
  }
4963
5137
  // the address is a varint prefixed multihash string representation
4964
- const size = Uint8Array.from(varint$1.encode(mh.length));
5138
+ const size = Uint8Array.from(encode$4(mh.length));
4965
5139
  return concat([size, mh], size.length + mh.length);
4966
5140
  }
4967
5141
  function mb2bytes(mbstr) {
4968
5142
  const mb = anybaseDecoder.decode(mbstr);
4969
- const size = Uint8Array.from(varint$1.encode(mb.length));
5143
+ const size = Uint8Array.from(encode$4(mb.length));
4970
5144
  return concat([size, mb], size.length + mb.length);
4971
5145
  }
4972
5146
  function bytes2mb(buf) {
4973
- const size = varint$1.decode(buf);
4974
- const hash = buf.slice(varint$1.decode.bytes);
5147
+ const size = decode$3(buf);
5148
+ const hash = buf.slice(encodingLength$1(size));
4975
5149
  if (hash.length !== size) {
4976
5150
  throw new Error('inconsistent lengths');
4977
5151
  }
@@ -4981,8 +5155,8 @@ function bytes2mb(buf) {
4981
5155
  * Converts bytes to bas58btc string
4982
5156
  */
4983
5157
  function bytes2mh(buf) {
4984
- const size = varint$1.decode(buf);
4985
- const address = buf.slice(varint$1.decode.bytes);
5158
+ const size = decode$3(buf);
5159
+ const address = buf.slice(encodingLength$1(size));
4986
5160
  if (address.length !== size) {
4987
5161
  throw new Error('inconsistent lengths');
4988
5162
  }
@@ -5032,20 +5206,27 @@ function bytes2onion(buf) {
5032
5206
  return `${addr}:${port}`;
5033
5207
  }
5034
5208
 
5035
- /**
5036
- * string -> [[str name, str addr]... ]
5037
- */
5038
- function stringToStringTuples(str) {
5209
+ function stringToMultiaddrParts(str) {
5210
+ str = cleanPath(str);
5039
5211
  const tuples = [];
5040
- const parts = str.split('/').slice(1); // skip first empty elem
5212
+ const stringTuples = [];
5213
+ let path = null;
5214
+ const parts = str.split('/').slice(1);
5041
5215
  if (parts.length === 1 && parts[0] === '') {
5042
- return [];
5216
+ return {
5217
+ bytes: new Uint8Array(),
5218
+ string: '/',
5219
+ tuples: [],
5220
+ stringTuples: [],
5221
+ path: null
5222
+ };
5043
5223
  }
5044
5224
  for (let p = 0; p < parts.length; p++) {
5045
5225
  const part = parts[p];
5046
5226
  const proto = getProtocol(part);
5047
5227
  if (proto.size === 0) {
5048
- tuples.push([part]);
5228
+ tuples.push([proto.code]);
5229
+ stringTuples.push([proto.code]);
5049
5230
  // eslint-disable-next-line no-continue
5050
5231
  continue;
5051
5232
  }
@@ -5055,18 +5236,67 @@ function stringToStringTuples(str) {
5055
5236
  }
5056
5237
  // if it's a path proto, take the rest
5057
5238
  if (proto.path === true) {
5058
- tuples.push([
5059
- part,
5060
- // should we need to check each path part to see if it's a proto?
5061
- // This would allow for other protocols to be added after a unix path,
5062
- // however it would have issues if the path had a protocol name in the path
5063
- cleanPath(parts.slice(p).join('/'))
5064
- ]);
5239
+ // should we need to check each path part to see if it's a proto?
5240
+ // This would allow for other protocols to be added after a unix path,
5241
+ // however it would have issues if the path had a protocol name in the path
5242
+ path = cleanPath(parts.slice(p).join('/'));
5243
+ tuples.push([proto.code, convertToBytes(proto.code, path)]);
5244
+ stringTuples.push([proto.code, path]);
5245
+ break;
5246
+ }
5247
+ const bytes = convertToBytes(proto.code, parts[p]);
5248
+ tuples.push([proto.code, bytes]);
5249
+ stringTuples.push([proto.code, convertToString(proto.code, bytes)]);
5250
+ }
5251
+ return {
5252
+ string: stringTuplesToString(stringTuples),
5253
+ bytes: tuplesToBytes(tuples),
5254
+ tuples,
5255
+ stringTuples,
5256
+ path
5257
+ };
5258
+ }
5259
+ function bytesToMultiaddrParts(bytes) {
5260
+ const tuples = [];
5261
+ const stringTuples = [];
5262
+ let path = null;
5263
+ let i = 0;
5264
+ while (i < bytes.length) {
5265
+ const code = decode$3(bytes, i);
5266
+ const n = encodingLength$1(code);
5267
+ const p = getProtocol(code);
5268
+ const size = sizeForAddr(p, bytes.slice(i + n));
5269
+ if (size === 0) {
5270
+ tuples.push([code]);
5271
+ stringTuples.push([code]);
5272
+ i += n;
5273
+ // eslint-disable-next-line no-continue
5274
+ continue;
5275
+ }
5276
+ const addr = bytes.slice(i + n, i + n + size);
5277
+ i += (size + n);
5278
+ if (i > bytes.length) { // did not end _exactly_ at buffer.length
5279
+ throw ParseError('Invalid address Uint8Array: ' + toString$1(bytes, 'base16'));
5280
+ }
5281
+ // ok, tuple seems good.
5282
+ tuples.push([code, addr]);
5283
+ const stringAddr = convertToString(code, addr);
5284
+ stringTuples.push([code, stringAddr]);
5285
+ if (p.path === true) {
5286
+ // should we need to check each path part to see if it's a proto?
5287
+ // This would allow for other protocols to be added after a unix path,
5288
+ // however it would have issues if the path had a protocol name in the path
5289
+ path = stringAddr;
5065
5290
  break;
5066
5291
  }
5067
- tuples.push([part, parts[p]]);
5068
5292
  }
5069
- return tuples;
5293
+ return {
5294
+ bytes: Uint8Array.from(bytes),
5295
+ string: stringTuplesToString(stringTuples),
5296
+ tuples,
5297
+ stringTuples,
5298
+ path
5299
+ };
5070
5300
  }
5071
5301
  /**
5072
5302
  * [[str name, str addr]... ] -> string
@@ -5074,7 +5304,7 @@ function stringToStringTuples(str) {
5074
5304
  function stringTuplesToString(tuples) {
5075
5305
  const parts = [];
5076
5306
  tuples.map((tup) => {
5077
- const proto = protoFromTuple(tup);
5307
+ const proto = getProtocol(tup[0]);
5078
5308
  parts.push(proto.name);
5079
5309
  if (tup.length > 1 && tup[1] != null) {
5080
5310
  parts.push(tup[1]);
@@ -5083,47 +5313,18 @@ function stringTuplesToString(tuples) {
5083
5313
  });
5084
5314
  return cleanPath(parts.join('/'));
5085
5315
  }
5086
- /**
5087
- * [[str name, str addr]... ] -> [[int code, Uint8Array]... ]
5088
- */
5089
- function stringTuplesToTuples(tuples) {
5090
- return tuples.map((tup) => {
5091
- if (!Array.isArray(tup)) {
5092
- tup = [tup];
5093
- }
5094
- const proto = protoFromTuple(tup);
5095
- if (tup.length > 1) {
5096
- return [proto.code, convertToBytes(proto.code, tup[1])];
5097
- }
5098
- return [proto.code];
5099
- });
5100
- }
5101
- /**
5102
- * Convert tuples to string tuples
5103
- *
5104
- * [[int code, Uint8Array]... ] -> [[int code, str addr]... ]
5105
- */
5106
- function tuplesToStringTuples(tuples) {
5107
- return tuples.map(tup => {
5108
- const proto = protoFromTuple(tup);
5109
- if (tup[1] != null) {
5110
- return [proto.code, convertToString(proto.code, tup[1])];
5111
- }
5112
- return [proto.code];
5113
- });
5114
- }
5115
5316
  /**
5116
5317
  * [[int code, Uint8Array ]... ] -> Uint8Array
5117
5318
  */
5118
5319
  function tuplesToBytes(tuples) {
5119
- return fromBytes(concat(tuples.map((tup) => {
5120
- const proto = protoFromTuple(tup);
5121
- let buf = Uint8Array.from(varint$1.encode(proto.code));
5320
+ return concat(tuples.map((tup) => {
5321
+ const proto = getProtocol(tup[0]);
5322
+ let buf = Uint8Array.from(encode$4(proto.code));
5122
5323
  if (tup.length > 1 && tup[1] != null) {
5123
5324
  buf = concat([buf, tup[1]]); // add address buffer
5124
5325
  }
5125
5326
  return buf;
5126
- })));
5327
+ }));
5127
5328
  }
5128
5329
  /**
5129
5330
  * For the passed address, return the serialized size
@@ -5136,73 +5337,8 @@ function sizeForAddr(p, addr) {
5136
5337
  return 0;
5137
5338
  }
5138
5339
  else {
5139
- const size = varint$1.decode(addr);
5140
- return size + (varint$1.decode.bytes ?? 0);
5141
- }
5142
- }
5143
- function bytesToTuples(buf) {
5144
- const tuples = [];
5145
- let i = 0;
5146
- while (i < buf.length) {
5147
- const code = varint$1.decode(buf, i);
5148
- const n = varint$1.decode.bytes ?? 0;
5149
- const p = getProtocol(code);
5150
- const size = sizeForAddr(p, buf.slice(i + n));
5151
- if (size === 0) {
5152
- tuples.push([code]);
5153
- i += n;
5154
- // eslint-disable-next-line no-continue
5155
- continue;
5156
- }
5157
- const addr = buf.slice(i + n, i + n + size);
5158
- i += (size + n);
5159
- if (i > buf.length) { // did not end _exactly_ at buffer.length
5160
- throw ParseError('Invalid address Uint8Array: ' + toString$1(buf, 'base16'));
5161
- }
5162
- // ok, tuple seems good.
5163
- tuples.push([code, addr]);
5164
- }
5165
- return tuples;
5166
- }
5167
- /**
5168
- * Uint8Array -> String
5169
- */
5170
- function bytesToString(buf) {
5171
- const a = bytesToTuples(buf);
5172
- const b = tuplesToStringTuples(a);
5173
- return stringTuplesToString(b);
5174
- }
5175
- /**
5176
- * String -> Uint8Array
5177
- */
5178
- function stringToBytes(str) {
5179
- str = cleanPath(str);
5180
- const a = stringToStringTuples(str);
5181
- const b = stringTuplesToTuples(a);
5182
- return tuplesToBytes(b);
5183
- }
5184
- /**
5185
- * String -> Uint8Array
5186
- */
5187
- function fromString(str) {
5188
- return stringToBytes(str);
5189
- }
5190
- /**
5191
- * Uint8Array -> Uint8Array
5192
- */
5193
- function fromBytes(buf) {
5194
- const err = validateBytes(buf);
5195
- if (err != null) {
5196
- throw err;
5197
- }
5198
- return Uint8Array.from(buf); // copy
5199
- }
5200
- function validateBytes(buf) {
5201
- try {
5202
- bytesToTuples(buf); // try to parse. will throw if breaks
5203
- }
5204
- catch (err) {
5205
- return err;
5340
+ const size = decode$3(addr instanceof Uint8Array ? addr : Uint8Array.from(addr));
5341
+ return size + encodingLength$1(size);
5206
5342
  }
5207
5343
  }
5208
5344
  function cleanPath(str) {
@@ -5211,44 +5347,6 @@ function cleanPath(str) {
5211
5347
  function ParseError(str) {
5212
5348
  return new Error('Error parsing address: ' + str);
5213
5349
  }
5214
- function protoFromTuple(tup) {
5215
- const proto = getProtocol(tup[0]);
5216
- return proto;
5217
- }
5218
-
5219
- /**
5220
- * When this error is thrown it means an operation was aborted,
5221
- * usually in response to the `abort` event being emitted by an
5222
- * AbortSignal.
5223
- */
5224
- class CodeError extends Error {
5225
- code;
5226
- props;
5227
- constructor(message, code, props) {
5228
- super(message);
5229
- this.code = code;
5230
- this.name = props?.name ?? 'CodeError';
5231
- this.props = props ?? {}; // eslint-disable-line @typescript-eslint/consistent-type-assertions
5232
- }
5233
- }
5234
-
5235
- /**
5236
- * Returns true if the two passed Uint8Arrays have the same content
5237
- */
5238
- function equals(a, b) {
5239
- if (a === b) {
5240
- return true;
5241
- }
5242
- if (a.byteLength !== b.byteLength) {
5243
- return false;
5244
- }
5245
- for (let i = 0; i < a.byteLength; i++) {
5246
- if (a[i] !== b[i]) {
5247
- return false;
5248
- }
5249
- }
5250
- return true;
5251
- }
5252
5350
 
5253
5351
  /**
5254
5352
  * @packageDocumentation
@@ -5263,18 +5361,6 @@ function equals(a, b) {
5263
5361
  * const ma = multiaddr('/ip4/127.0.0.1/tcp/1234')
5264
5362
  * ```
5265
5363
  */
5266
- var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
5267
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
5268
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5269
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5270
- };
5271
- var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
5272
- if (kind === "m") throw new TypeError("Private method is not writable");
5273
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5274
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5275
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
5276
- };
5277
- var _DefaultMultiaddr_string, _DefaultMultiaddr_tuples, _DefaultMultiaddr_stringTuples, _DefaultMultiaddr_path, _a;
5278
5364
  const inspect$1 = Symbol.for('nodejs.util.inspect.custom');
5279
5365
  const DNS_CODES = [
5280
5366
  getProtocol('dns').code,
@@ -5308,37 +5394,41 @@ function isMultiaddr(value) {
5308
5394
  * Creates a {@link Multiaddr} from a {@link MultiaddrInput}
5309
5395
  */
5310
5396
  class DefaultMultiaddr {
5397
+ bytes;
5398
+ #string;
5399
+ #tuples;
5400
+ #stringTuples;
5401
+ #path;
5402
+ [symbol$1] = true;
5311
5403
  constructor(addr) {
5312
- _DefaultMultiaddr_string.set(this, void 0);
5313
- _DefaultMultiaddr_tuples.set(this, void 0);
5314
- _DefaultMultiaddr_stringTuples.set(this, void 0);
5315
- _DefaultMultiaddr_path.set(this, void 0);
5316
- this[_a] = true;
5317
5404
  // default
5318
5405
  if (addr == null) {
5319
5406
  addr = '';
5320
5407
  }
5408
+ let parts;
5321
5409
  if (addr instanceof Uint8Array) {
5322
- this.bytes = fromBytes(addr);
5410
+ parts = bytesToMultiaddrParts(addr);
5323
5411
  }
5324
5412
  else if (typeof addr === 'string') {
5325
5413
  if (addr.length > 0 && addr.charAt(0) !== '/') {
5326
5414
  throw new Error(`multiaddr "${addr}" must start with a "/"`);
5327
5415
  }
5328
- this.bytes = fromString(addr);
5416
+ parts = stringToMultiaddrParts(addr);
5329
5417
  }
5330
5418
  else if (isMultiaddr(addr)) { // Multiaddr
5331
- this.bytes = fromBytes(addr.bytes); // validate + copy buffer
5419
+ parts = bytesToMultiaddrParts(addr.bytes);
5332
5420
  }
5333
5421
  else {
5334
5422
  throw new Error('addr must be a string, Buffer, or another Multiaddr');
5335
5423
  }
5424
+ this.bytes = parts.bytes;
5425
+ this.#string = parts.string;
5426
+ this.#tuples = parts.tuples;
5427
+ this.#stringTuples = parts.stringTuples;
5428
+ this.#path = parts.path;
5336
5429
  }
5337
5430
  toString() {
5338
- if (__classPrivateFieldGet(this, _DefaultMultiaddr_string, "f") == null) {
5339
- __classPrivateFieldSet(this, _DefaultMultiaddr_string, bytesToString(this.bytes), "f");
5340
- }
5341
- return __classPrivateFieldGet(this, _DefaultMultiaddr_string, "f");
5431
+ return this.#string;
5342
5432
  }
5343
5433
  toJSON() {
5344
5434
  return this.toString();
@@ -5388,36 +5478,19 @@ class DefaultMultiaddr {
5388
5478
  return opts;
5389
5479
  }
5390
5480
  protos() {
5391
- return this.protoCodes().map(code => Object.assign({}, getProtocol(code)));
5481
+ return this.#tuples.map(([code]) => Object.assign({}, getProtocol(code)));
5392
5482
  }
5393
5483
  protoCodes() {
5394
- const codes = [];
5395
- const buf = this.bytes;
5396
- let i = 0;
5397
- while (i < buf.length) {
5398
- const code = varint$1.decode(buf, i);
5399
- const n = varint$1.decode.bytes ?? 0;
5400
- const p = getProtocol(code);
5401
- const size = sizeForAddr(p, buf.slice(i + n));
5402
- i += (size + n);
5403
- codes.push(code);
5404
- }
5405
- return codes;
5484
+ return this.#tuples.map(([code]) => code);
5406
5485
  }
5407
5486
  protoNames() {
5408
- return this.protos().map(proto => proto.name);
5487
+ return this.#tuples.map(([code]) => getProtocol(code).name);
5409
5488
  }
5410
5489
  tuples() {
5411
- if (__classPrivateFieldGet(this, _DefaultMultiaddr_tuples, "f") == null) {
5412
- __classPrivateFieldSet(this, _DefaultMultiaddr_tuples, bytesToTuples(this.bytes), "f");
5413
- }
5414
- return __classPrivateFieldGet(this, _DefaultMultiaddr_tuples, "f");
5490
+ return this.#tuples;
5415
5491
  }
5416
5492
  stringTuples() {
5417
- if (__classPrivateFieldGet(this, _DefaultMultiaddr_stringTuples, "f") == null) {
5418
- __classPrivateFieldSet(this, _DefaultMultiaddr_stringTuples, tuplesToStringTuples(this.tuples()), "f");
5419
- }
5420
- return __classPrivateFieldGet(this, _DefaultMultiaddr_stringTuples, "f");
5493
+ return this.#stringTuples;
5421
5494
  }
5422
5495
  encapsulate(addr) {
5423
5496
  addr = new DefaultMultiaddr(addr);
@@ -5443,20 +5516,25 @@ class DefaultMultiaddr {
5443
5516
  }
5444
5517
  getPeerId() {
5445
5518
  try {
5446
- const tuples = this.stringTuples().filter((tuple) => {
5447
- if (tuple[0] === names.ipfs.code) {
5448
- return true;
5519
+ let tuples = [];
5520
+ this.stringTuples().forEach(([code, name]) => {
5521
+ if (code === names.p2p.code) {
5522
+ tuples.push([code, name]);
5523
+ }
5524
+ // if this is a p2p-circuit address, return the target peer id if present
5525
+ // not the peer id of the relay
5526
+ if (code === names['p2p-circuit'].code) {
5527
+ tuples = [];
5449
5528
  }
5450
- return false;
5451
5529
  });
5452
- // Get the last ipfs tuple ['ipfs', 'peerid string']
5530
+ // Get the last ipfs tuple ['p2p', 'peerid string']
5453
5531
  const tuple = tuples.pop();
5454
5532
  if (tuple?.[1] != null) {
5455
5533
  const peerIdStr = tuple[1];
5456
5534
  // peer id is base58btc encoded string but not multibase encoded so add the `z`
5457
5535
  // prefix so we can validate that it is correctly encoded
5458
5536
  if (peerIdStr[0] === 'Q' || peerIdStr[0] === '1') {
5459
- return toString$1(base58btc.decode(`z${peerIdStr}`), 'base58btc');
5537
+ return toString$1(base58btc$1.decode(`z${peerIdStr}`), 'base58btc');
5460
5538
  }
5461
5539
  // try to parse peer id as CID
5462
5540
  return toString$1(CID.parse(peerIdStr).multihash.bytes, 'base58btc');
@@ -5468,26 +5546,7 @@ class DefaultMultiaddr {
5468
5546
  }
5469
5547
  }
5470
5548
  getPath() {
5471
- // on initialization, this.#path is undefined
5472
- // after the first call, it is either a string or null
5473
- if (__classPrivateFieldGet(this, _DefaultMultiaddr_path, "f") === undefined) {
5474
- try {
5475
- __classPrivateFieldSet(this, _DefaultMultiaddr_path, this.stringTuples().filter((tuple) => {
5476
- const proto = getProtocol(tuple[0]);
5477
- if (proto.path === true) {
5478
- return true;
5479
- }
5480
- return false;
5481
- })[0][1], "f");
5482
- if (__classPrivateFieldGet(this, _DefaultMultiaddr_path, "f") == null) {
5483
- __classPrivateFieldSet(this, _DefaultMultiaddr_path, null, "f");
5484
- }
5485
- }
5486
- catch {
5487
- __classPrivateFieldSet(this, _DefaultMultiaddr_path, null, "f");
5488
- }
5489
- }
5490
- return __classPrivateFieldGet(this, _DefaultMultiaddr_path, "f");
5549
+ return this.#path;
5491
5550
  }
5492
5551
  equals(addr) {
5493
5552
  return equals(this.bytes, addr.bytes);
@@ -5500,7 +5559,7 @@ class DefaultMultiaddr {
5500
5559
  }
5501
5560
  const resolver = resolvers.get(resolvableProto.name);
5502
5561
  if (resolver == null) {
5503
- throw new CodeError(`no available resolver for ${resolvableProto.name}`, 'ERR_NO_AVAILABLE_RESOLVER');
5562
+ throw new CodeError$1(`no available resolver for ${resolvableProto.name}`, 'ERR_NO_AVAILABLE_RESOLVER');
5504
5563
  }
5505
5564
  const addresses = await resolver(this, options);
5506
5565
  return addresses.map((a) => new DefaultMultiaddr(a));
@@ -5541,8 +5600,8 @@ class DefaultMultiaddr {
5541
5600
  * // 'Multiaddr(/ip4/127.0.0.1/tcp/4001)'
5542
5601
  * ```
5543
5602
  */
5544
- [(_DefaultMultiaddr_string = new WeakMap(), _DefaultMultiaddr_tuples = new WeakMap(), _DefaultMultiaddr_stringTuples = new WeakMap(), _DefaultMultiaddr_path = new WeakMap(), _a = symbol$1, inspect$1)]() {
5545
- return `Multiaddr(${bytesToString(this.bytes)})`;
5603
+ [inspect$1]() {
5604
+ return `Multiaddr(${this.#string})`;
5546
5605
  }
5547
5606
  }
5548
5607
  /**
@@ -13525,15 +13584,15 @@ var forge$a = forge$m;
13525
13584
 
13526
13585
 
13527
13586
 
13528
- var sha256 = forge$a.sha256 = forge$a.sha256 || {};
13529
- forge$a.md.sha256 = forge$a.md.algorithms.sha256 = sha256;
13587
+ var sha256$1 = forge$a.sha256 = forge$a.sha256 || {};
13588
+ forge$a.md.sha256 = forge$a.md.algorithms.sha256 = sha256$1;
13530
13589
 
13531
13590
  /**
13532
13591
  * Creates a SHA-256 message digest object.
13533
13592
  *
13534
13593
  * @return a message digest object.
13535
13594
  */
13536
- sha256.create = function() {
13595
+ sha256$1.create = function() {
13537
13596
  // do initialization as necessary
13538
13597
  if(!_initialized$2) {
13539
13598
  _init$2();
@@ -19952,9 +20011,768 @@ function createPbkdf2Params(salt, countBytes, dkLen, prfAlgorithm) {
19952
20011
  asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
19953
20012
  ]));
19954
20013
  }
19955
- return params;
20014
+ return params;
20015
+ }
20016
+
20017
+ /**
20018
+ * When this error is thrown it means an operation was aborted,
20019
+ * usually in response to the `abort` event being emitted by an
20020
+ * AbortSignal.
20021
+ */
20022
+ class CodeError extends Error {
20023
+ code;
20024
+ props;
20025
+ constructor(message, code, props) {
20026
+ super(message);
20027
+ this.code = code;
20028
+ this.name = props?.name ?? 'CodeError';
20029
+ this.props = props ?? {}; // eslint-disable-line @typescript-eslint/consistent-type-assertions
20030
+ }
20031
+ }
20032
+
20033
+ // base-x encoding / decoding
20034
+ // Copyright (c) 2018 base-x contributors
20035
+ // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
20036
+ // Distributed under the MIT software license, see the accompanying
20037
+ // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
20038
+ function base (ALPHABET, name) {
20039
+ if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
20040
+ var BASE_MAP = new Uint8Array(256);
20041
+ for (var j = 0; j < BASE_MAP.length; j++) {
20042
+ BASE_MAP[j] = 255;
20043
+ }
20044
+ for (var i = 0; i < ALPHABET.length; i++) {
20045
+ var x = ALPHABET.charAt(i);
20046
+ var xc = x.charCodeAt(0);
20047
+ if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
20048
+ BASE_MAP[xc] = i;
20049
+ }
20050
+ var BASE = ALPHABET.length;
20051
+ var LEADER = ALPHABET.charAt(0);
20052
+ var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
20053
+ var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
20054
+ function encode (source) {
20055
+ if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
20056
+ source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
20057
+ } else if (Array.isArray(source)) {
20058
+ source = Uint8Array.from(source);
20059
+ }
20060
+ if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
20061
+ if (source.length === 0) { return '' }
20062
+ // Skip & count leading zeroes.
20063
+ var zeroes = 0;
20064
+ var length = 0;
20065
+ var pbegin = 0;
20066
+ var pend = source.length;
20067
+ while (pbegin !== pend && source[pbegin] === 0) {
20068
+ pbegin++;
20069
+ zeroes++;
20070
+ }
20071
+ // Allocate enough space in big-endian base58 representation.
20072
+ var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
20073
+ var b58 = new Uint8Array(size);
20074
+ // Process the bytes.
20075
+ while (pbegin !== pend) {
20076
+ var carry = source[pbegin];
20077
+ // Apply "b58 = b58 * 256 + ch".
20078
+ var i = 0;
20079
+ for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
20080
+ carry += (256 * b58[it1]) >>> 0;
20081
+ b58[it1] = (carry % BASE) >>> 0;
20082
+ carry = (carry / BASE) >>> 0;
20083
+ }
20084
+ if (carry !== 0) { throw new Error('Non-zero carry') }
20085
+ length = i;
20086
+ pbegin++;
20087
+ }
20088
+ // Skip leading zeroes in base58 result.
20089
+ var it2 = size - length;
20090
+ while (it2 !== size && b58[it2] === 0) {
20091
+ it2++;
20092
+ }
20093
+ // Translate the result into a string.
20094
+ var str = LEADER.repeat(zeroes);
20095
+ for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
20096
+ return str
20097
+ }
20098
+ function decodeUnsafe (source) {
20099
+ if (typeof source !== 'string') { throw new TypeError('Expected String') }
20100
+ if (source.length === 0) { return new Uint8Array() }
20101
+ var psz = 0;
20102
+ // Skip leading spaces.
20103
+ if (source[psz] === ' ') { return }
20104
+ // Skip and count leading '1's.
20105
+ var zeroes = 0;
20106
+ var length = 0;
20107
+ while (source[psz] === LEADER) {
20108
+ zeroes++;
20109
+ psz++;
20110
+ }
20111
+ // Allocate enough space in big-endian base256 representation.
20112
+ var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
20113
+ var b256 = new Uint8Array(size);
20114
+ // Process the characters.
20115
+ while (source[psz]) {
20116
+ // Decode character
20117
+ var carry = BASE_MAP[source.charCodeAt(psz)];
20118
+ // Invalid character
20119
+ if (carry === 255) { return }
20120
+ var i = 0;
20121
+ for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
20122
+ carry += (BASE * b256[it3]) >>> 0;
20123
+ b256[it3] = (carry % 256) >>> 0;
20124
+ carry = (carry / 256) >>> 0;
20125
+ }
20126
+ if (carry !== 0) { throw new Error('Non-zero carry') }
20127
+ length = i;
20128
+ psz++;
20129
+ }
20130
+ // Skip trailing spaces.
20131
+ if (source[psz] === ' ') { return }
20132
+ // Skip leading zeroes in b256.
20133
+ var it4 = size - length;
20134
+ while (it4 !== size && b256[it4] === 0) {
20135
+ it4++;
20136
+ }
20137
+ var vch = new Uint8Array(zeroes + (size - it4));
20138
+ var j = zeroes;
20139
+ while (it4 !== size) {
20140
+ vch[j++] = b256[it4++];
20141
+ }
20142
+ return vch
20143
+ }
20144
+ function decode (string) {
20145
+ var buffer = decodeUnsafe(string);
20146
+ if (buffer) { return buffer }
20147
+ throw new Error(`Non-${name} character`)
20148
+ }
20149
+ return {
20150
+ encode: encode,
20151
+ decodeUnsafe: decodeUnsafe,
20152
+ decode: decode
20153
+ }
20154
+ }
20155
+ var src = base;
20156
+
20157
+ var _brrp__multiformats_scope_baseX = src;
20158
+
20159
+ /**
20160
+ * @param {ArrayBufferView|ArrayBuffer|Uint8Array} o
20161
+ * @returns {Uint8Array}
20162
+ */
20163
+ const coerce = o => {
20164
+ if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array') return o
20165
+ if (o instanceof ArrayBuffer) return new Uint8Array(o)
20166
+ if (ArrayBuffer.isView(o)) {
20167
+ return new Uint8Array(o.buffer, o.byteOffset, o.byteLength)
20168
+ }
20169
+ throw new Error('Unknown type, must be binary type')
20170
+ };
20171
+
20172
+ /**
20173
+ * Class represents both BaseEncoder and MultibaseEncoder meaning it
20174
+ * can be used to encode to multibase or base encode without multibase
20175
+ * prefix.
20176
+ *
20177
+ * @class
20178
+ * @template {string} Base
20179
+ * @template {string} Prefix
20180
+ * @implements {API.MultibaseEncoder<Prefix>}
20181
+ * @implements {API.BaseEncoder}
20182
+ */
20183
+ class Encoder {
20184
+ /**
20185
+ * @param {Base} name
20186
+ * @param {Prefix} prefix
20187
+ * @param {(bytes:Uint8Array) => string} baseEncode
20188
+ */
20189
+ constructor (name, prefix, baseEncode) {
20190
+ this.name = name;
20191
+ this.prefix = prefix;
20192
+ this.baseEncode = baseEncode;
20193
+ }
20194
+
20195
+ /**
20196
+ * @param {Uint8Array} bytes
20197
+ * @returns {API.Multibase<Prefix>}
20198
+ */
20199
+ encode (bytes) {
20200
+ if (bytes instanceof Uint8Array) {
20201
+ return `${this.prefix}${this.baseEncode(bytes)}`
20202
+ } else {
20203
+ throw Error('Unknown type, must be binary type')
20204
+ }
20205
+ }
20206
+ }
20207
+
20208
+ /**
20209
+ * @template {string} Prefix
20210
+ */
20211
+ /**
20212
+ * Class represents both BaseDecoder and MultibaseDecoder so it could be used
20213
+ * to decode multibases (with matching prefix) or just base decode strings
20214
+ * with corresponding base encoding.
20215
+ *
20216
+ * @class
20217
+ * @template {string} Base
20218
+ * @template {string} Prefix
20219
+ * @implements {API.MultibaseDecoder<Prefix>}
20220
+ * @implements {API.UnibaseDecoder<Prefix>}
20221
+ * @implements {API.BaseDecoder}
20222
+ */
20223
+ class Decoder {
20224
+ /**
20225
+ * @param {Base} name
20226
+ * @param {Prefix} prefix
20227
+ * @param {(text:string) => Uint8Array} baseDecode
20228
+ */
20229
+ constructor (name, prefix, baseDecode) {
20230
+ this.name = name;
20231
+ this.prefix = prefix;
20232
+ /* c8 ignore next 3 */
20233
+ if (prefix.codePointAt(0) === undefined) {
20234
+ throw new Error('Invalid prefix character')
20235
+ }
20236
+ /** @private */
20237
+ this.prefixCodePoint = /** @type {number} */ (prefix.codePointAt(0));
20238
+ this.baseDecode = baseDecode;
20239
+ }
20240
+
20241
+ /**
20242
+ * @param {string} text
20243
+ */
20244
+ decode (text) {
20245
+ if (typeof text === 'string') {
20246
+ if (text.codePointAt(0) !== this.prefixCodePoint) {
20247
+ throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`)
20248
+ }
20249
+ return this.baseDecode(text.slice(this.prefix.length))
20250
+ } else {
20251
+ throw Error('Can only multibase decode strings')
20252
+ }
20253
+ }
20254
+
20255
+ /**
20256
+ * @template {string} OtherPrefix
20257
+ * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
20258
+ * @returns {ComposedDecoder<Prefix|OtherPrefix>}
20259
+ */
20260
+ or (decoder) {
20261
+ return or(this, decoder)
20262
+ }
20263
+ }
20264
+
20265
+ /**
20266
+ * @template {string} Prefix
20267
+ * @typedef {Record<Prefix, API.UnibaseDecoder<Prefix>>} Decoders
20268
+ */
20269
+
20270
+ /**
20271
+ * @template {string} Prefix
20272
+ * @implements {API.MultibaseDecoder<Prefix>}
20273
+ * @implements {API.CombobaseDecoder<Prefix>}
20274
+ */
20275
+ class ComposedDecoder {
20276
+ /**
20277
+ * @param {Decoders<Prefix>} decoders
20278
+ */
20279
+ constructor (decoders) {
20280
+ this.decoders = decoders;
20281
+ }
20282
+
20283
+ /**
20284
+ * @template {string} OtherPrefix
20285
+ * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
20286
+ * @returns {ComposedDecoder<Prefix|OtherPrefix>}
20287
+ */
20288
+ or (decoder) {
20289
+ return or(this, decoder)
20290
+ }
20291
+
20292
+ /**
20293
+ * @param {string} input
20294
+ * @returns {Uint8Array}
20295
+ */
20296
+ decode (input) {
20297
+ const prefix = /** @type {Prefix} */ (input[0]);
20298
+ const decoder = this.decoders[prefix];
20299
+ if (decoder) {
20300
+ return decoder.decode(input)
20301
+ } else {
20302
+ throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)
20303
+ }
20304
+ }
20305
+ }
20306
+
20307
+ /**
20308
+ * @template {string} L
20309
+ * @template {string} R
20310
+ * @param {API.UnibaseDecoder<L>|API.CombobaseDecoder<L>} left
20311
+ * @param {API.UnibaseDecoder<R>|API.CombobaseDecoder<R>} right
20312
+ * @returns {ComposedDecoder<L|R>}
20313
+ */
20314
+ const or = (left, right) => new ComposedDecoder(/** @type {Decoders<L|R>} */({
20315
+ ...(left.decoders || { [/** @type API.UnibaseDecoder<L> */(left).prefix]: left }),
20316
+ ...(right.decoders || { [/** @type API.UnibaseDecoder<R> */(right).prefix]: right })
20317
+ }));
20318
+
20319
+ /**
20320
+ * @class
20321
+ * @template {string} Base
20322
+ * @template {string} Prefix
20323
+ * @implements {API.MultibaseCodec<Prefix>}
20324
+ * @implements {API.MultibaseEncoder<Prefix>}
20325
+ * @implements {API.MultibaseDecoder<Prefix>}
20326
+ * @implements {API.BaseCodec}
20327
+ * @implements {API.BaseEncoder}
20328
+ * @implements {API.BaseDecoder}
20329
+ */
20330
+ class Codec {
20331
+ /**
20332
+ * @param {Base} name
20333
+ * @param {Prefix} prefix
20334
+ * @param {(bytes:Uint8Array) => string} baseEncode
20335
+ * @param {(text:string) => Uint8Array} baseDecode
20336
+ */
20337
+ constructor (name, prefix, baseEncode, baseDecode) {
20338
+ this.name = name;
20339
+ this.prefix = prefix;
20340
+ this.baseEncode = baseEncode;
20341
+ this.baseDecode = baseDecode;
20342
+ this.encoder = new Encoder(name, prefix, baseEncode);
20343
+ this.decoder = new Decoder(name, prefix, baseDecode);
20344
+ }
20345
+
20346
+ /**
20347
+ * @param {Uint8Array} input
20348
+ */
20349
+ encode (input) {
20350
+ return this.encoder.encode(input)
20351
+ }
20352
+
20353
+ /**
20354
+ * @param {string} input
20355
+ */
20356
+ decode (input) {
20357
+ return this.decoder.decode(input)
20358
+ }
20359
+ }
20360
+
20361
+ /**
20362
+ * @template {string} Base
20363
+ * @template {string} Prefix
20364
+ * @param {object} options
20365
+ * @param {Base} options.name
20366
+ * @param {Prefix} options.prefix
20367
+ * @param {(bytes:Uint8Array) => string} options.encode
20368
+ * @param {(input:string) => Uint8Array} options.decode
20369
+ * @returns {Codec<Base, Prefix>}
20370
+ */
20371
+ const from$1 = ({ name, prefix, encode, decode }) =>
20372
+ new Codec(name, prefix, encode, decode);
20373
+
20374
+ /**
20375
+ * @template {string} Base
20376
+ * @template {string} Prefix
20377
+ * @param {object} options
20378
+ * @param {Base} options.name
20379
+ * @param {Prefix} options.prefix
20380
+ * @param {string} options.alphabet
20381
+ * @returns {Codec<Base, Prefix>}
20382
+ */
20383
+ const baseX = ({ prefix, name, alphabet }) => {
20384
+ const { encode, decode } = _brrp__multiformats_scope_baseX(alphabet, name);
20385
+ return from$1({
20386
+ prefix,
20387
+ name,
20388
+ encode,
20389
+ /**
20390
+ * @param {string} text
20391
+ */
20392
+ decode: text => coerce(decode(text))
20393
+ })
20394
+ };
20395
+
20396
+ /**
20397
+ * @param {string} string
20398
+ * @param {string} alphabet
20399
+ * @param {number} bitsPerChar
20400
+ * @param {string} name
20401
+ * @returns {Uint8Array}
20402
+ */
20403
+ const decode$2 = (string, alphabet, bitsPerChar, name) => {
20404
+ // Build the character lookup table:
20405
+ /** @type {Record<string, number>} */
20406
+ const codes = {};
20407
+ for (let i = 0; i < alphabet.length; ++i) {
20408
+ codes[alphabet[i]] = i;
20409
+ }
20410
+
20411
+ // Count the padding bytes:
20412
+ let end = string.length;
20413
+ while (string[end - 1] === '=') {
20414
+ --end;
20415
+ }
20416
+
20417
+ // Allocate the output:
20418
+ const out = new Uint8Array((end * bitsPerChar / 8) | 0);
20419
+
20420
+ // Parse the data:
20421
+ let bits = 0; // Number of bits currently in the buffer
20422
+ let buffer = 0; // Bits waiting to be written out, MSB first
20423
+ let written = 0; // Next byte to write
20424
+ for (let i = 0; i < end; ++i) {
20425
+ // Read one character from the string:
20426
+ const value = codes[string[i]];
20427
+ if (value === undefined) {
20428
+ throw new SyntaxError(`Non-${name} character`)
20429
+ }
20430
+
20431
+ // Append the bits to the buffer:
20432
+ buffer = (buffer << bitsPerChar) | value;
20433
+ bits += bitsPerChar;
20434
+
20435
+ // Write out some bits if the buffer has a byte's worth:
20436
+ if (bits >= 8) {
20437
+ bits -= 8;
20438
+ out[written++] = 0xff & (buffer >> bits);
20439
+ }
20440
+ }
20441
+
20442
+ // Verify that we have received just enough bits:
20443
+ if (bits >= bitsPerChar || 0xff & (buffer << (8 - bits))) {
20444
+ throw new SyntaxError('Unexpected end of data')
20445
+ }
20446
+
20447
+ return out
20448
+ };
20449
+
20450
+ /**
20451
+ * @param {Uint8Array} data
20452
+ * @param {string} alphabet
20453
+ * @param {number} bitsPerChar
20454
+ * @returns {string}
20455
+ */
20456
+ const encode$3 = (data, alphabet, bitsPerChar) => {
20457
+ const pad = alphabet[alphabet.length - 1] === '=';
20458
+ const mask = (1 << bitsPerChar) - 1;
20459
+ let out = '';
20460
+
20461
+ let bits = 0; // Number of bits currently in the buffer
20462
+ let buffer = 0; // Bits waiting to be written out, MSB first
20463
+ for (let i = 0; i < data.length; ++i) {
20464
+ // Slurp data into the buffer:
20465
+ buffer = (buffer << 8) | data[i];
20466
+ bits += 8;
20467
+
20468
+ // Write out as much as we can:
20469
+ while (bits > bitsPerChar) {
20470
+ bits -= bitsPerChar;
20471
+ out += alphabet[mask & (buffer >> bits)];
20472
+ }
20473
+ }
20474
+
20475
+ // Partial character:
20476
+ if (bits) {
20477
+ out += alphabet[mask & (buffer << (bitsPerChar - bits))];
20478
+ }
20479
+
20480
+ // Add padding characters until we hit a byte boundary:
20481
+ if (pad) {
20482
+ while ((out.length * bitsPerChar) & 7) {
20483
+ out += '=';
20484
+ }
20485
+ }
20486
+
20487
+ return out
20488
+ };
20489
+
20490
+ /**
20491
+ * RFC4648 Factory
20492
+ *
20493
+ * @template {string} Base
20494
+ * @template {string} Prefix
20495
+ * @param {object} options
20496
+ * @param {Base} options.name
20497
+ * @param {Prefix} options.prefix
20498
+ * @param {string} options.alphabet
20499
+ * @param {number} options.bitsPerChar
20500
+ */
20501
+ const rfc4648 = ({ name, prefix, bitsPerChar, alphabet }) => {
20502
+ return from$1({
20503
+ prefix,
20504
+ name,
20505
+ encode (input) {
20506
+ return encode$3(input, alphabet, bitsPerChar)
20507
+ },
20508
+ decode (input) {
20509
+ return decode$2(input, alphabet, bitsPerChar, name)
20510
+ }
20511
+ })
20512
+ };
20513
+
20514
+ const base58btc = baseX({
20515
+ name: 'base58btc',
20516
+ prefix: 'z',
20517
+ alphabet: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
20518
+ });
20519
+
20520
+ baseX({
20521
+ name: 'base58flickr',
20522
+ prefix: 'Z',
20523
+ alphabet: '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
20524
+ });
20525
+
20526
+ var encode_1 = encode$2;
20527
+
20528
+ var MSB = 0x80
20529
+ , REST = 0x7F
20530
+ , MSBALL = ~REST
20531
+ , INT = Math.pow(2, 31);
20532
+
20533
+ function encode$2(num, out, offset) {
20534
+ out = out || [];
20535
+ offset = offset || 0;
20536
+ var oldOffset = offset;
20537
+
20538
+ while(num >= INT) {
20539
+ out[offset++] = (num & 0xFF) | MSB;
20540
+ num /= 128;
20541
+ }
20542
+ while(num & MSBALL) {
20543
+ out[offset++] = (num & 0xFF) | MSB;
20544
+ num >>>= 7;
20545
+ }
20546
+ out[offset] = num | 0;
20547
+
20548
+ encode$2.bytes = offset - oldOffset + 1;
20549
+
20550
+ return out
20551
+ }
20552
+
20553
+ var decode$1 = read;
20554
+
20555
+ var MSB$1 = 0x80
20556
+ , REST$1 = 0x7F;
20557
+
20558
+ function read(buf, offset) {
20559
+ var res = 0
20560
+ , offset = offset || 0
20561
+ , shift = 0
20562
+ , counter = offset
20563
+ , b
20564
+ , l = buf.length;
20565
+
20566
+ do {
20567
+ if (counter >= l) {
20568
+ read.bytes = 0;
20569
+ throw new RangeError('Could not decode varint')
20570
+ }
20571
+ b = buf[counter++];
20572
+ res += shift < 28
20573
+ ? (b & REST$1) << shift
20574
+ : (b & REST$1) * Math.pow(2, shift);
20575
+ shift += 7;
20576
+ } while (b >= MSB$1)
20577
+
20578
+ read.bytes = counter - offset;
20579
+
20580
+ return res
20581
+ }
20582
+
20583
+ var N1 = Math.pow(2, 7);
20584
+ var N2 = Math.pow(2, 14);
20585
+ var N3 = Math.pow(2, 21);
20586
+ var N4 = Math.pow(2, 28);
20587
+ var N5 = Math.pow(2, 35);
20588
+ var N6 = Math.pow(2, 42);
20589
+ var N7 = Math.pow(2, 49);
20590
+ var N8 = Math.pow(2, 56);
20591
+ var N9 = Math.pow(2, 63);
20592
+
20593
+ var length = function (value) {
20594
+ return (
20595
+ value < N1 ? 1
20596
+ : value < N2 ? 2
20597
+ : value < N3 ? 3
20598
+ : value < N4 ? 4
20599
+ : value < N5 ? 5
20600
+ : value < N6 ? 6
20601
+ : value < N7 ? 7
20602
+ : value < N8 ? 8
20603
+ : value < N9 ? 9
20604
+ : 10
20605
+ )
20606
+ };
20607
+
20608
+ var varint = {
20609
+ encode: encode_1
20610
+ , decode: decode$1
20611
+ , encodingLength: length
20612
+ };
20613
+
20614
+ var _brrp_varint = varint;
20615
+
20616
+ /**
20617
+ * @param {number} int
20618
+ * @param {Uint8Array} target
20619
+ * @param {number} [offset=0]
20620
+ */
20621
+ const encodeTo = (int, target, offset = 0) => {
20622
+ _brrp_varint.encode(int, target, offset);
20623
+ return target
20624
+ };
20625
+
20626
+ /**
20627
+ * @param {number} int
20628
+ * @returns {number}
20629
+ */
20630
+ const encodingLength = (int) => {
20631
+ return _brrp_varint.encodingLength(int)
20632
+ };
20633
+
20634
+ /**
20635
+ * Creates a multihash digest.
20636
+ *
20637
+ * @template {number} Code
20638
+ * @param {Code} code
20639
+ * @param {Uint8Array} digest
20640
+ */
20641
+ const create$3 = (code, digest) => {
20642
+ const size = digest.byteLength;
20643
+ const sizeOffset = encodingLength(code);
20644
+ const digestOffset = sizeOffset + encodingLength(size);
20645
+
20646
+ const bytes = new Uint8Array(digestOffset + size);
20647
+ encodeTo(code, bytes, 0);
20648
+ encodeTo(size, bytes, sizeOffset);
20649
+ bytes.set(digest, digestOffset);
20650
+
20651
+ return new Digest(code, size, digest, bytes)
20652
+ };
20653
+
20654
+ /**
20655
+ * @typedef {import('./interface.js').MultihashDigest} MultihashDigest
20656
+ */
20657
+
20658
+ /**
20659
+ * Represents a multihash digest which carries information about the
20660
+ * hashing algorithm and an actual hash digest.
20661
+ *
20662
+ * @template {number} Code
20663
+ * @template {number} Size
20664
+ * @class
20665
+ * @implements {MultihashDigest}
20666
+ */
20667
+ class Digest {
20668
+ /**
20669
+ * Creates a multihash digest.
20670
+ *
20671
+ * @param {Code} code
20672
+ * @param {Size} size
20673
+ * @param {Uint8Array} digest
20674
+ * @param {Uint8Array} bytes
20675
+ */
20676
+ constructor (code, size, digest, bytes) {
20677
+ this.code = code;
20678
+ this.size = size;
20679
+ this.digest = digest;
20680
+ this.bytes = bytes;
20681
+ }
20682
+ }
20683
+
20684
+ const code = 0x0;
20685
+ const name = 'identity';
20686
+
20687
+ /** @type {(input:Uint8Array) => Uint8Array} */
20688
+ const encode$1 = coerce;
20689
+
20690
+ /**
20691
+ * @param {Uint8Array} input
20692
+ * @returns {Digest.Digest<typeof code, number>}
20693
+ */
20694
+ const digest = (input) => create$3(code, encode$1(input));
20695
+
20696
+ const identity = { code, name, encode: encode$1, digest };
20697
+
20698
+ /**
20699
+ * @template {string} Name
20700
+ * @template {number} Code
20701
+ * @param {object} options
20702
+ * @param {Name} options.name
20703
+ * @param {Code} options.code
20704
+ * @param {(input: Uint8Array) => Await<Uint8Array>} options.encode
20705
+ */
20706
+ const from = ({ name, code, encode }) => new Hasher(name, code, encode);
20707
+
20708
+ /**
20709
+ * Hasher represents a hashing algorithm implementation that produces as
20710
+ * `MultihashDigest`.
20711
+ *
20712
+ * @template {string} Name
20713
+ * @template {number} Code
20714
+ * @class
20715
+ * @implements {MultihashHasher<Code>}
20716
+ */
20717
+ class Hasher {
20718
+ /**
20719
+ *
20720
+ * @param {Name} name
20721
+ * @param {Code} code
20722
+ * @param {(input: Uint8Array) => Await<Uint8Array>} encode
20723
+ */
20724
+ constructor (name, code, encode) {
20725
+ this.name = name;
20726
+ this.code = code;
20727
+ this.encode = encode;
20728
+ }
20729
+
20730
+ /**
20731
+ * @param {Uint8Array} input
20732
+ * @returns {Await<Digest.Digest<Code, number>>}
20733
+ */
20734
+ digest (input) {
20735
+ if (input instanceof Uint8Array) {
20736
+ const result = this.encode(input);
20737
+ return result instanceof Uint8Array
20738
+ ? create$3(this.code, result)
20739
+ /* c8 ignore next 1 */
20740
+ : result.then(digest => create$3(this.code, digest))
20741
+ } else {
20742
+ throw Error('Unknown type, must be binary type')
20743
+ /* c8 ignore next 1 */
20744
+ }
20745
+ }
19956
20746
  }
19957
20747
 
20748
+ /**
20749
+ * @template {number} Alg
20750
+ * @typedef {import('./interface.js').MultihashHasher} MultihashHasher
20751
+ */
20752
+
20753
+ /**
20754
+ * @template T
20755
+ * @typedef {Promise<T>|T} Await
20756
+ */
20757
+
20758
+ /* global crypto */
20759
+
20760
+
20761
+ /**
20762
+ * @param {AlgorithmIdentifier} name
20763
+ */
20764
+ const sha = name =>
20765
+ /**
20766
+ * @param {Uint8Array} data
20767
+ */
20768
+ async data => new Uint8Array(await crypto.subtle.digest(name, data));
20769
+
20770
+ const sha256 = from({
20771
+ name: 'sha2-256',
20772
+ code: 0x12,
20773
+ encode: sha('SHA-256')
20774
+ });
20775
+
19958
20776
  /*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
19959
20777
  const _0n = BigInt(0);
19960
20778
  const _1n = BigInt(1);
@@ -20775,6 +21593,37 @@ function concatKeys(privateKeyRaw, publicKey) {
20775
21593
  return privateKey;
20776
21594
  }
20777
21595
 
21596
+ // @ts-check
21597
+
21598
+
21599
+ const base64$2 = rfc4648({
21600
+ prefix: 'm',
21601
+ name: 'base64',
21602
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
21603
+ bitsPerChar: 6
21604
+ });
21605
+
21606
+ rfc4648({
21607
+ prefix: 'M',
21608
+ name: 'base64pad',
21609
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
21610
+ bitsPerChar: 6
21611
+ });
21612
+
21613
+ rfc4648({
21614
+ prefix: 'u',
21615
+ name: 'base64url',
21616
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
21617
+ bitsPerChar: 6
21618
+ });
21619
+
21620
+ rfc4648({
21621
+ prefix: 'U',
21622
+ name: 'base64urlpad',
21623
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=',
21624
+ bitsPerChar: 6
21625
+ });
21626
+
20778
21627
  /* eslint-env browser */
20779
21628
  // Check native crypto exists and is enabled (In insecure context `self.crypto`
20780
21629
  // exists but `self.crypto.subtle` does not).
@@ -20822,7 +21671,7 @@ function create$2(opts) {
20822
21671
  const nonce = crypto.getRandomValues(new Uint8Array(nonceLength));
20823
21672
  const aesGcm = { name: algorithm, iv: nonce };
20824
21673
  if (typeof password === 'string') {
20825
- password = fromString$1(password);
21674
+ password = fromString(password);
20826
21675
  }
20827
21676
  let cryptoKey;
20828
21677
  if (password.length === 0) {
@@ -20858,7 +21707,7 @@ function create$2(opts) {
20858
21707
  const ciphertext = data.subarray(saltLength + nonceLength);
20859
21708
  const aesGcm = { name: algorithm, iv: nonce };
20860
21709
  if (typeof password === 'string') {
20861
- password = fromString$1(password);
21710
+ password = fromString(password);
20862
21711
  }
20863
21712
  let cryptoKey;
20864
21713
  if (password.length === 0) {
@@ -21096,588 +21945,628 @@ var base64$1 = {};
21096
21945
  };
21097
21946
  } (base64$1));
21098
21947
 
21099
- var eventemitter = EventEmitter;
21948
+ var eventemitter;
21949
+ var hasRequiredEventemitter;
21950
+
21951
+ function requireEventemitter () {
21952
+ if (hasRequiredEventemitter) return eventemitter;
21953
+ hasRequiredEventemitter = 1;
21954
+ eventemitter = EventEmitter;
21100
21955
 
21101
- /**
21102
- * Constructs a new event emitter instance.
21103
- * @classdesc A minimal event emitter.
21104
- * @memberof util
21105
- * @constructor
21106
- */
21107
- function EventEmitter() {
21956
+ /**
21957
+ * Constructs a new event emitter instance.
21958
+ * @classdesc A minimal event emitter.
21959
+ * @memberof util
21960
+ * @constructor
21961
+ */
21962
+ function EventEmitter() {
21108
21963
 
21109
- /**
21110
- * Registered listeners.
21111
- * @type {Object.<string,*>}
21112
- * @private
21113
- */
21114
- this._listeners = {};
21115
- }
21964
+ /**
21965
+ * Registered listeners.
21966
+ * @type {Object.<string,*>}
21967
+ * @private
21968
+ */
21969
+ this._listeners = {};
21970
+ }
21116
21971
 
21117
- /**
21118
- * Registers an event listener.
21119
- * @param {string} evt Event name
21120
- * @param {function} fn Listener
21121
- * @param {*} [ctx] Listener context
21122
- * @returns {util.EventEmitter} `this`
21123
- */
21124
- EventEmitter.prototype.on = function on(evt, fn, ctx) {
21125
- (this._listeners[evt] || (this._listeners[evt] = [])).push({
21126
- fn : fn,
21127
- ctx : ctx || this
21128
- });
21129
- return this;
21130
- };
21972
+ /**
21973
+ * Registers an event listener.
21974
+ * @param {string} evt Event name
21975
+ * @param {function} fn Listener
21976
+ * @param {*} [ctx] Listener context
21977
+ * @returns {util.EventEmitter} `this`
21978
+ */
21979
+ EventEmitter.prototype.on = function on(evt, fn, ctx) {
21980
+ (this._listeners[evt] || (this._listeners[evt] = [])).push({
21981
+ fn : fn,
21982
+ ctx : ctx || this
21983
+ });
21984
+ return this;
21985
+ };
21131
21986
 
21132
- /**
21133
- * Removes an event listener or any matching listeners if arguments are omitted.
21134
- * @param {string} [evt] Event name. Removes all listeners if omitted.
21135
- * @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
21136
- * @returns {util.EventEmitter} `this`
21137
- */
21138
- EventEmitter.prototype.off = function off(evt, fn) {
21139
- if (evt === undefined)
21140
- this._listeners = {};
21141
- else {
21142
- if (fn === undefined)
21143
- this._listeners[evt] = [];
21144
- else {
21145
- var listeners = this._listeners[evt];
21146
- for (var i = 0; i < listeners.length;)
21147
- if (listeners[i].fn === fn)
21148
- listeners.splice(i, 1);
21149
- else
21150
- ++i;
21151
- }
21152
- }
21153
- return this;
21154
- };
21987
+ /**
21988
+ * Removes an event listener or any matching listeners if arguments are omitted.
21989
+ * @param {string} [evt] Event name. Removes all listeners if omitted.
21990
+ * @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
21991
+ * @returns {util.EventEmitter} `this`
21992
+ */
21993
+ EventEmitter.prototype.off = function off(evt, fn) {
21994
+ if (evt === undefined)
21995
+ this._listeners = {};
21996
+ else {
21997
+ if (fn === undefined)
21998
+ this._listeners[evt] = [];
21999
+ else {
22000
+ var listeners = this._listeners[evt];
22001
+ for (var i = 0; i < listeners.length;)
22002
+ if (listeners[i].fn === fn)
22003
+ listeners.splice(i, 1);
22004
+ else
22005
+ ++i;
22006
+ }
22007
+ }
22008
+ return this;
22009
+ };
21155
22010
 
21156
- /**
21157
- * Emits an event by calling its listeners with the specified arguments.
21158
- * @param {string} evt Event name
21159
- * @param {...*} args Arguments
21160
- * @returns {util.EventEmitter} `this`
21161
- */
21162
- EventEmitter.prototype.emit = function emit(evt) {
21163
- var listeners = this._listeners[evt];
21164
- if (listeners) {
21165
- var args = [],
21166
- i = 1;
21167
- for (; i < arguments.length;)
21168
- args.push(arguments[i++]);
21169
- for (i = 0; i < listeners.length;)
21170
- listeners[i].fn.apply(listeners[i++].ctx, args);
21171
- }
21172
- return this;
21173
- };
21174
-
21175
- var float = factory(factory);
22011
+ /**
22012
+ * Emits an event by calling its listeners with the specified arguments.
22013
+ * @param {string} evt Event name
22014
+ * @param {...*} args Arguments
22015
+ * @returns {util.EventEmitter} `this`
22016
+ */
22017
+ EventEmitter.prototype.emit = function emit(evt) {
22018
+ var listeners = this._listeners[evt];
22019
+ if (listeners) {
22020
+ var args = [],
22021
+ i = 1;
22022
+ for (; i < arguments.length;)
22023
+ args.push(arguments[i++]);
22024
+ for (i = 0; i < listeners.length;)
22025
+ listeners[i].fn.apply(listeners[i++].ctx, args);
22026
+ }
22027
+ return this;
22028
+ };
22029
+ return eventemitter;
22030
+ }
22031
+
22032
+ var float;
22033
+ var hasRequiredFloat;
22034
+
22035
+ function requireFloat () {
22036
+ if (hasRequiredFloat) return float;
22037
+ hasRequiredFloat = 1;
21176
22038
 
21177
- /**
21178
- * Reads / writes floats / doubles from / to buffers.
21179
- * @name util.float
21180
- * @namespace
21181
- */
22039
+ float = factory(factory);
21182
22040
 
21183
- /**
21184
- * Writes a 32 bit float to a buffer using little endian byte order.
21185
- * @name util.float.writeFloatLE
21186
- * @function
21187
- * @param {number} val Value to write
21188
- * @param {Uint8Array} buf Target buffer
21189
- * @param {number} pos Target buffer offset
21190
- * @returns {undefined}
21191
- */
22041
+ /**
22042
+ * Reads / writes floats / doubles from / to buffers.
22043
+ * @name util.float
22044
+ * @namespace
22045
+ */
21192
22046
 
21193
- /**
21194
- * Writes a 32 bit float to a buffer using big endian byte order.
21195
- * @name util.float.writeFloatBE
21196
- * @function
21197
- * @param {number} val Value to write
21198
- * @param {Uint8Array} buf Target buffer
21199
- * @param {number} pos Target buffer offset
21200
- * @returns {undefined}
21201
- */
22047
+ /**
22048
+ * Writes a 32 bit float to a buffer using little endian byte order.
22049
+ * @name util.float.writeFloatLE
22050
+ * @function
22051
+ * @param {number} val Value to write
22052
+ * @param {Uint8Array} buf Target buffer
22053
+ * @param {number} pos Target buffer offset
22054
+ * @returns {undefined}
22055
+ */
21202
22056
 
21203
- /**
21204
- * Reads a 32 bit float from a buffer using little endian byte order.
21205
- * @name util.float.readFloatLE
21206
- * @function
21207
- * @param {Uint8Array} buf Source buffer
21208
- * @param {number} pos Source buffer offset
21209
- * @returns {number} Value read
21210
- */
22057
+ /**
22058
+ * Writes a 32 bit float to a buffer using big endian byte order.
22059
+ * @name util.float.writeFloatBE
22060
+ * @function
22061
+ * @param {number} val Value to write
22062
+ * @param {Uint8Array} buf Target buffer
22063
+ * @param {number} pos Target buffer offset
22064
+ * @returns {undefined}
22065
+ */
21211
22066
 
21212
- /**
21213
- * Reads a 32 bit float from a buffer using big endian byte order.
21214
- * @name util.float.readFloatBE
21215
- * @function
21216
- * @param {Uint8Array} buf Source buffer
21217
- * @param {number} pos Source buffer offset
21218
- * @returns {number} Value read
21219
- */
22067
+ /**
22068
+ * Reads a 32 bit float from a buffer using little endian byte order.
22069
+ * @name util.float.readFloatLE
22070
+ * @function
22071
+ * @param {Uint8Array} buf Source buffer
22072
+ * @param {number} pos Source buffer offset
22073
+ * @returns {number} Value read
22074
+ */
21220
22075
 
21221
- /**
21222
- * Writes a 64 bit double to a buffer using little endian byte order.
21223
- * @name util.float.writeDoubleLE
21224
- * @function
21225
- * @param {number} val Value to write
21226
- * @param {Uint8Array} buf Target buffer
21227
- * @param {number} pos Target buffer offset
21228
- * @returns {undefined}
21229
- */
22076
+ /**
22077
+ * Reads a 32 bit float from a buffer using big endian byte order.
22078
+ * @name util.float.readFloatBE
22079
+ * @function
22080
+ * @param {Uint8Array} buf Source buffer
22081
+ * @param {number} pos Source buffer offset
22082
+ * @returns {number} Value read
22083
+ */
21230
22084
 
21231
- /**
21232
- * Writes a 64 bit double to a buffer using big endian byte order.
21233
- * @name util.float.writeDoubleBE
21234
- * @function
21235
- * @param {number} val Value to write
21236
- * @param {Uint8Array} buf Target buffer
21237
- * @param {number} pos Target buffer offset
21238
- * @returns {undefined}
21239
- */
22085
+ /**
22086
+ * Writes a 64 bit double to a buffer using little endian byte order.
22087
+ * @name util.float.writeDoubleLE
22088
+ * @function
22089
+ * @param {number} val Value to write
22090
+ * @param {Uint8Array} buf Target buffer
22091
+ * @param {number} pos Target buffer offset
22092
+ * @returns {undefined}
22093
+ */
21240
22094
 
21241
- /**
21242
- * Reads a 64 bit double from a buffer using little endian byte order.
21243
- * @name util.float.readDoubleLE
21244
- * @function
21245
- * @param {Uint8Array} buf Source buffer
21246
- * @param {number} pos Source buffer offset
21247
- * @returns {number} Value read
21248
- */
22095
+ /**
22096
+ * Writes a 64 bit double to a buffer using big endian byte order.
22097
+ * @name util.float.writeDoubleBE
22098
+ * @function
22099
+ * @param {number} val Value to write
22100
+ * @param {Uint8Array} buf Target buffer
22101
+ * @param {number} pos Target buffer offset
22102
+ * @returns {undefined}
22103
+ */
21249
22104
 
21250
- /**
21251
- * Reads a 64 bit double from a buffer using big endian byte order.
21252
- * @name util.float.readDoubleBE
21253
- * @function
21254
- * @param {Uint8Array} buf Source buffer
21255
- * @param {number} pos Source buffer offset
21256
- * @returns {number} Value read
21257
- */
22105
+ /**
22106
+ * Reads a 64 bit double from a buffer using little endian byte order.
22107
+ * @name util.float.readDoubleLE
22108
+ * @function
22109
+ * @param {Uint8Array} buf Source buffer
22110
+ * @param {number} pos Source buffer offset
22111
+ * @returns {number} Value read
22112
+ */
21258
22113
 
21259
- // Factory function for the purpose of node-based testing in modified global environments
21260
- function factory(exports) {
22114
+ /**
22115
+ * Reads a 64 bit double from a buffer using big endian byte order.
22116
+ * @name util.float.readDoubleBE
22117
+ * @function
22118
+ * @param {Uint8Array} buf Source buffer
22119
+ * @param {number} pos Source buffer offset
22120
+ * @returns {number} Value read
22121
+ */
21261
22122
 
21262
- // float: typed array
21263
- if (typeof Float32Array !== "undefined") (function() {
22123
+ // Factory function for the purpose of node-based testing in modified global environments
22124
+ function factory(exports) {
21264
22125
 
21265
- var f32 = new Float32Array([ -0 ]),
21266
- f8b = new Uint8Array(f32.buffer),
21267
- le = f8b[3] === 128;
22126
+ // float: typed array
22127
+ if (typeof Float32Array !== "undefined") (function() {
21268
22128
 
21269
- function writeFloat_f32_cpy(val, buf, pos) {
21270
- f32[0] = val;
21271
- buf[pos ] = f8b[0];
21272
- buf[pos + 1] = f8b[1];
21273
- buf[pos + 2] = f8b[2];
21274
- buf[pos + 3] = f8b[3];
21275
- }
22129
+ var f32 = new Float32Array([ -0 ]),
22130
+ f8b = new Uint8Array(f32.buffer),
22131
+ le = f8b[3] === 128;
21276
22132
 
21277
- function writeFloat_f32_rev(val, buf, pos) {
21278
- f32[0] = val;
21279
- buf[pos ] = f8b[3];
21280
- buf[pos + 1] = f8b[2];
21281
- buf[pos + 2] = f8b[1];
21282
- buf[pos + 3] = f8b[0];
21283
- }
22133
+ function writeFloat_f32_cpy(val, buf, pos) {
22134
+ f32[0] = val;
22135
+ buf[pos ] = f8b[0];
22136
+ buf[pos + 1] = f8b[1];
22137
+ buf[pos + 2] = f8b[2];
22138
+ buf[pos + 3] = f8b[3];
22139
+ }
21284
22140
 
21285
- /* istanbul ignore next */
21286
- exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
21287
- /* istanbul ignore next */
21288
- exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
22141
+ function writeFloat_f32_rev(val, buf, pos) {
22142
+ f32[0] = val;
22143
+ buf[pos ] = f8b[3];
22144
+ buf[pos + 1] = f8b[2];
22145
+ buf[pos + 2] = f8b[1];
22146
+ buf[pos + 3] = f8b[0];
22147
+ }
21289
22148
 
21290
- function readFloat_f32_cpy(buf, pos) {
21291
- f8b[0] = buf[pos ];
21292
- f8b[1] = buf[pos + 1];
21293
- f8b[2] = buf[pos + 2];
21294
- f8b[3] = buf[pos + 3];
21295
- return f32[0];
21296
- }
22149
+ /* istanbul ignore next */
22150
+ exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
22151
+ /* istanbul ignore next */
22152
+ exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
21297
22153
 
21298
- function readFloat_f32_rev(buf, pos) {
21299
- f8b[3] = buf[pos ];
21300
- f8b[2] = buf[pos + 1];
21301
- f8b[1] = buf[pos + 2];
21302
- f8b[0] = buf[pos + 3];
21303
- return f32[0];
21304
- }
22154
+ function readFloat_f32_cpy(buf, pos) {
22155
+ f8b[0] = buf[pos ];
22156
+ f8b[1] = buf[pos + 1];
22157
+ f8b[2] = buf[pos + 2];
22158
+ f8b[3] = buf[pos + 3];
22159
+ return f32[0];
22160
+ }
21305
22161
 
21306
- /* istanbul ignore next */
21307
- exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
21308
- /* istanbul ignore next */
21309
- exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
22162
+ function readFloat_f32_rev(buf, pos) {
22163
+ f8b[3] = buf[pos ];
22164
+ f8b[2] = buf[pos + 1];
22165
+ f8b[1] = buf[pos + 2];
22166
+ f8b[0] = buf[pos + 3];
22167
+ return f32[0];
22168
+ }
21310
22169
 
21311
- // float: ieee754
21312
- })(); else (function() {
22170
+ /* istanbul ignore next */
22171
+ exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
22172
+ /* istanbul ignore next */
22173
+ exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
21313
22174
 
21314
- function writeFloat_ieee754(writeUint, val, buf, pos) {
21315
- var sign = val < 0 ? 1 : 0;
21316
- if (sign)
21317
- val = -val;
21318
- if (val === 0)
21319
- writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
21320
- else if (isNaN(val))
21321
- writeUint(2143289344, buf, pos);
21322
- else if (val > 3.4028234663852886e+38) // +-Infinity
21323
- writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
21324
- else if (val < 1.1754943508222875e-38) // denormal
21325
- writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
21326
- else {
21327
- var exponent = Math.floor(Math.log(val) / Math.LN2),
21328
- mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
21329
- writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
21330
- }
21331
- }
22175
+ // float: ieee754
22176
+ })(); else (function() {
21332
22177
 
21333
- exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
21334
- exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
22178
+ function writeFloat_ieee754(writeUint, val, buf, pos) {
22179
+ var sign = val < 0 ? 1 : 0;
22180
+ if (sign)
22181
+ val = -val;
22182
+ if (val === 0)
22183
+ writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
22184
+ else if (isNaN(val))
22185
+ writeUint(2143289344, buf, pos);
22186
+ else if (val > 3.4028234663852886e+38) // +-Infinity
22187
+ writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
22188
+ else if (val < 1.1754943508222875e-38) // denormal
22189
+ writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
22190
+ else {
22191
+ var exponent = Math.floor(Math.log(val) / Math.LN2),
22192
+ mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
22193
+ writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
22194
+ }
22195
+ }
21335
22196
 
21336
- function readFloat_ieee754(readUint, buf, pos) {
21337
- var uint = readUint(buf, pos),
21338
- sign = (uint >> 31) * 2 + 1,
21339
- exponent = uint >>> 23 & 255,
21340
- mantissa = uint & 8388607;
21341
- return exponent === 255
21342
- ? mantissa
21343
- ? NaN
21344
- : sign * Infinity
21345
- : exponent === 0 // denormal
21346
- ? sign * 1.401298464324817e-45 * mantissa
21347
- : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
21348
- }
22197
+ exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
22198
+ exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
21349
22199
 
21350
- exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
21351
- exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
22200
+ function readFloat_ieee754(readUint, buf, pos) {
22201
+ var uint = readUint(buf, pos),
22202
+ sign = (uint >> 31) * 2 + 1,
22203
+ exponent = uint >>> 23 & 255,
22204
+ mantissa = uint & 8388607;
22205
+ return exponent === 255
22206
+ ? mantissa
22207
+ ? NaN
22208
+ : sign * Infinity
22209
+ : exponent === 0 // denormal
22210
+ ? sign * 1.401298464324817e-45 * mantissa
22211
+ : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
22212
+ }
21352
22213
 
21353
- })();
22214
+ exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
22215
+ exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
21354
22216
 
21355
- // double: typed array
21356
- if (typeof Float64Array !== "undefined") (function() {
22217
+ })();
21357
22218
 
21358
- var f64 = new Float64Array([-0]),
21359
- f8b = new Uint8Array(f64.buffer),
21360
- le = f8b[7] === 128;
22219
+ // double: typed array
22220
+ if (typeof Float64Array !== "undefined") (function() {
21361
22221
 
21362
- function writeDouble_f64_cpy(val, buf, pos) {
21363
- f64[0] = val;
21364
- buf[pos ] = f8b[0];
21365
- buf[pos + 1] = f8b[1];
21366
- buf[pos + 2] = f8b[2];
21367
- buf[pos + 3] = f8b[3];
21368
- buf[pos + 4] = f8b[4];
21369
- buf[pos + 5] = f8b[5];
21370
- buf[pos + 6] = f8b[6];
21371
- buf[pos + 7] = f8b[7];
21372
- }
22222
+ var f64 = new Float64Array([-0]),
22223
+ f8b = new Uint8Array(f64.buffer),
22224
+ le = f8b[7] === 128;
21373
22225
 
21374
- function writeDouble_f64_rev(val, buf, pos) {
21375
- f64[0] = val;
21376
- buf[pos ] = f8b[7];
21377
- buf[pos + 1] = f8b[6];
21378
- buf[pos + 2] = f8b[5];
21379
- buf[pos + 3] = f8b[4];
21380
- buf[pos + 4] = f8b[3];
21381
- buf[pos + 5] = f8b[2];
21382
- buf[pos + 6] = f8b[1];
21383
- buf[pos + 7] = f8b[0];
21384
- }
22226
+ function writeDouble_f64_cpy(val, buf, pos) {
22227
+ f64[0] = val;
22228
+ buf[pos ] = f8b[0];
22229
+ buf[pos + 1] = f8b[1];
22230
+ buf[pos + 2] = f8b[2];
22231
+ buf[pos + 3] = f8b[3];
22232
+ buf[pos + 4] = f8b[4];
22233
+ buf[pos + 5] = f8b[5];
22234
+ buf[pos + 6] = f8b[6];
22235
+ buf[pos + 7] = f8b[7];
22236
+ }
21385
22237
 
21386
- /* istanbul ignore next */
21387
- exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
21388
- /* istanbul ignore next */
21389
- exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
22238
+ function writeDouble_f64_rev(val, buf, pos) {
22239
+ f64[0] = val;
22240
+ buf[pos ] = f8b[7];
22241
+ buf[pos + 1] = f8b[6];
22242
+ buf[pos + 2] = f8b[5];
22243
+ buf[pos + 3] = f8b[4];
22244
+ buf[pos + 4] = f8b[3];
22245
+ buf[pos + 5] = f8b[2];
22246
+ buf[pos + 6] = f8b[1];
22247
+ buf[pos + 7] = f8b[0];
22248
+ }
21390
22249
 
21391
- function readDouble_f64_cpy(buf, pos) {
21392
- f8b[0] = buf[pos ];
21393
- f8b[1] = buf[pos + 1];
21394
- f8b[2] = buf[pos + 2];
21395
- f8b[3] = buf[pos + 3];
21396
- f8b[4] = buf[pos + 4];
21397
- f8b[5] = buf[pos + 5];
21398
- f8b[6] = buf[pos + 6];
21399
- f8b[7] = buf[pos + 7];
21400
- return f64[0];
21401
- }
22250
+ /* istanbul ignore next */
22251
+ exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
22252
+ /* istanbul ignore next */
22253
+ exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
21402
22254
 
21403
- function readDouble_f64_rev(buf, pos) {
21404
- f8b[7] = buf[pos ];
21405
- f8b[6] = buf[pos + 1];
21406
- f8b[5] = buf[pos + 2];
21407
- f8b[4] = buf[pos + 3];
21408
- f8b[3] = buf[pos + 4];
21409
- f8b[2] = buf[pos + 5];
21410
- f8b[1] = buf[pos + 6];
21411
- f8b[0] = buf[pos + 7];
21412
- return f64[0];
21413
- }
22255
+ function readDouble_f64_cpy(buf, pos) {
22256
+ f8b[0] = buf[pos ];
22257
+ f8b[1] = buf[pos + 1];
22258
+ f8b[2] = buf[pos + 2];
22259
+ f8b[3] = buf[pos + 3];
22260
+ f8b[4] = buf[pos + 4];
22261
+ f8b[5] = buf[pos + 5];
22262
+ f8b[6] = buf[pos + 6];
22263
+ f8b[7] = buf[pos + 7];
22264
+ return f64[0];
22265
+ }
21414
22266
 
21415
- /* istanbul ignore next */
21416
- exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
21417
- /* istanbul ignore next */
21418
- exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
22267
+ function readDouble_f64_rev(buf, pos) {
22268
+ f8b[7] = buf[pos ];
22269
+ f8b[6] = buf[pos + 1];
22270
+ f8b[5] = buf[pos + 2];
22271
+ f8b[4] = buf[pos + 3];
22272
+ f8b[3] = buf[pos + 4];
22273
+ f8b[2] = buf[pos + 5];
22274
+ f8b[1] = buf[pos + 6];
22275
+ f8b[0] = buf[pos + 7];
22276
+ return f64[0];
22277
+ }
21419
22278
 
21420
- // double: ieee754
21421
- })(); else (function() {
22279
+ /* istanbul ignore next */
22280
+ exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
22281
+ /* istanbul ignore next */
22282
+ exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
21422
22283
 
21423
- function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
21424
- var sign = val < 0 ? 1 : 0;
21425
- if (sign)
21426
- val = -val;
21427
- if (val === 0) {
21428
- writeUint(0, buf, pos + off0);
21429
- writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
21430
- } else if (isNaN(val)) {
21431
- writeUint(0, buf, pos + off0);
21432
- writeUint(2146959360, buf, pos + off1);
21433
- } else if (val > 1.7976931348623157e+308) { // +-Infinity
21434
- writeUint(0, buf, pos + off0);
21435
- writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
21436
- } else {
21437
- var mantissa;
21438
- if (val < 2.2250738585072014e-308) { // denormal
21439
- mantissa = val / 5e-324;
21440
- writeUint(mantissa >>> 0, buf, pos + off0);
21441
- writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
21442
- } else {
21443
- var exponent = Math.floor(Math.log(val) / Math.LN2);
21444
- if (exponent === 1024)
21445
- exponent = 1023;
21446
- mantissa = val * Math.pow(2, -exponent);
21447
- writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
21448
- writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
21449
- }
21450
- }
21451
- }
22284
+ // double: ieee754
22285
+ })(); else (function() {
21452
22286
 
21453
- exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
21454
- exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
22287
+ function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
22288
+ var sign = val < 0 ? 1 : 0;
22289
+ if (sign)
22290
+ val = -val;
22291
+ if (val === 0) {
22292
+ writeUint(0, buf, pos + off0);
22293
+ writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
22294
+ } else if (isNaN(val)) {
22295
+ writeUint(0, buf, pos + off0);
22296
+ writeUint(2146959360, buf, pos + off1);
22297
+ } else if (val > 1.7976931348623157e+308) { // +-Infinity
22298
+ writeUint(0, buf, pos + off0);
22299
+ writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
22300
+ } else {
22301
+ var mantissa;
22302
+ if (val < 2.2250738585072014e-308) { // denormal
22303
+ mantissa = val / 5e-324;
22304
+ writeUint(mantissa >>> 0, buf, pos + off0);
22305
+ writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
22306
+ } else {
22307
+ var exponent = Math.floor(Math.log(val) / Math.LN2);
22308
+ if (exponent === 1024)
22309
+ exponent = 1023;
22310
+ mantissa = val * Math.pow(2, -exponent);
22311
+ writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
22312
+ writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
22313
+ }
22314
+ }
22315
+ }
21455
22316
 
21456
- function readDouble_ieee754(readUint, off0, off1, buf, pos) {
21457
- var lo = readUint(buf, pos + off0),
21458
- hi = readUint(buf, pos + off1);
21459
- var sign = (hi >> 31) * 2 + 1,
21460
- exponent = hi >>> 20 & 2047,
21461
- mantissa = 4294967296 * (hi & 1048575) + lo;
21462
- return exponent === 2047
21463
- ? mantissa
21464
- ? NaN
21465
- : sign * Infinity
21466
- : exponent === 0 // denormal
21467
- ? sign * 5e-324 * mantissa
21468
- : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
21469
- }
22317
+ exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
22318
+ exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
21470
22319
 
21471
- exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
21472
- exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
22320
+ function readDouble_ieee754(readUint, off0, off1, buf, pos) {
22321
+ var lo = readUint(buf, pos + off0),
22322
+ hi = readUint(buf, pos + off1);
22323
+ var sign = (hi >> 31) * 2 + 1,
22324
+ exponent = hi >>> 20 & 2047,
22325
+ mantissa = 4294967296 * (hi & 1048575) + lo;
22326
+ return exponent === 2047
22327
+ ? mantissa
22328
+ ? NaN
22329
+ : sign * Infinity
22330
+ : exponent === 0 // denormal
22331
+ ? sign * 5e-324 * mantissa
22332
+ : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
22333
+ }
21473
22334
 
21474
- })();
22335
+ exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
22336
+ exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
21475
22337
 
21476
- return exports;
21477
- }
22338
+ })();
21478
22339
 
21479
- // uint helpers
22340
+ return exports;
22341
+ }
21480
22342
 
21481
- function writeUintLE(val, buf, pos) {
21482
- buf[pos ] = val & 255;
21483
- buf[pos + 1] = val >>> 8 & 255;
21484
- buf[pos + 2] = val >>> 16 & 255;
21485
- buf[pos + 3] = val >>> 24;
21486
- }
22343
+ // uint helpers
21487
22344
 
21488
- function writeUintBE(val, buf, pos) {
21489
- buf[pos ] = val >>> 24;
21490
- buf[pos + 1] = val >>> 16 & 255;
21491
- buf[pos + 2] = val >>> 8 & 255;
21492
- buf[pos + 3] = val & 255;
21493
- }
22345
+ function writeUintLE(val, buf, pos) {
22346
+ buf[pos ] = val & 255;
22347
+ buf[pos + 1] = val >>> 8 & 255;
22348
+ buf[pos + 2] = val >>> 16 & 255;
22349
+ buf[pos + 3] = val >>> 24;
22350
+ }
21494
22351
 
21495
- function readUintLE(buf, pos) {
21496
- return (buf[pos ]
21497
- | buf[pos + 1] << 8
21498
- | buf[pos + 2] << 16
21499
- | buf[pos + 3] << 24) >>> 0;
21500
- }
22352
+ function writeUintBE(val, buf, pos) {
22353
+ buf[pos ] = val >>> 24;
22354
+ buf[pos + 1] = val >>> 16 & 255;
22355
+ buf[pos + 2] = val >>> 8 & 255;
22356
+ buf[pos + 3] = val & 255;
22357
+ }
21501
22358
 
21502
- function readUintBE(buf, pos) {
21503
- return (buf[pos ] << 24
21504
- | buf[pos + 1] << 16
21505
- | buf[pos + 2] << 8
21506
- | buf[pos + 3]) >>> 0;
21507
- }
21508
-
21509
- var inquire_1 = inquire;
22359
+ function readUintLE(buf, pos) {
22360
+ return (buf[pos ]
22361
+ | buf[pos + 1] << 8
22362
+ | buf[pos + 2] << 16
22363
+ | buf[pos + 3] << 24) >>> 0;
22364
+ }
21510
22365
 
21511
- /**
21512
- * Requires a module only if available.
21513
- * @memberof util
21514
- * @param {string} moduleName Module to require
21515
- * @returns {?Object} Required module if available and not empty, otherwise `null`
21516
- */
21517
- function inquire(moduleName) {
21518
- try {
21519
- var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
21520
- if (mod && (mod.length || Object.keys(mod).length))
21521
- return mod;
21522
- } catch (e) {} // eslint-disable-line no-empty
21523
- return null;
22366
+ function readUintBE(buf, pos) {
22367
+ return (buf[pos ] << 24
22368
+ | buf[pos + 1] << 16
22369
+ | buf[pos + 2] << 8
22370
+ | buf[pos + 3]) >>> 0;
22371
+ }
22372
+ return float;
21524
22373
  }
21525
22374
 
21526
- var utf8$2 = {};
22375
+ var inquire_1;
22376
+ var hasRequiredInquire;
21527
22377
 
21528
- (function (exports) {
22378
+ function requireInquire () {
22379
+ if (hasRequiredInquire) return inquire_1;
22380
+ hasRequiredInquire = 1;
22381
+ inquire_1 = inquire;
21529
22382
 
21530
22383
  /**
21531
- * A minimal UTF8 implementation for number arrays.
22384
+ * Requires a module only if available.
21532
22385
  * @memberof util
21533
- * @namespace
22386
+ * @param {string} moduleName Module to require
22387
+ * @returns {?Object} Required module if available and not empty, otherwise `null`
21534
22388
  */
21535
- var utf8 = exports;
22389
+ function inquire(moduleName) {
22390
+ try {
22391
+ var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
22392
+ if (mod && (mod.length || Object.keys(mod).length))
22393
+ return mod;
22394
+ } catch (e) {} // eslint-disable-line no-empty
22395
+ return null;
22396
+ }
22397
+ return inquire_1;
22398
+ }
22399
+
22400
+ var utf8$2 = {};
22401
+
22402
+ var hasRequiredUtf8;
22403
+
22404
+ function requireUtf8 () {
22405
+ if (hasRequiredUtf8) return utf8$2;
22406
+ hasRequiredUtf8 = 1;
22407
+ (function (exports) {
22408
+
22409
+ /**
22410
+ * A minimal UTF8 implementation for number arrays.
22411
+ * @memberof util
22412
+ * @namespace
22413
+ */
22414
+ var utf8 = exports;
22415
+
22416
+ /**
22417
+ * Calculates the UTF8 byte length of a string.
22418
+ * @param {string} string String
22419
+ * @returns {number} Byte length
22420
+ */
22421
+ utf8.length = function utf8_length(string) {
22422
+ var len = 0,
22423
+ c = 0;
22424
+ for (var i = 0; i < string.length; ++i) {
22425
+ c = string.charCodeAt(i);
22426
+ if (c < 128)
22427
+ len += 1;
22428
+ else if (c < 2048)
22429
+ len += 2;
22430
+ else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
22431
+ ++i;
22432
+ len += 4;
22433
+ } else
22434
+ len += 3;
22435
+ }
22436
+ return len;
22437
+ };
22438
+
22439
+ /**
22440
+ * Reads UTF8 bytes as a string.
22441
+ * @param {Uint8Array} buffer Source buffer
22442
+ * @param {number} start Source start
22443
+ * @param {number} end Source end
22444
+ * @returns {string} String read
22445
+ */
22446
+ utf8.read = function utf8_read(buffer, start, end) {
22447
+ var len = end - start;
22448
+ if (len < 1)
22449
+ return "";
22450
+ var parts = null,
22451
+ chunk = [],
22452
+ i = 0, // char offset
22453
+ t; // temporary
22454
+ while (start < end) {
22455
+ t = buffer[start++];
22456
+ if (t < 128)
22457
+ chunk[i++] = t;
22458
+ else if (t > 191 && t < 224)
22459
+ chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
22460
+ else if (t > 239 && t < 365) {
22461
+ t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
22462
+ chunk[i++] = 0xD800 + (t >> 10);
22463
+ chunk[i++] = 0xDC00 + (t & 1023);
22464
+ } else
22465
+ chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
22466
+ if (i > 8191) {
22467
+ (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
22468
+ i = 0;
22469
+ }
22470
+ }
22471
+ if (parts) {
22472
+ if (i)
22473
+ parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
22474
+ return parts.join("");
22475
+ }
22476
+ return String.fromCharCode.apply(String, chunk.slice(0, i));
22477
+ };
22478
+
22479
+ /**
22480
+ * Writes a string as UTF8 bytes.
22481
+ * @param {string} string Source string
22482
+ * @param {Uint8Array} buffer Destination buffer
22483
+ * @param {number} offset Destination offset
22484
+ * @returns {number} Bytes written
22485
+ */
22486
+ utf8.write = function utf8_write(string, buffer, offset) {
22487
+ var start = offset,
22488
+ c1, // character 1
22489
+ c2; // character 2
22490
+ for (var i = 0; i < string.length; ++i) {
22491
+ c1 = string.charCodeAt(i);
22492
+ if (c1 < 128) {
22493
+ buffer[offset++] = c1;
22494
+ } else if (c1 < 2048) {
22495
+ buffer[offset++] = c1 >> 6 | 192;
22496
+ buffer[offset++] = c1 & 63 | 128;
22497
+ } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
22498
+ c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
22499
+ ++i;
22500
+ buffer[offset++] = c1 >> 18 | 240;
22501
+ buffer[offset++] = c1 >> 12 & 63 | 128;
22502
+ buffer[offset++] = c1 >> 6 & 63 | 128;
22503
+ buffer[offset++] = c1 & 63 | 128;
22504
+ } else {
22505
+ buffer[offset++] = c1 >> 12 | 224;
22506
+ buffer[offset++] = c1 >> 6 & 63 | 128;
22507
+ buffer[offset++] = c1 & 63 | 128;
22508
+ }
22509
+ }
22510
+ return offset - start;
22511
+ };
22512
+ } (utf8$2));
22513
+ return utf8$2;
22514
+ }
22515
+
22516
+ var pool_1;
22517
+ var hasRequiredPool;
22518
+
22519
+ function requirePool () {
22520
+ if (hasRequiredPool) return pool_1;
22521
+ hasRequiredPool = 1;
22522
+ pool_1 = pool;
21536
22523
 
21537
22524
  /**
21538
- * Calculates the UTF8 byte length of a string.
21539
- * @param {string} string String
21540
- * @returns {number} Byte length
22525
+ * An allocator as used by {@link util.pool}.
22526
+ * @typedef PoolAllocator
22527
+ * @type {function}
22528
+ * @param {number} size Buffer size
22529
+ * @returns {Uint8Array} Buffer
21541
22530
  */
21542
- utf8.length = function utf8_length(string) {
21543
- var len = 0,
21544
- c = 0;
21545
- for (var i = 0; i < string.length; ++i) {
21546
- c = string.charCodeAt(i);
21547
- if (c < 128)
21548
- len += 1;
21549
- else if (c < 2048)
21550
- len += 2;
21551
- else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
21552
- ++i;
21553
- len += 4;
21554
- } else
21555
- len += 3;
21556
- }
21557
- return len;
21558
- };
21559
22531
 
21560
22532
  /**
21561
- * Reads UTF8 bytes as a string.
21562
- * @param {Uint8Array} buffer Source buffer
21563
- * @param {number} start Source start
21564
- * @param {number} end Source end
21565
- * @returns {string} String read
22533
+ * A slicer as used by {@link util.pool}.
22534
+ * @typedef PoolSlicer
22535
+ * @type {function}
22536
+ * @param {number} start Start offset
22537
+ * @param {number} end End offset
22538
+ * @returns {Uint8Array} Buffer slice
22539
+ * @this {Uint8Array}
21566
22540
  */
21567
- utf8.read = function utf8_read(buffer, start, end) {
21568
- var len = end - start;
21569
- if (len < 1)
21570
- return "";
21571
- var parts = null,
21572
- chunk = [],
21573
- i = 0, // char offset
21574
- t; // temporary
21575
- while (start < end) {
21576
- t = buffer[start++];
21577
- if (t < 128)
21578
- chunk[i++] = t;
21579
- else if (t > 191 && t < 224)
21580
- chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
21581
- else if (t > 239 && t < 365) {
21582
- t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
21583
- chunk[i++] = 0xD800 + (t >> 10);
21584
- chunk[i++] = 0xDC00 + (t & 1023);
21585
- } else
21586
- chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
21587
- if (i > 8191) {
21588
- (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
21589
- i = 0;
21590
- }
21591
- }
21592
- if (parts) {
21593
- if (i)
21594
- parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
21595
- return parts.join("");
21596
- }
21597
- return String.fromCharCode.apply(String, chunk.slice(0, i));
21598
- };
21599
22541
 
21600
22542
  /**
21601
- * Writes a string as UTF8 bytes.
21602
- * @param {string} string Source string
21603
- * @param {Uint8Array} buffer Destination buffer
21604
- * @param {number} offset Destination offset
21605
- * @returns {number} Bytes written
22543
+ * A general purpose buffer pool.
22544
+ * @memberof util
22545
+ * @function
22546
+ * @param {PoolAllocator} alloc Allocator
22547
+ * @param {PoolSlicer} slice Slicer
22548
+ * @param {number} [size=8192] Slab size
22549
+ * @returns {PoolAllocator} Pooled allocator
21606
22550
  */
21607
- utf8.write = function utf8_write(string, buffer, offset) {
21608
- var start = offset,
21609
- c1, // character 1
21610
- c2; // character 2
21611
- for (var i = 0; i < string.length; ++i) {
21612
- c1 = string.charCodeAt(i);
21613
- if (c1 < 128) {
21614
- buffer[offset++] = c1;
21615
- } else if (c1 < 2048) {
21616
- buffer[offset++] = c1 >> 6 | 192;
21617
- buffer[offset++] = c1 & 63 | 128;
21618
- } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
21619
- c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
21620
- ++i;
21621
- buffer[offset++] = c1 >> 18 | 240;
21622
- buffer[offset++] = c1 >> 12 & 63 | 128;
21623
- buffer[offset++] = c1 >> 6 & 63 | 128;
21624
- buffer[offset++] = c1 & 63 | 128;
21625
- } else {
21626
- buffer[offset++] = c1 >> 12 | 224;
21627
- buffer[offset++] = c1 >> 6 & 63 | 128;
21628
- buffer[offset++] = c1 & 63 | 128;
22551
+ function pool(alloc, slice, size) {
22552
+ var SIZE = size || 8192;
22553
+ var MAX = SIZE >>> 1;
22554
+ var slab = null;
22555
+ var offset = SIZE;
22556
+ return function pool_alloc(size) {
22557
+ if (size < 1 || size > MAX)
22558
+ return alloc(size);
22559
+ if (offset + size > SIZE) {
22560
+ slab = alloc(SIZE);
22561
+ offset = 0;
21629
22562
  }
21630
- }
21631
- return offset - start;
21632
- };
21633
- } (utf8$2));
21634
-
21635
- var pool_1 = pool;
21636
-
21637
- /**
21638
- * An allocator as used by {@link util.pool}.
21639
- * @typedef PoolAllocator
21640
- * @type {function}
21641
- * @param {number} size Buffer size
21642
- * @returns {Uint8Array} Buffer
21643
- */
21644
-
21645
- /**
21646
- * A slicer as used by {@link util.pool}.
21647
- * @typedef PoolSlicer
21648
- * @type {function}
21649
- * @param {number} start Start offset
21650
- * @param {number} end End offset
21651
- * @returns {Uint8Array} Buffer slice
21652
- * @this {Uint8Array}
21653
- */
21654
-
21655
- /**
21656
- * A general purpose buffer pool.
21657
- * @memberof util
21658
- * @function
21659
- * @param {PoolAllocator} alloc Allocator
21660
- * @param {PoolSlicer} slice Slicer
21661
- * @param {number} [size=8192] Slab size
21662
- * @returns {PoolAllocator} Pooled allocator
21663
- */
21664
- function pool(alloc, slice, size) {
21665
- var SIZE = size || 8192;
21666
- var MAX = SIZE >>> 1;
21667
- var slab = null;
21668
- var offset = SIZE;
21669
- return function pool_alloc(size) {
21670
- if (size < 1 || size > MAX)
21671
- return alloc(size);
21672
- if (offset + size > SIZE) {
21673
- slab = alloc(SIZE);
21674
- offset = 0;
21675
- }
21676
- var buf = slice.call(slab, offset, offset += size);
21677
- if (offset & 7) // align to 32 bit
21678
- offset = (offset | 7) + 1;
21679
- return buf;
21680
- };
22563
+ var buf = slice.call(slab, offset, offset += size);
22564
+ if (offset & 7) // align to 32 bit
22565
+ offset = (offset | 7) + 1;
22566
+ return buf;
22567
+ };
22568
+ }
22569
+ return pool_1;
21681
22570
  }
21682
22571
 
21683
22572
  var longbits;
@@ -21903,19 +22792,19 @@ function requireMinimal () {
21903
22792
  util.base64 = base64$1;
21904
22793
 
21905
22794
  // base class of rpc.Service
21906
- util.EventEmitter = eventemitter;
22795
+ util.EventEmitter = requireEventemitter();
21907
22796
 
21908
22797
  // float handling accross browsers
21909
- util.float = float;
22798
+ util.float = requireFloat();
21910
22799
 
21911
22800
  // requires modules optionally and hides the call from bundlers
21912
- util.inquire = inquire_1;
22801
+ util.inquire = requireInquire();
21913
22802
 
21914
22803
  // converts to / from utf8 encoded strings
21915
- util.utf8 = utf8$2;
22804
+ util.utf8 = requireUtf8();
21916
22805
 
21917
22806
  // provides a node-like buffer pool in the browser
21918
- util.pool = pool_1;
22807
+ util.pool = requirePool();
21919
22808
 
21920
22809
  // utility to work with the low and high bits of a 64 bit value
21921
22810
  util.LongBits = requireLongbits();
@@ -22648,9 +23537,14 @@ Reader$1.prototype.bytes = function read_bytes() {
22648
23537
  this.pos += length;
22649
23538
  if (Array.isArray(this.buf)) // plain array
22650
23539
  return this.buf.slice(start, end);
22651
- return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1
22652
- ? new this.buf.constructor(0)
22653
- : this._slice.call(this.buf, start, end);
23540
+
23541
+ if (start === end) { // fix for IE 10/Win8 and others' subarray returning array of size 1
23542
+ var nativeBuffer = util$4.Buffer;
23543
+ return nativeBuffer
23544
+ ? nativeBuffer.alloc(0)
23545
+ : new this.buf.constructor(0);
23546
+ }
23547
+ return this._slice.call(this.buf, start, end);
22654
23548
  };
22655
23549
 
22656
23550
  /**
@@ -23459,6 +24353,10 @@ function message(encode, decode) {
23459
24353
  }
23460
24354
 
23461
24355
  /* eslint-disable import/export */
24356
+ /* eslint-disable complexity */
24357
+ /* eslint-disable @typescript-eslint/no-namespace */
24358
+ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
24359
+ /* eslint-disable @typescript-eslint/no-empty-interface */
23462
24360
  var KeyType;
23463
24361
  (function (KeyType) {
23464
24362
  KeyType["RSA"] = "RSA";
@@ -23596,7 +24494,7 @@ class Ed25519PublicKey {
23596
24494
  return equals(this.bytes, key.bytes);
23597
24495
  }
23598
24496
  async hash() {
23599
- const { bytes } = await sha256$1.digest(this.bytes);
24497
+ const { bytes } = await sha256.digest(this.bytes);
23600
24498
  return bytes;
23601
24499
  }
23602
24500
  }
@@ -23628,7 +24526,7 @@ class Ed25519PrivateKey {
23628
24526
  return equals(this.bytes, key.bytes);
23629
24527
  }
23630
24528
  async hash() {
23631
- const { bytes } = await sha256$1.digest(this.bytes);
24529
+ const { bytes } = await sha256.digest(this.bytes);
23632
24530
  return bytes;
23633
24531
  }
23634
24532
  /**
@@ -23720,7 +24618,7 @@ function base64urlToBigInteger(str) {
23720
24618
  return new forge$n.jsbn.BigInteger(toString$1(buf, 'base16'), 16);
23721
24619
  }
23722
24620
  function base64urlToBuffer(str, len) {
23723
- let buf = fromString$1(str, 'base64urlpad');
24621
+ let buf = fromString(str, 'base64urlpad');
23724
24622
  if (len != null) {
23725
24623
  if (buf.length > len)
23726
24624
  throw new Error('byte array longer than desired length');
@@ -24350,7 +25248,7 @@ function jwkToPkcs1(jwk) {
24350
25248
  dQ: base64urlToBigInteger(jwk.dq),
24351
25249
  qInv: base64urlToBigInteger(jwk.qi)
24352
25250
  });
24353
- return fromString$1(forge$n.asn1.toDer(asn1).getBytes(), 'ascii');
25251
+ return fromString(forge$n.asn1.toDer(asn1).getBytes(), 'ascii');
24354
25252
  }
24355
25253
  // Convert a PKCIX in ASN1 DER format to a JWK key
24356
25254
  function pkixToJwk(bytes) {
@@ -24371,7 +25269,7 @@ function jwkToPkix(jwk) {
24371
25269
  n: base64urlToBigInteger(jwk.n),
24372
25270
  e: base64urlToBigInteger(jwk.e)
24373
25271
  });
24374
- return fromString$1(forge$n.asn1.toDer(asn1).getBytes(), 'ascii');
25272
+ return fromString(forge$n.asn1.toDer(asn1).getBytes(), 'ascii');
24375
25273
  }
24376
25274
 
24377
25275
  async function generateKey$1(bits) {
@@ -24455,7 +25353,7 @@ function convertKey(key, pub, msg, handle) {
24455
25353
  const fkey = pub ? jwk2pub(key) : jwk2priv(key);
24456
25354
  const fmsg = toString$1(Uint8Array.from(msg), 'ascii');
24457
25355
  const fomsg = handle(fmsg, fkey);
24458
- return fromString$1(fomsg, 'ascii');
25356
+ return fromString(fomsg, 'ascii');
24459
25357
  }
24460
25358
  function encrypt(key, msg) {
24461
25359
  return convertKey(key, true, msg, (msg, key) => key.encrypt(msg));
@@ -24488,7 +25386,7 @@ class RsaPublicKey {
24488
25386
  return equals(this.bytes, key.bytes);
24489
25387
  }
24490
25388
  async hash() {
24491
- const { bytes } = await sha256$1.digest(this.bytes);
25389
+ const { bytes } = await sha256.digest(this.bytes);
24492
25390
  return bytes;
24493
25391
  }
24494
25392
  }
@@ -24527,7 +25425,7 @@ class RsaPrivateKey {
24527
25425
  return equals(this.bytes, key.bytes);
24528
25426
  }
24529
25427
  async hash() {
24530
- const { bytes } = await sha256$1.digest(this.bytes);
25428
+ const { bytes } = await sha256.digest(this.bytes);
24531
25429
  return bytes;
24532
25430
  }
24533
25431
  /**
@@ -24600,7 +25498,7 @@ function generateKey() {
24600
25498
  * Hash and sign message with private key
24601
25499
  */
24602
25500
  async function hashAndSign(key, msg) {
24603
- const { digest } = await sha256$1.digest(msg);
25501
+ const { digest } = await sha256.digest(msg);
24604
25502
  try {
24605
25503
  return await sign$3(digest, key);
24606
25504
  }
@@ -24613,7 +25511,7 @@ async function hashAndSign(key, msg) {
24613
25511
  */
24614
25512
  async function hashAndVerify(key, sig, msg) {
24615
25513
  try {
24616
- const { digest } = await sha256$1.digest(msg);
25514
+ const { digest } = await sha256.digest(msg);
24617
25515
  return verify$1(sig, digest, key);
24618
25516
  }
24619
25517
  catch (err) {
@@ -24671,7 +25569,7 @@ class Secp256k1PublicKey {
24671
25569
  return equals(this.bytes, key.bytes);
24672
25570
  }
24673
25571
  async hash() {
24674
- const { bytes } = await sha256$1.digest(this.bytes);
25572
+ const { bytes } = await sha256.digest(this.bytes);
24675
25573
  return bytes;
24676
25574
  }
24677
25575
  }
@@ -24703,7 +25601,7 @@ class Secp256k1PrivateKey {
24703
25601
  return equals(this.bytes, key.bytes);
24704
25602
  }
24705
25603
  async hash() {
24706
- const { bytes } = await sha256$1.digest(this.bytes);
25604
+ const { bytes } = await sha256.digest(this.bytes);
24707
25605
  return bytes;
24708
25606
  }
24709
25607
  /**
@@ -24825,7 +25723,7 @@ class PeerIdImpl {
24825
25723
  [symbol] = true;
24826
25724
  toString() {
24827
25725
  if (this.string == null) {
24828
- this.string = base58btc.encode(this.multihash.bytes).slice(1);
25726
+ this.string = base58btc$1.encode(this.multihash.bytes).slice(1);
24829
25727
  }
24830
25728
  return this.string;
24831
25729
  }
@@ -24904,7 +25802,7 @@ function peerIdFromString(str, decoder) {
24904
25802
  if (str.charAt(0) === '1' || str.charAt(0) === 'Q') {
24905
25803
  // identity hash ed25519/secp256k1 key or sha2-256 hash of
24906
25804
  // rsa public key - base58btc encoded either way
24907
- const multihash = decode$2(base58btc.decode(`z${str}`));
25805
+ const multihash = decode$4(base58btc$1.decode(`z${str}`));
24908
25806
  if (str.startsWith('12D')) {
24909
25807
  return new Ed25519PeerIdImpl({ multihash });
24910
25808
  }
@@ -24919,8 +25817,8 @@ function peerIdFromString(str, decoder) {
24919
25817
  }
24920
25818
  function peerIdFromBytes(buf) {
24921
25819
  try {
24922
- const multihash = decode$2(buf);
24923
- if (multihash.code === identity.code) {
25820
+ const multihash = decode$4(buf);
25821
+ if (multihash.code === identity$1.code) {
24924
25822
  if (multihash.digest.length === MARSHALLED_ED225519_PUBLIC_KEY_LENGTH) {
24925
25823
  return new Ed25519PeerIdImpl({ multihash });
24926
25824
  }
@@ -24928,7 +25826,7 @@ function peerIdFromBytes(buf) {
24928
25826
  return new Secp256k1PeerIdImpl({ multihash });
24929
25827
  }
24930
25828
  }
24931
- if (multihash.code === sha256$1.code) {
25829
+ if (multihash.code === sha256$2.code) {
24932
25830
  return new RSAPeerIdImpl({ multihash });
24933
25831
  }
24934
25832
  }
@@ -24942,10 +25840,10 @@ function peerIdFromCID(cid) {
24942
25840
  throw new Error('Supplied PeerID CID is invalid');
24943
25841
  }
24944
25842
  const multihash = cid.multihash;
24945
- if (multihash.code === sha256$1.code) {
25843
+ if (multihash.code === sha256$2.code) {
24946
25844
  return new RSAPeerIdImpl({ multihash: cid.multihash });
24947
25845
  }
24948
- else if (multihash.code === identity.code) {
25846
+ else if (multihash.code === identity$1.code) {
24949
25847
  if (multihash.digest.length === MARSHALLED_ED225519_PUBLIC_KEY_LENGTH) {
24950
25848
  return new Ed25519PeerIdImpl({ multihash: cid.multihash });
24951
25849
  }
@@ -24961,12 +25859,12 @@ function peerIdFromCID(cid) {
24961
25859
  */
24962
25860
  async function peerIdFromKeys(publicKey, privateKey) {
24963
25861
  if (publicKey.length === MARSHALLED_ED225519_PUBLIC_KEY_LENGTH) {
24964
- return new Ed25519PeerIdImpl({ multihash: create$3(identity.code, publicKey), privateKey });
25862
+ return new Ed25519PeerIdImpl({ multihash: create$4(identity$1.code, publicKey), privateKey });
24965
25863
  }
24966
25864
  if (publicKey.length === MARSHALLED_SECP256K1_PUBLIC_KEY_LENGTH) {
24967
- return new Secp256k1PeerIdImpl({ multihash: create$3(identity.code, publicKey), privateKey });
25865
+ return new Secp256k1PeerIdImpl({ multihash: create$4(identity$1.code, publicKey), privateKey });
24968
25866
  }
24969
- return new RSAPeerIdImpl({ multihash: await sha256$1.digest(publicKey), publicKey, privateKey });
25867
+ return new RSAPeerIdImpl({ multihash: await sha256$2.digest(publicKey), publicKey, privateKey });
24970
25868
  }
24971
25869
 
24972
25870
  function createPeerIdFromPublicKey(publicKey) {
@@ -25021,6 +25919,60 @@ function encodeMultiaddrs(multiaddrs) {
25021
25919
  return bytes;
25022
25920
  }
25023
25921
 
25922
+ const decodeRelayShard = (bytes) => {
25923
+ // explicitly converting to Uint8Array to avoid Buffer
25924
+ // https://github.com/libp2p/js-libp2p/issues/2146
25925
+ bytes = new Uint8Array(bytes);
25926
+ if (bytes.length < 3)
25927
+ throw new Error("Insufficient data");
25928
+ const view = new DataView(bytes.buffer);
25929
+ const cluster = view.getUint16(0);
25930
+ const indexList = [];
25931
+ if (bytes.length === 130) {
25932
+ // rsv format (Bit Vector)
25933
+ for (let i = 0; i < 1024; i++) {
25934
+ const byteIndex = Math.floor(i / 8) + 2; // Adjusted for the 2-byte cluster field
25935
+ const bitIndex = 7 - (i % 8);
25936
+ if (view.getUint8(byteIndex) & (1 << bitIndex)) {
25937
+ indexList.push(i);
25938
+ }
25939
+ }
25940
+ }
25941
+ else {
25942
+ // rs format (Index List)
25943
+ const numIndices = view.getUint8(2);
25944
+ for (let i = 0, offset = 3; i < numIndices; i++, offset += 2) {
25945
+ if (offset + 1 >= bytes.length)
25946
+ throw new Error("Unexpected end of data");
25947
+ indexList.push(view.getUint16(offset));
25948
+ }
25949
+ }
25950
+ return { cluster, indexList };
25951
+ };
25952
+ const encodeRelayShard = (shardInfo) => {
25953
+ const { cluster, indexList } = shardInfo;
25954
+ const totalLength = indexList.length >= 64 ? 130 : 3 + 2 * indexList.length;
25955
+ const buffer = new ArrayBuffer(totalLength);
25956
+ const view = new DataView(buffer);
25957
+ view.setUint16(0, cluster);
25958
+ if (indexList.length >= 64) {
25959
+ // rsv format (Bit Vector)
25960
+ for (const index of indexList) {
25961
+ const byteIndex = Math.floor(index / 8) + 2; // Adjusted for the 2-byte cluster field
25962
+ const bitIndex = 7 - (index % 8);
25963
+ view.setUint8(byteIndex, view.getUint8(byteIndex) | (1 << bitIndex));
25964
+ }
25965
+ }
25966
+ else {
25967
+ // rs format (Index List)
25968
+ view.setUint8(2, indexList.length);
25969
+ for (let i = 0, offset = 3; i < indexList.length; i++, offset += 2) {
25970
+ view.setUint16(offset, indexList[i]);
25971
+ }
25972
+ }
25973
+ return new Uint8Array(buffer);
25974
+ };
25975
+
25024
25976
  function encodeWaku2(protocols) {
25025
25977
  let byte = 0;
25026
25978
  if (protocols.lightPush)
@@ -25041,7 +25993,7 @@ function decodeWaku2(byte) {
25041
25993
  relay: false,
25042
25994
  store: false,
25043
25995
  filter: false,
25044
- lightPush: false,
25996
+ lightPush: false
25045
25997
  };
25046
25998
  if (byte % 2)
25047
25999
  waku2.relay = true;
@@ -25084,6 +26036,18 @@ class RawEnr extends Map {
25084
26036
  throw new Error(ERR_INVALID_ID);
25085
26037
  }
25086
26038
  }
26039
+ get rs() {
26040
+ const rs = this.get("rs");
26041
+ if (!rs)
26042
+ return undefined;
26043
+ return decodeRelayShard(rs);
26044
+ }
26045
+ get rsv() {
26046
+ const rsv = this.get("rsv");
26047
+ if (!rsv)
26048
+ return undefined;
26049
+ return decodeRelayShard(rsv);
26050
+ }
25087
26051
  get ip() {
25088
26052
  return getStringValue(this, "ip", "ip4");
25089
26053
  }
@@ -25198,7 +26162,7 @@ function deleteUndefined(map, key, value, transform) {
25198
26162
 
25199
26163
  async function sign(privKey, msg) {
25200
26164
  return sign$3(keccak256(msg), privKey, {
25201
- der: false,
26165
+ der: false
25202
26166
  });
25203
26167
  }
25204
26168
  function nodeId(pubKey) {
@@ -25245,6 +26209,12 @@ class ENR extends RawEnr {
25245
26209
  }
25246
26210
  }
25247
26211
  getLocationMultiaddr = locationMultiaddrFromEnrFields.bind({}, this);
26212
+ get shardInfo() {
26213
+ if (this.rs && this.rsv) {
26214
+ log("Warning: ENR contains both `rs` and `rsv` fields.");
26215
+ }
26216
+ return this.rs || this.rsv;
26217
+ }
25248
26218
  setLocationMultiaddr(multiaddr) {
25249
26219
  const protoNames = multiaddr.protoNames();
25250
26220
  if (protoNames.length !== 2 &&
@@ -25283,7 +26253,7 @@ class ENR extends RawEnr {
25283
26253
  return {
25284
26254
  id,
25285
26255
  multiaddrs: this.getAllLocationMultiaddrs(),
25286
- protocols: [],
26256
+ protocols: []
25287
26257
  };
25288
26258
  }
25289
26259
  /**
@@ -25345,7 +26315,7 @@ class EnrCreator {
25345
26315
  return ENR.create({
25346
26316
  ...kvs,
25347
26317
  id: utf8ToBytes("v4"),
25348
- secp256k1: publicKey,
26318
+ secp256k1: publicKey
25349
26319
  });
25350
26320
  }
25351
26321
  static async fromPeerId(peerId, kvs = {}) {
@@ -25988,7 +26958,7 @@ class EnrDecoder {
25988
26958
  if (!encoded.startsWith(ENR.RECORD_PREFIX)) {
25989
26959
  throw new Error(`"string encoded ENR must start with '${ENR.RECORD_PREFIX}'`);
25990
26960
  }
25991
- return EnrDecoder.fromRLP(fromString$1(encoded.slice(4), "base64url"));
26961
+ return EnrDecoder.fromRLP(fromString(encoded.slice(4), "base64url"));
25992
26962
  }
25993
26963
  static fromRLP(encoded) {
25994
26964
  const decoded = decode(encoded).map(hexToBytes$2);
@@ -26040,4 +27010,4 @@ function checkSignature(seq, kvs, enr, signature) {
26040
27010
  }
26041
27011
  }
26042
27012
 
26043
- export { ENR, ERR_INVALID_ID, ERR_NO_SIGNATURE, EnrCreator, EnrDecoder, MAX_RECORD_SIZE, MULTIADDR_LENGTH_SIZE, TransportProtocol, TransportProtocolPerIpVersion, compressPublicKey$1 as compressPublicKey, createPeerIdFromPublicKey, decodeWaku2, encodeWaku2, getPrivateKeyFromPeerId, getPublicKeyFromPeerId, keccak256, sign$2 as sign, verifySignature };
27013
+ export { ENR, ERR_INVALID_ID, ERR_NO_SIGNATURE, EnrCreator, EnrDecoder, MAX_RECORD_SIZE, MULTIADDR_LENGTH_SIZE, TransportProtocol, TransportProtocolPerIpVersion, compressPublicKey$1 as compressPublicKey, createPeerIdFromPublicKey, decodeRelayShard, decodeWaku2, encodeRelayShard, encodeWaku2, getPrivateKeyFromPeerId, getPublicKeyFromPeerId, keccak256, sign$2 as sign, verifySignature };