This demo showcases how to use the Lit network to encrypt data and enable decryption through a Lit Action, which performs custom authentication checks using the ucanto library.
Before you start, run pnpm install
to install dependencies and configure the environment variables.
-
Encrypt The File And Upload To STORACHA:
Run the encryption script, passing the file path:node src/scripts/encrypt-and-upload.js testFile.md
This will output the root CID of the file containing the ciphertext and the necessary metadata to decrypt.
-
Delegate The Decrypt Capability:
With theroot CID
from the encryption step, your space DID where the file was uploaded, and the DID of the audience you want to grant decryption capability to, run:node src/scripts/delegate-decrypt-capability.js id:key:z6MktfnQz8Kcz5nsC65oyXWFXhbbAZQavjg6aaaa000space bafkreihesl6njk7gimdhxwlode2qvkpr4eeywmw5bmffjxaa000rootCid did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi
This will output the
delegation.car
file. -
Decrypt The File:
With theroot CID
and the path to thedelegation.car
, run the decryption script:node src/scripts/download-and-decrypt.js bafkreihesl6njk7gimdhxwlode2qvkpr4eeywmw5bmffjxaa000rootCid delegation.car
If you want to crate your own lit action or modify the existing one, you'll need to deploy the build version of it to IPFS.
-
Build The Lit Action:
pnpm run build-actions
-
Obtain The
ipfsHash
:
Run the following command to get the IPFS CID v0:pnpm run ipfsCID
Ensure that the hash matches the one in
src/acc.js
. If not, update it. -
Upload To IPFS:
If you modified the Lit Action code, upload the generated files fromsrc/lit-actions/dist/
to IPFS (CID v0).
Lit is a decentralized network where each node operates as a sealed machine, providing a Trusted Execution Environment (TEE). Nodes use Distributed Key Generation (DKG) to collaboratively generate public/private key pairs without any single party holding the entire key. Each node retains a key share for signing and decryption.
Key features relevant to this demo:
- Decentralized key management
- Client-side encryption
- Access control
- Lit Actions for custom workflows
- Lit Protocol enables private data storage on Storacha.
- Files encrypted with Lit can be stored on the Storacha network
- The decryption and access control are managed by Lit.
- Lit Actions can utilize ucanto to provide custom decryption capabilities.