Add definitions for CSRF module

This commit is contained in:
Markis Taylor
2017-03-30 23:38:42 -07:00
parent f2b6506ba5
commit 073e443bf5
4 changed files with 101 additions and 0 deletions

16
types/csrf/csrf-tests.ts Normal file
View File

@@ -0,0 +1,16 @@
import Tokens = require('csrf');
const csrf = new Tokens();
// test synchronous secret/token creation
const secret = csrf.secretSync();
const token = csrf.create(secret);
csrf.verify(secret, token);
// test asynchronous secret/token creation
csrf.secret((err: Error, secret: string) => {
if (err) throw err;
const token = csrf.create(secret);
csrf.verify(secret, token);
});

62
types/csrf/index.d.ts vendored Normal file
View File

@@ -0,0 +1,62 @@
// Type definitions for b_ 1.3
// Project: https://github.com/pillarjs/csrf
// Definitions by: Markis Taylor <https://github.com/markis>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
type SecretCallback = (err: Error | null, secret: string) => void;
interface TokensOptions {
/**
* The string length of the salt (default: 8)
*/
saltLength: number;
/**
* The byte length of the secret key (default: 18)
*/
secretLength: number;
}
declare class Tokens {
/**
* Token generation/verification class.
*
* @param {object} [options]
* @param {number} [options.saltLength=8] The string length of the salt
* @param {number} [options.secretLength=18] The byte length of the secret key
* @public
*/
constructor(options?: TokensOptions)
/**
* Create a new CSRF token.
*
* @param {string} secret The secret for the token.
* @public
*/
create(secret: string): string;
/**
* Create a new secret key.
*
* @param {function} [callback]
* @public
*/
secret(callback?: SecretCallback): Promise<string>;
/**
* Create a new secret key synchronously.
* @public
*/
secretSync(): string;
/**
* Verify if a given token is valid for a given secret.
*
* @param {string} secret
* @param {string} token
* @public
*/
verify(secret: string, token: string): boolean;
}
export = Tokens;

22
types/csrf/tsconfig.json Normal file
View File

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

1
types/csrf/tslint.json Normal file
View File

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