-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.js
74 lines (64 loc) · 2.17 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import express from 'express';
import cors from 'cors';
import worldcoin from './worldcoin.js';
import humangram from './humangram.js';
import biometrics from './biometrics.js';
import ledger from './ledger.js';
const app = express();
const PORT = 3000;
// Enable CORS for all routes
app.use(cors());
// Middleware to parse JSON request bodies
app.use(express.json());
// Endpoint for Proof of Humanity
app.get('/', (req, res) => {
res.json({ message: 'Proof of Humanity' });
});
// Endpoint for generating a proof using Worldcoin validator
app.post('/worldcoin/proof', async (req, res) => {
try {
const { data, worldcoinProof } = req.body;
console.log("data - " + data)
console.log("worldcoinProof - " + JSON.stringify(worldcoinProof))
const proof = await worldcoin.generateProof(data, worldcoinProof);
res.json({ proof });
} catch (error) {
console.log(error)
res.status(500).json({ error: 'An error occurred while generating the proof.' });
}
});
// Endpoint for generating a proof using Humangram validator
app.post('/humangram/proof', async (req, res) => {
try {
const { data, humangramProof } = req.body;
const proof = await humangram.generateProof(data, humangramProof);
res.json({ proof });
} catch (error) {
res.status(500).json({ error: 'An error occurred while generating the proof.' });
}
});
// Endpoint for generating a proof using Biometrics validator
app.post('/biometrics/proof', async (req, res) => {
try {
const { data, token } = req.body;
const proof = await biometrics.generateProof(data, token);
res.json({ proof });
} catch (error) {
res.status(500).json({ error: 'An error occurred while generating the proof.' });
}
});
// Endpoint for generating a proof using Ledger validator
app.post('/ledger/proof', async (req, res) => {
try {
const { data, ledgerProof } = req.body;
const proof = await ledger.generateProof(data, ledgerProof);
res.json({ proof });
} catch (error) {
res.status(500).json({ error: 'An error occurred while generating the proof.' });
}
});
// Start the server
app.listen(PORT, () => {
console.log(`API server running on port ${PORT}`);
});
export default app;