Agents: signed action envelope and endpoints
The protocol 3 AgentsAction envelope and its zero-sig signing rule, the two endpoint layouts, server URL normalization and the secret-target check.

src/agents/envelope.ts is the protocol edge of the agents package. It builds the signed envelope every request carries, resolves the three endpoint URLs of an agents server, and validates what the user types as a server address. It has no network code and no state.

The envelope

encodeAgentEnvelope(signer, action, now) returns DAG-CBOR bytes of this map:

Field

Value

type

"AgentsAction"

signer

The signing key as a principal: 34 bytes, the Ed25519 multicodec prefix 0xed 0x01 then the 32 byte public key

sig

64 byte Ed25519 signature

account

The principal bytes decoded from the account id string

protocol

3

action

The action object with undefined fields removed, plus ts: Math.floor(now) in milliseconds

The action's discriminator is its _ field, for example {_: 'ListAgents'}.

Zero-sig signing

The signature covers the whole envelope, including a placeholder for itself:

    Build the envelope with sig set to 64 zero bytes.

    Encode it with the canonical codec and sign those bytes.

    Encode again with the real signature in place.

A verifier does the reverse: replace sig with zeros, re-encode, verify. The first unit test checks both that this verifies and that verifying over the envelope with sig removed does not. The codec is encode from src/crypto/cbor, crypto's vendored cborg with DAG-CBOR options. The header comment explains: "The server verifies by re-encoding with the shared client codec ... which is exactly crypto's vendored encode; no separately patched cborg is needed here". See Crypto: vendored codecs.

omitUndefined strips undefined object fields recursively, maps undefined array items to null, and leaves Uint8Array values intact so a binary field such as SetSecret.value stays bytes.

Signers

AgentSigner is {accountId, publicKey, sign(bytes)}. publicKey may be raw (32 bytes) or already a principal (34 bytes); the encoder normalises it. If the principal string does not equal signer.accountId, encoding throws "The local key holds no delegation for this account": delegated signing with a capability is not implemented, so the signer and the account are always the same key. In production the signer comes from signerFor in identity. agentSignerFromSeed builds one from an explicit seed and is "used only with throwaway keys in tests".

Endpoint layouts

agentEndpoint(base, leaf) supports two server layouts:

Leaf

Base path ends with /hm/api/agents

Any other base

message

<base>/message

<base>/api/message

health

<base>/health

<base>/agents/api/health

ws

<base>/ws

<base>/agents/ws

For ws the scheme becomes wss: for https: and ws: otherwise. The default server https://agentic.seed.hyper.media uses the second column.

Server URL normalization

normalizeAgentServerUrl(input) runs once, when the user saves the agent server field (through the agentsNormalizeServer source). It trims, requires http: or https:, refuses a username or password, drops query and fragment, turns a path of exactly /agents into the root, and strips trailing slashes. Errors are user-facing sentences: "Agent server URL is required.", "Use an http:// or https:// server URL.", "Use an http:// or https:// server URL without credentials.". The same function validates a model provider's base URL before it is saved.

Secret-target safety

safeAgentSecretTarget(base) is true for https: and for http: only when the host is localhost, 127.0.0.1 or [::1]. It guards provider API keys twice: the overview reply carries it as safeSecrets, which disables the Save button and shows "This server uses remote HTTP. Use HTTPS before sending an API key.", and agentsSaveProvider checks again before sending.

Tests

In agents.test.ts, the agents protocol group has five tests: the byte-for-byte vector, raw or principal public keys and the delegation refusal, undefined stripping with binary preserved, URL normalization with both layouts, and the secret target. The vector, envelope-vector.json, was produced by tools/mock-agents/generate-vector.ts, which extracts and executes signAgentActionWith from frontend/packages/ui/src/agents/client.ts and sign from frontend/packages/client/src/blobs.ts with a fixed clock, and records a SHA-256 of that source. review.test.ts asserts that no file in src/agents imports @ipld/dag-cbor or cborg directly.

Related

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime