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

feat: add flag to output signer key signature in JSON #4580

Merged
merged 7 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -320,12 +320,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 @@ -446,6 +462,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 @@ -500,6 +517,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