-
Notifications
You must be signed in to change notification settings - Fork 98
fix::> confidential escrow example - LFX25 #831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6b30633
fix::> init confidential escrow
PsychoPunkSage 84833e9
fix::> Added Create and read transaction
PsychoPunkSage 2b1f157
fix::>> changed some of the params
PsychoPunkSage 292094e
fix::> integrated txns
PsychoPunkSage 3e597b7
fix::> README.md updated
PsychoPunkSage 8da643c
fix::> 2 automation script added
PsychoPunkSage 51eab0f
fix::> Changed ACLs and corrected READ logics fo alll assets
PsychoPunkSage a144e96
fix::>> Removed/cleanup unnecessary fields
PsychoPunkSage 9dbf17c
fix::>> made a unified setup scripts. source file and cleaneup useles…
PsychoPunkSage 359f381
fix::> Made a minimalistic main.go + a dedicated go modules for this …
PsychoPunkSage 2061cb0
fix::>> modified ssets den
PsychoPunkSage b672204
fix::> Modified CRUD ops based on changes
PsychoPunkSage 6a177c2
fix::> Made main script bit more slimer + updated Readme
PsychoPunkSage fd350c8
update setup.go with new functionality
PsychoPunkSage e416c3e
fix::> Addn of new functionality for Token... + cleanup
PsychoPunkSage 9cfd367
fix::> Get balance + get wallet by owner added
PsychoPunkSage bdb3fec
fix::> Updated scripts
PsychoPunkSage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ecc | ||
| ecc-bundle | ||
| enclave.json | ||
| private.pem | ||
| public.pem | ||
| mrenclave | ||
| details.env | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| TOP = ../../.. | ||
| include $(TOP)/ecc_go/build.mk | ||
|
|
||
| CC_NAME ?= confidential-escrow | ||
|
|
||
| EGO_CONFIG_FILE = $(FPC_PATH)/samples/chaincode/confidential-escrow/confidentialEscrowEnclave.json | ||
| ECC_MAIN_FILES=$(FPC_PATH)/samples/chaincode/confidential-escrow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| ## Optimal Project Structure | ||
|
|
||
| ``` | ||
| $FPC_PATH/samples/chaincode/confidential-escrow/ | ||
| ├── main.go # FPC chaincode entry point | ||
| ├── Makefile # Build configuration | ||
| ├── confidential-escrow-compose.yaml # Docker compose for ECC services | ||
| ├── confidentialEscrowEnclave.json # SGX enclave configuration | ||
| ├── setup.sh # Project setup script | ||
| ├── testTutorial.sh # Testing script | ||
| ├── chaincode/ | ||
| │ ├── confidential_escrow.go # Main chaincode logic | ||
| │ ├── assets/ | ||
| │ │ ├── digital_asset.go # Digital asset token structure | ||
| │ │ ├── wallet.go # Wallet structure and operations | ||
| │ │ ├── escrow.go # Escrow contract structure | ||
| │ │ └── user_directory.go # User directory mapping | ||
| │ ├── transactions/ | ||
| │ │ ├── wallet_ops.go # Wallet creation, balance queries | ||
| │ │ ├── token_ops.go # Mint, transfer operations | ||
| │ │ ├── escrow_ops.go # Escrow creation, release, refund | ||
| │ │ └── admin_ops.go # Admin functions, schema queries | ||
| │ └── utils/ | ||
| │ ├── crypto_utils.go # Hashing, signature verification | ||
| │ ├── auth_utils.go # Certificate-based authentication | ||
| │ └── validation_utils.go # Input validation and checks | ||
| ├── go.mod # Go module dependencies | ||
| ├── go.sum # Dependency checksums | ||
| └── README.md # Project documentation | ||
| ``` | ||
|
|
||
| ## Revised Implementation Plan (12 Weeks) | ||
|
|
||
| ### Phase 1: FPC Environment & Project Bootstrap (Week 1-2) | ||
|
|
||
| #### Step 1: FPC Environment Verification | ||
|
|
||
| - Verify existing FPC setup and SGX functionality | ||
| - Test existing examples (kv-test-go, cc-tools-demo) | ||
| - Understand FPC build process and deployment workflow | ||
| - Study the existing sample structures and patterns | ||
|
|
||
| #### Step 2: Project Structure Creation | ||
|
|
||
| - Create `confidential-escrow` directory in `$FPC_PATH/samples/chaincode/` | ||
| - Copy and adapt `main.go` from kv-test-go (use CHAINCODE_PKG_ID pattern) | ||
| - Create basic `Makefile` following existing examples | ||
| - Set up `confidentialEscrowEnclave.json` with proper SGX configuration | ||
| - Create `confidential-escrow-compose.yaml` for ECC services | ||
|
|
||
| #### Step 3: Basic Chaincode Shell | ||
|
|
||
| - Implement basic chaincode structure with function dispatcher (like kv-test pattern) | ||
| - Add initialization logic and basic error handling | ||
| - Create placeholder transaction functions | ||
| - Test basic deployment and invocation using FPC tutorial steps | ||
|
|
||
| ### Phase 2: Core Data Models & Basic Operations (Week 3-4) | ||
|
|
||
| #### Step 4: Asset Structure Implementation | ||
|
|
||
| - Implement Digital Asset Token struct in `assets/digital_asset.go` | ||
| - Create Wallet struct with encrypted balance in `assets/wallet.go` | ||
| - Implement UserDirectory mapping in `assets/user_directory.go` | ||
| - Add basic serialization/deserialization using JSON | ||
| - Test basic state storage and retrieval | ||
|
|
||
| #### Step 5: Cryptographic & Authentication Utilities | ||
|
|
||
| - Implement SHA-256 hashing in `utils/crypto_utils.go` | ||
| - Add ECDSA signature verification utilities | ||
| - Create certificate handling in `utils/auth_utils.go` using `stub.GetCreator()` | ||
| - Implement UUID generation for wallet and escrow IDs | ||
| - Add input validation framework in `utils/validation_utils.go` | ||
|
|
||
| #### Step 6: Basic Ledger Operations | ||
|
|
||
| - Implement key formatting (userdir:hash, wallet:uuid patterns) | ||
| - Create secure state read/write operations within SGX | ||
| - Add basic CRUD operations for each asset type | ||
| - Test data persistence and retrieval through FPC client | ||
| - Verify data confidentiality (peers see encrypted blobs only) | ||
|
|
||
| ### Phase 3: Wallet Management System (Week 5-6) | ||
|
|
||
| #### Step 7: Wallet Creation & Authentication | ||
|
|
||
| - Implement `createWallet` transaction in `transactions/wallet_ops.go` | ||
| - Add certificate-based user authentication using `stub.GetCreator()` | ||
| - Create userdir mapping and wallet ID generation | ||
| - Test wallet creation through FPC client | ||
| - Verify ownership authentication works correctly | ||
|
|
||
| #### Step 8: Wallet Operations & Token Management | ||
|
|
||
| - Implement `getBalance` with proper access control | ||
| - Create `mintToken` transaction (issuer-only) in `transactions/token_ops.go` | ||
| - Add `transferToken` transaction with balance validation | ||
| - Implement proper balance updates and overflow protection | ||
| - Test all wallet operations end-to-end | ||
|
|
||
| #### Step 9: Advanced Wallet Features | ||
|
|
||
| - Add wallet metadata management | ||
| - Implement audit trails for token operations | ||
| - Create role-based access control (issuer vs users) | ||
| - Add comprehensive error handling and validation | ||
| - Performance testing for wallet operations | ||
|
|
||
| ### Phase 4: Escrow System Core (Week 7-8) | ||
|
|
||
| #### Step 10: Escrow Contract Foundation | ||
|
|
||
| - Implement Escrow struct in `assets/escrow.go` | ||
| - Create `createEscrow` transaction in `transactions/escrow_ops.go` | ||
| - Add fund locking mechanism (debit buyer wallet) | ||
| - Implement escrow status management (Active, Released, Refunded) | ||
| - Test basic escrow creation and fund locking | ||
|
|
||
| #### Step 11: Condition System Implementation | ||
|
|
||
| - Implement hashlock condition verification (SHA-256 matching) | ||
| - Add signature-based condition verification (ECDSA) | ||
| - Create condition evaluation engine within SGX | ||
| - Test condition verification with test secrets/signatures | ||
| - Add proper error handling for invalid conditions | ||
|
|
||
| #### Step 12: Fund Release & Refund Mechanisms | ||
|
|
||
| - Implement `releaseEscrow` transaction for successful conditions | ||
| - Add automatic fund transfer from escrow to seller wallet | ||
| - Create `refundEscrow` transaction for failed/expired escrows | ||
| - Implement comprehensive escrow state updates | ||
| - Test complete escrow lifecycle (create → condition → release) | ||
|
|
||
| ### Phase 5: Integration & Advanced Features (Week 9-10) | ||
|
|
||
| #### Step 13: FPC Client Integration & Testing | ||
|
|
||
| - Create comprehensive test suite using FPC client | ||
| - Test all transactions through encrypted FPC communication | ||
| - Verify end-to-end privacy (no data leakage to peers) | ||
| - Performance benchmarking and optimization | ||
| - Load testing with multiple concurrent operations | ||
|
|
||
| #### Step 14: Advanced Escrow Features | ||
|
|
||
| - Implement multi-condition escrows (AND/OR logic) | ||
| - Add partial release mechanisms | ||
| - Create escrow templates for common use cases | ||
| - Implement escrow modification and extension capabilities | ||
| - Add dispute resolution framework basics | ||
|
|
||
| #### Step 15: Security Hardening & Optimization | ||
|
|
||
| - Comprehensive input validation and sanitization | ||
| - Protection against common attack vectors | ||
| - Secure error handling without information leakage | ||
| - Memory optimization for SGX enclave | ||
| - Rate limiting and DoS protection | ||
|
|
||
| ### Phase 6: Production Features & Documentation (Week 11-12) | ||
|
|
||
| #### Step 16: Demo Application & Real-world Scenarios | ||
|
|
||
| - Create client application demonstrating all features | ||
| - Implement atomic swaps between different asset types | ||
| - Add multi-party escrow scenarios | ||
| - Test cross-chain escrow capabilities (if applicable) | ||
| - Create realistic use case demonstrations | ||
|
|
||
| #### Step 17: Documentation & Deployment | ||
|
|
||
| - Comprehensive API documentation | ||
| - Deployment guides and configuration management | ||
| - User manuals and tutorials | ||
| - Troubleshooting guides and FAQs | ||
| - Security best practices documentation | ||
|
|
||
| #### Step 18: Final Testing & Optimization | ||
|
|
||
| - End-to-end system testing | ||
| - Security audit and penetration testing | ||
| - Performance optimization and tuning | ||
| - Final integration testing with all components | ||
| - Production readiness assessment | ||
|
|
||
| ## Key Differences from Original Plan: | ||
|
|
||
| ### **Simplified Structure:** | ||
|
|
||
| - Single chaincode following FPC patterns instead of complex CC-Tools integration | ||
| - Direct implementation in FPC repository for easier dependency management | ||
| - Follows existing sample patterns (kv-test-go structure) | ||
|
|
||
| ### **FPC-Specific Considerations:** | ||
|
|
||
| - All sensitive operations run inside SGX enclave | ||
| - Use `CHAINCODE_PKG_ID` instead of `CHAINCODE_ID` | ||
| - Follow FPC build and deployment patterns | ||
| - Leverage existing FPC infrastructure and tooling | ||
|
|
||
| ### **Reduced Complexity:** | ||
|
|
||
| - Focus on core functionality first | ||
| - Avoid CC-Tools integration complexity initially | ||
| - Use proven FPC patterns and structures | ||
| - Streamlined 12-week timeline | ||
|
|
||
| ### **Testing Approach:** | ||
|
|
||
| - Use FPC client for all testing | ||
| - Follow existing tutorial patterns | ||
| - Test privacy and confidentiality at each step | ||
| - Continuous integration with FPC deployment process |
46 changes: 46 additions & 0 deletions
46
samples/chaincode/confidential-escrow/chaincode/assets/digital_asset.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package assets | ||
|
|
||
| import ( | ||
| "github.com/hyperledger-labs/cc-tools/assets" | ||
| ) | ||
|
|
||
| var DigitalAssetToken = assets.AssetType{ | ||
| Tag: "digitalAsset", | ||
| Label: "Digital Asset Token", | ||
| Description: "Confidential digital currency token (e.g., CBDC)", | ||
|
|
||
| Props: []assets.AssetProp{ | ||
| { | ||
| Tag: "name", | ||
| Label: "Token Name", | ||
| DataType: "string", | ||
| Required: true, | ||
| }, | ||
| { | ||
| Tag: "symbol", | ||
| Label: "Token Symbol", | ||
| DataType: "string", | ||
| Required: true, | ||
| }, | ||
| { | ||
| Tag: "decimals", | ||
| Label: "Decimal Places", | ||
| DataType: "number", | ||
| Required: true, | ||
| }, | ||
| { | ||
| Tag: "totalSupply", | ||
| Label: "Total Supply", | ||
| DataType: "number", | ||
| Required: true, | ||
| }, | ||
| { | ||
| Tag: "issuerHash", | ||
| Label: "Issuer Certificate Hash", | ||
| DataType: "string", | ||
| Required: true, | ||
| }, | ||
| }, | ||
|
|
||
| Readers: []string{"$org1MSP", "$org2MSP"}, | ||
PsychoPunkSage marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
35 changes: 35 additions & 0 deletions
35
samples/chaincode/confidential-escrow/chaincode/assets/user_directory.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package assets | ||
|
|
||
| import ( | ||
| "github.com/hyperledger-labs/cc-tools/assets" | ||
| ) | ||
|
|
||
| var UserDirectory = assets.AssetType{ | ||
| Tag: "userdir", | ||
| Label: "User Directory", | ||
| Description: "Maps user public key hash to wallet ID for authentication", | ||
|
|
||
| Props: []assets.AssetProp{ | ||
| { | ||
| Tag: "publicKeyHash", | ||
| Label: "Public Key Hash", | ||
| DataType: "String", | ||
| Required: true, | ||
| IsKey: true, | ||
| }, | ||
| { | ||
| Tag: "walletId", | ||
| Label: "Associated Wallet ID", | ||
| DataType: "string", | ||
| Required: true, | ||
| }, | ||
| { | ||
| Tag: "certHash", | ||
| Label: "Certificate Hash", | ||
| DataType: "string", | ||
| Required: true, | ||
| }, | ||
| }, | ||
|
|
||
| Readers: []string{"$org1MSP", "$org2MSP"}, | ||
| } |
48 changes: 48 additions & 0 deletions
48
samples/chaincode/confidential-escrow/chaincode/assets/wallet.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package assets | ||
|
|
||
| import ( | ||
| "github.com/hyperledger-labs/cc-tools/assets" | ||
| ) | ||
|
|
||
| // Wallet represents a confidential user wallet | ||
| var Wallet = assets.AssetType{ | ||
| Tag: "wallet", | ||
| Label: "User Wallet", | ||
| Description: "Confidential wallet holding digital assets", | ||
|
|
||
| Props: []assets.AssetProp{ | ||
| { | ||
| Tag: "walletId", | ||
| Label: "Wallet ID", | ||
| DataType: "string", | ||
| Required: true, | ||
| IsKey: true, // primary key | ||
| }, | ||
| { | ||
| Tag: "ownerCertHash", | ||
| Label: "Owner Certificate Hash", | ||
| DataType: "string", | ||
| Required: true, | ||
| }, | ||
| { | ||
| Tag: "balance", | ||
| Label: "Token Balance", | ||
| DataType: "number", | ||
| Required: true, | ||
| }, | ||
| { | ||
| Tag: "assetType", | ||
PsychoPunkSage marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Label: "Asset Type Reference", | ||
| DataType: "@digitalAsset", // References digitalAsset | ||
PsychoPunkSage marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Required: true, | ||
| }, | ||
| { | ||
| Tag: "createdAt", | ||
| Label: "Creation Timestamp", | ||
| DataType: "datetime", | ||
| Required: true, | ||
| }, | ||
| }, | ||
|
|
||
| Readers: []string{"$org1MSP", "$org2MSP"}, | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
samples/chaincode/confidential-escrow/chaincode/header/header.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package header | ||
|
|
||
| var ( | ||
| Name = "Confidential Escrow" | ||
| Version = "1.0.0" | ||
| Colors = map[string][]string{ | ||
| "@default": {"#4267B2", "#34495E", "#ECF0F1"}, | ||
| } | ||
| Title = map[string]string{ | ||
| "@default": "Confidential Digital Assets & Programmable Escrow", | ||
| } | ||
| ) |
12 changes: 12 additions & 0 deletions
12
samples/chaincode/confidential-escrow/confidential-escrow-compose.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| services: | ||
| # org1 | ||
| ecc.peer0.org1.example.com: | ||
| environment: | ||
| - RUN_CCAAS=true | ||
| - FPC_ENABLED=true | ||
|
|
||
| # org2 | ||
| ecc.peer0.org2.example.com: | ||
| environment: | ||
| - RUN_CCAAS=true | ||
| - FPC_ENABLED=true |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.