0000-export-types.test.ts (1844B)
1 import tap = require('tap'); 2 import * as lib from '../src/index'; 3 import KeyPair from '../src/index'; 4 5 tap.ok(((!!lib) && (typeof lib)) === 'object', 'Supercop exports as an object'); 6 tap.ok('function' === typeof KeyPair , 'Default export is a class-ish'); 7 tap.doesNotThrow(() => new KeyPair() , 'Default export can be initialized as class'); 8 tap.ok(KeyPair === lib.KeyPair , 'Default export is KeyPair class'); 9 10 // Verify stand-alone functions are exported 11 tap.ok('function' === typeof lib.createSeed , 'createSeed fn is exported'); 12 tap.ok('function' === typeof lib.keyPairFrom , 'keyPairFrom fn is exported'); 13 tap.ok('function' === typeof lib.createKeyPair, 'createKeyPair fn is exported'); 14 tap.ok('function' === typeof lib.sign , 'sign fn is exported'); 15 tap.ok('function' === typeof lib.verify , 'verify fn is exported'); 16 tap.ok('function' === typeof lib.keyExchange , 'verify fn is exported'); 17 18 // Verify static functions on KeyPair class are there 19 tap.ok('function' === typeof KeyPair.create, 'KeyPair contains static create fn'); 20 tap.ok('function' === typeof KeyPair.from , 'KeyPair contains static from fn'); 21 22 // Go async, needed for the supercop lib 23 (async () => { 24 25 // Create keypair to test with 26 const kp = await KeyPair.create(lib.createSeed()); 27 28 tap.ok(kp instanceof KeyPair, 'KeyPair.create generates a KeyPair instance'); 29 30 // Tricking TSC into believing kp == instanceof keypair 31 if (!(kp instanceof KeyPair)) throw new Error(); 32 33 // Verify the methods are there 34 tap.ok('function' === typeof kp.toJSON , 'kp.toJSON method exists'); 35 tap.ok('function' === typeof kp.keyExchange, 'kp.keyExchange method exists'); 36 tap.ok('function' === typeof kp.sign , 'kp.sign method exists'); 37 tap.ok('function' === typeof kp.verify , 'kp.verify method exists'); 38 })();