Skip to content
On this page

Scope grammar

A scope is a compact declarative statement of the form:

Code
<product>:<verb>(<constraint-list>)

Scopes are the protocol's contract for "what may this agent do, and on what terms." They are parseable, comparable, and composable across orangecheck sub-products.

ShapeLink to this section

Code
scope           := product ":" verb [ "(" constraint-list ")" ]
product         := lowercase-ident
verb            := lowercase-ident
constraint-list := constraint ( "," constraint )*
constraint      := key op value
key             := lowercase-ident
op              := "=" | "!=" | "<" | "<=" | ">" | ">=" | "*"
value           := quoted-string | bare-token

No whitespace is permitted inside a scope string. * is the wildcard op and takes no value. A bare token is made of A-Z a-z 0-9 _ . : / @ + -; any other character, such as ?, % or ~, needs a quoted string: mcp:invoke(server="https://example.com/mcp?v=2",tool=search).

MVP scope registryLink to this section

Implementations MUST accept these products and verbs.

ScopeRegistered keys
lock:sealrecipient, mime, max_bytes
lock:chatrecipient, max_bytes_per_msg, max_msgs
stamp:signmime, max_bytes, content_hash_prefix
vote:castpoll_id, choice
nostr:publishkind, relay, max_bytes
http:requestorigin, method, max_rps, max_bytes_out
ln:sendmax_sats, node, max_fee_sats
mcp:invokeserver, tool, max_invocations
pledge:createmax_bond_sats, mechanism, counterparty
anthropic:toolname (case-sensitive), from agent-anthropic
openai:functionname (case-sensitive), from agent-openai
vercel:toolverb (case-sensitive), from agent-vercel
langgraph:toolverb (case-sensitive), from agent-langgraph

In strict mode (default), verifiers reject unknown products / verbs / constraint keys. In permissive mode, verifiers accept unknowns and still apply them: an unknown key in a granted scope is a constraint like any other, so an exercised scope must meet it. Neither mode drops a constraint or reads one as a wildcard. OC Pledge refuses an unknown pledge:create key in both modes.

Canonical formLink to this section

To make sub-scope comparison deterministic, scopes are canonicalized before use:

  1. Constraints sorted lexicographically by key.
  2. Values kept exactly as written, case included, and compared byte for byte.
  3. No whitespace.
  4. Typed values have one spelling, in ASCII: an integer key (kind, the max_* keys) takes a decimal integer; method an ASCII token with no lower-case letter; node, poll_id and content_hash_prefix lower-case hex; mime a lower-case type/subtype with no parameters; a bech32 address (bc1…, tb1…, bcrt1…) lower case, while a base58 address keeps its case; a URL (origin, server, relay) no backslash and a lower-case scheme and authority, its path as written. Any other value makes the scope malformed (E_BAD_SCOPE_GRAMMAR) in either mode.
  5. A registered prefix key, content_hash_prefix of stamp:sign, is written with =, meaning "starts with"; != on it is malformed in either mode. A key is a prefix key by registration, not by its name.

ln:send(node=03abc,max_sats<=1000) canonicalizes to ln:send(max_sats<=1000,node=03abc). The canonical form is what gets written to scopes and scope_exercised.

Sub-scope containmentLink to this section

An exercised scope S_x is a sub-scope of a granted scope S_g iff:

  1. product and verb are identical.
  2. For every constraint (k, op, v) in S_g:
    • op = * — no requirement on S_x.
    • op = = — S_x must contain (k, =, v) exactly. The prefix key content_hash_prefix means "starts with": =abc meets =ab.
    • op = != — S_x must contain a value that isn't v (via = or another !=). Integer keys compare as integers, so kind=00 is still 0. Other values compare byte for byte: for a key whose values can still be spelled two ways, such as a URL with and without its default port, grant with =.
    • Ordered ops (<, <=, >, >=) — S_x's implied numeric range must be a subset of S_g's.
  3. S_x may add constraints on keys not present in S_g, as long as they're registered for that product:verb.

Keys read from the contentLink to this section

For stamp:sign, three keys describe the action's own content, so a verifier reads them from the signed content and never from the agent's claim: mime from content.mime (its type/subtype, lower case), max_bytes from content.length, and content_hash_prefix from the hex of content.hash. Those values must meet the grant that admits scope_exercised, else E_SCOPE_DENIED; agent-signer refuses to sign content its own claim does not cover. No other registered scope has a key the action's signed fields describe: a recipient, poll, kind or tool sits inside the content bytes, and the product's own verifier reads it there.

ExamplesLink to this section

GrantedExercisedResult
lock:seal(recipient=bc1qalice)lock:seal(recipient=bc1qalice)✓ exact match
ln:send(max_sats<=1000)ln:send(max_sats=500,node=03abc)✓ tighter bound + extra key
stamp:sign(mime=text/markdown)stamp:sign(mime=application/pdf)✗ = value mismatch
http:request(origin=https://api.example.com)http:request(origin=https://api.evil.com)✗ = value mismatch
http:request(method!=POST)http:request(method=GET)✓ admissible under !=
http:request(method!=POST)http:request(method=POST)✗ disallowed under !=
http:request(method!=POST)http:request(method=post)✗ malformed method
stamp:sign(mime!=text/html)stamp:sign(mime="text/html;charset=utf-8")✗ MIME parameters
stamp:sign(content_hash_prefix=ab)stamp:sign(content_hash_prefix=abc)✓ starts with ab
nostr:publish(kind!=0)nostr:publish(kind=00)✗ 00 is 0
ln:send(max_sats<=1000)ln:send(max_sats=5000)✗ wider range
http:request(origin=*)http:request(origin=https://anything)✓ wildcard grants everything

WildcardsLink to this section

A delegation MAY grant product:verb(key=*) to express "any value for key." Wildcards widen — use them deliberately. The blanket grant is the scope with no constraint list, http:request: maximally permissive, and verifiers MAY reject such delegations by policy. A constraint always names a key, so http:request(*) is not a scope string.

Adding new scopesLink to this section

New products, verbs, and constraint keys are allocated by PR to the oc-agent-protocol (opens in a new tab) repository. Each name is a lowercase identifier ([a-z][a-z0-9_]*). Until a name is registered, strict-mode verifiers refuse it.

Implementing the sub-scope checkLink to this section

The reference TypeScript implementation lives in @orangecheck/agent-core (opens in a new tab):

TypeScript
import { isSubScope, parseScope } from '@orangecheck/agent-core';

const granted = parseScope('ln:send(max_sats<=1000,node=03abc)');
const exercised = parseScope('ln:send(max_sats=500,node=03abc,max_fee_sats=5)');

if (!isSubScope(exercised, granted)) {
    throw new Error('scope escalation attempt');
}

The algorithm is pure and deterministic — same inputs on any compliant implementation yield the same accept/reject.