Code Snippet

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

Generate Proof

use crate::lib_loader::generate_zkpass_proof;

let zkpass_proof_token = unsafe {
    generate_zkpass_proof(credentials, user_data_tokens, dvr_token)
};

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

  1. credentials : Get yours API key and secret at https://portal.ssi.id

  2. user_data_tokens : stringified signed users data.

  3. dvr_token : signed Dvr query.

Verify Proof

use crate::lib_loader::verify_zkpass_proof;
use dvr_types::ExpectedDvrMetadataFfi;

//
// Step 1: Create the expected metadata object.
//
let expected_metadata = ExpectedDvrMetadataFfi {
    ttl: some_ttl,
    dvr: expected_dvr_cstring.as_ptr(),
    user_data_verifying_keys: user_data_requests_slice.as_ptr(),
    user_data_verifying_keys_len: user_data_requests_slice.len() as u64,
};

//
// Step 2: Call verify proof.
//
let result = unsafe {
    verify_zkpass_proof(&service_url, zkvm, zkpass_proof_token, expected_metadata)
};

This code snippet verifies a zkPass proof token. Components :

  1. zkpass_proof_token : check Generate Proof section for more details.

  2. expected_metadata : this is the expected metadata of the dvr.

  3. zkvm: zkvm used to generate proof, currently we only support r0.

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

Generate User Data Token

use crate::lib_loader::generate_user_data_token;

let user_data_token = unsafe {
    generate_user_data_token(signing_key, &data.to_string(), verifying_key)
};

This code snippet generate user data token. Components :

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

  2. data : user data in JSON format.

  3. verifying_key : a public key to verify that user data token.

Generate DVR Token

use crate::lib_loader::generate_query_token;

let dvr_token = unsafe { generate_query_token(signing_key, dvr_data) };

This code snippet generate DVR token. Components :

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

  2. dvr_data : Dvr data to sign.

Last updated