supercop.ts

cross-compiled javascript implementation of ed25519 based on supercop-ref10
git clone git://git.finwo.net/lib/supercop.ts
Log | Files | Refs | README | LICENSE

0006-key-exchange.test.ts (1171B)


      1 import tap = require('tap');
      2 import pbkdf2 = require('pbkdf2');
      3 import KeyPair, { createSeed } from '../src/index';
      4 
      5 (async () => {
      6 
      7   const seedAlice   = pbkdf2.pbkdf2Sync('alice'  , 'NaCl', 1, 32, 'sha512');
      8   const seedBob     = pbkdf2.pbkdf2Sync('bob'    , 'NaCl', 1, 32, 'sha512');
      9   const seedCharlie = pbkdf2.pbkdf2Sync('charlie', 'NaCl', 1, 32, 'sha512');
     10 
     11   const kpAlice   = await KeyPair.create(seedAlice  );
     12   const kpBob     = await KeyPair.create(seedBob    );
     13   const kpCharlie = await KeyPair.create(seedCharlie);
     14 
     15   const secretAliceBob = (await kpAlice.keyExchange(kpBob  .publicKey)).toString('hex');
     16   const secretBobAlice = (await kpBob  .keyExchange(kpAlice.publicKey)).toString('hex');
     17 
     18   const secretAliceCharlie = (await kpAlice  .keyExchange(kpCharlie.publicKey)).toString('hex');
     19   const secretCharlieAlice = (await kpCharlie.keyExchange(kpAlice  .publicKey)).toString('hex');
     20 
     21   tap.ok(secretAliceBob     == secretBobAlice    , 'Alice <-> Bob secrets match');
     22   tap.ok(secretAliceCharlie == secretCharlieAlice, 'Alice <-> Charlie secrets match');
     23   tap.ok(secretAliceBob     != secretAliceCharlie, 'Secret pairs differ from eachother');
     24 })();