# Sharenet Passport Library A secure Rust library for creating and managing Sharenet Passport files (.spf) for decentralized identity management. ## Features - **Secure Passport Creation**: Generate encrypted .spf files with BIP-39 mnemonic recovery phrases - **Ed25519 Key Generation**: Cryptographically secure key derivation and signing - **Recovery Support**: Import passports from recovery phrases or existing .spf files - **Export & Re-encrypt**: Export passports with new passwords - **Message Signing**: Sign messages using your passport's private key - **Security First**: Zeroize memory management and secure file encryption - **WASM Support**: Compatible with web applications via WebAssembly ## Installation ### From Private Registry ```toml [dependencies] sharenet-passport = { version = "0.1.0", registry = "sharenet-sh-forgejo", features = ["std"] } ``` ### For WASM Projects ```toml [dependencies] sharenet-passport = { version = "0.1.0", registry = "sharenet-sh-forgejo", features = ["wasm"] } ``` ## Usage ### Creating a New Passport ```rust use sharenet_passport::{ application::use_cases::CreatePassportUseCase, infrastructure::{Bip39MnemonicGenerator, Ed25519KeyDeriver, XChaCha20FileEncryptor, FileSystemStorage}, }; let use_case = CreatePassportUseCase::new( Bip39MnemonicGenerator, Ed25519KeyDeriver, XChaCha20FileEncryptor, FileSystemStorage, ); let (passport, recovery_phrase) = use_case.execute("your-password", "passport.spf")?; println!("Public Key: {:?}", passport.public_key()); println!("DID: {}", passport.did().as_str()); println!("Recovery Phrase: {}", recovery_phrase.to_string()); ``` ### Importing from Recovery Phrase ```rust use sharenet_passport::{ application::use_cases::ImportFromRecoveryUseCase, infrastructure::{Bip39MnemonicGenerator, Ed25519KeyDeriver, XChaCha20FileEncryptor, FileSystemStorage}, }; let use_case = ImportFromRecoveryUseCase::new( Bip39MnemonicGenerator, Ed25519KeyDeriver, XChaCha20FileEncryptor, FileSystemStorage, ); let recovery_words = vec!["word1".to_string(), "word2".to_string(), /* ... 24 words */]; let passport = use_case.execute(&recovery_words, "new-password", "recovered-passport.spf")?; ``` ### Signing Messages ```rust use sharenet_passport::{ application::use_cases::{ImportFromFileUseCase, SignCardUseCase}, infrastructure::{XChaCha20FileEncryptor, FileSystemStorage}, }; // Import passport from file let import_use_case = ImportFromFileUseCase::new( XChaCha20FileEncryptor, FileSystemStorage, ); let passport = import_use_case.execute("passport.spf", "password", None)?; // Sign message let sign_use_case = SignCardUseCase::new(); let signature = sign_use_case.execute(&passport, "Hello, Sharenet!")?; ``` ## Architecture Built with Clean Architecture principles: - **Domain Layer**: Core entities (Passport, RecoveryPhrase, PublicKey, etc.) and traits - **Application Layer**: Use cases (CreatePassport, ImportFromRecovery, SignCard, etc.) - **Infrastructure Layer**: Crypto implementations, file storage ## Feature Flags - `std` (default): Standard library support for CLI and server applications - `wasm`: WebAssembly support for web applications - `alloc`: No-std with allocator support ## Security Features - **XChaCha20-Poly1305**: Authenticated encryption for file security - **HKDF-SHA256**: Key derivation from passwords - **Zeroize**: Secure memory wiping for sensitive data - **BIP-39**: Standard mnemonic generation and validation - **Ed25519**: Cryptographically secure signing ## File Format (.spf) Sharenet Passport Files (.spf) are encrypted containers that store: - **Encrypted Seed**: The master seed encrypted with XChaCha20-Poly1305 - **Public Key**: Your Ed25519 public key - **DID**: Your Decentralized Identifier - **Metadata**: Creation timestamp, version, and encryption parameters ## Development ### Running Tests ```bash # Run all tests cargo test # Test specific features cargo test --features std cargo test --features wasm ``` ### Building for WASM ```bash # Install wasm-pack if needed cargo install wasm-pack # Build for web wasm-pack build --target web --features wasm ``` ## License This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. You are free to: - **Share** — copy and redistribute the material in any medium or format - **Adapt** — remix, transform, and build upon the material Under the following terms: - **Attribution** — You must give appropriate credit, provide a link to the license, and indicate if changes were made. - **NonCommercial** — You may not use the material for commercial purposes. - **ShareAlike** — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/4.0/