@libp2p/utils 6.0.5-82bd42bcf → 6.0.5-dad979f9b

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/utils",
3
- "version": "6.0.5-82bd42bcf",
3
+ "version": "6.0.5-dad979f9b",
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/tree/main/packages/utils#readme",
@@ -56,10 +56,6 @@
56
56
  "types": "./dist/src/adaptive-timeout.d.ts",
57
57
  "import": "./dist/src/adaptive-timeout.js"
58
58
  },
59
- "./address-sort": {
60
- "types": "./dist/src/address-sort.d.ts",
61
- "import": "./dist/src/address-sort.js"
62
- },
63
59
  "./array-equals": {
64
60
  "types": "./dist/src/array-equals.d.ts",
65
61
  "import": "./dist/src/array-equals.js"
@@ -152,11 +148,10 @@
152
148
  },
153
149
  "dependencies": {
154
150
  "@chainsafe/is-ip": "^2.0.2",
155
- "@libp2p/crypto": "5.0.4-82bd42bcf",
156
- "@libp2p/interface": "2.1.2-82bd42bcf",
157
- "@libp2p/logger": "5.1.0-82bd42bcf",
151
+ "@libp2p/crypto": "5.0.4-dad979f9b",
152
+ "@libp2p/interface": "2.1.2-dad979f9b",
153
+ "@libp2p/logger": "5.1.0-dad979f9b",
158
154
  "@multiformats/multiaddr": "^12.2.3",
159
- "@multiformats/multiaddr-matcher": "^1.2.1",
160
155
  "@sindresorhus/fnv1a": "^3.1.0",
161
156
  "@types/murmurhash3js-revisited": "^3.0.3",
162
157
  "any-signal": "^4.1.1",
@@ -1,39 +0,0 @@
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
- import type { Address } from '@libp2p/interface';
23
- /**
24
- * Compare function for array.sort() that moves public addresses to the start
25
- * of the array.
26
- */
27
- export declare function publicAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
28
- /**
29
- * Compare function for array.sort() that moves certified addresses to the start
30
- * of the array.
31
- */
32
- export declare function certifiedAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
33
- /**
34
- * Compare function for array.sort() that moves circuit relay addresses to the
35
- * start of the array.
36
- */
37
- export declare function circuitRelayAddressesLast(a: Address, b: Address): -1 | 0 | 1;
38
- export declare function defaultAddressSort(a: Address, b: Address): -1 | 0 | 1;
39
- //# sourceMappingURL=address-sort.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"address-sort.d.ts","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAWxE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAQ3E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAW7E;AAED,wBAAgB,kBAAkB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAgBtE"}
@@ -1,79 +0,0 @@
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
- import { Circuit } from '@multiformats/multiaddr-matcher';
23
- import { isPrivate } from './multiaddr/is-private.js';
24
- /**
25
- * Compare function for array.sort() that moves public addresses to the start
26
- * of the array.
27
- */
28
- export function publicAddressesFirst(a, b) {
29
- const isAPrivate = isPrivate(a.multiaddr);
30
- const isBPrivate = isPrivate(b.multiaddr);
31
- if (isAPrivate && !isBPrivate) {
32
- return 1;
33
- }
34
- else if (!isAPrivate && isBPrivate) {
35
- return -1;
36
- }
37
- return 0;
38
- }
39
- /**
40
- * Compare function for array.sort() that moves certified addresses to the start
41
- * of the array.
42
- */
43
- export function certifiedAddressesFirst(a, b) {
44
- if (a.isCertified && !b.isCertified) {
45
- return -1;
46
- }
47
- else if (!a.isCertified && b.isCertified) {
48
- return 1;
49
- }
50
- return 0;
51
- }
52
- /**
53
- * Compare function for array.sort() that moves circuit relay addresses to the
54
- * start of the array.
55
- */
56
- export function circuitRelayAddressesLast(a, b) {
57
- const isACircuit = Circuit.exactMatch(a.multiaddr);
58
- const isBCircuit = Circuit.exactMatch(b.multiaddr);
59
- if (isACircuit && !isBCircuit) {
60
- return 1;
61
- }
62
- else if (!isACircuit && isBCircuit) {
63
- return -1;
64
- }
65
- return 0;
66
- }
67
- export function defaultAddressSort(a, b) {
68
- const publicResult = publicAddressesFirst(a, b);
69
- if (publicResult !== 0) {
70
- return publicResult;
71
- }
72
- const relayResult = circuitRelayAddressesLast(a, b);
73
- if (relayResult !== 0) {
74
- return relayResult;
75
- }
76
- const certifiedResult = certifiedAddressesFirst(a, b);
77
- return certifiedResult;
78
- }
79
- //# sourceMappingURL=address-sort.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"address-sort.js","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAGrD;;;GAGG;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,CAAC;QAC9B,OAAO,CAAC,CAAA;IACV,CAAC;SAAM,IAAI,CAAC,UAAU,IAAI,UAAU,EAAE,CAAC;QACrC,OAAO,CAAC,CAAC,CAAA;IACX,CAAC;IAED,OAAO,CAAC,CAAA;AACV,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAE,CAAU,EAAE,CAAU;IAC7D,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACpC,OAAO,CAAC,CAAC,CAAA;IACX,CAAC;SAAM,IAAI,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3C,OAAO,CAAC,CAAA;IACV,CAAC;IAED,OAAO,CAAC,CAAA;AACV,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAE,CAAU,EAAE,CAAU;IAC/D,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAClD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAElD,IAAI,UAAU,IAAI,CAAC,UAAU,EAAE,CAAC;QAC9B,OAAO,CAAC,CAAA;IACV,CAAC;SAAM,IAAI,CAAC,UAAU,IAAI,UAAU,EAAE,CAAC;QACrC,OAAO,CAAC,CAAC,CAAA;IACX,CAAC;IAED,OAAO,CAAC,CAAA;AACV,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAE,CAAU,EAAE,CAAU;IACxD,MAAM,YAAY,GAAG,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAE/C,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,MAAM,WAAW,GAAG,yBAAyB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAEnD,IAAI,WAAW,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,WAAW,CAAA;IACpB,CAAC;IAED,MAAM,eAAe,GAAG,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAErD,OAAO,eAAe,CAAA;AACxB,CAAC"}
@@ -1,91 +0,0 @@
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
-
23
- import { Circuit } from '@multiformats/multiaddr-matcher'
24
- import { isPrivate } from './multiaddr/is-private.js'
25
- import type { Address } from '@libp2p/interface'
26
-
27
- /**
28
- * Compare function for array.sort() that moves public addresses to the start
29
- * of the array.
30
- */
31
- export function publicAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
32
- const isAPrivate = isPrivate(a.multiaddr)
33
- const isBPrivate = isPrivate(b.multiaddr)
34
-
35
- if (isAPrivate && !isBPrivate) {
36
- return 1
37
- } else if (!isAPrivate && isBPrivate) {
38
- return -1
39
- }
40
-
41
- return 0
42
- }
43
-
44
- /**
45
- * Compare function for array.sort() that moves certified addresses to the start
46
- * of the array.
47
- */
48
- export function certifiedAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
49
- if (a.isCertified && !b.isCertified) {
50
- return -1
51
- } else if (!a.isCertified && b.isCertified) {
52
- return 1
53
- }
54
-
55
- return 0
56
- }
57
-
58
- /**
59
- * Compare function for array.sort() that moves circuit relay addresses to the
60
- * start of the array.
61
- */
62
- export function circuitRelayAddressesLast (a: Address, b: Address): -1 | 0 | 1 {
63
- const isACircuit = Circuit.exactMatch(a.multiaddr)
64
- const isBCircuit = Circuit.exactMatch(b.multiaddr)
65
-
66
- if (isACircuit && !isBCircuit) {
67
- return 1
68
- } else if (!isACircuit && isBCircuit) {
69
- return -1
70
- }
71
-
72
- return 0
73
- }
74
-
75
- export function defaultAddressSort (a: Address, b: Address): -1 | 0 | 1 {
76
- const publicResult = publicAddressesFirst(a, b)
77
-
78
- if (publicResult !== 0) {
79
- return publicResult
80
- }
81
-
82
- const relayResult = circuitRelayAddressesLast(a, b)
83
-
84
- if (relayResult !== 0) {
85
- return relayResult
86
- }
87
-
88
- const certifiedResult = certifiedAddressesFirst(a, b)
89
-
90
- return certifiedResult
91
- }