didPass
didPass Developer's Guide
didPass Developer's Guide
  • getting started
    • 👋Welcome to didPass
    • 📘Introduction
    • 🔺Triangle of Trust
    • ⚡Quickstart
      • Issuer - Typescript/Node.js
      • Verifier - Typescript/Node.js
      • Installing The SDK
  • Issuer
    • 📋Requirements
    • 🔧Installation
    • 💻Sample Code
      • Connecting Wallet with Issuer
        • Request Connect QR Code
        • Authenticate with Signature
      • Download Verifiable Credential
        • Generating QR Code for Claiming VC
        • Claiming and Signing Credential
      • Download Jws Credential
        • Generating QR Code for Claiming JWS Credential
        • Claiming JWS Credential
    • API References
  • Verifier
    • 📃Requirements
    • 🛠️Installation
    • 👨‍💻Sample Code
      • Prerequisite
      • Generating QR Code for DVR
      • Generating Signed DVR Token
      • Verifying Siwe
      • Verifying Proof
    • API References
  • Wallet
    • ✅Requirements
    • 📥Installation
    • 🖥️Sample Code
    • API References
  • References
    • didPass User's Guide
    • zkPass User's Guide
    • zkPass Developer's Guide
Powered by GitBook
On this page
  • Step 1: Import Required Modules
  • Step 2: Set Up Details
  • Step 3: Generate QR Code
  • Step 4: Return QR Code
  • Final Code
  1. Issuer
  2. Sample Code
  3. Download Verifiable Credential

Generating QR Code for Claiming VC

Step 1: Import Required Modules

Import the necessary modules at the beginning of your script:

import { Credential, DIDAccount, QRGenerator } from "@didpass/issuer-sdk";
import { QRTypes } from "@didpass/issuer-sdk/lib/types/QRTypes";

Step 2: Set Up Details

Replace the placeholder values with your actual details:

const privateKey = "YOUR_PRIVATE_KEY";

const callbackUrl = "YOUR_CALLBACK_URL";
const did = "USER_WALLET_DID";
const sessionId = "YOUR_SESSION_ID";

const credentialId = "YOUR_CREDENTIAL_ID";
const description = "YOUR_CREDENTIAL_DESCRIPTION";
const qrType = QRTypes.TYPE_CREDENTIAL_VC;
const preview = {
  nik: "YOUR_CREDENTIAL_NIK_PREVIEW",
  name: "YOUR_CREDENTIAL_NAME_PREVIEW",
};

const credentials = [
  {
    id: credentialId,
    description: description,
    preview: preview, // optional
  },
];

Step 3: Generate QR Code

Generate the QR code for credential:

const account = new DIDAccount(privateKey);
const qrGenerator = new QRGenerator(account);

const qrCode = await qrGenerator.credentialQR(
  callbackUrl,
  did,
  credentials,
  sessionId,
  qrType
);

Step 4: Return QR Code

Return the generated QR code:

return qrCode;

Final Code

Here's the complete code:

import { Credential, DIDAccount, QRGenerator } from "@didpass/issuer-sdk";
import { QRTypes } from "@didpass/issuer-sdk/lib/types/QRTypes";

async function getCredentialQRCode() {
  // Set up credential details
  const privateKey = "YOUR_PRIVATE_KEY";

  const callbackUrl = "YOUR_CALLBACK_URL";
  const did = "USER_WALLET_DID";
  const sessionId = "YOUR_SESSION_ID";

  const credentialId = "YOUR_CREDENTIAL_ID";
  const description = "YOUR_CREDENTIAL_DESCRIPTION";
  const qrType = QRTypes.TYPE_CREDENTIAL_VC;
  const preview = {
    nik: "YOUR_CREDENTIAL_NIK_PREVIEW",
    name: "YOUR_CREDENTIAL_NAME_PREVIEW",
  };

  const credentials = [
    {
      id: credentialId,
      description: description,
      preview: preview,
    },
  ];

  // Generate credential QR code
  const account = new DIDAccount(privateKey);
  const qrGenerator = new QRGenerator(account);
  const qrCode = await qrGenerator.credentialQR(
    callbackUrl,
    did,
    credentials,
    sessionId,
    qrType
  );

  // Return credential QR code
  return qrCode;
PreviousDownload Verifiable CredentialNextClaiming and Signing Credential

Last updated 1 year ago

💻