AgentBlueprintProtocol.Digest (Agent Blueprint Protocol v1.1.0)

Copy Markdown View Source

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

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

Summary

Types

The digest algorithm identifier supported by this release.

A closed digest domain used to separate protocol digest inputs.

t()

The public data type for AgentBlueprintProtocol.Digest.

Functions

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

Parses a tagged digest string.

Creates a domain-separated digest from the supplied bytes.

Creates a SHA-256 digest from the supplied bytes.

Formats a digest as its tagged wire string.

Checks a tagged digest against the supplied content and domain.

Types

algorithm()

(since 1.0.0)
@type algorithm() :: :sha256

The digest algorithm identifier supported by this release.

domain()

(since 1.0.0)
@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)
@type t() :: %AgentBlueprintProtocol.Digest{algorithm: algorithm(), bytes: <<_::256>>}

The public data type for AgentBlueprintProtocol.Digest.

Functions

equal?(arg1, arg2)

(since 1.0.0)
@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(input)

(since 1.0.0)
@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(domain, data)

(since 1.0.0)
@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(data)

(since 1.0.0)
@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(arg1)

(since 1.0.0)
@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(domain, jcs_bytes, tagged)

(since 1.0.0)
@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