From b7604091c60faf39f2ea16247ca470a68c2464d1 Mon Sep 17 00:00:00 2001 From: Caleb Tuttle <1calebtuttle@gmail.com> Date: Sat, 6 Apr 2024 16:56:33 -0400 Subject: [PATCH] add epassport sybil resistance route --- src/constants/misc.js | 5 +++ src/routes/sybil-resistance.js | 2 + src/services/sybil-resistance.js | 67 +++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/constants/misc.js b/src/constants/misc.js index 13002b3..f1c2636 100644 --- a/src/constants/misc.js +++ b/src/constants/misc.js @@ -16,3 +16,8 @@ export const v3KYCSybilResistanceCircuitId = "0x729d660e1c02e4e419745e617d643f897a538673ccf1051e093bbfa58b0a120b"; export const v3PhoneSybilResistanceCircuitId = "0xbce052cf723dca06a21bd3cf838bc518931730fb3db7859fc9cc86f0d5483495"; +export const v3EPassportSybilResistanceCircuitId = + "0xf2ce248b529343e105f7b3c16459da619281c5f81cf716d28f7df9f87667364d"; + +export const ePassportIssuerMerkleRoot = + "0x111abc2c2de1738067395fa944c07ce6e44c4a38accfed392797bb94cee2cdac"; diff --git a/src/routes/sybil-resistance.js b/src/routes/sybil-resistance.js index fa4ddf8..88bf603 100644 --- a/src/routes/sybil-resistance.js +++ b/src/routes/sybil-resistance.js @@ -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; diff --git a/src/services/sybil-resistance.js b/src/services/sybil-resistance.js index 26970ec..573ed1d 100644 --- a/src/services/sybil-resistance.js +++ b/src/services/sybil-resistance.js @@ -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"; @@ -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; @@ -165,4 +226,8 @@ async function sybilResistancePhone(req, res) { } } -export { sybilResistanceGovId, sybilResistancePhone }; +export { + sybilResistanceGovId, + sybilResistanceEPassport, + sybilResistancePhone +};