Skip to content

Commit

Permalink
feat: add private HTLC base
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Belchior <[email protected]>

feat: improve hash time lock base

Signed-off-by: Rafael Belchior <[email protected]>

feat: add privacy helper offchain relayer

Signed-off-by: Rafael Belchior <[email protected]>

feat: add private HTLC draft (wip)

Signed-off-by: Rafael Belchior <[email protected]>

chore: add configuration files

Signed-off-by: Rafael Belchior <[email protected]>

chore: recompile contracts

Signed-off-by: Rafael Belchior <[email protected]>

test(wip): private htlc

Signed-off-by: Rafael Belchior <[email protected]>

feat: private htlc verifications

Signed-off-by: Rafael Belchior <[email protected]>

docs: update documentation and configs

Signed-off-by: Rafael Belchior <[email protected]>

test: private HTLC (wip)

Signed-off-by: Rafael Belchior <[email protected]>

chore: config files and artefacts

Signed-off-by: Rafael Belchior <[email protected]>

feat: private htlc

Signed-off-by: Rafael Belchior <[email protected]>

feat: fix bug in proof verification

Signed-off-by: Rafael Belchior <[email protected]>

chore: lint contracts

Signed-off-by: Rafael Belchior <[email protected]>

chore: use hardcoded variable for contract name

Signed-off-by: Rafael Belchior <[email protected]>

feat: privacy enhancements

Signed-off-by: Rafael Belchior <[email protected]>

feat: update offchain relayer

Signed-off-by: Rafael Belchior <[email protected]>
  • Loading branch information
