@libp2p/utils 3.0.1 → 3.0.3

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 CHANGED
@@ -1,10 +1,9 @@
1
1
  # @libp2p/utils <!-- omit in toc -->
2
2
 
3
3
  [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4
- [![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
5
4
  [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
6
5
  [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-utils.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-utils)
7
- [![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-utils/actions/workflows/js-test-and-release.yml)
6
+ [![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-utils/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-utils/actions/workflows/js-test-and-release.yml)
8
7
 
9
8
  > Package to aggregate shared logic and dependencies for the libp2p ecosystem
10
9
 
@@ -15,7 +14,7 @@
15
14
  - [Usage](#usage)
16
15
  - [Contribute](#contribute)
17
16
  - [License](#license)
18
- - [Contribution](#contribution)
17
+ - [Contribute](#contribute-1)
19
18
 
20
19
  ## Install
21
20
 
@@ -59,6 +58,6 @@ Licensed under either of
59
58
  - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
60
59
  - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
61
60
 
62
- ## Contribution
61
+ ## Contribute
63
62
 
64
63
  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,WAG9C"}
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"}
@@ -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
- return a.length === b.length && b.sort(sort) && a.sort(sort).every((item, index) => b[index].equals(item));
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;IACzE,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,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;AAC5G,CAAC"}
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":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAMnD,eAAO,MAAM,MAAM;;;;CAIlB,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,aA8BnE"}
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 { Multiaddr } from '@multiformats/multiaddr';
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 new Multiaddr(`/ip4/${ip}/tcp/${port}`);
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
- ? new Multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`)
35
- : new Multiaddr(`/ip6/${ip}/tcp/${port}`);
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,yBAAy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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.1",
3
+ "version": "3.0.3",
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": "chore",
105
+ "type": "docs",
106
106
  "release": "patch"
107
107
  },
108
108
  {
109
- "type": "docs",
109
+ "type": "test",
110
110
  "release": "patch"
111
111
  },
112
112
  {
113
- "type": "test",
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": "Trivial Changes"
143
+ "section": "Documentation"
144
+ },
145
+ {
146
+ "type": "deps",
147
+ "section": "Dependencies"
144
148
  },
145
149
  {
146
150
  "type": "test",
@@ -172,24 +176,24 @@
172
176
  },
173
177
  "dependencies": {
174
178
  "@achingbrain/ip-address": "^8.1.0",
175
- "@libp2p/interface-connection": "^3.0.1",
176
- "@libp2p/interface-peer-store": "^1.0.0",
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": "^10.1.1",
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",
182
186
  "it-stream-types": "^1.0.4",
183
- "private-ip": "^2.1.1",
187
+ "private-ip": "^3.0.0",
184
188
  "uint8arraylist": "^2.3.2"
185
189
  },
186
190
  "devDependencies": {
187
191
  "aegir": "^37.2.0",
188
- "it-all": "^1.0.6",
189
- "it-map": "^1.0.6",
192
+ "it-all": "^2.0.0",
193
+ "it-map": "^2.0.0",
190
194
  "it-pair": "^2.0.2",
191
195
  "it-pipe": "^2.0.2",
192
196
  "p-defer": "^4.0.0",
193
- "uint8arrays": "^3.0.0"
197
+ "uint8arrays": "^4.0.2"
194
198
  }
195
199
  }
@@ -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
- return a.length === b.length && b.sort(sort) && a.sort(sort).every((item, index) => b[index].equals(item))
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 { Multiaddr } from '@multiformats/multiaddr'
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 new Multiaddr(`/ip4/${ip}/tcp/${port}`)
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
- ? new Multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`)
41
- : new Multiaddr(`/ip6/${ip}/tcp/${port}`)
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)