Skip to content

otplib API Documentation / @otplib/core / / Base32Context

Class: Base32Context ​

Defined in: packages/core/src/base32-context.ts:12

Base32Context provides a unified interface for Base32 operations using a pluggable Base32 backend.

All errors from the underlying plugin are wrapped in otplib error types with the original error preserved via the cause property.

Constructors ​

Constructor ​

new Base32Context(base32): Base32Context

Defined in: packages/core/src/base32-context.ts:18

Create a new Base32Context with the given Base32 plugin

Parameters ​

base32 ​

Base32Plugin

The Base32 plugin to use

Returns ​

Base32Context

Accessors ​

plugin ​

Get Signature ​

get plugin(): Base32Plugin

Defined in: packages/core/src/base32-context.ts:23

Get the underlying Base32 plugin

Returns ​

Base32Plugin

Methods ​

decode() ​

decode(str): Uint8Array

Defined in: packages/core/src/base32-context.ts:51

Decode Base32 string to binary data using the configured plugin

Parameters ​

str ​

string

Base32 string to decode

Returns ​

Uint8Array

Decoded Uint8Array

Throws ​

If string contains invalid characters or decoding fails


encode() ​

encode(data, options?): string

Defined in: packages/core/src/base32-context.ts:35

Encode binary data to Base32 string using the configured plugin

Parameters ​

data ​

Uint8Array

Uint8Array to encode

options? ​

Base32EncodeOptions

Encoding options

Returns ​

string

Base32 encoded string

Throws ​

If encoding fails

Released under the MIT License.