From 01972623953bfefc9378b829bf1afd21a550d504 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Wed, 28 Nov 2018 20:27:35 +0100 Subject: [PATCH] Add types for diffie-hellman --- types/diffie-hellman/diffie-hellman-tests.ts | 48 ++++++++++++++++++++ types/diffie-hellman/index.d.ts | 8 ++++ types/diffie-hellman/tsconfig.json | 23 ++++++++++ types/diffie-hellman/tslint.json | 1 + 4 files changed, 80 insertions(+) create mode 100644 types/diffie-hellman/diffie-hellman-tests.ts create mode 100644 types/diffie-hellman/index.d.ts create mode 100644 types/diffie-hellman/tsconfig.json create mode 100644 types/diffie-hellman/tslint.json diff --git a/types/diffie-hellman/diffie-hellman-tests.ts b/types/diffie-hellman/diffie-hellman-tests.ts new file mode 100644 index 0000000000..645ebc23bd --- /dev/null +++ b/types/diffie-hellman/diffie-hellman-tests.ts @@ -0,0 +1,48 @@ +import * as dh from 'diffie-hellman'; + +const dh1 = dh.getDiffieHellman('modp1'); +// $ExpectType DiffieHellman +dh1; +// $ExpectType Buffer +dh1.generateKeys(); +// $ExpectType string +dh1.generateKeys('hex'); +// $ExpectType Buffer +dh1.getPrime(); +// $ExpectType string +dh1.getPrime('hex'); +// $ExpectType Buffer +dh1.getGenerator(); +// $ExpectType string +dh1.getGenerator('hex'); +const pk = dh1.getPublicKey(); +// $ExpectType Buffer +pk; +// $ExpectType string +dh1.getPublicKey('hex'); +// $ExpectType Buffer +dh1.getPrivateKey(); +// $ExpectType string +dh1.getPrivateKey('hex'); +// $ExpectType Buffer +dh1.computeSecret(pk); +// $ExpectType Buffer +dh1.computeSecret(pk.toString('hex'), 'hex'); +// $ExpectType string +dh1.computeSecret(pk.toString('hex'), 'hex', 'hex'); + +const dh2 = dh.createDiffieHellman(new Buffer([5])); +// $ExpectType DiffieHellman +dh2; +dh.createDiffieHellman('prime', 'hex'); +dh.createDiffieHellman('prime', 'hex', new Buffer([5])); +dh.createDiffieHellman('prime', 'hex', 5); +dh.createDiffieHellman('prime', 'hex', 'generator', 'hex'); +dh.createDiffieHellman(1); +dh.createDiffieHellman(1, 1); +dh.createDiffieHellman(1, new Buffer([5])); + +dh2.setPublicKey(pk); +dh2.setPublicKey(pk.toString('hex'), 'hex'); +dh2.setPrivateKey(pk); +dh2.setPrivateKey(pk.toString('hex'), 'hex'); diff --git a/types/diffie-hellman/index.d.ts b/types/diffie-hellman/index.d.ts new file mode 100644 index 0000000000..7b59cf9182 --- /dev/null +++ b/types/diffie-hellman/index.d.ts @@ -0,0 +1,8 @@ +// Type definitions for diffie-hellman 5.0 +// Project: https://github.com/crypto-browserify/diffie-hellman +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export { createDiffieHellman, getDiffieHellman, DiffieHellman } from 'crypto'; diff --git a/types/diffie-hellman/tsconfig.json b/types/diffie-hellman/tsconfig.json new file mode 100644 index 0000000000..743c9eea4c --- /dev/null +++ b/types/diffie-hellman/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "diffie-hellman-tests.ts" + ] +} diff --git a/types/diffie-hellman/tslint.json b/types/diffie-hellman/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/diffie-hellman/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }