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

Commit

Permalink
fix: use multihashing-async (#12)
Browse files Browse the repository at this point in the history
use the standard hashing package, see #7
  • Loading branch information
richardschneider authored Jun 26, 2018
1 parent 8384849 commit dfffd96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"dependencies": {
"cids": "~0.5.2",
"dirty-chai": "^2.0.1",
"hash.js": "^1.1.3",
"multihashes": "~0.4.12",
"multihashing-async": "~0.5.1",
"zcash-bitcore-lib": "^0.13.20-rc3"
},
"devDependencies": {
Expand Down
26 changes: 12 additions & 14 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const ZcashBitcoreBlock = require('zcash-bitcore-lib').Block
const CID = require('cids')
const multihashes = require('multihashes')
const sha256 = require('hash.js/lib/hash/sha/256')
const multihashing = require('multihashing-async')
const waterfall = require('async/waterfall')

/**
* @callback SerializeCallback
Expand Down Expand Up @@ -76,19 +77,16 @@ const cid = (dagNode, options, callback) => {
options = {}
}
options = options || {}
let err = null
let cid
try {
// Zcash double hashes
const firstHash = sha256().update(dagNode.header.toBuffer(true)).digest()
const headerHash = sha256().update(Buffer.from(firstHash)).digest()

cid = hashToCid(Buffer.from(headerHash))
} catch (cidError) {
err = cidError
} finally {
callback(err, cid)
}
waterfall([
(cb) => {
try {
multihashing(dagNode.header.toBuffer(true), 'dbl-sha2-256', cb)
} catch (err) {
cb(err)
}
},
(mh, cb) => cb(null, new CID(1, 'zcash-block', mh))
], callback)
}

// Convert a Zcash hash (as Buffer) to a CID
Expand Down

0 comments on commit dfffd96

Please sign in to comment.