Skip to content
Docs

Client: wallets

Duplicate detection

findMnemonic / findPrivateKey return arrays; findAddress supports prefix search.

Overview

Use find helpers before import—or rely on automatic conflict throws. Policy is set at GrayClient.create({ duplicates }): "strict" (default), "address", or "none".

TypeScript reality: findMnemonic and findPrivateKey return WalletDuplicate[] (empty if none). findAddress returns AddressMatch[] (prefix search by default).

findMnemonic

Signature

js
await client.wallets.findMnemonic(mnemonic, options?)

Parameters

FieldRequiredDescription
mnemonicYes`string` — BIP-39 phrase.
options.passwordNo`string` — when encrypted storage must be unlocked to scan.

Response

Promise<WalletDuplicate[]> — [] if none. Exact match (normalized whitespace/case).

ts
type WalletDuplicate = {
  id: string;
  label: string;
  kind: "mnemonic" | "private_key" | "watch";
  chains: GrayChainId[]; // empty for mnemonic-only match
};

findPrivateKey

Signature

js
await client.wallets.findPrivateKey(privateKey, options?)

Parameters

FieldRequiredDescription
privateKeyYes`"0x"` + 64 hex.
options.familyNo`ChainFamily` — optional; omit to scan all families on this client.
options.chainIdNo`GrayChainId` — optional scope when family is set / non-EVM.
options.passwordNo`string` — encrypted storage PIN.

Response

Promise<WalletDuplicate[]> — derives addresses then matches stored receive rows (seed / PK / watch / keystore).

findAddress

Signature

js
await client.wallets.findAddress(query, options?)

Parameters

FieldRequiredDescription
queryYes`string` — full address or prefix (UI search).
options.familyNo`ChainFamily` — optional filter.
options.chainIdNo`GrayChainId` — optional filter.
options.modeNo`"prefix"` (default) | `"exact"` — match mode.
options.passwordNo`string` — encrypted storage PIN.

Response

Promise<AddressMatch[]>

ts
type AddressMatch = {
  id: string;
  label: string;
  kind: "mnemonic" | "private_key" | "watch";
  chainId: GrayChainId;
  address: string; // stored receive address that matched
};

Usage

js
const hits = await client.wallets.findMnemonic(mnemonic, { password: pin });
if (hits.length) {
  // hits[0].id, hits[0].label, hits[0].chains
}

const pkHits = await client.wallets.findPrivateKey(pk, {
  family: "evm",
  password: pin,
});

const addrHits = await client.wallets.findAddress("0xsd", { password: pin });
// prefix autocomplete across stored addresses

// Import still throws under strict / address policies:
// GrayError code "conflict"
await client.wallets.importPrivateKey({ privateKey: pk, family: "evm", password: pin });
await client.wallets.importMnemonic({ mnemonic, password: pin });
await client.wallets.watch({ address, family: "evm", password: pin });
await client.wallets.importEvmKeystore({ json, password: filePin, storagePassword: pin });

Throws

FieldRequiredDescription
conflictNoAutomatic on import/watch/keystore when policy blocks the duplicate (not thrown by find* — those return arrays).
unauthorizedNoEncrypted storage — bad or missing PIN while scanning.
invalid_argumentNoMalformed private key / empty query where required.

create() never runs a mnemonic duplicate check—call findMnemonic if the UI lets users paste a phrase into “create”.