Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle vss key not found #100

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions mutiny-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ pub enum MutinyError {
JwtAuthFailure,
#[error("Failed to parse VSS value from getObject response.")]
FailedParsingVssValue,
#[error("VSS key not found.")]
VssKeyNotFound,
#[error("Device lock changed when connecting.")]
DeviceLockChangedWhenConnecting,
#[error(transparent)]
Expand Down
3 changes: 3 additions & 0 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,9 @@ impl<S: MutinyStorage> MutinyWalletBuilder<S> {
}
}
}
Err(MutinyError::VssKeyNotFound) => {
log_info!(logger, "VSS key not found, retrying... {retries}");
}
Err(MutinyError::FailedParsingVssValue) => {
log_info!(logger, "Failed to parse VSS value, retrying... {retries}");
}
Expand Down
14 changes: 13 additions & 1 deletion mutiny-core/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,19 @@ pub trait MutinyStorage: Clone + Sized + Send + Sync + 'static {
) -> Result<(), MutinyError> {
let device = self.get_device_id()?;
let device_description = self.get_device_description();
if let Some(lock) = self.fetch_device_lock().await? {

let lock = match self.fetch_device_lock().await {
Ok(lock) => lock,
Err(MutinyError::VssKeyNotFound) => {
log_debug!(logger, "Vss device lock not yet created, proceeding...");
None
}
Err(e) => {
return Err(e);
}
};

if let Some(lock) = lock {
if lock.is_locked(&device) {
log_debug!(logger, "current device is {}", device);
log_debug!(logger, "locked device is {}", lock.device);
Expand Down
26 changes: 19 additions & 7 deletions mutiny-core/src/vss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anyhow::anyhow;
use bitcoin::secp256k1::{Secp256k1, SecretKey};
use hex_conservative::DisplayHex;
use lightning::util::logger::*;
use lightning::{log_error, log_info, log_warn};
use lightning::{log_debug, log_error, log_info, log_warn};
use reqwest::{Method, Url};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
Expand Down Expand Up @@ -170,12 +170,24 @@ impl MutinyVssClient {

let body = json!({ "store_id": self.store_id, "key": key });

let result: EncryptedVssKeyValueItem = self
.make_request(Method::POST, url, Some(body))
.await?
.json()
.await
.map_err(|e| {
let response = self.make_request(Method::POST, url, Some(body)).await?;

let response_text = response.text().await.map_err(|e| {
log_error!(self.logger, "Error reading response body: {e}");
MutinyError::FailedParsingVssValue
})?;

if response_text == "null" {
log_debug!(
self.logger,
"Vss key not found, response is 'null' for key: {}",
key
);
return Err(MutinyError::VssKeyNotFound);
}

let result: EncryptedVssKeyValueItem =
serde_json::from_str(&response_text).map_err(|e| {
log_error!(self.logger, "Error parsing get objects response: {e}");
MutinyError::FailedParsingVssValue
})?;
Expand Down
2 changes: 1 addition & 1 deletion mutiny-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cargo-features = ["per-package-target"]

[package]
name = "mutiny-wasm"
version = "1.14.2"
version = "1.14.3"
edition = "2021"
authors = ["utxostack"]
forced-target = "wasm32-unknown-unknown"
Expand Down
3 changes: 3 additions & 0 deletions mutiny-wasm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ pub enum MutinyJsError {
JwtAuthFailure,
#[error("Failed to parse VSS value from getObject response.")]
FailedParsingVssValue,
#[error("VSS key not found.")]
VssKeyNotFound,
#[error("Device lock has changed when connecting.")]
DeviceLockChangedWhenConnecting,
#[error("Cannot have more than one node.")]
Expand Down Expand Up @@ -262,6 +264,7 @@ impl From<MutinyError> for MutinyJsError {
MutinyError::InvalidHex => MutinyJsError::InvalidHex,
MutinyError::JwtAuthFailure => MutinyJsError::JwtAuthFailure,
MutinyError::FailedParsingVssValue => MutinyJsError::FailedParsingVssValue,
MutinyError::VssKeyNotFound => MutinyJsError::VssKeyNotFound,
MutinyError::DeviceLockChangedWhenConnecting => {
MutinyJsError::DeviceLockChangedWhenConnecting
}
Expand Down
Loading