From c85f80dc6e254b073935208b6cbfbf168db1774f Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 4 Aug 2020 16:41:09 +0100 Subject: [PATCH] fix: update all deps to versions that return uint8arrays 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 https://github.com/multiformats/js-cid/pull/117 for changes --- package.json | 31 ++++++++++++++----------------- src/index.js | 7 +++---- test/basics.spec.js | 17 ++++++----------- test/format-support.spec.js | 7 +------ test/ipld-all.spec.js | 15 +++++---------- test/ipld-bitcoin.spec.js | 5 +---- test/ipld-dag-cbor.spec.js | 7 +------ test/ipld-dag-pb.spec.js | 29 ++++++++++++----------------- test/ipld-eth-block.spec.js | 7 +------ test/ipld-eth.spec.js | 5 +---- test/ipld-git.spec.js | 9 +++------ test/ipld-zcash.spec.js | 7 +------ 12 files changed, 49 insertions(+), 97 deletions(-) diff --git a/package.json b/package.json index b84e02c..c69cc8c 100644 --- a/package.json +++ b/package.json @@ -36,29 +36,26 @@ "abort-controller": "^3.0.0", "aegir": "^25.0.0", "bitcoinjs-lib": "^5.1.6", - "chai": "^4.2.0", - "chai-as-promised": "^7.1.1", - "dirty-chai": "^2.0.1", + "buffer": "^5.6.0", "ethereumjs-block": "^2.2.0", - "fs-extra": "^9.0.0", - "ipld-bitcoin": "^0.3.0", - "ipld-ethereum": "^4.0.0", - "ipld-git": "^0.5.0", + "ipld-bitcoin": "ipld/js-ipld-bitcoin#fix/replace-node-buffers-with-uint8array", + "ipld-ethereum": "ipld/js-ipld-ethereum#fix/replace-buffers-with-uint8arrays", + "ipld-git": "ipld/js-ipld-git#fix/replace-buffers-with-uint8arrays", "ipld-in-memory": "^5.0.0", - "ipld-zcash": "^0.4.3", + "ipld-zcash": "ipld/js-ipld-zcash#fix/replace-buffers-with-uint8arrays", "merkle-patricia-tree": "^3.0.0", - "multihashes": "^1.0.1", - "rlp": "^2.2.3" + "multihashes": "^3.0.1", + "rlp": "^2.2.3", + "uint8arrays": "^1.0.0" }, "dependencies": { - "buffer": "^5.6.0", - "cids": "^0.8.3", - "ipld-block": "^0.9.1", - "ipld-dag-cbor": "^0.16.0", - "ipld-dag-pb": "^0.19.0", - "ipld-raw": "^5.0.0", + "cids": "^1.0.0", + "ipld-block": "ipld/js-ipld-block#fix/replace-node-buffers-with-uint8arrays", + "ipld-dag-cbor": "ipld/js-ipld-dag-cbor#fix/replace-node-buffers-with-uint8arrays", + "ipld-dag-pb": "ipld/js-ipld-dag-pb", + "ipld-raw": "ipld/js-ipld-raw#fix/replace-node-buffers-with-uint8arrays", "merge-options": "^2.0.0", - "multicodec": "^1.0.0", + "multicodec": "^2.0.0", "typical": "^6.0.0" }, "contributors": [ diff --git a/src/index.js b/src/index.js index 1fcb1c5..7255c37 100644 --- a/src/index.js +++ b/src/index.js @@ -8,7 +8,6 @@ const ipldDagPb = require('ipld-dag-pb') const ipldRaw = require('ipld-raw') const multicodec = require('multicodec') const typical = require('typical') -const { Buffer } = require('buffer') const { extendIterator } = require('./util') class IPLDResolver { @@ -150,7 +149,7 @@ class IPLDResolver { */ getMany (cids, options) { if (!typical.isIterable(cids) || typeof cids === 'string' || - Buffer.isBuffer(cids)) { + cids instanceof Uint8Array) { throw new Error('`cids` must be an iterable of CIDs') } @@ -221,7 +220,7 @@ class IPLDResolver { */ putMany (nodes, format, userOptions) { if (!typical.isIterable(nodes) || typeof nodes === 'string' || - Buffer.isBuffer(nodes)) { + nodes instanceof Uint8Array) { throw new Error('`nodes` must be an iterable') } if (format === undefined) { @@ -281,7 +280,7 @@ class IPLDResolver { */ removeMany (cids, options) { if (!typical.isIterable(cids) || typeof cids === 'string' || - Buffer.isBuffer(cids)) { + cids instanceof Uint8Array) { throw new Error('`cids` must be an iterable of CIDs') } diff --git a/test/basics.spec.js b/test/basics.spec.js index f20e7a9..140499c 100644 --- a/test/basics.spec.js +++ b/test/basics.spec.js @@ -1,18 +1,13 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const chaiAsProised = require('chai-as-promised') -const expect = chai.expect -chai.use(dirtyChai) -chai.use(chaiAsProised) +const { expect } = require('aegir/utils/chai') const CID = require('cids') const multihash = require('multihashes') const multicodec = require('multicodec') const inMemory = require('ipld-in-memory') const AbortController = require('abort-controller') -const { Buffer } = require('buffer') +const uint8ArrayFromString = require('uint8arrays/from-string') const IPLDResolver = require('../src') @@ -28,7 +23,7 @@ describe('validation', () => { const cid = new CID( 1, 'blake2b-8', - multihash.encode(Buffer.from('abcd', 'hex'), 'sha1') + multihash.encode(uint8ArrayFromString('abcd', 'base16'), 'sha1') ) const result = r.resolve(cid, '') await expect(result.next()).to.be.rejectedWith( @@ -61,7 +56,7 @@ describe('validation', () => { const cid = new CID( 1, 'blake2b-8', - multihash.encode(Buffer.from('abcd', 'hex'), 'sha1') + multihash.encode(uint8ArrayFromString('abcd', 'base16'), 'sha1') ) const result = r.tree(cid) await expect(result.next()).to.be.rejectedWith( @@ -97,7 +92,7 @@ describe('aborting requests', () => { const controller = new AbortController() setTimeout(() => controller.abort(), 100) - await expect(r.put(Buffer.from([0, 1, 2]), multicodec.RAW, { + await expect(r.put(Uint8Array.from([0, 1, 2]), multicodec.RAW, { signal: controller.signal })).to.eventually.rejectedWith(abortedErr) }) @@ -106,7 +101,7 @@ describe('aborting requests', () => { const controller = new AbortController() setTimeout(() => controller.abort(), 100) - await expect(r.putMany([Buffer.from([0, 1, 2])], multicodec.RAW, { + await expect(r.putMany([Uint8Array.from([0, 1, 2])], multicodec.RAW, { signal: controller.signal }).all()).to.eventually.rejectedWith(abortedErr) }) diff --git a/test/format-support.spec.js b/test/format-support.spec.js index 825c36d..a55c066 100644 --- a/test/format-support.spec.js +++ b/test/format-support.spec.js @@ -1,12 +1,7 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const chaiAsProised = require('chai-as-promised') -const expect = chai.expect -chai.use(dirtyChai) -chai.use(chaiAsProised) +const { expect } = require('aegir/utils/chai') const dagCBOR = require('ipld-dag-cbor') const multicodec = require('multicodec') const inMemory = require('ipld-in-memory') diff --git a/test/ipld-all.spec.js b/test/ipld-all.spec.js index c2616b4..00b813b 100644 --- a/test/ipld-all.spec.js +++ b/test/ipld-all.spec.js @@ -7,17 +7,12 @@ * Test data made of mixed data structures! */ -const chai = require('chai') -const chaiAsProised = require('chai-as-promised') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(chaiAsProised) -chai.use(dirtyChai) +const { expect } = require('aegir/utils/chai') const dagPB = require('ipld-dag-pb') const CID = require('cids') const inMemory = require('ipld-in-memory') const multicodec = require('multicodec') -const { Buffer } = require('buffer') +const uint8ArrayFromString = require('uint8arrays/from-string') const IPLDResolver = require('../src') @@ -32,7 +27,7 @@ describe('IPLD Resolver for dag-cbor + dag-pb', () => { before(async () => { resolver = await inMemory(IPLDResolver) - nodePb = new dagPB.DAGNode(Buffer.from('I am inside a Protobuf')) + nodePb = new dagPB.DAGNode(uint8ArrayFromString('I am inside a Protobuf')) cidPb = await resolver.put(nodePb, multicodec.DAG_PB, { cidVersion: 0 }) nodeCbor = { @@ -50,11 +45,11 @@ describe('IPLD Resolver for dag-cbor + dag-pb', () => { expect(node1.remainderPath).to.eql('Data') expect(node1.value.equals(cidPb)).to.be.true() expect(node2.remainderPath).to.eql('') - expect(node2.value).to.eql(Buffer.from('I am inside a Protobuf')) + expect(node2.value).to.eql(uint8ArrayFromString('I am inside a Protobuf')) }) it('does not store nodes when onlyHash is passed', async () => { - const node = new dagPB.DAGNode(Buffer.from('Some data here')) + const node = new dagPB.DAGNode(uint8ArrayFromString('Some data here')) const cid = await resolver.put(node, multicodec.DAG_PB, { onlyHash: true, cidVersion: 1, diff --git a/test/ipld-bitcoin.spec.js b/test/ipld-bitcoin.spec.js index 8c49320..46b52ec 100644 --- a/test/ipld-bitcoin.spec.js +++ b/test/ipld-bitcoin.spec.js @@ -1,10 +1,7 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) +const { expect } = require('aegir/utils/chai') const ipldBitcoin = require('ipld-bitcoin') const BitcoinBlock = require('bitcoinjs-lib').Block const multihash = require('multihashes') diff --git a/test/ipld-dag-cbor.spec.js b/test/ipld-dag-cbor.spec.js index 0dd66eb..49d8168 100644 --- a/test/ipld-dag-cbor.spec.js +++ b/test/ipld-dag-cbor.spec.js @@ -1,12 +1,7 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const chaiAsProised = require('chai-as-promised') -const expect = chai.expect -chai.use(dirtyChai) -chai.use(chaiAsProised) +const { expect } = require('aegir/utils/chai') const dagCBOR = require('ipld-dag-cbor') const multicodec = require('multicodec') const multihash = require('multihashes') diff --git a/test/ipld-dag-pb.spec.js b/test/ipld-dag-pb.spec.js index 8e5fce4..3601859 100644 --- a/test/ipld-dag-pb.spec.js +++ b/test/ipld-dag-pb.spec.js @@ -1,16 +1,11 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const chaiAsProised = require('chai-as-promised') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(chaiAsProised) -chai.use(dirtyChai) +const { expect } = require('aegir/utils/chai') const dagPB = require('ipld-dag-pb') const multihash = require('multihashes') const multicodec = require('multicodec') -const { Buffer } = require('buffer') +const uint8ArrayFromString = require('uint8arrays/from-string') const inMemory = require('ipld-in-memory') const IPLDResolver = require('../src') @@ -27,9 +22,9 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => { before(async () => { resolver = await inMemory(IPLDResolver) - node1 = new dagPB.DAGNode(Buffer.from('I am 1')) - node2 = new dagPB.DAGNode(Buffer.from('I am 2')) - node3 = new dagPB.DAGNode(Buffer.from('I am 3')) + node1 = new dagPB.DAGNode(uint8ArrayFromString('I am 1')) + node2 = new dagPB.DAGNode(uint8ArrayFromString('I am 2')) + node3 = new dagPB.DAGNode(uint8ArrayFromString('I am 3')) const serialized1 = dagPB.util.serialize(node1) cid1 = await dagPB.util.cid(serialized1) node2.addLink({ @@ -80,7 +75,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => { const result = resolver.resolve(cid1, 'Data') const node = await result.first() expect(node.remainderPath).to.eql('') - expect(node.value).to.eql(Buffer.from('I am 1')) + expect(node.value).to.eql(uint8ArrayFromString('I am 1')) }) it('resolves a value within nested scope (1 level)', async () => { @@ -91,7 +86,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => { expect(node1.value.equals(cid1)).to.be.true() expect(node2.remainderPath).to.eql('') - expect(node2.value).to.eql(Buffer.from('I am 1')) + expect(node2.value).to.eql(uint8ArrayFromString('I am 1')) }) it('resolves value within nested scope (2 levels)', async () => { @@ -105,7 +100,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => { expect(node2.value.equals(cid1)).to.be.true() expect(node3.remainderPath).to.eql('') - expect(node3.value).to.eql(Buffer.from('I am 1')) + expect(node3.value).to.eql(uint8ArrayFromString('I am 1')) }) it('resolves value within nested scope (2 levels) with named links', async () => { @@ -119,7 +114,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => { expect(node2.value.equals(cid1)).to.be.true() expect(node3.remainderPath).to.eql('') - expect(node3.value).to.eql(Buffer.from('I am 1')) + expect(node3.value).to.eql(uint8ArrayFromString('I am 1')) }) it('resolver.get round-trip', async () => { @@ -135,7 +130,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => { // seems to be some race condition with inserting and removing items. // Hence create a unique item for this test. Though the tests // should really be independent so that there are no race conditions. - const node = new dagPB.DAGNode(Buffer.from('a dag-pb node')) + const node = new dagPB.DAGNode(uint8ArrayFromString('a dag-pb node')) const cid = await resolver.put(node, multicodec.DAG_PB) const sameAsNode = await resolver.get(cid) // `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)', () => { }) it('should return a v0 CID when specified', async () => { - const node = new dagPB.DAGNode(Buffer.from('a dag-pb node')) + const node = new dagPB.DAGNode(uint8ArrayFromString('a dag-pb node')) const cid = await resolver.put(node, multicodec.DAG_PB, { cidVersion: 0 }) @@ -160,7 +155,7 @@ describe('IPLD Resolver with dag-pb (MerkleDAG Protobuf)', () => { }) it('should return a v1 CID when specified', async () => { - const node = new dagPB.DAGNode(Buffer.from('a dag-pb node')) + const node = new dagPB.DAGNode(uint8ArrayFromString('a dag-pb node')) const cid = await resolver.put(node, multicodec.DAG_PB, { cidVersion: 1 }) diff --git a/test/ipld-eth-block.spec.js b/test/ipld-eth-block.spec.js index 7f80c4e..a6a48d3 100644 --- a/test/ipld-eth-block.spec.js +++ b/test/ipld-eth-block.spec.js @@ -1,12 +1,7 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const chaiAsProised = require('chai-as-promised') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(chaiAsProised) -chai.use(dirtyChai) +const { expect } = require('aegir/utils/chai') const ipldEthBlock = require('ipld-ethereum').ethBlock const EthBlockHeader = require('ethereumjs-block/header') const multihash = require('multihashes') diff --git a/test/ipld-eth.spec.js b/test/ipld-eth.spec.js index ab43481..5a9e69e 100644 --- a/test/ipld-eth.spec.js +++ b/test/ipld-eth.spec.js @@ -1,10 +1,7 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) +const { expect } = require('aegir/utils/chai') const rlp = require('rlp') const ipldEthBlock = require('ipld-ethereum').ethBlock const ipldEthStateTrie = require('ipld-ethereum').ethStateTrie diff --git a/test/ipld-git.spec.js b/test/ipld-git.spec.js index 51fbf24..7888ac5 100644 --- a/test/ipld-git.spec.js +++ b/test/ipld-git.spec.js @@ -1,15 +1,12 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) +const { expect } = require('aegir/utils/chai') const ipldGit = require('ipld-git') const multihash = require('multihashes') const multicodec = require('multicodec') -const { Buffer } = require('buffer') const inMemory = require('ipld-in-memory') +const uint8ArrayFromString = require('uint8arrays/from-string') const IPLDResolver = require('../src') @@ -33,7 +30,7 @@ describe('IPLD Resolver with ipld-git', () => { formats: [ipldGit] }) - blobNode = Buffer.from('626c6f62203800736f6d6564617461', 'hex') // blob 8\0somedata + blobNode = uint8ArrayFromString('626c6f62203800736f6d6564617461', 'base16') // blob 8\0somedata blobCid = await ipldGit.util.cid(blobNode) treeNode = { diff --git a/test/ipld-zcash.spec.js b/test/ipld-zcash.spec.js index 1d87d41..434ef03 100644 --- a/test/ipld-zcash.spec.js +++ b/test/ipld-zcash.spec.js @@ -1,13 +1,8 @@ /* eslint-env mocha */ 'use strict' +const { expect } = require('aegir/utils/chai') const Block = require('ipld-block') -const chai = require('chai') -const chaiAsProised = require('chai-as-promised') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(chaiAsProised) -chai.use(dirtyChai) const ipldZcash = require('ipld-zcash') const loadFixture = require('aegir/fixtures') const inMemory = require('ipld-in-memory')