import { EvmWalletProvider } from '@coinbase/agentkit'; import { getAddress, isAddress } from 'viem'; import { BriefError } from './brief-core.js'; /** * Minimal local-signing AgentKit EVM wallet for this example. * The native wallet interface is used; only typed-data signing is enabled. * signerFactory is invoked only when the guarded action calls signTypedData. */ export class LazyBriefWalletProvider extends EvmWalletProvider { #payer; #factory; constructor({ address, signerFactory } = {}) { super(); if (typeof address !== 'string' || !isAddress(address, { strict: false }) || /^0x0{40}$/i.test(address) || typeof signerFactory !== 'function') { throw new BriefError('INVALID_WALLET_CONFIGURATION'); } this.#payer = getAddress(address); this.#factory = signerFactory; } getAddress() { return this.#payer; } getNetwork() { return { protocolFamily: 'evm', chainId: '8453', networkId: 'base-mainnet' }; } getName() { return 'blockchainiq_lazy_local_wallet'; } // WalletProvider's constructor calls this virtual hook on the next tick. // The published SDK default sends an unawaited analytics POST. Override the // hook in our own subclass so this minimal example has no telemetry request. trackInitialization() {} async signTypedData(input) { const signer = this.#factory(); if (!signer || typeof signer.signTypedData !== 'function' || typeof signer.address !== 'string' || signer.address.toLowerCase() !== this.#payer.toLowerCase()) { throw new BriefError('SIGNER_PAYER_MISMATCH'); } return signer.signTypedData(input); } sign() { throw new BriefError('UNSUPPORTED_WALLET_OPERATION'); } signMessage() { throw new BriefError('UNSUPPORTED_WALLET_OPERATION'); } signTransaction() { throw new BriefError('UNSUPPORTED_WALLET_OPERATION'); } sendTransaction() { throw new BriefError('UNSUPPORTED_WALLET_OPERATION'); } waitForTransactionReceipt() { throw new BriefError('UNSUPPORTED_WALLET_OPERATION'); } readContract() { throw new BriefError('UNSUPPORTED_WALLET_OPERATION'); } getPublicClient() { throw new BriefError('UNSUPPORTED_WALLET_OPERATION'); } getBalance() { throw new BriefError('UNSUPPORTED_WALLET_OPERATION'); } nativeTransfer() { throw new BriefError('UNSUPPORTED_WALLET_OPERATION'); } }