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