AgentBlueprintProtocol.Canonicalization (Agent Blueprint Protocol v1.1.0)

Copy Markdown View Source

This module encodes tagged JSON values using RFC 8785 canonicalization and verifies canonical input bytes.

Use it when producing canonical bytes or checking whether received JSON is already canonical.

This module does not authorize operations.

Example

value = {:object, [{"ready", {:boolean, true}}]}
{:ok, bytes} = AgentBlueprintProtocol.Canonicalization.encode(value)

Summary

Functions

Encodes a tagged JSON value as RFC 8785 canonical UTF-8 bytes.

Decodes bounded JSON and requires the input bytes to equal its canonical encoding. Returns {:ok, tagged_value} or a typed denial, including :non_canonical_bytes.

Functions

encode(value, bounds \\ Bounds.maximum())

(since 1.0.0)

Encodes a tagged JSON value as RFC 8785 canonical UTF-8 bytes.

Example

iex> value = {:object, [{"a", {:integer, 1}}]}
iex> match?({:ok, ~S({"a":1})}, AgentBlueprintProtocol.Canonicalization.encode(value))
true
iex> match?({:ok, ~S({"a":1})}, AgentBlueprintProtocol.Canonicalization.encode(value, %{bytes: 32}))
true

verify(input, bounds \\ Bounds.maximum())

(since 1.0.0)

Decodes bounded JSON and requires the input bytes to equal its canonical encoding. Returns {:ok, tagged_value} or a typed denial, including :non_canonical_bytes.

Example

iex> match?({:ok, {:object, [{"a", {:integer, 1}}]}}, AgentBlueprintProtocol.Canonicalization.verify(~S({"a":1})))
true
iex> match?({:ok, {:object, [{"a", {:integer, 1}}]}}, AgentBlueprintProtocol.Canonicalization.verify(~S({"a":1}), %{bytes: 32}))
true