From bc5a3d59a012a9b3f6702474710c50d0318e6b68 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 23 Sep 2019 15:24:47 +0200 Subject: [PATCH 001/124] first commit --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000000..959801e53d --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# js-libp2p-utils From 426b42196e00d2017527e8df6bbbc12ebc24d3a8 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 23 Sep 2019 17:39:32 +0200 Subject: [PATCH 002/124] feat: ip port to multiaddr (#1) --- .gitignore | 32 +++++++++++++++++++ .travis.yml | 52 +++++++++++++++++++++++++++++++ LICENSE | 21 +++++++++++++ README.md | 48 ++++++++++++++++++++++++++++ package.json | 40 ++++++++++++++++++++++++ src/index.js | 0 src/ip-port-to-multiaddr.js | 30 ++++++++++++++++++ test/ip-port-to-multiaddr.spec.js | 50 +++++++++++++++++++++++++++++ 8 files changed, 273 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 package.json create mode 100644 src/index.js create mode 100644 src/ip-port-to-multiaddr.js create mode 100644 test/ip-port-to-multiaddr.spec.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..ce9a4d1190 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +package-lock.json +yarn.lock +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git +node_modules + +dist +docs diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..bd3dcaf568 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,52 @@ +language: node_js +cache: npm +stages: + - check + - test + - cov + +node_js: + - '10' + - '12' + +os: + - linux + - osx + +script: npx nyc -s npm run test:node -- --bail +after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov + +jobs: + include: + - os: windows + filter_secrets: false + cache: false + + - stage: check + script: + - npx aegir commitlint --travis + - npx aegir dep-check + - npm run lint + + - stage: test + name: chrome + addons: + chrome: stable + script: npx aegir test -t browser -t webworker + + - stage: test + name: firefox + addons: + firefox: latest + script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless + + - stage: test + name: electron + services: + - xvfb + script: + - npm run test:electron + - npm run test:electron-renderer + +notifications: + email: false diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..60d500031f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) IPFS + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 959801e53d..5553afddd1 100644 --- a/README.md +++ b/README.md @@ -1 +1,49 @@ # js-libp2p-utils + +[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai) +[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) +[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p) +[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io) +[![](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-utils.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-utils) +[![](https://img.shields.io/travis/libp2p/js-libp2p-utils.svg?style=flat-square)](https://travis-ci.com/libp2p/js-libp2p-utils) +[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-utils.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-utils) +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) + +> This package serves as a central repository for shared logic and dependencies for all libp2p packages, using `libp2p-utils` helps to easily re-use small scoped blocks of logic across all libp2p modules and also as a dependency proxy (think `aegir` for domain logic dependencies). + + +The libp2p ecosystem has lots of repos with it comes several problems like: +- Domain logic dedupe - all modules shared a lot of logic like validation, streams handling, etc. +- Dependencies management - it's really easy with so many repos for dependencies to go out of control, they become outdated, different repos use different modules to do the same thing (like merging defaults options), browser bundles ends up with multiple versions of the same package, bumping versions is cumbersome to do because we need to go through several repos, etc. + +These problems are the motivation for this package, having shared logic in this package avoids creating cyclic dependencies, centralizes common use modules/functions (exactly like aegir does for the tooling), semantic versioning for 3rd party dependencies is handled in one single place (a good example is going from streams 2 to 3) and maintainers should only care about having `libp2p-utils` updated. + +## Lead Maintainer + +[Vasco Santos](https://github.com/vasco-santos) + +## Install + + +```bash +$ npm install --save libp2p-utils +``` + +## Usage +Each function should be imported directly. + +```js +const ipAndPortToMultiaddr = require('libp2p-utils/src/ip-port-to-multiaddr') + +const ma = ipAndPortToMultiaddr('127.0.0.1', 9000) +``` + +## Contribute + +Contributions welcome. Please check out [the issues](https://github.com/libp2p/js-libp2p-utils/issues). + +Check out our [contributing document](https://github.com/ipfs/community/blob/master/contributing.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). + +## License + +[MIT](LICENSE) © Protocol Labs Inc. diff --git a/package.json b/package.json new file mode 100644 index 0000000000..11076651ce --- /dev/null +++ b/package.json @@ -0,0 +1,40 @@ +{ + "name": "libp2p-utils", + "version": "0.0.0", + "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", + "leadMaintainer": "Vasco Santos ", + "main": "src/index.js", + "scripts": { + "test": "aegir test", + "test:browser": "aegir test -t browser", + "test:node": "aegir test -t node", + "test:electron": "aegir test -t electron-main", + "test:electron-renderer": "aegir test -t electron-renderer", + "lint": "aegir lint", + "release": "aegir release --docs", + "release-minor": "aegir release --type minor --docs", + "release-major": "aegir release --type major --docs", + "build": "aegir build" + }, + "pre-push": [ + "lint" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/libp2p/js-libp2p-utils.git" + }, + "license": "MIT", + "bugs": { + "url": "https://github.com/libp2p/js-libp2p-utils/issues" + }, + "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", + "devDependencies": { + "aegir": "^20.3.1", + "chai": "^4.2.0", + "dirty-chai": "^2.0.1" + }, + "dependencies": { + "ip-address": "^6.1.0", + "multiaddr": "^7.1.0" + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/ip-port-to-multiaddr.js b/src/ip-port-to-multiaddr.js new file mode 100644 index 0000000000..6d980c4953 --- /dev/null +++ b/src/ip-port-to-multiaddr.js @@ -0,0 +1,30 @@ +'use strict' + +const multiaddr = require('multiaddr') +const { Address4, Address6 } = require('ip-address') + +module.exports = (ip, port) => { + if (typeof ip !== 'string') { + throw new Error('invalid ip') + } + + port = parseInt(port) + + if (isNaN(port)) { + throw new Error('invalid port') + } + + if (new Address4(ip).isValid()) { + return multiaddr(`/ip4/${ip}/tcp/${port}`) + } + + const ip6 = new Address6(ip) + + if (ip6.isValid()) { + return ip6.is4() + ? multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`) + : multiaddr(`/ip6/${ip}/tcp/${port}`) + } + + throw new Error('invalid ip') +} diff --git a/test/ip-port-to-multiaddr.spec.js b/test/ip-port-to-multiaddr.spec.js new file mode 100644 index 0000000000..657e56927f --- /dev/null +++ b/test/ip-port-to-multiaddr.spec.js @@ -0,0 +1,50 @@ +/* eslint-env mocha */ +'use strict' + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) +const toMultiaddr = require('../src/ip-port-to-multiaddr') + +describe('IP and port to Multiaddr', () => { + it('creates multiaddr from valid IPv4 IP and port', () => { + const ip = '127.0.0.1' + const port = '9090' + expect(toMultiaddr(ip, port).toString()).to.equal(`/ip4/${ip}/tcp/${port}`) + }) + + it('creates multiaddr from valid IPv4 IP and numeric port', () => { + const ip = '127.0.0.1' + const port = 9090 + expect(toMultiaddr(ip, port).toString()).to.equal(`/ip4/${ip}/tcp/${port}`) + }) + + it('creates multiaddr from valid IPv4 in IPv6 IP and port', () => { + const ip = '0:0:0:0:0:0:101.45.75.219' + const port = '9090' + expect(toMultiaddr(ip, port).toString()).to.equal(`/ip4/101.45.75.219/tcp/${port}`) + }) + + it('creates multiaddr from valid IPv6 IP and port', () => { + const ip = '::1' + const port = '9090' + expect(toMultiaddr(ip, port).toString()).to.equal(`/ip6/${ip}/tcp/${port}`) + }) + + it('throws for missing IP address', () => { + expect(() => toMultiaddr()).to.throw('invalid ip') + }) + + it('throws for invalid IP address', () => { + const ip = 'aewmrn4awoew' + const port = '234' + expect(() => toMultiaddr(ip, port)).to.throw('invalid ip') + }) + + it('throws for invalid port', () => { + const ip = '127.0.0.1' + const port = 'garbage' + expect(() => toMultiaddr(ip, port)).to.throw('invalid port') + }) +}) From bb46bca7d66638bb34198a7ab7acfeffc000a6a5 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 23 Sep 2019 17:43:12 +0200 Subject: [PATCH 003/124] chore: update contributors --- package.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 11076651ce..f14851d59f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libp2p-utils", - "version": "0.0.0", + "version": "0.1.0", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", @@ -12,7 +12,7 @@ "test:electron-renderer": "aegir test -t electron-renderer", "lint": "aegir lint", "release": "aegir release --docs", - "release-minor": "aegir release --type minor --docs", + "release-minor": "aegir release --target node --type minor --docs", "release-major": "aegir release --type major --docs", "build": "aegir build" }, @@ -36,5 +36,8 @@ "dependencies": { "ip-address": "^6.1.0", "multiaddr": "^7.1.0" - } + }, + "contributors": [ + "Vasco Santos " + ] } From 8364aa89c2147377ba46c181aea0c76b4ed0a63f Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 23 Sep 2019 17:43:12 +0200 Subject: [PATCH 004/124] chore: release version v0.1.0 --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000..d9150214d4 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ + +# 0.1.0 (2019-09-23) + + +### Features + +* ip port to multiaddr ([#1](https://github.com/libp2p/js-libp2p-utils/issues/1)) ([426b421](https://github.com/libp2p/js-libp2p-utils/commit/426b421)) + + + From 30c236d92f4fc4aeb4df92cc88dcb212b27cba6f Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 13 Feb 2020 16:22:12 +0100 Subject: [PATCH 005/124] chore: add meaningful errors for ip:port to multiaddr (#4) * chore: add meaningful errors for ip:port to multiaddr * chore: address review --- package.json | 1 + src/ip-port-to-multiaddr.js | 15 ++++++++++++--- test/ip-port-to-multiaddr.spec.js | 8 +++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index f14851d59f..098448c317 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "dirty-chai": "^2.0.1" }, "dependencies": { + "err-code": "^2.0.0", "ip-address": "^6.1.0", "multiaddr": "^7.1.0" }, diff --git a/src/ip-port-to-multiaddr.js b/src/ip-port-to-multiaddr.js index 6d980c4953..2d6b5eff1c 100644 --- a/src/ip-port-to-multiaddr.js +++ b/src/ip-port-to-multiaddr.js @@ -1,17 +1,24 @@ 'use strict' const multiaddr = require('multiaddr') +const errCode = require('err-code') const { Address4, Address6 } = require('ip-address') +const errors = { + ERR_INVALID_IP_PARAMETER: 'ERR_INVALID_IP_PARAMETER', + ERR_INVALID_PORT_PARAMETER: 'ERR_INVALID_PORT_PARAMETER', + ERR_INVALID_IP: 'ERR_INVALID_IP' +} + module.exports = (ip, port) => { if (typeof ip !== 'string') { - throw new Error('invalid ip') + throw errCode(new Error(`invalid ip provided: ${ip}`), errors.ERR_INVALID_IP_PARAMETER) } port = parseInt(port) if (isNaN(port)) { - throw new Error('invalid port') + throw errCode(new Error(`invalid port provided: ${port}`), errors.ERR_INVALID_PORT_PARAMETER) } if (new Address4(ip).isValid()) { @@ -26,5 +33,7 @@ module.exports = (ip, port) => { : multiaddr(`/ip6/${ip}/tcp/${port}`) } - throw new Error('invalid ip') + throw errCode(new Error(`invalid ip:port for creating a multiaddr: ${ip}:${port}`), errors.ERR_INVALID_IP) } + +module.exports.Errors = errors diff --git a/test/ip-port-to-multiaddr.spec.js b/test/ip-port-to-multiaddr.spec.js index 657e56927f..c634047dfe 100644 --- a/test/ip-port-to-multiaddr.spec.js +++ b/test/ip-port-to-multiaddr.spec.js @@ -5,7 +5,9 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) + const toMultiaddr = require('../src/ip-port-to-multiaddr') +const { Errors } = require('../src/ip-port-to-multiaddr') describe('IP and port to Multiaddr', () => { it('creates multiaddr from valid IPv4 IP and port', () => { @@ -33,18 +35,18 @@ describe('IP and port to Multiaddr', () => { }) it('throws for missing IP address', () => { - expect(() => toMultiaddr()).to.throw('invalid ip') + expect(() => toMultiaddr()).to.throw('invalid ip provided').with.property('code', Errors.ERR_INVALID_IP_PARAMETER) }) it('throws for invalid IP address', () => { const ip = 'aewmrn4awoew' const port = '234' - expect(() => toMultiaddr(ip, port)).to.throw('invalid ip') + expect(() => toMultiaddr(ip, port)).to.throw('invalid ip:port for creating a multiaddr').with.property('code', Errors.ERR_INVALID_IP) }) it('throws for invalid port', () => { const ip = '127.0.0.1' const port = 'garbage' - expect(() => toMultiaddr(ip, port)).to.throw('invalid port') + expect(() => toMultiaddr(ip, port)).to.throw('invalid port provided').with.property('code', Errors.ERR_INVALID_PORT_PARAMETER) }) }) From 523f80ea6c37fd94512732a4b1f712730f507fcf Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 13 Feb 2020 16:22:57 +0100 Subject: [PATCH 006/124] chore: update contributors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 098448c317..c75337dadc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libp2p-utils", - "version": "0.1.0", + "version": "0.1.1", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", From b67dcbe74a0e232fe9d1661bc610fc97c0de813c Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 13 Feb 2020 16:22:57 +0100 Subject: [PATCH 007/124] chore: release version v0.1.1 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9150214d4..1559d01a99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ + +## [0.1.1](https://github.com/libp2p/js-libp2p-utils/compare/v0.1.0...v0.1.1) (2020-02-13) + + + # 0.1.0 (2019-09-23) From 622063163d7c82867423fb452d3e46cedbf7d614 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Sat, 15 Feb 2020 09:43:12 +0100 Subject: [PATCH 008/124] feat: stream to multiaddr connection converter (#2) --- package.json | 11 +++++-- src/stream-to-ma-conn.js | 49 +++++++++++++++++++++++++++++ test/stream-to-ma-conn.spec.js | 56 ++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 src/stream-to-ma-conn.js create mode 100644 test/stream-to-ma-conn.spec.js diff --git a/package.json b/package.json index c75337dadc..7dcd94c0d8 100644 --- a/package.json +++ b/package.json @@ -29,14 +29,19 @@ }, "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", "devDependencies": { - "aegir": "^20.3.1", + "aegir": "^20.6.0", "chai": "^4.2.0", - "dirty-chai": "^2.0.1" + "dirty-chai": "^2.0.1", + "it-pair": "^1.0.0", + "it-pipe": "^1.1.0", + "streaming-iterables": "^4.1.2" }, "dependencies": { + "abortable-iterator": "^3.0.0", + "debug": "^4.1.1", "err-code": "^2.0.0", "ip-address": "^6.1.0", - "multiaddr": "^7.1.0" + "multiaddr": "^7.3.0" }, "contributors": [ "Vasco Santos " diff --git a/src/stream-to-ma-conn.js b/src/stream-to-ma-conn.js new file mode 100644 index 0000000000..d19e96076d --- /dev/null +++ b/src/stream-to-ma-conn.js @@ -0,0 +1,49 @@ +'use strict' + +const abortable = require('abortable-iterator') +const log = require('debug')('libp2p:stream:converter') + +// Convert a duplex iterable into a MultiaddrConnection +// https://github.com/libp2p/interface-transport#multiaddrconnection +module.exports = ({ stream, remoteAddr, localAddr }, options = {}) => { + const { sink, source } = stream + const maConn = { + async sink (source) { + if (options.signal) { + source = abortable(source, options.signal) + } + + try { + await sink(source) + } catch (err) { + // If aborted we can safely ignore + if (err.type !== 'aborted') { + // If the source errored the socket will already have been destroyed by + // toIterable.duplex(). If the socket errored it will already be + // destroyed. There's nothing to do here except log the error & return. + log(err) + } + } + close() + }, + + source: options.signal ? abortable(source, options.signal) : source, + conn: stream, + localAddr, + remoteAddr, + timeline: { open: Date.now() }, + + close () { + sink([]) + close() + } + } + + function close () { + if (!maConn.timeline.close) { + maConn.timeline.close = Date.now() + } + } + + return maConn +} diff --git a/test/stream-to-ma-conn.spec.js b/test/stream-to-ma-conn.spec.js new file mode 100644 index 0000000000..9e223b5666 --- /dev/null +++ b/test/stream-to-ma-conn.spec.js @@ -0,0 +1,56 @@ +/* eslint-env mocha */ +'use strict' + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) + +const pair = require('it-pair') +const pipe = require('it-pipe') +const { collect } = require('streaming-iterables') +const multiaddr = require('multiaddr') + +const streamToMaConn = require('../src/stream-to-ma-conn') + +describe('Convert stream into a multiaddr connection', () => { + it('converts a stream and adds the provided metadata', () => { + const stream = pair() + const localAddr = multiaddr('/ip4/101.45.75.219/tcp/6000') + const remoteAddr = multiaddr('/ip4/100.46.74.201/tcp/6002') + + const maConn = streamToMaConn({ + stream, + localAddr, + remoteAddr + }) + + expect(maConn).to.exist() + expect(maConn.sink).to.exist() + expect(maConn.source).to.exist() + expect(maConn.localAddr).to.eql(localAddr) + expect(maConn.remoteAddr).to.eql(remoteAddr) + expect(maConn.timeline).to.exist() + expect(maConn.timeline.open).to.exist() + expect(maConn.timeline.close).to.not.exist() + + maConn.close() + expect(maConn.timeline.close).to.exist() + }) + + it('can stream data over the multiaddr connection', async () => { + const stream = pair() + const maConn = streamToMaConn({ stream }) + + const data = 'hey' + const streamData = await pipe( + [data], + maConn, + collect + ) + + expect(streamData).to.eql([data]) + // underlying stream end closes the connection + expect(maConn.timeline.close).to.exist() + }) +}) From e7d087947472a699433d37d449de81a49b5f3d62 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Sat, 15 Feb 2020 08:44:29 +0000 Subject: [PATCH 009/124] chore: update contributors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7dcd94c0d8..7e87d3a7e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libp2p-utils", - "version": "0.1.1", + "version": "0.1.2", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", From 1491fabc964f5729c4c7ee7965528dee2a6d745b Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Sat, 15 Feb 2020 08:44:29 +0000 Subject: [PATCH 010/124] chore: release version v0.1.2 --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1559d01a99..05c7bbaa79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ + +## [0.1.2](https://github.com/libp2p/js-libp2p-utils/compare/v0.1.1...v0.1.2) (2020-02-15) + + +### Features + +* stream to multiaddr connection converter ([#2](https://github.com/libp2p/js-libp2p-utils/issues/2)) ([6220631](https://github.com/libp2p/js-libp2p-utils/commit/6220631)) + + + ## [0.1.1](https://github.com/libp2p/js-libp2p-utils/compare/v0.1.0...v0.1.1) (2020-02-13) From c8c9c76ebf2b53b88e315fd42f2b71d803cbc98e Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 17 Feb 2020 16:18:34 -0500 Subject: [PATCH 011/124] chore(deps-dev): bump aegir from 20.6.1 to 21.0.2 (#6) Bumps [aegir](https://github.com/ipfs/aegir) from 20.6.1 to 21.0.2. - [Release notes](https://github.com/ipfs/aegir/releases) - [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md) - [Commits](https://github.com/ipfs/aegir/compare/v20.6.1...v21.0.2) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7e87d3a7e0..15d39d57e8 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ }, "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", "devDependencies": { - "aegir": "^20.6.0", + "aegir": "^21.0.2", "chai": "^4.2.0", "dirty-chai": "^2.0.1", "it-pair": "^1.0.0", From 0e7fc344ecbb2001f058bc8701810d89fbf86b6f Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 27 May 2020 19:52:33 +0200 Subject: [PATCH 012/124] chore(deps-dev): bump aegir from 21.10.2 to 22.0.0 (#7) Bumps [aegir](https://github.com/ipfs/aegir) from 21.10.2 to 22.0.0. - [Release notes](https://github.com/ipfs/aegir/releases) - [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md) - [Commits](https://github.com/ipfs/aegir/compare/v21.10.2...v22.0.0) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 15d39d57e8..048e5374d1 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ }, "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", "devDependencies": { - "aegir": "^21.0.2", + "aegir": "^22.0.0", "chai": "^4.2.0", "dirty-chai": "^2.0.1", "it-pair": "^1.0.0", From 80668fff1a037a30ace5a2427ed43d57b06df5f1 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 15 Jul 2020 11:21:34 +0200 Subject: [PATCH 013/124] feat: arrayEquals for non primitive types with equals function --- src/array-equals.js | 14 ++++++++ test/array-equals.spec.js | 76 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/array-equals.js create mode 100644 test/array-equals.spec.js diff --git a/src/array-equals.js b/src/array-equals.js new file mode 100644 index 0000000000..e293167600 --- /dev/null +++ b/src/array-equals.js @@ -0,0 +1,14 @@ +'use strict' + +/** + * Verify if two arrays of non primitive types with the "equals" function are equal. + * Compatible with multiaddr, peer-id and Buffer. + * @param {Array<*>} a + * @param {Array<*>} b + * @returns {boolean} + */ +function arrayEquals (a, b) { + return a.length === b.length && b.sort() && a.sort().every((item, index) => b[index].equals(item)) +} + +module.exports = arrayEquals diff --git a/test/array-equals.spec.js b/test/array-equals.spec.js new file mode 100644 index 0000000000..36c60ccb5a --- /dev/null +++ b/test/array-equals.spec.js @@ -0,0 +1,76 @@ +/* eslint-env mocha */ +'use strict' + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) + +const multiaddr = require('multiaddr') + +const arrayEquals = require('../src/array-equals') + +describe('non primitive array equals', () => { + it('returns true if two arrays of multiaddrs are equal', () => { + const a = [ + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/dns4/test.libp2p.io') + ] + + const b = [ + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/dns4/test.libp2p.io') + ] + + expect(arrayEquals(a, b)).to.eql(true) + }) + + it('returns true if two arrays of multiaddrs have the same content but different orders', () => { + const a = [ + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/dns4/test.libp2p.io') + ] + + const b = [ + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/dns4/test.libp2p.io') + ] + + expect(arrayEquals(a, b)).to.eql(true) + }) + + it('returns false if two arrays of multiaddrs are different', () => { + const a = [ + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/dns4/test.libp2p.io') + ] + + const b = [ + multiaddr('/ip4/127.0.0.1/tcp/8001'), + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/dns4/test.libp2p.io') + ] + + expect(arrayEquals(a, b)).to.eql(false) + }) + + it('returns false if two arrays of multiaddrs are partially equal, but different lengths', () => { + const a = [ + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/dns4/test.libp2p.io') + ] + + const b = [ + multiaddr('/ip4/127.0.0.1/tcp/8001'), + multiaddr('/dns4/test.libp2p.io') + ] + + expect(arrayEquals(a, b)).to.eql(false) + }) +}) From 673da424707f088770a79ac93b1c8a9b105741b6 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 15 Jul 2020 11:25:54 +0200 Subject: [PATCH 014/124] chore: update deps --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 048e5374d1..9e6123909e 100644 --- a/package.json +++ b/package.json @@ -29,19 +29,19 @@ }, "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", "devDependencies": { - "aegir": "^22.0.0", + "aegir": "^25.0.0", "chai": "^4.2.0", "dirty-chai": "^2.0.1", "it-pair": "^1.0.0", "it-pipe": "^1.1.0", - "streaming-iterables": "^4.1.2" + "streaming-iterables": "^5.0.2" }, "dependencies": { "abortable-iterator": "^3.0.0", "debug": "^4.1.1", - "err-code": "^2.0.0", + "err-code": "^2.0.3", "ip-address": "^6.1.0", - "multiaddr": "^7.3.0" + "multiaddr": "^7.5.0" }, "contributors": [ "Vasco Santos " From 2f81fc49149bfa069482b7d2e23f1160af892806 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 15 Jul 2020 12:22:12 +0200 Subject: [PATCH 015/124] chore: apply suggestions from code review Co-authored-by: Jacob Heun --- test/array-equals.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/array-equals.spec.js b/test/array-equals.spec.js index 36c60ccb5a..c87f6eb018 100644 --- a/test/array-equals.spec.js +++ b/test/array-equals.spec.js @@ -67,7 +67,7 @@ describe('non primitive array equals', () => { ] const b = [ - multiaddr('/ip4/127.0.0.1/tcp/8001'), + multiaddr('/ip4/127.0.0.1/tcp/8000'), multiaddr('/dns4/test.libp2p.io') ] From 141aac3a33bc4c82e2450cf8010df3b1cf514dd6 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 15 Jul 2020 12:29:21 +0200 Subject: [PATCH 016/124] chore: update contributors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9e6123909e..2191880e7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libp2p-utils", - "version": "0.1.2", + "version": "0.1.3", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", From 46d17ca1424fbbfbebf4d66aec79122a2f95f4d5 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 15 Jul 2020 12:29:21 +0200 Subject: [PATCH 017/124] chore: release version v0.1.3 --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05c7bbaa79..ec6f6c1162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ + +## [0.1.3](https://github.com/libp2p/js-libp2p-utils/compare/v0.1.2...v0.1.3) (2020-07-15) + + +### Features + +* arrayEquals for non primitive types with equals function ([80668ff](https://github.com/libp2p/js-libp2p-utils/commit/80668ff)) + + + ## [0.1.2](https://github.com/libp2p/js-libp2p-utils/compare/v0.1.1...v0.1.2) (2020-02-15) From a2ea68f31979d5bc4c2e3425ef1238dbf7d7c372 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 7 Aug 2020 16:40:19 +0100 Subject: [PATCH 018/124] chore: update deps (#9) * chore: update deps Pulls in the latest multiaddrs that replaces node Buffers with Uint8Arrays BREAKING CHANGES: - The multiaddr dep of this module uses Uint8Arrays and may not be compatible with previous versions * chore: remove gh url --- package.json | 4 +--- test/array-equals.spec.js | 6 +----- test/ip-port-to-multiaddr.spec.js | 6 +----- test/stream-to-ma-conn.spec.js | 6 +----- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 2191880e7b..383d7b2424 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,6 @@ "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", "devDependencies": { "aegir": "^25.0.0", - "chai": "^4.2.0", - "dirty-chai": "^2.0.1", "it-pair": "^1.0.0", "it-pipe": "^1.1.0", "streaming-iterables": "^5.0.2" @@ -41,7 +39,7 @@ "debug": "^4.1.1", "err-code": "^2.0.3", "ip-address": "^6.1.0", - "multiaddr": "^7.5.0" + "multiaddr": "^8.0.0" }, "contributors": [ "Vasco Santos " diff --git a/test/array-equals.spec.js b/test/array-equals.spec.js index c87f6eb018..6c83c0addb 100644 --- a/test/array-equals.spec.js +++ b/test/array-equals.spec.js @@ -1,11 +1,7 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) - +const { expect } = require('aegir/utils/chai') const multiaddr = require('multiaddr') const arrayEquals = require('../src/array-equals') diff --git a/test/ip-port-to-multiaddr.spec.js b/test/ip-port-to-multiaddr.spec.js index c634047dfe..e51aeb0309 100644 --- a/test/ip-port-to-multiaddr.spec.js +++ b/test/ip-port-to-multiaddr.spec.js @@ -1,11 +1,7 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) - +const { expect } = require('aegir/utils/chai') const toMultiaddr = require('../src/ip-port-to-multiaddr') const { Errors } = require('../src/ip-port-to-multiaddr') diff --git a/test/stream-to-ma-conn.spec.js b/test/stream-to-ma-conn.spec.js index 9e223b5666..68e4bf1ff1 100644 --- a/test/stream-to-ma-conn.spec.js +++ b/test/stream-to-ma-conn.spec.js @@ -1,11 +1,7 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) - +const { expect } = require('aegir/utils/chai') const pair = require('it-pair') const pipe = require('it-pipe') const { collect } = require('streaming-iterables') From c564ea01f9d5ab23aad0f1ee2b6cd4bbcd933718 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Fri, 7 Aug 2020 17:43:26 +0200 Subject: [PATCH 019/124] chore: update contributors --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 383d7b2424..d571b20403 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libp2p-utils", - "version": "0.1.3", + "version": "0.2.0", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", @@ -42,6 +42,7 @@ "multiaddr": "^8.0.0" }, "contributors": [ - "Vasco Santos " + "Vasco Santos ", + "Alex Potsides " ] } From 03e272cd246d023f70725acaa84d92878ebd4503 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Fri, 7 Aug 2020 17:43:27 +0200 Subject: [PATCH 020/124] chore: release version v0.2.0 --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec6f6c1162..70f06cf6e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ + +# [0.2.0](https://github.com/libp2p/js-libp2p-utils/compare/v0.1.3...v0.2.0) (2020-08-07) + + +### Chores + +* update deps ([#9](https://github.com/libp2p/js-libp2p-utils/issues/9)) ([a2ea68f](https://github.com/libp2p/js-libp2p-utils/commit/a2ea68f)) + + +### BREAKING CHANGES + +* - The multiaddr dep of this module uses Uint8Arrays and may not be + compatible with previous versions + +* chore: remove gh url + + + ## [0.1.3](https://github.com/libp2p/js-libp2p-utils/compare/v0.1.2...v0.1.3) (2020-07-15) From d7fa562d91ae480dc8f3896b8358990bf54d08a2 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 7 Oct 2020 17:02:08 +0200 Subject: [PATCH 021/124] feat: is multiaddr private and loopback (#10) --- README.md | 54 ++++++++++++++++++++++++++++ package.json | 10 +++--- src/array-equals.js | 1 + src/multiaddr/is-loopback.js | 17 +++++++++ src/multiaddr/is-private.js | 17 +++++++++ test/multiaddr/is-loopback.spec.js | 57 +++++++++++++++++++++++++++++ test/multiaddr/is-private.spec.js | 58 ++++++++++++++++++++++++++++++ 7 files changed, 210 insertions(+), 4 deletions(-) create mode 100644 src/multiaddr/is-loopback.js create mode 100644 src/multiaddr/is-private.js create mode 100644 test/multiaddr/is-loopback.spec.js create mode 100644 test/multiaddr/is-private.spec.js diff --git a/README.md b/README.md index 5553afddd1..471eaea70e 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,60 @@ const ipAndPortToMultiaddr = require('libp2p-utils/src/ip-port-to-multiaddr') const ma = ipAndPortToMultiaddr('127.0.0.1', 9000) ``` +## API + +### multiaddr `.isLoopback(ma)` + +Check if a given multiaddr is a loopback address. + +#### Parameters + +| Name | Type | Description | +|------|------|-------------| +| ma | `Multiaddr` | multiaddr to verify | + +#### Returns + +| Type | Description | +|------|-------------| +| `boolean` | returns true if multiaddr is a loopback address, false otherwise | + +#### Example + +```js +const multiaddr = require('multiaddr') +const isLoopback = require('libp2p-utils/src/multiaddr/is-loopback') + +const ma = multiaddr('/ip4/127.0.0.1/tcp/1000') +isMultiaddrLoopbackAddrs = isLoopback(ma) +``` + +### multiaddr `.isPrivate(ma)` + +Check if a given multiaddr has a private address. + +#### Parameters + +| Name | Type | Description | +|------|------|-------------| +| ma | `Multiaddr` | multiaddr to verify | + +#### Returns + +| Type | Description | +|------|-------------| +| `boolean` | returns true if multiaddr is a private address, false otherwise | + +#### Example + +```js +const multiaddr = require('multiaddr') +const isPrivate = require('libp2p-utils/src/multiaddr/is-private') + +const ma = multiaddr('/ip4/10.0.0.1/tcp/1000') +isMultiaddrPrivateAddrs = isPrivate(ma) +``` + ## Contribute Contributions welcome. Please check out [the issues](https://github.com/libp2p/js-libp2p-utils/issues). diff --git a/package.json b/package.json index d571b20403..15ad818c9a 100644 --- a/package.json +++ b/package.json @@ -29,17 +29,19 @@ }, "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", "devDependencies": { - "aegir": "^25.0.0", + "aegir": "^27.0.0", "it-pair": "^1.0.0", "it-pipe": "^1.1.0", - "streaming-iterables": "^5.0.2" + "streaming-iterables": "^5.0.3" }, "dependencies": { "abortable-iterator": "^3.0.0", - "debug": "^4.1.1", + "debug": "^4.2.0", "err-code": "^2.0.3", "ip-address": "^6.1.0", - "multiaddr": "^8.0.0" + "is-loopback-addr": "^1.0.0", + "multiaddr": "^8.0.0", + "private-ip": "^1.0.5" }, "contributors": [ "Vasco Santos ", diff --git a/src/array-equals.js b/src/array-equals.js index e293167600..4679e274ab 100644 --- a/src/array-equals.js +++ b/src/array-equals.js @@ -3,6 +3,7 @@ /** * Verify if two arrays of non primitive types with the "equals" function are equal. * Compatible with multiaddr, peer-id and Buffer. + * * @param {Array<*>} a * @param {Array<*>} b * @returns {boolean} diff --git a/src/multiaddr/is-loopback.js b/src/multiaddr/is-loopback.js new file mode 100644 index 0000000000..1c11c1ccc4 --- /dev/null +++ b/src/multiaddr/is-loopback.js @@ -0,0 +1,17 @@ +'use strict' + +const isLoopbackAddr = require('is-loopback-addr') + +/** + * Check if a given multiaddr is a loopback address. + * + * @param {Multiaddr} ma + * @returns {boolean} + */ +function isLoopback (ma) { + const { address } = ma.nodeAddress() + + return isLoopbackAddr(address) +} + +module.exports = isLoopback diff --git a/src/multiaddr/is-private.js b/src/multiaddr/is-private.js new file mode 100644 index 0000000000..69192b7c62 --- /dev/null +++ b/src/multiaddr/is-private.js @@ -0,0 +1,17 @@ +'use strict' + +const isIpPrivate = require('private-ip') + +/** + * Check if a given multiaddr has a private address. + * + * @param {Multiaddr} ma + * @returns {boolean} + */ +function isPrivate (ma) { + const { address } = ma.nodeAddress() + + return isIpPrivate(address) +} + +module.exports = isPrivate diff --git a/test/multiaddr/is-loopback.spec.js b/test/multiaddr/is-loopback.spec.js new file mode 100644 index 0000000000..2880973d28 --- /dev/null +++ b/test/multiaddr/is-loopback.spec.js @@ -0,0 +1,57 @@ +/* eslint-env mocha */ +'use strict' + +const { expect } = require('aegir/utils/chai') +const multiaddr = require('multiaddr') + +const isLoopback = require('../../src/multiaddr/is-loopback') + +describe('multiaddr isLoopback', () => { + it('identifies loopback ip4 multiaddrs', () => { + [ + multiaddr('/ip4/127.0.0.1/tcp/1000'), + multiaddr('/ip4/127.0.1.1/tcp/1000'), + multiaddr('/ip4/127.1.1.1/tcp/1000'), + multiaddr('/ip4/127.255.255.255/tcp/1000') + ].forEach(ma => { + expect(isLoopback(ma)).to.eql(true) + }) + }) + + it('identifies non loopback ip4 multiaddrs', () => { + [ + multiaddr('/ip4/101.0.26.90/tcp/1000'), + multiaddr('/ip4/10.0.0.1/tcp/1000'), + multiaddr('/ip4/192.168.0.1/tcp/1000'), + multiaddr('/ip4/172.16.0.1/tcp/1000') + ].forEach(ma => { + expect(isLoopback(ma)).to.eql(false) + }) + }) + + it('identifies loopback ip6 multiaddrs', () => { + [ + multiaddr('/ip6/::1/tcp/1000') + ].forEach(ma => { + expect(isLoopback(ma)).to.eql(true) + }) + }) + + it('identifies non loopback ip6 multiaddrs', () => { + [ + multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'), + multiaddr('/ip6/::/tcp/1000') + ].forEach(ma => { + expect(isLoopback(ma)).to.eql(false) + }) + }) + + it('identifies other multiaddrs as not loopback addresses', () => { + [ + multiaddr('/dns4/wss0.bootstrap.libp2p.io/tcp/443'), + multiaddr('/dns6/wss0.bootstrap.libp2p.io/tcp/443') + ].forEach(ma => { + expect(isLoopback(ma)).to.eql(false) + }) + }) +}) diff --git a/test/multiaddr/is-private.spec.js b/test/multiaddr/is-private.spec.js new file mode 100644 index 0000000000..aef55033df --- /dev/null +++ b/test/multiaddr/is-private.spec.js @@ -0,0 +1,58 @@ +/* eslint-env mocha */ +'use strict' + +const { expect } = require('aegir/utils/chai') +const multiaddr = require('multiaddr') + +const isPrivate = require('../../src/multiaddr/is-private') + +describe('multiaddr isPrivate', () => { + it('identifies private ip4 multiaddrs', () => { + [ + multiaddr('/ip4/127.0.0.1/tcp/1000'), + multiaddr('/ip4/10.0.0.1/tcp/1000'), + multiaddr('/ip4/192.168.0.1/tcp/1000'), + multiaddr('/ip4/172.16.0.1/tcp/1000') + ].forEach(ma => { + expect(isPrivate(ma)).to.eql(true) + }) + }) + + it('identifies public ip4 multiaddrs', () => { + [ + multiaddr('/ip4/101.0.26.90/tcp/1000'), + multiaddr('/ip4/40.1.20.9/tcp/1000'), + multiaddr('/ip4/92.168.0.1/tcp/1000'), + multiaddr('/ip4/2.16.0.1/tcp/1000') + ].forEach(ma => { + expect(isPrivate(ma)).to.eql(false) + }) + }) + + it('identifies private ip6 multiaddrs', () => { + [ + multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:7095/tcp/1000'), + multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:1/tcp/1000') + ].forEach(ma => { + expect(isPrivate(ma)).to.eql(true) + }) + }) + + it('identifies public ip6 multiaddrs', () => { + [ + multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'), + multiaddr('/ip6/2000:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000') + ].forEach(ma => { + expect(isPrivate(ma)).to.eql(false) + }) + }) + + it('identifies other multiaddrs as not private addresses', () => { + [ + multiaddr('/dns4/wss0.bootstrap.libp2p.io/tcp/443'), + multiaddr('/dns6/wss0.bootstrap.libp2p.io/tcp/443') + ].forEach(ma => { + expect(isPrivate(ma)).to.eql(false) + }) + }) +}) From 645b483cb460057d63c248eae58fdcad7b0bfb3f Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 7 Oct 2020 15:01:44 +0200 Subject: [PATCH 022/124] chore: complete docs --- README.md | 95 +++++++++++++++++++++++++++++++++++++ src/array-equals.js | 2 +- src/ip-port-to-multiaddr.js | 10 +++- src/stream-to-ma-conn.js | 17 +++++-- 4 files changed, 119 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 471eaea70e..5e2e71e84b 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,36 @@ const ma = ipAndPortToMultiaddr('127.0.0.1', 9000) ## API +### arrayEquals(a, b) + +Verify if two arrays of non primitive types with the "equals" function are equal. +Compatible with multiaddr, peer-id and others. + +#### Parameters + +| Name | Type | Description | +|------|------|-------------| +| a | `Array<*>` | First array to verify | +| b | `Array<*>` | Second array to verify | + +#### Returns + +| Type | Description | +|------|-------------| +| `boolean` | returns true if arrays are equal, false otherwise | + +#### Example + +```js +const PeerId = require('peer-id') +const arrayEquals = require('libp2p-utils/src/multiaddr/array-equals') + +const peerId1 = await PeerId.create() +const peerId2 = await PeerId.create() + +const equals = arrayEquals([peerId1], [peerId2]) +``` + ### multiaddr `.isLoopback(ma)` Check if a given multiaddr is a loopback address. @@ -92,6 +122,71 @@ const ma = multiaddr('/ip4/10.0.0.1/tcp/1000') isMultiaddrPrivateAddrs = isPrivate(ma) ``` +### ipPortToMultiaddr(ip, port) + +Transform an IP, Port pair into a multiaddr with tcp transport. + +#### Parameters + +| Name | Type | Description | +|------|------|-------------| +| ip | `string` | ip for multiaddr | +| port | `number|string` | port for multiaddr | + +#### Returns + +| Type | Description | +|------|-------------| +| `Multiaddr` | returns created multiaddr | + +#### Example + +```js +const ipPortPairToMultiaddr = require('libp2p-utils/src/multiaddr/ip-port-to-multiaddr') +const ip = '127.0.0.1' +const port = '9090' + +const ma = ipPortPairToMultiaddr(ma) +``` + +### streamToMaConnection(streamProperties, options) + +Convert a duplex stream into a [MultiaddrConnection](https://github.com/libp2p/interface-transport#multiaddrconnection). + +#### Parameters + +| Name | Type | Description | +|------|------|-------------| +| streamProperties | `object` | duplex stream properties | +| streamProperties.stream | [`DuplexStream`](https://github.com/libp2p/js-libp2p/blob/master/doc/STREAMING_ITERABLES.md#duplex) | duplex stream | +| streamProperties.remoteAddr | `Multiaddr` | stream remote address | +| streamProperties.localAddr | `Multiaddr` | stream local address | +| [options] | `object` | options | +| [options.signal] | `AbortSignal` | abort signal | + +#### Returns + +| Type | Description | +|------|-------------| +| `Connection` | returns a multiaddr [Connection](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/connection) | + +#### Example + +```js +const streamToMaConnection = require('libp2p-utils/src/stream-to-ma-conn') + +const stream = { + sink: async source => {/* ... */}, + source: { [Symbol.asyncIterator] () {/* ... */} } +} + +const conn = streamToMaConnection({ + stream, + remoteAddr: /* ... */ + localAddr; /* ... */ +}) +``` + ## Contribute Contributions welcome. Please check out [the issues](https://github.com/libp2p/js-libp2p-utils/issues). diff --git a/src/array-equals.js b/src/array-equals.js index 4679e274ab..bb9f91cc27 100644 --- a/src/array-equals.js +++ b/src/array-equals.js @@ -2,7 +2,7 @@ /** * Verify if two arrays of non primitive types with the "equals" function are equal. - * Compatible with multiaddr, peer-id and Buffer. + * Compatible with multiaddr, peer-id and others. * * @param {Array<*>} a * @param {Array<*>} b diff --git a/src/ip-port-to-multiaddr.js b/src/ip-port-to-multiaddr.js index 2d6b5eff1c..f928b60fa1 100644 --- a/src/ip-port-to-multiaddr.js +++ b/src/ip-port-to-multiaddr.js @@ -10,7 +10,13 @@ const errors = { ERR_INVALID_IP: 'ERR_INVALID_IP' } -module.exports = (ip, port) => { +/** + * Transform an IP, Port pair into a multiaddr + * + * @param {string} ip + * @param {number|string} port + */ +function ipPortToMultiaddr (ip, port) { if (typeof ip !== 'string') { throw errCode(new Error(`invalid ip provided: ${ip}`), errors.ERR_INVALID_IP_PARAMETER) } @@ -36,4 +42,6 @@ module.exports = (ip, port) => { throw errCode(new Error(`invalid ip:port for creating a multiaddr: ${ip}:${port}`), errors.ERR_INVALID_IP) } +module.exports = ipPortToMultiaddr + module.exports.Errors = errors diff --git a/src/stream-to-ma-conn.js b/src/stream-to-ma-conn.js index d19e96076d..91a3f4bbf0 100644 --- a/src/stream-to-ma-conn.js +++ b/src/stream-to-ma-conn.js @@ -3,9 +3,18 @@ const abortable = require('abortable-iterator') const log = require('debug')('libp2p:stream:converter') -// Convert a duplex iterable into a MultiaddrConnection -// https://github.com/libp2p/interface-transport#multiaddrconnection -module.exports = ({ stream, remoteAddr, localAddr }, options = {}) => { +/** + * Convert a duplex iterable into a MultiaddrConnection. + * https://github.com/libp2p/interface-transport#multiaddrconnection + * + * @param {object} streamProperties + * @param {DuplexStream} streamProperties.stream + * @param {Multiaddr} streamProperties.remoteAddr + * @param {Multiaddr} streamProperties.localAddr + * @param {object} [options] + * @param {AbortSignal} [options.signal] + */ +function streamToMaConnection ({ stream, remoteAddr, localAddr }, options = {}) { const { sink, source } = stream const maConn = { async sink (source) { @@ -47,3 +56,5 @@ module.exports = ({ stream, remoteAddr, localAddr }, options = {}) => { return maConn } + +module.exports = streamToMaConnection From b91a241d078c905cbb6f92beb9808538b3d78588 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 7 Oct 2020 18:37:24 +0200 Subject: [PATCH 023/124] chore: apply suggestions from code review Co-authored-by: Jacob Heun --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e2e71e84b..f15dd07da3 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Compatible with multiaddr, peer-id and others. ```js const PeerId = require('peer-id') -const arrayEquals = require('libp2p-utils/src/multiaddr/array-equals') +const arrayEquals = require('libp2p-utils/src/array-equals') const peerId1 = await PeerId.create() const peerId2 = await PeerId.create() From b38bf3472949e21b81230e0eedf5e0e893d7b5b3 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 7 Oct 2020 18:42:46 +0200 Subject: [PATCH 024/124] chore: create API doc --- API.md | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 149 +---------------------------------------------- 2 files changed, 170 insertions(+), 148 deletions(-) create mode 100644 API.md diff --git a/API.md b/API.md new file mode 100644 index 0000000000..0cbb4e62de --- /dev/null +++ b/API.md @@ -0,0 +1,169 @@ +# API + +* [arrayEquals(a, b)](#arrayequalsa-b) + * [Parameters](#parameters) + * [Returns](#returns) + * [Example](#example) +* [multiaddr .isLoopback(ma)](#multiaddr-isloopbackma) + * [Parameters](#parameters-1) + * [Returns](#returns-1) + * [Example](#example-1) +* [multiaddr .isPrivate(ma)](#multiaddr-isprivatema) + * [Parameters](#parameters-2) + * [Returns](#returns-2) + * [Example](#example-2) +* [ipPortToMultiaddr(ip, port)](#ipporttomultiaddrip-port) + * [Parameters](#parameters-3) + * [Returns](#returns-3) + * [Example](#example-3) +* [streamToMaConnection(streamProperties, options)](#streamtomaconnectionstreamproperties-options) + * [Parameters](#parameters-4) + * [Returns](#returns-4) + * [Example](#example-4) + +## arrayEquals(a, b) + +Verify if two arrays of non primitive types with the "equals" function are equal. +Compatible with multiaddr, peer-id and others. + +### Parameters + +| Name | Type | Description | +|------|------|-------------| +| a | `Array<*>` | First array to verify | +| b | `Array<*>` | Second array to verify | + +### Returns + +| Type | Description | +|------|-------------| +| `boolean` | returns true if arrays are equal, false otherwise | + +### Example + +```js +const PeerId = require('peer-id') +const arrayEquals = require('libp2p-utils/src/array-equals') + +const peerId1 = await PeerId.create() +const peerId2 = await PeerId.create() + +const equals = arrayEquals([peerId1], [peerId2]) +``` + +## multiaddr `.isLoopback(ma)` + +Check if a given multiaddr is a loopback address. + +### Parameters + +| Name | Type | Description | +|------|------|-------------| +| ma | `Multiaddr` | multiaddr to verify | + +### Returns + +| Type | Description | +|------|-------------| +| `boolean` | returns true if multiaddr is a loopback address, false otherwise | + +### Example + +```js +const multiaddr = require('multiaddr') +const isLoopback = require('libp2p-utils/src/multiaddr/is-loopback') + +const ma = multiaddr('/ip4/127.0.0.1/tcp/1000') +isMultiaddrLoopbackAddrs = isLoopback(ma) +``` + +## multiaddr `.isPrivate(ma)` + +Check if a given multiaddr has a private address. + +### Parameters + +| Name | Type | Description | +|------|------|-------------| +| ma | `Multiaddr` | multiaddr to verify | + +### Returns + +| Type | Description | +|------|-------------| +| `boolean` | returns true if multiaddr is a private address, false otherwise | + +### Example + +```js +const multiaddr = require('multiaddr') +const isPrivate = require('libp2p-utils/src/multiaddr/is-private') + +const ma = multiaddr('/ip4/10.0.0.1/tcp/1000') +isMultiaddrPrivateAddrs = isPrivate(ma) +``` + +## ipPortToMultiaddr(ip, port) + +Transform an IP, Port pair into a multiaddr with tcp transport. + +### Parameters + +| Name | Type | Description | +|------|------|-------------| +| ip | `string` | ip for multiaddr | +| port | `number|string` | port for multiaddr | + +### Returns + +| Type | Description | +|------|-------------| +| `Multiaddr` | returns created multiaddr | + +### Example + +```js +const ipPortPairToMultiaddr = require('libp2p-utils/src/multiaddr/ip-port-to-multiaddr') +const ip = '127.0.0.1' +const port = '9090' + +const ma = ipPortPairToMultiaddr(ma) +``` + +## streamToMaConnection(streamProperties, options) + +Convert a duplex stream into a [MultiaddrConnection](https://github.com/libp2p/interface-transport#multiaddrconnection). + +### Parameters + +| Name | Type | Description | +|------|------|-------------| +| streamProperties | `object` | duplex stream properties | +| streamProperties.stream | [`DuplexStream`](https://github.com/libp2p/js-libp2p/blob/master/doc/STREAMING_ITERABLES.md#duplex) | duplex stream | +| streamProperties.remoteAddr | `Multiaddr` | stream remote address | +| streamProperties.localAddr | `Multiaddr` | stream local address | +| [options] | `object` | options | +| [options.signal] | `AbortSignal` | abort signal | + +### Returns + +| Type | Description | +|------|-------------| +| `Connection` | returns a multiaddr [Connection](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/connection) | + +### Example + +```js +const streamToMaConnection = require('libp2p-utils/src/stream-to-ma-conn') + +const stream = { + sink: async source => {/* ... */}, + source: { [Symbol.asyncIterator] () {/* ... */} } +} + +const conn = streamToMaConnection({ + stream, + remoteAddr: /* ... */ + localAddr; /* ... */ +}) +``` diff --git a/README.md b/README.md index f15dd07da3..19197a94e0 100644 --- a/README.md +++ b/README.md @@ -38,154 +38,7 @@ const ipAndPortToMultiaddr = require('libp2p-utils/src/ip-port-to-multiaddr') const ma = ipAndPortToMultiaddr('127.0.0.1', 9000) ``` -## API - -### arrayEquals(a, b) - -Verify if two arrays of non primitive types with the "equals" function are equal. -Compatible with multiaddr, peer-id and others. - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| a | `Array<*>` | First array to verify | -| b | `Array<*>` | Second array to verify | - -#### Returns - -| Type | Description | -|------|-------------| -| `boolean` | returns true if arrays are equal, false otherwise | - -#### Example - -```js -const PeerId = require('peer-id') -const arrayEquals = require('libp2p-utils/src/array-equals') - -const peerId1 = await PeerId.create() -const peerId2 = await PeerId.create() - -const equals = arrayEquals([peerId1], [peerId2]) -``` - -### multiaddr `.isLoopback(ma)` - -Check if a given multiaddr is a loopback address. - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| ma | `Multiaddr` | multiaddr to verify | - -#### Returns - -| Type | Description | -|------|-------------| -| `boolean` | returns true if multiaddr is a loopback address, false otherwise | - -#### Example - -```js -const multiaddr = require('multiaddr') -const isLoopback = require('libp2p-utils/src/multiaddr/is-loopback') - -const ma = multiaddr('/ip4/127.0.0.1/tcp/1000') -isMultiaddrLoopbackAddrs = isLoopback(ma) -``` - -### multiaddr `.isPrivate(ma)` - -Check if a given multiaddr has a private address. - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| ma | `Multiaddr` | multiaddr to verify | - -#### Returns - -| Type | Description | -|------|-------------| -| `boolean` | returns true if multiaddr is a private address, false otherwise | - -#### Example - -```js -const multiaddr = require('multiaddr') -const isPrivate = require('libp2p-utils/src/multiaddr/is-private') - -const ma = multiaddr('/ip4/10.0.0.1/tcp/1000') -isMultiaddrPrivateAddrs = isPrivate(ma) -``` - -### ipPortToMultiaddr(ip, port) - -Transform an IP, Port pair into a multiaddr with tcp transport. - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| ip | `string` | ip for multiaddr | -| port | `number|string` | port for multiaddr | - -#### Returns - -| Type | Description | -|------|-------------| -| `Multiaddr` | returns created multiaddr | - -#### Example - -```js -const ipPortPairToMultiaddr = require('libp2p-utils/src/multiaddr/ip-port-to-multiaddr') -const ip = '127.0.0.1' -const port = '9090' - -const ma = ipPortPairToMultiaddr(ma) -``` - -### streamToMaConnection(streamProperties, options) - -Convert a duplex stream into a [MultiaddrConnection](https://github.com/libp2p/interface-transport#multiaddrconnection). - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| streamProperties | `object` | duplex stream properties | -| streamProperties.stream | [`DuplexStream`](https://github.com/libp2p/js-libp2p/blob/master/doc/STREAMING_ITERABLES.md#duplex) | duplex stream | -| streamProperties.remoteAddr | `Multiaddr` | stream remote address | -| streamProperties.localAddr | `Multiaddr` | stream local address | -| [options] | `object` | options | -| [options.signal] | `AbortSignal` | abort signal | - -#### Returns - -| Type | Description | -|------|-------------| -| `Connection` | returns a multiaddr [Connection](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/connection) | - -#### Example - -```js -const streamToMaConnection = require('libp2p-utils/src/stream-to-ma-conn') - -const stream = { - sink: async source => {/* ... */}, - source: { [Symbol.asyncIterator] () {/* ... */} } -} - -const conn = streamToMaConnection({ - stream, - remoteAddr: /* ... */ - localAddr; /* ... */ -}) -``` +You can check the [API docs](./API.md). ## Contribute From 684366b8ae672d7977d7cbd2ad33200fb9c3b610 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 8 Oct 2020 09:33:44 +0200 Subject: [PATCH 025/124] chore: update contributors --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 15ad818c9a..e28b844bdb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libp2p-utils", - "version": "0.2.0", + "version": "0.2.1", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", @@ -45,6 +45,7 @@ }, "contributors": [ "Vasco Santos ", + "Jacob Heun ", "Alex Potsides " ] } From 301c63a91ed20b0fd0d505cfe5ed807d0a184a51 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 8 Oct 2020 09:33:45 +0200 Subject: [PATCH 026/124] chore: release version v0.2.1 --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70f06cf6e9..e81b52ca17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,26 @@ + +## [0.2.1](https://github.com/libp2p/js-libp2p-utils/compare/v0.1.3...v0.2.1) (2020-10-08) + + +### Chores + +* update deps ([#9](https://github.com/libp2p/js-libp2p-utils/issues/9)) ([a2ea68f](https://github.com/libp2p/js-libp2p-utils/commit/a2ea68f)) + + +### Features + +* is multiaddr private and loopback ([#10](https://github.com/libp2p/js-libp2p-utils/issues/10)) ([d7fa562](https://github.com/libp2p/js-libp2p-utils/commit/d7fa562)) + + +### BREAKING CHANGES + +* - The multiaddr dep of this module uses Uint8Arrays and may not be + compatible with previous versions + +* chore: remove gh url + + + # [0.2.0](https://github.com/libp2p/js-libp2p-utils/compare/v0.1.3...v0.2.0) (2020-08-07) From cb5e71644bb1c09b10d51f0fe4a9dae8ecd1693b Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 16 Nov 2020 15:03:20 +0100 Subject: [PATCH 027/124] feat: address sorter (#13) --- API.md | 40 +++++++++++++++++++++++++++++ src/address-sort.js | 44 ++++++++++++++++++++++++++++++++ test/address-sort.spec.js | 53 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 src/address-sort.js create mode 100644 test/address-sort.spec.js diff --git a/API.md b/API.md index 0cbb4e62de..3dbf66d3e6 100644 --- a/API.md +++ b/API.md @@ -1,5 +1,9 @@ # API +* [addressSort.publicAddressesFirst(addresses)](#addresssortpublicaddressesfirstaddresses) + * [Parameters](#parameters) + * [Returns](#returns) + * [Example](#example) * [arrayEquals(a, b)](#arrayequalsa-b) * [Parameters](#parameters) * [Returns](#returns) @@ -21,6 +25,42 @@ * [Returns](#returns-4) * [Example](#example-4) +## addressSort.publicAddressesFirst(addresses) + +Sort given addresses by putting public addresses first. In case of equality, a certified address will come first. + +### Parameters + +| Name | Type | Description | +|------|------|-------------| +| addresses | `Array
` | Array of AddressBook addresses | + +### Returns + +| Type | Description | +|------|-------------| +| `Array
` | returns array of sorted addresses | + +### Example + +```js +const multiaddr = require('multiaddr') +const { publicAddressesFirst } = require('libp2p-utils/src/address-sort') + +const addresses = [ + { + multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4000'), + isCertified: false + }, + { + multiaddr: multiaddr('/ip4/30.0.0.1/tcp/4000'), + isCertified: false + } +] + +const sortedAddresses = publicAddressesFirst(addresses) +``` + ## arrayEquals(a, b) Verify if two arrays of non primitive types with the "equals" function are equal. diff --git a/src/address-sort.js b/src/address-sort.js new file mode 100644 index 0000000000..0a49143d0f --- /dev/null +++ b/src/address-sort.js @@ -0,0 +1,44 @@ +'use strict' + +const isPrivate = require('./multiaddr/is-private') + +/** + * Compare function for array.sort(). + * This sort aims to move the private adresses to the end of the array. + * In case of equality, a certified address will come first. + * + * @param {Address} a + * @param {Address} b + * @returns {number} + */ +function addressesPublicFirstCompareFunction (a, b) { + const isAPrivate = isPrivate(a.multiaddr) + const isBPrivate = isPrivate(b.multiaddr) + + if (isAPrivate && !isBPrivate) { + return 1 + } else if (!isAPrivate && isBPrivate) { + return -1 + } + // Check certified? + if (a.isCertified && !b.isCertified) { + return -1 + } else if (!a.isCertified && b.isCertified) { + return 1 + } + + return 0 +} + +/** + * Sort given addresses by putting public addresses first. + * In case of equality, a certified address will come first. + * + * @param {Array
} addresses + * @returns {Array
} + */ +function publicAddressesFirst (addresses) { + return [...addresses].sort(addressesPublicFirstCompareFunction) +} + +module.exports.publicAddressesFirst = publicAddressesFirst diff --git a/test/address-sort.spec.js b/test/address-sort.spec.js new file mode 100644 index 0000000000..4e8dbd7f39 --- /dev/null +++ b/test/address-sort.spec.js @@ -0,0 +1,53 @@ +'use strict' +/* eslint-env mocha */ + +const { expect } = require('aegir/utils/chai') +const multiaddr = require('multiaddr') + +const { publicAddressesFirst } = require('../src/address-sort') + +describe('address-sort', () => { + it('should sort public addresses first', () => { + const addresses = [ + { + multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4000'), + isCertified: false + }, + { + multiaddr: multiaddr('/ip4/30.0.0.1/tcp/4000'), + isCertified: false + }, + { + multiaddr: multiaddr('/ip4/31.0.0.1/tcp/4000'), + isCertified: false + } + ] + + const sortedAddresses = publicAddressesFirst(addresses) + expect(sortedAddresses[0].multiaddr.equals(multiaddr('/ip4/30.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[1].multiaddr.equals(multiaddr('/ip4/31.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[2].multiaddr.equals(multiaddr('/ip4/127.0.0.1/tcp/4000'))).to.eql(true) + }) + + it('should sort public certified addresses first', () => { + const addresses = [ + { + multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4000'), + isCertified: false + }, + { + multiaddr: multiaddr('/ip4/30.0.0.1/tcp/4000'), + isCertified: false + }, + { + multiaddr: multiaddr('/ip4/31.0.0.1/tcp/4000'), + isCertified: true + } + ] + + const sortedAddresses = publicAddressesFirst(addresses) + expect(sortedAddresses[0].multiaddr.equals(multiaddr('/ip4/31.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[1].multiaddr.equals(multiaddr('/ip4/30.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[2].multiaddr.equals(multiaddr('/ip4/127.0.0.1/tcp/4000'))).to.eql(true) + }) +}) From edbd46e25d66f877a26d1932190b6b50d154812e Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 16 Nov 2020 15:06:09 +0100 Subject: [PATCH 028/124] chore: update contributors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e28b844bdb..9b664d51c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libp2p-utils", - "version": "0.2.1", + "version": "0.2.2", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", From 584af9d7c0fa50caf3b58b1f7c37c3dc5fc7562a Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 16 Nov 2020 15:06:09 +0100 Subject: [PATCH 029/124] chore: release version v0.2.2 --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e81b52ca17..7636ff6bec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ + +## [0.2.2](https://github.com/libp2p/js-libp2p-utils/compare/v0.2.1...v0.2.2) (2020-11-16) + + +### Features + +* address sorter ([#13](https://github.com/libp2p/js-libp2p-utils/issues/13)) ([cb5e716](https://github.com/libp2p/js-libp2p-utils/commit/cb5e716)) + + + ## [0.2.1](https://github.com/libp2p/js-libp2p-utils/compare/v0.1.3...v0.2.1) (2020-10-08) From d16d9fe0a66826e543b99d3be575b270192ab2df Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 30 Nov 2020 10:35:45 +0100 Subject: [PATCH 030/124] chore: update private-ip (#15) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9b664d51c6..3d31709751 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "ip-address": "^6.1.0", "is-loopback-addr": "^1.0.0", "multiaddr": "^8.0.0", - "private-ip": "^1.0.5" + "private-ip": "^2.1.1" }, "contributors": [ "Vasco Santos ", From 6e7c7c64ce5905af2178869fb24f6cbe86c3245d Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 30 Nov 2020 11:09:49 +0100 Subject: [PATCH 031/124] chore: update contributors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3d31709751..be3f1d7c21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libp2p-utils", - "version": "0.2.2", + "version": "0.2.3", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", From 28869e6cdaf805cb1c4b9d274c1de5a936be75fd Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 30 Nov 2020 11:09:49 +0100 Subject: [PATCH 032/124] chore: release version v0.2.3 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7636ff6bec..f47e6b1d75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ + +## [0.2.3](https://github.com/libp2p/js-libp2p-utils/compare/v0.2.2...v0.2.3) (2020-11-30) + + + ## [0.2.2](https://github.com/libp2p/js-libp2p-utils/compare/v0.2.1...v0.2.2) (2020-11-16) From e0552b5b6b1d912a8f6f1e39b1a4b70fca91f547 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 8 Apr 2021 11:52:55 +0200 Subject: [PATCH 033/124] feat: add types (#16) --- .github/workflows/main.yml | 74 ++++++++++++++++++++++++++++++++++++ .travis.yml | 52 ------------------------- package.json | 29 +++++++++++--- src/address-sort.js | 10 +++++ src/ip-port-to-multiaddr.js | 26 +++++++++---- src/multiaddr/is-loopback.js | 5 +++ src/multiaddr/is-private.js | 5 +++ src/stream-to-ma-conn.js | 32 ++++++++++++---- tsconfig.json | 9 +++++ 9 files changed, 168 insertions(+), 74 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .travis.yml create mode 100644 tsconfig.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000000..25fc39581d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,74 @@ +name: ci +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: npm install + - run: npx aegir lint + - run: npx aegir ts -p check + - run: npx aegir build + - run: npx aegir dep-check + - uses: ipfs/aegir/actions/bundle-size@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + test-node: + needs: check + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + node: [14, 15] + fail-fast: true + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + - run: npm install + - run: npx nyc --reporter=lcov aegir test -t node -- --bail + - uses: codecov/codecov-action@v1 + test-chrome: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: npm install + - run: npx aegir test -t browser -t webworker --bail + test-firefox: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: npm install + - run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless + test-webkit: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: microsoft/playwright-github-action@v1 + - run: npm install + - run: npx aegir test -t browser -t webworker --bail -- --browser webkit + test-electron-main: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: npm install + - run: npx xvfb-maybe aegir test -t electron-main --bail + test-electron-renderer: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: npm install + - run: npx xvfb-maybe aegir test -t electron-renderer --bail \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index bd3dcaf568..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,52 +0,0 @@ -language: node_js -cache: npm -stages: - - check - - test - - cov - -node_js: - - '10' - - '12' - -os: - - linux - - osx - -script: npx nyc -s npm run test:node -- --bail -after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov - -jobs: - include: - - os: windows - filter_secrets: false - cache: false - - - stage: check - script: - - npx aegir commitlint --travis - - npx aegir dep-check - - npm run lint - - - stage: test - name: chrome - addons: - chrome: stable - script: npx aegir test -t browser -t webworker - - - stage: test - name: firefox - addons: - firefox: latest - script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless - - - stage: test - name: electron - services: - - xvfb - script: - - npm run test:electron - - npm run test:electron-renderer - -notifications: - email: false diff --git a/package.json b/package.json index be3f1d7c21..1d50cfa4c7 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,21 @@ "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "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", "test:browser": "aegir test -t browser", "test:node": "aegir test -t node", @@ -29,18 +43,21 @@ }, "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", "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" }, "contributors": [ diff --git a/src/address-sort.js b/src/address-sort.js index 0a49143d0f..9e9468ed42 100644 --- a/src/address-sort.js +++ b/src/address-sort.js @@ -2,6 +2,16 @@ const isPrivate = require('./multiaddr/is-private') +/** + * @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(). * This sort aims to move the private adresses to the end of the array. diff --git a/src/ip-port-to-multiaddr.js b/src/ip-port-to-multiaddr.js index f928b60fa1..dfd27f0727 100644 --- a/src/ip-port-to-multiaddr.js +++ b/src/ip-port-to-multiaddr.js @@ -1,5 +1,9 @@ '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') const errCode = require('err-code') const { Address4, Address6 } = require('ip-address') @@ -21,25 +25,31 @@ function ipPortToMultiaddr (ip, port) { throw errCode(new Error(`invalid ip provided: ${ip}`), errors.ERR_INVALID_IP_PARAMETER) } - port = parseInt(port) + if (typeof port === 'string') { + port = parseInt(port) + } if (isNaN(port)) { throw errCode(new Error(`invalid port provided: ${port}`), errors.ERR_INVALID_PORT_PARAMETER) } - 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) } module.exports = ipPortToMultiaddr diff --git a/src/multiaddr/is-loopback.js b/src/multiaddr/is-loopback.js index 1c11c1ccc4..b30b709ab4 100644 --- a/src/multiaddr/is-loopback.js +++ b/src/multiaddr/is-loopback.js @@ -1,7 +1,12 @@ '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. * diff --git a/src/multiaddr/is-private.js b/src/multiaddr/is-private.js index 69192b7c62..67e293b4dc 100644 --- a/src/multiaddr/is-private.js +++ b/src/multiaddr/is-private.js @@ -1,7 +1,12 @@ '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. * diff --git a/src/stream-to-ma-conn.js b/src/stream-to-ma-conn.js index 91a3f4bbf0..335d4619d0 100644 --- a/src/stream-to-ma-conn.js +++ b/src/stream-to-ma-conn.js @@ -1,24 +1,40 @@ '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. * https://github.com/libp2p/interface-transport#multiaddrconnection * * @param {object} streamProperties - * @param {DuplexStream} streamProperties.stream + * @param {MuxedStream} streamProperties.stream * @param {Multiaddr} streamProperties.remoteAddr * @param {Multiaddr} streamProperties.localAddr * @param {object} [options] * @param {AbortSignal} [options.signal] + * @returns {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} */ function streamToMaConnection ({ stream, remoteAddr, localAddr }, options = {}) { const { sink, source } = stream 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) } @@ -35,16 +51,15 @@ function streamToMaConnection ({ stream, remoteAddr, localAddr }, options = {}) } close() }, - source: options.signal ? abortable(source, options.signal) : source, conn: stream, localAddr, remoteAddr, - timeline: { open: Date.now() }, - + /** @type {Timeline} */ + timeline: { open: Date.now(), close: undefined }, close () { - sink([]) - close() + sink(new Uint8Array(0)) + return close() } } @@ -52,6 +67,7 @@ function streamToMaConnection ({ stream, remoteAddr, localAddr }, options = {}) if (!maConn.timeline.close) { maConn.timeline.close = Date.now() } + return Promise.resolve() } return maConn diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000..5fe8ea40d7 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "src" + ] +} From c206807805c89a3b1fd4bf22b95e820948e3bd04 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 8 Apr 2021 11:55:52 +0200 Subject: [PATCH 034/124] chore: update contributors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1d50cfa4c7..bb13a1390b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "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 ", "main": "src/index.js", From 4326d714d9e8d0cca338c9e6d05031a8177d400b Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 8 Apr 2021 11:55:53 +0200 Subject: [PATCH 035/124] chore: release version v0.3.0 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f47e6b1d75..f7134a85ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# [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)) + + + ## [0.2.3](https://github.com/libp2p/js-libp2p-utils/compare/v0.2.2...v0.2.3) (2020-11-30) From 220fcaaaa367e665c78cd2669824767e13bc3ec1 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 12 Apr 2021 12:54:48 +0200 Subject: [PATCH 036/124] chore: update multiaddr to 9 (#17) * chore: update multiaddr to 9 * chore: update interfaces --- package.json | 6 ++-- src/address-sort.js | 2 +- src/ip-port-to-multiaddr.js | 8 ++--- src/multiaddr/is-loopback.js | 2 +- src/multiaddr/is-private.js | 2 +- src/stream-to-ma-conn.js | 2 +- test/address-sort.spec.js | 26 ++++++++-------- test/array-equals.spec.js | 48 +++++++++++++++--------------- test/multiaddr/is-loopback.spec.js | 28 ++++++++--------- test/multiaddr/is-private.spec.js | 30 +++++++++---------- test/stream-to-ma-conn.spec.js | 6 ++-- 11 files changed, 80 insertions(+), 80 deletions(-) diff --git a/package.json b/package.json index bb13a1390b..c9168c0b45 100644 --- a/package.json +++ b/package.json @@ -44,10 +44,10 @@ "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", "devDependencies": { "@types/debug": "^4.1.5", - "aegir": "^32.1.0", + "aegir": "^33.0.0", "it-pair": "^1.0.0", "it-pipe": "^1.1.0", - "libp2p-interfaces": "^0.9.0", + "libp2p-interfaces": "^0.10.0", "streaming-iterables": "^5.0.3", "util": "^0.12.3" }, @@ -57,7 +57,7 @@ "err-code": "^3.0.1", "ip-address": "^7.1.0", "is-loopback-addr": "^1.0.0", - "multiaddr": "^8.1.2", + "multiaddr": "^9.0.1", "private-ip": "^2.1.1" }, "contributors": [ diff --git a/src/address-sort.js b/src/address-sort.js index 9e9468ed42..2e54de864b 100644 --- a/src/address-sort.js +++ b/src/address-sort.js @@ -3,7 +3,7 @@ const isPrivate = require('./multiaddr/is-private') /** - * @typedef {import('multiaddr')} Multiaddr + * @typedef {import('multiaddr').Multiaddr} Multiaddr */ /** diff --git a/src/ip-port-to-multiaddr.js b/src/ip-port-to-multiaddr.js index dfd27f0727..00b9f920d2 100644 --- a/src/ip-port-to-multiaddr.js +++ b/src/ip-port-to-multiaddr.js @@ -4,7 +4,7 @@ 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') +const { Multiaddr } = require('multiaddr') const errCode = require('err-code') const { Address4, Address6 } = require('ip-address') @@ -36,15 +36,15 @@ function ipPortToMultiaddr (ip, port) { try { // Test valid IPv4 new Address4(ip) // eslint-disable-line no-new - return multiaddr(`/ip4/${ip}/tcp/${port}`) + return new Multiaddr(`/ip4/${ip}/tcp/${port}`) } catch {} try { // Test valid IPv6 const ip6 = new Address6(ip) return ip6.is4() - ? multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`) - : multiaddr(`/ip6/${ip}/tcp/${port}`) + ? new Multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`) + : new Multiaddr(`/ip6/${ip}/tcp/${port}`) } catch (err) { const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}` log.error(errMsg) diff --git a/src/multiaddr/is-loopback.js b/src/multiaddr/is-loopback.js index b30b709ab4..dd29c3daa7 100644 --- a/src/multiaddr/is-loopback.js +++ b/src/multiaddr/is-loopback.js @@ -4,7 +4,7 @@ const isLoopbackAddr = require('is-loopback-addr') /** - * @typedef {import('multiaddr')} Multiaddr + * @typedef {import('multiaddr').Multiaddr} Multiaddr */ /** diff --git a/src/multiaddr/is-private.js b/src/multiaddr/is-private.js index 67e293b4dc..efe6b2f17b 100644 --- a/src/multiaddr/is-private.js +++ b/src/multiaddr/is-private.js @@ -4,7 +4,7 @@ const isIpPrivate = require('private-ip') /** - * @typedef {import('multiaddr')} Multiaddr + * @typedef {import('multiaddr').Multiaddr} Multiaddr */ /** diff --git a/src/stream-to-ma-conn.js b/src/stream-to-ma-conn.js index 335d4619d0..eb9c0ab0b9 100644 --- a/src/stream-to-ma-conn.js +++ b/src/stream-to-ma-conn.js @@ -5,7 +5,7 @@ const debug = require('debug') const log = debug('libp2p:stream:converter') /** - * @typedef {import('multiaddr')} Multiaddr + * @typedef {import('multiaddr').Multiaddr} Multiaddr * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream * * @typedef {Object} Timeline diff --git a/test/address-sort.spec.js b/test/address-sort.spec.js index 4e8dbd7f39..4f1780e3bf 100644 --- a/test/address-sort.spec.js +++ b/test/address-sort.spec.js @@ -2,7 +2,7 @@ /* eslint-env mocha */ const { expect } = require('aegir/utils/chai') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const { publicAddressesFirst } = require('../src/address-sort') @@ -10,44 +10,44 @@ describe('address-sort', () => { it('should sort public addresses first', () => { const addresses = [ { - multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4000'), + multiaddr: new Multiaddr('/ip4/127.0.0.1/tcp/4000'), isCertified: false }, { - multiaddr: multiaddr('/ip4/30.0.0.1/tcp/4000'), + multiaddr: new Multiaddr('/ip4/30.0.0.1/tcp/4000'), isCertified: false }, { - multiaddr: multiaddr('/ip4/31.0.0.1/tcp/4000'), + multiaddr: new Multiaddr('/ip4/31.0.0.1/tcp/4000'), isCertified: false } ] const sortedAddresses = publicAddressesFirst(addresses) - expect(sortedAddresses[0].multiaddr.equals(multiaddr('/ip4/30.0.0.1/tcp/4000'))).to.eql(true) - expect(sortedAddresses[1].multiaddr.equals(multiaddr('/ip4/31.0.0.1/tcp/4000'))).to.eql(true) - expect(sortedAddresses[2].multiaddr.equals(multiaddr('/ip4/127.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[0].multiaddr.equals(new Multiaddr('/ip4/30.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[1].multiaddr.equals(new Multiaddr('/ip4/31.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[2].multiaddr.equals(new Multiaddr('/ip4/127.0.0.1/tcp/4000'))).to.eql(true) }) it('should sort public certified addresses first', () => { const addresses = [ { - multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4000'), + multiaddr: new Multiaddr('/ip4/127.0.0.1/tcp/4000'), isCertified: false }, { - multiaddr: multiaddr('/ip4/30.0.0.1/tcp/4000'), + multiaddr: new Multiaddr('/ip4/30.0.0.1/tcp/4000'), isCertified: false }, { - multiaddr: multiaddr('/ip4/31.0.0.1/tcp/4000'), + multiaddr: new Multiaddr('/ip4/31.0.0.1/tcp/4000'), isCertified: true } ] const sortedAddresses = publicAddressesFirst(addresses) - expect(sortedAddresses[0].multiaddr.equals(multiaddr('/ip4/31.0.0.1/tcp/4000'))).to.eql(true) - expect(sortedAddresses[1].multiaddr.equals(multiaddr('/ip4/30.0.0.1/tcp/4000'))).to.eql(true) - expect(sortedAddresses[2].multiaddr.equals(multiaddr('/ip4/127.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[0].multiaddr.equals(new Multiaddr('/ip4/31.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[1].multiaddr.equals(new Multiaddr('/ip4/30.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[2].multiaddr.equals(new Multiaddr('/ip4/127.0.0.1/tcp/4000'))).to.eql(true) }) }) diff --git a/test/array-equals.spec.js b/test/array-equals.spec.js index 6c83c0addb..bb70cba39f 100644 --- a/test/array-equals.spec.js +++ b/test/array-equals.spec.js @@ -2,22 +2,22 @@ 'use strict' const { expect } = require('aegir/utils/chai') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const arrayEquals = require('../src/array-equals') describe('non primitive array equals', () => { it('returns true if two arrays of multiaddrs are equal', () => { const a = [ - multiaddr('/ip4/127.0.0.1/tcp/8000'), - multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - multiaddr('/dns4/test.libp2p.io') + new Multiaddr('/ip4/127.0.0.1/tcp/8000'), + new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + new Multiaddr('/dns4/test.libp2p.io') ] const b = [ - multiaddr('/ip4/127.0.0.1/tcp/8000'), - multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - multiaddr('/dns4/test.libp2p.io') + new Multiaddr('/ip4/127.0.0.1/tcp/8000'), + new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + new Multiaddr('/dns4/test.libp2p.io') ] expect(arrayEquals(a, b)).to.eql(true) @@ -25,15 +25,15 @@ describe('non primitive array equals', () => { it('returns true if two arrays of multiaddrs have the same content but different orders', () => { const a = [ - multiaddr('/ip4/127.0.0.1/tcp/8000'), - multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - multiaddr('/dns4/test.libp2p.io') + new Multiaddr('/ip4/127.0.0.1/tcp/8000'), + new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + new Multiaddr('/dns4/test.libp2p.io') ] const b = [ - multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - multiaddr('/ip4/127.0.0.1/tcp/8000'), - multiaddr('/dns4/test.libp2p.io') + new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + new Multiaddr('/ip4/127.0.0.1/tcp/8000'), + new Multiaddr('/dns4/test.libp2p.io') ] expect(arrayEquals(a, b)).to.eql(true) @@ -41,15 +41,15 @@ describe('non primitive array equals', () => { it('returns false if two arrays of multiaddrs are different', () => { const a = [ - multiaddr('/ip4/127.0.0.1/tcp/8000'), - multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - multiaddr('/dns4/test.libp2p.io') + new Multiaddr('/ip4/127.0.0.1/tcp/8000'), + new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + new Multiaddr('/dns4/test.libp2p.io') ] const b = [ - multiaddr('/ip4/127.0.0.1/tcp/8001'), - multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - multiaddr('/dns4/test.libp2p.io') + new Multiaddr('/ip4/127.0.0.1/tcp/8001'), + new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + new Multiaddr('/dns4/test.libp2p.io') ] expect(arrayEquals(a, b)).to.eql(false) @@ -57,14 +57,14 @@ describe('non primitive array equals', () => { it('returns false if two arrays of multiaddrs are partially equal, but different lengths', () => { const a = [ - multiaddr('/ip4/127.0.0.1/tcp/8000'), - multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - multiaddr('/dns4/test.libp2p.io') + new Multiaddr('/ip4/127.0.0.1/tcp/8000'), + new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + new Multiaddr('/dns4/test.libp2p.io') ] const b = [ - multiaddr('/ip4/127.0.0.1/tcp/8000'), - multiaddr('/dns4/test.libp2p.io') + new Multiaddr('/ip4/127.0.0.1/tcp/8000'), + new Multiaddr('/dns4/test.libp2p.io') ] expect(arrayEquals(a, b)).to.eql(false) diff --git a/test/multiaddr/is-loopback.spec.js b/test/multiaddr/is-loopback.spec.js index 2880973d28..9c591573da 100644 --- a/test/multiaddr/is-loopback.spec.js +++ b/test/multiaddr/is-loopback.spec.js @@ -2,17 +2,17 @@ 'use strict' const { expect } = require('aegir/utils/chai') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const isLoopback = require('../../src/multiaddr/is-loopback') describe('multiaddr isLoopback', () => { it('identifies loopback ip4 multiaddrs', () => { [ - multiaddr('/ip4/127.0.0.1/tcp/1000'), - multiaddr('/ip4/127.0.1.1/tcp/1000'), - multiaddr('/ip4/127.1.1.1/tcp/1000'), - multiaddr('/ip4/127.255.255.255/tcp/1000') + new Multiaddr('/ip4/127.0.0.1/tcp/1000'), + new Multiaddr('/ip4/127.0.1.1/tcp/1000'), + new Multiaddr('/ip4/127.1.1.1/tcp/1000'), + new Multiaddr('/ip4/127.255.255.255/tcp/1000') ].forEach(ma => { expect(isLoopback(ma)).to.eql(true) }) @@ -20,10 +20,10 @@ describe('multiaddr isLoopback', () => { it('identifies non loopback ip4 multiaddrs', () => { [ - multiaddr('/ip4/101.0.26.90/tcp/1000'), - multiaddr('/ip4/10.0.0.1/tcp/1000'), - multiaddr('/ip4/192.168.0.1/tcp/1000'), - multiaddr('/ip4/172.16.0.1/tcp/1000') + new Multiaddr('/ip4/101.0.26.90/tcp/1000'), + new Multiaddr('/ip4/10.0.0.1/tcp/1000'), + new Multiaddr('/ip4/192.168.0.1/tcp/1000'), + new Multiaddr('/ip4/172.16.0.1/tcp/1000') ].forEach(ma => { expect(isLoopback(ma)).to.eql(false) }) @@ -31,7 +31,7 @@ describe('multiaddr isLoopback', () => { it('identifies loopback ip6 multiaddrs', () => { [ - multiaddr('/ip6/::1/tcp/1000') + new Multiaddr('/ip6/::1/tcp/1000') ].forEach(ma => { expect(isLoopback(ma)).to.eql(true) }) @@ -39,8 +39,8 @@ describe('multiaddr isLoopback', () => { it('identifies non loopback ip6 multiaddrs', () => { [ - multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'), - multiaddr('/ip6/::/tcp/1000') + new Multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'), + new Multiaddr('/ip6/::/tcp/1000') ].forEach(ma => { expect(isLoopback(ma)).to.eql(false) }) @@ -48,8 +48,8 @@ describe('multiaddr isLoopback', () => { it('identifies other multiaddrs as not loopback addresses', () => { [ - multiaddr('/dns4/wss0.bootstrap.libp2p.io/tcp/443'), - multiaddr('/dns6/wss0.bootstrap.libp2p.io/tcp/443') + new Multiaddr('/dns4/wss0.bootstrap.libp2p.io/tcp/443'), + new Multiaddr('/dns6/wss0.bootstrap.libp2p.io/tcp/443') ].forEach(ma => { expect(isLoopback(ma)).to.eql(false) }) diff --git a/test/multiaddr/is-private.spec.js b/test/multiaddr/is-private.spec.js index aef55033df..0c9418bb1f 100644 --- a/test/multiaddr/is-private.spec.js +++ b/test/multiaddr/is-private.spec.js @@ -2,17 +2,17 @@ 'use strict' const { expect } = require('aegir/utils/chai') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const isPrivate = require('../../src/multiaddr/is-private') describe('multiaddr isPrivate', () => { it('identifies private ip4 multiaddrs', () => { [ - multiaddr('/ip4/127.0.0.1/tcp/1000'), - multiaddr('/ip4/10.0.0.1/tcp/1000'), - multiaddr('/ip4/192.168.0.1/tcp/1000'), - multiaddr('/ip4/172.16.0.1/tcp/1000') + new Multiaddr('/ip4/127.0.0.1/tcp/1000'), + new Multiaddr('/ip4/10.0.0.1/tcp/1000'), + new Multiaddr('/ip4/192.168.0.1/tcp/1000'), + new Multiaddr('/ip4/172.16.0.1/tcp/1000') ].forEach(ma => { expect(isPrivate(ma)).to.eql(true) }) @@ -20,10 +20,10 @@ describe('multiaddr isPrivate', () => { it('identifies public ip4 multiaddrs', () => { [ - multiaddr('/ip4/101.0.26.90/tcp/1000'), - multiaddr('/ip4/40.1.20.9/tcp/1000'), - multiaddr('/ip4/92.168.0.1/tcp/1000'), - multiaddr('/ip4/2.16.0.1/tcp/1000') + new Multiaddr('/ip4/101.0.26.90/tcp/1000'), + new Multiaddr('/ip4/40.1.20.9/tcp/1000'), + new Multiaddr('/ip4/92.168.0.1/tcp/1000'), + new Multiaddr('/ip4/2.16.0.1/tcp/1000') ].forEach(ma => { expect(isPrivate(ma)).to.eql(false) }) @@ -31,8 +31,8 @@ describe('multiaddr isPrivate', () => { it('identifies private ip6 multiaddrs', () => { [ - multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:7095/tcp/1000'), - multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:1/tcp/1000') + new Multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:7095/tcp/1000'), + new Multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:1/tcp/1000') ].forEach(ma => { expect(isPrivate(ma)).to.eql(true) }) @@ -40,8 +40,8 @@ describe('multiaddr isPrivate', () => { it('identifies public ip6 multiaddrs', () => { [ - multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'), - multiaddr('/ip6/2000:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000') + new Multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'), + new Multiaddr('/ip6/2000:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000') ].forEach(ma => { expect(isPrivate(ma)).to.eql(false) }) @@ -49,8 +49,8 @@ describe('multiaddr isPrivate', () => { it('identifies other multiaddrs as not private addresses', () => { [ - multiaddr('/dns4/wss0.bootstrap.libp2p.io/tcp/443'), - multiaddr('/dns6/wss0.bootstrap.libp2p.io/tcp/443') + new Multiaddr('/dns4/wss0.bootstrap.libp2p.io/tcp/443'), + new Multiaddr('/dns6/wss0.bootstrap.libp2p.io/tcp/443') ].forEach(ma => { expect(isPrivate(ma)).to.eql(false) }) diff --git a/test/stream-to-ma-conn.spec.js b/test/stream-to-ma-conn.spec.js index 68e4bf1ff1..e7d322a792 100644 --- a/test/stream-to-ma-conn.spec.js +++ b/test/stream-to-ma-conn.spec.js @@ -5,15 +5,15 @@ const { expect } = require('aegir/utils/chai') const pair = require('it-pair') const pipe = require('it-pipe') const { collect } = require('streaming-iterables') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const streamToMaConn = require('../src/stream-to-ma-conn') describe('Convert stream into a multiaddr connection', () => { it('converts a stream and adds the provided metadata', () => { const stream = pair() - const localAddr = multiaddr('/ip4/101.45.75.219/tcp/6000') - const remoteAddr = multiaddr('/ip4/100.46.74.201/tcp/6002') + const localAddr = new Multiaddr('/ip4/101.45.75.219/tcp/6000') + const remoteAddr = new Multiaddr('/ip4/100.46.74.201/tcp/6002') const maConn = streamToMaConn({ stream, From 386ffa98610084966b9222433200c42283f23c2c Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 12 Apr 2021 12:58:48 +0200 Subject: [PATCH 037/124] chore: update contributors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c9168c0b45..f2bce0b292 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libp2p-utils", - "version": "0.3.0", + "version": "0.3.1", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", From ee22150536b2a7baed3d1c9a5f9b47ee42b492a6 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 12 Apr 2021 12:58:48 +0200 Subject: [PATCH 038/124] chore: release version v0.3.1 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7134a85ed..7989a69ac5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.3.1](https://github.com/libp2p/js-libp2p-utils/compare/v0.3.0...v0.3.1) (2021-04-12) + + + # [0.3.0](https://github.com/libp2p/js-libp2p-utils/compare/v0.2.3...v0.3.0) (2021-04-08) From 24ca72c95bf485af513fba59830796a5fcf71437 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 7 Jul 2021 07:41:06 +0100 Subject: [PATCH 039/124] chore: update to new multiformats (#18) * chore: update to new multiformats BREAKING CHANGE: updates multiaddr which uses the new CID class --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f2bce0b292..4738b3311d 100644 --- a/package.json +++ b/package.json @@ -47,17 +47,17 @@ "aegir": "^33.0.0", "it-pair": "^1.0.0", "it-pipe": "^1.1.0", - "libp2p-interfaces": "^0.10.0", - "streaming-iterables": "^5.0.3", + "libp2p-interfaces": "^0.12.0", + "streaming-iterables": "^6.0.0", "util": "^0.12.3" }, "dependencies": { "abortable-iterator": "^3.0.0", "debug": "^4.3.0", "err-code": "^3.0.1", - "ip-address": "^7.1.0", + "ip-address": "^8.0.0", "is-loopback-addr": "^1.0.0", - "multiaddr": "^9.0.1", + "multiaddr": "^10.0.0", "private-ip": "^2.1.1" }, "contributors": [ From 8bdd201db2a5dabe0a4adffee4968d28b66c48cb Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 7 Jul 2021 08:45:23 +0200 Subject: [PATCH 040/124] chore: update contributors --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 4738b3311d..3a6bd8e2c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libp2p-utils", - "version": "0.3.1", + "version": "0.4.0", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", @@ -62,7 +62,7 @@ }, "contributors": [ "Vasco Santos ", - "Jacob Heun ", - "Alex Potsides " + "Alex Potsides ", + "Jacob Heun " ] } From db27efa8248bfd65977097ced4e167c2d1399d9f Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 7 Jul 2021 08:45:24 +0200 Subject: [PATCH 041/124] chore: release version v0.4.0 --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7989a69ac5..3b1ba9d1b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +# [0.4.0](https://github.com/libp2p/js-libp2p-utils/compare/v0.3.1...v0.4.0) (2021-07-07) + + +### chore + +* update to new multiformats ([#18](https://github.com/libp2p/js-libp2p-utils/issues/18)) ([24ca72c](https://github.com/libp2p/js-libp2p-utils/commit/24ca72c95bf485af513fba59830796a5fcf71437)) + + +### BREAKING CHANGES + +* updates multiaddr which uses the new CID class + + + ## [0.3.1](https://github.com/libp2p/js-libp2p-utils/compare/v0.3.0...v0.3.1) (2021-04-12) From 08659ead7def049467f0a606e20f11a2f0798900 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Thu, 8 Jul 2021 13:33:30 +0100 Subject: [PATCH 042/124] chore: upgrade libp2p-interfaces (#19) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3a6bd8e2c0..4f5af3f306 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "aegir": "^33.0.0", "it-pair": "^1.0.0", "it-pipe": "^1.1.0", - "libp2p-interfaces": "^0.12.0", + "libp2p-interfaces": "^1.0.0", "streaming-iterables": "^6.0.0", "util": "^0.12.3" }, From ca2ca5a1853b8c49efaae593ef43501c9e19fd9e Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 8 Jul 2021 14:38:26 +0200 Subject: [PATCH 043/124] chore: update contributors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4f5af3f306..7cb0c7a8e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libp2p-utils", - "version": "0.4.0", + "version": "0.4.1", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", From 3730ffbb6eb64237391a4f312060d9ff37ed540f Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 8 Jul 2021 14:38:26 +0200 Subject: [PATCH 044/124] chore: release version v0.4.1 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b1ba9d1b2..1114cbe56e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.4.1](https://github.com/libp2p/js-libp2p-utils/compare/v0.4.0...v0.4.1) (2021-07-08) + + + # [0.4.0](https://github.com/libp2p/js-libp2p-utils/compare/v0.3.1...v0.4.0) (2021-07-07) From bd0080cd615fc547d292b0362436045f50127b84 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 5 Jan 2022 20:16:29 +0100 Subject: [PATCH 045/124] feat(!): convert to typescript (#20) Converts this module to typescript Track: https://github.com/libp2p/js-libp2p/issues/1021 BREAKING CHANGE: No more default exports, no more CJS --- .github/workflows/main.yml | 99 ++++++++++++++----- LICENSE | 23 +---- LICENSE-APACHE | 5 + LICENSE-MIT | 19 ++++ README.md | 6 +- package.json | 67 ++++++++----- src/{address-sort.js => address-sort.ts} | 21 ++-- src/array-equals.js | 15 --- src/array-equals.ts | 8 ++ src/index.js | 0 ...o-multiaddr.js => ip-port-to-multiaddr.ts} | 26 ++--- src/multiaddr/is-loopback.js | 22 ----- src/multiaddr/is-loopback.ts | 12 +++ src/multiaddr/is-private.js | 22 ----- src/multiaddr/is-private.ts | 11 +++ src/stream-to-ma-conn.js | 76 -------------- src/stream-to-ma-conn.ts | 92 +++++++++++++++++ ...ress-sort.spec.js => address-sort.spec.ts} | 8 +- ...ay-equals.spec.js => array-equals.spec.ts} | 8 +- test/ip-port-to-multiaddr.spec.js | 48 --------- test/ip-port-to-multiaddr.spec.ts | 47 +++++++++ ...s-loopback.spec.js => is-loopback.spec.ts} | 8 +- ...{is-private.spec.js => is-private.spec.ts} | 10 +- ...conn.spec.js => stream-to-ma-conn.spec.ts} | 32 +++--- tsconfig.json | 7 +- 25 files changed, 372 insertions(+), 320 deletions(-) create mode 100644 LICENSE-APACHE create mode 100644 LICENSE-MIT rename src/{address-sort.js => address-sort.ts} (72%) delete mode 100644 src/array-equals.js create mode 100644 src/array-equals.ts delete mode 100644 src/index.js rename src/{ip-port-to-multiaddr.js => ip-port-to-multiaddr.ts} (62%) delete mode 100644 src/multiaddr/is-loopback.js create mode 100644 src/multiaddr/is-loopback.ts delete mode 100644 src/multiaddr/is-private.js create mode 100644 src/multiaddr/is-private.ts delete mode 100644 src/stream-to-ma-conn.js create mode 100644 src/stream-to-ma-conn.ts rename test/{address-sort.spec.js => address-sort.spec.ts} (90%) rename test/{array-equals.spec.js => array-equals.spec.ts} (92%) delete mode 100644 test/ip-port-to-multiaddr.spec.js create mode 100644 test/ip-port-to-multiaddr.spec.ts rename test/multiaddr/{is-loopback.spec.js => is-loopback.spec.ts} (89%) rename test/multiaddr/{is-private.spec.js => is-private.spec.ts} (86%) rename test/{stream-to-ma-conn.spec.js => stream-to-ma-conn.spec.ts} (57%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 25fc39581d..c9772b6fca 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: ci +name: test & maybe release on: push: branches: @@ -8,67 +8,118 @@ on: - master jobs: + check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: npm install - - run: npx aegir lint - - run: npx aegir ts -p check - - run: npx aegir build - - run: npx aegir dep-check - - uses: ipfs/aegir/actions/bundle-size@master + - uses: actions/setup-node@v2 with: - github_token: ${{ secrets.GITHUB_TOKEN }} + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present lint + - run: npm run --if-present dep-check + test-node: needs: check runs-on: ${{ matrix.os }} strategy: matrix: os: [windows-latest, ubuntu-latest, macos-latest] - node: [14, 15] + node: [16] fail-fast: true steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} - - run: npm install - - run: npx nyc --reporter=lcov aegir test -t node -- --bail + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:node - uses: codecov/codecov-action@v1 + test-chrome: needs: check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: npm install - - run: npx aegir test -t browser -t webworker --bail + - uses: actions/setup-node@v2 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:chrome + + test-chrome-webworker: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:chrome-webworker + test-firefox: needs: check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: npm install - - run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless - test-webkit: + - uses: actions/setup-node@v2 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:firefox + + test-firefox-webworker: needs: check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: microsoft/playwright-github-action@v1 - - run: npm install - - run: npx aegir test -t browser -t webworker --bail -- --browser webkit + - uses: actions/setup-node@v2 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:firefox-webworker + test-electron-main: needs: check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: npm install - - run: npx xvfb-maybe aegir test -t electron-main --bail + - uses: actions/setup-node@v2 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npx xvfb-maybe npm run --if-present test:electron-main + test-electron-renderer: needs: check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: npm install - - run: npx xvfb-maybe aegir test -t electron-renderer --bail \ No newline at end of file + - uses: actions/setup-node@v2 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npx xvfb-maybe npm run --if-present test:electron-renderer + + release: + needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer] + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + steps: + - uses: actions/checkout@v2.4.0 + with: + fetch-depth: 0 + - uses: actions/setup-node@v2 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - uses: ipfs/aegir/actions/docker-login@master + with: + docker-token: ${{ secrets.DOCKER_USERNAME }} + docker-username: ${{ secrets.DOCKER_USERNAME }} + - run: npm run --if-present release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/LICENSE b/LICENSE index 60d500031f..b0b237faab 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,2 @@ -The MIT License (MIT) - -Copyright (c) IPFS - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT: https://www.opensource.org/licenses/mit +Apache-2.0: https://www.apache.org/licenses/license-2.0 \ No newline at end of file diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000000..14478a3b60 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000000..749aa1ecd9 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 19197a94e0..564fa57573 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ > This package serves as a central repository for shared logic and dependencies for all libp2p packages, using `libp2p-utils` helps to easily re-use small scoped blocks of logic across all libp2p modules and also as a dependency proxy (think `aegir` for domain logic dependencies). -The libp2p ecosystem has lots of repos with it comes several problems like: +The libp2p ecosystem has lots of repos with it comes several problems like: - Domain logic dedupe - all modules shared a lot of logic like validation, streams handling, etc. - Dependencies management - it's really easy with so many repos for dependencies to go out of control, they become outdated, different repos use different modules to do the same thing (like merging defaults options), browser bundles ends up with multiple versions of the same package, bumping versions is cumbersome to do because we need to go through several repos, etc. @@ -26,14 +26,14 @@ These problems are the motivation for this package, having shared logic in this ```bash -$ npm install --save libp2p-utils +$ npm install --save @libp2p/utils ``` ## Usage Each function should be imported directly. ```js -const ipAndPortToMultiaddr = require('libp2p-utils/src/ip-port-to-multiaddr') +import ipAndPortToMultiaddr from '@libp2p/utils/ip-port-to-multiaddr' const ma = ipAndPortToMultiaddr('127.0.0.1', 9000) ``` diff --git a/package.json b/package.json index 7cb0c7a8e0..397aad9998 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,35 @@ { - "name": "libp2p-utils", + "name": "@libp2p/utils", "version": "0.4.1", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", - "main": "src/index.js", - "types": "dist/src/index.d.ts", + "type": "module", + "exports": { + "multiaddr/is-loopback": { + "import": "./dist/src/multiaddr/is-loopback.js", + "types": "./dist/src/multiaddr/is-loopback.d.ts" + }, + "multiaddr/is-private": { + "import": "./dist/src/multiaddr/is-private.js", + "types": "./dist/src/multiaddr/is-private.d.ts" + }, + "address-sort": { + "import": "./dist/src/address-sort.js", + "types": "./dist/src/address-sort.d.ts" + }, + "array-equals": { + "import": "./dist/src/array-equals.js", + "types": "./dist/src/array-equals.d.ts" + }, + "ip-port-to-multiaddr": { + "import": "./dist/src/ip-port-to-multiaddr.js", + "types": "./dist/src/ip-port-to-multiaddr.d.ts" + }, + "stream-to-ma-conn": { + "import": "./dist/src/stream-to-ma-connr.js", + "types": "./dist/src/stream-to-ma-connr.d.ts" + } + }, "typesVersions": { "*": { "src/*": [ @@ -15,49 +40,47 @@ }, "files": [ "src", - "dist" + "dist/src" ], "scripts": { - "prepare": "aegir build --no-bundle", - "test": "aegir test", - "test:browser": "aegir test -t browser", - "test:node": "aegir test -t node", - "test:electron": "aegir test -t electron-main", - "test:electron-renderer": "aegir test -t electron-renderer", "lint": "aegir lint", - "release": "aegir release --docs", - "release-minor": "aegir release --target node --type minor --docs", - "release-major": "aegir release --type major --docs", - "build": "aegir build" + "dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js", + "build": "tsc", + "pretest": "npm run build", + "test": "aegir test -f ./dist/test/**/*.js", + "test:chrome": "npm run test -- -t browser", + "test:chrome-webworker": "npm run test -- -t webworker", + "test:firefox": "npm run test -- -t browser -- --browser firefox", + "test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox", + "test:node": "npm run test -- -t node --cov", + "test:electron-main": "npm run test -- -t electron-main", + "release": "semantic-release" }, - "pre-push": [ - "lint" - ], "repository": { "type": "git", "url": "git+https://github.com/libp2p/js-libp2p-utils.git" }, - "license": "MIT", + "license": "(Apache-2.0 OR MIT)", "bugs": { "url": "https://github.com/libp2p/js-libp2p-utils/issues" }, "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", "devDependencies": { + "@libp2p/interfaces": "^0.2.0", "@types/debug": "^4.1.5", - "aegir": "^33.0.0", + "aegir": "^36.1.2", "it-pair": "^1.0.0", "it-pipe": "^1.1.0", - "libp2p-interfaces": "^1.0.0", "streaming-iterables": "^6.0.0", "util": "^0.12.3" }, "dependencies": { + "@achingbrain/ip-address": "^8.1.0", + "@multiformats/multiaddr": "^10.1.1", "abortable-iterator": "^3.0.0", "debug": "^4.3.0", "err-code": "^3.0.1", - "ip-address": "^8.0.0", "is-loopback-addr": "^1.0.0", - "multiaddr": "^10.0.0", "private-ip": "^2.1.1" }, "contributors": [ diff --git a/src/address-sort.js b/src/address-sort.ts similarity index 72% rename from src/address-sort.js rename to src/address-sort.ts index 2e54de864b..7459142d7f 100644 --- a/src/address-sort.js +++ b/src/address-sort.ts @@ -1,10 +1,10 @@ -'use strict' +import type { Multiaddr } from '@multiformats/multiaddr' +import { isPrivate } from './multiaddr/is-private.js' -const isPrivate = require('./multiaddr/is-private') - -/** - * @typedef {import('multiaddr').Multiaddr} Multiaddr - */ +interface Address { + multiaddr: Multiaddr + isCertified: boolean +} /** * @typedef {Object} Address @@ -21,7 +21,7 @@ const isPrivate = require('./multiaddr/is-private') * @param {Address} b * @returns {number} */ -function addressesPublicFirstCompareFunction (a, b) { +function addressesPublicFirstCompareFunction (a: Address, b: Address) { const isAPrivate = isPrivate(a.multiaddr) const isBPrivate = isPrivate(b.multiaddr) @@ -43,12 +43,7 @@ function addressesPublicFirstCompareFunction (a, b) { /** * Sort given addresses by putting public addresses first. * In case of equality, a certified address will come first. - * - * @param {Array
} addresses - * @returns {Array
} */ -function publicAddressesFirst (addresses) { +export function publicAddressesFirst (addresses: Address[]) { return [...addresses].sort(addressesPublicFirstCompareFunction) } - -module.exports.publicAddressesFirst = publicAddressesFirst diff --git a/src/array-equals.js b/src/array-equals.js deleted file mode 100644 index bb9f91cc27..0000000000 --- a/src/array-equals.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict' - -/** - * Verify if two arrays of non primitive types with the "equals" function are equal. - * Compatible with multiaddr, peer-id and others. - * - * @param {Array<*>} a - * @param {Array<*>} b - * @returns {boolean} - */ -function arrayEquals (a, b) { - return a.length === b.length && b.sort() && a.sort().every((item, index) => b[index].equals(item)) -} - -module.exports = arrayEquals diff --git a/src/array-equals.ts b/src/array-equals.ts new file mode 100644 index 0000000000..7455201a3f --- /dev/null +++ b/src/array-equals.ts @@ -0,0 +1,8 @@ +/** + * Verify if two arrays of non primitive types with the "equals" function are equal. + * Compatible with multiaddr, peer-id and others. + */ +export function arrayEquals (a: any[], b: any[]) { + const sort = (a: any, b: any) => a.toString().localeCompare(b.toString()) + return a.length === b.length && b.sort(sort) && a.sort(sort).every((item, index) => b[index].equals(item)) +} diff --git a/src/index.js b/src/index.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/ip-port-to-multiaddr.js b/src/ip-port-to-multiaddr.ts similarity index 62% rename from src/ip-port-to-multiaddr.js rename to src/ip-port-to-multiaddr.ts index 00b9f920d2..1bca51fe45 100644 --- a/src/ip-port-to-multiaddr.js +++ b/src/ip-port-to-multiaddr.ts @@ -1,14 +1,13 @@ -'use strict' +import debug from 'debug' +import { Multiaddr } from '@multiformats/multiaddr' +import errCode from 'err-code' +import { Address4, Address6 } from '@achingbrain/ip-address' -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') -const errCode = require('err-code') -const { Address4, Address6 } = require('ip-address') -const errors = { +export const Errors = { ERR_INVALID_IP_PARAMETER: 'ERR_INVALID_IP_PARAMETER', ERR_INVALID_PORT_PARAMETER: 'ERR_INVALID_PORT_PARAMETER', ERR_INVALID_IP: 'ERR_INVALID_IP' @@ -16,13 +15,10 @@ const errors = { /** * Transform an IP, Port pair into a multiaddr - * - * @param {string} ip - * @param {number|string} port */ -function ipPortToMultiaddr (ip, port) { +export function ipPortToMultiaddr (ip: string, port: number | string) { if (typeof ip !== 'string') { - throw errCode(new Error(`invalid ip provided: ${ip}`), errors.ERR_INVALID_IP_PARAMETER) + throw errCode(new Error(`invalid ip provided: ${ip}`), Errors.ERR_INVALID_IP_PARAMETER) // eslint-disable-line @typescript-eslint/restrict-template-expressions } if (typeof port === 'string') { @@ -30,7 +26,7 @@ function ipPortToMultiaddr (ip, port) { } if (isNaN(port)) { - throw errCode(new Error(`invalid port provided: ${port}`), errors.ERR_INVALID_PORT_PARAMETER) + throw errCode(new Error(`invalid port provided: ${port}`), Errors.ERR_INVALID_PORT_PARAMETER) } try { @@ -48,10 +44,6 @@ function ipPortToMultiaddr (ip, 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(errMsg), Errors.ERR_INVALID_IP) } } - -module.exports = ipPortToMultiaddr - -module.exports.Errors = errors diff --git a/src/multiaddr/is-loopback.js b/src/multiaddr/is-loopback.js deleted file mode 100644 index dd29c3daa7..0000000000 --- a/src/multiaddr/is-loopback.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict' - -// @ts-ignore is-loopback-addr does not publish types -const isLoopbackAddr = require('is-loopback-addr') - -/** - * @typedef {import('multiaddr').Multiaddr} Multiaddr - */ - -/** - * Check if a given multiaddr is a loopback address. - * - * @param {Multiaddr} ma - * @returns {boolean} - */ -function isLoopback (ma) { - const { address } = ma.nodeAddress() - - return isLoopbackAddr(address) -} - -module.exports = isLoopback diff --git a/src/multiaddr/is-loopback.ts b/src/multiaddr/is-loopback.ts new file mode 100644 index 0000000000..aae4e20fdc --- /dev/null +++ b/src/multiaddr/is-loopback.ts @@ -0,0 +1,12 @@ +// @ts-expect-error is-loopback-addr does not publish types +import isLoopbackAddr from 'is-loopback-addr' +import type { Multiaddr } from '@multiformats/multiaddr' + +/** + * Check if a given multiaddr is a loopback address. + */ +export function isLoopback (ma: Multiaddr) { + const { address } = ma.nodeAddress() + + return isLoopbackAddr(address) +} diff --git a/src/multiaddr/is-private.js b/src/multiaddr/is-private.js deleted file mode 100644 index efe6b2f17b..0000000000 --- a/src/multiaddr/is-private.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict' - -// @ts-ignore private-ip does not publish types -const isIpPrivate = require('private-ip') - -/** - * @typedef {import('multiaddr').Multiaddr} Multiaddr - */ - -/** - * Check if a given multiaddr has a private address. - * - * @param {Multiaddr} ma - * @returns {boolean} - */ -function isPrivate (ma) { - const { address } = ma.nodeAddress() - - return isIpPrivate(address) -} - -module.exports = isPrivate diff --git a/src/multiaddr/is-private.ts b/src/multiaddr/is-private.ts new file mode 100644 index 0000000000..54e8072ec4 --- /dev/null +++ b/src/multiaddr/is-private.ts @@ -0,0 +1,11 @@ +import type { Multiaddr } from '@multiformats/multiaddr' +import isIpPrivate from 'private-ip' + +/** + * Check if a given multiaddr has a private address. + */ +export function isPrivate (ma: Multiaddr) { + const { address } = ma.nodeAddress() + + return Boolean(isIpPrivate(address)) +} diff --git a/src/stream-to-ma-conn.js b/src/stream-to-ma-conn.js deleted file mode 100644 index eb9c0ab0b9..0000000000 --- a/src/stream-to-ma-conn.js +++ /dev/null @@ -1,76 +0,0 @@ -'use strict' - -const { source: abortable } = require('abortable-iterator') -const debug = require('debug') -const log = debug('libp2p:stream:converter') - -/** - * @typedef {import('multiaddr').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. - * https://github.com/libp2p/interface-transport#multiaddrconnection - * - * @param {object} streamProperties - * @param {MuxedStream} streamProperties.stream - * @param {Multiaddr} streamProperties.remoteAddr - * @param {Multiaddr} streamProperties.localAddr - * @param {object} [options] - * @param {AbortSignal} [options.signal] - * @returns {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} - */ -function streamToMaConnection ({ stream, remoteAddr, localAddr }, options = {}) { - const { sink, source } = stream - 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) - } - - try { - await sink(source) - } catch (err) { - // If aborted we can safely ignore - if (err.type !== 'aborted') { - // If the source errored the socket will already have been destroyed by - // toIterable.duplex(). If the socket errored it will already be - // destroyed. There's nothing to do here except log the error & return. - log(err) - } - } - close() - }, - source: options.signal ? abortable(source, options.signal) : source, - conn: stream, - localAddr, - remoteAddr, - /** @type {Timeline} */ - timeline: { open: Date.now(), close: undefined }, - close () { - sink(new Uint8Array(0)) - return close() - } - } - - function close () { - if (!maConn.timeline.close) { - maConn.timeline.close = Date.now() - } - return Promise.resolve() - } - - return maConn -} - -module.exports = streamToMaConnection diff --git a/src/stream-to-ma-conn.ts b/src/stream-to-ma-conn.ts new file mode 100644 index 0000000000..3be9b52469 --- /dev/null +++ b/src/stream-to-ma-conn.ts @@ -0,0 +1,92 @@ +import { source as abortable } from 'abortable-iterator' +import debug from 'debug' +import type { MuxedStream } from '@libp2p/interfaces/stream-muxer' +import type { Multiaddr } from '@multiformats/multiaddr' +import type { MultiaddrConnection } from '@libp2p/interfaces/transport' + +const log = debug('libp2p:stream:converter') + +/** + * @typedef {Object} Timeline + * @property {number} open - + * @property {number} [upgraded] - . + * @property {number} [close] + */ + +export interface Timeline { + /** + * Connection opening timestamp + */ + open: number + + /** + * Connection upgraded timestamp + */ + upgraded?: number + + /** + * Connection closed timestamp + */ + close?: number +} + +interface StreamOptions { + signal?: AbortSignal + +} + +interface StreamProperties { + stream: MuxedStream + remoteAddr: Multiaddr + localAddr: Multiaddr +} + +/** + * Convert a duplex iterable into a MultiaddrConnection. + * https://github.com/libp2p/interface-transport#multiaddrconnection + */ +export function streamToMaConnection (props: StreamProperties, options: StreamOptions = {}) { + const { stream, remoteAddr, localAddr } = props + const { sink, source } = stream + const maConn: MultiaddrConnection = { + async sink (source) { + if (options.signal != null) { + source = abortable(source, options.signal) + } + + try { + await sink(source) + await close() + } catch (err: any) { + // If aborted we can safely ignore + if (err.type !== 'aborted') { + // If the source errored the socket will already have been destroyed by + // toIterable.duplex(). If the socket errored it will already be + // destroyed. There's nothing to do here except log the error & return. + log(err) + } + } + }, + source: (options.signal != null) ? abortable(source, options.signal) : source, + conn: stream, + localAddr, + remoteAddr, + /** @type {Timeline} */ + timeline: { open: Date.now(), close: undefined }, + async close () { + await sink(async function * () { + yield new Uint8Array(0) + }()) + await close() + } + } + + async function close () { + if (maConn.timeline.close == null) { + maConn.timeline.close = Date.now() + } + return await Promise.resolve() + } + + return maConn +} diff --git a/test/address-sort.spec.js b/test/address-sort.spec.ts similarity index 90% rename from test/address-sort.spec.js rename to test/address-sort.spec.ts index 4f1780e3bf..06bdeff4c1 100644 --- a/test/address-sort.spec.js +++ b/test/address-sort.spec.ts @@ -1,10 +1,8 @@ -'use strict' /* eslint-env mocha */ -const { expect } = require('aegir/utils/chai') -const { Multiaddr } = require('multiaddr') - -const { publicAddressesFirst } = require('../src/address-sort') +import { expect } from 'aegir/utils/chai.js' +import { Multiaddr } from '@multiformats/multiaddr' +import { publicAddressesFirst } from '../src/address-sort.js' describe('address-sort', () => { it('should sort public addresses first', () => { diff --git a/test/array-equals.spec.js b/test/array-equals.spec.ts similarity index 92% rename from test/array-equals.spec.js rename to test/array-equals.spec.ts index bb70cba39f..6aa3977fe0 100644 --- a/test/array-equals.spec.js +++ b/test/array-equals.spec.ts @@ -1,10 +1,8 @@ /* eslint-env mocha */ -'use strict' -const { expect } = require('aegir/utils/chai') -const { Multiaddr } = require('multiaddr') - -const arrayEquals = require('../src/array-equals') +import { expect } from 'aegir/utils/chai.js' +import { Multiaddr } from '@multiformats/multiaddr' +import { arrayEquals } from '../src/array-equals.js' describe('non primitive array equals', () => { it('returns true if two arrays of multiaddrs are equal', () => { diff --git a/test/ip-port-to-multiaddr.spec.js b/test/ip-port-to-multiaddr.spec.js deleted file mode 100644 index e51aeb0309..0000000000 --- a/test/ip-port-to-multiaddr.spec.js +++ /dev/null @@ -1,48 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const { expect } = require('aegir/utils/chai') -const toMultiaddr = require('../src/ip-port-to-multiaddr') -const { Errors } = require('../src/ip-port-to-multiaddr') - -describe('IP and port to Multiaddr', () => { - it('creates multiaddr from valid IPv4 IP and port', () => { - const ip = '127.0.0.1' - const port = '9090' - expect(toMultiaddr(ip, port).toString()).to.equal(`/ip4/${ip}/tcp/${port}`) - }) - - it('creates multiaddr from valid IPv4 IP and numeric port', () => { - const ip = '127.0.0.1' - const port = 9090 - expect(toMultiaddr(ip, port).toString()).to.equal(`/ip4/${ip}/tcp/${port}`) - }) - - it('creates multiaddr from valid IPv4 in IPv6 IP and port', () => { - const ip = '0:0:0:0:0:0:101.45.75.219' - const port = '9090' - expect(toMultiaddr(ip, port).toString()).to.equal(`/ip4/101.45.75.219/tcp/${port}`) - }) - - it('creates multiaddr from valid IPv6 IP and port', () => { - const ip = '::1' - const port = '9090' - expect(toMultiaddr(ip, port).toString()).to.equal(`/ip6/${ip}/tcp/${port}`) - }) - - it('throws for missing IP address', () => { - expect(() => toMultiaddr()).to.throw('invalid ip provided').with.property('code', Errors.ERR_INVALID_IP_PARAMETER) - }) - - it('throws for invalid IP address', () => { - const ip = 'aewmrn4awoew' - const port = '234' - expect(() => toMultiaddr(ip, port)).to.throw('invalid ip:port for creating a multiaddr').with.property('code', Errors.ERR_INVALID_IP) - }) - - it('throws for invalid port', () => { - const ip = '127.0.0.1' - const port = 'garbage' - expect(() => toMultiaddr(ip, port)).to.throw('invalid port provided').with.property('code', Errors.ERR_INVALID_PORT_PARAMETER) - }) -}) diff --git a/test/ip-port-to-multiaddr.spec.ts b/test/ip-port-to-multiaddr.spec.ts new file mode 100644 index 0000000000..39e5897fa1 --- /dev/null +++ b/test/ip-port-to-multiaddr.spec.ts @@ -0,0 +1,47 @@ +/* eslint-env mocha */ + +import { expect } from 'aegir/utils/chai.js' +import { ipPortToMultiaddr, Errors } from '../src/ip-port-to-multiaddr.js' + +describe('IP and port to Multiaddr', () => { + it('creates multiaddr from valid IPv4 IP and port', () => { + const ip = '127.0.0.1' + const port = '9090' + expect(ipPortToMultiaddr(ip, port).toString()).to.equal(`/ip4/${ip}/tcp/${port}`) + }) + + it('creates multiaddr from valid IPv4 IP and numeric port', () => { + const ip = '127.0.0.1' + const port = 9090 + expect(ipPortToMultiaddr(ip, port).toString()).to.equal(`/ip4/${ip}/tcp/${port}`) + }) + + it('creates multiaddr from valid IPv4 in IPv6 IP and port', () => { + const ip = '0:0:0:0:0:0:101.45.75.219' + const port = '9090' + expect(ipPortToMultiaddr(ip, port).toString()).to.equal(`/ip4/101.45.75.219/tcp/${port}`) + }) + + it('creates multiaddr from valid IPv6 IP and port', () => { + const ip = '::1' + const port = '9090' + expect(ipPortToMultiaddr(ip, port).toString()).to.equal(`/ip6/${ip}/tcp/${port}`) + }) + + it('throws for missing IP address', () => { + // @ts-expect-error invalid args + expect(() => ipPortToMultiaddr()).to.throw('invalid ip provided').with.property('code', Errors.ERR_INVALID_IP_PARAMETER) + }) + + it('throws for invalid IP address', () => { + const ip = 'aewmrn4awoew' + const port = '234' + expect(() => ipPortToMultiaddr(ip, port)).to.throw('invalid ip:port for creating a multiaddr').with.property('code', Errors.ERR_INVALID_IP) + }) + + it('throws for invalid port', () => { + const ip = '127.0.0.1' + const port = 'garbage' + expect(() => ipPortToMultiaddr(ip, port)).to.throw('invalid port provided').with.property('code', Errors.ERR_INVALID_PORT_PARAMETER) + }) +}) diff --git a/test/multiaddr/is-loopback.spec.js b/test/multiaddr/is-loopback.spec.ts similarity index 89% rename from test/multiaddr/is-loopback.spec.js rename to test/multiaddr/is-loopback.spec.ts index 9c591573da..443196226c 100644 --- a/test/multiaddr/is-loopback.spec.js +++ b/test/multiaddr/is-loopback.spec.ts @@ -1,10 +1,8 @@ /* eslint-env mocha */ -'use strict' -const { expect } = require('aegir/utils/chai') -const { Multiaddr } = require('multiaddr') - -const isLoopback = require('../../src/multiaddr/is-loopback') +import { expect } from 'aegir/utils/chai.js' +import { Multiaddr } from '@multiformats/multiaddr' +import { isLoopback } from '../../src/multiaddr/is-loopback.js' describe('multiaddr isLoopback', () => { it('identifies loopback ip4 multiaddrs', () => { diff --git a/test/multiaddr/is-private.spec.js b/test/multiaddr/is-private.spec.ts similarity index 86% rename from test/multiaddr/is-private.spec.js rename to test/multiaddr/is-private.spec.ts index 0c9418bb1f..dcfe813ed4 100644 --- a/test/multiaddr/is-private.spec.js +++ b/test/multiaddr/is-private.spec.ts @@ -1,10 +1,8 @@ /* eslint-env mocha */ -'use strict' -const { expect } = require('aegir/utils/chai') -const { Multiaddr } = require('multiaddr') - -const isPrivate = require('../../src/multiaddr/is-private') +import { expect } from 'aegir/utils/chai.js' +import { Multiaddr } from '@multiformats/multiaddr' +import { isPrivate } from '../../src/multiaddr/is-private.js' describe('multiaddr isPrivate', () => { it('identifies private ip4 multiaddrs', () => { @@ -47,7 +45,7 @@ describe('multiaddr isPrivate', () => { }) }) - it('identifies other multiaddrs as not private addresses', () => { + it('identifies other multiaddrs as not private addresses', () => { [ new Multiaddr('/dns4/wss0.bootstrap.libp2p.io/tcp/443'), new Multiaddr('/dns6/wss0.bootstrap.libp2p.io/tcp/443') diff --git a/test/stream-to-ma-conn.spec.js b/test/stream-to-ma-conn.spec.ts similarity index 57% rename from test/stream-to-ma-conn.spec.js rename to test/stream-to-ma-conn.spec.ts index e7d322a792..ee1ba96a5d 100644 --- a/test/stream-to-ma-conn.spec.js +++ b/test/stream-to-ma-conn.spec.ts @@ -1,21 +1,21 @@ /* eslint-env mocha */ -'use strict' -const { expect } = require('aegir/utils/chai') -const pair = require('it-pair') -const pipe = require('it-pipe') -const { collect } = require('streaming-iterables') -const { Multiaddr } = require('multiaddr') - -const streamToMaConn = require('../src/stream-to-ma-conn') +import { expect } from 'aegir/utils/chai.js' +// @ts-expect-error no types +import pair from 'it-pair' +import pipe from 'it-pipe' +import { collect } from 'streaming-iterables' +import { Multiaddr } from '@multiformats/multiaddr' +import { streamToMaConnection } from '../src/stream-to-ma-conn.js' describe('Convert stream into a multiaddr connection', () => { - it('converts a stream and adds the provided metadata', () => { + const localAddr = new Multiaddr('/ip4/101.45.75.219/tcp/6000') + const remoteAddr = new Multiaddr('/ip4/100.46.74.201/tcp/6002') + + it('converts a stream and adds the provided metadata', async () => { const stream = pair() - const localAddr = new Multiaddr('/ip4/101.45.75.219/tcp/6000') - const remoteAddr = new Multiaddr('/ip4/100.46.74.201/tcp/6002') - const maConn = streamToMaConn({ + const maConn = streamToMaConnection({ stream, localAddr, remoteAddr @@ -30,13 +30,17 @@ describe('Convert stream into a multiaddr connection', () => { expect(maConn.timeline.open).to.exist() expect(maConn.timeline.close).to.not.exist() - maConn.close() + await maConn.close() expect(maConn.timeline.close).to.exist() }) it('can stream data over the multiaddr connection', async () => { const stream = pair() - const maConn = streamToMaConn({ stream }) + const maConn = streamToMaConnection({ + stream, + localAddr, + remoteAddr + }) const data = 'hey' const streamData = await pipe( diff --git a/tsconfig.json b/tsconfig.json index 5fe8ea40d7..f296f99426 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,12 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "dist" + "outDir": "dist", + "emitDeclarationOnly": false, + "module": "ES2020" }, "include": [ - "src" + "src", + "test" ] } From e721c5e23bdb60a61ceacf03b474971f7678c5cb Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 5 Jan 2022 23:27:33 +0100 Subject: [PATCH 046/124] fix: exports and types (#21) Updates exports map and typesVersions field --- package.json | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 397aad9998..2434f597c1 100644 --- a/package.json +++ b/package.json @@ -5,33 +5,37 @@ "leadMaintainer": "Vasco Santos ", "type": "module", "exports": { - "multiaddr/is-loopback": { + "./multiaddr/is-loopback": { "import": "./dist/src/multiaddr/is-loopback.js", "types": "./dist/src/multiaddr/is-loopback.d.ts" }, - "multiaddr/is-private": { + "./multiaddr/is-private": { "import": "./dist/src/multiaddr/is-private.js", "types": "./dist/src/multiaddr/is-private.d.ts" }, - "address-sort": { + "./address-sort": { "import": "./dist/src/address-sort.js", "types": "./dist/src/address-sort.d.ts" }, - "array-equals": { + "./array-equals": { "import": "./dist/src/array-equals.js", "types": "./dist/src/array-equals.d.ts" }, - "ip-port-to-multiaddr": { + "./ip-port-to-multiaddr": { "import": "./dist/src/ip-port-to-multiaddr.js", "types": "./dist/src/ip-port-to-multiaddr.d.ts" }, - "stream-to-ma-conn": { + "./stream-to-ma-conn": { "import": "./dist/src/stream-to-ma-connr.js", "types": "./dist/src/stream-to-ma-connr.d.ts" } }, "typesVersions": { "*": { + "*": [ + "dist/src/*", + "dist/src/*/index" + ], "src/*": [ "dist/src/*", "dist/src/*/index" From 5fcf8c7f57864e4e92f6606656cf3ea1f214f0c4 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Sat, 8 Jan 2022 07:42:35 +0100 Subject: [PATCH 047/124] chore: add semantic release config (#22) Generate changelogs again. --- package.json | 71 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 2434f597c1..f7d4927c14 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "type": "git", "url": "git+https://github.com/libp2p/js-libp2p-utils.git" }, - "license": "(Apache-2.0 OR MIT)", + "license": "Apache-2.0 OR MIT", "bugs": { "url": "https://github.com/libp2p/js-libp2p-utils/issues" }, @@ -87,9 +87,68 @@ "is-loopback-addr": "^1.0.0", "private-ip": "^2.1.1" }, - "contributors": [ - "Vasco Santos ", - "Alex Potsides ", - "Jacob Heun " - ] + "release": { + "branches": [ + "master" + ], + "plugins": [ + [ + "@semantic-release/commit-analyzer", { + "preset": "conventionalcommits", + "releaseRules": [{ + "breaking": true, + "release": "major" + }, { + "revert": true, + "release": "patch" + }, { + "type": "feat", + "release": "minor" + }, { + "type": "fix", + "release": "patch" + }, { + "type": "chore", + "release": "patch" + }, { + "type": "docs", + "release": "patch" + }, { + "type": "test", + "release": "patch" + }, { + "scope": "no-release", + "release": false + }] + } + ], + [ + "@semantic-release/release-notes-generator", { + "preset": "conventionalcommits", + "presetConfig": { + "types": [{ + "type": "feat", + "section": "Features" + }, { + "type": "fix", + "section": "Bug Fixes" + }, { + "type": "chore", + "section": "Trivial Changes" + }, { + "type": "docs", + "section": "Trivial Changes" + }, { + "type": "test", + "section": "Tests" + }] + } + } + ], + "@semantic-release/changelog", + "@semantic-release/npm", + "@semantic-release/github", + "@semantic-release/git" + ] + } } From e98a1e561ccadfab091fc54d858c61352de1739a Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sat, 8 Jan 2022 06:47:20 +0000 Subject: [PATCH 048/124] chore(release): 1.0.2 [skip ci] ### [1.0.2](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.1...v1.0.2) (2022-01-08) ### Trivial Changes * add semantic release config ([#22](https://github.com/libp2p/js-libp2p-utils/issues/22)) ([5fcf8c7](https://github.com/libp2p/js-libp2p-utils/commit/5fcf8c7f57864e4e92f6606656cf3ea1f214f0c4)) --- CHANGELOG.md | 10 +++-- package.json | 105 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 68 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1114cbe56e..3d0313b45f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### [1.0.2](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.1...v1.0.2) (2022-01-08) + + +### Trivial Changes + +* add semantic release config ([#22](https://github.com/libp2p/js-libp2p-utils/issues/22)) ([5fcf8c7](https://github.com/libp2p/js-libp2p-utils/commit/5fcf8c7f57864e4e92f6606656cf3ea1f214f0c4)) + ## [0.4.1](https://github.com/libp2p/js-libp2p-utils/compare/v0.4.0...v0.4.1) (2021-07-08) @@ -117,6 +124,3 @@ ### Features * ip port to multiaddr ([#1](https://github.com/libp2p/js-libp2p-utils/issues/1)) ([426b421](https://github.com/libp2p/js-libp2p-utils/commit/426b421)) - - - diff --git a/package.json b/package.json index f7d4927c14..c093dcbd3e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "0.4.1", + "version": "1.0.2", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "leadMaintainer": "Vasco Santos ", "type": "module", @@ -93,55 +93,72 @@ ], "plugins": [ [ - "@semantic-release/commit-analyzer", { + "@semantic-release/commit-analyzer", + { "preset": "conventionalcommits", - "releaseRules": [{ - "breaking": true, - "release": "major" - }, { - "revert": true, - "release": "patch" - }, { - "type": "feat", - "release": "minor" - }, { - "type": "fix", - "release": "patch" - }, { - "type": "chore", - "release": "patch" - }, { - "type": "docs", - "release": "patch" - }, { - "type": "test", - "release": "patch" - }, { - "scope": "no-release", - "release": false - }] - } - ], - [ - "@semantic-release/release-notes-generator", { - "preset": "conventionalcommits", - "presetConfig": { - "types": [{ + "releaseRules": [ + { + "breaking": true, + "release": "major" + }, + { + "revert": true, + "release": "patch" + }, + { "type": "feat", - "section": "Features" - }, { + "release": "minor" + }, + { "type": "fix", - "section": "Bug Fixes" - }, { + "release": "patch" + }, + { "type": "chore", - "section": "Trivial Changes" - }, { + "release": "patch" + }, + { "type": "docs", - "section": "Trivial Changes" - }, { + "release": "patch" + }, + { "type": "test", - "section": "Tests" - }] + "release": "patch" + }, + { + "scope": "no-release", + "release": false + } + ] + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "chore", + "section": "Trivial Changes" + }, + { + "type": "docs", + "section": "Trivial Changes" + }, + { + "type": "test", + "section": "Tests" + } + ] } } ], From cb7ea61e6df7a721863ad8fba7c73d376b2c3ab8 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 14 Jan 2022 17:49:59 +0000 Subject: [PATCH 049/124] chore: project updates (#23) Output of `check-aegir-project` --- .github/dependabot.yml | 8 ++ .../{main.yml => js-test-and-release.yml} | 39 +++++- LICENSE | 4 +- LICENSE-MIT | 2 +- package.json | 127 ++++++++++-------- 5 files changed, 116 insertions(+), 64 deletions(-) create mode 100644 .github/dependabot.yml rename .github/workflows/{main.yml => js-test-and-release.yml} (70%) diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000000..290ad02837 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: +- package-ecosystem: npm + directory: "/" + schedule: + interval: daily + time: "10:00" + open-pull-requests-limit: 10 diff --git a/.github/workflows/main.yml b/.github/workflows/js-test-and-release.yml similarity index 70% rename from .github/workflows/main.yml rename to .github/workflows/js-test-and-release.yml index c9772b6fca..8630dc5c3a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/js-test-and-release.yml @@ -2,10 +2,10 @@ name: test & maybe release on: push: branches: - - master + - master # with #262 - ${{{ github.default_branch }}} pull_request: branches: - - master + - master # with #262 - ${{{ github.default_branch }}} jobs: @@ -35,7 +35,10 @@ jobs: node-version: ${{ matrix.node }} - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:node - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: node test-chrome: needs: check @@ -47,6 +50,10 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:chrome + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: chrome test-chrome-webworker: needs: check @@ -58,6 +65,10 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:chrome-webworker + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: chrome-webworker test-firefox: needs: check @@ -69,6 +80,10 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:firefox + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: firefox test-firefox-webworker: needs: check @@ -80,6 +95,10 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:firefox-webworker + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: firefox-webworker test-electron-main: needs: check @@ -91,6 +110,10 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npx xvfb-maybe npm run --if-present test:electron-main + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: electron-main test-electron-renderer: needs: check @@ -102,13 +125,17 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npx xvfb-maybe npm run --if-present test:electron-renderer + - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + with: + directory: ./.nyc_output + flags: electron-renderer release: needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer] runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/master' + if: github.event_name == 'push' && github.ref == 'refs/heads/master' # with #262 - 'refs/heads/${{{ github.default_branch }}}' steps: - - uses: actions/checkout@v2.4.0 + - uses: actions/checkout@v2 with: fetch-depth: 0 - uses: actions/setup-node@v2 @@ -117,7 +144,7 @@ jobs: - uses: ipfs/aegir/actions/cache-node-modules@master - uses: ipfs/aegir/actions/docker-login@master with: - docker-token: ${{ secrets.DOCKER_USERNAME }} + docker-token: ${{ secrets.DOCKER_TOKEN }} docker-username: ${{ secrets.DOCKER_USERNAME }} - run: npm run --if-present release env: diff --git a/LICENSE b/LICENSE index b0b237faab..20ce483c86 100644 --- a/LICENSE +++ b/LICENSE @@ -1,2 +1,4 @@ +This project is dual licensed under MIT and Apache-2.0. + MIT: https://www.opensource.org/licenses/mit -Apache-2.0: https://www.apache.org/licenses/license-2.0 \ No newline at end of file +Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/LICENSE-MIT b/LICENSE-MIT index 749aa1ecd9..72dc60d84b 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. diff --git a/package.json b/package.json index c093dcbd3e..da109df88c 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,43 @@ "name": "@libp2p/utils", "version": "1.0.2", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", - "leadMaintainer": "Vasco Santos ", + "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", + "license": "Apache-2.0 OR MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/libp2p/js-libp2p-utils.git" + }, + "bugs": { + "url": "https://github.com/libp2p/js-libp2p-utils/issues" + }, "type": "module", + "types": "./dist/src/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" + ], + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" + ] + } + }, + "files": [ + "src", + "dist/src", + "!dist/test", + "!**/*.tsbuildinfo" + ], "exports": { + ".": { + "import": "./dist/src/index.js" + }, "./multiaddr/is-loopback": { "import": "./dist/src/multiaddr/is-loopback.js", "types": "./dist/src/multiaddr/is-loopback.d.ts" @@ -30,63 +64,12 @@ "types": "./dist/src/stream-to-ma-connr.d.ts" } }, - "typesVersions": { - "*": { - "*": [ - "dist/src/*", - "dist/src/*/index" - ], - "src/*": [ - "dist/src/*", - "dist/src/*/index" - ] + "eslintConfig": { + "extends": "ipfs", + "parserOptions": { + "sourceType": "module" } }, - "files": [ - "src", - "dist/src" - ], - "scripts": { - "lint": "aegir lint", - "dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js", - "build": "tsc", - "pretest": "npm run build", - "test": "aegir test -f ./dist/test/**/*.js", - "test:chrome": "npm run test -- -t browser", - "test:chrome-webworker": "npm run test -- -t webworker", - "test:firefox": "npm run test -- -t browser -- --browser firefox", - "test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox", - "test:node": "npm run test -- -t node --cov", - "test:electron-main": "npm run test -- -t electron-main", - "release": "semantic-release" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/libp2p/js-libp2p-utils.git" - }, - "license": "Apache-2.0 OR MIT", - "bugs": { - "url": "https://github.com/libp2p/js-libp2p-utils/issues" - }, - "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", - "devDependencies": { - "@libp2p/interfaces": "^0.2.0", - "@types/debug": "^4.1.5", - "aegir": "^36.1.2", - "it-pair": "^1.0.0", - "it-pipe": "^1.1.0", - "streaming-iterables": "^6.0.0", - "util": "^0.12.3" - }, - "dependencies": { - "@achingbrain/ip-address": "^8.1.0", - "@multiformats/multiaddr": "^10.1.1", - "abortable-iterator": "^3.0.0", - "debug": "^4.3.0", - "err-code": "^3.0.1", - "is-loopback-addr": "^1.0.0", - "private-ip": "^2.1.1" - }, "release": { "branches": [ "master" @@ -167,5 +150,37 @@ "@semantic-release/github", "@semantic-release/git" ] + }, + "scripts": { + "lint": "aegir lint", + "dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js", + "build": "tsc", + "pretest": "npm run build", + "test": "aegir test -f ./dist/test/**/*.js", + "test:chrome": "npm run test -- -t browser", + "test:chrome-webworker": "npm run test -- -t webworker", + "test:firefox": "npm run test -- -t browser -- --browser firefox", + "test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox", + "test:node": "npm run test -- -t node --cov", + "test:electron-main": "npm run test -- -t electron-main", + "release": "semantic-release" + }, + "dependencies": { + "@achingbrain/ip-address": "^8.1.0", + "@multiformats/multiaddr": "^10.1.1", + "abortable-iterator": "^3.0.0", + "debug": "^4.3.0", + "err-code": "^3.0.1", + "is-loopback-addr": "^1.0.0", + "private-ip": "^2.1.1" + }, + "devDependencies": { + "@libp2p/interfaces": "^0.2.0", + "@types/debug": "^4.1.5", + "aegir": "^36.1.2", + "it-pair": "^1.0.0", + "it-pipe": "^1.1.0", + "streaming-iterables": "^6.0.0", + "util": "^0.12.3" } } From fd5cca2af6af2de1aef6f7796fa432e2a0736fb6 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 14 Jan 2022 17:57:44 +0000 Subject: [PATCH 050/124] chore(release): 1.0.3 [skip ci] ### [1.0.3](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.2...v1.0.3) (2022-01-14) ### Trivial Changes * project updates ([#23](https://github.com/libp2p/js-libp2p-utils/issues/23)) ([cb7ea61](https://github.com/libp2p/js-libp2p-utils/commit/cb7ea61e6df7a721863ad8fba7c73d376b2c3ab8)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d0313b45f..8af09254ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### [1.0.3](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.2...v1.0.3) (2022-01-14) + + +### Trivial Changes + +* project updates ([#23](https://github.com/libp2p/js-libp2p-utils/issues/23)) ([cb7ea61](https://github.com/libp2p/js-libp2p-utils/commit/cb7ea61e6df7a721863ad8fba7c73d376b2c3ab8)) + ### [1.0.2](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.1...v1.0.2) (2022-01-08) diff --git a/package.json b/package.json index da109df88c..b1623600d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "1.0.2", + "version": "1.0.3", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", "license": "Apache-2.0 OR MIT", From 47ce53c34b0106101215ed4b3ffe9f1fffd51cb6 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Sat, 15 Jan 2022 06:40:00 +0000 Subject: [PATCH 051/124] chore: engines version (#29) Add engines field in line with supported node versions --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b1623600d0..b04de320cb 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "@libp2p/utils", "version": "1.0.3", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", - "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", "license": "Apache-2.0 OR MIT", + "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", "repository": { "type": "git", "url": "git+https://github.com/libp2p/js-libp2p-utils.git" @@ -11,6 +11,10 @@ "bugs": { "url": "https://github.com/libp2p/js-libp2p-utils/issues" }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + }, "type": "module", "types": "./dist/src/index.d.ts", "typesVersions": { From c378da0f71652292849088f9dd893afc403c9b04 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sat, 15 Jan 2022 06:44:45 +0000 Subject: [PATCH 052/124] chore(release): 1.0.4 [skip ci] ### [1.0.4](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.3...v1.0.4) (2022-01-15) ### Trivial Changes * engines version ([#29](https://github.com/libp2p/js-libp2p-utils/issues/29)) ([47ce53c](https://github.com/libp2p/js-libp2p-utils/commit/47ce53c34b0106101215ed4b3ffe9f1fffd51cb6)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8af09254ef..601ca36097 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### [1.0.4](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.3...v1.0.4) (2022-01-15) + + +### Trivial Changes + +* engines version ([#29](https://github.com/libp2p/js-libp2p-utils/issues/29)) ([47ce53c](https://github.com/libp2p/js-libp2p-utils/commit/47ce53c34b0106101215ed4b3ffe9f1fffd51cb6)) + ### [1.0.3](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.2...v1.0.3) (2022-01-14) diff --git a/package.json b/package.json index b04de320cb..cbfa025bf4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "1.0.3", + "version": "1.0.4", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From b65ae5c813efdc20ac11a13f349dc914ffc64c48 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Sat, 15 Jan 2022 08:33:29 +0000 Subject: [PATCH 053/124] fix: update it-* deps to typed versions (#30) Updates all deps to typed versions --- package.json | 10 +++++----- src/multiaddr/is-loopback.ts | 3 +-- src/stream-to-ma-conn.ts | 8 ++++---- test/stream-to-ma-conn.spec.ts | 33 +++++++++++++++++++++++++-------- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index cbfa025bf4..2a083dc248 100644 --- a/package.json +++ b/package.json @@ -172,18 +172,18 @@ "dependencies": { "@achingbrain/ip-address": "^8.1.0", "@multiformats/multiaddr": "^10.1.1", - "abortable-iterator": "^3.0.0", + "abortable-iterator": "^4.0.2", "debug": "^4.3.0", "err-code": "^3.0.1", - "is-loopback-addr": "^1.0.0", + "is-loopback-addr": "^2.0.1", "private-ip": "^2.1.1" }, "devDependencies": { - "@libp2p/interfaces": "^0.2.0", + "@libp2p/interfaces": "^1.0.3", "@types/debug": "^4.1.5", "aegir": "^36.1.2", - "it-pair": "^1.0.0", - "it-pipe": "^1.1.0", + "it-pair": "^2.0.2", + "it-pipe": "^2.0.2", "streaming-iterables": "^6.0.0", "util": "^0.12.3" } diff --git a/src/multiaddr/is-loopback.ts b/src/multiaddr/is-loopback.ts index aae4e20fdc..d676a66b4c 100644 --- a/src/multiaddr/is-loopback.ts +++ b/src/multiaddr/is-loopback.ts @@ -1,5 +1,4 @@ -// @ts-expect-error is-loopback-addr does not publish types -import isLoopbackAddr from 'is-loopback-addr' +import { isLoopbackAddr } from 'is-loopback-addr' import type { Multiaddr } from '@multiformats/multiaddr' /** diff --git a/src/stream-to-ma-conn.ts b/src/stream-to-ma-conn.ts index 3be9b52469..7b5a0d8b3c 100644 --- a/src/stream-to-ma-conn.ts +++ b/src/stream-to-ma-conn.ts @@ -1,4 +1,4 @@ -import { source as abortable } from 'abortable-iterator' +import { abortableSource } from 'abortable-iterator' import debug from 'debug' import type { MuxedStream } from '@libp2p/interfaces/stream-muxer' import type { Multiaddr } from '@multiformats/multiaddr' @@ -36,7 +36,7 @@ interface StreamOptions { } interface StreamProperties { - stream: MuxedStream + stream: MuxedStream remoteAddr: Multiaddr localAddr: Multiaddr } @@ -51,7 +51,7 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp const maConn: MultiaddrConnection = { async sink (source) { if (options.signal != null) { - source = abortable(source, options.signal) + source = abortableSource(source, options.signal) } try { @@ -67,7 +67,7 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp } } }, - source: (options.signal != null) ? abortable(source, options.signal) : source, + source: (options.signal != null) ? abortableSource(source, options.signal) : source, conn: stream, localAddr, remoteAddr, diff --git a/test/stream-to-ma-conn.spec.ts b/test/stream-to-ma-conn.spec.ts index ee1ba96a5d..ce65852f34 100644 --- a/test/stream-to-ma-conn.spec.ts +++ b/test/stream-to-ma-conn.spec.ts @@ -1,22 +1,39 @@ /* eslint-env mocha */ import { expect } from 'aegir/utils/chai.js' -// @ts-expect-error no types -import pair from 'it-pair' -import pipe from 'it-pipe' +import { pair } from 'it-pair' +import { pipe } from 'it-pipe' import { collect } from 'streaming-iterables' import { Multiaddr } from '@multiformats/multiaddr' import { streamToMaConnection } from '../src/stream-to-ma-conn.js' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import type { MuxedStream } from '@libp2p/interfaces/stream-muxer' +import type { Duplex } from 'it-stream-types' + +function toMuxedStream (stream: Duplex) { + const muxedStream: MuxedStream = { + ...stream, + close: () => {}, + abort: () => {}, + reset: () => {}, + timeline: { + open: Date.now() + }, + id: `muxed-stream-${Math.random()}` + } + + return muxedStream +} describe('Convert stream into a multiaddr connection', () => { const localAddr = new Multiaddr('/ip4/101.45.75.219/tcp/6000') const remoteAddr = new Multiaddr('/ip4/100.46.74.201/tcp/6002') it('converts a stream and adds the provided metadata', async () => { - const stream = pair() + const stream = pair() const maConn = streamToMaConnection({ - stream, + stream: toMuxedStream(stream), localAddr, remoteAddr }) @@ -35,14 +52,14 @@ describe('Convert stream into a multiaddr connection', () => { }) it('can stream data over the multiaddr connection', async () => { - const stream = pair() + const stream = pair() const maConn = streamToMaConnection({ - stream, + stream: toMuxedStream(stream), localAddr, remoteAddr }) - const data = 'hey' + const data = uint8ArrayFromString('hey') const streamData = await pipe( [data], maConn, From b92aedaafb0f74a5352aa74a73ac6326137d18da Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sat, 15 Jan 2022 08:37:55 +0000 Subject: [PATCH 054/124] chore(release): 1.0.5 [skip ci] ### [1.0.5](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.4...v1.0.5) (2022-01-15) ### Bug Fixes * update it-* deps to typed versions ([#30](https://github.com/libp2p/js-libp2p-utils/issues/30)) ([b65ae5c](https://github.com/libp2p/js-libp2p-utils/commit/b65ae5c813efdc20ac11a13f349dc914ffc64c48)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 601ca36097..0adb895df3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### [1.0.5](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.4...v1.0.5) (2022-01-15) + + +### Bug Fixes + +* update it-* deps to typed versions ([#30](https://github.com/libp2p/js-libp2p-utils/issues/30)) ([b65ae5c](https://github.com/libp2p/js-libp2p-utils/commit/b65ae5c813efdc20ac11a13f349dc914ffc64c48)) + ### [1.0.4](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.3...v1.0.4) (2022-01-15) diff --git a/package.json b/package.json index 2a083dc248..686716d0c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "1.0.4", + "version": "1.0.5", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From 5d960f3d1566ccb9bf043b71eca5a83117955940 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Thu, 10 Feb 2022 08:05:29 +0200 Subject: [PATCH 055/124] fix: update interfaces (#32) --- package.json | 28 +++++++++++++--------------- src/ip-port-to-multiaddr.ts | 6 ++---- src/stream-to-ma-conn.ts | 12 +++++------- test/stream-to-ma-conn.spec.ts | 9 ++++----- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 686716d0c2..45d02203b5 100644 --- a/package.json +++ b/package.json @@ -43,14 +43,6 @@ ".": { "import": "./dist/src/index.js" }, - "./multiaddr/is-loopback": { - "import": "./dist/src/multiaddr/is-loopback.js", - "types": "./dist/src/multiaddr/is-loopback.d.ts" - }, - "./multiaddr/is-private": { - "import": "./dist/src/multiaddr/is-private.js", - "types": "./dist/src/multiaddr/is-private.d.ts" - }, "./address-sort": { "import": "./dist/src/address-sort.js", "types": "./dist/src/address-sort.d.ts" @@ -63,6 +55,14 @@ "import": "./dist/src/ip-port-to-multiaddr.js", "types": "./dist/src/ip-port-to-multiaddr.d.ts" }, + "./multiaddr/is-loopback": { + "import": "./dist/src/multiaddr/is-loopback.js", + "types": "./dist/src/multiaddr/is-loopback.d.ts" + }, + "./multiaddr/is-private": { + "import": "./dist/src/multiaddr/is-private.js", + "types": "./dist/src/multiaddr/is-private.d.ts" + }, "./stream-to-ma-conn": { "import": "./dist/src/stream-to-ma-connr.js", "types": "./dist/src/stream-to-ma-connr.d.ts" @@ -160,8 +160,8 @@ "dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js", "build": "tsc", "pretest": "npm run build", - "test": "aegir test -f ./dist/test/**/*.js", - "test:chrome": "npm run test -- -t browser", + "test": "aegir test -f ./dist/test/*.js -f ./dist/test/**/*.js", + "test:chrome": "npm run test -- -t browser --cov", "test:chrome-webworker": "npm run test -- -t webworker", "test:firefox": "npm run test -- -t browser -- --browser firefox", "test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox", @@ -171,20 +171,18 @@ }, "dependencies": { "@achingbrain/ip-address": "^8.1.0", + "@libp2p/logger": "^1.0.1", "@multiformats/multiaddr": "^10.1.1", "abortable-iterator": "^4.0.2", - "debug": "^4.3.0", "err-code": "^3.0.1", "is-loopback-addr": "^2.0.1", "private-ip": "^2.1.1" }, "devDependencies": { "@libp2p/interfaces": "^1.0.3", - "@types/debug": "^4.1.5", "aegir": "^36.1.2", + "it-all": "^1.0.6", "it-pair": "^2.0.2", - "it-pipe": "^2.0.2", - "streaming-iterables": "^6.0.0", - "util": "^0.12.3" + "it-pipe": "^2.0.2" } } diff --git a/src/ip-port-to-multiaddr.ts b/src/ip-port-to-multiaddr.ts index 1bca51fe45..adad125a8e 100644 --- a/src/ip-port-to-multiaddr.ts +++ b/src/ip-port-to-multiaddr.ts @@ -1,11 +1,9 @@ -import debug from 'debug' +import { logger } from '@libp2p/logger' import { Multiaddr } from '@multiformats/multiaddr' import errCode from 'err-code' import { Address4, Address6 } from '@achingbrain/ip-address' -const log = Object.assign(debug('libp2p:ip-port-to-multiaddr'), { - error: debug('libp2p:ip-port-to-multiaddr:err') -}) +const log = logger('libp2p:ip-port-to-multiaddr') export const Errors = { ERR_INVALID_IP_PARAMETER: 'ERR_INVALID_IP_PARAMETER', diff --git a/src/stream-to-ma-conn.ts b/src/stream-to-ma-conn.ts index 7b5a0d8b3c..011c109c79 100644 --- a/src/stream-to-ma-conn.ts +++ b/src/stream-to-ma-conn.ts @@ -1,10 +1,10 @@ import { abortableSource } from 'abortable-iterator' -import debug from 'debug' -import type { MuxedStream } from '@libp2p/interfaces/stream-muxer' +import { logger } from '@libp2p/logger' +import type { Stream } from '@libp2p/interfaces/connection' import type { Multiaddr } from '@multiformats/multiaddr' import type { MultiaddrConnection } from '@libp2p/interfaces/transport' -const log = debug('libp2p:stream:converter') +const log = logger('libp2p:stream:converter') /** * @typedef {Object} Timeline @@ -36,7 +36,7 @@ interface StreamOptions { } interface StreamProperties { - stream: MuxedStream + stream: Stream remoteAddr: Multiaddr localAddr: Multiaddr } @@ -46,7 +46,7 @@ interface StreamProperties { * https://github.com/libp2p/interface-transport#multiaddrconnection */ export function streamToMaConnection (props: StreamProperties, options: StreamOptions = {}) { - const { stream, remoteAddr, localAddr } = props + const { stream, remoteAddr } = props const { sink, source } = stream const maConn: MultiaddrConnection = { async sink (source) { @@ -68,8 +68,6 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp } }, source: (options.signal != null) ? abortableSource(source, options.signal) : source, - conn: stream, - localAddr, remoteAddr, /** @type {Timeline} */ timeline: { open: Date.now(), close: undefined }, diff --git a/test/stream-to-ma-conn.spec.ts b/test/stream-to-ma-conn.spec.ts index ce65852f34..39978d1cf3 100644 --- a/test/stream-to-ma-conn.spec.ts +++ b/test/stream-to-ma-conn.spec.ts @@ -3,15 +3,15 @@ import { expect } from 'aegir/utils/chai.js' import { pair } from 'it-pair' import { pipe } from 'it-pipe' -import { collect } from 'streaming-iterables' import { Multiaddr } from '@multiformats/multiaddr' import { streamToMaConnection } from '../src/stream-to-ma-conn.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import type { MuxedStream } from '@libp2p/interfaces/stream-muxer' +import all from 'it-all' +import type { Stream } from '@libp2p/interfaces/connection' import type { Duplex } from 'it-stream-types' function toMuxedStream (stream: Duplex) { - const muxedStream: MuxedStream = { + const muxedStream: Stream = { ...stream, close: () => {}, abort: () => {}, @@ -41,7 +41,6 @@ describe('Convert stream into a multiaddr connection', () => { expect(maConn).to.exist() expect(maConn.sink).to.exist() expect(maConn.source).to.exist() - expect(maConn.localAddr).to.eql(localAddr) expect(maConn.remoteAddr).to.eql(remoteAddr) expect(maConn.timeline).to.exist() expect(maConn.timeline.open).to.exist() @@ -63,7 +62,7 @@ describe('Convert stream into a multiaddr connection', () => { const streamData = await pipe( [data], maConn, - collect + async (source) => await all(source) ) expect(streamData).to.eql([data]) From 9b22f46b70e63b059ed7cb4ad7c32370c4e6a330 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 10 Feb 2022 06:09:59 +0000 Subject: [PATCH 056/124] chore(release): 1.0.6 [skip ci] ### [1.0.6](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.5...v1.0.6) (2022-02-10) ### Bug Fixes * update interfaces ([#32](https://github.com/libp2p/js-libp2p-utils/issues/32)) ([5d960f3](https://github.com/libp2p/js-libp2p-utils/commit/5d960f3d1566ccb9bf043b71eca5a83117955940)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0adb895df3..82fc5b7877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### [1.0.6](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.5...v1.0.6) (2022-02-10) + + +### Bug Fixes + +* update interfaces ([#32](https://github.com/libp2p/js-libp2p-utils/issues/32)) ([5d960f3](https://github.com/libp2p/js-libp2p-utils/commit/5d960f3d1566ccb9bf043b71eca5a83117955940)) + ### [1.0.5](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.4...v1.0.5) (2022-01-15) diff --git a/package.json b/package.json index 45d02203b5..b8425d7585 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "1.0.5", + "version": "1.0.6", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From ebc5c6074c971e39c6e5c5c51e251aa00c544b50 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 2 Mar 2022 09:05:32 +0000 Subject: [PATCH 057/124] fix: pass duplex to stream-to-ma-conn not stream (#33) Stream is a (possibly) multiplexed stream which comes later in the flow. stream-to-ma-conn takes the low-level byte stream. Also removes some redundant comments. --- package.json | 1 + src/address-sort.ts | 10 ---------- src/stream-to-ma-conn.ts | 11 ++--------- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index b8425d7585..b1b7b1861a 100644 --- a/package.json +++ b/package.json @@ -176,6 +176,7 @@ "abortable-iterator": "^4.0.2", "err-code": "^3.0.1", "is-loopback-addr": "^2.0.1", + "it-stream-types": "^1.0.4", "private-ip": "^2.1.1" }, "devDependencies": { diff --git a/src/address-sort.ts b/src/address-sort.ts index 7459142d7f..64583a29df 100644 --- a/src/address-sort.ts +++ b/src/address-sort.ts @@ -6,20 +6,10 @@ interface Address { isCertified: boolean } -/** - * @typedef {Object} Address - * @property {Multiaddr} multiaddr peer multiaddr. - * @property {boolean} isCertified obtained from a signed peer record. - */ - /** * Compare function for array.sort(). * This sort aims to move the private adresses to the end of the array. * In case of equality, a certified address will come first. - * - * @param {Address} a - * @param {Address} b - * @returns {number} */ function addressesPublicFirstCompareFunction (a: Address, b: Address) { const isAPrivate = isPrivate(a.multiaddr) diff --git a/src/stream-to-ma-conn.ts b/src/stream-to-ma-conn.ts index 011c109c79..c819dbf60d 100644 --- a/src/stream-to-ma-conn.ts +++ b/src/stream-to-ma-conn.ts @@ -1,18 +1,11 @@ import { abortableSource } from 'abortable-iterator' import { logger } from '@libp2p/logger' -import type { Stream } from '@libp2p/interfaces/connection' import type { Multiaddr } from '@multiformats/multiaddr' import type { MultiaddrConnection } from '@libp2p/interfaces/transport' +import type { Duplex } from 'it-stream-types' const log = logger('libp2p:stream:converter') -/** - * @typedef {Object} Timeline - * @property {number} open - - * @property {number} [upgraded] - . - * @property {number} [close] - */ - export interface Timeline { /** * Connection opening timestamp @@ -36,7 +29,7 @@ interface StreamOptions { } interface StreamProperties { - stream: Stream + stream: Duplex remoteAddr: Multiaddr localAddr: Multiaddr } From 208eda446b5867bdf8faf362b4e50a4fb4805865 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 2 Mar 2022 09:11:39 +0000 Subject: [PATCH 058/124] chore(release): 1.0.7 [skip ci] ### [1.0.7](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.6...v1.0.7) (2022-03-02) ### Bug Fixes * pass duplex to stream-to-ma-conn not stream ([#33](https://github.com/libp2p/js-libp2p-utils/issues/33)) ([ebc5c60](https://github.com/libp2p/js-libp2p-utils/commit/ebc5c6074c971e39c6e5c5c51e251aa00c544b50)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82fc5b7877..361858a72e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### [1.0.7](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.6...v1.0.7) (2022-03-02) + + +### Bug Fixes + +* pass duplex to stream-to-ma-conn not stream ([#33](https://github.com/libp2p/js-libp2p-utils/issues/33)) ([ebc5c60](https://github.com/libp2p/js-libp2p-utils/commit/ebc5c6074c971e39c6e5c5c51e251aa00c544b50)) + ### [1.0.6](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.5...v1.0.6) (2022-02-10) diff --git a/package.json b/package.json index b1b7b1861a..6da83e1a19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "1.0.6", + "version": "1.0.7", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From 90cc6f563c8640ba52ebfe2f8794999664ccd7eb Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Thu, 3 Mar 2022 15:26:34 +0000 Subject: [PATCH 059/124] fix: correct update path for stream-to-ma-conn (#34) The path was wrong. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6da83e1a19..85649d51f2 100644 --- a/package.json +++ b/package.json @@ -64,8 +64,8 @@ "types": "./dist/src/multiaddr/is-private.d.ts" }, "./stream-to-ma-conn": { - "import": "./dist/src/stream-to-ma-connr.js", - "types": "./dist/src/stream-to-ma-connr.d.ts" + "import": "./dist/src/stream-to-ma-conn.js", + "types": "./dist/src/stream-to-ma-conn.d.ts" } }, "eslintConfig": { From 9a163b2e2b59a2ccc4a1eaca282a586be7516663 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 3 Mar 2022 15:30:58 +0000 Subject: [PATCH 060/124] chore(release): 1.0.8 [skip ci] ### [1.0.8](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.7...v1.0.8) (2022-03-03) ### Bug Fixes * correct update path for stream-to-ma-conn ([#34](https://github.com/libp2p/js-libp2p-utils/issues/34)) ([90cc6f5](https://github.com/libp2p/js-libp2p-utils/commit/90cc6f563c8640ba52ebfe2f8794999664ccd7eb)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 361858a72e..542fbf2d88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### [1.0.8](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.7...v1.0.8) (2022-03-03) + + +### Bug Fixes + +* correct update path for stream-to-ma-conn ([#34](https://github.com/libp2p/js-libp2p-utils/issues/34)) ([90cc6f5](https://github.com/libp2p/js-libp2p-utils/commit/90cc6f563c8640ba52ebfe2f8794999664ccd7eb)) + ### [1.0.7](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.6...v1.0.7) (2022-03-02) diff --git a/package.json b/package.json index 85649d51f2..f2aae3e3b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "1.0.7", + "version": "1.0.8", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From 71d0cd7c0fc1525de0f95390b9a1996d1166aaac Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Tue, 15 Mar 2022 09:32:36 +0100 Subject: [PATCH 061/124] sync: update CI config files (#31) Co-authored-by: web3-bot --- .github/workflows/automerge.yml | 53 +++++++++++++++++++++++ .github/workflows/js-test-and-release.yml | 3 ++ 2 files changed, 56 insertions(+) create mode 100644 .github/workflows/automerge.yml diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml new file mode 100644 index 0000000000..44fad65fc1 --- /dev/null +++ b/.github/workflows/automerge.yml @@ -0,0 +1,53 @@ +# File managed by web3-bot. DO NOT EDIT. +# See https://github.com/protocol/.github/ for details. + +# Automatically merge pull requests opened by web3-bot, as soon as (and only if) all tests pass. +# This reduces the friction associated with updating with our workflows. + +on: [ pull_request ] +name: Automerge + +jobs: + automerge-check: + if: github.event.pull_request.user.login == 'web3-bot' + runs-on: ubuntu-latest + outputs: + status: ${{ steps.should-automerge.outputs.status }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Check if we should automerge + id: should-automerge + run: | + for commit in $(git rev-list --first-parent origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }}); do + committer=$(git show --format=$'%ce' -s $commit) + echo "Committer: $committer" + if [[ "$committer" != "web3-bot@users.noreply.github.com" ]]; then + echo "Commit $commit wasn't committed by web3-bot, but by $committer." + echo "::set-output name=status::false" + exit + fi + done + echo "::set-output name=status::true" + automerge: + needs: automerge-check + runs-on: ubuntu-latest + # The check for the user is redundant here, as this job depends on the automerge-check job, + # but it prevents this job from spinning up, just to be skipped shortly after. + if: github.event.pull_request.user.login == 'web3-bot' && needs.automerge-check.outputs.status == 'true' + steps: + - name: Wait on tests + uses: lewagon/wait-on-check-action@bafe56a6863672c681c3cf671f5e10b20abf2eaa # v0.2 + with: + ref: ${{ github.event.pull_request.head.sha }} + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 10 + running-workflow-name: 'automerge' # the name of this job + - name: Merge PR + uses: pascalgn/automerge-action@741c311a47881be9625932b0a0de1b0937aab1ae # v0.13.1 + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + MERGE_LABELS: "" + MERGE_METHOD: "squash" + MERGE_DELETE_BRANCH: true diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index 8630dc5c3a..1d6c6ebe6b 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -1,3 +1,6 @@ +# File managed by web3-bot. DO NOT EDIT. +# See https://github.com/protocol/.github/ for details. + name: test & maybe release on: push: From 8d4e3d6f1b56d24e4e58df16ded87d3ca4f82a3f Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Tue, 15 Mar 2022 08:34:34 +0000 Subject: [PATCH 062/124] fix: refactor address sort to be a regular sort function (#35) Instead of taking a list of addresses and sorting them, refactor the `publicAddressesFirst` function to be one that you can pass to `Array.sort` and friends. --- src/address-sort.ts | 19 +++---------------- test/address-sort.spec.ts | 4 ++-- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/address-sort.ts b/src/address-sort.ts index 64583a29df..9210777fec 100644 --- a/src/address-sort.ts +++ b/src/address-sort.ts @@ -1,17 +1,12 @@ -import type { Multiaddr } from '@multiformats/multiaddr' +import type { Address } from '@libp2p/interfaces/peer-store' import { isPrivate } from './multiaddr/is-private.js' -interface Address { - multiaddr: Multiaddr - isCertified: boolean -} - /** * Compare function for array.sort(). - * This sort aims to move the private adresses to the end of the array. + * This sort aims to move the private addresses to the end of the array. * In case of equality, a certified address will come first. */ -function addressesPublicFirstCompareFunction (a: Address, b: Address) { +export function publicAddressesFirst (a: Address, b: Address): -1 | 0 | 1 { const isAPrivate = isPrivate(a.multiaddr) const isBPrivate = isPrivate(b.multiaddr) @@ -29,11 +24,3 @@ function addressesPublicFirstCompareFunction (a: Address, b: Address) { return 0 } - -/** - * Sort given addresses by putting public addresses first. - * In case of equality, a certified address will come first. - */ -export function publicAddressesFirst (addresses: Address[]) { - return [...addresses].sort(addressesPublicFirstCompareFunction) -} diff --git a/test/address-sort.spec.ts b/test/address-sort.spec.ts index 06bdeff4c1..eb7aaf4150 100644 --- a/test/address-sort.spec.ts +++ b/test/address-sort.spec.ts @@ -21,7 +21,7 @@ describe('address-sort', () => { } ] - const sortedAddresses = publicAddressesFirst(addresses) + const sortedAddresses = addresses.sort(publicAddressesFirst) expect(sortedAddresses[0].multiaddr.equals(new Multiaddr('/ip4/30.0.0.1/tcp/4000'))).to.eql(true) expect(sortedAddresses[1].multiaddr.equals(new Multiaddr('/ip4/31.0.0.1/tcp/4000'))).to.eql(true) expect(sortedAddresses[2].multiaddr.equals(new Multiaddr('/ip4/127.0.0.1/tcp/4000'))).to.eql(true) @@ -43,7 +43,7 @@ describe('address-sort', () => { } ] - const sortedAddresses = publicAddressesFirst(addresses) + const sortedAddresses = addresses.sort(publicAddressesFirst) expect(sortedAddresses[0].multiaddr.equals(new Multiaddr('/ip4/31.0.0.1/tcp/4000'))).to.eql(true) expect(sortedAddresses[1].multiaddr.equals(new Multiaddr('/ip4/30.0.0.1/tcp/4000'))).to.eql(true) expect(sortedAddresses[2].multiaddr.equals(new Multiaddr('/ip4/127.0.0.1/tcp/4000'))).to.eql(true) From b7e2b31b1b447961294f7fffba481169a00201cf Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 15 Mar 2022 08:39:37 +0000 Subject: [PATCH 063/124] chore(release): 1.0.9 [skip ci] ### [1.0.9](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.8...v1.0.9) (2022-03-15) ### Bug Fixes * refactor address sort to be a regular sort function ([#35](https://github.com/libp2p/js-libp2p-utils/issues/35)) ([8d4e3d6](https://github.com/libp2p/js-libp2p-utils/commit/8d4e3d6f1b56d24e4e58df16ded87d3ca4f82a3f)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 542fbf2d88..fd9083bf9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### [1.0.9](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.8...v1.0.9) (2022-03-15) + + +### Bug Fixes + +* refactor address sort to be a regular sort function ([#35](https://github.com/libp2p/js-libp2p-utils/issues/35)) ([8d4e3d6](https://github.com/libp2p/js-libp2p-utils/commit/8d4e3d6f1b56d24e4e58df16ded87d3ca4f82a3f)) + ### [1.0.8](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.7...v1.0.8) (2022-03-03) diff --git a/package.json b/package.json index f2aae3e3b7..12f180ebee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "1.0.8", + "version": "1.0.9", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From 608156fde78c16e5c8afd720322e3ba9d43e894f Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Mon, 4 Apr 2022 13:09:03 +0200 Subject: [PATCH 064/124] update .github/workflows/js-test-and-release.yml (#36) --- .github/workflows/js-test-and-release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index 1d6c6ebe6b..77e6b16b82 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -5,10 +5,10 @@ name: test & maybe release on: push: branches: - - master # with #262 - ${{{ github.default_branch }}} + - $default-branch # with #262 - ${{{ github.default_branch }}} pull_request: branches: - - master # with #262 - ${{{ github.default_branch }}} + - $default-branch # with #262 - ${{{ github.default_branch }}} jobs: @@ -136,7 +136,7 @@ jobs: release: needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer] runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/master' # with #262 - 'refs/heads/${{{ github.default_branch }}}' + if: github.event_name == 'push' && github.ref == 'refs/heads/$default-branch' # with #262 - 'refs/heads/${{{ github.default_branch }}}' steps: - uses: actions/checkout@v2 with: From 3ec5ad1751bb4ce44076c6ed07163f019837cf36 Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Mon, 4 Apr 2022 18:57:13 +0200 Subject: [PATCH 065/124] sync: update CI config files (#37) --- .github/workflows/automerge.yml | 50 ++--------------------- .github/workflows/js-test-and-release.yml | 6 +-- 2 files changed, 7 insertions(+), 49 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 44fad65fc1..3833fc2291 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -1,53 +1,11 @@ # File managed by web3-bot. DO NOT EDIT. # See https://github.com/protocol/.github/ for details. -# Automatically merge pull requests opened by web3-bot, as soon as (and only if) all tests pass. -# This reduces the friction associated with updating with our workflows. - -on: [ pull_request ] name: Automerge +on: [ pull_request ] jobs: - automerge-check: - if: github.event.pull_request.user.login == 'web3-bot' - runs-on: ubuntu-latest - outputs: - status: ${{ steps.should-automerge.outputs.status }} - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Check if we should automerge - id: should-automerge - run: | - for commit in $(git rev-list --first-parent origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }}); do - committer=$(git show --format=$'%ce' -s $commit) - echo "Committer: $committer" - if [[ "$committer" != "web3-bot@users.noreply.github.com" ]]; then - echo "Commit $commit wasn't committed by web3-bot, but by $committer." - echo "::set-output name=status::false" - exit - fi - done - echo "::set-output name=status::true" automerge: - needs: automerge-check - runs-on: ubuntu-latest - # The check for the user is redundant here, as this job depends on the automerge-check job, - # but it prevents this job from spinning up, just to be skipped shortly after. - if: github.event.pull_request.user.login == 'web3-bot' && needs.automerge-check.outputs.status == 'true' - steps: - - name: Wait on tests - uses: lewagon/wait-on-check-action@bafe56a6863672c681c3cf671f5e10b20abf2eaa # v0.2 - with: - ref: ${{ github.event.pull_request.head.sha }} - repo-token: ${{ secrets.GITHUB_TOKEN }} - wait-interval: 10 - running-workflow-name: 'automerge' # the name of this job - - name: Merge PR - uses: pascalgn/automerge-action@741c311a47881be9625932b0a0de1b0937aab1ae # v0.13.1 - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - MERGE_LABELS: "" - MERGE_METHOD: "squash" - MERGE_DELETE_BRANCH: true + uses: protocol/.github/.github/workflows/automerge.yml@master + with: + job: 'automerge' diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index 77e6b16b82..1d6c6ebe6b 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -5,10 +5,10 @@ name: test & maybe release on: push: branches: - - $default-branch # with #262 - ${{{ github.default_branch }}} + - master # with #262 - ${{{ github.default_branch }}} pull_request: branches: - - $default-branch # with #262 - ${{{ github.default_branch }}} + - master # with #262 - ${{{ github.default_branch }}} jobs: @@ -136,7 +136,7 @@ jobs: release: needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer] runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/$default-branch' # with #262 - 'refs/heads/${{{ github.default_branch }}}' + if: github.event_name == 'push' && github.ref == 'refs/heads/master' # with #262 - 'refs/heads/${{{ github.default_branch }}}' steps: - uses: actions/checkout@v2 with: From 34f1fde4310c6571e90a6d312924146e089b5a9d Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Thu, 7 Apr 2022 14:31:51 +0100 Subject: [PATCH 066/124] chore: update aegir (#39) Updates to the latest aegir, removes boilerplate config that's now been pushed into aegir. --- .gitignore | 1 + package.json | 31 ++++++++++++++++-------------- src/index.ts | 1 + test/address-sort.spec.ts | 2 +- test/array-equals.spec.ts | 2 +- test/ip-port-to-multiaddr.spec.ts | 2 +- test/multiaddr/is-loopback.spec.ts | 2 +- test/multiaddr/is-private.spec.ts | 2 +- test/stream-to-ma-conn.spec.ts | 2 +- tsconfig.json | 4 +--- 10 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 src/index.ts diff --git a/.gitignore b/.gitignore index ce9a4d1190..7d3286a2cd 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ pids # Directory for instrumented libs generated by jscoverage/JSCover lib-cov +.nyc_output # Coverage directory used by tools like istanbul coverage diff --git a/package.json b/package.json index 12f180ebee..484c376445 100644 --- a/package.json +++ b/package.json @@ -156,18 +156,18 @@ ] }, "scripts": { + "clean": "aegir clean", "lint": "aegir lint", - "dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js", - "build": "tsc", - "pretest": "npm run build", - "test": "aegir test -f ./dist/test/*.js -f ./dist/test/**/*.js", - "test:chrome": "npm run test -- -t browser --cov", - "test:chrome-webworker": "npm run test -- -t webworker", - "test:firefox": "npm run test -- -t browser -- --browser firefox", - "test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox", - "test:node": "npm run test -- -t node --cov", - "test:electron-main": "npm run test -- -t electron-main", - "release": "semantic-release" + "dep-check": "aegir dep-check", + "build": "aegir build", + "test": "aegir test", + "test:chrome": "aegir test -t browser --cov", + "test:chrome-webworker": "aegir test -t webworker", + "test:firefox": "aegir test -t browser -- --browser firefox", + "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", + "test:node": "aegir test -t node --cov", + "test:electron-main": "aegir test -t electron-main", + "release": "aegir release" }, "dependencies": { "@achingbrain/ip-address": "^8.1.0", @@ -177,13 +177,16 @@ "err-code": "^3.0.1", "is-loopback-addr": "^2.0.1", "it-stream-types": "^1.0.4", - "private-ip": "^2.1.1" + "private-ip": "^2.1.1", + "ts-mocha": "^9.0.2", + "ts-node": "^10.7.0" }, "devDependencies": { "@libp2p/interfaces": "^1.0.3", - "aegir": "^36.1.2", + "aegir": "^37.0.4", "it-all": "^1.0.6", "it-pair": "^2.0.2", - "it-pipe": "^2.0.2" + "it-pipe": "^2.0.2", + "uint8arrays": "^3.0.0" } } diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000000..336ce12bb9 --- /dev/null +++ b/src/index.ts @@ -0,0 +1 @@ +export {} diff --git a/test/address-sort.spec.ts b/test/address-sort.spec.ts index eb7aaf4150..258b0e23d1 100644 --- a/test/address-sort.spec.ts +++ b/test/address-sort.spec.ts @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { Multiaddr } from '@multiformats/multiaddr' import { publicAddressesFirst } from '../src/address-sort.js' diff --git a/test/array-equals.spec.ts b/test/array-equals.spec.ts index 6aa3977fe0..6d54d23407 100644 --- a/test/array-equals.spec.ts +++ b/test/array-equals.spec.ts @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { Multiaddr } from '@multiformats/multiaddr' import { arrayEquals } from '../src/array-equals.js' diff --git a/test/ip-port-to-multiaddr.spec.ts b/test/ip-port-to-multiaddr.spec.ts index 39e5897fa1..2e1631743f 100644 --- a/test/ip-port-to-multiaddr.spec.ts +++ b/test/ip-port-to-multiaddr.spec.ts @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { ipPortToMultiaddr, Errors } from '../src/ip-port-to-multiaddr.js' describe('IP and port to Multiaddr', () => { diff --git a/test/multiaddr/is-loopback.spec.ts b/test/multiaddr/is-loopback.spec.ts index 443196226c..d8b918cd0d 100644 --- a/test/multiaddr/is-loopback.spec.ts +++ b/test/multiaddr/is-loopback.spec.ts @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { Multiaddr } from '@multiformats/multiaddr' import { isLoopback } from '../../src/multiaddr/is-loopback.js' diff --git a/test/multiaddr/is-private.spec.ts b/test/multiaddr/is-private.spec.ts index dcfe813ed4..3a2070f6cd 100644 --- a/test/multiaddr/is-private.spec.ts +++ b/test/multiaddr/is-private.spec.ts @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { Multiaddr } from '@multiformats/multiaddr' import { isPrivate } from '../../src/multiaddr/is-private.js' diff --git a/test/stream-to-ma-conn.spec.ts b/test/stream-to-ma-conn.spec.ts index 39978d1cf3..0f6888d36f 100644 --- a/test/stream-to-ma-conn.spec.ts +++ b/test/stream-to-ma-conn.spec.ts @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { pair } from 'it-pair' import { pipe } from 'it-pipe' import { Multiaddr } from '@multiformats/multiaddr' diff --git a/tsconfig.json b/tsconfig.json index f296f99426..13a3599639 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,7 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "dist", - "emitDeclarationOnly": false, - "module": "ES2020" + "outDir": "dist" }, "include": [ "src", From 68c8ed1937d9125ccba9b6188e3b99184cda9082 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 7 Apr 2022 13:36:29 +0000 Subject: [PATCH 067/124] chore(release): 1.0.10 [skip ci] ### [1.0.10](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.9...v1.0.10) (2022-04-07) ### Trivial Changes * update aegir ([#39](https://github.com/libp2p/js-libp2p-utils/issues/39)) ([34f1fde](https://github.com/libp2p/js-libp2p-utils/commit/34f1fde4310c6571e90a6d312924146e089b5a9d)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd9083bf9c..0127845ef7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### [1.0.10](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.9...v1.0.10) (2022-04-07) + + +### Trivial Changes + +* update aegir ([#39](https://github.com/libp2p/js-libp2p-utils/issues/39)) ([34f1fde](https://github.com/libp2p/js-libp2p-utils/commit/34f1fde4310c6571e90a6d312924146e089b5a9d)) + ### [1.0.9](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.8...v1.0.9) (2022-03-15) diff --git a/package.json b/package.json index 484c376445..d1279fe01c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "1.0.9", + "version": "1.0.10", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From 8023ab6109186217e1c72139c54c0ed5dbc2144c Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Wed, 1 Jun 2022 11:39:59 +0200 Subject: [PATCH 068/124] update .github/workflows/js-test-and-release.yml (#43) --- .github/workflows/js-test-and-release.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index 1d6c6ebe6b..fb8750529d 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -38,7 +38,7 @@ jobs: node-version: ${{ matrix.node }} - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:node - - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: directory: ./.nyc_output flags: node @@ -53,7 +53,7 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:chrome - - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: directory: ./.nyc_output flags: chrome @@ -68,7 +68,7 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:chrome-webworker - - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: directory: ./.nyc_output flags: chrome-webworker @@ -83,7 +83,7 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:firefox - - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: directory: ./.nyc_output flags: firefox @@ -98,7 +98,7 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:firefox-webworker - - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: directory: ./.nyc_output flags: firefox-webworker @@ -113,7 +113,7 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npx xvfb-maybe npm run --if-present test:electron-main - - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: directory: ./.nyc_output flags: electron-main @@ -128,7 +128,7 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npx xvfb-maybe npm run --if-present test:electron-renderer - - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: directory: ./.nyc_output flags: electron-renderer From 018fbe48f3506c0b90dc88779a3f12a2714ab09c Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 15 Jun 2022 16:25:55 +0100 Subject: [PATCH 069/124] feat!: update libp2p interfaces (#47) BREAKING CHANGE: uses new single-issue libp2p interface modules --- README.md | 49 +++++++++++++++++++----------- package.json | 36 +++++++++++----------- src/address-sort.ts | 2 +- src/stream-to-ma-conn.ts | 2 +- test/address-sort.spec.ts | 26 ++++++++-------- test/array-equals.spec.ts | 48 ++++++++++++++--------------- test/multiaddr/is-loopback.spec.ts | 28 ++++++++--------- test/multiaddr/is-private.spec.ts | 30 +++++++++--------- test/stream-to-ma-conn.spec.ts | 10 +++--- 9 files changed, 124 insertions(+), 107 deletions(-) diff --git a/README.md b/README.md index 564fa57573..a8dbdc76f8 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,30 @@ -# js-libp2p-utils +# @libp2p/utils -[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai) -[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) -[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p) -[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io) -[![](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-utils.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-utils) -[![](https://img.shields.io/travis/libp2p/js-libp2p-utils.svg?style=flat-square)](https://travis-ci.com/libp2p/js-libp2p-utils) -[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-utils.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-utils) -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) +[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) +[![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p) +[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) +[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-utils.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-utils) +[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-utils/actions/workflows/js-test-and-release.yml) -> This package serves as a central repository for shared logic and dependencies for all libp2p packages, using `libp2p-utils` helps to easily re-use small scoped blocks of logic across all libp2p modules and also as a dependency proxy (think `aegir` for domain logic dependencies). +> Package to aggregate shared logic and dependencies for the libp2p ecosystem +## Table of contents + +- [Install](#install) +- [Lead Maintainer](#lead-maintainer) +- [Usage](#usage) +- [Contribute](#contribute) +- [License](#license) +- [Contribution](#contribution) + +## Install + +```console +$ npm i @libp2p/utils +``` The libp2p ecosystem has lots of repos with it comes several problems like: + - Domain logic dedupe - all modules shared a lot of logic like validation, streams handling, etc. - Dependencies management - it's really easy with so many repos for dependencies to go out of control, they become outdated, different repos use different modules to do the same thing (like merging defaults options), browser bundles ends up with multiple versions of the same package, bumping versions is cumbersome to do because we need to go through several repos, etc. @@ -22,14 +34,8 @@ These problems are the motivation for this package, having shared logic in this [Vasco Santos](https://github.com/vasco-santos) -## Install - - -```bash -$ npm install --save @libp2p/utils -``` - ## Usage + Each function should be imported directly. ```js @@ -48,4 +54,11 @@ Check out our [contributing document](https://github.com/ipfs/community/blob/mas ## License -[MIT](LICENSE) © Protocol Labs Inc. +Licensed under either of + +- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](LICENSE-MIT) / ) + +## Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/package.json b/package.json index d1279fe01c..88aac64cea 100644 --- a/package.json +++ b/package.json @@ -41,31 +41,32 @@ ], "exports": { ".": { + "types": "./src/index.d.ts", "import": "./dist/src/index.js" }, "./address-sort": { - "import": "./dist/src/address-sort.js", - "types": "./dist/src/address-sort.d.ts" + "types": "./dist/src/address-sort.d.ts", + "import": "./dist/src/address-sort.js" }, "./array-equals": { - "import": "./dist/src/array-equals.js", - "types": "./dist/src/array-equals.d.ts" + "types": "./dist/src/array-equals.d.ts", + "import": "./dist/src/array-equals.js" }, "./ip-port-to-multiaddr": { - "import": "./dist/src/ip-port-to-multiaddr.js", - "types": "./dist/src/ip-port-to-multiaddr.d.ts" + "types": "./dist/src/ip-port-to-multiaddr.d.ts", + "import": "./dist/src/ip-port-to-multiaddr.js" }, "./multiaddr/is-loopback": { - "import": "./dist/src/multiaddr/is-loopback.js", - "types": "./dist/src/multiaddr/is-loopback.d.ts" + "types": "./dist/src/multiaddr/is-loopback.d.ts", + "import": "./dist/src/multiaddr/is-loopback.js" }, "./multiaddr/is-private": { - "import": "./dist/src/multiaddr/is-private.js", - "types": "./dist/src/multiaddr/is-private.d.ts" + "types": "./dist/src/multiaddr/is-private.d.ts", + "import": "./dist/src/multiaddr/is-private.js" }, "./stream-to-ma-conn": { - "import": "./dist/src/stream-to-ma-conn.js", - "types": "./dist/src/stream-to-ma-conn.d.ts" + "types": "./dist/src/stream-to-ma-conn.d.ts", + "import": "./dist/src/stream-to-ma-conn.js" } }, "eslintConfig": { @@ -171,19 +172,20 @@ }, "dependencies": { "@achingbrain/ip-address": "^8.1.0", - "@libp2p/logger": "^1.0.1", + "@libp2p/interface-connection": "^1.0.1", + "@libp2p/interface-peer-store": "^1.0.0", + "@libp2p/interface-transport": "^1.0.0", + "@libp2p/logger": "^2.0.0", "@multiformats/multiaddr": "^10.1.1", "abortable-iterator": "^4.0.2", "err-code": "^3.0.1", "is-loopback-addr": "^2.0.1", "it-stream-types": "^1.0.4", - "private-ip": "^2.1.1", - "ts-mocha": "^9.0.2", - "ts-node": "^10.7.0" + "private-ip": "^2.1.1" }, "devDependencies": { "@libp2p/interfaces": "^1.0.3", - "aegir": "^37.0.4", + "aegir": "^37.2.0", "it-all": "^1.0.6", "it-pair": "^2.0.2", "it-pipe": "^2.0.2", diff --git a/src/address-sort.ts b/src/address-sort.ts index 9210777fec..1cf3cb3d6c 100644 --- a/src/address-sort.ts +++ b/src/address-sort.ts @@ -1,4 +1,4 @@ -import type { Address } from '@libp2p/interfaces/peer-store' +import type { Address } from '@libp2p/interface-peer-store' import { isPrivate } from './multiaddr/is-private.js' /** diff --git a/src/stream-to-ma-conn.ts b/src/stream-to-ma-conn.ts index c819dbf60d..fd6f837448 100644 --- a/src/stream-to-ma-conn.ts +++ b/src/stream-to-ma-conn.ts @@ -1,7 +1,7 @@ import { abortableSource } from 'abortable-iterator' import { logger } from '@libp2p/logger' import type { Multiaddr } from '@multiformats/multiaddr' -import type { MultiaddrConnection } from '@libp2p/interfaces/transport' +import type { MultiaddrConnection } from '@libp2p/interface-connection' import type { Duplex } from 'it-stream-types' const log = logger('libp2p:stream:converter') diff --git a/test/address-sort.spec.ts b/test/address-sort.spec.ts index 258b0e23d1..2c20ca4316 100644 --- a/test/address-sort.spec.ts +++ b/test/address-sort.spec.ts @@ -1,51 +1,51 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import { publicAddressesFirst } from '../src/address-sort.js' describe('address-sort', () => { it('should sort public addresses first', () => { const addresses = [ { - multiaddr: new Multiaddr('/ip4/127.0.0.1/tcp/4000'), + multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4000'), isCertified: false }, { - multiaddr: new Multiaddr('/ip4/30.0.0.1/tcp/4000'), + multiaddr: multiaddr('/ip4/30.0.0.1/tcp/4000'), isCertified: false }, { - multiaddr: new Multiaddr('/ip4/31.0.0.1/tcp/4000'), + multiaddr: multiaddr('/ip4/31.0.0.1/tcp/4000'), isCertified: false } ] const sortedAddresses = addresses.sort(publicAddressesFirst) - expect(sortedAddresses[0].multiaddr.equals(new Multiaddr('/ip4/30.0.0.1/tcp/4000'))).to.eql(true) - expect(sortedAddresses[1].multiaddr.equals(new Multiaddr('/ip4/31.0.0.1/tcp/4000'))).to.eql(true) - expect(sortedAddresses[2].multiaddr.equals(new Multiaddr('/ip4/127.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[0].multiaddr.equals(multiaddr('/ip4/30.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[1].multiaddr.equals(multiaddr('/ip4/31.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[2].multiaddr.equals(multiaddr('/ip4/127.0.0.1/tcp/4000'))).to.eql(true) }) it('should sort public certified addresses first', () => { const addresses = [ { - multiaddr: new Multiaddr('/ip4/127.0.0.1/tcp/4000'), + multiaddr: multiaddr('/ip4/127.0.0.1/tcp/4000'), isCertified: false }, { - multiaddr: new Multiaddr('/ip4/30.0.0.1/tcp/4000'), + multiaddr: multiaddr('/ip4/30.0.0.1/tcp/4000'), isCertified: false }, { - multiaddr: new Multiaddr('/ip4/31.0.0.1/tcp/4000'), + multiaddr: multiaddr('/ip4/31.0.0.1/tcp/4000'), isCertified: true } ] const sortedAddresses = addresses.sort(publicAddressesFirst) - expect(sortedAddresses[0].multiaddr.equals(new Multiaddr('/ip4/31.0.0.1/tcp/4000'))).to.eql(true) - expect(sortedAddresses[1].multiaddr.equals(new Multiaddr('/ip4/30.0.0.1/tcp/4000'))).to.eql(true) - expect(sortedAddresses[2].multiaddr.equals(new Multiaddr('/ip4/127.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[0].multiaddr.equals(multiaddr('/ip4/31.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[1].multiaddr.equals(multiaddr('/ip4/30.0.0.1/tcp/4000'))).to.eql(true) + expect(sortedAddresses[2].multiaddr.equals(multiaddr('/ip4/127.0.0.1/tcp/4000'))).to.eql(true) }) }) diff --git a/test/array-equals.spec.ts b/test/array-equals.spec.ts index 6d54d23407..8de93ab0ea 100644 --- a/test/array-equals.spec.ts +++ b/test/array-equals.spec.ts @@ -1,21 +1,21 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import { arrayEquals } from '../src/array-equals.js' describe('non primitive array equals', () => { it('returns true if two arrays of multiaddrs are equal', () => { const a = [ - new Multiaddr('/ip4/127.0.0.1/tcp/8000'), - new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - new Multiaddr('/dns4/test.libp2p.io') + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/dns4/test.libp2p.io') ] const b = [ - new Multiaddr('/ip4/127.0.0.1/tcp/8000'), - new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - new Multiaddr('/dns4/test.libp2p.io') + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/dns4/test.libp2p.io') ] expect(arrayEquals(a, b)).to.eql(true) @@ -23,15 +23,15 @@ describe('non primitive array equals', () => { it('returns true if two arrays of multiaddrs have the same content but different orders', () => { const a = [ - new Multiaddr('/ip4/127.0.0.1/tcp/8000'), - new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - new Multiaddr('/dns4/test.libp2p.io') + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/dns4/test.libp2p.io') ] const b = [ - new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - new Multiaddr('/ip4/127.0.0.1/tcp/8000'), - new Multiaddr('/dns4/test.libp2p.io') + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/dns4/test.libp2p.io') ] expect(arrayEquals(a, b)).to.eql(true) @@ -39,15 +39,15 @@ describe('non primitive array equals', () => { it('returns false if two arrays of multiaddrs are different', () => { const a = [ - new Multiaddr('/ip4/127.0.0.1/tcp/8000'), - new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - new Multiaddr('/dns4/test.libp2p.io') + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/dns4/test.libp2p.io') ] const b = [ - new Multiaddr('/ip4/127.0.0.1/tcp/8001'), - new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - new Multiaddr('/dns4/test.libp2p.io') + multiaddr('/ip4/127.0.0.1/tcp/8001'), + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/dns4/test.libp2p.io') ] expect(arrayEquals(a, b)).to.eql(false) @@ -55,14 +55,14 @@ describe('non primitive array equals', () => { it('returns false if two arrays of multiaddrs are partially equal, but different lengths', () => { const a = [ - new Multiaddr('/ip4/127.0.0.1/tcp/8000'), - new Multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), - new Multiaddr('/dns4/test.libp2p.io') + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/ip4/127.0.0.1/tcp/3000/ws'), + multiaddr('/dns4/test.libp2p.io') ] const b = [ - new Multiaddr('/ip4/127.0.0.1/tcp/8000'), - new Multiaddr('/dns4/test.libp2p.io') + multiaddr('/ip4/127.0.0.1/tcp/8000'), + multiaddr('/dns4/test.libp2p.io') ] expect(arrayEquals(a, b)).to.eql(false) diff --git a/test/multiaddr/is-loopback.spec.ts b/test/multiaddr/is-loopback.spec.ts index d8b918cd0d..cafed69fe1 100644 --- a/test/multiaddr/is-loopback.spec.ts +++ b/test/multiaddr/is-loopback.spec.ts @@ -1,16 +1,16 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import { isLoopback } from '../../src/multiaddr/is-loopback.js' describe('multiaddr isLoopback', () => { it('identifies loopback ip4 multiaddrs', () => { [ - new Multiaddr('/ip4/127.0.0.1/tcp/1000'), - new Multiaddr('/ip4/127.0.1.1/tcp/1000'), - new Multiaddr('/ip4/127.1.1.1/tcp/1000'), - new Multiaddr('/ip4/127.255.255.255/tcp/1000') + multiaddr('/ip4/127.0.0.1/tcp/1000'), + multiaddr('/ip4/127.0.1.1/tcp/1000'), + multiaddr('/ip4/127.1.1.1/tcp/1000'), + multiaddr('/ip4/127.255.255.255/tcp/1000') ].forEach(ma => { expect(isLoopback(ma)).to.eql(true) }) @@ -18,10 +18,10 @@ describe('multiaddr isLoopback', () => { it('identifies non loopback ip4 multiaddrs', () => { [ - new Multiaddr('/ip4/101.0.26.90/tcp/1000'), - new Multiaddr('/ip4/10.0.0.1/tcp/1000'), - new Multiaddr('/ip4/192.168.0.1/tcp/1000'), - new Multiaddr('/ip4/172.16.0.1/tcp/1000') + multiaddr('/ip4/101.0.26.90/tcp/1000'), + multiaddr('/ip4/10.0.0.1/tcp/1000'), + multiaddr('/ip4/192.168.0.1/tcp/1000'), + multiaddr('/ip4/172.16.0.1/tcp/1000') ].forEach(ma => { expect(isLoopback(ma)).to.eql(false) }) @@ -29,7 +29,7 @@ describe('multiaddr isLoopback', () => { it('identifies loopback ip6 multiaddrs', () => { [ - new Multiaddr('/ip6/::1/tcp/1000') + multiaddr('/ip6/::1/tcp/1000') ].forEach(ma => { expect(isLoopback(ma)).to.eql(true) }) @@ -37,8 +37,8 @@ describe('multiaddr isLoopback', () => { it('identifies non loopback ip6 multiaddrs', () => { [ - new Multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'), - new Multiaddr('/ip6/::/tcp/1000') + multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'), + multiaddr('/ip6/::/tcp/1000') ].forEach(ma => { expect(isLoopback(ma)).to.eql(false) }) @@ -46,8 +46,8 @@ describe('multiaddr isLoopback', () => { it('identifies other multiaddrs as not loopback addresses', () => { [ - new Multiaddr('/dns4/wss0.bootstrap.libp2p.io/tcp/443'), - new Multiaddr('/dns6/wss0.bootstrap.libp2p.io/tcp/443') + multiaddr('/dns4/wss0.bootstrap.libp2p.io/tcp/443'), + multiaddr('/dns6/wss0.bootstrap.libp2p.io/tcp/443') ].forEach(ma => { expect(isLoopback(ma)).to.eql(false) }) diff --git a/test/multiaddr/is-private.spec.ts b/test/multiaddr/is-private.spec.ts index 3a2070f6cd..073c416f11 100644 --- a/test/multiaddr/is-private.spec.ts +++ b/test/multiaddr/is-private.spec.ts @@ -1,16 +1,16 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import { isPrivate } from '../../src/multiaddr/is-private.js' describe('multiaddr isPrivate', () => { it('identifies private ip4 multiaddrs', () => { [ - new Multiaddr('/ip4/127.0.0.1/tcp/1000'), - new Multiaddr('/ip4/10.0.0.1/tcp/1000'), - new Multiaddr('/ip4/192.168.0.1/tcp/1000'), - new Multiaddr('/ip4/172.16.0.1/tcp/1000') + multiaddr('/ip4/127.0.0.1/tcp/1000'), + multiaddr('/ip4/10.0.0.1/tcp/1000'), + multiaddr('/ip4/192.168.0.1/tcp/1000'), + multiaddr('/ip4/172.16.0.1/tcp/1000') ].forEach(ma => { expect(isPrivate(ma)).to.eql(true) }) @@ -18,10 +18,10 @@ describe('multiaddr isPrivate', () => { it('identifies public ip4 multiaddrs', () => { [ - new Multiaddr('/ip4/101.0.26.90/tcp/1000'), - new Multiaddr('/ip4/40.1.20.9/tcp/1000'), - new Multiaddr('/ip4/92.168.0.1/tcp/1000'), - new Multiaddr('/ip4/2.16.0.1/tcp/1000') + multiaddr('/ip4/101.0.26.90/tcp/1000'), + multiaddr('/ip4/40.1.20.9/tcp/1000'), + multiaddr('/ip4/92.168.0.1/tcp/1000'), + multiaddr('/ip4/2.16.0.1/tcp/1000') ].forEach(ma => { expect(isPrivate(ma)).to.eql(false) }) @@ -29,8 +29,8 @@ describe('multiaddr isPrivate', () => { it('identifies private ip6 multiaddrs', () => { [ - new Multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:7095/tcp/1000'), - new Multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:1/tcp/1000') + multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:7095/tcp/1000'), + multiaddr('/ip6/fd52:8342:fc46:6c91:3ac9:86ff:fe31:1/tcp/1000') ].forEach(ma => { expect(isPrivate(ma)).to.eql(true) }) @@ -38,8 +38,8 @@ describe('multiaddr isPrivate', () => { it('identifies public ip6 multiaddrs', () => { [ - new Multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'), - new Multiaddr('/ip6/2000:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000') + multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000'), + multiaddr('/ip6/2000:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/1000') ].forEach(ma => { expect(isPrivate(ma)).to.eql(false) }) @@ -47,8 +47,8 @@ describe('multiaddr isPrivate', () => { it('identifies other multiaddrs as not private addresses', () => { [ - new Multiaddr('/dns4/wss0.bootstrap.libp2p.io/tcp/443'), - new Multiaddr('/dns6/wss0.bootstrap.libp2p.io/tcp/443') + multiaddr('/dns4/wss0.bootstrap.libp2p.io/tcp/443'), + multiaddr('/dns6/wss0.bootstrap.libp2p.io/tcp/443') ].forEach(ma => { expect(isPrivate(ma)).to.eql(false) }) diff --git a/test/stream-to-ma-conn.spec.ts b/test/stream-to-ma-conn.spec.ts index 0f6888d36f..b49ead3eeb 100644 --- a/test/stream-to-ma-conn.spec.ts +++ b/test/stream-to-ma-conn.spec.ts @@ -3,17 +3,19 @@ import { expect } from 'aegir/chai' import { pair } from 'it-pair' import { pipe } from 'it-pipe' -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import { streamToMaConnection } from '../src/stream-to-ma-conn.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import all from 'it-all' -import type { Stream } from '@libp2p/interfaces/connection' +import type { Stream } from '@libp2p/interface-connection' import type { Duplex } from 'it-stream-types' function toMuxedStream (stream: Duplex) { const muxedStream: Stream = { ...stream, close: () => {}, + closeRead: () => {}, + closeWrite: () => {}, abort: () => {}, reset: () => {}, timeline: { @@ -26,8 +28,8 @@ function toMuxedStream (stream: Duplex) { } describe('Convert stream into a multiaddr connection', () => { - const localAddr = new Multiaddr('/ip4/101.45.75.219/tcp/6000') - const remoteAddr = new Multiaddr('/ip4/100.46.74.201/tcp/6002') + const localAddr = multiaddr('/ip4/101.45.75.219/tcp/6000') + const remoteAddr = multiaddr('/ip4/100.46.74.201/tcp/6002') it('converts a stream and adds the provided metadata', async () => { const stream = pair() From ad6645ac71a480b2b7848b6be68a09aebe10f5d7 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 15 Jun 2022 15:51:10 +0000 Subject: [PATCH 070/124] chore(release): 2.0.0 [skip ci] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [2.0.0](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.10...v2.0.0) (2022-06-15) ### ⚠ BREAKING CHANGES * uses new single-issue libp2p interface modules ### Features * update libp2p interfaces ([#47](https://github.com/libp2p/js-libp2p-utils/issues/47)) ([018fbe4](https://github.com/libp2p/js-libp2p-utils/commit/018fbe48f3506c0b90dc88779a3f12a2714ab09c)) --- CHANGELOG.md | 11 +++++++++++ package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0127845ef7..83a20e1dd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## [2.0.0](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.10...v2.0.0) (2022-06-15) + + +### ⚠ BREAKING CHANGES + +* uses new single-issue libp2p interface modules + +### Features + +* update libp2p interfaces ([#47](https://github.com/libp2p/js-libp2p-utils/issues/47)) ([018fbe4](https://github.com/libp2p/js-libp2p-utils/commit/018fbe48f3506c0b90dc88779a3f12a2714ab09c)) + ### [1.0.10](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.9...v1.0.10) (2022-04-07) diff --git a/package.json b/package.json index 88aac64cea..c8951a78f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "1.0.10", + "version": "2.0.0", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From ac20ed891fc316e05cca10efad1215860cb9fe09 Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Thu, 16 Jun 2022 15:18:29 +0200 Subject: [PATCH 071/124] update .github/workflows/js-test-and-release.yml (#48) --- .github/workflows/js-test-and-release.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index fb8750529d..8030ec6520 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -40,7 +40,6 @@ jobs: - run: npm run --if-present test:node - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: - directory: ./.nyc_output flags: node test-chrome: @@ -55,7 +54,6 @@ jobs: - run: npm run --if-present test:chrome - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: - directory: ./.nyc_output flags: chrome test-chrome-webworker: @@ -70,7 +68,6 @@ jobs: - run: npm run --if-present test:chrome-webworker - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: - directory: ./.nyc_output flags: chrome-webworker test-firefox: @@ -85,7 +82,6 @@ jobs: - run: npm run --if-present test:firefox - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: - directory: ./.nyc_output flags: firefox test-firefox-webworker: @@ -100,7 +96,6 @@ jobs: - run: npm run --if-present test:firefox-webworker - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: - directory: ./.nyc_output flags: firefox-webworker test-electron-main: @@ -115,7 +110,6 @@ jobs: - run: npx xvfb-maybe npm run --if-present test:electron-main - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: - directory: ./.nyc_output flags: electron-main test-electron-renderer: @@ -130,7 +124,6 @@ jobs: - run: npx xvfb-maybe npm run --if-present test:electron-renderer - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: - directory: ./.nyc_output flags: electron-renderer release: From 8f339c9a50b466d65b41492abfd1bd88ffa0a38c Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Mon, 27 Jun 2022 12:15:47 +0100 Subject: [PATCH 072/124] chore: remove unused deps (#52) These deps are unused so are not necessary --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index c8951a78f0..60b2ca1d35 100644 --- a/package.json +++ b/package.json @@ -174,7 +174,6 @@ "@achingbrain/ip-address": "^8.1.0", "@libp2p/interface-connection": "^1.0.1", "@libp2p/interface-peer-store": "^1.0.0", - "@libp2p/interface-transport": "^1.0.0", "@libp2p/logger": "^2.0.0", "@multiformats/multiaddr": "^10.1.1", "abortable-iterator": "^4.0.2", @@ -184,7 +183,6 @@ "private-ip": "^2.1.1" }, "devDependencies": { - "@libp2p/interfaces": "^1.0.3", "aegir": "^37.2.0", "it-all": "^1.0.6", "it-pair": "^2.0.2", From 786a7128b54cb59c15a7e3f8ac24a665dec53d20 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 27 Jun 2022 11:19:44 +0000 Subject: [PATCH 073/124] chore(release): 2.0.1 [skip ci] ## [2.0.1](https://github.com/libp2p/js-libp2p-utils/compare/v2.0.0...v2.0.1) (2022-06-27) ### Trivial Changes * remove unused deps ([#52](https://github.com/libp2p/js-libp2p-utils/issues/52)) ([8f339c9](https://github.com/libp2p/js-libp2p-utils/commit/8f339c9a50b466d65b41492abfd1bd88ffa0a38c)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83a20e1dd4..83837c5798 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.0.1](https://github.com/libp2p/js-libp2p-utils/compare/v2.0.0...v2.0.1) (2022-06-27) + + +### Trivial Changes + +* remove unused deps ([#52](https://github.com/libp2p/js-libp2p-utils/issues/52)) ([8f339c9](https://github.com/libp2p/js-libp2p-utils/commit/8f339c9a50b466d65b41492abfd1bd88ffa0a38c)) + ## [2.0.0](https://github.com/libp2p/js-libp2p-utils/compare/v1.0.10...v2.0.0) (2022-06-15) diff --git a/package.json b/package.json index 60b2ca1d35..71eaa9e07c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "2.0.0", + "version": "2.0.1", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From 0f99bf833f7732d74eac4a06fd2b607555c7f34b Mon Sep 17 00:00:00 2001 From: Franck R Date: Mon, 27 Jun 2022 21:23:39 +1000 Subject: [PATCH 074/124] chore(deps)!: bump @libp2p/interface-connection from 1.0.1 to 2.1.0 (#51) BREAKING CHANGE: the API of the returned MultiaddrConnection has changed --- package.json | 2 +- test/stream-to-ma-conn.spec.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 71eaa9e07c..500f371205 100644 --- a/package.json +++ b/package.json @@ -172,7 +172,7 @@ }, "dependencies": { "@achingbrain/ip-address": "^8.1.0", - "@libp2p/interface-connection": "^1.0.1", + "@libp2p/interface-connection": "^2.1.0", "@libp2p/interface-peer-store": "^1.0.0", "@libp2p/logger": "^2.0.0", "@multiformats/multiaddr": "^10.1.1", diff --git a/test/stream-to-ma-conn.spec.ts b/test/stream-to-ma-conn.spec.ts index b49ead3eeb..7f6510fe24 100644 --- a/test/stream-to-ma-conn.spec.ts +++ b/test/stream-to-ma-conn.spec.ts @@ -18,9 +18,13 @@ function toMuxedStream (stream: Duplex) { closeWrite: () => {}, abort: () => {}, reset: () => {}, - timeline: { - open: Date.now() + stat: { + direction: 'outbound', + timeline: { + open: Date.now() + } }, + metadata: {}, id: `muxed-stream-${Math.random()}` } From b1a68a23df19a595d3d12f174f57e822763bca04 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 27 Jun 2022 11:28:01 +0000 Subject: [PATCH 075/124] chore(release): 3.0.0 [skip ci] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [3.0.0](https://github.com/libp2p/js-libp2p-utils/compare/v2.0.1...v3.0.0) (2022-06-27) ### ⚠ BREAKING CHANGES * **deps:** the API of the returned MultiaddrConnection has changed ### Trivial Changes * **deps:** bump @libp2p/interface-connection from 1.0.1 to 2.1.0 ([#51](https://github.com/libp2p/js-libp2p-utils/issues/51)) ([0f99bf8](https://github.com/libp2p/js-libp2p-utils/commit/0f99bf833f7732d74eac4a06fd2b607555c7f34b)) --- CHANGELOG.md | 11 +++++++++++ package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83837c5798..bf111c20bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## [3.0.0](https://github.com/libp2p/js-libp2p-utils/compare/v2.0.1...v3.0.0) (2022-06-27) + + +### ⚠ BREAKING CHANGES + +* **deps:** the API of the returned MultiaddrConnection has changed + +### Trivial Changes + +* **deps:** bump @libp2p/interface-connection from 1.0.1 to 2.1.0 ([#51](https://github.com/libp2p/js-libp2p-utils/issues/51)) ([0f99bf8](https://github.com/libp2p/js-libp2p-utils/commit/0f99bf833f7732d74eac4a06fd2b607555c7f34b)) + ## [2.0.1](https://github.com/libp2p/js-libp2p-utils/compare/v2.0.0...v2.0.1) (2022-06-27) diff --git a/package.json b/package.json index 500f371205..e59cf7752f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "2.0.1", + "version": "3.0.0", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From 134c633f107247ce309ed7da3a29f872615ee920 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 10 Aug 2022 12:11:23 +0100 Subject: [PATCH 076/124] fix: update deps (#55) --- package.json | 7 +++++-- src/stream-to-ma-conn.ts | 12 ++++++++++-- test/fixtures/pair.ts | 28 ++++++++++++++++++++++++++++ test/stream-to-ma-conn.spec.ts | 9 +++++---- 4 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/pair.ts diff --git a/package.json b/package.json index e59cf7752f..d4040e276c 100644 --- a/package.json +++ b/package.json @@ -172,7 +172,7 @@ }, "dependencies": { "@achingbrain/ip-address": "^8.1.0", - "@libp2p/interface-connection": "^2.1.0", + "@libp2p/interface-connection": "^3.0.1", "@libp2p/interface-peer-store": "^1.0.0", "@libp2p/logger": "^2.0.0", "@multiformats/multiaddr": "^10.1.1", @@ -180,13 +180,16 @@ "err-code": "^3.0.1", "is-loopback-addr": "^2.0.1", "it-stream-types": "^1.0.4", - "private-ip": "^2.1.1" + "private-ip": "^2.1.1", + "uint8arraylist": "^2.3.2" }, "devDependencies": { "aegir": "^37.2.0", "it-all": "^1.0.6", + "it-map": "^1.0.6", "it-pair": "^2.0.2", "it-pipe": "^2.0.2", + "p-defer": "^4.0.0", "uint8arrays": "^3.0.0" } } diff --git a/src/stream-to-ma-conn.ts b/src/stream-to-ma-conn.ts index fd6f837448..cbce121369 100644 --- a/src/stream-to-ma-conn.ts +++ b/src/stream-to-ma-conn.ts @@ -3,6 +3,7 @@ import { logger } from '@libp2p/logger' import type { Multiaddr } from '@multiformats/multiaddr' import type { MultiaddrConnection } from '@libp2p/interface-connection' import type { Duplex } from 'it-stream-types' +import type { Uint8ArrayList } from 'uint8arraylist' const log = logger('libp2p:stream:converter') @@ -29,7 +30,7 @@ interface StreamOptions { } interface StreamProperties { - stream: Duplex + stream: Duplex remoteAddr: Multiaddr localAddr: Multiaddr } @@ -41,6 +42,13 @@ interface StreamProperties { export function streamToMaConnection (props: StreamProperties, options: StreamOptions = {}) { const { stream, remoteAddr } = props const { sink, source } = stream + + const mapSource = (async function * () { + for await (const list of source) { + yield * list + } + }()) + const maConn: MultiaddrConnection = { async sink (source) { if (options.signal != null) { @@ -60,7 +68,7 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp } } }, - source: (options.signal != null) ? abortableSource(source, options.signal) : source, + source: (options.signal != null) ? abortableSource(mapSource, options.signal) : mapSource, remoteAddr, /** @type {Timeline} */ timeline: { open: Date.now(), close: undefined }, diff --git a/test/fixtures/pair.ts b/test/fixtures/pair.ts new file mode 100644 index 0000000000..bac8554f94 --- /dev/null +++ b/test/fixtures/pair.ts @@ -0,0 +1,28 @@ +import defer from 'p-defer' +import map from 'it-map' +import type { Source, Duplex } from 'it-stream-types' +import { Uint8ArrayList } from 'uint8arraylist' + +/** + * A pair of streams where one drains from the other + */ +export function pair (): Duplex { + const deferred = defer>() + let piped = false + + return { + sink: async source => { + if (piped) { + throw new Error('already piped') + } + + piped = true + deferred.resolve(source) + }, + source: (async function * () { + const source = await deferred.promise + + yield * map(source, (buf) => buf instanceof Uint8Array ? new Uint8ArrayList(buf) : buf) + }()) + } +} diff --git a/test/stream-to-ma-conn.spec.ts b/test/stream-to-ma-conn.spec.ts index 7f6510fe24..0e9d52cf16 100644 --- a/test/stream-to-ma-conn.spec.ts +++ b/test/stream-to-ma-conn.spec.ts @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import { pair } from 'it-pair' +import { pair } from './fixtures/pair.js' import { pipe } from 'it-pipe' import { multiaddr } from '@multiformats/multiaddr' import { streamToMaConnection } from '../src/stream-to-ma-conn.js' @@ -9,8 +9,9 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import all from 'it-all' import type { Stream } from '@libp2p/interface-connection' import type { Duplex } from 'it-stream-types' +import type { Uint8ArrayList } from 'uint8arraylist' -function toMuxedStream (stream: Duplex) { +function toMuxedStream (stream: Duplex) { const muxedStream: Stream = { ...stream, close: () => {}, @@ -36,7 +37,7 @@ describe('Convert stream into a multiaddr connection', () => { const remoteAddr = multiaddr('/ip4/100.46.74.201/tcp/6002') it('converts a stream and adds the provided metadata', async () => { - const stream = pair() + const stream = pair() const maConn = streamToMaConnection({ stream: toMuxedStream(stream), @@ -57,7 +58,7 @@ describe('Convert stream into a multiaddr connection', () => { }) it('can stream data over the multiaddr connection', async () => { - const stream = pair() + const stream = pair() const maConn = streamToMaConnection({ stream: toMuxedStream(stream), localAddr, From 4ba45faa5e7da5c8d1aafbe4d97e8fab35e899c3 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 10 Aug 2022 11:19:03 +0000 Subject: [PATCH 077/124] chore(release): 3.0.1 [skip ci] ## [3.0.1](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.0...v3.0.1) (2022-08-10) ### Bug Fixes * update deps ([#55](https://github.com/libp2p/js-libp2p-utils/issues/55)) ([134c633](https://github.com/libp2p/js-libp2p-utils/commit/134c633f107247ce309ed7da3a29f872615ee920)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf111c20bf..ab3c9764d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [3.0.1](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.0...v3.0.1) (2022-08-10) + + +### Bug Fixes + +* update deps ([#55](https://github.com/libp2p/js-libp2p-utils/issues/55)) ([134c633](https://github.com/libp2p/js-libp2p-utils/commit/134c633f107247ce309ed7da3a29f872615ee920)) + ## [3.0.0](https://github.com/libp2p/js-libp2p-utils/compare/v2.0.1...v3.0.0) (2022-06-27) diff --git a/package.json b/package.json index d4040e276c..c45a2d71d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "3.0.0", + "version": "3.0.1", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From ae3a0c8199ea318a25c36f998d7706f048c6f261 Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Tue, 23 Aug 2022 20:10:30 +0200 Subject: [PATCH 078/124] update .github/workflows/js-test-and-release.yml (#56) --- .github/workflows/js-test-and-release.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index 8030ec6520..b02826b1b5 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -15,7 +15,7 @@ jobs: check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-node@v2 with: node-version: lts/* @@ -32,7 +32,7 @@ jobs: node: [16] fail-fast: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} @@ -46,7 +46,7 @@ jobs: needs: check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-node@v2 with: node-version: lts/* @@ -60,7 +60,7 @@ jobs: needs: check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-node@v2 with: node-version: lts/* @@ -74,7 +74,7 @@ jobs: needs: check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-node@v2 with: node-version: lts/* @@ -88,7 +88,7 @@ jobs: needs: check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-node@v2 with: node-version: lts/* @@ -102,7 +102,7 @@ jobs: needs: check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-node@v2 with: node-version: lts/* @@ -116,7 +116,7 @@ jobs: needs: check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-node@v2 with: node-version: lts/* @@ -131,7 +131,7 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'push' && github.ref == 'refs/heads/master' # with #262 - 'refs/heads/${{{ github.default_branch }}}' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - uses: actions/setup-node@v2 From ad8a25ee50472491806bea2c5f11ee71d510ec77 Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Mon, 5 Sep 2022 17:07:21 +0200 Subject: [PATCH 079/124] update .github/workflows/js-test-and-release.yml (#57) --- .github/workflows/js-test-and-release.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index b02826b1b5..65d30bdadc 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master @@ -33,7 +33,7 @@ jobs: fail-fast: true steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node }} - uses: ipfs/aegir/actions/cache-node-modules@master @@ -47,7 +47,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master @@ -61,7 +61,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master @@ -75,7 +75,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master @@ -89,7 +89,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master @@ -103,7 +103,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master @@ -117,7 +117,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master @@ -134,7 +134,7 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master From ea425dc19253202009497587681da1a7703ac429 Mon Sep 17 00:00:00 2001 From: "libp2p-mgmt-read-write[bot]" <104492852+libp2p-mgmt-read-write[bot]@users.noreply.github.com> Date: Mon, 19 Sep 2022 13:42:04 +0000 Subject: [PATCH 080/124] chore: Update .github/workflows/stale.yml [skip ci] --- .github/workflows/stale.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/stale.yml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000000..6f6d895d19 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,26 @@ +name: Close and mark stale issue + +on: + schedule: + - cron: '0 0 * * *' + +jobs: + stale: + + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + + steps: + - uses: actions/stale@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: 'Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.' + close-issue-message: 'This issue was closed because it is missing author input.' + stale-issue-label: 'kind/stale' + any-of-labels: 'need/author-input' + exempt-issue-labels: 'need/triage,need/community-input,need/maintainer-input,need/maintainers-input,need/analysis,status/blocked,status/in-progress,status/ready,status/deferred,status/inactive' + days-before-issue-stale: 6 + days-before-issue-close: 7 + enable-statistics: true From 46bff23bc5296359cfca02fbf078ee197a1629cc Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 21 Sep 2022 08:59:13 +0100 Subject: [PATCH 081/124] deps: update @multiformats/multiaddr to 11.0.0 (#59) Updates all use of @multiformats/multiaddr --- .github/dependabot.yml | 3 +++ README.md | 4 ++-- package.json | 18 +++++++++++------- src/array-equals.ts | 9 ++++++++- src/ip-port-to-multiaddr.ts | 8 ++++---- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 290ad02837..0bc3b42de8 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,3 +6,6 @@ updates: interval: daily time: "10:00" open-pull-requests-limit: 10 + commit-message: + prefix: "deps" + prefix-development: "deps(dev)" diff --git a/README.md b/README.md index a8dbdc76f8..8879ccafee 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ - [Usage](#usage) - [Contribute](#contribute) - [License](#license) -- [Contribution](#contribution) +- [Contribute](#contribute-1) ## Install @@ -59,6 +59,6 @@ Licensed under either of - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) - MIT ([LICENSE-MIT](LICENSE-MIT) / ) -## Contribution +## Contribute Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/package.json b/package.json index c45a2d71d7..f1f9ece8ff 100644 --- a/package.json +++ b/package.json @@ -102,15 +102,15 @@ "release": "patch" }, { - "type": "chore", + "type": "docs", "release": "patch" }, { - "type": "docs", + "type": "test", "release": "patch" }, { - "type": "test", + "type": "deps", "release": "patch" }, { @@ -140,7 +140,11 @@ }, { "type": "docs", - "section": "Trivial Changes" + "section": "Documentation" + }, + { + "type": "deps", + "section": "Dependencies" }, { "type": "test", @@ -172,10 +176,10 @@ }, "dependencies": { "@achingbrain/ip-address": "^8.1.0", - "@libp2p/interface-connection": "^3.0.1", - "@libp2p/interface-peer-store": "^1.0.0", + "@libp2p/interface-connection": "^3.0.2", + "@libp2p/interface-peer-store": "^1.2.1", "@libp2p/logger": "^2.0.0", - "@multiformats/multiaddr": "^10.1.1", + "@multiformats/multiaddr": "^11.0.0", "abortable-iterator": "^4.0.2", "err-code": "^3.0.1", "is-loopback-addr": "^2.0.1", diff --git a/src/array-equals.ts b/src/array-equals.ts index 7455201a3f..3d530d4f29 100644 --- a/src/array-equals.ts +++ b/src/array-equals.ts @@ -4,5 +4,12 @@ */ export function arrayEquals (a: any[], b: any[]) { const sort = (a: any, b: any) => a.toString().localeCompare(b.toString()) - return a.length === b.length && b.sort(sort) && a.sort(sort).every((item, index) => b[index].equals(item)) + + if (a.length !== b.length) { + return false + } + + b.sort(sort) + + return a.sort(sort).every((item, index) => b[index].equals(item)) } diff --git a/src/ip-port-to-multiaddr.ts b/src/ip-port-to-multiaddr.ts index adad125a8e..12cfe40e1e 100644 --- a/src/ip-port-to-multiaddr.ts +++ b/src/ip-port-to-multiaddr.ts @@ -1,5 +1,5 @@ import { logger } from '@libp2p/logger' -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import errCode from 'err-code' import { Address4, Address6 } from '@achingbrain/ip-address' @@ -30,15 +30,15 @@ export function ipPortToMultiaddr (ip: string, port: number | string) { try { // Test valid IPv4 new Address4(ip) // eslint-disable-line no-new - return new Multiaddr(`/ip4/${ip}/tcp/${port}`) + return multiaddr(`/ip4/${ip}/tcp/${port}`) } catch {} try { // Test valid IPv6 const ip6 = new Address6(ip) return ip6.is4() - ? new Multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`) - : new Multiaddr(`/ip6/${ip}/tcp/${port}`) + ? 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) From 66e604cb0bfcf686eb68e44f278d62e3464c827c Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 21 Sep 2022 08:16:13 +0000 Subject: [PATCH 082/124] chore(release): 3.0.2 [skip ci] ## [3.0.2](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.1...v3.0.2) (2022-09-21) ### Trivial Changes * Update .github/workflows/stale.yml [skip ci] ([ea425dc](https://github.com/libp2p/js-libp2p-utils/commit/ea425dc19253202009497587681da1a7703ac429)) ### Dependencies * update @multiformats/multiaddr to 11.0.0 ([#59](https://github.com/libp2p/js-libp2p-utils/issues/59)) ([46bff23](https://github.com/libp2p/js-libp2p-utils/commit/46bff23bc5296359cfca02fbf078ee197a1629cc)) --- CHANGELOG.md | 12 ++++++++++++ package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab3c9764d4..bab809a2f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## [3.0.2](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.1...v3.0.2) (2022-09-21) + + +### Trivial Changes + +* Update .github/workflows/stale.yml [skip ci] ([ea425dc](https://github.com/libp2p/js-libp2p-utils/commit/ea425dc19253202009497587681da1a7703ac429)) + + +### Dependencies + +* update @multiformats/multiaddr to 11.0.0 ([#59](https://github.com/libp2p/js-libp2p-utils/issues/59)) ([46bff23](https://github.com/libp2p/js-libp2p-utils/commit/46bff23bc5296359cfca02fbf078ee197a1629cc)) + ## [3.0.1](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.0...v3.0.1) (2022-08-10) diff --git a/package.json b/package.json index f1f9ece8ff..eda0bbdf27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "3.0.1", + "version": "3.0.2", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From 3f9a2291c6b7de1502dda9da6ba619ea5c565a10 Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Mon, 14 Nov 2022 17:00:48 +0100 Subject: [PATCH 083/124] sync: update CI config files (#64) --- .github/workflows/js-test-and-release.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index 65d30bdadc..ed173493d9 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -7,8 +7,6 @@ on: branches: - master # with #262 - ${{{ github.default_branch }}} pull_request: - branches: - - master # with #262 - ${{{ github.default_branch }}} jobs: From bfd0de0cdf670ae1e83d699f6e7867da3d5de86d Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Fri, 25 Nov 2022 21:23:32 +0100 Subject: [PATCH 084/124] sync: update CI config files (#65) --- .github/workflows/js-test-and-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index ed173493d9..c6897e3b53 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -27,7 +27,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest, macos-latest] - node: [16] + node: [lts/*] fail-fast: true steps: - uses: actions/checkout@v3 From 956f404bba12f2c712999046b19825496fe8be41 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Dec 2022 07:41:49 +0000 Subject: [PATCH 085/124] deps: bump private-ip from 2.3.4 to 3.0.0 (#63) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [private-ip](https://github.com/frenchbread/private-ip) from 2.3.4 to 3.0.0.
Release notes

Sourced from private-ip's releases.

private-ip v3.0.0

breaking changes

  • converted package to ESM. Make sure it is supported in your project if using > v3.0.0. [90ee0ce - thanks @​tuyennhv]

other changes

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=private-ip&package-manager=npm_and_yarn&previous-version=2.3.4&new-version=3.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eda0bbdf27..2a4c38d2ba 100644 --- a/package.json +++ b/package.json @@ -184,7 +184,7 @@ "err-code": "^3.0.1", "is-loopback-addr": "^2.0.1", "it-stream-types": "^1.0.4", - "private-ip": "^2.1.1", + "private-ip": "^3.0.0", "uint8arraylist": "^2.3.2" }, "devDependencies": { From 99cca2505721f282ed557dcfd28d8b46d064d6e2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Dec 2022 07:42:00 +0000 Subject: [PATCH 086/124] deps(dev): bump it-all from 1.0.6 to 2.0.0 (#62) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [it-all](https://github.com/achingbrain/it) from 1.0.6 to 2.0.0.
Release notes

Sourced from it-all's releases.

it-all-v2.0.0

it-all-v2.0.0 (2022-10-17)

⚠ BREAKING CHANGES

  • all modules are now published as ESM-only

Features

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=it-all&package-manager=npm_and_yarn&previous-version=1.0.6&new-version=2.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2a4c38d2ba..bc9cecc00a 100644 --- a/package.json +++ b/package.json @@ -189,7 +189,7 @@ }, "devDependencies": { "aegir": "^37.2.0", - "it-all": "^1.0.6", + "it-all": "^2.0.0", "it-map": "^1.0.6", "it-pair": "^2.0.2", "it-pipe": "^2.0.2", From 88b05b4a6223774cd6dbaaa4f97e1da318f89856 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Dec 2022 07:42:40 +0000 Subject: [PATCH 087/124] deps(dev): bump it-map from 1.0.6 to 2.0.0 (#61) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [//]: # (dependabot-start) ⚠️ **Dependabot is rebasing this PR** ⚠️ Rebasing might not happen immediately, so don't worry if this takes some time. Note: if you make any changes to this PR yourself, they will take precedence over the rebase. --- [//]: # (dependabot-end) Bumps [it-map](https://github.com/achingbrain/it) from 1.0.6 to 2.0.0.
Release notes

Sourced from it-map's releases.

it-map-v2.0.0

it-map-v2.0.0 (2022-10-17)

⚠ BREAKING CHANGES

  • all modules are now published as ESM-only

Features

Commits
  • 0f47f1e chore(release): 2.0.0 [skip ci]
  • bd57f5c chore(release): 2.0.0 [skip ci]
  • b7caa4c chore(release): 2.0.0 [skip ci]
  • 6d3cfef chore(release): 2.0.0 [skip ci]
  • 35b8856 deps: update sibling dependencies
  • c3a3077 chore(release): 2.0.0 [skip ci]
  • c572706 chore(release): 3.0.0 [skip ci]
  • 1415cdd deps: update sibling dependencies
  • 417a1f3 chore(release): 2.0.0 [skip ci]
  • 8bd4bd2 chore: update build scripts
  • Additional commits viewable in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=it-map&package-manager=npm_and_yarn&previous-version=1.0.6&new-version=2.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alex Potsides --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bc9cecc00a..a3bc810022 100644 --- a/package.json +++ b/package.json @@ -190,7 +190,7 @@ "devDependencies": { "aegir": "^37.2.0", "it-all": "^2.0.0", - "it-map": "^1.0.6", + "it-map": "^2.0.0", "it-pair": "^2.0.2", "it-pipe": "^2.0.2", "p-defer": "^4.0.0", From ca0b63243b0ae23b6fa9195387466516c9acce80 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Dec 2022 07:42:51 +0000 Subject: [PATCH 088/124] deps(dev): bump uint8arrays from 3.1.1 to 4.0.2 (#60) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [uint8arrays](https://github.com/achingbrain/uint8arrays) from 3.1.1 to 4.0.2.
Release notes

Sourced from uint8arrays's releases.

v4.0.2

4.0.2 (2022-10-12)

Bug Fixes

v4.0.1

4.0.1 (2022-10-12)

Bug Fixes

  • export SupportedEncodings from to-string and from-string (#40) (d3f1412)

v4.0.0

4.0.0 (2022-10-12)

⚠ BREAKING CHANGES

  • this module is has been converted to typescript, the API should be the same but releasing as a major just in case

Features

Documentation

Changelog

Sourced from uint8arrays's changelog.

4.0.2 (2022-10-12)

Bug Fixes

4.0.1 (2022-10-12)

Bug Fixes

  • export SupportedEncodings from to-string and from-string (#40) (d3f1412)

4.0.0 (2022-10-12)

⚠ BREAKING CHANGES

  • this module is now ESM-only

Features

  • convert to typescript and release as ESM-only (#28) (e4c9627)

Documentation

Commits
  • 4264165 chore(release): 4.0.2 [skip ci]
  • 4e78d9e fix: update exports map paths (#41)
  • b0189b2 chore(release): 4.0.1 [skip ci]
  • d3f1412 fix: export SupportedEncodings from to-string and from-string (#40)
  • 93b959b chore(release): 4.0.0 [skip ci]
  • 803cb5f docs: fix readme header
  • e4c9627 feat!: convert to typescript and release as ESM-only (#28)
  • See full diff in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=uint8arrays&package-manager=npm_and_yarn&previous-version=3.1.1&new-version=4.0.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a3bc810022..3f10c59aa5 100644 --- a/package.json +++ b/package.json @@ -194,6 +194,6 @@ "it-pair": "^2.0.2", "it-pipe": "^2.0.2", "p-defer": "^4.0.0", - "uint8arrays": "^3.0.0" + "uint8arrays": "^4.0.2" } } From 7e977a2739717225a4b1d74304e69500652a3386 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 7 Dec 2022 15:24:46 +0000 Subject: [PATCH 089/124] fix: update project readme (#66) Update badges to point at correct locations. --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 8879ccafee..f538097e37 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ # @libp2p/utils [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) -[![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-utils.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-utils) -[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-utils/actions/workflows/js-test-and-release.yml) +[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-utils/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-utils/actions/workflows/js-test-and-release.yml) > Package to aggregate shared logic and dependencies for the libp2p ecosystem From d412279b07adc28c27730e5f9337a9a3b93d4fa7 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 7 Dec 2022 15:28:40 +0000 Subject: [PATCH 090/124] chore(release): 3.0.3 [skip ci] ## [3.0.3](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.2...v3.0.3) (2022-12-07) ### Bug Fixes * update project readme ([#66](https://github.com/libp2p/js-libp2p-utils/issues/66)) ([7e977a2](https://github.com/libp2p/js-libp2p-utils/commit/7e977a2739717225a4b1d74304e69500652a3386)) ### Dependencies * bump private-ip from 2.3.4 to 3.0.0 ([#63](https://github.com/libp2p/js-libp2p-utils/issues/63)) ([956f404](https://github.com/libp2p/js-libp2p-utils/commit/956f404bba12f2c712999046b19825496fe8be41)), closes [ChainSafe/is-ip#1](https://github.com/ChainSafe/is-ip/issues/1) [#19](https://github.com/libp2p/js-libp2p-utils/issues/19) [#21](https://github.com/libp2p/js-libp2p-utils/issues/21) * **dev:** bump it-all from 1.0.6 to 2.0.0 ([#62](https://github.com/libp2p/js-libp2p-utils/issues/62)) ([99cca25](https://github.com/libp2p/js-libp2p-utils/commit/99cca2505721f282ed557dcfd28d8b46d064d6e2)), closes [#28](https://github.com/libp2p/js-libp2p-utils/issues/28) [#28](https://github.com/libp2p/js-libp2p-utils/issues/28) [#27](https://github.com/libp2p/js-libp2p-utils/issues/27) [#24](https://github.com/libp2p/js-libp2p-utils/issues/24) * **dev:** bump it-map from 1.0.6 to 2.0.0 ([#61](https://github.com/libp2p/js-libp2p-utils/issues/61)) ([88b05b4](https://github.com/libp2p/js-libp2p-utils/commit/88b05b4a6223774cd6dbaaa4f97e1da318f89856)) * **dev:** bump uint8arrays from 3.1.1 to 4.0.2 ([#60](https://github.com/libp2p/js-libp2p-utils/issues/60)) ([ca0b632](https://github.com/libp2p/js-libp2p-utils/commit/ca0b63243b0ae23b6fa9195387466516c9acce80)), closes [#41](https://github.com/libp2p/js-libp2p-utils/issues/41) [#40](https://github.com/libp2p/js-libp2p-utils/issues/40) [#28](https://github.com/libp2p/js-libp2p-utils/issues/28) [#41](https://github.com/libp2p/js-libp2p-utils/issues/41) [#40](https://github.com/libp2p/js-libp2p-utils/issues/40) [#28](https://github.com/libp2p/js-libp2p-utils/issues/28) [#41](https://github.com/libp2p/js-libp2p-utils/issues/41) [#40](https://github.com/libp2p/js-libp2p-utils/issues/40) [#28](https://github.com/libp2p/js-libp2p-utils/issues/28) --- CHANGELOG.md | 15 +++++++++++++++ package.json | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bab809a2f0..a7063436a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +## [3.0.3](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.2...v3.0.3) (2022-12-07) + + +### Bug Fixes + +* update project readme ([#66](https://github.com/libp2p/js-libp2p-utils/issues/66)) ([7e977a2](https://github.com/libp2p/js-libp2p-utils/commit/7e977a2739717225a4b1d74304e69500652a3386)) + + +### Dependencies + +* bump private-ip from 2.3.4 to 3.0.0 ([#63](https://github.com/libp2p/js-libp2p-utils/issues/63)) ([956f404](https://github.com/libp2p/js-libp2p-utils/commit/956f404bba12f2c712999046b19825496fe8be41)), closes [ChainSafe/is-ip#1](https://github.com/ChainSafe/is-ip/issues/1) [#19](https://github.com/libp2p/js-libp2p-utils/issues/19) [#21](https://github.com/libp2p/js-libp2p-utils/issues/21) +* **dev:** bump it-all from 1.0.6 to 2.0.0 ([#62](https://github.com/libp2p/js-libp2p-utils/issues/62)) ([99cca25](https://github.com/libp2p/js-libp2p-utils/commit/99cca2505721f282ed557dcfd28d8b46d064d6e2)), closes [#28](https://github.com/libp2p/js-libp2p-utils/issues/28) [#28](https://github.com/libp2p/js-libp2p-utils/issues/28) [#27](https://github.com/libp2p/js-libp2p-utils/issues/27) [#24](https://github.com/libp2p/js-libp2p-utils/issues/24) +* **dev:** bump it-map from 1.0.6 to 2.0.0 ([#61](https://github.com/libp2p/js-libp2p-utils/issues/61)) ([88b05b4](https://github.com/libp2p/js-libp2p-utils/commit/88b05b4a6223774cd6dbaaa4f97e1da318f89856)) +* **dev:** bump uint8arrays from 3.1.1 to 4.0.2 ([#60](https://github.com/libp2p/js-libp2p-utils/issues/60)) ([ca0b632](https://github.com/libp2p/js-libp2p-utils/commit/ca0b63243b0ae23b6fa9195387466516c9acce80)), closes [#41](https://github.com/libp2p/js-libp2p-utils/issues/41) [#40](https://github.com/libp2p/js-libp2p-utils/issues/40) [#28](https://github.com/libp2p/js-libp2p-utils/issues/28) [#41](https://github.com/libp2p/js-libp2p-utils/issues/41) [#40](https://github.com/libp2p/js-libp2p-utils/issues/40) [#28](https://github.com/libp2p/js-libp2p-utils/issues/28) [#41](https://github.com/libp2p/js-libp2p-utils/issues/41) [#40](https://github.com/libp2p/js-libp2p-utils/issues/40) [#28](https://github.com/libp2p/js-libp2p-utils/issues/28) + ## [3.0.2](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.1...v3.0.2) (2022-09-21) diff --git a/package.json b/package.json index 3f10c59aa5..9607546c3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "3.0.2", + "version": "3.0.3", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From 7a193cfe58c85cf9df1f3430947f58e03fcb5154 Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Wed, 14 Dec 2022 12:50:03 +0100 Subject: [PATCH 091/124] sync: update CI config files (#67) --- .github/workflows/js-test-and-release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index c6897e3b53..da747937a6 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -144,3 +144,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + - run: npm run --if-present docs + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 3a254c0667dd5663630cfb863f4d2e5bbd47e7e4 Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Thu, 15 Dec 2022 10:10:24 +0100 Subject: [PATCH 092/124] sync: update CI config files (#68) --- .github/workflows/js-test-and-release.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index da747937a6..c6897e3b53 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -144,6 +144,3 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - run: npm run --if-present docs - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 044fd7232eb0be2d8cd71fab6130c4f30190e22b Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 16 Dec 2022 18:47:23 +0000 Subject: [PATCH 093/124] docs: publish api docs (#69) Update project config to publish api docs --- .gitignore | 35 ++++------------------------------- README.md | 30 ++++++++++++++++-------------- package.json | 3 ++- src/address-sort.ts | 29 +++++++++++++++++++++++++++++ src/array-equals.ts | 19 +++++++++++++++++++ src/stream-to-ma-conn.ts | 4 ++-- 6 files changed, 72 insertions(+), 48 deletions(-) diff --git a/.gitignore b/.gitignore index 7d3286a2cd..1531bdf9de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,33 +1,6 @@ -package-lock.json -yarn.lock -# Logs -logs -*.log - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov -.nyc_output - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directory -# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules - dist -docs +.docs +.coverage +package-lock.json +yarn.lock diff --git a/README.md b/README.md index f538097e37..750e0b7b6b 100644 --- a/README.md +++ b/README.md @@ -3,18 +3,18 @@ [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-utils.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-utils) -[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-utils/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-utils/actions/workflows/js-test-and-release.yml) +[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-utils/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-utils/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) > Package to aggregate shared logic and dependencies for the libp2p ecosystem ## Table of contents - [Install](#install) -- [Lead Maintainer](#lead-maintainer) + - [Browser ` +``` + The libp2p ecosystem has lots of repos with it comes several problems like: - Domain logic dedupe - all modules shared a lot of logic like validation, streams handling, etc. @@ -29,10 +37,6 @@ The libp2p ecosystem has lots of repos with it comes several problems like: These problems are the motivation for this package, having shared logic in this package avoids creating cyclic dependencies, centralizes common use modules/functions (exactly like aegir does for the tooling), semantic versioning for 3rd party dependencies is handled in one single place (a good example is going from streams 2 to 3) and maintainers should only care about having `libp2p-utils` updated. -## Lead Maintainer - -[Vasco Santos](https://github.com/vasco-santos) - ## Usage Each function should be imported directly. @@ -43,13 +47,11 @@ import ipAndPortToMultiaddr from '@libp2p/utils/ip-port-to-multiaddr' const ma = ipAndPortToMultiaddr('127.0.0.1', 9000) ``` -You can check the [API docs](./API.md). - -## Contribute +You can check the [API docs](https://libp2p.github.io/js-libp2p-utils). -Contributions welcome. Please check out [the issues](https://github.com/libp2p/js-libp2p-utils/issues). +## API Docs -Check out our [contributing document](https://github.com/ipfs/community/blob/master/contributing.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). +- ## License @@ -58,6 +60,6 @@ Licensed under either of - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) - MIT ([LICENSE-MIT](LICENSE-MIT) / ) -## Contribute +## Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/package.json b/package.json index 9607546c3f..30886a7416 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ }, "files": [ "src", - "dist/src", + "dist", "!dist/test", "!**/*.tsbuildinfo" ], @@ -165,6 +165,7 @@ "lint": "aegir lint", "dep-check": "aegir dep-check", "build": "aegir build", + "docs": "aegir docs", "test": "aegir test", "test:chrome": "aegir test -t browser --cov", "test:chrome-webworker": "aegir test -t webworker", diff --git a/src/address-sort.ts b/src/address-sort.ts index 1cf3cb3d6c..b9a1ced15c 100644 --- a/src/address-sort.ts +++ b/src/address-sort.ts @@ -1,3 +1,25 @@ +/** + * @packageDocumentation + * + * Provides strategies to sort a list of multiaddrs. + * + * @example + * + * ```typescript + * import { publicAddressesFirst } from '@libp2p/utils/address-sort' + * import { multiaddr } from '@multformats/multiaddr' + * + * + * const addresses = [ + * multiaddr('/ip4/127.0.0.1/tcp/9000'), + * multiaddr('/ip4/82.41.53.1/tcp/9000') + * ].sort(publicAddressesFirst) + * + * console.info(addresses) + * // ['/ip4/82.41.53.1/tcp/9000', '/ip4/127.0.0.1/tcp/9000'] + * ``` + */ + import type { Address } from '@libp2p/interface-peer-store' import { isPrivate } from './multiaddr/is-private.js' @@ -24,3 +46,10 @@ export function publicAddressesFirst (a: Address, b: Address): -1 | 0 | 1 { return 0 } + +/** + * A test thing + */ +export async function something (): Promise { + return Uint8Array.from([0, 1, 2]) +} diff --git a/src/array-equals.ts b/src/array-equals.ts index 3d530d4f29..21db48875e 100644 --- a/src/array-equals.ts +++ b/src/array-equals.ts @@ -1,3 +1,22 @@ +/** + * @packageDocumentation + * + * Provides strategies ensure arrays are equivalent. + * + * @example + * + * ```typescript + * import { arrayEquals } from '@libp2p/utils/array-equals' + * import { multiaddr } from '@multformats/multiaddr' + * + * const ma1 = multiaddr('/ip4/127.0.0.1/tcp/9000'), + * const ma2 = multiaddr('/ip4/82.41.53.1/tcp/9000') + * + * console.info(arrayEquals([ma1], [ma1])) // true + * console.info(arrayEquals([ma1], [ma2])) // false + * ``` + */ + /** * Verify if two arrays of non primitive types with the "equals" function are equal. * Compatible with multiaddr, peer-id and others. diff --git a/src/stream-to-ma-conn.ts b/src/stream-to-ma-conn.ts index cbce121369..2eeb28d6ed 100644 --- a/src/stream-to-ma-conn.ts +++ b/src/stream-to-ma-conn.ts @@ -24,12 +24,12 @@ export interface Timeline { close?: number } -interface StreamOptions { +export interface StreamOptions { signal?: AbortSignal } -interface StreamProperties { +export interface StreamProperties { stream: Duplex remoteAddr: Multiaddr localAddr: Multiaddr From f201f30d7a3054c92105ecb79a92f850f71b2747 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 16 Dec 2022 18:55:56 +0000 Subject: [PATCH 094/124] chore(release): 3.0.4 [skip ci] ## [3.0.4](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.3...v3.0.4) (2022-12-16) ### Documentation * publish api docs ([#69](https://github.com/libp2p/js-libp2p-utils/issues/69)) ([044fd72](https://github.com/libp2p/js-libp2p-utils/commit/044fd7232eb0be2d8cd71fab6130c4f30190e22b)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7063436a7..0f7e00254a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [3.0.4](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.3...v3.0.4) (2022-12-16) + + +### Documentation + +* publish api docs ([#69](https://github.com/libp2p/js-libp2p-utils/issues/69)) ([044fd72](https://github.com/libp2p/js-libp2p-utils/commit/044fd7232eb0be2d8cd71fab6130c4f30190e22b)) + ## [3.0.3](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.2...v3.0.3) (2022-12-07) diff --git a/package.json b/package.json index 30886a7416..056cb74766 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "3.0.3", + "version": "3.0.4", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From beb252d79f69d0f49d1fa4fd664a49e33ff80cd3 Mon Sep 17 00:00:00 2001 From: tabcat Date: Fri, 13 Jan 2023 14:03:34 -0600 Subject: [PATCH 095/124] chore: replace err-code with CodeError (#70) Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](https://github.com/libp2p/js-libp2p-interfaces/pull/314) Related: [js-libp2p#1269](https://github.com/libp2p/js-libp2p/issues/1269) Changes - removes err-code from dependencies - adds @libp2p/interfaces@3.2.0 to dependencies - uses CodeError in place of err-code --- package.json | 2 +- src/ip-port-to-multiaddr.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 056cb74766..b33e551b05 100644 --- a/package.json +++ b/package.json @@ -179,10 +179,10 @@ "@achingbrain/ip-address": "^8.1.0", "@libp2p/interface-connection": "^3.0.2", "@libp2p/interface-peer-store": "^1.2.1", + "@libp2p/interfaces": "^3.2.0", "@libp2p/logger": "^2.0.0", "@multiformats/multiaddr": "^11.0.0", "abortable-iterator": "^4.0.2", - "err-code": "^3.0.1", "is-loopback-addr": "^2.0.1", "it-stream-types": "^1.0.4", "private-ip": "^3.0.0", diff --git a/src/ip-port-to-multiaddr.ts b/src/ip-port-to-multiaddr.ts index 12cfe40e1e..35144d0f7d 100644 --- a/src/ip-port-to-multiaddr.ts +++ b/src/ip-port-to-multiaddr.ts @@ -1,6 +1,6 @@ import { logger } from '@libp2p/logger' import { multiaddr } from '@multiformats/multiaddr' -import errCode from 'err-code' +import { CodeError } from '@libp2p/interfaces/errors' import { Address4, Address6 } from '@achingbrain/ip-address' const log = logger('libp2p:ip-port-to-multiaddr') @@ -16,7 +16,7 @@ export const Errors = { */ export function ipPortToMultiaddr (ip: string, port: number | string) { if (typeof ip !== 'string') { - throw errCode(new Error(`invalid ip provided: ${ip}`), Errors.ERR_INVALID_IP_PARAMETER) // eslint-disable-line @typescript-eslint/restrict-template-expressions + throw new CodeError(`invalid ip provided: ${ip}`, Errors.ERR_INVALID_IP_PARAMETER) // eslint-disable-line @typescript-eslint/restrict-template-expressions } if (typeof port === 'string') { @@ -24,7 +24,7 @@ export function ipPortToMultiaddr (ip: string, port: number | string) { } if (isNaN(port)) { - throw errCode(new Error(`invalid port provided: ${port}`), Errors.ERR_INVALID_PORT_PARAMETER) + throw new CodeError(`invalid port provided: ${port}`, Errors.ERR_INVALID_PORT_PARAMETER) } try { @@ -42,6 +42,6 @@ export function ipPortToMultiaddr (ip: string, port: number | string) { } 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 new CodeError(errMsg, Errors.ERR_INVALID_IP) } } From b0e8510eecddc9e2e6af0430dc4d5697c1fe5113 Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Fri, 3 Feb 2023 13:40:47 +0100 Subject: [PATCH 096/124] sync: update CI config files (#72) --- .github/workflows/js-test-and-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index c6897e3b53..55c45a837c 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -5,7 +5,7 @@ name: test & maybe release on: push: branches: - - master # with #262 - ${{{ github.default_branch }}} + - master pull_request: jobs: @@ -127,7 +127,7 @@ jobs: release: needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer] runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/master' # with #262 - 'refs/heads/${{{ github.default_branch }}}' + if: github.event_name == 'push' && github.ref == 'refs/heads/master' steps: - uses: actions/checkout@v3 with: From 58167c31a04c6ea3c6b39823bddb585b4403816f Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Wed, 8 Feb 2023 18:58:42 +0100 Subject: [PATCH 097/124] sync: update CI config files (#74) --- .github/workflows/js-test-and-release.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index 55c45a837c..ef28bb0bd9 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -36,7 +36,7 @@ jobs: node-version: ${{ matrix.node }} - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:node - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 with: flags: node @@ -50,7 +50,7 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:chrome - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 with: flags: chrome @@ -64,7 +64,7 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:chrome-webworker - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 with: flags: chrome-webworker @@ -78,7 +78,7 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:firefox - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 with: flags: firefox @@ -92,7 +92,7 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npm run --if-present test:firefox-webworker - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 with: flags: firefox-webworker @@ -106,7 +106,7 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npx xvfb-maybe npm run --if-present test:electron-main - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 with: flags: electron-main @@ -120,7 +120,7 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - run: npx xvfb-maybe npm run --if-present test:electron-renderer - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 with: flags: electron-renderer @@ -142,5 +142,5 @@ jobs: docker-username: ${{ secrets.DOCKER_USERNAME }} - run: npm run --if-present release env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} From 10d6e7a7731b746f199ffb2f186e28185cb512f5 Mon Sep 17 00:00:00 2001 From: "libp2p-mgmt-read-write[bot]" <104492852+libp2p-mgmt-read-write[bot]@users.noreply.github.com> Date: Wed, 22 Feb 2023 07:53:37 +0000 Subject: [PATCH 098/124] chore: Update .github/workflows/semantic-pull-request.yml [skip ci] --- .github/workflows/semantic-pull-request.yml | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/semantic-pull-request.yml diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml new file mode 100644 index 0000000000..6ce44e57f6 --- /dev/null +++ b/.github/workflows/semantic-pull-request.yml @@ -0,0 +1,29 @@ +name: "Semantic PR" + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + main: + name: Validate PR title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@01d5fd8a8ebb9aafe902c40c53f0f4744f7381eb # v5.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + # Configure which types are allowed (newline delimited). + types: | + feat + fix + chore + docs + deps + test + refactor + ci + requireScope: false From 82f64dfcecef96c29497eb86bf848a2ec781863d Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Thu, 23 Feb 2023 18:36:26 +0100 Subject: [PATCH 099/124] ci: update CI config files (#79) Co-authored-by: web3-bot --- .github/workflows/js-test-and-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index ef28bb0bd9..74b23866f0 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -142,5 +142,5 @@ jobs: docker-username: ${{ secrets.DOCKER_USERNAME }} - run: npm run --if-present release env: - GITHUB_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN || github.token }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} From 1b96837cac6c9625ed243d0f62595582a57f7f04 Mon Sep 17 00:00:00 2001 From: GitHub Date: Thu, 2 Mar 2023 09:50:43 +0000 Subject: [PATCH 100/124] chore: Update .github/workflows/semantic-pull-request.yml [skip ci] --- .github/workflows/semantic-pull-request.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml index 6ce44e57f6..0324e0bd42 100644 --- a/.github/workflows/semantic-pull-request.yml +++ b/.github/workflows/semantic-pull-request.yml @@ -27,3 +27,14 @@ jobs: refactor ci requireScope: false + + - name: Check PR title length + env: + TITLE: ${{ github.event.pull_request.title }} + run: | + title_length=${#TITLE} + if [ $title_length -gt 72 ] + then + echo "PR title is too long (greater than 72 characters)" + exit 1 + fi From acad1fe38a1cfef19f63de7283e721caec059d34 Mon Sep 17 00:00:00 2001 From: GitHub Date: Thu, 9 Mar 2023 12:35:19 +0000 Subject: [PATCH 101/124] chore: Update .github/workflows/semantic-pull-request.yml [skip ci] --- .github/workflows/semantic-pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml index 0324e0bd42..4f9798c2d5 100644 --- a/.github/workflows/semantic-pull-request.yml +++ b/.github/workflows/semantic-pull-request.yml @@ -12,7 +12,7 @@ jobs: name: Validate PR title runs-on: ubuntu-latest steps: - - uses: amannn/action-semantic-pull-request@01d5fd8a8ebb9aafe902c40c53f0f4744f7381eb # v5.0.2 + - uses: amannn/action-semantic-pull-request@b6bca70dcd3e56e896605356ce09b76f7e1e0d39 # v5.1.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: From 9e665d6a4cc03e39f13441328bc43115cf2407ee Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Wed, 15 Mar 2023 11:11:58 +0100 Subject: [PATCH 102/124] ci: update Unified CI configuration (#81) --- .github/workflows/js-test-and-release.yml | 38 ++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index 74b23866f0..4e6d4ec0c9 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -96,6 +96,42 @@ jobs: with: flags: firefox-webworker + test-webkit: + needs: check + runs-on: ${{ matrix.os }} + matrix: + os: [ubuntu-latest, macos-latest] + node: [lts/*] + fail-fast: true + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:webkit + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: webkit + + test-webkit: + needs: check + runs-on: ${{ matrix.os }} + matrix: + os: [ubuntu-latest, macos-latest] + node: [lts/*] + fail-fast: true + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:webkit-webworker + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: webkit-webworker + test-electron-main: needs: check runs-on: ubuntu-latest @@ -125,7 +161,7 @@ jobs: flags: electron-renderer release: - needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer] + needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-webkit, test-webkit-webworker, test-electron-main, test-electron-renderer] runs-on: ubuntu-latest if: github.event_name == 'push' && github.ref == 'refs/heads/master' steps: From de1c3d818bc30724ca8bcb237a468423bb03a667 Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Wed, 15 Mar 2023 14:29:51 +0100 Subject: [PATCH 103/124] ci: update Unified CI configuration (#82) --- .github/workflows/js-test-and-release.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index 4e6d4ec0c9..546f6d4a36 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -99,7 +99,8 @@ jobs: test-webkit: needs: check runs-on: ${{ matrix.os }} - matrix: + strategy: + matrix: os: [ubuntu-latest, macos-latest] node: [lts/*] fail-fast: true @@ -114,10 +115,11 @@ jobs: with: flags: webkit - test-webkit: + test-webkit-webworker: needs: check runs-on: ${{ matrix.os }} - matrix: + strategy: + matrix: os: [ubuntu-latest, macos-latest] node: [lts/*] fail-fast: true From 2c262ba37d3668bc4f957914c40c5167cd8faf4f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 17 Mar 2023 12:54:21 +0100 Subject: [PATCH 104/124] deps(dev): bump aegir from 37.12.1 to 38.1.7 (#80) * deps(dev): bump aegir from 37.12.1 to 38.1.7 Bumps [aegir](https://github.com/ipfs/aegir) from 37.12.1 to 38.1.7. - [Release notes](https://github.com/ipfs/aegir/releases) - [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md) - [Commits](https://github.com/ipfs/aegir/compare/v37.12.1...v38.1.7) --- updated-dependencies: - dependency-name: aegir dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * chore: fix linting * chore: update project --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: achingbrain --- .gitignore | 3 +++ package.json | 3 +-- src/array-equals.ts | 4 ++-- src/ip-port-to-multiaddr.ts | 4 ++-- src/multiaddr/is-loopback.ts | 2 +- src/multiaddr/is-private.ts | 2 +- src/stream-to-ma-conn.ts | 6 +++--- test/stream-to-ma-conn.spec.ts | 2 +- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 1531bdf9de..7ad9e674ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ node_modules +build dist .docs .coverage +node_modules package-lock.json yarn.lock +.vscode diff --git a/package.json b/package.json index b33e551b05..0a9b55e05d 100644 --- a/package.json +++ b/package.json @@ -189,10 +189,9 @@ "uint8arraylist": "^2.3.2" }, "devDependencies": { - "aegir": "^37.2.0", + "aegir": "^38.1.7", "it-all": "^2.0.0", "it-map": "^2.0.0", - "it-pair": "^2.0.2", "it-pipe": "^2.0.2", "p-defer": "^4.0.0", "uint8arrays": "^4.0.2" diff --git a/src/array-equals.ts b/src/array-equals.ts index 21db48875e..e94499acbb 100644 --- a/src/array-equals.ts +++ b/src/array-equals.ts @@ -21,8 +21,8 @@ * Verify if two arrays of non primitive types with the "equals" function are equal. * Compatible with multiaddr, peer-id and others. */ -export function arrayEquals (a: any[], b: any[]) { - const sort = (a: any, b: any) => a.toString().localeCompare(b.toString()) +export function arrayEquals (a: any[], b: any[]): boolean { + const sort = (a: any, b: any): number => a.toString().localeCompare(b.toString()) if (a.length !== b.length) { return false diff --git a/src/ip-port-to-multiaddr.ts b/src/ip-port-to-multiaddr.ts index 35144d0f7d..bb80dcb90e 100644 --- a/src/ip-port-to-multiaddr.ts +++ b/src/ip-port-to-multiaddr.ts @@ -1,5 +1,5 @@ import { logger } from '@libp2p/logger' -import { multiaddr } from '@multiformats/multiaddr' +import { Multiaddr, multiaddr } from '@multiformats/multiaddr' import { CodeError } from '@libp2p/interfaces/errors' import { Address4, Address6 } from '@achingbrain/ip-address' @@ -14,7 +14,7 @@ export const Errors = { /** * Transform an IP, Port pair into a multiaddr */ -export function ipPortToMultiaddr (ip: string, port: number | string) { +export function ipPortToMultiaddr (ip: string, port: number | string): Multiaddr { if (typeof ip !== 'string') { throw new CodeError(`invalid ip provided: ${ip}`, Errors.ERR_INVALID_IP_PARAMETER) // eslint-disable-line @typescript-eslint/restrict-template-expressions } diff --git a/src/multiaddr/is-loopback.ts b/src/multiaddr/is-loopback.ts index d676a66b4c..d66f545681 100644 --- a/src/multiaddr/is-loopback.ts +++ b/src/multiaddr/is-loopback.ts @@ -4,7 +4,7 @@ import type { Multiaddr } from '@multiformats/multiaddr' /** * Check if a given multiaddr is a loopback address. */ -export function isLoopback (ma: Multiaddr) { +export function isLoopback (ma: Multiaddr): boolean { const { address } = ma.nodeAddress() return isLoopbackAddr(address) diff --git a/src/multiaddr/is-private.ts b/src/multiaddr/is-private.ts index 54e8072ec4..4d8f416b75 100644 --- a/src/multiaddr/is-private.ts +++ b/src/multiaddr/is-private.ts @@ -4,7 +4,7 @@ import isIpPrivate from 'private-ip' /** * Check if a given multiaddr has a private address. */ -export function isPrivate (ma: Multiaddr) { +export function isPrivate (ma: Multiaddr): boolean { const { address } = ma.nodeAddress() return Boolean(isIpPrivate(address)) diff --git a/src/stream-to-ma-conn.ts b/src/stream-to-ma-conn.ts index 2eeb28d6ed..941f0a0327 100644 --- a/src/stream-to-ma-conn.ts +++ b/src/stream-to-ma-conn.ts @@ -39,7 +39,7 @@ export interface StreamProperties { * Convert a duplex iterable into a MultiaddrConnection. * https://github.com/libp2p/interface-transport#multiaddrconnection */ -export function streamToMaConnection (props: StreamProperties, options: StreamOptions = {}) { +export function streamToMaConnection (props: StreamProperties, options: StreamOptions = {}): MultiaddrConnection { const { stream, remoteAddr } = props const { sink, source } = stream @@ -80,11 +80,11 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp } } - async function close () { + async function close (): Promise { if (maConn.timeline.close == null) { maConn.timeline.close = Date.now() } - return await Promise.resolve() + await Promise.resolve() } return maConn diff --git a/test/stream-to-ma-conn.spec.ts b/test/stream-to-ma-conn.spec.ts index 0e9d52cf16..1997862c1a 100644 --- a/test/stream-to-ma-conn.spec.ts +++ b/test/stream-to-ma-conn.spec.ts @@ -11,7 +11,7 @@ import type { Stream } from '@libp2p/interface-connection' import type { Duplex } from 'it-stream-types' import type { Uint8ArrayList } from 'uint8arraylist' -function toMuxedStream (stream: Duplex) { +function toMuxedStream (stream: Duplex): Stream { const muxedStream: Stream = { ...stream, close: () => {}, From 3eeeeba52b764b96463a1b6bcfcff394492eab2e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 17 Mar 2023 12:55:00 +0100 Subject: [PATCH 105/124] deps: bump @multiformats/multiaddr from 11.6.1 to 12.0.0 (#83) Bumps [@multiformats/multiaddr](https://github.com/multiformats/js-multiaddr) from 11.6.1 to 12.0.0. - [Release notes](https://github.com/multiformats/js-multiaddr/releases) - [Changelog](https://github.com/multiformats/js-multiaddr/blob/master/CHANGELOG.md) - [Commits](https://github.com/multiformats/js-multiaddr/compare/v11.6.1...v12.0.0) --- updated-dependencies: - dependency-name: "@multiformats/multiaddr" dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0a9b55e05d..a810bb3993 100644 --- a/package.json +++ b/package.json @@ -181,7 +181,7 @@ "@libp2p/interface-peer-store": "^1.2.1", "@libp2p/interfaces": "^3.2.0", "@libp2p/logger": "^2.0.0", - "@multiformats/multiaddr": "^11.0.0", + "@multiformats/multiaddr": "^12.0.0", "abortable-iterator": "^4.0.2", "is-loopback-addr": "^2.0.1", "it-stream-types": "^1.0.4", From ec1b7b98d6c953f36a5393937f331fa39dade1e8 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 17 Mar 2023 12:02:13 +0000 Subject: [PATCH 106/124] chore(release): 3.0.5 [skip ci] ## [3.0.5](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.4...v3.0.5) (2023-03-17) ### Trivial Changes * replace err-code with CodeError ([#70](https://github.com/libp2p/js-libp2p-utils/issues/70)) ([beb252d](https://github.com/libp2p/js-libp2p-utils/commit/beb252d79f69d0f49d1fa4fd664a49e33ff80cd3)), closes [js-libp2p#1269](https://github.com/libp2p/js-libp2p/issues/1269) * Update .github/workflows/semantic-pull-request.yml [skip ci] ([acad1fe](https://github.com/libp2p/js-libp2p-utils/commit/acad1fe38a1cfef19f63de7283e721caec059d34)) * Update .github/workflows/semantic-pull-request.yml [skip ci] ([1b96837](https://github.com/libp2p/js-libp2p-utils/commit/1b96837cac6c9625ed243d0f62595582a57f7f04)) * Update .github/workflows/semantic-pull-request.yml [skip ci] ([10d6e7a](https://github.com/libp2p/js-libp2p-utils/commit/10d6e7a7731b746f199ffb2f186e28185cb512f5)) ### Dependencies * bump @multiformats/multiaddr from 11.6.1 to 12.0.0 ([#83](https://github.com/libp2p/js-libp2p-utils/issues/83)) ([3eeeeba](https://github.com/libp2p/js-libp2p-utils/commit/3eeeeba52b764b96463a1b6bcfcff394492eab2e)) * **dev:** bump aegir from 37.12.1 to 38.1.7 ([#80](https://github.com/libp2p/js-libp2p-utils/issues/80)) ([2c262ba](https://github.com/libp2p/js-libp2p-utils/commit/2c262ba37d3668bc4f957914c40c5167cd8faf4f)) --- CHANGELOG.md | 16 ++++++++++++++++ package.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f7e00254a..fc5141c2a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +## [3.0.5](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.4...v3.0.5) (2023-03-17) + + +### Trivial Changes + +* replace err-code with CodeError ([#70](https://github.com/libp2p/js-libp2p-utils/issues/70)) ([beb252d](https://github.com/libp2p/js-libp2p-utils/commit/beb252d79f69d0f49d1fa4fd664a49e33ff80cd3)), closes [js-libp2p#1269](https://github.com/libp2p/js-libp2p/issues/1269) +* Update .github/workflows/semantic-pull-request.yml [skip ci] ([acad1fe](https://github.com/libp2p/js-libp2p-utils/commit/acad1fe38a1cfef19f63de7283e721caec059d34)) +* Update .github/workflows/semantic-pull-request.yml [skip ci] ([1b96837](https://github.com/libp2p/js-libp2p-utils/commit/1b96837cac6c9625ed243d0f62595582a57f7f04)) +* Update .github/workflows/semantic-pull-request.yml [skip ci] ([10d6e7a](https://github.com/libp2p/js-libp2p-utils/commit/10d6e7a7731b746f199ffb2f186e28185cb512f5)) + + +### Dependencies + +* bump @multiformats/multiaddr from 11.6.1 to 12.0.0 ([#83](https://github.com/libp2p/js-libp2p-utils/issues/83)) ([3eeeeba](https://github.com/libp2p/js-libp2p-utils/commit/3eeeeba52b764b96463a1b6bcfcff394492eab2e)) +* **dev:** bump aegir from 37.12.1 to 38.1.7 ([#80](https://github.com/libp2p/js-libp2p-utils/issues/80)) ([2c262ba](https://github.com/libp2p/js-libp2p-utils/commit/2c262ba37d3668bc4f957914c40c5167cd8faf4f)) + ## [3.0.4](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.3...v3.0.4) (2022-12-16) diff --git a/package.json b/package.json index a810bb3993..a16ceba83e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "3.0.4", + "version": "3.0.5", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From af2c2221ad175a06f758a45fc71fbb2f870eece4 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Mon, 27 Mar 2023 10:02:02 +0100 Subject: [PATCH 107/124] fix: handle non ip4/ip6/dns addresses in isPrivate (#84) Update code to allow returning true for addresses that are not publicly routable but are valid like unix sockets. --- src/multiaddr/is-private.ts | 8 ++++++-- test/multiaddr/is-private.spec.ts | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/multiaddr/is-private.ts b/src/multiaddr/is-private.ts index 4d8f416b75..b787e64cb2 100644 --- a/src/multiaddr/is-private.ts +++ b/src/multiaddr/is-private.ts @@ -5,7 +5,11 @@ import isIpPrivate from 'private-ip' * Check if a given multiaddr has a private address. */ export function isPrivate (ma: Multiaddr): boolean { - const { address } = ma.nodeAddress() + try { + const { address } = ma.nodeAddress() - return Boolean(isIpPrivate(address)) + return Boolean(isIpPrivate(address)) + } catch { + return true + } } diff --git a/test/multiaddr/is-private.spec.ts b/test/multiaddr/is-private.spec.ts index 073c416f11..f38629960b 100644 --- a/test/multiaddr/is-private.spec.ts +++ b/test/multiaddr/is-private.spec.ts @@ -53,4 +53,14 @@ describe('multiaddr isPrivate', () => { expect(isPrivate(ma)).to.eql(false) }) }) + + it('identifies non-public addresses', () => { + [ + multiaddr('/ip4/127.0.0.1/tcp/1000/p2p-circuit'), + multiaddr('/unix/foo/bar/baz.sock'), + multiaddr('/ip4/127.0.0.1/sctp/1000') + ].forEach(ma => { + expect(isPrivate(ma)).to.eql(true) + }) + }) }) From e71c46406e1fb65b45ef14405ddd2a3a9397a2d6 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 27 Mar 2023 11:19:22 +0000 Subject: [PATCH 108/124] chore(release): 3.0.6 [skip ci] ## [3.0.6](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.5...v3.0.6) (2023-03-27) ### Bug Fixes * handle non ip4/ip6/dns addresses in isPrivate ([#84](https://github.com/libp2p/js-libp2p-utils/issues/84)) ([af2c222](https://github.com/libp2p/js-libp2p-utils/commit/af2c2221ad175a06f758a45fc71fbb2f870eece4)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc5141c2a5..53cd63f4a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [3.0.6](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.5...v3.0.6) (2023-03-27) + + +### Bug Fixes + +* handle non ip4/ip6/dns addresses in isPrivate ([#84](https://github.com/libp2p/js-libp2p-utils/issues/84)) ([af2c222](https://github.com/libp2p/js-libp2p-utils/commit/af2c2221ad175a06f758a45fc71fbb2f870eece4)) + ## [3.0.5](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.4...v3.0.5) (2023-03-17) diff --git a/package.json b/package.json index a16ceba83e..8beec7fbf3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "3.0.5", + "version": "3.0.6", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From fc286345ff55e23b7619da2bdcedfd848d7c1f85 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 31 Mar 2023 10:33:17 -0500 Subject: [PATCH 109/124] deps(dev): bump it-pipe from 2.0.5 to 3.0.0 (#87) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8beec7fbf3..0792fdd21c 100644 --- a/package.json +++ b/package.json @@ -192,7 +192,7 @@ "aegir": "^38.1.7", "it-all": "^2.0.0", "it-map": "^2.0.0", - "it-pipe": "^2.0.2", + "it-pipe": "^3.0.0", "p-defer": "^4.0.0", "uint8arrays": "^4.0.2" } From 1797a583b70b9fd3b539b071cb489bea98463204 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 31 Mar 2023 15:50:43 +0000 Subject: [PATCH 110/124] chore(release): 3.0.7 [skip ci] ## [3.0.7](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.6...v3.0.7) (2023-03-31) ### Dependencies * **dev:** bump it-pipe from 2.0.5 to 3.0.0 ([#87](https://github.com/libp2p/js-libp2p-utils/issues/87)) ([fc28634](https://github.com/libp2p/js-libp2p-utils/commit/fc286345ff55e23b7619da2bdcedfd848d7c1f85)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53cd63f4a0..2e9985dc5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [3.0.7](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.6...v3.0.7) (2023-03-31) + + +### Dependencies + +* **dev:** bump it-pipe from 2.0.5 to 3.0.0 ([#87](https://github.com/libp2p/js-libp2p-utils/issues/87)) ([fc28634](https://github.com/libp2p/js-libp2p-utils/commit/fc286345ff55e23b7619da2bdcedfd848d7c1f85)) + ## [3.0.6](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.5...v3.0.6) (2023-03-27) diff --git a/package.json b/package.json index 0792fdd21c..7932d9caed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "3.0.6", + "version": "3.0.7", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From d140507f1d4263886c515f4877425a01f28b88e7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 12 Apr 2023 11:13:52 -0500 Subject: [PATCH 111/124] deps: bump @libp2p/interface-connection from 3.1.1 to 4.0.0 (#90) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7932d9caed..f93d0aa00a 100644 --- a/package.json +++ b/package.json @@ -177,7 +177,7 @@ }, "dependencies": { "@achingbrain/ip-address": "^8.1.0", - "@libp2p/interface-connection": "^3.0.2", + "@libp2p/interface-connection": "^4.0.0", "@libp2p/interface-peer-store": "^1.2.1", "@libp2p/interfaces": "^3.2.0", "@libp2p/logger": "^2.0.0", From 114b983372b2b83f19cb20d25975e045f709631c Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 12 Apr 2023 16:22:43 +0000 Subject: [PATCH 112/124] chore(release): 3.0.8 [skip ci] ## [3.0.8](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.7...v3.0.8) (2023-04-12) ### Dependencies * bump @libp2p/interface-connection from 3.1.1 to 4.0.0 ([#90](https://github.com/libp2p/js-libp2p-utils/issues/90)) ([d140507](https://github.com/libp2p/js-libp2p-utils/commit/d140507f1d4263886c515f4877425a01f28b88e7)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e9985dc5a..eddb811a13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [3.0.8](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.7...v3.0.8) (2023-04-12) + + +### Dependencies + +* bump @libp2p/interface-connection from 3.1.1 to 4.0.0 ([#90](https://github.com/libp2p/js-libp2p-utils/issues/90)) ([d140507](https://github.com/libp2p/js-libp2p-utils/commit/d140507f1d4263886c515f4877425a01f28b88e7)) + ## [3.0.7](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.6...v3.0.7) (2023-03-31) diff --git a/package.json b/package.json index f93d0aa00a..50292f9bfc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "3.0.7", + "version": "3.0.8", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From b0295176c2c6553209ebb26149497a5f9a73fc9e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Apr 2023 15:34:55 +0200 Subject: [PATCH 113/124] deps(dev): bump it-all from 2.0.1 to 3.0.1 (#85) Bumps [it-all](https://github.com/achingbrain/it) from 2.0.1 to 3.0.1. - [Release notes](https://github.com/achingbrain/it/releases) - [Commits](https://github.com/achingbrain/it/compare/it-all-v2.0.1...it-all-v3.0.1) --- updated-dependencies: - dependency-name: it-all dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 50292f9bfc..fd051fba3f 100644 --- a/package.json +++ b/package.json @@ -190,7 +190,7 @@ }, "devDependencies": { "aegir": "^38.1.7", - "it-all": "^2.0.0", + "it-all": "^3.0.1", "it-map": "^2.0.0", "it-pipe": "^3.0.0", "p-defer": "^4.0.0", From 6e24d5a91b4df40c7a395d3d3c9379120de0754d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Apr 2023 15:35:33 +0200 Subject: [PATCH 114/124] deps(dev): bump it-map from 2.0.1 to 3.0.2 (#88) Bumps [it-map](https://github.com/achingbrain/it) from 2.0.1 to 3.0.2. - [Release notes](https://github.com/achingbrain/it/releases) - [Commits](https://github.com/achingbrain/it/compare/it-map-v2.0.1...it-map-v3.0.2) --- updated-dependencies: - dependency-name: it-map dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alex Potsides --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fd051fba3f..24f0c6a74a 100644 --- a/package.json +++ b/package.json @@ -191,7 +191,7 @@ "devDependencies": { "aegir": "^38.1.7", "it-all": "^3.0.1", - "it-map": "^2.0.0", + "it-map": "^3.0.2", "it-pipe": "^3.0.0", "p-defer": "^4.0.0", "uint8arrays": "^4.0.2" From 64f1e87c2d67ee5f45b3bca22218e62f939e338a Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 18 Apr 2023 13:40:22 +0000 Subject: [PATCH 115/124] chore(release): 3.0.9 [skip ci] ## [3.0.9](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.8...v3.0.9) (2023-04-18) ### Dependencies * **dev:** bump it-all from 2.0.1 to 3.0.1 ([#85](https://github.com/libp2p/js-libp2p-utils/issues/85)) ([b029517](https://github.com/libp2p/js-libp2p-utils/commit/b0295176c2c6553209ebb26149497a5f9a73fc9e)) * **dev:** bump it-map from 2.0.1 to 3.0.2 ([#88](https://github.com/libp2p/js-libp2p-utils/issues/88)) ([6e24d5a](https://github.com/libp2p/js-libp2p-utils/commit/6e24d5a91b4df40c7a395d3d3c9379120de0754d)) --- CHANGELOG.md | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eddb811a13..3116c753eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## [3.0.9](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.8...v3.0.9) (2023-04-18) + + +### Dependencies + +* **dev:** bump it-all from 2.0.1 to 3.0.1 ([#85](https://github.com/libp2p/js-libp2p-utils/issues/85)) ([b029517](https://github.com/libp2p/js-libp2p-utils/commit/b0295176c2c6553209ebb26149497a5f9a73fc9e)) +* **dev:** bump it-map from 2.0.1 to 3.0.2 ([#88](https://github.com/libp2p/js-libp2p-utils/issues/88)) ([6e24d5a](https://github.com/libp2p/js-libp2p-utils/commit/6e24d5a91b4df40c7a395d3d3c9379120de0754d)) + ## [3.0.8](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.7...v3.0.8) (2023-04-12) diff --git a/package.json b/package.json index 24f0c6a74a..1ca1779334 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "3.0.8", + "version": "3.0.9", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From 0de4a85bd6caa3dfec673ceb3be9130d4051e407 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Apr 2023 18:04:52 -0500 Subject: [PATCH 116/124] deps: bump it-stream-types from 1.0.5 to 2.0.1 (#89) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alex Potsides --- package.json | 9 ++++----- src/stream-to-ma-conn.ts | 11 +++++++---- test/fixtures/pair.ts | 28 ---------------------------- test/stream-to-ma-conn.spec.ts | 10 +++++----- 4 files changed, 16 insertions(+), 42 deletions(-) delete mode 100644 test/fixtures/pair.ts diff --git a/package.json b/package.json index 1ca1779334..97ec125379 100644 --- a/package.json +++ b/package.json @@ -177,23 +177,22 @@ }, "dependencies": { "@achingbrain/ip-address": "^8.1.0", - "@libp2p/interface-connection": "^4.0.0", + "@libp2p/interface-connection": "^5.0.1", "@libp2p/interface-peer-store": "^1.2.1", "@libp2p/interfaces": "^3.2.0", "@libp2p/logger": "^2.0.0", "@multiformats/multiaddr": "^12.0.0", - "abortable-iterator": "^4.0.2", + "abortable-iterator": "^5.0.0", "is-loopback-addr": "^2.0.1", - "it-stream-types": "^1.0.4", + "it-stream-types": "^2.0.1", "private-ip": "^3.0.0", "uint8arraylist": "^2.3.2" }, "devDependencies": { "aegir": "^38.1.7", "it-all": "^3.0.1", - "it-map": "^3.0.2", + "it-pair": "^2.0.6", "it-pipe": "^3.0.0", - "p-defer": "^4.0.0", "uint8arrays": "^4.0.2" } } diff --git a/src/stream-to-ma-conn.ts b/src/stream-to-ma-conn.ts index 941f0a0327..714c395d00 100644 --- a/src/stream-to-ma-conn.ts +++ b/src/stream-to-ma-conn.ts @@ -2,7 +2,7 @@ import { abortableSource } from 'abortable-iterator' import { logger } from '@libp2p/logger' import type { Multiaddr } from '@multiformats/multiaddr' import type { MultiaddrConnection } from '@libp2p/interface-connection' -import type { Duplex } from 'it-stream-types' +import type { Duplex, Source } from 'it-stream-types' import type { Uint8ArrayList } from 'uint8arraylist' const log = logger('libp2p:stream:converter') @@ -30,7 +30,7 @@ export interface StreamOptions { } export interface StreamProperties { - stream: Duplex + stream: Duplex, Source> remoteAddr: Multiaddr localAddr: Multiaddr } @@ -45,7 +45,11 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp const mapSource = (async function * () { for await (const list of source) { - yield * list + if (list instanceof Uint8Array) { + yield list + } else { + yield * list + } } }()) @@ -70,7 +74,6 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp }, source: (options.signal != null) ? abortableSource(mapSource, options.signal) : mapSource, remoteAddr, - /** @type {Timeline} */ timeline: { open: Date.now(), close: undefined }, async close () { await sink(async function * () { diff --git a/test/fixtures/pair.ts b/test/fixtures/pair.ts deleted file mode 100644 index bac8554f94..0000000000 --- a/test/fixtures/pair.ts +++ /dev/null @@ -1,28 +0,0 @@ -import defer from 'p-defer' -import map from 'it-map' -import type { Source, Duplex } from 'it-stream-types' -import { Uint8ArrayList } from 'uint8arraylist' - -/** - * A pair of streams where one drains from the other - */ -export function pair (): Duplex { - const deferred = defer>() - let piped = false - - return { - sink: async source => { - if (piped) { - throw new Error('already piped') - } - - piped = true - deferred.resolve(source) - }, - source: (async function * () { - const source = await deferred.promise - - yield * map(source, (buf) => buf instanceof Uint8Array ? new Uint8ArrayList(buf) : buf) - }()) - } -} diff --git a/test/stream-to-ma-conn.spec.ts b/test/stream-to-ma-conn.spec.ts index 1997862c1a..d3e588bd47 100644 --- a/test/stream-to-ma-conn.spec.ts +++ b/test/stream-to-ma-conn.spec.ts @@ -1,17 +1,17 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import { pair } from './fixtures/pair.js' +import { pair } from 'it-pair' import { pipe } from 'it-pipe' import { multiaddr } from '@multiformats/multiaddr' import { streamToMaConnection } from '../src/stream-to-ma-conn.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import all from 'it-all' import type { Stream } from '@libp2p/interface-connection' -import type { Duplex } from 'it-stream-types' +import type { Duplex, Source } from 'it-stream-types' import type { Uint8ArrayList } from 'uint8arraylist' -function toMuxedStream (stream: Duplex): Stream { +function toMuxedStream (stream: Duplex, Source, Promise>): Stream { const muxedStream: Stream = { ...stream, close: () => {}, @@ -37,7 +37,7 @@ describe('Convert stream into a multiaddr connection', () => { const remoteAddr = multiaddr('/ip4/100.46.74.201/tcp/6002') it('converts a stream and adds the provided metadata', async () => { - const stream = pair() + const stream = pair() const maConn = streamToMaConnection({ stream: toMuxedStream(stream), @@ -58,7 +58,7 @@ describe('Convert stream into a multiaddr connection', () => { }) it('can stream data over the multiaddr connection', async () => { - const stream = pair() + const stream = pair() const maConn = streamToMaConnection({ stream: toMuxedStream(stream), localAddr, From 63f094089d0b607a2544af01b2356879d222198f Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 18 Apr 2023 23:10:07 +0000 Subject: [PATCH 117/124] chore(release): 3.0.10 [skip ci] ## [3.0.10](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.9...v3.0.10) (2023-04-18) ### Dependencies * bump it-stream-types from 1.0.5 to 2.0.1 ([#89](https://github.com/libp2p/js-libp2p-utils/issues/89)) ([0de4a85](https://github.com/libp2p/js-libp2p-utils/commit/0de4a85bd6caa3dfec673ceb3be9130d4051e407)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3116c753eb..6678142fb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [3.0.10](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.9...v3.0.10) (2023-04-18) + + +### Dependencies + +* bump it-stream-types from 1.0.5 to 2.0.1 ([#89](https://github.com/libp2p/js-libp2p-utils/issues/89)) ([0de4a85](https://github.com/libp2p/js-libp2p-utils/commit/0de4a85bd6caa3dfec673ceb3be9130d4051e407)) + ## [3.0.9](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.8...v3.0.9) (2023-04-18) diff --git a/package.json b/package.json index 97ec125379..ef55f6ec48 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "3.0.9", + "version": "3.0.10", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From c7569d77a56d5fc3a5323c89ba93230206c35d2b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Apr 2023 14:48:04 +0100 Subject: [PATCH 118/124] deps: bump @libp2p/interface-peer-store from 1.2.9 to 2.0.0 (#91) Bumps [@libp2p/interface-peer-store](https://github.com/libp2p/js-libp2p-interfaces) from 1.2.9 to 2.0.0. - [Release notes](https://github.com/libp2p/js-libp2p-interfaces/releases) - [Commits](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interface-peer-store-v1.2.9...@libp2p/interface-peer-store-v2.0.0) --- updated-dependencies: - dependency-name: "@libp2p/interface-peer-store" dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ef55f6ec48..f0706abf98 100644 --- a/package.json +++ b/package.json @@ -178,7 +178,7 @@ "dependencies": { "@achingbrain/ip-address": "^8.1.0", "@libp2p/interface-connection": "^5.0.1", - "@libp2p/interface-peer-store": "^1.2.1", + "@libp2p/interface-peer-store": "^2.0.0", "@libp2p/interfaces": "^3.2.0", "@libp2p/logger": "^2.0.0", "@multiformats/multiaddr": "^12.0.0", From 5223f7f9be64d52ca915528af996d92fe8ce9769 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 24 Apr 2023 13:56:26 +0000 Subject: [PATCH 119/124] chore(release): 3.0.11 [skip ci] ## [3.0.11](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.10...v3.0.11) (2023-04-24) ### Dependencies * bump @libp2p/interface-peer-store from 1.2.9 to 2.0.0 ([#91](https://github.com/libp2p/js-libp2p-utils/issues/91)) ([c7569d7](https://github.com/libp2p/js-libp2p-utils/commit/c7569d77a56d5fc3a5323c89ba93230206c35d2b)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6678142fb8..8c2e8f8368 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [3.0.11](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.10...v3.0.11) (2023-04-24) + + +### Dependencies + +* bump @libp2p/interface-peer-store from 1.2.9 to 2.0.0 ([#91](https://github.com/libp2p/js-libp2p-utils/issues/91)) ([c7569d7](https://github.com/libp2p/js-libp2p-utils/commit/c7569d77a56d5fc3a5323c89ba93230206c35d2b)) + ## [3.0.10](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.9...v3.0.10) (2023-04-18) diff --git a/package.json b/package.json index f0706abf98..8e347114e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "3.0.10", + "version": "3.0.11", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From 2c91adc7e17fadd9f96c0fc222fb5557df037459 Mon Sep 17 00:00:00 2001 From: GitHub Date: Wed, 14 Jun 2023 09:03:53 +0000 Subject: [PATCH 120/124] chore: Update .github/workflows/semantic-pull-request.yml [skip ci] --- .github/workflows/semantic-pull-request.yml | 32 ++------------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml index 4f9798c2d5..bd00f090c1 100644 --- a/.github/workflows/semantic-pull-request.yml +++ b/.github/workflows/semantic-pull-request.yml @@ -1,4 +1,4 @@ -name: "Semantic PR" +name: Semantic PR on: pull_request_target: @@ -9,32 +9,4 @@ on: jobs: main: - name: Validate PR title - runs-on: ubuntu-latest - steps: - - uses: amannn/action-semantic-pull-request@b6bca70dcd3e56e896605356ce09b76f7e1e0d39 # v5.1.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - # Configure which types are allowed (newline delimited). - types: | - feat - fix - chore - docs - deps - test - refactor - ci - requireScope: false - - - name: Check PR title length - env: - TITLE: ${{ github.event.pull_request.title }} - run: | - title_length=${#TITLE} - if [ $title_length -gt 72 ] - then - echo "PR title is too long (greater than 72 characters)" - exit 1 - fi + uses: pl-strflt/.github/.github/workflows/reusable-semantic-pull-request.yml@v0.3 From e5fbee99f549ad708dd375516356c5b20915cf87 Mon Sep 17 00:00:00 2001 From: GitHub Date: Wed, 14 Jun 2023 09:06:07 +0000 Subject: [PATCH 121/124] chore: Update .github/workflows/stale.yml [skip ci] --- .github/workflows/stale.yml | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 6f6d895d19..668bd07d49 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -6,21 +6,4 @@ on: jobs: stale: - - runs-on: ubuntu-latest - permissions: - issues: write - pull-requests: write - - steps: - - uses: actions/stale@v3 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.' - close-issue-message: 'This issue was closed because it is missing author input.' - stale-issue-label: 'kind/stale' - any-of-labels: 'need/author-input' - exempt-issue-labels: 'need/triage,need/community-input,need/maintainer-input,need/maintainers-input,need/analysis,status/blocked,status/in-progress,status/ready,status/deferred,status/inactive' - days-before-issue-stale: 6 - days-before-issue-close: 7 - enable-statistics: true + uses: pl-strflt/.github/.github/workflows/reusable-stale-issue.yml@v0.3 From da6547cdd073ba1a4225be5a419c6776c4ebe6f1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Jun 2023 15:47:52 +0200 Subject: [PATCH 122/124] deps(dev): bump aegir from 38.1.8 to 39.0.10 (#100) * deps(dev): bump aegir from 38.1.8 to 39.0.10 Bumps [aegir](https://github.com/ipfs/aegir) from 38.1.8 to 39.0.10. - [Release notes](https://github.com/ipfs/aegir/releases) - [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md) - [Commits](https://github.com/ipfs/aegir/compare/v38.1.8...v39.0.10) --- updated-dependencies: - dependency-name: aegir dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * chore: fix linting --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: achingbrain --- package.json | 2 +- src/address-sort.ts | 2 +- src/ip-port-to-multiaddr.ts | 6 +++--- src/multiaddr/is-private.ts | 2 +- src/stream-to-ma-conn.ts | 4 ++-- test/address-sort.spec.ts | 2 +- test/array-equals.spec.ts | 2 +- test/multiaddr/is-loopback.spec.ts | 2 +- test/multiaddr/is-private.spec.ts | 2 +- test/stream-to-ma-conn.spec.ts | 8 ++++---- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 8e347114e2..d1ad8245fd 100644 --- a/package.json +++ b/package.json @@ -189,7 +189,7 @@ "uint8arraylist": "^2.3.2" }, "devDependencies": { - "aegir": "^38.1.7", + "aegir": "^39.0.10", "it-all": "^3.0.1", "it-pair": "^2.0.6", "it-pipe": "^3.0.0", diff --git a/src/address-sort.ts b/src/address-sort.ts index b9a1ced15c..3df8ababd4 100644 --- a/src/address-sort.ts +++ b/src/address-sort.ts @@ -20,8 +20,8 @@ * ``` */ -import type { Address } from '@libp2p/interface-peer-store' import { isPrivate } from './multiaddr/is-private.js' +import type { Address } from '@libp2p/interface-peer-store' /** * Compare function for array.sort(). diff --git a/src/ip-port-to-multiaddr.ts b/src/ip-port-to-multiaddr.ts index bb80dcb90e..bff7020e3a 100644 --- a/src/ip-port-to-multiaddr.ts +++ b/src/ip-port-to-multiaddr.ts @@ -1,7 +1,7 @@ -import { logger } from '@libp2p/logger' -import { Multiaddr, multiaddr } from '@multiformats/multiaddr' -import { CodeError } from '@libp2p/interfaces/errors' import { Address4, Address6 } from '@achingbrain/ip-address' +import { CodeError } from '@libp2p/interfaces/errors' +import { logger } from '@libp2p/logger' +import { type Multiaddr, multiaddr } from '@multiformats/multiaddr' const log = logger('libp2p:ip-port-to-multiaddr') diff --git a/src/multiaddr/is-private.ts b/src/multiaddr/is-private.ts index b787e64cb2..ab563e032c 100644 --- a/src/multiaddr/is-private.ts +++ b/src/multiaddr/is-private.ts @@ -1,5 +1,5 @@ -import type { Multiaddr } from '@multiformats/multiaddr' import isIpPrivate from 'private-ip' +import type { Multiaddr } from '@multiformats/multiaddr' /** * Check if a given multiaddr has a private address. diff --git a/src/stream-to-ma-conn.ts b/src/stream-to-ma-conn.ts index 714c395d00..3fa09dac4a 100644 --- a/src/stream-to-ma-conn.ts +++ b/src/stream-to-ma-conn.ts @@ -1,7 +1,7 @@ -import { abortableSource } from 'abortable-iterator' import { logger } from '@libp2p/logger' -import type { Multiaddr } from '@multiformats/multiaddr' +import { abortableSource } from 'abortable-iterator' import type { MultiaddrConnection } from '@libp2p/interface-connection' +import type { Multiaddr } from '@multiformats/multiaddr' import type { Duplex, Source } from 'it-stream-types' import type { Uint8ArrayList } from 'uint8arraylist' diff --git a/test/address-sort.spec.ts b/test/address-sort.spec.ts index 2c20ca4316..39ede62c9a 100644 --- a/test/address-sort.spec.ts +++ b/test/address-sort.spec.ts @@ -1,7 +1,7 @@ /* eslint-env mocha */ -import { expect } from 'aegir/chai' import { multiaddr } from '@multiformats/multiaddr' +import { expect } from 'aegir/chai' import { publicAddressesFirst } from '../src/address-sort.js' describe('address-sort', () => { diff --git a/test/array-equals.spec.ts b/test/array-equals.spec.ts index 8de93ab0ea..7b50b76071 100644 --- a/test/array-equals.spec.ts +++ b/test/array-equals.spec.ts @@ -1,7 +1,7 @@ /* eslint-env mocha */ -import { expect } from 'aegir/chai' import { multiaddr } from '@multiformats/multiaddr' +import { expect } from 'aegir/chai' import { arrayEquals } from '../src/array-equals.js' describe('non primitive array equals', () => { diff --git a/test/multiaddr/is-loopback.spec.ts b/test/multiaddr/is-loopback.spec.ts index cafed69fe1..3aa79ca6cb 100644 --- a/test/multiaddr/is-loopback.spec.ts +++ b/test/multiaddr/is-loopback.spec.ts @@ -1,7 +1,7 @@ /* eslint-env mocha */ -import { expect } from 'aegir/chai' import { multiaddr } from '@multiformats/multiaddr' +import { expect } from 'aegir/chai' import { isLoopback } from '../../src/multiaddr/is-loopback.js' describe('multiaddr isLoopback', () => { diff --git a/test/multiaddr/is-private.spec.ts b/test/multiaddr/is-private.spec.ts index f38629960b..a5a12f6406 100644 --- a/test/multiaddr/is-private.spec.ts +++ b/test/multiaddr/is-private.spec.ts @@ -1,7 +1,7 @@ /* eslint-env mocha */ -import { expect } from 'aegir/chai' import { multiaddr } from '@multiformats/multiaddr' +import { expect } from 'aegir/chai' import { isPrivate } from '../../src/multiaddr/is-private.js' describe('multiaddr isPrivate', () => { diff --git a/test/stream-to-ma-conn.spec.ts b/test/stream-to-ma-conn.spec.ts index d3e588bd47..470cb85090 100644 --- a/test/stream-to-ma-conn.spec.ts +++ b/test/stream-to-ma-conn.spec.ts @@ -1,12 +1,12 @@ /* eslint-env mocha */ +import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' +import all from 'it-all' import { pair } from 'it-pair' import { pipe } from 'it-pipe' -import { multiaddr } from '@multiformats/multiaddr' -import { streamToMaConnection } from '../src/stream-to-ma-conn.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import all from 'it-all' +import { streamToMaConnection } from '../src/stream-to-ma-conn.js' import type { Stream } from '@libp2p/interface-connection' import type { Duplex, Source } from 'it-stream-types' import type { Uint8ArrayList } from 'uint8arraylist' @@ -69,7 +69,7 @@ describe('Convert stream into a multiaddr connection', () => { const streamData = await pipe( [data], maConn, - async (source) => await all(source) + async (source) => all(source) ) expect(streamData).to.eql([data]) From 9511239f6bd9f13f2dbec99d76c0c1a89c4c8f20 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 15 Jun 2023 13:52:02 +0000 Subject: [PATCH 123/124] chore(release): 3.0.12 [skip ci] ## [3.0.12](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.11...v3.0.12) (2023-06-15) ### Trivial Changes * Update .github/workflows/semantic-pull-request.yml [skip ci] ([2c91adc](https://github.com/libp2p/js-libp2p-utils/commit/2c91adc7e17fadd9f96c0fc222fb5557df037459)) * Update .github/workflows/stale.yml [skip ci] ([e5fbee9](https://github.com/libp2p/js-libp2p-utils/commit/e5fbee99f549ad708dd375516356c5b20915cf87)) ### Dependencies * **dev:** bump aegir from 38.1.8 to 39.0.10 ([#100](https://github.com/libp2p/js-libp2p-utils/issues/100)) ([da6547c](https://github.com/libp2p/js-libp2p-utils/commit/da6547cdd073ba1a4225be5a419c6776c4ebe6f1)) --- CHANGELOG.md | 13 +++++++++++++ package.json | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c2e8f8368..8ed268837a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +## [3.0.12](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.11...v3.0.12) (2023-06-15) + + +### Trivial Changes + +* Update .github/workflows/semantic-pull-request.yml [skip ci] ([2c91adc](https://github.com/libp2p/js-libp2p-utils/commit/2c91adc7e17fadd9f96c0fc222fb5557df037459)) +* Update .github/workflows/stale.yml [skip ci] ([e5fbee9](https://github.com/libp2p/js-libp2p-utils/commit/e5fbee99f549ad708dd375516356c5b20915cf87)) + + +### Dependencies + +* **dev:** bump aegir from 38.1.8 to 39.0.10 ([#100](https://github.com/libp2p/js-libp2p-utils/issues/100)) ([da6547c](https://github.com/libp2p/js-libp2p-utils/commit/da6547cdd073ba1a4225be5a419c6776c4ebe6f1)) + ## [3.0.11](https://github.com/libp2p/js-libp2p-utils/compare/v3.0.10...v3.0.11) (2023-04-24) diff --git a/package.json b/package.json index d1ad8245fd..9f12a6c96c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/utils", - "version": "3.0.11", + "version": "3.0.12", "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p-utils#readme", From a226369e22f88fa14f9ddf9b3f426f0a057f954e Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 19 Jun 2023 13:12:44 +0200 Subject: [PATCH 124/124] chore: prepare for monorepo migration --- API.md => packages/utils/API.md | 0 CHANGELOG.md => packages/utils/CHANGELOG.md | 0 LICENSE => packages/utils/LICENSE | 0 LICENSE-APACHE => packages/utils/LICENSE-APACHE | 0 LICENSE-MIT => packages/utils/LICENSE-MIT | 0 README.md => packages/utils/README.md | 0 package.json => packages/utils/package.json | 0 {src => packages/utils/src}/address-sort.ts | 0 {src => packages/utils/src}/array-equals.ts | 0 {src => packages/utils/src}/index.ts | 0 {src => packages/utils/src}/ip-port-to-multiaddr.ts | 0 {src => packages/utils/src}/multiaddr/is-loopback.ts | 0 {src => packages/utils/src}/multiaddr/is-private.ts | 0 {src => packages/utils/src}/stream-to-ma-conn.ts | 0 {test => packages/utils/test}/address-sort.spec.ts | 0 {test => packages/utils/test}/array-equals.spec.ts | 0 {test => packages/utils/test}/ip-port-to-multiaddr.spec.ts | 0 {test => packages/utils/test}/multiaddr/is-loopback.spec.ts | 0 {test => packages/utils/test}/multiaddr/is-private.spec.ts | 0 {test => packages/utils/test}/stream-to-ma-conn.spec.ts | 0 tsconfig.json => packages/utils/tsconfig.json | 0 21 files changed, 0 insertions(+), 0 deletions(-) rename API.md => packages/utils/API.md (100%) rename CHANGELOG.md => packages/utils/CHANGELOG.md (100%) rename LICENSE => packages/utils/LICENSE (100%) rename LICENSE-APACHE => packages/utils/LICENSE-APACHE (100%) rename LICENSE-MIT => packages/utils/LICENSE-MIT (100%) rename README.md => packages/utils/README.md (100%) rename package.json => packages/utils/package.json (100%) rename {src => packages/utils/src}/address-sort.ts (100%) rename {src => packages/utils/src}/array-equals.ts (100%) rename {src => packages/utils/src}/index.ts (100%) rename {src => packages/utils/src}/ip-port-to-multiaddr.ts (100%) rename {src => packages/utils/src}/multiaddr/is-loopback.ts (100%) rename {src => packages/utils/src}/multiaddr/is-private.ts (100%) rename {src => packages/utils/src}/stream-to-ma-conn.ts (100%) rename {test => packages/utils/test}/address-sort.spec.ts (100%) rename {test => packages/utils/test}/array-equals.spec.ts (100%) rename {test => packages/utils/test}/ip-port-to-multiaddr.spec.ts (100%) rename {test => packages/utils/test}/multiaddr/is-loopback.spec.ts (100%) rename {test => packages/utils/test}/multiaddr/is-private.spec.ts (100%) rename {test => packages/utils/test}/stream-to-ma-conn.spec.ts (100%) rename tsconfig.json => packages/utils/tsconfig.json (100%) diff --git a/API.md b/packages/utils/API.md similarity index 100% rename from API.md rename to packages/utils/API.md diff --git a/CHANGELOG.md b/packages/utils/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to packages/utils/CHANGELOG.md diff --git a/LICENSE b/packages/utils/LICENSE similarity index 100% rename from LICENSE rename to packages/utils/LICENSE diff --git a/LICENSE-APACHE b/packages/utils/LICENSE-APACHE similarity index 100% rename from LICENSE-APACHE rename to packages/utils/LICENSE-APACHE diff --git a/LICENSE-MIT b/packages/utils/LICENSE-MIT similarity index 100% rename from LICENSE-MIT rename to packages/utils/LICENSE-MIT diff --git a/README.md b/packages/utils/README.md similarity index 100% rename from README.md rename to packages/utils/README.md diff --git a/package.json b/packages/utils/package.json similarity index 100% rename from package.json rename to packages/utils/package.json diff --git a/src/address-sort.ts b/packages/utils/src/address-sort.ts similarity index 100% rename from src/address-sort.ts rename to packages/utils/src/address-sort.ts diff --git a/src/array-equals.ts b/packages/utils/src/array-equals.ts similarity index 100% rename from src/array-equals.ts rename to packages/utils/src/array-equals.ts diff --git a/src/index.ts b/packages/utils/src/index.ts similarity index 100% rename from src/index.ts rename to packages/utils/src/index.ts diff --git a/src/ip-port-to-multiaddr.ts b/packages/utils/src/ip-port-to-multiaddr.ts similarity index 100% rename from src/ip-port-to-multiaddr.ts rename to packages/utils/src/ip-port-to-multiaddr.ts diff --git a/src/multiaddr/is-loopback.ts b/packages/utils/src/multiaddr/is-loopback.ts similarity index 100% rename from src/multiaddr/is-loopback.ts rename to packages/utils/src/multiaddr/is-loopback.ts diff --git a/src/multiaddr/is-private.ts b/packages/utils/src/multiaddr/is-private.ts similarity index 100% rename from src/multiaddr/is-private.ts rename to packages/utils/src/multiaddr/is-private.ts diff --git a/src/stream-to-ma-conn.ts b/packages/utils/src/stream-to-ma-conn.ts similarity index 100% rename from src/stream-to-ma-conn.ts rename to packages/utils/src/stream-to-ma-conn.ts diff --git a/test/address-sort.spec.ts b/packages/utils/test/address-sort.spec.ts similarity index 100% rename from test/address-sort.spec.ts rename to packages/utils/test/address-sort.spec.ts diff --git a/test/array-equals.spec.ts b/packages/utils/test/array-equals.spec.ts similarity index 100% rename from test/array-equals.spec.ts rename to packages/utils/test/array-equals.spec.ts diff --git a/test/ip-port-to-multiaddr.spec.ts b/packages/utils/test/ip-port-to-multiaddr.spec.ts similarity index 100% rename from test/ip-port-to-multiaddr.spec.ts rename to packages/utils/test/ip-port-to-multiaddr.spec.ts diff --git a/test/multiaddr/is-loopback.spec.ts b/packages/utils/test/multiaddr/is-loopback.spec.ts similarity index 100% rename from test/multiaddr/is-loopback.spec.ts rename to packages/utils/test/multiaddr/is-loopback.spec.ts diff --git a/test/multiaddr/is-private.spec.ts b/packages/utils/test/multiaddr/is-private.spec.ts similarity index 100% rename from test/multiaddr/is-private.spec.ts rename to packages/utils/test/multiaddr/is-private.spec.ts diff --git a/test/stream-to-ma-conn.spec.ts b/packages/utils/test/stream-to-ma-conn.spec.ts similarity index 100% rename from test/stream-to-ma-conn.spec.ts rename to packages/utils/test/stream-to-ma-conn.spec.ts diff --git a/tsconfig.json b/packages/utils/tsconfig.json similarity index 100% rename from tsconfig.json rename to packages/utils/tsconfig.json