mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
Add typings for argon2.
This commit is contained in:
35
argon2/argon2-tests.ts
Normal file
35
argon2/argon2-tests.ts
Normal 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
44
argon2/index.d.ts
vendored
Normal 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
19
argon2/tsconfig.json
Normal 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
1
argon2/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user