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

0005-signature-validation.test.ts (1147B)


      1 import tap = require('tap');
      2 import pbkdf2 = require('pbkdf2');
      3 import KeyPair, { createSeed } from '../src/index';
      4 
      5 (async () => {
      6 
      7   const seed   = pbkdf2.pbkdf2Sync('password', 'NaCl', 1, 32, 'sha512');
      8   const goodKP = await KeyPair.create(seed);
      9   const badKP  = await KeyPair.create(createSeed());
     10 
     11   const messageBuf = Buffer.from('message');
     12   const messageStr =             'message';
     13   const messageBad = Buffer.from(createSeed());
     14 
     15   const signatureBuf = await goodKP.sign(messageBuf);
     16   const signatureStr = await goodKP.sign(messageStr);
     17 
     18   tap.ok(Buffer.compare(signatureBuf, signatureStr) === 0, 'Buffer and string input generate the same signature');
     19 
     20   tap.ok(await goodKP.verify(signatureBuf, messageBuf), 'Correct signature matches with original message buffer');
     21   tap.ok(await goodKP.verify(signatureBuf, messageStr), 'Correct signature matches with original message string');
     22   tap.notOk(await goodKP.verify(signatureBuf, messageBad), 'Correct signature fails with bad message buffer');
     23   tap.notOk(await badKP.verify(signatureBuf, messageBuf), 'Correct signature fails with original message buffer on different key');
     24 })();