From 071a0050da1c235dc71f5818eda8a32043c5483f Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Tue, 26 Jun 2018 15:05:06 +1200 Subject: [PATCH] fix: use multihashing-async --- package.json | 2 +- src/util.js | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 1d4b45b..a507310 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/util.js b/src/util.js index 1b0136c..7aaad93 100644 --- a/src/util.js +++ b/src/util.js @@ -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 @@ -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