1 | // Type definitions for jsSHA
|
2 | // Project: https://github.com/Caligatio/jsSHA
|
3 | // Definitions by: David Li <https://github.com/randombk>, Tobias Kahlert <https://github.com/SrTobi>
|
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
5 |
|
6 |
|
7 | declare namespace jsSHA {
|
8 |
|
9 | export interface EncodingOptions {
|
10 | encoding? : string;
|
11 | }
|
12 |
|
13 | export interface Options extends EncodingOptions {
|
14 | numRounds? : number;
|
15 | }
|
16 |
|
17 | export interface OutputFormatOptions {
|
18 | outputUpper? : boolean;
|
19 | b64Pad? : string;
|
20 | }
|
21 |
|
22 | export interface jsSHA {
|
23 | /**
|
24 | * jsSHA is the workhorse of the library. Instantiate it with the string to
|
25 | * be hashed as the parameter
|
26 | *
|
27 | * @param {string} variant The desired SHA variant (SHA-1, SHA-224, SHA-256,
|
28 | * SHA-384, or SHA-512)
|
29 | * @param {string} inputFormat The format of srcString: HEX, TEXT, B64, or BYTES
|
30 | * @param {{encoding: (string|undefined), numRounds: (string|undefined)}=}
|
31 | * options Optional values
|
32 | */
|
33 | new (variant:string, inputFormat:string, options?:Options):jsSHA;
|
34 |
|
35 | /**
|
36 | * Sets the HMAC key for an eventual getHMAC call. Must be called
|
37 | * immediately after jsSHA object instantiation
|
38 | *
|
39 | * @param {string} key The key used to calculate the HMAC
|
40 | * @param {string} inputFormat The format of key, HEX, TEXT, B64, or BYTES
|
41 | * @param {{encoding : (string|undefined)}=} encodingOpts Associative array
|
42 | * of input format options
|
43 | */
|
44 | setHMACKey(key:string, inputFormat:string, encodingOpts?:EncodingOptions):void;
|
45 |
|
46 | /**
|
47 | * Takes strString and hashes as many blocks as possible. Stores the
|
48 | * rest for either a future update or getHash call.
|
49 | *
|
50 | * @param {string} srcString The string to be hashed
|
51 | */
|
52 | update(srcString:string):void;
|
53 |
|
54 |
|
55 | /**
|
56 | * Returns the desired SHA hash of the string specified at instantiation
|
57 | * using the specified parameters
|
58 | *
|
59 | * @param {string} format The desired output formatting (B64, HEX, or BYTES)
|
60 | * @param {{outputUpper : (boolean|undefined), b64Pad : (string|undefined)}=}
|
61 | * outputFormatOpts Hash list of output formatting options
|
62 | * @return {string} The string representation of the hash in the format
|
63 | * specified
|
64 | */
|
65 | getHash(format:string, outputFormatOpts?:OutputFormatOptions):string;
|
66 |
|
67 | /**
|
68 | * Returns the the HMAC in the specified format using the key given by
|
69 | * a previous setHMACKey call.
|
70 | *
|
71 | * @param {string} format The desired output formatting
|
72 | * (B64, HEX, or BYTES)
|
73 | * @param {{outputUpper : (boolean|undefined), b64Pad : (string|undefined)}=}
|
74 | * outputFormatOpts associative array of output formatting options
|
75 | * @return {string} The string representation of the hash in the format
|
76 | * specified
|
77 | */
|
78 | getHMAC(format:string, outputFormatOpts?:OutputFormatOptions):string;
|
79 | }
|
80 | }
|
81 |
|
82 | declare var jsSHA: jsSHA.jsSHA;
|
83 | export = jsSHA;
|
84 | export as namespace jsSHA;
|