From a31ed409a81e8b272f0c29cee0249ec82e591f99 Mon Sep 17 00:00:00 2001 From: Jacob Heider Date: Tue, 10 Jun 2025 16:17:58 -0400 Subject: [PATCH 1/3] `bpb sign-hex 0xfooo` QoL helped for tea gpg rewards wallets --- bpb/src/main.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bpb/src/main.rs b/bpb/src/main.rs index b89b17d..15469c3 100644 --- a/bpb/src/main.rs +++ b/bpb/src/main.rs @@ -35,6 +35,13 @@ fn main() -> Result<(), Error> { Some("print") => print_public_key(), Some("fingerprint") => print_fingerprint(), Some("key-id") => print_key_id(), + Some("sign-hex") => { + if let Some(hex) = args.next() { + sign_from_hex(hex) + } else { + bail!("Must specify a hex string to sign, e.g.: `bpb sign-hex 1234abcd`") + } + } Some("--help") => print_help_message(), Some(arg) if gpg_sign_arg(arg) => verify_commit(), _ => { @@ -60,6 +67,7 @@ fn print_help_message() -> Result<(), Error> { println!(" print: Print public key in OpenPGP format."); println!(" fingerprint: Print the fingerprint of the public key."); println!(" key-id: Print the key ID of the public key.\n"); + println!(" sign-hex : Sign a hex string and print the signature and public key."); println!("See https://github.com/pkgxdev/bpb for more information."); Ok(()) } @@ -155,6 +163,28 @@ fn verify_commit() -> Result<(), Error> { Ok(()) } +// Signs a hex string and prints the signature +fn sign_from_hex(hex: String) -> Result<(), Error> { + let config = Config::load()?; + let service = config.service(); + let account = config.user_id(); + let secret_str = get_keychain_item(service, account)?; + let secret = to_32_bytes(&secret_str)?; + + let keypair = KeyData::load(&config, secret)?; + // remove any leading 0x prefix + let hex = hex.trim_start_matches("0x").trim_end_matches(' '); + let data = hex::decode(hex)?; + + let signed = keypair.sign(&data)?; + let signature = hex::encode(signed.as_bytes()); + + let public_key = hex::encode_upper(keypair.public().as_bytes()); + println!("signature:\n\n{signature}\n"); + println!("public key:\n\n{public_key}\n"); + Ok(()) +} + fn delegate() -> ! { use std::process; From d20930f809653aeab8eaa02c23f3375f57529cbf Mon Sep 17 00:00:00 2001 From: Jacob Heider Date: Tue, 10 Jun 2025 17:07:30 -0400 Subject: [PATCH 2/3] thanks, Copilot! --- bpb/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bpb/src/main.rs b/bpb/src/main.rs index 15469c3..2bdf235 100644 --- a/bpb/src/main.rs +++ b/bpb/src/main.rs @@ -173,7 +173,8 @@ fn sign_from_hex(hex: String) -> Result<(), Error> { let keypair = KeyData::load(&config, secret)?; // remove any leading 0x prefix - let hex = hex.trim_start_matches("0x").trim_end_matches(' '); + let hex = hex.trim().to_lowercase(); + let hex = hex.trim_start_matches("0x"); let data = hex::decode(hex)?; let signed = keypair.sign(&data)?; From 9c3ab04be10922d6e0025101391a2e4112e0c6f8 Mon Sep 17 00:00:00 2001 From: Jacob Heider Date: Tue, 10 Jun 2025 21:56:48 -0400 Subject: [PATCH 3/3] very small mistake --- bpb/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bpb/src/main.rs b/bpb/src/main.rs index 2bdf235..cf2b774 100644 --- a/bpb/src/main.rs +++ b/bpb/src/main.rs @@ -66,8 +66,8 @@ fn print_help_message() -> Result<(), Error> { println!(" import : Import a key from the command line."); println!(" print: Print public key in OpenPGP format."); println!(" fingerprint: Print the fingerprint of the public key."); - println!(" key-id: Print the key ID of the public key.\n"); - println!(" sign-hex : Sign a hex string and print the signature and public key."); + println!(" key-id: Print the key ID of the public key."); + println!(" sign-hex : Sign a hex string and print the signature and public key.\n"); println!("See https://github.com/pkgxdev/bpb for more information."); Ok(()) }