bech32

local bech32 = require 'bech32'

This module exposes a bech32 codec. The implementation is based on the original C++ reference implementation, but changes were made to fill user-provided buffers (instead of relying on memory allocators). The new interface is friendlier to botan.secure_byte_span.

Usually it’s not important use secure allocators for bech32 as it’s mostly used to encode public keys. However that’s not always the case (e.g. nostr’s nsec1…​ addresses). Even if you do use bech32 to encode secrets, it still doesn’t warrant an excuse to use secure allocators. Nonetheless this module will always — except for the human-readable part — avoid allocations as a way to be useful even for those few who need it. If you need to hold bech32 data exclusively through secure allocations (except for the human-readable part[1]), you can use this module.


1. Memory allocations might still happen to hold the lower-case version of the human-readable part. However even the source code for your program already holds the expected human-readable part of a bech32 address. In a way, your program is already “leaking” the human-readable part. It’s not a safe pattern to depend on the secrecy of the human-readable part of bech32 addresses.