| Crates.io | yotquitas-core |
| lib.rs | yotquitas-core |
| version | 0.2.0 |
| created_at | 2025-11-21 23:46:27.606311+00 |
| updated_at | 2025-11-25 18:22:00.86798+00 |
| description | Core library for Yotquitas blockchain providing foundational data structures, cryptographic primitives, and transaction handling. |
| homepage | https://github.com/Joel-Ajayi/yotquitas |
| repository | https://github.com/Joel-Ajayi/yotquitas/levels/yotquitas-core |
| max_upload_size | |
| id | 1944515 |
| size | 65,010 |
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.
🔐 Cryptographic Primitives:
📝 Transaction Structures:
🧱 Block Structures:
👤 Account Management:
🔄 Serialization:
Add this to your Cargo.toml:
[dependencies]
yotquitas-core = "0.1.0"
Or install from crates.io:
cargo add yotquitas-core
use yotquitas_core::{generate_keypair, SigningKey};
// Generate a new Ed25519 keypair
let (signing_key, public_key) = generate_keypair();
// The signing_key is your private key (SigningKey type)
// The public_key is your public key (PublicKey/VerifyingKey type)
use yotquitas_core::{Transaction, TransactionPayload, generate_keypair, SigningKey};
// Generate keypair
let (signing_key, public_key) = generate_keypair();
// Create a transfer transaction
let payload = TransactionPayload::Transfer {
to: [0u8; 32], // recipient address (32 bytes)
amount: 100, // amount in AEQ
};
// Create unsigned transaction
let tx = Transaction::new(
public_key, // sender's public key
payload,
1, // fee
0, // nonce
);
// Sign the transaction
let signed_tx = tx.sign(&signing_key);
// Verify the signature
assert!(signed_tx.verify());
// Get transaction hash
let tx_hash = signed_tx.hash();
// Get sender address
let sender_address = signed_tx.sender_address();
use yotquitas_core::Transaction;
// Serialize to JSON
let json = serde_json::to_string(&signed_tx).unwrap();
// Deserialize from JSON
let deserialized: Transaction = serde_json::from_str(&json).unwrap();
// Verify signature still works after deserialization
assert!(deserialized.verify());
use yotquitas_core::{Block, BlockHeader, Transaction, TransactionPayload, generate_keypair};
// Create transactions
let (_, pubkey) = generate_keypair();
let tx = Transaction::new(
pubkey,
TransactionPayload::Transfer {
to: [0u8; 32],
amount: 100,
},
1,
0,
);
// Create block header
let header = BlockHeader::new(
0, // block index
1000, // timestamp
[0u8; 32], // previous block hash
);
// Create block with transactions
let block = Block::new(header, vec![tx]);
// Verify block integrity
assert!(block.verify());
// Get block hash
let block_hash = block.hash();
use yotquitas_core::{Account, AccountType, generate_keypair, address_from_public_key};
// Create account from public key
let (_, public_key) = generate_keypair();
let account = Account::new_user_from_pubkey(public_key);
// Check account capabilities
assert!(account.can_send());
assert!(account.can_receive());
assert!(account.can_deploy());
// Create contract account
let contract_address = [1u8; 32];
let contract_account = Account::new_contract(contract_address);
assert!(!contract_account.can_send()); // Contracts can't send
crypto - Cryptographic OperationsCore cryptographic functions for the blockchain:
generate_keypair() - Creates Ed25519 keypairssign(signing_key, data) - Signs data with private keyverify(public_key, data, signature) - Verifies signaturessha256(), double_sha256() - SHA-256 hashingaddress_from_public_key() - Derives 32-byte address from public keyencode_hex(), decode_hex() - Hex string utilitiesTypes:
Hash - 32-byte hash (SHA-256 output)PublicKey - Ed25519 public key (VerifyingKey)Signature - Ed25519 signatureSigningKey - Ed25519 private key (re-exported from ed25519_dalek)transaction - Transaction HandlingTransaction 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 functionTransaction 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 StructuresBlock creation and verification:
Block Methods:
new() - Create new block with transactionsverify() - Verify block integrityhash() - Get block hashindex() - Get block indexprevious_hash() - Get previous block hashBlock Header Methods:
new() - Create new block headerhash() - Compute header hashUtilities:
compute_merkle_root() - Compute Merkle root from transactionsTypes:
Block - Complete block with header and transactionsBlockHeader - Block header structureaccount - Account ManagementAccount types and capabilities:
Account Types:
User - Standard user accountValidator - Validator account (can produce blocks)Contract - Smart contract accountTreasury - System treasury accountAccount 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 contractsTypes:
Account - Account structureAccountType - Account type enumerationuse yotquitas_core::{generate_keypair, SigningKey};
use hex;
// Generate keypair
let (signing_key, public_key) = generate_keypair();
// Export private key as bytes (32 bytes)
let private_key_bytes: [u8; 32] = signing_key.to_bytes();
// Export as hex string (64 hex characters)
let private_key_hex = hex::encode(private_key_bytes);
// Import from bytes
let imported_signing_key = SigningKey::from_bytes(&private_key_bytes);
// Import from hex
let bytes_from_hex = hex::decode(&private_key_hex).unwrap();
let signing_key_from_hex = SigningKey::from_bytes(
bytes_from_hex.try_into().unwrap()
);
use yotquitas_core::{Transaction, TransactionPayload, generate_keypair};
let (signing_key, public_key) = generate_keypair();
// Transfer transaction
let transfer_tx = Transaction::new(
public_key,
TransactionPayload::Transfer {
to: [0u8; 32],
amount: 1000,
},
1,
0,
).sign(&signing_key);
// Contract call transaction
let contract_call_tx = Transaction::new(
public_key,
TransactionPayload::ContractCall {
contract_address: [1u8; 32],
function: "transfer".to_string(),
args: vec![1, 2, 3],
},
10,
1,
).sign(&signing_key);
// Deploy contract transaction
let deploy_tx = Transaction::new(
public_key,
TransactionPayload::DeployContract {
wasm_bytecode: vec![0, 1, 2, 3], // WASM bytecode
init_args: vec![], // Initialization arguments
},
100,
2,
).sign(&signing_key);
use yotquitas_core::{generate_keypair, address_from_public_key, validate_address, encode_hex};
// Generate keypair
let (_, public_key) = generate_keypair();
// Derive address from public key
let address = address_from_public_key(&public_key);
// Validate address (must be 32 bytes)
assert!(validate_address(&address));
// Encode address as hex string
let address_hex = encode_hex(&address);
println!("Address: 0x{}", address_hex);
Address - 32-byte address (alias for Hash)Hash - 32-byte hash (SHA-256 output)PublicKey - Ed25519 public key (alias for VerifyingKey)Signature - Ed25519 signatureed25519-dalek - Ed25519 signature schemesha2 - SHA-256 hashingserde - Serialization frameworkserde_json - JSON serializationhex - Hex encoding/decodingrand - Random number generationPrivate Key Storage: Never store SigningKey in 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.
Run the test suite:
cargo test
Run tests for a specific module:
cargo test --lib crypto
cargo test --lib transaction
cargo test --lib block
cargo test --lib account
Generate full API documentation:
cargo doc --open
Licensed under the MIT license.
See LICENSE-MIT or http://opensource.org/licenses/MIT for details.
Contributions are welcome! Please see the main project contributing guide for more details.
Current version: 0.1.0