diff --git a/README.md b/README.md index 5b32ecb218..fd67cc66ae 100644 --- a/README.md +++ b/README.md @@ -455,8 +455,18 @@ A set of data types are exposed directly from the IPFS instance under `ipfs.type - [`ipfs.types.PeerId`](https://github.com/libp2p/js-peer-id) - [`ipfs.types.PeerInfo`](https://github.com/libp2p/js-peer-info) - [`ipfs.types.multiaddr`](https://github.com/multiformats/js-multiaddr) +- [`ipfs.types.multibase`](https://github.com/multiformats/multibase) - [`ipfs.types.multihash`](https://github.com/multiformats/js-multihash) - [`ipfs.types.CID`](https://github.com/ipld/js-cid) +- [`ipfs.types.dagPB`](https://github.com/ipld/js-ipld-dag-pb) +- [`ipfs.types.dagCBOR`](https://github.com/ipld/js-ipld-dag-cbor) + +#### `Util` + +A set of utils are exposed directly from the IPFS instance under `ipfs.util`. That way you're not required to import/require the following: + +- [`ipfs.util.crypto`](https://github.com/libp2p/js-libp2p-crypto) +- [`ipfs.util.isIPFS`](https://github.com/ipfs-shipyard/is-ipfs) ## FAQ diff --git a/package.json b/package.json index 889ee6bb85..ff9847481d 100644 --- a/package.json +++ b/package.json @@ -113,6 +113,8 @@ "ipfs-multipart": "~0.1.0", "ipfs-repo": "^0.20.0", "ipfs-unixfs": "~0.1.14", + "ipld-dag-cbor": "^0.12.0", + "ipld-dag-pb": "^0.13.1", "ipfs-unixfs-engine": "~0.29.0", "ipld": "^0.17.0", "is-ipfs": "^0.3.2", @@ -141,6 +143,7 @@ "mafmt": "^6.0.0", "mime-types": "^2.1.18", "mkdirp": "~0.5.1", + "multibase": "^0.4.0", "multiaddr": "^5.0.0", "multihashes": "~0.4.13", "once": "^1.4.0", diff --git a/src/core/index.js b/src/core/index.js index d27d178f85..46f8c9bb2c 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -4,9 +4,14 @@ const BlockService = require('ipfs-block-service') const Ipld = require('ipld') const PeerId = require('peer-id') const PeerInfo = require('peer-info') +const dagCBOR = require('ipld-dag-cbor') +const dagPB = require('ipld-dag-pb') +const crypto = require('libp2p-crypto') +const isIPFS = require('is-ipfs') const multiaddr = require('multiaddr') const multihash = require('multihashes') const PeerBook = require('peer-book') +const multibase = require('multibase') const CID = require('cids') const debug = require('debug') const extend = require('deep-extend') @@ -58,8 +63,11 @@ class IPFS extends EventEmitter { PeerId: PeerId, PeerInfo: PeerInfo, multiaddr: multiaddr, + multibase: multibase, multihash: multihash, - CID: CID + CID: CID, + dagPB: dagPB, + dagCBOR: dagCBOR } // IPFS Core Internals @@ -120,6 +128,12 @@ class IPFS extends EventEmitter { this.lsReadableStream = this.files.lsReadableStreamImmutable this.lsPullStream = this.files.lsPullStreamImmutable + // ipfs.util + this.util = { + crypto: crypto, + isIPFS: isIPFS + } + boot(this) } } diff --git a/test/core/init.spec.js b/test/core/init.spec.js index 58916ecbe4..92c4623d97 100644 --- a/test/core/init.spec.js +++ b/test/core/init.spec.js @@ -10,7 +10,12 @@ const isNode = require('detect-node') const hat = require('hat') const PeerId = require('peer-id') const PeerInfo = require('peer-info') +const dagCBOR = require('ipld-dag-cbor') +const dagPB = require('ipld-dag-pb') +const crypto = require('libp2p-crypto') +const isIPFS = require('is-ipfs') const multiaddr = require('multiaddr') +const multibase = require('multibase') const multihash = require('multihashes') const CID = require('cids') const IPFS = require('../../src/core') @@ -101,8 +106,18 @@ describe('init', () => { PeerId: PeerId, PeerInfo: PeerInfo, multiaddr: multiaddr, + multibase: multibase, multihash: multihash, - CID: CID + CID: CID, + dagPB: dagPB, + dagCBOR: dagCBOR + }) + }) + + it('util', () => { + expect(ipfs.util).to.be.deep.equal({ + crypto: crypto, + isIPFS: isIPFS }) }) })