Generating keys & Encrypt

This section follows the first step to interact with the TEE, to store and secure private content on the Ternoa chain. We recommend reading the cluster section first, to familiarize yourself with the process of encrypting your content with a public key.

How to generate keys and encrypt content on IPFS

Generate some PGP keys

Here you can use the Ternoa helper

import { generatePGPKeys } from "ternoa-js";

const getPGPKeys = async () => {
  try {
    const { privateKey, publicKey } = await generatePGPKeys();
    console.log(privateKey, publicKey); // Output expected is two strings under the following fomat:
    // -----BEGIN PGP PRIVATE KEY BLOCK-----
    // xVgEZZgHdBYJKwYBBAHaRw8BAQdAeOzyPsxdJ9/s1FiYbE7pziJrING8EGhN
    // ...
    // U5n1IAjQkCvJsdrJBNYynTnMTBmrd079dMufBw===afDl
    // -----END PGP PRIVATE KEY BLOCK-----

    // -----BEGIN PGP PUBLIC KEY BLOCK-----
    // xjMEZZgHdBYJKwYBBAHaRw8BAQdAeOzyPsxdJ9/s1FiYbE7pziJrING8EGhN
    // ...
    // PjQP/lIzerB6OgD/SvxPeVOZ9SAI0JArybHayQTWMp05zEwZq3dO/XTLnwc==Ap5s
    // -----END PGP PUBLIC KEY BLOCK-----

    process.exit(0);
  } catch (error) {
    process.exit(1);
  }
};

Encrypt content and store it on IPFS

We assume you are familiar with the Ternoa IPFS client. Use the Ternoa IPFS node endpoint, with a key generated from our key generator, or your own storage provider. Read more about the Ternoa IPFS client. Read more about storage options.

The process of encryption requires a few steps: preparing your file (do not forget to import the File from the ternoa-js library), preparing your metadata, and generating your storage solution (here we use the Ternoa IPFS client).

Example using the secretNftEncryptAndUploadFile() helper, to encrypt the content of a Secret NFT.

Under the hood the secretNftEncryptAndUploadFile() executes the following code. It utilizes another user-friendly atomic helper,encryptFile(), that you can use at your convenience to encrypt the content of your Capsule, for example. You can simply replace the helper by this piece of code:

The flow to encrypt the content of a Capsule NFT is quite similar.

Depending on the kind of NFT you want to create, whether a Capsule NFT or a Secret NFT, you will find the corresponding detailed code sections here:

Try to open the encrypted_media hash from the generated Secret NFT IPFS hash on https://ipfs-dev.trnnfr.com/ipfs/repalce-with-your-hash. You can see that the content is encrypted.

Now that your content is stored and encrypted, you can proceed to the final step to secure your NFT on the TEE.

Last updated