zkPass
zkPass Developer's Guide
zkPass Developer's Guide
  • â›Šī¸Introduction
  • ZKPASS OVERVIEW
    • đŸ›ī¸Architecture
    • 🧱zkPass Components
    • 🤝Trust Models
    • 🚚Deployment
      • Public-Cloud Hosting
      • Private-Cloud Hosting
      • On-Premise Hosting
    • đŸŽ¯SDK Objectives
    • 🔑API Key
  • zkPass Modules
    • â˜ī¸DVR
      • đŸ—ģHigh Level View
      • đŸ—ī¸Key Concepts
        • User Data
        • DVR Info
        • zkPass Proof
      • đŸ‘ĨDVR Client Roles
        • Data Issuer
          • Providing User Data Retrieval API
        • Data Holder
          • 1. Retrieving the DVR
          • 2. Retrieving the User Data
          • 3. Generating the Proof
          • 4. Verifying the Proof
        • Proof Verifier
          • 1. Providing DVR Retrieval API
          • 2. Providing Proof Verification API
      • 🔎DVR Query
        • Building Query Engine
        • Processing Query
        • Query Grammar
      • đŸ—ī¸Integration Guidelines
      • 🌊DVR Workflows
  • SDK Tutorial
    • Typescript
      • Running Code
      • Code Snippet
      • Directory Structure
    • Rust
      • Running Code
      • Code Snippet
      • Directory Structure
  • API Reference
    • Typescript
      • Classes
        • Class: DvrModuleClient
      • Functions
        • Functions: ffiHelper
        • Functions: jwtHelper
        • Functions: publicKeyOptionUtils
      • Type Aliases
        • Types
        • Types: ffiType
      • Interfaces
        • Interfaces
      • Constants
        • Constants
        • Enums
      • Errors
    • Rust
      • Building Rust doc
    • RESTful API
      • Overview
      • Endpoints
        • Generate Proof
      • Utilities
        • Generate Key Pair
        • Sign User Data and DVR
        • Encrypt User Data and DVR
      • Errors
  • Glossary
    • DVR
    • User Data
    • ZKP
Powered by GitBook
On this page
Export as PDF
  1. SDK Tutorial
  2. Typescript

Code Snippet

PreviousRunning CodeNextDirectory Structure

Last updated 5 months ago

This section describes how we use the zkPass SDK in our demo code

Generate Proof

import { DvrModuleClient } from "@zkpass/dvr-client-ts";

...

// Step 1: Instantiate DvrModuleClient
const dvrModuleClient = new DvrModuleClient({
      baseUrl: SERVICE_URL,
      apiKey: API_KEY,
      secretApiKey: API_SECRET,
    });

// Step 2: Call the DVR module client's callDvrGenerateZkPassProof
const zkPassProof = dvrModuleClient.callDvrGenerateZkPassProof(
      JSON.stringify(userDataToken),
      dvrToken
    );

This code snippet generates a zkPass proof. It requires 3 parameters:

  1. SERVICE_URL : you can use https://playground-zkpass.ssi.id , or use your own endpoint if you deploy zkPass on your own server.

  2. API_KEY & API_SECRET: Get yours at https://portal.ssi.id

  3. userDataToken : check section for more details.

  4. dvrToken : check section for more details.

Verify Proof

import { DvrModuleClient, extractPayload } from "@zkpass/dvr-client-ts";

const dvrPayload = extractPayload(dvrToken);
...

// Step 1: Instantiate the zkPassClient object.
const dvrModuleClient = new DvrModuleClient({
      baseUrl: ZKPASS_SERVICE_URL,
      apiKey: API_KEY,
      secretApiKey: API_SECRET,
    });

// Step 2: Create the expected metadata
const expectedMetadata = {
      dvr: JSON.stringify(dvrPayload),
      ttl: EXPECTED_DVR_TTL,
      user_data_verifying_keys: userDataVerifyingKeys,
    };

// Step 3: Call zkPassClient.verifyZkPassProof to verify the proof.
const proofOutput = dvrModuleClient.callDvrVerifyZkPassProof(
      ZKPASS_ZKVM,
      zkPassProofToken,
      expectedMetadata
    );

This code snippet verifies a zkPass proof token. Components :

  1. expectedMetadata : this is the expected metadata of the dvr.

  2. dvrPayload: the dvr payload extracted from Dvr token.

Generate User Data Token

import { DvrModuleClient } from "@zkpass/dvr-client-ts";

...

// Step 1: Instantiate DvrModuleClient
const dvrModuleClient = new DvrModuleClient({
      baseUrl: SERVICE_URL,
      apiKey: API_KEY,
      secretApiKey: API_SECRET,
    });
//
// Step 2: Call the DVR module client's callDvrGenerateUserDataToken
//         This is to digitally-sign the user data.
const userDataToken = dvrModuleClient.callDvrGenerateUserDataToken(
      signingKey,
      JSON.stringify(data)
    );

This code snippet generate user data token. Components :

  1. signingKey : a private key used to sign user data.

  2. data : user data in JSON format.

Generate DVR Token

import { DvrModuleClient } from "@zkpass/dvr-client-ts";

...

// Step 1: Initiate DvrModuleClient
const dvrModuleClient = new DvrModuleClient({
      baseUrl: SERVICE_URL,
      apiKey: API_KEY,
      secretApiKey: API_SECRET,
    });

// Step 2: Generate Dvr query token
const dvrToken = dvrModuleClient.callDvrGenerateQueryToken(
      signingKey,
      dvrData
    );

This code snippet generate DVR token. Components :

  1. signingKey : a private key used to sign dvr.

  2. dvrData : Dvr data to sign.

zkPassProofToken : check section for more details.

Generate User Data Token
Generate DVR Token
Generate Proof