Files: 5a8195ec90ba51f0c5d8272e9cd56428f32f0f61 / eccjs.js
942 bytesRaw
1 | |
2 | |
3 | var ecc = require('eccjs') |
4 | var crypto = require('crypto') |
5 | var Blake2s = require('blake2s') |
6 | |
7 | var curve = ecc.curves.k256 |
8 | |
9 | function hash (message) { |
10 | return new Blake2s().update(message).digest() |
11 | } |
12 | |
13 | module.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