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

Commit b1a3a2a

Browse files
achingbrainvmx
authored andcommitted
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.
1 parent 8a45949 commit b1a3a2a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class IPLDResolver {
185185
const options = mergeOptions(defaultOptions, userOptions)
186186

187187
const cidOptions = {
188-
version: options.cidVersion,
188+
cidVersion: options.cidVersion,
189189
hashAlg: options.hashAlg,
190190
onlyHash: options.onlyHash
191191
}

test/ipld-dag-pb.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,24 @@ module.exports = (repo) => {
135135
await expect(resolver.get(cid)).to.eventually.be.rejected()
136136
}
137137
})
138+
139+
it('should return a v0 CID when specified', async () => {
140+
const node = dagPB.DAGNode.create(Buffer.from('a dag-pb node'))
141+
const cid = await resolver.put(node, multicodec.DAG_PB, {
142+
cidVersion: 0
143+
})
144+
145+
expect(cid.version).to.equal(0)
146+
})
147+
148+
it('should return a v1 CID when specified', async () => {
149+
const node = dagPB.DAGNode.create(Buffer.from('a dag-pb node'))
150+
const cid = await resolver.put(node, multicodec.DAG_PB, {
151+
cidVersion: 1
152+
})
153+
154+
expect(cid.version).to.equal(1)
155+
})
138156
})
139157
})
140158
}

0 commit comments

Comments
 (0)