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

Commit

Permalink
feat: add defaultHashAlg (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jun 22, 2018
1 parent 847be51 commit 6e28d3e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/resolver.js
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
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
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

0 comments on commit 6e28d3e

Please sign in to comment.