From 19bb6751d89d7806a433b04828a880fcd4940f04 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Mon, 22 Oct 2018 19:36:51 +0200 Subject: [PATCH 1/3] chore: update to js-ipld 0.19 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: dag-cbor nodes now represent links as CID objects The API for [dag-cbor](https://github.com/ipld/js-ipld-dag-cbor) changed. Links are no longer represented as JSON objects (`{"/": "base-encoded-cid"}`, but as [CID objects](https://github.com/ipld/js-cid). `ipfs.dag.get()` and now always return links as CID objects. `ipfs.dag.put()` also expects links to be represented as CID objects. The old-style JSON objects representation is still supported, but deprecated. Prior to this change: ```js const cid = new CID('QmXed8RihWcWFXRRmfSRG9yFjEbXNxu1bDwgCFAN8Dxcq5') // Link as JSON object representation const putCid = await ipfs.dag.put({link: {'/': cid.toBaseEncodedString()}}) const result = await ipfs.dag.get(putCid) console.log(result.value) ``` Output: ```js { link: { '/': } } ``` Now: ```js const cid = new CID('QmXed8RihWcWFXRRmfSRG9yFjEbXNxu1bDwgCFAN8Dxcq5') // Link as CID object const putCid = await ipfs.dag.put({link: cid}) const result = await ipfs.dag.get(putCid) console.log(result.value) ``` Output: ```js { link: CID { codec: 'dag-pb', version: 0, multihash: } } ``` See https://github.com/ipld/ipld/issues/44 for more information on why this change was made. --- .../get-path-accross-formats.js | 2 +- package.json | 10 +++++-- src/cli/utils.js | 15 ++++++++++ src/core/index.js | 28 +++++++++++++++++-- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/examples/traverse-ipld-graphs/get-path-accross-formats.js b/examples/traverse-ipld-graphs/get-path-accross-formats.js index 004c93171b..984e9f234d 100644 --- a/examples/traverse-ipld-graphs/get-path-accross-formats.js +++ b/examples/traverse-ipld-graphs/get-path-accross-formats.js @@ -36,7 +36,7 @@ createNode((err, ipfs) => { const myData = { name: 'David', likes: ['js-ipfs', 'icecream', 'steak'], - hobbies: [{ '/': cidPBNode.toBaseEncodedString() }] + hobbies: [cidPBNode] } ipfs.dag.put(myData, { format: 'dag-cbor', hashAlg: 'sha3-512' }, (err, cid) => { diff --git a/package.json b/package.json index b8e91a43a6..b93cb64b94 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "execa": "~0.10.0", "form-data": "^2.3.2", "hat": "0.0.3", - "interface-ipfs-core": "~0.78.0", + "interface-ipfs-core": "~0.79.0", "ipfsd-ctl": "~0.39.3", "ncp": "^2.0.0", "qs": "^6.5.2", @@ -108,9 +108,15 @@ "ipfs-repo": "~0.24.0", "ipfs-unixfs": "~0.1.15", "ipfs-unixfs-engine": "~0.32.3", - "ipld": "~0.17.3", "ipld-dag-pb": "~0.14.6", "ipns": "~0.3.0", + "ipld": "~0.19.0", + "ipld-bitcoin": "~0.1.8", + "ipld-dag-pb": "~0.14.6", + "ipld-ethereum": "^2.0.1", + "ipld-git": "~0.2.2", + "ipld-raw": "^2.0.1", + "ipld-zcash": "~0.1.6", "is-ipfs": "~0.4.2", "is-pull-stream": "~0.0.0", "is-stream": "^1.1.0", diff --git a/src/cli/utils.js b/src/cli/utils.js index 02f830f6c6..8641c65908 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -11,6 +11,21 @@ const Progress = require('progress') const byteman = require('byteman') const promisify = require('promisify-es6') +// All known IPLD formats +const ipldBitcoin = require('ipld-bitcoin') +const ipldDagCbor = require('ipld-dag-cbor') +const ipldDagPb = require('ipld-dag-pb') +const ipldEthAccountSnapshot = require('ipld-ethereum').ethAccountSnapshot +const ipldEthBlock = require('ipld-ethereum').ethBlock +const ipldEthBlockList = require('ipld-ethereum').ethBlockList +const ipldEthStateTrie = require('ipld-ethereum').ethStateTrie +const ipldEthStorageTrie = require('ipld-ethereum').ethStorageTrie +const ipldEthTrie = require('ipld-ethereum').ethTxTrie +const ipldEthTx = require('ipld-ethereum').ethTx +const ipldGit = require('ipld-git') +const ipldRaw = require('ipld-raw') +const ipldZcash = require('ipld-zcash') + exports = module.exports exports.isDaemonOn = isDaemonOn diff --git a/src/core/index.js b/src/core/index.js index a0b59977cc..990cd38053 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -15,6 +15,21 @@ const debug = require('debug') const extend = require('deep-extend') const EventEmitter = require('events') +// All known IPLD formats +const ipldBitcoin = require('ipld-bitcoin') +const ipldDagCbor = require('ipld-dag-cbor') +const ipldDagPb = require('ipld-dag-pb') +const ipldEthAccountSnapshot = require('ipld-ethereum').ethAccountSnapshot +const ipldEthBlock = require('ipld-ethereum').ethBlock +const ipldEthBlockList = require('ipld-ethereum').ethBlockList +const ipldEthStateTrie = require('ipld-ethereum').ethStateTrie +const ipldEthStorageTrie = require('ipld-ethereum').ethStorageTrie +const ipldEthTrie = require('ipld-ethereum').ethTxTrie +const ipldEthTx = require('ipld-ethereum').ethTx +const ipldGit = require('ipld-git') +const ipldRaw = require('ipld-raw') +const ipldZcash = require('ipld-zcash') + const config = require('./config') const boot = require('./boot') const components = require('./components') @@ -72,7 +87,9 @@ class IPFS extends EventEmitter { multiaddr: multiaddr, multibase: multibase, multihash: multihash, - CID: CID + CID: CID, + dagPB: ipldDagPb, + dagCBOR: ipldDagCbor } // IPFS Core Internals @@ -82,7 +99,14 @@ class IPFS extends EventEmitter { this._libp2pNode = undefined this._bitswap = undefined this._blockService = new BlockService(this._repo) - this._ipld = new Ipld(this._blockService) + this._ipld = new Ipld({ + blockService: this._blockService, + formats: [ + ipldBitcoin, ipldDagCbor, ipldDagPb, ipldEthAccountSnapshot, + ipldEthBlock, ipldEthBlockList, ipldEthStateTrie, ipldEthStorageTrie, + ipldEthTrie, ipldEthTx, ipldGit, ipldRaw, ipldZcash + ] + }) this._preload = preload(this) this._mfsPreload = mfsPreload(this) this._ipns = new IPNS(null, this) From bf6758bd6e601b967baa856971123f93007a407f Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 31 Oct 2018 06:39:57 +0000 Subject: [PATCH 2/3] chore: update deps --- package.json | 95 ++++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index b93cb64b94..bafaafe06a 100644 --- a/package.json +++ b/package.json @@ -59,17 +59,17 @@ }, "homepage": "https://github.com/ipfs/js-ipfs#readme", "devDependencies": { - "aegir": "^15.1.0", - "chai": "^4.1.2", - "delay": "^3.0.0", - "detect-node": "^2.0.3", + "aegir": "^17.0.1", + "chai": "^4.2.0", + "delay": "^4.1.0", + "detect-node": "^2.0.4", "dir-compare": "^1.4.0", "dirty-chai": "^2.0.1", - "execa": "~0.10.0", - "form-data": "^2.3.2", + "execa": "^1.0.0", + "form-data": "^2.3.3", "hat": "0.0.3", - "interface-ipfs-core": "~0.79.0", - "ipfsd-ctl": "~0.39.3", + "interface-ipfs-core": "~0.83.0", + "ipfsd-ctl": "~0.39.5", "ncp": "^2.0.0", "qs": "^6.5.2", "rimraf": "^2.6.2", @@ -78,101 +78,100 @@ "dependencies": { "@nodeutils/defaults-deep": "^1.1.0", "async": "^2.6.1", - "big.js": "^5.1.2", + "big.js": "^5.2.2", "binary-querystring": "~0.1.2", - "bl": "^2.0.1", + "bl": "^2.1.2", "boom": "^7.2.0", "bs58": "^4.0.1", "byteman": "^1.3.5", "cid-tool": "~0.1.0", - "cids": "~0.5.3", - "debug": "^3.1.0", + "cids": "~0.5.5", + "debug": "^4.1.0", "err-code": "^1.1.2", - "file-type": "^8.1.0", + "file-type": "^10.2.0", "fnv1a": "^1.0.1", "fsm-event": "^2.1.0", "get-folder-size": "^2.0.0", - "glob": "^7.1.2", + "glob": "^7.1.3", "hapi": "^16.6.2", "hapi-set-header": "^1.0.2", - "hoek": "^5.0.3", + "hoek": "^5.0.4", "human-to-milliseconds": "^1.0.0", "interface-datastore": "~0.6.0", - "ipfs-api": "^24.0.0", - "ipfs-bitswap": "~0.20.3", - "ipfs-block": "~0.7.1", - "ipfs-block-service": "~0.14.0", - "ipfs-http-response": "~0.1.2", - "ipfs-mfs": "~0.4.0", + "ipfs-api": "^26.0.3", + "ipfs-bitswap": "~0.21.0", + "ipfs-block": "~0.8.0", + "ipfs-block-service": "~0.15.1", + "ipfs-http-response": "~0.2.0", + "ipfs-mfs": "~0.4.2", "ipfs-multipart": "~0.1.0", - "ipfs-repo": "~0.24.0", - "ipfs-unixfs": "~0.1.15", - "ipfs-unixfs-engine": "~0.32.3", - "ipld-dag-pb": "~0.14.6", + "ipfs-repo": "~0.25.0", + "ipfs-unixfs": "~0.1.16", + "ipfs-unixfs-engine": "~0.33.0", + "ipld-dag-pb": "~0.14.11", "ipns": "~0.3.0", - "ipld": "~0.19.0", + "ipld": "~0.19.1", "ipld-bitcoin": "~0.1.8", - "ipld-dag-pb": "~0.14.6", "ipld-ethereum": "^2.0.1", "ipld-git": "~0.2.2", "ipld-raw": "^2.0.1", "ipld-zcash": "~0.1.6", - "is-ipfs": "~0.4.2", + "is-ipfs": "~0.4.7", "is-pull-stream": "~0.0.0", "is-stream": "^1.1.0", "joi": "^13.4.0", "joi-browser": "^13.4.0", "joi-multiaddr": "^2.0.0", - "libp2p": "~0.23.0", + "libp2p": "~0.23.1", "libp2p-bootstrap": "~0.9.3", - "libp2p-crypto": "~0.13.0", - "libp2p-kad-dht": "~0.10.1", - "libp2p-keychain": "~0.3.1", + "libp2p-crypto": "~0.14.0", + "libp2p-kad-dht": "~0.10.6", + "libp2p-keychain": "~0.3.3", "libp2p-mdns": "~0.12.0", - "libp2p-mplex": "~0.8.0", + "libp2p-mplex": "~0.8.2", "libp2p-record": "~0.6.0", "libp2p-secio": "~0.10.0", - "libp2p-tcp": "~0.12.0", - "libp2p-webrtc-star": "~0.15.3", - "libp2p-websocket-star": "~0.8.1", + "libp2p-tcp": "~0.13.0", + "libp2p-webrtc-star": "~0.15.5", + "libp2p-websocket-star": "~0.9.0", "libp2p-websockets": "~0.12.0", - "lodash": "^4.17.10", - "mafmt": "^6.0.0", - "mime-types": "^2.1.19", + "lodash": "^4.17.11", + "mafmt": "^6.0.2", + "mime-types": "^2.1.21", "mkdirp": "~0.5.1", "multiaddr": "^5.0.0", "multiaddr-to-uri": "^4.0.0", "multibase": "~0.5.0", - "multihashes": "~0.4.13", + "multihashes": "~0.4.14", "once": "^1.4.0", "peer-book": "~0.8.0", "peer-id": "~0.12.0", "peer-info": "~0.14.1", - "progress": "^2.0.0", + "progress": "^2.0.1", "promisify-es6": "^1.0.3", "pull-abortable": "^4.1.1", - "pull-defer": "~0.2.2", + "pull-defer": "~0.2.3", "pull-file": "^1.1.0", "pull-ndjson": "~0.1.1", "pull-paramap": "^1.2.2", "pull-pushable": "^2.2.0", "pull-sort": "^1.0.1", - "pull-stream": "^3.6.8", + "pull-stream": "^3.6.9", "pull-stream-to-stream": "^1.3.4", "pull-zip": "^2.0.1", "read-pkg-up": "^4.0.0", - "readable-stream": "2.3.6", + "readable-stream": "3.0.6", "receptacle": "^1.3.2", "stream-to-pull-stream": "^1.7.2", - "tar-stream": "^1.6.1", + "tar-stream": "^1.6.2", "temp": "~0.8.3", "update-notifier": "^2.5.0", - "yargs": "^12.0.1", + "yargs": "^12.0.2", "yargs-promise": "^1.1.0" }, "optionalDependencies": { - "prom-client": "^11.1.1", - "prometheus-gc-stats": "~0.5.1" + "prom-client": "^11.1.3", + "prometheus-gc-stats": "~0.6.0" }, "contributors": [ "0xflotus <0xflotus@gmail.com>", From f3c70e6c0a19a7aca4d81fb284d5afda8a315144 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 31 Oct 2018 07:24:00 +0000 Subject: [PATCH 3/3] test: add remaining types that were added with this PR to the test --- test/core/init.spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/core/init.spec.js b/test/core/init.spec.js index 4db10e7181..84c8df411c 100644 --- a/test/core/init.spec.js +++ b/test/core/init.spec.js @@ -15,6 +15,8 @@ const isIPFS = require('is-ipfs') const multiaddr = require('multiaddr') const multibase = require('multibase') const multihash = require('multihashes') +const ipldDagCbor = require('ipld-dag-cbor') +const ipldDagPb = require('ipld-dag-pb') const CID = require('cids') const IPFS = require('../../src/core') @@ -120,7 +122,9 @@ describe('init', () => { multiaddr: multiaddr, multibase: multibase, multihash: multihash, - CID: CID + CID: CID, + dagPB: ipldDagPb, + dagCBOR: ipldDagCbor }) })