# Identity: keyed pseudonyms, generations and what is stored

Product analytics counts people without being able to read them back. Every end-user identifier
(a distinct id, an email, an IP, a device id, a cookieless visitor, a survey respondent, an
account key) is turned into a **pseudonym** before it is stored. This page is the contract.

## Two schemes

| | v1 (scoped pseudonym) | v2 (keyed pseudonym) |
| --- | --- | --- |
| Construction | `sha256("<projectId>:<value>")`, hex, first 32 | `HMAC-SHA256(key, "<purpose>\0<value>")`, hex, first 32 |
| Secret | none (the project id is public) | a per-project key derived from a secret Bucker holds |
| Used by | existing `userHash`, `ipHash`, release-session hashes | every new subject, visitor, respondent, device and account key |
| Status | **frozen**; never changed | current |

v1 lets anyone holding a leaked column test candidate emails offline. v2 does not. v1 stays because
rows already carry it; an erasure or a lookup computes both, so it finds either.

Purposes: `subject`, `anon`, `device`, `account`, `respondent`, `visitor`. The purpose is part of
the message, so the same string under two purposes gives unrelated values.

## Keys: derived, never stored

```
key = HKDF-SHA256(ikm = Bucker's secret, salt = "bucker:pseudonym:v2",
                  info = "bucker:pseudonym:<generation>:<projectId>", 32 bytes)
```

For each project Bucker records its generations: the generation number, when it became active, when
it was retired, and a one-way **check** of the derived key (`hkdf-sha256:<32 hex>`), never the key
itself.

Bucker refuses to compute a pseudonym under a key that fails the active generation's check, rather
than write values that could never be matched again: a pseudonym that does not match would make an
erasure miss rows. If the secret behind the keys ever has to change, it is a deliberate, recorded
step that opens a new generation, and its cost is stated rather than hidden: v2 values stored under
the generations opened before the change can no longer be linked to anyone (in effect they are
crypto-shredded), while the frozen v1 values beside them still match for as long as both schemes
are matched.

## Generations

- Generation 1 is created on a project's first write. Exactly one generation is active.
- When a project's key is rotated, the active generation is retired and the next one opened at the
  same moment.
- New writes use the active generation. An erasure or a lookup matches the active value, the frozen
  v1 value and every retired generation's value. A retired generation keeps matching with no time
  cutoff: subject, device and account records are not telemetry and do not age out on a retention
  class, and dropping a generation from matching while a row still carries it would let an erasure
  miss that row.
- Key material never appears in a log line or an API response.
- A rotation reaches every Bucker server within 60 seconds.

## What is and is not stored

Stored: keyed pseudonyms (`subjectKey`, `deviceKey`, `visitorKey` and similar), the frozen v1
beside them for as long as both schemes are matched, generation numbers, and the encrypted draft of an end-user erasure request (sealed with
Bucker's at-rest encryption).

Not stored: a raw email, IP, distinct id, device id or user agent of an end user, and no key.
Bucker checks its stored data model so that no new field holds an end user's email, distinct id,
IP address or user id in the clear. The older fields that hold such values belong to organization
members, their sign-in and SSO records, billing and a few earlier features, and are covered by their
own erasure paths.
