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 Credential Payload
  • Step 3: Set Up Credential Verification Key
  • Step 4: Set Up JWS Credential Data
  • Step 5: Claim JWS Credential
  • Step 6: Return Signed Credential
  • Final Code
  1. Issuer
  2. Sample Code
  3. Download Jws Credential

Claiming JWS Credential

Step 1: Import Required Modules

Import the necessary modules at the beginning of your script:

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

Step 2: Set Up Credential Payload

Replace the placeholder values with your actual Credential payload:

// this is the payload sent by wallet
const credentialPayload = {
  credentialId: "YOUR_CREDENTIAL_ID",
  did: "USER_DID",
  qrType: QRTypes.TYPE_CREDENTIAL_JWT,
  message: "MESSAGE_FROM_WALLET",
  signature: "SIGNATURE_FROM_WALLET",
};

Step 3: Set Up Credential Verification Key

Prepare your key for signing the credential, and the endpoint for verifying the token:

// Your private key in pem format
const keyPem = "-----BEGIN PRIVATE KEY-----\nYOUR_PRIVATE_KEY_PEM\n-----END PRIVATE KEY-----\n";
const verifyEndpoint: JwksEndpoint = {
    jku: "http://localhost:3000/.well-known/jwks.json", // Replace this with your endpoint
    kid: "key-100" // Replace with your actual kid
}

Step 4: Set Up JWS Credential Data

Replace the placeholder values with your actual credential details:

const credentialSubject = {
  // Replace with user's data for credential (based on credentialId)
};

const type = "YOUR_CREDENTIAL_TYPE"; // ex: KtpCred

Step 5: Claim JWS Credential

Claim and sign the credential using the provided payload and details:

const privateKey = "YOUR_ISSUER_PRIVATE_KEY";
const account = new DIDAccount(privateKey);

const credential = new JwsCredential(keyPem, verifyEndpoint);

const payload: TokenizePayload = {
  issuer: account,
  receiverDID: did,
  type: type,
  userData: credentialSubject,
  message: credentialPayload.message,
  signature: credentialPayload.signature
}

const jwsCredential = await credential.tokenizeCredential(payload);

Step 6: Return Signed Credential

Return the signed credential:

return jwsCredential;

Final Code

Here's the complete code:

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

async function claimCredential() {
  // this is the payload sent by wallet
  const credentialPayload = {
    credentialId: "YOUR_CREDENTIAL_ID",
    did: "USER_DID",
    qrType: QRTypes.TYPE_CREDENTIAL_JWT,
    message: "MESSAGE_FROM_WALLET",
    signature: "SIGNATURE_FROM_WALLET",
  };
  
  // Your private key in pem format
  const keyPem = "-----BEGIN PRIVATE KEY-----\nYOUR_PRIVATE_KEY_PEM\n-----END PRIVATE KEY-----\n";
  const verifyEndpoint: JwksEndpoint = {
      jku: "http://localhost:3000/.well-known/jwks.json", // Replace this with your endpoint
      kid: "key-100" // Replace with your actual kid
  }

  // Set up credential details
  const credentialSubject = {
    // Replace with user's data for credential (based on credentialId)
  };
  const type = "YOUR_CREDENTIAL_TYPE"; // ex: KtpCred

  // Claim and sign credential
  const privateKey = "YOUR_ISSUER_PRIVATE_KEY";
  const account = new DIDAccount(privateKey);
  const credential = new JwsCredential(keyPem, verifyEndpoint);
  const payload: TokenizePayload = {
    issuer: account,
    receiverDID: did,
    type: type,
    userData: credentialSubject,
    message: credentialPayload.message,
    signature: credentialPayload.signature
  }
  
  const jwsCredential = await credential.tokenizeCredential(payload);

  // Return jws credential
  return jwsCredential;
}
PreviousGenerating QR Code for Claiming JWS CredentialNextRequirements

Last updated 1 year ago

💻