Skip to content

Commit

Permalink
Merge pull request #808 from ethereum-oasis-op/803-sri-ccsm-connect-b…
Browse files Browse the repository at this point in the history
…pi-with-ccsm-contract

Connect BPI with CCSM contract
  • Loading branch information
biscuitdey authored Jul 18, 2024
2 parents accb6f0 + 1ab172e commit 29bf04f
Show file tree
Hide file tree
Showing 35 changed files with 8,533 additions and 4,073 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/bri-3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ jobs:
DID_REGISTRY: "0x03d5003bf0e79c5f5223588f347eba39afbc3818"
DID_BPI_OPERATOR_PUBLIC_KEY: "0x08872e27BC5d78F1FC4590803369492868A1FCCb"
DID_BPI_OPERATOR_PRIVATE_KEY: "2c95d82bcd8851bd3a813c50afafb025228bf8d237e8fd37ba4adba3a7596d58"
DID_NETWORK: "sepolia"
CCSM_NETWORK: "sepolia"
INFURA_PROVIDER_API_KEY: "c5f37cd25eca4007a9768f18f492bc6f"
CCSM_BPI_STATE_ANCHOR_CONTRACT_ADDRESS: "<smart_contract_address>"
SERVICE_URL: "bri-3"
BPI_NATS_SERVER_URL: "localhost:4222"
BPI_NATS_SERVER_USER: "bpi_operator"
Expand Down
3 changes: 2 additions & 1 deletion examples/bri-3/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ DATABASE_URL="postgresql://postgres:example@localhost:5432/postgres" # DB connec
DID_REGISTRY="0x03d5003bf0e79c5f5223588f347eba39afbc3818" # Sepolia did registry https://sepolia.etherscan.io/address/0x03d5003bf0e79c5f5223588f347eba39afbc3818#code
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
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
DID_NETWORK="sepolia" # network used to resolve dids
CCSM_NETWORK="sepolia" # network used to resolve dids and connect to BPI smart contract
INFURA_PROVIDER_API_KEY="<infura_api_key>" # API key of the infura account used to connect to the network
CCSM_BPI_STATE_ANCHOR_CONTRACT_ADDRESS="<smart_contract_address>" # address of the smart contract where CAHs are stored
SERVICE_URL="bri-3" # JWT token audience
BPI_NATS_SERVER_URL="localhost:4222" # URL of the local NATS server instance used by the BPI
BPI_NATS_SERVER_USER="bpi_operator"
Expand Down
1 change: 0 additions & 1 deletion examples/bri-3/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/dist
/node_modules
src/bri/zeroKnowledgeProof/services/circuit/snarkjs/*.sol
/zeroKnowledgeArtifacts/blockchain/ethereum/artifacts
/typechain-types
/cache

Expand Down
4 changes: 3 additions & 1 deletion examples/bri-3/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"solidity-va.diagnostics.cdili_json.import": true,
"solidity.compileUsingRemoteVersion": "v0.8.20+commit.a1b79de6"
}
17 changes: 17 additions & 0 deletions examples/bri-3/ccsm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
node_modules
.env

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

# Hardhat Ignition default folder for deployments against a local node
ignition/deployments/chain-31337
12 changes: 12 additions & 0 deletions examples/bri-3/ccsm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Sample Hardhat Project

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.

Try running some of the following tasks:

```shell
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
```
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
//SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;
pragma solidity 0.8.24;

import "@openzeppelin/contracts/access/AccessControl.sol";
import '@openzeppelin/contracts/access/AccessControl.sol';

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

bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
bytes32 public constant ADMIN_ROLE = keccak256('ADMIN_ROLE');

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

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

function setAnchorHash(
string calldata _workgroupId,
string calldata _anchorHash
) external onlyAdmin {
require(bytes(_workgroupId).length > 0, 'WorkgroupId cannot be empty');
require(bytes(_workgroupId).length < 36, 'WorkgroupId cannot exceed 36 bytes');
require(
bytes(_workgroupId).length < 36,
'WorkgroupId cannot exceed 36 bytes'
);
require(bytes(_anchorHash).length > 0, 'AnchorHash cannot be empty');
require(bytes(_anchorHash).length > 256, 'AnchorHash cannot exceed 256 bytes');
require(
bytes(_anchorHash).length <= 256,
'AnchorHash cannot exceed 256 bytes'
);

anchorHashStore[_workgroupId] = _anchorHash;

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

modifier onlyAdmin() {
require(hasRole(ADMIN_ROLE, msg.sender), "Only admin can call this function");
modifier onlyAdmin() {
require(
hasRole(ADMIN_ROLE, msg.sender),
'Only admin can call this function'
);
_;
}
}
16 changes: 16 additions & 0 deletions examples/bri-3/ccsm/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
solidity: "0.8.24",
defaultNetwork: "hardhat",
networks: {
sepolia: {
url: "https://sepolia.infura.io/v3/" + process.env.INFURA_PROVIDER_API_KEY,
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], // TODO: Add test account for sepolia
}
}
};

export default config;
Loading

0 comments on commit 29bf04f

Please sign in to comment.