# `AgentBlueprintProtocol.Digest`
[🔗](https://github.com/baselabs/agent_blueprint_protocol/blob/v1.1.0/lib/agent_blueprint_protocol/digest.ex#L1)

This module creates, parses, and compares tagged SHA-256 digests.

Use it when computing or checking a digest over canonical bytes.

This module does not authorize operations.

## Example

```elixir
match?(
  "sha-256:" <> _,
  AgentBlueprintProtocol.Digest.to_tagged(
    AgentBlueprintProtocol.Digest.hash(:blueprint_content, "{}")
  )
)
```

# `algorithm`
*since 1.0.0* 

```elixir
@type algorithm() :: :sha256
```

The digest algorithm identifier supported by this release.

# `domain`
*since 1.0.0* 

```elixir
@type domain() ::
  :blueprint_content
  | :deployment_content
  | :federation_envelope
  | :signature
  | :extension_schema
  | :extension_registry
  | :conformance_report
  | :corpus_index
```

A closed digest domain used to separate protocol digest inputs.

# `t`
*since 1.0.0* 

```elixir
@type t() :: %AgentBlueprintProtocol.Digest{algorithm: algorithm(), bytes: &lt;&lt;_::256&gt;&gt;}
```

The public data type for AgentBlueprintProtocol.Digest.

# `equal?`
*since 1.0.0* 

```elixir
@spec equal?(t(), t()) :: boolean()
```

Compares two values for equality under this module’s rules.

## Example

    iex> AgentBlueprintProtocol.Digest.equal?(AgentBlueprintProtocol.Digest.hash(:signature, "input"), AgentBlueprintProtocol.Digest.hash(:signature, "input"))
    true

# `from_tagged`
*since 1.0.0* 

```elixir
@spec from_tagged(binary()) :: {:ok, t()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Parses a tagged digest string.

## Example

    iex> match?({:ok, %AgentBlueprintProtocol.Digest{algorithm: :sha256}}, AgentBlueprintProtocol.Digest.from_tagged("sha-256:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))
    true

# `hash`
*since 1.0.0* 

```elixir
@spec hash(domain(), iodata()) :: t() | {:error, AgentBlueprintProtocol.Error.t()}
```

Creates a domain-separated digest from the supplied bytes.

## Example

    iex> match?(%AgentBlueprintProtocol.Digest{algorithm: :sha256, bytes: <<_::256>>}, AgentBlueprintProtocol.Digest.hash(:blueprint_content, "{}"))
    true

# `of`
*since 1.0.0* 

```elixir
@spec of(iodata()) :: t() | {:error, AgentBlueprintProtocol.Error.t()}
```

Creates a SHA-256 digest from the supplied bytes.

## Example

    iex> match?(%AgentBlueprintProtocol.Digest{algorithm: :sha256, bytes: <<_::256>>}, AgentBlueprintProtocol.Digest.of("abc"))
    true

# `to_tagged`
*since 1.0.0* 

```elixir
@spec to_tagged(t()) :: binary() | {:error, AgentBlueprintProtocol.Error.t()}
```

Formats a digest as its tagged wire string.

## Example

    iex> digest = AgentBlueprintProtocol.Digest.hash(:blueprint_content, "{}")
    iex> String.starts_with?(AgentBlueprintProtocol.Digest.to_tagged(digest), "sha-256:")
    true

# `verify_content`
*since 1.0.0* 

```elixir
@spec verify_content(domain(), binary(), binary()) ::
  :ok | {:error, AgentBlueprintProtocol.Error.t()}
```

Checks a tagged digest against the supplied content and domain.

## Example

    iex> bytes = "{}"; tagged = AgentBlueprintProtocol.Digest.hash(:blueprint_content, bytes) |> AgentBlueprintProtocol.Digest.to_tagged(); AgentBlueprintProtocol.Digest.verify_content(:blueprint_content, bytes, tagged)
    :ok

---

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