otplib API Documentation / @otplib/core / CryptoPlugin
Type Alias: CryptoPlugin
CryptoPlugin =
object
Defined in: packages/core/src/types.ts:15
Cryptographic plugin type for abstracting HMAC and random byte generation across different runtime environments (Node.js, browser, edge, etc.)
Properties
name
readonlyname:string
Defined in: packages/core/src/types.ts:19
The name of the crypto plugin (e.g., 'node', 'web', 'js')
Methods
constantTimeEqual()
constantTimeEqual(
a,b):boolean
Defined in: packages/core/src/types.ts:54
Constant-time comparison to prevent timing side-channel attacks
Compares two values in a way that takes constant time regardless of whether they match or differ. This prevents timing attacks where an attacker could determine the secret by measuring comparison time.
Parameters
a
First value to compare (string or Uint8Array)
string | Uint8Array<ArrayBufferLike>
b
Second value to compare (string or Uint8Array)
string | Uint8Array<ArrayBufferLike>
Returns
boolean
true if values are equal, false otherwise
hmac()
hmac(
algorithm,key,data):Uint8Array<ArrayBufferLike> |Promise<Uint8Array<ArrayBufferLike>>
Defined in: packages/core/src/types.ts:29
Compute HMAC using the specified hash algorithm
Parameters
algorithm
The hash algorithm to use
key
Uint8Array
The secret key as a byte array
data
Uint8Array
The data to authenticate as a byte array
Returns
Uint8Array<ArrayBufferLike> | Promise<Uint8Array<ArrayBufferLike>>
HMAC digest as a byte array
randomBytes()
randomBytes(
length):Uint8Array
Defined in: packages/core/src/types.ts:41
Generate cryptographically secure random bytes
Parameters
length
number
Number of random bytes to generate
Returns
Uint8Array
Random bytes