Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
feat: Provide access to bundled libraries when in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Apr 5, 2018
1 parent e189b72 commit 7861794
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,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

Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@
"ipfs-unixfs": "~0.1.14",
"ipfs-unixfs-engine": "~0.27.0",
"ipld": "^0.15.0",
"ipld-dag-cbor": "^0.12.0",
"ipld-dag-pb": "^0.13.1",
"is-ipfs": "^0.3.2",
"is-stream": "^1.1.0",
"joi": "^13.1.2",
"joi-browser": "^13.0.1",
"joi-multiaddr": "^1.0.1",
"libp2p": "~0.19.2",
"libp2p-circuit": "~0.1.5",
"libp2p-crypto": "^0.12.1",
"libp2p-floodsub": "~0.14.1",
"libp2p-kad-dht": "~0.9.0",
"libp2p-keychain": "~0.3.1",
Expand All @@ -141,6 +144,7 @@
"mime-types": "^2.1.18",
"mkdirp": "~0.5.1",
"multiaddr": "^3.1.0",
"multibase": "^0.4.0",
"multihashes": "~0.4.13",
"once": "^1.4.0",
"path-exists": "^3.0.0",
Expand Down
16 changes: 15 additions & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
17 changes: 16 additions & 1 deletion test/core/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
})
})
})

0 comments on commit 7861794

Please sign in to comment.