mirror of
https://github.com/mimblewimble/mwixnet.git
synced 2025-01-21 03:21:09 +03:00
fix wallet comm issue when using api secrets
This commit is contained in:
parent
6f626ac11e
commit
856817af8b
1 changed files with 14 additions and 5 deletions
|
@ -108,7 +108,7 @@ impl HttpWallet {
|
||||||
wallet_pass: &ZeroingString,
|
wallet_pass: &ZeroingString,
|
||||||
) -> Result<HttpWallet> {
|
) -> Result<HttpWallet> {
|
||||||
println!("Opening wallet at {}", wallet_owner_url);
|
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!({
|
let open_wallet_params = json!({
|
||||||
"name": null,
|
"name": null,
|
||||||
|
@ -131,7 +131,10 @@ impl HttpWallet {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_secure_api(wallet_owner_url: &SocketAddr) -> Result<SecretKey> {
|
fn init_secure_api(
|
||||||
|
wallet_owner_url: &SocketAddr,
|
||||||
|
wallet_owner_secret: &Option<String>,
|
||||||
|
) -> Result<SecretKey> {
|
||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
let ephemeral_sk = secp::random_secret();
|
let ephemeral_sk = secp::random_secret();
|
||||||
let ephemeral_pk = PublicKey::from_secret_key(&secp, &ephemeral_sk)?;
|
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()
|
"ecdh_pubkey": ephemeral_pk.serialize_vec(&secp, true).to_hex()
|
||||||
});
|
});
|
||||||
|
|
||||||
let response_pk: ECDHPubkey =
|
let response_pk: ECDHPubkey = HttpWallet::send_json_request(
|
||||||
HttpWallet::send_json_request(&wallet_owner_url, "init_secure_api", &init_params)?;
|
&wallet_owner_url,
|
||||||
|
&wallet_owner_secret,
|
||||||
|
"init_secure_api",
|
||||||
|
&init_params,
|
||||||
|
)?;
|
||||||
|
|
||||||
let shared_key = {
|
let shared_key = {
|
||||||
let mut shared_pubkey = response_pk.ecdh_pubkey.clone();
|
let mut shared_pubkey = response_pk.ecdh_pubkey.clone();
|
||||||
|
@ -181,12 +188,14 @@ impl HttpWallet {
|
||||||
|
|
||||||
fn send_json_request<D: serde::de::DeserializeOwned>(
|
fn send_json_request<D: serde::de::DeserializeOwned>(
|
||||||
wallet_owner_url: &SocketAddr,
|
wallet_owner_url: &SocketAddr,
|
||||||
|
wallet_owner_secret: &Option<String>,
|
||||||
method: &str,
|
method: &str,
|
||||||
params: &serde_json::Value,
|
params: &serde_json::Value,
|
||||||
) -> Result<D> {
|
) -> Result<D> {
|
||||||
let url = format!("http://{}{}", wallet_owner_url, ENDPOINT);
|
let url = format!("http://{}{}", wallet_owner_url, ENDPOINT);
|
||||||
let req = build_request(method, params);
|
let req = build_request(method, params);
|
||||||
let res = client::post::<Request, Response>(url.as_str(), None, &req)?;
|
let res =
|
||||||
|
client::post::<Request, Response>(url.as_str(), wallet_owner_secret.clone(), &req)?;
|
||||||
let parsed = res.clone().into_result()?;
|
let parsed = res.clone().into_result()?;
|
||||||
Ok(parsed)
|
Ok(parsed)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue