From 6836cac995838af060eea3a0d2b3a119f4dbe53f Mon Sep 17 00:00:00 2001 From: benk10 Date: Tue, 26 Nov 2024 20:47:19 +0400 Subject: [PATCH 1/2] Fix getting accounts from device --- src-tauri/src/device.rs | 13 ++++++++++--- src-tauri/src/main.rs | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/device.rs b/src-tauri/src/device.rs index c7ebb13..40610db 100644 --- a/src-tauri/src/device.rs +++ b/src-tauri/src/device.rs @@ -10,7 +10,10 @@ pub enum ScriptType { P2TR, } -pub fn get_xpubs(hwi_state: &HWIClientState, account: u32) -> Result { +pub fn get_xpubs( + hwi_state: &HWIClientState, + account: usize, +) -> Result { let ss_path = get_derivation_path(ScriptType::P2WPKH, hwi_state.network, account); let ms_path = get_derivation_path(ScriptType::P2WSH, hwi_state.network, account); let tr_path = get_derivation_path(ScriptType::P2TR, hwi_state.network, account); @@ -37,14 +40,18 @@ pub fn get_xpubs(hwi_state: &HWIClientState, account: u32) -> Result DerivationPath { +fn get_derivation_path( + script_type: ScriptType, + network: Network, + account: usize, +) -> DerivationPath { let network_num = match network { Network::Bitcoin => 0, Network::Testnet | Network::Signet | Network::Regtest => 1, _ => panic!("Unsupported Network"), }; match script_type { - ScriptType::P2WPKH => format!("m/84'/{}'/{}'/", network_num, account) + ScriptType::P2WPKH => format!("m/84'/{}'/{}'", network_num, account) .parse() .unwrap(), ScriptType::P2WSH => format!("m/48'/{}'/{}'/2'", network_num, account) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 01f7523..5a34630 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -138,7 +138,7 @@ fn set_hwi_client( } #[tauri::command] -async fn hwi_get_xpubs(state: State<'_, AppState>, account: u32) -> Result { +async fn hwi_get_xpubs(state: State<'_, AppState>, account: usize) -> Result { let state = state.lock().await; let hwi_state = state.hwi.as_ref().ok_or("HWI client not initialized")?; let xpub_data = get_xpubs(hwi_state, account).map_err(|e| e.to_string())?; @@ -155,7 +155,7 @@ async fn hwi_get_xpubs(state: State<'_, AppState>, account: u32) -> Result, account: u32) -> Result { +async fn hwi_healthcheck(state: State<'_, AppState>, account: usize) -> Result { let state = state.lock().await; let hwi_state = state.hwi.as_ref().ok_or("HWI client not initialized")?; let xpub_data = get_xpubs(hwi_state, account).map_err(|e| e.to_string())?; From 0dcb1c78e09b0f8ec239768fd93244d2f0cf1ee2 Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 27 Nov 2024 15:23:39 +0400 Subject: [PATCH 2/2] Re-add m to path --- src-tauri/src/device.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/device.rs b/src-tauri/src/device.rs index 40610db..865976e 100644 --- a/src-tauri/src/device.rs +++ b/src-tauri/src/device.rs @@ -30,11 +30,11 @@ pub fn get_xpubs( } Ok(json!({ - "singleSigPath": ss_path.to_string(), + "singleSigPath": format!("m/{}", ss_path.to_string()), "singleSigXpub": single_sig_xpub.to_string(), - "multiSigPath": ms_path.to_string(), + "multiSigPath": format!("m/{}", ms_path.to_string()), "multiSigXpub": multi_sig_xpub.to_string(), - "taprootPath": tr_path.to_string(), + "taprootPath": format!("m/{}", tr_path.to_string()), "taprootXpub": taproot_xpub.to_string(), "mfp": hwi_state.fingerprint.as_ref().unwrap().to_string().to_uppercase(), }))