diff --git a/package.json b/package.json index bb13a13..c9168c0 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 9e9468e..2e54de8 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 dfd27f0..00b9f92 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 b30b709..dd29c3d 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 67e293b..efe6b2f 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 335d461..eb9c0ab 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 4e8dbd7..4f1780e 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 6c83c0a..bb70cba 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 2880973..9c59157 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 aef5503..0c9418b 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 68e4bf1..e7d322a 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,