mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
add: added type definitions for new jssha version (2.0.2) because of the rework from 1.6 to 2.0
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/// <reference path="jssha.d.ts" />
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
var imported = require("jssha");
|
||||
|
||||
// constructor
|
||||
let shaObj1:jsSHA.jsSHA = imported("SHA-256", "HEX");
|
||||
let shaObj2:jsSHA.jsSHA = new jsSHA("SHA-512", "TEXT");
|
||||
let shaObj3:jsSHA.jsSHA = new jsSHA("SHA-512", "TEXT", { });
|
||||
let shaObj4:jsSHA.jsSHA = new jsSHA("SHA-512", "TEXT", { encoding: "UTF" });
|
||||
let shaObj5:jsSHA.jsSHA = new jsSHA("SHA-512", "TEXT", { numRounds: 1 });
|
||||
let shaObj6:jsSHA.jsSHA = new jsSHA("SHA-512", "TEXT", { encoding: "UTF", numRounds: 1 });
|
||||
|
||||
// setHMACKey
|
||||
shaObj1.setHMACKey("key", "TEXT");
|
||||
shaObj1.setHMACKey("key", "TEXT", { });
|
||||
shaObj1.setHMACKey("key", "TEXT", { encoding: "UTF" });
|
||||
|
||||
// update
|
||||
shaObj1.update("This is a test");
|
||||
|
||||
// getHash
|
||||
let hash1:string = shaObj1.getHash("HEX");
|
||||
let hash2:string = shaObj1.getHash("HEX", {});
|
||||
let hash3:string = shaObj1.getHash("HEX", { b64Pad: "=" });
|
||||
let hash4:string = shaObj1.getHash("HEX", { outputUpper: true });
|
||||
let hash5:string = shaObj1.getHash("HEX", { outputUpper: true, b64Pad: '=' });
|
||||
|
||||
// getHMAC
|
||||
let hmac1:string = shaObj1.getHMAC("HEX");
|
||||
let hmac2:string = shaObj1.getHMAC("HEX", {});
|
||||
let hmac3:string = shaObj1.getHMAC("HEX", { b64Pad: "=" });
|
||||
let hmac4:string = shaObj1.getHMAC("HEX", { outputUpper: true });
|
||||
let hmac5:string = shaObj1.getHMAC("HEX", { outputUpper: true, b64Pad: '=' });
|
||||
|
||||
|
||||
// examples from the readme.md (https://github.com/Caligatio/jsSHA/blob/v2.0.2/README.md)
|
||||
{
|
||||
var shaObj = new jsSHA("SHA-512", "TEXT");
|
||||
shaObj.update("This is a test");
|
||||
var hash = shaObj.getHash("HEX");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
let shaObj = new jsSHA("SHA-256", "TEXT");
|
||||
shaObj.setHMACKey("abc", "TEXT");
|
||||
shaObj.update("This is a test");
|
||||
let hmac = shaObj.getHMAC("HEX");
|
||||
}
|
||||
Vendored
+87
@@ -0,0 +1,87 @@
|
||||
// Type definitions for jsSHA
|
||||
// Project: https://github.com/Caligatio/jsSHA
|
||||
// Definitions by: Tobias Kahlert <https://github.com/SrTobi>
|
||||
// Definitions: https://github.com/SrTobi/DefinitelyTyped
|
||||
|
||||
|
||||
declare module jsSHA {
|
||||
|
||||
export interface EncodingOptions {
|
||||
encoding? : string;
|
||||
}
|
||||
|
||||
export interface Options extends EncodingOptions {
|
||||
numRounds? : number;
|
||||
}
|
||||
|
||||
export interface OutputFormatOptions {
|
||||
outputUpper? : boolean;
|
||||
b64Pad? : string;
|
||||
}
|
||||
|
||||
export interface jsSHA {
|
||||
/**
|
||||
* jsSHA is the workhorse of the library. Instantiate it with the string to
|
||||
* be hashed as the parameter
|
||||
*
|
||||
* @constructor
|
||||
* @this {jsSHA}
|
||||
* @param {string} variant The desired SHA variant (SHA-1, SHA-224, SHA-256,
|
||||
* SHA-384, or SHA-512)
|
||||
* @param {string} inputFormat The format of srcString: HEX, TEXT, B64, or BYTES
|
||||
* @param {{encoding: (string|undefined), numRounds: (string|undefined)}=}
|
||||
* options Optional values
|
||||
*/
|
||||
new (variant:string, inputFormat:string, options?:Options):jsSHA;
|
||||
|
||||
/**
|
||||
* Sets the HMAC key for an eventual getHMAC call. Must be called
|
||||
* immediately after jsSHA object instantiation
|
||||
*
|
||||
* @param {string} key The key used to calculate the HMAC
|
||||
* @param {string} inputFormat The format of key, HEX, TEXT, B64, or BYTES
|
||||
* @param {{encoding : (string|undefined)}=} options Associative array
|
||||
* of input format options
|
||||
*/
|
||||
setHMACKey(key:string, inputFormat:string, encodingOpts?:EncodingOptions):void;
|
||||
|
||||
/**
|
||||
* Takes strString and hashes as many blocks as possible. Stores the
|
||||
* rest for either a future update or getHash call.
|
||||
*
|
||||
* @param {string} srcString The string to be hashed
|
||||
*/
|
||||
update(srcString:string):void;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the desired SHA hash of the string specified at instantiation
|
||||
* using the specified parameters
|
||||
*
|
||||
* @param {string} format The desired output formatting (B64, HEX, or BYTES)
|
||||
* @param {{outputUpper : (boolean|undefined), b64Pad : (string|undefined)}=}
|
||||
* options Hash list of output formatting options
|
||||
* @return {string} The string representation of the hash in the format
|
||||
* specified
|
||||
*/
|
||||
getHash(format:string, outputFormatOpts?:OutputFormatOptions):string;
|
||||
|
||||
/**
|
||||
* Returns the the HMAC in the specified format using the key given by
|
||||
* a previous setHMACKey call.
|
||||
*
|
||||
* @param {string} format The desired output formatting
|
||||
* (B64, HEX, or BYTES)
|
||||
* @param {{outputUpper : (boolean|undefined), b64Pad : (string|undefined)}=}
|
||||
* options associative array of output formatting options
|
||||
* @return {string} The string representation of the hash in the format
|
||||
* specified
|
||||
*/
|
||||
getHMAC(format:string, outputFormatOpts?:OutputFormatOptions):string;
|
||||
}
|
||||
}
|
||||
|
||||
declare var jsSHA: jsSHA.jsSHA;
|
||||
declare module 'jssha' {
|
||||
export = jsSHA;
|
||||
}
|
||||
Reference in New Issue
Block a user