@libp2p/utils
Advanced tools
Comparing version 6.2.1-f53f65d18 to 6.2.1-f8da60e73
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-f53f65d18", | ||
"version": "6.2.1-f8da60e73", | ||
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", | ||
@@ -87,2 +87,6 @@ "license": "Apache-2.0 OR MIT", | ||
}, | ||
"./link-local-ip": { | ||
"types": "./dist/src/link-local-ip.d.ts", | ||
"import": "./dist/src/link-local-ip.js" | ||
}, | ||
"./moving-average": { | ||
@@ -92,2 +96,6 @@ "types": "./dist/src/moving-average.d.ts", | ||
}, | ||
"./multiaddr/is-link-local": { | ||
"types": "./dist/src/multiaddr/is-link-local.d.ts", | ||
"import": "./dist/src/multiaddr/is-link-local.js" | ||
}, | ||
"./multiaddr/is-loopback": { | ||
@@ -161,6 +169,6 @@ "types": "./dist/src/multiaddr/is-loopback.d.ts", | ||
"@chainsafe/is-ip": "^2.0.2", | ||
"@libp2p/crypto": "5.0.7-f53f65d18", | ||
"@libp2p/interface": "2.2.1-f53f65d18", | ||
"@libp2p/logger": "5.1.4-f53f65d18", | ||
"@multiformats/multiaddr": "^12.2.3", | ||
"@libp2p/crypto": "5.0.7-f8da60e73", | ||
"@libp2p/interface": "2.2.1-f8da60e73", | ||
"@libp2p/logger": "5.1.4-f8da60e73", | ||
"@multiformats/multiaddr": "^12.3.3", | ||
"@sindresorhus/fnv1a": "^3.1.0", | ||
@@ -175,3 +183,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", | ||
@@ -181,3 +189,3 @@ "netmask": "^2.0.2", | ||
"race-event": "^1.3.0", | ||
"race-signal": "^1.0.2", | ||
"race-signal": "^1.1.0", | ||
"uint8arraylist": "^2.4.8", | ||
@@ -187,5 +195,5 @@ "uint8arrays": "^5.1.0" | ||
"devDependencies": { | ||
"@libp2p/peer-id": "5.0.8-f53f65d18", | ||
"@libp2p/peer-id": "5.0.8-f8da60e73", | ||
"@types/netmask": "^2.0.5", | ||
"aegir": "^44.0.1", | ||
"aegir": "^45.0.5", | ||
"benchmark": "^2.1.4", | ||
@@ -196,3 +204,3 @@ "delay": "^6.0.0", | ||
"it-pair": "^2.0.6", | ||
"sinon": "^18.0.0", | ||
"sinon": "^19.0.2", | ||
"sinon-ts": "^2.0.0" | ||
@@ -199,0 +207,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
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
271792
178
0
100
5175
+ Added@libp2p/crypto@5.0.7-f8da60e73(transitive)
+ Added@libp2p/interface@2.2.1-f8da60e73(transitive)
+ Added@libp2p/logger@5.1.4-f8da60e73(transitive)
- Removed@libp2p/crypto@5.0.7-f53f65d18(transitive)
- Removed@libp2p/interface@2.2.1-f53f65d18(transitive)
- Removed@libp2p/logger@5.1.4-f53f65d18(transitive)
Updatedit-stream-types@^2.0.2
Updatedrace-signal@^1.1.0