Spaces:
Sleeping
Sleeping
Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express from 'express';
|
| 2 |
+
import cors from 'cors';
|
| 3 |
+
import * as snarkjs from 'snarkjs';
|
| 4 |
+
import fs from 'fs';
|
| 5 |
+
|
| 6 |
+
const app = express();
|
| 7 |
+
app.use(cors());
|
| 8 |
+
app.use(express.json({ limit: '10mb' }));
|
| 9 |
+
|
| 10 |
+
app.post('/verify', async (req, res) => {
|
| 11 |
+
try {
|
| 12 |
+
const { zkProof, publicSignals, walletPublicKey } = req.body;
|
| 13 |
+
|
| 14 |
+
console.log("Received ZK proof for verification");
|
| 15 |
+
console.log("Wallet:", walletPublicKey);
|
| 16 |
+
|
| 17 |
+
const vKey = JSON.parse(fs.readFileSync('verification_key.json', 'utf8'));
|
| 18 |
+
|
| 19 |
+
console.log("Starting verification...");
|
| 20 |
+
const startTime = Date.now();
|
| 21 |
+
|
| 22 |
+
const isValid = await snarkjs.groth16.verify(vKey, publicSignals, zkProof);
|
| 23 |
+
|
| 24 |
+
const endTime = Date.now();
|
| 25 |
+
console.log(`Verification complete in ${endTime - startTime}ms:`, isValid);
|
| 26 |
+
|
| 27 |
+
res.json({
|
| 28 |
+
valid: isValid,
|
| 29 |
+
wallet: walletPublicKey,
|
| 30 |
+
verificationTime: endTime - startTime,
|
| 31 |
+
message: isValid ? "ZK proof verified!" : "Invalid proof"
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
} catch (error) {
|
| 35 |
+
console.error("Verification error:", error);
|
| 36 |
+
res.status(500).json({ valid: false, error: error.message });
|
| 37 |
+
}
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
app.listen(7860, () => {
|
| 41 |
+
console.log('ZK Verification server running on 7860');
|
| 42 |
+
});
|