From fdac3e88016c828e66ea9832bbd95d540cde4a9d Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 5 Nov 2019 20:49:57 +0100 Subject: [PATCH 1/2] feat: support name.resolve of peerid as cid This is a hacky way to support CIDs when API is go-ipfs 0.4.22 or older (convert toBase58btc before sending) License: MIT Signed-off-by: Marcin Rataj --- package.json | 2 +- src/name/resolve.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a45e2e32e..70010d07a 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,7 @@ "browser-process-platform": "~0.1.1", "cross-env": "^6.0.0", "go-ipfs-dep": "^0.4.22", - "interface-ipfs-core": "^0.117.2", + "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#feat/peerid-as-cid", "ipfsd-ctl": "^0.47.1", "nock": "^11.4.0", "stream-equal": "^1.1.1" diff --git a/src/name/resolve.js b/src/name/resolve.js index addb567d6..7fcfa09da 100644 --- a/src/name/resolve.js +++ b/src/name/resolve.js @@ -1,6 +1,8 @@ 'use strict' const promisify = require('promisify-es6') +const CID = require('cids') +const multihash = require('multihashes') const transform = function (res, callback) { callback(null, res.Path) @@ -13,6 +15,19 @@ module.exports = (send) => { opts = {} } + // normalize PeerIDs to Base58btc, so it works with go-ipfs <=0.4.22 + if (typeof (args) === 'string') { + try { + const path = args.split('/') + if (path.length > 2) { + path[2] = multihash.toB58String(new CID(path[2]).multihash) + args = path.join('/') + } + } catch (err) { + // noop + } + } + send.andTransform({ path: 'name/resolve', args: args, From 571b126bf37526a8bc908465150ea9b8ac9bcb2c Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 7 Nov 2019 16:38:54 +0100 Subject: [PATCH 2/2] chore: interface-ipfs-core v0.118.0 License: MIT Signed-off-by: Marcin Rataj --- package.json | 2 +- src/name/resolve.js | 15 --------------- test/interface.spec.js | 10 +++++++++- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 70010d07a..811af7099 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,7 @@ "browser-process-platform": "~0.1.1", "cross-env": "^6.0.0", "go-ipfs-dep": "^0.4.22", - "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#feat/peerid-as-cid", + "interface-ipfs-core": "^0.118.0", "ipfsd-ctl": "^0.47.1", "nock": "^11.4.0", "stream-equal": "^1.1.1" diff --git a/src/name/resolve.js b/src/name/resolve.js index 7fcfa09da..addb567d6 100644 --- a/src/name/resolve.js +++ b/src/name/resolve.js @@ -1,8 +1,6 @@ 'use strict' const promisify = require('promisify-es6') -const CID = require('cids') -const multihash = require('multihashes') const transform = function (res, callback) { callback(null, res.Path) @@ -15,19 +13,6 @@ module.exports = (send) => { opts = {} } - // normalize PeerIDs to Base58btc, so it works with go-ipfs <=0.4.22 - if (typeof (args) === 'string') { - try { - const path = args.split('/') - if (path.length > 2) { - path[2] = multihash.toB58String(new CID(path[2]).multihash) - args = path.join('/') - } - } catch (err) { - // noop - } - } - send.andTransform({ path: 'name/resolve', args: args, diff --git a/test/interface.spec.js b/test/interface.spec.js index 090246822..760962b38 100644 --- a/test/interface.spec.js +++ b/test/interface.spec.js @@ -176,7 +176,15 @@ describe('interface-ipfs-core tests', () => { spawnOptions: { args: ['--offline'] } - })) + }), { + skip: [ + // stop + { + name: 'should resolve a record from peerid as cidv1 in base32', + reason: 'TODO not implemented in go-ipfs yet: https://github.com/ipfs/go-ipfs/issues/5287' + } + ] + }) // TODO: uncomment after https://github.com/ipfs/interface-ipfs-core/pull/361 being merged and a new release tests.namePubsub(CommonFactory.create({