From b7bd19b7e695579edcec0e45b26b9ce48c8d080f Mon Sep 17 00:00:00 2001 From: Alexey Shchur Date: Wed, 25 Mar 2026 09:48:26 +0200 Subject: [PATCH] cbore: docs: cleanup unused sol example --- .../docs-snippets/remix/EncryptedCounter.sol | 38 ----- .../remix/open-encrypted-counter.mjs | 151 ------------------ 2 files changed, 189 deletions(-) delete mode 100644 examples/docs-snippets/remix/EncryptedCounter.sol delete mode 100644 examples/docs-snippets/remix/open-encrypted-counter.mjs diff --git a/examples/docs-snippets/remix/EncryptedCounter.sol b/examples/docs-snippets/remix/EncryptedCounter.sol deleted file mode 100644 index 37490c8b..00000000 --- a/examples/docs-snippets/remix/EncryptedCounter.sol +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -// [!region docs-snippet] -pragma solidity ^0.8.28; - -// Remix-friendly import: pulls the CoFHE contracts from npm CDN. -// Remix can resolve nested imports (including @openzeppelin) when fetching remote sources. -import 'https://unpkg.com/@fhenixprotocol/cofhe-contracts@0.1.0/FHE.sol'; - -/// @title EncryptedCounter -/// @notice Minimal encrypted counter used for docs + runnable examples. -/// @dev Calls `FHE.allowPublic` so the encrypted value can be decrypted by anyone. -/// Use this pattern only for demo/public data. -contract EncryptedCounter { - euint32 private _value; - - constructor(uint32 initialValue) { - _value = FHE.asEuint32(initialValue); - _allow(_value); - } - - /// @notice Returns an encrypted handle (ctHash) for `_value`. - function getValue() external view returns (euint32) { - return _value; - } - - function increment() external { - _value = FHE.add(_value, FHE.asEuint32(1)); - _allow(_value); - } - - function _allow(euint32 v) internal { - FHE.allowThis(v); - FHE.allowSender(v); - FHE.allowPublic(v); - } -} -// [!endregion docs-snippet] diff --git a/examples/docs-snippets/remix/open-encrypted-counter.mjs b/examples/docs-snippets/remix/open-encrypted-counter.mjs deleted file mode 100644 index 6e20ff86..00000000 --- a/examples/docs-snippets/remix/open-encrypted-counter.mjs +++ /dev/null @@ -1,151 +0,0 @@ -import { spawnSync } from 'node:child_process'; -import { createServer } from 'node:http'; -import { readFileSync } from 'node:fs'; -import { resolve } from 'node:path'; -import { fileURLToPath } from 'node:url'; - -function execOrNull(cmd, args) { - const result = spawnSync(cmd, args, { encoding: 'utf8' }); - if (result.status !== 0) return null; - return (result.stdout || '').trim() || null; -} - -function parseGitHubRemote(remoteUrl) { - if (!remoteUrl) return null; - // git@github.com:Owner/Repo.git - const sshMatch = remoteUrl.match(/^git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?$/); - if (sshMatch) return { owner: sshMatch[1], repo: sshMatch[2] }; - - // https://github.com/Owner/Repo.git - const httpsMatch = remoteUrl.match(/^https:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?$/); - if (httpsMatch) return { owner: httpsMatch[1], repo: httpsMatch[2] }; - - return null; -} - -function openUrl(url) { - const platform = process.platform; - if (platform === 'darwin') return spawnSync('open', [url], { stdio: 'inherit' }); - if (platform === 'win32') return spawnSync('cmd', ['/c', 'start', '', url], { stdio: 'inherit' }); - return spawnSync('xdg-open', [url], { stdio: 'inherit' }); -} - -const here = resolve(fileURLToPath(new URL('.', import.meta.url))); -const repoRoot = resolve(here, '../../../'); - -const contractFilePath = resolve(repoRoot, 'examples/docs-snippets/remix/EncryptedCounter.sol'); - -const args = process.argv.slice(2).filter((a) => a !== '--'); -const printOnly = args.includes('--print'); -const useLocal = args.includes('--local'); -const portArgIndex = args.indexOf('--port'); -const portArg = portArgIndex >= 0 ? args[portArgIndex + 1] : null; -const refArgIndex = args.indexOf('--ref'); -const refArg = refArgIndex >= 0 ? args[refArgIndex + 1] : null; - -function startLocalServer() { - const content = readFileSync(contractFilePath, 'utf8'); - const preferredPort = portArg ? Number(portArg) : 0; - if (portArg && (!Number.isFinite(preferredPort) || preferredPort <= 0 || preferredPort > 65535)) { - throw new Error(`Invalid --port value: ${portArg}`); - } - - const server = createServer((req, res) => { - if (!req.url || req.url === '/' || req.url === '/EncryptedCounter.sol') { - res.statusCode = 200; - res.setHeader('Content-Type', 'text/plain; charset=utf-8'); - res.setHeader('Access-Control-Allow-Origin', '*'); - res.end(content); - return; - } - - res.statusCode = 404; - res.setHeader('Content-Type', 'text/plain; charset=utf-8'); - res.end('Not found'); - }); - - return new Promise((resolvePromise, rejectPromise) => { - server.on('error', rejectPromise); - server.listen(preferredPort, '127.0.0.1', () => { - const addr = server.address(); - if (!addr || typeof addr === 'string') { - rejectPromise(new Error('Unexpected server address')); - return; - } - - const localUrl = `http://127.0.0.1:${addr.port}/EncryptedCounter.sol`; - resolvePromise({ server, localUrl }); - }); - }); -} - -async function main() { - let sourceUrl; - let keepAliveServer = null; - - if (useLocal) { - const { server, localUrl } = await startLocalServer(); - keepAliveServer = server; - sourceUrl = localUrl; - } else { - const remoteUrl = execOrNull('git', ['-C', repoRoot, 'config', '--get', 'remote.origin.url']); - const gh = parseGitHubRemote(remoteUrl); - - const pathInRepo = 'examples/docs-snippets/remix/EncryptedCounter.sol'; - - // Prefer a commit SHA that is very likely to exist on GitHub: - // the last commit that touched the file (rather than current HEAD). - // This avoids "Remix opens but file doesn't load" when HEAD isn't pushed. - const lastFileCommit = execOrNull('git', ['-C', repoRoot, 'log', '-n', '1', '--format=%H', '--', pathInRepo]); - const headCommit = execOrNull('git', ['-C', repoRoot, 'rev-parse', 'HEAD']); - const defaultRef = lastFileCommit ?? headCommit ?? 'master'; - const ref = process.env.REMIX_REF ?? refArg ?? defaultRef; - - if (!refArg && !process.env.REMIX_REF) { - const status = execOrNull('git', ['-C', repoRoot, 'status', '--porcelain', '--', pathInRepo]); - if (status) { - console.warn( - '[remix:encrypted-counter] Note: local file has uncommitted changes. Remix will load the last pushed commit, not your working tree.' - ); - console.warn('[remix:encrypted-counter] Tip: commit + push, or pass --ref to a pushed branch/tag/SHA.'); - } - } - - if (gh) { - sourceUrl = `https://raw.githubusercontent.com/${gh.owner}/${gh.repo}/${ref}/${pathInRepo}`; - } else { - sourceUrl = `https://raw.githubusercontent.com/FhenixProtocol/cofhesdk/${ref}/${pathInRepo}`; - } - } - - const remixUrl = `https://remix.ethereum.org/#url=${sourceUrl}`; - - console.log('Remix URL:'); - console.log(remixUrl); - console.log(''); - console.log('Solidity URL:'); - console.log(sourceUrl); - - if (!useLocal && !refArg && !process.env.REMIX_REF) { - console.log(''); - console.log('If Remix opens but does not load the file, your ref may not be pushed to GitHub yet.'); - console.log('Try: git push, or re-run with --ref .'); - } - - if (!printOnly) { - const result = openUrl(remixUrl); - if ((result.status ?? 0) !== 0) process.exit(result.status ?? 1); - } - - if (keepAliveServer) { - console.log(''); - console.log('Local server running. Keep this process alive while Remix is open.'); - console.log('Press Ctrl+C to stop.'); - await new Promise(() => {}); - } -} - -main().catch((err) => { - console.error(err); - process.exitCode = 1; -});