Trait bip38::Generate [−][src]
Expand description
Allow generation of encrypted private keys using elliptic curve multiplication.
Required methods
Create an encrypted private key in the form of a String
of 58 base58 characters based on
a passphrase (using elliptic curve multiplication and pseudo-random number generation).
This function don’t receives a private key, it’s generated internally as specified in
bip-0038
. The target string is the passphrase to be used to decrypt. The resulting
private key is only know if the encrypted private key is decrypted. So the result is, by
design, not deterministic.
When decrypting the boolean flag compress
is just an indication, but here it influences
on the resulting prefix of the encrypted private key and obviously on the indication when
decrypting, but not in the private key itself.
Examples
use bip38::{Decrypt, Generate}; // true => compress assert!("hopefully_a_strong_passphrase".generate(true).unwrap().starts_with("6Pn")); // false => uncompress assert!("hopefully_a_strong_passphrase".generate(false).unwrap().starts_with("6Pf")); assert!("バンドメイド".generate(true).unwrap().decrypt("バンドメイド").is_ok()); assert!("くるっぽー!".generate(false).unwrap().decrypt("くるっぽー!").is_ok());
Errors
The only case this function can fail by itself is if the generated private key could not
result in a bitcoin address. In this case the function results in Error::PrvKey
. All
other errors are here for safety and are related to dependencies. This function don’t
unwrap
internally to let the decision to do or not to the developer using the crate.
Passphrase
This function handle the normalization (nfc
) of the passphrase as specified on
bip-0038
.
use bip38::{Decrypt, Generate}; assert!( "\u{03d2}\u{0301}\u{0000}\u{010400}\u{01f4a9}".generate(true).unwrap() .decrypt("\u{03d2}\u{0301}\u{0000}\u{010400}\u{01f4a9}").is_ok() );