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

This module parses signature entries and verifies them with host-supplied public keys.

Use it when checking signature evidence attached to an artifact.

This module does not authorize operations.

## Complete setup

Run stages 1 to 3 of the [compose and sign guide](compose-and-sign.md#3-sign-both-artifacts-and-reconcile-them)
to obtain the valid `entry`, `public_key_record`, and `blueprint_digest` used
below. It constructs and signs both artifacts in memory without a checkout.
The examples below continue that setup; keys are not printed.

```elixir
{:ok, attributes} = AgentBlueprintProtocol.Signature.verify(entry, [public_key_record])
true = attributes.purpose == :blueprint
true = AgentBlueprintProtocol.Digest.to_tagged(attributes.content_digest) == blueprint_digest
```

# `attributes`
*since 1.0.0* 

```elixir
@spec attributes(AgentBlueprintProtocol.Json.value()) ::
  {:ok, AgentBlueprintProtocol.Signature.Attributes.t()}
  | {:error, AgentBlueprintProtocol.Error.t()}
```

Parses attributes; it does not verify their signature.

Continue the [complete setup](#module-complete-setup) from the module documentation.

```elixir
{:ok, %AgentBlueprintProtocol.Signature.Attributes{purpose: :blueprint} = attributes} =
  AgentBlueprintProtocol.Signature.attributes(entry)
true = AgentBlueprintProtocol.Digest.to_tagged(attributes.content_digest) == blueprint_digest
```

# `signing_input`
*since 1.0.0* 

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

Returns the exact protected-header and detached payload bytes to sign.

Continue the [complete setup](#module-complete-setup) from the module documentation.

```elixir
{:ok, signing_input} = AgentBlueprintProtocol.Signature.signing_input(entry)
true = is_binary(signing_input)
```

# `to_compact`
*since 1.0.0* 

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

Formats the entry as detached compact serialization: protected header, two dots, signature.

Continue the [complete setup](#module-complete-setup) from the module documentation.

```elixir
{:ok, compact} = AgentBlueprintProtocol.Signature.to_compact(entry)
[header, "", signature] = String.split(compact, ".")
true = byte_size(header) > 0 and byte_size(signature) > 0
```

# `verify`
*since 1.0.0* 

```elixir
@spec verify(AgentBlueprintProtocol.Json.value(), [
  AgentBlueprintProtocol.Signature.PublicKey.t()
]) ::
  {:ok, AgentBlueprintProtocol.Signature.Attributes.t()}
  | {:error, AgentBlueprintProtocol.Error.t()}
```

Verifies the detached signature using the supplied public keys and returns verified attributes.

Continue the [complete setup](#module-complete-setup) from the module documentation.
Compare returned `purpose` and `content_digest` with the intended artifact;
standalone verification has no expected-artifact argument. Reconciliation
separately compares the signed digest with each artifact.

```elixir
{:ok, %AgentBlueprintProtocol.Signature.Attributes{purpose: :blueprint} = attributes} =
  AgentBlueprintProtocol.Signature.verify(entry, [public_key_record])
true = AgentBlueprintProtocol.Digest.to_tagged(attributes.content_digest) == blueprint_digest
```

# `verify_attestation`
*since 1.0.0* 

```elixir
@spec verify_attestation(AgentBlueprintProtocol.Json.value(), [
  AgentBlueprintProtocol.Signature.PublicKey.t()
]) ::
  {:ok, AgentBlueprintProtocol.Signature.Attributes.t()}
  | {:error, AgentBlueprintProtocol.Error.t()}
```

Validates an attestation entry against the accepted-kind set.
This release has no accepted attestation kinds, so this operation returns a typed denial;
it has no successful attestation-verification example in this release.

## Example

```elixir
match?(
  {:error, %AgentBlueprintProtocol.Error{}},
  AgentBlueprintProtocol.Signature.verify_attestation(nil, [])
)
```

---

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