AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 15 Bitcoin

Merge rust-bitcoin/rust-bitcoin#7083: key_expression: Add Xpriv::from_byte_array and Xpub::from_byte_array

Public commit record

What the developer wrote

Authored by Andrew Poelstra

91/100 · Strong
Merge rust-bitcoin/rust-bitcoin#7083: key_expression: Add Xpriv::from_byte_array and Xpub::from_byte_array

245733dab9ad8b4917ccc754361e291ceab9440a key_expression: Add Xpriv::from_byte_array and Xpub::from_byte_array (PeterXMR)

Pull request description:

An encoded extended key is always 78 bytes and `encode` already returns `[u8; 78]`, so add `Xpriv::from_byte_array` and `Xpub::from_byte_array` taking `&[u8; 78]`, and make the internal `Common::decode` take the array too.

`decode(&[u8])` is kept unchanged so callers holding a slice, `Vec` or boxed slice keep working via deref coercion without a conversion. It now checks the length, still returning `XkeyDecodeError::WrongExtendedKeyLength` on a mismatch, and delegates to `from_byte_array`. `FromStr` behaves as before.

This is purely additive, there is no API break.

Tests cover `decode` and `from_byte_array` agreeing on valid keys, `decode` rejecting 0, 77 and 79 byte inputs, and `FromStr` returning `InvalidBase58PayloadLength` for payloads of those lengths.

Closes #4196

This patch was written with the assistance of an LLM (Claude Opus 5.5) and reviewed by me.


ACKs for top commit:
apoelstra:
ACK 245733dab9ad8b4917ccc754361e291ceab9440a; successfully ran local tests
tcharding:
ACK 245733dab9ad8b4917ccc754361e291ceab9440a


Tree-SHA512: 2652c590d8e707a33d33cc0c70ccfe9f6dca24f56f7ce83b5bb757e7b4aa35392e8408919b78cd50e8a274d9e3f9aa8a7e398c51d298e8021b63e2c32a752705
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit adds two new helper functions, Xpriv::from_byte_array and Xpub::from_byte_array, for decoding Bitcoin extended keys from a fixed 78-byte array. It also moves the length check out of an internal helper so the new functions can rely on Rust's type system for length safety. The existing decode(slice) API is preserved and still validates length. There is no security bug or vulnerability here—this is a routine, purely additive API improvement with added tests.

Recommended action

No security action needed. This is a benign API enhancement. Normal code-review approval is sufficient.

Security signals we found

No strong security signals were identified.

Risk score

Why this scored 15/100

Our methodology →
Potential impact 0/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 0/15
Confidence 10/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.