Crates.io | stealth_address_kit |
lib.rs | stealth_address_kit |
version | 0.3.1 |
source | src |
created_at | 2024-05-21 15:05:31.119604 |
updated_at | 2024-06-28 06:37:11.081803 |
description | Stealth Address Kit: A Rust library for generating stealth addresses. |
homepage | https://vac.dev |
repository | https://github.com/vacp2p/stealth-address-kit |
max_upload_size | |
id | 1246917 |
size | 51,245 |
The Stealth Address Kit leverages the arkworks-rs suite of libraries to provide a robust implementation of stealth addresses.
The following curves are currently supported:
ark_bn254
ark_bls_12_381
ark_bls_12_377
secp256k1
secp256r1
pallas
vesta
bw6_761
baby_jub_jub
See the benchmarks for performance comparisons across supported curves.
Below is an example demonstrating how to use the Stealth Address Kit with the ark_bn254
curve:
use stealth_address_kit::StealthAddressOnCurve;
use ark_bn254::Bn254;
fn main() {
let (spending_key, spending_public_key) = Bn254::random_keypair();
let (viewing_key, viewing_public_key) = Bn254::random_keypair();
// Generate ephemeral keypair
let (ephemeral_private_key, ephemeral_public_key) = Bn254::random_keypair();
let (stealth_address, view_tag) = Bn254::generate_stealth_address(viewing_public_key, spending_public_key, ephemeral_private_key);
let stealth_private_key_opt = Bn254::generate_stealth_private_key(ephemeral_public_key, viewing_key, spending_key, view_tag);
if stealth_private_key_opt.is_none() {
panic!("View tags did not match");
}
let derived_stealth_address = Bn254::derive_public_key(&stealth_private_key_opt.unwrap());
assert_eq!(derived_stealth_address, stealth_address);
}
To add support for a new curve, follow these steps:
Cargo.toml
file as a feature.src
directory with the curve name, suffixed by _impl.rs
.StealthAddressOnCurve
trait for the curve.define_curve_ffi
.lib.rs
file in the mod
declaration, and re-export if required.To build the project, use the following command:
cargo build --release --features <bn254/bls12_381/bls12_377/secp256k1/secp256r1/etc>
To run tests, use the following command:
cargo test --release --features <bn254/bls12_381/bls12_377/secp256k1/secp256r1/etc>
To run benchmarks, use the following command:
make bench
This will run benchmarks for all supported curves, and output the results to the benchmarks
directory.
The exposed FFI API supports all curves, prefixed by the curve name. Ensure that the correct feature is enabled when building the library.
Precompiled libraries are available in the nightly releases.
This project is inspired by the ERC-5564 EIP and the proof of concept by Nerolation.