Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

davinat0r
Copy link
Collaborator

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.

@davinat0r davinat0r added the enhancement New feature or request label Dec 20, 2024
@davinat0r davinat0r requested a review from iskyd December 20, 2024 17:18
@davinat0r davinat0r self-assigned this Dec 20, 2024
/// 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;
Copy link
Contributor

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 {
Copy link
Contributor

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>
Copy link
Contributor

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]) {
Copy link
Contributor

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 }
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants