Skip to content
Docs

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)
FieldRequiredDescription
addressYes`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)
FieldRequiredDescription
privateKeyYes`"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 applicable

validateAddress / isValidAddress / assertValidAddress

js
validateAddress({ chainId, address })
isValidAddress({ chainId, address })
assertValidAddress({ chainId, address })
normalizeAddress({ chainId, address })
FieldRequiredDescription
chainIdYes`GrayChainId`
addressYes`string`
ts
// validateAddress
{ valid: true, normalized?: string }
{ valid: false, message: string }

// isValidAddress → boolean
// assertValidAddress → string (normalized) or throws invalid_argument
// normalizeAddress → string | undefined

Mnemonic helpers

js
generateMnemonic(strength?)     // default 128 → 12 words
validateMnemonic(mnemonic)       // → boolean
mnemonicToSeed(mnemonic, bip39Passphrase?)  // → Uint8Array (64 bytes)
FieldRequiredDescription
strengthNo`128 | 160 | 192 | 224 | 256` — entropy for generateMnemonic
bip39PassphraseNo`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

FieldRequiredDescription
invalid_argumentNo`assertValidAddress` when invalid; `mnemonicToSeed` when mnemonic invalid.