@libp2p/utils 3.0.3 → 3.0.4
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 +16 -14
- package/dist/index.min.js +3 -0
- package/dist/src/address-sort.d.ts +25 -0
- package/dist/src/address-sort.d.ts.map +1 -1
- package/dist/src/address-sort.js +27 -0
- package/dist/src/address-sort.js.map +1 -1
- package/dist/src/array-equals.d.ts +18 -0
- package/dist/src/array-equals.d.ts.map +1 -1
- package/dist/src/array-equals.js +18 -0
- package/dist/src/array-equals.js.map +1 -1
- package/dist/src/stream-to-ma-conn.d.ts +2 -3
- package/dist/src/stream-to-ma-conn.d.ts.map +1 -1
- package/dist/typedoc-urls.json +13 -0
- package/package.json +3 -2
- package/src/address-sort.ts +29 -0
- package/src/array-equals.ts +19 -0
- package/src/stream-to-ma-conn.ts +2 -2
package/README.md
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
[](http://libp2p.io/)
|
|
4
4
|
[](https://discuss.libp2p.io)
|
|
5
5
|
[](https://codecov.io/gh/libp2p/js-libp2p-utils)
|
|
6
|
-
[](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
|
-
- [
|
|
13
|
+
- [Browser `<script>` tag](#browser-script-tag)
|
|
14
14
|
- [Usage](#usage)
|
|
15
|
-
- [
|
|
15
|
+
- [API Docs](#api-docs)
|
|
16
16
|
- [License](#license)
|
|
17
|
-
- [
|
|
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](
|
|
47
|
-
|
|
48
|
-
## Contribute
|
|
50
|
+
You can check the [API docs](https://libp2p.github.io/js-libp2p-utils).
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
## API Docs
|
|
51
53
|
|
|
52
|
-
|
|
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
|
-
##
|
|
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"}
|
package/dist/src/address-sort.js
CHANGED
|
@@ -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":"
|
|
1
|
+
{"version":3,"file":"address-sort.js","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAE,CAAU,EAAE,CAAU;IAC1D,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACzC,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAEzC,IAAI,UAAU,IAAI,CAAC,UAAU,EAAE;QAC7B,OAAO,CAAC,CAAA;KACT;SAAM,IAAI,CAAC,UAAU,IAAI,UAAU,EAAE;QACpC,OAAO,CAAC,CAAC,CAAA;KACV;IACD,mBAAmB;IACnB,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE;QACnC,OAAO,CAAC,CAAC,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,WAU9C"}
|
package/dist/src/array-equals.js
CHANGED
|
@@ -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,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"}
|
|
@@ -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,QAAQ;IACvB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,
|
|
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,QAAQ;IACvB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAA;CAErB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC,cAAc,EAAE,cAAc,GAAG,UAAU,CAAC,CAAA;IAC3D,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,SAAS,CAAA;CACrB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,GAAE,aAAkB,uBAiDzF"}
|
|
@@ -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
|
+
"version": "3.0.4",
|
|
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
|
|
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",
|
package/src/address-sort.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/array-equals.ts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
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.
|
package/src/stream-to-ma-conn.ts
CHANGED
|
@@ -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
|