From 71261e132324916afab1591b7ddc1a9cb33d1bee Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 11 Sep 2023 21:31:00 -0500 Subject: [PATCH] keyfork-derive-util: impl FromStr for DerivationAlgorithm --- keyfork-derive-util/Cargo.toml | 2 ++ keyfork-derive-util/src/request.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/keyfork-derive-util/Cargo.toml b/keyfork-derive-util/Cargo.toml index 28b8b60..1c54933 100644 --- a/keyfork-derive-util/Cargo.toml +++ b/keyfork-derive-util/Cargo.toml @@ -26,6 +26,8 @@ thiserror = "1.0.47" # Optional, not personally audited k256 = { version = "0.13.1", default-features = false, features = ["std", "arithmetic"], optional = true } ed25519-dalek = { version = "2.0.0", optional = true } + +# Workspace keyfork-mnemonic-util = { version = "0.1.0", path = "../keyfork-mnemonic-util" } [dev-dependencies] diff --git a/keyfork-derive-util/src/request.rs b/keyfork-derive-util/src/request.rs index 5245037..6f4401e 100644 --- a/keyfork-derive-util/src/request.rs +++ b/keyfork-derive-util/src/request.rs @@ -48,6 +48,18 @@ impl DerivationAlgorithm { } } +impl std::str::FromStr for DerivationAlgorithm { + type Err = DerivationError; + + fn from_str(s: &str) -> std::result::Result { + Ok(match s { + "ed25519" => Self::Ed25519, + "secp256k1" => Self::Secp256k1, + _ => return Err(DerivationError::Algorithm), + }) + } +} + #[derive(Serialize, Deserialize, Clone, Debug)] pub struct DerivationRequest { algorithm: DerivationAlgorithm,