mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 21:00:01 +08:00
Add type definitions for node-srp
This commit is contained in:
45
srp/srp-tests.ts
Normal file
45
srp/srp-tests.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/// <reference path="srp.d.ts" />
|
||||
|
||||
var srp = require('srp');
|
||||
|
||||
|
||||
// Test the `params` variable.
|
||||
var params = srp.params['1024'];
|
||||
|
||||
|
||||
// Test the `genKey` function.
|
||||
srp.genKey(function (err: Error, buf: Buffer): void {});
|
||||
srp.genKey(16, function (err: Error, buf: Buffer): void {});
|
||||
|
||||
|
||||
// Test the `computeVerifier` function.
|
||||
var salt = new Buffer('deadbeef', 'hex');
|
||||
var identifier = new Buffer('AzureDiamond');
|
||||
var password = new Buffer('hunter2');
|
||||
|
||||
var verifier = srp.computeVerifier(params, salt, identifier, password);
|
||||
|
||||
|
||||
// Test the `Client` class.
|
||||
var secret1 = new Buffer(32);
|
||||
var client = new srp.Client(params, salt, identifier, password, secret1);
|
||||
|
||||
|
||||
// Test the `Server` class.
|
||||
var secret2 = new Buffer(32);
|
||||
var server = new srp.Server(params, verifier, secret2);
|
||||
|
||||
|
||||
// Test handshake protocol.
|
||||
var A = client.computeA();
|
||||
server.setA(A);
|
||||
|
||||
var B = server.computeB();
|
||||
client.setB(B);
|
||||
|
||||
var M1 = client.computeM1();
|
||||
var M2 = server.checkM1(M1);
|
||||
client.checkM2(M2);
|
||||
|
||||
client.computeK();
|
||||
server.computeK();
|
||||
75
srp/srp.d.ts
vendored
Normal file
75
srp/srp.d.ts
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
// Type definitions for node-srp
|
||||
// Project: https://github.com/mozilla/node-srp
|
||||
// Definitions by: Pat Smuk <https://github.com/Patman64>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../bignum/bignum.d.ts" />
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare namespace SRP {
|
||||
export interface Params {
|
||||
N_length_bits: number;
|
||||
N: BigNum;
|
||||
g: BigNum;
|
||||
hash: string;
|
||||
}
|
||||
|
||||
export var params: {
|
||||
[bits: string]: Params;
|
||||
};
|
||||
|
||||
/**
|
||||
* The verifier is calculated as described in Section 3 of [SRP-RFC].
|
||||
* We give the algorithm here for convenience.
|
||||
*
|
||||
* The verifier (v) is computed based on the salt (s), user name (I),
|
||||
* password (P), and group parameters (N, g).
|
||||
*
|
||||
* x = H(s | H(I | ":" | P))
|
||||
* v = g^x % N
|
||||
*
|
||||
* @param {Params} params group parameters, with .N, .g, .hash
|
||||
* @param {Buffer} salt salt
|
||||
* @param {Buffer} I user identity
|
||||
* @param {Buffer} P user password
|
||||
*
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
export function computeVerifier(params: Params, salt: Buffer, I: Buffer, P: Buffer): Buffer;
|
||||
|
||||
/**
|
||||
* Generate a random key.
|
||||
*
|
||||
* @param {number} bytes length of key (default=32)
|
||||
* @param {function} callback function to call with err,key
|
||||
*/
|
||||
export function genKey(bytes: number, callback: (error: Error, key: Buffer) => void): void;
|
||||
|
||||
/**
|
||||
* Generate a random 32-byte key.
|
||||
*
|
||||
* @param {function} callback function to call with err,key
|
||||
*/
|
||||
export function genKey(callback: (error: Error, key: Buffer) => void): void;
|
||||
|
||||
export class Client {
|
||||
constructor(params: Params, salt: Buffer, identity: Buffer, password: Buffer, secret1: Buffer);
|
||||
computeA(): Buffer;
|
||||
setB(B: Buffer): void;
|
||||
computeM1(): Buffer;
|
||||
checkM2(M2: Buffer): void;
|
||||
computeK(): Buffer;
|
||||
}
|
||||
|
||||
export class Server {
|
||||
constructor(params: Params, verifier: Buffer, secret2: Buffer);
|
||||
computeB(): Buffer;
|
||||
setA(A: Buffer): void;
|
||||
checkM1(M1: Buffer): Buffer;
|
||||
computeK(): Buffer;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "srp" {
|
||||
export = SRP;
|
||||
}
|
||||
Reference in New Issue
Block a user