From b1a3a2a54ee025ff48e3266f96856c4030db2d51 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 15 May 2019 12:17:20 +0100 Subject: [PATCH] fix: respect the `cidVersion` option The [interface-ipld-format spec](https://github.com/ipld/interface-ipld-format#utilcidbinaryblob-options) says the CID verison option is `cidVersion`. This module passes it to formats as `version` which is subsequently ignored. --- src/index.js | 2 +- test/ipld-dag-pb.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index e64075c..28bb6f8 100644 --- a/src/index.js +++ b/src/index.js @@ -185,7 +185,7 @@ class IPLDResolver { const options = mergeOptions(defaultOptions, userOptions) const cidOptions = { - version: options.cidVersion, + cidVersion: options.cidVersion, hashAlg: options.hashAlg, onlyHash: options.onlyHash } diff --git a/test/ipld-dag-pb.js b/test/ipld-dag-pb.js index 959038c..ce07ddf 100644 --- a/test/ipld-dag-pb.js +++ b/test/ipld-dag-pb.js @@ -135,6 +135,24 @@ module.exports = (repo) => { await expect(resolver.get(cid)).to.eventually.be.rejected() } }) + + it('should return a v0 CID when specified', async () => { + const node = dagPB.DAGNode.create(Buffer.from('a dag-pb node')) + const cid = await resolver.put(node, multicodec.DAG_PB, { + cidVersion: 0 + }) + + expect(cid.version).to.equal(0) + }) + + it('should return a v1 CID when specified', async () => { + const node = dagPB.DAGNode.create(Buffer.from('a dag-pb node')) + const cid = await resolver.put(node, multicodec.DAG_PB, { + cidVersion: 1 + }) + + expect(cid.version).to.equal(1) + }) }) }) }