forked from alchemyplatform/GiftList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (24 loc) · 840 Bytes
/
index.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
const express = require('express');
const verifyProof = require('../utils/verifyProof');
const port = 1225;
const app = express();
app.use(express.json());
// TODO: hardcode a merkle root here representing the whole nice list
// paste the hex string in here, without the 0x prefix
const MERKLE_ROOT = "ddd59a2ffccddd60ff47993312821cd57cf30f7f14fb82937ebe2c4dc78375aa";
app.post('/gift', (req, res) => {
const { name, proof } = req.body;
if (!name || !proof) {
return res.status(400).send({ message: "Request payload is invalid!" });
}
const isInTheList = verifyProof(proof, name, MERKLE_ROOT);
if (isInTheList) {
res.send("You got a toy robot!");
}
else {
res.send("You are not on the list :(");
}
});
app.listen(port, () => {
console.log(`Listening on port ${port}!`);
});