diff --git a/CHANGELOG-npm.md b/CHANGELOG-npm.md index 554db18..9958c0c 100644 --- a/CHANGELOG-npm.md +++ b/CHANGELOG-npm.md @@ -1,5 +1,8 @@ # Changelog +## 0.13.0 +- add `changePassword()` to change the device password (firmware >=9.25.0) + ## 0.12.0 - btc: add support for OP_RETURN outputs diff --git a/CHANGELOG-rust.md b/CHANGELOG-rust.md index 634b2db..b2ebca3 100644 --- a/CHANGELOG-rust.md +++ b/CHANGELOG-rust.md @@ -1,5 +1,8 @@ # Changelog +## 0.12.0 +- add `change_password()` to change the device password (firmware >=9.25.0) + ## 0.11.0 - btc: add support for OP_RETURN outputs diff --git a/Cargo.lock b/Cargo.lock index f5d0cff..ac9a1e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,7 +162,7 @@ checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" [[package]] name = "bitbox-api" -version = "0.11.0" +version = "0.12.0" dependencies = [ "async-trait", "base32", diff --git a/Cargo.toml b/Cargo.toml index 0025066..8b3a53c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bitbox-api" authors = ["Marko Bencun "] -version = "0.11.0" +version = "0.12.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 ac454c6..54d1a4f 100644 --- a/NPM_VERSION +++ b/NPM_VERSION @@ -1 +1 @@ -0.12.0 +0.13.0 diff --git a/messages/bitbox02_system.proto b/messages/bitbox02_system.proto index a5e8e55..aef431f 100644 --- a/messages/bitbox02_system.proto +++ b/messages/bitbox02_system.proto @@ -66,3 +66,6 @@ message SetDeviceNameRequest { message SetPasswordRequest { bytes entropy = 1; } + +message ChangePasswordRequest{ +} \ No newline at end of file diff --git a/messages/hww.proto b/messages/hww.proto index 4088ae3..ea7177e 100644 --- a/messages/hww.proto +++ b/messages/hww.proto @@ -69,6 +69,7 @@ message Request { CardanoRequest cardano = 27; BIP85Request bip85 = 28; BluetoothRequest bluetooth = 29; + ChangePasswordRequest change_password = 30; } } diff --git a/sandbox/package-lock.json b/sandbox/package-lock.json index 2e0b145..fcb8c37 100644 --- a/sandbox/package-lock.json +++ b/sandbox/package-lock.json @@ -30,7 +30,7 @@ }, "../pkg": { "name": "bitbox-api", - "version": "0.12.0", + "version": "0.13.0", "license": "Apache-2.0" }, "node_modules/@esbuild/aix-ppc64": { diff --git a/sandbox/src/General.tsx b/sandbox/src/General.tsx index c6b77cb..1c00462 100644 --- a/sandbox/src/General.tsx +++ b/sandbox/src/General.tsx @@ -82,6 +82,32 @@ function ShowMnemonic({ bb02 } : Props) { ); } +function ChangePassword({ bb02 } : Props) { + const [running, setRunning] = useState(false); + const [err, setErr] = useState(); + + const actionChangePassword = async (e: FormEvent) => { + e.preventDefault(); + setRunning(true); + setErr(undefined); + try { + await bb02.changePassword(); + } catch (err) { + setErr(bitbox.ensureError(err)); + } finally { + setRunning(false); + } + } + + return ( + <> +

Change Password

+ + + + ); +} + function Bip85AppBip39({ bb02 } : Props) { const [running, setRunning] = useState(false); const [err, setErr] = useState(); @@ -123,6 +149,9 @@ export function General({ bb02 } : Props) {
+
+ +
); } diff --git a/src/lib.rs b/src/lib.rs index 5dd33cc..c551245 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -400,6 +400,19 @@ impl PairedBitBox { } } + /// Invokes the password change workflow on the device. + /// Requires firmware version >=9.25.0. + pub async fn change_password(&self) -> Result<(), Error> { + self.validate_version(">=9.25.0")?; + match self + .query_proto(Request::ChangePassword(pb::ChangePasswordRequest {})) + .await? + { + Response::Success(_) => Ok(()), + _ => 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> { diff --git a/src/shiftcrypto.bitbox02.rs b/src/shiftcrypto.bitbox02.rs index ed93f59..ee80be9 100644 --- a/src/shiftcrypto.bitbox02.rs +++ b/src/shiftcrypto.bitbox02.rs @@ -257,6 +257,10 @@ pub struct SetPasswordRequest { #[cfg_attr(feature = "wasm", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "wasm", serde(rename_all = "camelCase"))] #[derive(Clone, Copy, PartialEq, ::prost::Message)] +pub struct ChangePasswordRequest {} +#[cfg_attr(feature = "wasm", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "wasm", serde(rename_all = "camelCase"))] +#[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct BluetoothToggleEnabledRequest {} #[cfg_attr(feature = "wasm", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "wasm", serde(rename_all = "camelCase"))] @@ -2236,7 +2240,7 @@ pub struct Success {} pub struct Request { #[prost( oneof = "request::Request", - tags = "2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29" + tags = "2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30" )] pub request: ::core::option::Option, } @@ -2302,6 +2306,8 @@ pub mod request { Bip85(super::Bip85Request), #[prost(message, tag = "29")] Bluetooth(super::BluetoothRequest), + #[prost(message, tag = "30")] + ChangePassword(super::ChangePasswordRequest), } } #[cfg_attr(feature = "wasm", derive(serde::Serialize, serde::Deserialize))] diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 92bf852..25fc6cc 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -236,6 +236,12 @@ impl PairedBitBox { Ok(self.device.show_mnemonic().await?) } + /// Invokes the password change workflow on the device. + #[wasm_bindgen(js_name = changePassword)] + pub async fn change_password(&self) -> Result<(), JavascriptError> { + Ok(self.device.change_password().await?) + } + /// Retrieves an xpub. For non-standard keypaths, a warning is displayed on the BitBox even if /// `display` is false. #[wasm_bindgen(js_name = btcXpub)] diff --git a/tests/test_device.rs b/tests/test_device.rs index 3487364..a3cb634 100644 --- a/tests/test_device.rs +++ b/tests/test_device.rs @@ -42,3 +42,21 @@ async fn test_root_fingerprint() { }) .await } + +#[tokio::test] +async fn test_change_password() { + test_initialized_simulators(async |bitbox| { + if semver::VersionReq::parse(">=9.25.0") + .unwrap() + .matches(bitbox.version()) + { + assert!(bitbox.change_password().await.is_ok()); + } else { + assert!(matches!( + bitbox.change_password().await, + Err(bitbox_api::error::Error::Version(">=9.25.0")) + )); + } + }) + .await +}