# Signed Messages

The **Bitcoin protocol** allows users to sign any type of data (not just transactions) using a **Bitcoin private key**. The same counts for BSV. This process is primarily used for **message authentication**—proving that the signer has access to a specific BSV address at the time of signing.

***

### Private and Public Key Generation

The process of generating **private and public keys** is the same as in BSV transactions.\
Some wallets also provide a **message signing feature**, enabling you to sign data with your private key.

***

### How a Message is Signed

1. The message is **prepended** with the string:\
   `"Bitcoin Signed Message:\n"` along with the message length.
2. It is then **double-hashed** with **SHA-256**.
3. The result is signed using **ECDSA**.
4. The **signature** is produced as a tuple `(i, r, s)` where:
   * `i` = 1 byte (parity byte)
   * `r` = 32 bytes
   * `s` = 32 bytes
5. Finally, the tuple is **base64 encoded**.

<figure><img src="/files/3VZ1K17LexnRTxEIBA1z" alt=""><figcaption></figcaption></figure>

### How a Message is Verified

1. The **address** is transmitted with the **original message** and the **signed message**.
2. Using the **parity byte** `i`, the system derives between **0–4 candidate public keys**.
3. The verification process repeats the same steps:
   * Prepend `"Bitcoin Signed Message:\n"`
   * **Double-hash** the message with SHA-256
   * Run the **verification algorithm** for each candidate key
4. If one of the candidate keys returns **True**, the signature is valid.
5. The valid public key is then converted into an **address** and checked against the sender’s provided address.

<figure><img src="/files/eREKO9TPrld5CW8zfxsf" alt=""><figcaption></figcaption></figure>

### Address Reminder

Recall: a **BSV address** is derived as follows:

* Start with the **public key**
* Apply **SHA-256**, then **RIPEMD-160**
* Encode the result as a **Base58 string**

***

### Key Takeaway

* **Signed messages** prove control of a BSV private key without moving coins.
* The process ensures **authenticity** (message truly from the signer) and **integrity** (message unchanged).
* Both **signing** and **verification** rely on **ECDSA**, **double hashing**, and the **Base58-encoded address** structure.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hub.bsvblockchain.org/higher-learning/bsv-academy/bitcoin-primitives-digital-signatures/bsv-and-digital-signatures/signed-messages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
