From ac30a82ad14723e5826b9cb613256ee6faf3044c Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Tue, 13 Nov 2018 08:46:09 +0000 Subject: [PATCH] fix: updates ipld-dag-pb dep to version without .cid properties (#889) Follows on from https://github.com/ipld/js-ipld-dag-pb/pull/99 and updates this module to not rely on DAGNodes having knowledge of their CIDs. --- examples/bundle-browserify/package.json | 2 +- examples/bundle-webpack/package.json | 2 +- package.json | 4 ++-- src/object/addLink.js | 2 +- src/object/new.js | 4 ---- src/object/put.js | 20 ++++++++++---------- src/utils/clean-multihash.js | 4 ++++ 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/bundle-browserify/package.json b/examples/bundle-browserify/package.json index f69d566d0..576b8304c 100644 --- a/examples/bundle-browserify/package.json +++ b/examples/bundle-browserify/package.json @@ -11,7 +11,7 @@ "license": "MIT", "devDependencies": { "browserify": "^13.1.1", - "ipfs-api": "^24.0.0", + "ipfs-api": "../../", "http-server": "~0.9.0" }, "dependencies": {} diff --git a/examples/bundle-webpack/package.json b/examples/bundle-webpack/package.json index b1ad4eead..be4be8fa6 100644 --- a/examples/bundle-webpack/package.json +++ b/examples/bundle-webpack/package.json @@ -11,7 +11,7 @@ "devDependencies": { "babel-core": "^5.4.7", "babel-loader": "^5.1.2", - "ipfs-api": "^11.1.0", + "ipfs-api": "../../", "json-loader": "~0.5.3", "react": "~0.13.0", "react-hot-loader": "^1.3.0", diff --git a/package.json b/package.json index b28f9a6b0..3f2c56d6f 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "ipfs-block": "~0.8.0", "ipfs-unixfs": "~0.1.16", "ipld-dag-cbor": "~0.13.0", - "ipld-dag-pb": "~0.14.11", + "ipld-dag-pb": "~0.15.0", "is-ipfs": "~0.4.7", "is-pull-stream": "0.0.0", "is-stream": "^1.1.0", @@ -85,7 +85,7 @@ "eslint-plugin-react": "^7.11.1", "go-ipfs-dep": "~0.4.18", "gulp": "^3.9.1", - "interface-ipfs-core": "~0.84.3", + "interface-ipfs-core": "~0.85.0", "ipfsd-ctl": "~0.40.0", "pull-stream": "^3.6.9", "stream-equal": "^1.1.1" diff --git a/src/object/addLink.js b/src/object/addLink.js index 3659f46f4..d586d73d7 100644 --- a/src/object/addLink.js +++ b/src/object/addLink.js @@ -26,7 +26,7 @@ module.exports = (send) => { args: [ multihash, dLink.name, - cleanMultihash(dLink.multihash) + cleanMultihash(dLink.cid.buffer) ] }, (err, result) => { if (err) { diff --git a/src/object/new.js b/src/object/new.js index e508be129..351e7b885 100644 --- a/src/object/new.js +++ b/src/object/new.js @@ -35,10 +35,6 @@ module.exports = (send) => { return callback(err) } - if (node.toJSON().multihash !== result.Hash) { - return callback(new Error('multihashes do not match')) - } - callback(null, node) }) }) diff --git a/src/object/put.js b/src/object/put.js index 1fd6aca11..2d4f8ad5a 100644 --- a/src/object/put.js +++ b/src/object/put.js @@ -39,12 +39,12 @@ module.exports = (send) => { Links: [] } } - } else if (obj.multihash) { + } else if (DAGNode.isDAGNode(obj)) { tmpObj = { Data: obj.data.toString(), Links: obj.links.map((l) => { const link = l.toJSON() - link.hash = link.multihash + link.hash = link.cid return link }) } @@ -82,7 +82,7 @@ module.exports = (send) => { let node - if (obj.multihash) { + if (DAGNode.isDAGNode(obj)) { node = obj } else if (options.enc === 'protobuf') { dagPB.util.deserialize(obj, (err, _node) => { @@ -106,14 +106,14 @@ module.exports = (send) => { next() function next () { - const nodeJSON = node.toJSON() - if (nodeJSON.multihash !== result.Hash) { - const err = new Error('multihashes do not match') - return callback(err) - } + dagPB.util.cid(node, (err, cid) => { + if (err) { + return callback(err) + } - cache.set(result.Hash, node) - callback(null, node) + cache.set(cid.toBaseEncodedString(), node) + callback(null, node) + }) } }) }) diff --git a/src/utils/clean-multihash.js b/src/utils/clean-multihash.js index ff66af759..230135ad7 100644 --- a/src/utils/clean-multihash.js +++ b/src/utils/clean-multihash.js @@ -1,12 +1,16 @@ 'use strict' const bs58 = require('bs58') +const CID = require('cids') const isIPFS = require('is-ipfs') module.exports = function (multihash) { if (Buffer.isBuffer(multihash)) { multihash = bs58.encode(multihash) } + if (CID.isCID(multihash)) { + multihash = multihash.toBaseEncodedString() + } if (typeof multihash !== 'string') { throw new Error('unexpected multihash type: ' + typeof multihash) }