@libp2p/utils
Advanced tools
Comparing version 6.2.1 to 6.3.0-023ea575c
import type { Multiaddr } from '@multiformats/multiaddr'; | ||
/** | ||
* Check if a given multiaddr has a private address. | ||
* Check if a given multiaddr starts with a private address | ||
*/ | ||
export declare function isPrivate(ma: Multiaddr): boolean; | ||
//# sourceMappingURL=is-private.d.ts.map |
import { isPrivateIp } from '../private-ip.js'; | ||
const CODEC_IP4 = 0x04; | ||
const CODEC_IP6 = 0x29; | ||
const CODEC_DNS = 0x35; | ||
const CODEC_DNS4 = 0x36; | ||
const CODEC_DNS6 = 0x37; | ||
const CODEC_DNSADDR = 0x38; | ||
/** | ||
* Check if a given multiaddr has a private address. | ||
* Check if a given multiaddr starts with a private address | ||
*/ | ||
export function isPrivate(ma) { | ||
try { | ||
const { address } = ma.nodeAddress(); | ||
return Boolean(isPrivateIp(address)); | ||
const [[codec, value]] = ma.stringTuples(); | ||
if (value == null) { | ||
return true; | ||
} | ||
if (codec === CODEC_DNS || codec === CODEC_DNS4 || codec === CODEC_DNS6 || codec === CODEC_DNSADDR) { | ||
return false; | ||
} | ||
if (codec === CODEC_IP4 || codec === CODEC_IP6) { | ||
return isPrivateIp(value) ?? false; | ||
} | ||
} | ||
catch { | ||
return true; | ||
} | ||
return true; | ||
} | ||
//# sourceMappingURL=is-private.js.map |
{ | ||
"name": "@libp2p/utils", | ||
"version": "6.2.1", | ||
"version": "6.3.0-023ea575c", | ||
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", | ||
@@ -79,2 +79,6 @@ "license": "Apache-2.0 OR MIT", | ||
}, | ||
"./global-unicast-ip": { | ||
"types": "./dist/src/global-unicast-ip.d.ts", | ||
"import": "./dist/src/global-unicast-ip.js" | ||
}, | ||
"./ip-port-to-multiaddr": { | ||
@@ -88,2 +92,6 @@ "types": "./dist/src/ip-port-to-multiaddr.d.ts", | ||
}, | ||
"./link-local-ip": { | ||
"types": "./dist/src/link-local-ip.d.ts", | ||
"import": "./dist/src/link-local-ip.js" | ||
}, | ||
"./moving-average": { | ||
@@ -93,2 +101,10 @@ "types": "./dist/src/moving-average.d.ts", | ||
}, | ||
"./multiaddr/is-global-unicast": { | ||
"types": "./dist/src/multiaddr/is-global-unicast.d.ts", | ||
"import": "./dist/src/multiaddr/is-global-unicast.js" | ||
}, | ||
"./multiaddr/is-link-local": { | ||
"types": "./dist/src/multiaddr/is-link-local.d.ts", | ||
"import": "./dist/src/multiaddr/is-link-local.js" | ||
}, | ||
"./multiaddr/is-loopback": { | ||
@@ -162,6 +178,7 @@ "types": "./dist/src/multiaddr/is-loopback.d.ts", | ||
"@chainsafe/is-ip": "^2.0.2", | ||
"@libp2p/crypto": "^5.0.7", | ||
"@libp2p/interface": "^2.2.1", | ||
"@libp2p/logger": "^5.1.4", | ||
"@multiformats/multiaddr": "^12.2.3", | ||
"@chainsafe/netmask": "^2.0.0", | ||
"@libp2p/crypto": "5.0.8-023ea575c", | ||
"@libp2p/interface": "2.3.0-023ea575c", | ||
"@libp2p/logger": "5.1.5-023ea575c", | ||
"@multiformats/multiaddr": "^12.3.3", | ||
"@sindresorhus/fnv1a": "^3.1.0", | ||
@@ -176,3 +193,3 @@ "@types/murmurhash3js-revisited": "^3.0.3", | ||
"it-pushable": "^3.2.3", | ||
"it-stream-types": "^2.0.1", | ||
"it-stream-types": "^2.0.2", | ||
"murmurhash3js-revisited": "^3.0.0", | ||
@@ -182,3 +199,3 @@ "netmask": "^2.0.2", | ||
"race-event": "^1.3.0", | ||
"race-signal": "^1.0.2", | ||
"race-signal": "^1.1.0", | ||
"uint8arraylist": "^2.4.8", | ||
@@ -188,5 +205,5 @@ "uint8arrays": "^5.1.0" | ||
"devDependencies": { | ||
"@libp2p/peer-id": "^5.0.8", | ||
"@libp2p/peer-id": "5.0.9-023ea575c", | ||
"@types/netmask": "^2.0.5", | ||
"aegir": "^44.0.1", | ||
"aegir": "^45.0.5", | ||
"benchmark": "^2.1.4", | ||
@@ -197,3 +214,3 @@ "delay": "^6.0.0", | ||
"it-pair": "^2.0.6", | ||
"sinon": "^18.0.0", | ||
"sinon": "^19.0.2", | ||
"sinon-ts": "^2.0.0" | ||
@@ -200,0 +217,0 @@ }, |
@@ -52,3 +52,3 @@ # @libp2p/utils | ||
Loading this module through a script tag will make it's exports available as `Libp2pUtils` in the global namespace. | ||
Loading this module through a script tag will make its exports available as `Libp2pUtils` in the global namespace. | ||
@@ -55,0 +55,0 @@ ```html |
import { isPrivateIp } from '../private-ip.js' | ||
import type { Multiaddr } from '@multiformats/multiaddr' | ||
const CODEC_IP4 = 0x04 | ||
const CODEC_IP6 = 0x29 | ||
const CODEC_DNS = 0x35 | ||
const CODEC_DNS4 = 0x36 | ||
const CODEC_DNS6 = 0x37 | ||
const CODEC_DNSADDR = 0x38 | ||
/** | ||
* Check if a given multiaddr has a private address. | ||
* Check if a given multiaddr starts with a private address | ||
*/ | ||
export function isPrivate (ma: Multiaddr): boolean { | ||
try { | ||
const { address } = ma.nodeAddress() | ||
const [[codec, value]] = ma.stringTuples() | ||
return Boolean(isPrivateIp(address)) | ||
if (value == null) { | ||
return true | ||
} | ||
if (codec === CODEC_DNS || codec === CODEC_DNS4 || codec === CODEC_DNS6 || codec === CODEC_DNSADDR) { | ||
return false | ||
} | ||
if (codec === CODEC_IP4 || codec === CODEC_IP6) { | ||
return isPrivateIp(value) ?? false | ||
} | ||
} catch { | ||
return true | ||
} | ||
return true | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
188
0
100
5235
275362
23
1
+ Added@chainsafe/netmask@^2.0.0
+ Added@libp2p/crypto@5.0.8-023ea575c(transitive)
+ Added@libp2p/interface@2.3.0-023ea575c(transitive)
+ Added@libp2p/logger@5.1.5-023ea575c(transitive)
- Removed@libp2p/crypto@5.0.9(transitive)
- Removed@libp2p/interface@2.4.0(transitive)
- Removed@libp2p/logger@5.1.6(transitive)
Updatedit-stream-types@^2.0.2
Updatedrace-signal@^1.1.0