import { AztecClientBackend, Barretenberg } from '@aztec/bb.js'; import { createLogger } from '@aztec/foundation/log'; import { MockAppCreatorCircuit, MockHidingCircuit, MockPrivateKernelInitCircuit, MockPrivateKernelTailCircuit, generateTestingIVCStack, } from './witgen.js'; const logger = createLogger('aztec:ivc-test'); /* eslint-disable no-console */ // Expose APIs on window for browser testing (window as any).Barretenberg = Barretenberg; (window as any).AztecClientBackend = AztecClientBackend; (window as any).generateTestingIVCStack = generateTestingIVCStack; (window as any).MockAppCreatorCircuit = MockAppCreatorCircuit; (window as any).MockPrivateKernelInitCircuit = MockPrivateKernelInitCircuit; (window as any).MockPrivateKernelTailCircuit = MockPrivateKernelTailCircuit; (window as any).MockHidingCircuit = MockHidingCircuit; // Function to set up the output element and redirect all console output function setupConsoleOutput() { const container = document.createElement('div'); container.style.marginBottom = '10px'; document.body.appendChild(container); const copyButton = document.createElement('button'); copyButton.innerText = 'Copy Logs to Clipboard'; copyButton.style.marginBottom = '10px'; copyButton.addEventListener('click', () => { const logContent = logContainer.textContent || ''; // Get text content of log container navigator.clipboard .writeText(logContent) .then(() => { alert('Logs copied to clipboard!'); }) .catch(err => { console.error('Failed to copy logs:', err); }); }); container.appendChild(copyButton); const logContainer = document.createElement('pre'); logContainer.id = 'logOutput'; logContainer.style.border = '1px solid #ccc'; logContainer.style.padding = '10px'; logContainer.style.maxHeight = '400px'; logContainer.style.overflowY = 'auto'; container.appendChild(logContainer); // Helper to append messages to logContainer function addLogMessage(message: string) { logContainer.textContent += message + '\n'; logContainer.scrollTop = logContainer.scrollHeight; // Auto-scroll to the bottom } // Override console methods to output clean logs const originalLog = console.log; const originalDebug = console.debug; console.log = (...args: any[]) => { const message = args .map(arg => typeof arg === 'string' ? arg .replace(/%c/g, '') .replace(/color:.*?(;|$)/g, '') .trim() : arg, ) .join(' '); originalLog.apply(console, args); // Keep original behavior addLogMessage(message); }; console.debug = (...args: any[]) => { const message = args .map(arg => typeof arg === 'string' ? arg .replace(/%c/g, '') .replace(/color:.*?(;|$)/g, '') .trim() : arg, ) .join(' '); originalDebug.apply(console, args); // Keep original behavior addLogMessage(message); }; } // Only set up the interactive UI if this is not being used for automated testing if (!document.getElementById('status')) { document.addEventListener('DOMContentLoaded', function () { setupConsoleOutput(); // Initialize console output capture const button = document.createElement('button'); button.innerText = 'Run Test'; // eslint-disable-next-line @typescript-eslint/no-misused-promises button.addEventListener('click', async () => { logger.info(`generating circuit and witness...`); const [bytecodes, witnessStack, _publicInputs, precomputedVks] = await generateTestingIVCStack(1, 0); logger.info(`done. proving and verifying...`); const barretenberg = await Barretenberg.initSingleton({ threads: 16, logger: (m: string) => logger.info(m), }); const backend = new AztecClientBackend(bytecodes, barretenberg); const { proof, vk } = await backend.prove(witnessStack, precomputedVks); const verified = await backend.verify(proof, vk); logger.info(`verified? ${verified}`); await Barretenberg.destroySingleton(); }); document.body.appendChild(button); }); }