0xys / hdkey-rs

bip32 HD Wallet implementation in Rust
MIT License
0 stars 0 forks source link

Handle invalid curve point during derivation #9

Open 0xys opened 3 years ago

0xys commented 3 years ago

Overview

Although the probability is extremely low (one in 2^127), bip32 CFD function would produce invalid private key or public key. bip39 spec requires implementer to handle this edge case.

xprv child derivation

https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#private-parent-key--private-child-key

In case parse256(IL) ≥ n or ki = 0, the resulting key is invalid, and one should proceed with the next value for i. (Note: this has probability lower than 1 in 2127.)

xpub child derivation

https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#private-parent-key--private-child-key

In case parse256(IL) ≥ n or Ki is the point at infinity, the resulting key is invalid, and one should proceed with the next value for i.