Skip to content

Commit 29bf04f

Browse files
authored
Merge pull request #808 from ethereum-oasis-op/803-sri-ccsm-connect-bpi-with-ccsm-contract
Connect BPI with CCSM contract
2 parents accb6f0 + 1ab172e commit 29bf04f

35 files changed

+8533
-4073
lines changed

.github/workflows/bri-3.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ jobs:
4646
DID_REGISTRY: "0x03d5003bf0e79c5f5223588f347eba39afbc3818"
4747
DID_BPI_OPERATOR_PUBLIC_KEY: "0x08872e27BC5d78F1FC4590803369492868A1FCCb"
4848
DID_BPI_OPERATOR_PRIVATE_KEY: "2c95d82bcd8851bd3a813c50afafb025228bf8d237e8fd37ba4adba3a7596d58"
49-
DID_NETWORK: "sepolia"
49+
CCSM_NETWORK: "sepolia"
5050
INFURA_PROVIDER_API_KEY: "c5f37cd25eca4007a9768f18f492bc6f"
51+
CCSM_BPI_STATE_ANCHOR_CONTRACT_ADDRESS: "<smart_contract_address>"
5152
SERVICE_URL: "bri-3"
5253
BPI_NATS_SERVER_URL: "localhost:4222"
5354
BPI_NATS_SERVER_USER: "bpi_operator"

examples/bri-3/.env.sample

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ DATABASE_URL="postgresql://postgres:example@localhost:5432/postgres" # DB connec
88
DID_REGISTRY="0x03d5003bf0e79c5f5223588f347eba39afbc3818" # Sepolia did registry https://sepolia.etherscan.io/address/0x03d5003bf0e79c5f5223588f347eba39afbc3818#code
99
DID_BPI_OPERATOR_PUBLIC_KEY="<bpi_operator_public_key>" # bpi_operator_public_key = public key of the bpi operator that represents the issuer of the JWT token
1010
DID_BPI_OPERATOR_PRIVATE_KEY="<bpi_operator_private_key>" # bpi_operator_private_key = private key of the bpi operator that is used to sign the issued JWT token
11-
DID_NETWORK="sepolia" # network used to resolve dids
11+
CCSM_NETWORK="sepolia" # network used to resolve dids and connect to BPI smart contract
1212
INFURA_PROVIDER_API_KEY="<infura_api_key>" # API key of the infura account used to connect to the network
13+
CCSM_BPI_STATE_ANCHOR_CONTRACT_ADDRESS="<smart_contract_address>" # address of the smart contract where CAHs are stored
1314
SERVICE_URL="bri-3" # JWT token audience
1415
BPI_NATS_SERVER_URL="localhost:4222" # URL of the local NATS server instance used by the BPI
1516
BPI_NATS_SERVER_USER="bpi_operator"

examples/bri-3/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/dist
33
/node_modules
44
src/bri/zeroKnowledgeProof/services/circuit/snarkjs/*.sol
5-
/zeroKnowledgeArtifacts/blockchain/ethereum/artifacts
65
/typechain-types
76
/cache
87

examples/bri-3/.vscode/settings.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"typescript.tsdk": "node_modules/typescript/lib"
2+
"typescript.tsdk": "node_modules/typescript/lib",
3+
"solidity-va.diagnostics.cdili_json.import": true,
4+
"solidity.compileUsingRemoteVersion": "v0.8.20+commit.a1b79de6"
35
}

examples/bri-3/ccsm/.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
node_modules
2+
.env
3+
4+
# Hardhat files
5+
/cache
6+
/artifacts
7+
8+
# TypeChain files
9+
/typechain
10+
/typechain-types
11+
12+
# solidity-coverage files
13+
/coverage
14+
/coverage.json
15+
16+
# Hardhat Ignition default folder for deployments against a local node
17+
ignition/deployments/chain-31337

examples/bri-3/ccsm/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Sample Hardhat Project
2+
3+
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.
4+
5+
Try running some of the following tasks:
6+
7+
```shell
8+
npx hardhat help
9+
npx hardhat test
10+
REPORT_GAS=true npx hardhat test
11+
npx hardhat node
12+
```
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
//SPDX-License-Identifier: UNLICENSED
2-
pragma solidity 0.8.17;
2+
pragma solidity 0.8.24;
33

4-
import "@openzeppelin/contracts/access/AccessControl.sol";
4+
import '@openzeppelin/contracts/access/AccessControl.sol';
55

66
contract CcsmBpiStateAnchor is AccessControl {
77
mapping(string => string) public anchorHashStore;
88
event AnchorHashSet(string indexed workgroupId, string anchorHash);
99

10-
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
10+
bytes32 public constant ADMIN_ROLE = keccak256('ADMIN_ROLE');
1111

12-
constructor(address[] memory admins) {
13-
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender); // Grant deployer the default admin role
12+
constructor(address[] memory admins) {
13+
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender); // Grant deployer the default admin role
1414

15-
for (uint i = 0; i < admins.length; i++) {
16-
_grantRole(ADMIN_ROLE, admins[i]); // Grant admin role to each address
17-
}
18-
}
15+
for (uint i = 0; i < admins.length; i++) {
16+
_grantRole(ADMIN_ROLE, admins[i]); // Grant admin role to each address
17+
}
18+
}
1919

2020
function setAnchorHash(
2121
string calldata _workgroupId,
2222
string calldata _anchorHash
2323
) external onlyAdmin {
2424
require(bytes(_workgroupId).length > 0, 'WorkgroupId cannot be empty');
25-
require(bytes(_workgroupId).length < 36, 'WorkgroupId cannot exceed 36 bytes');
25+
require(
26+
bytes(_workgroupId).length < 36,
27+
'WorkgroupId cannot exceed 36 bytes'
28+
);
2629
require(bytes(_anchorHash).length > 0, 'AnchorHash cannot be empty');
27-
require(bytes(_anchorHash).length > 256, 'AnchorHash cannot exceed 256 bytes');
30+
require(
31+
bytes(_anchorHash).length <= 256,
32+
'AnchorHash cannot exceed 256 bytes'
33+
);
2834

2935
anchorHashStore[_workgroupId] = _anchorHash;
3036

@@ -37,8 +43,11 @@ contract CcsmBpiStateAnchor is AccessControl {
3743
return anchorHashStore[_workgroupId];
3844
}
3945

40-
modifier onlyAdmin() {
41-
require(hasRole(ADMIN_ROLE, msg.sender), "Only admin can call this function");
46+
modifier onlyAdmin() {
47+
require(
48+
hasRole(ADMIN_ROLE, msg.sender),
49+
'Only admin can call this function'
50+
);
4251
_;
4352
}
4453
}

examples/bri-3/ccsm/hardhat.config.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { HardhatUserConfig } from "hardhat/config";
2+
import "@nomicfoundation/hardhat-toolbox";
3+
4+
const config: HardhatUserConfig = {
5+
solidity: "0.8.24",
6+
defaultNetwork: "hardhat",
7+
networks: {
8+
sepolia: {
9+
url: "https://sepolia.infura.io/v3/" + process.env.INFURA_PROVIDER_API_KEY,
10+
accounts:
11+
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], // TODO: Add test account for sepolia
12+
}
13+
}
14+
};
15+
16+
export default config;

0 commit comments

Comments
 (0)