soroban_cli/commands/message/
mod.rs

1use crate::commands::global;
2
3pub mod sign;
4pub mod verify;
5
6/// The prefix used for SEP-53 message signing.
7/// See: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0053.md
8pub const SEP53_PREFIX: &str = "Stellar Signed Message:\n";
9
10#[derive(Debug, clap::Subcommand)]
11pub enum Cmd {
12    /// Sign an arbitrary message using SEP-53
13    ///
14    /// Signs a message following the SEP-53 specification for arbitrary message signing.
15    /// The provided message will get prefixed with "Stellar Signed Message:\n", hashed with SHA-256,
16    /// and signed with the ed25519 private key.
17    ///
18    /// Example: stellar message sign "Hello, World!" --sign-with-key alice
19    Sign(sign::Cmd),
20
21    /// Verify a SEP-53 signed message
22    ///
23    /// Verifies that a signature was produced by the holder of the private key
24    /// corresponding to the given account public key, following the SEP-53 specification. The
25    /// provided message will get prefixed with "Stellar Signed Message:\n" before verification.
26    ///
27    /// Example: stellar message verify "Hello, World!" --signature BASE64_SIG --public-key GABC...
28    Verify(verify::Cmd),
29}
30
31#[derive(thiserror::Error, Debug)]
32pub enum Error {
33    #[error(transparent)]
34    Sign(#[from] sign::Error),
35
36    #[error(transparent)]
37    Verify(#[from] verify::Error),
38}
39
40impl Cmd {
41    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
42        match self {
43            Cmd::Sign(cmd) => cmd.run(global_args).await?,
44            Cmd::Verify(cmd) => cmd.run(global_args)?,
45        }
46        Ok(())
47    }
48}