From 615a9c2643a80c19f83da02a0cad797610711077 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Mon, 9 Nov 2020 22:02:21 +0100 Subject: [PATCH] feat: dnsaddr support in peerMultiaddr This bumps dependencies to the latest versions including js-multiaddr 8.x which shipped support for resolving /dnsaddr/ Peer addresses. License: MIT Signed-off-by: Marcin Rataj --- README.md | 2 +- package.json | 12 ++++++------ src/index.js | 2 +- test/test-multiaddr.spec.js | 7 +++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 39af1d8..297995d 100644 --- a/README.md +++ b/README.md @@ -216,7 +216,7 @@ Returns `true` if the provided `string`, [`Multiaddr`](https://github.com/multif ### `isIPFS.peerMultiaddr(addr)` -Returns `true` if the provided `string`, [`Multiaddr`](https://github.com/multiformats/js-multiaddr) or `Uint8Array` represents a valid "IPFS Peer" multiaddr (matching [`IPFS` format from `mafmt`](https://github.com/multiformats/js-mafmt#api)) or `false` otherwise. +Returns `true` if the provided `string`, [`Multiaddr`](https://github.com/multiformats/js-multiaddr) or `Uint8Array` represents a valid libp2p peer multiaddr (matching [`P2P` format from `mafmt`](https://github.com/multiformats/js-mafmt#api)) or `false` otherwise. # License diff --git a/package.json b/package.json index 0061c16..bc1b732 100644 --- a/package.json +++ b/package.json @@ -41,16 +41,16 @@ "coverage-publish": "aegir coverage --upload" }, "dependencies": { - "cids": "^1.0.0", - "iso-url": "~0.4.7", - "mafmt": "^8.0.0", - "multiaddr": "^8.0.0", - "multibase": "^3.0.0", + "cids": "^1.0.2", + "iso-url": "^1.0.0", + "mafmt": "^8.0.1", + "multiaddr": "^8.1.1", + "multibase": "^3.0.1", "multihashes": "^3.0.1", "uint8arrays": "^1.1.0" }, "devDependencies": { - "aegir": "^25.0.0", + "aegir": "^28.1.0", "pre-commit": "^1.2.2" }, "engines": { diff --git a/src/index.js b/src/index.js index 0b09d08..879f612 100644 --- a/src/index.js +++ b/src/index.js @@ -60,7 +60,7 @@ function isMultiaddr (input) { } function isPeerMultiaddr (input) { - return isMultiaddr(input) && mafmt.IPFS.matches(input) + return isMultiaddr(input) && mafmt.P2P.matches(input) } function isIpfs (input, pattern, protocolMatch = defaultProtocolMatch, hashMatch = defaultHashMath) { diff --git a/test/test-multiaddr.spec.js b/test/test-multiaddr.spec.js index ca2283d..a877dec 100644 --- a/test/test-multiaddr.spec.js +++ b/test/test-multiaddr.spec.js @@ -19,6 +19,12 @@ describe('ipfs multiaddr', () => { done() }) + it('isIPFS.multiaddr should match a string with valid dnsaddr multiaddr', (done) => { + const actual = isIPFS.multiaddr('/dnsaddr/bootstrap.libp2p.io') + expect(actual).to.equal(true) + done() + }) + it('isIPFS.multiaddr should match a valid Multiaddr instance', (done) => { const ma = new Multiaddr('/ip6/::1/udp/1234/http') const actual = isIPFS.multiaddr(ma) @@ -90,6 +96,7 @@ describe('ipfs peerMultiaddr', () => { '/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN', '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit', '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj' ].concat(goodCircuit)