UNPKG

836 BJavaScriptView Raw
1/*
2
3all these functions should work with a byte array while in other places
4there is a lot of monkey-business about 0x, strings, hex, and etc.
5
6*/
7
8let blake2b = require('blake2b')
9let nacl = require('tweetnacl')
10let node =
11 typeof global === 'undefined'
12 ? require('crypto-browserify')
13 : require('crypto')
14let scrypt = require('scryptsy')
15let jsSha3 = require('js-sha3')
16
17function blake2b128(val) {
18 // 16
19 let out = Buffer.alloc(blake2b.BYTES_MIN)
20 blake2b(blake2b.BYTES_MIN)
21 .update(val)
22 .digest(out)
23 return out
24}
25
26function blake2b256(val) {
27 // 32
28 let out = Buffer.alloc(blake2b.BYTES)
29 blake2b(blake2b.BYTES)
30 .update(val)
31 .digest(out)
32 return out
33}
34
35function keccak256(val) {
36 return jsSha3.keccak256(val)
37}
38
39module.exports = {
40 blake2b128,
41 blake2b256,
42 nacl,
43 node,
44 scrypt,
45 keccak256
46}