Skip to content

Commit 19cffe0

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

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

node/src/bin/space-cli.rs

+41
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,27 @@ enum Commands {
193194
#[arg(long, short)]
194195
fee_rate: Option<u64>,
195196
},
197+
/// Sign a message using the owner address of the specified space
198+
#[command(name = "signmessage")]
199+
SignMessage {
200+
/// The space to use
201+
space: String,
202+
/// The message to sign
203+
message: String,
204+
},
205+
/// Verify a message using the owner address of the specified space
206+
#[command(name = "verifymessage")]
207+
VerifyMessage {
208+
/// The space to verify
209+
space: String,
210+
211+
/// The message to verify
212+
message: String,
213+
214+
/// The signature to verify
215+
#[arg(long)]
216+
signature: String,
217+
},
196218
/// List a space you own for sale
197219
#[command(name = "sell")]
198220
Sell {
@@ -700,6 +722,25 @@ async fn handle_commands(
700722
.verify_listing(listing).await?;
701723
println!("{}", serde_json::to_string_pretty(&result).expect("result"));
702724
}
725+
Commands::SignMessage { mut space, message } => {
726+
space = normalize_space(&space);
727+
let result = cli.client
728+
.wallet_sign_message(&cli.wallet, &space, protocol::Bytes::new(message.as_bytes().to_vec())).await?;
729+
println!("{}", result.signature);
730+
}
731+
Commands::VerifyMessage { mut space, message, signature } => {
732+
space = normalize_space(&space);
733+
let raw = hex::decode(signature)
734+
.map_err(|_| ClientError::Custom("Invalid signature".to_string()))?;
735+
let signature = Signature::from_slice(raw.as_slice())
736+
.map_err(|_| ClientError::Custom("Invalid signature".to_string()))?;
737+
let result = cli.client.verify_message(SignedMessage {
738+
space,
739+
message: protocol::Bytes::new(message.as_bytes().to_vec()),
740+
signature,
741+
}).await?;
742+
println!("{}", serde_json::to_string_pretty(&result).expect("result"));
743+
}
703744
}
704745

705746
Ok(())

0 commit comments

Comments
 (0)