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

fix: use multihashing-async #12

Merged
merged 1 commit into from
Jun 26, 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
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