Skip to content

Commit 0d5895d

Browse files
committed
Reformatting
1 parent 730fc4f commit 0d5895d

File tree

2 files changed

+67
-32
lines changed

2 files changed

+67
-32
lines changed

accs-contract-call/nodejs/README.md

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,53 @@
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.

accs-contract-call/nodejs/src/index.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ export const runExample = async (dataToEncrypt: string) => {
4444
},
4545
];
4646

47+
const ethersWallet = new ethers.Wallet(
48+
ETHEREUM_PRIVATE_KEY,
49+
new ethers.providers.JsonRpcProvider(LIT_RPC.CHRONICLE_YELLOWSTONE)
50+
);
51+
4752
console.log(`🔄 Connecting to Lit ${LIT_NETWORK} network...`);
4853
litNodeClient = new LitNodeClient({
4954
litNetwork: LIT_NETWORK,
@@ -52,6 +57,15 @@ export const runExample = async (dataToEncrypt: string) => {
5257
await litNodeClient.connect();
5358
console.log(`✅ Connected to Lit ${LIT_NETWORK} network`);
5459

60+
console.log(`🔄 Connecting LitContracts client to ${LIT_NETWORK} network...`);
61+
const litContracts = new LitContracts({
62+
signer: ethersWallet,
63+
network: LIT_NETWORK,
64+
debug: false,
65+
});
66+
await litContracts.connect();
67+
console.log(`✅ Connected LitContracts client to ${LIT_NETWORK} network`);
68+
5569
console.log("🔄 Encrypting the string...");
5670
const { ciphertext, dataToEncryptHash } = await encryptString(
5771
{
@@ -62,22 +76,6 @@ export const runExample = async (dataToEncrypt: string) => {
6276
);
6377
console.log("✅ Encrypted the string");
6478

65-
const ethersWallet = new ethers.Wallet(
66-
ETHEREUM_PRIVATE_KEY,
67-
new ethers.providers.JsonRpcProvider(LIT_RPC.CHRONICLE_YELLOWSTONE)
68-
);
69-
70-
console.log(
71-
`🔄 Connecting LitContracts client to ${LIT_NETWORK} network...`
72-
);
73-
const litContracts = new LitContracts({
74-
signer: ethersWallet,
75-
network: LIT_NETWORK,
76-
debug: false,
77-
});
78-
await litContracts.connect();
79-
console.log(`✅ Connected LitContracts client to ${LIT_NETWORK} network`);
80-
8179
let capacityTokenId = LIT_CAPACITY_CREDIT_TOKEN_ID;
8280
if (capacityTokenId === "" || capacityTokenId === undefined) {
8381
console.log("🔄 No Capacity Credit provided, minting a new one...");

0 commit comments

Comments
 (0)