Starknet Client
Starknet RPC client for interacting with TONGO contracts on Starknet.
✅ Implemented Features
Core Infrastructure
- ✅ Starknet RPC provider creation - JSON-RPC client setup
- ✅ Account address derivation - OpenZeppelin account address calculation
- ✅ ElGamal decryption - Decrypt cipher balances from chain
- ✅ Proof generation - Full parity with TypeScript for Fund, Transfer, Rollover, Withdraw
- ✅ Integration test skeleton - Complete flow documentation with TypeScript parity
Key Management
- ✅ BIP-44 key derivation - TONGO coin type 5454 and Starknet coin type 9004
- ✅ Public key derivation - Elliptic curve scalar multiplication
- ✅ Account address calculation - Pedersen hash + Starknet Keccak
Cryptographic Primitives
- ✅ Proof of Exponentiation (PoE) - Schnorr-like proofs for balances
- ✅ Proof of Exponentiation 2 (PoE2) - Okamoto's protocol for rollovers
- ✅ ElGamal encryption - Homomorphic encryption for transfers
- ✅ Fiat-Shamir challenges - Non-interactive proof generation
🚧 To Be Implemented
The following components require integration with the live Starknet network:
- RPC State Querying - Fetch encrypted balances from TONGO contract
- Transaction Signing - Sign and submit transactions using starknet-rust
- Calldata Serialization - Convert Rust proofs to Cairo calldata format
- ERC20 Approve Flow - Token approval before fund operations
- State Verification - Query and decrypt state after transactions
Account Derivation
The crate supports deriving Starknet account contract addresses using the standard contract address calculation formula:
use ;
use Felt;
// Derive a keypair from mnemonic
let keypair = derive_keypair?;
// Get the public key x-coordinate
let affine = keypair.public_key.to_affine?;
let public_key_x = affine.x;
// Calculate the account contract address
let class_hash = from_hex?;
let account_address = derive_oz_account_address?;
Testing
Run the account derivation tests:
Next Steps
To complete the integration with Starknet:
1. Add TONGO Contract Interactions
Create a TongoClient struct that wraps the starknet provider and provides high-level methods:
2. Implement Account Signer
Add utilities for signing transactions using derived keys:
use ;
use ;
3. Add Integration Tests
Create tests that replicate the TypeScript tongo-sepolia.test.ts:
// Requires Sepolia testnet access
async
OpenZeppelin Account Class Hash
The tests use the OpenZeppelin account class hash deployed on Sepolia:
0x05b4b537eaa2399e3aa99c4e2e0208ebd6c71bc1467938cd52c798c601e43564
This is the same class hash used in the TypeScript reference implementation.
TONGO Contract Address (Sepolia)
0x00b4cca30f0f641e01140c1c388f55641f1c3fe5515484e622b6cb91d8cee585
Related Crates
krusty-kms: Key derivation and account address calculationkrusty-kms-sdk: TONGO operation proof generationkrusty-kms-crypto: Cryptographic primitives (PoE, PoE2, ElGamal)