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
  • Issuer Demo Application
  • Prerequisites
  • Run Issuer Demo Application
  • Setting up ngrok
  • Testing the Demo Application
  • Modifying the Demo Application Data
  • Code Snippets
  1. getting started
  2. Quickstart

Issuer - Typescript/Node.js

PreviousQuickstartNextVerifier - Typescript/Node.js

Last updated 1 year ago

Issuer Demo Application

This application built with Node.js/Typescript to demonstrate the usage of package, Please note that you will also need to have the latest didPass-Wallet application on your phone to test the demo application, you can download the latest apk .

Prerequisites

ngrok is needed as the wallet needs to communicate with the issuer application on your local

Run Issuer Demo Application

  1. Clone the demo project from

git clone https://github.com/GDP-ADMIN/didPass-demo.git
  1. Navigate to the issuer-demo

cd didPass-demo/didpass-demo/issuer-demo
  1. Install all dependencies with npm

npm install
  1. Rename .env.example to .env

  2. Initiate ngrok by following step

  3. Change NEXT_PUBLIC_URL and NEXT_PUBLIC_DOMAIN_URL on .env to the forwarding port from ngrok that has been initiated on step 5, for example my ngrok forwarding url is https://9c53-149-108-164-96.ngrok-free.app

NEXT_PUBLIC_URL=placeholder<'your ngrok forwarding url'> #https://9c53-149-108-164-96.ngrok-free.app
NEXT_PUBLIC_DOMAIN_URL=placeholder<'your ngrok forwarding url domain'> #9c53-149-108-164-96.ngrok-free.app
  1. Run the application

npm run dev

Setting up ngrok

  1. Initiate new terminal on didpass-demo/issuer-demo repository

  2. Run the following command on terminal

ngrok http 3000

Testing the Demo Application

  1. Click Connect button to show the QR Code

  1. Scan the QR Code from didPass-Wallet application on your phone and wait for the process to finish

  2. The data shown on your verifier-demo is the mock data that will be claimed by your wallet

  3. To claim the data, click Claim by VC or Claim by JWT button on the bottom of the screen (for now, to test with the verifier you will need to claim the credential by JWT)

  1. QR Code will be shown, scan it to claim the data and wait for the process to complete

  2. Check if the data successfully claimed on wallet's List of Credentials page

If you encounter any error while testing Issuer Demo, please disconnect your wallet and start from the beginning

Modifying the Demo Application Data

You can modify the mock data by changing the values on didPass-demo/didpass-demo/issuer-demo/src/backend/mocks/detailCredentialMock.json

Code Snippets

Before delving into the code snippets, it's important to note that the following examples utilize mocked data to simulate user information. Below is the mocked data in JSON format:

detailCredentialMock.json
{
    "NIK": 1808023348760001,
    "Nama": "JHON DOE",
    "BerlakuHingga": "SEUMUR HIDUP",
    "Pekerjaan": "PEGAWAI SWASTA",
    "StatusPerkawinan": "BELUM KAWIN",
    "GolonganDarah": "O",
    "Agama": "ISLAM",
    "TanggalLahir": 19900208,
    "TempatLahir": "GROGOL",
    "Alamat": "Jl. PETOJO VIJ.3 NO. 60",
    "JenisKelamin": "LAKI-LAKI",
    "Kecamatan": "GAMBIR",
    "KelurahanDesa": "CIDENG",
    "Kewarganegaraan": "WNI",
    "KotaKabupaten": "JAKARTA PUSAT",
    "Provinsi": "DKI JAKARTA",
    "RTRW": "001/001"
}

Generate Connect QR Code

  1. Import the necessary classes from the SDK

import { QRGenerator, DIDAccount } from "@didpass/issuer-sdk";
  1. Initialize DIDAccount instance for the QRGenerator to use

const privateKey = '-----BEGIN PRIVATE KEY-----\n' +
    'MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgm3GHIFEfdOuuMk0W\n' +
    'xBIgVCsPoqy+EgSV3o3tQvjejo+hRANCAASSWi/7X7DyERyVwkcHmwO85ow3UJS5\n' +
    'hlrCQPaC+XIoWuQoZywYSAkJnLtez0C9DaXch7mv1d5+V+6iYywMLF/B\n' +
    '-----END PRIVATE KEY-----\n';
const didAccount = new DIDAccount(privateKey);
const qrGenerator = new QRGenerator(didAccount);
  1. Prepare the data for QR Code generation

const baseUrl = process.env.NEXT_PUBLIC_URL;
const callbackUrl = `${baseUrl}/api/issuer/connect/callback`;
const sessionId = uuidv4();

// Below is an example of issuer detail object which is optional
const issuerDetail: IIssuerDetail = {
    fullName: "didPass demo issuer",
    shortName: "didPass",
    logo: `${baseUrl}/images/logo.png`,
    restoreUrl: `${baseUrl}/api/restore`,
};
  1. Generate QR Code

