Generating QR Code for Claiming JWS Credential

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_JWT;
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_JWT;
  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;

Last updated