# Code Snippet

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

#### <mark style="color:orange;">Generate Proof</mark>

```typescript
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 [Generate User Data Token](https://docs.ssi.id/zkpass/v/zkpass-developers-guide/sdk-tutorial/quick-start/typescript-node.js-linux#generate-user-data-token) section for more details.
4. `dvrToken` : check [Generate DVR Token](https://docs.ssi.id/zkpass/v/zkpass-developers-guide/sdk-tutorial/quick-start/typescript-node.js-linux#generate-dvr-token) section for more details.

#### <mark style="color:orange;">Verify Proof</mark>

```typescript
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. `zkPassProofToken` : check [Generate Proof](https://docs.ssi.id/zkpass/v/zkpass-developers-guide/sdk-tutorial/quick-start/typescript-node.js-linux#generate-proof) section for more details.
2. `expectedMetadata` :  this is the expected metadata of the dvr.
3. `dvrPayload`: the dvr payload extracted from Dvr token.

#### <mark style="color:orange;">Generate User Data Token</mark>

```typescript
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.

#### <mark style="color:orange;">Generate DVR Token</mark>

```typescript
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gl-docs.gitbook.io/zkpass/zkpass-developers-guide/sdk-tutorial/typescript/code-snippet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
