Skip to content
On this page

Quickstart

Five minutes from nothing to a signed delegation, an exercised action, and a verified result.

InstallLink to this section

npm install @orangecheck/agent-core @orangecheck/agent-signer

Optional:

  • @orangecheck/wallet-adapter — browser Bitcoin wallets (UniSat / Xverse / Leather)
  • @orangecheck/stamp-ots — OpenTimestamps anchoring
  • @orangecheck/agent-mcp — stamp MCP tool invocations as agent-actions
  • @orangecheck/agent-cli — oc-agent shell for verify / inspect / canonicalize / scope checks

1. DelegateLink to this section

The principal creates a delegation. signMessage is any function that returns a BIP-322 base64 signature of the given string. In a browser, @orangecheck/wallet-adapter gets one from the person's wallet. With no wallet, agent.ochk.io/app/compose/delegation (opens in a new tab) issues one in the page.

TypeScript
import { createDelegation } from '@orangecheck/agent-signer';

declare const wallet: { signMessage(message: string): Promise<string> }; // the person's wallet

const principal = {
    address: 'bc1qprincipal…',
    signMessage: async (msg: string) => wallet.signMessage(msg),
};

const delegation = await createDelegation({
    principal,
    agentAddress: 'bc1qagent…',
    scopes: [
        'lock:seal(recipient=bc1qalice)',
        'stamp:sign(mime=text/markdown)',
    ],
    ttlMs: 7 * 24 * 60 * 60 * 1000, // 7 days
});

// delegation is a self-contained envelope; stringify and ship it
const encoded = JSON.stringify(delegation);

Send encoded to the agent — over OC Lock, email, MCP, whatever transport fits. The agent stores it.

2. ActLink to this section

The agent produces an action envelope citing the delegation.

TypeScript
import type { DelegationEnvelope } from '@orangecheck/agent-signer';

import { signAsAgent } from '@orangecheck/agent-signer';
import { signMessage } from '@orangecheck/bip322';

declare const delegation: DelegationEnvelope; // from step 1
declare const agentPrivateKey: string; // hex or WIF

const content = new TextEncoder().encode('hello world');

// The agent's own key, held where the agent runs (P2WPKH or single-key P2TR).
const action = await signAsAgent({
    agent: {
        address: 'bc1qagent…',
        signMessage: async (msg: string) =>
            signMessage('bc1qagent…', msg, agentPrivateKey),
    },
    delegation,
    content,
    mime: 'text/plain',
    scopeExercised: 'lock:seal(recipient=bc1qalice)',
});

Every action is:

  • a strict extension of an OC Stamp (opens in a new tab) envelope (so stamp verifiers keep working),
  • signed by the agent's Bitcoin address (non-repudiable),
  • bound to the delegation by id (no cross-delegation replay),
  • scope-constrained (verifiers enforce sub-scope containment).

3. VerifyLink to this section

Any counterparty — auditor, recipient, the principal themselves — runs the verification algorithm offline. verifyAction is the live check, for deciding whether to act on the action now: the delegation must be in force now, a revocation already in effect refuses it, and signed_at must be within 120 seconds of your clock (E_STALE otherwise; set maxSkewMs to change it).

TypeScript
import type {
    ActionEnvelope,
    DelegationEnvelope,
    RevocationEnvelope,
} from '@orangecheck/agent-core';

import { createReplayGuard, verifyAction } from '@orangecheck/agent-core';
import { verifySignature } from '@orangecheck/bip322';

declare const action: ActionEnvelope, delegation: DelegationEnvelope; // from steps 2 and 1

const seen = createReplayGuard(); // one per process; several instances share a store instead

// The revocations published for this delegation (step 4): query your relays
// for { kinds: [30085], '#t': [delegation.id] } and keep each envelope whose
// delegation_id matches. An empty array means a relay answered (EOSE) and
// none matched; a relay that rejected the query or timed out has not answered.
const revocations: RevocationEnvelope[] = [];

const result = await verifyAction({
    action,
    delegation,
    revocations,
    // agent-core passes (message, signature, address) and expects a Promise.
    verifyBip322: async (msg, sig, addr) => verifySignature(addr, msg, sig),
});

