-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (20 loc) · 755 Bytes
/
index.js
File metadata and controls
25 lines (20 loc) · 755 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
var sodium = require('sodium-universal')
var alloc = require('buffer-alloc-unsafe')
exports.keyPair = function (seed) {
var publicKey = alloc(sodium.crypto_sign_PUBLICKEYBYTES)
var secretKey = alloc(sodium.crypto_sign_SECRETKEYBYTES)
if (seed) sodium.crypto_sign_seed_keypair(publicKey, secretKey, seed)
else sodium.crypto_sign_keypair(publicKey, secretKey)
return {
publicKey: publicKey,
secretKey: secretKey
}
}
exports.sign = function (message, secretKey) {
var signature = alloc(sodium.crypto_sign_BYTES)
sodium.crypto_sign_detached(signature, message, secretKey)
return signature
}
exports.verify = function (message, signature, publicKey) {
return sodium.crypto_sign_verify_detached(signature, message, publicKey)
}