add type definitions for elgamal (#36131)

This commit is contained in:
Yu-Hsi Chiang 2019-06-13 19:12:21 +00:00 committed by Ron Buckton
parent 3537919757
commit 8f4ca2e2bd
4 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,11 @@
import ElGamal from 'elgamal';
(async () => {
const eg = await ElGamal.generateAsync();
const secret = 'The quick brown fox jumps over the lazy dog';
const encrypted = await eg.encryptAsync(secret); // $ExpectType EncryptedValue
const decrypted = await eg.decryptAsync(encrypted); // $ExpectType DecryptedValue
decrypted.toString(); // $ExpectType string
})();

42
types/elgamal/index.d.ts vendored Normal file
View File

@ -0,0 +1,42 @@
// Type definitions for elgamal 0.3
// Project: https://github.com/kripod/elgamal.js
// Definitions by: Yu-Hsi Chiang <https://github.com/arbuztw>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { BigInteger as BigInt } from 'jsbn';
export default class ElGamal {
p: BigInt;
g: BigInt;
y: BigInt;
x: BigInt;
static generateAsync(primeBits?: number): Promise<ElGamal>;
constructor(p: BigInt | string | number, g: BigInt | string | number, y: BigInt | string | number, x: BigInt | string | number);
encryptAsync(m: BigInt | string | number, k?: BigInt | string | number): Promise<EncryptedValue>;
decryptAsync(m: EncryptedValue): Promise<DecryptedValue>;
}
export { BigInt };
export class DecryptedValue {
bi: BigInt;
constructor(m: BigInt | string | number);
toString(): string;
}
export class EncryptedValue {
a: BigInt;
b: BigInt;
constructor(a: BigInt, b: BigInt);
multiply(encryptedValue: EncryptedValue): EncryptedValue;
}
export namespace Utils {
const BIG_TWO: BigInt;
function getRandomNbitBigIntAsync(bits: number): Promise<BigInt>;
function getRandomBigIntAsync(min: BigInt, max: BigInt): Promise<BigInt>;
function getBigPrimeAsync(bits: number): Promise<BigInt>;
function parseBigInt(obj: BigInt | string | number): BigInt | null;
}
export class MissingPrivateKeyError extends Error { }

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"elgamal-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }