Bounded Authority Report Adapter for Bounded Authority Protocolâ„¢

Hex Docs

The Elixir signer for the Bounded Authority Protocol.

The protocol package builds the exact bytes to sign for every protocol object, verifies them, and never signs. This library does the signing: you give it a key handle that reaches your own key custody (an HSM, a KMS, or an in-process key for development) and it returns the signed compact form. The handle must contain only an opaque reference; never put private key bytes in it.

Use it when an agent or service must prove, per request, that it holds the key an issuer granted authority to: the holder signs a proof over the issuer's grant and the exact request, and any verifier checks both offline with public keys. The same signing path signs the issuer's grants, chain checkpoints, key rotations and content assertions.

Verifiers depend only on the protocol package, never on this one.

What this is not

Installation

Add the package to deps/0 in mix.exs:

def deps do
  [
    {:bounded_authority_report_adapter, "~> 2.0"}
  ]
end

Requires Elixir 1.18, 1.19 or 1.20 on Erlang/OTP 27 through 29. Mix also resolves bounded_authority_protocol from Hex using ~> 2.0.

Quick start

A key handle is a {module, term} pair. The module implements the BoundedAuthorityReportAdapter callbacks against your key store, and the term is a key reference only that module understands. This development handle derives each Ed25519 key from its name, in process. Never use it in production; a production handle forwards the same calls to your HSM or KMS.

defmodule MyApp.DevKey do
  @moduledoc "Development only: derives an Ed25519 key from its label. Never use in production."
  @behaviour BoundedAuthorityReportAdapter

  alias BoundedAuthorityReportAdapter.Custody

  @impl true
  def key_snapshot({kind, name} = reference),
    do: {:ok, {name, public_key_of(reference), purposes(kind), reference}}

  @impl true
  def sign(purpose, message, {kind, _name} = reference) do
    with true <- purpose in purposes(kind),
         {:ok, ^purpose} <- Custody.purpose(message) do
      {:ok, :crypto.sign(:eddsa, :none, message, [private_key(reference), :ed25519])}
    else
      _ -> {:error, :purpose_mismatch}
    end
  end

  defp purposes(:issuer), do: [:grant]
  defp purposes(:holder), do: [:holder_proof, :loopback_proof, :chain_anchor, :key_transition,
    :content_assertion, :diagnostic_probe]
  defp purposes(:reviewer), do: [:action_approval]

  defp private_key({kind, name}),
    do: :crypto.hash(:sha256, "development only: " <> Atom.to_string(kind) <> ":" <> name)

  defp public_key_of(reference) do
    {public_key, _private_key} = :crypto.generate_key(:eddsa, :ed25519, private_key(reference))
    public_key
  end
end

The whole loop: an issuer grants one holder key one operation, the holder signs a proof for one request, and a verifier checks the pair with public keys only.

alias BoundedAuthorityProtocol.V1

issuer = {MyApp.DevKey, {:issuer, "issuer-key-1"}}
holder = {MyApp.DevKey, {:holder, "holder-key-1"}}
now = System.system_time(:second)

# 1. Issuer: grant the holder's key the "archive_document" operation for one hour.
{:ok, {_, holder_public, _, _}} = MyApp.DevKey.key_snapshot({:holder, "holder-key-1"})
{:ok, holder_thumbprint} = BoundedAuthorityReportAdapter.public_key_thumbprint(holder_public)

{:ok, %{grant: grant}} =
  BoundedAuthorityReportAdapter.sign_grant(
    %{
      issuer: "https://issuer.example",
      grant_id: "urn:example:grant:archive-1",
      audiences: ["https://records.example"],
      issued_at: now,
      not_before: now,
      expires_at: now + 3600,
      holder_thumbprint: holder_thumbprint,
      operations: [%V1.Operation{name: "archive_document", selectors: [:all]}]
    },
    issuer
  )

# 2. Holder: sign a proof that binds the grant to this exact request. The request body
#    is passed in the protocol's tagged form, decoded from the raw bytes sent.
raw_body = ~s({"document":"minutes-2026-10-01.pdf"})
{:ok, cast_arguments} = V1.Json.decode(raw_body)