// verifyAction keeps no state, so stop a second use of the same action yourself.
// createReplayGuard remembers ids for as long as they could pass the 120 s bound.
if (result.ok && !seen.firstUse(action)) {
    console.log('REJECTED: this action was already used');
} else if (!result.ok) {
    console.log(`REJECTED: ${result.code} — ${result.message}`);
} else {
    console.log(
        `OK: principal ${delegation.principal.address} authorized agent ${delegation.agent.address}`
    );
    console.log(`  scope exercised: ${result.scopeExercised}`);
    console.log(`  content hash:    ${action.content.hash}`);
}

revocations is required. Leave it out and verifyAction returns E_MALFORMED, unless you pass skipRevocationCheck: true to say you are not checking revocation at all. verifyDelegation has the same rule. If no relay answered, you have not checked: refuse rather than act.

Reading a log of past actions is an audit, not a live check. Use verifyActionAsOfSignedAt: it checks each action as of its own signed_at, and its result's asOf.anchored says whether that time is fixed by a verified OTS anchor or is only the agent's claim. Never use it to decide whether to act.

4. Revoke (optional)Link to this section

If you need to burn the delegation early:

TypeScript
import type { DelegationEnvelope, SignerRef } from '@orangecheck/agent-signer';

import { revoke } from '@orangecheck/agent-signer';
import { submitToCalendars, toStampOts } from '@orangecheck/stamp-ots'; // optional anchoring

declare const principal: SignerRef, delegation: DelegationEnvelope; // from step 1
declare const nostr: { publish(event: object): Promise<void> }; // your Nostr client

const rev = await revoke({
    signer: principal, // or the agent: either may always revoke
    delegation,
    reason: 'agent key rotated',
});

// Anchor for priority ordering (optional but recommended):
// pending until a Bitcoin block confirms it; upgradeProof() fetches the confirmation later.
rev.ots = toStampOts(await submitToCalendars(rev.id));

// Publish to Nostr kind-30085 (optional but recommended):
await nostr.publish({
    kind: 30085,
    tags: [
        ['d', 'oc-agent-rev:' + rev.id],
        ['t', rev.delegation_id], // verifiers find revocations by this tag
        ['t', rev.signer.address],
        ['delegation', rev.delegation_id],
        ['signer_addr', rev.signer.address],
    ],
    content: JSON.stringify(rev),
});

A verifier passing revocations: [rev] to verifyAction() returns E_REVOKED for every action from the moment the revocation is in effect. An audit with verifyActionAsOfSignedAt() compares the two times instead: the revocation's effective time (a verified OTS anchor if present, else signed_at) against the action's.

From the shellLink to this section

The CLI mirrors the library for ops work and CI:

Shell
npx @orangecheck/agent-cli verify delegation.json
npx @orangecheck/agent-cli verify pair.json --revocations revs.json   # pair.json: [delegation, action]
npx @orangecheck/agent-cli verify pair.json --as-of-signed-at         # audit a past action
npx @orangecheck/agent-cli inspect action.json
npx @orangecheck/agent-cli canonical revocation.json
npx @orangecheck/agent-cli scope 'ln:send(max_sats<=1000,node=03abc)'
npx @orangecheck/agent-cli subscope 'ln:send(max_sats<=1000)' 'ln:send(max_sats=500)'

verify takes a file: one envelope, or an array [delegation, action] or [delegation, revocation]. It has no relay access, so it checks revocation only against the JSON array you pass with --revocations, and says so when you pass none. An action is checked live, as of now; --as-of-signed-at audits it as of its own signed_at. Exit codes: 0 = verified / admitted, 1 = any rejection. verify, inspect, scope and subscope take --json.

Next stepsLink to this section

  • Learn the scope grammar — what the registered scopes express, how sub-scope containment works, how to write constraints.
  • An MCP server? MCP servers — where the action rides in the request, and what to check before running the tool.
  • Try the live playground (opens in a new tab) — the same library, in your browser.
  • Read the protocol walkthrough for a diagram-first view of the three envelopes.
  • Skim the security posture before trusting a production delegation.