Skip to content

otplib API Documentation / @otplib/plugin-base32-alt / createBase32Plugin

Function: createBase32Plugin()

createBase32Plugin(options): Base32Plugin

Defined in: core/src/plugin-factories.ts:80

Create a custom Base32 plugin from encode/decode functions

Use this factory to create plugins that bypass Base32 encoding or implement custom secret transformations.

Parameters

options

CreateBase32PluginOptions

Returns

Base32Plugin

Example

ts
import { createBase32Plugin, stringToBytes, bytesToString } from '@otplib/core';

// UTF-8 string bypass (no Base32)
const bypassAsString = createBase32Plugin({
  name: 'bypass-as-string',
  encode: bytesToString,
  decode: stringToBytes,
});

// Base64 bypass
const base64Bypass = createBase32Plugin({
  name: 'base64-bypass',
  encode: (data) => btoa(String.fromCharCode(...data)),
  decode: (str) => new Uint8Array([...atob(str)].map(c => c.charCodeAt(0))),
});

Released under the MIT License.