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

Improve derivation path checking logic #3

Open
lrettig opened this issue May 7, 2023 · 0 comments
Open

Improve derivation path checking logic #3

lrettig opened this issue May 7, 2023 · 0 comments
Labels
help wanted Extra attention is needed technical debt

Comments

@lrettig
Copy link
Member

lrettig commented May 7, 2023

It's not 100% clear whether this logic belongs here, or whether the caller should implement it (and this lib should be more unopinionated). Either remove it, and make sure similar logic is called downstream, or else clean this up (move it into the derivation-path crate and bake it into the type).

// for now we are rather strict with which types of paths we accept, to avoid errors and to
// be as compatible as possible with BIP-44. the path must be of the format
// "m/44'/540'/...", i.e., it must have purpose 44 and coin type
// 540 and all path elements must be hardened. we expect it to contain between 2 and 5
// elements.
if derivation_path_inner.path().len() < 2 {
err!("path too short");
}
if derivation_path_inner.path().len() > 5 {
err!("path too long");
}
if derivation_path_inner.path()[0].to_u32() != 44 {
err!("bad path purpose");
}
if derivation_path_inner.path()[1].to_u32() != 540 {
err!("bad path coin type");
}
for p in derivation_path_inner.path() {
if !p.is_hardened() {
err!("path isn't fully hardened");
}
}

@lrettig lrettig added technical debt help wanted Extra attention is needed labels May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed technical debt
Projects
None yet
Development

No branches or pull requests

1 participant