Skip to content

Commit

Permalink
more tests!
Browse files Browse the repository at this point in the history
  • Loading branch information
ansuz committed May 16, 2019
1 parent 56a3d60 commit d0b93bf
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,46 @@ var Alice_public = Nacl.util.encodeBase64(Alice.publicKey);
var Bob = Nacl.box.keyPair();
var Bob_public = Nacl.util.encodeBase64(Bob.publicKey);

(function () {
var Curve = Crypto.Curve;

// Basic one to one curve encryption used in CryptPad's chat

// Alice and Bob can use their own private keys and the other's public key
// to derive some shared values for their pairwise-encrypted channel
// that includes a pre-computed secret key for curve encryption, a signing key, and a validate key

// Alice derives the keys
var Alice_set = Curve.deriveKeys(Bob_public, Nacl.util.encodeBase64(Alice.secretKey));

// Bob does the same
var Bob_set = Curve.deriveKeys(Alice_public, Nacl.util.encodeBase64(Bob.secretKey));

['cryptKey', 'signKey', 'validateKey'].forEach(function (k) {
// these should all be strings
Assert.equal('string', typeof(Alice_set[k]));
Assert.equal('string', typeof(Bob_set[k]));

// and Alice and Bob should have exactly the same values
Assert.equal(Alice_set[k], Bob_set[k]);
});

var Alice_cryptor = Curve.createEncryptor(Alice_set);
var Bob_cryptor = Curve.createEncryptor(Bob_set);

// Now Alice should be able to send Bob a message

var message = 'pewpewpew';

var Alice_ciphertext = Alice_cryptor.encrypt(message);

var Bob_plaintext = Bob_cryptor.decrypt(Alice_ciphertext);

Assert.equal(message, Bob_plaintext);
}());

// Mailbox stuff

/*
(function () {
// validate internal methods
Expand Down

0 comments on commit d0b93bf

Please sign in to comment.