@libp2p/utils 7.0.17-fd68eecf7 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,10 +46,13 @@ export interface DNSAddrNetConfig {
46
46
  }
47
47
  export type NetConfig = IP4NetConfig | IP6NetConfig | DNSNetConfig | DNS4NetConfig | DNS6NetConfig | DNSAddrNetConfig;
48
48
  /**
49
- * Returns host/port/etc information for multiaddrs, if it is available.
50
- *
51
- * It will throw if the passed multiaddr does not start with a network address,
52
- * e.g. a IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address
49
+ * Returns host/port/etc information for a multiaddr if it starts with a
50
+ * network address (IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR), or null otherwise.
51
+ */
52
+ export declare function tryGetNetConfig(ma: Multiaddr): NetConfig | null;
53
+ /**
54
+ * Like `tryGetNetConfig` but throws `InvalidParametersError` when the multiaddr
55
+ * does not start with a network address.
53
56
  */
54
57
  export declare function getNetConfig(ma: Multiaddr): NetConfig;
55
58
  //# sourceMappingURL=get-net-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-net-config.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/get-net-config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IACxB,IAAI,CAAC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IACf,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,YAAY,GAAG,YAAY,GAAG,aAAa,GAAG,aAAa,GAAG,gBAAgB,CAAA;AAErH;;;GAGG;AACH,wBAAgB,eAAe,CAAE,EAAE,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAiDhE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAE,EAAE,EAAE,SAAS,GAAG,SAAS,CAQtD"}
@@ -1,11 +1,9 @@
1
1
  import { InvalidParametersError } from '@libp2p/interface';
2
2
  /**
3
- * Returns host/port/etc information for multiaddrs, if it is available.
4
- *
5
- * It will throw if the passed multiaddr does not start with a network address,
6
- * e.g. a IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address
3
+ * Returns host/port/etc information for a multiaddr if it starts with a
4
+ * network address (IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR), or null otherwise.
7
5
  */
