Skip to content

Getting started

Requirements

  • Node.js 20 or newer

Install

npm install agent-passport

The three primitives

  1. Identity — every agent and operator has a did:key.
  2. Passport — the operator issues a scoped credential to the agent.
  3. Action — the agent signs each action; verifiers check who did it.
import {
  createIdentity, issuePassport, verifyPassport, assertScope,
  signAction, verifyAction,
} from 'agent-passport';

const operator = createIdentity();
const agent = createIdentity();

const passportJwt = await issuePassport({
  operator, agentDid: agent.did, name: 'support-bot',
  scopes: ['email:send'], expiresIn: 86400,
});

const passport = await verifyPassport(passportJwt);
assertScope(passport, 'email:send');

const actionJwt = await signAction(agent, { type: 'email:send', target: 'a@b.com' });
const done = await verifyAction(actionJwt);

Persisting an identity

createIdentity() returns a 32-byte privateKey. Store it securely (KMS, encrypted secret) and rehydrate the same DID later:

const agent = createIdentity(savedPrivateKey); // same DID every time

Run from source

git clone https://github.com/marcelogdomingues/agent-passport
cd agent-passport
npm install
npm run demo
npm test