Overview
This repository contains an implementation of an HTTP(S) server and a smart contract for audit log. The audit log targets data transfer scenarios under International Data Spaces (IDSA) in specific to the workflow of Eclipse EDC data connectors. The smart contract implementation assumes the blockchain is Ethereum-compatible.
HTTP Server
The HTTP(S) server provides four APIs for logging information on the start and end of (i) contract negotiation and (ii) data transfer.
The server API specification can be found in http-server-openapi.yaml
.
Smart Contract for Audit Logging
The smart contract tracks the established contracts and their data transfer progress. It emits events to an Ethereum-compatible blockchain to log the operation metadata to the blockchain.
Tools
Tools for reading back (and decoding) the information logged in the blockchain are also provided as a reference for further development.
-
Download and install the prerequisites - Nodejs, following the guide at Nodejs official site: https://nodejs.org/en/download
- The recommended (and tested) versions are as follows for reference
node
: v20.12.2npm
: 10.5.0
- The recommended (and tested) versions are as follows for reference
-
Install the required Nodejs packages
npm install
The following provides the steps to run the system in an local environment as an example.
To run with a private/public blockchain, specify the correct blockchain JSON-RPC endpoints and wallet (public and private keys) for smart contract deployment and server run.
-
Go to the 'smart_contracts' folder
cd smart_contracts
-
Compile the smart contract using Hardhat compiler
npx hardhat compile
-
Go back to the root folder
cd ..
In a new terminal,
-
Go to the smart contract folder
cd smart_contracts
-
Run a local Hardhat single-node blockchain
npx hardhat node
which gives an output similar to the following on success.
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/ Accounts ======== WARNING: These accounts, and their private keys, are publicly known. Any funds sent to them on Mainnet or any other live network WILL BE LOST. Account #0: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (10000 ETH) Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 Account #1: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 (10000 ETH) Private Key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d Account #2: 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC (10000 ETH) Private Key: 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a Account #3: 0x90F79bf6EB2c4f870365E785982E1f101E93b906 (10000 ETH) Private Key: 0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6 Account #4: 0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65 (10000 ETH) Private Key: 0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a
The JSON-RPC endpoint is therefore 'http://127.0.0.1:8545/'. We can pick a pair of private and public keys from any account, e.g., for account #0, the public key '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' and the private key '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'.
In the original terminal,
-
Go to the 'tools' folder
cd tools
-
Update the JSON-RPC endpoint (
<json-rpc endpoint>
), wallet private key (<wallet private key>
), and wallet public key (<wallet public key>
) inconfig.js
module.exports = { ethereum: { endpoint: '<json-rpc endpoint>', private_key: '<wallet private key>', public_key: '<wallet public key>' }, contract: { abi_file_path: '../smart_contracts/artifacts/contracts/DataTransferAuditLog.sol/DataTransferAuditLog.json' } };
-
Run
deploy_contract.js
to deploy the contractnode deploy_contract.js
which gives an output similar to the following on success.
Deployer account: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (node:5046) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead. (Use `node --trace-deprecation ...` to show where the warning was created) Estimated gas: 2231966n Contract deployed at address: 0x5FbDB2315678afecb367f032d93F642f64180aa3
And here shows the contract address in the blockchain is '0x5FbDB2315678afecb367f032d93F642f64180aa3'.
-
Go back to the root folder
cd ..
In a new terminal,
-
Go to the 'server/src' folder
cd server/src
-
Update the JSON-RPC endpoint (
<json-rpc endpoint>
), wallet private key (<wallet private key>
), wallet public key (<wallet public key>
), and deployed contract address (<contract address>
) inconfig.js
. The wallet should be different from that used for contract deployment.module.exports = { server: { port: 3000, api_key: "myapikey1234", ssl: { key_file_path: '', cert_file_path: '', } }, contract: { abi_file_path: '../../smart_contracts/artifacts/contracts/DataTransferAuditLog.sol/DataTransferAuditLog.json', }, ethereum: { endpoint: '<json-rpc endpoint>', private_key: '<wallet private key>', public_key: '<wallet public key>', contract_address: '<contract address>' }, misc: { check_ssl_cert: false, async_save_activity: false, }, };
-
Start the server
node index.js
In the original terminal,
-
Log the start of a contract negotiation
curl -v http://localhost:3000/contract/negotiation/start -X POST -H 'api_key:myapikey1234' -d@resources/contract_negotiation_start.json
-
Log the end a contract negotiation
curl -v http://localhost:3000/contract/negotiation/end -X POST -H 'api_key:myapikey1234' -d@resources/contract_negotiation_end.json
-
Log the start of a data transfer
curl -v http://localhost:3000/transfer/start -X POST -H 'api_key:myapikey1234' -d@resources/data_transfer_start.json
-
Log the end of a data transfer
curl -v http://localhost:3000/transfer/end -X POST -H 'api_key:myapikey1234' -d@resources/data_transfer_end.json
-
Go to the tools folder
cd tools
-
Display the logs in the blockchain
node get_logs.js
The HTTP server configuration file is server/src/config.js
. Following are the options.
server
: HTTP server endpointport
: server portapi_key
: API key for authenticationssl
key_file_path
: Path to the SSL/TLS private key filecert_file_path
: Path to the SSL/TLS certificate file
contract
: Smart contractabi_file_path
: Path to the ABI (application binary interface) specification for the blockchain smart contract
ethereum
: Blockchainendpoint
: Blockchain JSON-RPC endpointprivate_key
: Blockchain wallet private keypublic_key
: Blockchain wallet public keycontract_address
: Address of the deployed audit logging smart contract on the blockcahin
server/
: Source code for the HTTP serversmart_contracts/
: Smart contract for audit log, test scripts and configurations for Hardhattools/
: Scripts for contract deployment and log browsingresources/
: Example request bodies for each API (for API testing)
-
Go to the smart contract folder
cd smart_contracts
-
Test the smart contract via Hardhat
npx hardhat test