# Module BSV::Primitives::SignedMessage <a id="module-BSV-Primitives-SignedMessage"></a>

BRC-77 signed messages.

Provides authenticated messaging using BRC-42 derived signing keys. The sender
proves their identity to a specific recipient (or anyone) without encrypting
the message content.

- **@see** `https://github.com/bitcoin-sv/BRCs/blob/master/peer-to-peer/0077.md`

**@example Sign and verify for a specific recipient**
```ruby
sig = SignedMessage.sign(message, sender_priv, recipient_pub)
SignedMessage.verify(message, sig, recipient_priv) #=> true
```

**@example Sign for anyone to verify**
```ruby
sig = SignedMessage.sign(message, sender_priv)
SignedMessage.verify(message, sig) #=> true
```

## Constants
### `VERSION` <a id="constant-VERSION"></a> <a id="VERSION-constant"></a>
Protocol version bytes: "BB3x01"

## Public Class Methods
### `sign(message, signer, verifier = nil)` <a id="method-c-sign"></a> <a id="sign-class_method"></a>
Sign a message using the BRC-77 protocol.
- **@param** `message` [String] the message to sign
- **@param** `signer` [PrivateKey] the sender's private key
- **@param** `verifier` [PublicKey, nil] the recipient's public key (nil for anyone-can-verify)
- **@return** [String] binary signed message (version + keys + key_id + DER signature)

### `verify(message, sig, recipient = nil)` <a id="method-c-verify"></a> <a id="verify-class_method"></a>
Verify a BRC-77 signed message.
- **@param** `message` [String] the original message
- **@param** `sig` [String] the binary signature (from {.sign})
- **@param** `recipient` [PrivateKey, nil] the recipient's private key (nil for anyone-can-verify)
- **@raise** [ArgumentError] if the version is wrong, recipient is required but missing, or recipient doesn't match
- **@return** [Boolean] true if the signature is valid
