TBD54566975 / web5-rs

Apache License 2.0
9 stars 5 forks source link

Add singular cryptography interfaces for generating, signing and verifying #205

Open KendallWeihe opened 3 months ago

KendallWeihe commented 3 months ago

In a ton of places throughout the codebase, wherever we make a call to on of the crypto crates' generate()/sign()/verify() functions we always have to have a match statement. For example,

        let private_key = Arc::new(match curve {
            Curve::Ed25519 => Ed25519::generate(),
            Curve::Secp256k1 => Secp256k1::generate(),
        }?);

This is an obvious place where DRY and the convenience would save us a lot of lines of code (and overhead). We should create singular interfaces for this set of functionality, within the crypto crate, perhaps multiple different functions depending on what the required set of parameters are (rust doesn't support function overloading, so prefer to use required parameters with named functions; for example sign_crv(curve: Curve) and sign_crv_str(curve: &str)).

KendallWeihe commented 3 months ago

oh interesting, I can see @diehuxx you're already thinking about this with #156, nice!