Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit 75037ea

Browse files
authored
fix: update all deps to versions that return uint8arrays (#286)
Removes use of node Buffer in favour of Uint8Arrays and updates all dependencies to versions that do the same. BREAKING CHANGES: - CIDs returned from `put*` methods have breaking API changes See see multiformats/js-cid#117 for changes
1 parent 3e03866 commit 75037ea

12 files changed

+49
-97
lines changed

package.json

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,26 @@
3636
"abort-controller": "^3.0.0",
3737
"aegir": "^25.0.0",
3838
"bitcoinjs-lib": "^5.1.6",
39-
"chai": "^4.2.0",
40-
"chai-as-promised": "^7.1.1",
41-
"dirty-chai": "^2.0.1",
39+
"buffer": "^5.6.0",
4240
"ethereumjs-block": "^2.2.0",
43-
"fs-extra": "^9.0.0",
44-
"ipld-bitcoin": "^0.3.0",
45-
"ipld-ethereum": "^4.0.0",
46-
"ipld-git": "^0.5.0",
41+
"ipld-bitcoin": "^0.4.0",
42+
"ipld-ethereum": "^5.0.0",
43+
"ipld-git": "^0.6.0",
4744
"ipld-in-memory": "^5.0.0",
48-
"ipld-zcash": "^0.4.3",
45+
"ipld-zcash": "^0.5.0",
4946
"merkle-patricia-tree": "^3.0.0",
50-
"multihashes": "^1.0.1",
51-
"rlp": "^2.2.3"
47+
"multihashes": "^3.0.1",
48+
"rlp": "^2.2.3",
49+
"uint8arrays": "^1.0.0"
5250
},
5351
"dependencies": {
54-
"buffer": "^5.6.0",
55-
"cids": "^0.8.3",
56-
"ipld-block": "^0.9.1",
57-
"ipld-dag-cbor": "^0.16.0",
58-
"ipld-dag-pb": "^0.19.0",
59-
"ipld-raw": "^5.0.0",
52+
"cids": "^1.0.0",
53+
"ipld-block": "^0.10.0",
54+
"ipld-dag-cbor": "^0.17.0",
55+
"ipld-dag-pb": "^0.20.0",
56+
"ipld-raw": "^6.0.0",
6057
"merge-options": "^2.0.0",
61-
"multicodec": "^1.0.0",
58+
"multicodec": "^2.0.0",
6259
"typical": "^6.0.0"
6360
},
6461
"contributors": [

src/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const ipldDagPb = require('ipld-dag-pb')
88
const ipldRaw = require('ipld-raw')
99
const multicodec = require('multicodec')
1010
const typical = require('typical')
11-
const { Buffer } = require('buffer')
1211
const { extendIterator } = require('./util')
1312

1413
class IPLDResolver {
@@ -150,7 +149,7 @@ class IPLDResolver {
150149
*/
151150
getMany (cids, options) {
152151
if (!typical.isIterable(cids) || typeof cids === 'string' ||
153-
Buffer.isBuffer(cids)) {
152+
cids instanceof Uint8Array) {
154153
throw new Error('`cids` must be an iterable of CIDs')
155154
}
156155

@@ -221,7 +220,7 @@ class IPLDResolver {
221220
*/
222221
putMany (nodes, format, userOptions) {
223222
if (!typical.isIterable(nodes) || typeof nodes === 'string' ||
224-
Buffer.isBuffer(nodes)) {
223+
nodes instanceof Uint8Array) {
225224
throw new Error('`nodes` must be an iterable')
226225
}
227226
if (format === undefined) {
@@ -281,7 +280,7 @@ class IPLDResolver {
281280
*/
282281
removeMany (cids, options) {
283282
if (!typical.isIterable(cids) || typeof cids === 'string' ||
284-
Buffer.isBuffer(cids)) {
283+
cids instanceof Uint8Array) {
285284
throw new Error('`cids` must be an iterable of CIDs')
286285
}
287286

test/basics.spec.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const dirtyChai = require('dirty-chai')
6-
const chaiAsProised = require('chai-as-promised')
7-
const expect = chai.expect
8-
chai.use(dirtyChai)
9-
chai.use(chaiAsProised)
4+
const { expect } = require('aegir/utils/chai')
105
const CID = require('cids')
116
const multihash = require('multihashes')
127
const multicodec = require('multicodec')
138
const inMemory = require('ipld-in-memory')
149
const AbortController = require('abort-controller')
15-
const { Buffer } = require('buffer')
10+
const uint8ArrayFromString = require('uint8arrays/from-string')
1611

1712
const IPLDResolver = require('../src')
1813

@@ -28,7 +23,7 @@ describe('validation', () => {
2823
const cid = new CID(
2924
1,
3025
'blake2b-8',
31-
multihash.encode(Buffer.from('abcd', 'hex'), 'sha1')
26+
multihash.encode(uint8ArrayFromString('abcd', 'base16'), 'sha1')
3227
)
3328
const result = r.resolve(cid, '')
3429
await expect(result.next()).to.be.rejectedWith(
@@ -61,7 +56,7 @@ describe('validation', () => {
6156
const cid = new CID(
6257
1,
6358
'blake2b-8',
64-
multihash.encode(Buffer.from('abcd', 'hex'), 'sha1')
59+
multihash.encode(uint8ArrayFromString('abcd', 'base16'), 'sha1')
6560
)
6661
const result = r.tree(cid)
6762
await expect(result.next()).to.be.rejectedWith(
@@ -97,7 +92,7 @@ describe('aborting requests', () => {
9792
const controller = new AbortController()
9893
setTimeout(() => controller.abort(), 100)
9994

100-
await expect(r.put(Buffer.from([0, 1, 2]), multicodec.RAW, {
95+
await expect(r.put(Uint8Array.from([0, 1, 2]), multicodec.RAW, {
10196
signal: controller.signal
10297
})).to.eventually.rejectedWith(abortedErr)
10398
})
@@ -106,7 +101,7 @@ describe('aborting requests', () => {
106101
const controller = new AbortController()
107102
setTimeout(() => controller.abort(), 100)
108103

109-
await expect(r.putMany([Buffer.from([0, 1, 2])], multicodec.RAW, {
104+
await expect(r.putMany([Uint8Array.from([0, 1, 2])], multicodec.RAW, {
110105
signal: controller.signal
111106
}).all()).to.eventually.rejectedWith(abortedErr)
112107
})

test/format-support.spec.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const dirtyChai = require('dirty-chai')
6-
const chaiAsProised = require('chai-as-promised')
7-
const expect = chai.expect
8-
chai.use(dirtyChai)
9-
chai.use(chaiAsProised)
4+
const { expect } = require('aegir/utils/chai')
105
const dagCBOR = require('ipld-dag-cbor')
116
const multicodec = require('multicodec')
127
const inMemory = require('ipld-in-memory')

test/ipld-all.spec.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@
77
* Test data made of mixed data structures!
88
*/
99

10-
const chai = require('chai')
11-
const chaiAsProised = require('chai-as-promised')
12-
const dirtyChai = require('dirty-chai')
13-
const expect = chai.expect
14-
chai.use(chaiAsProised)
15-
chai.use(dirtyChai)
10+
const { expect } = require('aegir/utils/chai')
1611
const dagPB = require('ipld-dag-pb')
1712
const CID = require('cids')
1813
const inMemory = require('ipld-in-memory')
1914
const multicodec = require('multicodec')
20-
const { Buffer } = require('buffer')
15+
const uint8ArrayFromString = require('uint8arrays/from-string')
2116

2217
const IPLDResolver = require('../src')
2318

@@ -32,7 +27,7 @@ describe('IPLD Resolver for dag-cbor + dag-pb', () => {
3227
before(async () => {
3328
resolver = await inMemory(IPLDResolver)
3429

35-
nodePb = new dagPB.DAGNode(Buffer.from('I am inside a Protobuf'))
30+
nodePb = new dagPB.DAGNode(uint8ArrayFromString('I am inside a Protobuf'))
3631
cidPb = await resolver.put(nodePb, multicodec.DAG_PB, { cidVersion: 0 })
3732

3833
nodeCbor = {
@@ -50,11 +45,11 @@ describe('IPLD Resolver for dag-cbor + dag-pb', () => {
5045
expect(node1.remainderPath).to.eql('Data')
5146
expect(node1.value.equals(cidPb)).to.be.true()
5247
expect(node2.remainderPath).to.eql('')
53-
expect(node2.value).to.eql(Buffer.from('I am inside a Protobuf'))
48+
expect(node2.value).to.eql(uint8ArrayFromString('I am inside a Protobuf'))
5449
})
5550

5651
it('does not store nodes when onlyHash is passed', async () => {
57-
const node = new dagPB.DAGNode(Buffer.from('Some data here'))
52+
const node = new dagPB.DAGNode(uint8ArrayFromString('Some data here'))
5853
const cid = await resolver.put(node, multicodec.DAG_PB, {
5954
onlyHash: true,
6055
cidVersion: 1,

test/ipld-bitcoin.spec.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const dirtyChai = require('dirty-chai')
6-
const expect = chai.expect
7-
chai.use(dirtyChai)
4+
const { expect } = require('aegir/utils/chai')
85
const ipldBitcoin = require('ipld-bitcoin')
96
const BitcoinBlock = require('bitcoinjs-lib').Block
107
const multihash = require('multihashes')

test/ipld-dag-cbor.spec.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const dirtyChai = require('dirty-chai')
6-
const chaiAsProised = require('chai-as-promised')
7-
const expect = chai.expect
8-
chai.use(dirtyChai)
9-
chai.use(chaiAsProised)
4+
const { expect } = require('aegir/utils/chai')
105
const dagCBOR = require('ipld-dag-cbor')
116
const multicodec = require('multicodec')
127
const multihash = require('multihashes')

test/ipld-dag-pb.spec.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const chaiAsProised = require('chai-as-promised')
6-
const dirtyChai = require('dirty-chai')
7-
const expect = chai.expect
8-
chai.use(chaiAsProised)
9-
chai.use(dirtyChai)
4+
const { expect } = require('aegir/utils/chai')
105
const dagPB = require('ipld-dag-pb')
116
const multihash = require('multihashes')
127
const multicodec = require('multicodec')
13-
const { Buffer } = require('buffer')
8+
const uint8ArrayFromString = require('uint8arrays/from-string')
149
const inMemory = require('ipld-in-memory')
1510

1611
const IPLDResolver = require('../src')
@@ -27,9 +22,9 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => {
2722
before(async () => {
2823
resolver = await inMemory(IPLDResolver)
2924

30-
node1 = new dagPB.DAGNode(Buffer.from('I am 1'))
31-
node2 = new dagPB.DAGNode(Buffer.from('I am 2'))
32-
node3 = new dagPB.DAGNode(Buffer.from('I am 3'))
25+
node1 = new dagPB.DAGNode(uint8ArrayFromString('I am 1'))
26+
node2 = new dagPB.DAGNode(uint8ArrayFromString('I am 2'))
27+
node3 = new dagPB.DAGNode(uint8ArrayFromString('I am 3'))
3328
const serialized1 = dagPB.util.serialize(node1)
3429
cid1 = await dagPB.util.cid(serialized1)
3530
node2.addLink({
@@ -80,7 +75,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => {
8075
const result = resolver.resolve(cid1, 'Data')
8176
const node = await result.first()
8277
expect(node.remainderPath).to.eql('')
83-
expect(node.value).to.eql(Buffer.from('I am 1'))
78+
expect(node.value).to.eql(uint8ArrayFromString('I am 1'))
8479
})
8580

8681
it('resolves a value within nested scope (1 level)', async () => {
@@ -91,7 +86,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => {
9186
expect(node1.value.equals(cid1)).to.be.true()
9287

9388
expect(node2.remainderPath).to.eql('')
94-
expect(node2.value).to.eql(Buffer.from('I am 1'))
89+
expect(node2.value).to.eql(uint8ArrayFromString('I am 1'))
9590
})
9691

9792
it('resolves value within nested scope (2 levels)', async () => {
@@ -105,7 +100,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => {
105100
expect(node2.value.equals(cid1)).to.be.true()
106101

107102
expect(node3.remainderPath).to.eql('')
108-
expect(node3.value).to.eql(Buffer.from('I am 1'))
103+
expect(node3.value).to.eql(uint8ArrayFromString('I am 1'))
109104
})
110105

111106
it('resolves value within nested scope (2 levels) with named links', async () => {
@@ -119,7 +114,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => {
119114
expect(node2.value.equals(cid1)).to.be.true()
120115

121116
expect(node3.remainderPath).to.eql('')
122-
expect(node3.value).to.eql(Buffer.from('I am 1'))
117+
expect(node3.value).to.eql(uint8ArrayFromString('I am 1'))
123118
})
124119

125120
it('resolver.get round-trip', async () => {
@@ -135,7 +130,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => {
135130
// seems to be some race condition with inserting and removing items.
136131
// Hence create a unique item for this test. Though the tests
137132
// should really be independent so that there are no race conditions.
138-
const node = new dagPB.DAGNode(Buffer.from('a dag-pb node'))
133+
const node = new dagPB.DAGNode(uint8ArrayFromString('a dag-pb node'))
139134
const cid = await resolver.put(node, multicodec.DAG_PB)
140135
const sameAsNode = await resolver.get(cid)
141136
// `size` is lazy, without a call to it a deep equal check would fail
@@ -151,7 +146,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => {
151146
})
152147

153148
it('should return a v0 CID when specified', async () => {
154-
const node = new dagPB.DAGNode(Buffer.from('a dag-pb node'))
149+
const node = new dagPB.DAGNode(uint8ArrayFromString('a dag-pb node'))
155150
const cid = await resolver.put(node, multicodec.DAG_PB, {
156151
cidVersion: 0
157152
})
@@ -160,7 +155,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => {
160155
})
161156

162157
it('should return a v1 CID when specified', async () => {
163-
const node = new dagPB.DAGNode(Buffer.from('a dag-pb node'))
158+
const node = new dagPB.DAGNode(uint8ArrayFromString('a dag-pb node'))
164159
const cid = await resolver.put(node, multicodec.DAG_PB, {
165160
cidVersion: 1
166161
})

test/ipld-eth-block.spec.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const chaiAsProised = require('chai-as-promised')
6-
const dirtyChai = require('dirty-chai')
7-
const expect = chai.expect
8-
chai.use(chaiAsProised)
9-
chai.use(dirtyChai)
4+
const { expect } = require('aegir/utils/chai')
105
const ipldEthBlock = require('ipld-ethereum').ethBlock
116
const EthBlockHeader = require('ethereumjs-block/header')
127
const multihash = require('multihashes')

test/ipld-eth.spec.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const dirtyChai = require('dirty-chai')
6-
const expect = chai.expect
7-
chai.use(dirtyChai)
4+
const { expect } = require('aegir/utils/chai')
85
const rlp = require('rlp')
96
const ipldEthBlock = require('ipld-ethereum').ethBlock
107
const ipldEthStateTrie = require('ipld-ethereum').ethStateTrie

test/ipld-git.spec.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const dirtyChai = require('dirty-chai')
6-
const expect = chai.expect
7-
chai.use(dirtyChai)
4+
const { expect } = require('aegir/utils/chai')
85
const ipldGit = require('ipld-git')
96
const multihash = require('multihashes')
107
const multicodec = require('multicodec')
11-
const { Buffer } = require('buffer')
128
const inMemory = require('ipld-in-memory')
9+
const uint8ArrayFromString = require('uint8arrays/from-string')
1310

1411
const IPLDResolver = require('../src')
1512

@@ -33,7 +30,7 @@ describe('IPLD Resolver with ipld-git', () => {
3330
formats: [ipldGit]
3431
})
3532

36-
blobNode = Buffer.from('626c6f62203800736f6d6564617461', 'hex') // blob 8\0somedata
33+
blobNode = uint8ArrayFromString('626c6f62203800736f6d6564617461', 'base16') // blob 8\0somedata
3734
blobCid = await ipldGit.util.cid(blobNode)
3835

3936
treeNode = {

test/ipld-zcash.spec.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
/* eslint-env mocha */
22
'use strict'
33

4+
const { expect } = require('aegir/utils/chai')
45
const Block = require('ipld-block')
5-
const chai = require('chai')
6-
const chaiAsProised = require('chai-as-promised')
7-
const dirtyChai = require('dirty-chai')
8-
const expect = chai.expect
9-
chai.use(chaiAsProised)
10-
chai.use(dirtyChai)
116
const ipldZcash = require('ipld-zcash')
127
const loadFixture = require('aegir/fixtures')
138
const inMemory = require('ipld-in-memory')

0 commit comments

Comments
 (0)