Message Signing

Learn how to implement message signing in your Stacks application. Message signing allows users to cryptographically prove they control an address without making an on-chain transaction, enabling authentication, authorization, and verifiable statements.

What you'll learn

  • Connect to a user's wallet and request message signatures

  • Sign both simple text messages and structured data

  • Verify signatures to ensure authenticity

Prerequisites

  • Node.js installed on your machine

  • A code editor like VS Code

Installation

Install the required packages for message signing and verification.

npm install @stacks/connect @stacks/encryption

Connect to wallet

Before signing messages, establish a connection to the user's wallet. The connection persists across page reloads.

Call this function when your app loads or when the user clicks a connect button.

Sign text messages

Request a signature for a simple text message using the request method.

The wallet will display the message to the user for approval before signing.

Sign structured data

For more complex data, use structured message signing with Clarity values.

Structured messages provide better type safety and are easier to parse on-chain.

Verify signatures

Validate signatures to ensure they match the expected message and public key.

Always verify signatures before trusting the signed data.

Complete verification flow

Try it out

Create a simple authentication system using message signatures.

Last updated

Was this helpful?