@libp2p/utils
Advanced tools
Comparing version 6.2.1-0862522fe to 6.2.1-339b7df88
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-0862522fe", | ||
"version": "6.2.1-339b7df88", | ||
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", | ||
@@ -159,6 +159,6 @@ "license": "Apache-2.0 OR MIT", | ||
"@chainsafe/is-ip": "^2.0.2", | ||
"@libp2p/crypto": "5.0.7-0862522fe", | ||
"@libp2p/interface": "2.2.1-0862522fe", | ||
"@libp2p/logger": "5.1.4-0862522fe", | ||
"@multiformats/multiaddr": "^12.2.3", | ||
"@libp2p/crypto": "5.0.7-339b7df88", | ||
"@libp2p/interface": "2.2.1-339b7df88", | ||
"@libp2p/logger": "5.1.4-339b7df88", | ||
"@multiformats/multiaddr": "^12.3.3", | ||
"@sindresorhus/fnv1a": "^3.1.0", | ||
@@ -173,3 +173,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", | ||
@@ -179,3 +179,3 @@ "netmask": "^2.0.2", | ||
"race-event": "^1.3.0", | ||
"race-signal": "^1.0.2", | ||
"race-signal": "^1.1.0", | ||
"uint8arraylist": "^2.4.8", | ||
@@ -185,5 +185,5 @@ "uint8arrays": "^5.1.0" | ||
"devDependencies": { | ||
"@libp2p/peer-id": "5.0.8-0862522fe", | ||
"@libp2p/peer-id": "5.0.8-339b7df88", | ||
"@types/netmask": "^2.0.5", | ||
"aegir": "^44.0.1", | ||
"aegir": "^45.0.5", | ||
"benchmark": "^2.1.4", | ||
@@ -194,3 +194,3 @@ "delay": "^6.0.0", | ||
"it-pair": "^2.0.6", | ||
"sinon": "^18.0.0", | ||
"sinon": "^19.0.2", | ||
"sinon-ts": "^2.0.0" | ||
@@ -197,0 +197,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
268020
0
100
5105
168
+ Added@libp2p/crypto@5.0.7-339b7df88(transitive)
+ Added@libp2p/interface@2.2.1-339b7df88(transitive)
+ Added@libp2p/logger@5.1.4-339b7df88(transitive)
- Removed@libp2p/crypto@5.0.7-0862522fe(transitive)
- Removed@libp2p/interface@2.2.1-0862522fe(transitive)
- Removed@libp2p/logger@5.1.4-0862522fe(transitive)
Updatedit-stream-types@^2.0.2
Updatedrace-signal@^1.1.0