Feat/test api (#223)

This commit is contained in:
nicoshark
2025-03-04 16:56:59 -07:00
committed by GitHub
parent 4d3439df67
commit d24713ee8a
9 changed files with 199 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
RPC_URL=https://forno.celo.org
SCOPE=test-scope

44
sdk/tests/api-server/.gitignore vendored Normal file
View File

@@ -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

View File

@@ -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.

BIN
sdk/tests/api-server/bun.lockb Executable file

Binary file not shown.

View File

@@ -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"
}

View File

@@ -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 };

View File

@@ -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}`,
);

View File

@@ -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',
},
},
);

View File

@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES2021",
"module": "ES2022",
"moduleResolution": "node",
"types": [
"bun-types"
],
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true
}
}