import { Client, AccountId, TransactionId, TopicCreateTransaction } from '@hashgraph/sdk'; import { getCurrentWallet } from './wallet-context'; export type Network = 'mainnet' | 'testnet'; export async function startHCSOperationViaLocalBuilder( op: string, request: Record, network: Network ): Promise<{ transactionBytes: string }> { switch (op) { case 'hcs2.createRegistry': { return await buildHCS2CreateRegistryBytes(request, network); } case 'hcs2.migrateRegistry': { // For now, treat migrate as a topic creation to bootstrap the target topic; the agent can finalize with follow-up messages return await buildHCS2CreateRegistryBytes(request, network); } default: { throw new Error(`startHCSOperation unsupported op: ${op}`); } } } async function buildHCS2CreateRegistryBytes( request: Record, network: Network ): Promise<{ transactionBytes: string }> { const wallet = getCurrentWallet(); if (!wallet || !wallet.accountId || wallet.network !== network) { throw new Error('wallet_unavailable: no connected wallet or network mismatch'); } // Minimal topic create for HCS-2 registry const client = network === 'mainnet' ? Client.forMainnet() : Client.forTestnet(); const payer = AccountId.fromString(wallet.accountId); const tx = new TopicCreateTransaction() .setTransactionId(TransactionId.generate(payer)) .setTopicMemo('HCS-2 Registry'); const frozen = await tx.freezeWith(client); const bytes = Buffer.from(frozen.toBytes()); return { transactionBytes: bytes.toString('base64') }; }