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

Commit cb3779d

Browse files
vmxdaviddias
authored andcommitted
feat: add double SHA2-256 hashing
The double SHA2-256 is e.g. used for Bitcoin and Zcash. Fixes #25.
1 parent d1fe2e6 commit cb3779d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/crypto.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ const toBuf = utils.toBuf
1111
const fromString = utils.fromString
1212
const fromNumberTo32BitBuf = utils.fromNumberTo32BitBuf
1313

14+
const dblSha2256 = (buf, cb) => {
15+
sha.sha2256(buf, (err, firstHash) => {
16+
if (err) {
17+
cb(err)
18+
}
19+
sha.sha2256((Buffer.from(firstHash)), cb)
20+
})
21+
}
22+
1423
module.exports = {
1524
sha1: sha.sha1,
1625
sha2256: sha.sha2256,
@@ -27,5 +36,6 @@ module.exports = {
2736
keccak512: toCallback(toBuf(sha3.keccak_512)),
2837
murmur3128: toCallback(toBuf(fromString(murmur3.x64.hash128))),
2938
murmur332: toCallback(fromNumberTo32BitBuf(fromString(murmur3.x86.hash32))),
30-
addBlake: require('./blake')
39+
addBlake: require('./blake'),
40+
dblSha2256: dblSha2256
3141
}

src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ Multihashing.functions = {
132132
// murmur3-128
133133
0x22: crypto.murmur3128,
134134
// murmur3-32
135-
0x23: crypto.murmur332
135+
0x23: crypto.murmur332,
136+
// dbl-sha2-256
137+
0x56: crypto.dblSha2256
136138
}
137139

138140
// add blake functions

test/fixtures/encodes.js

+4
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,8 @@ module.exports = [[
7272
'beep boop',
7373
'blake2s-256',
7474
'e0e402204542eaca484e4311def8af74b546edd7fceb49eeb3cdcfd8a4a72ed0dc81d4c0'
75+
], [
76+
'beep boop',
77+
'dbl-sha2-256',
78+
'56209cd9115d76945c2455b1450295b05f4edeba2e7286bc24c23e266b48faf578c0'
7579
]]

0 commit comments

Comments
 (0)