Encrypt User Data and DVR
Prerequisites
Make sure you have :
userDataToken
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 :
Encrypted User Data Token (in JWE Format).
Encrypted DVR Token (in JWE Format).
Here's the example
{
"encryptedUserDatatoken": "eyJ0eXAiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiZXBrIjp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoielJJdWp5aDdmbG84OU5MbHFweEt0VWpmckhabVd1NVIzNGNkTlhnLVMzUSIsInkiOiJwNHN6LXc3U3pGRTBMbGY2R0Z4cUd2YmtuSHpEaENHY2dMSXZvTHpIbTlZIn0sImFsZyI6IkVDREgtRVMifQ..STqfLlyIzO-vlPu-.ju8WoPSCiLBSIUNw9EzSVjINBVx5NzN_XXb4jd8GjQ8d9USaQ0i9yU2M-kXf-eD8PZDYDvQ3hvuIi25MlRlyf_vWQSIrFuReHmZxQGZE1pc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