@libp2p/utils 6.2.1-406b3916c → 6.2.1-48e9cfa56
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/global-unicast-ip.d.ts +2 -0
- package/dist/src/global-unicast-ip.d.ts.map +1 -0
- package/dist/src/global-unicast-ip.js +9 -0
- package/dist/src/global-unicast-ip.js.map +1 -0
- package/dist/src/multiaddr/is-global-unicast.d.ts +6 -0
- package/dist/src/multiaddr/is-global-unicast.d.ts.map +1 -0
- package/dist/src/multiaddr/is-global-unicast.js +20 -0
- package/dist/src/multiaddr/is-global-unicast.js.map +1 -0
- package/package.json +14 -5
- package/src/global-unicast-ip.ts +10 -0
- package/src/multiaddr/is-global-unicast.ts +25 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-unicast-ip.d.ts","sourceRoot":"","sources":["../../src/global-unicast-ip.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,CAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAMtD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { isIPv6 } from '@chainsafe/is-ip';
|
|
2
|
+
import { cidrContains } from '@chainsafe/netmask';
|
|
3
|
+
export function isGlobalUnicastIp(ip) {
|
|
4
|
+
if (isIPv6(ip)) {
|
|
5
|
+
return cidrContains('2000::/3', ip);
|
|
6
|
+
}
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=global-unicast-ip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-unicast-ip.js","sourceRoot":"","sources":["../../src/global-unicast-ip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,MAAM,UAAU,iBAAiB,CAAE,EAAU;IAC3C,IAAI,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;QACf,OAAO,YAAY,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;IACrC,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-global-unicast.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-global-unicast.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD;;GAEG;AACH,wBAAgB,eAAe,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAgBvD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { cidrContains } from '@chainsafe/netmask';
|
|
2
|
+
const CODEC_IP6 = 0x29;
|
|
3
|
+
/**
|
|
4
|
+
* Check if a given multiaddr is an IPv6 global unicast address
|
|
5
|
+
*/
|
|
6
|
+
export function isGlobalUnicast(ma) {
|
|
7
|
+
try {
|
|
8
|
+
const [[codec, value]] = ma.stringTuples();
|
|
9
|
+
if (value == null) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (codec === CODEC_IP6) {
|
|
13
|
+
return cidrContains('2000::/3', value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=is-global-unicast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-global-unicast.js","sourceRoot":"","sources":["../../../src/multiaddr/is-global-unicast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGjD,MAAM,SAAS,GAAG,IAAI,CAAA;AAEtB;;GAEG;AACH,MAAM,UAAU,eAAe,CAAE,EAAa;IAC5C,IAAI,CAAC;QACH,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,CAAA;QAE1C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;QACxC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;IAET,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.2.1-
|
|
3
|
+
"version": "6.2.1-48e9cfa56",
|
|
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,10 @@
|
|
|
76
76
|
"types": "./dist/src/filters/index.d.ts",
|
|
77
77
|
"import": "./dist/src/filters/index.js"
|
|
78
78
|
},
|
|
79
|
+
"./global-unicast-ip": {
|
|
80
|
+
"types": "./dist/src/global-unicast-ip.d.ts",
|
|
81
|
+
"import": "./dist/src/global-unicast-ip.js"
|
|
82
|
+
},
|
|
79
83
|
"./ip-port-to-multiaddr": {
|
|
80
84
|
"types": "./dist/src/ip-port-to-multiaddr.d.ts",
|
|
81
85
|
"import": "./dist/src/ip-port-to-multiaddr.js"
|
|
@@ -92,6 +96,10 @@
|
|
|
92
96
|
"types": "./dist/src/moving-average.d.ts",
|
|
93
97
|
"import": "./dist/src/moving-average.js"
|
|
94
98
|
},
|
|
99
|
+
"./multiaddr/is-global-unicast": {
|
|
100
|
+
"types": "./dist/src/multiaddr/is-global-unicast.d.ts",
|
|
101
|
+
"import": "./dist/src/multiaddr/is-global-unicast.js"
|
|
102
|
+
},
|
|
95
103
|
"./multiaddr/is-link-local": {
|
|
96
104
|
"types": "./dist/src/multiaddr/is-link-local.d.ts",
|
|
97
105
|
"import": "./dist/src/multiaddr/is-link-local.js"
|
|
@@ -164,9 +172,10 @@
|
|
|
164
172
|
},
|
|
165
173
|
"dependencies": {
|
|
166
174
|
"@chainsafe/is-ip": "^2.0.2",
|
|
167
|
-
"@
|
|
168
|
-
"@libp2p/
|
|
169
|
-
"@libp2p/
|
|
175
|
+
"@chainsafe/netmask": "^2.0.0",
|
|
176
|
+
"@libp2p/crypto": "5.0.7-48e9cfa56",
|
|
177
|
+
"@libp2p/interface": "2.2.1-48e9cfa56",
|
|
178
|
+
"@libp2p/logger": "5.1.4-48e9cfa56",
|
|
170
179
|
"@multiformats/multiaddr": "^12.3.3",
|
|
171
180
|
"@sindresorhus/fnv1a": "^3.1.0",
|
|
172
181
|
"@types/murmurhash3js-revisited": "^3.0.3",
|
|
@@ -187,7 +196,7 @@
|
|
|
187
196
|
"uint8arrays": "^5.1.0"
|
|
188
197
|
},
|
|
189
198
|
"devDependencies": {
|
|
190
|
-
"@libp2p/peer-id": "5.0.8-
|
|
199
|
+
"@libp2p/peer-id": "5.0.8-48e9cfa56",
|
|
191
200
|
"@types/netmask": "^2.0.5",
|
|
192
201
|
"aegir": "^45.0.5",
|
|
193
202
|
"benchmark": "^2.1.4",
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { cidrContains } from '@chainsafe/netmask'
|
|
2
|
+
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
3
|
+
|
|
4
|
+
const CODEC_IP6 = 0x29
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Check if a given multiaddr is an IPv6 global unicast address
|
|
8
|
+
*/
|
|
9
|
+
export function isGlobalUnicast (ma: Multiaddr): boolean {
|
|
10
|
+
try {
|
|
11
|
+
const [[codec, value]] = ma.stringTuples()
|
|
12
|
+
|
|
13
|
+
if (value == null) {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (codec === CODEC_IP6) {
|
|
18
|
+
return cidrContains('2000::/3', value)
|
|
19
|
+
}
|
|
20
|
+
} catch {
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return false
|
|
25
|
+
}
|