# `BSV.PublicKey`
[🔗](https://github.com/Bittoku/bsv_sdk_elixir/blob/main/lib/bsv/public_key.ex#L1)

Bitcoin public key operations: derivation, compression, address generation, verification.

# `t`

```elixir
@type t() :: %BSV.PublicKey{point: binary()}
```

# `compress`

```elixir
@spec compress(t()) :: t()
```

Compress a public key to 33 bytes.

# `decompress`

```elixir
@spec decompress(t()) :: {:ok, t()}
```

Decompress a public key to 65 bytes.

# `derive_child`

```elixir
@spec derive_child(t(), BSV.PrivateKey.t(), String.t()) ::
  {:ok, t()} | {:error, String.t()}
```

Derive a child public key using BRC-42 key derivation.

Computes ECDH shared secret with the private key, then
HMAC-SHA256(shared_secret_compressed, invoice_number) to derive a scalar,
multiplies G by that scalar, and adds the result to this public key point.

# `derive_shared_secret`

```elixir
@spec derive_shared_secret(t(), BSV.PrivateKey.t()) ::
  {:ok, t()} | {:error, String.t()}
```

Compute ECDH shared secret (delegates to private key).

# `from_bytes`

```elixir
@spec from_bytes(binary()) :: {:ok, t()} | {:error, String.t()}
```

Create a public key from raw bytes (33 compressed or 65 uncompressed).

Validates that the point lies on the secp256k1 curve (y² ≡ x³ + 7 mod p).

# `from_private_key`

```elixir
@spec from_private_key(BSV.PrivateKey.t()) :: t()
```

Derive a compressed public key from a private key.

# `to_address`

```elixir
@spec to_address(
  t(),
  keyword()
) :: String.t()
```

Generate a Bitcoin address from this public key.

# `verify`

```elixir
@spec verify(t(), binary(), binary()) :: boolean()
```

Verify a signature against a message hash.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
