From 71949a20c0a9f503d43afd5ed5e07f9ad7429f61 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Thu, 13 Aug 2020 21:21:29 +0200 Subject: [PATCH 1/5] fix: validate with inline keys --- packages/ipfs/src/core/ipns/resolver.js | 29 +------------------------ packages/ipfs/test/core/name-pubsub.js | 10 +++++++-- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/packages/ipfs/src/core/ipns/resolver.js b/packages/ipfs/src/core/ipns/resolver.js index 57bf65e740..96eaae99e9 100644 --- a/packages/ipfs/src/core/ipns/resolver.js +++ b/packages/ipfs/src/core/ipns/resolver.js @@ -99,34 +99,7 @@ class IpnsResolver { throw errcode(new Error('found ipns record that we couldn\'t convert to a value'), 'ERR_INVALID_RECORD_RECEIVED') } - // if the record has a public key validate it - if (ipnsEntry.pubKey) { - return this._validateRecord(peerId, ipnsEntry) - } - - // Otherwise, try to get the public key from routing - let pubKey - try { - pubKey = await this._routing.get(routingKey.toBuffer()) - } catch (err) { - log.error(err) - - if (err.code === ERR_NOT_FOUND) { - throw errcode(new Error(`public key requested for ${name} was not found in the network`), 'ERR_NO_RECORD_FOUND') - } - - throw errcode(new Error(`unexpected error getting the public key for the ipns record ${peerId.id}`), 'ERR_UNEXPECTED_ERROR_GETTING_PUB_KEY') - } - - try { - // Insert it into the peer id, in order to be validated by IPNS validator - peerId.pubKey = crypto.keys.unmarshalPublicKey(pubKey) - } catch (err) { - log.error(err) - - throw errcode(new Error('found public key record that we couldn\'t convert to a value'), 'ERR_INVALID_PUB_KEY_RECEIVED') - } - + // We should have the public key by now (inline, or in the entry) return this._validateRecord(peerId, ipnsEntry) } diff --git a/packages/ipfs/test/core/name-pubsub.js b/packages/ipfs/test/core/name-pubsub.js index 93cb421184..02fddc716c 100644 --- a/packages/ipfs/test/core/name-pubsub.js +++ b/packages/ipfs/test/core/name-pubsub.js @@ -18,6 +18,12 @@ const factory = require('../utils/factory') const namespace = '/record/' const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' +const daemonsOptions = { + ipfsOptions: { + EXPERIMENTAL: { ipnsPubsub: true } + } +} + describe('name-pubsub', function () { const df = factory() // TODO make this work in the browser and between daemon and in-proc in nodes @@ -33,8 +39,8 @@ describe('name-pubsub', function () { this.timeout(40 * 1000) nodes = await Promise.all([ - df.spawn({ type: 'proc', ipfsOptions: { pass: nanoid(), EXPERIMENTAL: { ipnsPubsub: true } } }), - df.spawn({ type: 'proc', ipfsOptions: { pass: nanoid(), EXPERIMENTAL: { ipnsPubsub: true } } }) + df.spawn({ ...daemonsOptions }), + df.spawn({ ...daemonsOptions }) ]) nodeA = nodes[0].api From 5e33b530a55f21119953e4fdcdc35dcf3c9b6a8f Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Thu, 13 Aug 2020 21:54:19 +0200 Subject: [PATCH 2/5] test: check inlined pubkey support --- packages/ipfs/src/core/ipns/resolver.js | 1 - packages/ipfs/test/core/name-pubsub.js | 1 - packages/ipfs/test/core/name.spec.js | 15 +++++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/ipfs/src/core/ipns/resolver.js b/packages/ipfs/src/core/ipns/resolver.js index 96eaae99e9..e17fb46999 100644 --- a/packages/ipfs/src/core/ipns/resolver.js +++ b/packages/ipfs/src/core/ipns/resolver.js @@ -1,7 +1,6 @@ 'use strict' const ipns = require('ipns') -const crypto = require('libp2p-crypto') const PeerId = require('peer-id') const errcode = require('err-code') const debug = require('debug') diff --git a/packages/ipfs/test/core/name-pubsub.js b/packages/ipfs/test/core/name-pubsub.js index 02fddc716c..a663f7f34c 100644 --- a/packages/ipfs/test/core/name-pubsub.js +++ b/packages/ipfs/test/core/name-pubsub.js @@ -2,7 +2,6 @@ /* eslint-env mocha */ 'use strict' -const { nanoid } = require('nanoid') const { Buffer } = require('buffer') const { expect } = require('interface-ipfs-core/src/utils/mocha') const base64url = require('base64url') diff --git a/packages/ipfs/test/core/name.spec.js b/packages/ipfs/test/core/name.spec.js index 993fd868ba..d7ddb36dfc 100644 --- a/packages/ipfs/test/core/name.spec.js +++ b/packages/ipfs/test/core/name.spec.js @@ -9,6 +9,7 @@ const { Key } = require('interface-datastore') const last = require('it-last') const PeerId = require('peer-id') const errCode = require('err-code') +const ipns = require('ipns') const getIpnsRoutingConfig = require('../../src/core/ipns/routing/config') const IpnsPublisher = require('../../src/core/ipns/publisher') const IpnsRepublisher = require('../../src/core/ipns/republisher') @@ -199,6 +200,20 @@ describe('name', function () { }) describe('resolver', () => { + it('should resolve an inlined public key', async () => { + const peerId = await PeerId.create({ keyType: 'ed25519' }) + const value = `/ipfs/${peerId.toB58String()}` + const record = await ipns.create(peerId.privKey, value, 1, 10e3) + + const routing = { + get: sinon.stub().returns(ipns.marshal(record)) + } + const resolver = new IpnsResolver(routing) + + const resolved = await resolver.resolve(`/ipns/${peerId.toB58String()}`) + expect(resolved).to.equal(value) + }) + it('should fail to resolve if the received name is not a string', () => { const resolver = new IpnsResolver() return expect(resolver.resolve(false)) From 8ba0ab981fffaddff600b0e65aa32550781b8bac Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Mon, 17 Aug 2020 16:08:57 +0200 Subject: [PATCH 3/5] chore: lock ipfs-utils at 2.3.1 --- packages/ipfs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index 359d011ddb..8880f7b5ef 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -101,7 +101,7 @@ "ipfs-unixfs": "^1.0.3", "ipfs-unixfs-exporter": "^2.0.2", "ipfs-unixfs-importer": "^2.0.2", - "ipfs-utils": "^2.2.2", + "ipfs-utils": "2.3.1", "ipld": "^0.26.2", "ipld-bitcoin": "^0.3.0", "ipld-block": "^0.9.2", From a019448ad61cb583c3ef949f4ee9448e14b28e6a Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Tue, 18 Aug 2020 12:59:33 +0200 Subject: [PATCH 4/5] chore: test with ipfs-utils fix --- packages/interface-ipfs-core/package.json | 2 +- packages/ipfs-core-utils/package.json | 2 +- packages/ipfs-http-client/package.json | 2 +- packages/ipfs/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index 4dce48a062..c20f92a644 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -41,7 +41,7 @@ "dirty-chai": "^2.0.1", "ipfs-unixfs": "^1.0.3", "ipfs-unixfs-importer": "^2.0.2", - "ipfs-utils": "^2.2.2", + "ipfs-utils": "ipfs/js-ipfs-utils#xhr-2", "ipld-block": "^0.9.2", "ipld-dag-cbor": "^0.16.0", "ipld-dag-pb": "^0.19.0", diff --git a/packages/ipfs-core-utils/package.json b/packages/ipfs-core-utils/package.json index f450d1c00d..07f1673047 100644 --- a/packages/ipfs-core-utils/package.json +++ b/packages/ipfs-core-utils/package.json @@ -33,7 +33,7 @@ "buffer": "^5.6.0", "cids": "^0.8.3", "err-code": "^2.0.0", - "ipfs-utils": "^2.2.2", + "ipfs-utils": "ipfs/js-ipfs-utils#xhr-2", "it-all": "^1.0.1", "it-map": "^1.0.0", "it-peekable": "0.0.1" diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index fdbf0bf64d..bd46f78264 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -48,7 +48,7 @@ "debug": "^4.1.0", "form-data": "^3.0.0", "ipfs-core-utils": "^0.3.1", - "ipfs-utils": "^2.2.2", + "ipfs-utils": "ipfs/js-ipfs-utils#xhr-2", "ipld-block": "^0.9.2", "ipld-dag-cbor": "^0.16.0", "ipld-dag-pb": "^0.19.0", diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index 8880f7b5ef..d3b32ae7fa 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -101,7 +101,7 @@ "ipfs-unixfs": "^1.0.3", "ipfs-unixfs-exporter": "^2.0.2", "ipfs-unixfs-importer": "^2.0.2", - "ipfs-utils": "2.3.1", + "ipfs-utils": "ipfs/js-ipfs-utils#xhr-2", "ipld": "^0.26.2", "ipld-bitcoin": "^0.3.0", "ipld-block": "^0.9.2", From d1d4392dbda107525ea4cd74f836f09b8f1c0642 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Tue, 18 Aug 2020 14:22:09 +0200 Subject: [PATCH 5/5] chore: update ipfs-utils to 3.0.0 --- packages/interface-ipfs-core/package.json | 2 +- packages/ipfs-core-utils/package.json | 2 +- packages/ipfs-http-client/package.json | 2 +- packages/ipfs/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index c20f92a644..9477129011 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -41,7 +41,7 @@ "dirty-chai": "^2.0.1", "ipfs-unixfs": "^1.0.3", "ipfs-unixfs-importer": "^2.0.2", - "ipfs-utils": "ipfs/js-ipfs-utils#xhr-2", + "ipfs-utils": "^3.0.0", "ipld-block": "^0.9.2", "ipld-dag-cbor": "^0.16.0", "ipld-dag-pb": "^0.19.0", diff --git a/packages/ipfs-core-utils/package.json b/packages/ipfs-core-utils/package.json index 07f1673047..d0bc7472c5 100644 --- a/packages/ipfs-core-utils/package.json +++ b/packages/ipfs-core-utils/package.json @@ -33,7 +33,7 @@ "buffer": "^5.6.0", "cids": "^0.8.3", "err-code": "^2.0.0", - "ipfs-utils": "ipfs/js-ipfs-utils#xhr-2", + "ipfs-utils": "^3.0.0", "it-all": "^1.0.1", "it-map": "^1.0.0", "it-peekable": "0.0.1" diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index bd46f78264..41b5936f3c 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -48,7 +48,7 @@ "debug": "^4.1.0", "form-data": "^3.0.0", "ipfs-core-utils": "^0.3.1", - "ipfs-utils": "ipfs/js-ipfs-utils#xhr-2", + "ipfs-utils": "^3.0.0", "ipld-block": "^0.9.2", "ipld-dag-cbor": "^0.16.0", "ipld-dag-pb": "^0.19.0", diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index d3b32ae7fa..9922cb227b 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -101,7 +101,7 @@ "ipfs-unixfs": "^1.0.3", "ipfs-unixfs-exporter": "^2.0.2", "ipfs-unixfs-importer": "^2.0.2", - "ipfs-utils": "ipfs/js-ipfs-utils#xhr-2", + "ipfs-utils": "^3.0.0", "ipld": "^0.26.2", "ipld-bitcoin": "^0.3.0", "ipld-block": "^0.9.2",