Sats Connect - Wallet API for Bitcoin & Stacks
  • Introduction
  • Wallet Providers
    • getInfo
    • getProviders & getProviderById
  • Connecting to the wallet
    • Connect to Xverse Wallet
    • Disconnect from Xverse Wallet
    • Connect to other wallets
      • Manage a user's default wallet
    • [Legacy ⚠️] getAccounts
  • Wallet Methods
    • request methods
    • wallet_getAccount
    • wallet_getNetwork
    • wallet_changeNetwork
    • Xverse Custom Methods
  • Xverse Wallet Permissions
  • Xverse Wallet events
  • BITCOIN METHODS
    • 🟠getAddresses
    • 🟠signMessage
    • 🟠signPsbt
    • 🟠sendTransfer
    • 🟠signMultipleTransactions
    • 🟠getBalance
    • 🎨createInscription
    • 🎨createRepeatInscriptions
    • 🎨ord_getInscriptions
    • 🎨ord_sendInscriptions
    • 🔲runes_getBalance
    • 🔲runes_transfer
    • 🔲Mint Runes
      • runes_estimateMint
      • runes_mint
    • 🔲Etch Runes
      • runes_estimateEtch
      • runes_etch
    • 🔲runes_getOrder
    • 🔲Speed up a Rune Mint or Etch order
      • 🔲runes_estimateRbfOrder
      • 🔲runes_rbfOrder
  • STACKS METHODS
    • 🔴stx_getAccounts
    • 🔴stx_signMessage
    • 🔴stx_signStructuredMessage
    • 🔴stx_transferStx
    • 🔴stx_signTransaction
    • 🔴stx_callContract
    • 🔴stx_deployContract
  • GUIDES
    • Verify Bitcoin message signatures
    • Creating Bitcoin PSBTs
    • 📱Mobile Integration
    • Next.js support
  • RESOURCES
    • App Template
    • Demo App
    • Changelog
    • Github Issues
    • Developer forum
    • BIP322
Powered by GitBook
On this page
  1. STACKS METHODS

stx_signStructuredMessage

Previousstx_signMessageNextstx_transferStx

Last updated 5 months ago

You can request your user to sign a message with structured data, using their wallet's Stacks address, by invoking the stx_signStructuredMessage method.

The structured data implementation makes the message easier to read and allows you facilitates the interaction with ClarityValue in your application. It follows the Signed Structured Data specification, a standard way to represent information in human-readable format in applications and smart contracts in order to produce signatures that are straightforward and inexpensive to verify. For developers familiar with Ethereum, this design is similar to .

Request parameters
Description

message

domain

To convert Clarity values to their hex representation, you can use the { cvToHex, stringAsciiCV, tupleCV, uintCV } helpers from @stacks/transactions package.

   import { cvToHex, stringAsciiCV, tupleCV, uintCV } from "@stacks/transactions";
   import { request } from "sats-connect";
   
   const response = await request("stx_signStructuredMessage", {
      message: cvToHex(tupleCV({ hello: stringAsciiCV("world") })).slice(2), // remove 0x,
      domain: cvToHex(
        tupleCV({
          name: stringAsciiCV("sats-connect-example"),
          version: stringAsciiCV("1.2.3"),
          "chain-id": uintCV(chainIds[network]),
        })
      ).slice(2),
    });
    if (response.status === "success") {
      alert("Success! Check the console for the response.");
      console.log(response.result);
    } else {
      console.error(
        "Something went wrong. Check the console for the response."
      );
      console.error(response);
    }

The user will see a Stacks structured message signing request prompt in the wallet.

Property
Description

signature

a string representing the signed message

publicKey

a string representing the public key of the address used for signing, as a hex-encoded string

a string representing the message, as a serialized in hexadecimal format.

a string representing the domain, as a serialized in hexadecimal format.

The stx_signStructuredMessage method returns a that resolves if the user approves the request. The message is then hashed using sha256 before being signed with secp256k1, and the method returns the SignStxStructuredMessageResult object:

🔴
SIP-018
EIP-712
Promise
ClarityValue
ClarityValue