Skip to content

Commit 132ced0

Browse files
authored
Merge pull request #4580 from stacks-network/feat/signer-signature-json
feat: add flag to output signer key signature in JSON
2 parents e797c04 + 37258ee commit 132ced0

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

stacks-signer/src/cli.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::path::PathBuf;
1919

2020
use blockstack_lib::chainstate::stacks::address::PoxAddress;
2121
use blockstack_lib::util_lib::signed_structured_data::pox4::Pox4SignatureTopic;
22-
use clap::{Parser, ValueEnum};
22+
use clap::{ArgAction, Parser, ValueEnum};
2323
use clarity::vm::types::QualifiedContractIdentifier;
2424
use stacks_common::address::{
2525
b58, AddressHashMode, C32_ADDRESS_VERSION_MAINNET_MULTISIG,
@@ -238,13 +238,14 @@ pub struct GenerateStackingSignatureArgs {
238238
/// BTC address used to receive rewards
239239
#[arg(short, long, value_parser = parse_pox_addr)]
240240
pub pox_address: PoxAddress,
241-
/// The reward cycle to be used in the signature's message hash
241+
/// The reward cycle during which this signature
242+
/// can be used
242243
#[arg(short, long)]
243244
pub reward_cycle: u64,
244-
/// Path to config file
245+
/// Path to signer config file
245246
#[arg(long, short, value_name = "FILE")]
246247
pub config: PathBuf,
247-
/// Topic for signature
248+
/// Stacking method that can be used
248249
#[arg(long)]
249250
pub method: StackingSignatureMethod,
250251
/// Number of cycles used as a lock period.
@@ -257,6 +258,9 @@ pub struct GenerateStackingSignatureArgs {
257258
/// A unique identifier to prevent re-using this authorization
258259
#[arg(long)]
259260
pub auth_id: u128,
261+
/// Output information in JSON format
262+
#[arg(long, action=ArgAction::SetTrue, required=false)]
263+
pub json: bool,
260264
}
261265

262266
/// Parse the contract ID

stacks-signer/src/main.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,28 @@ fn handle_generate_stacking_signature(
322322
)
323323
.expect("Failed to generate signature");
324324

325-
if do_print {
326-
println!(
327-
"\nSigner Public Key: 0x{}\nSigner Key Signature: 0x{}\n\n",
325+
let output_str = if args.json {
326+
serde_json::to_string(&serde_json::json!({
327+
"signerKey": to_hex(&public_key.to_bytes_compressed()),
328+
"signerSignature": to_hex(signature.to_rsv().as_slice()),
329+
"authId": format!("{}", args.auth_id),
330+
"rewardCycle": args.reward_cycle,
331+
"maxAmount": format!("{}", args.max_amount),
332+
"period": args.period,
333+
"poxAddress": args.pox_address.to_b58(),
334+
"method": args.method.topic().to_string(),
335+
}))
336+
.expect("Failed to serialize JSON")
337+
} else {
338+
format!(
339+
"Signer Public Key: 0x{}\nSigner Key Signature: 0x{}\n\n",
328340
to_hex(&public_key.to_bytes_compressed()),
329341
to_hex(signature.to_rsv().as_slice()) // RSV is needed for Clarity
330-
);
342+
)
343+
};
344+
345+
if do_print {
346+
println!("{}", output_str);
331347
}
332348

333349
signature
@@ -448,6 +464,7 @@ pub mod tests {
448464
period: 12,
449465
max_amount: u128::MAX,
450466
auth_id: 1,
467+
json: false,
451468
};
452469

453470
let signature = handle_generate_stacking_signature(args.clone(), false);
@@ -502,6 +519,7 @@ pub mod tests {
502519
period: 12,
503520
max_amount: u128::MAX,
504521
auth_id: 1,
522+
json: false,
505523
};
506524

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

0 commit comments

Comments
 (0)