-
Notifications
You must be signed in to change notification settings - Fork 2
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
Extended public/private keys for creating Stacks Accounts #4
base: main
Are you sure you want to change the base?
Conversation
… and propagate errors
…ill add error mgmt
/// Maximum size of a Base58Check-encoded extended key in bytes. | ||
/// | ||
/// Note that extended keys can also be 111-bytes. | ||
pub const MAX_BASE58_SIZE: usize = 112; |
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.
This const is not used anywhere
const INDEX_THRESHOLD: u32 = 2147483648; | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub struct ChildNumber { |
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 do you think giving a more explicit name to this structure? Something like DerivationStep, PathNode, KeyIndex or KeyStep?
} | ||
|
||
pub struct DerivationPath { | ||
pub path: Vec<ChildNumber> |
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.
It would be good if we explicitly set the depth of the derivation path at compile time so that everywhere we know the depth at compile time.
Something like that. (we also need to implements other methods like push, len and so on).
pub struct KeyPathVec<T, const MAX: usize> {
inner: Vec<T>,
}
impl<T, const MAX: usize> KeyPathVec<T, MAX> {
pub fn new() -> Self {
Self { inner: Vec::new() }
}
}
|
||
impl Version { | ||
pub fn to_bytes(&self) -> [u8; VERSION_LEN] { | ||
fn convert<'a>(version_string: &str, buf: &'a mut [u8; VERSION_LEN]) { |
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 about setting directly the correct bytes without doing a conversion so we don't need to perform any operation at runtime?
|
||
impl ExtendedKeyAttrs { | ||
pub fn new(depth: u8, parent_fingerprint: KeyFingerprint, child_number: ChildNumber) -> Self { | ||
Self { depth: depth, parent_fingerprint: parent_fingerprint, child_number: child_number } |
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.
Maybe we can directly set the index (just the unsigned integer) so that we don't have to worry about is_hardened here.
Just creating a PR because this feature it's increasing so much in size.
Still have to correctly propagate errors in key creation/derivation.
Let me know boss.