Skip to content

Commit 477876a

Browse files
authored
feat(cast): Verbose signing output (#10529)
* add verbose logging * respect pipe as default * add verbose signing to signAuth
1 parent d381a8a commit 477876a

File tree

1 file changed

+48
-2
lines changed
  • crates/cast/src/cmd/wallet

1 file changed

+48
-2
lines changed

crates/cast/src/cmd/wallet/mod.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,29 @@ impl WalletSubcommands {
454454
} else {
455455
wallet.sign_message(&Self::hex_str_to_bytes(&message)?).await?
456456
};
457-
sh_println!("0x{}", hex::encode(sig.as_bytes()))?;
457+
458+
if shell::verbosity() > 0 {
459+
if shell::is_json() {
460+
sh_println!(
461+
"{}",
462+
serde_json::to_string_pretty(&json!({
463+
"message": message,
464+
"address": wallet.address(),
465+
"signature": hex::encode(sig.as_bytes()),
466+
}))?
467+
)?;
468+
} else {
469+
sh_println!(
470+
"Successfully signed!\n Message: {}\n Address: {}\n Signature: 0x{}",
471+
message,
472+
wallet.address(),
473+
hex::encode(sig.as_bytes()),
474+
)?;
475+
}
476+
} else {
477+
// Pipe friendly output
478+
sh_println!("0x{}", hex::encode(sig.as_bytes()))?;
479+
}
458480
}
459481
Self::SignAuth { rpc, nonce, chain, wallet, address } => {
460482
let wallet = wallet.signer().await?;
@@ -472,7 +494,31 @@ impl WalletSubcommands {
472494
let auth = Authorization { chain_id: U256::from(chain_id), address, nonce };
473495
let signature = wallet.sign_hash(&auth.signature_hash()).await?;
474496
let auth = auth.into_signed(signature);
475-
sh_println!("{}", hex::encode_prefixed(alloy_rlp::encode(&auth)))?;
497+
498+
if shell::verbosity() > 0 {
499+
if shell::is_json() {
500+
sh_println!(
501+
"{}",
502+
serde_json::to_string_pretty(&json!({
503+
"nonce": nonce,
504+
"chain_id": chain_id,
505+
"address": wallet.address(),
506+
"signature": hex::encode_prefixed(alloy_rlp::encode(&auth)),
507+
}))?
508+
)?;
509+
} else {
510+
sh_println!(
511+
"Successfully signed!\n Nonce: {}\n Chain ID: {}\n Address: {}\n Signature: 0x{}",
512+
nonce,
513+
chain_id,
514+
wallet.address(),
515+
hex::encode_prefixed(alloy_rlp::encode(&auth)),
516+
)?;
517+
}
518+
} else {
519+
// Pipe friendly output
520+
sh_println!("{}", hex::encode_prefixed(alloy_rlp::encode(&auth)))?;
521+
}
476522
}
477523
Self::Verify { message, signature, address } => {
478524
let recovered_address = Self::recover_address_from_message(&message, &signature)?;

0 commit comments

Comments
 (0)