Skip to content

Commit

Permalink
Strip input private key data
Browse files Browse the repository at this point in the history
  • Loading branch information
pshenmic committed Oct 19, 2024
1 parent da2d694 commit 058feff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/commands/masternode_vote_dpns_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct MasternodeVoteDPNSNameCommand {
#[clap(long, default_value(""))]
pro_tx_hash: String,

/// Voting (or Owner) private key in WIF format
/// Path to file with voting (or owner) private key in WIF format
#[clap(long, default_value(""))]
private_key: String,

Expand Down Expand Up @@ -67,7 +67,8 @@ impl MasternodeVoteDPNSNameCommand {
let secp = Secp256k1::new();

let private_key_data = fs::read_to_string(&self.private_key).expect("Unable to read file");
let private_key = PrivateKey::from_wif(&private_key_data).expect("Could not load private key from WIF");
let (private_key_data_stripped, _) = private_key_data.split_at(52);
let private_key = PrivateKey::from_wif(&private_key_data_stripped).expect("Could not load private key from WIF");
let public_key = private_key.public_key(&secp);
let pro_tx_hash = ProTxHash::from_hex(&self.pro_tx_hash).expect("Could not decode pro tx hash");
let voting_address = public_key.pubkey_hash().to_byte_array();
Expand Down
5 changes: 3 additions & 2 deletions src/commands/register_dpns_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct RegisterDPNSNameCommand {
#[clap(long, default_value(""))]
identity: String,

/// Identity private key in WIF format
/// Path to file with private key from Identity in WIF format
#[clap(long, default_value(""))]
private_key: String,

Expand Down Expand Up @@ -78,7 +78,8 @@ impl RegisterDPNSNameCommand {
let secp = Secp256k1::new();

let private_key_data = fs::read_to_string(&self.private_key).expect("Unable to read file");
let private_key = PrivateKey::from_wif(&private_key_data).expect("Could not load private key from WIF");
let (private_key_data_stripped, _) = private_key_data.split_at(52);
let private_key = PrivateKey::from_wif(&private_key_data_stripped).expect("Could not load private key from WIF");
let public_key = private_key.public_key(&secp);
let identifier = Identifier::from_string(&self.identity, Base58).unwrap();

Expand Down
11 changes: 8 additions & 3 deletions src/commands/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ pub struct WithdrawCommand {
/// DAPI GRPC Endpoint URL, ex. https://127.0.0.1:1443
#[clap(long, default_value(""))]
dapi_url: String,

/// Identity address, that initiate withdrawal
#[clap(long, default_value(""))]
identity: String,
/// Identity private key in WIF format

/// Path to file with private key from Identity in WIF format
#[clap(long, default_value(""))]
private_key: String,

/// Core withdrawal address (P2PKH / P2SH)
#[clap(long, default_value(""))]
withdrawal_address: String,

/// Amount of credits to withdraw
#[clap(long, default_value(""))]
amount: String,
Expand Down Expand Up @@ -65,8 +69,9 @@ impl WithdrawCommand {

let secp = Secp256k1::new();

let private_key_data = fs::read_to_string(&self.private_key).expect("Unable to read file");
let private_key = PrivateKey::from_wif(&private_key_data).expect("Could not load private key from WIF");
let private_key_data = fs::read_to_string(&self.private_key.trim()).expect("Unable to read file");
let (private_key_data_stripped, _) = private_key_data.split_at(52);
let private_key = PrivateKey::from_wif(&private_key_data_stripped).expect("Could not load private key from WIF");
let public_key = private_key.public_key(&secp);

let platform_grpc_client = PlatformGRPCClient::new(&self.dapi_url);
Expand Down

0 comments on commit 058feff

Please sign in to comment.