yotquitas-core
Core library for the Yotquitas blockchain providing foundational data structures, cryptographic primitives, and transaction handling.
This crate is the foundation of the Yotquitas blockchain, providing all the essential building blocks for creating transactions, blocks, accounts, and cryptographic operations.
Features
-
🔐 Cryptographic Primitives:
- SHA-256 hashing (single and double)
- Ed25519 digital signatures (key generation, signing, verification)
- Address derivation from public keys
- Hex encoding/decoding utilities
-
📝 Transaction Structures:
- Multiple transaction types (Transfer, ContractCall, DeployContract, DeployModule, MoveCall)
- Transaction signing and verification
- Transaction serialization (JSON)
- Transaction receipts and logs
-
🧱 Block Structures:
- Block headers with Merkle root computation
- Block creation and verification
- Double SHA-256 hashing for block integrity
-
👤 Account Management:
- Account types (User, Validator, Contract, Treasury)
- Account capabilities and permissions
- Address-based account creation
-
🔄 Serialization:
- Full serde support with JSON serialization/deserialization
- Custom serializers for cryptographic types
- Transaction and block serialization
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Or install from crates.io:
Quick Start
Generate a Keypair
use ;
// Generate a new Ed25519 keypair
let = generate_keypair;
// The signing_key is your private key (SigningKey type)
// The public_key is your public key (PublicKey/VerifyingKey type)
Create and Sign a Transaction
use ;
// Generate keypair
let = generate_keypair;
// Create a transfer transaction
let payload = Transfer ;
// Create unsigned transaction
let tx = new;
// Sign the transaction
let signed_tx = tx.sign;
// Verify the signature
assert!;
// Get transaction hash
let tx_hash = signed_tx.hash;
// Get sender address
let sender_address = signed_tx.sender_address;
Serialize and Deserialize Transactions
use Transaction;
// Serialize to JSON
let json = to_string.unwrap;
// Deserialize from JSON
let deserialized: Transaction = from_str.unwrap;
// Verify signature still works after deserialization
assert!;
Create a Block
use ;
// Create transactions
let = generate_keypair;
let tx = new;
// Create block header
let header = new;
// Create block with transactions
let block = new;
// Verify block integrity
assert!;
// Get block hash
let block_hash = block.hash;
Work with Accounts
use ;
// Create account from public key
let = generate_keypair;
let account = new_user_from_pubkey;
// Check account capabilities
assert!;
assert!;
assert!;
// Create contract account
let contract_address = ;
let contract_account = new_contract;
assert!; // Contracts can't send
Module Overview
crypto - Cryptographic Operations
Core cryptographic functions for the blockchain:
- Key Generation:
generate_keypair()- Creates Ed25519 keypairs - Signing:
sign(signing_key, data)- Signs data with private key - Verification:
verify(public_key, data, signature)- Verifies signatures - Hashing:
sha256(),double_sha256()- SHA-256 hashing - Address Derivation:
address_from_public_key()- Derives 32-byte address from public key - Hex Encoding:
encode_hex(),decode_hex()- Hex string utilities
Types:
Hash- 32-byte hash (SHA-256 output)PublicKey- Ed25519 public key (VerifyingKey)Signature- Ed25519 signatureSigningKey- Ed25519 private key (re-exported fromed25519_dalek)
transaction - Transaction Handling
Transaction creation, signing, and verification:
-
Transaction Types:
Transfer- Simple token transferContractCall- Call a smart contract functionDeployContract- Deploy a WASM contractDeployModule- Deploy a Move moduleMoveCall- Call a Move function
-
Transaction Methods:
new()- Create unsigned transactionsign()- Sign transaction with private keyverify()- Verify transaction signaturehash()- Get transaction hashsender_address()- Get sender's addressrecipient_address()- Get recipient address (if applicable)
Types:
Transaction- Main transaction structureTransactionPayload- Transaction payload variantsTransactionReceipt- Transaction execution resultTransactionLog- Event log entryAddress- 32-byte address (type alias for Hash)
block - Block Structures
Block creation and verification:
-
Block Methods:
new()- Create new block with transactionsverify()- Verify block integrityhash()- Get block hashindex()- Get block indexprevious_hash()- Get previous block hash
-
Block Header Methods:
new()- Create new block headerhash()- Compute header hash
-
Utilities:
compute_merkle_root()- Compute Merkle root from transactions
Types:
Block- Complete block with header and transactionsBlockHeader- Block header structure
account - Account Management
Account types and capabilities:
-
Account Types:
User- Standard user accountValidator- Validator account (can produce blocks)Contract- Smart contract accountTreasury- System treasury account
-
Account Methods:
new_user()- Create user account from addressnew_user_from_pubkey()- Create user account from public keynew_validator()- Create validator accountnew_contract()- Create contract accountnew_treasury()- Create treasury accountcan_send()- Check if account can send transactionscan_receive()- Check if account can receive transactionscan_deploy()- Check if account can deploy contracts
Types:
Account- Account structureAccountType- Account type enumeration
Detailed Examples
Exporting and Importing Private Keys
use ;
use hex;
// Generate keypair
let = generate_keypair;
// Export private key as bytes (32 bytes)
let private_key_bytes: = signing_key.to_bytes;
// Export as hex string (64 hex characters)
let private_key_hex = encode;
// Import from bytes
let imported_signing_key = from_bytes;
// Import from hex
let bytes_from_hex = decode.unwrap;
let signing_key_from_hex = from_bytes;
Creating Different Transaction Types
use ;
let = generate_keypair;
// Transfer transaction
let transfer_tx = new.sign;
// Contract call transaction
let contract_call_tx = new.sign;
// Deploy contract transaction
let deploy_tx = new.sign;
Working with Addresses
use ;
// Generate keypair
let = generate_keypair;
// Derive address from public key
let address = address_from_public_key;
// Validate address (must be 32 bytes)
assert!;
// Encode address as hex string
let address_hex = encode_hex;
println!;
Type Aliases
Address- 32-byte address (alias forHash)Hash- 32-byte hash (SHA-256 output)PublicKey- Ed25519 public key (alias forVerifyingKey)Signature- Ed25519 signature
Dependencies
ed25519-dalek- Ed25519 signature schemesha2- SHA-256 hashingserde- Serialization frameworkserde_json- JSON serializationhex- Hex encoding/decodingrand- Random number generation
Security Considerations
-
Private Key Storage: Never store
SigningKeyin plain text. Always export as bytes or hex and use secure storage. -
Transaction Signing: Always sign transactions client-side. Never send private keys to servers.
-
Address Validation: Always validate addresses are 32 bytes before using them.
-
Signature Verification: Always verify transaction signatures before processing.
-
Merkle Root: Block Merkle roots are computed automatically. Don't modify them manually.
Testing
Run the test suite:
Run tests for a specific module:
Documentation
Generate full API documentation:
License
Licensed under the MIT license.
See LICENSE-MIT or http://opensource.org/licenses/MIT for details.
Contributing
Contributions are welcome! Please see the main project contributing guide for more details.
Links
- Repository: https://github.com/Joel-Ajayi/yotquitas
- Crates.io: https://crates.io/crates/yotquitas-core
- Documentation: https://docs.rs/yotquitas-core
Version
Current version: 0.1.0