Litestone guide / Protected data
Secrets, hashes and personal data
Three words say what a column is. @hashed is a one-way digest you can match and never read, @secret is an encrypted, guarded, audited credential, and @personal marks data about a person.
model Device {
id Int
label String
token String
(0)
}
await db.device.create({ data: { id: 1, label: 'kiosk', token: 'tok-123' } })
const found = await db.asSystem().device.findFirst({ where: { token: 'tok-123' } })
if (found?.id !== 1) throw new Error('a hashed column matches by value')
if ('token' in found) throw new Error('a digest is never handed back')
try { await db.asSystem().device.findMany({ select: { token: true } }); throw new Error('the select should be refused') } catch (e) { if (e.name !== 'ValidationError') throw e }
A hashed column is matched in a where and never read back, not even by asSystem().
What else it can do
@secretis@encryptedplus@guardedplus an audit entry on every write, with the value redacted@secret(deterministic: true)stays findable by its own value, and@secret(rotate: false)is excluded from$rotateKey@secret @hashedis a credential a server verifies: matchable, never readable, still guarded and audited@secretneeds adriver traildatabase in the schema, or its audit half is dropped with a warning@guardedis a column only the system reads or writes, and aselectcannot unlock it@omitleaves a column out of the default payload, and@omit(all)out of every read- A
@derivedBoolean such ashasPasswordanswers whether a hashed column is set without exposing it @hashedneeds aStringcolumn and does not combine with@encrypted,@guardedor@allow@personaland@personal(contact)mark a column about a person, and the audit trail records it as[personal]@@personsays every row is a person$rotateKeyrefuses while a@hashedorrotate: falsecolumn exists, unless it is named inorphan
In depth: Encryption § @hashed, § @secret, § @guarded, Schema § Visibility & security, Trail § Personal data