8
- export function getNetConfig(ma) {
6
+ export function tryGetNetConfig(ma) {
9
7
  const components = ma.getComponents();
10
8
  const config = {};
11
9
  let index = 0;
@@ -13,17 +11,17 @@ export function getNetConfig(ma) {
13
11
  config.zone = `${components[index].value}`;
14
12
  index++;
15
13
  }
16
- if (components[index].name === 'ip4' || components[index].name === 'ip6') {
14
+ if (components[index]?.name === 'ip4' || components[index]?.name === 'ip6') {
17
15
  config.type = components[index].name;
18
16
  config.host = components[index].value;
19
17
  index++;
20
18
  }
21
- else if (components[index].name === 'dns' || components[index].name === 'dns4' || components[index].name === 'dns6') {
19
+ else if (components[index]?.name === 'dns' || components[index]?.name === 'dns4' || components[index]?.name === 'dns6') {
22
20
  config.type = components[index].name;
23
21
  config.host = components[index].value;
24
22
  index++;
25
23
  }
26
- else if (components[index].name === 'dnsaddr') {
24
+ else if (components[index]?.name === 'dnsaddr') {
27
25
  config.type = components[index].name;
28
26
  config.host = `_dnsaddr.${components[index].value}`;
29
27
  index++;
@@ -43,7 +41,7 @@ export function getNetConfig(ma) {
43
41
  index++;
44
42
  }
45
43
  if (config.type == null || config.host == null) {
46
- throw new InvalidParametersError(`Multiaddr ${ma} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);
44
+ return null;
47
45
  }
48
46
  if (components[index]?.name === 'tls' && components[index + 1]?.name === 'sni') {
49
47
  config.sni = components[index + 1].value;
@@ -51,4 +49,15 @@ export function getNetConfig(ma) {
51
49
  }
52
50
  return config;
53
51
  }
52
+ /**
53
+ * Like `tryGetNetConfig` but throws `InvalidParametersError` when the multiaddr
54
+ * does not start with a network address.
55
+ */
56
+ export function getNetConfig(ma) {
57
+ const config = tryGetNetConfig(ma);
58
+ if (config == null) {
59
+ throw new InvalidParametersError(`Multiaddr ${ma} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);
60
+ }
61
+ return config;
62
+ }
54
63
  //# sourceMappingURL=get-net-config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-net-config.js","sourceRoot":"","sources":["../../../src/multiaddr/get-net-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAwD1D;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAE,EAAa;IACzC,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,EAAE,CAAA;IACrC,MAAM,MAAM,GAAQ,EAAE,CAAA;IACtB,IAAI,KAAK,GAAG,CAAC,CAAA;IAEb,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,SAAS,EAAE,CAAC;QAC1C,MAAM,CAAC,IAAI,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,CAAA;QAC1C,KAAK,EAAE,CAAA;IACT,CAAC;IAED,IAAI,UAAU,CAAC,KAAK,CAAC,C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MAAM,MAAM,GAAG,eAAe,CAAC,EAAE,CAAC,CAAA;IAElC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,sBAAsB,CAAC,aAAa,EAAE,4DAA4D,CAAC,CAAA;IAC/G,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"is-network-address.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-network-address.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;GAEG;AACH,wBAAgB,gBAAgB,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAQxD"}
1
+ {"version":3,"file":"is-network-address.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-network-address.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;GAEG;AACH,wBAAgB,gBAAgB,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAExD"}
@@ -1,14 +1,8 @@
1
- import { getNetConfig } from "./get-net-config.js";
1
+ import { tryGetNetConfig } from "./get-net-config.js";
2
2
  /**
3
3
  * Check if a given multiaddr is a network address
4
4
  */
5
5
  export function isNetworkAddress(ma) {
6
- try {
7
- getNetConfig(ma);
8
- return true;
9
- }
10
- catch {
11
- return false;
12
- }
6
+ return tryGetNetConfig(ma) !== null;
13
7
  }
14
8
  //# sourceMappingURL=is-network-address.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-network-address.js","sourceRoot":"","sources":["../../../src/multiaddr/is-network-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAGlD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAE,EAAa;IAC7C,IAAI,CAAC;QACH,YAAY,CAAC,EAAE,CAAC,CAAA;QAEhB,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"is-network-address.js","sourceRoot":"","sources":["../../../src/multiaddr/is-network-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAGrD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAE,EAAa;IAC7C,OAAO,eAAe,CAAC,EAAE,CAAC,KAAK,IAAI,CAAA;AACrC,CAAC"}
@@ -0,0 +1,125 @@
1
+ {
2
+ "AbstractMessageStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.AbstractMessageStream.html",
3
+ "AbstractMultiaddrConnection": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.AbstractMultiaddrConnection.html",
4
+ "AbstractStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.AbstractStream.html",
5
+ "AbstractStreamMuxer": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.AbstractStreamMuxer.html",
6
+ "AdaptiveTimeout": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.AdaptiveTimeout.html",
7
+ "BloomFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.BloomFilter.html",
8
+ "CuckooFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.CuckooFilter.html",
9
+ "InvalidDataLengthError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.InvalidDataLengthError.html",
10
+ "InvalidDataLengthLengthError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.InvalidDataLengthLengthError.html",
11
+ "InvalidMessageLengthError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.InvalidMessageLengthError.html",
12
+ "LengthPrefixedDecoder": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.LengthPrefixedDecoder.html",
13
+ "MaxEarlyStreamsError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.MaxEarlyStreamsError.html",
14
+ "MemoryStorage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.MemoryStorage.html",
15
+ "MockStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.MockStream.html",
16
+ "MovingAverage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.MovingAverage.html",
17
+ "PeerQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.PeerQueue.html",
18
+ "PriorityQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.PriorityQueue.html",
19
+ "Queue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.Queue.html",
20
+ "QueueFullError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.QueueFullError.html",
21
+ "RateLimiter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.RateLimiter.html",
22
+ "RateLimitError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.RateLimitError.html",
23
+ "ScalableCuckooFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.ScalableCuckooFilter.html",
24
+ "StreamClosedError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.StreamClosedError.html",
25
+ "UnexpectedEOFError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.UnexpectedEOFError.html",
26
+ "UnwrappedError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.UnwrappedError.html",
27
+ "AbstractMultiaddrConnectionInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.AbstractMultiaddrConnectionInit.html",
28
+ "AbstractStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.AbstractStreamInit.html",
29
+ "AbstractStreamMuxerInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.AbstractStreamMuxerInit.html",
30
+ "AdaptiveTimeoutInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.AdaptiveTimeoutInit.html",
31
+ "AdaptiveTimeoutSignal": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.AdaptiveTimeoutSignal.html",
32
+ "BloomFilterOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.BloomFilterOptions.html",
33
+ "Bucket": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.Bucket.html",
34
+ "ByteStream": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ByteStream.html",
35
+ "ByteStreamOpts": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ByteStreamOpts.html",
36
+ "Comparator": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.Comparator.html",
37
+ "CreateTrackedListInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.CreateTrackedListInit.html",
38
+ "CreateTrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.CreateTrackedMapInit.html",
39
+ "CuckooFilterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.CuckooFilterInit.html",
40
+ "DebouncedFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.DebouncedFunction.html",
41
+ "DNS4NetConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.DNS4NetConfig.html",
42
+ "DNS6NetConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.DNS6NetConfig.html",
43
+ "DNSAddrNetConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.DNSAddrNetConfig.html",
44
+ "DNSNetConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.DNSNetConfig.html",
45
+ "Filter": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.Filter.html",
46
+ "Fingerprint": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.Fingerprint.html",
47
+ "GetKeySecDurationOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.GetKeySecDurationOptions.html",
48
+ "GetTimeoutSignalOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.GetTimeoutSignalOptions.html",
49
+ "Hash": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.Hash.html",
50
+ "IP4NetConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.IP4NetConfig.html",
51
+ "IP6NetConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.IP6NetConfig.html",
52
+ "Job": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.Job.html",
53
+ "JobMatcher": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.JobMatcher.html",
54
+ "JobRecipient": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.JobRecipient.html",
55
+ "JobTimeline": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.JobTimeline.html",
56
+ "LengthPrefixedDecoderInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.LengthPrefixedDecoderInit.html",
57
+ "LengthPrefixedStream": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.LengthPrefixedStream.html",
58
+ "LengthPrefixedStreamOpts": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.LengthPrefixedStreamOpts.html",
59
+ "MessageStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.MessageStreamInit.html",
60
+ "MockMultiaddrConnectionInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.MockMultiaddrConnectionInit.html",
61
+ "MockMuxedStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.MockMuxedStreamInit.html",
62
+ "MultiaddrConnectionPairOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.MultiaddrConnectionPairOptions.html",
63
+ "PeerQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.PeerQueueJobOptions.html",
64
+ "PriorityQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.PriorityQueueJobOptions.html",
65
+ "ProtobufDecoder": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ProtobufDecoder.html",
66
+ "ProtobufEncoder": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ProtobufEncoder.html",
67
+ "ProtobufMessageStream": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ProtobufMessageStream.html",
68
+ "ProtobufStream": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ProtobufStream.html",
69
+ "ProtobufStreamOpts": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ProtobufStreamOpts.html",
70
+ "QueueEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.QueueEvents.html",
71
+ "QueueInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.QueueInit.html",
72
+ "QueueJobFailure": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.QueueJobFailure.html",
73
+ "QueueJobSuccess": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.QueueJobSuccess.html",
74
+ "RateLimiterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.RateLimiterInit.html",
75
+ "RateLimiterResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.RateLimiterResult.html",
76
+ "RateRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.RateRecord.html",
77
+ "ReadBytesOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ReadBytesOptions.html",
78
+ "RepeatingTask": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.RepeatingTask.html",
79
+ "RepeatingTaskOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.RepeatingTaskOptions.html",
80
+ "RunFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.RunFunction.html",
81
+ "ScalableCuckooFilterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ScalableCuckooFilterInit.html",
82
+ "SendResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.SendResult.html",
83
+ "StreamPairOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.StreamPairOptions.html",
84
+ "TrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.TrackedMapInit.html",
85
+ "JobStatus": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.JobStatus.html",
86
+ "NetConfig": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.NetConfig.html",
87
+ "PipeInput": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.PipeInput.html",
88
+ "DEFAULT_FAILURE_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.DEFAULT_FAILURE_MULTIPLIER.html",
89
+ "DEFAULT_INTERVAL": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.DEFAULT_INTERVAL.html",
90
+ "DEFAULT_MAX_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.DEFAULT_MAX_TIMEOUT.html",
91
+ "DEFAULT_MIN_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.DEFAULT_MIN_TIMEOUT.html",
92
+ "DEFAULT_TIMEOUT_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.DEFAULT_TIMEOUT_MULTIPLIER.html",
93
+ "byteStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.byteStream.html",
94
+ "createBloomFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.createBloomFilter.html",
95
+ "createCuckooFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.createCuckooFilter.html",
96
+ "createScalableCuckooFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.createScalableCuckooFilter.html",
97
+ "debounce": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.debounce.html",
98
+ "echo": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.echo.html",
99
+ "echoStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.echoStream.html",
100
+ "getNetConfig": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.getNetConfig.html",
101
+ "getThinWaistAddresses": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.getThinWaistAddresses.html",
102
+ "ipPortToMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.ipPortToMultiaddr.html",
103
+ "isAsyncGenerator": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isAsyncGenerator.html",
104
+ "isGenerator": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isGenerator.html",
105
+ "isGlobalUnicast": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isGlobalUnicast.html",
106
+ "isGlobalUnicastIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isGlobalUnicastIp.html",
107
+ "isLinkLocal": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isLinkLocal.html",
108
+ "isLinkLocalIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isLinkLocalIp.html",
109
+ "isLoopback": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isLoopback.html",
110
+ "isNetworkAddress": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isNetworkAddress.html",
111
+ "isPrivate": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isPrivate.html",
112
+ "isPrivateIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isPrivateIp.html",
113
+ "isPromise": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isPromise.html",
114
+ "lpStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.lpStream.html",
115
+ "messageStreamToDuplex": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.messageStreamToDuplex.html",
116
+ "mockMuxer": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.mockMuxer.html",
117
+ "multiaddrConnectionPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddrConnectionPair.html",
118
+ "pbStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.pbStream.html",
119
+ "pipe": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.pipe.html",
120
+ "repeatingTask": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.repeatingTask.html",
121
+ "streamPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.streamPair.html",
122
+ "trackedList": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.trackedList.html",
123
+ "trackedMap": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.trackedMap.html",
124
+ "tryGetNetConfig": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tryGetNetConfig.html"
125
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/utils",
3
- "version": "7.0.17-fd68eecf7",
3
+ "version": "7.1.0",
4
4
  "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/utils#readme",
@@ -47,9 +47,9 @@
47
47
  "dependencies": {
48
48
  "@chainsafe/is-ip": "^2.1.0",
49
49
  "@chainsafe/netmask": "^2.0.0",
50
- "@libp2p/crypto": "5.1.17-fd68eecf7",
51
- "@libp2p/interface": "3.2.2-fd68eecf7",
52
- "@libp2p/logger": "6.2.6-fd68eecf7",
50
+ "@libp2p/crypto": "^5.1.17",
51
+ "@libp2p/interface": "^3.2.2",
52
+ "@libp2p/logger": "^6.2.6",
53
53
  "@multiformats/multiaddr": "^13.0.1",
54
54
  "@sindresorhus/fnv1a": "^3.1.0",
55
55
  "any-signal": "^4.1.1",
@@ -71,7 +71,7 @@
71
71
  "uint8arrays": "^5.1.0"
72
72
  },
73
73
  "devDependencies": {
74
- "@libp2p/peer-id": "6.0.8-fd68eecf7",
74
+ "@libp2p/peer-id": "^6.0.8",
75
75
  "@types/netmask": "^2.0.5",
76
76
  "aegir": "^47.0.22",
77
77
  "benchmark": "^2.1.4",
@@ -55,12 +55,10 @@ export interface DNSAddrNetConfig {
55
55
  export type NetConfig = IP4NetConfig | IP6NetConfig | DNSNetConfig | DNS4NetConfig | DNS6NetConfig | DNSAddrNetConfig
56
56
 
57
57
  /**
58
- * Returns host/port/etc information for multiaddrs, if it is available.
59
- *
60
- * It will throw if the passed multiaddr does not start with a network address,
61
- * e.g. a IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address
58
+ * Returns host/port/etc information for a multiaddr if it starts with a
59
+ * network address (IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR), or null otherwise.
62
60
  */
63
- export function getNetConfig (ma: Multiaddr): NetConfig {
61
+ export function tryGetNetConfig (ma: Multiaddr): NetConfig | null {
64
62
  const components = ma.getComponents()
65
63
  const config: any = {}
66
64
  let index = 0
@@ -70,15 +68,15 @@ export function getNetConfig (ma: Multiaddr): NetConfig {
70
68
  index++
71
69
  }
72
70
 
73
- if (components[index].name === 'ip4' || components[index].name === 'ip6') {
71
+ if (components[index]?.name === 'ip4' || components[index]?.name === 'ip6') {
74
72
  config.type = components[index].name
75
73
  config.host = components[index].value
76
74
  index++
77
- } else if (components[index].name === 'dns' || components[index].name === 'dns4' || components[index].name === 'dns6') {
75
+ } else if (components[index]?.name === 'dns' || components[index]?.name === 'dns4' || components[index]?.name === 'dns6') {
78
76
  config.type = components[index].name
79
77
  config.host = components[index].value
80
78
  index++
81
- } else if (components[index].name === 'dnsaddr') {
79
+ } else if (components[index]?.name === 'dnsaddr') {
82
80
  config.type = components[index].name
83
81
  config.host = `_dnsaddr.${components[index].value}`
84
82
  index++
@@ -100,7 +98,7 @@ export function getNetConfig (ma: Multiaddr): NetConfig {
100
98
  }
101
99
 
102
100
  if (config.type == null || config.host == null) {
103
- throw new InvalidParametersError(`Multiaddr ${ma} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`)
101
+ return null
104
102
  }
105
103
 
106
104
  if (components[index]?.name === 'tls' && components[index + 1]?.name === 'sni') {
@@ -110,3 +108,17 @@ export function getNetConfig (ma: Multiaddr): NetConfig {
110
108
 
111
109
  return config
112
110
  }
111
+
112
+ /**
113
+ * Like `tryGetNetConfig` but throws `InvalidParametersError` when the multiaddr
114
+ * does not start with a network address.
115
+ */
116
+ export function getNetConfig (ma: Multiaddr): NetConfig {
117
+ const config = tryGetNetConfig(ma)
118
+
119
+ if (config == null) {
120
+ throw new InvalidParametersError(`Multiaddr ${ma} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`)
121
+ }
122
+
123
+ return config
124
+ }
@@ -1,15 +1,9 @@
1
- import { getNetConfig } from './get-net-config.ts'
1
+ import { tryGetNetConfig } from './get-net-config.ts'
2
2
  import type { Multiaddr } from '@multiformats/multiaddr'
3
3
 
4
4
  /**
5
5
  * Check if a given multiaddr is a network address
6
6
  */
7
7
  export function isNetworkAddress (ma: Multiaddr): boolean {
8
- try {
9
- getNetConfig(ma)
10
-
11
- return true
12
- } catch {
13
- return false
14
- }
8
+ return tryGetNetConfig(ma) !== null
15
9
  }