UNPKG

cryptonism

Version:

End-to-end encryption library for browser

156 lines (143 loc) 4.64 kB
declare class DecryptionError extends Error { constructor(message?: string); } declare class EncryptionError extends Error { constructor(message?: string); } declare class PasswordRotationError extends Error { constructor(message?: string); } declare class RecoverEncryptionError extends Error { constructor(message?: string); } type ArgonConfig = { time?: number; mem?: number; hashLen?: number; }; interface GenerateEncryptedKeyParams { password: string; argonConfig?: ArgonConfig; } type GenerateEncryptedKeySuccess = { success: true; encryptedKey: string; salt: string; iv: string; recoveryPhrase: string; encryptedRecoveryKey: string; recoverySalt: string; recoveryIV: string; }; type GenerateEncryptedKeyFailure = { success: false; error: EncryptionError; }; type GenerateEncryptedKeyResult = GenerateEncryptedKeySuccess | GenerateEncryptedKeyFailure; interface DecryptGeneratedKeyParams { salt: string; iv: string; encryptedKey: string; password: string; argonConfig?: ArgonConfig; trackAttempts?: TrackAttemptsOptions; } type DecryptSuccess = { success: true; decryptedKey: Uint8Array; attempts: number; }; type DecryptFailure = { success: false; error: DecryptionError; attempts?: number; }; type DecryptGeneratedKeyResult = DecryptSuccess | DecryptFailure; interface TrackAttemptsOptions { enable: true; id: string; maxAttempts: number; } interface RotatePasswordParams { encryptedKey: string; salt: string; iv: string; oldPassword: string; newPassword: string; argonConfig?: ArgonConfig; } type RotatePasswordSuccess = { success: true; encryptedKey: string; salt: string; iv: string; }; type RotatePasswordFailure = { success: false; error: PasswordRotationError; }; type RotatePasswordReturn = RotatePasswordSuccess | RotatePasswordFailure; interface RecoverEncryptedKeyParams { recoveryMnemonic: string; encryptedRecoveryKey: string; recoverySalt: string; recoveryIV: string; argonConfig?: ArgonConfig; } type RecoverEncryptedKeyResult = { success: true; decryptedKey: Uint8Array; } | { success: false; error: RecoverEncryptionError; }; interface rotatePasswordAfterRecoveryParams { recoveredDecryptedKey: Uint8Array; newPassword: string; argonConfig?: ArgonConfig; } type RotatePasswordAfterRecoverySuccess = { success: true; encryptedKey: string; salt: string; iv: string; }; type RotatePasswordAfterRecoveryFailure = { success: false; error: PasswordRotationError; }; type RotatePasswordAfterRecoveryResult = RotatePasswordAfterRecoverySuccess | RotatePasswordAfterRecoveryFailure; interface EncryptSecretParams { secret: string; decryptedKey: Uint8Array; } type EncryptedSecretSuccess = { success: true; encryptedSecret: string; iv: string; }; type EncryptedSecretFailure = { success: false; error: EncryptionError; }; type EncryptedSecretResult = EncryptedSecretSuccess | EncryptedSecretFailure; interface DecryptSecretParams { encryptedSecret: string; iv: string; decryptedKey: Uint8Array; } type DecryptSecretResult = { success: true; decryptedSecret: string; } | { success: false; error: DecryptionError; }; declare const generateEncryptedKey: ({ password, argonConfig }: GenerateEncryptedKeyParams) => Promise<GenerateEncryptedKeyResult>; declare const decryptGeneratedKey: ({ salt, iv, encryptedKey, password, argonConfig, trackAttempts, }: DecryptGeneratedKeyParams) => Promise<DecryptGeneratedKeyResult>; declare const rotatePassword: ({ encryptedKey, salt, iv, oldPassword, newPassword, argonConfig }: RotatePasswordParams) => Promise<RotatePasswordReturn>; declare const recoverEncryptedKey: ({ recoveryMnemonic, encryptedRecoveryKey, recoverySalt, recoveryIV, argonConfig }: RecoverEncryptedKeyParams) => Promise<RecoverEncryptedKeyResult>; declare const rotatePasswordAfterRecovery: ({ recoveredDecryptedKey, newPassword, argonConfig }: rotatePasswordAfterRecoveryParams) => Promise<RotatePasswordAfterRecoveryResult>; declare const encryptSecret: ({ secret, decryptedKey }: EncryptSecretParams) => Promise<EncryptedSecretResult>; declare const decryptSecret: ({ encryptedSecret, iv, decryptedKey }: DecryptSecretParams) => Promise<DecryptSecretResult>; export { DecryptionError, EncryptionError, PasswordRotationError, RecoverEncryptionError, decryptGeneratedKey, decryptSecret, encryptSecret, generateEncryptedKey, recoverEncryptedKey, rotatePassword, rotatePasswordAfterRecovery };