@libp2p/utils 4.0.1-eaac8943 → 4.0.2-4ef9c79c
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ip-port-to-multiaddr.d.ts","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,yBAAyB,CAAA;AAInE,eAAO,MAAM,MAAM;;;;CAIlB,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"ip-port-to-multiaddr.d.ts","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,yBAAyB,CAAA;AAInE,eAAO,MAAM,MAAM;;;;CAIlB,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAwB/E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isIPv4, isIPv6 } from '@chainsafe/is-ip';
|
|
2
2
|
import { CodeError } from '@libp2p/interface/errors';
|
|
3
3
|
import { logger } from '@libp2p/logger';
|
|
4
4
|
import { multiaddr } from '@multiformats/multiaddr';
|
|
@@ -21,23 +21,14 @@ export function ipPortToMultiaddr(ip, port) {
|
|
|
21
21
|
if (isNaN(port)) {
|
|
22
22
|
throw new CodeError(`invalid port provided: ${port}`, Errors.ERR_INVALID_PORT_PARAMETER);
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
// Test valid IPv4
|
|
26
|
-
new Address4(ip); // eslint-disable-line no-new
|
|
24
|
+
if (isIPv4(ip)) {
|
|
27
25
|
return multiaddr(`/ip4/${ip}/tcp/${port}`);
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// Test valid IPv6
|
|
32
|
-
const ip6 = new Address6(ip);
|
|
33
|
-
return ip6.is4()
|
|
34
|
-
? multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`)
|
|
35
|
-
: multiaddr(`/ip6/${ip}/tcp/${port}`);
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}`;
|
|
39
|
-
log.error(errMsg);
|
|
40
|
-
throw new CodeError(errMsg, Errors.ERR_INVALID_IP);
|
|
27
|
+
if (isIPv6(ip)) {
|
|
28
|
+
return multiaddr(`/ip6/${ip}/tcp/${port}`);
|
|
41
29
|
}
|
|
30
|
+
const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}`;
|
|
31
|
+
log.error(errMsg);
|
|
32
|
+
throw new CodeError(errMsg, Errors.ERR_INVALID_IP);
|
|
42
33
|
}
|
|
43
34
|
//# sourceMappingURL=ip-port-to-multiaddr.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ip-port-to-multiaddr.js","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ip-port-to-multiaddr.js","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAkB,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnE,MAAM,GAAG,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAA;AAEjD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,wBAAwB,EAAE,0BAA0B;IACpD,0BAA0B,EAAE,4BAA4B;IACxD,cAAc,EAAE,gBAAgB;CACjC,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAE,EAAU,EAAE,IAAqB;IAClE,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE;QAC1B,MAAM,IAAI,SAAS,CAAC,wBAAwB,EAAE,EAAE,EAAE,MAAM,CAAC,wBAAwB,CAAC,CAAA,CAAC,uEAAuE;KAC3J;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;KACtB;IAED,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE;QACf,MAAM,IAAI,SAAS,CAAC,0BAA0B,IAAI,EAAE,EAAE,MAAM,CAAC,0BAA0B,CAAC,CAAA;KACzF;IAED,IAAI,MAAM,CAAC,EAAE,CAAC,EAAE;QACd,OAAO,SAAS,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;KAC3C;IAED,IAAI,MAAM,CAAC,EAAE,CAAC,EAAE;QACd,OAAO,SAAS,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;KAC3C;IAED,MAAM,MAAM,GAAG,6CAA6C,EAAE,IAAI,IAAI,EAAE,CAAA;IACxE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACjB,MAAM,IAAI,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,CAAA;AACpD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/utils",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2-4ef9c79c",
|
|
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/master/packages/utils#readme",
|
|
@@ -85,17 +85,17 @@
|
|
|
85
85
|
"test:electron-main": "aegir test -t electron-main"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@
|
|
89
|
-
"@libp2p/interface": "0.1.
|
|
90
|
-
"@libp2p/logger": "3.0.
|
|
91
|
-
"@multiformats/multiaddr": "^12.1.
|
|
88
|
+
"@chainsafe/is-ip": "^2.0.2",
|
|
89
|
+
"@libp2p/interface": "0.1.2-4ef9c79c",
|
|
90
|
+
"@libp2p/logger": "3.0.2-4ef9c79c",
|
|
91
|
+
"@multiformats/multiaddr": "^12.1.5",
|
|
92
92
|
"is-loopback-addr": "^2.0.1",
|
|
93
93
|
"it-stream-types": "^2.0.1",
|
|
94
94
|
"private-ip": "^3.0.0",
|
|
95
95
|
"uint8arraylist": "^2.4.3"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
|
-
"aegir": "^40.0.
|
|
98
|
+
"aegir": "^40.0.8",
|
|
99
99
|
"it-all": "^3.0.1",
|
|
100
100
|
"it-pair": "^2.0.6",
|
|
101
101
|
"it-pipe": "^3.0.1",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isIPv4, isIPv6 } from '@chainsafe/is-ip'
|
|
2
2
|
import { CodeError } from '@libp2p/interface/errors'
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
|
|
@@ -27,21 +27,15 @@ export function ipPortToMultiaddr (ip: string, port: number | string): Multiaddr
|
|
|
27
27
|
throw new CodeError(`invalid port provided: ${port}`, Errors.ERR_INVALID_PORT_PARAMETER)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
// Test valid IPv4
|
|
32
|
-
new Address4(ip) // eslint-disable-line no-new
|
|
30
|
+
if (isIPv4(ip)) {
|
|
33
31
|
return multiaddr(`/ip4/${ip}/tcp/${port}`)
|
|
34
|
-
} catch {}
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
// Test valid IPv6
|
|
38
|
-
const ip6 = new Address6(ip)
|
|
39
|
-
return ip6.is4()
|
|
40
|
-
? multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`)
|
|
41
|
-
: multiaddr(`/ip6/${ip}/tcp/${port}`)
|
|
42
|
-
} catch (err) {
|
|
43
|
-
const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}`
|
|
44
|
-
log.error(errMsg)
|
|
45
|
-
throw new CodeError(errMsg, Errors.ERR_INVALID_IP)
|
|
46
32
|
}
|
|
33
|
+
|
|
34
|
+
if (isIPv6(ip)) {
|
|
35
|
+
return multiaddr(`/ip6/${ip}/tcp/${port}`)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}`
|
|
39
|
+
log.error(errMsg)
|
|
40
|
+
throw new CodeError(errMsg, Errors.ERR_INVALID_IP)
|
|
47
41
|
}
|