Skip to content

Commit c86a143

Browse files
authored
Merge pull request #55 from psgreco/consistent-wif
Show consistently compressed and uncompressed wif private keys in key inpsect
2 parents 799cd27 + 90ceafa commit c86a143

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/key.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub struct KeyInfo {
99
pub raw_private_key: HexBytes,
1010
#[serde(skip_serializing_if = "Option::is_none")]
1111
pub wif_private_key: Option<PrivateKey>,
12+
#[serde(skip_serializing_if = "Option::is_none")]
13+
pub uncompressed_wif_private_key: Option<PrivateKey>,
1214
pub public_key: PublicKey,
1315
pub xonly_public_key: XOnlyPublicKey,
1416
pub uncompressed_public_key: PublicKey,
@@ -18,9 +20,14 @@ pub struct KeyInfo {
1820
impl GetInfo<KeyInfo> for PrivateKey {
1921
fn get_info(&self, network: Network) -> KeyInfo {
2022
let pubkey = self.public_key(&SECP);
23+
let mut compressed_wif_privkey = *self;
24+
compressed_wif_privkey.compressed = true;
25+
let mut uncompressed_wif_privkey = *self;
26+
uncompressed_wif_privkey.compressed = false;
2127
KeyInfo {
2228
raw_private_key: (&self.inner[..]).into(),
23-
wif_private_key: Some(*self),
29+
wif_private_key: Some(compressed_wif_privkey),
30+
uncompressed_wif_private_key: Some(uncompressed_wif_privkey),
2431
public_key: pubkey,
2532
xonly_public_key: pubkey.inner.into(),
2633
uncompressed_public_key: {
@@ -43,6 +50,7 @@ impl GetInfo<KeyInfo> for secp256k1::SecretKey {
4350
KeyInfo {
4451
raw_private_key: self[..].into(),
4552
wif_private_key: None,
53+
uncompressed_wif_private_key: None,
4654
public_key: btc_pubkey,
4755
xonly_public_key: pubkey.into(),
4856
uncompressed_public_key: PublicKey {

0 commit comments

Comments
 (0)