rust-sign
A Rust library for document signing using BLAKE3 hashing and Ed25519 digital signatures.
Features
- Fast & Secure Hashing: Uses BLAKE3 for lightning-fast, cryptographically secure document fingerprinting
- Ed25519 Signatures: Modern, compact digital signatures (64 bytes)
- Multi-Signature Support: Multiple parties can sign the same document
- JSON Output: Human-readable signature format with timestamps and metadata
- Streaming Support: Efficiently sign large files without loading them entirely into memory
- Key Management: Generate, save, and load keypairs
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Generate a Keypair
use KeyPair;
let keypair = generate;
// Optionally save to file
keypair.save_to_file?;
// Load later
let keypair = load_from_file?;
Sign a Document
use ;
let keypair = generate;
let document = b"Important document content";
let signature = new
.with_signer_id
.with_metadata
.sign_bytes?;
// Save signature to file
signature.save?;
// Or get as JSON string
println!;
Sign a File
use ;
let keypair = generate;
let signature = new
.with_signer_id
.sign_file?;
signature.save?;
Verify a Signature
use ;
// Verify bytes
let result = verify_bytes?;
if result.all_valid else
// Verify file against signature file
let result = verify_file?;
Multiple Signatures
use ;
let alice = generate;
let bob = generate;
let document = b"Contract requiring multiple signatures";
// Alice signs first
let mut signature = new
.with_signer_id
.sign_bytes?;
// Bob co-signs
new
.with_signer_id
.cosign?;
// Verify all signatures
let result = verify_bytes?;
assert!;
assert_eq!;
Signature Format
Signatures are stored as JSON:
Security Notes
- Private Keys: Keep your private key files secure. Anyone with access can sign documents as you.
- BLAKE3: Provides 256-bit security level, faster than SHA-256 while being just as secure.
- Ed25519: Well-audited, fast signature scheme. 64-byte signatures, 32-byte public keys.
- Verification: Always verify signatures before trusting document authenticity.
API Reference
Core Types
| Type | Description |
|---|---|
KeyPair |
Ed25519 signing keypair |
PublicKey |
Ed25519 public key for verification |
Signer |
Builder for creating signatures |
Verifier |
Signature verification utilities |
DocumentSignature |
Signed document container |
SignatureEntry |
Individual signature with metadata |
DocumentHash |
BLAKE3 hash wrapper |
Error Handling
All operations return Result<T, SignError>. Error types include:
SignError::Io- File I/O errorsSignError::Json- JSON serialization errorsSignError::Signature- Cryptographic signature errorsSignError::InvalidKey- Invalid key formatSignError::HashMismatch- Document was modifiedSignError::NoSignatures- No signatures in document
License
MIT