Skip to content

Commit

Permalink
add epassport sybil resistance route
Browse files Browse the repository at this point in the history
  • Loading branch information
calebtuttle committed Apr 6, 2024
1 parent 8053f26 commit b760409
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/constants/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ export const v3KYCSybilResistanceCircuitId =
"0x729d660e1c02e4e419745e617d643f897a538673ccf1051e093bbfa58b0a120b";
export const v3PhoneSybilResistanceCircuitId =
"0xbce052cf723dca06a21bd3cf838bc518931730fb3db7859fc9cc86f0d5483495";
export const v3EPassportSybilResistanceCircuitId =
"0xf2ce248b529343e105f7b3c16459da619281c5f81cf716d28f7df9f87667364d";

export const ePassportIssuerMerkleRoot =
"0x111abc2c2de1738067395fa944c07ce6e44c4a38accfed392797bb94cee2cdac";
2 changes: 2 additions & 0 deletions src/routes/sybil-resistance.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import express from "express";
import {
sybilResistanceGovId,
sybilResistanceEPassport,
sybilResistancePhone,
} from "../services/sybil-resistance.js";

const router = express.Router();

router.get("/gov-id/:network", sybilResistanceGovId);
router.get("/epassport/:network", sybilResistanceEPassport);
router.get("/phone/:network", sybilResistancePhone);

export default router;
67 changes: 66 additions & 1 deletion src/services/sybil-resistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
phoneIssuerAddress,
v3KYCSybilResistanceCircuitId,
v3PhoneSybilResistanceCircuitId,
v3EPassportSybilResistanceCircuitId,
ePassportIssuerMerkleRoot,
} from "../constants/misc.js";
import AntiSybilStoreABI from "../constants/AntiSybilStoreABI.js";
import HubV3ABI from "../constants/HubV3ABI.js";
Expand Down Expand Up @@ -93,6 +95,65 @@ async function sybilResistanceGovId(req, res) {
}
}

async function sybilResistanceEPassport(req, res) {
try {
const address = req.query.user;
const actionId = req.query["action-id"];
if (!address) {
return res
.status(400)
.json({ error: "Request query params do not include user address" });
}
if (!actionId) {
return res
.status(400)
.json({ error: "Request query params do not include action-id" });
}
if (!assertValidAddress(address)) {
return res.status(400).json({ error: "Invalid user address" });
}
if (!parseInt(actionId)) {
return res.status(400).json({ error: "Invalid action-id" });
}

// Check blocklist first
const blockListResult = await blocklistGetAddress(address);
if (blockListResult.Item) {
return res.status(200).json({ result: false });
}

const network = req.params.network;

const provider = providers[network];

// Check v3 contract
try {
const hubV3Contract = new ethers.Contract(hubV3Address, HubV3ABI, provider);

const sbt = await hubV3Contract.getSBT(address, v3EPassportSybilResistanceCircuitId);

const publicValues = sbt[1];
const merkleRoot = publicValues[2].toHexString();

return res.status(200).json({
result: merkleRoot === ePassportIssuerMerkleRoot
});
} catch (err) {
if ((err.errorArgs?.[0] ?? "").includes("SBT is expired")) {
return res.status(200).json({ result: false });
}

throw err;
}
} catch (err) {
console.log(err);
logWithTimestamp(
"sybilResistanceEPassport: Encountered error while calling smart contract. Exiting"
);
return res.status(500).json({ error: "An unexpected error occured" });
}
}

async function sybilResistancePhone(req, res) {
try {
const address = req.query.user;
Expand Down Expand Up @@ -165,4 +226,8 @@ async function sybilResistancePhone(req, res) {
}
}

export { sybilResistanceGovId, sybilResistancePhone };
export {
sybilResistanceGovId,
sybilResistanceEPassport,
sybilResistancePhone
};

0 comments on commit b760409

Please sign in to comment.