-
Notifications
You must be signed in to change notification settings - Fork 129
feat: add SEP-53 message signing and verification #2346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mootz12
merged 10 commits into
stellar:main
from
tomerweller:feature/sep53-message-signing
Jan 21, 2026
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3d5bf2c
feat: add SEP-53 message signing and verification
tomerweller 104ab59
fix: address clippy warnings
tomerweller c0b97bf
Fix cargo fmt formatting
5798763
chore: improve message commands and add tests
mootz12 fe45227
Merge branch 'main' into feature/sep53-message-signing
mootz12 72c0fc8
chore: remove unnecessary Print fn
mootz12 d279f2e
Merge branch 'feature/sep53-message-signing' of github.com:tomerwelle…
mootz12 f01b058
chore: fix typo an update docs
mootz12 f2417b7
Merge branch 'main' into feature/sep53-message-signing
mootz12 8d97377
Merge branch 'main' into feature/sep53-message-signing
mootz12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| use soroban_test::{AssertExt, TestEnv}; | ||
|
|
||
| #[tokio::test] | ||
| async fn sep_53_sign_message_and_verify() { | ||
| let sandbox = &TestEnv::new(); | ||
|
|
||
| let message = "Hello, World!"; | ||
| let expected_signature = | ||
| "fO5dbYhXUhBMhe6kId/cuVq/AfEnHRHEvsP8vXh03M1uLpi5e46yO2Q8rEBzu3feXQewcQE5GArp88u6ePK6BA=="; | ||
| let wrong_signature = | ||
| "CDU265Xs8y3OWbB/56H9jPgUss5G9A0qFuTqH2zs2YDgTm+++dIfmAEceFqB7bhfN3am59lCtDXrCtwH2k1GBA=="; | ||
| let secret_key = "SAKICEVQLYWGSOJS4WW7HZJWAHZVEEBS527LHK5V4MLJALYKICQCJXMW"; | ||
| let public_key = "GBXFXNDLV4LSWA4VB7YIL5GBD7BVNR22SGBTDKMO2SBZZHDXSKZYCP7L"; | ||
| let wrong_public_key = "GAREAZZQWHOCBJS236KIE3AWYBVFLSBK7E5UW3ICI3TCRWQKT5LNLCEZ"; | ||
|
|
||
| let output = sandbox | ||
| .new_assert_cmd("message") | ||
| .args(["sign", message, "--sign-with-key", secret_key]) | ||
| .assert() | ||
| .success() | ||
| .stdout_as_str(); | ||
| assert_eq!(output.trim(), expected_signature); | ||
|
|
||
| sandbox | ||
| .new_assert_cmd("message") | ||
| .args([ | ||
| "verify", | ||
| message, | ||
| "--signature", | ||
| expected_signature, | ||
| "--public-key", | ||
| public_key, | ||
| ]) | ||
| .assert() | ||
| .success(); | ||
|
|
||
| // wrong signature | ||
| sandbox | ||
| .new_assert_cmd("message") | ||
| .args([ | ||
| "verify", | ||
| message, | ||
| "--signature", | ||
| wrong_signature, | ||
| "--public-key", | ||
| public_key, | ||
| ]) | ||
| .assert() | ||
| .failure(); | ||
|
|
||
| // wrong public key | ||
| sandbox | ||
| .new_assert_cmd("message") | ||
| .args([ | ||
| "verify", | ||
| message, | ||
| "--signature", | ||
| expected_signature, | ||
| "--public-key", | ||
| wrong_public_key, | ||
| ]) | ||
| .assert() | ||
| .failure(); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn sep_53_sign_message_and_verify_stdin() { | ||
| let sandbox = &TestEnv::new(); | ||
|
|
||
| let message = "Hello, World!"; | ||
| let expected_signature = | ||
| "fO5dbYhXUhBMhe6kId/cuVq/AfEnHRHEvsP8vXh03M1uLpi5e46yO2Q8rEBzu3feXQewcQE5GArp88u6ePK6BA=="; | ||
| let secret_key = "SAKICEVQLYWGSOJS4WW7HZJWAHZVEEBS527LHK5V4MLJALYKICQCJXMW"; | ||
| let public_key = "GBXFXNDLV4LSWA4VB7YIL5GBD7BVNR22SGBTDKMO2SBZZHDXSKZYCP7L"; | ||
|
|
||
| // sandbox | ||
| // .new_assert_cmd("keys") | ||
| // .args(["add", alias_secret, "--secret-key", secret_key]) | ||
| // .assert() | ||
| // .success(); | ||
| // sandbox | ||
| // .new_assert_cmd("keys") | ||
| // .args(["add", alias_public, "--public-key", public_key]) | ||
| // .assert() | ||
| // .success(); | ||
|
|
||
| let output = sandbox | ||
| .new_assert_cmd("message") | ||
| .write_stdin(message) | ||
| .args(["sign", "--sign-with-key", secret_key]) | ||
| .assert() | ||
| .success() | ||
| .stdout_as_str(); | ||
| assert_eq!(output.trim(), expected_signature); | ||
|
|
||
| sandbox | ||
| .new_assert_cmd("message") | ||
| .write_stdin(message) | ||
| .args([ | ||
| "verify", | ||
| "--signature", | ||
| expected_signature, | ||
| "--public-key", | ||
| public_key, | ||
| ]) | ||
| .assert() | ||
| .success(); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn sep_53_sign_message_and_verify_with_alias() { | ||
| let sandbox = &TestEnv::new(); | ||
|
|
||
| let message = "Hello, World!"; | ||
| let expected_signature = | ||
| "fO5dbYhXUhBMhe6kId/cuVq/AfEnHRHEvsP8vXh03M1uLpi5e46yO2Q8rEBzu3feXQewcQE5GArp88u6ePK6BA=="; | ||
| let public_key = "GBXFXNDLV4LSWA4VB7YIL5GBD7BVNR22SGBTDKMO2SBZZHDXSKZYCP7L"; | ||
|
|
||
| // generate a new secret "alice" and a public alias "bob" of the example pubkey | ||
| sandbox | ||
| .new_assert_cmd("keys") | ||
| .args(["generate", "alice"]) | ||
| .assert() | ||
| .success(); | ||
| sandbox | ||
| .new_assert_cmd("keys") | ||
| .args(["add", "bob", "--public-key", public_key]) | ||
| .assert() | ||
| .success(); | ||
|
|
||
| // since this is randomly generated, just validate the output matches for alice | ||
| let alice_signature = sandbox | ||
| .new_assert_cmd("message") | ||
| .write_stdin(message) | ||
| .args(["sign", "--sign-with-key", "alice"]) | ||
| .assert() | ||
| .success() | ||
| .stdout_as_str(); | ||
| sandbox | ||
| .new_assert_cmd("message") | ||
| .write_stdin(message) | ||
| .args([ | ||
| "verify", | ||
| "--signature", | ||
| &alice_signature, | ||
| "--public-key", | ||
| "alice", | ||
| ]) | ||
| .assert() | ||
| .success(); | ||
|
|
||
| // validate a public key alias works for validation | ||
| sandbox | ||
| .new_assert_cmd("message") | ||
| .write_stdin(message) | ||
| .args([ | ||
| "verify", | ||
| "--signature", | ||
| expected_signature, | ||
| "--public-key", | ||
| "bob", | ||
| ]) | ||
| .assert() | ||
| .success(); | ||
| sandbox | ||
| .new_assert_cmd("message") | ||
| .write_stdin(message) | ||
| .args([ | ||
| "verify", | ||
| "--signature", | ||
| &alice_signature, | ||
| "--public-key", | ||
| "bob", | ||
| ]) | ||
| .assert() | ||
| .failure(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| use crate::commands::global; | ||
|
|
||
| pub mod sign; | ||
| pub mod verify; | ||
|
|
||
| /// The prefix used for SEP-53 message signing. | ||
| /// See: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0053.md | ||
| pub const SEP53_PREFIX: &str = "Stellar Signed Message:\n"; | ||
|
|
||
| #[derive(Debug, clap::Subcommand)] | ||
| pub enum Cmd { | ||
| /// Sign an arbitrary message using SEP-53 | ||
| /// | ||
| /// Signs a message following the SEP-53 specification for arbitrary message signing. | ||
| /// The provided message will get prefixed with "Stellar Signed Message:\n", hashed with SHA-256, | ||
| /// and signed with the ed25519 private key. | ||
| /// | ||
| /// Example: stellar message sign "Hello, World!" --sign-with-key alice | ||
| Sign(sign::Cmd), | ||
|
|
||
| /// Verify a SEP-53 signed message | ||
| /// | ||
| /// Verifies that a signature was produced by the holder of the private key | ||
| /// corresponding to the given account public key, following the SEP-53 specification. The | ||
| /// provided message will get prefixed with "Stellar Signed Message:\n" before verification. | ||
| /// | ||
| /// Example: stellar message verify "Hello, World!" --signature <BASE64_SIG> --account GABC... | ||
| Verify(verify::Cmd), | ||
| } | ||
|
|
||
| #[derive(thiserror::Error, Debug)] | ||
| pub enum Error { | ||
| #[error(transparent)] | ||
| Sign(#[from] sign::Error), | ||
|
|
||
| #[error(transparent)] | ||
| Verify(#[from] verify::Error), | ||
| } | ||
|
|
||
| impl Cmd { | ||
| pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> { | ||
| match self { | ||
| Cmd::Sign(cmd) => cmd.run(global_args).await?, | ||
| Cmd::Verify(cmd) => cmd.run(global_args)?, | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.