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

Bitcoin Signed Messages (BSM).

Signs and verifies messages using the standard Bitcoin message signing
protocol. Messages are prefixed with +"Bitcoin Signed Message:n"+,
length-prefixed, and double-SHA-256 hashed before signing with recoverable
ECDSA. Signatures are 65-byte compact format, base64-encoded.

**@example Sign and verify a message**
```ruby
key = BSV::Primitives::PrivateKey.generate
sig = BSV::Primitives::BSM.sign('hello', key)
BSV::Primitives::BSM.verify('hello', sig, key.public_key.address) #=> true
```

## Constants
### `MAGIC_PREFIX` <a id="constant-MAGIC_PREFIX"></a> <a id="MAGIC_PREFIX-constant"></a>
The standard Bitcoin message signing prefix.

## Public Class Methods
### `magic_hash(message)` <a id="method-c-magic_hash"></a> <a id="magic_hash-class_method"></a>
Compute the double-SHA-256 hash of a Bitcoin-prefixed message.
- **@param** `message` [String] the message to hash
- **@return** [String] 32-byte double-SHA-256 digest

### `sign(message, private_key)` <a id="method-c-sign"></a> <a id="sign-class_method"></a>
Sign a message with a private key.

Produces a 65-byte compact recoverable signature encoded as base64. The flag
byte (31-34) indicates compressed P2PKH recovery per BIP-137.
- **@param** `message` [String] the message to sign
- **@param** `private_key` [PrivateKey] the signing key
- **@return** [String] base64-encoded compact signature

### `verify(message, signature, address)` <a id="method-c-verify"></a> <a id="verify-class_method"></a>
Verify a signed message against a Bitcoin address.

Recovers the public key from the compact signature and checks whether the
derived address matches the expected address.
- **@param** `message` [String] the original message
- **@param** `signature` [String] base64-encoded compact signature
- **@param** `address` [String] the expected Bitcoin address
- **@raise** [ArgumentError] if the signature encoding or flag byte is invalid
- **@return** [Boolean] +true+ if the signature is valid for the given address
