-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Arbitrary labels for extended keys (u32, H256 built-in) #4438
Conversation
ethkey/src/extended.rs
Outdated
@@ -21,6 +21,46 @@ use Public; | |||
use bigint::hash::{H256, FixedHash}; | |||
pub use self::derivation::Error as DerivationError; | |||
|
|||
pub trait Label { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
particularly the implied invariant on store
that target.len()
must be > T::len()
, and that breaking this invariant will lead to panic.
ethkey/src/extended.rs
Outdated
@@ -228,24 +266,24 @@ mod derivation { | |||
// curve point (compressed public key) -- index | |||
// 0.33 -- 33..37 | |||
data[0..33].copy_from_slice(&public_serialized); | |||
BigEndian::write_u32(&mut data[33..37], index); | |||
index.store(&mut data[33..37]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use T::len()
looks like this only supports hard derivation for > 31 bit indexes, no? it's important to support soft derivation for 256-bit indexes... |
@gavofyork Nope, both soft and hard derivation can be made for any It's just the original bitcoin spec that splits 0..2^32 field to two fields of |
cool |
ethkey/src/extended.rs
Outdated
fn len() -> usize { 32 } | ||
|
||
fn store(&self, target: &mut [u8]) { | ||
self.copy_to(&mut target[0..4]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's happening here? only copying the first 4 bytes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah right
i added it more like an example here, didn't payed much attention, thanx
Can be basically any byte sequence (but caller must be sure what is he doing since key is compacted into a 512-bit hash after all, no matter of original data length). This slightly increase complexity of the signatures, but probably worth it.