Docs / Concepts

Keysets

A keyset is what an application loads: one purpose, one or more keys, exactly one primary. It is how pqlock rotates keys and changes algorithms without code changes.

01Purposes

PurposeUsed byPQL-DEFAULT key
sealseal, open, seal_batch, stream, rotateX-Wing seed, 32 B secret, 1,216 B public
signsign, verify, auditML-DSA-65 + Ed25519, 64 B secret, 1,984 B public
tokentokens.issue, tokens.checkML-DSA-65, 32 B secret, 1,952 B public

Every operation checks the purpose before touching key material, so a token keyset passed to seal is an error. The purpose is also mixed into the key id, so the same public bytes under two purposes never share an id.

02Key status

StatusSeal, sign, issueOpen, verify, check
primaryYes, exactly one per keysetYes
activeNoYes
retiredNoYes, so old data stays readable

create makes a keyset with one primary key. add adds an active key. promote makes a key primary and demotes the old primary to active. retire stops a key from being used for new data. The primary cannot be retired; promote another key first. Removing a key from the file is the only way to stop it opening old data.

let ks = keyset.load(privateJson);
ks = keyset.add(ks, { suite: 'PQL-DEFAULT' });   // new active key
const newKid = ks.keys.at(-1)!.kid;              // its id
ks = keyset.promote(ks, newKid);                    // new data uses it
ks = keyset.retire(ks, oldKid);                  // still opens old data
ks = keyset.load(private_json)
ks = keyset.add(ks, suite="PQL-DEFAULT")
ks = keyset.promote(ks, new_kid)
ks = keyset.retire(ks, old_kid)
ks, _ = keyset.Add(ks, keyset.WithSuite(keyset.SuiteDefault))
ks, _ = keyset.Promote(ks, newKid)
ks, _ = keyset.Retire(ks, oldKid)
Always name the suite when adding

add without a suite creates a PQL-DEFAULT key in every SDK, even on a PQL-HIGH keyset. Promoting that key would move new data down to PQL-DEFAULT.

03Key ids

A key id is 8 bytes: the first 8 bytes of SHA-256("PQL1 kid" || suite id || purpose code || public key). It appears as lowercase hex in keyset files and as base64url in token headers. Key ids are identifiers, not secrets. Every envelope and signature carries the key id, which is how open finds the right key after a rotation.

04File format

seal.keyset.json
{
  "pql_keyset": 0,
  "purpose": "seal",
  "keys": [
    { "kid": "9c1f…", "suite": "PQL-DEFAULT", "status": "primary",
      "public": "…base64url…", "secret": "…base64url, private file only…" }
  ]
}

The normative format is spec/keyset.md. Parsers are strict: unknown fields, non-canonical base64url and wrong lengths are rejected.

05Where keysets live

pqlock v0.1.0 · unaudited preview · source of truth: spec/