@varnir/network-codes
v0.1.0
Published
Zero-dependency network-code mapper (toCanonical / toLedgerCode / toRegistryNetworkKey) shared across the monorepo. Compiled to CommonJS with declarations so node10/CommonJS services (minigate, l1-relay) can require() the same source of truth the bundler
Readme
@varnir/network-codes
A zero-dependency mapper between the network-name spellings a Varnir chain can show up as: the ledger's own credit code, the code services use in config and pool lookups, and the ad-hoc provider chain ids seen on the wire. No custody or signing logic lives here — it does not touch keys, it just keeps one chain from being silently treated as another.
Why this exists
The same chain gets spelled differently depending on where you look:
'tBNB' at rest on the ledger, 'tbnb' in pool/config code, 'bnbchain-testnet'
from a provider, and stray variants like 'trx-niles' seen in the wild. Four
conventions for the same set of chains means a naive toLowerCase() compare
or a locally-grown alias list can silently fold two different networks
together — or fail to fold the same network to itself — and a deposit or
lookup for the wrong chain goes missing without an error. This package is
the single place that mapping lives, so every consumer folds through it
instead of re-deriving its own (and drifting).
Install
npm install @varnir/network-codesUsage
import {toCanonical, toLedgerCode, toRegistryNetworkKey} from '@varnir/network-codes';
toCanonical('bnbchain-testnet'); // 'tbnb' — lower-case, for display/compare
toLedgerCode('tbnb'); // 'tBNB' — the mixed-case form stored at rest
toRegistryNetworkKey('tbnb'); // 'TBNB' — upper-case, for registry-keyed lookupsThree functions, three different output forms — pick the one that matches where the result is going, not the one that looks closest to your input:
toCanonical— folds any spelling to the lower-case display/compare form ('niles','tbnb','sep'). Use this for reads, comparisons, and anywhere a pool or config keys on network name.toLedgerCode— folds to the code a chain is stored under at rest, exactly as configured (including mixed case, e.g.'tBNB').toRegistryNetworkKey— folds to the upper-case form a raw, case-sensitive registry key is seeded with. Not interchangeable withtoLedgerCode: some registries are seeded upper-case even when the ledger code itself is mixed-case.
An unrecognised spelling degrades to a trimmed pass-through (lower-cased for
toCanonical, upper-cased for the other two) rather than throwing, matching
the lenient behavior of the ad-hoc folds this package replaces.
Covers the full network set a Varnir token registry can name: Ethereum (mainnet/Sepolia), Tron (mainnet/Nile/Shasta), BNB Chain (mainnet/testnet), and Solana (mainnet/devnet).
Pure TypeScript, no runtime dependencies, and no Node/browser-specific APIs
— safe to import from a browser bundle, React Native, or a plain Node
script. Ships as compiled CommonJS with type declarations so require()-based
services can consume the same source of truth as bundler and React Native
consumers, with no drift between copies.
License
MIT
