/**
 * Private Key Wallet Adapter
 *
 * **Development only.** Do not use in production — the private key is held
 * in memory for the lifetime of the adapter.
 *
 * Useful for:
 * - Testing and integration tests
 * - Backend/server-side applications
 * - Scripting and automation
 */
import { createWalletClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
export class PrivateKeyWalletAdapter {
    id = 'private-key';
    privateKey;
    rpcUrl;
    customChain;
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    walletClient;
    constructor(config) {
        if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'production') {
            console.warn('[PrivacyBoost] PrivateKeyWalletAdapter is intended for development/testing only. Do not use in production.'); // eslint-disable-line no-console
        }
        this.privateKey = config.privateKey;
        this.rpcUrl = config.rpcUrl;
        this.customChain = config.chain;
    }
    async connect(args) {
        const account = privateKeyToAccount(this.privateKey);
        const rpcUrl = args.rpcUrl || this.rpcUrl;
        const response = await fetch(rpcUrl, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'eth_chainId', params: [] }),
        });
        const data = await response.json();
        const chainId = parseInt(data.result, 16);
        if (args.expectedChainId && chainId !== args.expectedChainId) {
            throw new Error(`Chain ID mismatch: expected ${args.expectedChainId}, got ${chainId}`);
        }
        const chain = this.customChain || {
            id: chainId,
            name: 'Network',
            nativeCurrency: { name: 'ETH', symbol: 'ETH', decimals: 18 },
            rpcUrls: { default: { http: [rpcUrl] }, public: { http: [rpcUrl] } },
        };
        this.walletClient = createWalletClient({ account, chain, transport: http(rpcUrl) });
        return { walletClient: this.walletClient, address: account.address, chainId };
    }
    disconnect() {
        this.walletClient = undefined;
    }
}
//# sourceMappingURL=PrivateKeyWalletAdapter.js.map