Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

feat: add defaultHashAlg #17

Merged
merged 1 commit into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const resolveField = (dagNode, field) => {

module.exports = {
multicodec: 'bitcoin-block',
defaultHashAlg: 'dbl-sha2-256',
resolve: resolve,
tree: tree
}
4 changes: 3 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ const cid = (dagNode, callback) => {

// Convert a Bitcoin hash (as Buffer) to a CID
const hashToCid = (hash) => {
const multihash = multihashes.encode(hash, 'dbl-sha2-256')
// avoid deadly embrace between resolver and util
const defaultHashAlg = require('./resolver').defaultHashAlg
const multihash = multihashes.encode(hash, defaultHashAlg)
const cidVersion = 1
const cid = new CID(cidVersion, 'bitcoin-block', multihash)
return cid
Expand Down
5 changes: 5 additions & 0 deletions test/resolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ describe('IPLD format resolver API properties', () => {
expect(IpldBitcoin.resolver.multicodec).to.equal('bitcoin-block')
done()
})

it('should have `defaultHashAlg` defined correctly', (done) => {
expect(IpldBitcoin.resolver.defaultHashAlg).to.equal('dbl-sha2-256')
done()
})
})

const verifyPath = (block, path, expected, done) => {
Expand Down