mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 20:39:17 +08:00
Add definitions for CSRF module
This commit is contained in:
16
types/csrf/csrf-tests.ts
Normal file
16
types/csrf/csrf-tests.ts
Normal 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
62
types/csrf/index.d.ts
vendored
Normal 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
22
types/csrf/tsconfig.json
Normal 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
1
types/csrf/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user