refactor(sdk): replace get_xpub and get_public_key with get_public_node
What changed, and why it matters
This commit is a routine internal code cleanup in the Trezor firmware SDK. It renames and consolidates two ways of reading a public key into a single function, and adds a helper to decompress ECDSA public keys. There is no indication of a security bug being fixed.
No security action required; treat as normal refactoring review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors the Rust SDK’s crypto trait and implementations: CryptoV1::get_xpub and CryptoV1::get_public_key are replaced by CryptoV1::get_public_node, which returns the raw serialized public-node data (depth, fingerprint, child number, chain code, public key). Higher-level callers now derive xpub strings and public-key bytes from that PublicNode object. A new ecdsa_uncompress_pubkey helper is added to the trait and mock. The IPC buffer sizing comment is updated to reference the new method name. No security vulnerability is addressed in the diff.
Changed components
sdk/crates/trezor-app-sdk/src/crypto.rssdk/crates/trezor-app-sdk/src/mock.rssdk/crates/trezor-app-sdk/src/traits/crypto.rssdk/crates/trezor-app-tool/src/image/metadata.rsInspect captured patch +35 / −42
### sdk/crates/trezor-app-sdk/src/crypto.rs
@@ -120,28 +120,12 @@ impl PublicNode {
/// Derives the public node for `address_n` on `curve`.
pub fn get_public_node(curve: Curve, address_n: &[u32]) -> Result<PublicNode> {
get_crypto_or_die()
- .get_xpub(curve, address_n.into())
+ .get_public_node(curve, address_n.into())
.into_app_result()
.c()
.map(|raw| PublicNode::from_raw(&raw))
}
-/// Derives the extended public key (xpub) for `address_n` on `curve`,
-/// base58check-encoded with `version` as its version bytes (e.g. the
-/// "xpub"/"ypub"/"zpub" prefix bytes for the coin/script type in use).
-pub fn get_xpub(curve: Curve, address_n: &[u32], version: u32) -> Result<String> {
- Ok(get_public_node(curve, address_n)?.to_xpub(version))
-}
-
-/// Derives the public key for `address_n` on `curve`.
-pub fn get_public_key(curve: Curve, address_n: &[u32], compressed: bool) -> Result<Vec<u8>> {
- get_crypto_or_die()
- .get_public_key(curve, address_n.into(), compressed)
- .into_app_result()
- .c()
- .map(|b| b.as_ref().to_vec())
-}
-
/// Signs a raw 32-byte digest with the ECDSA key at `address_n` on `curve`,
/// returning the 65-byte recoverable signature. Ed25519 has no digest
/// signing, see [`ed25519_sign`].
@@ -221,6 +205,15 @@ pub fn ecdsa_recover_pubkey(curve: EcdsaCurve, signature: &[u8], digest: &[u8])
.map(|b| b.as_ref().to_vec())
}
+/// Uncompresses a 33-byte compressed ECDSA `public_key`, e.g. a
+/// [`PublicNode::public_key`], into its 65-byte `0x04`-prefixed form.
+pub fn ecdsa_uncompress_pubkey(curve: EcdsaCurve, public_key: &[u8; 33]) -> Result<[u8; 65]> {
+ get_crypto_or_die()
+ .ecdsa_uncompress_pubkey(curve, *public_key)
+ .into_app_result()
+ .c()
+}
+
/// Verifies a 64-byte Ed25519 `signature` of `message` against the 32-byte
/// `public_key`.
pub fn ed25519_verify(public_key: &[u8], signature: &[u8], message: &[u8]) -> Result<()> {
### sdk/crates/trezor-app-sdk/src/mock.rs
@@ -133,23 +133,14 @@ impl CryptoV1 for DummyCrypto {
}
}
- extern "C" fn get_xpub<'a>(
+ extern "C" fn get_public_node<'a>(
&self,
_curve: Curve,
_address_n: Slice<'a, u32>,
) -> ServiceResult<[u8; XPUB_RAW_LEN], CryptoError> {
unimplemented!("not exercised by the current test suite")
}
- extern "C" fn get_public_key<'a>(
- &self,
- _curve: Curve,
- _address_n: Slice<'a, u32>,
- _compressed: bool,
- ) -> ServiceResult<stabby::boxed::BoxedSlice<u8>, CryptoError> {
- unimplemented!("not exercised by the current test suite")
- }
-
extern "C" fn ecdsa_sign_digest<'a>(
&self,
_curve: EcdsaCurve,
@@ -207,6 +198,14 @@ impl CryptoV1 for DummyCrypto {
unimplemented!("not exercised by the current test suite")
}
+ extern "C" fn ecdsa_uncompress_pubkey(
+ &self,
+ _curve: EcdsaCurve,
+ _public_key: [u8; 33],
+ ) -> FastResult<[u8; 65], CryptoError> {
+ unimplemented!("not exercised by the current test suite")
+ }
+
extern "C" fn ed25519_verify<'a>(
&self,
_public_key: Slice<'a, u8>,
### sdk/crates/trezor-app-sdk/src/traits/crypto.rs
@@ -5,8 +5,8 @@ use stabby::str::Str;
use super::util::{FastResult, ServiceResult};
-/// Length of [`CryptoV1::get_xpub`]'s result: a serialized xpub without its
-/// 4-byte version.
+/// Length of [`CryptoV1::get_public_node`]'s result: a serialized xpub
+/// without its 4-byte version.
pub const XPUB_RAW_LEN: usize = 74;
/// Errors of the cryptographic functions.
@@ -115,21 +115,14 @@ pub trait CryptoV1: Send + Sync {
/// Derives the public node for `address_n` on `curve`, as a serialized
/// xpub without its version: depth (1), parent fingerprint (4), child
- /// number (4), chain code (32) and compressed public key (33).
- extern "C" fn get_xpub<'a>(
+ /// number (4), chain code (32) and public key (33): compressed for ECDSA
+ /// curves, `0x00` followed by the key for EdDSA curves (SLIP-10).
+ extern "C" fn get_public_node<'a>(
&self,
curve: Curve,
address_n: Slice<'a, u32>,
) -> ServiceResult<[u8; XPUB_RAW_LEN], CryptoError>;
- /// Derives the public key for `address_n` on `curve`.
- extern "C" fn get_public_key<'a>(
- &self,
- curve: Curve,
- address_n: Slice<'a, u32>,
- compressed: bool,
- ) -> ServiceResult<BoxedSlice<u8>, CryptoError>;
-
/// Signs a raw 32-byte digest with the ECDSA key at `address_n`; Ed25519
/// has no digest signing, see [`Self::ed25519_sign`].
///
@@ -196,6 +189,14 @@ pub trait CryptoV1: Send + Sync {
digest: Slice<'a, u8>,
) -> FastResult<BoxedSlice<u8>, CryptoError>;
+ /// Uncompresses a 33-byte compressed ECDSA `public_key` into its 65-byte
+ /// `0x04`-prefixed form.
+ extern "C" fn ecdsa_uncompress_pubkey(
+ &self,
+ curve: EcdsaCurve,
+ public_key: [u8; 33],
+ ) -> FastResult<[u8; 65], CryptoError>;
+
/// Verifies a 64-byte Ed25519 `signature` of `message` against the
/// 32-byte `public_key`.
extern "C" fn ed25519_verify<'a>(
### sdk/crates/trezor-app-tool/src/image/metadata.rs
@@ -20,9 +20,9 @@ pub const IPC_BUFFER_MIN_SIZE: u64 = 256;
///
/// Sized off the fixed API traffic, not off wire messages: the largest reply
/// Core sends back over IPC is the 111-byte xpub from
-/// `CryptoV1::get_xpub`, and UI replies are a handful of bytes each. With the
-/// 12-byte `ipc_queue_item_t` header that is ~128 bytes for the biggest single
-/// message, so 1 KiB leaves 8x headroom for queued replies.
+/// `CryptoV1::get_public_node`, and UI replies are a handful of bytes each.
+/// With the 12-byte `ipc_queue_item_t` header that is ~128 bytes for the
+/// biggest single message, so 1 KiB leaves 8x headroom for queued replies.
///
/// An app that receives host wire messages through the same inbox needs more
/// than this and must say so explicitly -- there is no way to guess how largeWhy this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.