const qrCode = await qrGenerator.connectQR(
    callbackUrl,
    sessionId,
    issuerDetail
);

Here's the full code

import { QRGenerator, DIDAccount } from "@didpass/issuer-sdk";

async function generateConnectQr(){
    const privateKey = 'f627d2c96b18cefd3720f68d5dd4b94951adee9de50a4dc4fcfb9b9f0e2e9bf2';
    const didAccount = new DIDAccount(privateKey);
    const qrGenerator = new QRGenerator(didAccount);

    const baseUrl = process.env.NEXT_PUBLIC_URL;
    const callbackUrl = `${baseUrl}/api/issuer/connect/callback`;
    const sessionId = uuidv4();

    // Below is an example of issuer detail object which is optional
    const issuerDetail: IIssuerDetail = {
        fullName: "didPass demo issuer",
        shortName: "didPass",
        logo: `${baseUrl}/images/logo.png`,
        restoreUrl: `${baseUrl}/api/restore`,
    };
    
    const qrCode = await qrGenerator.connectQR(
        callbackUrl,
        sessionId,
        issuerDetail
    );

    return qrCode;
}

Authenticate Signature

  1. Import the necessary classes from the SDK

import { Auth } from "@didpass/issuer-sdk";
  1. Initialize Auth instance

const auth = new Auth();
  1. Prepare the data for Authentication from the payload

 const message = params.message;
 const signature = params.signature;
  1. Authenticate

const result = await auth.authenticateSignature(message, signature);

Here's the full code

import { Auth } from "@didpass/issuer-sdk";

async function authenticate(params){
    const auth = new Auth();

    const message = params.message;
    const signature = params.signature;
    
    const result = await auth.authenticateSignature(message, signature);
    
    return result;
}

Generate Credential QR Code

  1. Import the necessary classes from the SDK

import { DIDAccount, QRGenerator } from "@didpass/issuer-sdk";
import credentialMock from "./detailCredentialMock.json";
  1. Initialize DIDAccount instance for the QRGenerator to use

const privateKey = 'f627d2c96b18cefd3720f68d5dd4b94951adee9de50a4dc4fcfb9b9f0e2e9bf2';
const didAccount = new DIDAccount(privateKey);
const qrGenerator = new QRGenerator(didAccount);
  1. Prepare the data for QR Code generation

const credentialId = "63918bf3-fb19-4079-b93a-e92b43927212"; //The credential's id
const description = "didPass Credential";
// For this example, we import it from a JSON file
const preview = {
  nik: credentialMock.NIK,
  name: credentialMock.Nama,
};
const credentials = [
  {
    id: credentialId,
    description,
    preview,
  },
];
const baseUrl = process.env.NEXT_PUBLIC_URL;
const callbackUrl = `${baseUrl}/api/issuer/agent`;
const sessionId = uuidv4();
  1. Generate QR Code

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

Here's the full code

import { DIDAccount, QRGenerator } from "@didpass/issuer-sdk";
import credentialMock from "./detailCredentialMock.json";

async function generateCredentialQr(params) {
    const privateKey = "f627d2c96b18cefd3720f68d5dd4b94951adee9de50a4dc4fcfb9b9f0e2e9bf2";
    const didAccount = new DIDAccount(privateKey);
    const qrGenerator = new QRGenerator(didAccount);

    const credentialId = "63918bf3-fb19-4079-b93a-e92b43927212"; //The credential's id
    const description = "didPass Credential";
    // For this example, we import it from a JSON file
    const preview = {
        nik: credentialMock.NIK,
        name: credentialMock.Nama,
    };
    const credentials = [
        {
            id: credentialId,
            description,
            preview,
        },
    ];
    const baseUrl = process.env.NEXT_PUBLIC_URL;
    const callbackUrl = `${baseUrl}/api/issuer/agent`;
    const sessionId = uuidv4();

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

    return qrCode;
}

Sign Credential (For Verifiable Credential)

  1. Import the necessary classes from the SDK

import credentialMock from "../mocks/detailCredentialMock.json";
import { Credential, DIDAccount } from "@didpass/issuer-sdk";
  1. Initialize the DIDAccount

const privateKey = "f627d2c96b18cefd3720f68d5dd4b94951adee9de50a4dc4fcfb9b9f0e2e9bf2";
const didAccount = new DIDAccount(privateKey);
  1. Prepare the data to be signed

const type = "KtpCred"; // KtpCred is an example of credential type

// Replace with user's credential subject data for VC (based on credentialId)
// In this example, we use the mock data
const credentialSubject = credentialMock;
const issuanceDetails = {
    issuer: didAccount,
    metadata: {
        id: uuidv4(),
        credentialType: type,
        receiverDID: params.did,
    },
    credentialSubject: credentialSubject,
};
  1. Sign Credential

