@libp2p/utils 7.0.17-fd68eecf7 → 7.1.0-10b2bdf50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +4 -4
- package/dist/index.min.js.map +3 -3
- package/dist/src/multiaddr/get-net-config.d.ts +7 -4
- package/dist/src/multiaddr/get-net-config.d.ts.map +1 -1
- package/dist/src/multiaddr/get-net-config.js +18 -9
- package/dist/src/multiaddr/get-net-config.js.map +1 -1
- package/dist/src/multiaddr/is-network-address.d.ts.map +1 -1
- package/dist/src/multiaddr/is-network-address.js +2 -8
- package/dist/src/multiaddr/is-network-address.js.map +1 -1
- package/package.json +5 -5
- package/src/multiaddr/get-net-config.ts +21 -9
- package/src/multiaddr/is-network-address.ts +2 -8
|
@@ -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
|
|
50
|
-
*
|
|
51
|
-
|
|
52
|
-
|
|
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,EA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AE,KAAK,GAAG,KAAK,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,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,WAAW,gBAAgB;IAC/B,IAAI,EAAE,SAAS,CAAA;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
|
|
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
|
|
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]
|
|
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]
|
|
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]
|
|
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
|
-
|
|
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
|
|
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;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAE,EAAa;IAC5C,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,EAAE,IAAI,KAAK,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,KAAK,EAAE,CAAC;QAC3E,MAAM,CAAC,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,CAAA;QACpC,MAAM,CAAC,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,KAAK,CAAA;QACrC,KAAK,EAAE,CAAA;IACT,CAAC;SAAM,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,MAAM,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,MAAM,EAAE,CAAC;QACzH,MAAM,CAAC,IAAI,G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;IACT,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,KAAK,IAAI,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,IAAI,KAAK,KAAK,EAAE,CAAC;QAC/E,MAAM,CAAC,GAAG,GAAG,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAA;QACxC,KAAK,IAAI,CAAC,CAAA;IACZ,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAE,EAAa;IACzC,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,
|
|
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 {
|
|
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
|
-
|
|
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,
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/utils",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0-10b2bdf50",
|
|
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-
|
|
51
|
-
"@libp2p/interface": "3.2.2-
|
|
52
|
-
"@libp2p/logger": "6.2.6-
|
|
50
|
+
"@libp2p/crypto": "5.1.17-10b2bdf50",
|
|
51
|
+
"@libp2p/interface": "3.2.2-10b2bdf50",
|
|
52
|
+
"@libp2p/logger": "6.2.6-10b2bdf50",
|
|
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-
|
|
74
|
+
"@libp2p/peer-id": "6.0.8-10b2bdf50",
|
|
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
|
|
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
|
|
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]
|
|
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]
|
|
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]
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
9
|
-
getNetConfig(ma)
|
|
10
|
-
|
|
11
|
-
return true
|
|
12
|
-
} catch {
|
|
13
|
-
return false
|
|
14
|
-
}
|
|
8
|
+
return tryGetNetConfig(ma) !== null
|
|
15
9
|
}
|