mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
add type definitions for elgamal (#36131)
This commit is contained in:
parent
3537919757
commit
8f4ca2e2bd
11
types/elgamal/elgamal-tests.ts
Normal file
11
types/elgamal/elgamal-tests.ts
Normal 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
42
types/elgamal/index.d.ts
vendored
Normal 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 { }
|
||||
24
types/elgamal/tsconfig.json
Normal file
24
types/elgamal/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/elgamal/tslint.json
Normal file
1
types/elgamal/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user