@interopio/gateway-server
Version:
[](https://www.npmjs.com/package/@interopio/gateway-server)
128 lines (111 loc) • 3.08 kB
TypeScript
/**
* Argon2 version 1.0 (0x10)
*/
export const ARGON2_VERSION_10: number;
/**
* Argon2 version 1.3 (0x13) - current version
*/
export const ARGON2_VERSION_13: number;
/**
* Current Argon2 version used by default
*/
export const ARGON2_VERSION: number;
/**
* Default salt length in bytes (16)
*/
export const DEFAULT_SALT_LENGTH: number;
/**
* Default hash length in bytes (32)
*/
export const DEFAULT_HASH_LENGTH: number;
/**
* Default parallelism parameter (4)
*/
export const DEFAULT_PARALLELISM: number;
/**
* Default memory cost in KiB (65536 = 64 MB)
*/
export const DEFAULT_MEMORY: number;
/**
* Default number of iterations (3)
*/
export const DEFAULT_PASSES: number;
/**
* Argon2 algorithm variants
*/
export type Argon2Algorithm = 'argon2d' | 'argon2i' | 'argon2id';
/**
* Argon2 hash parameters
*/
export type Argon2HashParameters = {
memory: number;
passes: number;
parallelism: number;
nonce: Buffer;
};
/**
* Decoded Argon2 hash structure
*/
export type Argon2Hash = {
algorithm: Argon2Algorithm;
version: number;
parameters: Argon2HashParameters;
hash: Buffer;
};
/**
* Hash a password using Argon2.
*
* @param password - The plain text password to hash
* @param options - Optional parameters. If not provided, defaults will be used.
* @returns The encoded Argon2 hash string
*/
export function hash(
password: string,
options?: {
saltLength?: number;
hashLength?: number;
parallelism?: number;
memory?: number;
passes?: number;
}
): Promise<string>;
/**
* Verify a password against an Argon2 hash.
*
* @param encodedHash - The encoded Argon2 hash to verify against
* @param password - The plain text password to verify
* @returns true if password matches the hash, false otherwise
*/
export function verify(encodedHash: string, password: string): Promise<boolean>;
/**
* Create an Argon2 hash from parameters.
* Low-level wrapper around node:crypto's argon2Sync.
*
* @param algorithm - Argon2 algorithm variant ('argon2d' | 'argon2i' | 'argon2id')
* @param password - The password to hash
* @param hashLength - Length of the output hash in bytes
* @param parameters - Argon2 parameters (nonce, memory, passes, parallelism). If not provided, defaults will be used.
* @returns The hash buffer
*/
export function createHash(
algorithm: Argon2Algorithm,
password: string,
hashLength: number,
parameters?: Argon2HashParameters
): Promise<Buffer>;
/**
* Decode an encoded Argon2 hash string into its components.
* Format: $argon2id$v=19$m=65536,t=3,p=4$base64salt$base64hash
*
* @param encodedHash - The encoded Argon2 hash string
* @returns Decoded hash components
*/
export function decode(encodedHash: string): Argon2Hash;
/**
* Encode Argon2 hash components into a standard string format.
* Format: $argon2id$v=19$m=65536,t=3,p=4$base64salt$base64hash
*
* @param hashData - The hash components to encode
* @returns Encoded hash string
*/
export function encode(hashData: Argon2Hash): string;