@waku/enr 0.0.20-7eb3375.0 → 0.0.20

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
@@ -10,7 +10,7 @@ const MULTIADDR_LENGTH_SIZE = 2;
10
10
  * To guarantee Uint8Array semantics, convert nodejs Buffers
11
11
  * into vanilla Uint8Arrays
12
12
  */
13
- function asUint8Array(buf) {
13
+ function asUint8Array$1(buf) {
14
14
  if (globalThis.Buffer != null) {
15
15
  return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
16
16
  }
@@ -147,7 +147,7 @@ var _brrp__multiformats_scope_baseX = src;
147
147
  * @param {Uint8Array} aa
148
148
  * @param {Uint8Array} bb
149
149
  */
150
- const equals$2 = (aa, bb) => {
150
+ const equals$3 = (aa, bb) => {
151
151
  if (aa === bb) return true
152
152
  if (aa.byteLength !== bb.byteLength) {
153
153
  return false
@@ -179,13 +179,13 @@ const coerce = o => {
179
179
  * @param {string} str
180
180
  * @returns {Uint8Array}
181
181
  */
182
- const fromString$1 = str => (new TextEncoder()).encode(str);
182
+ const fromString$2 = str => (new TextEncoder()).encode(str);
183
183
 
184
184
  /**
185
185
  * @param {Uint8Array} b
186
186
  * @returns {string}
187
187
  */
188
- const toString$2 = b => (new TextDecoder()).decode(b);
188
+ const toString$3 = b => (new TextDecoder()).decode(b);
189
189
 
190
190
  /**
191
191
  * Class represents both BaseEncoder and MultibaseEncoder meaning it
@@ -793,8 +793,8 @@ var base8$1 = /*#__PURE__*/Object.freeze({
793
793
  const identity$1 = from$1({
794
794
  prefix: '\x00',
795
795
  name: 'identity',
796
- encode: (buf) => toString$2(buf),
797
- decode: (str) => fromString$1(str)
796
+ encode: (buf) => toString$3(buf),
797
+ decode: (str) => fromString$2(str)
798
798
  });
799
799
 
800
800
  var identityBase = /*#__PURE__*/Object.freeze({
@@ -974,7 +974,7 @@ const decode$2 = (multihash) => {
974
974
  * @param {unknown} b
975
975
  * @returns {b is MultihashDigest}
976
976
  */
977
- const equals$1 = (a, b) => {
977
+ const equals$2 = (a, b) => {
978
978
  if (a === b) {
979
979
  return true
980
980
  } else {
@@ -984,7 +984,7 @@ const equals$1 = (a, b) => {
984
984
  a.code === data.code &&
985
985
  a.size === data.size &&
986
986
  data.bytes instanceof Uint8Array &&
987
- equals$2(a.bytes, data.bytes)
987
+ equals$3(a.bytes, data.bytes)
988
988
  )
989
989
  }
990
990
  };
@@ -1287,7 +1287,7 @@ class CID {
1287
1287
  unknown &&
1288
1288
  self.code === unknown.code &&
1289
1289
  self.version === unknown.version &&
1290
- equals$1(self.multihash, unknown.multihash)
1290
+ equals$2(self.multihash, unknown.multihash)
1291
1291
  )
1292
1292
  }
1293
1293
 
@@ -1692,14 +1692,14 @@ const bases = { ...identityBase, ...base2$1, ...base8$1, ...base10$1, ...base16$
1692
1692
  * uninitialized memory. Only use if you are certain you will immediately
1693
1693
  * overwrite every value in the returned `Uint8Array`.
1694
1694
  */
1695
- function allocUnsafe(size = 0) {
1695
+ function allocUnsafe$1(size = 0) {
1696
1696
  if (globalThis.Buffer?.allocUnsafe != null) {
1697
- return asUint8Array(globalThis.Buffer.allocUnsafe(size));
1697
+ return asUint8Array$1(globalThis.Buffer.allocUnsafe(size));
1698
1698
  }
1699
1699
  return new Uint8Array(size);
1700
1700
  }
1701
1701
 
1702
- function createCodec$1(name, prefix, encode, decode) {
1702
+ function createCodec$2(name, prefix, encode, decode) {
1703
1703
  return {
1704
1704
  name,
1705
1705
  prefix,
@@ -1713,14 +1713,14 @@ function createCodec$1(name, prefix, encode, decode) {
1713
1713
  }
1714
1714
  };
1715
1715
  }
1716
- const string = createCodec$1('utf8', 'u', (buf) => {
1716
+ const string$1 = createCodec$2('utf8', 'u', (buf) => {
1717
1717
  const decoder = new TextDecoder('utf8');
1718
1718
  return 'u' + decoder.decode(buf);
1719
1719
  }, (str) => {
1720
1720
  const encoder = new TextEncoder();
1721
1721
  return encoder.encode(str.substring(1));
1722
1722
  });
1723
- const ascii = createCodec$1('ascii', 'a', (buf) => {
1723
+ const ascii$1 = createCodec$2('ascii', 'a', (buf) => {
1724
1724
  let string = 'a';
1725
1725
  for (let i = 0; i < buf.length; i++) {
1726
1726
  string += String.fromCharCode(buf[i]);
@@ -1728,19 +1728,19 @@ const ascii = createCodec$1('ascii', 'a', (buf) => {
1728
1728
  return string;
1729
1729
  }, (str) => {
1730
1730
  str = str.substring(1);
1731
- const buf = allocUnsafe(str.length);
1731
+ const buf = allocUnsafe$1(str.length);
1732
1732
  for (let i = 0; i < str.length; i++) {
1733
1733
  buf[i] = str.charCodeAt(i);
1734
1734
  }
1735
1735
  return buf;
1736
1736
  });
1737
- const BASES = {
1738
- utf8: string,
1739
- 'utf-8': string,
1737
+ const BASES$1 = {
1738
+ utf8: string$1,
1739
+ 'utf-8': string$1,
1740
1740
  hex: bases.base16,
1741
- latin1: ascii,
1742
- ascii,
1743
- binary: ascii,
1741
+ latin1: ascii$1,
1742
+ ascii: ascii$1,
1743
+ binary: ascii$1,
1744
1744
  ...bases
1745
1745
  };
1746
1746
 
@@ -1751,13 +1751,13 @@ const BASES = {
1751
1751
  *
1752
1752
  * Also `ascii` which is similar to node's 'binary' encoding.
1753
1753
  */
1754
- function fromString(string, encoding = 'utf8') {
1755
- const base = BASES[encoding];
1754
+ function fromString$1(string, encoding = 'utf8') {
1755
+ const base = BASES$1[encoding];
1756
1756
  if (base == null) {
1757
1757
  throw new Error(`Unsupported encoding "${encoding}"`);
1758
1758
  }
1759
1759
  if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
1760
- return asUint8Array(globalThis.Buffer.from(string, 'utf-8'));
1760
+ return asUint8Array$1(globalThis.Buffer.from(string, 'utf-8'));
1761
1761
  }
1762
1762
  // add multibase prefix
1763
1763
  return base.decoder.decode(`${base.prefix}${string}`); // eslint-disable-line @typescript-eslint/restrict-template-expressions
@@ -1770,8 +1770,8 @@ function fromString(string, encoding = 'utf8') {
1770
1770
  *
1771
1771
  * Also `ascii` which is similar to node's 'binary' encoding.
1772
1772
  */
1773
- function toString$1(array, encoding = 'utf8') {
1774
- const base = BASES[encoding];
1773
+ function toString$2(array, encoding = 'utf8') {
1774
+ const base = BASES$1[encoding];
1775
1775
  if (base == null) {
1776
1776
  throw new Error(`Unsupported encoding "${encoding}"`);
1777
1777
  }
@@ -1790,26 +1790,26 @@ function toString$1(array, encoding = 'utf8') {
1790
1790
  function hexToBytes$2(hex) {
1791
1791
  if (typeof hex === "string") {
1792
1792
  const _hex = hex.replace(/^0x/i, "");
1793
- return fromString(_hex.toLowerCase(), "base16");
1793
+ return fromString$1(_hex.toLowerCase(), "base16");
1794
1794
  }
1795
1795
  return hex;
1796
1796
  }
1797
1797
  /**
1798
1798
  * Convert byte array to hex string (no `0x` prefix).
1799
1799
  */
1800
- const bytesToHex$2 = (bytes) => toString$1(bytes, "base16");
1800
+ const bytesToHex$2 = (bytes) => toString$2(bytes, "base16");
1801
1801
  /**
1802
1802
  * Decode byte array to utf-8 string.
1803
1803
  */
1804
- const bytesToUtf8 = (b) => toString$1(b, "utf8");
1804
+ const bytesToUtf8 = (b) => toString$2(b, "utf8");
1805
1805
  /**
1806
1806
  * Encode utf-8 string to byte array.
1807
1807
  */
1808
- const utf8ToBytes$2 = (s) => fromString(s, "utf8");
1808
+ const utf8ToBytes$2 = (s) => fromString$1(s, "utf8");
1809
1809
  /**
1810
1810
  * Concatenate using Uint8Arrays as `Buffer` has a different behavior with `DataView`
1811
1811
  */
1812
- function concat$1(byteArrays, totalLength) {
1812
+ function concat$2(byteArrays, totalLength) {
1813
1813
  const len = totalLength ?? byteArrays.reduce((acc, curr) => acc + curr.length, 0);
1814
1814
  const res = new Uint8Array(len);
1815
1815
  let offset = 0;
@@ -3559,14 +3559,14 @@ async function sign$1(message, privateKey) {
3559
3559
  recovered: true,
3560
3560
  der: false
3561
3561
  });
3562
- return concat$1([signature, new Uint8Array([recoveryId])], signature.length + 1);
3562
+ return concat$2([signature, new Uint8Array([recoveryId])], signature.length + 1);
3563
3563
  }
3564
3564
  function keccak256(input) {
3565
3565
  return new Uint8Array(sha3.keccak256.arrayBuffer(input));
3566
3566
  }
3567
3567
  function compressPublicKey$1(publicKey) {
3568
3568
  if (publicKey.length === 64) {
3569
- publicKey = concat$1([new Uint8Array([4]), publicKey], 65);
3569
+ publicKey = concat$2([new Uint8Array([4]), publicKey], 65);
3570
3570
  }
3571
3571
  const point = Point.fromHex(publicKey);
3572
3572
  return point.toRawBytes(true);
@@ -3912,6 +3912,85 @@ class SHA256 extends SHA2 {
3912
3912
  */
3913
3913
  const sha256$1 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
3914
3914
 
3915
+ var Protocols;
3916
+ (function (Protocols) {
3917
+ Protocols["Relay"] = "relay";
3918
+ Protocols["Store"] = "store";
3919
+ Protocols["LightPush"] = "lightpush";
3920
+ Protocols["Filter"] = "filter";
3921
+ })(Protocols || (Protocols = {}));
3922
+ var SendError;
3923
+ (function (SendError) {
3924
+ /** Could not determine the origin of the fault. Best to check connectivity and try again */
3925
+ SendError["GENERIC_FAIL"] = "Generic error";
3926
+ /**
3927
+ * Failure to protobuf encode the message. This is not recoverable and needs
3928
+ * further investigation.
3929
+ */
3930
+ SendError["ENCODE_FAILED"] = "Failed to encode";
3931
+ /**
3932
+ * Failure to protobuf decode the message. May be due to a remote peer issue,
3933
+ * ensuring that messages are sent via several peer enable mitigation of this error.
3934
+ */
3935
+ SendError["DECODE_FAILED"] = "Failed to decode";
3936
+ /**
3937
+ * The message payload is empty, making the message invalid. Ensure that a non-empty
3938
+ * payload is set on the outgoing message.
3939
+ */
3940
+ SendError["EMPTY_PAYLOAD"] = "Payload is empty";
3941
+ /**
3942
+ * The message size is above the maximum message size allowed on the Waku Network.
3943
+ * Compressing the message or using an alternative strategy for large messages is recommended.
3944
+ */
3945
+ SendError["SIZE_TOO_BIG"] = "Size is too big";
3946
+ /**
3947
+ * The PubsubTopic passed to the send function is not configured on the Waku node.
3948
+ * Please ensure that the PubsubTopic is used when initializing the Waku node.
3949
+ */
3950
+ SendError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
3951
+ /**
3952
+ * Failure to find a peer with suitable protocols. This may due to a connection issue.
3953
+ * Mitigation can be: retrying after a given time period, display connectivity issue
3954
+ * to user or listening for `peer:connected:bootstrap` or `peer:connected:peer-exchange`
3955
+ * on the connection manager before retrying.
3956
+ */
3957
+ SendError["NO_PEER_AVAILABLE"] = "No peer available";
3958
+ /**
3959
+ * The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
3960
+ * or `DECODE_FAILED` can be used.
3961
+ */
3962
+ SendError["REMOTE_PEER_FAULT"] = "Remote peer fault";
3963
+ /**
3964
+ * The remote peer rejected the message. Information provided by the remote peer
3965
+ * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
3966
+ * or `DECODE_FAILED` can be used.
3967
+ */
3968
+ SendError["REMOTE_PEER_REJECTED"] = "Remote peer rejected";
3969
+ })(SendError || (SendError = {}));
3970
+
3971
+ var PageDirection;
3972
+ (function (PageDirection) {
3973
+ PageDirection["BACKWARD"] = "backward";
3974
+ PageDirection["FORWARD"] = "forward";
3975
+ })(PageDirection || (PageDirection = {}));
3976
+
3977
+ var Tags;
3978
+ (function (Tags) {
3979
+ Tags["BOOTSTRAP"] = "bootstrap";
3980
+ Tags["PEER_EXCHANGE"] = "peer-exchange";
3981
+ })(Tags || (Tags = {}));
3982
+ var EPeersByDiscoveryEvents;
3983
+ (function (EPeersByDiscoveryEvents) {
3984
+ EPeersByDiscoveryEvents["PEER_DISCOVERY_BOOTSTRAP"] = "peer:discovery:bootstrap";
3985
+ EPeersByDiscoveryEvents["PEER_DISCOVERY_PEER_EXCHANGE"] = "peer:discovery:peer-exchange";
3986
+ EPeersByDiscoveryEvents["PEER_CONNECT_BOOTSTRAP"] = "peer:connected:bootstrap";
3987
+ EPeersByDiscoveryEvents["PEER_CONNECT_PEER_EXCHANGE"] = "peer:connected:peer-exchange";
3988
+ })(EPeersByDiscoveryEvents || (EPeersByDiscoveryEvents = {}));
3989
+ var EConnectionStateEvents;
3990
+ (function (EConnectionStateEvents) {
3991
+ EConnectionStateEvents["CONNECTION_STATUS"] = "waku:connection";
3992
+ })(EConnectionStateEvents || (EConnectionStateEvents = {}));
3993
+
3915
3994
  var browser = {exports: {}};
3916
3995
 
3917
3996
  /**
@@ -4662,12 +4741,51 @@ let Logger$1 = class Logger {
4662
4741
  }
4663
4742
  };
4664
4743
 
4744
+ /**
4745
+ * On the producing side:
4746
+ * * Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields.
4747
+ *
4748
+ * On the consuming side:
4749
+ * * Enforce the fields to be present, reject otherwise.
4750
+ * * Propagate only if the fields are valid and signature can be verified, reject otherwise.
4751
+ */
4752
+ var TopicValidatorResult$1;
4753
+ (function (TopicValidatorResult) {
4754
+ /**
4755
+ * The message is considered valid, and it should be delivered and forwarded to the network
4756
+ */
4757
+ TopicValidatorResult["Accept"] = "accept";
4758
+ /**
4759
+ * The message is neither delivered nor forwarded to the network
4760
+ */
4761
+ TopicValidatorResult["Ignore"] = "ignore";
4762
+ /**
4763
+ * The message is considered invalid, and it should be rejected
4764
+ */
4765
+ TopicValidatorResult["Reject"] = "reject";
4766
+ })(TopicValidatorResult$1 || (TopicValidatorResult$1 = {}));
4767
+
4768
+ /**
4769
+ * Enum Transport Manager Fault Tolerance values
4770
+ */
4771
+ var FaultTolerance$1;
4772
+ (function (FaultTolerance) {
4773
+ /**
4774
+ * should be used for failing in any listen circumstance
4775
+ */
4776
+ FaultTolerance[FaultTolerance["FATAL_ALL"] = 0] = "FATAL_ALL";
4777
+ /**
4778
+ * should be used for not failing when not listening
4779
+ */
4780
+ FaultTolerance[FaultTolerance["NO_FATAL"] = 1] = "NO_FATAL";
4781
+ })(FaultTolerance$1 || (FaultTolerance$1 = {}));
4782
+
4665
4783
  /**
4666
4784
  * When this error is thrown it means an operation was aborted,
4667
4785
  * usually in response to the `abort` event being emitted by an
4668
4786
  * AbortSignal.
4669
4787
  */
4670
- class CodeError extends Error {
4788
+ let CodeError$1 = class CodeError extends Error {
4671
4789
  code;
4672
4790
  props;
4673
4791
  constructor(message, code, props) {
@@ -4676,12 +4794,12 @@ class CodeError extends Error {
4676
4794
  this.name = props?.name ?? 'CodeError';
4677
4795
  this.props = props ?? {}; // eslint-disable-line @typescript-eslint/consistent-type-assertions
4678
4796
  }
4679
- }
4797
+ };
4680
4798
 
4681
4799
  /**
4682
4800
  * Returns true if the two passed Uint8Arrays have the same content
4683
4801
  */
4684
- function equals(a, b) {
4802
+ function equals$1(a, b) {
4685
4803
  if (a === b) {
4686
4804
  return true;
4687
4805
  }
@@ -4903,7 +5021,7 @@ function decodeUint8ArrayList(buf, offset) {
4903
5021
  }
4904
5022
  function encode$1(value, buf, offset = 0) {
4905
5023
  if (buf == null) {
4906
- buf = allocUnsafe(encodingLength(value));
5024
+ buf = allocUnsafe$1(encodingLength(value));
4907
5025
  }
4908
5026
  if (buf instanceof Uint8Array) {
4909
5027
  return encodeUint8Array(value, buf, offset);
@@ -4924,17 +5042,17 @@ function decode$1(buf, offset = 0) {
4924
5042
  /**
4925
5043
  * Returns a new Uint8Array created by concatenating the passed ArrayLikes
4926
5044
  */
4927
- function concat(arrays, length) {
5045
+ function concat$1(arrays, length) {
4928
5046
  if (length == null) {
4929
5047
  length = arrays.reduce((acc, curr) => acc + curr.length, 0);
4930
5048
  }
4931
- const output = allocUnsafe(length);
5049
+ const output = allocUnsafe$1(length);
4932
5050
  let offset = 0;
4933
5051
  for (const arr of arrays) {
4934
5052
  output.set(arr, offset);
4935
5053
  offset += arr.length;
4936
5054
  }
4937
- return asUint8Array(output);
5055
+ return asUint8Array$1(output);
4938
5056
  }
4939
5057
 
4940
5058
  /* eslint-disable @typescript-eslint/no-unsafe-return */
@@ -5207,10 +5325,10 @@ const toBytes = function (ip) {
5207
5325
  let v4Buffer;
5208
5326
  if (isv4) {
5209
5327
  v4Buffer = toBytes(sections[i]);
5210
- sections[i] = toString$1(v4Buffer.slice(0, 2), 'base16');
5328
+ sections[i] = toString$2(v4Buffer.slice(0, 2), 'base16');
5211
5329
  }
5212
5330
  if (v4Buffer != null && ++i < 8) {
5213
- sections.splice(i, 0, toString$1(v4Buffer.slice(2, 4), 'base16'));
5331
+ sections.splice(i, 0, toString$2(v4Buffer.slice(2, 4), 'base16'));
5214
5332
  }
5215
5333
  }
5216
5334
  if (sections[0] === '') {
@@ -5241,7 +5359,7 @@ const toBytes = function (ip) {
5241
5359
  throw new Error('invalid ip address');
5242
5360
  };
5243
5361
  // Copied from https://github.com/indutny/node-ip/blob/master/lib/ip.js#L63
5244
- const toString = function (buf, offset = 0, length) {
5362
+ const toString$1 = function (buf, offset = 0, length) {
5245
5363
  offset = ~~offset;
5246
5364
  length = length ?? (buf.length - offset);
5247
5365
  const view = new DataView(buf.buffer);
@@ -5397,7 +5515,7 @@ function convertToString(proto, buf) {
5397
5515
  case 466: // certhash
5398
5516
  return bytes2mb(buf);
5399
5517
  default:
5400
- return toString$1(buf, 'base16'); // no clue. convert to hex
5518
+ return toString$2(buf, 'base16'); // no clue. convert to hex
5401
5519
  }
5402
5520
  }
5403
5521
  function convertToBytes(proto, str) {
@@ -5431,7 +5549,7 @@ function convertToBytes(proto, str) {
5431
5549
  case 466: // certhash
5432
5550
  return mb2bytes(str);
5433
5551
  default:
5434
- return fromString(str, 'base16'); // no clue. convert from hex
5552
+ return fromString$1(str, 'base16'); // no clue. convert from hex
5435
5553
  }
5436
5554
  }
5437
5555
  const decoders = Object.values(bases).map((c) => c.decoder);
@@ -5447,7 +5565,7 @@ function ip2bytes(ipString) {
5447
5565
  return toBytes(ipString);
5448
5566
  }
5449
5567
  function bytes2ip(ipBuff) {
5450
- const ipString = toString(ipBuff, 0, ipBuff.length);
5568
+ const ipString = toString$1(ipBuff, 0, ipBuff.length);
5451
5569
  if (ipString == null) {
5452
5570
  throw new Error('ipBuff is required');
5453
5571
  }
@@ -5467,9 +5585,9 @@ function bytes2port(buf) {
5467
5585
  return view.getUint16(buf.byteOffset);
5468
5586
  }
5469
5587
  function str2bytes(str) {
5470
- const buf = fromString(str);
5588
+ const buf = fromString$1(str);
5471
5589
  const size = Uint8Array.from(encode$1(buf.length));
5472
- return concat([size, buf], size.length + buf.length);
5590
+ return concat$1([size, buf], size.length + buf.length);
5473
5591
  }
5474
5592
  function bytes2str(buf) {
5475
5593
  const size = decode$1(buf);
@@ -5477,7 +5595,7 @@ function bytes2str(buf) {
5477
5595
  if (buf.length !== size) {
5478
5596
  throw new Error('inconsistent lengths');
5479
5597
  }
5480
- return toString$1(buf);
5598
+ return toString$2(buf);
5481
5599
  }
5482
5600
  function mh2bytes(hash) {
5483
5601
  let mh;
@@ -5489,12 +5607,12 @@ function mh2bytes(hash) {
5489
5607
  }
5490
5608
  // the address is a varint prefixed multihash string representation
5491
5609
  const size = Uint8Array.from(encode$1(mh.length));
5492
- return concat([size, mh], size.length + mh.length);
5610
+ return concat$1([size, mh], size.length + mh.length);
5493
5611
  }
5494
5612
  function mb2bytes(mbstr) {
5495
5613
  const mb = anybaseDecoder.decode(mbstr);
5496
5614
  const size = Uint8Array.from(encode$1(mb.length));
5497
- return concat([size, mb], size.length + mb.length);
5615
+ return concat$1([size, mb], size.length + mb.length);
5498
5616
  }
5499
5617
  function bytes2mb(buf) {
5500
5618
  const size = decode$1(buf);
@@ -5502,7 +5620,7 @@ function bytes2mb(buf) {
5502
5620
  if (hash.length !== size) {
5503
5621
  throw new Error('inconsistent lengths');
5504
5622
  }
5505
- return 'u' + toString$1(hash, 'base64url');
5623
+ return 'u' + toString$2(hash, 'base64url');
5506
5624
  }
5507
5625
  /**
5508
5626
  * Converts bytes to bas58btc string
@@ -5513,7 +5631,7 @@ function bytes2mh(buf) {
5513
5631
  if (address.length !== size) {
5514
5632
  throw new Error('inconsistent lengths');
5515
5633
  }
5516
- return toString$1(address, 'base58btc');
5634
+ return toString$2(address, 'base58btc');
5517
5635
  }
5518
5636
  function onion2bytes(str) {
5519
5637
  const addr = str.split(':');
@@ -5531,7 +5649,7 @@ function onion2bytes(str) {
5531
5649
  throw new Error('Port number is not in range(1, 65536)');
5532
5650
  }
5533
5651
  const portBuf = port2bytes(port);
5534
- return concat([buf, portBuf], buf.length + portBuf.length);
5652
+ return concat$1([buf, portBuf], buf.length + portBuf.length);
5535
5653
  }
5536
5654
  function onion32bytes(str) {
5537
5655
  const addr = str.split(':');
@@ -5549,12 +5667,12 @@ function onion32bytes(str) {
5549
5667
  throw new Error('Port number is not in range(1, 65536)');
5550
5668
  }
5551
5669
  const portBuf = port2bytes(port);
5552
- return concat([buf, portBuf], buf.length + portBuf.length);
5670
+ return concat$1([buf, portBuf], buf.length + portBuf.length);
5553
5671
  }
5554
5672
  function bytes2onion(buf) {
5555
5673
  const addrBytes = buf.slice(0, buf.length - 2);
5556
5674
  const portBytes = buf.slice(buf.length - 2);
5557
- const addr = toString$1(addrBytes, 'base32');
5675
+ const addr = toString$2(addrBytes, 'base32');
5558
5676
  const port = bytes2port(portBytes);
5559
5677
  return `${addr}:${port}`;
5560
5678
  }
@@ -5629,7 +5747,7 @@ function bytesToMultiaddrParts(bytes) {
5629
5747
  const addr = bytes.slice(i + n, i + n + size);
5630
5748
  i += (size + n);
5631
5749
  if (i > bytes.length) { // did not end _exactly_ at buffer.length
5632
- throw ParseError('Invalid address Uint8Array: ' + toString$1(bytes, 'base16'));
5750
+ throw ParseError('Invalid address Uint8Array: ' + toString$2(bytes, 'base16'));
5633
5751
  }
5634
5752
  // ok, tuple seems good.
5635
5753
  tuples.push([code, addr]);
@@ -5670,11 +5788,11 @@ function stringTuplesToString(tuples) {
5670
5788
  * [[int code, Uint8Array ]... ] -> Uint8Array
5671
5789
  */
5672
5790
  function tuplesToBytes(tuples) {
5673
- return concat(tuples.map((tup) => {
5791
+ return concat$1(tuples.map((tup) => {
5674
5792
  const proto = getProtocol(tup[0]);
5675
5793
  let buf = Uint8Array.from(encode$1(proto.code));
5676
5794
  if (tup.length > 1 && tup[1] != null) {
5677
- buf = concat([buf, tup[1]]); // add address buffer
5795
+ buf = concat$1([buf, tup[1]]); // add address buffer
5678
5796
  }
5679
5797
  return buf;
5680
5798
  }));
@@ -5715,38 +5833,17 @@ function ParseError(str) {
5715
5833
  * ```
5716
5834
  */
5717
5835
  const inspect$1 = Symbol.for('nodejs.util.inspect.custom');
5836
+ const symbol$1 = Symbol.for('@multiformats/js-multiaddr/multiaddr');
5718
5837
  const DNS_CODES = [
5719
5838
  getProtocol('dns').code,
5720
5839
  getProtocol('dns4').code,
5721
5840
  getProtocol('dns6').code,
5722
5841
  getProtocol('dnsaddr').code
5723
5842
  ];
5724
- /**
5725
- * All configured {@link Resolver}s
5726
- */
5727
- const resolvers = new Map();
5728
- const symbol$1 = Symbol.for('@multiformats/js-multiaddr/multiaddr');
5729
- /**
5730
- * Check if object is a {@link Multiaddr} instance
5731
- *
5732
- * @example
5733
- *
5734
- * ```js
5735
- * import { isMultiaddr, multiaddr } from '@multiformats/multiaddr'
5736
- *
5737
- * isMultiaddr(5)
5738
- * // false
5739
- * isMultiaddr(multiaddr('/ip4/127.0.0.1'))
5740
- * // true
5741
- * ```
5742
- */
5743
- function isMultiaddr(value) {
5744
- return Boolean(value?.[symbol$1]);
5745
- }
5746
5843
  /**
5747
5844
  * Creates a {@link Multiaddr} from a {@link MultiaddrInput}
5748
5845
  */
5749
- class DefaultMultiaddr {
5846
+ class Multiaddr {
5750
5847
  bytes;
5751
5848
  #string;
5752
5849
  #tuples;
@@ -5846,8 +5943,8 @@ class DefaultMultiaddr {
5846
5943
  return this.#stringTuples;
5847
5944
  }
5848
5945
  encapsulate(addr) {
5849
- addr = new DefaultMultiaddr(addr);
5850
- return new DefaultMultiaddr(this.toString() + addr.toString());
5946
+ addr = new Multiaddr(addr);
5947
+ return new Multiaddr(this.toString() + addr.toString());
5851
5948
  }
5852
5949
  decapsulate(addr) {
5853
5950
  const addrString = addr.toString();
@@ -5856,13 +5953,13 @@ class DefaultMultiaddr {
5856
5953
  if (i < 0) {
5857
5954
  throw new Error(`Address ${this.toString()} does not contain subaddress: ${addr.toString()}`);
5858
5955
  }
5859
- return new DefaultMultiaddr(s.slice(0, i));
5956
+ return new Multiaddr(s.slice(0, i));
5860
5957
  }
5861
5958
  decapsulateCode(code) {
5862
5959
  const tuples = this.tuples();
5863
5960
  for (let i = tuples.length - 1; i >= 0; i--) {
5864
5961
  if (tuples[i][0] === code) {
5865
- return new DefaultMultiaddr(tuplesToBytes(tuples.slice(0, i)));
5962
+ return new Multiaddr(tuplesToBytes(tuples.slice(0, i)));
5866
5963
  }
5867
5964
  }
5868
5965
  return this;
@@ -5887,10 +5984,10 @@ class DefaultMultiaddr {
5887
5984
  // peer id is base58btc encoded string but not multibase encoded so add the `z`
5888
5985
  // prefix so we can validate that it is correctly encoded
5889
5986
  if (peerIdStr[0] === 'Q' || peerIdStr[0] === '1') {
5890
- return toString$1(base58btc.decode(`z${peerIdStr}`), 'base58btc');
5987
+ return toString$2(base58btc.decode(`z${peerIdStr}`), 'base58btc');
5891
5988
  }
5892
5989
  // try to parse peer id as CID
5893
- return toString$1(CID.parse(peerIdStr).multihash.bytes, 'base58btc');
5990
+ return toString$2(CID.parse(peerIdStr).multihash.bytes, 'base58btc');
5894
5991
  }
5895
5992
  return null;
5896
5993
  }
@@ -5902,7 +5999,7 @@ class DefaultMultiaddr {
5902
5999
  return this.#path;
5903
6000
  }
5904
6001
  equals(addr) {
5905
- return equals(this.bytes, addr.bytes);
6002
+ return equals$1(this.bytes, addr.bytes);
5906
6003
  }
5907
6004
  async resolve(options) {
5908
6005
  const resolvableProto = this.protos().find((p) => p.resolvable);
@@ -5912,10 +6009,10 @@ class DefaultMultiaddr {
5912
6009
  }
5913
6010
  const resolver = resolvers.get(resolvableProto.name);
5914
6011
  if (resolver == null) {
5915
- throw new CodeError(`no available resolver for ${resolvableProto.name}`, 'ERR_NO_AVAILABLE_RESOLVER');
6012
+ throw new CodeError$1(`no available resolver for ${resolvableProto.name}`, 'ERR_NO_AVAILABLE_RESOLVER');
5916
6013
  }
5917
6014
  const addresses = await resolver(this, options);
5918
- return addresses.map((a) => new DefaultMultiaddr(a));
6015
+ return addresses.map((a) => new Multiaddr(a));
5919
6016
  }
5920
6017
  nodeAddress() {
5921
6018
  const options = this.toOptions();
@@ -5957,6 +6054,93 @@ class DefaultMultiaddr {
5957
6054
  return `Multiaddr(${this.#string})`;
5958
6055
  }
5959
6056
  }
6057
+
6058
+ /**
6059
+ * @packageDocumentation
6060
+ *
6061
+ * A standard way to represent addresses that
6062
+ *
6063
+ * - support any standard network protocol
6064
+ * - are self-describing
6065
+ * - have a binary packed format
6066
+ * - have a nice string representation
6067
+ * - encapsulate well
6068
+ *
6069
+ * @example
6070
+ *
6071
+ * ```js
6072
+ * import { multiaddr } from '@multiformats/multiaddr'
6073
+ * const addr = multiaddr("/ip4/127.0.0.1/udp/1234")
6074
+ * // Multiaddr(/ip4/127.0.0.1/udp/1234)
6075
+ *
6076
+ * const addr = multiaddr("/ip4/127.0.0.1/udp/1234")
6077
+ * // Multiaddr(/ip4/127.0.0.1/udp/1234)
6078
+ *
6079
+ * addr.bytes
6080
+ * // <Uint8Array 04 7f 00 00 01 11 04 d2>
6081
+ *
6082
+ * addr.toString()
6083
+ * // '/ip4/127.0.0.1/udp/1234'
6084
+ *
6085
+ * addr.protos()
6086
+ * // [
6087
+ * // {code: 4, name: 'ip4', size: 32},
6088
+ * // {code: 273, name: 'udp', size: 16}
6089
+ * // ]
6090
+ *
6091
+ * // gives you an object that is friendly with what Node.js core modules expect for addresses
6092
+ * addr.nodeAddress()
6093
+ * // {
6094
+ * // family: 4,
6095
+ * // port: 1234,
6096
+ * // address: "127.0.0.1"
6097
+ * // }
6098
+ *
6099
+ * addr.encapsulate('/sctp/5678')
6100
+ * // Multiaddr(/ip4/127.0.0.1/udp/1234/sctp/5678)
6101
+ * ```
6102
+ *
6103
+ * ## Resolvers
6104
+ *
6105
+ * `multiaddr` allows multiaddrs to be resolved when appropriate resolvers are provided. This module already has resolvers available, but you can also create your own. Resolvers should always be set in the same module that is calling `multiaddr.resolve()` to avoid conflicts if multiple versions of `multiaddr` are in your dependency tree.
6106
+ *
6107
+ * To provide multiaddr resolvers you can do:
6108
+ *
6109
+ * ```js
6110
+ * import { resolvers } from '@multiformats/multiaddr'
6111
+ *
6112
+ * resolvers.set('dnsaddr', resolvers.dnsaddrResolver)
6113
+ * ```
6114
+ *
6115
+ * The available resolvers are:
6116
+ *
6117
+ * | Name | type | Description |
6118
+ * | ----------------- | --------- | ----------------------------------- |
6119
+ * | `dnsaddrResolver` | `dnsaddr` | dnsaddr resolution with TXT Records |
6120
+ *
6121
+ * A resolver receives a `Multiaddr` as a parameter and returns a `Promise<Array<string>>`.
6122
+ */
6123
+ /**
6124
+ * All configured {@link Resolver}s
6125
+ */
6126
+ const resolvers = new Map();
6127
+ /**
6128
+ * Check if object is a {@link Multiaddr} instance
6129
+ *
6130
+ * @example
6131
+ *
6132
+ * ```js
6133
+ * import { isMultiaddr, multiaddr } from '@multiformats/multiaddr'
6134
+ *
6135
+ * isMultiaddr(5)
6136
+ * // false
6137
+ * isMultiaddr(multiaddr('/ip4/127.0.0.1'))
6138
+ * // true
6139
+ * ```
6140
+ */
6141
+ function isMultiaddr(value) {
6142
+ return Boolean(value?.[symbol$1]);
6143
+ }
5960
6144
  /**
5961
6145
  * A function that takes a {@link MultiaddrInput} and returns a {@link Multiaddr}
5962
6146
  *
@@ -5971,7 +6155,7 @@ class DefaultMultiaddr {
5971
6155
  * @param {MultiaddrInput} [addr] - If String or Uint8Array, needs to adhere to the address format of a [multiaddr](https://github.com/multiformats/multiaddr#string-format)
5972
6156
  */
5973
6157
  function multiaddr(addr) {
5974
- return new DefaultMultiaddr(addr);
6158
+ return new Multiaddr(addr);
5975
6159
  }
5976
6160
 
5977
6161
  function multiaddrFromFields(ipFamily, protocol, ipBytes, protocolBytes) {
@@ -20367,6 +20551,242 @@ function createPbkdf2Params(salt, countBytes, dkLen, prfAlgorithm) {
20367
20551
  return params;
20368
20552
  }
20369
20553
 
20554
+ /**
20555
+ * On the producing side:
20556
+ * * Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields.
20557
+ *
20558
+ * On the consuming side:
20559
+ * * Enforce the fields to be present, reject otherwise.
20560
+ * * Propagate only if the fields are valid and signature can be verified, reject otherwise.
20561
+ */
20562
+ var TopicValidatorResult;
20563
+ (function (TopicValidatorResult) {
20564
+ /**
20565
+ * The message is considered valid, and it should be delivered and forwarded to the network
20566
+ */
20567
+ TopicValidatorResult["Accept"] = "accept";
20568
+ /**
20569
+ * The message is neither delivered nor forwarded to the network
20570
+ */
20571
+ TopicValidatorResult["Ignore"] = "ignore";
20572
+ /**
20573
+ * The message is considered invalid, and it should be rejected
20574
+ */
20575
+ TopicValidatorResult["Reject"] = "reject";
20576
+ })(TopicValidatorResult || (TopicValidatorResult = {}));
20577
+
20578
+ /**
20579
+ * Enum Transport Manager Fault Tolerance values
20580
+ */
20581
+ var FaultTolerance;
20582
+ (function (FaultTolerance) {
20583
+ /**
20584
+ * should be used for failing in any listen circumstance
20585
+ */
20586
+ FaultTolerance[FaultTolerance["FATAL_ALL"] = 0] = "FATAL_ALL";
20587
+ /**
20588
+ * should be used for not failing when not listening
20589
+ */
20590
+ FaultTolerance[FaultTolerance["NO_FATAL"] = 1] = "NO_FATAL";
20591
+ })(FaultTolerance || (FaultTolerance = {}));
20592
+
20593
+ /**
20594
+ * When this error is thrown it means an operation was aborted,
20595
+ * usually in response to the `abort` event being emitted by an
20596
+ * AbortSignal.
20597
+ */
20598
+ class CodeError extends Error {
20599
+ code;
20600
+ props;
20601
+ constructor(message, code, props) {
20602
+ super(message);
20603
+ this.code = code;
20604
+ this.name = props?.name ?? 'CodeError';
20605
+ this.props = props ?? {}; // eslint-disable-line @typescript-eslint/consistent-type-assertions
20606
+ }
20607
+ }
20608
+
20609
+ /**
20610
+ * To guarantee Uint8Array semantics, convert nodejs Buffers
20611
+ * into vanilla Uint8Arrays
20612
+ */
20613
+ function asUint8Array(buf) {
20614
+ if (globalThis.Buffer != null) {
20615
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
20616
+ }
20617
+ return buf;
20618
+ }
20619
+
20620
+ /**
20621
+ * Where possible returns a Uint8Array of the requested size that references
20622
+ * uninitialized memory. Only use if you are certain you will immediately
20623
+ * overwrite every value in the returned `Uint8Array`.
20624
+ */
20625
+ function allocUnsafe(size = 0) {
20626
+ if (globalThis.Buffer?.allocUnsafe != null) {
20627
+ return asUint8Array(globalThis.Buffer.allocUnsafe(size));
20628
+ }
20629
+ return new Uint8Array(size);
20630
+ }
20631
+
20632
+ function createCodec$1(name, prefix, encode, decode) {
20633
+ return {
20634
+ name,
20635
+ prefix,
20636
+ encoder: {
20637
+ name,
20638
+ prefix,
20639
+ encode
20640
+ },
20641
+ decoder: {
20642
+ decode
20643
+ }
20644
+ };
20645
+ }
20646
+ const string = createCodec$1('utf8', 'u', (buf) => {
20647
+ const decoder = new TextDecoder('utf8');
20648
+ return 'u' + decoder.decode(buf);
20649
+ }, (str) => {
20650
+ const encoder = new TextEncoder();
20651
+ return encoder.encode(str.substring(1));
20652
+ });
20653
+ const ascii = createCodec$1('ascii', 'a', (buf) => {
20654
+ let string = 'a';
20655
+ for (let i = 0; i < buf.length; i++) {
20656
+ string += String.fromCharCode(buf[i]);
20657
+ }
20658
+ return string;
20659
+ }, (str) => {
20660
+ str = str.substring(1);
20661
+ const buf = allocUnsafe(str.length);
20662
+ for (let i = 0; i < str.length; i++) {
20663
+ buf[i] = str.charCodeAt(i);
20664
+ }
20665
+ return buf;
20666
+ });
20667
+ const BASES = {
20668
+ utf8: string,
20669
+ 'utf-8': string,
20670
+ hex: bases.base16,
20671
+ latin1: ascii,
20672
+ ascii,
20673
+ binary: ascii,
20674
+ ...bases
20675
+ };
20676
+
20677
+ /**
20678
+ * Create a `Uint8Array` from the passed string
20679
+ *
20680
+ * Supports `utf8`, `utf-8`, `hex`, and any encoding supported by the multiformats module.
20681
+ *
20682
+ * Also `ascii` which is similar to node's 'binary' encoding.
20683
+ */
20684
+ function fromString(string, encoding = 'utf8') {
20685
+ const base = BASES[encoding];
20686
+ if (base == null) {
20687
+ throw new Error(`Unsupported encoding "${encoding}"`);
20688
+ }
20689
+ if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
20690
+ return asUint8Array(globalThis.Buffer.from(string, 'utf-8'));
20691
+ }
20692
+ // add multibase prefix
20693
+ return base.decoder.decode(`${base.prefix}${string}`); // eslint-disable-line @typescript-eslint/restrict-template-expressions
20694
+ }
20695
+
20696
+ /**
20697
+ * Returns true if the two passed Uint8Arrays have the same content
20698
+ */
20699
+ function equals(a, b) {
20700
+ if (a === b) {
20701
+ return true;
20702
+ }
20703
+ if (a.byteLength !== b.byteLength) {
20704
+ return false;
20705
+ }
20706
+ for (let i = 0; i < a.byteLength; i++) {
20707
+ if (a[i] !== b[i]) {
20708
+ return false;
20709
+ }
20710
+ }
20711
+ return true;
20712
+ }
20713
+
20714
+ /**
20715
+ * Returns a new Uint8Array created by concatenating the passed Uint8Arrays
20716
+ */
20717
+ function concat(arrays, length) {
20718
+ if (globalThis.Buffer != null) {
20719
+ return asUint8Array(globalThis.Buffer.concat(arrays, length));
20720
+ }
20721
+ if (length == null) {
20722
+ length = arrays.reduce((acc, curr) => acc + curr.length, 0);
20723
+ }
20724
+ const output = allocUnsafe(length);
20725
+ let offset = 0;
20726
+ for (const arr of arrays) {
20727
+ output.set(arr, offset);
20728
+ offset += arr.length;
20729
+ }
20730
+ return asUint8Array(output);
20731
+ }
20732
+
20733
+ /**
20734
+ * Turns a `Uint8Array` into a string.
20735
+ *
20736
+ * Supports `utf8`, `utf-8` and any encoding supported by the multibase module.
20737
+ *
20738
+ * Also `ascii` which is similar to node's 'binary' encoding.
20739
+ */
20740
+ function toString(array, encoding = 'utf8') {
20741
+ const base = BASES[encoding];
20742
+ if (base == null) {
20743
+ throw new Error(`Unsupported encoding "${encoding}"`);
20744
+ }
20745
+ if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
20746
+ return globalThis.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString('utf8');
20747
+ }
20748
+ // strip multibase prefix
20749
+ return base.encoder.encode(array).substring(1);
20750
+ }
20751
+
20752
+ function bigIntegerToUintBase64url(num, len) {
20753
+ // Call `.abs()` to convert to unsigned
20754
+ let buf = Uint8Array.from(num.abs().toByteArray()); // toByteArray converts to big endian
20755
+ // toByteArray() gives us back a signed array, which will include a leading 0
20756
+ // byte if the most significant bit of the number is 1:
20757
+ // https://docs.microsoft.com/en-us/windows/win32/seccertenroll/about-integer
20758
+ // Our number will always be positive so we should remove the leading padding.
20759
+ buf = buf[0] === 0 ? buf.subarray(1) : buf;
20760
+ if (len != null) {
20761
+ if (buf.length > len)
20762
+ throw new Error('byte array longer than desired length');
20763
+ buf = concat([new Uint8Array(len - buf.length), buf]);
20764
+ }
20765
+ return toString(buf, 'base64url');
20766
+ }
20767
+ // Convert a base64url encoded string to a BigInteger
20768
+ function base64urlToBigInteger(str) {
20769
+ const buf = base64urlToBuffer(str);
20770
+ return new forge$n.jsbn.BigInteger(toString(buf, 'base16'), 16);
20771
+ }
20772
+ function base64urlToBuffer(str, len) {
20773
+ let buf = fromString(str, 'base64urlpad');
20774
+ if (len != null) {
20775
+ if (buf.length > len)
20776
+ throw new Error('byte array longer than desired length');
20777
+ buf = concat([new Uint8Array(len - buf.length), buf]);
20778
+ }
20779
+ return buf;
20780
+ }
20781
+ function isPromise(thing) {
20782
+ if (thing == null) {
20783
+ return false;
20784
+ }
20785
+ return typeof thing.then === 'function' &&
20786
+ typeof thing.catch === 'function' &&
20787
+ typeof thing.finally === 'function';
20788
+ }
20789
+
20370
20790
  const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
20371
20791
  const _32n = /* @__PURE__ */ BigInt(32);
20372
20792
  // We are not using BigUint64Array, because they are extremely slow as per 2022
@@ -21894,6 +22314,20 @@ const ed25519Defaults = {
21894
22314
  uvRatio,
21895
22315
  };
21896
22316
  const ed25519 = /* @__PURE__ */ twistedEdwards(ed25519Defaults);
22317
+ function ed25519_domain(data, ctx, phflag) {
22318
+ if (ctx.length > 255)
22319
+ throw new Error('Context is too big');
22320
+ return concatBytes$1(utf8ToBytes$1('SigEd25519 no Ed25519 collisions'), new Uint8Array([phflag ? 1 : 0, ctx.length]), ctx, data);
22321
+ }
22322
+ /* @__PURE__ */ twistedEdwards({
22323
+ ...ed25519Defaults,
22324
+ domain: ed25519_domain,
22325
+ });
22326
+ /* @__PURE__ */ twistedEdwards({
22327
+ ...ed25519Defaults,
22328
+ domain: ed25519_domain,
22329
+ prehash: sha512$1,
22330
+ });
21897
22331
  // Hash To Curve Elligator2 Map (NOTE: different from ristretto255 elligator)
21898
22332
  // NOTE: very important part is usage of FpSqrtEven for ELL2_C1_EDWARDS, since
21899
22333
  // SageMath returns different root first and everything falls apart
@@ -21916,7 +22350,7 @@ BigInt('0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
21916
22350
  const PUBLIC_KEY_BYTE_LENGTH = 32;
21917
22351
  const PRIVATE_KEY_BYTE_LENGTH = 64; // private key is actually 32 bytes but for historical reasons we concat private and public keys
21918
22352
  const KEYS_BYTE_LENGTH = 32;
21919
- async function generateKey$2() {
22353
+ function generateKey$2() {
21920
22354
  // the actual private key (32 bytes)
21921
22355
  const privateKeyRaw = ed25519.utils.randomPrivateKey();
21922
22356
  const publicKey = ed25519.getPublicKey(privateKeyRaw);
@@ -21930,7 +22364,7 @@ async function generateKey$2() {
21930
22364
  /**
21931
22365
  * Generate keypair from a 32 byte uint8array
21932
22366
  */
21933
- async function generateKeyFromSeed(seed) {
22367
+ function generateKeyFromSeed(seed) {
21934
22368
  if (seed.length !== KEYS_BYTE_LENGTH) {
21935
22369
  throw new TypeError('"seed" must be 32 bytes in length.');
21936
22370
  }
@@ -21946,12 +22380,12 @@ async function generateKeyFromSeed(seed) {
21946
22380
  publicKey
21947
22381
  };
21948
22382
  }
21949
- async function hashAndSign$2(privateKey, msg) {
22383
+ function hashAndSign$2(privateKey, msg) {
21950
22384
  const privateKeyRaw = privateKey.subarray(0, KEYS_BYTE_LENGTH);
21951
- return ed25519.sign(msg, privateKeyRaw);
22385
+ return ed25519.sign(msg instanceof Uint8Array ? msg : msg.subarray(), privateKeyRaw);
21952
22386
  }
21953
- async function hashAndVerify$2(publicKey, sig, msg) {
21954
- return ed25519.verify(sig, msg, publicKey);
22387
+ function hashAndVerify$2(publicKey, sig, msg) {
22388
+ return ed25519.verify(sig, msg instanceof Uint8Array ? msg : msg.subarray(), publicKey);
21955
22389
  }
21956
22390
  function concatKeys(privateKeyRaw, publicKey) {
21957
22391
  const privateKey = new Uint8Array(PRIVATE_KEY_BYTE_LENGTH);
@@ -21973,7 +22407,7 @@ var webcrypto = {
21973
22407
  'The most likely cause of this error is that this page is being accessed ' +
21974
22408
  'from an insecure context (i.e. not HTTPS). For more information and ' +
21975
22409
  'possible resolutions see ' +
21976
- 'https://github.com/libp2p/js-libp2p-crypto/blob/master/README.md#web-crypto-api'), { code: 'ERR_MISSING_WEB_CRYPTO' });
22410
+ 'https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api'), { code: 'ERR_MISSING_WEB_CRYPTO' });
21977
22411
  }
21978
22412
  return nativeCrypto;
21979
22413
  }
@@ -24831,7 +25265,7 @@ class Ed25519PublicKey {
24831
25265
  constructor(key) {
24832
25266
  this._key = ensureKey(key, PUBLIC_KEY_BYTE_LENGTH);
24833
25267
  }
24834
- async verify(data, sig) {
25268
+ verify(data, sig) {
24835
25269
  return hashAndVerify$2(this._key, sig, data);
24836
25270
  }
24837
25271
  marshal() {
@@ -24846,9 +25280,12 @@ class Ed25519PublicKey {
24846
25280
  equals(key) {
24847
25281
  return equals(this.bytes, key.bytes);
24848
25282
  }
24849
- async hash() {
24850
- const { bytes } = await sha256$2.digest(this.bytes);
24851
- return bytes;
25283
+ hash() {
25284
+ const p = sha256$2.digest(this.bytes);
25285
+ if (isPromise(p)) {
25286
+ return p.then(({ bytes }) => bytes);
25287
+ }
25288
+ return p.bytes;
24852
25289
  }
24853
25290
  }
24854
25291
  class Ed25519PrivateKey {
@@ -24860,7 +25297,7 @@ class Ed25519PrivateKey {
24860
25297
  this._key = ensureKey(key, PRIVATE_KEY_BYTE_LENGTH);
24861
25298
  this._publicKey = ensureKey(publicKey, PUBLIC_KEY_BYTE_LENGTH);
24862
25299
  }
24863
- async sign(message) {
25300
+ sign(message) {
24864
25301
  return hashAndSign$2(this._key, message);
24865
25302
  }
24866
25303
  get public() {
@@ -24879,7 +25316,14 @@ class Ed25519PrivateKey {
24879
25316
  return equals(this.bytes, key.bytes);
24880
25317
  }
24881
25318
  async hash() {
24882
- const { bytes } = await sha256$2.digest(this.bytes);
25319
+ const p = sha256$2.digest(this.bytes);
25320
+ let bytes;
25321
+ if (isPromise(p)) {
25322
+ ({ bytes } = await p);
25323
+ }
25324
+ else {
25325
+ bytes = p.bytes;
25326
+ }
24883
25327
  return bytes;
24884
25328
  }
24885
25329
  /**
@@ -24925,11 +25369,11 @@ function unmarshalEd25519PublicKey(bytes) {
24925
25369
  return new Ed25519PublicKey(bytes);
24926
25370
  }
24927
25371
  async function generateKeyPair$2() {
24928
- const { privateKey, publicKey } = await generateKey$2();
25372
+ const { privateKey, publicKey } = generateKey$2();
24929
25373
  return new Ed25519PrivateKey(privateKey, publicKey);
24930
25374
  }
24931
25375
  async function generateKeyPairFromSeed(seed) {
24932
- const { privateKey, publicKey } = await generateKeyFromSeed(seed);
25376
+ const { privateKey, publicKey } = generateKeyFromSeed(seed);
24933
25377
  return new Ed25519PrivateKey(privateKey, publicKey);
24934
25378
  }
24935
25379
  function ensureKey(key, length) {
@@ -24950,36 +25394,6 @@ var Ed25519 = /*#__PURE__*/Object.freeze({
24950
25394
  unmarshalEd25519PublicKey: unmarshalEd25519PublicKey
24951
25395
  });
24952
25396
 
24953
- function bigIntegerToUintBase64url(num, len) {
24954
- // Call `.abs()` to convert to unsigned
24955
- let buf = Uint8Array.from(num.abs().toByteArray()); // toByteArray converts to big endian
24956
- // toByteArray() gives us back a signed array, which will include a leading 0
24957
- // byte if the most significant bit of the number is 1:
24958
- // https://docs.microsoft.com/en-us/windows/win32/seccertenroll/about-integer
24959
- // Our number will always be positive so we should remove the leading padding.
24960
- buf = buf[0] === 0 ? buf.subarray(1) : buf;
24961
- if (len != null) {
24962
- if (buf.length > len)
24963
- throw new Error('byte array longer than desired length');
24964
- buf = concat([new Uint8Array(len - buf.length), buf]);
24965
- }
24966
- return toString$1(buf, 'base64url');
24967
- }
24968
- // Convert a base64url encoded string to a BigInteger
24969
- function base64urlToBigInteger(str) {
24970
- const buf = base64urlToBuffer(str);
24971
- return new forge$n.jsbn.BigInteger(toString$1(buf, 'base16'), 16);
24972
- }
24973
- function base64urlToBuffer(str, len) {
24974
- let buf = fromString(str, 'base64urlpad');
24975
- if (len != null) {
24976
- if (buf.length > len)
24977
- throw new Error('byte array longer than desired length');
24978
- buf = concat([new Uint8Array(len - buf.length), buf]);
24979
- }
24980
- return buf;
24981
- }
24982
-
24983
25397
  const bits = {
24984
25398
  'P-256': 256,
24985
25399
  'P-384': 384,
@@ -25573,7 +25987,7 @@ function jwk2pub(key) {
25573
25987
 
25574
25988
  // Convert a PKCS#1 in ASN1 DER format to a JWK key
25575
25989
  function pkcs1ToJwk(bytes) {
25576
- const asn1 = forge$n.asn1.fromDer(toString$1(bytes, 'ascii'));
25990
+ const asn1 = forge$n.asn1.fromDer(toString(bytes, 'ascii'));
25577
25991
  const privateKey = forge$n.pki.privateKeyFromAsn1(asn1);
25578
25992
  // https://tools.ietf.org/html/rfc7518#section-6.3.1
25579
25993
  return {
@@ -25608,7 +26022,7 @@ function jwkToPkcs1(jwk) {
25608
26022
  }
25609
26023
  // Convert a PKCIX in ASN1 DER format to a JWK key
25610
26024
  function pkixToJwk(bytes) {
25611
- const asn1 = forge$n.asn1.fromDer(toString$1(bytes, 'ascii'));
26025
+ const asn1 = forge$n.asn1.fromDer(toString(bytes, 'ascii'));
25612
26026
  const publicKey = forge$n.pki.publicKeyFromAsn1(asn1);
25613
26027
  return {
25614
26028
  kty: 'RSA',
@@ -25665,7 +26079,7 @@ async function hashAndSign$1(key, msg) {
25665
26079
  name: 'RSASSA-PKCS1-v1_5',
25666
26080
  hash: { name: 'SHA-256' }
25667
26081
  }, false, ['sign']);
25668
- const sig = await webcrypto.get().subtle.sign({ name: 'RSASSA-PKCS1-v1_5' }, privateKey, Uint8Array.from(msg));
26082
+ const sig = await webcrypto.get().subtle.sign({ name: 'RSASSA-PKCS1-v1_5' }, privateKey, msg instanceof Uint8Array ? msg : msg.subarray());
25669
26083
  return new Uint8Array(sig, 0, sig.byteLength);
25670
26084
  }
25671
26085
  async function hashAndVerify$1(key, sig, msg) {
@@ -25673,7 +26087,7 @@ async function hashAndVerify$1(key, sig, msg) {
25673
26087
  name: 'RSASSA-PKCS1-v1_5',
25674
26088
  hash: { name: 'SHA-256' }
25675
26089
  }, false, ['verify']);
25676
- return webcrypto.get().subtle.verify({ name: 'RSASSA-PKCS1-v1_5' }, publicKey, sig, msg);
26090
+ return webcrypto.get().subtle.verify({ name: 'RSASSA-PKCS1-v1_5' }, publicKey, sig, msg instanceof Uint8Array ? msg : msg.subarray());
25677
26091
  }
25678
26092
  async function exportKey(pair) {
25679
26093
  if (pair.privateKey == null || pair.publicKey == null) {
@@ -25707,7 +26121,7 @@ Explanation:
25707
26121
  */
25708
26122
  function convertKey(key, pub, msg, handle) {
25709
26123
  const fkey = pub ? jwk2pub(key) : jwk2priv(key);
25710
- const fmsg = toString$1(Uint8Array.from(msg), 'ascii');
26124
+ const fmsg = toString(msg instanceof Uint8Array ? msg : msg.subarray(), 'ascii');
25711
26125
  const fomsg = handle(fmsg, fkey);
25712
26126
  return fromString(fomsg, 'ascii');
25713
26127
  }
@@ -25734,7 +26148,7 @@ class RsaPublicKey {
25734
26148
  constructor(key) {
25735
26149
  this._key = key;
25736
26150
  }
25737
- async verify(data, sig) {
26151
+ verify(data, sig) {
25738
26152
  return hashAndVerify$1(this._key, sig, data);
25739
26153
  }
25740
26154
  marshal() {
@@ -25752,9 +26166,12 @@ class RsaPublicKey {
25752
26166
  equals(key) {
25753
26167
  return equals(this.bytes, key.bytes);
25754
26168
  }
25755
- async hash() {
25756
- const { bytes } = await sha256$2.digest(this.bytes);
25757
- return bytes;
26169
+ hash() {
26170
+ const p = sha256$2.digest(this.bytes);
26171
+ if (isPromise(p)) {
26172
+ return p.then(({ bytes }) => bytes);
26173
+ }
26174
+ return p.bytes;
25758
26175
  }
25759
26176
  }
25760
26177
  class RsaPrivateKey {
@@ -25767,7 +26184,7 @@ class RsaPrivateKey {
25767
26184
  genSecret() {
25768
26185
  return randomBytes(16);
25769
26186
  }
25770
- async sign(message) {
26187
+ sign(message) {
25771
26188
  return hashAndSign$1(this._key, message);
25772
26189
  }
25773
26190
  get public() {
@@ -25791,9 +26208,12 @@ class RsaPrivateKey {
25791
26208
  equals(key) {
25792
26209
  return equals(this.bytes, key.bytes);
25793
26210
  }
25794
- async hash() {
25795
- const { bytes } = await sha256$2.digest(this.bytes);
25796
- return bytes;
26211
+ hash() {
26212
+ const p = sha256$2.digest(this.bytes);
26213
+ if (isPromise(p)) {
26214
+ return p.then(({ bytes }) => bytes);
26215
+ }
26216
+ return p.bytes;
25797
26217
  }
25798
26218
  /**
25799
26219
  * Gets the ID of the key.
@@ -25804,7 +26224,7 @@ class RsaPrivateKey {
25804
26224
  */
25805
26225
  async id() {
25806
26226
  const hash = await this.public.hash();
25807
- return toString$1(hash, 'base58btc');
26227
+ return toString(hash, 'base58btc');
25808
26228
  }
25809
26229
  /**
25810
26230
  * Exports the key into a password protected PEM format
@@ -26978,11 +27398,16 @@ function generateKey() {
26978
27398
  /**
26979
27399
  * Hash and sign message with private key
26980
27400
  */
26981
- async function hashAndSign(key, msg) {
26982
- const { digest } = await sha256$2.digest(msg);
27401
+ function hashAndSign(key, msg) {
27402
+ const p = sha256$2.digest(msg instanceof Uint8Array ? msg : msg.subarray());
27403
+ if (isPromise(p)) {
27404
+ return p.then(({ digest }) => secp256k1.sign(digest, key).toDERRawBytes())
27405
+ .catch(err => {
27406
+ throw new CodeError(String(err), 'ERR_INVALID_INPUT');
27407
+ });
27408
+ }
26983
27409
  try {
26984
- const signature = secp256k1.sign(digest, key);
26985
- return signature.toDERRawBytes();
27410
+ return secp256k1.sign(p.digest, key).toDERRawBytes();
26986
27411
  }
26987
27412
  catch (err) {
26988
27413
  throw new CodeError(String(err), 'ERR_INVALID_INPUT');
@@ -26991,10 +27416,16 @@ async function hashAndSign(key, msg) {
26991
27416
  /**
26992
27417
  * Hash message and verify signature with public key
26993
27418
  */
26994
- async function hashAndVerify(key, sig, msg) {
27419
+ function hashAndVerify(key, sig, msg) {
27420
+ const p = sha256$2.digest(msg instanceof Uint8Array ? msg : msg.subarray());
27421
+ if (isPromise(p)) {
27422
+ return p.then(({ digest }) => secp256k1.verify(sig, digest, key))
27423
+ .catch(err => {
27424
+ throw new CodeError(String(err), 'ERR_INVALID_INPUT');
27425
+ });
27426
+ }
26995
27427
  try {
26996
- const { digest } = await sha256$2.digest(msg);
26997
- return secp256k1.verify(sig, digest, key);
27428
+ return secp256k1.verify(sig, p.digest, key);
26998
27429
  }
26999
27430
  catch (err) {
27000
27431
  throw new CodeError(String(err), 'ERR_INVALID_INPUT');
@@ -27035,7 +27466,7 @@ class Secp256k1PublicKey {
27035
27466
  validatePublicKey(key);
27036
27467
  this._key = key;
27037
27468
  }
27038
- async verify(data, sig) {
27469
+ verify(data, sig) {
27039
27470
  return hashAndVerify(this._key, sig, data);
27040
27471
  }
27041
27472
  marshal() {
@@ -27051,7 +27482,14 @@ class Secp256k1PublicKey {
27051
27482
  return equals(this.bytes, key.bytes);
27052
27483
  }
27053
27484
  async hash() {
27054
- const { bytes } = await sha256$2.digest(this.bytes);
27485
+ const p = sha256$2.digest(this.bytes);
27486
+ let bytes;
27487
+ if (isPromise(p)) {
27488
+ ({ bytes } = await p);
27489
+ }
27490
+ else {
27491
+ bytes = p.bytes;
27492
+ }
27055
27493
  return bytes;
27056
27494
  }
27057
27495
  }
@@ -27064,7 +27502,7 @@ class Secp256k1PrivateKey {
27064
27502
  validatePrivateKey(this._key);
27065
27503
  validatePublicKey(this._publicKey);
27066
27504
  }
27067
- async sign(message) {
27505
+ sign(message) {
27068
27506
  return hashAndSign(this._key, message);
27069
27507
  }
27070
27508
  get public() {
@@ -27082,9 +27520,12 @@ class Secp256k1PrivateKey {
27082
27520
  equals(key) {
27083
27521
  return equals(this.bytes, key.bytes);
27084
27522
  }
27085
- async hash() {
27086
- const { bytes } = await sha256$2.digest(this.bytes);
27087
- return bytes;
27523
+ hash() {
27524
+ const p = sha256$2.digest(this.bytes);
27525
+ if (isPromise(p)) {
27526
+ return p.then(({ bytes }) => bytes);
27527
+ }
27528
+ return p.bytes;
27088
27529
  }
27089
27530
  /**
27090
27531
  * Gets the ID of the key.
@@ -27095,7 +27536,7 @@ class Secp256k1PrivateKey {
27095
27536
  */
27096
27537
  async id() {
27097
27538
  const hash = await this.public.hash();
27098
- return toString$1(hash, 'base58btc');
27539
+ return toString(hash, 'base58btc');
27099
27540
  }
27100
27541
  /**
27101
27542
  * Exports the key into a password protected `format`
@@ -27256,13 +27697,13 @@ class PeerIdImpl {
27256
27697
  */
27257
27698
  equals(id) {
27258
27699
  if (id instanceof Uint8Array) {
27259
- return equals(this.multihash.bytes, id);
27700
+ return equals$1(this.multihash.bytes, id);
27260
27701
  }
27261
27702
  else if (typeof id === 'string') {
27262
27703
  return peerIdFromString(id).equals(this);
27263
27704
  }
27264
27705
  else if (id?.multihash?.bytes != null) {
27265
- return equals(this.multihash.bytes, id.multihash.bytes);
27706
+ return equals$1(this.multihash.bytes, id.multihash.bytes);
27266
27707
  }
27267
27708
  else {
27268
27709
  throw new Error('not valid Id');
@@ -27436,15 +27877,15 @@ const decodeRelayShard = (bytes) => {
27436
27877
  if (bytes.length < 3)
27437
27878
  throw new Error("Insufficient data");
27438
27879
  const view = new DataView(bytes.buffer);
27439
- const cluster = view.getUint16(0);
27440
- const indexList = [];
27880
+ const clusterId = view.getUint16(0);
27881
+ const shards = [];
27441
27882
  if (bytes.length === 130) {
27442
27883
  // rsv format (Bit Vector)
27443
27884
  for (let i = 0; i < 1024; i++) {
27444
27885
  const byteIndex = Math.floor(i / 8) + 2; // Adjusted for the 2-byte cluster field
27445
27886
  const bitIndex = 7 - (i % 8);
27446
27887
  if (view.getUint8(byteIndex) & (1 << bitIndex)) {
27447
- indexList.push(i);
27888
+ shards.push(i);
27448
27889
  }
27449
27890
  }
27450
27891
  }
@@ -27454,20 +27895,20 @@ const decodeRelayShard = (bytes) => {
27454
27895
  for (let i = 0, offset = 3; i < numIndices; i++, offset += 2) {
27455
27896
  if (offset + 1 >= bytes.length)
27456
27897
  throw new Error("Unexpected end of data");
27457
- indexList.push(view.getUint16(offset));
27898
+ shards.push(view.getUint16(offset));
27458
27899
  }
27459
27900
  }
27460
- return { cluster, indexList };
27901
+ return { clusterId, shards };
27461
27902
  };
27462
27903
  const encodeRelayShard = (shardInfo) => {
27463
- const { cluster, indexList } = shardInfo;
27464
- const totalLength = indexList.length >= 64 ? 130 : 3 + 2 * indexList.length;
27904
+ const { clusterId, shards } = shardInfo;
27905
+ const totalLength = shards.length >= 64 ? 130 : 3 + 2 * shards.length;
27465
27906
  const buffer = new ArrayBuffer(totalLength);
27466
27907
  const view = new DataView(buffer);
27467
- view.setUint16(0, cluster);
27468
- if (indexList.length >= 64) {
27908
+ view.setUint16(0, clusterId);
27909
+ if (shards.length >= 64) {
27469
27910
  // rsv format (Bit Vector)
27470
- for (const index of indexList) {
27911
+ for (const index of shards) {
27471
27912
  const byteIndex = Math.floor(index / 8) + 2; // Adjusted for the 2-byte cluster field
27472
27913
  const bitIndex = 7 - (index % 8);
27473
27914
  view.setUint8(byteIndex, view.getUint8(byteIndex) | (1 << bitIndex));
@@ -27475,9 +27916,9 @@ const encodeRelayShard = (shardInfo) => {
27475
27916
  }
27476
27917
  else {
27477
27918
  // rs format (Index List)
27478
- view.setUint8(2, indexList.length);
27479
- for (let i = 0, offset = 3; i < indexList.length; i++, offset += 2) {
27480
- view.setUint16(offset, indexList[i]);
27919
+ view.setUint8(2, shards.length);
27920
+ for (let i = 0, offset = 3; i < shards.length; i++, offset += 2) {
27921
+ view.setUint16(offset, shards[i]);
27481
27922
  }
27482
27923
  }
27483
27924
  return new Uint8Array(buffer);
@@ -28469,7 +28910,7 @@ class EnrDecoder {
28469
28910
  if (!encoded.startsWith(ENR.RECORD_PREFIX)) {
28470
28911
  throw new Error(`"string encoded ENR must start with '${ENR.RECORD_PREFIX}'`);
28471
28912
  }
28472
- return EnrDecoder.fromRLP(fromString(encoded.slice(4), "base64url"));
28913
+ return EnrDecoder.fromRLP(fromString$1(encoded.slice(4), "base64url"));
28473
28914
  }
28474
28915
  static fromRLP(encoded) {
28475
28916
  const decoded = decode(encoded).map(hexToBytes$2);