Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit db83b50

Browse files
vasco-santosdaviddias
authored andcommitted
feat: Provide access to bundled libraries when in browser
1 parent 0e1ad8d commit db83b50

File tree

6 files changed

+120
-0
lines changed

6 files changed

+120
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ In order to be considered "valid", an IPFS core implementation must expose the
103103
- [config](/SPEC/CONFIG.md)
104104
- [stats](/SPEC/STATS.md)
105105
- [repo](/SPEC/REPO.md)
106+
- [**Types**](/SPEC/TYPES.md)
107+
- [**Util**](/SPEC/UTIL.md)
106108

107109
## Contribute
108110

SPEC/TYPES.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
TYPES API
2+
=======
3+
4+
A set of data types are exposed directly from the IPFS instance under `ipfs.types`. That way you're not required to import/require the following.
5+
6+
- [`ipfs.types.Buffer`](https://www.npmjs.com/package/buffer)
7+
- [`ipfs.types.PeerId`](https://github.com/libp2p/js-peer-id)
8+
- [`ipfs.types.PeerInfo`](https://github.com/libp2p/js-peer-info)
9+
- [`ipfs.types.multiaddr`](https://github.com/multiformats/js-multiaddr)
10+
- [`ipfs.types.multibase`](https://github.com/multiformats/multibase)
11+
- [`ipfs.types.multihash`](https://github.com/multiformats/js-multihash)
12+
- [`ipfs.types.CID`](https://github.com/ipld/js-cid)
13+
- [`ipfs.types.dagPB`](https://github.com/ipld/js-ipld-dag-pb)
14+
- [`ipfs.types.dagCBOR`](https://github.com/ipld/js-ipld-dag-cbor)

SPEC/UTIL.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
UTIL API
2+
=======
3+
4+
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:
5+
6+
- [`ipfs.util.crypto`](https://github.com/libp2p/js-libp2p-crypto)
7+
- [`ipfs.util.isIPFS`](https://github.com/ipfs-shipyard/is-ipfs)

js/src/types.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const PeerId = require('peer-id')
5+
const PeerInfo = require('peer-info')
6+
const dagCBOR = require('ipld-dag-cbor')
7+
const dagPB = require('ipld-dag-pb')
8+
const multiaddr = require('multiaddr')
9+
const multibase = require('multibase')
10+
const multihash = require('multihashes')
11+
const CID = require('cids')
12+
13+
const chai = require('chai')
14+
const dirtyChai = require('dirty-chai')
15+
const expect = chai.expect
16+
chai.use(dirtyChai)
17+
18+
describe('.types', function () {
19+
let ipfs
20+
21+
before(function (done) {
22+
// CI takes longer to instantiate the daemon, so we need to increase the
23+
// timeout for the before step
24+
this.timeout(60 * 1000)
25+
26+
common.setup((err, factory) => {
27+
expect(err).to.not.exist()
28+
factory.spawnNode((err, node) => {
29+
expect(err).to.not.exist()
30+
ipfs = node
31+
done()
32+
})
33+
})
34+
})
35+
36+
after((done) => {
37+
common.teardown(done)
38+
})
39+
40+
it('types object', () => {
41+
expect(ipfs.types).to.be.deep.equal({
42+
Buffer: Buffer,
43+
PeerId: PeerId,
44+
PeerInfo: PeerInfo,
45+
multiaddr: multiaddr,
46+
multibase: multibase,
47+
multihash: multihash,
48+
CID: CID,
49+
dagPB: dagPB,
50+
dagCBOR: dagCBOR
51+
})
52+
})
53+
})

js/src/util.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const crypto = require('libp2p-crypto')
5+
const isIPFS = require('is-ipfs')
6+
7+
const chai = require('chai')
8+
const dirtyChai = require('dirty-chai')
9+
const expect = chai.expect
10+
chai.use(dirtyChai)
11+
util
12+
describe('.types', function () {
13+
let ipfs
14+
15+
before(function (done) {
16+
// CI takes longer to instantiate the daemon, so we need to increase the
17+
// timeout for the before step
18+
this.timeout(60 * 1000)
19+
20+
common.setup((err, factory) => {
21+
expect(err).to.not.exist()
22+
factory.spawnNode((err, node) => {
23+
expect(err).to.not.exist()
24+
ipfs = node
25+
done()
26+
})
27+
})
28+
})
29+
30+
after((done) => {
31+
common.teardown(done)
32+
})
33+
34+
it('util object', () => {
35+
expect(ipfs.util).to.be.deep.equal({
36+
crypto: crypto,
37+
isIPFS: isIPFS
38+
})
39+
})
40+
})

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@
4444
"ipfs-block": "~0.6.1",
4545
"ipld-dag-cbor": "~0.12.0",
4646
"ipld-dag-pb": "~0.13.1",
47+
"is-ipfs": "^0.3.2",
48+
"libp2p-crypto": "^0.12.1",
4749
"multiaddr": "^3.1.0",
50+
"multibase": "^0.4.0",
4851
"multihashes": "~0.4.13",
4952
"multihashing-async": "~0.4.8",
5053
"peer-id": "~0.10.6",
54+
"peer-info": "^0.11.6",
5155
"pull-stream": "^3.6.7"
5256
},
5357
"devDependencies": {},

0 commit comments

Comments
 (0)