This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
test.js
50 lines (38 loc) · 1.44 KB
/
test.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
43
44
45
46
47
48
49
50
const test = require('tape');
const util = require('tweetnacl-util');
const nacl = require('tweetnacl');
const libsodium = require('libsodium-wrappers');
const sodium = require('./dist/index.umd.js');
test('basic round trip', function(t) {
t.plan(1);
const msg = 'hello, world!';
const msgBytes = util.decodeUTF8(msg);
const kp = nacl.box.keyPair();
const ct = sodium.seal(msgBytes, kp.publicKey);
const pt = sodium.sealOpen(ct, kp.publicKey, kp.secretKey);
t.equal(util.encodeUTF8(pt), msg);
});
test('can decrypt ciphertext from libsodium', function(t) {
t.plan(1);
libsodium.ready.then(function() {
const msg = 'hello, world!';
const msgBytes = util.decodeUTF8(msg);
const kp = libsodium.crypto_box_keypair();
const ct = libsodium.crypto_box_seal(msgBytes, kp.publicKey);
const pt = sodium.sealOpen(ct, kp.publicKey, kp.privateKey);
t.equal(util.encodeUTF8(pt), msg);
}).catch(function(err) {
t.error(err)
});
});
test('ciphertext can be decrypted by libsodium', function(t) {
t.plan(1);
libsodium.ready.then(function() {
const msg = 'hello, world!';
const msgBytes = util.decodeUTF8(msg);
const kp = libsodium.crypto_box_keypair();
const ct = sodium.seal(msgBytes, kp.publicKey);
const pt = libsodium.crypto_box_seal_open(ct, kp.publicKey, kp.privateKey);
t.equal(util.encodeUTF8(pt), msg);
});
});