@libp2p/utils 6.2.1-4a85eb033 → 6.2.1-6ab85ea68

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
@@ -49,7 +49,7 @@ $ npm i @libp2p/utils
49
49
 
50
50
  ## Browser `<script>` tag
51
51
 
52
- Loading this module through a script tag will make it's exports available as `Libp2pUtils` in the global namespace.
52
+ Loading this module through a script tag will make its exports available as `Libp2pUtils` in the global namespace.
53
53
 
54
54
  ```html
55
55
  <script src="https://unpkg.com/@libp2p/utils/dist/index.min.js"></script>
@@ -0,0 +1,2 @@
1
+ export declare function isGlobalUnicastIp(ip: string): boolean;
2
+ //# sourceMappingURL=global-unicast-ip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-unicast-ip.d.ts","sourceRoot":"","sources":["../../src/global-unicast-ip.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,CAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAMtD"}
@@ -0,0 +1,9 @@
1
+ import { isIPv6 } from '@chainsafe/is-ip';
2
+ import { cidrContains } from '@chainsafe/netmask';
3
+ export function isGlobalUnicastIp(ip) {
4
+ if (isIPv6(ip)) {
5
+ return cidrContains('2000::/3', ip);
6
+ }
7
+ return false;
8
+ }
9
+ //# sourceMappingURL=global-unicast-ip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-unicast-ip.js","sourceRoot":"","sources":["../../src/global-unicast-ip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,MAAM,UAAU,iBAAiB,CAAE,EAAU;IAC3C,IAAI,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;QACf,OAAO,YAAY,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;IACrC,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function isLinkLocalIp(ip: string): boolean;
2
+ //# sourceMappingURL=link-local-ip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link-local-ip.d.ts","sourceRoot":"","sources":["../../src/link-local-ip.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAUlD"}
@@ -0,0 +1,11 @@
1
+ import { isIPv4, isIPv6 } from '@chainsafe/is-ip';
2
+ export function isLinkLocalIp(ip) {
3
+ if (isIPv4(ip)) {
4
+ return ip.startsWith('169.254.');
5
+ }
6
+ if (isIPv6(ip)) {
7
+ return ip.toLowerCase().startsWith('fe80');
8
+ }
9
+ return false;
10
+ }
11
+ //# sourceMappingURL=link-local-ip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link-local-ip.js","sourceRoot":"","sources":["../../src/link-local-ip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEjD,MAAM,UAAU,aAAa,CAAE,EAAU;IACvC,IAAI,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;QACf,OAAO,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IAClC,CAAC;IAED,IAAI,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;QACf,OAAO,EAAE,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAC5C,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { Multiaddr } from '@multiformats/multiaddr';
2
+ /**
3
+ * Check if a given multiaddr is an IPv6 global unicast address
4
+ */
5
+ export declare function isGlobalUnicast(ma: Multiaddr): boolean;
6
+ //# sourceMappingURL=is-global-unicast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-global-unicast.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-global-unicast.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD;;GAEG;AACH,wBAAgB,eAAe,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAgBvD"}
@@ -0,0 +1,20 @@
1
+ import { cidrContains } from '@chainsafe/netmask';
2
+ const CODEC_IP6 = 0x29;
3
+ /**
4
+ * Check if a given multiaddr is an IPv6 global unicast address
5
+ */
6
+ export function isGlobalUnicast(ma) {
7
+ try {
8
+ const [[codec, value]] = ma.stringTuples();
9
+ if (value == null) {
10
+ return false;
11
+ }
12
+ if (codec === CODEC_IP6) {
13
+ return cidrContains('2000::/3', value);
14
+ }
15
+ }
16
+ catch {
17
+ }
18
+ return false;
19
+ }
20
+ //# sourceMappingURL=is-global-unicast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-global-unicast.js","sourceRoot":"","sources":["../../../src/multiaddr/is-global-unicast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGjD,MAAM,SAAS,GAAG,IAAI,CAAA;AAEtB;;GAEG;AACH,MAAM,UAAU,eAAe,CAAE,EAAa;IAC5C,IAAI,CAAC;QACH,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,CAAA;QAE1C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;QACxC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;IAET,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { Multiaddr } from '@multiformats/multiaddr';
2
+ /**
3
+ * Check if a given multiaddr is a link-local address
4
+ */
5
+ export declare function isLinkLocal(ma: Multiaddr): boolean;
6
+ //# sourceMappingURL=is-link-local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-link-local.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-link-local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAKxD;;GAEG;AACH,wBAAgB,WAAW,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAoBnD"}
@@ -0,0 +1,23 @@
1
+ const CODEC_IP4 = 0x04;
2
+ const CODEC_IP6 = 0x29;
3
+ /**
4
+ * Check if a given multiaddr is a link-local address
5
+ */
6
+ export function isLinkLocal(ma) {
7
+ try {
8
+ const [[codec, value]] = ma.stringTuples();
9
+ if (value == null) {
10
+ return false;
11
+ }
12
+ if (codec === CODEC_IP4) {
13
+ return value.startsWith('169.254.');
14
+ }
15
+ if (codec === CODEC_IP6) {
16
+ return value.toLowerCase().startsWith('fe80');
17
+ }
18
+ }
19
+ catch {
20
+ }
21
+ return false;
22
+ }
23
+ //# sourceMappingURL=is-link-local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-link-local.js","sourceRoot":"","sources":["../../../src/multiaddr/is-link-local.ts"],"names":[],"mappings":"AAEA,MAAM,SAAS,GAAG,IAAI,CAAA;AACtB,MAAM,SAAS,GAAG,IAAI,CAAA;AAEtB;;GAEG;AACH,MAAM,UAAU,WAAW,CAAE,EAAa;IACxC,IAAI,CAAC;QACH,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,CAAA;QAE1C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;QACrC,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;QAC/C,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;IAET,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { Multiaddr } from '@multiformats/multiaddr';
2
2
  /**
3
- * Check if a given multiaddr has a private address.
3
+ * Check if a given multiaddr starts with a private address
4
4
  */
5
5
  export declare function isPrivate(ma: Multiaddr): boolean;
6
6
  //# sourceMappingURL=is-private.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-private.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-private.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;GAEG;AACH,wBAAgB,SAAS,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAQjD"}
1
+ {"version":3,"file":"is-private.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-private.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AASxD;;GAEG;AACH,wBAAgB,SAAS,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAoBjD"}
@@ -1,14 +1,28 @@
1
1
  import { isPrivateIp } from '../private-ip.js';
2
+ const CODEC_IP4 = 0x04;
3
+ const CODEC_IP6 = 0x29;
4
+ const CODEC_DNS = 0x35;
5
+ const CODEC_DNS4 = 0x36;
6
+ const CODEC_DNS6 = 0x37;
7
+ const CODEC_DNSADDR = 0x38;
2
8
  /**
3
- * Check if a given multiaddr has a private address.
9
+ * Check if a given multiaddr starts with a private address
4
10
  */
5
11
  export function isPrivate(ma) {
6
12
  try {
7
- const { address } = ma.nodeAddress();
8
- return Boolean(isPrivateIp(address));
13
+ const [[codec, value]] = ma.stringTuples();
14
+ if (value == null) {
15
+ return true;
16
+ }
17
+ if (codec === CODEC_DNS || codec === CODEC_DNS4 || codec === CODEC_DNS6 || codec === CODEC_DNSADDR) {
18
+ return false;
19
+ }
20
+ if (codec === CODEC_IP4 || codec === CODEC_IP6) {
21
+ return isPrivateIp(value) ?? false;
22
+ }
9
23
  }
10
24
  catch {
11
- return true;
12
25
  }
26
+ return true;
13
27
  }
14
28
  //# sourceMappingURL=is-private.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-private.js","sourceRoot":"","sources":["../../../src/multiaddr/is-private.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9C;;GAEG;AACH,MAAM,UAAU,SAAS,CAAE,EAAa;IACtC,IAAI,CAAC;QACH,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,CAAA;QAEpC,OAAO,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAA;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"is-private.js","sourceRoot":"","sources":["../../../src/multiaddr/is-private.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9C,MAAM,SAAS,GAAG,IAAI,CAAA;AACtB,MAAM,SAAS,GAAG,IAAI,CAAA;AACtB,MAAM,SAAS,GAAG,IAAI,CAAA;AACtB,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,aAAa,GAAG,IAAI,CAAA;AAE1B;;GAEG;AACH,MAAM,UAAU,SAAS,CAAE,EAAa;IACtC,IAAI,CAAC;QACH,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,CAAA;QAE1C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,UAAU,IAAI,KAAK,KAAK,UAAU,IAAI,KAAK,KAAK,aAAa,EAAE,CAAC;YACnG,OAAO,KAAK,CAAA;QACd,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/C,OAAO,WAAW,CAAC,KAAK,CAAC,IAAI,KAAK,CAAA;QACpC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;IAET,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/utils",
3
- "version": "6.2.1-4a85eb033",
3
+ "version": "6.2.1-6ab85ea68",
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",
@@ -76,6 +76,10 @@
76
76
  "types": "./dist/src/filters/index.d.ts",
77
77
  "import": "./dist/src/filters/index.js"
78
78
  },
79
+ "./global-unicast-ip": {
80
+ "types": "./dist/src/global-unicast-ip.d.ts",
81
+ "import": "./dist/src/global-unicast-ip.js"
82
+ },
79
83
  "./ip-port-to-multiaddr": {
80
84
  "types": "./dist/src/ip-port-to-multiaddr.d.ts",
81
85
  "import": "./dist/src/ip-port-to-multiaddr.js"
@@ -84,10 +88,22 @@
84
88
  "types": "./dist/src/is-promise.d.ts",
85
89
  "import": "./dist/src/is-promise.js"
86
90
  },
91
+ "./link-local-ip": {
92
+ "types": "./dist/src/link-local-ip.d.ts",
93
+ "import": "./dist/src/link-local-ip.js"
94
+ },
87
95
  "./moving-average": {
88
96
  "types": "./dist/src/moving-average.d.ts",
89
97
  "import": "./dist/src/moving-average.js"
90
98
  },
99
+ "./multiaddr/is-global-unicast": {
100
+ "types": "./dist/src/multiaddr/is-global-unicast.d.ts",
101
+ "import": "./dist/src/multiaddr/is-global-unicast.js"
102
+ },
103
+ "./multiaddr/is-link-local": {
104
+ "types": "./dist/src/multiaddr/is-link-local.d.ts",
105
+ "import": "./dist/src/multiaddr/is-link-local.js"
106
+ },
91
107
  "./multiaddr/is-loopback": {
92
108
  "types": "./dist/src/multiaddr/is-loopback.d.ts",
93
109
  "import": "./dist/src/multiaddr/is-loopback.js"
@@ -156,10 +172,11 @@
156
172
  },
157
173
  "dependencies": {
158
174
  "@chainsafe/is-ip": "^2.0.2",
159
- "@libp2p/crypto": "5.0.7-4a85eb033",
160
- "@libp2p/interface": "2.2.1-4a85eb033",
161
- "@libp2p/logger": "5.1.4-4a85eb033",
162
- "@multiformats/multiaddr": "^12.2.3",
175
+ "@chainsafe/netmask": "^2.0.0",
176
+ "@libp2p/crypto": "5.0.7-6ab85ea68",
177
+ "@libp2p/interface": "2.2.1-6ab85ea68",
178
+ "@libp2p/logger": "5.1.4-6ab85ea68",
179
+ "@multiformats/multiaddr": "^12.3.3",
163
180
  "@sindresorhus/fnv1a": "^3.1.0",
164
181
  "@types/murmurhash3js-revisited": "^3.0.3",
165
182
  "any-signal": "^4.1.1",
@@ -169,25 +186,25 @@
169
186
  "it-foreach": "^2.1.1",
170
187
  "it-pipe": "^3.0.1",
171
188
  "it-pushable": "^3.2.3",
172
- "it-stream-types": "^2.0.1",
189
+ "it-stream-types": "^2.0.2",
173
190
  "murmurhash3js-revisited": "^3.0.0",
174
191
  "netmask": "^2.0.2",
175
192
  "p-defer": "^4.0.1",
176
193
  "race-event": "^1.3.0",
177
- "race-signal": "^1.0.2",
194
+ "race-signal": "^1.1.0",
178
195
  "uint8arraylist": "^2.4.8",
179
196
  "uint8arrays": "^5.1.0"
180
197
  },
181
198
  "devDependencies": {
182
- "@libp2p/peer-id": "5.0.8-4a85eb033",
199
+ "@libp2p/peer-id": "5.0.8-6ab85ea68",
183
200
  "@types/netmask": "^2.0.5",
184
- "aegir": "^44.0.1",
201
+ "aegir": "^45.0.5",
185
202
  "benchmark": "^2.1.4",
186
203
  "delay": "^6.0.0",
187
204
  "it-all": "^3.0.6",
188
205
  "it-drain": "^3.0.7",
189
206
  "it-pair": "^2.0.6",
190
- "sinon": "^18.0.0",
207
+ "sinon": "^19.0.2",
191
208
  "sinon-ts": "^2.0.0"
192
209
  },
193
210
  "sideEffects": false
@@ -0,0 +1,10 @@
1
+ import { isIPv6 } from '@chainsafe/is-ip'
2
+ import { cidrContains } from '@chainsafe/netmask'
3
+
4
+ export function isGlobalUnicastIp (ip: string): boolean {
5
+ if (isIPv6(ip)) {
6
+ return cidrContains('2000::/3', ip)
7
+ }
8
+
9
+ return false
10
+ }
@@ -0,0 +1,13 @@
1
+ import { isIPv4, isIPv6 } from '@chainsafe/is-ip'
2
+
3
+ export function isLinkLocalIp (ip: string): boolean {
4
+ if (isIPv4(ip)) {
5
+ return ip.startsWith('169.254.')
6
+ }
7
+
8
+ if (isIPv6(ip)) {
9
+ return ip.toLowerCase().startsWith('fe80')
10
+ }
11
+
12
+ return false
13
+ }
@@ -0,0 +1,25 @@
1
+ import { cidrContains } from '@chainsafe/netmask'
2
+ import type { Multiaddr } from '@multiformats/multiaddr'
3
+
4
+ const CODEC_IP6 = 0x29
5
+
6
+ /**
7
+ * Check if a given multiaddr is an IPv6 global unicast address
8
+ */
9
+ export function isGlobalUnicast (ma: Multiaddr): boolean {
10
+ try {
11
+ const [[codec, value]] = ma.stringTuples()
12
+
13
+ if (value == null) {
14
+ return false
15
+ }
16
+
17
+ if (codec === CODEC_IP6) {
18
+ return cidrContains('2000::/3', value)
19
+ }
20
+ } catch {
21
+
22
+ }
23
+
24
+ return false
25
+ }
@@ -0,0 +1,29 @@
1
+ import type { Multiaddr } from '@multiformats/multiaddr'
2
+
3
+ const CODEC_IP4 = 0x04
4
+ const CODEC_IP6 = 0x29
5
+
6
+ /**
7
+ * Check if a given multiaddr is a link-local address
8
+ */
9
+ export function isLinkLocal (ma: Multiaddr): boolean {
10
+ try {
11
+ const [[codec, value]] = ma.stringTuples()
12
+
13
+ if (value == null) {
14
+ return false
15
+ }
16
+
17
+ if (codec === CODEC_IP4) {
18
+ return value.startsWith('169.254.')
19
+ }
20
+
21
+ if (codec === CODEC_IP6) {
22
+ return value.toLowerCase().startsWith('fe80')
23
+ }
24
+ } catch {
25
+
26
+ }
27
+
28
+ return false
29
+ }
@@ -1,15 +1,34 @@
1
1
  import { isPrivateIp } from '../private-ip.js'
2
2
  import type { Multiaddr } from '@multiformats/multiaddr'
3
3
 
4
+ const CODEC_IP4 = 0x04
5
+ const CODEC_IP6 = 0x29
6
+ const CODEC_DNS = 0x35
7
+ const CODEC_DNS4 = 0x36
8
+ const CODEC_DNS6 = 0x37
9
+ const CODEC_DNSADDR = 0x38
10
+
4
11
  /**
5
- * Check if a given multiaddr has a private address.
12
+ * Check if a given multiaddr starts with a private address
6
13
  */
7
14
  export function isPrivate (ma: Multiaddr): boolean {
8
15
  try {
9
- const { address } = ma.nodeAddress()
16
+ const [[codec, value]] = ma.stringTuples()
17
+
18
+ if (value == null) {
19
+ return true
20
+ }
21
+
22
+ if (codec === CODEC_DNS || codec === CODEC_DNS4 || codec === CODEC_DNS6 || codec === CODEC_DNSADDR) {
23
+ return false
24
+ }
10
25
 
11
- return Boolean(isPrivateIp(address))
26
+ if (codec === CODEC_IP4 || codec === CODEC_IP6) {
27
+ return isPrivateIp(value) ?? false
28
+ }
12
29
  } catch {
13
- return true
30
+
14
31
  }
32
+
33
+ return true
15
34
  }
package/LICENSE DELETED
@@ -1,4 +0,0 @@
1
- This project is dual licensed under MIT and Apache-2.0.
2
-
3
- MIT: https://www.opensource.org/licenses/mit
4
- Apache-2.0: https://www.apache.org/licenses/license-2.0