RafaelAPB committed May 9, 2023
1 parent 839177c commit d16f60c
Show file tree
Hide file tree
Showing 43 changed files with 6,004 additions and 17,613 deletions.
8 changes: 3 additions & 5 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"JORDI",
"jsrsa",
"jsrsasign",
"keccak",
"Keychain",
"Keycloak",
"KEYUTIL",
Expand Down Expand Up @@ -103,6 +104,7 @@
"openethereum",
"organisation",
"Orgs",
"ossp",
"parameterizable",
"Postgres",
"proto",
Expand Down Expand Up @@ -139,11 +141,7 @@
"uuidv",
"vscc",
"wasm",
"Xdai",
"goquorum",
"hada",
"undici",
"ossp"
"Xdai"
],
"dictionaries": [
"typescript,node,npm,go,rust"
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ packages/cactus-cmd-socketio-server/**
packages/cactus-plugin-ledger-connector-sawtooth-socketio/**
packages/cactus-plugin-ledger-connector-go-ethereum-socketio/**
packages/cactus-plugin-ledger-connector-*-socketio/**
packages/cactus-plugin-htlc-eth-besu/vendor/**

weaver/**
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "packages/cactus-plugin-htlc-eth-besu/vendor/oz"]
path = packages/cactus-plugin-htlc-eth-besu/vendor/oz
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "packages/cactus-plugin-htlc-eth-besu/vendor/forge-std"]
path = packages/cactus-plugin-htlc-eth-besu/vendor/forge-std
url = https://github.com/foundry-rs/forge-std
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ test(testCase, async (t: Test) => {
JSON.stringify(DemoHelperJSON),
);
keychainPlugin.set(
HashTimeLockJSON.contractName,
"Hashed Time Lock Contract v0.1",
JSON.stringify(HashTimeLockJSON),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test(testCase, async (t: Test) => {
JSON.stringify(DemoHelperJSON),
);
keychainPlugin.set(
HashTimeLockJSON.contractName,
"Hashed Time Lock Contract v0.1",
JSON.stringify(HashTimeLockJSON),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test(testCase, async (t: Test) => {
JSON.stringify(DemoHelperJSON),
);
keychainPlugin.set(
HashTimeLockJSON.contractName,
"Hashed Time Lock Contract v0.1",
JSON.stringify(HashTimeLockJSON),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test(testCase, async (t: Test) => {
JSON.stringify(DemoHelperJSON),
);
keychainPlugin.set(
HashTimeLockJSON.contractName,
"Hashed Time Lock Contract v0.1",
JSON.stringify(HashTimeLockJSON),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class PluginHtlcEthBesuErc20
) as PluginLedgerConnectorBesu;

const hashedTimeLockResponse = await connector.deployContract({
contractName: HashTimeLockJSON.contractName,
contractName: "Hashed Time Lock Contract v0.1",
contractAbi: HashTimeLockJSON.abi,
bytecode: HashTimeLockJSON.bytecode,
web3SigningCredential: initializeRequest.web3SigningCredential,
Expand Down Expand Up @@ -187,7 +187,7 @@ export class PluginHtlcEthBesuErc20
) as PluginLedgerConnectorBesu;

const result = await connector.invokeContract({
contractName: HashTimeLockJSON.contractName,
contractName: "Hashed Time Lock Contract v0.1",
keychainId: newContractRequest.keychainId,
signingCredential: newContractRequest.web3SigningCredential,
contractAddress: newContractRequest.contractAddress,
Expand All @@ -208,7 +208,7 @@ export class PluginHtlcEthBesuErc20
) as PluginLedgerConnectorBesu;

const result = await connector.invokeContract({
contractName: HashTimeLockJSON.contractName,
contractName: "Hashed Time Lock Contract v0.1",
keychainId: refundRequest.keychainId,
signingCredential: refundRequest.web3SigningCredential,
invocationType: EthContractInvocationType.Send,
Expand All @@ -228,7 +228,7 @@ export class PluginHtlcEthBesuErc20
) as PluginLedgerConnectorBesu;
const params = [withdrawRequest.id, withdrawRequest.secret];
const result = await connector.invokeContract({
contractName: HashTimeLockJSON.contractName,
contractName: "Hashed Time Lock Contract v0.1",
keychainId: withdrawRequest.keychainId,
signingCredential: withdrawRequest.web3SigningCredential,
invocationType: EthContractInvocationType.Send,
Expand All @@ -248,7 +248,7 @@ export class PluginHtlcEthBesuErc20
) as PluginLedgerConnectorBesu;

const result = await connector.invokeContract({
contractName: HashTimeLockJSON.contractName,
contractName: "Hashed Time Lock Contract v0.1",
signingCredential: req.web3SigningCredential,
invocationType: EthContractInvocationType.Call,
methodName: "getSingleStatus",
Expand All @@ -266,7 +266,7 @@ export class PluginHtlcEthBesuErc20
) as PluginLedgerConnectorBesu;

const result = await connector.invokeContract({
contractName: HashTimeLockJSON.contractName,
contractName: "Hashed Time Lock Contract v0.1",
signingCredential: req.web3SigningCredential,
invocationType: EthContractInvocationType.Call,
methodName: "getStatus",
Expand Down
4 changes: 4 additions & 0 deletions packages/cactus-plugin-htlc-eth-besu/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
cache
lib
vendor
15 changes: 15 additions & 0 deletions packages/cactus-plugin-htlc-eth-besu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ your local machine for development and testing purposes.

### Installing

Install Foundry: https://book.getfoundry.sh/getting-started/installation

Initialize git submodules: `git submodule update --init --recursive`

If it does not work, add each manually:
`git submodule add --force https://github.com/OpenZeppelin/openzeppelin-contracts vendor/oz`
`git submodule add --force https://github.com/foundry-rs/forge-std vendor/forge-std`

Steps to compile the project:

In a `Cactus` root directory execute:
Expand All @@ -35,6 +43,13 @@ The tests can be found in @hyperledger/cactus-test-htlc-eth-besu. To run this, i
npm run test:plugin-htlc-besu
```

To run the solidity tests (within the root directory of this package):
`forge test --match-contract PrivateHashTimeLockTest`

To run a specific function:
`forge test --match-contract PrivateHashTimeLockTest --match-test testDeployment`


## Contributing

We welcome contributions to Hyperledger Cactus in many forms, and there’s always plenty to do!
Expand Down
42 changes: 42 additions & 0 deletions packages/cactus-plugin-htlc-eth-besu/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Foundry Configuration File
# Default definitions: https://github.com/gakonst/foundry/blob/b7917fa8491aedda4dd6db53fbb206ea233cd531/config/src/lib.rs#L782
# See more config options at: https://github.com/gakonst/foundry/tree/master/config

[profile.default]
# The source directory
src = './src/main/solidity/contracts'
# The test directory
test = 'src/test/solidity/integration'
# The script directory
script = './src/main/solidity/contracts/scripts'
# The artifact directory
out = 'build'
solc_version = '0.8.19'
auto_detect_solc = false
optimizer_runs = 1_000
sender = '0x00a329c0648769a73afac7f9381e08fb43dbea72' # the address of `msg.sender` in tests
tx_origin = '0x00a329c0648769a73afac7f9381e08fb43dbea72' # the address of `tx.origin` in tests
block_number = 0 # the block number we are at in tests
chain_id = 99 # the chain id we are on in tests
gas_limit = 9223372036854775807 # the gas limit in tests
gas_reports = ['*']
gas_price = 0 # the gas price (in wei) in tests
block_base_fee_per_gas = 0 # the base fee (in wei) in tests
block_coinbase = '0x0000000000000000000000000000000000000000' # the address of `block.coinbase` in tests
block_timestamp = 0 # the value of `block.timestamp` in tests
block_difficulty = 0
fuzz = { runs = 256 } # the number of fuzz runs for tests


# Fuzzing CI
[profile.ci]
fuzz_runs = 100_00
verbosity = 4

[rpc_endpoints]
goerli = "${RPC_URL_GOERLI}"
mainnet = "${RPC_URL_MAINNET}"

[etherscan]
goerli = {key = "${ETHERSCAN_KEY}", url = "https://api-goerli.etherscan.io/api"}
mainnet = {key = "${ETHERSCAN_KEY}"}
19 changes: 15 additions & 4 deletions packages/cactus-plugin-htlc-eth-besu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
"name": "Azahara Castaño",
"email": "[email protected]",
"url": "https://accenture.com"
},
{
"name": "Rafael Belchior",
"email": "[email protected]",
"url": "https://rafaelapb.github.io/"
}
],
"main": "dist/lib/main/typescript/index.js",
Expand All @@ -52,11 +57,13 @@
"codegen:openapi": "npm run generate-sdk",
"generate-sdk": "run-p generate-sdk:*",
"generate-sdk:typescript-axios": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g typescript-axios -o ./src/main/typescript/generated/openapi/typescript-axios/ --reserved-words-mappings protected=protected",
"lint": "solhint --fix",
"watch": "npm-watch",
"webpack": "npm-run-all webpack:dev",
"webpack:dev": "npm-run-all webpack:dev:node webpack:dev:web",
"webpack:dev:node": "webpack --env=dev --target=node --config ../../webpack.config.js",
"webpack:dev:web": "webpack --env=dev --target=web --config ../../webpack.config.js"
"webpack:dev:web": "webpack --env=dev --target=web --config ../../webpack.config.js",
"compile-contracts": "forge build"
},
"dependencies": {
"@hyperledger/cactus-common": "1.2.0",
Expand All @@ -66,18 +73,22 @@
"@hyperledger/cactus-plugin-ledger-connector-besu": "1.2.0",
"@hyperledger/cactus-test-tooling": "1.2.0",
"axios": "0.21.4",
"bn.js": "5.2.1",
"dotenv": "16.0.3",
"ethers": "6.3.0",
"express": "4.17.1",
"joi": "17.9.1",
"openapi-types": "9.1.0",
"typescript-optional": "2.0.1",
"web3": "1.5.2",
"web3js-quorum": "21.7.0-rc1"
},
"devDependencies": {
"@hyperledger/cactus-plugin-keychain-memory": "1.2.0",
"@hyperledger/cactus-test-tooling": "1.2.0",
"@types/express": "4.17.13"
},
"@types/express": "4.17.13",
"@types/bn.js": "5.1.1",
"solhint": "3.4.1"
},
"engines": {
"node": ">=10",
"npm": ">=6"
Expand Down
2 changes: 2 additions & 0 deletions packages/cactus-plugin-htlc-eth-besu/remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
forge-std/=vendor/forge-std/src/
ds-test/=vendor/forge-std/lib/ds-test/src/
Loading

0 comments on commit d16f60c

Please sign in to comment.