@libp2p/utils 6.2.1-339b7df88 → 6.2.1-406b3916c

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.
@@ -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 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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/utils",
3
- "version": "6.2.1-339b7df88",
3
+ "version": "6.2.1-406b3916c",
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",
@@ -84,10 +84,18 @@
84
84
  "types": "./dist/src/is-promise.d.ts",
85
85
  "import": "./dist/src/is-promise.js"
86
86
  },
87
+ "./link-local-ip": {
88
+ "types": "./dist/src/link-local-ip.d.ts",
89
+ "import": "./dist/src/link-local-ip.js"
90
+ },
87
91
  "./moving-average": {
88
92
  "types": "./dist/src/moving-average.d.ts",
89
93
  "import": "./dist/src/moving-average.js"
90
94
  },
95
+ "./multiaddr/is-link-local": {
96
+ "types": "./dist/src/multiaddr/is-link-local.d.ts",
97
+ "import": "./dist/src/multiaddr/is-link-local.js"
98
+ },
91
99
  "./multiaddr/is-loopback": {
92
100
  "types": "./dist/src/multiaddr/is-loopback.d.ts",
93
101
  "import": "./dist/src/multiaddr/is-loopback.js"
@@ -156,9 +164,9 @@
156
164
  },
157
165
  "dependencies": {
158
166
  "@chainsafe/is-ip": "^2.0.2",
159
- "@libp2p/crypto": "5.0.7-339b7df88",
160
- "@libp2p/interface": "2.2.1-339b7df88",
161
- "@libp2p/logger": "5.1.4-339b7df88",
167
+ "@libp2p/crypto": "5.0.7-406b3916c",
168
+ "@libp2p/interface": "2.2.1-406b3916c",
169
+ "@libp2p/logger": "5.1.4-406b3916c",
162
170
  "@multiformats/multiaddr": "^12.3.3",
163
171
  "@sindresorhus/fnv1a": "^3.1.0",
164
172
  "@types/murmurhash3js-revisited": "^3.0.3",
@@ -179,7 +187,7 @@
179
187
  "uint8arrays": "^5.1.0"
180
188
  },
181
189
  "devDependencies": {
182
- "@libp2p/peer-id": "5.0.8-339b7df88",
190
+ "@libp2p/peer-id": "5.0.8-406b3916c",
183
191
  "@types/netmask": "^2.0.5",
184
192
  "aegir": "^45.0.5",
185
193
  "benchmark": "^2.1.4",
@@ -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,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
+ }