-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
42 lines (33 loc) · 1.07 KB
/
index.js
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
31
32
33
34
35
36
37
38
39
40
41
42
var binding = require('./build/Release/node_nacl')
// produces an authenticated ciphertext. might return null.
exports.box = function(message, nonce, pubkey, privkey) {
if (typeof message === 'string') message = new Buffer(message)
return binding.box(message, nonce, pubkey, privkey)
}
// opens a cryptobox. might return null.
exports.unbox = binding.box_open
// make a private and its corresponding public key
exports.boxKeypair = function() {
var result = binding.box_keypair()
return {private: result[0], public: result[1]}
}
exports.sign = function(message, privkey) {
if (typeof message === 'string') message = new Buffer(message)
return binding.sign(message, privkey)
}
exports.unsign = binding.sign_open
exports.signKeypair = function() {
var result = binding.sign_keypair()
return {private: result[0], public: result[1]}
}
exports.lengths =
{ box:
{ nonce: binding.box_NONCEBYTES
, pubkey: binding.box_PUBLICKEYBYTES
, privkey: binding.box_SECRETKEYBYTES
}
, sign:
{ pubkey: binding.sign_PUBLICKEYBYTES
, privkey: binding.sign_SECRETKEYBYTES
}
}