stx_signMessage

Request the signature of an arbitrary message with the Stacks address of an account

Method name

stx_signMessage

Parameters

ParameterDescriptionRequiredType

message

Arbitrary message for signing

string

messageType

Type of message for signing: utf8 for basic string or structured for structured data.

string

network

Network for signing: mainnet, testnet (default), signet, sbtcDevenv or devnet

string

domain

Domain tuple per SIP-018 (for structured messages only)

string

Example request

try {
  // Request signature
  const response = await window.LeatherProvider.request("stx_signMessage", {
    message: "Hello world",
    messageType: "utf8",
    network: "testnet",
  });

  console.log("Response:", response);

  // Verify signature
  try {
    const isValid = Verifier.verifySignature(
      response.result.address,
      response.result.message,
      response.result.signature
    );

    console.log("Signature is valid: ", isValid);
  } catch (error) {
    console.log("Verification error:", error);
  }
} catch (error) {
  console.log("Request error:", error.error.code, error.error.message);
}

Example response

{
    "jsonrpc": "2.0",
    "id": "7d0e6f7f-3ecf-4cc4-b555-80d1e4102d01",
    "result": {
        "signature": "8d33430a7b017ba29af2410cd7e0e79edd44e004a8611132fcfa475244b00dcf72972e15ebde4a72efca1dd628414e28bfaf495098bf0506664eee54e811b20801"
    }
}

Sandbox

Install the Leather extension then try out this method below:

Preview

Last updated