@libp2p/utils 1.0.8 → 2.0.0
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 +31 -18
- package/dist/src/address-sort.d.ts +4 -8
- package/dist/src/address-sort.d.ts.map +1 -1
- package/dist/src/address-sort.js +2 -9
- package/dist/src/address-sort.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/stream-to-ma-conn.d.ts +1 -1
- package/package.json +32 -27
- package/src/address-sort.ts +3 -16
- package/src/index.ts +1 -0
- package/src/stream-to-ma-conn.ts +1 -1
package/README.md
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @libp2p/utils <!-- omit in toc -->
|
|
2
2
|
|
|
3
|
-
[](https://travis-ci.com/libp2p/js-libp2p-utils)
|
|
9
|
-
[](https://david-dm.org/libp2p/js-libp2p-utils)
|
|
10
|
-
[](https://github.com/feross/standard)
|
|
3
|
+
[](http://libp2p.io/)
|
|
4
|
+
[](http://webchat.freenode.net/?channels=%23libp2p)
|
|
5
|
+
[](https://discuss.libp2p.io)
|
|
6
|
+
[](https://codecov.io/gh/libp2p/js-libp2p-utils)
|
|
7
|
+
[](https://github.com/libp2p/js-libp2p-utils/actions/workflows/js-test-and-release.yml)
|
|
11
8
|
|
|
12
|
-
>
|
|
9
|
+
> Package to aggregate shared logic and dependencies for the libp2p ecosystem
|
|
13
10
|
|
|
11
|
+
## Table of contents <!-- omit in toc -->
|
|
12
|
+
|
|
13
|
+
- [Install](#install)
|
|
14
|
+
- [Lead Maintainer](#lead-maintainer)
|
|
15
|
+
- [Usage](#usage)
|
|
16
|
+
- [Contribute](#contribute)
|
|
17
|
+
- [License](#license)
|
|
18
|
+
- [Contribution](#contribution)
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```console
|
|
23
|
+
$ npm i @libp2p/utils
|
|
24
|
+
```
|
|
14
25
|
|
|
15
26
|
The libp2p ecosystem has lots of repos with it comes several problems like:
|
|
27
|
+
|
|
16
28
|
- Domain logic dedupe - all modules shared a lot of logic like validation, streams handling, etc.
|
|
17
29
|
- Dependencies management - it's really easy with so many repos for dependencies to go out of control, they become outdated, different repos use different modules to do the same thing (like merging defaults options), browser bundles ends up with multiple versions of the same package, bumping versions is cumbersome to do because we need to go through several repos, etc.
|
|
18
30
|
|
|
@@ -22,14 +34,8 @@ These problems are the motivation for this package, having shared logic in this
|
|
|
22
34
|
|
|
23
35
|
[Vasco Santos](https://github.com/vasco-santos)
|
|
24
36
|
|
|
25
|
-
## Install
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
$ npm install --save @libp2p/utils
|
|
30
|
-
```
|
|
31
|
-
|
|
32
37
|
## Usage
|
|
38
|
+
|
|
33
39
|
Each function should be imported directly.
|
|
34
40
|
|
|
35
41
|
```js
|
|
@@ -48,4 +54,11 @@ Check out our [contributing document](https://github.com/ipfs/community/blob/mas
|
|
|
48
54
|
|
|
49
55
|
## License
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
Licensed under either of
|
|
58
|
+
|
|
59
|
+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
60
|
+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
61
|
+
|
|
62
|
+
## Contribution
|
|
63
|
+
|
|
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,12 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
interface Address {
|
|
3
|
-
multiaddr: Multiaddr;
|
|
4
|
-
isCertified: boolean;
|
|
5
|
-
}
|
|
1
|
+
import type { Address } from '@libp2p/interface-peer-store';
|
|
6
2
|
/**
|
|
7
|
-
*
|
|
3
|
+
* Compare function for array.sort().
|
|
4
|
+
* This sort aims to move the private addresses to the end of the array.
|
|
8
5
|
* In case of equality, a certified address will come first.
|
|
9
6
|
*/
|
|
10
|
-
export declare function publicAddressesFirst(
|
|
11
|
-
export {};
|
|
7
|
+
export declare function publicAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
|
|
12
8
|
//# 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,
|
|
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"}
|
package/dist/src/address-sort.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isPrivate } from './multiaddr/is-private.js';
|
|
2
2
|
/**
|
|
3
3
|
* Compare function for array.sort().
|
|
4
|
-
* This sort aims to move the private
|
|
4
|
+
* This sort aims to move the private addresses to the end of the array.
|
|
5
5
|
* In case of equality, a certified address will come first.
|
|
6
6
|
*/
|
|
7
|
-
function
|
|
7
|
+
export function publicAddressesFirst(a, b) {
|
|
8
8
|
const isAPrivate = isPrivate(a.multiaddr);
|
|
9
9
|
const isBPrivate = isPrivate(b.multiaddr);
|
|
10
10
|
if (isAPrivate && !isBPrivate) {
|
|
@@ -22,11 +22,4 @@ function addressesPublicFirstCompareFunction(a, b) {
|
|
|
22
22
|
}
|
|
23
23
|
return 0;
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Sort given addresses by putting public addresses first.
|
|
27
|
-
* In case of equality, a certified address will come first.
|
|
28
|
-
*/
|
|
29
|
-
export function publicAddressesFirst(addresses) {
|
|
30
|
-
return [...addresses].sort(addressesPublicFirstCompareFunction);
|
|
31
|
-
}
|
|
32
25
|
//# 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,SAAS,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"address-sort.js","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AACA,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
2
|
-
import type { MultiaddrConnection } from '@libp2p/
|
|
2
|
+
import type { MultiaddrConnection } from '@libp2p/interface-connection';
|
|
3
3
|
import type { Duplex } from 'it-stream-types';
|
|
4
4
|
export interface Timeline {
|
|
5
5
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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",
|
|
@@ -41,31 +41,32 @@
|
|
|
41
41
|
],
|
|
42
42
|
"exports": {
|
|
43
43
|
".": {
|
|
44
|
+
"types": "./src/index.d.ts",
|
|
44
45
|
"import": "./dist/src/index.js"
|
|
45
46
|
},
|
|
46
47
|
"./address-sort": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
48
|
+
"types": "./dist/src/address-sort.d.ts",
|
|
49
|
+
"import": "./dist/src/address-sort.js"
|
|
49
50
|
},
|
|
50
51
|
"./array-equals": {
|
|
51
|
-
"
|
|
52
|
-
"
|
|
52
|
+
"types": "./dist/src/array-equals.d.ts",
|
|
53
|
+
"import": "./dist/src/array-equals.js"
|
|
53
54
|
},
|
|
54
55
|
"./ip-port-to-multiaddr": {
|
|
55
|
-
"
|
|
56
|
-
"
|
|
56
|
+
"types": "./dist/src/ip-port-to-multiaddr.d.ts",
|
|
57
|
+
"import": "./dist/src/ip-port-to-multiaddr.js"
|
|
57
58
|
},
|
|
58
59
|
"./multiaddr/is-loopback": {
|
|
59
|
-
"
|
|
60
|
-
"
|
|
60
|
+
"types": "./dist/src/multiaddr/is-loopback.d.ts",
|
|
61
|
+
"import": "./dist/src/multiaddr/is-loopback.js"
|
|
61
62
|
},
|
|
62
63
|
"./multiaddr/is-private": {
|
|
63
|
-
"
|
|
64
|
-
"
|
|
64
|
+
"types": "./dist/src/multiaddr/is-private.d.ts",
|
|
65
|
+
"import": "./dist/src/multiaddr/is-private.js"
|
|
65
66
|
},
|
|
66
67
|
"./stream-to-ma-conn": {
|
|
67
|
-
"
|
|
68
|
-
"
|
|
68
|
+
"types": "./dist/src/stream-to-ma-conn.d.ts",
|
|
69
|
+
"import": "./dist/src/stream-to-ma-conn.js"
|
|
69
70
|
}
|
|
70
71
|
},
|
|
71
72
|
"eslintConfig": {
|
|
@@ -156,22 +157,25 @@
|
|
|
156
157
|
]
|
|
157
158
|
},
|
|
158
159
|
"scripts": {
|
|
160
|
+
"clean": "aegir clean",
|
|
159
161
|
"lint": "aegir lint",
|
|
160
|
-
"dep-check": "aegir dep-check
|
|
161
|
-
"build": "
|
|
162
|
-
"
|
|
163
|
-
"test": "aegir test -
|
|
164
|
-
"test:chrome": "
|
|
165
|
-
"test:
|
|
166
|
-
"test:firefox": "
|
|
167
|
-
"test:
|
|
168
|
-
"test:
|
|
169
|
-
"
|
|
170
|
-
"release": "semantic-release"
|
|
162
|
+
"dep-check": "aegir dep-check",
|
|
163
|
+
"build": "aegir build",
|
|
164
|
+
"test": "aegir test",
|
|
165
|
+
"test:chrome": "aegir test -t browser --cov",
|
|
166
|
+
"test:chrome-webworker": "aegir test -t webworker",
|
|
167
|
+
"test:firefox": "aegir test -t browser -- --browser firefox",
|
|
168
|
+
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
|
|
169
|
+
"test:node": "aegir test -t node --cov",
|
|
170
|
+
"test:electron-main": "aegir test -t electron-main",
|
|
171
|
+
"release": "aegir release"
|
|
171
172
|
},
|
|
172
173
|
"dependencies": {
|
|
173
174
|
"@achingbrain/ip-address": "^8.1.0",
|
|
174
|
-
"@libp2p/
|
|
175
|
+
"@libp2p/interface-connection": "^1.0.1",
|
|
176
|
+
"@libp2p/interface-peer-store": "^1.0.0",
|
|
177
|
+
"@libp2p/interface-transport": "^1.0.0",
|
|
178
|
+
"@libp2p/logger": "^2.0.0",
|
|
175
179
|
"@multiformats/multiaddr": "^10.1.1",
|
|
176
180
|
"abortable-iterator": "^4.0.2",
|
|
177
181
|
"err-code": "^3.0.1",
|
|
@@ -181,9 +185,10 @@
|
|
|
181
185
|
},
|
|
182
186
|
"devDependencies": {
|
|
183
187
|
"@libp2p/interfaces": "^1.0.3",
|
|
184
|
-
"aegir": "^
|
|
188
|
+
"aegir": "^37.2.0",
|
|
185
189
|
"it-all": "^1.0.6",
|
|
186
190
|
"it-pair": "^2.0.2",
|
|
187
|
-
"it-pipe": "^2.0.2"
|
|
191
|
+
"it-pipe": "^2.0.2",
|
|
192
|
+
"uint8arrays": "^3.0.0"
|
|
188
193
|
}
|
|
189
194
|
}
|
package/src/address-sort.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Address } from '@libp2p/interface-peer-store'
|
|
2
2
|
import { isPrivate } from './multiaddr/is-private.js'
|
|
3
3
|
|
|
4
|
-
interface Address {
|
|
5
|
-
multiaddr: Multiaddr
|
|
6
|
-
isCertified: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
4
|
/**
|
|
10
5
|
* Compare function for array.sort().
|
|
11
|
-
* This sort aims to move the private
|
|
6
|
+
* This sort aims to move the private addresses to the end of the array.
|
|
12
7
|
* In case of equality, a certified address will come first.
|
|
13
8
|
*/
|
|
14
|
-
function
|
|
9
|
+
export function publicAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
|
|
15
10
|
const isAPrivate = isPrivate(a.multiaddr)
|
|
16
11
|
const isBPrivate = isPrivate(b.multiaddr)
|
|
17
12
|
|
|
@@ -29,11 +24,3 @@ function addressesPublicFirstCompareFunction (a: Address, b: Address) {
|
|
|
29
24
|
|
|
30
25
|
return 0
|
|
31
26
|
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Sort given addresses by putting public addresses first.
|
|
35
|
-
* In case of equality, a certified address will come first.
|
|
36
|
-
*/
|
|
37
|
-
export function publicAddressesFirst (addresses: Address[]) {
|
|
38
|
-
return [...addresses].sort(addressesPublicFirstCompareFunction)
|
|
39
|
-
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/src/stream-to-ma-conn.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { abortableSource } from 'abortable-iterator'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
3
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
4
|
-
import type { MultiaddrConnection } from '@libp2p/
|
|
4
|
+
import type { MultiaddrConnection } from '@libp2p/interface-connection'
|
|
5
5
|
import type { Duplex } from 'it-stream-types'
|
|
6
6
|
|
|
7
7
|
const log = logger('libp2p:stream:converter')
|