Issuing Credentials

What We Are Doing:

  • Implementing a route (/kyc-credential) in our Express app that:

    • Takes user input (age, firstName, lastName).

    • Contacts the Issuer to create a credential issuance offering.

    • Returns the offering data, including a qr_code_url.

Why: This route enables users to input their info and receive a QR code. Scanning the QR code with the Empe DID Wallet allows them to claim the credential.

Steps: Update src/routes.ts:

import { Router, Request, Response } from "express";
import fetch from "node-fetch";
import dotenv from "dotenv";

dotenv.config();

const router = Router();
const ISSUER_URL = process.env.ISSUER_URL!;
const ISSUER_SECRET = process.env.ISSUER_SECRET!;

router.post("/kyc-credential", async (req: Request, res: Response) => {
  try {
    const { age, firstName, lastName } = req.body;

    // Fetch issuer metadata to get offering_endpoint
    const metadataRes = await fetch(`${ISSUER_URL}/.well-known/openid-credential-issuer`, {
      headers: { "Content-Type": "application/json" },
    });
    const metadata = await metadataRes.json();
    const offering_endpoint = metadata.offering_endpoint;

    // Request an issuance offering from the Issuer
    const offeringRes = await fetch(offering_endpoint, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "x-client-secret": ISSUER_SECRET,
      },
      body: JSON.stringify({
        credential_type: "KYC Verifiable Credential",
        credential_subject: { age: Number(age), firstName, lastName },
      }),
    });

    const offeringData = await offeringRes.json();
    res.status(200).json(offeringData);
  } catch (error) {
    console.error(error);
    res.status(500).json({ error: "Internal server error" });
  }
});

export default router;

Next, we`ll create a simple frontend form to submit user data and display the QR code.

Last updated