Add typings for argon2.

This commit is contained in:
Peter Safranek
2016-11-24 00:50:58 -08:00
parent b58357a144
commit b93dc24e1b
4 changed files with 99 additions and 0 deletions

35
argon2/argon2-tests.ts Normal file
View File

@@ -0,0 +1,35 @@
import { defaults, limits, hash, verify, generateSalt } from 'argon2';
main();
async function main() {
const defaultTimeCost: number = defaults.timeCost;
const defaultMemoryCost: number = defaults.memoryCost;
const defaultParallelism: number = defaults.parallelism;
const defaultArgon2d: boolean = defaults.argon2d;
const minMemoryCost: number = limits.memoryCost.min;
const maxMemoryCost: number = limits.memoryCost.max;
const minTimeCost: number = limits.timeCost.min;
const maxTimeCost: number = limits.timeCost.max;
const minParallelism: number = limits.parallelism.min;
const maxParallelism: number = limits.parallelism.max;
const options = {
timeCost: 4,
memoryCost: 13,
parallelism: 2,
argon2d: true,
};
const hash1: string = await hash('secret', new Buffer(''), options);
const hash2: string = await hash('secret', new Buffer(''), {});
const hash3: string = await hash('secret', new Buffer(''));
const verified: boolean = await verify('long-hash', 'secret');
const salt1: Buffer = await generateSalt();
const salt2: Buffer = await generateSalt(32);
}

44
argon2/index.d.ts vendored Normal file
View File

@@ -0,0 +1,44 @@
// Type definitions for argon2 0.14
// Project: https://github.com/ranisalt/node-argon2#readme
// Definitions by: Peter Safranek <https://github.com/pe8ter>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
declare namespace argon2 {
export var defaults: {
timeCost: number;
memoryCost: number;
parallelism: number;
argon2d: boolean;
};
export var limits: {
memoryCost: {
min: number;
max: number;
};
timeCost: {
min: number;
max: number;
};
parallelism: {
min: number;
max: number;
};
};
export function hash(plain: string, salt: Buffer, options?: {
timeCost?: number;
memoryCost?: number;
parallelism?: number;
argon2d?: boolean;
}): Promise<string>;
export function verify(hash: string, plain: string): Promise<boolean>;
export function generateSalt(length?: number): Promise<Buffer>;
}
export = argon2;

19
argon2/tsconfig.json Normal file
View File

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

1
argon2/tslint.json Normal file
View File

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