Skip to content

Commit

Permalink
Merge pull request #6 from ETHNYC-ZK-KYC-Soulbound/add-kyc-backend
Browse files Browse the repository at this point in the history
KYC Backend
  • Loading branch information
devlyn37 authored Jun 25, 2022
2 parents aa9d424 + f7c81ac commit c8e82aa
Show file tree
Hide file tree
Showing 13 changed files with 8,920 additions and 10,839 deletions.
17 changes: 0 additions & 17 deletions .github/dependabot.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/ci.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/dependencies.yml

This file was deleted.

1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

18 changes: 0 additions & 18 deletions .husky/post-merge

This file was deleted.

4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

48 changes: 48 additions & 0 deletions api/create-verification-session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { VercelRequest, VercelResponse } from "@vercel/node";
import { utils } from "ethers";
import Stripe from "stripe";

const stripe = new Stripe(process.env.STRIPE_TEST_API_KEY as string, {
apiVersion: "2020-08-27",
typescript: true,
});

interface VerificationSessionInput {
address: string | undefined;
}

export default async (req: VercelRequest, res: VercelResponse) => {
try {
const { address } = req.body as VerificationSessionInput;

// Check if address is provided and is legit
if (typeof address !== "string" || !utils.isAddress(address)) {
return res.status(401).send("Invalid parameters");
}

const verificationSession =
await stripe.identity.verificationSessions.create({
type: "document",
metadata: {
user_id: address,
},
// Additional options for configuring the verification session:
options: {
document: {
allowed_types: ["driving_license", "passport", "id_card"],
require_id_number: true, // https://stripe.com/docs/identity/verification-checks?type=id-number
require_live_capture: true,
require_matching_selfie: true, // https://stripe.com/docs/identity/selfie#session
},
},
});
const clientSecret = verificationSession.client_secret;
res.status(200).json({
address,
clientSecret,
});
} catch (err) {
console.log(err);
res.status(500);
}
};
5 changes: 5 additions & 0 deletions api/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { VercelRequest, VercelResponse } from "@vercel/node";

export default (request: VercelRequest, response: VercelResponse) => {
response.status(200).send("Hello");
};
64 changes: 64 additions & 0 deletions api/webhook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { VercelRequest, VercelResponse } from "@vercel/node";
import Stripe from "stripe";

const stripe = new Stripe(process.env.STRIPE_TEST_API_KEY as string, {
apiVersion: "2020-08-27",
typescript: true,
});

export default (req: VercelRequest, res: VercelResponse) => {
let event;
const stripeEndpointSecret = process.env.STRIPE_TEST_WEBHOOK_KEY;

// Verify the event came from Stripe
try {
const sig = req.headers["stripe-signature"];
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
event = stripe.webhooks.constructEvent(req.body, sig, stripeEndpointSecret);
} catch (err) {
// On error, log and return the error message
console.log(err);
return res.status(400).send("Webhook Error");
}

// Successfully constructed event
console.log(event);

// If event is not the 'verified' event, skip it
if (event.type !== "identity.verification_session.verified") {
if (event.type !== "identity.verification_session.requires_input") {
const verificationSession = event.data
.object as Stripe.Identity.VerificationSession;
console.log("Verification check failed!");
if (verificationSession?.last_error)
console.log(verificationSession.last_error);
}
return res.json({ received: true }); // send back to webhook to end
}

// Verified!
// https://stripe.com/docs/api/identity/verification_sessions/object#identity_verification_session_object-verified_outputs
const verificationSession = event.data
.object as Stripe.Identity.VerificationSession;
const { verified_outputs: verifiedOutputs } = verificationSession;
if (verifiedOutputs !== null) {
const {
address,
dob,
id_number: idNumber,
first_name: firstName,
last_name: lastName,
} = verifiedOutputs;
if (!address) {
console.log("Invalid address after verification!");
console.log(verifiedOutputs);
return res.json({ received: true }); // send back to webhook to end
}

const { city, state } = address;
}

return res.json({ received: true }); // send back to webhook to end
};
Loading

1 comment on commit c8e82aa

@vercel
Copy link

@vercel vercel bot commented on c8e82aa Jun 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web-stuff – ./

web-stuff-devlyn37.vercel.app
web-stuff-git-main-devlyn37.vercel.app
web-stuff-lac.vercel.app

Please sign in to comment.