diff --git a/sdk/tests/api-server/.env.sample b/sdk/tests/api-server/.env.sample new file mode 100644 index 000000000..d6a1d35a5 --- /dev/null +++ b/sdk/tests/api-server/.env.sample @@ -0,0 +1,2 @@ +RPC_URL=https://forno.celo.org +SCOPE=test-scope \ No newline at end of file diff --git a/sdk/tests/api-server/.gitignore b/sdk/tests/api-server/.gitignore new file mode 100644 index 000000000..fb94ae776 --- /dev/null +++ b/sdk/tests/api-server/.gitignore @@ -0,0 +1,44 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env.local +.env.development.local +.env.test.local +.env.production.local + +# vercel +.vercel + +**/*.trace +**/*.zip +**/*.tar.gz +**/*.tgz +**/*.log +package-lock.json +**/*.bun + +.env \ No newline at end of file diff --git a/sdk/tests/api-server/README.md b/sdk/tests/api-server/README.md new file mode 100644 index 000000000..688c87e69 --- /dev/null +++ b/sdk/tests/api-server/README.md @@ -0,0 +1,15 @@ +# Elysia with Bun runtime + +## Getting Started +To get started with this template, simply paste this command into your terminal: +```bash +bun create elysia ./elysia-example +``` + +## Development +To start the development server run: +```bash +bun run dev +``` + +Open http://localhost:3000/ with your browser to see the result. \ No newline at end of file diff --git a/sdk/tests/api-server/bun.lockb b/sdk/tests/api-server/bun.lockb new file mode 100755 index 000000000..dea8b1fcb Binary files /dev/null and b/sdk/tests/api-server/bun.lockb differ diff --git a/sdk/tests/api-server/package.json b/sdk/tests/api-server/package.json new file mode 100644 index 000000000..f55e3eb07 --- /dev/null +++ b/sdk/tests/api-server/package.json @@ -0,0 +1,30 @@ +{ + "name": "backend-api", + "version": "1.0.50", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "dev": "bun run --watch src/app.ts", + "init": "bash scripts/copy_abi.sh && bash scripts/copy_deployedAddress.sh", + "start:daemon": "bun run src/app.ts > app.log 2>&1 &", + "stop:daemon": "pkill -f 'bun run src/app.ts'" + }, + "dependencies": { + "@elysiajs/swagger": "^1.2.0", + "@selfxyz/core": "^0.0.3", + "@openpassport/zk-kit-imt": "^0.0.5", + "@openpassport/zk-kit-lean-imt": "^0.0.6", + "dotenv": "^16.4.7", + "elysia": "latest", + "logixlysia": "^4.1.1", + "pg": "^8.13.1", + "poseidon-lite": "^0.3.0", + "snarkjs": "^0.7.5", + "swagger": "^0.7.5", + "viem": "^2.22.23" + }, + "devDependencies": { + "@types/pg": "^8.11.11", + "bun-types": "latest" + }, + "module": "index.ts" +} \ No newline at end of file diff --git a/sdk/tests/api-server/src/app.routes.ts b/sdk/tests/api-server/src/app.routes.ts new file mode 100644 index 000000000..3870e30ed --- /dev/null +++ b/sdk/tests/api-server/src/app.routes.ts @@ -0,0 +1,8 @@ +import Elysia from 'elysia'; + +import { ContractsController } from './contracts/infrastructure/contracts.controller'; + +const routes = new Elysia({ prefix: 'api/v1' }) + .use(ContractsController); + +export { routes as AppRoutes }; \ No newline at end of file diff --git a/sdk/tests/api-server/src/app.ts b/sdk/tests/api-server/src/app.ts new file mode 100644 index 000000000..34f2c3836 --- /dev/null +++ b/sdk/tests/api-server/src/app.ts @@ -0,0 +1,31 @@ +import { Elysia } from "elysia"; +import swagger from "@elysiajs/swagger"; +import logger from "logixlysia"; +import { AppRoutes } from "./app.routes.js"; +import dotenv from "dotenv"; + +dotenv.config(); + +const app = new Elysia() + .use(logger()) + .use( + swagger({ + exclude: ['/swagger'], + autoDarkMode: true, + documentation: { + info: { + title: 'backend-api', + description: + 'backend api to interact with the contracts', + version: '1.0.0', + }, + }, + }), + ) + .use(AppRoutes); + +app.listen({ port: process.env.PORT }); + +console.log( + `🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`, +); \ No newline at end of file diff --git a/sdk/tests/api-server/src/contracts/infrastructure/contracts.controller.ts b/sdk/tests/api-server/src/contracts/infrastructure/contracts.controller.ts new file mode 100644 index 000000000..526085ed3 --- /dev/null +++ b/sdk/tests/api-server/src/contracts/infrastructure/contracts.controller.ts @@ -0,0 +1,54 @@ +import Elysia, { t } from 'elysia'; +// import { SelfBackendVerifier } from "@selfxyz/core"; +import { SelfBackendVerifier } from "../../../../../core/src/SelfBackendVerifier"; + +export const ContractsController = new Elysia() + .post( + 'verify-vc-and-disclose-proof', + async (request: any) => { + try { + const selfBackendVerifier = new SelfBackendVerifier( + process.env.RPC_URL as string, + process.env.SCOPE as string, + ); + + const result = await selfBackendVerifier.verify( + request.body.proof, + request.body.publicSignals + ); + console.log(result); + + return { + status: "success", + result: result.isValid, + }; + } catch (error) { + return { + status: "error", + message: error instanceof Error ? error.message : "Unknown error", + }; + } + }, + { + body: t.Object({ + proof: t.Any(), + publicSignals: t.Any(), + }), + response: { + 200: t.Object({ + status: t.String(), + result: t.Boolean(), + }), + 500: t.Object({ + status: t.String(), + message: t.String(), + }), + }, + detail: { + tags: ['Contracts'], + summary: 'Verify a VC and disclose a proof', + description: 'Verify a VC and disclose a proof', + }, + }, + ); + \ No newline at end of file diff --git a/sdk/tests/api-server/tsconfig.json b/sdk/tests/api-server/tsconfig.json new file mode 100644 index 000000000..5a36dab8d --- /dev/null +++ b/sdk/tests/api-server/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES2021", + "module": "ES2022", + "moduleResolution": "node", + "types": [ + "bun-types" + ], + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "resolveJsonModule": true + } +} \ No newline at end of file