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
| Field | Required | Description |
|---|---|---|
| mnemonic | Yes | `string` — BIP-39 phrase. |
| options.password | No | `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
| Field | Required | Description |
|---|---|---|
| privateKey | Yes | `"0x"` + 64 hex. |
| options.family | No | `ChainFamily` — optional; omit to scan all families on this client. |
| options.chainId | No | `GrayChainId` — optional scope when family is set / non-EVM. |
| options.password | No | `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
| Field | Required | Description |
|---|---|---|
| query | Yes | `string` — full address or prefix (UI search). |
| options.family | No | `ChainFamily` — optional filter. |
| options.chainId | No | `GrayChainId` — optional filter. |
| options.mode | No | `"prefix"` (default) | `"exact"` — match mode. |
| options.password | No | `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
| Field | Required | Description |
|---|---|---|
| conflict | No | Automatic on import/watch/keystore when policy blocks the duplicate (not thrown by find* — those return arrays). |
| unauthorized | No | Encrypted storage — bad or missing PIN while scanning. |
| invalid_argument | No | Malformed 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”.