@libp2p/utils 6.2.1-0862522fe → 6.2.1-339b7df88

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/README.md CHANGED
@@ -49,7 +49,7 @@ $ npm i @libp2p/utils
49
49
 
50
50
  ## Browser `<script>` tag
51
51
 
52
- Loading this module through a script tag will make it's exports available as `Libp2pUtils` in the global namespace.
52
+ Loading this module through a script tag will make its exports available as `Libp2pUtils` in the global namespace.
53
53
 
54
54
  ```html
55
55
  <script src="https://unpkg.com/@libp2p/utils/dist/index.min.js"></script>
@@ -1,6 +1,6 @@
1
1
  import type { Multiaddr } from '@multiformats/multiaddr';
2
2
  /**
3
- * Check if a given multiaddr has a private address.
3
+ * Check if a given multiaddr starts with a private address
4
4
  */
5
5
  export declare function isPrivate(ma: Multiaddr): boolean;
6
6
  //# sourceMappingURL=is-private.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-private.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-private.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;GAEG;AACH,wBAAgB,SAAS,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAQjD"}
1
+ {"version":3,"file":"is-private.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-private.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AASxD;;GAEG;AACH,wBAAgB,SAAS,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAoBjD"}
@@ -1,14 +1,28 @@
1
1
  import { isPrivateIp } from '../private-ip.js';
2
+ const CODEC_IP4 = 0x04;
3
+ const CODEC_IP6 = 0x29;
4
+ const CODEC_DNS = 0x35;
5
+ const CODEC_DNS4 = 0x36;
6
+ const CODEC_DNS6 = 0x37;
7
+ const CODEC_DNSADDR = 0x38;
2
8
  /**
3
- * Check if a given multiaddr has a private address.
9
+ * Check if a given multiaddr starts with a private address
4
10
  */
5
11
  export function isPrivate(ma) {
6
12
  try {
7
- const { address } = ma.nodeAddress();
8
- return Boolean(isPrivateIp(address));
13
+ const [[codec, value]] = ma.stringTuples();
14
+ if (value == null) {
15
+ return true;
16
+ }
17
+ if (codec === CODEC_DNS || codec === CODEC_DNS4 || codec === CODEC_DNS6 || codec === CODEC_DNSADDR) {
18
+ return false;
19
+ }
20
+ if (codec === CODEC_IP4 || codec === CODEC_IP6) {
21
+ return isPrivateIp(value) ?? false;
22
+ }
9
23
  }
10
24
  catch {
11
- return true;
12
25
  }
26
+ return true;
13
27
  }
14
28
  //# sourceMappingURL=is-private.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-private.js","sourceRoot":"","sources":["../../../src/multiaddr/is-private.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9C;;GAEG;AACH,MAAM,UAAU,SAAS,CAAE,EAAa;IACtC,IAAI,CAAC;QACH,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,CAAA;QAEpC,OAAO,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAA;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"is-private.js","sourceRoot":"","sources":["../../../src/multiaddr/is-private.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9C,MAAM,SAAS,GAAG,IAAI,CAAA;AACtB,MAAM,SAAS,GAAG,IAAI,CAAA;AACtB,MAAM,SAAS,GAAG,IAAI,CAAA;AACtB,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,aAAa,GAAG,IAAI,CAAA;AAE1B;;GAEG;AACH,MAAM,UAAU,SAAS,CAAE,EAAa;IACtC,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,IAAI,CAAA;QACb,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,UAAU,IAAI,KAAK,KAAK,UAAU,IAAI,KAAK,KAAK,aAAa,EAAE,CAAC;YACnG,OAAO,KAAK,CAAA;QACd,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/C,OAAO,WAAW,CAAC,KAAK,CAAC,IAAI,KAAK,CAAA;QACpC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;IAET,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/utils",
3
- "version": "6.2.1-0862522fe",
3
+ "version": "6.2.1-339b7df88",
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",
@@ -156,10 +156,10 @@
156
156
  },
157
157
  "dependencies": {
158
158
  "@chainsafe/is-ip": "^2.0.2",
159
- "@libp2p/crypto": "5.0.7-0862522fe",
160
- "@libp2p/interface": "2.2.1-0862522fe",
161
- "@libp2p/logger": "5.1.4-0862522fe",
162
- "@multiformats/multiaddr": "^12.2.3",
159
+ "@libp2p/crypto": "5.0.7-339b7df88",
160
+ "@libp2p/interface": "2.2.1-339b7df88",
161
+ "@libp2p/logger": "5.1.4-339b7df88",
162
+ "@multiformats/multiaddr": "^12.3.3",
163
163
  "@sindresorhus/fnv1a": "^3.1.0",
164
164
  "@types/murmurhash3js-revisited": "^3.0.3",
165
165
  "any-signal": "^4.1.1",
@@ -169,25 +169,25 @@
169
169
  "it-foreach": "^2.1.1",
170
170
  "it-pipe": "^3.0.1",
171
171
  "it-pushable": "^3.2.3",
172
- "it-stream-types": "^2.0.1",
172
+ "it-stream-types": "^2.0.2",
173
173
  "murmurhash3js-revisited": "^3.0.0",
174
174
  "netmask": "^2.0.2",
175
175
  "p-defer": "^4.0.1",
176
176
  "race-event": "^1.3.0",
177
- "race-signal": "^1.0.2",
177
+ "race-signal": "^1.1.0",
178
178
  "uint8arraylist": "^2.4.8",
179
179
  "uint8arrays": "^5.1.0"
180
180
  },
181
181
  "devDependencies": {
182
- "@libp2p/peer-id": "5.0.8-0862522fe",
182
+ "@libp2p/peer-id": "5.0.8-339b7df88",
183
183
  "@types/netmask": "^2.0.5",
184
- "aegir": "^44.0.1",
184
+ "aegir": "^45.0.5",
185
185
  "benchmark": "^2.1.4",
186
186
  "delay": "^6.0.0",
187
187
  "it-all": "^3.0.6",
188
188
  "it-drain": "^3.0.7",
189
189
  "it-pair": "^2.0.6",
190
- "sinon": "^18.0.0",
190
+ "sinon": "^19.0.2",
191
191
  "sinon-ts": "^2.0.0"
192
192
  },
193
193
  "sideEffects": false
@@ -1,15 +1,34 @@
1
1
  import { isPrivateIp } from '../private-ip.js'
2
2
  import type { Multiaddr } from '@multiformats/multiaddr'
3
3
 
4
+ const CODEC_IP4 = 0x04
5
+ const CODEC_IP6 = 0x29
6
+ const CODEC_DNS = 0x35
7
+ const CODEC_DNS4 = 0x36
8
+ const CODEC_DNS6 = 0x37
9
+ const CODEC_DNSADDR = 0x38
10
+
4
11
  /**
5
- * Check if a given multiaddr has a private address.
12
+ * Check if a given multiaddr starts with a private address
6
13
  */
7
14
  export function isPrivate (ma: Multiaddr): boolean {
8
15
  try {
9
- const { address } = ma.nodeAddress()
16
+ const [[codec, value]] = ma.stringTuples()
17
+
18
+ if (value == null) {
19
+ return true
20
+ }
21
+
22
+ if (codec === CODEC_DNS || codec === CODEC_DNS4 || codec === CODEC_DNS6 || codec === CODEC_DNSADDR) {
23
+ return false
24
+ }
10
25
 
11
- return Boolean(isPrivateIp(address))
26
+ if (codec === CODEC_IP4 || codec === CODEC_IP6) {
27
+ return isPrivateIp(value) ?? false
28
+ }
12
29
  } catch {
13
- return true
30
+
14
31
  }
32
+
33
+ return true
15
34
  }
package/LICENSE DELETED
@@ -1,4 +0,0 @@
1
- This project is dual licensed under MIT and Apache-2.0.
2
-
3
- MIT: https://www.opensource.org/licenses/mit
4
- Apache-2.0: https://www.apache.org/licenses/license-2.0