// Package migrate moves a Matrix identity's plaintext history into end-to-end encrypted rooms // (QA-289, docs/e2ee/work-plan.md 4.5 and 4.10). It is a bridgekit extension (Install): it runs // inside each bridge, in the bridge's enclave, behind the bridge's provisioning secret, so the // plaintext it reads and the ciphertext it writes never pass through the API server. // // A move gives an old room a new encrypted room (move: a portal's room is created again by bridgev2, // which bridgekit makes encrypted; two Xessenger users' room is made by the API and taken on by the // mail bridge), writes the old room's messages and reactions into it as their senders with their // original timestamps (migrate), and lets the old room go once the API is ready to delete it // (release). Every written event carries a marker (MarkerKey) inside its ciphertext, with the room's // digest key. The events of someone who can no longer write in the room (a Xessenger person who left // it) are written by the bot, the marker naming the original sender: taken into the new room, they // would get its keys. // // What the API server and the app check a move against is defined here, once, for every side: // // - Counter counts what a plaintext room holds that a move takes along (messages, reactions) // and the files of this homeserver its messages point to. The API counts the same way through // Synapse's admin API before a move begins and again right before the plaintext is deleted, // so the numbers agree only if nothing was lost or added. // - Digest summarises the moved events as the app decrypts them, keyed with the room's digest key // the markers carry. The bridge computes it from the content it encrypts, the app from the // content it decrypts; the API compares the two without knowing the key. // - EncryptedFileURLs counts the moved files as the app does. // // These rules are pinned by testdata/*.json, which the API's and the app's tests read as well. package migrate