From 9f5d864d533ce86459e654f5d78212933c0269ea Mon Sep 17 00:00:00 2001 From: gabrix73 Date: Mon, 1 Jun 2026 18:41:36 +0200 Subject: Initial commit: OnionCoin prototype with Proof-of-Relay consensus OnionCoin is a privacy cryptocurrency that rewards Tor relay operators through a unique Proof-of-Contribution consensus mechanism. Core Features: - Proof-of-Relay: 30% of block rewards go to Tor operators - Native .onion node identity (no IP exposure) - Temporal obfuscation protocols - Dandelion++ over Tor propagation - Native inheritance system with dead man's switch Technical Stack: - Rust workspace with 8 crates - Ed25519/X25519 cryptography - arti (Rust Tor client) integration planned - 10 minute block time, 5-10 TPS design Status: Prototype - Consensus logic complete with passing tests (30/33) - Network layer conceptual design complete - Tor integration pending - Testnet launch planned Q3 2026 License: MIT Author: Gabriele Salati (virebent) Contact: g48rix@gmail.com Website: https://www.gabrielesalati.eu Repository: https://git.virebent.art/virebent/onioncoin --- crypto/Cargo.toml | 15 ++++++++++ crypto/src/keys.rs | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ crypto/src/lib.rs | 10 +++++++ 3 files changed, 109 insertions(+) create mode 100644 crypto/Cargo.toml create mode 100644 crypto/src/keys.rs create mode 100644 crypto/src/lib.rs (limited to 'crypto') diff --git a/crypto/Cargo.toml b/crypto/Cargo.toml new file mode 100644 index 0000000..4741b00 --- /dev/null +++ b/crypto/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "onioncoin-crypto" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true + +[dependencies] +ed25519-dalek.workspace = true +curve25519-dalek.workspace = true +sha3.workspace = true +blake3.workspace = true +rand.workspace = true +serde.workspace = true +thiserror.workspace = true diff --git a/crypto/src/keys.rs b/crypto/src/keys.rs new file mode 100644 index 0000000..4666476 --- /dev/null +++ b/crypto/src/keys.rs @@ -0,0 +1,84 @@ +use ed25519_dalek::{Signer, Verifier}; +use serde::{Deserialize, Serialize}; + +/// Public key wrapper +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +pub struct PublicKey(pub [u8; 32]); + +/// Secret key wrapper +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SecretKey(pub [u8; 32]); + +/// Key pair for signing +#[derive(Debug, Clone)] +pub struct KeyPair { + pub public: PublicKey, + pub secret: SecretKey, + signing_key: ed25519_dalek::SigningKey, +} + +impl KeyPair { + /// Generate new random keypair + pub fn generate() -> Self { + use rand::RngCore; + let mut rng = rand::thread_rng(); + let mut secret_bytes = [0u8; 32]; + rng.fill_bytes(&mut secret_bytes); + + let signing_key = ed25519_dalek::SigningKey::from_bytes(&secret_bytes); + let verifying_key = signing_key.verifying_key(); + + Self { + public: PublicKey(verifying_key.to_bytes()), + secret: SecretKey(signing_key.to_bytes()), + signing_key, + } + } + + /// Sign a message + pub fn sign(&self, message: &[u8]) -> [u8; 64] { + self.signing_key.sign(message).to_bytes() + } + + /// Verify a signature + pub fn verify(public_key: &PublicKey, message: &[u8], signature: &[u8; 64]) -> bool { + let verifying_key = match ed25519_dalek::VerifyingKey::from_bytes(&public_key.0) { + Ok(key) => key, + Err(_) => return false, + }; + + let sig = ed25519_dalek::Signature::from_bytes(signature); + + verifying_key.verify(message, &sig).is_ok() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_keypair_generation() { + let keypair = KeyPair::generate(); + assert_ne!(keypair.public.0, [0u8; 32]); + assert_ne!(keypair.secret.0, [0u8; 32]); + } + + #[test] + fn test_sign_verify() { + let keypair = KeyPair::generate(); + let message = b"Hello, OnionCoin!"; + + let signature = keypair.sign(message); + assert!(KeyPair::verify(&keypair.public, message, &signature)); + } + + #[test] + fn test_verify_invalid_signature() { + let keypair = KeyPair::generate(); + let message = b"Hello, OnionCoin!"; + let wrong_sig = [0u8; 64]; + + assert!(!KeyPair::verify(&keypair.public, message, &wrong_sig)); + } +} diff --git a/crypto/src/lib.rs b/crypto/src/lib.rs new file mode 100644 index 0000000..92bf68a --- /dev/null +++ b/crypto/src/lib.rs @@ -0,0 +1,10 @@ +// Placeholder crypto module for OnionCoin +// Production implementation would include: +// - Ring signatures (Monero-style) +// - Bulletproofs for confidential transactions +// - Stealth address generation +// - Key derivation (HD wallets) + +pub mod keys; + +pub use keys::{KeyPair, PublicKey, SecretKey}; -- cgit v1.2.3