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

Commit 7861794

Browse files
committed
feat: Provide access to bundled libraries when in browser
1 parent e189b72 commit 7861794

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,18 @@ A set of data types are exposed directly from the IPFS instance under `ipfs.type
366366
- [`ipfs.types.PeerId`](https://github.com/libp2p/js-peer-id)
367367
- [`ipfs.types.PeerInfo`](https://github.com/libp2p/js-peer-info)
368368
- [`ipfs.types.multiaddr`](https://github.com/multiformats/js-multiaddr)
369+
- [`ipfs.types.multibase`](https://github.com/multiformats/multibase)
369370
- [`ipfs.types.multihash`](https://github.com/multiformats/js-multihash)
370371
- [`ipfs.types.CID`](https://github.com/ipld/js-cid)
372+
- [`ipfs.types.dagPB`](https://github.com/ipld/js-ipld-dag-pb)
373+
- [`ipfs.types.dagCBOR`](https://github.com/ipld/js-ipld-dag-cbor)
374+
375+
#### `Util`
376+
377+
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:
378+
379+
- [`ipfs.util.crypto`](https://github.com/libp2p/js-libp2p-crypto)
380+
- [`ipfs.util.isIPFS`](https://github.com/ipfs-shipyard/is-ipfs)
371381

372382
## FAQ
373383

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,16 @@
115115
"ipfs-unixfs": "~0.1.14",
116116
"ipfs-unixfs-engine": "~0.27.0",
117117
"ipld": "^0.15.0",
118+
"ipld-dag-cbor": "^0.12.0",
119+
"ipld-dag-pb": "^0.13.1",
118120
"is-ipfs": "^0.3.2",
119121
"is-stream": "^1.1.0",
120122
"joi": "^13.1.2",
121123
"joi-browser": "^13.0.1",
122124
"joi-multiaddr": "^1.0.1",
123125
"libp2p": "~0.19.2",
124126
"libp2p-circuit": "~0.1.5",
127+
"libp2p-crypto": "^0.12.1",
125128
"libp2p-floodsub": "~0.14.1",
126129
"libp2p-kad-dht": "~0.9.0",
127130
"libp2p-keychain": "~0.3.1",
@@ -141,6 +144,7 @@
141144
"mime-types": "^2.1.18",
142145
"mkdirp": "~0.5.1",
143146
"multiaddr": "^3.1.0",
147+
"multibase": "^0.4.0",
144148
"multihashes": "~0.4.13",
145149
"once": "^1.4.0",
146150
"path-exists": "^3.0.0",

src/core/index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ const BlockService = require('ipfs-block-service')
44
const Ipld = require('ipld')
55
const PeerId = require('peer-id')
66
const PeerInfo = require('peer-info')
7+
const dagCBOR = require('ipld-dag-cbor')
8+
const dagPB = require('ipld-dag-pb')
9+
const crypto = require('libp2p-crypto')
10+
const isIPFS = require('is-ipfs')
711
const multiaddr = require('multiaddr')
812
const multihash = require('multihashes')
913
const PeerBook = require('peer-book')
14+
const multibase = require('multibase')
1015
const CID = require('cids')
1116
const debug = require('debug')
1217
const extend = require('deep-extend')
@@ -58,8 +63,11 @@ class IPFS extends EventEmitter {
5863
PeerId: PeerId,
5964
PeerInfo: PeerInfo,
6065
multiaddr: multiaddr,
66+
multibase: multibase,
6167
multihash: multihash,
62-
CID: CID
68+
CID: CID,
69+
dagPB: dagPB,
70+
dagCBOR: dagCBOR
6371
}
6472

6573
// IPFS Core Internals
@@ -120,6 +128,12 @@ class IPFS extends EventEmitter {
120128
this.lsReadableStream = this.files.lsReadableStreamImmutable
121129
this.lsPullStream = this.files.lsPullStreamImmutable
122130

131+
// ipfs.util
132+
this.util = {
133+
crypto: crypto,
134+
isIPFS: isIPFS
135+
}
136+
123137
boot(this)
124138
}
125139
}

test/core/init.spec.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ const isNode = require('detect-node')
1010
const hat = require('hat')
1111
const PeerId = require('peer-id')
1212
const PeerInfo = require('peer-info')
13+
const dagCBOR = require('ipld-dag-cbor')
14+
const dagPB = require('ipld-dag-pb')
15+
const crypto = require('libp2p-crypto')
16+
const isIPFS = require('is-ipfs')
1317
const multiaddr = require('multiaddr')
18+
const multibase = require('multibase')
1419
const multihash = require('multihashes')
1520
const CID = require('cids')
1621
const IPFS = require('../../src/core')
@@ -101,8 +106,18 @@ describe('init', () => {
101106
PeerId: PeerId,
102107
PeerInfo: PeerInfo,
103108
multiaddr: multiaddr,
109+
multibase: multibase,
104110
multihash: multihash,
105-
CID: CID
111+
CID: CID,
112+
dagPB: dagPB,
113+
dagCBOR: dagCBOR
114+
})
115+
})
116+
117+
it('util', () => {
118+
expect(ipfs.util).to.be.deep.equal({
119+
crypto: crypto,
120+
isIPFS: isIPFS
106121
})
107122
})
108123
})

0 commit comments

Comments
 (0)