PhoenixKit.API.Canonical (phoenix_kit v2.63.0)

Copy Markdown View Source

The canonical form of a tool's arguments, and the hash that binds a confirmation code, an approval and an idempotency key to a request.

Canonical JSON: object keys sorted (atoms turned into strings), arrays in their order, scalars as JSON.encode!/1 writes them. Two requests with the same arguments in a different key order hash the same; a different list order, value, type (1 and "1") or tool hashes differently. The caller passes the arguments without the control fields (dry_run, confirm_token, idempotency_key), so a confirming call, which adds a confirm_token, hashes like the preview call.

1 and 1.0 are different JSON numbers and hash differently; a client that changes how it writes a number between the preview and the confirmation gets 409 confirm_token_invalid, which is safe.

Summary

Functions

The canonical JSON of value as iodata.

The SHA-256 (64 lowercase hex characters) of the tool name and the canonical form of input.

Functions

encode(map)

@spec encode(term()) :: iodata()

The canonical JSON of value as iodata.

hash(tool_name, input)

@spec hash(String.t(), term()) :: String.t()

The SHA-256 (64 lowercase hex characters) of the tool name and the canonical form of input.