Merge pull request #30899 from BendingBender/diffie-hellman

Add types for diffie-hellman
This commit is contained in:
Nathan Shively-Sanders
2018-11-30 09:25:57 -08:00
committed by GitHub
4 changed files with 80 additions and 0 deletions
@@ -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');
+8
View File
@@ -0,0 +1,8 @@
// Type definitions for diffie-hellman 5.0
// Project: https://github.com/crypto-browserify/diffie-hellman
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
export { createDiffieHellman, getDiffieHellman, DiffieHellman } from 'crypto';
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }