Client: accounts and chains
Validate and detect addresses
Detect paste formats, validate per chainId, and generate or check BIP-39 phrases.
Overview
Free functions (also scoped on client.detectAddress / detectPrivateKey to the client allowlist) help paste UX and import flows.
detectAddress
js
detectAddress(address)
client.detectAddress(address)| Field | Required | Description |
|---|---|---|
| address | Yes | `string` — pasted address (any family). |
ts
type DetectAddressResult = {
address: string;
normalized?: string;
matches: Array<{
family: ChainFamily;
chainIds: GrayChainId[]; // preferred chain is [0]
}>;
};An empty matches array means the format is unknown. Preferred family is matches[0].
detectPrivateKey
js
detectPrivateKey(privateKey)| Field | Required | Description |
|---|---|---|
| privateKey | Yes | `"0x"` + 64 hex (32 bytes). |
ts
{
candidates: Array<{
family: ChainFamily;
chainIds: GrayChainId[];
address: string; // derived — show so the user picks
}>;
}
// Invalid length → { candidates: [] }
// Includes family: "monero" when applicablevalidateAddress / isValidAddress / assertValidAddress
js
validateAddress({ chainId, address })
isValidAddress({ chainId, address })
assertValidAddress({ chainId, address })
normalizeAddress({ chainId, address })| Field | Required | Description |
|---|---|---|
| chainId | Yes | `GrayChainId` |
| address | Yes | `string` |
ts
// validateAddress
{ valid: true, normalized?: string }
{ valid: false, message: string }
// isValidAddress → boolean
// assertValidAddress → string (normalized) or throws invalid_argument
// normalizeAddress → string | undefinedMnemonic helpers
js
generateMnemonic(strength?) // default 128 → 12 words
validateMnemonic(mnemonic) // → boolean
mnemonicToSeed(mnemonic, bip39Passphrase?) // → Uint8Array (64 bytes)| Field | Required | Description |
|---|---|---|
| strength | No | `128 | 160 | 192 | 224 | 256` — entropy for generateMnemonic |
| bip39Passphrase | No | `string` — optional; passed to `mnemonicToSeed` |
Usage
js
const d = detectAddress(input);
const m = d.matches[0];
if (!m) { /* unknown */ }
else if (m.family === "monero") { /* import + sync, do not watch */ }
else {
await client.wallets.watch({
address: d.normalized ?? d.address,
family: m.family,
...(m.family !== "evm" ? { chainId: m.chainIds[0] } : {}),
});
}
const v = validateAddress({ chainId: "bitcoin", address: "bc1q…" });
assertValidAddress({ chainId: "ethereum", address: "0x…" });Throws
| Field | Required | Description |
|---|---|---|
| invalid_argument | No | `assertValidAddress` when invalid; `mnemonicToSeed` when mnemonic invalid. |