-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscrypt.d.ts
More file actions
71 lines (64 loc) · 2.25 KB
/
scrypt.d.ts
File metadata and controls
71 lines (64 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* scrypt parameters
*/
interface ScryptParamsKdf {
/** CPU/memory cost parameter. */
logN: number;
/** Block size parameter. */
r?: number;
/** Parallelization parameter. */
p?: number;
}
/**
* scrypt parameters
*/
export type ScryptParams = Required<ScryptParamsKdf>;
/**
* Produce derived key using scrypt as a key derivation function.
*
* @param passphrase Secret value such as a password from which key is to be derived.
* @param params Scrypt parameters.
* @returns Derived key.
*
* @example
* const key = await Scrypt.kdf('my secret password', { logN: 15 });
*/
export declare function kdf(passphrase: string|Uint8Array, params: Readonly<ScryptParamsKdf>): Promise<Uint8Array>;
/**
* Check whether key was generated from passphrase.
*
* @param key Derived key obtained from Scrypt.kdf().
* @param passphrase Passphrase originally used to generate key.
* @returns True if key was generated from passphrase.
*
* @example
* const ok = await Scrypt.verify(key, 'my secret password');
*/
export declare function verify(key: string|Uint8Array, passphrase: string|Uint8Array): Promise<boolean>;
/**
* View scrypt parameters which were used to derive key.
*
* @param key Derived key obtained from Scrypt.kdf().
* @returns Scrypt parameters logN, r, p.
*
* @example
* const key = await Scrypt.kdf('my secret password', { logN: 15 } );
* const params = Scrypt.viewParams(key); // => { logN: 15, r: 8, p: 1 }
*/
export declare function viewParams(key: string|Uint8Array): ScryptParams;
/**
* Calculate scrypt parameters from maxtime, maxmem, maxmemfrac values.
*
* Adapted from Colin Percival's code: see github.com/Tarsnap/scrypt/tree/master/lib.
*
* Returned parameters may vary depending on computer specs & current loading.
*
* @param maxtime Maximum time in seconds scrypt will spend computing the derived key.
* @param maxmem Maximum bytes of RAM used when computing the derived encryption key.
* @param maxmemfrac Fraction of the available RAM used when computing the derived key.
* @returns Scrypt parameters logN, r, p.
*
* @example
* const params = Scrypt.pickParams(0.1); // => e.g. { logN: 15, r: 8, p: 1 }
*/
export declare function pickParams(maxtime: number, maxmem?: number, maxmemfrac?: number): ScryptParams;