Files: 89171dfc684b68a1ec0741e78b5c882a9e2be86a / sodium.js
700 bytesRaw
1 | |
2 | var sodium = require('chloride') |
3 | |
4 | module.exports = { |
5 | |
6 | curves: ['ed25519'], |
7 | |
8 | generate: function (seed) { |
9 | if(!seed) sodium.randombytes(seed = new Buffer(32)) |
10 | |
11 | var keys = seed ? sodium.crypto_sign_seed_keypair(seed) : sodium.crypto_sign_keypair() |
12 | return { |
13 | curve: 'ed25519', |
14 | public: keys.publicKey, |
15 | |
16 | //so that this works with either sodium |
17 | //or libsodium-wrappers (in browser) |
18 | private: keys.privateKey || keys.secretKey |
19 | } |
20 | }, |
21 | |
22 | sign: function (private, message) { |
23 | return sodium.crypto_sign_detached(message, private) |
24 | }, |
25 | |
26 | verify: function (public, sig, message) { |
27 | return sodium.crypto_sign_verify_detached(sig, message, public) |
28 | } |
29 | |
30 | } |
31 | |
32 | |
33 | |
34 | |
35 | |
36 |
Built with git-ssb-web