Create device_prekeys table: id uuid PK, deviceId uuid FK → user_devices.id (cascade), keyType pgEnum (signed/one_time), keyId integer, publicKey text, signature text nullable, consumed boolean default false, createdAt. Indexes: unique (deviceId, keyType, keyId); partial on (deviceId) WHERE key_type='one_time' AND consumed=false. Signed prekeys require non-null signature.
Acceptance criteria:
- One device has exactly one active signed prekey and many one-time prekeys
- Consuming a one-time prekey flips
consumed=true atomically
- Signed prekey rows require a non-null
signature
Create
device_prekeystable:iduuid PK,deviceIduuid FK →user_devices.id(cascade),keyTypepgEnum (signed/one_time),keyIdinteger,publicKeytext,signaturetext nullable,consumedboolean default false,createdAt. Indexes: unique(deviceId, keyType, keyId); partial on(deviceId) WHERE key_type='one_time' AND consumed=false. Signed prekeys require non-null signature.Acceptance criteria:
consumed=trueatomicallysignature