Skip to content

Commit 29f8536

Browse files
feat: Working mulri-party Confidential Escrow implemented successfully
Signed-off-by: Abhinav Prakash <abhinav.prakash319@gmail.com>
1 parent 75c0fcb commit 29f8536

39 files changed

+9339
-48
lines changed

go.mod

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ replace google.golang.org/grpc => google.golang.org/grpc v1.29.1
2323
require (
2424
github.com/client9/misspell v0.3.4
2525
github.com/golang/protobuf v1.5.3
26-
github.com/hyperledger/fabric v1.4.0-rc1.0.20230405174026-695dd57e01c2
26+
github.com/hyperledger-labs/cc-tools v1.0.2
27+
github.com/hyperledger/fabric v2.1.1+incompatible
2728
github.com/hyperledger/fabric-chaincode-go v0.0.0-20230228194215-b84622ba6a7a
2829
github.com/hyperledger/fabric-contract-api-go v1.2.1
2930
github.com/hyperledger/fabric-protos-go v0.3.0
@@ -46,21 +47,12 @@ require (
4647
require (
4748
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
4849
github.com/BurntSushi/toml v1.2.1 // indirect
49-
github.com/IBM/idemix v0.0.2-0.20231107110441-534ea4193b8f // indirect
50-
github.com/IBM/idemix/bccsp/schemes/aries v0.0.0-20231107110234-4cf31dd43660 // indirect
51-
github.com/IBM/idemix/bccsp/schemes/weak-bb v0.0.0-20231107110234-4cf31dd43660 // indirect
52-
github.com/IBM/idemix/bccsp/types v0.0.0-20231107110234-4cf31dd43660 // indirect
53-
github.com/IBM/mathlib v0.0.3-0.20231011094432-44ee0eb539da // indirect
5450
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
5551
github.com/Microsoft/go-winio v0.6.1 // indirect
56-
github.com/ale-linux/aries-framework-go/component/kmscrypto v0.0.0-20231023164747-f3f972769504 // indirect
5752
github.com/benbjohnson/clock v1.3.5 // indirect
5853
github.com/beorn7/perks v1.0.1 // indirect
59-
github.com/bits-and-blooms/bitset v1.7.0 // indirect
6054
github.com/cespare/xxhash/v2 v2.2.0 // indirect
6155
github.com/cloudflare/cfssl v1.4.1 // indirect
62-
github.com/consensys/bavard v0.1.13 // indirect
63-
github.com/consensys/gnark-crypto v0.12.1 // indirect
6456
github.com/containerd/containerd v1.7.13 // indirect
6557
github.com/containerd/log v0.1.0 // indirect
6658
github.com/davecgh/go-spew v1.1.1 // indirect
@@ -85,6 +77,7 @@ require (
8577
github.com/google/certificate-transparency-go v1.0.21 // indirect
8678
github.com/google/go-cmp v0.6.0 // indirect
8779
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b // indirect
80+
github.com/google/uuid v1.3.0 // indirect
8881
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
8982
github.com/hashicorp/hcl v1.0.0 // indirect
9083
github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 // indirect
@@ -93,14 +86,12 @@ require (
9386
github.com/inconshreveable/mousetrap v1.1.0 // indirect
9487
github.com/joho/godotenv v1.4.0 // indirect
9588
github.com/josharian/intern v1.0.0 // indirect
96-
github.com/kilic/bls12-381 v0.1.0 // indirect
9789
github.com/klauspost/compress v1.17.4 // indirect
9890
github.com/magiconair/properties v1.8.7 // indirect
9991
github.com/mailru/easyjson v0.7.7 // indirect
10092
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
10193
github.com/miekg/pkcs11 v1.1.1 // indirect
10294
github.com/mitchellh/mapstructure v1.4.3 // indirect
103-
github.com/mmcloughlin/addchain v0.4.0 // indirect
10495
github.com/moby/docker-image-spec v1.3.1 // indirect
10596
github.com/moby/patternmatcher v0.6.0 // indirect
10697
github.com/moby/sys/sequential v0.5.0 // indirect
@@ -145,5 +136,4 @@ require (
145136
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
146137
gopkg.in/yaml.v3 v3.0.1 // indirect
147138
gotest.tools/v3 v3.5.1 // indirect
148-
rsc.io/tmplfunc v0.0.3 // indirect
149139
)

go.sum

Lines changed: 14 additions & 35 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export CC_ID=confidential-escrow
2+
export CHANNEL_NAME=mychannel
3+
export CORE_PEER_ADDRESS=localhost:7051
4+
export CORE_PEER_ID=peer0.org1.example.com
5+
export CORE_PEER_ORG_NAME=org1
6+
export CORE_PEER_LOCALMSPID=Org1MSP
7+
export CORE_PEER_MSPCONFIGPATH=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
8+
export CORE_PEER_TLS_CERT_FILE=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
9+
export CORE_PEER_TLS_ENABLED="true"
10+
export CORE_PEER_TLS_KEY_FILE=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
11+
export CORE_PEER_TLS_ROOTCERT_FILE=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
12+
export ORDERER_CA=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
13+
export GATEWAY_CONFIG=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml
14+
export FPC_ENABLED=true
15+
export RUN_CCAAS=true
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export CC_ID=confidential-escrow
2+
export CHANNEL_NAME=mychannel
3+
export CORE_PEER_ADDRESS=localhost:9051
4+
export CORE_PEER_ID=peer0.org2.example.com
5+
export CORE_PEER_ORG_NAME=org2
6+
export CORE_PEER_LOCALMSPID=Org2MSP
7+
export CORE_PEER_MSPCONFIGPATH=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
8+
export CORE_PEER_TLS_CERT_FILE=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
9+
export CORE_PEER_TLS_ENABLED="true"
10+
export CORE_PEER_TLS_KEY_FILE=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key
11+
export CORE_PEER_TLS_ROOTCERT_FILE=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
12+
export ORDERER_CA=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
13+
export GATEWAY_CONFIG=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/connection-org2.yaml
14+
export FPC_ENABLED=true
15+
export RUN_CCAAS=true
16+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export CC_ID=confidential-escrow
2+
export CHANNEL_NAME=mychannel
3+
export CORE_PEER_ADDRESS=localhost:7051
4+
export CORE_PEER_ID=peer0.org1.example.com
5+
export CORE_PEER_ORG_NAME=org1
6+
export CORE_PEER_LOCALMSPID=Org1MSP
7+
export CORE_PEER_MSPCONFIGPATH=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
8+
export CORE_PEER_TLS_CERT_FILE=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
9+
export CORE_PEER_TLS_ENABLED="true"
10+
export CORE_PEER_TLS_KEY_FILE=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
11+
export CORE_PEER_TLS_ROOTCERT_FILE=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
12+
export ORDERER_CA=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
13+
export GATEWAY_CONFIG=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml
14+
export FPC_ENABLED=true
15+
export RUN_CCAAS=true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ecc
2+
ecc-bundle
3+
enclave.json
4+
private.pem
5+
public.pem
6+
mrenclave
7+
details.env
8+
9+
.env
10+
*.bak
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
TOP = ../../..
2+
include $(TOP)/ecc_go/build.mk
3+
4+
CC_NAME ?= confidential-escrow
5+
6+
EGO_CONFIG_FILE = $(FPC_PATH)/samples/chaincode/confidential-escrow/confidentialEscrowEnclave.json
7+
ECC_MAIN_FILES=$(FPC_PATH)/samples/chaincode/confidential-escrow
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Confidential Escrow Chaincode
2+
3+
A privacy-preserving escrow system built on Hyperledger Fabric Private Chaincode (FPC) that enables secure digital asset management with programmable conditional payments.
4+
5+
## Overview
6+
7+
This chaincode implements a confidential escrow mechanism for digital assets, combining:
8+
9+
- **Privacy-Preserving Transactions**: All transaction data is encrypted within Intel SGX enclaves
10+
- **Programmable Escrow Contracts**: Automated conditional fund releases based on cryptographic verification
11+
- **Multi-Asset Support**: Manage multiple token types within individual wallets
12+
- **Certificate-Based Authorization**: Fine-grained access control using X.509 certificate hashes
13+
14+
## Architecture
15+
16+
### Core Components
17+
18+
**Assets**
19+
20+
- `DigitalAsset`: Fungible tokens with controlled supply (CBDC, stablecoins, etc.)
21+
- `Wallet`: User accounts supporting multiple asset types with separate available and escrowed balances
22+
- `Escrow`: Smart contracts holding funds pending condition fulfillment
23+
- `UserDirectory`: Privacy-preserving public key to wallet UUID mapping
24+
25+
**Transaction Operations**
26+
27+
- Asset lifecycle: Create, mint, transfer, burn
28+
- Wallet management: Create wallets, query balances
29+
- Escrow workflow: Lock funds, verify conditions, release or refund
30+
31+
## Project Structure
32+
33+
```
34+
confidential-escrow/
35+
├── chaincode/
36+
│ ├── assets/ # Asset type definitions
37+
│ ├── transactions/ # Transaction handlers
38+
│ ├── header/ # Chaincode metadata
39+
│ ├── escrow.go # Main chaincode implementation
40+
│ ├── server.go # CCaaS server setup
41+
│ └── setup.go # Component registration
42+
├── main.go # Entry point
43+
├── main.sh # Deployment and test automation
44+
└── README.md # This file
45+
```
46+
47+
### Security Model
48+
49+
1. **Access Control**: All operations require valid certificate hash verification
50+
2. **Atomic Escrow**: Funds move from available to escrowed balance during lock, preventing double-spending
51+
3. **Condition Verification**: SHA-256 hash of `(secret + parcelId)` ensures only authorized parties can release funds
52+
4. **Confidential Execution**: FPC ensures transaction details remain private within SGX enclaves
53+
54+
## Running Procedure
55+
56+
### Prerequisites
57+
58+
- FPC is properly set up and built
59+
- `multi_user_dashboard.sh ` script is placed in the chaincode directory
60+
- `.env.alice` and `.env.bob` file is present
61+
62+
### Setup Files
63+
64+
**1. Set FPC_PATH:**
65+
66+
```bash
67+
export FPC_PATH=/project/src/github.com/hyperledger/fabric-private-chaincode
68+
```
69+
70+
### Running Procedure
71+
72+
#### 1. In 1st terminal window - Setup and Deploy
73+
74+
```bash
75+
# Get inside dev env
76+
make -C $FPC_PATH/utils/docker run-dev
77+
cd samples/chaincode/confidential-escrow
78+
79+
# Interactive menu
80+
./multi_user_dashboard.sh
81+
82+
# Choose Option 1. or 2. as per your setup condn
83+
```
84+
85+
#### 2. In 2nd terminal window - Docker Environment (`Alice`)
86+
87+
```bash
88+
# Enter docker container
89+
docker exec -it fpc-development-main /bin/bash
90+
cd samples/chaincode/confidential-escrow
91+
92+
# Interactive menu
93+
./multi_user_dashboard.sh
94+
95+
# Setup Alice using Option 3.
96+
```
97+
98+
#### 3. In 3rd terminal window - Docker Environment (`Bob`)
99+
100+
```bash
101+
# Enter docker container
102+
docker exec -it fpc-development-main /bin/bash
103+
cd samples/chaincode/confidential-escrow
104+
105+
# Interactive menu
106+
./multi_user_dashboard.sh
107+
108+
# Setup Bob using Option 4.
109+
```
110+
111+
#### 4. In 3rd terminal window - Docker Environment (`Monitor`)
112+
113+
```bash
114+
# Enter docker container
115+
docker exec -it fpc-development-main /bin/bash
116+
cd samples/chaincode/confidential-escrow
117+
118+
# Interactive menu
119+
./multi_user_dashboard.sh
120+
121+
# Setup Bob using Option 5.
122+
```
123+
124+
#### 5. Run Tests
125+
126+
```bash
127+
# Run all basic tests
128+
./multi_user_dashboard.sh
129+
130+
# Chosing Option 7.
131+
```
132+
133+
## Contributing
134+
135+
When adding new features:
136+
137+
1. Define asset types in `chaincode/assets/`
138+
2. Implement transaction logic in `chaincode/transactions/`
139+
3. Register new components in `chaincode/setup.go`
140+
4. Add test cases to `main.sh`
141+
5. Update this README with usage examples
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package assets
2+
3+
import (
4+
"github.com/hyperledger-labs/cc-tools/assets"
5+
)
6+
7+
// DigitalAssetToken defines the asset type for fungible digital tokens.
8+
// This represents confidential digital currencies such as Central Bank Digital Currencies (CBDC)
9+
// or tokenized assets. Each token type has a fixed supply controlled by the issuer.
10+
//
11+
// Security: The issuerHash ensures only authorized entities can mint/burn tokens.
12+
var DigitalAssetToken = assets.AssetType{
13+
Tag: "digitalAsset",
14+
Label: "Digital Asset Token",
15+
Description: "Confidential digital currency token (e.g., CBDC)",
16+
17+
Props: []assets.AssetProp{
18+
{
19+
Tag: "name",
20+
Label: "Token Name",
21+
DataType: "string",
22+
Required: true,
23+
},
24+
{
25+
Tag: "symbol",
26+
Label: "Token Symbol",
27+
DataType: "string",
28+
Required: true,
29+
IsKey: true,
30+
},
31+
{
32+
Tag: "decimals",
33+
Label: "Decimal Places",
34+
DataType: "number",
35+
Required: true,
36+
},
37+
{
38+
Tag: "totalSupply",
39+
Label: "Total Supply",
40+
DataType: "number",
41+
Required: true,
42+
},
43+
{
44+
Tag: "issuerHash",
45+
Label: "Issuer Certificate Hash",
46+
DataType: "string",
47+
Required: true,
48+
},
49+
{
50+
Tag: "owner",
51+
Label: "Owner Identity",
52+
DataType: "string",
53+
Required: true,
54+
},
55+
{
56+
Tag: "issuedAt",
57+
Label: "Issued At",
58+
DataType: "datetime",
59+
Required: false,
60+
},
61+
},
62+
}

0 commit comments

Comments
 (0)