Code Snippet
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:
SERVICE_URL
: you can use https://playground-zkpass.ssi.id
, or use your own endpoint if you deploy zkPass on your own server.
API_KEY
& API_SECRET
: Get yours at https://portal.ssi.id
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 :
expectedMetadata
: this is the expected metadata of the dvr.
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),
verifyingKey
);
This code snippet generate user data token. Components :
signingKey
: a private key used to sign user data.
data
: user data in JSON format.
verifyingKey
: a public key to verify that user data token.
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 :
signingKey
: a private key used to sign dvr.
dvrData
: Dvr data to sign.