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
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
Initiate new terminal on didpass-demo/issuer-demo repository
Run the following command on terminal
ngrok http 3000
Testing the Demo Application
Click Connect button to show the QR Code
Scan the QR Code from didPass-Wallet application on your phone and wait for the process to finish
The data shown on your verifier-demo is the mock data that will be claimed by your wallet
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)
QR Code will be shown, scan it to claim the data and wait for the process to complete
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:
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)
Import the necessary classes from the SDK
import credentialMock from "../mocks/detailCredentialMock.json";
import { Credential, DIDAccount } from "@didpass/issuer-sdk";
Initialize the DIDAccount
const privateKey = "f627d2c96b18cefd3720f68d5dd4b94951adee9de50a4dc4fcfb9b9f0e2e9bf2";
const didAccount = new DIDAccount(privateKey);
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,
};
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)
Import the necessary classes from the SDK
import credentialMock from "../mocks/detailCredentialMock.json";
import { DIDAccount, JwsCredential } from "@didpass/issuer-sdk";
Initialize the DID Account
const privateKey = "f627d2c96b18cefd3720f68d5dd4b94951adee9de50a4dc4fcfb9b9f0e2e9bf2";
const didAccount = new DIDAccount(privateKey);
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,
};
Initialize the JWS Credential and tokenize the credential