Skip to content

Commit e015094

Browse files
committed
lib: add restore_from_mnemonic()
1 parent 64e2723 commit e015094

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

Cargo.lock

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ serde_json = { version = "1.0" }
3030
thiserror = "1.0"
3131
zeroize = "1"
3232

33+
chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
3334
enum-assoc = { version = "1.1.0", optional = true }
3435
hidapi = { version = "2.3", optional = true }
3536
js-sys = { version = "0.3.64", optional = true }

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,22 @@ impl<R: Runtime> PairedBitBox<R> {
359359
_ => Err(Error::UnexpectedResponse),
360360
}
361361
}
362+
363+
/// Restore from recovery words on the Bitbox.
364+
pub async fn restore_from_mnemonic(&self) -> Result<(), Error> {
365+
let now = std::time::SystemTime::now();
366+
let duration_since_epoch = now.duration_since(std::time::UNIX_EPOCH).unwrap();
367+
match self
368+
.query_proto(Request::RestoreFromMnemonic(
369+
pb::RestoreFromMnemonicRequest {
370+
timestamp: duration_since_epoch.as_secs() as u32,
371+
timezone_offset: chrono::Local::now().offset().local_minus_utc(),
372+
},
373+
))
374+
.await?
375+
{
376+
Response::Success(_) => Ok(()),
377+
_ => Err(Error::UnexpectedResponse),
378+
}
379+
}
362380
}

0 commit comments

Comments
 (0)