@libp2p/utils
Advanced tools
Comparing version 6.5.2 to 6.5.3-9b1a3791d
import { isLoopbackAddr } from 'is-loopback-addr'; | ||
import { isIpBased } from './is-ip-based.js'; | ||
/** | ||
@@ -6,2 +7,6 @@ * Check if a given multiaddr is a loopback address. | ||
export function isLoopback(ma) { | ||
if (!isIpBased(ma)) { | ||
// not an IP based multiaddr, cannot be private | ||
return false; | ||
} | ||
const { address } = ma.nodeAddress(); | ||
@@ -8,0 +13,0 @@ return isLoopbackAddr(address); |
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; | ||
import { isIpBased } from './is-ip-based.js'; | ||
/** | ||
@@ -13,12 +8,11 @@ * Check if a given multiaddr starts with a private address | ||
try { | ||
const [[codec, value]] = ma.stringTuples(); | ||
if (!isIpBased(ma)) { | ||
// not an IP based multiaddr, cannot be private | ||
return false; | ||
} | ||
const [[, 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; | ||
} | ||
return isPrivateIp(value) ?? false; | ||
} | ||
@@ -25,0 +19,0 @@ catch { |
{ | ||
"name": "@libp2p/utils", | ||
"version": "6.5.2", | ||
"version": "6.5.3-9b1a3791d", | ||
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", | ||
@@ -111,2 +111,6 @@ "license": "Apache-2.0 OR MIT", | ||
}, | ||
"./multiaddr/is-ip-based": { | ||
"types": "./dist/src/multiaddr/is-ip-based.d.ts", | ||
"import": "./dist/src/multiaddr/is-ip-based.js" | ||
}, | ||
"./multiaddr/is-link-local": { | ||
@@ -120,2 +124,6 @@ "types": "./dist/src/multiaddr/is-link-local.d.ts", | ||
}, | ||
"./multiaddr/is-network-address": { | ||
"types": "./dist/src/multiaddr/is-network-address.d.ts", | ||
"import": "./dist/src/multiaddr/is-network-address.js" | ||
}, | ||
"./multiaddr/is-private": { | ||
@@ -186,5 +194,5 @@ "types": "./dist/src/multiaddr/is-private.d.ts", | ||
"@chainsafe/netmask": "^2.0.0", | ||
"@libp2p/crypto": "^5.0.12", | ||
"@libp2p/interface": "^2.6.0", | ||
"@libp2p/logger": "^5.1.9", | ||
"@libp2p/crypto": "5.0.12-9b1a3791d", | ||
"@libp2p/interface": "2.6.0-9b1a3791d", | ||
"@libp2p/logger": "5.1.9-9b1a3791d", | ||
"@multiformats/multiaddr": "^12.3.3", | ||
@@ -208,3 +216,3 @@ "@sindresorhus/fnv1a": "^3.1.0", | ||
"devDependencies": { | ||
"@libp2p/peer-id": "^5.0.13", | ||
"@libp2p/peer-id": "5.0.13-9b1a3791d", | ||
"@types/netmask": "^2.0.5", | ||
@@ -211,0 +219,0 @@ "aegir": "^45.0.5", |
import { isLoopbackAddr } from 'is-loopback-addr' | ||
import { isIpBased } from './is-ip-based.js' | ||
import type { Multiaddr } from '@multiformats/multiaddr' | ||
@@ -8,2 +9,7 @@ | ||
export function isLoopback (ma: Multiaddr): boolean { | ||
if (!isIpBased(ma)) { | ||
// not an IP based multiaddr, cannot be private | ||
return false | ||
} | ||
const { address } = ma.nodeAddress() | ||
@@ -10,0 +16,0 @@ |
import { isPrivateIp } from '../private-ip.js' | ||
import { isIpBased } from './is-ip-based.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 | ||
/** | ||
@@ -16,15 +10,14 @@ * Check if a given multiaddr starts with a private address | ||
try { | ||
const [[codec, value]] = ma.stringTuples() | ||
if (!isIpBased(ma)) { | ||
// not an IP based multiaddr, cannot be private | ||
return false | ||
} | ||
const [[, 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 | ||
} | ||
return isPrivateIp(value) ?? false | ||
} catch { | ||
@@ -31,0 +24,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
208
284265
5432
1
+ Added@libp2p/crypto@5.0.12-9b1a3791d(transitive)
+ Added@libp2p/interface@2.6.0-9b1a3791d(transitive)
+ Added@libp2p/logger@5.1.9-9b1a3791d(transitive)
- Removed@libp2p/crypto@5.0.12(transitive)
- Removed@libp2p/interface@2.6.0(transitive)
- Removed@libp2p/logger@5.1.9(transitive)