Skip to content

Commit

Permalink
chore: refactor into 2 crates, example and sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed May 27, 2024
1 parent 3abd6ce commit 66a5f27
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/nightly-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
- name: Install dependencies
run: make deps
- name: cross build
working-directory: ./sdk
run: |
cross build --release --target ${{ matrix.target }} --features ${{ matrix.curve }}
mkdir release
Expand Down Expand Up @@ -84,6 +85,7 @@ jobs:
- name: Install dependencies
run: make deps
- name: cross build
working-directory: ./sdk
run: |
cross build --release --target ${{ matrix.target }} --features ${{ matrix.curve }}
mkdir release
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 6 additions & 50 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,51 +1,7 @@
[package]
name = "stealth_address_kit"
version = "0.1.0"
edition = "2021"
description = "Stealth Address Kit: A Rust library for generating stealth addresses."
license = "MIT"
homepage = "https://vac.dev"
[workspace]

[lib]
name = "stealth_address_kit"
path = "src/lib.rs"
crate-type = ["staticlib"]

[features]
ffi = []
bls12_381 = []
bls12_377 = []
secp256k1 = []
secp256r1 = []
bn254 = []
pallas = []
vesta = []
bw6_761 = []
default = ["all"]
all = ["ffi", "secp256k1", "bls12_381", "bls12_377", "bn254", "secp256r1", "pallas", "vesta", "bw6_761"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rln = "0.3.4"
ark-std = "0.4.0"
num-bigint = "0.4.3"
num-traits = "0.2.15"
ark-ff = "0.4.1"
ark-bn254 = "0.4.0"
ark-bls12-381 = "0.4.0"
ark-bls12-377 = "0.4.0"
ark-secp256k1 = "0.4.0"
ark-secp256r1 = "0.4.0"
ark-pallas = "0.4.0"
ark-vesta = "0.4.0"
ark-bw6-761 = "0.4.0"
tiny-keccak = { version = "=2.0.2", features = ["keccak"] }
ark-ec = "0.4.1"
ark-serialize = "0.4.1"
cfg-if = "1.0.0"
paste = "1.0.0"

[dev-dependencies]
serde_json = "1.0.96"
color-eyre = "0.6.2"
members = [
"sdk",
"example"
]
resolver = "2"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Uses the [arkworks-rs](https://github.com/arkworks-rs/curves) suite of libraries
## Usage

```rust
use stealth_address_kit::{StealthAddressOnCurve};
use stealth_address_kit::StealthAddressOnCurve;
use ark_bn254::Bn254; // or ark_bls_12_381::Bls12_381 or ark_bls_12_377::Bls12_377, stealth_address_kit::Secp256k1, stealth_address_kit::Secp256r1, etc

fn main() {
Expand All @@ -34,7 +34,7 @@ fn main() {
panic!("View tags did not match");
}

let derived_stealth_address = Bn254::derive_public_key(stealth_private_key_opt.unwrap());
let derived_stealth_address = Bn254::derive_public_key(&stealth_private_key_opt.unwrap());
assert_eq!(derived_stealth_address, stealth_address);
}
```
Expand All @@ -45,7 +45,7 @@ fn main() {
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
5. Add the curve to the `lib.rs` file, in the `mod` declaration, as well as re-export if required
6. Add the curve to the README
7. Add the curve to the nightly release workflow

Expand Down
9 changes: 9 additions & 0 deletions example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "stealth_address_kit_example"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
stealth_address_kit = { path = "../sdk", default-features = false, features = ["secp256r1"] }
7 changes: 7 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Example

Feel free to play around with the `curves` that are exported by the `stealth_address_kit` crate. The following example demonstrates how to generate a stealth address using the `secp256r1` curve.

Update the `Cargo.toml` file to include the features/curves that you would like to use.

Supported Curves: [here](../README.md#Existing-Implementations)
32 changes: 32 additions & 0 deletions example/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use stealth_address_kit::Secp256r1;
use stealth_address_kit::StealthAddressOnCurve;

type Curve = Secp256r1;

fn main() {
let (spending_key, spending_public_key) = Curve::random_keypair();
let (viewing_key, viewing_public_key) = Curve::random_keypair();

// generate ephemeral keypair
let (ephemeral_private_key, ephemeral_public_key) = Curve::random_keypair();

let (stealth_address, view_tag) = Curve::generate_stealth_address(
viewing_public_key,
spending_public_key,
ephemeral_private_key,
);

let stealth_private_key_opt = Curve::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 = Curve::derive_public_key(&stealth_private_key_opt.unwrap());
assert_eq!(derived_stealth_address, stealth_address);
}
51 changes: 51 additions & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[package]
name = "stealth_address_kit"
version = "0.1.0"
edition = "2021"
description = "Stealth Address Kit: A Rust library for generating stealth addresses."
license = "MIT"
homepage = "https://vac.dev"

[lib]
name = "stealth_address_kit"
path = "src/lib.rs"
crate-type = ["staticlib", "rlib"]

[features]
ffi = []
bls12_381 = []
bls12_377 = []
secp256k1 = []
secp256r1 = []
bn254 = []
pallas = []
vesta = []
bw6_761 = []
default = ["secp256k1", "ffi"]
all = ["ffi", "secp256k1", "bls12_381", "bls12_377", "bn254", "secp256r1", "pallas", "vesta", "bw6_761"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rln = "0.3.4"
ark-std = "0.4.0"
num-bigint = "0.4.3"
num-traits = "0.2.15"
ark-ff = "0.4.1"
ark-bn254 = "0.4.0"
ark-bls12-381 = "0.4.0"
ark-bls12-377 = "0.4.0"
ark-secp256k1 = "0.4.0"
ark-secp256r1 = "0.4.0"
ark-pallas = "0.4.0"
ark-vesta = "0.4.0"
ark-bw6-761 = "0.4.0"
tiny-keccak = { version = "=2.0.2", features = ["keccak"] }
ark-ec = "0.4.1"
ark-serialize = "0.4.1"
cfg-if = "1.0.0"
paste = "1.0.0"

[dev-dependencies]
serde_json = "1.0.96"
color-eyre = "0.6.2"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions src/lib.rs → sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ mod vesta_impl;

#[cfg(feature = "ffi")]
mod ffi;

#[cfg(feature = "pallas")]
pub use pallas_impl::Pallas;
#[cfg(feature = "secp256k1")]
pub use secp256k1_impl::Secp256k1;
#[cfg(feature = "secp256r1")]
pub use secp256r1_impl::Secp256r1;
pub use stealth_addresses::StealthAddressOnCurve;
#[cfg(feature = "vesta")]
pub use vesta_impl::Vesta;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 66a5f27

Please sign in to comment.