Skip to content

Conversation

@tomerweller
Copy link

Summary

Implements SEP-53 (Stellar Arbitrary Message Signing) by adding two new methods to the Keypair class:

  • signMessage(message): Signs an arbitrary message by prepending the SEP-53 prefix "Stellar Signed Message:\n", hashing with SHA-256, and signing with the ed25519 key.

  • verifyMessage(message, signature): Verifies a SEP-53 signature by recomputing the hash and verifying against the public key.

Both methods accept string or Buffer inputs.

Use Cases

  • Proving account ownership without on-chain transactions
  • Off-chain attestations
  • Application-specific authentication
  • Wallet verification ("Connect Wallet" flows)

Implementation Details

  • Uses the existing hash() function from hashing.js for SHA-256
  • Uses the existing sign() and verify() primitives from signing.js
  • Compatible with SEP-53 implementations in other SDKs (Python, Java, Freighter)

Example Usage

import { Keypair } from '@stellar/stellar-base';

// Sign a message
const kp = Keypair.fromSecret('SAKICEVQLYWGSOJS4WW7HZJWAHZVEEBS527LHK5V4MLJALYKICQCJXMW');
const signature = kp.signMessage('Hello, World!');

// Verify a signature
const publicKp = Keypair.fromPublicKey('GBXFXNDLV4LSWA4VB7YIL5GBD7BVNR22SGBTDKMO2SBZZHDXSKZYCP7L');
const isValid = publicKp.verifyMessage('Hello, World!', signature);

Closes #827

Test plan

  • Added comprehensive tests for signMessage and verifyMessage
  • Verified against SEP-53 test vectors from the specification
  • Tests cover edge cases: empty messages, unicode, long messages, binary data
  • Tests verify rejection of invalid signatures and wrong signers
  • All 1132 tests pass (Node.js + browser environments)

🤖 Generated with Claude Code

Implements SEP-53 (Stellar Arbitrary Message Signing) by adding two new
methods to the Keypair class:

- `signMessage(message)`: Signs an arbitrary message by prepending the
  SEP-53 prefix "Stellar Signed Message:\n", hashing with SHA-256, and
  signing with the ed25519 key.

- `verifyMessage(message, signature)`: Verifies a SEP-53 signature by
  recomputing the hash and verifying against the public key.

Both methods accept string or Buffer inputs, enabling use cases like:
- Proving account ownership
- Off-chain attestations
- Application-specific authentication

Includes comprehensive tests with SEP-53 test vectors and TypeScript
type definitions.

Closes stellar#827

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add SEP-53 message signing and verification to Keypair

1 participant