Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gatekeep decryption access using a EVM contract #52

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "evm-swap-example"]
path = evm-swap-example
url = https://github.com/LIT-Protocol/evm-swap-example.git
[submodule "accs-contract-call/contracts/lib/forge-std"]
path = accs-contract-call/contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
45 changes: 45 additions & 0 deletions accs-contract-call/contracts/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Show Forge version
run: |
forge --version
- name: Run Forge fmt
run: |
forge fmt --check
id: fmt

- name: Run Forge build
run: |
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
12 changes: 12 additions & 0 deletions accs-contract-call/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
/broadcast

# Docs
docs/

# Dotenv file
.env
66 changes: 66 additions & 0 deletions accs-contract-call/contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Foundry

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

Foundry consists of:

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.

## Documentation

https://book.getfoundry.sh/

## Usage

### Build

```shell
$ forge build
```

### Test

```shell
$ forge test
```

### Format

```shell
$ forge fmt
```

### Gas Snapshots

```shell
$ forge snapshot
```

### Anvil

```shell
$ anvil
```

### Deploy

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```

### Cast

```shell
$ cast <subcommand>
```

### Help

```shell
$ forge --help
$ anvil --help
$ cast --help
```
6 changes: 6 additions & 0 deletions accs-contract-call/contracts/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
1 change: 1 addition & 0 deletions accs-contract-call/contracts/lib/forge-std
Submodule forge-std added at 1714be
19 changes: 19 additions & 0 deletions accs-contract-call/contracts/script/AccessControl.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console} from "forge-std/Script.sol";
import {AccessControl} from "../src/AccessControl.sol";

contract DeployAccessControl is Script {
AccessControl public accessControl;

function setUp() public {}

function run() public {
vm.startBroadcast();

accessControl = new AccessControl();

vm.stopBroadcast();
}
}
18 changes: 18 additions & 0 deletions accs-contract-call/contracts/src/AccessControl.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

contract AccessControl {
mapping(address => bool) public revokedAccess;

function grantAccess() public {
revokedAccess[msg.sender] = false;
}

function revokeAccess() public {
revokedAccess[msg.sender] = true;
}

function hasRevokedAccess(address user) public view returns (bool) {
return revokedAccess[user];
}
}
44 changes: 44 additions & 0 deletions accs-contract-call/contracts/test/AccessControl.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";
import {AccessControl} from "../src/AccessControl.sol";

contract AccessControlTest is Test {
AccessControl public accessControl;

function setUp() public {
accessControl = new AccessControl();
}

function testGrantedByDefault() public {
address user = address(this);
assertFalse(accessControl.hasRevokedAccess(user));
}

function testGrantAccess() public {
address user = address(this);
accessControl.grantAccess();
assertFalse(accessControl.hasRevokedAccess(user));
}

function testRevokeAccess() public {
address user = address(this);
accessControl.revokeAccess();
assertTrue(accessControl.hasRevokedAccess(user));
}

function testHasRevokedAccess() public {
address user1 = address(this);
address user2 = address(0xFEED);

vm.prank(user1);
accessControl.revokeAccess();

vm.prank(user2);
accessControl.grantAccess();

assertTrue(accessControl.hasRevokedAccess(user1));
assertFalse(accessControl.hasRevokedAccess(user2));
}
}
3 changes: 3 additions & 0 deletions accs-contract-call/nodejs/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ETHEREUM_PRIVATE_KEY=
DEPLOYED_ACCESS_CONTROL_CONTRACT_ADDRESS=0x4fc0c02ebbAbb81C04dB0C462C8c25cb37970eB1
LIT_CAPACITY_CREDIT_TOKEN_ID=
4 changes: 4 additions & 0 deletions accs-contract-call/nodejs/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://json.schemastore.org/mocharc.json",
"require": "tsx"
}
16 changes: 16 additions & 0 deletions accs-contract-call/nodejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Revoke Access to Encrypted Data

This code example demonstrates how access to decrypt data can be revoked using `EvmContractConditions` by making a request to an Access Control Contract.

## Running the Example

1. Install the dependencies with `yarn`
2. Copy the `.env.example` file to `.env` and set the environment variables
- `ETHEREUM_PRIVATE_KEY` - The private key of the Ethereum account that will be used to:
- Mint Lit Capacity Credits if one wasn't provided
- Create the Lit Capacity Delegation Auth Sig
- Create the Lit Auth Sig to generate the Session Signatures
- `DEPLOYED_ACCESS_CONTROL_CONTRACT_ADDRESS` - The address of the deployed Access Control Contract
- [The contract](../contracts/src/AccessControl.sol) has been deployed on the Lit Chronicle Yellowstone blockchain at: `0x4fc0c02ebbAbb81C04dB0C462C8c25cb37970eB1` for testing purposes
- `LIT_CAPACITY_CREDIT_TOKEN_ID` - The ID of the Lit Capacity Credit Token to avoid minting a new one when the example is ran
3. Run the included tests using `yarn test`
30 changes: 30 additions & 0 deletions accs-contract-call/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "nodejs",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"type": "module",
"scripts": {
"test": "npx @dotenvx/dotenvx run -- mocha test/**/*.spec.ts"
},
"dependencies": {
"@dotenvx/dotenvx": "^0.44.1",
"@lit-protocol/auth-helpers": "^6.4.10",
"@lit-protocol/constants": "^6.4.10",
"@lit-protocol/contracts-sdk": "^6.4.10",
"@lit-protocol/lit-node-client": "^6.4.10",
"@lit-protocol/types": "^6.4.10",
"ethers": "v5"
},
"devDependencies": {
"@types/chai": "^4.3.16",
"@types/chai-json-schema": "^1.4.10",
"@types/mocha": "^10.0.6",
"chai": "^5.1.1",
"chai-json-schema": "^1.5.1",
"mocha": "^10.4.0",
"tsc": "^2.0.4",
"tsx": "^4.12.0",
"typescript": "^5.4.5"
}
}
Loading