|
1 |
| -# Revoke Access to Encrypted Data |
2 |
| - |
3 |
| -This code example demonstrates how access can be revoked to decrypt data using `EvmContractConditions` to making a request to an Access Control Contract. |
4 |
| - |
5 |
| -## Running the Example |
6 |
| - |
7 |
| -1. Install the dependencies with `yarn` |
8 |
| -2. Copy the `.env.example` file to `.env` and set the environment variables |
9 |
| - - `ETHEREUM_PRIVATE_KEY` - The private key of the Ethereum account that will be used to: |
10 |
| - - Mint Lit Capacity Credits if one wasn't provided |
11 |
| - - Create the Lit Capacity Delegation Auth Sig |
12 |
| - - Create the Lit Auth Sig to generate the Session Signatures |
13 |
| - - `DEPLOYED_ACCESS_CONTROL_CONTRACT_ADDRESS` - The address of the deployed Access Control Contract |
14 |
| - - [The contract](../contracts/src/AccessControl.sol) has been deployed on the Lit Chronicle Yellowstone blockchain at: `0x4fc0c02ebbAbb81C04dB0C462C8c25cb37970eB1` for testing purposes |
15 |
| - - `LIT_CAPACITY_CREDIT_TOKEN_ID` - The ID of the Lit Capacity Credit Token to avoid minting a new one when the example is ran |
16 |
| -3. Run the included tests using `yarn test` |
| 1 | +# Revoking Decryption Access Using the Lit SDK in Node.js |
| 2 | + |
| 3 | +This code example demonstrates how access to decrypt data can be revoked using `EvmContractConditions` by making a request to an Access Control Contract. |
| 4 | + |
| 5 | +## Understanding the Implementation |
| 6 | + |
| 7 | +1. Using an imported Ethereum private key, connect the wallet to the Lit RPC endpoint `Chronicle Yellowstone` |
| 8 | +2. Connect `LitNodeClient` to the Lit network (`datil-test` in this case) |
| 9 | +3. Connect the `LitContracts` client to the Lit network (`datil-test` in this case) |
| 10 | +4. Encrypt the string passed into the function. The string is encrypted with the `EVMContractConditions` defined at the beginning of the function |
| 11 | +5. **If not provided in the .env file**: Mint a [`capacityCreditsNFT`](https://developer.litprotocol.com/sdk/capacity-credits) and define the request limit and expiration date |
| 12 | +6. Create a `capacityDelegationAuthSig`. Any network costs will be undertaken by the `dAppOwnerWallet` |
| 13 | +7. Generate a resource string using the `dataToEncryptHash` and `EVMContractConditions`. This ensures our session signatures can only attempt to decrypt the provided string |
| 14 | +8. Generate the session signatures and decrypt the string |
| 15 | + |
| 16 | +## Running this Example |
| 17 | + |
| 18 | +### Install the Dependencies |
| 19 | + |
| 20 | +In this directory, `accs-contract-call/nodejs`, run `yarn` to install the project dependencies. |
| 21 | + |
| 22 | +### Setting Up the `.env` File |
| 23 | + |
| 24 | +Make a copy of the provided `.env.example` file and name it `.env`: |
| 25 | + |
| 26 | +``` |
| 27 | +cp .env.example .env |
| 28 | +``` |
| 29 | + |
| 30 | +Within the `.env` file there are three ENVs |
| 31 | + |
| 32 | +1. `ETHEREUM_PRIVATE_KEY` - **Required** Will be used to generate an Ethers.js wallet to perform message signing (CapacityDelegationAuthSig, AuthSig for session signatures) |
| 33 | +2. `DEPLOYED_ACCESS_CONTROL_CONTRACT_ADDRESS` - **Required** The address of the deployed Access Control Contract |
| 34 | + - [The contract](../contracts/src/AccessControl.sol) has been deployed on the Lit Chronicle Yellowstone blockchain at: `0x4fc0c02ebbAbb81C04dB0C462C8c25cb37970eB1` for testing purposes |
| 35 | +3. `LIT_CAPACITY_CREDIT_TOKEN_ID` - **Optional** |
| 36 | + - If provided, this [CapacityCredit](https://developer.litprotocol.com/paying-for-lit/capacity-credits) will be used to create an AuthSig to pay for usage the Lit network |
| 37 | + - If not provided, a new CapacityCredit will be minted and used to run this example. Please make sure that your wallet has enough `tstLPX` to pay for decryption on the Lit network |
| 38 | + |
| 39 | +Your `.env` file should look like: |
| 40 | + |
| 41 | +``` |
| 42 | +ETHEREUM_PRIVATE_KEY= |
| 43 | +DEPLOYED_ACCESS_CONTROL_CONTRACT_ADDRESS=0x4fc0c02ebbAbb81C04dB0C462C8c25cb37970eB1 |
| 44 | +LIT_CAPACITY_CREDIT_TOKEN_ID= |
| 45 | +``` |
| 46 | + |
| 47 | +### Running the Test |
| 48 | + |
| 49 | +After the `.env` is configured, there is a NPM script in the `package.json` to run the test in the `test/index.spec.ts` file. To run the test, use the `yarn test` command. |
| 50 | + |
| 51 | +### Contracts Directory |
| 52 | + |
| 53 | +Outside of this directory is the `accs-contract-call/contracts` directory. It contains the contract used for testing in this example. If you'd like to see the complete setup or extend the example, you can check out the contracts directory. |
0 commit comments