This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add many sha3 functions * tests: create tests table
- Loading branch information
Showing
5 changed files
with
89 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict' | ||
|
||
const sha3 = require('js-sha3') | ||
|
||
const functions = { | ||
0x14: sha3.sha3_512, | ||
0x15: sha3.sha3_384, | ||
0x16: sha3.sha3_256, | ||
0x17: sha3.sha3_224, | ||
0x18: sha3.shake128, | ||
0x19: sha3.shake256, | ||
0x1A: sha3.keccak224, | ||
0x1B: sha3.keccak256, | ||
0x1C: sha3.keccak384, | ||
0x1D: sha3.keccak512 | ||
} | ||
|
||
class Hasher { | ||
constructor (hashFunc) { | ||
this.hf = hashFunc | ||
this.input = null | ||
} | ||
|
||
update (buf) { | ||
this.input = buf | ||
return this | ||
} | ||
|
||
digest () { | ||
const input = this.input | ||
return Buffer.from(this.hf(input)) | ||
} | ||
} | ||
|
||
function addFuncs (table) { | ||
for (const code in functions) { | ||
if (functions.hasOwnProperty(code)) { | ||
table[code] = () => new Hasher(functions[code]) | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
addFuncs: addFuncs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters