Address validation
The call
import { getChain, InvalidAddressError } from "@agntn/chains";
const bitcoin = getChain("btc");
bitcoin.validatesAddress; // true
bitcoin.assertAddress("bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4"); // returns the address
try {
bitcoin.assertAddress("bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5");
} catch (error) {
error instanceof InvalidAddressError; // true, the checksum caught the last digit
(error as InvalidAddressError).chain; // "bitcoin"
}
chain.assertAddress(address) returns the address when it fits the chain's format and throws InvalidAddressError when it doesn't. Chains without a validator throw AddressValidationUnsupportedError instead of quietly saying yes, and chain.validatesAddress tells you which ones those are before you ask. Right now every built-in chain validates. A false green light costs more than a false alarm when the caller is about to send funds.
The library doesn't trim. assertAddress(" bc1q…") fails on the space. The CLI's validate passes the argument through as typed too. The agent tools do trim, because an address lifted out of a log line keeps its trailing newline and one invisible byte should not turn a good address into a bad one.
Why decode
Character counts aren't enough. A 34-character window takes a Bitcoin legacy address and a TRON address, both 25 bytes of Base58Check under different version bytes. Solana's System Program is 32 characters and 32 bytes, a Bitcoin address is 34 characters and 25 bytes. So the base58 validators decode and look at the bytes. The Bech32 validators run the polymod. And Octra is the one base58 chain where decoding would be wrong: a contract address there is cut out of a base58 string rather than encoded from a payload, so the width is the whole format.
What each family checks
| Chain | Accepted forms | Verified | Left alone |
|---|---|---|---|
| EVM, thirteen chains | 0x and 40 hex digits, any case | shape | EIP-55 checksum |
| Bitcoin | legacy 1… 3…, Bech32 bc1q…, Bech32m bc1p… | 25 Base58Check bytes under 0x00 or 0x05; the full BIP-173/350 encoding, witness version, program length, padding, checksum | legacy checksum |
| Litecoin | legacy L… M…, ltc1… | same as Bitcoin under versions 0x30 and 0x32 and the ltc prefix | legacy checksum; deprecated 3… script version is out |
| Pepecoin | P…, 9…, A… | 25 bytes under 0x38 or 0x16 | checksum; no Bech32 at all |
| eCash | CashAddr with or without ecash: | the CashAddr checksum, version 0x00 or 0x08, 20-byte hash, zero padding | nothing; a bare Bitcoin Cash address fails on the checksum |
| Cardano | Shelley addr1…, stake1…, Byron Ae2… DdzFF… | Bech32 checksum past BIP-173's 90 characters, CIP-19 header, mainnet tag, payload length, pointer coordinates | Byron CRC and network |
| Decred | Ds De DS Dc, Dk | 26-byte hash forms, 39-byte public key form with its selector | BLAKE-256 checksum, curve points |
| Solana | base58 | exactly 32 decoded bytes | nothing else exists to check |
| Stellar | SEP-23 Strkey G… M… C… | canonical base32, version byte, CRC16-XModem | account existence |
| XRP Ledger | classic r…, X-address X… | the ledger's own base58 alphabet, version 0x00, X-address prefix, flag and reserved bytes | checksum |
| Aptos, Sui | 64 hex digits or the single digit AIP-40 short form | shape | nothing else |
| TON | TEP-2 friendly, either base64 alphabet | 36 bytes, tag 0x11 or 0x51, workchain 0x00 or 0xff | CRC16; the raw workchain:hex form isn't accepted |
| TRON | T… | 25 bytes under 0x41 | checksum |
| Octra | oct and 44 base58 characters | the width and the alphabet | everything else, on purpose |
| Arweave | 43 base64url characters | zero unused bits in the last digit | the optional :checksum suffix is rejected |
| Monero | standard 4…, subaddress 8…, integrated 4… | base58 block bounds, mainnet type byte, 95 or 106 characters | Keccak checksum, curve points; testnet and stagenet are rejected |
Mixed case fails on every Bech32 and CashAddr chain, all upper or all lower passes, as the specs say. Testnet forms are rejected everywhere the format can tell: Bitcoin's version bytes, TON's testnet flag, Monero's network byte, XRP's testnet X-address prefix. Cardano's Byron form is the one exception, its network hides in an attribute the check doesn't open.
Move addresses and EVM addresses
Aptos and Sui want all 32 bytes of hex written out, or the single digit short form AIP-40 defines for the special addresses, which is how the framework address 0x1 is actually written. Anything in between stays rejected. Accepting dropped leading zeros would make every EVM address a valid Move address too, and identify would report a family nobody asked about.
Where this stops
None of this touches a network. Not existence, not balances, not whether a contract sits at the address. That belongs in @agntn/nodes, and the Playground says the same thing under every green result.
Registry and aliases
Keys and display names plus the aliases people actually type. All land on the same class. How the registry is seeded and why nothing registers itself.
Identify
One address of unknown origin through every registered validator. Which chains accept the format and which couldn't be asked. What a match doesn't mean.