# `BSV.SPV.MerklePath`
[🔗](https://github.com/Bittoku/bsv_sdk_elixir/blob/main/lib/bsv/spv/merkle_path.ex#L1)

Merkle path (BUMP) types and verification — BRC-74 binary format.

A MerklePath associates a transaction with a block via a sequence of
hashes at each tree level.

# `t`

```elixir
@type t() :: %BSV.SPV.MerklePath{
  block_height: non_neg_integer(),
  path: [[BSV.SPV.MerklePath.PathElement.t()]]
}
```

# `compute_root`

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

Compute the Merkle root given a transaction hash (32 bytes, internal byte order).

If `txid` is nil, uses the first available hash from level 0.

Validates that `duplicate` elements only appear at the rightmost position
of each level (mitigates CVE-2012-2459 second preimage attack).

# `compute_root_hex`

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

Compute root from hex txid string (display order, byte-reversed).

# `from_bytes`

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

Parse a MerklePath from binary data (BRC-74).

Returns `{:ok, merkle_path, remaining_bytes}` so callers (e.g. BEEF parser)
know exactly how many bytes were consumed without re-serialization.

# `from_hex`

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

Parse a MerklePath from a hex string.

# `to_bytes`

```elixir
@spec to_bytes(t()) :: binary()
```

Serialize to BRC-74 binary format.

# `to_hex`

```elixir
@spec to_hex(t()) :: String.t()
```

Serialize to hex string.

---

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