Files
Haven/src/groupDmSchema.js
ancsemi 25f00a0de7 Move the new group DM key trust tables out of database.js (#5733)
A pure move into src/groupDmSchema.js, so database.js ends up smaller
than before the group DM fixes. The tables and their contents are
unchanged.
2026-10-05 18:28:50 -04:00

36 lines
1.3 KiB
JavaScript

/**
* Tables behind group DM key trust (#5733), kept out of database.js, which
* is already past its size budget. Runs from initDatabase after the other
* group DM tables.
*/
function migrateGroupDmTrust(db) {
// Every signing key an account has published, never removed, so messages
// signed before a key reset still verify afterwards.
db.exec(`
CREATE TABLE IF NOT EXISTS user_signing_keys (
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
fp TEXT NOT NULL,
jwk TEXT NOT NULL,
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (user_id, fp)
);
INSERT OR IGNORE INTO user_signing_keys (user_id, fp, jwk)
SELECT id, json_extract(signing_key, '$.x') || '.' || json_extract(signing_key, '$.y'), signing_key
FROM users WHERE signing_key IS NOT NULL;
`);
// The statement each epoch's publisher signed: the key, the group, the
// epoch and exactly who it was shared with.
db.exec(`
CREATE TABLE IF NOT EXISTS dm_group_epochs (
channel_id INTEGER NOT NULL,
epoch INTEGER NOT NULL,
published_by INTEGER NOT NULL,
sig TEXT NOT NULL,
roster TEXT NOT NULL,
PRIMARY KEY (channel_id, epoch)
);
`);
}
module.exports = { migrateGroupDmTrust };