From 95416f875107706c911606b7a14cd76b52f6a787 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 12 Aug 2024 18:13:55 -0400 Subject: [PATCH] Handle BIP-32 errors instead of panicking --- Cargo.lock | 3 +++ crates/threshold-signature-server/Cargo.toml | 3 ++- crates/threshold-signature-server/src/helpers/signing.rs | 2 +- .../threshold-signature-server/src/signing_client/errors.rs | 2 ++ .../src/signing_client/protocol_execution/mod.rs | 4 ++-- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cffe24e2e..2a125d758 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -831,6 +831,8 @@ dependencies = [ "bs58 0.5.1", "hmac 0.12.1", "k256", + "once_cell", + "pbkdf2 0.12.2", "rand_core 0.6.4", "ripemd", "sha2 0.10.8", @@ -2753,6 +2755,7 @@ dependencies = [ "backoff", "base64 0.22.1", "bincode 1.3.3", + "bip32", "bip39", "blake2 0.10.6", "blake3", diff --git a/crates/threshold-signature-server/Cargo.toml b/crates/threshold-signature-server/Cargo.toml index 73772b4a8..2673b8d8e 100644 --- a/crates/threshold-signature-server/Cargo.toml +++ b/crates/threshold-signature-server/Cargo.toml @@ -57,8 +57,9 @@ uuid ={ version="1.10.0", features=["v4"] } # Misc tokio-tungstenite="0.23.1" -bip39 ={ version="2.0.0", features=["zeroize"] } bincode ="1.3.3" +bip32 ={ version="0.5.2" } +bip39 ={ version="2.0.0", features=["zeroize"] } bytes ={ version="1.7", default-features=false, features=["serde"] } base64 ="0.22.1" clap ={ version="4.5.15", features=["derive"] } diff --git a/crates/threshold-signature-server/src/helpers/signing.rs b/crates/threshold-signature-server/src/helpers/signing.rs index fc8799687..ddab8a9d0 100644 --- a/crates/threshold-signature-server/src/helpers/signing.rs +++ b/crates/threshold-signature-server/src/helpers/signing.rs @@ -45,7 +45,7 @@ pub async fn do_signing( app_state: &AppState, signing_session_info: SigningSessionInfo, request_limit: u32, - derivation_path: Option, // TODO (Nando): Not a fan of this... + derivation_path: Option, ) -> Result { tracing::debug!("Preparing to perform signing"); diff --git a/crates/threshold-signature-server/src/signing_client/errors.rs b/crates/threshold-signature-server/src/signing_client/errors.rs index 66155004d..abe5c9065 100644 --- a/crates/threshold-signature-server/src/signing_client/errors.rs +++ b/crates/threshold-signature-server/src/signing_client/errors.rs @@ -108,6 +108,8 @@ pub enum ProtocolErr { SubstrateClient(#[from] entropy_client::substrate::SubstrateError), #[error("Listener: {0}")] Listener(#[from] entropy_protocol::errors::ListenerErr), + #[error("Failed to derive BIP-32 account: {0}")] + Bip32DerivationError(#[from] bip32::Error), } impl IntoResponse for ProtocolErr { diff --git a/crates/threshold-signature-server/src/signing_client/protocol_execution/mod.rs b/crates/threshold-signature-server/src/signing_client/protocol_execution/mod.rs index 3d348ec3c..4b161a6db 100644 --- a/crates/threshold-signature-server/src/signing_client/protocol_execution/mod.rs +++ b/crates/threshold-signature-server/src/signing_client/protocol_execution/mod.rs @@ -86,8 +86,8 @@ impl<'a> ThresholdSigningService<'a> { .ok_or_else(|| ProtocolErr::Deserialization("Failed to load KeyShare".into()))?; let key_share = if let Some(path) = derivation_path { - let path = path.parse().expect("TODO"); - key_share.derive_bip32(&path).expect("TODO") + let path = path.parse()?; + key_share.derive_bip32(&path)? } else { key_share };