For a calling site
Your site already runs the agentic-web browser runtime, which shows a consent card before it contacts another site. Countersign wraps that card.
-
Add two lines to your page
Put them after your runtime's own script. The anchors are the authorities you trust; this example trusts the demo board for scholarship topics only.
<link rel="stylesheet" href="https://countersign.sidkhuntia.in/kit/countersign.css"> <script type="module" src="https://countersign.sidkhuntia.in/kit/countersign.js" data-policy="inform" data-anchors='[{"origin":"https://scholarship-board.sidkhuntia.in","name":"Demo National Scholarship Board","scopes":["scholarship.*"]}]'></script>The script waits for
window.__nsweb.engine, wrapsengine.onConsent, verifies the peer in the visitor's browser, and adds the result to the card. The stylesheet line is optional: the script adds it if it is missing. -
Choose your anchors and policy
Each anchor is
{origin, name, scopes, kids}.scopeslimits what you trust that authority for, with.*matching sub-scopes; leave it out to trust all of its scopes.kidsoptionally pins its signing keys. A visitor may add anchors on their own device, and those are always labelled as added there.Verdict inform(default)strictendorsed Card says who vouches, for what, until when Allowed card revoked, invalid Declined automatically, reason shown in chat Declined automatically expired, untrusted issuer, changed, unendorsed Card warns; the visitor decides Declined automatically unverifiable Card says it couldn't check; never shown as endorsed Declined automatically -
Allow it in your Content-Security-Policy
If your pages send a CSP, allow the kit's origin in
script-srcandstyle-src, and allow your anchors and peers inconnect-src(or allowhttps:). To self-host instead, copycountersign.js,countersign-core.jsandcountersign.cssfrom the kit into your site and point the two lines at your copy.script-src 'self' https://countersign.sidkhuntia.in; style-src 'self' https://countersign.sidkhuntia.in; connect-src 'self' https: -
See it work
Ask your assistant something that needs a peer. The card now carries a trust line. In the console,
window.Countersign.lastVerdictsholds the latest verdicts, and every check fires acountersign:verdictevent onwindowwith the verdict asdetail.await window.Countersign.verifyPeer({ origin: "https://sahyadri-education.sidkhuntia.in", network: "sahyadri_scholarships" })
For an authority
An authority is any HTTPS origin that publishes /.well-known/countersign-authority.json. The CLI runs on Node 22 with no install. Keep the private key off your web server; only the public key is published.
-
Make a signing key
node kit/cli.mjs keygen --kid board-2027 --out keys/board.private.jwk.jsonIt writes the private key with mode 0600, never overwrites one, and prints the public key entry for your authority file.
-
Endorse a site for named scopes
node kit/cli.mjs endorse --key keys/board.private.jwk.json --add-to authority.source.json \ --sub https://partner.example --net partner_net --scope scholarship.eligibility --exp 2027-06-30 \ --title "Partner State Department" --network-url https://partner.example/partner_net \ --sample-query "Which scholarships suit a first-year student?"The token names the exact origin and network, the scopes and an expiry. The title, URL and sample queries are directory hints for people; callers trust only the signed token.
-
Publish your authority file
node kit/cli.mjs publish-authority --config authority.source.json \ --key keys/board.private.jwk.json --out site/.well-known/countersign-authority.json --status-days 7This signs a fresh revocation list valid for seven days. Re-run it on a schedule: once the list goes stale, callers show your endorsements as unverifiable, never as endorsed. Serve the file with
Access-Control-Allow-Origin: *and no credentials. -
Revoke when you must
node kit/cli.mjs revoke --config authority.source.json --jti end-2026-0003 \ --reason "Charged students fees for a free scheme" node kit/cli.mjs publish-authority --config authority.source.json \ --key keys/board.private.jwk.json --out site/.well-known/countersign-authority.jsonCallers re-check on every call, so a revocation takes effect within your file's
cache_ttl(300 seconds by default). The reason is shown to visitors.
For an endorsed site
Publishing your endorsements lets any caller find them, even one that did not know which authorities to ask. Callers still fetch each issuer's keys and revocation list and accept only issuers they trust, so a lookalike gains nothing by copying the file.
curl -s https://authority.example/.well-known/countersign-authority.json -o authority.json
node kit/cli.mjs publish-subject --subject https://partner.example \
--from authority.json --out site/.well-known/countersign.json
Or pass each token you were given with --token <jws>.
Nothing in your agent-manifest.json, links.json or network file changes. A runtime without Countersign behaves exactly as before.
Check from a terminal
node kit/cli.mjs verify https://sahyadri-education.sidkhuntia.in/sahyadri_scholarships \
--anchor https://scholarship-board.sidkhuntia.in
It prints the verdict and the same step-by-step trace this site shows. Exit codes: 0 endorsed, 1 warning, 3 blocked (revoked or invalid), 2 usage error, so it fits in CI. inspect <jws> decodes a token, and with --authority checks its signature.
Check from your code
The core module has no DOM and runs in browsers and Node 22.
import { verifyPeer } from "https://countersign.sidkhuntia.in/kit/countersign-core.js";
const verdict = await verifyPeer({
origin: "https://scholarship-express.sidkhuntia.in",
network: "fast_track_scholarships",
anchors: [{ origin: "https://scholarship-board.sidkhuntia.in", scopes: ["scholarship.*"] }],
});
console.log(verdict.status, verdict.summary); // "revoked", with the board's reason
A verdict carries status, summary, matches, revocations, untrusted and a full trace. listDirectory(authorityOrigin) returns an authority's directory with each entry verified.
Ask from your agent
This site is itself an agentic site. Its network, countersign_explorer, shares two read actions with every agent site: verify_site and list_endorsed. Name it as a partner in your network's tools, and your agent can ask “is X endorsed for Y by Z?” before it hands work to X.
https://countersign.sidkhuntia.in/countersign_explorer
The call runs in your visitor's browser on your router, after your consent card, like any partner. Verdicts still come from the kit's code; the agent only explains them.
Honest limits
- Bootstrap. Who tells a visitor that an anchor is legitimate? It is the same problem as a browser's root store. Countersign answers it with anchors the publisher declares and the visitor can see and change. It does not solve it.
- A signature proves that the authority said so. It does not prove the peer is honest or correct, or that its instructions are safe.
- Revocation is only as fresh as the status token's expiry and the caller's cache.
- If an authority's key is compromised, it needs a new key id and re-issued endorsements, and callers that pin keys must update.
Relation to other work
- JOSE and VC-JOSE. Tokens are standard compact JWS, so any JOSE library can verify them. A later version could wrap the payload as a W3C Verifiable Credential 2.0 with a Bitstring Status List.
- NANDA. Closest in spirit to NANDA's DAT grants (a grantor signs scoped authority for a subject, with revocation) and to AgentFacts. Issuers and subjects are origins, which map directly to
did:web. - Integrity tools such as Gatehouse, Pinned and Agent Customs. Complementary: they answer “is it unchanged and safe to run?”, Countersign answers “is it the legitimate source?” An endorsement's optional
pincombines the two.
The full rules are in the protocol specification.
Kit reference
From kit/README.md
Countersign kit
Before your browser agent hands work to another agentic site, Countersign answers one question: has an authority you trust signed that this site is a legitimate source for this topic, and has that been revoked? The answer shows on the consent card. Revoked or forged peers are declined automatically and visibly. It uses standard compact JWS (ES256) over WebCrypto, with zero dependencies and no build step. The protocol is in ../PROTOCOL.md.
Adopt it
Callers (a site whose agent contacts other sites) add two lines after the runtime:
<link rel="stylesheet" href="/kit/countersign.css">
<script type="module" src="/kit/countersign.js"
data-anchors='[{"origin":"https://scholarship-board.sidkhuntia.in","name":"Demo National Scholarship Board","scopes":["scholarship.*"]}]'></script>
Authorities (anyone who vouches for sites) run three commands:
node kit/cli.mjs keygen --kid board-2027 --out keys/board.private.jwk.json
node kit/cli.mjs endorse --key keys/board.private.jwk.json --add-to authority.source.json \
--sub https://partner.example --net partner_net --scope scholarship.eligibility --exp 2027-06-30
node kit/cli.mjs publish-authority --config authority.source.json \
--key keys/board.private.jwk.json --out site/.well-known/countersign-authority.json
Subjects (sites that get endorsed) publish their tokens with one command. It's optional, but it lets callers who haven't anchored the authority yet still find them:
node kit/cli.mjs publish-subject --subject https://partner.example \
--from authority-file.json --out site/.well-known/countersign.json
Step-by-step instructions for each role are in ADOPT.md.
Files
| File | What it is |
|---|---|
countersign-core.js | Verification, JWS, and the policy table. It has no DOM and runs in browsers and Node 22. |
countersign.js | The browser drop-in. It wraps engine.onConsent, decorates the card and blocks bad peers. |
countersign.css | Styles for the trust panel and the blocked notice, themable with --cs-* variables. |
cli.mjs | Commands to create keys, endorse, revoke, publish and verify, plus inspect. |
authority-tools.mjs | The Node helpers the CLI and the demo script use. |
tests/ | Tests run with node --test "kit/tests/*.test.mjs". They use no network. |
Verdicts
| Verdict | Meaning | inform (default) | strict |
|---|---|---|---|
endorsed | A valid, unrevoked, in-scope token from an anchor | Green panel on the card; the visitor decides | Same |
revoked | An anchor revoked its endorsement of this site | Auto-decline, with the reason shown in chat | Auto-decline |
invalid | A token claims to be from an anchor, but its signature fails | Auto-decline | Auto-decline |
pinned-mismatch | Endorsed, but the network file changed since it was signed | Amber warning; the visitor decides | Auto-decline |
expired | The anchor's endorsement is past exp or before nbf | Amber warning | Auto-decline |
untrusted-issuer | Signed only by authorities you don't trust, such as a self-made "council" | Amber warning | Auto-decline |
unverifiable | A fetch failed, or the revocation list is stale. Never shown as endorsed | Amber "couldn't check" | Auto-decline |
unendorsed | Nothing mentions this site | Amber warning | Auto-decline |
When several apply, the precedence is: revoked, invalid, endorsed, pinned-mismatch, expired, untrusted-issuer, unverifiable, unendorsed.
API
countersign-core.js (no DOM)
import { verifyPeer, listDirectory, loadAuthority, decideConsent } from "./countersign-core.js";
const verdict = await verifyPeer({
origin: "https://sahyadri-education.sidkhuntia.in",
network: "sahyadri_scholarships", // null when unknown: matched on origin, flagged
anchors: [{ origin: "https://scholarship-board.sidkhuntia.in", name: "Demo National Scholarship Board", scopes: ["scholarship.*"] }],
// optional: policy, base (site base URL for `pin`), fetch, now (ms), cache (Map or null), timeoutMs (default 4000)
});
verdict.status; // "endorsed"
verdict.summary; // "Endorsed by Demo National Scholarship Board for … until 30 Jun 2027."
verdict.trace; // [{ step, ok: true|false|null, detail }] in plain English
verifyPeer(opts) → Verdict. It never throws. The Verdict hasstatus, origin, network, networkKnown, summary, matches[], revocations[], untrusted[], invalid[], expired[], problems[], tokens[] (each with its state), trace[], checkedAt, decision.listDirectory(anchorOrigin, { anchors?, fetch?, now? }) → [{ entry, claims, verdict }]returns every network the authority lists, each one verified.loadAuthority(origin, opts) → AuthorityDoccaches for the doc'scache_ttl, and throws a readable error.checkStatus(doc, nowMs) → { ok, fresh, exp, revoked: Map, problem }.decideConsent(verdict, policy) → { action: "ask"|"block", tone: "ok"|"warn"|"bad", status }.- JWS:
decodeJws(jws),verifyJws(jws, jwk) → boolean,signJws(header, payload, key), andjwkThumbprint(jwk)(RFC 7638). - Helpers:
normalizeOrigin,scopeMatches,normalizeAnchors,formatDate,statusLabel,sha256Hex.
countersign.js (browser)
The script installs itself from its tag (data-anchors, data-policy="inform|strict", and data-ui="false" to decide without decorating). It waits up to 20 s for window.__nsweb.engine.
import { install, registerCountersignAction } from "/kit/countersign.js";
install({ engine, anchors, policy: "inform", ui: true }); // explicit install, returns { verify, uninstall }
window.Countersign.verifyPeer({ origin, network }); // uses this page's anchors
window.Countersign.getAnchors(); // publisher anchors, then local ones (local: true)
window.Countersign.setLocalAnchors([{ origin, name, scopes }]); // stored in localStorage "countersign-anchors-v1"
window.Countersign.lastVerdicts; // Map "origin/network" → latest verdict
window.addEventListener("countersign:verdict", (e) => console.log(e.detail.status));
Model-facing action (optional). registerCountersignAction(booted.actions) registers a read action, countersign_check_site ({origin, network?} → verdict summary). Add "countersign_check_site" to your manifest's actions.agentTools, and the model can then answer "is this site official?" as website_countersign_check_site. It only checks origins your anchors know about: the anchors and the sites in their directories. That way the model can't make the browser contact any origin it likes. Pass { openOrigins: true } on a page whose job is checking any site.
cli.mjs
Run node kit/cli.mjs help for the full usage. Exit codes for verify are 0 for endorsed, 1 for a warning verdict, 3 for blocked (revoked or invalid), and 2 for a usage error.
node kit/cli.mjs verify https://scholarship-express.sidkhuntia.in/fast_track_scholarships \
--anchor https://scholarship-board.sidkhuntia.in # prints REVOKED with the trace, exit 3
node kit/cli.mjs inspect <jws> --authority https://scholarship-board.sidkhuntia.in
node kit/cli.mjs revoke --config authority.source.json --jti dnsb-2026-0003 --reason "…"
node kit/cli.mjs publish-authority … --status-days 30 # status token lifetime (default 7, max 90)
Honest limits
- Bootstrap. Countersign doesn't tell a visitor which authorities deserve trust. The publisher declares anchors, and the visitor can see and change them, as with a browser's root store. Anchors a visitor adds are labelled "added on this device".
- A signature proves that the authority said so. It doesn't prove the peer is honest, or that its instructions are safe. Use integrity tools for that;
pincombines the two. - Revocation is only as fresh as the status token's
exp, pluscache_ttl(300 s in the demo) and the host's HTTP cache (60 s in the demo). - The check makes credential-free GETs of public files before consent: the peer's
countersign.jsonand the authority files. They carry no visitor data, key or request text, but the peer can see that a lookup happened. pinis compared against the bytes the kit fetched, and the runtime fetches the network file separately.
Security notes
- Verification is deterministic code. The model never decides a verdict.
- Every DOM node is built with
textContent, neverinnerHTMLwith data. There are no inline styles or scripts, so it works under a strict CSP with Trusted Types (tested). - Fetches use
credentials: "omit"andreferrerPolicy: "no-referrer", with a 4 s timeout and a 512 KB cap. - Private keys are JWK files written with mode 0600. Keep them out of published folders. This repo keeps them in
keys/, which is gitignored. - A click on a card that is still checking can't get around a block: the kit waits for the verdict before it answers the runtime.
From kit/ADOPT.md
Adopt Countersign in five minutes
Countersign has three roles, and a site can play more than one:
- A caller checks peers before contacting them.
- An authority vouches for sites.
- A subject is a site that gets vouched for.
All you need is Node 22 for the CLI and an ordinary static host for the files.
Caller: show trust on the consent card
- Copy
kit/countersign-core.js,kit/countersign.jsandkit/countersign.cssinto your site, for example as/kit/. - Add this after your agentic-web runtime script. It needs a runtime that exposes
window.__nsweb.engine, as the reference runtime does.``
html <link rel="stylesheet" href="/kit/countersign.css"> <script type="module" src="/kit/countersign.js" data-anchors='[{"origin":"https://scholarship-board.sidkhuntia.in","name":"Demo National Scholarship Board","scopes":["scholarship.*"]}]' data-policy="inform"></script>``data-anchorslists the authorities you trust, and for which scopes (a.*matches any sub-scope). Leave outscopesto trust all of an authority's scopes.data-policy="inform"(the default) blocks revoked or forged peers and warns on the rest."strict"blocks anything that isn't endorsed.
- Test it from a terminal, using the same code the browser runs:
``
sh node kit/cli.mjs verify https://sahyadri-education.sidkhuntia.in/sahyadri_scholarships \ --anchor https://scholarship-board.sidkhuntia.in``
That's all there is to it. Your manifest, network and links.json don't change.
Optional extras:
- If your page is dark, add
data-cs-theme="dark"on<html>, or"auto"to follow the system. - To let your model explain trust, call
registerCountersignAction(booted.actions)fromcountersign.js, and add"countersign_check_site"toactions.agentTools.
Authority: vouch for a site
- Make a key. Keep the private file secret, and outside any published folder.
``
sh node kit/cli.mjs keygen --kid myauth-2027 --out keys/myauth.private.jwk.json`` - Describe your authority in
authority.source.json. This file isn't published.``
json { "issuer": "https://my-authority.example", "name": "My Authority", "description": "Who we are and what we vouch for.", "scopes": [{ "id": "scholarship.eligibility", "label": "Scholarship eligibility information" }], "cache_ttl": 300, "endorsements": [], "revoked": [] }`` - Endorse a site's network. Use
--net "*"to cover every network at that origin.``
sh node kit/cli.mjs endorse --key keys/myauth.private.jwk.json --add-to authority.source.json \ --sub https://partner.example --net partner_net --scope scholarship.eligibility --exp 2027-06-30 \ --title "Partner (directory title)" --network-url https://partner.example/partner_net \ --description "What it answers." --sample-query "An example question"`` - Publish. This signs a fresh status token, valid for 7 days by default, and writes the public file:
``
sh node kit/cli.mjs publish-authority --config authority.source.json \ --key keys/myauth.private.jwk.json --out public/.well-known/countersign-authority.json``Serve it with
Access-Control-Allow-Origin: *. Re-runpublish-authoritybefore the status token expires, or callers will show your endorsements as "couldn't check". Use--status-days Nto choose the lifetime (up to 90). - Revoke when needed, then publish again:
``
sh node kit/cli.mjs revoke --config authority.source.json --jti <token id> --reason "Why, in plain words" node kit/cli.mjs publish-authority --config authority.source.json --key keys/myauth.private.jwk.json \ --out public/.well-known/countersign-authority.json``Keep the revoked endorsement in your directory until it expires. That way callers find the revocation even if the site stops publishing the token.
Subject: carry your endorsement
Ask your authority for your token, or take it from their public authority file. Then:
node kit/cli.mjs publish-subject --subject https://partner.example \
--from their-countersign-authority.json --out public/.well-known/countersign.json
Serve it with Access-Control-Allow-Origin: *. Check the result:
node kit/cli.mjs verify https://partner.example/partner_net --anchor https://my-authority.example
Inspect any token with node kit/cli.mjs inspect <jws> --authority <origin>.