From 856817af8b27a8ced15aee45b4cbaaa835ad2004 Mon Sep 17 00:00:00 2001 From: scilio Date: Wed, 3 Aug 2022 17:05:32 -0400 Subject: [PATCH] fix wallet comm issue when using api secrets --- src/wallet.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/wallet.rs b/src/wallet.rs index 8b3aa1b..1520812 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -108,7 +108,7 @@ impl HttpWallet { wallet_pass: &ZeroingString, ) -> Result { println!("Opening wallet at {}", wallet_owner_url); - let shared_key = HttpWallet::init_secure_api(&wallet_owner_url)?; + let shared_key = HttpWallet::init_secure_api(&wallet_owner_url, &wallet_owner_secret)?; let open_wallet_params = json!({ "name": null, @@ -131,7 +131,10 @@ impl HttpWallet { }) } - fn init_secure_api(wallet_owner_url: &SocketAddr) -> Result { + fn init_secure_api( + wallet_owner_url: &SocketAddr, + wallet_owner_secret: &Option, + ) -> Result { let secp = Secp256k1::new(); let ephemeral_sk = secp::random_secret(); let ephemeral_pk = PublicKey::from_secret_key(&secp, &ephemeral_sk)?; @@ -139,8 +142,12 @@ impl HttpWallet { "ecdh_pubkey": ephemeral_pk.serialize_vec(&secp, true).to_hex() }); - let response_pk: ECDHPubkey = - HttpWallet::send_json_request(&wallet_owner_url, "init_secure_api", &init_params)?; + let response_pk: ECDHPubkey = HttpWallet::send_json_request( + &wallet_owner_url, + &wallet_owner_secret, + "init_secure_api", + &init_params, + )?; let shared_key = { let mut shared_pubkey = response_pk.ecdh_pubkey.clone(); @@ -181,12 +188,14 @@ impl HttpWallet { fn send_json_request( wallet_owner_url: &SocketAddr, + wallet_owner_secret: &Option, method: &str, params: &serde_json::Value, ) -> Result { let url = format!("http://{}{}", wallet_owner_url, ENDPOINT); let req = build_request(method, params); - let res = client::post::(url.as_str(), None, &req)?; + let res = + client::post::(url.as_str(), wallet_owner_secret.clone(), &req)?; let parsed = res.clone().into_result()?; Ok(parsed) }