> From *AT Protocol Spaces: A Field Guide* on atproto.how, revised 2026-11-23.
> Web page: https://atproto.how/atproto-spaces-field-guide/2-identity-and-keys
> Index for agents: https://atproto.how/llms.txt · Text CC BY-SA 4.0, code samples MIT.

# Chapter 2 · Identity and keys

Every identity in atproto has a permanent identifier in the form of a DID, and a DID document that lists the identity’s keys and the services it uses. Anyone can look up a DID’s document. Spaces need a handful of keys to save data into a space and read it back, and most of them live in these documents.

> *In the family space.* The family app is about to read Ruth’s health update for Elena. A few things have to be settled first: who vouches that Elena asked, which app is asking, and how the app will know the answer came from Ruth’s PDS.

Spaces rely on cryptographic material in DID documents and OAuth client metadata documents. This material is used to verify authorization and to facilitate the exchange of data.

- `#atproto` signs tokens. Elena’s PDS uses it to vouch that she asked.
- `#atproto_kem` lets a reader derive a secret for one request, which is how the app knows an answer came from Ruth’s PDS.
- An application’s own key, published in its JSON Web Key Set (JWKS), signs its client attestation, which tells a space host which app is asking.

> **If you’re building an app**
>
> Your app rarely touches these keys directly. The user’s PDS holds `#atproto_kem` and `#atproto` and uses them for the user.
>
> Your app already works with keys like these. A confidential client publishes a key in its OAuth client metadata, and spaces use that same key to sign a client attestation. Every app also generates a key for DPoP in each session. Spaces add two more: a key for each credential, and a key for each request that asks for a MAC. They are the same kind of key you already handle, P-256 key pairs, put to new uses. [Chapter 6](https://atproto.how/atproto-spaces-field-guide/6-access-control.md) covers the attestation and the credential key, and [Chapter 5](https://atproto.how/atproto-spaces-field-guide/5-cryptography.md) covers the MAC.
>
> If your app reads spaces, it resolves the authority’s DID document to find the space host, and each writer’s DID document to find their PDS and KEM key. It refreshes a document when a check fails. [Chapter 5](https://atproto.how/atproto-spaces-field-guide/5-cryptography.md) covers the checks.

<a id="a-did-document-with-spaces-support"></a>

## 2.1 A DID document with spaces support

Elena’s DID document is an ordinary atproto DID document with one addition. The `#atproto_kem` verification method is introduced to support spaces. The `#atproto` verification method item and `#atproto_pds` service item are already present and remain untouched.

**Reference: Elena’s DID document**

Her identity’s two keys, and the server that acts for her.

```json
{
  "@context": [
    "https://www.w3.org/ns/did/v1",
    "https://w3id.org/security/multikey/v1",
    "https://w3id.org/security/suites/secp256k1-2019/v1",
    "https://w3id.org/security/suites/ecdsa-2019/v1"
  ],
  "id": "did:plc:53ni6w7okqrxvjxezmopejoo",
  "alsoKnownAs": [
    "at://elena.example.com"
  ],
  "verificationMethod": [
    {
      "id": "did:plc:53ni6w7okqrxvjxezmopejoo#atproto",
      "type": "Multikey",
      "controller": "did:plc:53ni6w7okqrxvjxezmopejoo",
      "publicKeyMultibase": "zQ3shPWwfJKjriJqb4CsR7KBBHkaffnpZin5NCyAYJzztnuRV"
    },
    {
      "id": "did:plc:53ni6w7okqrxvjxezmopejoo#atproto_kem",
      "type": "Multikey",
      "controller": "did:plc:53ni6w7okqrxvjxezmopejoo",
      "publicKeyMultibase": "zDnaeueFwjSjPA49dvab7bN4VjYDvv7eBVsDSjncdQHsud125"
    }
  ],
  "service": [
    {
      "id": "#atproto_pds",
      "type": "AtprotoPersonalDataServer",
      "serviceEndpoint": "https://pds-a.example.com"
    }
  ]
}
```

| Field | What it holds | In Elena’s document |
| --- | --- | --- |
| `@context` | The standards the document follows | DID Core, Multikey, and two signature suites |
| `id` | The DID itself | `did:plc:53ni6w7okqrxvjxezmopejoo` |
| `alsoKnownAs` | The identity’s handle | `at://elena.example.com` |
| `verificationMethod` | The identity’s public keys, each named by a fragment | `#atproto` and `#atproto_kem` |
| `service` | The servers that act for the identity | Her PDS, as `#atproto_pds` |

These fields come from specifications outside atproto. [DID Core](https://www.w3.org/TR/did-core/) defines the document’s structure, and the [did:plc](https://web.plc.directory/spec/v0.1/did-plc) and [did:web](https://w3c-ccg.github.io/did-method-web/) method specifications define how each kind of DID is created, updated, and resolved.

<a id="atproto-the-signing-key"></a>

## 2.2 #atproto: the signing key

This is the identity’s existing signing key (K-256 or P-256). It belongs to the core AT Protocol, and spaces reuse it. The PDS almost always manages it entirely, because the PDS is the service that signs data with it. As a *reader*, it signs delegation tokens. As a *space authority*, it signs space credentials and the service auth the authority sends (`notifyCredentialsRevoked`, `checkAccess`). When its account writes to a space, the PDS uses it to sign the service auth on `notifyRepoUpdate`. Every space token header carries `kid: "#atproto"` exactly \[spec\].

<a id="atproto-kem-the-key-encapsulation-key"></a>

## 2.3 #atproto\_kem: the key-encapsulation key

Each identity whose account holds space repos publishes a P-256 key with `id` `{did}#atproto_kem`, its DID as controller, `type` `Multikey`, and the key in atproto multikey encoding (the `zDna...` prefix) \[spec\]. The repo host holds the private half and uses it only to derive per-request shared secrets for MACs ([Chapter 5](https://atproto.how/atproto-spaces-field-guide/5-cryptography.md#the-shared-secret)). It should be a dedicated keypair rather than a reuse of `#atproto`, so rotating one leaves the other alone.

A requester needs this key before it can ask for a MAC, and it may cache it. `atproto-space-client` resolves an author’s DID document once, keeps the key, and resolves again after a failed MAC check or an `#identity` event \[crates\]. An account whose identity publishes no KEM key can’t be read with a space credential, because no requester can derive a secret for it.

<a id="atproto-pds-the-space-host"></a>

## 2.4 #atproto\_pds: the space host

A space authority is resolved like any other identity. Its `#atproto_pds` service endpoint is the space host, and its `#atproto` key signs the space’s credentials \[spec\]. Tokens addressed to the space host use the service-id form `did:plc:ejjl2znzqp3ci25dqaslpkk2#atproto_pds` as their `aud`, the claim that names the service a token is meant for.

<a id="client-keys"></a>

## 2.5 Client keys

A space can limit which apps may read it. To enforce that, the space host has to know which app is asking.

An application proves who it is with a **client attestation** signed by a key from its own `client-metadata.json` (`jwks` or `jwks_uri`). The space host resolves `iss` to that document and picks the key by the attestation’s `kid`, the same machinery an atproto confidential OAuth client already uses for `private_key_jwt` \[spec\]. Public clients have no such key, so they can use only spaces that admit any app.

**Reference: The family app’s published key**

The `jwks` entry in its client metadata, at `https://family.example/client-metadata.json`.

```json
{
  "keys": [
    {
      "kty": "EC",
      "crv": "P-256",
      "x": "COmaVfdUzj6QHwm3ZTZgY8KsbNhtJN12EgFWLsm7_pE",
      "y": "G36xIW2qad2tMbOE8zj-pSq39311l313hbZbcAPTxKw",
      "kid": "key-1",
      "alg": "ES256",
      "use": "sig"
    }
  ]
}
```

<a id="ephemeral-keys"></a>

## 2.6 Ephemeral keys

Two more P-256 keys exist only briefly on the syncer. The **credential key** is generated for each credential, named in `authorizeSpaceSync` as `credentialKey`, and used to sign every call that presents that credential. That signature is what stops a repo host that receives the credential from replaying it to another host ([Chapter 5](https://atproto.how/atproto-spaces-field-guide/5-cryptography.md)).

The **KEM ephemeral key** is generated for each read that asks a repo host for a MAC: a call to `getLatestCommit`, `getRepo`, `listRepoOps`, or `getRecord` made with a space credential. Every page and every retry counts as its own read. The key is sent as the `keyid` of that read’s MAC request, and discarded once the response’s MAC is checked. Neither is published anywhere.

<a id="rotation"></a>

## 2.7 Rotation

Rotating different keys and key references will have side effects that developers should be aware of.

The `#atproto` key signs every space credential an authority issues, and any service auth it sends as the authority \[spec\]. A repo host has to validate a credential’s signature before it serves a read \[spec\]. `atproto-pds` checks it against the key in the authority’s current DID document \[crates\], so a credential issued before a rotation stops verifying once the host sees the new document. The spec gives no rule for that case. Its key rotation entry covers only `#atproto_kem`. What bounds the damage is the credential’s lifetime: ten minutes by default and sixty at most \[spec\].

Rotating `#atproto_kem` leaves every repo’s digest and revision as they were, because the key is not part of repo operations that use cryptographic material. Requests made against the old key may fail MAC verification. A syncer that sees a MAC failure refreshes the author’s DID document and retries with a new ephemeral key \[spec\]. Rotation, like every other identity change, arrives as an `#identity` event on the public firehose ([Chapter 10](https://atproto.how/atproto-spaces-field-guide/10-operations.md#account-status-and-identity-events)).

A space host fetches an app’s client metadata and JWKS each time it verifies a client attestation, and picks the key by `kid` \[crates\]. Rotating that key takes effect on the next attestation. One signed with a key that isn’t published yet is refused with `InvalidClientAttestation`, so publish the new key before the app signs with it. Credentials already issued keep working, because they are bound to the credential key.

<a id="what-should-an-app-do-when-a-user-s-signing-key-rotates"></a>

### 2.7.1 What should an app do when a user’s signing key rotates?

For an app, which user rotated matters. When a member’s key rotates, the app holds nothing signed by the old key. Delegation tokens are minted for each exchange and live 60 seconds \[spec\], so the next one carries the new key’s signature, and space repos hold no signatures at all \[spec\].

When the authority’s key rotates, the app’s credential is refused. It calls `authorizeSpaceSync` again, which the spec calls reauthorizing \[spec\], and retries the read. `atproto-space-client` does that once after an authorization failure \[crates\]. Until the new credential arrives the app still has its own copy of the space, so its users see data that is a little behind.

An app can also act before it is refused, because a signing key change arrives as an `#identity` event on the firehose \[spec\]. The spec asks for reauthorizing when the authority’s `#atproto_pds` endpoint changes \[spec\]. `atproto-space-client` gives an app a hook to drop a cached `#atproto_kem` key when an `#identity` event arrives, and it renews a credential when a read is refused \[crates\].

<a id="common-questions"></a>

## 2.8 Common questions

**Are app developers responsible for generating or updating an identity’s `#atproto` or `#atproto_kem` keys?**

No. The user’s PDS manages both keys and uses them for the user. Your app reads the public halves from the identity’s DID document.

**Does my app need a key of its own?**

A space that lists its allowed apps asks for a client attestation, which your app signs with the key in its client metadata. A public client has no key there, so it is limited to spaces that admit any app. An app that reads spaces also makes short-lived keys as it goes, one for each credential and one for each read that asks for a MAC.

**Why does an identity need a second key for spaces?**

`#atproto` signs tokens. `#atproto_kem` lets a reader and a repo host agree on a secret for one read, which is how the reader knows who answered ([Chapter 5](https://atproto.how/atproto-spaces-field-guide/5-cryptography.md)). They are separate keys so that either can be rotated by itself.

**What if an identity has no `#atproto_kem` key?**

Then no reader can derive a secret for its space repos, and reads of them with a space credential fail. Erin reads the family space and has no account, so she has no space repos and needs no such key ([Chapter 6](https://atproto.how/atproto-spaces-field-guide/6-access-control.md)).

**How does an app find the server for a space?**

It resolves the space authority’s DID document and reads the `#atproto_pds` entry, which names the space host. It finds each writer’s repo host the same way, from that writer’s document.

**What happens when a key is rotated?**

For an app, a rotation shows up as a failed check or a refused credential. It refreshes the DID document or asks for a new credential, and tries again. The Rotation section covers each key.
