git ssb

1+

Dominic / ssb-keys



Tree: 6c7f3d57c075b5250295383f964469552f713d1d

Files: 6c7f3d57c075b5250295383f964469552f713d1d / eccjs.js

942 bytesRaw
1
2
3var ecc = require('eccjs')
4var crypto = require('crypto')
5var Blake2s = require('blake2s')
6
7var curve = ecc.curves.k256
8
9function hash (message) {
10 return new Blake2s().update(message).digest()
11}
12
13module.exports = {
14
15 curves: ['k256'],
16
17 generate: function (seed) {
18 //we use eccjs.restore here, instead of eccjs.generate
19 //because we trust node's random generator much more than
20 //sjcl's (via crypto-browserify's polyfil this uses
21 //webcrypto's random generator in the browser)
22
23 var keys = ecc.restore(curve, seed || crypto.randomBytes(32))
24
25 return {
26 curve: 'k256',
27 public: keys.public,
28 private: keys.private
29 }
30 },
31
32 sign: function (private, message) {
33 return ecc.sign(curve, private, hash(message))
34 },
35
36 verify: function (public, sig, message) {
37 return ecc.verify(curve, public, sig, hash(message))
38 },
39
40 restore: function (seed) {
41 return ecc.restore(curve, seed)
42 }
43
44}
45

Built with git-ssb-web