Skip to content

Commit 3dffae9

Browse files
committed
Enable sign/verify for plain text messages with space-cli
1 parent bf86f73 commit 3dffae9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

node/src/bin/space-cli.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use spaced::{
2222
store::Sha256,
2323
wallets::AddressKind,
2424
};
25+
use spaced::rpc::SignedMessage;
2526
use wallet::bitcoin::secp256k1::schnorr::Signature;
2627
use wallet::export::WalletExport;
2728
use wallet::Listing;
@@ -193,6 +194,26 @@ enum Commands {
193194
#[arg(long, short)]
194195
fee_rate: Option<u64>,
195196
},
197+
/// Sign a message using the owner address of a space
198+
#[command(name = "signmessage")]
199+
SignMessage {
200+
space: String,
201+
/// The message to sign
202+
message: String,
203+
},
204+
/// Verify a message with the owner address of the specified space
205+
#[command(name = "verifymessage")]
206+
VerifyMessage {
207+
/// The space used to sign this message
208+
space: String,
209+
210+
/// The message to verify
211+
message: String,
212+
213+
/// The signature to verify
214+
#[arg(long)]
215+
signature: String,
216+
},
196217
/// List a space you own for sale
197218
#[command(name = "sell")]
198219
Sell {
@@ -700,6 +721,25 @@ async fn handle_commands(
700721
.verify_listing(listing).await?;
701722
println!("{}", serde_json::to_string_pretty(&result).expect("result"));
702723
}
724+
Commands::SignMessage { mut space, message } => {
725+
space = normalize_space(&space);
726+
let result = cli.client
727+
.wallet_sign_message(&cli.wallet, &space, protocol::Bytes::new(message.as_bytes().to_vec())).await?;
728+
println!("{}", result.signature);
729+
}
730+
Commands::VerifyMessage { mut space, message, signature } => {
731+
space = normalize_space(&space);
732+
let raw = hex::decode(signature)
733+
.map_err(|_| ClientError::Custom("Invalid signature".to_string()))?;
734+
let signature = Signature::from_slice(raw.as_slice())
735+
.map_err(|_| ClientError::Custom("Invalid signature".to_string()))?;
736+
let result = cli.client.verify_message(SignedMessage {
737+
space,
738+
message: protocol::Bytes::new(message.as_bytes().to_vec()),
739+
signature,
740+
}).await?;
741+
println!("{}", serde_json::to_string_pretty(&result).expect("result"));
742+
}
703743
}
704744

705745
Ok(())

0 commit comments

Comments
 (0)