Give an AI agent an identity a human can revoke
This guide gives an AI agent a did:guardian identity and makes a human its guardian. The guardian can then recover the agent's identity or deactivate it.
Background
The agent and the human each have an identity. The human's identity is recorded as a guardian in the agent's log (REQ-6-2). A guardian approves operations with its own key. It never needs the agent's key to recover the agent (REQ-7-6).
Keys are either self-held or held by the registrar. The CLI works with both. With a registrar-held key, you log in and pass --held, and the registrar signs for the identity you are logged in as (REQ-10-13). No other party can check that a registrar follows that rule.
What you need
- Node.js 18 or later.
- The
did-guardianCLI, built from source:
git clone https://github.com/did-method-guardian/did-method-guardian.git
cd did-method-guardian
npm install
npm run build --workspace=packages/lib
npm run build --workspace=packages/cli
alias did-guardian="node $PWD/packages/cli/dist/src/index.js"
- A registrar that accepts registration. The examples use
guardianspec.org.
The registrar API doc describes the HTTP calls behind each command.
Option A: self-held keys
1. Create the human's identity
did-guardian create priya --registrar guardianspec.org
did:guardian:guardianspec.org:priya is live.
Public key (Multikey): z...
The CLI saves the key under the label guardianspec.org:priya.
2. Create the agent's identity with the human as guardian
Run this on a machine that holds priya's key:
did-guardian create support-bot-7 --registrar guardianspec.org \
--guardian did:guardian:guardianspec.org:priya \
--guardian-key guardianspec.org:priya
did:guardian:guardianspec.org:support-bot-7 is live.
Public key (Multikey): z...
Guardian: did:guardian:guardianspec.org:priya
The CLI records priya's acceptWard first. It then submits the agent's create, signed by both keys (REQ-7-6). The guardian must have exactly one key. The CLI saves the agent's key under guardianspec.org:support-bot-7, as a file in ~/.config/did-guardian/keys/. Move that file to the agent's host. Do not keep it with the human.
If the agent's identity already exists without a guardian, add the guardian with both keys present:
did-guardian guardian add did:guardian:guardianspec.org:support-bot-7 did:guardian:guardianspec.org:priya \
--ward-key <agent key label> --guardian-key guardianspec.org:priya
Option B: registrar-held keys
1. Register both identities
did-guardian register support-bot-7 --registrar guardianspec.org
did-guardian register priya --registrar guardianspec.org
Created did:guardian:guardianspec.org:support-bot-7
Login secret (shown once -- save it now):
<secret>
Give the agent's login secret to the agent's operator. Give priya's login secret to priya.
2. Adopt the agent
Log in as the human and accept the agent as a ward:
did-guardian login did:guardian:guardianspec.org:priya --login-secret <priya's secret>
did-guardian guardian adopt did:guardian:guardianspec.org:support-bot-7
The command prints a pending id. The agent's operator logs in as the agent and confirms:
did-guardian login did:guardian:guardianspec.org:support-bot-7 --login-secret <agent's secret>
did-guardian guardian confirm-adopt did:guardian:guardianspec.org:support-bot-7 <pending id>
The CLI shows the guardian to be added and asks for confirmation. It then prints Done -- did:guardian:guardianspec.org:support-bot-7 now has did:guardian:guardianspec.org:priya as a guardian.
Do not run did-guardian key take-custody on priya after this step. Her entry in the agent's log records her current key. A new key loses her standing until an updateGuardian re-seats the entry (REQ-7-15).
With registrar-held keys, each identity signs through its login session. Pass --held to guardian deactivate, guardian recover and operation sign. The registrar signs with the key it holds for the identity you are logged in as (REQ-10-13).
Option C: a platform creates agents for a human
A platform with an OIDC client on the registrar can create agents that name a human as guardian in one request. The human first consents to the create:managed-identity scope at /authorize. The platform then calls /register with that access token:
curl -X POST https://guardianspec.org/register \
-H "Authorization: Bearer <priya's access token>" \
-H "content-type: application/json" \
-d '{"name": "support-bot-7"}'
{"did": "did:guardian:guardianspec.org:support-bot-7", "login_secret": "...", "guardian": "did:guardian:guardianspec.org:priya"}
The guardian is the token's sub. A token without the scope returns 403. If priya's key is held by another registrar, the response carries guardian_pending in place of guardian. Finish that case with guardian adopt and guardian confirm-adopt. Both keys in this option are registrar-held. See registrar doc §9.
priya deactivates or recovers these agents with the --held commands above. To stop the platform from creating more, priya selects Revoke access for its client on her /account page. This deletes her consent and the client's refresh tokens. Access tokens already issued stay valid until they expire, at most one hour.
Deactivate the agent
Under the default policy, deactivation needs one of the agent's current keys and a majority of its guardians (by: "both", REQ-6-11).
With registrar-held keys
Log in as the human and propose the deactivation:
did-guardian login did:guardian:guardianspec.org:priya --login-secret <priya's secret>
did-guardian guardian deactivate did:guardian:guardianspec.org:support-bot-7 did:guardian:guardianspec.org:priya --held
Under by: "both", the command prints a pending id. The agent's operator logs in as the agent and signs:
did-guardian login did:guardian:guardianspec.org:support-bot-7 --login-secret <agent's secret>
did-guardian operation sign <pending id> --registrar guardianspec.org --held
Under by: "guardians", the first command finalizes on its own.
With self-held keys
Run this on a machine that holds both keys:
did-guardian guardian deactivate did:guardian:guardianspec.org:support-bot-7 did:guardian:guardianspec.org:priya \
--guardian-key guardianspec.org:priya --ward-key guardianspec.org:support-bot-7 --submit
The CLI asks you to confirm. It then prints the signed operation and Submitted and accepted. Without --submit, it prints the operation and submits nothing.
For the human to deactivate the agent alone, set policy.deactivation.by to "guardians". Use a setPolicy operation (REQ-7-20), signed with the agent's key and approved by the guardians. There is no dedicated command for this. Write the operation to a file, propose it with the agent's key, and sign it with priya's key:
did-guardian operation propose did:guardian:guardianspec.org:support-bot-7 --file set-policy.json --key guardianspec.org:support-bot-7
did-guardian operation sign <pending id> --registrar guardianspec.org --key guardianspec.org:priya
After that, priya deactivates with --guardian-key alone. Do not use "either" unless the agent may also deactivate itself (Section 12).
Deactivation is permanent. No operation can follow it (REQ-8-1). The registrar accepts no further operations and keeps serving the log (REQ-10-11). The DID document then contains only @context and id (REQ-9-3).
Deactivation ends the agent's sessions and refresh tokens on its registrar and invalidates its login secret. The registrar refuses to log in a deactivated identity or to issue or accept its tokens. A relying party that validates an access token without contacting the registrar accepts it until it expires, at most one hour later. To check immediately, resolve the agent's DID.
Recover the agent
If the agent's key is lost or compromised, the guardian replaces it with an update approved per policy.recovery. The agent's old key is not needed. Follow Recover after a lost key.
Let the guardian act as the agent at a relying party
When the registrar holds the agent's key, a guardian can get an access token for the agent through token exchange (registrar doc §10):
POST /token
{
"grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
"subject_token": "<priya's access token>",
"resource": "did:guardian:guardianspec.org:support-bot-7",
"scope": "openid",
"client_id": "...", "client_secret": "..."
}
The registrar checks that priya is a guardian with standing. The issued token has sub set to the agent and act.sub set to priya. It expires in one hour and has no refresh token. Its scope defaults to openid. It must be a subset of the subject token's scope. A token that acts as another identity never carries create:managed-identity. The token does not authorize operations on the agent's log.
Short-lived agents
Give each agent a generated name, for example agent-$(openssl rand -hex 3). A name is 3 to 32 lowercase letters, digits and hyphens. Create each agent with its guardian, using Option A or Option C. Deactivate each agent separately. There is no bulk operation (REQ-7-2).
A registrar never reuses a name (REQ-10-12). It never removes an accepted operation (REQ-10-11). A retired agent's log stays resolvable.