Skip to content

Commit

Permalink
Enable sign/verify for plain text messages with space-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
buffrr committed Jan 26, 2025
1 parent bf86f73 commit 764c717
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions node/src/bin/space-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use spaced::{
store::Sha256,
wallets::AddressKind,
};
use spaced::rpc::SignedMessage;
use wallet::bitcoin::secp256k1::schnorr::Signature;
use wallet::export::WalletExport;
use wallet::Listing;
Expand Down Expand Up @@ -193,6 +194,26 @@ enum Commands {
#[arg(long, short)]
fee_rate: Option<u64>,
},
/// Sign a message using the owner address of a space
#[command(name = "signmessage")]
SignMessage {
space: String,
/// The input to sign (default: text string, use --input-format for other options)
message: String,
},
/// Verify a message with the owner address of the specified space
#[command(name = "verifymessage")]
VerifyMessage {
/// The space used to sign this message
space: String,

/// The message to verify
message: String,

/// The signature to verify
#[arg(long)]
signature: String,
},
/// List a space you own for sale
#[command(name = "sell")]
Sell {
Expand Down Expand Up @@ -700,6 +721,25 @@ async fn handle_commands(
.verify_listing(listing).await?;
println!("{}", serde_json::to_string_pretty(&result).expect("result"));
}
Commands::SignMessage { mut space, message } => {
space = normalize_space(&space);
let result = cli.client
.wallet_sign_message(&cli.wallet, &space, protocol::Bytes::new(message.as_bytes().to_vec())).await?;
println!("{}", result.signature);
}
Commands::VerifyMessage { mut space, message, signature } => {
space = normalize_space(&space);
let raw = hex::decode(signature)
.map_err(|_| ClientError::Custom("Invalid signature".to_string()))?;
let signature = Signature::from_slice(raw.as_slice())
.map_err(|_| ClientError::Custom("Invalid signature".to_string()))?;
let result = cli.client.verify_message(SignedMessage {
space,
message: protocol::Bytes::new(message.as_bytes().to_vec()),
signature,
}).await?;
println!("{}", serde_json::to_string_pretty(&result).expect("result"));
}
}

Ok(())
Expand Down

0 comments on commit 764c717

Please sign in to comment.