@libp2p/utils 6.5.7-a6c9aee5a → 6.5.8-2f2322a25
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/dist/src/get-thin-waist-addresses.browser.d.ts +9 -0
- package/dist/src/get-thin-waist-addresses.browser.d.ts.map +1 -0
- package/dist/src/get-thin-waist-addresses.browser.js +17 -0
- package/dist/src/get-thin-waist-addresses.browser.js.map +1 -0
- package/dist/src/get-thin-waist-addresses.d.ts +9 -0
- package/dist/src/get-thin-waist-addresses.d.ts.map +1 -0
- package/dist/src/get-thin-waist-addresses.js +47 -0
- package/dist/src/get-thin-waist-addresses.js.map +1 -0
- package/dist/src/link-local-ip.d.ts.map +1 -1
- package/dist/src/link-local-ip.js +4 -5
- package/dist/src/link-local-ip.js.map +1 -1
- package/package.json +19 -7
- package/src/get-thin-waist-addresses.browser.ts +20 -0
- package/src/get-thin-waist-addresses.ts +59 -0
- package/src/link-local-ip.ts +4 -6
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
2
|
+
/**
|
|
3
|
+
* Get all thin waist addresses on the current host that match the family of the
|
|
4
|
+
* passed multiaddr and optionally override the port.
|
|
5
|
+
*
|
|
6
|
+
* Wildcard IP4/6 addresses will be expanded into all available interfaces.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getThinWaistAddresses(ma?: Multiaddr, port?: number): Multiaddr[];
|
|
9
|
+
//# sourceMappingURL=get-thin-waist-addresses.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-thin-waist-addresses.browser.d.ts","sourceRoot":"","sources":["../../src/get-thin-waist-addresses.browser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAE,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAUjF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
2
|
+
/**
|
|
3
|
+
* Get all thin waist addresses on the current host that match the family of the
|
|
4
|
+
* passed multiaddr and optionally override the port.
|
|
5
|
+
*
|
|
6
|
+
* Wildcard IP4/6 addresses will be expanded into all available interfaces.
|
|
7
|
+
*/
|
|
8
|
+
export function getThinWaistAddresses(ma, port) {
|
|
9
|
+
if (ma == null) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const options = ma.toOptions();
|
|
13
|
+
return [
|
|
14
|
+
multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${port ?? options.port}`)
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=get-thin-waist-addresses.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-thin-waist-addresses.browser.js","sourceRoot":"","sources":["../../src/get-thin-waist-addresses.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGnD;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAE,EAAc,EAAE,IAAa;IAClE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QACf,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,OAAO,GAAG,EAAE,CAAC,SAAS,EAAE,CAAA;IAE9B,OAAO;QACL,SAAS,CAAC,MAAM,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,SAAS,IAAI,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;KAC/F,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
2
|
+
/**
|
|
3
|
+
* Get all thin waist addresses on the current host that match the family of the
|
|
4
|
+
* passed multiaddr and optionally override the port.
|
|
5
|
+
*
|
|
6
|
+
* Wildcard IP4/6 addresses will be expanded into all available interfaces.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getThinWaistAddresses(ma?: Multiaddr, port?: number): Multiaddr[];
|
|
9
|
+
//# sourceMappingURL=get-thin-waist-addresses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-thin-waist-addresses.d.ts","sourceRoot":"","sources":["../../src/get-thin-waist-addresses.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AA6BxD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAE,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAoBjF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
3
|
+
import { isLinkLocalIp } from './link-local-ip.js';
|
|
4
|
+
const FAMILIES = { 4: 'IPv4', 6: 'IPv6' };
|
|
5
|
+
function isWildcard(ip) {
|
|
6
|
+
return ['0.0.0.0', '::'].includes(ip);
|
|
7
|
+
}
|
|
8
|
+
function getNetworkAddrs(family) {
|
|
9
|
+
const addresses = [];
|
|
10
|
+
const networks = os.networkInterfaces();
|
|
11
|
+
for (const [, netAddrs] of Object.entries(networks)) {
|
|
12
|
+
if (netAddrs != null) {
|
|
13
|
+
for (const netAddr of netAddrs) {
|
|
14
|
+
if (isLinkLocalIp(netAddr.address)) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (netAddr.family === FAMILIES[family]) {
|
|
18
|
+
addresses.push(netAddr.address);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return addresses;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get all thin waist addresses on the current host that match the family of the
|
|
27
|
+
* passed multiaddr and optionally override the port.
|
|
28
|
+
*
|
|
29
|
+
* Wildcard IP4/6 addresses will be expanded into all available interfaces.
|
|
30
|
+
*/
|
|
31
|
+
export function getThinWaistAddresses(ma, port) {
|
|
32
|
+
if (ma == null) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
const options = ma.toOptions();
|
|
36
|
+
if (isWildcard(options.host)) {
|
|
37
|
+
const addrs = [];
|
|
38
|
+
for (const host of getNetworkAddrs(options.family)) {
|
|
39
|
+
addrs.push(multiaddr(`/ip${options.family}/${host}/${options.transport}/${port ?? options.port}`));
|
|
40
|
+
}
|
|
41
|
+
return addrs;
|
|
42
|
+
}
|
|
43
|
+
return [
|
|
44
|
+
multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${port ?? options.port}`)
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=get-thin-waist-addresses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-thin-waist-addresses.js","sourceRoot":"","sources":["../../src/get-thin-waist-addresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGlD,MAAM,QAAQ,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAA;AAEzC,SAAS,UAAU,CAAE,EAAU;IAC7B,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;AACvC,CAAC;AAED,SAAS,eAAe,CAAE,MAAa;IACrC,MAAM,SAAS,GAAa,EAAE,CAAA;IAC9B,MAAM,QAAQ,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAA;IAEvC,KAAK,MAAM,CAAC,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,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-ip.d.ts","sourceRoot":"","sources":["../../src/link-local-ip.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"link-local-ip.d.ts","sourceRoot":"","sources":["../../src/link-local-ip.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAUlD"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { isIPv4, isIPv6 } from '@chainsafe/is-ip';
|
|
2
1
|
export function isLinkLocalIp(ip) {
|
|
3
|
-
if (
|
|
4
|
-
return
|
|
2
|
+
if (ip.startsWith('169.254.')) {
|
|
3
|
+
return true;
|
|
5
4
|
}
|
|
6
|
-
if (
|
|
7
|
-
return
|
|
5
|
+
if (ip.toLowerCase().startsWith('fe80')) {
|
|
6
|
+
return true;
|
|
8
7
|
}
|
|
9
8
|
return false;
|
|
10
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-local-ip.js","sourceRoot":"","sources":["../../src/link-local-ip.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"link-local-ip.js","sourceRoot":"","sources":["../../src/link-local-ip.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAAE,EAAU;IACvC,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACxC,OAAO,IAAI,CAAA;IACb,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.5.
|
|
3
|
+
"version": "6.5.8-2f2322a25",
|
|
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,11 @@
|
|
|
76
76
|
"types": "./dist/src/filters/index.d.ts",
|
|
77
77
|
"import": "./dist/src/filters/index.js"
|
|
78
78
|
},
|
|
79
|
+
"./get-thin-waist-addresses": {
|
|
80
|
+
"types": "./dist/src/get-thin-waist-addresses.d.ts",
|
|
81
|
+
"browser": "./dist/src/get-thin-waist-addresses.browser.js",
|
|
82
|
+
"import": "./dist/src/get-thin-waist-addresses.js"
|
|
83
|
+
},
|
|
79
84
|
"./global-unicast-ip": {
|
|
80
85
|
"types": "./dist/src/global-unicast-ip.d.ts",
|
|
81
86
|
"import": "./dist/src/global-unicast-ip.js"
|
|
@@ -189,9 +194,9 @@
|
|
|
189
194
|
"dependencies": {
|
|
190
195
|
"@chainsafe/is-ip": "^2.0.2",
|
|
191
196
|
"@chainsafe/netmask": "^2.0.0",
|
|
192
|
-
"@libp2p/crypto": "5.0.15-
|
|
193
|
-
"@libp2p/interface": "2.7.0-
|
|
194
|
-
"@libp2p/logger": "5.1.
|
|
197
|
+
"@libp2p/crypto": "5.0.15-2f2322a25",
|
|
198
|
+
"@libp2p/interface": "2.7.0-2f2322a25",
|
|
199
|
+
"@libp2p/logger": "5.1.13-2f2322a25",
|
|
195
200
|
"@multiformats/multiaddr": "^12.3.3",
|
|
196
201
|
"@sindresorhus/fnv1a": "^3.1.0",
|
|
197
202
|
"any-signal": "^4.1.1",
|
|
@@ -210,7 +215,7 @@
|
|
|
210
215
|
"uint8arrays": "^5.1.0"
|
|
211
216
|
},
|
|
212
217
|
"devDependencies": {
|
|
213
|
-
"@libp2p/peer-id": "5.0
|
|
218
|
+
"@libp2p/peer-id": "5.1.0-2f2322a25",
|
|
214
219
|
"@types/netmask": "^2.0.5",
|
|
215
220
|
"aegir": "^45.1.1",
|
|
216
221
|
"benchmark": "^2.1.4",
|
|
@@ -219,7 +224,14 @@
|
|
|
219
224
|
"it-drain": "^3.0.7",
|
|
220
225
|
"it-pair": "^2.0.6",
|
|
221
226
|
"sinon": "^19.0.2",
|
|
222
|
-
"sinon-ts": "^2.0.0"
|
|
227
|
+
"sinon-ts": "^2.0.0",
|
|
228
|
+
"wherearewe": "^2.0.1"
|
|
229
|
+
},
|
|
230
|
+
"sideEffects": false,
|
|
231
|
+
"browser": {
|
|
232
|
+
"./dist/src/get-thin-waist-addresses.js": "./dist/src/get-thin-waist-addresses.browser.js"
|
|
223
233
|
},
|
|
224
|
-
"
|
|
234
|
+
"react-native": {
|
|
235
|
+
"./dist/src/get-thin-waist-addresses.js": "./dist/src/get-thin-waist-addresses.js"
|
|
236
|
+
}
|
|
225
237
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { multiaddr } from '@multiformats/multiaddr'
|
|
2
|
+
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get all thin waist addresses on the current host that match the family of the
|
|
6
|
+
* passed multiaddr and optionally override the port.
|
|
7
|
+
*
|
|
8
|
+
* Wildcard IP4/6 addresses will be expanded into all available interfaces.
|
|
9
|
+
*/
|
|
10
|
+
export function getThinWaistAddresses (ma?: Multiaddr, port?: number): Multiaddr[] {
|
|
11
|
+
if (ma == null) {
|
|
12
|
+
return []
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const options = ma.toOptions()
|
|
16
|
+
|
|
17
|
+
return [
|
|
18
|
+
multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${port ?? options.port}`)
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import os from 'node:os'
|
|
2
|
+
import { multiaddr } from '@multiformats/multiaddr'
|
|
3
|
+
import { isLinkLocalIp } from './link-local-ip.js'
|
|
4
|
+
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
5
|
+
|
|
6
|
+
const FAMILIES = { 4: 'IPv4', 6: 'IPv6' }
|
|
7
|
+
|
|
8
|
+
function isWildcard (ip: string): boolean {
|
|
9
|
+
return ['0.0.0.0', '::'].includes(ip)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getNetworkAddrs (family: 4 | 6): string[] {
|
|
13
|
+
const addresses: string[] = []
|
|
14
|
+
const networks = os.networkInterfaces()
|
|
15
|
+
|
|
16
|
+
for (const [, netAddrs] of Object.entries(networks)) {
|
|
17
|
+
if (netAddrs != null) {
|
|
18
|
+
for (const netAddr of netAddrs) {
|
|
19
|
+
if (isLinkLocalIp(netAddr.address)) {
|
|
20
|
+
continue
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (netAddr.family === FAMILIES[family]) {
|
|
24
|
+
addresses.push(netAddr.address)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return addresses
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get all thin waist addresses on the current host that match the family of the
|
|
35
|
+
* passed multiaddr and optionally override the port.
|
|
36
|
+
*
|
|
37
|
+
* Wildcard IP4/6 addresses will be expanded into all available interfaces.
|
|
38
|
+
*/
|
|
39
|
+
export function getThinWaistAddresses (ma?: Multiaddr, port?: number): Multiaddr[] {
|
|
40
|
+
if (ma == null) {
|
|
41
|
+
return []
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const options = ma.toOptions()
|
|
45
|
+
|
|
46
|
+
if (isWildcard(options.host)) {
|
|
47
|
+
const addrs = []
|
|
48
|
+
|
|
49
|
+
for (const host of getNetworkAddrs(options.family)) {
|
|
50
|
+
addrs.push(multiaddr(`/ip${options.family}/${host}/${options.transport}/${port ?? options.port}`))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return addrs
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return [
|
|
57
|
+
multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${port ?? options.port}`)
|
|
58
|
+
]
|
|
59
|
+
}
|
package/src/link-local-ip.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { isIPv4, isIPv6 } from '@chainsafe/is-ip'
|
|
2
|
-
|
|
3
1
|
export function isLinkLocalIp (ip: string): boolean {
|
|
4
|
-
if (
|
|
5
|
-
return
|
|
2
|
+
if (ip.startsWith('169.254.')) {
|
|
3
|
+
return true
|
|
6
4
|
}
|
|
7
5
|
|
|
8
|
-
if (
|
|
9
|
-
return
|
|
6
|
+
if (ip.toLowerCase().startsWith('fe80')) {
|
|
7
|
+
return true
|
|
10
8
|
}
|
|
11
9
|
|
|
12
10
|
return false
|