@libp2p/utils 3.0.1 → 3.0.2
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/README.md +2 -2
- package/dist/src/array-equals.d.ts.map +1 -1
- package/dist/src/array-equals.js +5 -1
- package/dist/src/array-equals.js.map +1 -1
- package/dist/src/ip-port-to-multiaddr.d.ts +1 -2
- package/dist/src/ip-port-to-multiaddr.d.ts.map +1 -1
- package/dist/src/ip-port-to-multiaddr.js +4 -4
- package/dist/src/ip-port-to-multiaddr.js.map +1 -1
- package/package.json +12 -8
- package/src/array-equals.ts +8 -1
- package/src/ip-port-to-multiaddr.ts +4 -4
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
- [Usage](#usage)
|
|
16
16
|
- [Contribute](#contribute)
|
|
17
17
|
- [License](#license)
|
|
18
|
-
- [
|
|
18
|
+
- [Contribute](#contribute-1)
|
|
19
19
|
|
|
20
20
|
## Install
|
|
21
21
|
|
|
@@ -59,6 +59,6 @@ Licensed under either of
|
|
|
59
59
|
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
60
60
|
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
61
61
|
|
|
62
|
-
##
|
|
62
|
+
## Contribute
|
|
63
63
|
|
|
64
64
|
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-equals.d.ts","sourceRoot":"","sources":["../../src/array-equals.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,WAAW,CAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"array-equals.d.ts","sourceRoot":"","sources":["../../src/array-equals.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,WAAW,CAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,WAU9C"}
|
package/dist/src/array-equals.js
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export function arrayEquals(a, b) {
|
|
6
6
|
const sort = (a, b) => a.toString().localeCompare(b.toString());
|
|
7
|
-
|
|
7
|
+
if (a.length !== b.length) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
b.sort(sort);
|
|
11
|
+
return a.sort(sort).every((item, index) => b[index].equals(item));
|
|
8
12
|
}
|
|
9
13
|
//# sourceMappingURL=array-equals.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-equals.js","sourceRoot":"","sources":["../../src/array-equals.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAE,CAAQ,EAAE,CAAQ;IAC7C,MAAM,IAAI,GAAG,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"array-equals.js","sourceRoot":"","sources":["../../src/array-equals.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAE,CAAQ,EAAE,CAAQ;IAC7C,MAAM,IAAI,GAAG,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;IAEzE,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE;QACzB,OAAO,KAAK,CAAA;KACb;IAED,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEZ,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;AACnE,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Multiaddr } from '@multiformats/multiaddr';
|
|
2
1
|
export declare const Errors: {
|
|
3
2
|
ERR_INVALID_IP_PARAMETER: string;
|
|
4
3
|
ERR_INVALID_PORT_PARAMETER: string;
|
|
@@ -7,5 +6,5 @@ export declare const Errors: {
|
|
|
7
6
|
/**
|
|
8
7
|
* Transform an IP, Port pair into a multiaddr
|
|
9
8
|
*/
|
|
10
|
-
export declare function ipPortToMultiaddr(ip: string, port: number | string): Multiaddr;
|
|
9
|
+
export declare function ipPortToMultiaddr(ip: string, port: number | string): import("@multiformats/multiaddr").Multiaddr;
|
|
11
10
|
//# sourceMappingURL=ip-port-to-multiaddr.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ip-port-to-multiaddr.d.ts","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ip-port-to-multiaddr.d.ts","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,MAAM;;;;CAIlB,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,+CA8BnE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger';
|
|
2
|
-
import {
|
|
2
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
3
3
|
import errCode from 'err-code';
|
|
4
4
|
import { Address4, Address6 } from '@achingbrain/ip-address';
|
|
5
5
|
const log = logger('libp2p:ip-port-to-multiaddr');
|
|
@@ -24,15 +24,15 @@ export function ipPortToMultiaddr(ip, port) {
|
|
|
24
24
|
try {
|
|
25
25
|
// Test valid IPv4
|
|
26
26
|
new Address4(ip); // eslint-disable-line no-new
|
|
27
|
-
return
|
|
27
|
+
return multiaddr(`/ip4/${ip}/tcp/${port}`);
|
|
28
28
|
}
|
|
29
29
|
catch { }
|
|
30
30
|
try {
|
|
31
31
|
// Test valid IPv6
|
|
32
32
|
const ip6 = new Address6(ip);
|
|
33
33
|
return ip6.is4()
|
|
34
|
-
?
|
|
35
|
-
:
|
|
34
|
+
? multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`)
|
|
35
|
+
: multiaddr(`/ip6/${ip}/tcp/${port}`);
|
|
36
36
|
}
|
|
37
37
|
catch (err) {
|
|
38
38
|
const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}`;
|
|
@@ -1 +1 @@
|
|
|
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,gBAAgB,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAE5D,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,OAAO,CAAC,IAAI,KAAK,CAAC,wBAAwB,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,wBAAwB,CAAC,CAAA,CAAC,uEAAuE;K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AO,CAAC,IAAI,KAAK,CAAC,0BAA0B,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,0BAA0B,CAAC,CAAA;KAC9F;IAED,IAAI;QACF,kBAAkB;QAClB,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAA,CAAC,6BAA6B;QAC9C,OAAO,SAAS,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;KAC3C;IAAC,MAAM,GAAE;IAEV,IAAI;QACF,kBAAkB;QAClB,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAA;QAC5B,OAAO,GAAG,CAAC,GAAG,EAAE;YACd,CAAC,CAAC,SAAS,CAAC,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,QAAQ,IAAI,EAAE,CAAC;YAC1D,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;KACxC;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,MAAM,GAAG,6CAA6C,EAAE,IAAI,IAAI,EAAE,CAAA;QACxE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QACjB,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC,CAAA;KACxD;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/utils",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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-utils#readme",
|
|
@@ -102,15 +102,15 @@
|
|
|
102
102
|
"release": "patch"
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
|
-
"type": "
|
|
105
|
+
"type": "docs",
|
|
106
106
|
"release": "patch"
|
|
107
107
|
},
|
|
108
108
|
{
|
|
109
|
-
"type": "
|
|
109
|
+
"type": "test",
|
|
110
110
|
"release": "patch"
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
|
-
"type": "
|
|
113
|
+
"type": "deps",
|
|
114
114
|
"release": "patch"
|
|
115
115
|
},
|
|
116
116
|
{
|
|
@@ -140,7 +140,11 @@
|
|
|
140
140
|
},
|
|
141
141
|
{
|
|
142
142
|
"type": "docs",
|
|
143
|
-
"section": "
|
|
143
|
+
"section": "Documentation"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"type": "deps",
|
|
147
|
+
"section": "Dependencies"
|
|
144
148
|
},
|
|
145
149
|
{
|
|
146
150
|
"type": "test",
|
|
@@ -172,10 +176,10 @@
|
|
|
172
176
|
},
|
|
173
177
|
"dependencies": {
|
|
174
178
|
"@achingbrain/ip-address": "^8.1.0",
|
|
175
|
-
"@libp2p/interface-connection": "^3.0.
|
|
176
|
-
"@libp2p/interface-peer-store": "^1.
|
|
179
|
+
"@libp2p/interface-connection": "^3.0.2",
|
|
180
|
+
"@libp2p/interface-peer-store": "^1.2.1",
|
|
177
181
|
"@libp2p/logger": "^2.0.0",
|
|
178
|
-
"@multiformats/multiaddr": "^
|
|
182
|
+
"@multiformats/multiaddr": "^11.0.0",
|
|
179
183
|
"abortable-iterator": "^4.0.2",
|
|
180
184
|
"err-code": "^3.0.1",
|
|
181
185
|
"is-loopback-addr": "^2.0.1",
|
package/src/array-equals.ts
CHANGED
|
@@ -4,5 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export function arrayEquals (a: any[], b: any[]) {
|
|
6
6
|
const sort = (a: any, b: any) => a.toString().localeCompare(b.toString())
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
if (a.length !== b.length) {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
b.sort(sort)
|
|
13
|
+
|
|
14
|
+
return a.sort(sort).every((item, index) => b[index].equals(item))
|
|
8
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
|
-
import {
|
|
2
|
+
import { multiaddr } from '@multiformats/multiaddr'
|
|
3
3
|
import errCode from 'err-code'
|
|
4
4
|
import { Address4, Address6 } from '@achingbrain/ip-address'
|
|
5
5
|
|
|
@@ -30,15 +30,15 @@ export function ipPortToMultiaddr (ip: string, port: number | string) {
|
|
|
30
30
|
try {
|
|
31
31
|
// Test valid IPv4
|
|
32
32
|
new Address4(ip) // eslint-disable-line no-new
|
|
33
|
-
return
|
|
33
|
+
return multiaddr(`/ip4/${ip}/tcp/${port}`)
|
|
34
34
|
} catch {}
|
|
35
35
|
|
|
36
36
|
try {
|
|
37
37
|
// Test valid IPv6
|
|
38
38
|
const ip6 = new Address6(ip)
|
|
39
39
|
return ip6.is4()
|
|
40
|
-
?
|
|
41
|
-
:
|
|
40
|
+
? multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`)
|
|
41
|
+
: multiaddr(`/ip6/${ip}/tcp/${port}`)
|
|
42
42
|
} catch (err) {
|
|
43
43
|
const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}`
|
|
44
44
|
log.error(errMsg)
|