libp2p-utils
Advanced tools
Comparing version 0.2.3 to 0.3.0
@@ -0,1 +1,10 @@ | ||
# [0.3.0](https://github.com/libp2p/js-libp2p-utils/compare/v0.2.3...v0.3.0) (2021-04-08) | ||
### Features | ||
* add types ([#16](https://github.com/libp2p/js-libp2p-utils/issues/16)) ([e0552b5](https://github.com/libp2p/js-libp2p-utils/commit/e0552b5b6b1d912a8f6f1e39b1a4b70fca91f547)) | ||
<a name="0.2.3"></a> | ||
@@ -2,0 +11,0 @@ ## [0.2.3](https://github.com/libp2p/js-libp2p-utils/compare/v0.2.2...v0.2.3) (2020-11-30) |
{ | ||
"name": "libp2p-utils", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", | ||
"leadMaintainer": "Vasco Santos <santos.vasco10@gmail.com>", | ||
"main": "src/index.js", | ||
"types": "dist/src/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"src/*": [ | ||
"dist/src/*", | ||
"dist/src/*/index" | ||
] | ||
} | ||
}, | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"scripts": { | ||
"prepare": "aegir build --no-bundle", | ||
"test": "aegir test", | ||
@@ -32,14 +46,17 @@ "test:browser": "aegir test -t browser", | ||
"devDependencies": { | ||
"aegir": "^27.0.0", | ||
"@types/debug": "^4.1.5", | ||
"aegir": "^32.1.0", | ||
"it-pair": "^1.0.0", | ||
"it-pipe": "^1.1.0", | ||
"streaming-iterables": "^5.0.3" | ||
"libp2p-interfaces": "^0.9.0", | ||
"streaming-iterables": "^5.0.3", | ||
"util": "^0.12.3" | ||
}, | ||
"dependencies": { | ||
"abortable-iterator": "^3.0.0", | ||
"debug": "^4.2.0", | ||
"err-code": "^2.0.3", | ||
"ip-address": "^6.1.0", | ||
"debug": "^4.3.0", | ||
"err-code": "^3.0.1", | ||
"ip-address": "^7.1.0", | ||
"is-loopback-addr": "^1.0.0", | ||
"multiaddr": "^8.0.0", | ||
"multiaddr": "^8.1.2", | ||
"private-ip": "^2.1.1" | ||
@@ -46,0 +63,0 @@ }, |
@@ -6,2 +6,12 @@ 'use strict' | ||
/** | ||
* @typedef {import('multiaddr')} Multiaddr | ||
*/ | ||
/** | ||
* @typedef {Object} Address | ||
* @property {Multiaddr} multiaddr peer multiaddr. | ||
* @property {boolean} isCertified obtained from a signed peer record. | ||
*/ | ||
/** | ||
* Compare function for array.sort(). | ||
@@ -8,0 +18,0 @@ * This sort aims to move the private adresses to the end of the array. |
'use strict' | ||
const debug = require('debug') | ||
const log = Object.assign(debug('libp2p:ip-port-to-multiaddr'), { | ||
error: debug('libp2p:ip-port-to-multiaddr:err') | ||
}) | ||
const multiaddr = require('multiaddr') | ||
@@ -24,3 +28,5 @@ const errCode = require('err-code') | ||
port = parseInt(port) | ||
if (typeof port === 'string') { | ||
port = parseInt(port) | ||
} | ||
@@ -31,15 +37,19 @@ if (isNaN(port)) { | ||
if (new Address4(ip).isValid()) { | ||
try { | ||
// Test valid IPv4 | ||
new Address4(ip) // eslint-disable-line no-new | ||
return multiaddr(`/ip4/${ip}/tcp/${port}`) | ||
} | ||
} catch {} | ||
const ip6 = new Address6(ip) | ||
if (ip6.isValid()) { | ||
try { | ||
// Test valid IPv6 | ||
const ip6 = new Address6(ip) | ||
return ip6.is4() | ||
? multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`) | ||
: multiaddr(`/ip6/${ip}/tcp/${port}`) | ||
} catch (err) { | ||
const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}` | ||
log.error(errMsg) | ||
throw errCode(new Error(errMsg), errors.ERR_INVALID_IP) | ||
} | ||
throw errCode(new Error(`invalid ip:port for creating a multiaddr: ${ip}:${port}`), errors.ERR_INVALID_IP) | ||
} | ||
@@ -46,0 +56,0 @@ |
'use strict' | ||
// @ts-ignore is-loopback-addr does not publish types | ||
const isLoopbackAddr = require('is-loopback-addr') | ||
/** | ||
* @typedef {import('multiaddr')} Multiaddr | ||
*/ | ||
/** | ||
* Check if a given multiaddr is a loopback address. | ||
@@ -7,0 +12,0 @@ * |
'use strict' | ||
// @ts-ignore private-ip does not publish types | ||
const isIpPrivate = require('private-ip') | ||
/** | ||
* @typedef {import('multiaddr')} Multiaddr | ||
*/ | ||
/** | ||
* Check if a given multiaddr has a private address. | ||
@@ -7,0 +12,0 @@ * |
'use strict' | ||
const abortable = require('abortable-iterator') | ||
const log = require('debug')('libp2p:stream:converter') | ||
const { source: abortable } = require('abortable-iterator') | ||
const debug = require('debug') | ||
const log = debug('libp2p:stream:converter') | ||
/** | ||
* @typedef {import('multiaddr')} Multiaddr | ||
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream | ||
* | ||
* @typedef {Object} Timeline | ||
* @property {number} open - connection opening timestamp. | ||
* @property {number} [upgraded] - connection upgraded timestamp. | ||
* @property {number} [close] | ||
*/ | ||
/** | ||
* Convert a duplex iterable into a MultiaddrConnection. | ||
@@ -11,3 +22,3 @@ * https://github.com/libp2p/interface-transport#multiaddrconnection | ||
* @param {object} streamProperties | ||
* @param {DuplexStream} streamProperties.stream | ||
* @param {MuxedStream} streamProperties.stream | ||
* @param {Multiaddr} streamProperties.remoteAddr | ||
@@ -17,2 +28,3 @@ * @param {Multiaddr} streamProperties.localAddr | ||
* @param {AbortSignal} [options.signal] | ||
* @returns {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} | ||
*/ | ||
@@ -22,4 +34,8 @@ function streamToMaConnection ({ stream, remoteAddr, localAddr }, options = {}) { | ||
const maConn = { | ||
/** | ||
* @param {Uint8Array} source | ||
*/ | ||
async sink (source) { | ||
if (options.signal) { | ||
// @ts-ignore ts infers source template will be a number | ||
source = abortable(source, options.signal) | ||
@@ -41,3 +57,2 @@ } | ||
}, | ||
source: options.signal ? abortable(source, options.signal) : source, | ||
@@ -47,7 +62,7 @@ conn: stream, | ||
remoteAddr, | ||
timeline: { open: Date.now() }, | ||
/** @type {Timeline} */ | ||
timeline: { open: Date.now(), close: undefined }, | ||
close () { | ||
sink([]) | ||
close() | ||
sink(new Uint8Array(0)) | ||
return close() | ||
} | ||
@@ -60,2 +75,3 @@ } | ||
} | ||
return Promise.resolve() | ||
} | ||
@@ -62,0 +78,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
25
20088
7
331
1
+ Addederr-code@3.0.1(transitive)
+ Addedip-address@7.1.0(transitive)
- Removedip-address@6.4.0(transitive)
- Removedlodash.find@4.6.0(transitive)
- Removedlodash.max@4.0.1(transitive)
- Removedlodash.merge@4.6.2(transitive)
- Removedlodash.padstart@4.6.1(transitive)
- Removedlodash.repeat@4.1.0(transitive)
Updateddebug@^4.3.0
Updatederr-code@^3.0.1
Updatedip-address@^7.1.0
Updatedmultiaddr@^8.1.2