From f871c8e4ebe379c431ae91f10d316c964e48dfbc Mon Sep 17 00:00:00 2001 From: Marko Bencun Date: Sun, 6 Apr 2025 21:57:58 +0200 Subject: [PATCH] add bip85-bip39 --- CHANGELOG-npm.md | 3 +++ CHANGELOG-rust.md | 3 +++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- NPM_VERSION | 2 +- sandbox/package-lock.json | 2 +- sandbox/src/General.tsx | 29 +++++++++++++++++++++++++++++ src/lib.rs | 17 +++++++++++++++++ src/wasm/mod.rs | 7 +++++++ 9 files changed, 64 insertions(+), 5 deletions(-) diff --git a/CHANGELOG-npm.md b/CHANGELOG-npm.md index 9f7cded..fc79986 100644 --- a/CHANGELOG-npm.md +++ b/CHANGELOG-npm.md @@ -1,5 +1,8 @@ # Changelog +## [Unreleased] +- Add `bip85AppBip39()` + ## 0.9.1 - WebHID: Automatically connect to a previoulsy connected device diff --git a/CHANGELOG-rust.md b/CHANGELOG-rust.md index 944e169..f5a96ab 100644 --- a/CHANGELOG-rust.md +++ b/CHANGELOG-rust.md @@ -1,5 +1,8 @@ # Changelog +## [Unreleased] +- Add `bip85_app_bip39()` + ## 0.7.0 - cardano: add support for 258-tagged sets diff --git a/Cargo.lock b/Cargo.lock index 82caeba..603607b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -162,7 +162,7 @@ checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" [[package]] name = "bitbox-api" -version = "0.7.0" +version = "0.8.0" dependencies = [ "async-trait", "base32", diff --git a/Cargo.toml b/Cargo.toml index 5ae7fdb..16d0309 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bitbox-api" authors = ["Marko Bencun "] -version = "0.7.0" +version = "0.8.0" homepage = "https://bitbox.swiss/" repository = "https://github.com/BitBoxSwiss/bitbox-api-rs/" readme = "README-rust.md" diff --git a/NPM_VERSION b/NPM_VERSION index f514a2f..2774f85 100644 --- a/NPM_VERSION +++ b/NPM_VERSION @@ -1 +1 @@ -0.9.1 \ No newline at end of file +0.10.0 \ No newline at end of file diff --git a/sandbox/package-lock.json b/sandbox/package-lock.json index c9ea28b..4102d41 100644 --- a/sandbox/package-lock.json +++ b/sandbox/package-lock.json @@ -30,7 +30,7 @@ }, "../pkg": { "name": "bitbox-api", - "version": "0.9.0", + "version": "0.9.1", "license": "Apache-2.0" }, "node_modules/@esbuild/aix-ppc64": { diff --git a/sandbox/src/General.tsx b/sandbox/src/General.tsx index a760a5b..c6b77cb 100644 --- a/sandbox/src/General.tsx +++ b/sandbox/src/General.tsx @@ -82,6 +82,32 @@ function ShowMnemonic({ bb02 } : Props) { ); } +function Bip85AppBip39({ bb02 } : Props) { + const [running, setRunning] = useState(false); + const [err, setErr] = useState(); + + const actionBip85 = async (e: FormEvent) => { + e.preventDefault(); + setRunning(true); + setErr(undefined); + try { + await bb02.bip85AppBip39(); + } catch (err) { + setErr(bitbox.ensureError(err)); + } finally { + setRunning(false); + } + } + + return ( + <> +

BIP-85

+ + + + ); +} + export function General({ bb02 } : Props) { return ( <> @@ -94,6 +120,9 @@ export function General({ bb02 } : Props) {
+
+ +
); } diff --git a/src/lib.rs b/src/lib.rs index 02475e5..25c093b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -392,4 +392,21 @@ impl PairedBitBox { _ => Err(Error::UnexpectedResponse), } } + + /// Invokes the BIP85-BIP39 workflow on the device, letting the user select the number of words + /// (12, 28, 24) and an index and display a derived BIP-39 mnemonic. + pub async fn bip85_app_bip39(&self) -> Result<(), Error> { + self.validate_version(">=9.17.0")?; + match self + .query_proto(Request::Bip85(pb::Bip85Request { + app: Some(pb::bip85_request::App::Bip39(())), + })) + .await? + { + Response::Bip85(pb::Bip85Response { + app: Some(pb::bip85_response::App::Bip39(())), + }) => Ok(()), + _ => Err(Error::UnexpectedResponse), + } + } } diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 46eb3eb..1a3ad1a 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -563,6 +563,13 @@ impl PairedBitBox { let result = self.device.cardano_sign_transaction(tt).await?; Ok(serde_wasm_bindgen::to_value(&result).unwrap().into()) } + + /// Invokes the BIP85-BIP39 workflow on the device, letting the user select the number of words + /// (12, 28, 24) and an index and display a derived BIP-39 mnemonic. + #[wasm_bindgen(js_name = bip85AppBip39)] + pub async fn bip85_app_bip39(&self) -> Result<(), JavascriptError> { + Ok(self.device.bip85_app_bip39().await?) + } } #[cfg(test)]