/** * File-based key store implementation compatible with NEAR CLI. */ import type { KeyPair, KeyStore } from "../core/types.js"; import { type Network } from "./credential-schemas.js"; /** * File-based key store compatible with NEAR CLI format. * * This keystore is fully compatible with the NEAR CLI credential format, * storing keys in `~/.near-credentials/` with network subdirectories. * * ## Directory Structure * ``` * ~/.near-credentials/ * ├── mainnet/ * │ └── account.near.json * ├── testnet/ * │ ├── account.testnet.json * │ └── account.testnet/ # Multi-key format (read-only) * │ └── ed25519_PublicKey.json * └── implicit/ * └── accountId.json * ``` * * ## Features * - Compatible with near-cli and near-cli-rs * - Supports network subdirectories (mainnet, testnet, etc.) * - Reads multi-key format (account.near/ed25519_*.json) * - Writes simple format (account.near.json) * - Preserves optional seed phrase fields * * @example * ```typescript * // Default: ~/.near-credentials/testnet/ * const keyStore = new FileKeyStore("~/.near-credentials", "testnet") * * // Custom path * const keyStore = new FileKeyStore("/path/to/keys", "mainnet") * * // Add a key * await keyStore.add("example.testnet", keyPair) * ``` */ export declare class FileKeyStore implements KeyStore { private readonly basePath; private readonly network; /** * Create a new file-based keystore. * * @param basePath - Base directory path (default: `"~/.near-credentials"`). * @param network - Network subdirectory (e.g., `"testnet"`, `"mainnet"`). * * @example * ```typescript * // Store in ~/.near-credentials/testnet/ * const keyStore = new FileKeyStore("~/.near-credentials", "testnet") * * // Store in custom directory without network subdirectory * const keyStore = new FileKeyStore("/my/keys") * ``` */ constructor(basePath?: string, network?: Network); /** * Get the directory path for storing keys. * Includes network subdirectory if specified. * @internal */ private getNetworkPath; /** * Get the file path for a specific account. * Uses simple format: `{network}/{accountId}.json`. * @internal */ private getKeyFilePath; /** * Get the multi-key directory path for an account. * Format: `{network}/{accountId}/`. * @internal */ private getMultiKeyDirPath; /** * Add a key to the keystore * * Stores in NEAR CLI format with network subdirectory. * Uses simple format (one file per account). * * @param accountId - NEAR account ID * @param key - Key pair to store * @param options - Optional metadata (seed phrase, derivation path) */ add(accountId: string, key: KeyPair, options?: { seedPhrase?: string; derivationPath?: string; implicitAccountId?: string; }): Promise; /** * Get a key from the keystore * * Attempts to read in this order: * 1. Simple format: {network}/{accountId}.json * 2. Multi-key format: {network}/{accountId}/ed25519_*.json (first match) * * @param accountId - NEAR account ID * @returns Key pair if found, null otherwise */ get(accountId: string): Promise; /** * Try to read from multi-key directory format. * Format: `{network}/{accountId}/ed25519_*.json`. * @internal */ private getFromMultiKeyDir; /** * Remove a key from the keystore * * Removes both simple format file and multi-key directory if they exist * * @param accountId - NEAR account ID */ remove(accountId: string): Promise; /** * List all account IDs in the keystore * * Returns account IDs from both simple format files and multi-key directories * * @returns Array of account IDs */ list(): Promise; } //# sourceMappingURL=file-keystore.d.ts.map