Encrypt User Data and DVR

Prerequisites

Make sure you have :

  1. userDataToken

  2. dvrToken

Read Sign User Data and DVR section for detail info.

Overview

zkPass enhances the security of your data during transport by encrypting it before sending it over the network. The are only two entities that can access the data: the holder and zkPass host running in a Trusted Execution Environment (TEE).

Example Implementation

First, find the zkPass public key in the .well-known/jwks.json file at this endpoint: https://playground-zkpass.ssi.id/.well-known/jwks.json The key you're looking for has a kid (Key ID) of "ServiceEncryptionPubK".

import { importSPKI, EncryptJWT } from "jose";

async encryptData(userDataOrDvrToken: string): Promise<string> {
    const keyUrl = 'https://playground-zkpass.ssi.id/.well-known/jwks.json';
    const fetchKeys = await fetch(keyUrl);
    const keys = await fetchKeys.json();
    const encryptionPubKey = keys.find(
      (key: { kid: string }) => key.kid === 'ServiceEncryptionPubK'
    );
    const zkPassPublicKey =
      '-----BEGIN PUBLIC KEY-----\n' +
      encryptionPubKey.x +
      '\n' +
      encryptionPubKey.y +
      '\n-----END PUBLIC KEY-----';
    const importedPublicKey = await importSPKI(zkPassPublicKey, "ES256");
    return await new EncryptJWT({ data: userDataOrDvrToken })
      .setProtectedHeader({
        alg: "ECDH-ES",
        enc: "A256GCM",
      })
      .encrypt(importedPublicKey);
  }

Output Example

After this section you should have :

  1. Encrypted User Data Token (in JWE Format).

  2. Encrypted DVR Token (in JWE Format).

Here's the example

{
  "encryptedUserDatatoken": "eyJ0eXAiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiZXBrIjp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiMzltNTN2ZmZJRXhaSVAxT0d6cHlqc3RMZDM1OUd0UHFwODJSSkZHOXU0WSIsInkiOiI5RHNTTHpGcWtMMklKRDl5TUVxQXYyb3hQcTZ6c05QUE9uNVh0aWZfX3FvIn0sImFsZyI6IkVDREgtRVMifQ..g_0l5lEYDWaPWFbF.IprX1dpBLdvMvmq_BHgzeutyYVPhnPGISi_3a3fMbKxp_p-NfZQtLV9awiGKvdNkYdneAQQM8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