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

Show consistently compressed and uncompressed wif private keys in key inpsect #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub struct KeyInfo {
pub raw_private_key: HexBytes,
#[serde(skip_serializing_if = "Option::is_none")]
pub wif_private_key: Option<PrivateKey>,
#[serde(skip_serializing_if = "Option::is_none")]
pub uncompressed_wif_private_key: Option<PrivateKey>,
pub public_key: PublicKey,
pub xonly_public_key: XOnlyPublicKey,
pub uncompressed_public_key: PublicKey,
Expand All @@ -18,9 +20,14 @@ pub struct KeyInfo {
impl GetInfo<KeyInfo> for PrivateKey {
fn get_info(&self, network: Network) -> KeyInfo {
let pubkey = self.public_key(&SECP);
let mut compressed_wif_privkey = *self;
compressed_wif_privkey.compressed = true;
let mut uncompressed_wif_privkey = *self;
uncompressed_wif_privkey.compressed = false;
KeyInfo {
raw_private_key: (&self.inner[..]).into(),
wif_private_key: Some(*self),
wif_private_key: Some(compressed_wif_privkey),
uncompressed_wif_private_key: Some(uncompressed_wif_privkey),
public_key: pubkey,
xonly_public_key: pubkey.inner.into(),
uncompressed_public_key: {
Expand All @@ -43,6 +50,7 @@ impl GetInfo<KeyInfo> for secp256k1::SecretKey {
KeyInfo {
raw_private_key: self[..].into(),
wif_private_key: None,
uncompressed_wif_private_key: None,
public_key: btc_pubkey,
xonly_public_key: pubkey.into(),
uncompressed_public_key: PublicKey {
Expand Down