BIP 32 binary encoding functions are extracted from base58#470
BIP 32 binary encoding functions are extracted from base58#470stevenroose merged 4 commits intorust-bitcoin:masterfrom BP-WG:feat/bip32-bin
Conversation
|
Could this perhaps be rebased just on master? I think this can be merged faster than the ypub stuff as it's way less opinionated on. |
|
@stevenroose done |
stevenroose
left a comment
There was a problem hiding this comment.
I don't understand one of the From cases and I think one error can be expect'ed.
src/util/bip32.rs
Outdated
There was a problem hiding this comment.
Heh, why exactly is this needed? This would create a bip32::Error::Base58(base58::Error::Other(bip32::Error::xxx)) which seems unnecessarily recursive, and should just be the inner bip32::Error::xxx instead..
src/util/bip32.rs
Outdated
There was a problem hiding this comment.
This here could be inlined to child_number: ChildNumber::from(endian::slice_to_u32_be(&data[9..13])),.
(You seem to not like .into(), because it could also be child_number: endian::slice_to_u32_be(&data[9..13]).into(),.)
There was a problem hiding this comment.
Just didn't wanted to touch original code (apart from moving it to a standalone function) to simplify the review. Done with special commit.
And I have nothing against .into() when it is obvious from the context into which type the conversion happens
|
Rebased onto fixed master (requires #512 to be merged first) and addressed @stevenroose comments |
|
Found another incorrect error conversion which fixed with 97e7d0d |
src/util/bip32.rs
Outdated
There was a problem hiding this comment.
Did you mean to use the new UnknownVersion error variant?
src/util/bip32.rs
Outdated
src/util/bip32.rs
Outdated
There was a problem hiding this comment.
This whole impl is weird and should be deleted.
|
@apoelstra your comments are addressed. Rebased onto master with the merged fix and kept two commits in the history: one for moving logic from old functions to a new once w/o code modification inside those functions; and the other on top with all improvements and addressing review suggestions. |
src/util/bip32.rs
Outdated
| ret[45] = 0; | ||
| ret[46..78].copy_from_slice(&self.private_key[..]); | ||
| fmt.write_str(&base58::check_encode_slice(&ret[..])) | ||
| fmt.write_str(&base58::check_encode_slice(&self.encode()[..])) |
There was a problem hiding this comment.
Can you use https://docs.rs/bitcoin/0.25.2/bitcoin/util/base58/fn.check_encode_slice_to_fmt.html to avoid the allocation
stevenroose
left a comment
There was a problem hiding this comment.
Looks good, could you perhaps do that one extra inline? Feel free to ignore the two nits otherwise.
src/util/bip32.rs
Outdated
| child_number: child_number, | ||
| chain_code: ChainCode::from(&data[13..45]), | ||
| public_key: PublicKey::from_slice( | ||
| &data[45..78])?, |
There was a problem hiding this comment.
nit: No reason for a newline here, but going to ack anyway
There was a problem hiding this comment.
Don't know how it happened, probably occasionally hit Enter... Fixed
src/util/bip32.rs
Outdated
| } | ||
|
|
||
| let cn_int: u32 = endian::slice_to_u32_be(&data[9..13]); | ||
| let child_number: ChildNumber = ChildNumber::from(cn_int); |
There was a problem hiding this comment.
nit: Type doesn't need to be specified twice.
There was a problem hiding this comment.
True, remnants on the older code
src/util/bip32.rs
Outdated
| }, | ||
| depth: data[4], | ||
| parent_fingerprint: Fingerprint::from(&data[5..9]), | ||
| child_number: child_number, |
There was a problem hiding this comment.
In fact this one can be inlined just like the above one to endian::slice_to_u32_be(&data[9..13]).into()
|
Updated according to @stevenroose review; all the changes are in fa4ecb4 |
Binary (non-base58) encoding for public and private keys are required for storing PSBT
PSBT_GLOBAL_XPUBaccording to BIP 174. This PR extracts binary encoding from insideDisplayandFromStrfunctions and put this as a standalone methods.This PR is dependent on #469; to see only changes specific to the current PR pls check commit 94c2dda