#elliptic-curve #addresses #stealth #address #kit #suite #secp256k1

stealth_address_kit

Stealth Address Kit: A Rust library for generating stealth addresses

5 unstable releases

0.3.1 Jun 28, 2024
0.3.0 Jun 28, 2024
0.2.0 Jun 18, 2024
0.2.0-beta May 27, 2024
0.1.0 May 21, 2024

#4 in #stealth

Download history 29/week @ 2024-07-23 12/week @ 2024-07-30 8/week @ 2024-09-10 3/week @ 2024-09-17 3/week @ 2024-09-24 13/week @ 2024-10-01

297 downloads per month

MIT license

47KB
814 lines

Stealth Address Kit

The Stealth Address Kit leverages the arkworks-rs suite of libraries to provide a robust implementation of stealth addresses.

Supported Curves

The following curves are currently supported:

  1. ark_bn254
  2. ark_bls_12_381
  3. ark_bls_12_377
  4. secp256k1
  5. secp256r1
  6. pallas
  7. vesta
  8. bw6_761
  9. baby_jub_jub

Benchmarks

See the benchmarks for performance comparisons across supported curves.

Usage Example

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);
}

Adding a New Curve

To add support for a new curve, follow these steps:

  1. Add the curve to the Cargo.toml file as a feature.
  2. Create a new module in the src directory with the curve name, suffixed by _impl.rs.
  3. Implement the StealthAddressOnCurve trait for the curve.
  4. Define the macro define_curve_ffi.
  5. Add the curve to the lib.rs file in the mod declaration, and re-export if required.
  6. Update the README to include the new curve.
  7. Add the curve to the nightly release workflow.
  8. Add the curve to the benchmarks.

Building and Testing

Building

To build the project, use the following command:

cargo build --release --features <bn254/bls12_381/bls12_377/secp256k1/secp256r1/etc>

Testing

To run tests, use the following command:

cargo test --release --features <bn254/bls12_381/bls12_377/secp256k1/secp256r1/etc>

Benchmarks

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.

FFI API

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

Precompiled libraries are available in the nightly releases.

Acknowledgements

This project is inspired by the ERC-5564 EIP and the proof of concept by Nerolation.

Dependencies

~5.5MB
~101K SLoC