Skip to content

Commit

Permalink
Merge pull request #4580 from stacks-network/feat/signer-signature-json
Browse files Browse the repository at this point in the history
feat: add flag to output signer key signature in JSON
  • Loading branch information
hstove committed Apr 2, 2024
2 parents e797c04 + 37258ee commit 132ced0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
12 changes: 8 additions & 4 deletions stacks-signer/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::path::PathBuf;

use blockstack_lib::chainstate::stacks::address::PoxAddress;
use blockstack_lib::util_lib::signed_structured_data::pox4::Pox4SignatureTopic;
use clap::{Parser, ValueEnum};
use clap::{ArgAction, Parser, ValueEnum};
use clarity::vm::types::QualifiedContractIdentifier;
use stacks_common::address::{
b58, AddressHashMode, C32_ADDRESS_VERSION_MAINNET_MULTISIG,
Expand Down Expand Up @@ -238,13 +238,14 @@ pub struct GenerateStackingSignatureArgs {
/// BTC address used to receive rewards
#[arg(short, long, value_parser = parse_pox_addr)]
pub pox_address: PoxAddress,
/// The reward cycle to be used in the signature's message hash
/// The reward cycle during which this signature
/// can be used
#[arg(short, long)]
pub reward_cycle: u64,
/// Path to config file
/// Path to signer config file
#[arg(long, short, value_name = "FILE")]
pub config: PathBuf,
/// Topic for signature
/// Stacking method that can be used
#[arg(long)]
pub method: StackingSignatureMethod,
/// Number of cycles used as a lock period.
Expand All @@ -257,6 +258,9 @@ pub struct GenerateStackingSignatureArgs {
/// A unique identifier to prevent re-using this authorization
#[arg(long)]
pub auth_id: u128,
/// Output information in JSON format
#[arg(long, action=ArgAction::SetTrue, required=false)]
pub json: bool,
}

/// Parse the contract ID
Expand Down
26 changes: 22 additions & 4 deletions stacks-signer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,28 @@ fn handle_generate_stacking_signature(
)
.expect("Failed to generate signature");

if do_print {
println!(
"\nSigner Public Key: 0x{}\nSigner Key Signature: 0x{}\n\n",
let output_str = if args.json {
serde_json::to_string(&serde_json::json!({
"signerKey": to_hex(&public_key.to_bytes_compressed()),
"signerSignature": to_hex(signature.to_rsv().as_slice()),
"authId": format!("{}", args.auth_id),
"rewardCycle": args.reward_cycle,
"maxAmount": format!("{}", args.max_amount),
"period": args.period,
"poxAddress": args.pox_address.to_b58(),
"method": args.method.topic().to_string(),
}))
.expect("Failed to serialize JSON")
} else {
format!(
"Signer Public Key: 0x{}\nSigner Key Signature: 0x{}\n\n",
to_hex(&public_key.to_bytes_compressed()),
to_hex(signature.to_rsv().as_slice()) // RSV is needed for Clarity
);
)
};

if do_print {
println!("{}", output_str);
}

signature
Expand Down Expand Up @@ -448,6 +464,7 @@ pub mod tests {
period: 12,
max_amount: u128::MAX,
auth_id: 1,
json: false,
};

let signature = handle_generate_stacking_signature(args.clone(), false);
Expand Down Expand Up @@ -502,6 +519,7 @@ pub mod tests {
period: 12,
max_amount: u128::MAX,
auth_id: 1,
json: false,
};

let signature = handle_generate_stacking_signature(args.clone(), false);
Expand Down

0 comments on commit 132ced0

Please sign in to comment.