{:ok, %{grant: grant, proof: proof}} =
  BoundedAuthorityReportAdapter.sign_report(
    %{
      grant_compact: grant,
      operation: "archive_document",
      method: "POST",
      target_uri: "https://records.example/archive",
      invocation_id: "7d3f1c2e-8a4b-4c5d-9e6f-0a1b2c3d4e5f",
      cast_arguments: cast_arguments,
      nonce: "nonce-archive-1"
    },
    holder
  )

# 3. Verifier: rebuild the expected request and check grant and proof together.
{:ok, {_, issuer_public_key, _, _}} = MyApp.DevKey.key_snapshot({:issuer, "issuer-key-1"})

{:ok, facts} =
  V1.check_envelope(
    %V1.Credentials{grant: grant, proof: proof},
    %V1.ExpectedRequest{
      trusted_issuer: %V1.TrustedIssuer{key_id: "issuer-key-1", public_key: issuer_public_key},
      issuer: "https://issuer.example",
      audience: "https://records.example",
      method: "POST",
      target_uri: "https://records.example/archive",
      invocation_id: "7d3f1c2e-8a4b-4c5d-9e6f-0a1b2c3d4e5f",
      operation: "archive_document",
      cast_arguments: cast_arguments,
      evaluation_time: now,
      clock_skew: 60,
      proof_max_age: 300,
      nonce: {:required, "nonce-archive-1"},
      bounds: V1.Bounds.maximum()
    }
  )

{facts.operation, facts.authorization}
#=> {"archive_document", :not_evaluated}

check_envelope/2 returns cryptographic facts, never an authorization decision (authorization: :not_evaluated): whether to act on a verified request is the host's policy. Before any effect, the host binds the holder to its authenticated identity, applies authorization, checks current revocation, and atomically admits nonce and invocation replay identities through its durable execution record. See Framework integration. Getting started walks this loop step by step.

What it signs

Function Object Custody purpose Verify with
sign_report/3 holder proof (the grant passes through unchanged) :holder_proof V1.check_envelope/2
sign_local_loopback_report/3 local-loopback development proof (ba+loopback-proof) :loopback_proof LocalLoopbackHttp.V1.check_envelope/2
sign_grant/3 capability grant :grant V1.verify_grant/3
sign_anchor/3 consumption-chain boundary anchor :chain_anchor V1.verify_historical_anchor/3
sign_key_transition/3 historical-key transition :key_transition V1.verify_key_transition/4
sign_content_assertion/3 content assertion (ba+content-assertion) :content_assertion ContentAssertion.V1.verify_assertion/2
sign_action_approval/3 action approval record and assertion :action_approval ActionApproval.V1.verify_eddsa/3

These take Ed25519 keys (contract-major 1). BoundedAuthorityReportAdapter.V3 provides sign_report/3, sign_grant/3, sign_anchor/3, sign_key_transition/3, sign_content_assertion/3 and sign_action_approval/3 for the ES256 suite (contract-major 3) with P-256 keys. Select the module explicitly: the main surface requires a 32-byte Ed25519 public key; V3 requires a 65-byte uncompressed P-256 point. Verify functions are in the protocol package (BoundedAuthorityProtocol.*). Before acting on a verified approval, the host runs the checks in the protocol's Verifying a grant before issuing it walkthrough.

Every signing function returns {:ok, map} or {:error, reason} with a closed set of reasons and no values in errors. The public_key_thumbprint/1 helper returns {:ok, <<_::256>>} or {:error, :invalid}. See Errors.

Safety properties

Documentation

Read the guides in this order:

Runnable notebooks (each installs the exact public release):

Development

Follow the toolchain setup in Contributing before running the reproducibility check.

mix deps.get --check-locked
MIX_ENV=test mix ci

mix ci runs the same checks as CI: formatting, compilation with warnings as errors, Credo, the test suite (including a conformance round-trip against the protocol's published vectors, the notebook registry, and the recursively discovered code samples in these docs), coverage, Dialyzer, documentation, rendered links, the notebooks against this checkout, advisory audits, and the package and reproducibility checks, for the library and the example app. It runs the steps in order and exits non-zero if any step failed. Not every failing step ends the run: a failing test suite, for one, lets the later steps run, so read the whole output.

Security

Report vulnerabilities as described in SECURITY.md.

License

Apache-2.0, maintained by BaseLabs Holdings LLC. See LICENSE and NOTICE, and IPR.md for contributions and use of the name.