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

Commit

Permalink
fix: update all deps to versions that return uint8arrays (#286)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
achingbrain authored Aug 5, 2020
1 parent 3e03866 commit 75037ea
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 97 deletions.
31 changes: 14 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "^0.4.0",
"ipld-ethereum": "^5.0.0",
"ipld-git": "^0.6.0",
"ipld-in-memory": "^5.0.0",
"ipld-zcash": "^0.4.3",
"ipld-zcash": "^0.5.0",
"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": "^0.10.0",
"ipld-dag-cbor": "^0.17.0",
"ipld-dag-pb": "^0.20.0",
"ipld-raw": "^6.0.0",
"merge-options": "^2.0.0",
"multicodec": "^1.0.0",
"multicodec": "^2.0.0",
"typical": "^6.0.0"
},
"contributors": [
Expand Down
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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')
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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')
}

Expand Down
17 changes: 6 additions & 11 deletions test/basics.spec.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
})
Expand All @@ -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)
})
Expand Down
7 changes: 1 addition & 6 deletions test/format-support.spec.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
15 changes: 5 additions & 10 deletions test/ipld-all.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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 = {
Expand All @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions test/ipld-bitcoin.spec.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
7 changes: 1 addition & 6 deletions test/ipld-dag-cbor.spec.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
29 changes: 12 additions & 17 deletions test/ipld-dag-pb.spec.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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({
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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
Expand All @@ -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
})
Expand All @@ -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
})
Expand Down
7 changes: 1 addition & 6 deletions test/ipld-eth-block.spec.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
5 changes: 1 addition & 4 deletions test/ipld-eth.spec.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 3 additions & 6 deletions test/ipld-git.spec.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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 = {
Expand Down
7 changes: 1 addition & 6 deletions test/ipld-zcash.spec.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down

0 comments on commit 75037ea

Please sign in to comment.