forked from ssbc/ssb-keys
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsodium.js
More file actions
35 lines (21 loc) · 712 Bytes
/
sodium.js
File metadata and controls
35 lines (21 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var sodium = require('chloride')
module.exports = {
curves: ['ed25519'],
generate: function (seed) {
if(!seed) sodium.randombytes(seed = new Buffer(32))
var keys = seed ? sodium.crypto_sign_seed_keypair(seed) : sodium.crypto_sign_keypair()
return {
curve: 'ed25519',
public: keys.publicKey,
//so that this works with either sodium
//or libsodium-wrappers (in browser)
private: keys.privateKey || keys.secretKey
}
},
sign: function (privateKey, message) {
return sodium.crypto_sign_detached(message, privateKey)
},
verify: function (publicKey, sig, message) {
return sodium.crypto_sign_verify_detached(sig, message, publicKey)
}
}