Skip to content
GitHub

Address helpers

Testnet

This page documents only exports exercised against the exact published package @monolythium/[email protected]. The repository test gate type-checks and runs the deterministic examples.

Monolythium address payloads are 20 bytes. User-facing strings use typed bech32m HRPs: mono for a user, monos for a smart account, monoc for a contract, monok for a cluster, monom for a multisig, and monox for a system module.

import {
addressToBech32,
addressToTypedBech32,
bech32ToAddress,
bech32ToAddressBytes,
} from "@monolythium/core-sdk";
const payload = new Uint8Array(20);
const user = addressToBech32(payload); // mono1…
const contract = addressToTypedBech32("contract", payload); // monoc1…
const hex = bech32ToAddress(user); // 0x + 40 lowercase hex digits
const roundTrip = bech32ToAddressBytes(user); // Uint8Array(20)

bech32ToAddress returns a hexadecimal string; use bech32ToAddressBytes when bytes are required. Older examples that claimed bech32ToAddress returned bytes are incorrect for 0.6.8.

import { validateAddress } from "@monolythium/core-sdk";
const result = validateAddress("mono1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxq7cge");
if (!result.valid) throw new Error(result.reason);
console.log(result.kind); // "user"
console.log(result.normalized);

For a required address role, use typedBech32ToAddress(address, expectedKind) or requireTypedAddress(address, expectedKind). Both are real 0.6.8 exports and reject a valid address carrying the wrong typed HRP.

The crypto subpath returns the derived 20-byte address as hexadecimal. Convert it explicitly for display:

import { addressToBech32 } from "@monolythium/core-sdk";
import { generateMnemonic, mnemonicToAddress } from "@monolythium/core-sdk/crypto";
const mnemonic = generateMnemonic();
const addressHex = mnemonicToAddress(mnemonic);
const display = addressToBech32(addressHex);

Generating a mnemonic inside an application creates custody responsibility. Do not use this example for an agent, hosted service, or website login. Wallet authentication does not reveal or transfer the mnemonic.

isReservedHrp, fromCanonicalPubkey, InvalidChecksumError, WrongHrpError, and ReservedHrpError are not root exports of @monolythium/[email protected]. Do not copy examples that import them.