Skip to content

add bip85-bip39 #102

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

Merged
merged 1 commit into from
Apr 6, 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
3 changes: 3 additions & 0 deletions CHANGELOG-npm.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [Unreleased]
- Add `bip85AppBip39()`

## 0.9.1
- WebHID: Automatically connect to a previoulsy connected device

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

## [Unreleased]
- Add `bip85_app_bip39()`

## 0.7.0
- cardano: add support for 258-tagged sets

Expand Down
4 changes: 2 additions & 2 deletions 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 <benma@bitbox.swiss>"]
version = "0.7.0"
version = "0.8.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.9.1
0.10.0
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 Bip85AppBip39({ bb02 } : Props) {
const [running, setRunning] = useState(false);
const [err, setErr] = useState<bitbox.Error>();

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 (
<>
<h4>BIP-85</h4>
<button onClick={actionBip85} disabled={running}>Invoke BIP-85 (BIP-39 app)</button>
<ShowError err={err} />
</>
);
}

export function General({ bb02 } : Props) {
return (
<>
Expand All @@ -94,6 +120,9 @@ export function General({ bb02 } : Props) {
<div className="action">
<ShowMnemonic bb02={bb02} />
</div>
<div className="action">
<Bip85AppBip39 bb02={bb02} />
</div>
</>
);
}
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,21 @@ impl<R: Runtime> PairedBitBox<R> {
_ => 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),
}
}
}
7 changes: 7 additions & 0 deletions src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down