Group rows
Users share a group (a trip, a flat) and add expenses that every member sees, while the server stores only ciphertexts.
1In practice
What the user sees. Users share a group (a trip, a flat) and add expenses that every member sees, while the server stores only ciphertexts. Behind that, the creator's phone makes a random group key and seals it to each member's public key. Every row is encrypted with encryptRow, bound to its table and row id, so the server can't move or alter a row without the change being refused.
Why. Shared data needs one key that several people hold, and the server must be able to store, sync and order rows without reading them.
Pros
- The server stores and syncs rows it can't read. A leaked database shows ciphertexts.
- A row is bound to its table and id: the server can't swap two rows, or pass an expense off as another table's row. A changed byte is refused too.
- A sealed group key is bound to its group id.
- Adding a member is one more sealed copy of the key. Nothing is re-encrypted.
Cons and limits
- An active server can read group data. Sealed boxes are anonymous and public keys aren't signed, so a server could hand out its own public key in place of a member's and receive the group key, or seal a key it knows (SPEC.md, Limits).
- Metadata stays visible: who is in which group, how many rows, their sizes and when they were written. Pad values if sizes matter.
- The server can drop or replay a whole row. Binding stops moving and editing, not deleting or restoring an old version of the same row.
- The app records which key version encrypted each row (
keyVersionhere). The library doesn't (08). - Server-side features that read values stop working: search, totals, sorting by amount. They move to the phone.
2Step-by-step flow
Each step shows who acts, which function runs, what travels and what every party holds afterwards. Use the controls, the step list or the arrow keys to replay any step.
3Code
The key lines from example/06-group-rows/index.ts. The full file runs every party in one process and ends with node:assert checks.
const groupKey = ez.newGroupKey();
const sealed = ez.sealGroupKey({ groupKey, groupId, publicKey: memberPublicKey }); // per member
const data = ez.encryptRow({ value: text(JSON.stringify(expense)), groupKey, table: "expense", rowId });
// on Ben's phone
const key = ez.openGroupKey({ sealed, groupId, keyPair: ben });
const expense = JSON.parse(read(ez.decryptRow({ encrypted: data, groupKey: key, table: "expense", rowId })));
| Function | Spec |
|---|---|
newGroupKey | Primitives |
sealGroupKey, openGroupKey | Ciphertexts |
encryptRow, decryptRow | Ciphertexts |
Run it
git clone https://github.com/ezpriv/crypto.git && cd crypto
pnpm install && pnpm build
node example/06-group-rows/index.ts