@libp2p/utils 3.0.3 → 3.0.5

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
@@ -3,18 +3,18 @@
3
3
  [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4
4
  [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
5
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)
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)
6
+ [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-utils/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-utils/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
7
7
 
8
8
  > Package to aggregate shared logic and dependencies for the libp2p ecosystem
9
9
 
10
10
  ## Table of contents <!-- omit in toc -->
11
11
 
12
12
  - [Install](#install)
13
- - [Lead Maintainer](#lead-maintainer)
13
+ - [Browser `<script>` tag](#browser-script-tag)
14
14
  - [Usage](#usage)
15
- - [Contribute](#contribute)
15
+ - [API Docs](#api-docs)
16
16
  - [License](#license)
17
- - [Contribute](#contribute-1)
17
+ - [Contribution](#contribution)
18
18
 
19
19
  ## Install
20
20
 
@@ -22,6 +22,14 @@
22
22
  $ npm i @libp2p/utils
23
23
  ```
24
24
 
25
+ ### Browser `<script>` tag
26
+
27
+ Loading this module through a script tag will make it's exports available as `Libp2pUtils` in the global namespace.
28
+
29
+ ```html
30
+ <script src="https://unpkg.com/@libp2p/utils/dist/index.min.js"></script>
31
+ ```
32
+
25
33
  The libp2p ecosystem has lots of repos with it comes several problems like:
26
34
 
27
35
  - Domain logic dedupe - all modules shared a lot of logic like validation, streams handling, etc.
@@ -29,10 +37,6 @@ The libp2p ecosystem has lots of repos with it comes several problems like:
29
37
 
30
38
  These problems are the motivation for this package, having shared logic in this package avoids creating cyclic dependencies, centralizes common use modules/functions (exactly like aegir does for the tooling), semantic versioning for 3rd party dependencies is handled in one single place (a good example is going from streams 2 to 3) and maintainers should only care about having `libp2p-utils` updated.
31
39
 
32
- ## Lead Maintainer
33
-
34
- [Vasco Santos](https://github.com/vasco-santos)
35
-
36
40
  ## Usage
37
41
 
38
42
  Each function should be imported directly.
@@ -43,13 +47,11 @@ import ipAndPortToMultiaddr from '@libp2p/utils/ip-port-to-multiaddr'
43
47
  const ma = ipAndPortToMultiaddr('127.0.0.1', 9000)
44
48
  ```
45
49
 
46
- You can check the [API docs](./API.md).
47
-
48
- ## Contribute
50
+ You can check the [API docs](https://libp2p.github.io/js-libp2p-utils).
49
51
 
50
- Contributions welcome. Please check out [the issues](https://github.com/libp2p/js-libp2p-utils/issues).
52
+ ## API Docs
51
53
 
52
- Check out our [contributing document](https://github.com/ipfs/community/blob/master/contributing.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
54
+ - <https://libp2p.github.io/js-libp2p-utils>
53
55
 
54
56
  ## License
55
57
 
@@ -58,6 +60,6 @@ Licensed under either of
58
60
  - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
59
61
  - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
60
62
 
61
- ## Contribute
63
+ ## Contribution
62
64
 
63
65
  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.
@@ -0,0 +1,3 @@
1
+ (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PUtils = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
+ "use strict";var Libp2PUtils=(()=>{var t=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var d=(o,e,x,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let p of b(e))!c.call(o,p)&&p!==x&&t(o,p,{get:()=>e[p],enumerable:!(r=a(e,p))||r.enumerable});return o};var f=o=>d(t({},"__esModule",{value:!0}),o);var g={};return f(g);})();
3
+ return Libp2PUtils}));
@@ -1,3 +1,24 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Provides strategies to sort a list of multiaddrs.
5
+ *
6
+ * @example
7
+ *
8
+ * ```typescript
9
+ * import { publicAddressesFirst } from '@libp2p/utils/address-sort'
10
+ * import { multiaddr } from '@multformats/multiaddr'
11
+ *
12
+ *
13
+ * const addresses = [
14
+ * multiaddr('/ip4/127.0.0.1/tcp/9000'),
15
+ * multiaddr('/ip4/82.41.53.1/tcp/9000')
16
+ * ].sort(publicAddressesFirst)
17
+ *
18
+ * console.info(addresses)
19
+ * // ['/ip4/82.41.53.1/tcp/9000', '/ip4/127.0.0.1/tcp/9000']
20
+ * ```
21
+ */
1
22
  import type { Address } from '@libp2p/interface-peer-store';
2
23
  /**
3
24
  * Compare function for array.sort().
@@ -5,4 +26,8 @@ import type { Address } from '@libp2p/interface-peer-store';
5
26
  * In case of equality, a certified address will come first.
6
27
  */
7
28
  export declare function publicAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
29
+ /**
30
+ * A test thing
31
+ */
32
+ export declare function something(): Promise<Uint8Array>;
8
33
  //# sourceMappingURL=address-sort.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"address-sort.d.ts","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAG3D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAiBxE"}
1
+ {"version":3,"file":"address-sort.d.ts","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAG3D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAiBxE;AAED;;GAEG;AACH,wBAAsB,SAAS,IAAK,OAAO,CAAC,UAAU,CAAC,CAEtD"}
@@ -1,3 +1,24 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Provides strategies to sort a list of multiaddrs.
5
+ *
6
+ * @example
7
+ *
8
+ * ```typescript
9
+ * import { publicAddressesFirst } from '@libp2p/utils/address-sort'
10
+ * import { multiaddr } from '@multformats/multiaddr'
11
+ *
12
+ *
13
+ * const addresses = [
14
+ * multiaddr('/ip4/127.0.0.1/tcp/9000'),
15
+ * multiaddr('/ip4/82.41.53.1/tcp/9000')
16
+ * ].sort(publicAddressesFirst)
17
+ *
18
+ * console.info(addresses)
19
+ * // ['/ip4/82.41.53.1/tcp/9000', '/ip4/127.0.0.1/tcp/9000']
20
+ * ```
21
+ */
1
22
  import { isPrivate } from './multiaddr/is-private.js';
2
23
  /**
3
24
  * Compare function for array.sort().
@@ -22,4 +43,10 @@ export function publicAddressesFirst(a, b) {
22
43
  }
23
44
  return 0;
24
45
  }
46
+ /**
47
+ * A test thing
48
+ */
49
+ export async function something() {
50
+ return Uint8Array.from([0, 1, 2]);
51
+ }
25
52
  //# sourceMappingURL=address-sort.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"address-sort.js","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SA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C,CAAA;KACV;SAAM,IAAI,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,WAAW,EAAE;QAC1C,OAAO,CAAC,CAAA;KACT;IAED,OAAO,CAAC,CAAA;AACV,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AACnC,CAAC"}
@@ -1,3 +1,21 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Provides strategies ensure arrays are equivalent.
5
+ *
6
+ * @example
7
+ *
8
+ * ```typescript
9
+ * import { arrayEquals } from '@libp2p/utils/array-equals'
10
+ * import { multiaddr } from '@multformats/multiaddr'
11
+ *
12
+ * const ma1 = multiaddr('/ip4/127.0.0.1/tcp/9000'),
13
+ * const ma2 = multiaddr('/ip4/82.41.53.1/tcp/9000')
14
+ *
15
+ * console.info(arrayEquals([ma1], [ma1])) // true
16
+ * console.info(arrayEquals([ma1], [ma2])) // false
17
+ * ```
18
+ */
1
19
  /**
2
20
  * Verify if two arrays of non primitive types with the "equals" function are equal.
3
21
  * Compatible with multiaddr, peer-id and others.
@@ -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,WAU9C"}
1
+ {"version":3,"file":"array-equals.d.ts","sourceRoot":"","sources":["../../src/array-equals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;GAGG;AACH,wBAAgB,WAAW,CAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAUxD"}
@@ -1,3 +1,21 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Provides strategies ensure arrays are equivalent.
5
+ *
6
+ * @example
7
+ *
8
+ * ```typescript
9
+ * import { arrayEquals } from '@libp2p/utils/array-equals'
10
+ * import { multiaddr } from '@multformats/multiaddr'
11
+ *
12
+ * const ma1 = multiaddr('/ip4/127.0.0.1/tcp/9000'),
13
+ * const ma2 = multiaddr('/ip4/82.41.53.1/tcp/9000')
14
+ *
15
+ * console.info(arrayEquals([ma1], [ma1])) // true
16
+ * console.info(arrayEquals([ma1], [ma2])) // false
17
+ * ```
18
+ */
1
19
  /**
2
20
  * Verify if two arrays of non primitive types with the "equals" function are equal.
3
21
  * Compatible with multiaddr, peer-id and others.
@@ -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;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
+ {"version":3,"file":"array-equals.js","sourceRoot":"","sources":["../../src/array-equals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAE,CAAQ,EAAE,CAAQ;IAC7C,MAAM,IAAI,GAAG,CAAC,CAAM,EAAE,CAAM,EAAU,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;IAEjF,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,3 +1,4 @@
1
+ import { Multiaddr } from '@multiformats/multiaddr';
1
2
  export declare const Errors: {
2
3
  ERR_INVALID_IP_PARAMETER: string;
3
4
  ERR_INVALID_PORT_PARAMETER: string;
@@ -6,5 +7,5 @@ export declare const Errors: {
6
7
  /**
7
8
  * Transform an IP, Port pair into a multiaddr
8
9
  */
9
- export declare function ipPortToMultiaddr(ip: string, port: number | string): import("@multiformats/multiaddr").Multiaddr;
10
+ export declare function ipPortToMultiaddr(ip: string, port: number | string): Multiaddr;
10
11
  //# 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":"AAOA,eAAO,MAAM,MAAM;;;;CAIlB,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,+CA8BnE"}
1
+ {"version":3,"file":"ip-port-to-multiaddr.d.ts","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAa,MAAM,yBAAyB,CAAA;AAM9D,eAAO,MAAM,MAAM;;;;CAIlB,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA8B/E"}
@@ -1,6 +1,6 @@
1
1
  import { logger } from '@libp2p/logger';
2
2
  import { multiaddr } from '@multiformats/multiaddr';
3
- import errCode from 'err-code';
3
+ import { CodeError } from '@libp2p/interfaces/errors';
4
4
  import { Address4, Address6 } from '@achingbrain/ip-address';
5
5
  const log = logger('libp2p:ip-port-to-multiaddr');
6
6
  export const Errors = {
@@ -13,13 +13,13 @@ export const Errors = {
13
13
  */
14
14
  export function ipPortToMultiaddr(ip, port) {
15
15
  if (typeof ip !== 'string') {
16
- throw errCode(new Error(`invalid ip provided: ${ip}`), Errors.ERR_INVALID_IP_PARAMETER); // eslint-disable-line @typescript-eslint/restrict-template-expressions
16
+ throw new CodeError(`invalid ip provided: ${ip}`, Errors.ERR_INVALID_IP_PARAMETER); // eslint-disable-line @typescript-eslint/restrict-template-expressions
17
17
  }
18
18
  if (typeof port === 'string') {
19
19
  port = parseInt(port);
20
20
  }
21
21
  if (isNaN(port)) {
22
- throw errCode(new Error(`invalid port provided: ${port}`), Errors.ERR_INVALID_PORT_PARAMETER);
22
+ throw new CodeError(`invalid port provided: ${port}`, Errors.ERR_INVALID_PORT_PARAMETER);
23
23
  }
24
24
  try {
25
25
  // Test valid IPv4
@@ -37,7 +37,7 @@ export function ipPortToMultiaddr(ip, port) {
37
37
  catch (err) {
38
38
  const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}`;
39
39
  log.error(errMsg);
40
- throw errCode(new Error(errMsg), Errors.ERR_INVALID_IP);
40
+ throw new CodeError(errMsg, Errors.ERR_INVALID_IP);
41
41
  }
42
42
  }
43
43
  //# 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,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f,MAAM,IAAI,SAAS,CAAC,0BAA0B,IAAI,EAAE,EAAE,MAAM,CAAC,0BAA0B,CAAC,CAAA;KACzF;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,IAAI,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,CAAA;KACnD;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"is-loopback.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-loopback.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;GAEG;AACH,wBAAgB,UAAU,CAAE,EAAE,EAAE,SAAS,WAIxC"}
1
+ {"version":3,"file":"is-loopback.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-loopback.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;GAEG;AACH,wBAAgB,UAAU,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAIlD"}
@@ -1 +1 @@
1
- {"version":3,"file":"is-private.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-private.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGxD;;GAEG;AACH,wBAAgB,SAAS,CAAE,EAAE,EAAE,SAAS,WAIvC"}
1
+ {"version":3,"file":"is-private.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-private.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGxD;;GAEG;AACH,wBAAgB,SAAS,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAIjD"}
@@ -16,10 +16,10 @@ export interface Timeline {
16
16
  */
17
17
  close?: number;
18
18
  }
19
- interface StreamOptions {
19
+ export interface StreamOptions {
20
20
  signal?: AbortSignal;
21
21
  }
22
- interface StreamProperties {
22
+ export interface StreamProperties {
23
23
  stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>;
24
24
  remoteAddr: Multiaddr;
25
25
  localAddr: Multiaddr;
@@ -29,5 +29,4 @@ interface StreamProperties {
29
29
  * https://github.com/libp2p/interface-transport#multiaddrconnection
30
30
  */
31
31
  export declare function streamToMaConnection(props: StreamProperties, options?: StreamOptions): MultiaddrConnection;
32
- export {};
33
32
  //# sourceMappingURL=stream-to-ma-conn.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream-to-ma-conn.d.ts","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAIpD,MAAM,WAAW,QAA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AAK,EAAE,gBAAgB,EAAE,OAAO,GAAE,aAAkB,GAAG,mBAAmB,CAiD/G"}
@@ -47,7 +47,7 @@ export function streamToMaConnection(props, options = {}) {
47
47
  if (maConn.timeline.close == null) {
48
48
  maConn.timeline.close = Date.now();
49
49
  }
50
- return await Promise.resolve();
50
+ await Promise.resolve();
51
51
  }
52
52
  return maConn;
53
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAMvC,MAAM,GAAG,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAA;AA8B7C;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAE,KAAuB,EAAE,UAAyB,EAAE;IACxF,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAA;IACpC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IAE/B,MAAM,SAAS,GAAG,CAAC,KAAK,SAAU,CAAC;QACjC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,EAAE;YAC/B,KAAM,CAAC,CAAC,IAAI,CAAA;SACb;IACH,CAAC,EAAE,CAAC,CAAA;IAEJ,MAAM,MAAM,GAAwB;QAClC,KAAK,CAAC,IAAI,CAAE,MAAM;YAChB,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI,EAAE;gBAC1B,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;aACjD;YAED,IAAI;gBACF,MAAM,IAAI,CAAC,MAAM,CAAC,CAAA;gBAClB,MAAM,KAAK,EAAE,CAAA;aACd;YAAC,OAAO,GAAQ,EAAE;gBACjB,kCAAkC;gBAClC,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE;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YACjC,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;SACnC;QACD,MAAM,OAAO,CAAC,OAAO,EAAE,CAAA;IACzB,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,13 @@
1
+ {
2
+ "publicAddressesFirst": "https://libp2p.github.io/js-libp2p-utils/functions/address_sort.publicAddressesFirst.html",
3
+ "something": "https://libp2p.github.io/js-libp2p-utils/functions/address_sort.something.html",
4
+ "arrayEquals": "https://libp2p.github.io/js-libp2p-utils/functions/array_equals.arrayEquals.html",
5
+ "Errors": "https://libp2p.github.io/js-libp2p-utils/variables/ip_port_to_multiaddr.Errors.html",
6
+ "ipPortToMultiaddr": "https://libp2p.github.io/js-libp2p-utils/functions/ip_port_to_multiaddr.ipPortToMultiaddr.html",
7
+ "isLoopback": "https://libp2p.github.io/js-libp2p-utils/functions/multiaddr_is_loopback.isLoopback.html",
8
+ "isPrivate": "https://libp2p.github.io/js-libp2p-utils/functions/multiaddr_is_private.isPrivate.html",
9
+ "StreamOptions": "https://libp2p.github.io/js-libp2p-utils/interfaces/stream_to_ma_conn.StreamOptions.html",
10
+ "StreamProperties": "https://libp2p.github.io/js-libp2p-utils/interfaces/stream_to_ma_conn.StreamProperties.html",
11
+ "Timeline": "https://libp2p.github.io/js-libp2p-utils/interfaces/stream_to_ma_conn.Timeline.html",
12
+ "streamToMaConnection": "https://libp2p.github.io/js-libp2p-utils/functions/stream_to_ma_conn.streamToMaConnection.html"
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/utils",
3
- "version": "3.0.3",
3
+ "version": "3.0.5",
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",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "files": [
37
37
  "src",
38
- "dist/src",
38
+ "dist",
39
39
  "!dist/test",
40
40
  "!**/*.tsbuildinfo"
41
41
  ],
@@ -165,6 +165,7 @@
165
165
  "lint": "aegir lint",
166
166
  "dep-check": "aegir dep-check",
167
167
  "build": "aegir build",
168
+ "docs": "aegir docs",
168
169
  "test": "aegir test",
169
170
  "test:chrome": "aegir test -t browser --cov",
170
171
  "test:chrome-webworker": "aegir test -t webworker",
@@ -178,20 +179,19 @@
178
179
  "@achingbrain/ip-address": "^8.1.0",
179
180
  "@libp2p/interface-connection": "^3.0.2",
180
181
  "@libp2p/interface-peer-store": "^1.2.1",
182
+ "@libp2p/interfaces": "^3.2.0",
181
183
  "@libp2p/logger": "^2.0.0",
182
- "@multiformats/multiaddr": "^11.0.0",
184
+ "@multiformats/multiaddr": "^12.0.0",
183
185
  "abortable-iterator": "^4.0.2",
184
- "err-code": "^3.0.1",
185
186
  "is-loopback-addr": "^2.0.1",
186
187
  "it-stream-types": "^1.0.4",
187
188
  "private-ip": "^3.0.0",
188
189
  "uint8arraylist": "^2.3.2"
189
190
  },
190
191
  "devDependencies": {
191
- "aegir": "^37.2.0",
192
+ "aegir": "^38.1.7",
192
193
  "it-all": "^2.0.0",
193
194
  "it-map": "^2.0.0",
194
- "it-pair": "^2.0.2",
195
195
  "it-pipe": "^2.0.2",
196
196
  "p-defer": "^4.0.0",
197
197
  "uint8arrays": "^4.0.2"
@@ -1,3 +1,25 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Provides strategies to sort a list of multiaddrs.
5
+ *
6
+ * @example
7
+ *
8
+ * ```typescript
9
+ * import { publicAddressesFirst } from '@libp2p/utils/address-sort'
10
+ * import { multiaddr } from '@multformats/multiaddr'
11
+ *
12
+ *
13
+ * const addresses = [
14
+ * multiaddr('/ip4/127.0.0.1/tcp/9000'),
15
+ * multiaddr('/ip4/82.41.53.1/tcp/9000')
16
+ * ].sort(publicAddressesFirst)
17
+ *
18
+ * console.info(addresses)
19
+ * // ['/ip4/82.41.53.1/tcp/9000', '/ip4/127.0.0.1/tcp/9000']
20
+ * ```
21
+ */
22
+
1
23
  import type { Address } from '@libp2p/interface-peer-store'
2
24
  import { isPrivate } from './multiaddr/is-private.js'
3
25
 
@@ -24,3 +46,10 @@ export function publicAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
24
46
 
25
47
  return 0
26
48
  }
49
+
50
+ /**
51
+ * A test thing
52
+ */
53
+ export async function something (): Promise<Uint8Array> {
54
+ return Uint8Array.from([0, 1, 2])
55
+ }
@@ -1,9 +1,28 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Provides strategies ensure arrays are equivalent.
5
+ *
6
+ * @example
7
+ *
8
+ * ```typescript
9
+ * import { arrayEquals } from '@libp2p/utils/array-equals'
10
+ * import { multiaddr } from '@multformats/multiaddr'
11
+ *
12
+ * const ma1 = multiaddr('/ip4/127.0.0.1/tcp/9000'),
13
+ * const ma2 = multiaddr('/ip4/82.41.53.1/tcp/9000')
14
+ *
15
+ * console.info(arrayEquals([ma1], [ma1])) // true
16
+ * console.info(arrayEquals([ma1], [ma2])) // false
17
+ * ```
18
+ */
19
+
1
20
  /**
2
21
  * Verify if two arrays of non primitive types with the "equals" function are equal.
3
22
  * Compatible with multiaddr, peer-id and others.
4
23
  */
5
- export function arrayEquals (a: any[], b: any[]) {
6
- const sort = (a: any, b: any) => a.toString().localeCompare(b.toString())
24
+ export function arrayEquals (a: any[], b: any[]): boolean {
25
+ const sort = (a: any, b: any): number => a.toString().localeCompare(b.toString())
7
26
 
8
27
  if (a.length !== b.length) {
9
28
  return false
@@ -1,6 +1,6 @@
1
1
  import { logger } from '@libp2p/logger'
2
- import { multiaddr } from '@multiformats/multiaddr'
3
- import errCode from 'err-code'
2
+ import { Multiaddr, multiaddr } from '@multiformats/multiaddr'
3
+ import { CodeError } from '@libp2p/interfaces/errors'
4
4
  import { Address4, Address6 } from '@achingbrain/ip-address'
5
5
 
6
6
  const log = logger('libp2p:ip-port-to-multiaddr')
@@ -14,9 +14,9 @@ export const Errors = {
14
14
  /**
15
15
  * Transform an IP, Port pair into a multiaddr
16
16
  */
17
- export function ipPortToMultiaddr (ip: string, port: number | string) {
17
+ export function ipPortToMultiaddr (ip: string, port: number | string): Multiaddr {
18
18
  if (typeof ip !== 'string') {
19
- throw errCode(new Error(`invalid ip provided: ${ip}`), Errors.ERR_INVALID_IP_PARAMETER) // eslint-disable-line @typescript-eslint/restrict-template-expressions
19
+ throw new CodeError(`invalid ip provided: ${ip}`, Errors.ERR_INVALID_IP_PARAMETER) // eslint-disable-line @typescript-eslint/restrict-template-expressions
20
20
  }
21
21
 
22
22
  if (typeof port === 'string') {
@@ -24,7 +24,7 @@ export function ipPortToMultiaddr (ip: string, port: number | string) {
24
24
  }
25
25
 
26
26
  if (isNaN(port)) {
27
- throw errCode(new Error(`invalid port provided: ${port}`), Errors.ERR_INVALID_PORT_PARAMETER)
27
+ throw new CodeError(`invalid port provided: ${port}`, Errors.ERR_INVALID_PORT_PARAMETER)
28
28
  }
29
29
 
30
30
  try {
@@ -42,6 +42,6 @@ export function ipPortToMultiaddr (ip: string, port: number | string) {
42
42
  } catch (err) {
43
43
  const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}`
44
44
  log.error(errMsg)
45
- throw errCode(new Error(errMsg), Errors.ERR_INVALID_IP)
45
+ throw new CodeError(errMsg, Errors.ERR_INVALID_IP)
46
46
  }
47
47
  }
@@ -4,7 +4,7 @@ import type { Multiaddr } from '@multiformats/multiaddr'
4
4
  /**
5
5
  * Check if a given multiaddr is a loopback address.
6
6
  */
7
- export function isLoopback (ma: Multiaddr) {
7
+ export function isLoopback (ma: Multiaddr): boolean {
8
8
  const { address } = ma.nodeAddress()
9
9
 
10
10
  return isLoopbackAddr(address)
@@ -4,7 +4,7 @@ import isIpPrivate from 'private-ip'
4
4
  /**
5
5
  * Check if a given multiaddr has a private address.
6
6
  */
7
- export function isPrivate (ma: Multiaddr) {
7
+ export function isPrivate (ma: Multiaddr): boolean {
8
8
  const { address } = ma.nodeAddress()
9
9
 
10
10
  return Boolean(isIpPrivate(address))
@@ -24,12 +24,12 @@ export interface Timeline {
24
24
  close?: number
25
25
  }
26
26
 
27
- interface StreamOptions {
27
+ export interface StreamOptions {
28
28
  signal?: AbortSignal
29
29
 
30
30
  }
31
31
 
32
- interface StreamProperties {
32
+ export interface StreamProperties {
33
33
  stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>
34
34
  remoteAddr: Multiaddr
35
35
  localAddr: Multiaddr
@@ -39,7 +39,7 @@ interface StreamProperties {
39
39
  * Convert a duplex iterable into a MultiaddrConnection.
40
40
  * https://github.com/libp2p/interface-transport#multiaddrconnection
41
41
  */
42
- export function streamToMaConnection (props: StreamProperties, options: StreamOptions = {}) {
42
+ export function streamToMaConnection (props: StreamProperties, options: StreamOptions = {}): MultiaddrConnection {
43
43
  const { stream, remoteAddr } = props
44
44
  const { sink, source } = stream
45
45
 
@@ -80,11 +80,11 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp
80
80
  }
81
81
  }
82
82
 
83
- async function close () {
83
+ async function close (): Promise<void> {
84
84
  if (maConn.timeline.close == null) {
85
85
  maConn.timeline.close = Date.now()
86
86
  }
87
- return await Promise.resolve()
87
+ await Promise.resolve()
88
88
  }
89
89
 
90
90
  return maConn