Guide · `@toip-tools/trust-core`

# Revoke a verifiable credential with a status list

Give each credential a bit in a signed status list, revoke by setting the bit and re-signing, and check status as a verifier.

Credentials are checked offline, so an issuer can't take one back by deleting a database row. Instead it publishes a signed list with one bit per credential it has issued. A verifier fetches the latest list, checks the issuer's signature, and reads the credential's bit.

One list covers many credentials, so fetching it doesn't tell the issuer which credential is being checked, or where.

## Before you start

You need Node 22.13 or later. In a new folder, install the package and `tsx`, a TypeScript runner:

Terminal:

```bash
mkdir revoke-credential-status-list && cd revoke-credential-status-list
npm init -y && npm pkg set type=module
npm install @toip-tools/trust-core tsx
```

## The code

Save this as `revoke-credential-status-list.ts`. It is the complete program; the site's checks run it on every build.

revoke-credential-status-list.ts:

```ts
// Revoke a verifiable credential with a signed status list: one bit per credential, published by the issuer.
import { StatusList, SystemClock, checkStatus, identityFromSeed, issueCredential, verifyCredential, type Credential } from "@toip-tools/trust-core";

const clock = new SystemClock();
const random = () => crypto.getRandomValues(new Uint8Array(32));
const gym = identityFromSeed(random());
const member = identityFromSeed(random());

// The issuer keeps one list for many credentials (1024 by default) and gives each credential a slot.
const list = new StatusList();
const slot = list.allocate();
const pass = issueCredential(gym, clock, {
  type: ["VerifiableCredential", "MembershipCredential"],
  credentialSubject: { id: member.did, plan: "monthly" },
  credentialStatus: { type: "BitstringStatusListEntry", statusListIndex: slot, statusListCredential: `${gym.did}#status` },
});

// The issuer signs the list and publishes it anywhere verifiers can fetch it: a web server, a relay, a file.
let published = list.sign(gym, clock);

// A verifier checks the credential, then the list: signed by the same issuer, and the credential's bit clear.
async function check(vc: Credential): Promise<string> {
  const proof = await verifyCredential(vc, clock);
  if (!proof.ok) return `invalid (${proof.failure})`;
  const status = await checkStatus(published, vc.credentialStatus!.statusListIndex, vc.issuer, clock);
  if (!status.signatureValid) return "status list not signed by the issuer";
  return status.revoked ? `revoked (list is ${status.ageSeconds}s old)` : `valid (list is ${status.ageSeconds}s old)`;
}

console.log(`Slot ${slot}:`, await check(pass));

// To revoke: set the bit, sign the list again, publish the new copy.
list.revoke(slot);
published = list.sign(gym, clock);
console.log(`Slot ${slot} after revocation:`, await check(pass));

// Someone in the middle swaps in an all-clear bitstring to un-revoke the pass. The issuer's signature catches it.
published = { ...published, bits: new StatusList().sign(gym, clock).bits };
console.log("With a tampered list:", await check(pass));
```

Run it:

Terminal:

```bash
npx tsx revoke-credential-status-list.ts
```

Output:

```text
Slot 0: valid (list is 0s old)
Slot 0 after revocation: revoked (list is 0s old)
With a tampered list: status list not signed by the issuer
```

Keys are random, so identifiers and sizes differ on each run. From a clone of the repository, run `npx tsx --tsconfig site/tsconfig.json site/examples/guides/revoke-credential-status-list.ts`, or read it in [`site/examples/guides/revoke-credential-status-list.ts`](https://github.com/yourbuddyconner/toip-tools/blob/main/site/examples/guides/revoke-credential-status-list.ts).

## How it works

- `StatusList` holds the bits (1024 by default). `allocate()` gives a new credential its slot, which goes in the credential's `credentialStatus.statusListIndex`.
- `sign(issuer, clock)` produces the publishable document: the bits in base64url, the issuer, a timestamp and a Data Integrity proof. Publish it wherever verifiers can fetch it.
- `checkStatus(list, index, expectedIssuer, clock)` returns `signatureValid` (signed by the expected issuer), `revoked` (the bit), and `ageSeconds`, so you can refuse a list that is too old.
- To revoke, call `revoke(slot)`, sign again and publish the new copy. Anyone holding an old copy still sees the old answer, which is why the age matters.

## Limits and production notes

- The list document is this library's own format, modeled on the W3C Bitstring Status List; credentials reference it with a `BitstringStatusListEntry`. It is not a W3C `BitstringStatusListCredential`, and other verifiers won't read it.
- The list isn't compressed. A 1024-entry list is 128 bytes of bits.
- For delegation, `@toip-tools/mandates` has a `StatusRegistry` that enforces how fresh a list must be: see [the mandates guide](https://toip.tools/guides/delegate-to-ai-agent/).

## Related

### API used

[`StatusList`](https://toip.tools/toolkit/trust-core/api/StatusList/) · [`checkStatus`](https://toip.tools/toolkit/trust-core/api/checkStatus/) · [`isRevokedIn`](https://toip.tools/toolkit/trust-core/api/isRevokedIn/) · [`StatusListDoc`](https://toip.tools/toolkit/trust-core/api/StatusListDoc/) · [`issueCredential`](https://toip.tools/toolkit/trust-core/api/issueCredential/)

### Libraries

- [`@toip-tools/trust-core`](https://toip.tools/toolkit/trust-core/): Identities, signed and encrypted Trust Tasks over TSP, credentials, status lists and local policy.

### Concepts

- [Verifiable credentials and status lists](https://toip.tools/concepts/#credentials)

### More guides

- [Issue and verify a W3C verifiable credential in TypeScript](https://toip.tools/guides/issue-verify-credential/)
- [Delegate bounded authority to an AI agent with mandates](https://toip.tools/guides/delegate-to-ai-agent/)

---

This is the Markdown version of https://toip.tools/guides/revoke-credential-status-list/. An index of the documentation for AI assistants is at https://toip.tools/llms.txt.
