Skip to content

otplib API Documentation / @otplib/hotp / OTPResult

Type Alias: OTPResult<T, E> ​

OTPResult<T, E> = OTPResultOk<T> | OTPResultError<E>

Defined in: core/src/types.ts:250

Result type for functional error handling

Allows returning errors as values instead of throwing exceptions. Use with generateSafe() and verifySafe() functions.

Type Parameters ​

T ​

T

E ​

E = Error

Example ​

typescript
const result = await generateSafe({ secret, crypto, base32 });
if (result.ok) {
  console.log('Token:', result.value);
} else {
  console.log('Error:', result.error.message);
}

Released under the MIT License.