|
| 1 | +/** |
| 2 | + * @bitgo/argon2 - Vendored from hash-wasm v4.12.0 |
| 3 | + * https://github.com/Daninet/hash-wasm |
| 4 | + * MIT License - Copyright (c) 2020 Dani Biro |
| 5 | + */ |
| 6 | + |
| 7 | +export type ITypedArray = Uint8Array | Uint16Array | Uint32Array; |
| 8 | +export type IDataType = string | Buffer | ITypedArray; |
| 9 | + |
| 10 | +export interface IArgon2Options { |
| 11 | + /** Password (or message) to be hashed */ |
| 12 | + password: IDataType; |
| 13 | + /** Salt (usually containing random bytes) */ |
| 14 | + salt: IDataType; |
| 15 | + /** Secret for keyed hashing */ |
| 16 | + secret?: IDataType; |
| 17 | + /** Number of iterations to perform */ |
| 18 | + iterations: number; |
| 19 | + /** Degree of parallelism */ |
| 20 | + parallelism: number; |
| 21 | + /** Amount of memory to be used in kibibytes (1024 bytes) */ |
| 22 | + memorySize: number; |
| 23 | + /** Output size in bytes */ |
| 24 | + hashLength: number; |
| 25 | + /** Desired output type. Defaults to 'hex' */ |
| 26 | + outputType?: 'hex' | 'binary' | 'encoded'; |
| 27 | +} |
| 28 | + |
| 29 | +interface IArgon2OptionsBinary { |
| 30 | + outputType: 'binary'; |
| 31 | +} |
| 32 | + |
| 33 | +type Argon2ReturnType<T> = T extends IArgon2OptionsBinary ? Uint8Array : string; |
| 34 | + |
| 35 | +/** Calculates hash using the argon2i password-hashing function */ |
| 36 | +export function argon2i<T extends IArgon2Options>(options: T): Promise<Argon2ReturnType<T>>; |
| 37 | + |
| 38 | +/** Calculates hash using the argon2id password-hashing function */ |
| 39 | +export function argon2id<T extends IArgon2Options>(options: T): Promise<Argon2ReturnType<T>>; |
| 40 | + |
| 41 | +/** Calculates hash using the argon2d password-hashing function */ |
| 42 | +export function argon2d<T extends IArgon2Options>(options: T): Promise<Argon2ReturnType<T>>; |
| 43 | + |
| 44 | +export interface Argon2VerifyOptions { |
| 45 | + /** Password to be verified */ |
| 46 | + password: IDataType; |
| 47 | + /** Secret used on hash creation */ |
| 48 | + secret?: IDataType; |
| 49 | + /** A previously generated argon2 hash in the 'encoded' output format */ |
| 50 | + hash: string; |
| 51 | +} |
| 52 | + |
| 53 | +/** Verifies password using the argon2 password-hashing function */ |
| 54 | +export function argon2Verify(options: Argon2VerifyOptions): Promise<boolean>; |
0 commit comments