diff options
| author | gabrix73 <gabriel1@frozenstar.info> | 2026-06-01 18:41:36 +0200 |
|---|---|---|
| committer | gabrix73 <gabriel1@frozenstar.info> | 2026-06-01 18:41:36 +0200 |
| commit | 9f5d864d533ce86459e654f5d78212933c0269ea (patch) | |
| tree | 4b71e8c7ab4e78da93e5f3164803da4de68c7031 /crypto | |
| download | onioncoin-0.1.0.tar.gz onioncoin-0.1.0.tar.xz onioncoin-0.1.0.zip | |
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
Diffstat (limited to 'crypto')
| -rw-r--r-- | crypto/Cargo.toml | 15 | ||||
| -rw-r--r-- | crypto/src/keys.rs | 84 | ||||
| -rw-r--r-- | crypto/src/lib.rs | 10 |
3 files changed, 109 insertions, 0 deletions
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}; |
