UNPKG

@scirexs/srp6a

Version:

SRP-6a (Secure Remote Password) implementation in TypeScript for browser and server.

132 lines 4.87 kB
export { computeHash, CryptoNumber, generateSecureRandom, getDefaultConfig, SRPConfig }; import type { HashAlgorithm, SRPHashConfig, SRPSecurityGroup } from "./types.js"; /** * Configuration class for SRP6a authentication protocol * Combines security group and hash settings to provide various parameters required for authentication */ declare class SRPConfig { #private; /** * Gets the prime number from the security group * @returns {CryptoNumber} Prime number value */ get prime(): CryptoNumber; /** * Gets the generator from the security group * @returns {CryptoNumber} Generator value */ get generator(): CryptoNumber; /** * Gets the bit length of the security group * @returns {number} Bit length */ get length(): number; /** * Gets the multiplier from the security group * @returns {string} Multiplier value */ get multiplier(): string; /** * Gets the hash algorithm * @returns {HashAlgorithm} Hash algorithm */ get algorithm(): HashAlgorithm; /** * Gets the number of bytes in the hash value * @returns {number} Number of bytes in hash value */ get hashBytes(): number; /** * Gets the salt bit length * @returns {number} Salt bit length */ get salt(): number; /** * Creates an instance of SRPConfig * @param {SRPSecurityGroup} group - Security group configuration * @param {SRPHashConfig} hash - Hash configuration */ constructor(group: SRPSecurityGroup, hash: SRPHashConfig); } /** * Gets the default SRP configuration * Returns default configuration using GROUP_2048 and SHA_256 * @returns {SRPConfig} Default SRP configuration */ declare function getDefaultConfig(): SRPConfig; declare function computeHash(num: CryptoNumber | Uint8Array, config: SRPConfig): Promise<CryptoNumber>; declare function generateSecureRandom(bytes: number): CryptoNumber; /** * Class representing numbers used in cryptographic operations * Manages numbers in three formats: bigint, hex string, and Uint8Array, * with lazy conversion performed as needed */ declare class CryptoNumber { #private; /** Padding length for hex strings (no need to use) */ static PAD_LEN: number; /** * Gets the number in bigint format (lazy evaluation) * @returns {bigint} Number in bigint format */ get int(): bigint; /** * Gets the number in hex string format (lazy evaluation) * @returns {string} Number in hex string format */ get hex(): string; /** * Gets the number in Uint8Array format (lazy evaluation) * @returns {Uint8Array} Number in Uint8Array format */ get buf(): Uint8Array; /** * Creates an instance of CryptoNumber * @param {bigint | string | Uint8Array} value - Initial value (bigint, hex string, or Uint8Array) * @throws {Error} If PAD_LEN is not initialized */ constructor(value: bigint | string | Uint8Array); /** * Returns a new CryptoNumber with hex string left-padded with zeros to the specified length * @param {number} [len] - Padding length (uses PAD_LEN if omitted) * @returns {CryptoNumber} New CryptoNumber with padded value */ pad(len?: number): CryptoNumber; /** * Clears the internal Uint8Array buffer by filling it with zeros * Used to securely erase sensitive data */ clear(): void; /** * Efficiently calculates modular exponentiation (base^pow mod mod) * @param {CryptoNumber | bigint} base - Base value * @param {CryptoNumber | bigint} pow - Exponent value * @param {CryptoNumber} mod - Modulus value * @returns {CryptoNumber} Result of modular exponentiation * @throws {Error} If arguments are invalid */ static modPow(base: CryptoNumber | bigint, pow: CryptoNumber | bigint, mod: CryptoNumber): CryptoNumber; /** * Concatenates multiple CryptoNumber buffers * @param {...CryptoNumber} nums - CryptoNumbers to concatenate * @returns {CryptoNumber} Concatenated CryptoNumber */ static concat(...nums: CryptoNumber[]): CryptoNumber; /** * Performs XOR operation on two CryptoNumbers * @param {CryptoNumber} a - First operand * @param {CryptoNumber} b - Second operand * @returns {CryptoNumber} XOR operation result * @throws {Error} If buffer lengths differ */ static xor(a: CryptoNumber, b: CryptoNumber): CryptoNumber; /** * Compares two CryptoNumbers in constant time * Used to prevent timing attacks * @param {CryptoNumber} a - First comparison target * @param {CryptoNumber} b - Second comparison target * @returns {boolean} True if values are equal */ static compare(a: CryptoNumber, b: CryptoNumber): boolean; } //# sourceMappingURL=crypto.d.ts.map