Skip to content

Commit

Permalink
Merge pull request #824 from ethereum-oasis-op/develop
Browse files Browse the repository at this point in the history
SRI milestone 5
  • Loading branch information
ognjenkurtic authored Jul 28, 2024
2 parents 1f57a18 + 47ef994 commit 7df0ea5
Show file tree
Hide file tree
Showing 121 changed files with 14,924 additions and 4,381 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/bri-3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ on:
- examples/bri-3/**
branches:
- main
- develop
pull_request:
paths:
- examples/bri-3/**
branches:
- main
- develop

jobs:
ci:
Expand Down Expand Up @@ -44,8 +46,9 @@ jobs:
DID_REGISTRY: "0x03d5003bf0e79c5f5223588f347eba39afbc3818"
DID_BPI_OPERATOR_PUBLIC_KEY: "0x08872e27BC5d78F1FC4590803369492868A1FCCb"
DID_BPI_OPERATOR_PRIVATE_KEY: "2c95d82bcd8851bd3a813c50afafb025228bf8d237e8fd37ba4adba3a7596d58"
DID_NETWORK: "sepolia"
CCSM_NETWORK: "localhost"
INFURA_PROVIDER_API_KEY: "c5f37cd25eca4007a9768f18f492bc6f"
CCSM_BPI_STATE_ANCHOR_CONTRACT_ADDRESS: "0x1CC96ba639d4fd7624913fde39122270a1aC5c34"
SERVICE_URL: "bri-3"
BPI_NATS_SERVER_URL: "localhost:4222"
BPI_NATS_SERVER_USER: "bpi_operator"
Expand Down Expand Up @@ -105,6 +108,16 @@ jobs:
- name: Run prisma db seed
working-directory: examples/bri-3
run: npx prisma db seed

- name: Install hardhat dependencies
working-directory: examples/bri-3/ccsm
run: npm ci

- name: Run hardhat and deploy contracts
working-directory: examples/bri-3/ccsm
run: |
npx hardhat node &
npx hardhat run scripts/deploy.ts
- name: Run e2e tests
working-directory: examples/bri-3
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="localhost" # network used to 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 (0x1CC96ba639d4fd7624913fde39122270a1aC5c34 for local hardhat node)
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"
}
6 changes: 3 additions & 3 deletions examples/bri-3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ $ npm run test -- transactions.agent.spec.ts


```bash
# e2e testing - .e2e.spec files located in ./test folder
# e2e testing - .e2e.spec files and the bash script used for running located in ./test folder
# before running the tests, make sure that postgres and nats are running
# and the database is properly populated with the seed.ts command (explained above)
# also make sure that the .env file contains correct values for DID login to work (as explained in the .env.sample)

$ npm run test:e2e
$ cd test
$ sh ./e2e-test.sh
```

## Architecture
Expand Down
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
```
56 changes: 56 additions & 0 deletions examples/bri-3/ccsm/contracts/CcsmBpiStateAnchor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;

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

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

bytes32 public constant ADMIN_ROLE = keccak256('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
}
}

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

anchorHashStore[_workstepInstanceId] = _anchorHash;

emit AnchorHashSet(_workstepInstanceId, _anchorHash);
}

function getAnchorHash(
string calldata _workstepInstanceId
) external view returns (string memory) {
return anchorHashStore[_workstepInstanceId];
}

modifier onlyAdmin() {
require(
hasRole(ADMIN_ROLE, msg.sender),
'Only admin can call this function'
);
_;
}
}
Loading

0 comments on commit 7df0ea5

Please sign in to comment.