1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | let blake2b = require('blake2b')
|
9 | let nacl = require('tweetnacl')
|
10 | let node =
|
11 | typeof global === 'undefined'
|
12 | ? require('crypto-browserify')
|
13 | : require('crypto')
|
14 | let scrypt = require('scryptsy')
|
15 | let jsSha3 = require('js-sha3')
|
16 |
|
17 | function blake2b128(val) {
|
18 |
|
19 | let out = Buffer.alloc(blake2b.BYTES_MIN)
|
20 | blake2b(blake2b.BYTES_MIN)
|
21 | .update(val)
|
22 | .digest(out)
|
23 | return out
|
24 | }
|
25 |
|
26 | function blake2b256(val) {
|
27 |
|
28 | let out = Buffer.alloc(blake2b.BYTES)
|
29 | blake2b(blake2b.BYTES)
|
30 | .update(val)
|
31 | .digest(out)
|
32 | return out
|
33 | }
|
34 |
|
35 | function keccak256(val) {
|
36 | return jsSha3.keccak256(val)
|
37 | }
|
38 |
|
39 | module.exports = {
|
40 | blake2b128,
|
41 | blake2b256,
|
42 | nacl,
|
43 | node,
|
44 | scrypt,
|
45 | keccak256
|
46 | }
|