| Crates.io | veil-crypto |
| lib.rs | veil-crypto |
| version | 1.2.0 |
| created_at | 2025-10-29 18:04:56.81804+00 |
| updated_at | 2026-01-09 16:15:03.132846+00 |
| description | Pure Rust secp256k1 cryptography for Veil blockchain with WASM bindings |
| homepage | https://github.com/blondfrogs/veil-secp256k1-wasm |
| repository | https://github.com/blondfrogs/veil-secp256k1-wasm |
| max_upload_size | |
| id | 1907082 |
| size | 259,062 |
Pure Rust implementation of secp256k1 cryptographic primitives for Veil blockchain.
veil-crypto is a pure Rust cryptography library that implements all the cryptographic primitives needed for Veil's privacy features. Unlike traditional implementations that rely on C libraries (libsecp256k1-zkp), this library is 100% Rust, making it fully compatible with WebAssembly and safe from memory-related vulnerabilities.
Add to your Cargo.toml:
[dependencies]
veil-crypto = "0.1"
use veil_crypto::pedersen_commit;
let value = 1000u64;
let blind = [0xAA; 32]; // Blinding factor
let commitment = pedersen_commit(value, &blind)?;
println!("Commitment: {}", hex::encode(&commitment));
use veil_crypto::{pedersen_commit, rangeproof_sign, rangeproof_verify};
let value = 1000u64;
let blind = [0xAA; 32];
let commitment = pedersen_commit(value, &blind)?;
// Generate range proof
let proof = rangeproof_sign(
&commitment,
value,
&blind,
&commitment,
&[], // extra_commit
0, // min_value
-1, // exp (auto)
0, // min_bits
)?;
// Verify range proof
let valid = rangeproof_verify(&commitment, &proof.proof)?;
assert!(valid);
use veil_crypto::{prepare_mlsag, generate_mlsag, verify_mlsag};
// Prepare MLSAG context
let context = prepare_mlsag(
&message,
ring_size,
real_index,
&private_keys,
&public_keys,
&commitments,
)?;
// Generate signature
let signature = generate_mlsag(&context)?;
// Verify signature
let valid = verify_mlsag(
&message,
&signature,
&public_keys,
&commitments,
)?;
assert!(valid);
use veil_crypto::generate_keyimage;
let secret_key = [0xAB; 32];
let key_image = generate_keyimage(&secret_key)?;
use veil_crypto::ecdh_veil;
let secret_key = [0xCD; 32];
let public_key = [0x02; 33]; // Compressed pubkey
let shared_secret = ecdh_veil(&secret_key, &public_key)?;
utils.rs - EC operations (derive_pubkey, point_add_scalar, etc.)ecdh.rs - ECDH_VEIL implementation for stealth addresseskeyimage.rs - Key image generation using hash-to-curvepedersen.rs - Pedersen commitments with QR format handlingrangeproof.rs - Bulletproof-style range proofsmlsag.rs - MLSAG signatures (870 lines, fully tested)borromean.rs - Borromean ring signaturesAll dependencies are pure Rust and WASM-compatible:
cd veil-crypto
cargo test
# Output:
# running 62 tests
# test result: ok. 62 passed; 0 failed
All tests use vectors generated from the original C implementation to ensure compatibility.
During development, we discovered a critical bug in how Pedersen format (0x08/0x09) commitments are converted to standard format (0x02/0x03).
The Problem: Simple bit mapping fails for ~50% of points because Pedersen format encodes based on quadratic residue (QR), not y-coordinate parity.
The Solution: Compute canonical y-coordinate via sqrt(x³ + 7), check parity, then select the correct point based on the format prefix bit.
See veil-crypto/src/pedersen.rs for implementation details. This fix is critical for MLSAG signature validity.
This library is designed to compile to WebAssembly. For JavaScript/TypeScript bindings, see the companion package:
@veil/secp256k1-wasm - WASM bindings for browser and Node.jsStatus: Ready for integration testing
This implementation is:
For production use:
| Operation | Time | Notes |
|---|---|---|
| Pedersen commitment | ~0.5ms | Pure Rust k256 |
| Range proof generation | ~50-100ms | CPU-intensive |
| MLSAG generation | ~50-100ms | Per input |
| Key image generation | ~1-2ms | Hash-to-curve |
Generate and view the full API documentation:
cargo doc --open
Contributions welcome! Please ensure:
cargo testcargo fmtcargo clippyMIT License - See LICENSE for details
Built with 🦀 Rust for the Veil community