Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG-npm.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG-rust.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
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: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bitbox-api"
authors = ["Marko Bencun <[email protected]>"]
version = "0.11.0"
version = "0.12.0"
homepage = "https://bitbox.swiss/"
repository = "https://github.com/BitBoxSwiss/bitbox-api-rs/"
readme = "README-rust.md"
Expand Down
2 changes: 1 addition & 1 deletion NPM_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.0
0.13.0
3 changes: 3 additions & 0 deletions messages/bitbox02_system.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ message SetDeviceNameRequest {
message SetPasswordRequest {
bytes entropy = 1;
}

message ChangePasswordRequest{
}
1 change: 1 addition & 0 deletions messages/hww.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ message Request {
CardanoRequest cardano = 27;
BIP85Request bip85 = 28;
BluetoothRequest bluetooth = 29;
ChangePasswordRequest change_password = 30;
}
}

Expand Down
2 changes: 1 addition & 1 deletion sandbox/package-lock.json

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

29 changes: 29 additions & 0 deletions sandbox/src/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ function ShowMnemonic({ bb02 } : Props) {
);
}

function ChangePassword({ bb02 } : Props) {
const [running, setRunning] = useState(false);
const [err, setErr] = useState<bitbox.Error>();

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 (
<>
<h4>Change Password</h4>
<button onClick={actionChangePassword} disabled={running}>Change password</button>
<ShowError err={err} />
</>
);
}

function Bip85AppBip39({ bb02 } : Props) {
const [running, setRunning] = useState(false);
const [err, setErr] = useState<bitbox.Error>();
Expand Down Expand Up @@ -123,6 +149,9 @@ export function General({ bb02 } : Props) {
<div className="action">
<Bip85AppBip39 bb02={bb02} />
</div>
<div className="action">
<ChangePassword bb02={bb02} />
</div>
</>
);
}
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,19 @@ impl<R: Runtime> PairedBitBox<R> {
}
}

/// 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> {
Expand Down
8 changes: 7 additions & 1 deletion src/shiftcrypto.bitbox02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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<request::Request>,
}
Expand Down Expand Up @@ -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))]
Expand Down
6 changes: 6 additions & 0 deletions src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
18 changes: 18 additions & 0 deletions tests/test_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}