const credential = new Credential();
const verifiableCredential = await credential.signCredential(
    issuanceDetails,
    params.message,
    params.signature
);

Here's the full code

import credentialMock from "../mocks/detailCredentialMock.json";
import { Credential, DIDAccount } from "@didpass/issuer-sdk";

async function signCredential(params) {
    const privateKey = "f627d2c96b18cefd3720f68d5dd4b94951adee9de50a4dc4fcfb9b9f0e2e9bf2";
    const didAccount = new DIDAccount(privateKey);
    
    const type = "KtpCred"; // KtpCred is an example of credential type
    
    // Replace with user's credential subject data for VC (based on credentialId)
    // In this example, we use the mock data
    const credentialSubject = credentialMock;
    const issuanceDetails = {
        issuer: didAccount,
        metadata: {
            id: uuidv4(),
            credentialType: type,
            receiverDID: params.did,
        },
        credentialSubject: credentialSubject,
    };
    
    const credential = new Credential();
    const verifiableCredential = await credential.signCredential(
        issuanceDetails,
        params.message,
        params.signature
    );

    return verifiableCredential;
}

Tokenize Credentials (For JWT)

  1. Import the necessary classes from the SDK

import credentialMock from "../mocks/detailCredentialMock.json";
import { DIDAccount, JwsCredential } from "@didpass/issuer-sdk";
  1. Initialize the DID Account

const privateKey = "f627d2c96b18cefd3720f68d5dd4b94951adee9de50a4dc4fcfb9b9f0e2e9bf2";
const didAccount = new DIDAccount(privateKey);
  1. Prepare the data to be tokenized

const type = "KtpCred"; // KtpCred is an example of credential type

// Replace with user's credential subject data for VC (based on credentialId)
// In this example, we use the mock data
const credentialSubject = credentialMock;
const payload = {
    issuer: didAccount,
    receiverDID: params.did,
    type: type,
    userData: credentialSubject,
    message: params.message,
    signature: params.signature,
};
  1. Initialize the JWS Credential and tokenize the credential

const keyPem =
    "-----BEGIN PRIVATE KEY-----\n" +
    "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgm3GHIFEfdOuuMk0W\n" +
    "xBIgVCsPoqy+EgSV3o3tQvjejo+hRANCAASSWi/7X7DyERyVwkcHmwO85ow3UJS5\n" +
    "hlrCQPaC+XIoWuQoZywYSAkJnLtez0C9DaXch7mv1d5+V+6iYywMLF/B\n" +
    "-----END PRIVATE KEY-----\n";
const baseUrl = process.env.NEXT_PUBLIC_URL;
const verifyEndpoint = {
    jku: `${baseUrl}/issuer/jwks`,
    kid: "jRDSDZcT1zptDb1xBN+2d3y5vPUjBE+bTUbuen25SkE=",
};
const credential = new JwsCredential(keyPem, verifyEndpoint);
const jwsCredential = await credential.tokenizeCredential(payload);

Here's the full code

import credentialMock from "../mocks/detailCredentialMock.json";
import { DIDAccount, JwsCredential } from "@didpass/issuer-sdk";

async function tokenizeCredential(params) {
    const privateKey = "f627d2c96b18cefd3720f68d5dd4b94951adee9de50a4dc4fcfb9b9f0e2e9bf2";
    const didAccount = new DIDAccount(privateKey);

    const type = "KtpCred"; // KtpCred is an example of credential type

    // Replace with user's credential subject data for VC (based on credentialId)
    // In this example, we use the mock data
    const credentialSubject = credentialMock;
    const payload = {
        issuer: didAccount,
        receiverDID: params.did,
        type: type,
        userData: credentialSubject,
        message: params.message,
        signature: params.signature,
    };

    const keyPem =
        "-----BEGIN PRIVATE KEY-----\n" +
        "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgm3GHIFEfdOuuMk0W\n" +
        "xBIgVCsPoqy+EgSV3o3tQvjejo+hRANCAASSWi/7X7DyERyVwkcHmwO85ow3UJS5\n" +
        "hlrCQPaC+XIoWuQoZywYSAkJnLtez0C9DaXch7mv1d5+V+6iYywMLF/B\n" +
        "-----END PRIVATE KEY-----\n";
    const baseUrl = process.env.NEXT_PUBLIC_URL;
    const verifyEndpoint = {
        jku: `${baseUrl}/issuer/jwks`,
        kid: "jRDSDZcT1zptDb1xBN+2d3y5vPUjBE+bTUbuen25SkE=",
    };
    const credential = new JwsCredential(keyPem, verifyEndpoint);
    const jwsCredential = await credential.tokenizeCredential(payload);
    return jwsCredential;
}

Access the demo on

Access on your browser

⚡
localhost:3000
localhost:3000
issuer-sdk
here
Node.js 18 or higher
Ngrok
Github
these