diff --git a/composeApp/schemas/mobi.giza.compose.database.GizaDatabase/45.json b/composeApp/schemas/mobi.giza.compose.database.GizaDatabase/45.json
index 4df0652f..5fb7cdb8 100644
--- a/composeApp/schemas/mobi.giza.compose.database.GizaDatabase/45.json
+++ b/composeApp/schemas/mobi.giza.compose.database.GizaDatabase/45.json
@@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 45,
- "identityHash": "efe0dacf1c5e6808f7fa2ae4dd9a2cba",
+ "identityHash": "4097e68a695ef0410fb2c8968c8fb2f3",
"entities": [
{
"tableName": "BroadcastNostrEventReceipt",
@@ -1071,6 +1071,167 @@
}
]
},
+ {
+ "tableName": "ConfederationSigningAttempt",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `confederationId` TEXT NOT NULL, `proposerPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `eventJson` TEXT NOT NULL, `stage` TEXT NOT NULL, `approvedAt` INTEGER, `declinedAt` INTEGER, `signedEventJson` TEXT, `failureReason` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`confederationId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "confederationId",
+ "columnName": "confederationId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "proposerPublicKey",
+ "columnName": "proposerPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "eventJson",
+ "columnName": "eventJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "approvedAt",
+ "columnName": "approvedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "declinedAt",
+ "columnName": "declinedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "signedEventJson",
+ "columnName": "signedEventJson",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ConfederationSigningAttempt_confederationId",
+ "unique": false,
+ "columnNames": [
+ "confederationId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationSigningAttempt_confederationId` ON `${TABLE_NAME}` (`confederationId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "confederationId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationSigningMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`attemptId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`attemptId`, `senderPublicKey`, `kind`), FOREIGN KEY(`attemptId`) REFERENCES `ConfederationSigningAttempt`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "attemptId",
+ "columnName": "attemptId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "attemptId",
+ "senderPublicKey",
+ "kind"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ConfederationSigningAttempt",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "attemptId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
{
"tableName": "ConfederationCeremonyMessage",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `senderPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `ConfederationCeremony`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
@@ -2168,524 +2329,6 @@
}
]
},
- {
- "tableName": "GroupConversationKey",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `peer` TEXT NOT NULL, `conversationKey` TEXT NOT NULL, `roundId` TEXT NOT NULL, `computedAt` INTEGER NOT NULL, PRIMARY KEY(`chatRoomId`, `peer`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "peer",
- "columnName": "peer",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "conversationKey",
- "columnName": "conversationKey",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "roundId",
- "columnName": "roundId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "computedAt",
- "columnName": "computedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "chatRoomId",
- "peer"
- ]
- },
- "foreignKeys": [
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "GroupDmMessage",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`rumorId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `conversationId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `rumorJson` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `outgoing` INTEGER NOT NULL, `wrapId` TEXT, `signingSessionId` TEXT, `readAt` INTEGER, `filedAt` INTEGER NOT NULL, PRIMARY KEY(`rumorId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "rumorId",
- "columnName": "rumorId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "conversationId",
- "columnName": "conversationId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "senderPublicKey",
- "columnName": "senderPublicKey",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "rumorJson",
- "columnName": "rumorJson",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "outgoing",
- "columnName": "outgoing",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "wrapId",
- "columnName": "wrapId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "signingSessionId",
- "columnName": "signingSessionId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "readAt",
- "columnName": "readAt",
- "affinity": "INTEGER"
- },
- {
- "fieldPath": "filedAt",
- "columnName": "filedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "rumorId"
- ]
- },
- "indices": [
- {
- "name": "index_GroupDmMessage_chatRoomId",
- "unique": false,
- "columnNames": [
- "chatRoomId"
- ],
- "orders": [],
- "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupDmMessage_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
- },
- {
- "name": "index_GroupDmMessage_conversationId",
- "unique": false,
- "columnNames": [
- "conversationId"
- ],
- "orders": [],
- "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupDmMessage_conversationId` ON `${TABLE_NAME}` (`conversationId`)"
- }
- ],
- "foreignKeys": [
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "GroupDmOutbound",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`signingSessionId` TEXT NOT NULL, `sealId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `recipient` TEXT NOT NULL, `relays` TEXT NOT NULL, `wrapJson` TEXT, `publishedAt` INTEGER, `attempts` INTEGER NOT NULL, `nextAttemptAt` INTEGER, PRIMARY KEY(`signingSessionId`, `sealId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "signingSessionId",
- "columnName": "signingSessionId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "sealId",
- "columnName": "sealId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "recipient",
- "columnName": "recipient",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relays",
- "columnName": "relays",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "wrapJson",
- "columnName": "wrapJson",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "publishedAt",
- "columnName": "publishedAt",
- "affinity": "INTEGER"
- },
- {
- "fieldPath": "attempts",
- "columnName": "attempts",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "nextAttemptAt",
- "columnName": "nextAttemptAt",
- "affinity": "INTEGER"
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "signingSessionId",
- "sealId"
- ]
- },
- "indices": [
- {
- "name": "index_GroupDmOutbound_chatRoomId",
- "unique": false,
- "columnNames": [
- "chatRoomId"
- ],
- "orders": [],
- "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupDmOutbound_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
- }
- ],
- "foreignKeys": [
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "GroupDmWrap",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `wrapJson` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `state` TEXT NOT NULL, `sealJson` TEXT, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "id",
- "columnName": "id",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "wrapJson",
- "columnName": "wrapJson",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "state",
- "columnName": "state",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "sealJson",
- "columnName": "sealJson",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "receivedAt",
- "columnName": "receivedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "indices": [
- {
- "name": "index_GroupDmWrap_chatRoomId",
- "unique": false,
- "columnNames": [
- "chatRoomId"
- ],
- "orders": [],
- "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupDmWrap_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
- },
- {
- "name": "index_GroupDmWrap_state",
- "unique": false,
- "columnNames": [
- "state"
- ],
- "orders": [],
- "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupDmWrap_state` ON `${TABLE_NAME}` (`state`)"
- }
- ],
- "foreignKeys": [
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "GroupEcdhPartial",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`roundId` TEXT NOT NULL, `participantId` INTEGER NOT NULL, `senderPublicKey` TEXT NOT NULL, `partial` TEXT NOT NULL, `proof` TEXT NOT NULL, `verified` INTEGER NOT NULL, `blamedAt` INTEGER, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`roundId`, `participantId`), FOREIGN KEY(`roundId`) REFERENCES `GroupEcdhRound`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "roundId",
- "columnName": "roundId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "participantId",
- "columnName": "participantId",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "senderPublicKey",
- "columnName": "senderPublicKey",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "partial",
- "columnName": "partial",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "proof",
- "columnName": "proof",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "verified",
- "columnName": "verified",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "blamedAt",
- "columnName": "blamedAt",
- "affinity": "INTEGER"
- },
- {
- "fieldPath": "receivedAt",
- "columnName": "receivedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "roundId",
- "participantId"
- ]
- },
- "foreignKeys": [
- {
- "table": "GroupEcdhRound",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "roundId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "GroupEcdhRound",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `generation` INTEGER NOT NULL, `point` TEXT NOT NULL, `purpose` TEXT NOT NULL, `ref` TEXT, `evidenceJson` TEXT, `state` TEXT NOT NULL, `partialSentAt` INTEGER, `openedAt` INTEGER NOT NULL, `combinedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "id",
- "columnName": "id",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "generation",
- "columnName": "generation",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "point",
- "columnName": "point",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "purpose",
- "columnName": "purpose",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "ref",
- "columnName": "ref",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "evidenceJson",
- "columnName": "evidenceJson",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "state",
- "columnName": "state",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "partialSentAt",
- "columnName": "partialSentAt",
- "affinity": "INTEGER"
- },
- {
- "fieldPath": "openedAt",
- "columnName": "openedAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "combinedAt",
- "columnName": "combinedAt",
- "affinity": "INTEGER"
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "indices": [
- {
- "name": "index_GroupEcdhRound_chatRoomId",
- "unique": false,
- "columnNames": [
- "chatRoomId"
- ],
- "orders": [],
- "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupEcdhRound_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
- },
- {
- "name": "index_GroupEcdhRound_point",
- "unique": false,
- "columnNames": [
- "point"
- ],
- "orders": [],
- "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupEcdhRound_point` ON `${TABLE_NAME}` (`point`)"
- }
- ],
- "foreignKeys": [
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
{
"tableName": "GroupKeyState",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `dkgSessionId` TEXT NOT NULL, `thresholdPublicKey` TEXT NOT NULL, `derivationPath` TEXT NOT NULL, `announcedBy` TEXT NOT NULL, `announcedAt` INTEGER NOT NULL, `parentChatRoomId` TEXT, `birthCertificateJson` TEXT, `generation` INTEGER, `publicSharesHash` TEXT, `memberBindings` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`chatRoomId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
@@ -6388,7 +6031,7 @@
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
- "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'efe0dacf1c5e6808f7fa2ae4dd9a2cba')"
+ "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '4097e68a695ef0410fb2c8968c8fb2f3')"
]
}
}
\ No newline at end of file
diff --git a/composeApp/schemas/mobi.giza.compose.database.GizaDatabase/46.json b/composeApp/schemas/mobi.giza.compose.database.GizaDatabase/46.json
new file mode 100644
index 00000000..5e158e09
--- /dev/null
+++ b/composeApp/schemas/mobi.giza.compose.database.GizaDatabase/46.json
@@ -0,0 +1,6699 @@
+{
+ "formatVersion": 1,
+ "database": {
+ "version": 46,
+ "identityHash": "3a8d838b225cf6371608e0f4900c6669",
+ "entities": [
+ {
+ "tableName": "BroadcastNostrEventReceipt",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `nostrEventId` TEXT NOT NULL, `unsignedNostrEventId` INTEGER, `isAccepted` INTEGER NOT NULL, `isSync` INTEGER NOT NULL, `relayURL` TEXT NOT NULL, `messages` TEXT, FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`unsignedNostrEventId`) REFERENCES `UnsignedNostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "unsignedNostrEventId",
+ "columnName": "unsignedNostrEventId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "isAccepted",
+ "columnName": "isAccepted",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isSync",
+ "columnName": "isSync",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "messages",
+ "columnName": "messages",
+ "affinity": "TEXT"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_BroadcastNostrEventReceipt_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_BroadcastNostrEventReceipt_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_BroadcastNostrEventReceipt_isAccepted",
+ "unique": false,
+ "columnNames": [
+ "isAccepted"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_BroadcastNostrEventReceipt_isAccepted` ON `${TABLE_NAME}` (`isAccepted`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "UnsignedNostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "unsignedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "BroadcastNostrEventRequest",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `nostrEventId` TEXT NOT NULL, `unsignedNostrEventId` INTEGER, `status` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`unsignedNostrEventId`) REFERENCES `UnsignedNostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "unsignedNostrEventId",
+ "columnName": "unsignedNostrEventId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "status",
+ "columnName": "status",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_BroadcastNostrEventRequest_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_BroadcastNostrEventRequest_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_BroadcastNostrEventRequest_status",
+ "unique": false,
+ "columnNames": [
+ "status"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_BroadcastNostrEventRequest_status` ON `${TABLE_NAME}` (`status`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "UnsignedNostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "unsignedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Connection",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sourcePublicKey` TEXT NOT NULL, `destinationPublicKey` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`sourcePublicKey`, `destinationPublicKey`), FOREIGN KEY(`sourcePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`destinationPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sourcePublicKey",
+ "columnName": "sourcePublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "destinationPublicKey",
+ "columnName": "destinationPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sourcePublicKey",
+ "destinationPublicKey"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sourcePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "destinationPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `senderPublicKey` TEXT NOT NULL, `isUserMessage` INTEGER NOT NULL, `giftWrapPayloadId` TEXT, `marmotGroupEventId` TEXT, `marmotInnerEventId` TEXT, `chatRoomId` TEXT NOT NULL, `replyToMessageId` INTEGER, `quotedMessageId` INTEGER, `content` TEXT NOT NULL, `messageType` TEXT NOT NULL, `directMessageRecipientPublicKey` TEXT, `frostSigningSessionId` TEXT, `dkgSessionId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`giftWrapPayloadId`) REFERENCES `GiftWrapPayload`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`marmotGroupEventId`) REFERENCES `MarmotGroupEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`marmotInnerEventId`) REFERENCES `MarmotInnerEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isUserMessage",
+ "columnName": "isUserMessage",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "giftWrapPayloadId",
+ "columnName": "giftWrapPayloadId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "marmotGroupEventId",
+ "columnName": "marmotGroupEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "marmotInnerEventId",
+ "columnName": "marmotInnerEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "replyToMessageId",
+ "columnName": "replyToMessageId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "quotedMessageId",
+ "columnName": "quotedMessageId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "messageType",
+ "columnName": "messageType",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "directMessageRecipientPublicKey",
+ "columnName": "directMessageRecipientPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "frostSigningSessionId",
+ "columnName": "frostSigningSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ChatMessage_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ChatMessage_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "GiftWrapPayload",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "giftWrapPayloadId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "MarmotGroupEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "marmotGroupEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "MarmotInnerEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "marmotInnerEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatMessageBroadcastNostrEventRequestRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `chatMessageId` INTEGER NOT NULL, `broadcastNostrEventRequestId` INTEGER NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, FOREIGN KEY(`chatMessageId`) REFERENCES `ChatMessage`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`broadcastNostrEventRequestId`) REFERENCES `BroadcastNostrEventRequest`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatMessageId",
+ "columnName": "chatMessageId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "broadcastNostrEventRequestId",
+ "columnName": "broadcastNostrEventRequestId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatMessage",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatMessageId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "BroadcastNostrEventRequest",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "broadcastNostrEventRequestId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatMessageBroadcastNostrEventReceiptRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `chatMessageId` INTEGER NOT NULL, `broadcastNostrEventReceiptId` INTEGER NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, FOREIGN KEY(`chatMessageId`) REFERENCES `ChatMessage`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`broadcastNostrEventReceiptId`) REFERENCES `BroadcastNostrEventReceipt`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatMessageId",
+ "columnName": "chatMessageId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "broadcastNostrEventReceiptId",
+ "columnName": "broadcastNostrEventReceiptId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatMessage",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatMessageId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "BroadcastNostrEventReceipt",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "broadcastNostrEventReceiptId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatMessageNostrEventRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `chatMessageId` INTEGER NOT NULL, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, FOREIGN KEY(`chatMessageId`) REFERENCES `ChatMessage`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatMessageId",
+ "columnName": "chatMessageId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatMessage",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatMessageId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatRoom",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `subject` TEXT, `description` TEXT, `mlsGroupState` TEXT, `initialGiftWrapPayloadId` TEXT, `leftGroupAt` INTEGER, `joinedGroupAt` INTEGER, `chronicleRequestedAt` INTEGER, `parentChatRoomId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`userPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`initialGiftWrapPayloadId`) REFERENCES `GiftWrapPayload`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "subject",
+ "columnName": "subject",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "description",
+ "columnName": "description",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "mlsGroupState",
+ "columnName": "mlsGroupState",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "initialGiftWrapPayloadId",
+ "columnName": "initialGiftWrapPayloadId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "leftGroupAt",
+ "columnName": "leftGroupAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "joinedGroupAt",
+ "columnName": "joinedGroupAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "chronicleRequestedAt",
+ "columnName": "chronicleRequestedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "parentChatRoomId",
+ "columnName": "parentChatRoomId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "userPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "GiftWrapPayload",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "initialGiftWrapPayloadId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Confederation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `proposalId` TEXT NOT NULL, `ceremonyId` TEXT NOT NULL, `name` TEXT NOT NULL, `roster` TEXT NOT NULL, `keyState` TEXT NOT NULL, `genesis` TEXT NOT NULL, `configSeq` INTEGER NOT NULL, `rosterHash` TEXT NOT NULL, `keyStateHash` TEXT NOT NULL, `recoveryPackages` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`id`))",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "proposalId",
+ "columnName": "proposalId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ceremonyId",
+ "columnName": "ceremonyId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "name",
+ "columnName": "name",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "roster",
+ "columnName": "roster",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "keyState",
+ "columnName": "keyState",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "genesis",
+ "columnName": "genesis",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "configSeq",
+ "columnName": "configSeq",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "rosterHash",
+ "columnName": "rosterHash",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "keyStateHash",
+ "columnName": "keyStateHash",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "recoveryPackages",
+ "columnName": "recoveryPackages",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Confederation_proposalId",
+ "unique": false,
+ "columnNames": [
+ "proposalId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Confederation_proposalId` ON `${TABLE_NAME}` (`proposalId`)"
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationCeremony",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `proposalId` TEXT NOT NULL, `coordinatorPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `openingJson` TEXT NOT NULL, `stage` TEXT NOT NULL, `approvedAt` INTEGER, `dealerSeeds` TEXT, `recoveryNonces` TEXT, `keyState` TEXT, `transitionHash` TEXT, `genesis` TEXT, `recoveryPackages` TEXT, `confederationPublicKey` TEXT, `failureReason` TEXT, `culprit` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "proposalId",
+ "columnName": "proposalId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorPublicKey",
+ "columnName": "coordinatorPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "openingJson",
+ "columnName": "openingJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "approvedAt",
+ "columnName": "approvedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "dealerSeeds",
+ "columnName": "dealerSeeds",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recoveryNonces",
+ "columnName": "recoveryNonces",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "keyState",
+ "columnName": "keyState",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "transitionHash",
+ "columnName": "transitionHash",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "genesis",
+ "columnName": "genesis",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recoveryPackages",
+ "columnName": "recoveryPackages",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "confederationPublicKey",
+ "columnName": "confederationPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "culprit",
+ "columnName": "culprit",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ConfederationCeremony_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationCeremony_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_ConfederationCeremony_proposalId",
+ "unique": false,
+ "columnNames": [
+ "proposalId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationCeremony_proposalId` ON `${TABLE_NAME}` (`proposalId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationMember",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`confederationId` TEXT NOT NULL, `groupPublicKey` TEXT NOT NULL, PRIMARY KEY(`confederationId`, `groupPublicKey`))",
+ "fields": [
+ {
+ "fieldPath": "confederationId",
+ "columnName": "confederationId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "groupPublicKey",
+ "columnName": "groupPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "confederationId",
+ "groupPublicKey"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ConfederationMember_groupPublicKey",
+ "unique": false,
+ "columnNames": [
+ "groupPublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationMember_groupPublicKey` ON `${TABLE_NAME}` (`groupPublicKey`)"
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationSigningAttempt",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `confederationId` TEXT NOT NULL, `proposerPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `eventJson` TEXT NOT NULL, `stage` TEXT NOT NULL, `approvedAt` INTEGER, `declinedAt` INTEGER, `signedEventJson` TEXT, `failureReason` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`confederationId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "confederationId",
+ "columnName": "confederationId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "proposerPublicKey",
+ "columnName": "proposerPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "eventJson",
+ "columnName": "eventJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "approvedAt",
+ "columnName": "approvedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "declinedAt",
+ "columnName": "declinedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "signedEventJson",
+ "columnName": "signedEventJson",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ConfederationSigningAttempt_confederationId",
+ "unique": false,
+ "columnNames": [
+ "confederationId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationSigningAttempt_confederationId` ON `${TABLE_NAME}` (`confederationId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "confederationId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationSigningMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`attemptId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`attemptId`, `senderPublicKey`, `kind`), FOREIGN KEY(`attemptId`) REFERENCES `ConfederationSigningAttempt`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "attemptId",
+ "columnName": "attemptId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "attemptId",
+ "senderPublicKey",
+ "kind"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ConfederationSigningAttempt",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "attemptId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationCeremonyMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `senderPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `ConfederationCeremony`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "senderPublicKey",
+ "kind"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ConfederationCeremony",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `kind` INTEGER NOT NULL, `pubKey` TEXT NOT NULL, `proposalId` TEXT NOT NULL, `eventCreatedAt` INTEGER NOT NULL, `eventJson` TEXT NOT NULL, `receivedAt` INTEGER NOT NULL, `ownSessionId` TEXT, `publishedAt` INTEGER, PRIMARY KEY(`id`))",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "pubKey",
+ "columnName": "pubKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "proposalId",
+ "columnName": "proposalId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "eventCreatedAt",
+ "columnName": "eventCreatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "eventJson",
+ "columnName": "eventJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ownSessionId",
+ "columnName": "ownSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "publishedAt",
+ "columnName": "publishedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ConfederationEvent_proposalId",
+ "unique": false,
+ "columnNames": [
+ "proposalId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationEvent_proposalId` ON `${TABLE_NAME}` (`proposalId`)"
+ },
+ {
+ "name": "index_ConfederationEvent_kind",
+ "unique": false,
+ "columnNames": [
+ "kind"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationEvent_kind` ON `${TABLE_NAME}` (`kind`)"
+ },
+ {
+ "name": "index_ConfederationEvent_publishedAt",
+ "unique": false,
+ "columnNames": [
+ "publishedAt"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationEvent_publishedAt` ON `${TABLE_NAME}` (`publishedAt`)"
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationInvitee",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`proposalId` TEXT NOT NULL, `groupPublicKey` TEXT NOT NULL, PRIMARY KEY(`proposalId`, `groupPublicKey`))",
+ "fields": [
+ {
+ "fieldPath": "proposalId",
+ "columnName": "proposalId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "groupPublicKey",
+ "columnName": "groupPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "proposalId",
+ "groupPublicKey"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ConfederationInvitee_groupPublicKey",
+ "unique": false,
+ "columnNames": [
+ "groupPublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationInvitee_groupPublicKey` ON `${TABLE_NAME}` (`groupPublicKey`)"
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationSigning",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `sealSecret` TEXT, `proposalJson` TEXT, `refusal` TEXT, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`), FOREIGN KEY(`sessionId`) REFERENCES `FrostSigningSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "sealSecret",
+ "columnName": "sealSecret",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "proposalJson",
+ "columnName": "proposalJson",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "refusal",
+ "columnName": "refusal",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "FrostSigningSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "DkgParticipantMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `participantPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `participantPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `DkgSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKey",
+ "columnName": "participantPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "participantPublicKey",
+ "kind"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_DkgParticipantMessage_sessionId",
+ "unique": false,
+ "columnNames": [
+ "sessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_DkgParticipantMessage_sessionId` ON `${TABLE_NAME}` (`sessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "DkgSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "DkgSession",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `coordinatorPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `threshold` INTEGER NOT NULL, `participantCount` INTEGER NOT NULL, `participantPublicKeys` TEXT, `subject` TEXT, `walletPolicy` TEXT, `stage` TEXT NOT NULL, `hostPublicKey` TEXT NOT NULL, `round1Random` TEXT NOT NULL, `round2AuxRandom` TEXT NOT NULL, `coordinatorRound1` TEXT, `certificate` TEXT, `thresholdPublicKey` TEXT, `secretShare` TEXT, `publicShares` TEXT, `recoveryData` TEXT, `failureReason` TEXT, `hostKeyApprovedAt` INTEGER, `round1ApprovedAt` INTEGER, `round2ApprovedAt` INTEGER, `approvalRequestedThrough` TEXT, `parentChatRoomId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorPublicKey",
+ "columnName": "coordinatorPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "threshold",
+ "columnName": "threshold",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantCount",
+ "columnName": "participantCount",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKeys",
+ "columnName": "participantPublicKeys",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "subject",
+ "columnName": "subject",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "walletPolicy",
+ "columnName": "walletPolicy",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "hostPublicKey",
+ "columnName": "hostPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "round1Random",
+ "columnName": "round1Random",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "round2AuxRandom",
+ "columnName": "round2AuxRandom",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorRound1",
+ "columnName": "coordinatorRound1",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "certificate",
+ "columnName": "certificate",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "thresholdPublicKey",
+ "columnName": "thresholdPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "secretShare",
+ "columnName": "secretShare",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "publicShares",
+ "columnName": "publicShares",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recoveryData",
+ "columnName": "recoveryData",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "hostKeyApprovedAt",
+ "columnName": "hostKeyApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "round1ApprovedAt",
+ "columnName": "round1ApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "round2ApprovedAt",
+ "columnName": "round2ApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "approvalRequestedThrough",
+ "columnName": "approvalRequestedThrough",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "parentChatRoomId",
+ "columnName": "parentChatRoomId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_DkgSession_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_DkgSession_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "FrostSignerMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `signerPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `signerPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `FrostSigningSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signerPublicKey",
+ "columnName": "signerPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "signerPublicKey",
+ "kind"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_FrostSignerMessage_sessionId",
+ "unique": false,
+ "columnNames": [
+ "sessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_FrostSignerMessage_sessionId` ON `${TABLE_NAME}` (`sessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "FrostSigningSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "FrostSigningItem",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `itemIndex` INTEGER NOT NULL, `unsignedEventJson` TEXT NOT NULL, `eventId` TEXT NOT NULL, `nonceRandom` TEXT NOT NULL, `aggregatedNonce` TEXT, `signature` TEXT, PRIMARY KEY(`sessionId`, `itemIndex`), FOREIGN KEY(`sessionId`) REFERENCES `FrostSigningSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "itemIndex",
+ "columnName": "itemIndex",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "unsignedEventJson",
+ "columnName": "unsignedEventJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "eventId",
+ "columnName": "eventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nonceRandom",
+ "columnName": "nonceRandom",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "aggregatedNonce",
+ "columnName": "aggregatedNonce",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "itemIndex"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_FrostSigningItem_sessionId",
+ "unique": false,
+ "columnNames": [
+ "sessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_FrostSigningItem_sessionId` ON `${TABLE_NAME}` (`sessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "FrostSigningSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "FrostSigningSession",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `coordinatorPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `dkgSessionId` TEXT NOT NULL, `threshold` INTEGER NOT NULL, `participantCount` INTEGER NOT NULL, `signerId` INTEGER NOT NULL, `derivationPath` TEXT, `generation` INTEGER, `stage` TEXT NOT NULL, `signerIds` TEXT, `failureReason` TEXT, `signApprovedAt` INTEGER, `signDeclinedAt` INTEGER, `approvalRequestedAt` INTEGER, `resentAt` INTEGER, `subject` TEXT NOT NULL DEFAULT 'EVENTS', `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorPublicKey",
+ "columnName": "coordinatorPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "threshold",
+ "columnName": "threshold",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantCount",
+ "columnName": "participantCount",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signerId",
+ "columnName": "signerId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "derivationPath",
+ "columnName": "derivationPath",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signerIds",
+ "columnName": "signerIds",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "signApprovedAt",
+ "columnName": "signApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "signDeclinedAt",
+ "columnName": "signDeclinedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "approvalRequestedAt",
+ "columnName": "approvalRequestedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "resentAt",
+ "columnName": "resentAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "subject",
+ "columnName": "subject",
+ "affinity": "TEXT",
+ "notNull": true,
+ "defaultValue": "'EVENTS'"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_FrostSigningSession_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_FrostSigningSession_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_FrostSigningSession_dkgSessionId",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_FrostSigningSession_dkgSessionId` ON `${TABLE_NAME}` (`dkgSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GiftWrapMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `receiverPublicKey` TEXT NOT NULL, `receiverRelayHit` TEXT, `content` TEXT NOT NULL, `signature` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receiverPublicKey",
+ "columnName": "receiverPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receiverRelayHit",
+ "columnName": "receiverRelayHit",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GiftWrapSeal",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `signature` TEXT NOT NULL, `giftWrapMessageId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`giftWrapMessageId`) REFERENCES `GiftWrapMessage`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "giftWrapMessageId",
+ "columnName": "giftWrapMessageId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "GiftWrapMessage",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "giftWrapMessageId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GiftWrapPayload",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `quotedEventId` TEXT, `giftWrapSealId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`giftWrapSealId`) REFERENCES `GiftWrapSeal`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "quotedEventId",
+ "columnName": "quotedEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "giftWrapSealId",
+ "columnName": "giftWrapSealId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "GiftWrapSeal",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "giftWrapSealId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupInboxMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `rumorId` TEXT NOT NULL, `wrapId` TEXT, `conversationId` TEXT NOT NULL, `participants` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `rumorJson` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `generation` INTEGER NOT NULL, `outgoing` INTEGER NOT NULL, `signingSessionId` TEXT, `readAt` INTEGER, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`chatRoomId`, `rumorId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "rumorId",
+ "columnName": "rumorId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "wrapId",
+ "columnName": "wrapId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "conversationId",
+ "columnName": "conversationId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participants",
+ "columnName": "participants",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "rumorJson",
+ "columnName": "rumorJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "outgoing",
+ "columnName": "outgoing",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signingSessionId",
+ "columnName": "signingSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "readAt",
+ "columnName": "readAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId",
+ "rumorId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupInboxMessage_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupInboxMessage_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GroupInboxMessage_conversationId",
+ "unique": false,
+ "columnNames": [
+ "conversationId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupInboxMessage_conversationId` ON `${TABLE_NAME}` (`conversationId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupInboxPublication",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`eventId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `kind` INTEGER NOT NULL, `eventJson` TEXT NOT NULL, `relays` TEXT NOT NULL, `signingSessionId` TEXT, `recipientPublicKey` TEXT, `attempts` INTEGER NOT NULL, `nextAttemptAt` INTEGER, `publishedAt` INTEGER, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`eventId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "eventId",
+ "columnName": "eventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "eventJson",
+ "columnName": "eventJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relays",
+ "columnName": "relays",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signingSessionId",
+ "columnName": "signingSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recipientPublicKey",
+ "columnName": "recipientPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "attempts",
+ "columnName": "attempts",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nextAttemptAt",
+ "columnName": "nextAttemptAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "publishedAt",
+ "columnName": "publishedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "eventId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupInboxPublication_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupInboxPublication_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GroupInboxPublication_signingSessionId",
+ "unique": false,
+ "columnNames": [
+ "signingSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupInboxPublication_signingSessionId` ON `${TABLE_NAME}` (`signingSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupInboxWrap",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `wrapJson` TEXT NOT NULL, `wrapCreatedAt` INTEGER NOT NULL, `openedGeneration` INTEGER, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "wrapJson",
+ "columnName": "wrapJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "wrapCreatedAt",
+ "columnName": "wrapCreatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "openedGeneration",
+ "columnName": "openedGeneration",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupInboxWrap_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupInboxWrap_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupKeyState",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `dkgSessionId` TEXT NOT NULL, `thresholdPublicKey` TEXT NOT NULL, `derivationPath` TEXT NOT NULL, `announcedBy` TEXT NOT NULL, `announcedAt` INTEGER NOT NULL, `parentChatRoomId` TEXT, `birthCertificateJson` TEXT, `generation` INTEGER, `publicSharesHash` TEXT, `memberBindings` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`chatRoomId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "thresholdPublicKey",
+ "columnName": "thresholdPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "derivationPath",
+ "columnName": "derivationPath",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "announcedBy",
+ "columnName": "announcedBy",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "announcedAt",
+ "columnName": "announcedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "parentChatRoomId",
+ "columnName": "parentChatRoomId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "birthCertificateJson",
+ "columnName": "birthCertificateJson",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "publicSharesHash",
+ "columnName": "publicSharesHash",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "memberBindings",
+ "columnName": "memberBindings",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupKeyState_dkgSessionId",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupKeyState_dkgSessionId` ON `${TABLE_NAME}` (`dkgSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupSignedEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `signature` TEXT NOT NULL, `derivationPath` TEXT, `frostSigningSessionId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "derivationPath",
+ "columnName": "derivationPath",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "frostSigningSessionId",
+ "columnName": "frostSigningSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupSignedEvent_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupSignedEvent_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GroupSignedEvent_kind",
+ "unique": false,
+ "columnNames": [
+ "kind"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupSignedEvent_kind` ON `${TABLE_NAME}` (`kind`)"
+ },
+ {
+ "name": "index_GroupSignedEvent_frostSigningSessionId",
+ "unique": false,
+ "columnNames": [
+ "frostSigningSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupSignedEvent_frostSigningSessionId` ON `${TABLE_NAME}` (`frostSigningSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "InboxKey",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `generation` INTEGER NOT NULL, `publicKey` TEXT NOT NULL, `secretKey` TEXT, `recoveryData` TEXT, `ceremonyId` TEXT NOT NULL, `state` TEXT NOT NULL, `announcementEventId` TEXT, `createdAt` INTEGER NOT NULL, `announcedAt` INTEGER, `wipedAt` INTEGER, PRIMARY KEY(`chatRoomId`, `userPublicKey`, `generation`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "secretKey",
+ "columnName": "secretKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recoveryData",
+ "columnName": "recoveryData",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "ceremonyId",
+ "columnName": "ceremonyId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "state",
+ "columnName": "state",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "announcementEventId",
+ "columnName": "announcementEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "announcedAt",
+ "columnName": "announcedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "wipedAt",
+ "columnName": "wipedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId",
+ "userPublicKey",
+ "generation"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_InboxKey_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_InboxKey_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "InboxKeyCeremony",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `generation` INTEGER NOT NULL, `coordinatorPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `participantPublicKeys` TEXT NOT NULL, `stage` TEXT NOT NULL, `hostPublicKey` TEXT, `round1Random` TEXT, `round2AuxRandom` TEXT, `announceRelays` TEXT, `inboxPublicKey` TEXT, `failureReason` TEXT, `culprit` TEXT, `lastMessageAt` INTEGER NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorPublicKey",
+ "columnName": "coordinatorPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKeys",
+ "columnName": "participantPublicKeys",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "hostPublicKey",
+ "columnName": "hostPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "round1Random",
+ "columnName": "round1Random",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "round2AuxRandom",
+ "columnName": "round2AuxRandom",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "announceRelays",
+ "columnName": "announceRelays",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inboxPublicKey",
+ "columnName": "inboxPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "culprit",
+ "columnName": "culprit",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "lastMessageAt",
+ "columnName": "lastMessageAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_InboxKeyCeremony_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_InboxKeyCeremony_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "InboxKeyCeremonyMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `senderPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `InboxKeyCeremony`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "senderPublicKey",
+ "kind"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "InboxKeyCeremony",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "InboxSigning",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `manifest` TEXT, `refusal` TEXT, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "manifest",
+ "columnName": "manifest",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "refusal",
+ "columnName": "refusal",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_InboxSigning_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_InboxSigning_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "KeyShareGeneration",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`dkgSessionId` TEXT NOT NULL, `generation` INTEGER NOT NULL, `secretShare` TEXT, `publicShares` TEXT NOT NULL, `state` TEXT NOT NULL, `refreshSessionId` TEXT, `recoveryData` TEXT, `activatedAt` INTEGER, `wipedAt` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`dkgSessionId`, `generation`), FOREIGN KEY(`dkgSessionId`) REFERENCES `DkgSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "secretShare",
+ "columnName": "secretShare",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "publicShares",
+ "columnName": "publicShares",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "state",
+ "columnName": "state",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "refreshSessionId",
+ "columnName": "refreshSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recoveryData",
+ "columnName": "recoveryData",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "activatedAt",
+ "columnName": "activatedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "wipedAt",
+ "columnName": "wipedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "dkgSessionId",
+ "generation"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_KeyShareGeneration_dkgSessionId",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_KeyShareGeneration_dkgSessionId` ON `${TABLE_NAME}` (`dkgSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "DkgSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "dkgSessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "KeyShareMember",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`dkgSessionId` TEXT NOT NULL, `generation` INTEGER NOT NULL, `participantId` INTEGER NOT NULL, `memberPublicKey` TEXT NOT NULL, `hostPublicKey` TEXT NOT NULL, `standing` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`dkgSessionId`, `generation`, `participantId`), FOREIGN KEY(`dkgSessionId`, `generation`) REFERENCES `KeyShareGeneration`(`dkgSessionId`, `generation`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantId",
+ "columnName": "participantId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "memberPublicKey",
+ "columnName": "memberPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "hostPublicKey",
+ "columnName": "hostPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "standing",
+ "columnName": "standing",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "dkgSessionId",
+ "generation",
+ "participantId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_KeyShareMember_dkgSessionId_generation",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId",
+ "generation"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_KeyShareMember_dkgSessionId_generation` ON `${TABLE_NAME}` (`dkgSessionId`, `generation`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "KeyShareGeneration",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "dkgSessionId",
+ "generation"
+ ],
+ "referencedColumns": [
+ "dkgSessionId",
+ "generation"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ShareRefreshConfirmation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`dkgSessionId` TEXT NOT NULL, `baseGeneration` INTEGER NOT NULL, `refreshSessionId` TEXT NOT NULL, `confirmedAt` INTEGER NOT NULL, PRIMARY KEY(`dkgSessionId`, `baseGeneration`))",
+ "fields": [
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "baseGeneration",
+ "columnName": "baseGeneration",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "refreshSessionId",
+ "columnName": "refreshSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "confirmedAt",
+ "columnName": "confirmedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "dkgSessionId",
+ "baseGeneration"
+ ]
+ }
+ },
+ {
+ "tableName": "ShareRefreshMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `participantPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `participantPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `ShareRefreshSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKey",
+ "columnName": "participantPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "participantPublicKey",
+ "kind"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ShareRefreshSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ShareRefreshSession",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `dkgSessionId` TEXT NOT NULL, `coordinatorPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `baseGeneration` INTEGER NOT NULL, `recipientIds` TEXT NOT NULL, `withheld` TEXT, `stage` TEXT NOT NULL, `round1Random` TEXT NOT NULL, `auxRandom` TEXT NOT NULL, `dealApprovedAt` INTEGER, `confirmApprovedAt` INTEGER, `approvalRequestedThrough` TEXT, `coordinatorRound1` TEXT, `certificate` TEXT, `failureReason` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorPublicKey",
+ "columnName": "coordinatorPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "baseGeneration",
+ "columnName": "baseGeneration",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "recipientIds",
+ "columnName": "recipientIds",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "withheld",
+ "columnName": "withheld",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "round1Random",
+ "columnName": "round1Random",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "auxRandom",
+ "columnName": "auxRandom",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dealApprovedAt",
+ "columnName": "dealApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "confirmApprovedAt",
+ "columnName": "confirmApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "approvalRequestedThrough",
+ "columnName": "approvalRequestedThrough",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "coordinatorRound1",
+ "columnName": "coordinatorRound1",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "certificate",
+ "columnName": "certificate",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ShareRefreshSession_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ShareRefreshSession_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_ShareRefreshSession_dkgSessionId",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ShareRefreshSession_dkgSessionId` ON `${TABLE_NAME}` (`dkgSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ShareRepairMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `recipientPublicKey` TEXT NOT NULL, `payload` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `senderPublicKey`, `kind`, `recipientPublicKey`), FOREIGN KEY(`sessionId`) REFERENCES `ShareRepairSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "recipientPublicKey",
+ "columnName": "recipientPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "senderPublicKey",
+ "kind",
+ "recipientPublicKey"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ShareRepairSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ShareRepairSession",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `dkgSessionId` TEXT NOT NULL, `generation` INTEGER NOT NULL, `targetId` INTEGER NOT NULL, `targetPublicKey` TEXT NOT NULL, `targetHostPublicKey` TEXT NOT NULL, `helperIds` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `stage` TEXT NOT NULL, `sessionRandom` TEXT NOT NULL, `helpApprovedAt` INTEGER, `approvalRequested` INTEGER NOT NULL, `failureReason` TEXT, `nParticipants` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "targetId",
+ "columnName": "targetId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "targetPublicKey",
+ "columnName": "targetPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "targetHostPublicKey",
+ "columnName": "targetHostPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "helperIds",
+ "columnName": "helperIds",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "sessionRandom",
+ "columnName": "sessionRandom",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "helpApprovedAt",
+ "columnName": "helpApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "approvalRequested",
+ "columnName": "approvalRequested",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nParticipants",
+ "columnName": "nParticipants",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ShareRepairSession_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ShareRepairSession_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_ShareRepairSession_dkgSessionId",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ShareRepairSession_dkgSessionId` ON `${TABLE_NAME}` (`dkgSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GovernanceProposal",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `routingId` TEXT NOT NULL, `epoch` INTEGER NOT NULL, `frostSigningSessionId` TEXT NOT NULL, `commitEventId` TEXT NOT NULL, `commitEventJson` TEXT NOT NULL, `peerKeyPackageEventId` TEXT, `priorStateHex` TEXT NOT NULL, `pendingStateHex` TEXT NOT NULL, `stage` TEXT NOT NULL, `thenRotateWithout` TEXT, `promotionOfferId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "routingId",
+ "columnName": "routingId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "epoch",
+ "columnName": "epoch",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "frostSigningSessionId",
+ "columnName": "frostSigningSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "commitEventId",
+ "columnName": "commitEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "commitEventJson",
+ "columnName": "commitEventJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "peerKeyPackageEventId",
+ "columnName": "peerKeyPackageEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "priorStateHex",
+ "columnName": "priorStateHex",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "pendingStateHex",
+ "columnName": "pendingStateHex",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "thenRotateWithout",
+ "columnName": "thenRotateWithout",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "promotionOfferId",
+ "columnName": "promotionOfferId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GovernanceProposal_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GovernanceProposal_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GovernanceProposal_frostSigningSessionId",
+ "unique": false,
+ "columnNames": [
+ "frostSigningSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GovernanceProposal_frostSigningSessionId` ON `${TABLE_NAME}` (`frostSigningSessionId`)"
+ },
+ {
+ "name": "index_GovernanceProposal_commitEventId",
+ "unique": false,
+ "columnNames": [
+ "commitEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GovernanceProposal_commitEventId` ON `${TABLE_NAME}` (`commitEventId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "InReplyToRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`replyingNostrEventId` TEXT NOT NULL, `inReplyToNostrEventId` TEXT NOT NULL, `inReplyToProfilePublicKey` TEXT, `inReplyToRootNostrEventId` TEXT, `inReplyToRootProfilePublicKey` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`replyingNostrEventId`, `inReplyToNostrEventId`), FOREIGN KEY(`inReplyToProfilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`inReplyToRootProfilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`replyingNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`inReplyToNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`inReplyToRootNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "replyingNostrEventId",
+ "columnName": "replyingNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "inReplyToNostrEventId",
+ "columnName": "inReplyToNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "inReplyToProfilePublicKey",
+ "columnName": "inReplyToProfilePublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToRootNostrEventId",
+ "columnName": "inReplyToRootNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToRootProfilePublicKey",
+ "columnName": "inReplyToRootProfilePublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "replyingNostrEventId",
+ "inReplyToNostrEventId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "inReplyToProfilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "inReplyToRootProfilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "replyingNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "inReplyToNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "inReplyToRootNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotCommitResult",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `peerKeyPackageEventId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `isOneMemberInitialGroupCreation` INTEGER NOT NULL, `commitBytes` BLOB NOT NULL, `welcomeBytes` BLOB, `groupInfoBytes` BLOB, `framedCommitBytes` BLOB NOT NULL, `preCommitExporterSecret` BLOB NOT NULL, `obligationId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`))",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "peerKeyPackageEventId",
+ "columnName": "peerKeyPackageEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isOneMemberInitialGroupCreation",
+ "columnName": "isOneMemberInitialGroupCreation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "commitBytes",
+ "columnName": "commitBytes",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "welcomeBytes",
+ "columnName": "welcomeBytes",
+ "affinity": "BLOB"
+ },
+ {
+ "fieldPath": "groupInfoBytes",
+ "columnName": "groupInfoBytes",
+ "affinity": "BLOB"
+ },
+ {
+ "fieldPath": "framedCommitBytes",
+ "columnName": "framedCommitBytes",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "preCommitExporterSecret",
+ "columnName": "preCommitExporterSecret",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "obligationId",
+ "columnName": "obligationId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ }
+ },
+ {
+ "tableName": "MarmotGroupEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `signature` TEXT NOT NULL, `encryptedContent` TEXT NOT NULL, `expiresAt` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`id`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "encryptedContent",
+ "columnName": "encryptedContent",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "expiresAt",
+ "columnName": "expiresAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "id"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotInnerEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `quotedEventId` TEXT, `marmotGroupEventId` TEXT, `directMessageRecipientPublicKey` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`marmotGroupEventId`) REFERENCES `MarmotGroupEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "quotedEventId",
+ "columnName": "quotedEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "marmotGroupEventId",
+ "columnName": "marmotGroupEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "directMessageRecipientPublicKey",
+ "columnName": "directMessageRecipientPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "MarmotGroupEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "marmotGroupEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotKeyPackage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `tlsEncodedMarmotKeyPackage` BLOB NOT NULL, `profile` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`publicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tlsEncodedMarmotKeyPackage",
+ "columnName": "tlsEncodedMarmotKeyPackage",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "profile",
+ "columnName": "profile",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "publicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotKeyPackageBundle",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `tlsEncodedMarmotKeyPackage` BLOB NOT NULL, `ncryptsecInitPrivateKey` TEXT NOT NULL, `ncryptsecEncryptionPrivateKey` TEXT NOT NULL, `ncryptsecSignaturePrivateKey` TEXT NOT NULL, `consumed` INTEGER NOT NULL, `rotated` INTEGER NOT NULL, `profile` TEXT, `dTag` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`))",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tlsEncodedMarmotKeyPackage",
+ "columnName": "tlsEncodedMarmotKeyPackage",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ncryptsecInitPrivateKey",
+ "columnName": "ncryptsecInitPrivateKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ncryptsecEncryptionPrivateKey",
+ "columnName": "ncryptsecEncryptionPrivateKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ncryptsecSignaturePrivateKey",
+ "columnName": "ncryptsecSignaturePrivateKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "consumed",
+ "columnName": "consumed",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "rotated",
+ "columnName": "rotated",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "profile",
+ "columnName": "profile",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "dTag",
+ "columnName": "dTag",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_MarmotKeyPackageBundle_publicKey",
+ "unique": false,
+ "columnNames": [
+ "publicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_MarmotKeyPackageBundle_publicKey` ON `${TABLE_NAME}` (`publicKey`)"
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotRouting",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`routingId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `activeFromEpoch` INTEGER NOT NULL, `retiredAtEpoch` INTEGER, PRIMARY KEY(`routingId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "routingId",
+ "columnName": "routingId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "activeFromEpoch",
+ "columnName": "activeFromEpoch",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "retiredAtEpoch",
+ "columnName": "retiredAtEpoch",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "routingId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_MarmotRouting_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_MarmotRouting_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotPublishObligation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`obligationId` TEXT NOT NULL, `bytes` BLOB NOT NULL, PRIMARY KEY(`obligationId`))",
+ "fields": [
+ {
+ "fieldPath": "obligationId",
+ "columnName": "obligationId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "bytes",
+ "columnName": "bytes",
+ "affinity": "BLOB",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "obligationId"
+ ]
+ }
+ },
+ {
+ "tableName": "MarmotOutboundGate",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`groupId` TEXT NOT NULL, `gate` TEXT NOT NULL, PRIMARY KEY(`groupId`))",
+ "fields": [
+ {
+ "fieldPath": "groupId",
+ "columnName": "groupId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "gate",
+ "columnName": "gate",
+ "affinity": "TEXT",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "groupId"
+ ]
+ }
+ },
+ {
+ "tableName": "MarmotRetainedEpochSecret",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `epoch` INTEGER NOT NULL, `senderDataSecret` BLOB NOT NULL, `encryptionSecret` BLOB NOT NULL, `leafCount` INTEGER NOT NULL, `exporterSecret` BLOB NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`chatRoomId`, `epoch`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "epoch",
+ "columnName": "epoch",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderDataSecret",
+ "columnName": "senderDataSecret",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "encryptionSecret",
+ "columnName": "encryptionSecret",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "leafCount",
+ "columnName": "leafCount",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "exporterSecret",
+ "columnName": "exporterSecret",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId",
+ "epoch"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotSenderRatchet",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `epoch` INTEGER NOT NULL, `leafIndex` INTEGER NOT NULL, `applicationGeneration` INTEGER NOT NULL, `record` BLOB NOT NULL, PRIMARY KEY(`chatRoomId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "epoch",
+ "columnName": "epoch",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "leafIndex",
+ "columnName": "leafIndex",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "applicationGeneration",
+ "columnName": "applicationGeneration",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "record",
+ "columnName": "record",
+ "affinity": "BLOB",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Mention",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `mentionedPublicKey` TEXT NOT NULL, `mentioningNostrEventId` TEXT, `relayUrl` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, FOREIGN KEY(`mentionedPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`mentioningNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "mentionedPublicKey",
+ "columnName": "mentionedPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "mentioningNostrEventId",
+ "columnName": "mentioningNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "relayUrl",
+ "columnName": "relayUrl",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "mentionedPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "mentioningNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "NegentropySynchronizeRequest",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `uuid` TEXT NOT NULL, `purpose` TEXT NOT NULL, `status` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `isRecommendedRelay` INTEGER NOT NULL, `level` INTEGER NOT NULL, `synchronizationFilter` TEXT NOT NULL, `ownerPublicKey` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "uuid",
+ "columnName": "uuid",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "purpose",
+ "columnName": "purpose",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "status",
+ "columnName": "status",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isRecommendedRelay",
+ "columnName": "isRecommendedRelay",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "level",
+ "columnName": "level",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "synchronizationFilter",
+ "columnName": "synchronizationFilter",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ownerPublicKey",
+ "columnName": "ownerPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_NegentropySynchronizeRequest_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NegentropySynchronizeRequest_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_NegentropySynchronizeRequest_status",
+ "unique": false,
+ "columnNames": [
+ "status"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NegentropySynchronizeRequest_status` ON `${TABLE_NAME}` (`status`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "NegentropySynchronizeResult",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `status` TEXT NOT NULL, `negentropySynchronizeRequestId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`negentropySynchronizeRequestId`) REFERENCES `SynchronizeNostrEventResult`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "status",
+ "columnName": "status",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "negentropySynchronizeRequestId",
+ "columnName": "negentropySynchronizeRequestId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "SynchronizeNostrEventResult",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "negentropySynchronizeRequestId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "NostrEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `pubKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `sig` TEXT NOT NULL, `relayUrl` TEXT, `quotedNostrEventId` TEXT, `quotedAuthorPublicKey` TEXT, `inReplyToNostrEventId` TEXT, `inReplyToAuthorPublicKey` TEXT, `inReplyToRootNostrEventId` TEXT, `inReplyToRootAuthorPublicKey` TEXT, `repostedNostrEventId` TEXT, `repostedAuthorPublicKey` TEXT, `unsignedNostrEventId` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`))",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "pubKey",
+ "columnName": "pubKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "sig",
+ "columnName": "sig",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayUrl",
+ "columnName": "relayUrl",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "quotedNostrEventId",
+ "columnName": "quotedNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "quotedAuthorPublicKey",
+ "columnName": "quotedAuthorPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToNostrEventId",
+ "columnName": "inReplyToNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToAuthorPublicKey",
+ "columnName": "inReplyToAuthorPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToRootNostrEventId",
+ "columnName": "inReplyToRootNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToRootAuthorPublicKey",
+ "columnName": "inReplyToRootAuthorPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "repostedNostrEventId",
+ "columnName": "repostedNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "repostedAuthorPublicKey",
+ "columnName": "repostedAuthorPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "unsignedNostrEventId",
+ "columnName": "unsignedNostrEventId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_NostrEvent_kind",
+ "unique": false,
+ "columnNames": [
+ "kind"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_kind` ON `${TABLE_NAME}` (`kind`)"
+ },
+ {
+ "name": "index_NostrEvent_pubKey",
+ "unique": false,
+ "columnNames": [
+ "pubKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_pubKey` ON `${TABLE_NAME}` (`pubKey`)"
+ },
+ {
+ "name": "index_NostrEvent_quotedNostrEventId",
+ "unique": false,
+ "columnNames": [
+ "quotedNostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_quotedNostrEventId` ON `${TABLE_NAME}` (`quotedNostrEventId`)"
+ },
+ {
+ "name": "index_NostrEvent_inReplyToNostrEventId",
+ "unique": false,
+ "columnNames": [
+ "inReplyToNostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_inReplyToNostrEventId` ON `${TABLE_NAME}` (`inReplyToNostrEventId`)"
+ },
+ {
+ "name": "index_NostrEvent_inReplyToRootNostrEventId",
+ "unique": false,
+ "columnNames": [
+ "inReplyToRootNostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_inReplyToRootNostrEventId` ON `${TABLE_NAME}` (`inReplyToRootNostrEventId`)"
+ }
+ ]
+ },
+ {
+ "tableName": "NostrEventRelay",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`relayURL` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`nostrEventId`, `relayURL`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "nostrEventId",
+ "relayURL"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_NostrEventRelay_relayURL",
+ "unique": false,
+ "columnNames": [
+ "relayURL"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEventRelay_relayURL` ON `${TABLE_NAME}` (`relayURL`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Participant",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `participantPublicKey` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `adminAt` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, FOREIGN KEY(`participantPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKey",
+ "columnName": "participantPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayHint",
+ "columnName": "relayHint",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "adminAt",
+ "columnName": "adminAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "participantPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Post",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `repostId` TEXT, `quote` TEXT, `content` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `replyToId` TEXT, `profilePublicKey` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`profilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`replyToId`) REFERENCES `Post`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`repostId`) REFERENCES `Post`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "repostId",
+ "columnName": "repostId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "quote",
+ "columnName": "quote",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "replyToId",
+ "columnName": "replyToId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "profilePublicKey",
+ "columnName": "profilePublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Post_profilePublicKey",
+ "unique": false,
+ "columnNames": [
+ "profilePublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Post_profilePublicKey` ON `${TABLE_NAME}` (`profilePublicKey`)"
+ },
+ {
+ "name": "index_Post_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Post_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_Post_replyToId",
+ "unique": false,
+ "columnNames": [
+ "replyToId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Post_replyToId` ON `${TABLE_NAME}` (`replyToId`)"
+ },
+ {
+ "name": "index_Post_repostId",
+ "unique": false,
+ "columnNames": [
+ "repostId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Post_repostId` ON `${TABLE_NAME}` (`repostId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "profilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "Post",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "replyToId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "Post",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "repostId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Profile",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`publicKey` TEXT NOT NULL, `userName` TEXT, `displayName` TEXT, `picture` TEXT, `banner` TEXT, `website` TEXT, `about` TEXT, `bot` INTEGER, `pronouns` TEXT, `nip05` TEXT, `domain` TEXT, `lud06` TEXT, `lud16` TEXT, `twitter` TEXT, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`publicKey`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userName",
+ "columnName": "userName",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "displayName",
+ "columnName": "displayName",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "picture",
+ "columnName": "picture",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "banner",
+ "columnName": "banner",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "website",
+ "columnName": "website",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "about",
+ "columnName": "about",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "bot",
+ "columnName": "bot",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "pronouns",
+ "columnName": "pronouns",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nip05",
+ "columnName": "nip05",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "domain",
+ "columnName": "domain",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "lud06",
+ "columnName": "lud06",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "lud16",
+ "columnName": "lud16",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "twitter",
+ "columnName": "twitter",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "publicKey"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Profile_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Profile_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "QuotedRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`quotingNostrEventId` TEXT NOT NULL, `quotedNostrEventId` TEXT NOT NULL, `quotedProfilePublicKey` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`quotingNostrEventId`, `quotedNostrEventId`), FOREIGN KEY(`quotedProfilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`quotingNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`quotedNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "quotingNostrEventId",
+ "columnName": "quotingNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "quotedNostrEventId",
+ "columnName": "quotedNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "quotedProfilePublicKey",
+ "columnName": "quotedProfilePublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "quotingNostrEventId",
+ "quotedNostrEventId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "quotedProfilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "quotingNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "quotedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Reaction",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `content` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `replyToId` TEXT NOT NULL, `profilePublicKey` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`profilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`replyToId`) REFERENCES `Post`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "replyToId",
+ "columnName": "replyToId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "profilePublicKey",
+ "columnName": "profilePublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Reaction_profilePublicKey",
+ "unique": false,
+ "columnNames": [
+ "profilePublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Reaction_profilePublicKey` ON `${TABLE_NAME}` (`profilePublicKey`)"
+ },
+ {
+ "name": "index_Reaction_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Reaction_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_Reaction_replyToId",
+ "unique": false,
+ "columnNames": [
+ "replyToId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Reaction_replyToId` ON `${TABLE_NAME}` (`replyToId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "profilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "Post",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "replyToId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "RecentSearch",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`query` TEXT NOT NULL, `synchronizationFilters` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`query`))",
+ "fields": [
+ {
+ "fieldPath": "query",
+ "columnName": "query",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "synchronizationFilters",
+ "columnName": "synchronizationFilters",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "query"
+ ]
+ }
+ },
+ {
+ "tableName": "Relay",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`publicKey` TEXT NOT NULL, `type` TEXT NOT NULL, `url` TEXT NOT NULL, `read` INTEGER NOT NULL, `write` INTEGER NOT NULL, PRIMARY KEY(`publicKey`, `type`, `url`))",
+ "fields": [
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "type",
+ "columnName": "type",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "url",
+ "columnName": "url",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "read",
+ "columnName": "read",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "write",
+ "columnName": "write",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "publicKey",
+ "type",
+ "url"
+ ]
+ }
+ },
+ {
+ "tableName": "RepostedRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`repostingNostrEventId` TEXT NOT NULL, `repostedNostrEventId` TEXT NOT NULL, `repostedProfilePublicKey` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`repostingNostrEventId`, `repostedNostrEventId`), FOREIGN KEY(`repostedProfilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`repostedNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`repostingNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "repostingNostrEventId",
+ "columnName": "repostingNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "repostedNostrEventId",
+ "columnName": "repostedNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "repostedProfilePublicKey",
+ "columnName": "repostedProfilePublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "repostingNostrEventId",
+ "repostedNostrEventId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "repostedProfilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "repostedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "repostingNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "SynchronizeNostrEventRequest",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `purpose` TEXT NOT NULL, `status` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `isRecommendedRelay` INTEGER NOT NULL, `level` INTEGER NOT NULL, `synchronizationFilters` TEXT NOT NULL, `ownerPublicKey` TEXT, `nostrEventId` TEXT, `unsignedNostrEventId` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`unsignedNostrEventId`) REFERENCES `UnsignedNostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "purpose",
+ "columnName": "purpose",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "status",
+ "columnName": "status",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isRecommendedRelay",
+ "columnName": "isRecommendedRelay",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "level",
+ "columnName": "level",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "synchronizationFilters",
+ "columnName": "synchronizationFilters",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ownerPublicKey",
+ "columnName": "ownerPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "unsignedNostrEventId",
+ "columnName": "unsignedNostrEventId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_SynchronizeNostrEventRequest_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_SynchronizeNostrEventRequest_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_SynchronizeNostrEventRequest_status",
+ "unique": false,
+ "columnNames": [
+ "status"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_SynchronizeNostrEventRequest_status` ON `${TABLE_NAME}` (`status`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "UnsignedNostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "unsignedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "SynchronizeNostrEventResult",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_SynchronizeNostrEventResult_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_SynchronizeNostrEventResult_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "UnsignedNostrEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `pubKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `privateTags` TEXT, `content` TEXT NOT NULL, `signedAt` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER)",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "pubKey",
+ "columnName": "pubKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "privateTags",
+ "columnName": "privateTags",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signedAt",
+ "columnName": "signedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_UnsignedNostrEvent_pubKey",
+ "unique": false,
+ "columnNames": [
+ "pubKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_UnsignedNostrEvent_pubKey` ON `${TABLE_NAME}` (`pubKey`)"
+ },
+ {
+ "name": "index_UnsignedNostrEvent_kind",
+ "unique": false,
+ "columnNames": [
+ "kind"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_UnsignedNostrEvent_kind` ON `${TABLE_NAME}` (`kind`)"
+ }
+ ]
+ },
+ {
+ "tableName": "Zap",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `postId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `receiverPublicKey` TEXT NOT NULL, `message` TEXT, `invoice` TEXT, `amountInMillisatoshis` INTEGER, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`senderPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`receiverPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`postId`) REFERENCES `Post`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "postId",
+ "columnName": "postId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receiverPublicKey",
+ "columnName": "receiverPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "message",
+ "columnName": "message",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "invoice",
+ "columnName": "invoice",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "amountInMillisatoshis",
+ "columnName": "amountInMillisatoshis",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Zap_senderPublicKey",
+ "unique": false,
+ "columnNames": [
+ "senderPublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Zap_senderPublicKey` ON `${TABLE_NAME}` (`senderPublicKey`)"
+ },
+ {
+ "name": "index_Zap_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Zap_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_Zap_postId",
+ "unique": false,
+ "columnNames": [
+ "postId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Zap_postId` ON `${TABLE_NAME}` (`postId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "senderPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "receiverPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "Post",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "postId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ }
+ ],
+ "setupQueries": [
+ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
+ "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3a8d838b225cf6371608e0f4900c6669')"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/composeApp/schemas/mobi.giza.compose.database.GizaDatabase/47.json b/composeApp/schemas/mobi.giza.compose.database.GizaDatabase/47.json
new file mode 100644
index 00000000..74bbbbc9
--- /dev/null
+++ b/composeApp/schemas/mobi.giza.compose.database.GizaDatabase/47.json
@@ -0,0 +1,7217 @@
+{
+ "formatVersion": 1,
+ "database": {
+ "version": 47,
+ "identityHash": "f999f93f24434e50c0425191e2bcccb5",
+ "entities": [
+ {
+ "tableName": "BroadcastNostrEventReceipt",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `nostrEventId` TEXT NOT NULL, `unsignedNostrEventId` INTEGER, `isAccepted` INTEGER NOT NULL, `isSync` INTEGER NOT NULL, `relayURL` TEXT NOT NULL, `messages` TEXT, FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`unsignedNostrEventId`) REFERENCES `UnsignedNostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "unsignedNostrEventId",
+ "columnName": "unsignedNostrEventId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "isAccepted",
+ "columnName": "isAccepted",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isSync",
+ "columnName": "isSync",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "messages",
+ "columnName": "messages",
+ "affinity": "TEXT"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_BroadcastNostrEventReceipt_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_BroadcastNostrEventReceipt_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_BroadcastNostrEventReceipt_isAccepted",
+ "unique": false,
+ "columnNames": [
+ "isAccepted"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_BroadcastNostrEventReceipt_isAccepted` ON `${TABLE_NAME}` (`isAccepted`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "UnsignedNostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "unsignedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "BroadcastNostrEventRequest",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `nostrEventId` TEXT NOT NULL, `unsignedNostrEventId` INTEGER, `status` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`unsignedNostrEventId`) REFERENCES `UnsignedNostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "unsignedNostrEventId",
+ "columnName": "unsignedNostrEventId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "status",
+ "columnName": "status",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_BroadcastNostrEventRequest_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_BroadcastNostrEventRequest_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_BroadcastNostrEventRequest_status",
+ "unique": false,
+ "columnNames": [
+ "status"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_BroadcastNostrEventRequest_status` ON `${TABLE_NAME}` (`status`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "UnsignedNostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "unsignedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Connection",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sourcePublicKey` TEXT NOT NULL, `destinationPublicKey` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`sourcePublicKey`, `destinationPublicKey`), FOREIGN KEY(`sourcePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`destinationPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sourcePublicKey",
+ "columnName": "sourcePublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "destinationPublicKey",
+ "columnName": "destinationPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sourcePublicKey",
+ "destinationPublicKey"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sourcePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "destinationPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `senderPublicKey` TEXT NOT NULL, `isUserMessage` INTEGER NOT NULL, `giftWrapPayloadId` TEXT, `marmotGroupEventId` TEXT, `marmotInnerEventId` TEXT, `chatRoomId` TEXT NOT NULL, `replyToMessageId` INTEGER, `quotedMessageId` INTEGER, `content` TEXT NOT NULL, `messageType` TEXT NOT NULL, `directMessageRecipientPublicKey` TEXT, `frostSigningSessionId` TEXT, `dkgSessionId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`giftWrapPayloadId`) REFERENCES `GiftWrapPayload`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`marmotGroupEventId`) REFERENCES `MarmotGroupEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`marmotInnerEventId`) REFERENCES `MarmotInnerEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isUserMessage",
+ "columnName": "isUserMessage",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "giftWrapPayloadId",
+ "columnName": "giftWrapPayloadId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "marmotGroupEventId",
+ "columnName": "marmotGroupEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "marmotInnerEventId",
+ "columnName": "marmotInnerEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "replyToMessageId",
+ "columnName": "replyToMessageId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "quotedMessageId",
+ "columnName": "quotedMessageId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "messageType",
+ "columnName": "messageType",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "directMessageRecipientPublicKey",
+ "columnName": "directMessageRecipientPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "frostSigningSessionId",
+ "columnName": "frostSigningSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ChatMessage_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ChatMessage_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "GiftWrapPayload",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "giftWrapPayloadId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "MarmotGroupEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "marmotGroupEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "MarmotInnerEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "marmotInnerEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatMessageBroadcastNostrEventRequestRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `chatMessageId` INTEGER NOT NULL, `broadcastNostrEventRequestId` INTEGER NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, FOREIGN KEY(`chatMessageId`) REFERENCES `ChatMessage`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`broadcastNostrEventRequestId`) REFERENCES `BroadcastNostrEventRequest`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatMessageId",
+ "columnName": "chatMessageId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "broadcastNostrEventRequestId",
+ "columnName": "broadcastNostrEventRequestId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatMessage",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatMessageId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "BroadcastNostrEventRequest",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "broadcastNostrEventRequestId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatMessageBroadcastNostrEventReceiptRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `chatMessageId` INTEGER NOT NULL, `broadcastNostrEventReceiptId` INTEGER NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, FOREIGN KEY(`chatMessageId`) REFERENCES `ChatMessage`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`broadcastNostrEventReceiptId`) REFERENCES `BroadcastNostrEventReceipt`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatMessageId",
+ "columnName": "chatMessageId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "broadcastNostrEventReceiptId",
+ "columnName": "broadcastNostrEventReceiptId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatMessage",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatMessageId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "BroadcastNostrEventReceipt",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "broadcastNostrEventReceiptId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatMessageNostrEventRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `chatMessageId` INTEGER NOT NULL, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, FOREIGN KEY(`chatMessageId`) REFERENCES `ChatMessage`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatMessageId",
+ "columnName": "chatMessageId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatMessage",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatMessageId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatRoom",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `subject` TEXT, `description` TEXT, `mlsGroupState` TEXT, `initialGiftWrapPayloadId` TEXT, `leftGroupAt` INTEGER, `joinedGroupAt` INTEGER, `chronicleRequestedAt` INTEGER, `parentChatRoomId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`userPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`initialGiftWrapPayloadId`) REFERENCES `GiftWrapPayload`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "subject",
+ "columnName": "subject",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "description",
+ "columnName": "description",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "mlsGroupState",
+ "columnName": "mlsGroupState",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "initialGiftWrapPayloadId",
+ "columnName": "initialGiftWrapPayloadId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "leftGroupAt",
+ "columnName": "leftGroupAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "joinedGroupAt",
+ "columnName": "joinedGroupAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "chronicleRequestedAt",
+ "columnName": "chronicleRequestedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "parentChatRoomId",
+ "columnName": "parentChatRoomId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "userPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "GiftWrapPayload",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "initialGiftWrapPayloadId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Confederation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `proposalId` TEXT NOT NULL, `ceremonyId` TEXT NOT NULL, `name` TEXT NOT NULL, `roster` TEXT NOT NULL, `keyState` TEXT NOT NULL, `genesis` TEXT NOT NULL, `configSeq` INTEGER NOT NULL, `rosterHash` TEXT NOT NULL, `keyStateHash` TEXT NOT NULL, `recoveryPackages` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`id`))",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "proposalId",
+ "columnName": "proposalId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ceremonyId",
+ "columnName": "ceremonyId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "name",
+ "columnName": "name",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "roster",
+ "columnName": "roster",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "keyState",
+ "columnName": "keyState",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "genesis",
+ "columnName": "genesis",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "configSeq",
+ "columnName": "configSeq",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "rosterHash",
+ "columnName": "rosterHash",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "keyStateHash",
+ "columnName": "keyStateHash",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "recoveryPackages",
+ "columnName": "recoveryPackages",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Confederation_proposalId",
+ "unique": false,
+ "columnNames": [
+ "proposalId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Confederation_proposalId` ON `${TABLE_NAME}` (`proposalId`)"
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationCeremony",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `proposalId` TEXT NOT NULL, `coordinatorPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `openingJson` TEXT NOT NULL, `stage` TEXT NOT NULL, `approvedAt` INTEGER, `dealerSeeds` TEXT, `recoveryNonces` TEXT, `keyState` TEXT, `transitionHash` TEXT, `genesis` TEXT, `recoveryPackages` TEXT, `confederationPublicKey` TEXT, `failureReason` TEXT, `culprit` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "proposalId",
+ "columnName": "proposalId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorPublicKey",
+ "columnName": "coordinatorPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "openingJson",
+ "columnName": "openingJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "approvedAt",
+ "columnName": "approvedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "dealerSeeds",
+ "columnName": "dealerSeeds",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recoveryNonces",
+ "columnName": "recoveryNonces",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "keyState",
+ "columnName": "keyState",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "transitionHash",
+ "columnName": "transitionHash",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "genesis",
+ "columnName": "genesis",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recoveryPackages",
+ "columnName": "recoveryPackages",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "confederationPublicKey",
+ "columnName": "confederationPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "culprit",
+ "columnName": "culprit",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ConfederationCeremony_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationCeremony_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_ConfederationCeremony_proposalId",
+ "unique": false,
+ "columnNames": [
+ "proposalId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationCeremony_proposalId` ON `${TABLE_NAME}` (`proposalId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationMember",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`confederationId` TEXT NOT NULL, `groupPublicKey` TEXT NOT NULL, PRIMARY KEY(`confederationId`, `groupPublicKey`))",
+ "fields": [
+ {
+ "fieldPath": "confederationId",
+ "columnName": "confederationId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "groupPublicKey",
+ "columnName": "groupPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "confederationId",
+ "groupPublicKey"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ConfederationMember_groupPublicKey",
+ "unique": false,
+ "columnNames": [
+ "groupPublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationMember_groupPublicKey` ON `${TABLE_NAME}` (`groupPublicKey`)"
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationSigningAttempt",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `confederationId` TEXT NOT NULL, `proposerPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `eventJson` TEXT NOT NULL, `stage` TEXT NOT NULL, `approvedAt` INTEGER, `declinedAt` INTEGER, `signedEventJson` TEXT, `failureReason` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`confederationId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "confederationId",
+ "columnName": "confederationId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "proposerPublicKey",
+ "columnName": "proposerPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "eventJson",
+ "columnName": "eventJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "approvedAt",
+ "columnName": "approvedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "declinedAt",
+ "columnName": "declinedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "signedEventJson",
+ "columnName": "signedEventJson",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ConfederationSigningAttempt_confederationId",
+ "unique": false,
+ "columnNames": [
+ "confederationId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationSigningAttempt_confederationId` ON `${TABLE_NAME}` (`confederationId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "confederationId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationSigningMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`attemptId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`attemptId`, `senderPublicKey`, `kind`), FOREIGN KEY(`attemptId`) REFERENCES `ConfederationSigningAttempt`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "attemptId",
+ "columnName": "attemptId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "attemptId",
+ "senderPublicKey",
+ "kind"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ConfederationSigningAttempt",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "attemptId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationCeremonyMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `senderPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `ConfederationCeremony`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "senderPublicKey",
+ "kind"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ConfederationCeremony",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `kind` INTEGER NOT NULL, `pubKey` TEXT NOT NULL, `proposalId` TEXT NOT NULL, `eventCreatedAt` INTEGER NOT NULL, `eventJson` TEXT NOT NULL, `receivedAt` INTEGER NOT NULL, `ownSessionId` TEXT, `publishedAt` INTEGER, PRIMARY KEY(`id`))",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "pubKey",
+ "columnName": "pubKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "proposalId",
+ "columnName": "proposalId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "eventCreatedAt",
+ "columnName": "eventCreatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "eventJson",
+ "columnName": "eventJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ownSessionId",
+ "columnName": "ownSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "publishedAt",
+ "columnName": "publishedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ConfederationEvent_proposalId",
+ "unique": false,
+ "columnNames": [
+ "proposalId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationEvent_proposalId` ON `${TABLE_NAME}` (`proposalId`)"
+ },
+ {
+ "name": "index_ConfederationEvent_kind",
+ "unique": false,
+ "columnNames": [
+ "kind"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationEvent_kind` ON `${TABLE_NAME}` (`kind`)"
+ },
+ {
+ "name": "index_ConfederationEvent_publishedAt",
+ "unique": false,
+ "columnNames": [
+ "publishedAt"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationEvent_publishedAt` ON `${TABLE_NAME}` (`publishedAt`)"
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationInvitee",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`proposalId` TEXT NOT NULL, `groupPublicKey` TEXT NOT NULL, PRIMARY KEY(`proposalId`, `groupPublicKey`))",
+ "fields": [
+ {
+ "fieldPath": "proposalId",
+ "columnName": "proposalId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "groupPublicKey",
+ "columnName": "groupPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "proposalId",
+ "groupPublicKey"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ConfederationInvitee_groupPublicKey",
+ "unique": false,
+ "columnNames": [
+ "groupPublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ConfederationInvitee_groupPublicKey` ON `${TABLE_NAME}` (`groupPublicKey`)"
+ }
+ ]
+ },
+ {
+ "tableName": "ConfederationSigning",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `sealSecret` TEXT, `proposalJson` TEXT, `refusal` TEXT, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`), FOREIGN KEY(`sessionId`) REFERENCES `FrostSigningSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "sealSecret",
+ "columnName": "sealSecret",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "proposalJson",
+ "columnName": "proposalJson",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "refusal",
+ "columnName": "refusal",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "FrostSigningSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "DkgParticipantMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `participantPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `participantPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `DkgSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKey",
+ "columnName": "participantPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "participantPublicKey",
+ "kind"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_DkgParticipantMessage_sessionId",
+ "unique": false,
+ "columnNames": [
+ "sessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_DkgParticipantMessage_sessionId` ON `${TABLE_NAME}` (`sessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "DkgSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "DkgSession",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `coordinatorPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `threshold` INTEGER NOT NULL, `participantCount` INTEGER NOT NULL, `participantPublicKeys` TEXT, `subject` TEXT, `walletPolicy` TEXT, `stage` TEXT NOT NULL, `hostPublicKey` TEXT NOT NULL, `round1Random` TEXT NOT NULL, `round2AuxRandom` TEXT NOT NULL, `coordinatorRound1` TEXT, `certificate` TEXT, `thresholdPublicKey` TEXT, `secretShare` TEXT, `publicShares` TEXT, `recoveryData` TEXT, `failureReason` TEXT, `hostKeyApprovedAt` INTEGER, `round1ApprovedAt` INTEGER, `round2ApprovedAt` INTEGER, `approvalRequestedThrough` TEXT, `parentChatRoomId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorPublicKey",
+ "columnName": "coordinatorPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "threshold",
+ "columnName": "threshold",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantCount",
+ "columnName": "participantCount",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKeys",
+ "columnName": "participantPublicKeys",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "subject",
+ "columnName": "subject",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "walletPolicy",
+ "columnName": "walletPolicy",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "hostPublicKey",
+ "columnName": "hostPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "round1Random",
+ "columnName": "round1Random",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "round2AuxRandom",
+ "columnName": "round2AuxRandom",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorRound1",
+ "columnName": "coordinatorRound1",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "certificate",
+ "columnName": "certificate",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "thresholdPublicKey",
+ "columnName": "thresholdPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "secretShare",
+ "columnName": "secretShare",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "publicShares",
+ "columnName": "publicShares",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recoveryData",
+ "columnName": "recoveryData",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "hostKeyApprovedAt",
+ "columnName": "hostKeyApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "round1ApprovedAt",
+ "columnName": "round1ApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "round2ApprovedAt",
+ "columnName": "round2ApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "approvalRequestedThrough",
+ "columnName": "approvalRequestedThrough",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "parentChatRoomId",
+ "columnName": "parentChatRoomId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_DkgSession_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_DkgSession_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "FrostSignerMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `signerPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `signerPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `FrostSigningSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signerPublicKey",
+ "columnName": "signerPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "signerPublicKey",
+ "kind"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_FrostSignerMessage_sessionId",
+ "unique": false,
+ "columnNames": [
+ "sessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_FrostSignerMessage_sessionId` ON `${TABLE_NAME}` (`sessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "FrostSigningSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "FrostSigningItem",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `itemIndex` INTEGER NOT NULL, `unsignedEventJson` TEXT NOT NULL, `eventId` TEXT NOT NULL, `nonceRandom` TEXT NOT NULL, `aggregatedNonce` TEXT, `signature` TEXT, PRIMARY KEY(`sessionId`, `itemIndex`), FOREIGN KEY(`sessionId`) REFERENCES `FrostSigningSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "itemIndex",
+ "columnName": "itemIndex",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "unsignedEventJson",
+ "columnName": "unsignedEventJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "eventId",
+ "columnName": "eventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nonceRandom",
+ "columnName": "nonceRandom",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "aggregatedNonce",
+ "columnName": "aggregatedNonce",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "itemIndex"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_FrostSigningItem_sessionId",
+ "unique": false,
+ "columnNames": [
+ "sessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_FrostSigningItem_sessionId` ON `${TABLE_NAME}` (`sessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "FrostSigningSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "FrostSigningSession",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `coordinatorPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `dkgSessionId` TEXT NOT NULL, `threshold` INTEGER NOT NULL, `participantCount` INTEGER NOT NULL, `signerId` INTEGER NOT NULL, `derivationPath` TEXT, `generation` INTEGER, `stage` TEXT NOT NULL, `signerIds` TEXT, `failureReason` TEXT, `signApprovedAt` INTEGER, `signDeclinedAt` INTEGER, `approvalRequestedAt` INTEGER, `resentAt` INTEGER, `subject` TEXT NOT NULL DEFAULT 'EVENTS', `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorPublicKey",
+ "columnName": "coordinatorPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "threshold",
+ "columnName": "threshold",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantCount",
+ "columnName": "participantCount",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signerId",
+ "columnName": "signerId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "derivationPath",
+ "columnName": "derivationPath",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signerIds",
+ "columnName": "signerIds",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "signApprovedAt",
+ "columnName": "signApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "signDeclinedAt",
+ "columnName": "signDeclinedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "approvalRequestedAt",
+ "columnName": "approvalRequestedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "resentAt",
+ "columnName": "resentAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "subject",
+ "columnName": "subject",
+ "affinity": "TEXT",
+ "notNull": true,
+ "defaultValue": "'EVENTS'"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_FrostSigningSession_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_FrostSigningSession_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_FrostSigningSession_dkgSessionId",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_FrostSigningSession_dkgSessionId` ON `${TABLE_NAME}` (`dkgSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GiftWrapMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `receiverPublicKey` TEXT NOT NULL, `receiverRelayHit` TEXT, `content` TEXT NOT NULL, `signature` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receiverPublicKey",
+ "columnName": "receiverPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receiverRelayHit",
+ "columnName": "receiverRelayHit",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GiftWrapSeal",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `signature` TEXT NOT NULL, `giftWrapMessageId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`giftWrapMessageId`) REFERENCES `GiftWrapMessage`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "giftWrapMessageId",
+ "columnName": "giftWrapMessageId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "GiftWrapMessage",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "giftWrapMessageId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GiftWrapPayload",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `quotedEventId` TEXT, `giftWrapSealId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`giftWrapSealId`) REFERENCES `GiftWrapSeal`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "quotedEventId",
+ "columnName": "quotedEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "giftWrapSealId",
+ "columnName": "giftWrapSealId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "GiftWrapSeal",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "giftWrapSealId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupConversationKey",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `peer` TEXT NOT NULL, `conversationKey` TEXT NOT NULL, `roundId` TEXT NOT NULL, `computedAt` INTEGER NOT NULL, PRIMARY KEY(`chatRoomId`, `peer`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "peer",
+ "columnName": "peer",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "conversationKey",
+ "columnName": "conversationKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "roundId",
+ "columnName": "roundId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "computedAt",
+ "columnName": "computedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId",
+ "peer"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupDmMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`rumorId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `conversationId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `rumorJson` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `outgoing` INTEGER NOT NULL, `wrapId` TEXT, `signingSessionId` TEXT, `readAt` INTEGER, `filedAt` INTEGER NOT NULL, PRIMARY KEY(`rumorId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "rumorId",
+ "columnName": "rumorId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "conversationId",
+ "columnName": "conversationId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "rumorJson",
+ "columnName": "rumorJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "outgoing",
+ "columnName": "outgoing",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "wrapId",
+ "columnName": "wrapId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "signingSessionId",
+ "columnName": "signingSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "readAt",
+ "columnName": "readAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "filedAt",
+ "columnName": "filedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "rumorId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupDmMessage_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupDmMessage_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GroupDmMessage_conversationId",
+ "unique": false,
+ "columnNames": [
+ "conversationId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupDmMessage_conversationId` ON `${TABLE_NAME}` (`conversationId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupDmOutbound",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`signingSessionId` TEXT NOT NULL, `sealId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `recipient` TEXT NOT NULL, `relays` TEXT NOT NULL, `wrapJson` TEXT, `publishedAt` INTEGER, `attempts` INTEGER NOT NULL, `nextAttemptAt` INTEGER, PRIMARY KEY(`signingSessionId`, `sealId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "signingSessionId",
+ "columnName": "signingSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "sealId",
+ "columnName": "sealId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "recipient",
+ "columnName": "recipient",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relays",
+ "columnName": "relays",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "wrapJson",
+ "columnName": "wrapJson",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "publishedAt",
+ "columnName": "publishedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "attempts",
+ "columnName": "attempts",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nextAttemptAt",
+ "columnName": "nextAttemptAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "signingSessionId",
+ "sealId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupDmOutbound_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupDmOutbound_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupDmWrap",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `wrapJson` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `state` TEXT NOT NULL, `sealJson` TEXT, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "wrapJson",
+ "columnName": "wrapJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "state",
+ "columnName": "state",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "sealJson",
+ "columnName": "sealJson",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupDmWrap_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupDmWrap_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GroupDmWrap_state",
+ "unique": false,
+ "columnNames": [
+ "state"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupDmWrap_state` ON `${TABLE_NAME}` (`state`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupEcdhPartial",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`roundId` TEXT NOT NULL, `participantId` INTEGER NOT NULL, `senderPublicKey` TEXT NOT NULL, `partial` TEXT NOT NULL, `proof` TEXT NOT NULL, `verified` INTEGER NOT NULL, `blamedAt` INTEGER, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`roundId`, `participantId`), FOREIGN KEY(`roundId`) REFERENCES `GroupEcdhRound`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "roundId",
+ "columnName": "roundId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantId",
+ "columnName": "participantId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "partial",
+ "columnName": "partial",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "proof",
+ "columnName": "proof",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "verified",
+ "columnName": "verified",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "blamedAt",
+ "columnName": "blamedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "roundId",
+ "participantId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "GroupEcdhRound",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "roundId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupEcdhRound",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `generation` INTEGER NOT NULL, `point` TEXT NOT NULL, `purpose` TEXT NOT NULL, `ref` TEXT, `evidenceJson` TEXT, `state` TEXT NOT NULL, `partialSentAt` INTEGER, `openedAt` INTEGER NOT NULL, `combinedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "point",
+ "columnName": "point",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "purpose",
+ "columnName": "purpose",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ref",
+ "columnName": "ref",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "evidenceJson",
+ "columnName": "evidenceJson",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "state",
+ "columnName": "state",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "partialSentAt",
+ "columnName": "partialSentAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "openedAt",
+ "columnName": "openedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "combinedAt",
+ "columnName": "combinedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupEcdhRound_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupEcdhRound_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GroupEcdhRound_point",
+ "unique": false,
+ "columnNames": [
+ "point"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupEcdhRound_point` ON `${TABLE_NAME}` (`point`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupInboxMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `rumorId` TEXT NOT NULL, `wrapId` TEXT, `conversationId` TEXT NOT NULL, `participants` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `rumorJson` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `generation` INTEGER NOT NULL, `outgoing` INTEGER NOT NULL, `signingSessionId` TEXT, `readAt` INTEGER, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`chatRoomId`, `rumorId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "rumorId",
+ "columnName": "rumorId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "wrapId",
+ "columnName": "wrapId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "conversationId",
+ "columnName": "conversationId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participants",
+ "columnName": "participants",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "rumorJson",
+ "columnName": "rumorJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "outgoing",
+ "columnName": "outgoing",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signingSessionId",
+ "columnName": "signingSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "readAt",
+ "columnName": "readAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId",
+ "rumorId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupInboxMessage_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupInboxMessage_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GroupInboxMessage_conversationId",
+ "unique": false,
+ "columnNames": [
+ "conversationId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupInboxMessage_conversationId` ON `${TABLE_NAME}` (`conversationId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupInboxPublication",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`eventId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `kind` INTEGER NOT NULL, `eventJson` TEXT NOT NULL, `relays` TEXT NOT NULL, `signingSessionId` TEXT, `recipientPublicKey` TEXT, `attempts` INTEGER NOT NULL, `nextAttemptAt` INTEGER, `publishedAt` INTEGER, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`eventId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "eventId",
+ "columnName": "eventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "eventJson",
+ "columnName": "eventJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relays",
+ "columnName": "relays",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signingSessionId",
+ "columnName": "signingSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recipientPublicKey",
+ "columnName": "recipientPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "attempts",
+ "columnName": "attempts",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nextAttemptAt",
+ "columnName": "nextAttemptAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "publishedAt",
+ "columnName": "publishedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "eventId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupInboxPublication_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupInboxPublication_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GroupInboxPublication_signingSessionId",
+ "unique": false,
+ "columnNames": [
+ "signingSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupInboxPublication_signingSessionId` ON `${TABLE_NAME}` (`signingSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupInboxWrap",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `wrapJson` TEXT NOT NULL, `wrapCreatedAt` INTEGER NOT NULL, `openedGeneration` INTEGER, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "wrapJson",
+ "columnName": "wrapJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "wrapCreatedAt",
+ "columnName": "wrapCreatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "openedGeneration",
+ "columnName": "openedGeneration",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupInboxWrap_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupInboxWrap_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupKeyState",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `dkgSessionId` TEXT NOT NULL, `thresholdPublicKey` TEXT NOT NULL, `derivationPath` TEXT NOT NULL, `announcedBy` TEXT NOT NULL, `announcedAt` INTEGER NOT NULL, `parentChatRoomId` TEXT, `birthCertificateJson` TEXT, `generation` INTEGER, `publicSharesHash` TEXT, `memberBindings` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`chatRoomId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "thresholdPublicKey",
+ "columnName": "thresholdPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "derivationPath",
+ "columnName": "derivationPath",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "announcedBy",
+ "columnName": "announcedBy",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "announcedAt",
+ "columnName": "announcedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "parentChatRoomId",
+ "columnName": "parentChatRoomId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "birthCertificateJson",
+ "columnName": "birthCertificateJson",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "publicSharesHash",
+ "columnName": "publicSharesHash",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "memberBindings",
+ "columnName": "memberBindings",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupKeyState_dkgSessionId",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupKeyState_dkgSessionId` ON `${TABLE_NAME}` (`dkgSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupSignedEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `signature` TEXT NOT NULL, `derivationPath` TEXT, `frostSigningSessionId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "derivationPath",
+ "columnName": "derivationPath",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "frostSigningSessionId",
+ "columnName": "frostSigningSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupSignedEvent_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupSignedEvent_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GroupSignedEvent_kind",
+ "unique": false,
+ "columnNames": [
+ "kind"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupSignedEvent_kind` ON `${TABLE_NAME}` (`kind`)"
+ },
+ {
+ "name": "index_GroupSignedEvent_frostSigningSessionId",
+ "unique": false,
+ "columnNames": [
+ "frostSigningSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupSignedEvent_frostSigningSessionId` ON `${TABLE_NAME}` (`frostSigningSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "InboxKey",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `generation` INTEGER NOT NULL, `publicKey` TEXT NOT NULL, `secretKey` TEXT, `recoveryData` TEXT, `ceremonyId` TEXT NOT NULL, `state` TEXT NOT NULL, `announcementEventId` TEXT, `createdAt` INTEGER NOT NULL, `announcedAt` INTEGER, `wipedAt` INTEGER, PRIMARY KEY(`chatRoomId`, `userPublicKey`, `generation`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "secretKey",
+ "columnName": "secretKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recoveryData",
+ "columnName": "recoveryData",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "ceremonyId",
+ "columnName": "ceremonyId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "state",
+ "columnName": "state",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "announcementEventId",
+ "columnName": "announcementEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "announcedAt",
+ "columnName": "announcedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "wipedAt",
+ "columnName": "wipedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId",
+ "userPublicKey",
+ "generation"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_InboxKey_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_InboxKey_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "InboxKeyCeremony",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `generation` INTEGER NOT NULL, `coordinatorPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `participantPublicKeys` TEXT NOT NULL, `stage` TEXT NOT NULL, `hostPublicKey` TEXT, `round1Random` TEXT, `round2AuxRandom` TEXT, `announceRelays` TEXT, `inboxPublicKey` TEXT, `failureReason` TEXT, `culprit` TEXT, `lastMessageAt` INTEGER NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorPublicKey",
+ "columnName": "coordinatorPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKeys",
+ "columnName": "participantPublicKeys",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "hostPublicKey",
+ "columnName": "hostPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "round1Random",
+ "columnName": "round1Random",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "round2AuxRandom",
+ "columnName": "round2AuxRandom",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "announceRelays",
+ "columnName": "announceRelays",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inboxPublicKey",
+ "columnName": "inboxPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "culprit",
+ "columnName": "culprit",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "lastMessageAt",
+ "columnName": "lastMessageAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_InboxKeyCeremony_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_InboxKeyCeremony_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "InboxKeyCeremonyMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `receivedAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `senderPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `InboxKeyCeremony`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receivedAt",
+ "columnName": "receivedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "senderPublicKey",
+ "kind"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "InboxKeyCeremony",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "InboxSigning",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `manifest` TEXT, `refusal` TEXT, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "manifest",
+ "columnName": "manifest",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "refusal",
+ "columnName": "refusal",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_InboxSigning_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_InboxSigning_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "KeyShareGeneration",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`dkgSessionId` TEXT NOT NULL, `generation` INTEGER NOT NULL, `secretShare` TEXT, `publicShares` TEXT NOT NULL, `state` TEXT NOT NULL, `refreshSessionId` TEXT, `recoveryData` TEXT, `activatedAt` INTEGER, `wipedAt` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`dkgSessionId`, `generation`), FOREIGN KEY(`dkgSessionId`) REFERENCES `DkgSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "secretShare",
+ "columnName": "secretShare",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "publicShares",
+ "columnName": "publicShares",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "state",
+ "columnName": "state",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "refreshSessionId",
+ "columnName": "refreshSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recoveryData",
+ "columnName": "recoveryData",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "activatedAt",
+ "columnName": "activatedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "wipedAt",
+ "columnName": "wipedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "dkgSessionId",
+ "generation"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_KeyShareGeneration_dkgSessionId",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_KeyShareGeneration_dkgSessionId` ON `${TABLE_NAME}` (`dkgSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "DkgSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "dkgSessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "KeyShareMember",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`dkgSessionId` TEXT NOT NULL, `generation` INTEGER NOT NULL, `participantId` INTEGER NOT NULL, `memberPublicKey` TEXT NOT NULL, `hostPublicKey` TEXT NOT NULL, `standing` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`dkgSessionId`, `generation`, `participantId`), FOREIGN KEY(`dkgSessionId`, `generation`) REFERENCES `KeyShareGeneration`(`dkgSessionId`, `generation`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantId",
+ "columnName": "participantId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "memberPublicKey",
+ "columnName": "memberPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "hostPublicKey",
+ "columnName": "hostPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "standing",
+ "columnName": "standing",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "dkgSessionId",
+ "generation",
+ "participantId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_KeyShareMember_dkgSessionId_generation",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId",
+ "generation"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_KeyShareMember_dkgSessionId_generation` ON `${TABLE_NAME}` (`dkgSessionId`, `generation`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "KeyShareGeneration",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "dkgSessionId",
+ "generation"
+ ],
+ "referencedColumns": [
+ "dkgSessionId",
+ "generation"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ShareRefreshConfirmation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`dkgSessionId` TEXT NOT NULL, `baseGeneration` INTEGER NOT NULL, `refreshSessionId` TEXT NOT NULL, `confirmedAt` INTEGER NOT NULL, PRIMARY KEY(`dkgSessionId`, `baseGeneration`))",
+ "fields": [
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "baseGeneration",
+ "columnName": "baseGeneration",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "refreshSessionId",
+ "columnName": "refreshSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "confirmedAt",
+ "columnName": "confirmedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "dkgSessionId",
+ "baseGeneration"
+ ]
+ }
+ },
+ {
+ "tableName": "ShareRefreshMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `participantPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `participantPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `ShareRefreshSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKey",
+ "columnName": "participantPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "participantPublicKey",
+ "kind"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ShareRefreshSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ShareRefreshSession",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `dkgSessionId` TEXT NOT NULL, `coordinatorPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `baseGeneration` INTEGER NOT NULL, `recipientIds` TEXT NOT NULL, `withheld` TEXT, `stage` TEXT NOT NULL, `round1Random` TEXT NOT NULL, `auxRandom` TEXT NOT NULL, `dealApprovedAt` INTEGER, `confirmApprovedAt` INTEGER, `approvalRequestedThrough` TEXT, `coordinatorRound1` TEXT, `certificate` TEXT, `failureReason` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorPublicKey",
+ "columnName": "coordinatorPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "baseGeneration",
+ "columnName": "baseGeneration",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "recipientIds",
+ "columnName": "recipientIds",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "withheld",
+ "columnName": "withheld",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "round1Random",
+ "columnName": "round1Random",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "auxRandom",
+ "columnName": "auxRandom",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dealApprovedAt",
+ "columnName": "dealApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "confirmApprovedAt",
+ "columnName": "confirmApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "approvalRequestedThrough",
+ "columnName": "approvalRequestedThrough",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "coordinatorRound1",
+ "columnName": "coordinatorRound1",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "certificate",
+ "columnName": "certificate",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ShareRefreshSession_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ShareRefreshSession_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_ShareRefreshSession_dkgSessionId",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ShareRefreshSession_dkgSessionId` ON `${TABLE_NAME}` (`dkgSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ShareRepairMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `recipientPublicKey` TEXT NOT NULL, `payload` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `senderPublicKey`, `kind`, `recipientPublicKey`), FOREIGN KEY(`sessionId`) REFERENCES `ShareRepairSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "recipientPublicKey",
+ "columnName": "recipientPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "senderPublicKey",
+ "kind",
+ "recipientPublicKey"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ShareRepairSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ShareRepairSession",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `dkgSessionId` TEXT NOT NULL, `generation` INTEGER NOT NULL, `targetId` INTEGER NOT NULL, `targetPublicKey` TEXT NOT NULL, `targetHostPublicKey` TEXT NOT NULL, `helperIds` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `stage` TEXT NOT NULL, `sessionRandom` TEXT NOT NULL, `helpApprovedAt` INTEGER, `approvalRequested` INTEGER NOT NULL, `failureReason` TEXT, `nParticipants` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "generation",
+ "columnName": "generation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "targetId",
+ "columnName": "targetId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "targetPublicKey",
+ "columnName": "targetPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "targetHostPublicKey",
+ "columnName": "targetHostPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "helperIds",
+ "columnName": "helperIds",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "sessionRandom",
+ "columnName": "sessionRandom",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "helpApprovedAt",
+ "columnName": "helpApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "approvalRequested",
+ "columnName": "approvalRequested",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nParticipants",
+ "columnName": "nParticipants",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ShareRepairSession_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ShareRepairSession_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_ShareRepairSession_dkgSessionId",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ShareRepairSession_dkgSessionId` ON `${TABLE_NAME}` (`dkgSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GovernanceProposal",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `routingId` TEXT NOT NULL, `epoch` INTEGER NOT NULL, `frostSigningSessionId` TEXT NOT NULL, `commitEventId` TEXT NOT NULL, `commitEventJson` TEXT NOT NULL, `peerKeyPackageEventId` TEXT, `priorStateHex` TEXT NOT NULL, `pendingStateHex` TEXT NOT NULL, `stage` TEXT NOT NULL, `thenRotateWithout` TEXT, `promotionOfferId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "routingId",
+ "columnName": "routingId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "epoch",
+ "columnName": "epoch",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "frostSigningSessionId",
+ "columnName": "frostSigningSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "commitEventId",
+ "columnName": "commitEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "commitEventJson",
+ "columnName": "commitEventJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "peerKeyPackageEventId",
+ "columnName": "peerKeyPackageEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "priorStateHex",
+ "columnName": "priorStateHex",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "pendingStateHex",
+ "columnName": "pendingStateHex",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "thenRotateWithout",
+ "columnName": "thenRotateWithout",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "promotionOfferId",
+ "columnName": "promotionOfferId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GovernanceProposal_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GovernanceProposal_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GovernanceProposal_frostSigningSessionId",
+ "unique": false,
+ "columnNames": [
+ "frostSigningSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GovernanceProposal_frostSigningSessionId` ON `${TABLE_NAME}` (`frostSigningSessionId`)"
+ },
+ {
+ "name": "index_GovernanceProposal_commitEventId",
+ "unique": false,
+ "columnNames": [
+ "commitEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GovernanceProposal_commitEventId` ON `${TABLE_NAME}` (`commitEventId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "InReplyToRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`replyingNostrEventId` TEXT NOT NULL, `inReplyToNostrEventId` TEXT NOT NULL, `inReplyToProfilePublicKey` TEXT, `inReplyToRootNostrEventId` TEXT, `inReplyToRootProfilePublicKey` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`replyingNostrEventId`, `inReplyToNostrEventId`), FOREIGN KEY(`inReplyToProfilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`inReplyToRootProfilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`replyingNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`inReplyToNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`inReplyToRootNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "replyingNostrEventId",
+ "columnName": "replyingNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "inReplyToNostrEventId",
+ "columnName": "inReplyToNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "inReplyToProfilePublicKey",
+ "columnName": "inReplyToProfilePublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToRootNostrEventId",
+ "columnName": "inReplyToRootNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToRootProfilePublicKey",
+ "columnName": "inReplyToRootProfilePublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "replyingNostrEventId",
+ "inReplyToNostrEventId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "inReplyToProfilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "inReplyToRootProfilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "replyingNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "inReplyToNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "inReplyToRootNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotCommitResult",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `peerKeyPackageEventId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `isOneMemberInitialGroupCreation` INTEGER NOT NULL, `commitBytes` BLOB NOT NULL, `welcomeBytes` BLOB, `groupInfoBytes` BLOB, `framedCommitBytes` BLOB NOT NULL, `preCommitExporterSecret` BLOB NOT NULL, `obligationId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`))",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "peerKeyPackageEventId",
+ "columnName": "peerKeyPackageEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isOneMemberInitialGroupCreation",
+ "columnName": "isOneMemberInitialGroupCreation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "commitBytes",
+ "columnName": "commitBytes",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "welcomeBytes",
+ "columnName": "welcomeBytes",
+ "affinity": "BLOB"
+ },
+ {
+ "fieldPath": "groupInfoBytes",
+ "columnName": "groupInfoBytes",
+ "affinity": "BLOB"
+ },
+ {
+ "fieldPath": "framedCommitBytes",
+ "columnName": "framedCommitBytes",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "preCommitExporterSecret",
+ "columnName": "preCommitExporterSecret",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "obligationId",
+ "columnName": "obligationId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ }
+ },
+ {
+ "tableName": "MarmotGroupEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `signature` TEXT NOT NULL, `encryptedContent` TEXT NOT NULL, `expiresAt` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`id`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "encryptedContent",
+ "columnName": "encryptedContent",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "expiresAt",
+ "columnName": "expiresAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "id"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotInnerEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `quotedEventId` TEXT, `marmotGroupEventId` TEXT, `directMessageRecipientPublicKey` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`marmotGroupEventId`) REFERENCES `MarmotGroupEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "quotedEventId",
+ "columnName": "quotedEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "marmotGroupEventId",
+ "columnName": "marmotGroupEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "directMessageRecipientPublicKey",
+ "columnName": "directMessageRecipientPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "MarmotGroupEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "marmotGroupEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotKeyPackage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `tlsEncodedMarmotKeyPackage` BLOB NOT NULL, `profile` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`publicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tlsEncodedMarmotKeyPackage",
+ "columnName": "tlsEncodedMarmotKeyPackage",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "profile",
+ "columnName": "profile",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "publicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotKeyPackageBundle",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `tlsEncodedMarmotKeyPackage` BLOB NOT NULL, `ncryptsecInitPrivateKey` TEXT NOT NULL, `ncryptsecEncryptionPrivateKey` TEXT NOT NULL, `ncryptsecSignaturePrivateKey` TEXT NOT NULL, `consumed` INTEGER NOT NULL, `rotated` INTEGER NOT NULL, `profile` TEXT, `dTag` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`))",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tlsEncodedMarmotKeyPackage",
+ "columnName": "tlsEncodedMarmotKeyPackage",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ncryptsecInitPrivateKey",
+ "columnName": "ncryptsecInitPrivateKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ncryptsecEncryptionPrivateKey",
+ "columnName": "ncryptsecEncryptionPrivateKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ncryptsecSignaturePrivateKey",
+ "columnName": "ncryptsecSignaturePrivateKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "consumed",
+ "columnName": "consumed",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "rotated",
+ "columnName": "rotated",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "profile",
+ "columnName": "profile",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "dTag",
+ "columnName": "dTag",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_MarmotKeyPackageBundle_publicKey",
+ "unique": false,
+ "columnNames": [
+ "publicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_MarmotKeyPackageBundle_publicKey` ON `${TABLE_NAME}` (`publicKey`)"
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotRouting",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`routingId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `activeFromEpoch` INTEGER NOT NULL, `retiredAtEpoch` INTEGER, PRIMARY KEY(`routingId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "routingId",
+ "columnName": "routingId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "activeFromEpoch",
+ "columnName": "activeFromEpoch",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "retiredAtEpoch",
+ "columnName": "retiredAtEpoch",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "routingId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_MarmotRouting_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_MarmotRouting_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotPublishObligation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`obligationId` TEXT NOT NULL, `bytes` BLOB NOT NULL, PRIMARY KEY(`obligationId`))",
+ "fields": [
+ {
+ "fieldPath": "obligationId",
+ "columnName": "obligationId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "bytes",
+ "columnName": "bytes",
+ "affinity": "BLOB",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "obligationId"
+ ]
+ }
+ },
+ {
+ "tableName": "MarmotOutboundGate",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`groupId` TEXT NOT NULL, `gate` TEXT NOT NULL, PRIMARY KEY(`groupId`))",
+ "fields": [
+ {
+ "fieldPath": "groupId",
+ "columnName": "groupId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "gate",
+ "columnName": "gate",
+ "affinity": "TEXT",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "groupId"
+ ]
+ }
+ },
+ {
+ "tableName": "MarmotRetainedEpochSecret",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `epoch` INTEGER NOT NULL, `senderDataSecret` BLOB NOT NULL, `encryptionSecret` BLOB NOT NULL, `leafCount` INTEGER NOT NULL, `exporterSecret` BLOB NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`chatRoomId`, `epoch`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "epoch",
+ "columnName": "epoch",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderDataSecret",
+ "columnName": "senderDataSecret",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "encryptionSecret",
+ "columnName": "encryptionSecret",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "leafCount",
+ "columnName": "leafCount",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "exporterSecret",
+ "columnName": "exporterSecret",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId",
+ "epoch"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotSenderRatchet",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `epoch` INTEGER NOT NULL, `leafIndex` INTEGER NOT NULL, `applicationGeneration` INTEGER NOT NULL, `record` BLOB NOT NULL, PRIMARY KEY(`chatRoomId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "epoch",
+ "columnName": "epoch",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "leafIndex",
+ "columnName": "leafIndex",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "applicationGeneration",
+ "columnName": "applicationGeneration",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "record",
+ "columnName": "record",
+ "affinity": "BLOB",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Mention",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `mentionedPublicKey` TEXT NOT NULL, `mentioningNostrEventId` TEXT, `relayUrl` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, FOREIGN KEY(`mentionedPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`mentioningNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "mentionedPublicKey",
+ "columnName": "mentionedPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "mentioningNostrEventId",
+ "columnName": "mentioningNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "relayUrl",
+ "columnName": "relayUrl",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "mentionedPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "mentioningNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "NegentropySynchronizeRequest",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `uuid` TEXT NOT NULL, `purpose` TEXT NOT NULL, `status` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `isRecommendedRelay` INTEGER NOT NULL, `level` INTEGER NOT NULL, `synchronizationFilter` TEXT NOT NULL, `ownerPublicKey` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "uuid",
+ "columnName": "uuid",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "purpose",
+ "columnName": "purpose",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "status",
+ "columnName": "status",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isRecommendedRelay",
+ "columnName": "isRecommendedRelay",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "level",
+ "columnName": "level",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "synchronizationFilter",
+ "columnName": "synchronizationFilter",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ownerPublicKey",
+ "columnName": "ownerPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_NegentropySynchronizeRequest_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NegentropySynchronizeRequest_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_NegentropySynchronizeRequest_status",
+ "unique": false,
+ "columnNames": [
+ "status"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NegentropySynchronizeRequest_status` ON `${TABLE_NAME}` (`status`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "NegentropySynchronizeResult",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `status` TEXT NOT NULL, `negentropySynchronizeRequestId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`negentropySynchronizeRequestId`) REFERENCES `SynchronizeNostrEventResult`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "status",
+ "columnName": "status",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "negentropySynchronizeRequestId",
+ "columnName": "negentropySynchronizeRequestId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "SynchronizeNostrEventResult",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "negentropySynchronizeRequestId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "NostrEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `pubKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `sig` TEXT NOT NULL, `relayUrl` TEXT, `quotedNostrEventId` TEXT, `quotedAuthorPublicKey` TEXT, `inReplyToNostrEventId` TEXT, `inReplyToAuthorPublicKey` TEXT, `inReplyToRootNostrEventId` TEXT, `inReplyToRootAuthorPublicKey` TEXT, `repostedNostrEventId` TEXT, `repostedAuthorPublicKey` TEXT, `unsignedNostrEventId` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`))",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "pubKey",
+ "columnName": "pubKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "sig",
+ "columnName": "sig",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayUrl",
+ "columnName": "relayUrl",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "quotedNostrEventId",
+ "columnName": "quotedNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "quotedAuthorPublicKey",
+ "columnName": "quotedAuthorPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToNostrEventId",
+ "columnName": "inReplyToNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToAuthorPublicKey",
+ "columnName": "inReplyToAuthorPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToRootNostrEventId",
+ "columnName": "inReplyToRootNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToRootAuthorPublicKey",
+ "columnName": "inReplyToRootAuthorPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "repostedNostrEventId",
+ "columnName": "repostedNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "repostedAuthorPublicKey",
+ "columnName": "repostedAuthorPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "unsignedNostrEventId",
+ "columnName": "unsignedNostrEventId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_NostrEvent_kind",
+ "unique": false,
+ "columnNames": [
+ "kind"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_kind` ON `${TABLE_NAME}` (`kind`)"
+ },
+ {
+ "name": "index_NostrEvent_pubKey",
+ "unique": false,
+ "columnNames": [
+ "pubKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_pubKey` ON `${TABLE_NAME}` (`pubKey`)"
+ },
+ {
+ "name": "index_NostrEvent_quotedNostrEventId",
+ "unique": false,
+ "columnNames": [
+ "quotedNostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_quotedNostrEventId` ON `${TABLE_NAME}` (`quotedNostrEventId`)"
+ },
+ {
+ "name": "index_NostrEvent_inReplyToNostrEventId",
+ "unique": false,
+ "columnNames": [
+ "inReplyToNostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_inReplyToNostrEventId` ON `${TABLE_NAME}` (`inReplyToNostrEventId`)"
+ },
+ {
+ "name": "index_NostrEvent_inReplyToRootNostrEventId",
+ "unique": false,
+ "columnNames": [
+ "inReplyToRootNostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_inReplyToRootNostrEventId` ON `${TABLE_NAME}` (`inReplyToRootNostrEventId`)"
+ }
+ ]
+ },
+ {
+ "tableName": "NostrEventRelay",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`relayURL` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`nostrEventId`, `relayURL`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "nostrEventId",
+ "relayURL"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_NostrEventRelay_relayURL",
+ "unique": false,
+ "columnNames": [
+ "relayURL"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEventRelay_relayURL` ON `${TABLE_NAME}` (`relayURL`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Participant",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `participantPublicKey` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `adminAt` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, FOREIGN KEY(`participantPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKey",
+ "columnName": "participantPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayHint",
+ "columnName": "relayHint",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "adminAt",
+ "columnName": "adminAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "participantPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Post",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `repostId` TEXT, `quote` TEXT, `content` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `replyToId` TEXT, `profilePublicKey` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`profilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`replyToId`) REFERENCES `Post`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`repostId`) REFERENCES `Post`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "repostId",
+ "columnName": "repostId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "quote",
+ "columnName": "quote",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "replyToId",
+ "columnName": "replyToId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "profilePublicKey",
+ "columnName": "profilePublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Post_profilePublicKey",
+ "unique": false,
+ "columnNames": [
+ "profilePublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Post_profilePublicKey` ON `${TABLE_NAME}` (`profilePublicKey`)"
+ },
+ {
+ "name": "index_Post_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Post_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_Post_replyToId",
+ "unique": false,
+ "columnNames": [
+ "replyToId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Post_replyToId` ON `${TABLE_NAME}` (`replyToId`)"
+ },
+ {
+ "name": "index_Post_repostId",
+ "unique": false,
+ "columnNames": [
+ "repostId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Post_repostId` ON `${TABLE_NAME}` (`repostId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "profilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "Post",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "replyToId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "Post",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "repostId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Profile",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`publicKey` TEXT NOT NULL, `userName` TEXT, `displayName` TEXT, `picture` TEXT, `banner` TEXT, `website` TEXT, `about` TEXT, `bot` INTEGER, `pronouns` TEXT, `nip05` TEXT, `domain` TEXT, `lud06` TEXT, `lud16` TEXT, `twitter` TEXT, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`publicKey`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userName",
+ "columnName": "userName",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "displayName",
+ "columnName": "displayName",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "picture",
+ "columnName": "picture",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "banner",
+ "columnName": "banner",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "website",
+ "columnName": "website",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "about",
+ "columnName": "about",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "bot",
+ "columnName": "bot",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "pronouns",
+ "columnName": "pronouns",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nip05",
+ "columnName": "nip05",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "domain",
+ "columnName": "domain",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "lud06",
+ "columnName": "lud06",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "lud16",
+ "columnName": "lud16",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "twitter",
+ "columnName": "twitter",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "publicKey"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Profile_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Profile_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "QuotedRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`quotingNostrEventId` TEXT NOT NULL, `quotedNostrEventId` TEXT NOT NULL, `quotedProfilePublicKey` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`quotingNostrEventId`, `quotedNostrEventId`), FOREIGN KEY(`quotedProfilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`quotingNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`quotedNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "quotingNostrEventId",
+ "columnName": "quotingNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "quotedNostrEventId",
+ "columnName": "quotedNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "quotedProfilePublicKey",
+ "columnName": "quotedProfilePublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "quotingNostrEventId",
+ "quotedNostrEventId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "quotedProfilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "quotingNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "quotedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Reaction",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `content` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `replyToId` TEXT NOT NULL, `profilePublicKey` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`profilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`replyToId`) REFERENCES `Post`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "replyToId",
+ "columnName": "replyToId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "profilePublicKey",
+ "columnName": "profilePublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Reaction_profilePublicKey",
+ "unique": false,
+ "columnNames": [
+ "profilePublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Reaction_profilePublicKey` ON `${TABLE_NAME}` (`profilePublicKey`)"
+ },
+ {
+ "name": "index_Reaction_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Reaction_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_Reaction_replyToId",
+ "unique": false,
+ "columnNames": [
+ "replyToId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Reaction_replyToId` ON `${TABLE_NAME}` (`replyToId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "profilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "Post",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "replyToId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "RecentSearch",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`query` TEXT NOT NULL, `synchronizationFilters` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`query`))",
+ "fields": [
+ {
+ "fieldPath": "query",
+ "columnName": "query",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "synchronizationFilters",
+ "columnName": "synchronizationFilters",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "query"
+ ]
+ }
+ },
+ {
+ "tableName": "Relay",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`publicKey` TEXT NOT NULL, `type` TEXT NOT NULL, `url` TEXT NOT NULL, `read` INTEGER NOT NULL, `write` INTEGER NOT NULL, PRIMARY KEY(`publicKey`, `type`, `url`))",
+ "fields": [
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "type",
+ "columnName": "type",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "url",
+ "columnName": "url",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "read",
+ "columnName": "read",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "write",
+ "columnName": "write",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "publicKey",
+ "type",
+ "url"
+ ]
+ }
+ },
+ {
+ "tableName": "RepostedRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`repostingNostrEventId` TEXT NOT NULL, `repostedNostrEventId` TEXT NOT NULL, `repostedProfilePublicKey` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`repostingNostrEventId`, `repostedNostrEventId`), FOREIGN KEY(`repostedProfilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`repostedNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`repostingNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "repostingNostrEventId",
+ "columnName": "repostingNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "repostedNostrEventId",
+ "columnName": "repostedNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "repostedProfilePublicKey",
+ "columnName": "repostedProfilePublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "repostingNostrEventId",
+ "repostedNostrEventId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "repostedProfilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "repostedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "repostingNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "SynchronizeNostrEventRequest",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `purpose` TEXT NOT NULL, `status` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `isRecommendedRelay` INTEGER NOT NULL, `level` INTEGER NOT NULL, `synchronizationFilters` TEXT NOT NULL, `ownerPublicKey` TEXT, `nostrEventId` TEXT, `unsignedNostrEventId` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`unsignedNostrEventId`) REFERENCES `UnsignedNostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "purpose",
+ "columnName": "purpose",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "status",
+ "columnName": "status",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isRecommendedRelay",
+ "columnName": "isRecommendedRelay",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "level",
+ "columnName": "level",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "synchronizationFilters",
+ "columnName": "synchronizationFilters",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ownerPublicKey",
+ "columnName": "ownerPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "unsignedNostrEventId",
+ "columnName": "unsignedNostrEventId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_SynchronizeNostrEventRequest_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_SynchronizeNostrEventRequest_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_SynchronizeNostrEventRequest_status",
+ "unique": false,
+ "columnNames": [
+ "status"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_SynchronizeNostrEventRequest_status` ON `${TABLE_NAME}` (`status`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "UnsignedNostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "unsignedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "SynchronizeNostrEventResult",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_SynchronizeNostrEventResult_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_SynchronizeNostrEventResult_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "UnsignedNostrEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `pubKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `privateTags` TEXT, `content` TEXT NOT NULL, `signedAt` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER)",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "pubKey",
+ "columnName": "pubKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "privateTags",
+ "columnName": "privateTags",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signedAt",
+ "columnName": "signedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_UnsignedNostrEvent_pubKey",
+ "unique": false,
+ "columnNames": [
+ "pubKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_UnsignedNostrEvent_pubKey` ON `${TABLE_NAME}` (`pubKey`)"
+ },
+ {
+ "name": "index_UnsignedNostrEvent_kind",
+ "unique": false,
+ "columnNames": [
+ "kind"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_UnsignedNostrEvent_kind` ON `${TABLE_NAME}` (`kind`)"
+ }
+ ]
+ },
+ {
+ "tableName": "Zap",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `postId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `receiverPublicKey` TEXT NOT NULL, `message` TEXT, `invoice` TEXT, `amountInMillisatoshis` INTEGER, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`senderPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`receiverPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`postId`) REFERENCES `Post`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "postId",
+ "columnName": "postId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receiverPublicKey",
+ "columnName": "receiverPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "message",
+ "columnName": "message",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "invoice",
+ "columnName": "invoice",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "amountInMillisatoshis",
+ "columnName": "amountInMillisatoshis",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Zap_senderPublicKey",
+ "unique": false,
+ "columnNames": [
+ "senderPublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Zap_senderPublicKey` ON `${TABLE_NAME}` (`senderPublicKey`)"
+ },
+ {
+ "name": "index_Zap_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Zap_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_Zap_postId",
+ "unique": false,
+ "columnNames": [
+ "postId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Zap_postId` ON `${TABLE_NAME}` (`postId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "senderPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "receiverPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "Post",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "postId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ }
+ ],
+ "setupQueries": [
+ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
+ "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f999f93f24434e50c0425191e2bcccb5')"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml
index c7e5814d..4bb0e818 100644
--- a/composeApp/src/commonMain/composeResources/values/strings.xml
+++ b/composeApp/src/commonMain/composeResources/values/strings.xml
@@ -740,6 +740,60 @@
%1$s: %2$d of %3$d admins to sign
Formed
This is the room of the confederation %1$s. Its key is held by the admins of its groups together. Until the confederation can sign, who is in this room cannot change.
+ The confederation's signature
+ Approve
+ Decline
+ Signed by %1$d admins of %2$d groups together, once enough of them approve. You approve for every group you are an admin of.
+ The confederation signed it
+ The confederation did not sign it: %1$s
+ You declined this
+ Approved
+ Declined
+ This device holds no such request for the confederation to sign
+ Propose the charter
+ The charter is the confederation's public statement of the groups it is made of, signed with its own key. It is how members who are not admins hear of it.
+
+ Inbox
+ Inbox settings
+ No new messages
+ 1 new message
+ %1$d new messages
+ Set up an inbox
+ Let anyone on nostr write to the group privately
+ The admins are making the group's inbox key
+ Couldn't find the group
+ Nobody has written to the group yet.
+ Messages sent before you held the group's inbox key aren't on this device.
+ 1 message this device can't open
+ %1$d messages this device can't open
+ It was sent to the group's npub by an app that doesn't know the group's inbox key, or to a key from before you were an admin.
+ The group hasn't signed its inbox announcement yet, so nobody can write to it.
+ The group
+ The group: %1$s
+ %1$s and the group
+ The group's admins will make a key together. Every admin holds it and can read what arrives. Nobody can write to the group until it signs its announcement, and the group signs every reply.
+ Where mail should arrive
+ One relay per line, starting wss://
+ Key %1$d, %2$s
+ Announced: anyone can write to it
+ Waiting for the group to sign its announcement
+ Retired, kept to open older mail
+ Mail arrives on %1$s
+ Waiting on %1$s
+ Rotate the inbox key
+ Makes a new key with the current admins. Mail sent to the old key can still be read by the admins who held it, and a removed admin keeps what they already read.
+ Couldn't start the ceremony
+ The inbox key ceremony started
+ None of those is a relay a stranger could reach
+ Reply as the group
+ Ask the group to sign this reply
+ The group's quorum has to sign this before it is sent. It goes out in the group's name, not yours, and can't be taken back once signed.
+ %1$s has announced no inbox key, so their app may not be able to open a message from a group.
+ Couldn't ask the group to sign this reply.
+ Not yet on a relay
+ Send again
+ Sent again
+ The group's admins have changed since this key was made. It changes on its own once an admin's device starts a new ceremony, or you can rotate it now.
Open the group's messages
Nobody can write to the group yet
@@ -757,7 +811,6 @@
Ask the group to sign
Couldn't ask the group to sign where it receives messages.
Only a current admin holding a share can open the group's messages.
- Nobody has written to the group yet
1 message being opened
%1$d messages being opened
Waiting for 1 more admin to open this
@@ -765,7 +818,6 @@
Not yet answered by %1$s
%1$d more are queued: the group was sent more than its admins open in an hour
A message this screen can't show yet
- The group
Signed, not yet sent
Sent
Signed but not sent
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ExperimentalFeatures.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ExperimentalFeatures.kt
index ee1e7a89..a35bef31 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ExperimentalFeatures.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ExperimentalFeatures.kt
@@ -40,6 +40,19 @@ object ExperimentalFeatures {
*/
val groupDirectMessages: Boolean
get() = groupDirectMessagesOverride ?: isDevelopmentBuild()
+
+ /** Set by a test that has to see the build a release would be. */
+ var groupInboxOverride: Boolean? = null
+
+ /**
+ * A group that can be written to privately (docs/group-inbox.md): an inbox key its admins
+ * make together and the group announces, the messages sent to it, and replies the quorum
+ * signs. Off in a release while NIP-4E is a draft: off, the app offers no inbox, starts no
+ * ceremony and listens for nothing. A device still declines, out loud, an inbox
+ * announcement or a reply it finds wrong -- that is a refusal, not a feature.
+ */
+ val groupInbox: Boolean
+ get() = groupInboxOverride ?: isDevelopmentBuild()
}
/** Whether this is a debug or development build of the app, rather than a release. */
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/GizaDatabase.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/GizaDatabase.kt
index c5b6d278..6885736e 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/GizaDatabase.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/GizaDatabase.kt
@@ -26,6 +26,8 @@ import mobi.giza.compose.database.dao.GiftWrapSealDao
import mobi.giza.compose.database.dao.GroupDmDao
import mobi.giza.compose.database.dao.GroupKeyStateDao
import mobi.giza.compose.database.dao.GroupSignedEventDao
+import mobi.giza.compose.database.dao.GroupInboxDao
+import mobi.giza.compose.database.dao.InboxKeyDao
import mobi.giza.compose.database.dao.InReplyToRelationDao
import mobi.giza.compose.database.dao.KeyShareDao
import mobi.giza.compose.database.dao.ShareRefreshDao
@@ -76,6 +78,8 @@ import mobi.giza.compose.database.model.GroupEcdhPartial
import mobi.giza.compose.database.model.GroupEcdhRound
import mobi.giza.compose.database.model.ConfederationCeremony
import mobi.giza.compose.database.model.ConfederationMember
+import mobi.giza.compose.database.model.ConfederationSigningAttempt
+import mobi.giza.compose.database.model.ConfederationSigningMessage
import mobi.giza.compose.database.model.ConfederationCeremonyMessage
import mobi.giza.compose.database.model.ConfederationEvent
import mobi.giza.compose.database.model.ConfederationInvitee
@@ -119,6 +123,13 @@ import mobi.giza.compose.database.model.Reaction
import mobi.giza.compose.database.model.RecentSearch
import mobi.giza.compose.database.model.DkgParticipantMessage
import mobi.giza.compose.database.model.DkgSession
+import mobi.giza.compose.database.model.GroupInboxMessage
+import mobi.giza.compose.database.model.GroupInboxPublication
+import mobi.giza.compose.database.model.GroupInboxWrap
+import mobi.giza.compose.database.model.InboxKey
+import mobi.giza.compose.database.model.InboxKeyCeremony
+import mobi.giza.compose.database.model.InboxKeyCeremonyMessage
+import mobi.giza.compose.database.model.InboxSigning
import mobi.giza.compose.database.model.FrostSignerMessage
import mobi.giza.compose.database.model.FrostSigningItem
import mobi.giza.compose.database.model.FrostSigningSession
@@ -145,6 +156,8 @@ val GENESIS_AT = Instant.fromEpochMilliseconds(1231006505000L)
Confederation::class,
ConfederationCeremony::class,
ConfederationMember::class,
+ ConfederationSigningAttempt::class,
+ ConfederationSigningMessage::class,
ConfederationCeremonyMessage::class,
ConfederationEvent::class,
ConfederationInvitee::class,
@@ -163,8 +176,15 @@ val GENESIS_AT = Instant.fromEpochMilliseconds(1231006505000L)
GroupDmWrap::class,
GroupEcdhPartial::class,
GroupEcdhRound::class,
+ GroupInboxMessage::class,
+ GroupInboxPublication::class,
+ GroupInboxWrap::class,
GroupKeyState::class,
GroupSignedEvent::class,
+ InboxKey::class,
+ InboxKeyCeremony::class,
+ InboxKeyCeremonyMessage::class,
+ InboxSigning::class,
KeyShareGeneration::class,
KeyShareMember::class,
ShareRefreshConfirmation::class,
@@ -202,7 +222,7 @@ val GENESIS_AT = Instant.fromEpochMilliseconds(1231006505000L)
UnsignedNostrEvent::class,
Zap::class
],
- version = 45,
+ version = 47,
autoMigrations = [
// v2 only adds the DkgSession/DkgParticipantMessage tables, so Room can
// generate the migration itself — nothing existing changes shape.
@@ -474,10 +494,18 @@ val GENESIS_AT = Instant.fromEpochMilliseconds(1231006505000L)
// Phases 11 and 12): ConfederationCeremony, ConfederationCeremonyMessage, Confederation
// and ConfederationMember. New tables only, so Room generates it.
AutoMigration(from = 43, to = 44),
- // v45 adds a group's direct messages (docs/group-threshold-ecdh.md, Phase 4):
- // GroupEcdhRound, GroupEcdhPartial, GroupConversationKey, GroupDmWrap, GroupDmMessage
- // and GroupDmOutbound. New tables only, so Room generates it.
+ // v45 adds the confederation signing as itself (docs/confederation.md, Phase 14):
+ // ConfederationSigningAttempt and ConfederationSigningMessage. New tables only.
AutoMigration(from = 44, to = 45),
+ // v46 adds the group's inbox (docs/group-inbox.md, Phase 3): InboxKeyCeremony,
+ // InboxKeyCeremonyMessage and InboxKey, kept apart from DkgSession so no signing path
+ // can find a threshold-1 key, and GroupInboxWrap, GroupInboxMessage and
+ // GroupInboxPublication, and InboxSigning (Phase 5). New tables only, so Room generates it.
+ AutoMigration(from = 45, to = 46),
+ // v47 adds a group's direct messages by threshold ECDH (docs/group-threshold-ecdh.md,
+ // Phase 4): GroupEcdhRound, GroupEcdhPartial, GroupConversationKey, GroupDmWrap,
+ // GroupDmMessage and GroupDmOutbound. New tables only, so Room generates it.
+ AutoMigration(from = 46, to = 47),
]
)
@ConstructedBy(GizaDatabaseConstructor::class)
@@ -525,6 +553,10 @@ abstract class GizaDatabase: RoomDatabase() {
abstract fun groupSignedEventDao(): GroupSignedEventDao
+ abstract fun inboxKeyDao(): InboxKeyDao
+
+ abstract fun groupInboxDao(): GroupInboxDao
+
abstract fun connectionDao(): ConnectionDao
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/ConfederationCeremonyDao.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/ConfederationCeremonyDao.kt
index 31ac7f8a..f2466cec 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/ConfederationCeremonyDao.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/ConfederationCeremonyDao.kt
@@ -62,4 +62,31 @@ interface ConfederationCeremonyDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insertMembers(members: List)
+
+ @Query("SELECT * FROM ConfederationSigningAttempt WHERE id = :id")
+ suspend fun getAttempt(id: String): mobi.giza.compose.database.model.ConfederationSigningAttempt?
+
+ @Query("SELECT * FROM ConfederationSigningAttempt WHERE id = :id")
+ fun observeAttempt(id: String): Flow
+
+ @Query("SELECT * FROM ConfederationSigningAttempt WHERE confederationId = :confederationId ORDER BY createdAt DESC")
+ fun observeAttempts(confederationId: HexKey): Flow>
+
+ @Query("SELECT * FROM ConfederationSigningAttempt WHERE userPublicKey = :userPublicKey AND stage NOT IN ('COMPLETE', 'FAILED')")
+ suspend fun getRunningAttempts(userPublicKey: HexKey): List
+
+ @Upsert
+ suspend fun upsertAttempt(attempt: mobi.giza.compose.database.model.ConfederationSigningAttempt)
+
+ @Query("SELECT * FROM ConfederationSigningMessage WHERE attemptId = :attemptId AND senderPublicKey = :sender AND kind = :kind")
+ suspend fun getSigningMessage(attemptId: String, sender: HexKey, kind: Kind): mobi.giza.compose.database.model.ConfederationSigningMessage?
+
+ @Query("SELECT * FROM ConfederationSigningMessage WHERE attemptId = :attemptId")
+ suspend fun getSigningMessages(attemptId: String): List
+
+ @Query("SELECT * FROM ConfederationSigningMessage WHERE attemptId = :attemptId")
+ fun observeSigningMessages(attemptId: String): Flow>
+
+ @Insert(onConflict = OnConflictStrategy.IGNORE)
+ suspend fun insertSigningMessage(message: mobi.giza.compose.database.model.ConfederationSigningMessage): Long
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/GroupInboxDao.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/GroupInboxDao.kt
new file mode 100644
index 00000000..7d96f30b
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/GroupInboxDao.kt
@@ -0,0 +1,106 @@
+package mobi.giza.compose.database.dao
+
+import androidx.room3.Dao
+import androidx.room3.Insert
+import androidx.room3.OnConflictStrategy
+import androidx.room3.Query
+import androidx.room3.Upsert
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import kotlinx.coroutines.flow.Flow
+import mobi.giza.compose.database.model.GroupInboxMessage
+import mobi.giza.compose.database.model.GroupInboxPublication
+import mobi.giza.compose.database.model.GroupInboxWrap
+import kotlin.time.Instant
+
+/** What a group's inbox has received, filed and owes relays (docs/group-inbox.md, Phase 3). */
+@Dao
+interface GroupInboxDao {
+ /** The ledger is keyed by the wrap's id: a second copy of one changes nothing. */
+ @Insert(onConflict = OnConflictStrategy.IGNORE)
+ suspend fun insertWrap(wrap: GroupInboxWrap): Long
+
+ @Query("SELECT * FROM GroupInboxWrap WHERE id = :id")
+ suspend fun getWrap(id: HexKey): GroupInboxWrap?
+
+ @Query("SELECT * FROM GroupInboxWrap WHERE chatRoomId = :chatRoomId AND openedGeneration IS NULL ORDER BY receivedAt")
+ suspend fun getUnopenedWraps(chatRoomId: String): List
+
+ /**
+ * Wraps no inbox key opened, less those the admins opened by threshold ECDH instead
+ * (docs/group-threshold-ecdh.md): those are in the group's messages, not unread mail.
+ */
+ @Query(
+ "SELECT COUNT(*) FROM GroupInboxWrap WHERE chatRoomId = :chatRoomId AND openedGeneration IS NULL " +
+ "AND id NOT IN (SELECT id FROM GroupDmWrap WHERE state = 'OPENED')"
+ )
+ fun observeUnopenedCount(chatRoomId: String): Flow
+
+ /** The newest wrap's own time in a room: where a catch-up starts, less NIP-59's two days. */
+ @Query("SELECT MAX(wrapCreatedAt) FROM GroupInboxWrap WHERE chatRoomId = :chatRoomId")
+ suspend fun newestWrapCreatedAt(chatRoomId: String): Long?
+
+ @Query("UPDATE GroupInboxWrap SET openedGeneration = :generation WHERE id = :id")
+ suspend fun markOpened(id: HexKey, generation: Int)
+
+ /** Keyed by room and rumor: two wraps of one rumor are one message, and the first is kept. */
+ @Insert(onConflict = OnConflictStrategy.IGNORE)
+ suspend fun insertMessage(message: GroupInboxMessage): Long
+
+ @Query("SELECT * FROM GroupInboxMessage WHERE chatRoomId = :chatRoomId AND rumorId = :rumorId")
+ suspend fun getMessage(chatRoomId: String, rumorId: HexKey): GroupInboxMessage?
+
+ @Query("SELECT * FROM GroupInboxMessage WHERE chatRoomId = :chatRoomId ORDER BY createdAt DESC")
+ fun observeMessages(chatRoomId: String): Flow>
+
+ @Query("SELECT * FROM GroupInboxMessage WHERE chatRoomId = :chatRoomId ORDER BY createdAt DESC")
+ suspend fun getMessages(chatRoomId: String): List
+
+ @Query("SELECT * FROM GroupInboxMessage WHERE chatRoomId = :chatRoomId AND conversationId = :conversationId ORDER BY createdAt ASC")
+ fun observeConversation(chatRoomId: String, conversationId: String): Flow>
+
+ @Query("SELECT * FROM GroupInboxMessage WHERE chatRoomId = :chatRoomId AND conversationId = :conversationId ORDER BY createdAt ASC")
+ suspend fun getConversation(chatRoomId: String, conversationId: String): List
+
+ @Query("SELECT COUNT(*) FROM GroupInboxMessage WHERE chatRoomId = :chatRoomId AND outgoing = 0 AND readAt IS NULL")
+ fun observeUnreadCount(chatRoomId: String): Flow
+
+ @Query("UPDATE GroupInboxMessage SET readAt = :at WHERE chatRoomId = :chatRoomId AND conversationId = :conversationId AND readAt IS NULL")
+ suspend fun markConversationRead(chatRoomId: String, conversationId: String, at: Instant)
+
+ @Query("DELETE FROM GroupInboxMessage WHERE chatRoomId = :chatRoomId")
+ suspend fun deleteMessages(chatRoomId: String)
+
+ @Query("DELETE FROM GroupInboxWrap WHERE chatRoomId = :chatRoomId")
+ suspend fun deleteWraps(chatRoomId: String)
+
+ @Upsert
+ suspend fun upsertPublication(publication: GroupInboxPublication)
+
+ @Query("SELECT * FROM GroupInboxPublication WHERE eventId = :eventId")
+ suspend fun getPublication(eventId: HexKey): GroupInboxPublication?
+
+ /** What is still owed and due by [now], oldest first. */
+ @Query("SELECT * FROM GroupInboxPublication WHERE publishedAt IS NULL AND (nextAttemptAt IS NULL OR nextAttemptAt <= :now) ORDER BY createdAt")
+ suspend fun getDuePublications(now: Instant): List
+
+ @Query("SELECT * FROM GroupInboxPublication WHERE signingSessionId = :signingSessionId")
+ suspend fun getPublicationsFor(signingSessionId: String): List
+
+ @Query("SELECT * FROM GroupInboxPublication WHERE publishedAt IS NULL ORDER BY createdAt")
+ fun observeUnpublished(): Flow>
+
+ @Query("UPDATE GroupInboxPublication SET publishedAt = :at WHERE eventId = :eventId")
+ suspend fun markPublished(eventId: HexKey, at: Instant)
+
+ @Query("UPDATE GroupInboxPublication SET attempts = attempts + 1, nextAttemptAt = :next WHERE eventId = :eventId")
+ suspend fun markAttempted(eventId: HexKey, next: Instant)
+
+ @Upsert
+ suspend fun upsertSigning(signing: mobi.giza.compose.database.model.InboxSigning)
+
+ @Query("SELECT * FROM InboxSigning WHERE sessionId = :sessionId")
+ suspend fun getSigning(sessionId: String): mobi.giza.compose.database.model.InboxSigning?
+
+ @Query("SELECT * FROM GroupInboxPublication WHERE signingSessionId = :signingSessionId")
+ fun observePublicationsFor(signingSessionId: String): Flow>
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/InboxKeyDao.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/InboxKeyDao.kt
new file mode 100644
index 00000000..4880c7b8
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/InboxKeyDao.kt
@@ -0,0 +1,86 @@
+package mobi.giza.compose.database.dao
+
+import androidx.room3.Dao
+import androidx.room3.Insert
+import androidx.room3.OnConflictStrategy
+import androidx.room3.Query
+import androidx.room3.Upsert
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.Kind
+import kotlinx.coroutines.flow.Flow
+import mobi.giza.compose.database.model.InboxKey
+import mobi.giza.compose.database.model.InboxKeyCeremony
+import mobi.giza.compose.database.model.InboxKeyCeremonyMessage
+import kotlin.time.Instant
+
+/** The group inbox's key ceremonies and the keys they leave (docs/group-inbox.md, Phase 3). */
+@Dao
+interface InboxKeyDao {
+ @Query("SELECT * FROM InboxKeyCeremony WHERE id = :id")
+ suspend fun getCeremony(id: String): InboxKeyCeremony?
+
+ @Query("SELECT * FROM InboxKeyCeremony WHERE id = :id")
+ fun observeCeremony(id: String): Flow
+
+ @Query("SELECT * FROM InboxKeyCeremony WHERE chatRoomId = :chatRoomId AND userPublicKey = :userPublicKey ORDER BY createdAt DESC LIMIT 1")
+ suspend fun getLatestCeremony(chatRoomId: String, userPublicKey: HexKey): InboxKeyCeremony?
+
+ @Query("SELECT * FROM InboxKeyCeremony WHERE chatRoomId = :chatRoomId AND userPublicKey = :userPublicKey ORDER BY createdAt DESC LIMIT 1")
+ fun observeLatestCeremony(chatRoomId: String, userPublicKey: HexKey): Flow
+
+ @Query("SELECT * FROM InboxKeyCeremony WHERE userPublicKey = :userPublicKey AND stage NOT IN ('COMPLETE', 'FAILED')")
+ suspend fun getRunningCeremonies(userPublicKey: HexKey): List
+
+ @Query("SELECT * FROM InboxKeyCeremony WHERE chatRoomId = :chatRoomId AND stage NOT IN ('COMPLETE', 'FAILED')")
+ suspend fun getRunningCeremoniesIn(chatRoomId: String): List
+
+ /** Every finished ceremony in a room as this identity saw it, newest generation first. */
+ @Query("SELECT * FROM InboxKeyCeremony WHERE chatRoomId = :chatRoomId AND userPublicKey = :userPublicKey AND stage = 'COMPLETE' ORDER BY generation DESC, createdAt DESC")
+ suspend fun getCompletedCeremonies(chatRoomId: String, userPublicKey: HexKey): List
+
+ @Upsert
+ suspend fun upsertCeremony(ceremony: InboxKeyCeremony)
+
+ @Query("SELECT * FROM InboxKeyCeremonyMessage WHERE sessionId = :sessionId")
+ suspend fun getMessages(sessionId: String): List
+
+ @Query("SELECT * FROM InboxKeyCeremonyMessage WHERE sessionId = :sessionId")
+ fun observeMessages(sessionId: String): Flow>
+
+ @Query("SELECT * FROM InboxKeyCeremonyMessage WHERE sessionId = :sessionId AND senderPublicKey = :sender AND kind = :kind")
+ suspend fun getMessage(sessionId: String, sender: HexKey, kind: Kind): InboxKeyCeremonyMessage?
+
+ /** Ignores a second copy: relays redeliver, and the first one a ceremony read is the one it used. */
+ @Insert(onConflict = OnConflictStrategy.IGNORE)
+ suspend fun insertMessage(message: InboxKeyCeremonyMessage): Long
+
+ @Query("SELECT * FROM InboxKey WHERE chatRoomId = :chatRoomId AND userPublicKey = :userPublicKey ORDER BY generation DESC")
+ suspend fun getKeys(chatRoomId: String, userPublicKey: HexKey): List
+
+ @Query("SELECT * FROM InboxKey WHERE chatRoomId = :chatRoomId AND userPublicKey = :userPublicKey ORDER BY generation DESC")
+ fun observeKeys(chatRoomId: String, userPublicKey: HexKey): Flow>
+
+ @Query("SELECT * FROM InboxKey WHERE chatRoomId = :chatRoomId AND userPublicKey = :userPublicKey AND generation = :generation")
+ suspend fun getKey(chatRoomId: String, userPublicKey: HexKey, generation: Int): InboxKey?
+
+ /** Every key this identity can still open mail with, in every room, newest generation first. */
+ @Query("SELECT * FROM InboxKey WHERE userPublicKey = :userPublicKey AND secretKey IS NOT NULL ORDER BY chatRoomId, generation DESC")
+ suspend fun getHeldKeys(userPublicKey: HexKey): List
+
+ @Query("SELECT * FROM InboxKey WHERE userPublicKey = :userPublicKey AND secretKey IS NOT NULL ORDER BY chatRoomId, generation DESC")
+ fun observeHeldKeys(userPublicKey: HexKey): Flow>
+
+ /** Any key a 10044 could name in this room, held here or not: [publicKey] is public. */
+ @Query("SELECT * FROM InboxKey WHERE chatRoomId = :chatRoomId AND publicKey = :publicKey LIMIT 1")
+ suspend fun findByPublicKey(chatRoomId: String, publicKey: HexKey): InboxKey?
+
+ /** The room an inbox key belongs to, for a wrap tagged with the key rather than the group. */
+ @Query("SELECT * FROM InboxKey WHERE userPublicKey = :userPublicKey AND publicKey = :publicKey LIMIT 1")
+ suspend fun findHeldByPublicKey(userPublicKey: HexKey, publicKey: HexKey): InboxKey?
+
+ @Upsert
+ suspend fun upsertKey(key: InboxKey)
+
+ @Query("UPDATE InboxKey SET secretKey = NULL, recoveryData = NULL, state = 'WIPED', wipedAt = :at WHERE chatRoomId = :chatRoomId AND userPublicKey = :userPublicKey")
+ suspend fun wipeKeys(chatRoomId: String, userPublicKey: HexKey, at: Instant)
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NostrDao.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NostrDao.kt
index 34607898..1cd27d48 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NostrDao.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NostrDao.kt
@@ -88,6 +88,10 @@ import mobi.giza.compose.nostr.Relays
import mobi.giza.compose.nostr.dkg.DkgRitualEvents
import mobi.giza.compose.nostr.confederation.ConfederationRitualEvents
import mobi.giza.compose.managers.ConfederationRitualManager
+import mobi.giza.compose.managers.ConfederationSigningManager
+import mobi.giza.compose.nostr.confederation.ConfederationSigningEvents
+import mobi.giza.compose.managers.InboxKeyRitualManager
+import mobi.giza.compose.nostr.inbox.InboxKeyRitualEvents
import mobi.giza.compose.ExperimentalFeatures
import mobi.giza.compose.nostr.frost.ShareRefreshEvents
import mobi.giza.compose.nostr.frost.ShareRepairEvents
@@ -1687,6 +1691,20 @@ abstract class NostrDao(
Event.fromJsonOrNull(groupEventResult.innerEventJson)
?.let { innerEvent ->
when {
+ // The confederation signing as itself, in its own room.
+ // docs/confederation.md, Phase 14.
+ ConfederationSigningEvents.isSigningKind(innerEvent.kind) -> {
+ if (ExperimentalFeatures.confederation) {
+ ConfederationSigningManager.process(
+ database = database,
+ localChatRoom = localChatRoom,
+ innerEvent = innerEvent,
+ userPublicKey = activeKeyPair.pubKey.toHex(),
+ nostrPrivateKey = activeKeyPair.privKey!!,
+ )
+ }
+ }
+
FrostSigningEvents.isFrostSigningKind(innerEvent.kind) ->
FrostSigningManager.processSigningPayload(
database = database,
@@ -1716,6 +1734,21 @@ abstract class NostrDao(
nostrPrivateKey = activeKeyPair.privKey!!
)
+ // The group's inbox key, made by its admins in the group's own
+ // room (docs/group-inbox.md, D3). Off with the feature: a release
+ // build takes no part in a ceremony for a key it would not use.
+ InboxKeyRitualEvents.isInboxKeyKind(innerEvent.kind) -> {
+ if (ExperimentalFeatures.groupInbox) {
+ InboxKeyRitualManager.process(
+ database = database,
+ localChatRoom = localChatRoom,
+ innerEvent = innerEvent,
+ userPublicKey = activeKeyPair.pubKey.toHex(),
+ nostrPrivateKey = activeKeyPair.privKey!!
+ )
+ }
+ }
+
// And a repair, in the same room (Phase 10).
ShareRepairEvents.isShareRepairKind(innerEvent.kind) ->
ShareRepairManager.processRepairPayload(
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatMessage.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatMessage.kt
index 650181a5..a9ce48f0 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatMessage.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatMessage.kt
@@ -4,6 +4,9 @@ import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
import mobi.giza.compose.nostr.GroupNostrProfile
import mobi.giza.compose.nostr.RetiredKinds
import mobi.giza.compose.nostr.confederation.ConfederationKinds
+import mobi.giza.compose.nostr.confederation.ConfederationSigningEvents
+import mobi.giza.compose.nostr.inbox.InboxAnnouncement
+import mobi.giza.compose.nostr.inbox.InboxKeyRitualEvents
import androidx.room3.Entity
import androidx.room3.ForeignKey
@@ -45,7 +48,6 @@ import mobi.giza.compose.nostr.frost.GovernanceEvents
import mobi.giza.compose.nostr.frost.ShareRefreshEvents
import mobi.giza.compose.nostr.frost.ShareRepairEvents
import mobi.giza.compose.nostr.groupdm.GroupEcdhEvents
-import mobi.giza.compose.managers.GroupDmRelays
import mobi.giza.compose.nostr.frost.FrostSigningEvents
import mobi.giza.compose.nostr.frost.GroupKeyStateEvent
import mobi.giza.compose.nostr.subgroup.SubgroupBirthCertificateEvent
@@ -521,12 +523,6 @@ data class ChatMessage(
*/
private const val TYPE_LEGACY_GROUP_RELAYS_SIGNED = "groupRelaysSigned"
- /**
- * The group signed where it receives direct messages: the first time, its decision
- * to receive them at all. docs/group-threshold-ecdh.md, D8.
- */
- const val TYPE_GROUP_DM_RELAYS_SIGNED = "groupDmRelaysSigned"
-
/**
* This device forgot the group's direct messages on seeing its member removed as an
* admin. docs/group-threshold-ecdh.md, D14.
@@ -558,6 +554,10 @@ data class ChatMessage(
/** A group's room, on its admins' devices: the group is now part of a formed confederation (Phase 12). */
const val TYPE_CONFEDERATION_FORMED = "confederationFormed"
+ /** The confederation's room: a proposal for it to sign, and one that did not finish (Phase 14). */
+ const val TYPE_CONFEDERATION_SIGNING_PROPOSED = "confederationSigningProposed"
+ const val TYPE_CONFEDERATION_SIGNING_FAILED = "confederationSigningFailed"
+
val CONFEDERATION_TYPES = setOf(
TYPE_CONFEDERATION_PROPOSED,
TYPE_CONFEDERATION_ACCEPTED,
@@ -567,18 +567,46 @@ data class ChatMessage(
TYPE_CONFEDERATION_CEREMONY_COMPLETE,
TYPE_CONFEDERATION_CEREMONY_FAILED,
TYPE_CONFEDERATION_FORMED,
+ TYPE_CONFEDERATION_SIGNING_PROPOSED,
+ TYPE_CONFEDERATION_SIGNING_FAILED,
+ )
+
+ /**
+ * The group's inbox (docs/group-inbox.md): its key ceremony starting, finishing or
+ * failing, written by `InboxKeyRitualManager` on every device in the room. Three lines a
+ * ceremony rather than a ladder per step: nobody is asked anything in it, so there is
+ * nobody whose door the ladder would tell a member to knock on until it stalls, and the
+ * ceremony's screen names them then.
+ */
+ const val TYPE_INBOX_KEY_STARTED = "inboxKeyStarted"
+ const val TYPE_INBOX_KEY_COMPLETE = "inboxKeyComplete"
+ const val TYPE_INBOX_KEY_FAILED = "inboxKeyFailed"
+
+ /** The group signed an announcement of its inbox's key (10044) or relays (10050). */
+ const val TYPE_INBOX_ANNOUNCED = "inboxAnnounced"
+ const val TYPE_INBOX_RELAYS_ANNOUNCED = "inboxRelaysAnnounced"
+
+ /** This device wiped the group's inbox when its owner stopped being an admin (D14). */
+ const val TYPE_INBOX_FORGOTTEN = "inboxForgotten"
+
+ val INBOX_TYPES = setOf(
+ TYPE_INBOX_KEY_STARTED,
+ TYPE_INBOX_KEY_COMPLETE,
+ TYPE_INBOX_KEY_FAILED,
+ TYPE_INBOX_ANNOUNCED,
+ TYPE_INBOX_RELAYS_ANNOUNCED,
+ TYPE_INBOX_FORGOTTEN,
)
val GROUP_IDENTITY_TYPES = setOf(
TYPE_GROUP_PROFILE_SIGNED,
TYPE_LEGACY_GROUP_RELAYS_SIGNED,
TYPE_GROUP_POST_SIGNED,
- TYPE_GROUP_DM_RELAYS_SIGNED,
TYPE_GROUP_DM_FORGOTTEN,
TYPE_LEGACY_GROUP_SCHEMA_SIGNED,
TYPE_LEGACY_GROUP_ENTRY_CURATED,
TYPE_WALLET_NOT_TAKEN_PART_IN,
- ) + CONFEDERATION_TYPES
+ ) + CONFEDERATION_TYPES + INBOX_TYPES
/**
* Every subgroup line, for the one check the transcript dispatches on.
@@ -1011,7 +1039,8 @@ data class ChatMessage(
event.kind in ShareRefreshEvents.ALL ||
event.kind in ShareRepairEvents.ALL ||
event.kind in GroupEcdhEvents.ALL ||
- event.kind in GovernanceEvents.ALL
+ event.kind in GovernanceEvents.ALL ||
+ event.kind in ConfederationSigningEvents.ALL
)
database.marmotInnerEventDao().upsert(
@@ -1290,6 +1319,17 @@ data class ChatMessage(
// a line each would bury the room (docs/group-threshold-ecdh.md, D11).
in GroupEcdhEvents.ALL -> null
+ // The inbox key ceremony's messages (docs/group-inbox.md).
+ // `InboxKeyRitualManager` files them and writes its own lines.
+ in InboxKeyRitualEvents.ALL -> null
+
+ // A reply's seals, signed by the group (docs/group-inbox.md, D10). The
+ // signing session's own lines say the group signed something; a line naming
+ // the reply would reach members who are not admins, who must learn nothing of
+ // the inbox (D9). The same for a message the group writes by threshold ECDH
+ // (docs/group-threshold-ecdh.md, D12).
+ com.vitorpamplona.quartz.nip59Giftwrap.seals.SealEvent.KIND -> null
+
ChatEvent.KIND -> {
ChatMessage(
giftWrapPayloadId = null,
@@ -1382,6 +1422,37 @@ data class ChatMessage(
// through the room -- identity plumbing nobody sends on purpose --
// and is neither a line nor a raw-JSON bubble.
// docs/group-nostr-profile-and-posts.md.
+ // The group announcing its inbox (docs/group-inbox.md, D5 and D6): a 10044
+ // naming the key its admins made, or a 10050 naming where mail should go.
+ // Verified, as a post is, so no member can put the announcement in the group's
+ // mouth; anything else of these kinds says nothing here.
+ InboxAnnouncement.KEY_KIND, InboxAnnouncement.RELAYS_KIND -> {
+ val signed = GroupSignedEvent.fromEvent(event, chatRoomId = groupId)
+ if (!event.pubKey.equals(groupId, ignoreCase = true) || !signed.verifies()) return null
+ val content = if (event.kind == InboxAnnouncement.KEY_KIND) {
+ val announced = database.groupSignedEventDao().getByChatRoomIdAndKind(groupId, InboxAnnouncement.KEY_KIND)
+ .count { it.publicKey.equals(groupId, ignoreCase = true) }
+ if (announced <= 1) {
+ "The group has an inbox. Anyone on nostr can now write to it privately, and every admin can read what arrives."
+ } else {
+ "The group changed its inbox key. Mail sent to the old key can still be read by the admins who held it."
+ }
+ } else {
+ "The group said where its private mail should arrive."
+ }
+ ChatMessage(
+ giftWrapPayloadId = null,
+ messageType = if (event.kind == InboxAnnouncement.KEY_KIND) TYPE_INBOX_ANNOUNCED else TYPE_INBOX_RELAYS_ANNOUNCED,
+ marmotGroupEventId = marmotGroupEventId,
+ marmotInnerEventId = marmotInnerEventId,
+ senderPublicKey = senderPublicKey,
+ isUserMessage = isUserMessage,
+ chatRoomId = groupId,
+ createdAt = createdAt,
+ content = content,
+ )
+ }
+
MetadataEvent.KIND -> {
if (!event.pubKey.equals(groupId, ignoreCase = true)) return null
@@ -1404,35 +1475,6 @@ data class ChatMessage(
)
}
- // A message the group signed to someone: a seal, ciphertext. The session's
- // own lines already say the group signed, and naming the message here would
- // tell members who are not admins (docs/group-threshold-ecdh.md, D12).
- com.vitorpamplona.quartz.nip59Giftwrap.seals.SealEvent.KIND ->
- if (event.pubKey.equals(groupId, ignoreCase = true)) null else unsupported()
-
- // Where the group receives direct messages, signed by the room's own key.
- // Verified, as a post is: a rumor's pubkey is whatever its sender wrote.
- // docs/group-threshold-ecdh.md, D8.
- GroupDmRelays.KIND -> {
- val signed = GroupSignedEvent.fromEvent(event, chatRoomId = groupId)
- if (!event.pubKey.equals(groupId, ignoreCase = true) || !signed.verifies()) return null
- val earlier = database.groupSignedEventDao().getByChatRoomIdAndKind(groupId, GroupDmRelays.KIND)
- .any { it.id != event.id && it.createdAt <= signed.createdAt }
-
- ChatMessage(
- giftWrapPayloadId = null,
- messageType = TYPE_GROUP_DM_RELAYS_SIGNED,
- marmotGroupEventId = marmotGroupEventId,
- marmotInnerEventId = marmotInnerEventId,
- senderPublicKey = senderPublicKey,
- isUserMessage = isUserMessage,
- chatRoomId = groupId,
- createdAt = createdAt,
- content = if (earlier) "The group changed where it receives messages"
- else "The group can now receive messages"
- )
- }
-
// The group saying something publicly, in its own name -- a
// different thing from a member saying something in the room. A
// room's messages are `ChatEvent`s; this is a kind:1 authored by
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ConfederationSigningAttempt.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ConfederationSigningAttempt.kt
new file mode 100644
index 00000000..305c5235
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ConfederationSigningAttempt.kt
@@ -0,0 +1,72 @@
+package mobi.giza.compose.database.model
+
+import androidx.room3.Entity
+import androidx.room3.ForeignKey
+import androidx.room3.Index
+import androidx.room3.PrimaryKey
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.Kind
+import kotlin.time.Clock
+import kotlin.time.Instant
+
+/**
+ * One attempt by a confederation to sign one event (docs/confederation.md, Phase 14).
+ *
+ * Unlike a FROST signing session, an attempt cannot outlive a restart once its nonces are out:
+ * upstream's signer state lives in memory only and must never be persisted, because a restored
+ * nonce can reveal the share. So this row holds what the attempt is about and what this device has
+ * said, and a device that comes back to an attempt it was signing in ends it, out loud; the
+ * proposer starts a new one under a new session id.
+ */
+@Entity(
+ foreignKeys = [
+ ForeignKey(entity = ChatRoom::class, parentColumns = ["id"], childColumns = ["confederationId"], onDelete = ForeignKey.CASCADE)
+ ],
+ indices = [Index("confederationId")],
+)
+data class ConfederationSigningAttempt(
+ /** The signing session id, 32 bytes of hex: hashed into D_sign. */
+ @PrimaryKey
+ val id: String,
+ /** The confederation's room, whose id is also the confederation's. */
+ val confederationId: HexKey,
+ val proposerPublicKey: HexKey,
+ val userPublicKey: HexKey,
+ /** The unsigned event, authored by the room, with its id. */
+ val eventJson: String,
+ val stage: ConfederationSigningStage = ConfederationSigningStage.AWAITING_APPROVAL,
+ val approvedAt: Instant? = null,
+ val declinedAt: Instant? = null,
+ /** The event, signed, once it is. */
+ val signedEventJson: String? = null,
+ val failureReason: String? = null,
+ val createdAt: Instant = Clock.System.now(),
+ val updatedAt: Instant = createdAt,
+) {
+ val isRunning: Boolean
+ get() = stage != ConfederationSigningStage.COMPLETE && stage != ConfederationSigningStage.FAILED
+}
+
+enum class ConfederationSigningStage {
+ AWAITING_APPROVAL,
+ SELECTING,
+ NONCES,
+ CONFIRMING,
+ SIGNING,
+ COMPLETE,
+ FAILED,
+}
+
+@Entity(
+ primaryKeys = ["attemptId", "senderPublicKey", "kind"],
+ foreignKeys = [
+ ForeignKey(entity = ConfederationSigningAttempt::class, parentColumns = ["id"], childColumns = ["attemptId"], onDelete = ForeignKey.CASCADE)
+ ],
+)
+data class ConfederationSigningMessage(
+ val attemptId: String,
+ val senderPublicKey: HexKey,
+ val kind: Kind,
+ val payload: String,
+ val receivedAt: Instant = Clock.System.now(),
+)
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/GroupInbox.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/GroupInbox.kt
new file mode 100644
index 00000000..286d0e0f
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/GroupInbox.kt
@@ -0,0 +1,136 @@
+package mobi.giza.compose.database.model
+
+import androidx.room3.Entity
+import androidx.room3.ForeignKey
+import androidx.room3.Index
+import androidx.room3.PrimaryKey
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.Kind
+import kotlin.time.Clock
+import kotlin.time.Instant
+
+/**
+ * Every gift wrap addressed to a group this device keeps an inbox for, opened or not
+ * (docs/group-inbox.md, D8).
+ *
+ * The ledger is what makes redelivery a no-op, and what lets a key that arrives later -- a
+ * restore, a ceremony that finished after the mail did -- reopen what is already here. A wrap
+ * no held key opens stays with [openedGeneration] null, and is counted on the inbox screen
+ * rather than hidden.
+ *
+ * Never a `GiftWrapMessage`: those belong to the personal inbox, which would file the group's
+ * correspondents into the admin's own direct messages.
+ */
+@Entity(
+ foreignKeys = [
+ ForeignKey(entity = ChatRoom::class, parentColumns = ["id"], childColumns = ["chatRoomId"], onDelete = ForeignKey.CASCADE)
+ ],
+ indices = [Index("chatRoomId")],
+)
+data class GroupInboxWrap(
+ @PrimaryKey
+ val id: HexKey,
+ val chatRoomId: String,
+ /** The wrap as it arrived, so it can be tried again with a key this device gets later. */
+ val wrapJson: String,
+ /** The wrap's own `created_at`: back-dated by up to two days, as NIP-59 has it. */
+ val wrapCreatedAt: Long,
+ /** The inbox key generation that opened it, or null while none has. */
+ val openedGeneration: Int? = null,
+ val receivedAt: Instant = Clock.System.now(),
+)
+
+/**
+ * A message in a group's inbox, incoming or outgoing (docs/group-inbox.md, D8 and D10): one row
+ * per rumor, however many wraps carried it.
+ */
+@Entity(
+ primaryKeys = ["chatRoomId", "rumorId"],
+ foreignKeys = [
+ ForeignKey(entity = ChatRoom::class, parentColumns = ["id"], childColumns = ["chatRoomId"], onDelete = ForeignKey.CASCADE)
+ ],
+ indices = [Index("chatRoomId"), Index("conversationId")],
+)
+data class GroupInboxMessage(
+ val chatRoomId: String,
+ /** Computed from the rumor, never taken from it. */
+ val rumorId: HexKey,
+ /** The first wrap it arrived in; null for an outgoing message filed before its copy came back. */
+ val wrapId: HexKey?,
+ /** [mobi.giza.compose.nostr.inbox.InboxConversation.idOf] over [participants]. */
+ val conversationId: String,
+ /** Everyone in the conversation but the group, sorted, comma-separated. */
+ val participants: String,
+ val senderPublicKey: HexKey,
+ val kind: Kind,
+ /** The rumor as NIP-59 carries it: its id and no signature. */
+ val rumorJson: String,
+ /** The rumor's own `created_at`, unfuzzed: when the sender says they wrote it. */
+ val createdAt: Long,
+ /** The inbox key generation that opened it, or sealed it if outgoing. */
+ val generation: Int,
+ /** Written by the group: a reply. */
+ val outgoing: Boolean,
+ /** The signing session a reply came from, when this device knows it. */
+ val signingSessionId: String? = null,
+ val readAt: Instant? = null,
+ val receivedAt: Instant = Clock.System.now(),
+) {
+ fun participantList(): List = participants.split(",").map { it.trim() }.filter { it.isNotEmpty() }
+}
+
+/**
+ * An event this device owes relays on the group's behalf (docs/group-inbox.md, D7 and D10): a
+ * signed 10044 or 10050 the group agreed to, or a gift wrap carrying a reply it signed. Sent with
+ * backoff until a relay takes it, as `ConfederationPublisher` sends confederation events.
+ *
+ * Never a `NostrEvent` row, for the reasons group-nostr-profile-and-posts.md D7 gives: the group's
+ * events are not the feed's, and a kind 0 or 10050 there would make a profile of the group.
+ */
+@Entity(
+ foreignKeys = [
+ ForeignKey(entity = ChatRoom::class, parentColumns = ["id"], childColumns = ["chatRoomId"], onDelete = ForeignKey.CASCADE)
+ ],
+ indices = [Index("chatRoomId"), Index("signingSessionId")],
+)
+data class GroupInboxPublication(
+ @PrimaryKey
+ val eventId: HexKey,
+ val chatRoomId: String,
+ val kind: Kind,
+ val eventJson: String,
+ /** Where it goes, comma-separated; the app's publish set is added to these. */
+ val relays: String,
+ /** The signing session it came from. */
+ val signingSessionId: String?,
+ /** For a wrap: who it is to. Null for the group's own announcements. */
+ val recipientPublicKey: HexKey?,
+ val attempts: Int = 0,
+ val nextAttemptAt: Instant? = null,
+ val publishedAt: Instant? = null,
+ val createdAt: Instant = Clock.System.now(),
+) {
+ fun relayList(): List = relays.split(",").map { it.trim() }.filter { it.isNotEmpty() }
+}
+
+/**
+ * What a signing session that touches the group's inbox carried, and why this device refused it,
+ * if it did (docs/group-inbox.md, D5 and D12): kept past arrival because approval checks again,
+ * and the decline has to say why.
+ */
+@Entity(
+ foreignKeys = [
+ ForeignKey(entity = ChatRoom::class, parentColumns = ["id"], childColumns = ["chatRoomId"], onDelete = ForeignKey.CASCADE)
+ ],
+ indices = [Index("chatRoomId")],
+)
+data class InboxSigning(
+ @PrimaryKey
+ val sessionId: String,
+ val chatRoomId: String,
+ /** A reply's sealed manifest, as its proposal carried it (D11). */
+ val manifest: String? = null,
+ /** Why this device declined, in the words the decline carries. */
+ val refusal: String? = null,
+ val createdAt: Instant = Clock.System.now(),
+)
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/InboxKeyCeremony.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/InboxKeyCeremony.kt
new file mode 100644
index 00000000..2cb4984e
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/InboxKeyCeremony.kt
@@ -0,0 +1,144 @@
+package mobi.giza.compose.database.model
+
+import androidx.room3.Entity
+import androidx.room3.ForeignKey
+import androidx.room3.Index
+import androidx.room3.PrimaryKey
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.Kind
+import kotlin.time.Clock
+import kotlin.time.Instant
+
+/**
+ * One device's part in a group's inbox key ceremony (docs/group-inbox.md, D2 and D3): ChillDKG
+ * at threshold 1 over the room's admins.
+ *
+ * Kept apart from [DkgSession] on purpose. Every completed `DkgSession` is a key the signing
+ * path may find, and a threshold-1 key there would be a key any one admin could sign as the
+ * group with. Nothing that looks for a signing key reads this table.
+ *
+ * Inputs, never protocol state, as `DkgSession` keeps them: every step is a pure function of
+ * the randomness here and the messages in [InboxKeyCeremonyMessage], so a device that dies
+ * between rounds recomputes the step on the next message. The secret it produces is not kept
+ * here but in [InboxKey], once, when the ceremony completes.
+ */
+@Entity(
+ foreignKeys = [
+ ForeignKey(entity = ChatRoom::class, parentColumns = ["id"], childColumns = ["chatRoomId"], onDelete = ForeignKey.CASCADE)
+ ],
+ indices = [Index("chatRoomId")],
+)
+data class InboxKeyCeremony(
+ @PrimaryKey
+ val id: String,
+ /** The group's Marmot room: the ceremony runs in it, and its admins are the participants. */
+ val chatRoomId: String,
+ /** Which generation of the room's inbox key this ceremony makes. */
+ val generation: Int,
+ val coordinatorPublicKey: HexKey,
+ /** The identity on this device taking part, or watching. */
+ val userPublicKey: HexKey,
+ /** The admins the proposal named, sorted, comma-separated. */
+ val participantPublicKeys: String,
+ val stage: InboxKeyCeremonyStage = InboxKeyCeremonyStage.COLLECTING_HOST_KEYS,
+ /** Null on the device of a member who is not a participant: it only watches. */
+ val hostPublicKey: HexKey? = null,
+ val round1Random: HexKey? = null,
+ val round2AuxRandom: HexKey? = null,
+ /**
+ * Where the group's mail should arrive, comma-separated, as the member who opened the first
+ * ceremony chose it: the 10050 the coordinator proposes beside the first 10044 (D6). Null
+ * for a rotation, which keeps the relays the group already announced.
+ */
+ val announceRelays: String? = null,
+ /** The ceremony's public key `E`, x-only, once it is certified. */
+ val inboxPublicKey: HexKey? = null,
+ val failureReason: String? = null,
+ /** Whose fault a failure was, when ChillDKG could say. */
+ val culprit: HexKey? = null,
+ /** When the last message arrived: what "waiting since" is measured from. */
+ val lastMessageAt: Instant = Clock.System.now(),
+ val createdAt: Instant = Clock.System.now(),
+ val updatedAt: Instant = createdAt,
+) {
+ val isRunning: Boolean
+ get() = stage != InboxKeyCeremonyStage.COMPLETE && stage != InboxKeyCeremonyStage.FAILED
+
+ fun isCoordinator(): Boolean = coordinatorPublicKey == userPublicKey
+
+ fun participants(): List = participantPublicKeys.split(",").map { it.trim() }.filter { it.isNotEmpty() }
+
+ fun isParticipant(): Boolean = userPublicKey in participants()
+
+ companion object {
+ fun formatParticipants(publicKeys: Collection): String = publicKeys.distinct().sorted().joinToString(",")
+ }
+}
+
+/** Where an inbox key ceremony has got to, as a label for screens. */
+enum class InboxKeyCeremonyStage {
+ COLLECTING_HOST_KEYS,
+ ROUND_1,
+ ROUND_2,
+ COMPLETE,
+ FAILED,
+}
+
+/** One message an inbox key ceremony has received or sent, written once per sender and kind. */
+@Entity(
+ primaryKeys = ["sessionId", "senderPublicKey", "kind"],
+ foreignKeys = [
+ ForeignKey(entity = InboxKeyCeremony::class, parentColumns = ["id"], childColumns = ["sessionId"], onDelete = ForeignKey.CASCADE)
+ ],
+)
+data class InboxKeyCeremonyMessage(
+ val sessionId: String,
+ val senderPublicKey: HexKey,
+ val kind: Kind,
+ val payload: String,
+ val receivedAt: Instant = Clock.System.now(),
+)
+
+/**
+ * One generation of a group's inbox key, as this device holds it (docs/group-inbox.md, D14).
+ *
+ * [secretKey] is the whole secret `e`: every admin holds it, which is the point of it. It is
+ * kept as a share is kept, and wiped as a share is wiped -- [state] goes to [InboxKeyState.WIPED]
+ * and the secret to null, while [publicKey] stays so the device can still say which key it was.
+ */
+@Entity(
+ primaryKeys = ["chatRoomId", "userPublicKey", "generation"],
+ foreignKeys = [
+ ForeignKey(entity = ChatRoom::class, parentColumns = ["id"], childColumns = ["chatRoomId"], onDelete = ForeignKey.CASCADE)
+ ],
+ indices = [Index("chatRoomId")],
+)
+data class InboxKey(
+ val chatRoomId: String,
+ val userPublicKey: HexKey,
+ val generation: Int,
+ /** `E`, x-only hex: what the group's 10044 names. */
+ val publicKey: HexKey,
+ /** `e`, hex; null once wiped. */
+ val secretKey: HexKey?,
+ /** ChillDKG's recovery data: with the host secret from the nsec, it restores [secretKey]. */
+ val recoveryData: HexKey?,
+ val ceremonyId: String,
+ val state: InboxKeyState = InboxKeyState.HELD,
+ /** The signed 10044 that announced this generation, once there is one. */
+ val announcementEventId: HexKey? = null,
+ val createdAt: Instant = Clock.System.now(),
+ val announcedAt: Instant? = null,
+ val wipedAt: Instant? = null,
+)
+
+enum class InboxKeyState {
+ /** Made, not yet announced: nobody has been told to write to it. */
+ HELD,
+ /** The key the group's newest signed 10044 names: replies are sealed from it. */
+ ANNOUNCED,
+ /** Replaced by a later generation: used to open, never to seal. */
+ RETIRED,
+ /** Gone from this device: the admin was removed, or the device asked to forget. */
+ WIPED,
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt
index 8db71d63..88e294d6 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt
@@ -81,6 +81,7 @@ import mobi.giza.compose.managers.ChronicleManager
import mobi.giza.compose.managers.FrostSigningManager
import mobi.giza.compose.extensions.toHex
import mobi.giza.compose.managers.ConfederationRitualManager
+import mobi.giza.compose.managers.ConfederationSigningManager
import mobi.giza.compose.managers.ConfederationFormation
import mobi.giza.compose.managers.ConfederationFollowThrough
import mobi.giza.compose.managers.GroupEcdhManager
@@ -177,6 +178,9 @@ class DatabaseChatRepository(
launch {
runCatching { ConfederationRitualManager.resumeRunning(database, keyPair.pubKey.toHex(), secret) }
.onFailure { logger.e("Could not resume confederation ceremonies", it) }
+ // An attempt this device was signing in cannot survive a restart: ended out loud.
+ runCatching { ConfederationSigningManager.resumeRunning(database, keyPair.pubKey.toHex(), secret) }
+ .onFailure { logger.e("Could not resume confederation signing", it) }
}
}
}
@@ -301,9 +305,47 @@ class DatabaseChatRepository(
}
}
+ override suspend fun inboxSummary(localChatRoom: LocalChatRoom): mobi.giza.compose.ui.view.state.InboxRowSummary? {
+ if (!mobi.giza.compose.ExperimentalFeatures.groupInbox || localChatRoom.chatRoom.mlsGroupState == null) return null
+ val roomId = localChatRoom.chatRoom.id
+ val user = localChatRoom.chatRoom.userPublicKey
+ val holds = database.inboxKeyDao().getKeys(roomId, user).any { it.secretKey != null }
+ val running = database.inboxKeyDao().getRunningCeremoniesIn(roomId).any { it.userPublicKey == user && it.isParticipant() }
+ val canSetUp = !holds && !running &&
+ mobi.giza.compose.managers.InboxKeyRitualManager.refusal(database, localChatRoom, user) == null
+ if (!holds && !running && !canSetUp) return null
+ val unread = if (holds) database.groupInboxDao().getMessages(roomId).count { !it.outgoing && it.readAt == null } else 0
+ return mobi.giza.compose.ui.view.state.InboxRowSummary(holdsKey = holds, unread = unread, ceremonyRunning = running, canSetUp = canSetUp)
+ }
+
override suspend fun confederationProposalCount(chatRoomId: String): Int =
database.confederationDao().getProposalsNaming(chatRoomId).size
+ override suspend fun canSignAsConfederation(chatRoomId: String): Boolean {
+ if (!ExperimentalFeatures.confederation) return false
+ val me = activeIdentity.value?.takeIf { it.canSign }?.nostrPublicKey ?: return false
+ return ConfederationSigningManager.canSign(database, chatRoomId, me)
+ }
+
+ override suspend fun proposeAsConfederation(
+ localChatRoom: LocalChatRoom,
+ kind: Kind,
+ tags: Array>,
+ content: String,
+ ): String {
+ val identity = activeIdentity.value ?: throw IllegalStateException("No identity is signed in")
+ val secret = identity.nostrPrivateKey ?: throw IllegalStateException("This identity cannot sign")
+ return ConfederationSigningManager.propose(
+ database, localChatRoom, identity.nostrPublicKey, kind, tags, content, secret.value.toByteArray(),
+ ).id
+ }
+
+ override suspend fun proposeCharter(localChatRoom: LocalChatRoom): String {
+ val (kind, tags, content) = ConfederationSigningManager.charterTemplate(database, localChatRoom.chatRoom.id)
+ ?: throw IllegalStateException("This device holds no confederation for this room")
+ return proposeAsConfederation(localChatRoom, kind, tags, content)
+ }
+
override suspend fun confederationOfRoom(chatRoomId: String): String? =
database.confederationCeremonyDao().getConfederation(chatRoomId)
?.takeIf { ConfederationFormation.verifies(it) }
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseConfederationRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseConfederationRepository.kt
index 3e857c81..e188f111 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseConfederationRepository.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseConfederationRepository.kt
@@ -16,6 +16,9 @@ import mobi.giza.compose.database.model.Confederation
import mobi.giza.compose.database.model.ConfederationCeremony
import mobi.giza.compose.database.model.ConfederationCeremonyMessage
import mobi.giza.compose.database.model.ConfederationEvent
+import mobi.giza.compose.database.model.ConfederationSigningAttempt
+import mobi.giza.compose.database.model.ConfederationSigningMessage
+import mobi.giza.compose.managers.ConfederationSigningManager
import mobi.giza.compose.managers.ConfederationRitualManager
import mobi.giza.compose.nostr.confederation.ConfederationRitualEvents
import mobi.giza.compose.nostr.confederation.ConfederationRosterBuilder
@@ -59,6 +62,22 @@ class DatabaseConfederationRepository(
override suspend fun abandonCeremony(sessionId: String) = ConfederationRitualManager.abandon(database, sessionId)
+ override fun observeSigningAttempt(attemptId: String): Flow =
+ database.confederationCeremonyDao().observeAttempt(attemptId)
+
+ override fun observeSigningMessages(attemptId: String): Flow> =
+ database.confederationCeremonyDao().observeSigningMessages(attemptId)
+
+ override suspend fun confederationPlan(confederationId: HexKey): ConfederationRosterBuilder.Plan? =
+ ConfederationSigningManager.held(database, confederationId)?.plan
+
+ override suspend fun approveSigning(attemptId: String) {
+ val secret = activeIdentity.value?.nostrPrivateKey ?: return
+ ConfederationSigningManager.approve(database, attemptId, secret.value.toByteArray())
+ }
+
+ override suspend fun declineSigning(attemptId: String) = ConfederationSigningManager.decline(database, attemptId)
+
override fun observeConfederationsOf(groupPublicKey: HexKey): Flow> =
database.confederationCeremonyDao().observeConfederationsOf(groupPublicKey)
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseFrostSigningRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseFrostSigningRepository.kt
index 7548b714..f0e23070 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseFrostSigningRepository.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseFrostSigningRepository.kt
@@ -27,8 +27,12 @@ class DatabaseFrostSigningRepository(
): FrostSigningRepository {
private val logger = Logger.withTag(TAG)
- override suspend fun confederationNotes(chatRoomId: String, sessionId: String, events: List): List =
+ override suspend fun proposalNotes(chatRoomId: String, sessionId: String, events: List): List =
runCatching { ConfederationRefusal.notes(database, chatRoomId, sessionId, events) }.getOrDefault(emptyList()) +
+ runCatching {
+ val user = database.frostSigningSessionDao().getSessionById(sessionId)?.userPublicKey ?: return@runCatching emptyList()
+ mobi.giza.compose.managers.InboxRefusal.notes(database, chatRoomId, user, sessionId, events)
+ }.getOrDefault(emptyList()) +
runCatching { groupDmNotes(sessionId, events) }.getOrDefault(emptyList())
/**
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseGroupInboxRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseGroupInboxRepository.kt
new file mode 100644
index 00000000..28a6fb70
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseGroupInboxRepository.kt
@@ -0,0 +1,132 @@
+package mobi.giza.compose.database.repository
+
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.map
+import kotlin.time.Clock
+import kotlin.time.Instant
+import mobi.giza.compose.database.GizaDatabase
+import mobi.giza.compose.database.model.GroupInboxMessage
+import mobi.giza.compose.database.model.GroupInboxPublication
+import mobi.giza.compose.database.model.InboxKeyCeremony
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.identity.Identity
+import mobi.giza.compose.managers.GroupInboxManager
+import mobi.giza.compose.managers.InboxAnnouncements
+import mobi.giza.compose.managers.InboxKeyRitualManager
+import mobi.giza.compose.managers.InboxReplies
+import mobi.giza.compose.managers.InboxRotation
+import mobi.giza.compose.nostr.inbox.InboxKeyRitualEvents
+import mobi.giza.compose.repository.GroupInboxRepository
+
+class DatabaseGroupInboxRepository(
+ private val database: GizaDatabase,
+ @Suppress("unused") private val scope: CoroutineScope,
+ /** The identity the app runs as: its key takes part in the ceremonies it starts. */
+ private val activeIdentity: StateFlow = MutableStateFlow(null),
+) : GroupInboxRepository {
+ override fun observeUnpublished(): Flow> =
+ database.groupInboxDao().observeUnpublished()
+
+ override suspend fun markPublished(eventId: HexKey, at: Instant) =
+ database.groupInboxDao().markPublished(eventId, at)
+
+ override fun observeRoutes(userPublicKey: HexKey): Flow> =
+ database.inboxKeyDao().observeHeldKeys(userPublicKey)
+ .map { keys -> keys.groupBy({ it.chatRoomId }, { it.publicKey }).toSortedMap() }
+ .distinctUntilChanged()
+ .map { byRoom -> byRoom.map { (room, keys) -> GroupInboxRepository.Route(room, keys, InboxAnnouncements.relaysOf(database, room)) } }
+
+ override suspend fun receive(wrap: Event, userPublicKey: HexKey): GroupInboxMessage? =
+ GroupInboxManager.receive(database, wrap, userPublicKey)
+
+ override fun observeConversations(chatRoomId: String): Flow> =
+ database.groupInboxDao().observeMessages(chatRoomId).map { messages ->
+ val names = namesOf(messages.flatMap { it.participantList() }.distinct())
+ messages.groupBy { it.conversationId }.map { (id, inConversation) ->
+ val newest = inConversation.maxBy { it.createdAt }
+ val participants = newest.participantList()
+ GroupInboxRepository.ConversationSummary(
+ conversationId = id,
+ participants = participants,
+ names = participants.map { names[it] ?: it.take(8) },
+ lastText = Event.fromJsonOrNull(newest.rumorJson)?.content.orEmpty(),
+ lastAt = newest.createdAt,
+ lastOutgoing = newest.outgoing,
+ unread = inConversation.count { !it.outgoing && it.readAt == null },
+ )
+ }.sortedByDescending { it.lastAt }
+ }
+
+ override fun observeConversation(chatRoomId: String, conversationId: String): Flow> =
+ database.groupInboxDao().observeConversation(chatRoomId, conversationId)
+
+ override fun observeUnopenedCount(chatRoomId: String): Flow =
+ database.groupInboxDao().observeUnopenedCount(chatRoomId)
+
+ override fun observeStatus(localChatRoom: LocalChatRoom, userPublicKey: HexKey): Flow {
+ val roomId = localChatRoom.chatRoom.id
+ return combine(
+ database.inboxKeyDao().observeKeys(roomId, userPublicKey),
+ database.inboxKeyDao().observeLatestCeremony(roomId, userPublicKey),
+ ) { keys, ceremony ->
+ GroupInboxRepository.Status(
+ keys = keys,
+ ceremony = ceremony,
+ announcedKey = InboxAnnouncements.announcedKey(database, roomId),
+ relays = InboxAnnouncements.relaysOf(database, roomId),
+ setUpRefusal = InboxKeyRitualManager.refusal(database, localChatRoom, userPublicKey),
+ waitingOn = ceremony?.takeIf { it.isRunning }?.let { waitingOn(it) }.orEmpty(),
+ rotationOwed = InboxRotation.isOwed(database, localChatRoom, userPublicKey),
+ )
+ }
+ }
+
+ /** The admins a running ceremony has not heard a host key from: who to knock on the door of. */
+ private suspend fun waitingOn(ceremony: InboxKeyCeremony): List {
+ val heard = database.inboxKeyDao().getMessages(ceremony.id)
+ .filter { it.kind == InboxKeyRitualEvents.HOST_KEY }.map { it.senderPublicKey }.toSet()
+ val silent = ceremony.participants().filter { it !in heard }
+ val names = namesOf(silent)
+ return silent.map { names[it] ?: it.take(8) }
+ }
+
+ override suspend fun markRead(chatRoomId: String, conversationId: String) =
+ database.groupInboxDao().markConversationRead(chatRoomId, conversationId, Clock.System.now())
+
+ override suspend fun namesOf(publicKeys: List): Map =
+ database.profileDao().getProfileByPublicKeys(publicKeys).associate { it.publicKey to it.humanReadableNameOrPubkey() }
+
+ private fun secret(): ByteArray =
+ activeIdentity.value?.nostrPrivateKey?.value?.toByteArray() ?: throw IllegalStateException("This identity cannot sign")
+
+ override suspend fun setUp(localChatRoom: LocalChatRoom, relays: List): InboxKeyCeremony =
+ InboxKeyRitualManager.propose(database, localChatRoom, localChatRoom.chatRoom.userPublicKey, secret(), relays)
+
+ override suspend fun rotate(localChatRoom: LocalChatRoom): InboxKeyCeremony =
+ InboxKeyRitualManager.propose(database, localChatRoom, localChatRoom.chatRoom.userPublicKey, secret())
+
+ override suspend fun abandon(localChatRoom: LocalChatRoom, ceremonyId: String): Boolean =
+ InboxKeyRitualManager.abandon(database, localChatRoom, ceremonyId)
+
+ override suspend fun proposeReply(localChatRoom: LocalChatRoom, conversationId: String, text: String): String =
+ InboxReplies.propose(database, localChatRoom, localChatRoom.chatRoom.userPublicKey, conversationId, text).id
+
+ override suspend fun withoutAnnouncedKey(publicKeys: List): List =
+ publicKeys.filterNot { InboxReplies.hasAnnouncedKey(database, it) }
+
+ override suspend fun unsentReplies(chatRoomId: String): Set =
+ database.groupInboxDao().getMessages(chatRoomId)
+ .mapNotNull { it.signingSessionId }
+ .filter { session -> database.groupInboxDao().getPublicationsFor(session).any { it.publishedAt == null } }
+ .toSet()
+
+ override suspend fun sendAgain(sessionId: String): Boolean = InboxReplies.sendAgain(database, sessionId)
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseNostrRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseNostrRepository.kt
index 7d105ec7..60c1ddcf 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseNostrRepository.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseNostrRepository.kt
@@ -61,6 +61,8 @@ import kotlinx.coroutines.sync.withLock
import mobi.giza.compose.managers.ChillDkgRitualManager
import mobi.giza.compose.managers.FrostSigningManager
import mobi.giza.compose.managers.ShareRefreshManager
+import mobi.giza.compose.managers.InboxKeyRitualManager
+import mobi.giza.compose.managers.InboxRotation
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import mobi.giza.compose.identity.Identity
@@ -158,6 +160,14 @@ class DatabaseNostrRepository(
) + FrostSigningManager.resumeVouched(
database = database,
userPublicKey = userPublicKey,
+ ) + InboxKeyRitualManager.resumeRunning(
+ database = database,
+ userPublicKey = userPublicKey,
+ nostrPrivateKey = privateKey
+ ) + InboxRotation.pass(
+ database = database,
+ userPublicKey = userPublicKey,
+ nostrPrivateKey = privateKey
)
}
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationManager.kt
index 62a6b66c..8ff6ad23 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationManager.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationManager.kt
@@ -16,6 +16,7 @@ import mobi.giza.compose.database.model.FrostSigningSession
import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
import mobi.giza.compose.extensions.toHex
import mobi.giza.compose.nostr.confederation.ConfederationAdminList
+import mobi.giza.compose.nostr.confederation.ConfederationCharterEvent
import mobi.giza.compose.nostr.confederation.ConfederationKinds
import mobi.giza.compose.nostr.confederation.ConfederationProposalAcceptanceEvent
import mobi.giza.compose.nostr.confederation.ConfederationProposalEvent
@@ -58,6 +59,9 @@ object ConfederationManager {
?.let { it.proposalId to emptyList() }
ConfederationKinds.WITHDRAWAL -> ConfederationProposalWithdrawalEvent.parse(event)
?.let { it.proposalId to emptyList() }
+ // Filed under its own id, and under every group it names, so each member group finds it.
+ ConfederationKinds.CHARTER -> ConfederationCharterEvent.parse(event)
+ ?.let { it.id to it.groups }
else -> null
} ?: run {
logger.w("Confederation event ${event.id.take(8)} of kind ${event.kind} is not well formed; dropping")
@@ -96,6 +100,7 @@ object ConfederationManager {
* not hold yet gets its line when the proposal is filed.
*/
private suspend fun announce(database: GizaDatabase, event: Event, proposalId: HexKey) {
+ if (event.kind == ConfederationKinds.CHARTER) return announceCharter(database, event)
val proposal = proposal(database, proposalId) ?: return
val rooms = proposal.groupPublicKeys.mapNotNull { database.chatRoomDao().findChatRoomById(it) }
if (rooms.isEmpty()) return
@@ -134,6 +139,31 @@ object ConfederationManager {
}
}
+ /**
+ * A line in each member group's room this device holds: the one way a group's members who are
+ * not admins hear that their group is part of a confederation. A claim by the confederation's
+ * key, which the line says.
+ */
+ private suspend fun announceCharter(database: GizaDatabase, event: Event) {
+ val charter = ConfederationCharterEvent.parse(event) ?: return
+ charter.groups.forEach { group ->
+ if (database.chatRoomDao().findChatRoomById(group) == null) return@forEach
+ database.chatMessageDao().upsert(
+ ChatMessage(
+ senderPublicKey = event.pubKey,
+ isUserMessage = false,
+ giftWrapPayloadId = null,
+ marmotGroupEventId = null,
+ marmotInnerEventId = null,
+ chatRoomId = group,
+ content = "The confederation ${charter.name} signed its charter, naming this group among its ${charter.groups.size}",
+ messageType = ChatMessage.TYPE_CONFEDERATION_FORMED,
+ createdAt = Instant.fromEpochSeconds(event.createdAt),
+ )
+ )
+ }
+ }
+
/** How a line names a group: "This group" in its own room, else its profile's name or its npub. */
suspend fun nameOf(database: GizaDatabase, group: HexKey, inRoom: String? = null): String {
if (group == inRoom) return "This group"
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationSigningManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationSigningManager.kt
new file mode 100644
index 00000000..8ce1580a
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationSigningManager.kt
@@ -0,0 +1,600 @@
+package mobi.giza.compose.managers
+
+import co.touchlab.kermit.Logger
+import com.vitorpamplona.crypto.random.RandomInstance
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.Kind
+import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
+import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
+import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
+import fr.acinq.bitcoin.ByteVector
+import fr.acinq.bitcoin.ByteVector32
+import fr.acinq.bitcoin.ByteVector64
+import fr.acinq.bitcoin.Crypto
+import fr.acinq.bitcoin.XonlyPublicKey
+import fr.acinq.bitcoin.crypto.confederation.ConfederationConfirmationCertificate
+import fr.acinq.bitcoin.crypto.confederation.ConfederationKeyState
+import fr.acinq.bitcoin.crypto.confederation.ConfederationRecoveryPackage
+import fr.acinq.bitcoin.crypto.confederation.ConfederationRoleId
+import fr.acinq.bitcoin.crypto.confederation.ConfederationRoster
+import fr.acinq.bitcoin.crypto.confederation.ConfederationShare
+import fr.acinq.bitcoin.crypto.confederation.ConfederationSigner
+import fr.acinq.bitcoin.crypto.confederation.ConfederationSignerSelection
+import fr.acinq.bitcoin.crypto.confederation.ConfederationSigning
+import fr.acinq.bitcoin.crypto.confederation.ConfederationSigningSession
+import fr.acinq.bitcoin.crypto.confederation.ConfederationTweak
+import fr.acinq.bitcoin.utils.Either
+import kotlin.time.Clock
+import kotlin.time.Instant
+import kotlinx.coroutines.sync.Mutex
+import kotlinx.coroutines.sync.withLock
+import mobi.giza.compose.database.GizaDatabase
+import mobi.giza.compose.database.model.ChatMessage
+import mobi.giza.compose.database.model.Confederation
+import mobi.giza.compose.database.model.ConfederationSigningAttempt
+import mobi.giza.compose.database.model.ConfederationSigningMessage
+import mobi.giza.compose.database.model.ConfederationSigningStage
+import mobi.giza.compose.database.model.GroupSignedEvent
+import mobi.giza.compose.database.model.MarmotInnerEvent
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.extensions.toHex
+import mobi.giza.compose.nostr.confederation.ConfederationCharterEvent
+import mobi.giza.compose.nostr.confederation.ConfederationRitualEvents
+import mobi.giza.compose.nostr.confederation.ConfederationRosterBuilder
+import mobi.giza.compose.nostr.confederation.ConfederationRosterBuilder.Plan
+import mobi.giza.compose.nostr.confederation.ConfederationSigningEvents
+
+/**
+ * A confederation signing an event as itself, one person per device (docs/confederation.md,
+ * Phase 14), over upstream's Option A signing, in the confederation's own Marmot room.
+ *
+ * Every role holder is asked, as a FROST member is: approving says this person's roles will sign.
+ * The proposer, who coordinates, fixes the selection from the first yeses -- at least `T` groups,
+ * at least `t_g` admins in each -- and then each selected role makes a nonce, confirms the
+ * transcript and the event, and gives its partial. Everything that takes no secret is computed on
+ * every device from the public messages, so each device builds the signature itself and checks it
+ * against the room's id before it keeps it.
+ *
+ * **A signer lives in memory only.** Upstream's state holds a secret nonce that must never be
+ * stored, restored or used twice, so [signers] is this process's and nothing else's. A device that
+ * restarts after sending a nonce can no longer confirm or sign; it ends the attempt, out loud, and
+ * the proposer starts a fresh one under a new session id. That is the opposite of
+ * `FrostSigningManager`, which stores its nonce randomness, and it is upstream's rule (F-24).
+ *
+ * The room signs as its own id: the key's tweaks are `SharedKeyDerivation`'s, as for every keyed
+ * room (D10).
+ *
+ * WARNING: upstream's confederation module is experimental and unaudited. This runs behind
+ * `ExperimentalFeatures.confederation`, off in release.
+ */
+object ConfederationSigningManager {
+ private val logger = Logger.withTag("ConfederationSigningManager")
+ private val mutex = Mutex()
+
+ /** Live signer states, by user, attempt and role. In memory only, by design. */
+ private val signers = mutableMapOf()
+
+ private fun signerKey(user: HexKey, attemptId: String, role: ConfederationRoleId) = "$user/$attemptId/${role.groupId}:${role.adminId}"
+
+ /** The kinds a confederation signs here: its profile, its posts and its charter (Phase 15). */
+ val SIGNABLE_KINDS: Set = setOf(MetadataEvent.KIND, TextNoteEvent.KIND, ConfederationCharterEvent.KIND)
+
+ const val RESTARTED = "A device restarted while signing, so this attempt cannot finish. Propose it again"
+
+ // ---- what a confederation is on this device ------------------------------------------------
+
+ /** Everything this device holds about one confederation, read back from storage. */
+ internal class Held(
+ val confederation: Confederation,
+ val plan: Plan,
+ val roster: ConfederationRoster,
+ val keyState: ConfederationKeyState,
+ val tweaks: List,
+ val roomKey: XonlyPublicKey,
+ )
+
+ internal suspend fun held(database: GizaDatabase, confederationId: HexKey): Held? {
+ val confederation = database.confederationCeremonyDao().getConfederation(confederationId)
+ ?.takeIf(ConfederationFormation::verifies) ?: return null
+ val ceremony = database.confederationCeremonyDao().getCeremony(confederation.ceremonyId) ?: return null
+ val plan = ConfederationRitualEvents.Opening.decode(ceremony.openingJson)
+ ?.let { ConfederationRitualManager.planFrom(it) as? Either.Right }?.value ?: return null
+ val roster = (ConfederationRoster.fromData(ByteVector(confederation.roster)) as? Either.Right)?.value ?: return null
+ val keyState = (ConfederationKeyState.fromData(ByteVector(confederation.keyState), roster) as? Either.Right)?.value ?: return null
+ val derived = SharedKeyDerivation.derive("02${confederation.publicKey}")
+ if (derived.hex != confederationId) return null
+ return Held(confederation, plan, roster, keyState, derived.tweaks.map { ConfederationTweak(it, isXonly = true) }, derived.publicKey)
+ }
+
+ /** Whether this device holds a role in [confederationId], and so can propose and sign for it. */
+ suspend fun canSign(database: GizaDatabase, confederationId: HexKey, userPublicKey: HexKey): Boolean =
+ held(database, confederationId)?.plan?.seatsOf(userPublicKey)?.isNotEmpty() == true
+
+ /** Why this device would not sign [event] for [held]'s confederation, or null. */
+ private fun refusalOf(held: Held, event: Event): String? = when {
+ event.pubKey != held.confederation.id -> "The event is not authored by the confederation"
+ event.kind !in SIGNABLE_KINDS -> "A confederation signs only its profile, its posts and its charter here"
+ event.kind == ConfederationCharterEvent.KIND && !isTrueCharter(held, event) ->
+ "The charter does not name exactly this confederation's groups, under its name"
+ event.kind == MetadataEvent.KIND && GroupStatementRefusal.isUnreadableProfile(event.tags, event.content) -> GroupStatementRefusal.REASON
+ event.kind == TextNoteEvent.KIND && GroupStatementRefusal.isBlankPost(event.content) -> GroupStatementRefusal.REASON
+ EventHasher.hashId(event.pubKey, event.createdAt, event.kind, event.tags, event.content) != event.id -> "The event's id is not the hash of its fields"
+ else -> null
+ }
+
+ /** A charter names exactly the groups the confederation was formed from, under its name. */
+ private fun isTrueCharter(held: Held, event: Event): Boolean {
+ val charter = ConfederationCharterEvent.parse(event) ?: return false
+ return charter.groups.toSet() == held.plan.groups.toSet() && charter.name == held.confederation.name
+ }
+
+ /** The charter [held]'s confederation would sign: its groups, under its name. */
+ suspend fun charterTemplate(database: GizaDatabase, confederationId: HexKey): Triple>, String>? {
+ val held = held(database, confederationId) ?: return null
+ return Triple(
+ ConfederationCharterEvent.KIND,
+ ConfederationCharterEvent.assembleTags(held.confederation.name, held.plan.groups),
+ ConfederationCharterEvent.content(held.confederation.name, held.plan.groups.size),
+ )
+ }
+
+ // ---- proposing -------------------------------------------------------------------------
+
+ /** Proposes that the confederation whose room is [localChatRoom] sign one event. Proposing is the proposer's approval. */
+ suspend fun propose(
+ database: GizaDatabase,
+ localChatRoom: LocalChatRoom,
+ userPublicKey: HexKey,
+ kind: Kind,
+ tags: Array>,
+ content: String,
+ nostrPrivateKey: ByteArray,
+ createdAt: Long = Clock.System.now().epochSeconds,
+ ): ConfederationSigningAttempt = mutex.withLock {
+ val roomId = localChatRoom.chatRoom.id
+ val held = held(database, roomId) ?: throw IllegalStateException("This device holds no confederation for this room")
+ check(held.plan.seatsOf(userPublicKey).isNotEmpty()) { "Only someone who holds a role in the confederation can propose for it" }
+ val id = EventHasher.hashId(roomId, createdAt, kind, tags, content)
+ val event = Event(id, roomId, createdAt, kind, tags, content, "")
+ refusalOf(held, event)?.let { throw IllegalArgumentException(it) }
+
+ val attempt = ConfederationSigningAttempt(
+ id = RandomInstance.bytes(32).toHex(),
+ confederationId = roomId,
+ proposerPublicKey = userPublicKey,
+ userPublicKey = userPublicKey,
+ eventJson = event.toJson(),
+ approvedAt = Clock.System.now(),
+ stage = ConfederationSigningStage.SELECTING,
+ )
+ database.confederationCeremonyDao().upsertAttempt(attempt)
+ announce(database, attempt, ChatMessage.TYPE_CONFEDERATION_SIGNING_PROPOSED, "A proposal for the confederation to sign: ${describe(event)}")
+ broadcast(database, localChatRoom, attempt, ConfederationSigningEvents.PROPOSAL, event.toJson())
+ publishAvailability(database, localChatRoom, attempt, held, available = true)
+ advance(database, localChatRoom, attempt.id, nostrPrivateKey)
+ database.confederationCeremonyDao().getAttempt(attempt.id)!!
+ }
+
+ // ---- inbound ---------------------------------------------------------------------------
+
+ suspend fun process(
+ database: GizaDatabase,
+ localChatRoom: LocalChatRoom,
+ innerEvent: Event,
+ userPublicKey: HexKey,
+ nostrPrivateKey: ByteArray,
+ ) = mutex.withLock {
+ val attemptId = ConfederationSigningEvents.parseSessionId(innerEvent.tags) ?: return@withLock
+ val held = held(database, localChatRoom.chatRoom.id) ?: run {
+ logger.i("Signing message for ${localChatRoom.chatRoom.id.take(12)}, which is no confederation here; leaving it stored")
+ return@withLock
+ }
+ val attempt = if (innerEvent.kind == ConfederationSigningEvents.PROPOSAL) {
+ acceptProposal(database, localChatRoom, held, innerEvent, attemptId, userPublicKey)
+ } else {
+ database.confederationCeremonyDao().getAttempt(attemptId)
+ } ?: return@withLock
+ if (!attempt.isRunning) return@withLock
+ if (!record(database, held, attempt, innerEvent)) return@withLock
+ advance(database, localChatRoom, attempt.id, nostrPrivateKey)
+ }
+
+ private suspend fun acceptProposal(
+ database: GizaDatabase,
+ localChatRoom: LocalChatRoom,
+ held: Held,
+ innerEvent: Event,
+ attemptId: String,
+ userPublicKey: HexKey,
+ ): ConfederationSigningAttempt? {
+ database.confederationCeremonyDao().getAttempt(attemptId)?.let { return it }
+ if (held.plan.seatsOf(innerEvent.pubKey).isEmpty()) {
+ logger.w("Signing proposal $attemptId from ${innerEvent.pubKey.take(8)}, who holds no role; dropping")
+ return null
+ }
+ if (held.plan.seatsOf(userPublicKey).isEmpty()) return null
+ val event = Event.fromJsonOrNull(innerEvent.content) ?: return null
+ val attempt = ConfederationSigningAttempt(
+ id = attemptId,
+ confederationId = held.confederation.id,
+ proposerPublicKey = innerEvent.pubKey,
+ userPublicKey = userPublicKey,
+ eventJson = event.toJson(),
+ )
+ val refusal = refusalOf(held, event)
+ if (refusal != null) {
+ // Declined out loud, as a FROST member declines what it cannot check: this person's
+ // roles will not sign, and the group can tell that from a phone in a pocket.
+ logger.w("Signing proposal $attemptId refused: $refusal")
+ database.confederationCeremonyDao().upsertAttempt(attempt.copy(declinedAt = Clock.System.now(), failureReason = refusal))
+ publishAvailability(database, localChatRoom, attempt, held, available = false)
+ return database.confederationCeremonyDao().getAttempt(attemptId)
+ }
+ database.confederationCeremonyDao().upsertAttempt(attempt)
+ announce(database, attempt, ChatMessage.TYPE_CONFEDERATION_SIGNING_PROPOSED, "A proposal for the confederation to sign: ${describe(event)}")
+ replayStoredMessages(database, held, attempt)
+ return database.confederationCeremonyDao().getAttempt(attemptId)
+ }
+
+ /**
+ * Files one message. Per-person messages only from a person holding a role, with a value for
+ * exactly their roles; the session only from the proposer; a failure from anyone with a role.
+ * Returns false when it ended the attempt.
+ */
+ private suspend fun record(database: GizaDatabase, held: Held, attempt: ConfederationSigningAttempt, innerEvent: Event): Boolean {
+ val sender = innerEvent.pubKey
+ val groups = held.plan.seatsOf(sender).map { it.group }.toSet()
+ when (innerEvent.kind) {
+ in ConfederationSigningEvents.PER_PERSON -> {
+ if (groups.isEmpty()) return true
+ if (ConfederationRitualEvents.decodeByGroup(innerEvent.content)?.keys != groups) return true
+ database.confederationCeremonyDao().insertSigningMessage(ConfederationSigningMessage(attempt.id, sender, innerEvent.kind, innerEvent.content))
+ }
+ ConfederationSigningEvents.SESSION -> {
+ if (sender != attempt.proposerPublicKey) return true
+ database.confederationCeremonyDao().insertSigningMessage(ConfederationSigningMessage(attempt.id, sender, innerEvent.kind, innerEvent.content))
+ }
+ ConfederationSigningEvents.FAILURE -> {
+ if (groups.isEmpty()) return true
+ fail(database, attempt, "Ended by ${ConfederationManager.nameOf(database, sender)}: ${innerEvent.content}")
+ return false
+ }
+ }
+ return true
+ }
+
+ // ---- the member's say --------------------------------------------------------------------
+
+ fun isAwaitingApproval(attempt: ConfederationSigningAttempt): Boolean =
+ attempt.isRunning && attempt.approvedAt == null && attempt.declinedAt == null
+
+ suspend fun approve(database: GizaDatabase, attemptId: String, nostrPrivateKey: ByteArray) = mutex.withLock {
+ val attempt = database.confederationCeremonyDao().getAttempt(attemptId)?.takeIf(::isAwaitingApproval) ?: return@withLock
+ val room = database.chatRoomDao().findChatRoomById(attempt.confederationId) ?: return@withLock
+ val held = held(database, attempt.confederationId) ?: return@withLock
+ // Checked again: what is signed has to be what this device would sign now.
+ refusalOf(held, Event.fromJson(attempt.eventJson))?.let { why ->
+ update(database, attempt) { it.copy(declinedAt = Clock.System.now(), failureReason = why) }
+ publishAvailability(database, room, attempt, held, available = false)
+ return@withLock
+ }
+ update(database, attempt) { it.copy(approvedAt = Clock.System.now()) }
+ publishAvailability(database, room, attempt, held, available = true)
+ advance(database, room, attemptId, nostrPrivateKey)
+ }
+
+ suspend fun decline(database: GizaDatabase, attemptId: String) = mutex.withLock {
+ val attempt = database.confederationCeremonyDao().getAttempt(attemptId)?.takeIf(::isAwaitingApproval) ?: return@withLock
+ val room = database.chatRoomDao().findChatRoomById(attempt.confederationId) ?: return@withLock
+ val held = held(database, attempt.confederationId) ?: return@withLock
+ update(database, attempt) { it.copy(declinedAt = Clock.System.now()) }
+ publishAvailability(database, room, attempt, held, available = false)
+ advance(database, room, attemptId, ByteArray(0))
+ }
+
+ /**
+ * After a restart: an attempt this device sent nonces in and has not finished cannot finish
+ * now, since the nonces went with the process. Ends each out loud. Others are moved on.
+ */
+ suspend fun resumeRunning(database: GizaDatabase, userPublicKey: HexKey, nostrPrivateKey: ByteArray): Int = mutex.withLock {
+ val running = database.confederationCeremonyDao().getRunningAttempts(userPublicKey)
+ running.forEach { attempt ->
+ val room = database.chatRoomDao().findChatRoomById(attempt.confederationId) ?: return@forEach
+ runCatching { advance(database, room, attempt.id, nostrPrivateKey) }
+ .onFailure { logger.e("Could not resume signing attempt ${attempt.id}", it) }
+ }
+ running.size
+ }
+
+ // ---- the rounds ----------------------------------------------------------------------------
+
+ private suspend fun advance(database: GizaDatabase, room: LocalChatRoom, attemptId: String, nostrPrivateKey: ByteArray) {
+ val attempt = database.confederationCeremonyDao().getAttempt(attemptId)?.takeIf { it.isRunning } ?: return
+ val held = held(database, attempt.confederationId) ?: return
+ val me = attempt.userPublicKey
+ val plan = held.plan
+ val event = Event.fromJson(attempt.eventJson)
+ val message = ByteVector32(event.id)
+
+ // 1. The proposer fixes the selection from the yeses, once there are enough.
+ if (me == attempt.proposerPublicKey && own(database, attempt, ConfederationSigningEvents.SESSION) == null) {
+ val availability = availability(database, attempt, plan)
+ val selection = select(held, availability)
+ if (selection == null) {
+ if (!stillPossible(held, availability)) {
+ return failOut(database, room, attempt, "Not enough admins of enough groups are willing to sign")
+ }
+ return moveTo(database, attempt, ConfederationSigningStage.SELECTING)
+ }
+ val session = ConfederationSigningSession.create(held.keyState, ByteVector32(attempt.id), selection, held.tweaks)
+ .rightOrFail { return failOut(database, room, attempt, "The signing session cannot be made: $it") }
+ publishOwn(database, room, attempt, ConfederationSigningEvents.SESSION,
+ ConfederationSigningEvents.Session(selection.groups, session.dSign.toHex()).encode())
+ }
+ val sent = database.confederationCeremonyDao().getSigningMessage(attempt.id, attempt.proposerPublicKey, ConfederationSigningEvents.SESSION)
+ ?.let { ConfederationSigningEvents.Session.decode(it.payload) }
+ ?: return moveTo(database, attempt, ConfederationSigningStage.SELECTING)
+ val selection = ConfederationSignerSelection(sent.selection)
+ val session = ConfederationSigningSession.create(held.keyState, ByteVector32(attempt.id), selection, held.tweaks)
+ .rightOrFail { return failOut(database, room, attempt, "The proposer's selection is not one this confederation can sign with: $it") }
+ if (!session.check(ByteVector(sent.dSign))) {
+ return failOut(database, room, attempt, "The proposer's signing session is not the one this device derives")
+ }
+ val selected = session.signers.mapNotNull { plan.seatOf(it) }
+ val people = selected.map { it.admin }.distinct()
+ val mine = selected.filter { it.admin == me }
+ val host = { seat: ConfederationRosterBuilder.Seat -> ConfederationRosterBuilder.hostSecretKey(nostrPrivateKey, seat.group, plan.proposal.id) }
+
+ // 2. Each selected role's nonce, made now and held in memory only.
+ if (mine.isNotEmpty() && own(database, attempt, ConfederationSigningEvents.NONCES) == null) {
+ val nonces = mine.associate { seat ->
+ val share = shareOf(held, seat, host(seat)) ?: return failOut(database, room, attempt, "This device's share no longer opens")
+ val signer = ConfederationSigning.generateNonce(session, seat.roleId, share, ByteVector32(RandomInstance.bytes(32)))
+ .rightOrFail { return failOut(database, room, attempt, "A nonce could not be made: $it") }
+ signers[signerKey(me, attempt.id, seat.roleId)] = signer
+ seat.group to signer.publicNonce.toHex()
+ }
+ publishOwn(database, room, attempt, ConfederationSigningEvents.NONCES, ConfederationRitualEvents.encodeByGroup(nonces))
+ }
+ val nonces = perRole(database, attempt, selected, people, ConfederationSigningEvents.NONCES) { ByteVector(it) }
+ ?: return moveTo(database, attempt, ConfederationSigningStage.NONCES)
+ val transcript = ConfederationSigning.transcript(session, nonces)
+ .rightOrFail { return failOut(database, room, attempt, "The nonce transcript cannot be built: $it") }
+
+ // 3. Each selected role confirms the transcript and the event.
+ if (mine.isNotEmpty() && own(database, attempt, ConfederationSigningEvents.CONFIRMATIONS) == null) {
+ val confirmations = mine.associate { seat ->
+ val signer = signers[signerKey(me, attempt.id, seat.roleId)] ?: return failOut(database, room, attempt, RESTARTED)
+ seat.group to ConfederationSigning.confirm(signer, transcript, message, host(seat))
+ .rightOrFail { return failOut(database, room, attempt, "Confirming failed: $it") }.toHex()
+ }
+ publishOwn(database, room, attempt, ConfederationSigningEvents.CONFIRMATIONS, ConfederationRitualEvents.encodeByGroup(confirmations))
+ }
+ val confirmations = perRole(database, attempt, selected, people, ConfederationSigningEvents.CONFIRMATIONS) { ByteVector64(it) }
+ ?: return moveTo(database, attempt, ConfederationSigningStage.CONFIRMING)
+ val certificate = ConfederationSigning.certificate(session, transcript, message, confirmations)
+ .rightOrFail { return failOut(database, room, attempt, "The confirmations cannot be certified: $it") }
+ if (!ConfederationSigning.verifyCertificate(session, transcript, message, certificate)) {
+ return failOut(database, room, attempt, "A confirmation does not verify")
+ }
+
+ // 4. Each selected role's partial: the signer is spent here, whatever happens.
+ if (mine.isNotEmpty() && own(database, attempt, ConfederationSigningEvents.PARTIALS) == null) {
+ val partials = mine.associate { seat ->
+ val signer = signers.remove(signerKey(me, attempt.id, seat.roleId)) ?: return failOut(database, room, attempt, RESTARTED)
+ val share = shareOf(held, seat, host(seat)) ?: return failOut(database, room, attempt, "This device's share no longer opens")
+ seat.group to ConfederationSigning.sign(signer, share, transcript, message, certificate)
+ .rightOrFail { return failOut(database, room, attempt, "Signing failed: $it") }.toHex()
+ }
+ publishOwn(database, room, attempt, ConfederationSigningEvents.PARTIALS, ConfederationRitualEvents.encodeByGroup(partials))
+ }
+ val partials = perRole(database, attempt, selected, people, ConfederationSigningEvents.PARTIALS) { ByteVector32(it) }
+ ?: return moveTo(database, attempt, ConfederationSigningStage.SIGNING)
+
+ // 5. Every group's partial and the signature, on every device.
+ complete(database, room, attempt, held, session, transcript, certificate, message, event, partials)
+ }
+
+ private suspend fun complete(
+ database: GizaDatabase,
+ room: LocalChatRoom,
+ attempt: ConfederationSigningAttempt,
+ held: Held,
+ session: ConfederationSigningSession,
+ transcript: fr.acinq.bitcoin.crypto.confederation.ConfederationNonceTranscript,
+ certificate: ConfederationConfirmationCertificate,
+ message: ByteVector32,
+ event: Event,
+ partials: Map,
+ ) {
+ val groupPartials = session.groups.associateWith { groupId ->
+ ConfederationSigning.aggregateGroup(session, transcript, message, certificate, groupId, partials.filterKeys { it.groupId == groupId })
+ .rightOrFail { culprit -> return failOut(database, room, attempt, "Group ${held.plan.groups.getOrNull(groupId.toInt())?.let { ConfederationManager.nameOf(database, it) }}'s partial does not add up: $culprit") }
+ }
+ val signature = ConfederationSigning.aggregate(session, transcript, message, certificate, groupPartials)
+ .rightOrFail { return failOut(database, room, attempt, "The signature cannot be assembled: $it") }
+ if (!Crypto.verifySignatureSchnorr(message, signature, held.roomKey)) {
+ return failOut(database, room, attempt, "The signature does not verify as the confederation's room")
+ }
+ val signed = Event(event.id, event.pubKey, event.createdAt, event.kind, event.tags, event.content, signature.toHex())
+ update(database, attempt) { it.copy(stage = ConfederationSigningStage.COMPLETE, signedEventJson = signed.toJson()) }
+ database.groupSignedEventDao().record(GroupSignedEvent.fromEvent(signed, chatRoomId = held.confederation.id))
+ announce(
+ database, attempt,
+ when (signed.kind) {
+ MetadataEvent.KIND -> ChatMessage.TYPE_GROUP_PROFILE_SIGNED
+ ConfederationCharterEvent.KIND -> ChatMessage.TYPE_CONFEDERATION_FORMED
+ else -> ChatMessage.TYPE_GROUP_POST_SIGNED
+ },
+ "The confederation signed ${describe(signed)}",
+ )
+ // The charter is the confederation's public statement: filed as Part A's events are, and
+ // owed to relays by the device that proposed it (D9), where the member groups' devices hear it.
+ if (signed.kind == ConfederationCharterEvent.KIND) {
+ ConfederationManager.record(database, signed)
+ if (attempt.proposerPublicKey == attempt.userPublicKey) database.confederationDao().markOwn(signed.id, attempt.id)
+ }
+ logger.i("Confederation ${held.confederation.id.take(12)} signed ${signed.id.take(8)}")
+ }
+
+ // ---- helpers ---------------------------------------------------------------------------
+
+ /** The roles available to sign, by role: true for a yes, false for a no. Missing for a person who has not said. */
+ private suspend fun availability(database: GizaDatabase, attempt: ConfederationSigningAttempt, plan: Plan): Map =
+ plan.people.flatMap { person ->
+ val said = database.confederationCeremonyDao().getSigningMessage(attempt.id, person, ConfederationSigningEvents.AVAILABILITY)
+ ?.let { ConfederationRitualEvents.decodeByGroup(it.payload) } ?: return@flatMap emptyList()
+ plan.seatsOf(person).mapNotNull { seat -> said[seat.group]?.let { seat.roleId to (it == ConfederationSigningEvents.YES) } }
+ }.toMap()
+
+ /**
+ * The first `T` groups, in roster order, with at least `t_g` yeses, and in each the `t_g` lowest
+ * admins who said yes. Null while that many are not yet in.
+ */
+ private fun select(held: Held, availability: Map): ConfederationSignerSelection? {
+ val groups = held.roster.groups.mapNotNull { group ->
+ val yes = group.roles.map { it.id }.filter { availability[it] == true }.map { it.adminId }.sorted()
+ if (yes.size >= group.threshold) group.groupId to yes.take(group.threshold).toSet() else null
+ }
+ if (groups.size < held.roster.outerThreshold) return null
+ return ConfederationSignerSelection(groups.take(held.roster.outerThreshold).toMap())
+ }
+
+ /** Whether enough roles that have not said no remain for a selection to be possible. */
+ private fun stillPossible(held: Held, availability: Map): Boolean =
+ held.roster.groups.count { group -> group.roles.count { availability[it.id] != false } >= group.threshold } >= held.roster.outerThreshold
+
+ private suspend fun perRole(
+ database: GizaDatabase,
+ attempt: ConfederationSigningAttempt,
+ selected: List,
+ people: List,
+ kind: Kind,
+ read: (String) -> T,
+ ): Map? {
+ val byPerson = people.associateWith { person ->
+ val message = database.confederationCeremonyDao().getSigningMessage(attempt.id, person, kind) ?: return null
+ ConfederationRitualEvents.decodeByGroup(message.payload) ?: return null
+ }
+ return selected.associate { seat -> seat.roleId to read(byPerson.getValue(seat.admin)[seat.group] ?: return null) }
+ }
+
+ /** This device's share for [seat], opened from the recovery package it kept. */
+ private fun shareOf(held: Held, seat: ConfederationRosterBuilder.Seat, host: fr.acinq.bitcoin.PrivateKey): ConfederationShare? {
+ val hex = ConfederationRitualEvents.decodeByGroup(held.confederation.recoveryPackages)?.get(seat.group) ?: return null
+ val recovery = (ConfederationRecoveryPackage.fromData(ByteVector(hex), host) as? Either.Right)?.value ?: return null
+ return (recovery.open(host, held.keyState) as? Either.Right)?.value
+ }
+
+ private suspend fun publishAvailability(database: GizaDatabase, room: LocalChatRoom, attempt: ConfederationSigningAttempt, held: Held, available: Boolean) {
+ if (own(database, attempt, ConfederationSigningEvents.AVAILABILITY) != null) return
+ val value = if (available) ConfederationSigningEvents.YES else ConfederationSigningEvents.NO
+ publishOwn(
+ database, room, attempt, ConfederationSigningEvents.AVAILABILITY,
+ ConfederationRitualEvents.encodeByGroup(held.plan.seatsOf(attempt.userPublicKey).associate { it.group to value }),
+ )
+ }
+
+ private suspend fun own(database: GizaDatabase, attempt: ConfederationSigningAttempt, kind: Kind) =
+ database.confederationCeremonyDao().getSigningMessage(attempt.id, attempt.userPublicKey, kind)
+
+ private suspend fun publishOwn(database: GizaDatabase, room: LocalChatRoom, attempt: ConfederationSigningAttempt, kind: Kind, content: String) {
+ broadcast(database, room, attempt, kind, content)
+ database.confederationCeremonyDao().insertSigningMessage(ConfederationSigningMessage(attempt.id, attempt.userPublicKey, kind, content))
+ }
+
+ /** Queues a rumor for the confederation's Marmot room, encrypted to the room as a group event. */
+ private suspend fun broadcast(database: GizaDatabase, room: LocalChatRoom, attempt: ConfederationSigningAttempt, kind: Kind, content: String) {
+ val tags = arrayOf(ConfederationSigningEvents.sessionTag(attempt.id))
+ val createdAt = Clock.System.now().epochSeconds
+ val id = EventHasher.hashId(attempt.userPublicKey, createdAt, kind, tags, content)
+ database.marmotInnerEventDao().upsert(
+ MarmotInnerEvent(
+ id = id,
+ publicKey = attempt.userPublicKey,
+ kind = kind,
+ createdAt = Instant.fromEpochSeconds(createdAt),
+ tags = tags,
+ content = content,
+ chatRoomId = room.chatRoom.id,
+ )
+ )
+ }
+
+ private suspend fun replayStoredMessages(database: GizaDatabase, held: Held, attempt: ConfederationSigningAttempt) {
+ database.marmotInnerEventDao()
+ .getByChatRoomAndKinds(attempt.confederationId, (ConfederationSigningEvents.ALL - ConfederationSigningEvents.PROPOSAL).toList())
+ .filter { ConfederationSigningEvents.parseSessionId(it.tags) == attempt.id }
+ .forEach { stored ->
+ val event = Event(stored.id, stored.publicKey, stored.createdAt.epochSeconds, stored.kind, stored.tags, stored.content, "")
+ if (!record(database, held, database.confederationCeremonyDao().getAttempt(attempt.id) ?: return, event)) return
+ }
+ }
+
+ private inline fun Either.rightOrFail(onLeft: (String) -> Nothing): T = when (this) {
+ is Either.Right -> value
+ is Either.Left -> onLeft(value.message ?: value.toString())
+ }
+
+ private suspend fun update(
+ database: GizaDatabase,
+ attempt: ConfederationSigningAttempt,
+ transform: (ConfederationSigningAttempt) -> ConfederationSigningAttempt,
+ ): ConfederationSigningAttempt {
+ val current = database.confederationCeremonyDao().getAttempt(attempt.id) ?: attempt
+ val next = transform(current).copy(updatedAt = Clock.System.now())
+ database.confederationCeremonyDao().upsertAttempt(next)
+ return next
+ }
+
+ private suspend fun moveTo(database: GizaDatabase, attempt: ConfederationSigningAttempt, stage: ConfederationSigningStage) {
+ if (attempt.stage != stage) update(database, attempt) { it.copy(stage = stage) }
+ }
+
+ private suspend fun failOut(database: GizaDatabase, room: LocalChatRoom, attempt: ConfederationSigningAttempt, reason: String) {
+ broadcast(database, room, attempt, ConfederationSigningEvents.FAILURE, reason)
+ fail(database, attempt, reason)
+ }
+
+ private suspend fun fail(database: GizaDatabase, attempt: ConfederationSigningAttempt, reason: String) {
+ val current = database.confederationCeremonyDao().getAttempt(attempt.id) ?: attempt
+ if (!current.isRunning) return
+ // Whatever this device was holding for the attempt goes with it.
+ signers.keys.filter { it.startsWith("${current.userPublicKey}/${current.id}/") }.forEach { signers.remove(it)?.abort() }
+ update(database, current) { it.copy(stage = ConfederationSigningStage.FAILED, failureReason = reason) }
+ logger.w("Signing attempt ${attempt.id} failed: $reason")
+ announce(database, current, ChatMessage.TYPE_CONFEDERATION_SIGNING_FAILED, "The confederation did not sign: $reason")
+ }
+
+ private fun describe(event: Event): String = when (event.kind) {
+ MetadataEvent.KIND -> "its profile"
+ TextNoteEvent.KIND -> "a post"
+ ConfederationCharterEvent.KIND -> "its charter"
+ else -> "an event of kind ${event.kind}"
+ }
+
+ private suspend fun announce(database: GizaDatabase, attempt: ConfederationSigningAttempt, type: String, content: String) {
+ database.chatMessageDao().upsert(
+ ChatMessage(
+ // The attempt, so the line opens it. Not a FROST session: the column has no key
+ // onto one, and the transcript reads it by the line's type.
+ frostSigningSessionId = attempt.id,
+ senderPublicKey = attempt.proposerPublicKey,
+ isUserMessage = false,
+ giftWrapPayloadId = null,
+ marmotGroupEventId = null,
+ marmotInnerEventId = null,
+ chatRoomId = attempt.confederationId,
+ content = content,
+ messageType = type,
+ )
+ )
+ }
+
+ /** For tests: forget every live signer, as a restart would. */
+ internal fun forgetSignersForTest() {
+ signers.values.forEach { it.abort() }
+ signers.clear()
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/FrostSigningManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/FrostSigningManager.kt
index a0400237..d1534267 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/FrostSigningManager.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/FrostSigningManager.kt
@@ -45,6 +45,7 @@ import mobi.giza.compose.database.model.types.ShareGenerationState
import mobi.giza.compose.extensions.toHex
import mobi.giza.compose.nostr.dkg.DkgRitualEvents
import mobi.giza.compose.nostr.frost.FrostSigningEvents
+import mobi.giza.compose.nostr.inbox.InboxReplyManifest
import mobi.giza.compose.nostr.frost.GovernanceStatementEvent
import mobi.giza.compose.nostr.frost.GroupKeyStateEvent
@@ -690,20 +691,6 @@ object FrostSigningManager {
return declined
}
- // Where the group receives direct messages, listing a relay that is not a
- // public wss:// address: declined on arrival for the same reason, so the
- // group's decision to receive is never spent on relays nobody can reach.
- // docs/group-threshold-ecdh.md, D8.
- GroupDmRelayRefusal.of(unsignedEvents)?.let { why ->
- logger.w("Signing proposal $sessionId $why; declining")
- val declined = newSession(sessionId, localChatRoom, innerEvent, userPublicKey, key, signerId, path, generation ?: 0, participantCount = n)
- .copy(signDeclinedAt = Clock.System.now())
- database.frostSigningSessionDao().upsert(declined)
- database.frostSigningSessionDao().upsertItems(itemsOver(sessionId, unsignedEvents))
- announceStarted(database, declined)
- return declined
- }
-
// A message the group would send: every signer reads it first, and declines one
// it cannot read or that says different things to different people. One still
// waiting on a recipient's key is held, stored, and asked once the key is made.
@@ -766,6 +753,25 @@ object FrostSigningManager {
return declined
}
+ // The group's inbox: an announcement of a key its admins did not make together, or
+ // of one since replaced, or relays a stranger could not reach, is declined before
+ // anybody is asked. docs/group-inbox.md, D5.
+ // A reply from the group's inbox carries its manifest beside the seals (D11), kept so
+ // approval can read the reply again and the signed seals can be sent.
+ val inboxManifest = InboxReplyManifest.sealedIn(innerEvent.tags)
+ if (InboxRefusal.involves(unsignedEvents)) {
+ InboxRefusal.of(database, localChatRoom, userPublicKey, unsignedEvents, inboxManifest)?.let { why ->
+ logger.w("Signing proposal $sessionId: $why")
+ val declined = newSession(sessionId, localChatRoom, innerEvent, userPublicKey, key, signerId, path, generation ?: 0, participantCount = n)
+ .copy(signDeclinedAt = Clock.System.now())
+ database.frostSigningSessionDao().upsert(declined)
+ database.frostSigningSessionDao().upsertItems(itemsOver(sessionId, unsignedEvents))
+ InboxRefusal.remember(database, sessionId, localChatRoom.chatRoom.id, why, inboxManifest)
+ announceStarted(database, declined)
+ return declined
+ }
+ }
+
// A share of the generation the proposal names, or a refusal said out loud.
// Signing with any other generation's share would put a partial signature
// behind the wrong public share -- it cannot aggregate -- and staying
@@ -811,6 +817,9 @@ object FrostSigningManager {
confederation?.let { ConfederationRefusal.remember(database, sessionId, it, null) }
// Read, so filed: every admin's device sees what the group is sending (D12).
groupDm?.let { GroupDmSender.record(database, session, localChatRoom.chatRoom.id, it.rumor, it.manifest) }
+ if (inboxManifest != null && InboxRefusal.involves(unsignedEvents)) {
+ InboxRefusal.remember(database, sessionId, localChatRoom.chatRoom.id, null, inboxManifest)
+ }
announceStarted(database, session)
logger.i(
@@ -1090,6 +1099,32 @@ object FrostSigningManager {
)
}
+ /**
+ * The one inbox question a device answers for its owner: the group's announcement of the
+ * key a rotation made, once the group has announced an inbox before and this device holds
+ * the new key. docs/group-inbox.md, D5.
+ */
+ private suspend fun announcesItsRotatedInbox(database: GizaDatabase, session: FrostSigningSession): Boolean {
+ val current = database.frostSigningSessionDao().getSessionById(session.id) ?: return false
+ if (current.signApprovedAt != null || current.signDeclinedAt != null) return false
+ if (current.stage == FrostSigningStage.COMPLETE || current.stage == FrostSigningStage.FAILED) return false
+ val room = database.chatRoomDao().findChatRoomById(current.chatRoomId) ?: return false
+ return InboxRefusal.vouchesFor(database, room, current, database.frostSigningSessionDao().getItems(current.id))
+ }
+
+ /** The inbox refusal that applies to [session] now. docs/group-inbox.md, D5. */
+ private suspend fun inboxRefusalNow(
+ database: GizaDatabase,
+ localChatRoom: LocalChatRoom,
+ session: FrostSigningSession,
+ items: List
+ ): String? {
+ if (session.subject != FrostSigningSubject.EVENTS) return null
+ val events = items.mapNotNull { Event.fromJsonOrNull(it.unsignedEventJson) }
+ if (!InboxRefusal.involves(events)) return null
+ return InboxRefusal.of(database, localChatRoom, session.userPublicKey, events, database.groupInboxDao().getSigning(session.id)?.manifest)
+ }
+
/** Whether [session] is waiting on this device and is a wallet's to sign. */
private suspend fun declinesAsWallet(database: GizaDatabase, session: FrostSigningSession): Boolean =
session.signApprovedAt == null && session.signDeclinedAt == null &&
@@ -1112,11 +1147,6 @@ object FrostSigningManager {
session.subject == FrostSigningSubject.EVENTS &&
items.any { item -> Event.fromJsonOrNull(item.unsignedEventJson)?.let(GroupStatementRefusal::of) != null }
- /** A 10050 [GroupDmRelayRefusal] declines. docs/group-threshold-ecdh.md, D8. */
- private fun isRefusedRelayList(session: FrostSigningSession, items: List): Boolean =
- session.subject == FrostSigningSubject.EVENTS &&
- items.any { item -> Event.fromJsonOrNull(item.unsignedEventJson)?.let(GroupDmRelayRefusal::of) != null }
-
/**
* The confederation refusal that applies to [session] now, read again from what it
* carried when it arrived. docs/confederation.md, D6.
@@ -1471,6 +1501,15 @@ object FrostSigningManager {
logger.e("Signed session ${session.id} but could not publish its change", e)
}
+ // The group's inbox announced: its key's state moves, and the device that
+ // proposed the announcement owes it to relays. docs/group-inbox.md, D7.
+ try {
+ InboxAnnouncements.onSigned(database, session, signedEvents)
+ InboxReplies.onSigned(database, session, signedEvents)
+ } catch (e: Throwable) {
+ logger.e("Signed session ${session.id} but could not file its inbox announcement", e)
+ }
+
// A confederation event: filed, and owed to relays by the device that
// proposed it. docs/confederation.md, D9.
try {
@@ -1487,14 +1526,6 @@ object FrostSigningManager {
logger.e("Signed session ${session.id} but could not wrap its message", e)
}
- // Where the group receives messages: owed to relays by the device that
- // proposed it. docs/group-threshold-ecdh.md, D8.
- try {
- GroupDmRelays.onSigned(database, session, signedEvents)
- } catch (e: Throwable) {
- logger.e("Signed session ${session.id} but could not file its message relays", e)
- }
-
announce(
database = database,
session = session,
@@ -2143,6 +2174,20 @@ object FrostSigningManager {
}
}
+ /**
+ * Takes another pass at every open session in [localChatRoom] once an inbox key ceremony has
+ * finished here (docs/group-inbox.md, D5): an announcement of the key it made, proposed
+ * before this device had made it, can now be vouched for or asked about.
+ */
+ suspend fun resumeInboxAnnouncements(database: GizaDatabase, localChatRoom: LocalChatRoom, userPublicKey: HexKey) {
+ database.frostSigningSessionDao().getOpenUnansweredSessionsFor(userPublicKey)
+ .filter { it.chatRoomId == localChatRoom.chatRoom.id }
+ .forEach { session ->
+ approveIfVouched(database, session)
+ advance(database, localChatRoom, session.id)
+ }
+ }
+
/**
* Signs every open key state this user's device can now vouch for and has not
* been answered about -- what a build that asked about them left waiting. Run
@@ -2162,7 +2207,7 @@ object FrostSigningManager {
/** Approves [session] on its owner's behalf when [signsAsItsOwnKeyState] says this device can. */
private suspend fun approveIfVouched(database: GizaDatabase, session: FrostSigningSession): Boolean {
- if (!signsAsItsOwnKeyState(database, session)) return false
+ if (!signsAsItsOwnKeyState(database, session) && !announcesItsRotatedInbox(database, session)) return false
logger.i("Session ${session.id} is a key state this device can vouch for; signing")
update(database, session) { it.copy(signApprovedAt = Clock.System.now()) }
return true
@@ -2302,14 +2347,6 @@ object FrostSigningManager {
return
}
- // And for a relay list a member could not have been asked about.
- if (isRefusedRelayList(session, items)) {
- logger.w("Session $sessionId signs a message relay list with a relay nobody can reach; declining")
- update(database, session) { it.copy(signDeclinedAt = Clock.System.now()) }
- advance(database, localChatRoom, sessionId)
- return
- }
-
// Checked again rather than trusted from arrival: the group's admins can change
// while a member decides, and the seal has to hold the ones it has when it signs.
// docs/confederation.md, D6.
@@ -2323,6 +2360,16 @@ object FrostSigningManager {
return
}
+ // And the inbox's, checked again: a newer key can be made, or the admins change,
+ // while a member decides. docs/group-inbox.md, D5.
+ inboxRefusalNow(database, localChatRoom, session, items)?.let { why ->
+ logger.w("Session $sessionId: $why")
+ InboxRefusal.remember(database, sessionId, localChatRoom.chatRoom.id, why)
+ update(database, session) { it.copy(signDeclinedAt = Clock.System.now()) }
+ advance(database, localChatRoom, sessionId)
+ return
+ }
+
update(database, session) { it.copy(signApprovedAt = Clock.System.now()) }
logger.i("Session $sessionId: signing approved")
@@ -2541,7 +2588,9 @@ object FrostSigningManager {
FrostSigningEvents.PROPOSAL,
FrostSigningEvents.encodeProposal(unsigned),
// What a confederation event is checked with goes again with it.
- ConfederationRefusal.carriedTagsFor(database, sessionId)
+ ConfederationRefusal.carriedTagsFor(database, sessionId) +
+ // And a reply's manifest (docs/group-inbox.md, D11).
+ InboxRefusal.carriedTagsFor(database, sessionId)
)
}
@@ -2807,11 +2856,12 @@ object FrostSigningManager {
) {
val items = database.frostSigningSessionDao().getItems(session.id)
val confederationReason = ConfederationRefusal.reasonFor(database, session.id)
+ val inboxReason = InboxRefusal.reasonFor(database, session.id)
val reason = when {
confederationReason != null -> confederationReason
+ inboxReason != null -> inboxReason
isWalletSession(session, items) -> WalletRefusal.REASON
isUnshowableSession(session, items) -> GroupStatementRefusal.REASON
- isRefusedRelayList(session, items) -> GroupDmRelayRefusal.REASON
session.subject == FrostSigningSubject.EVENTS && GroupDmRefusal.involvesItems(items) ->
GroupDmRefusal.reasonFor(database, session.chatRoomId, session.userPublicKey)
!holdsShareFor(database, session) -> GENERATION_REFUSAL
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceFollowThrough.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceFollowThrough.kt
index 6e9bcbc3..63438c11 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceFollowThrough.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceFollowThrough.kt
@@ -58,6 +58,12 @@ object GovernanceFollowThrough {
/** One pass over everything owed. */
suspend fun pass(database: GizaDatabase, keyPair: KeyPair) = mutex.withLock {
rotationsOwed(database).forEach { proposal -> rotateAway(database, keyPair, proposal) }
+ // The group's inbox key, made over admins the room no longer has (docs/group-inbox.md,
+ // D14). After the share rotation above, which its refusal waits on.
+ keyPair.privKey?.let { secret ->
+ runCatching { InboxRotation.pass(database, keyPair.pubKey.toHexKey(), secret) }
+ .onFailure { if (it is CancellationException) throw it; logger.w("An inbox rotation pass failed: ${it.message}") }
+ }
if (!ExperimentalFeatures.shareRefresh) return@withLock
val me = keyPair.pubKey.toHexKey()
val privateKey = keyPair.privKey ?: return@withLock
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupDmReceiver.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupDmReceiver.kt
index 9faa21b9..ac477406 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupDmReceiver.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupDmReceiver.kt
@@ -65,6 +65,13 @@ object GroupDmReceiver {
return ShareGenerations.active(database, key).signerIds.containsKey(userPublicKey)
}
+ /** Whether one of the group inbox's keys this device holds opens [wrap] (docs/group-inbox.md). */
+ private suspend fun opensWithInboxKey(database: GizaDatabase, roomId: HexKey, userPublicKey: HexKey, wrap: Event): Boolean {
+ if (!ExperimentalFeatures.groupInbox) return false
+ val secrets = database.inboxKeyDao().getKeys(roomId, userPublicKey).mapNotNull { it.secretKey?.hexToByteArray() }
+ return secrets.isNotEmpty() && mobi.giza.compose.nostr.inbox.InboxWrap.open(wrap, secrets) != null
+ }
+
/** The room a wrap is addressed to, among those this device reads for. */
suspend fun roomFor(database: GizaDatabase, wrap: Event, userPublicKey: HexKey): HexKey? {
if (wrap.kind != GiftWrapEvent.KIND) return null
@@ -78,6 +85,13 @@ object GroupDmReceiver {
*/
suspend fun receive(database: GizaDatabase, wrap: Event, userPublicKey: HexKey, nostrPrivateKey: ByteArray): Boolean {
val roomId = roomFor(database, wrap, userPublicKey) ?: return false
+ // The group's NIP-4E inbox key opens what a decoupled sender wrote, at once and with no
+ // round: it is tried first, and a round is opened only for what it cannot open
+ // (docs/group-threshold-ecdh.md, *Against the NIP-4E plan*).
+ if (opensWithInboxKey(database, roomId, userPublicKey, wrap)) {
+ GroupInboxManager.receive(database, wrap, userPublicKey)
+ return true
+ }
// The wrap is its own evidence (D5): signed by its pubkey and addressed to the group.
if (!Evidence.allows(EcdhPurpose.WRAP, wrap.pubKey, wrap, roomId)) return true
database.groupDmDao().insertWrap(
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupDmRefusal.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupDmRefusal.kt
index b2d97392..62dd1af7 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupDmRefusal.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupDmRefusal.kt
@@ -53,10 +53,20 @@ object GroupDmRefusal {
data object Waiting : Verdict
}
- fun involves(events: List): Boolean = events.any { it.kind == SealEvent.KIND }
+ /**
+ * A seal this refusal is about: every one that does not name an inbox key. The group
+ * inbox's replies (docs/group-inbox.md, D10) are seals too, and name the inbox key they
+ * come from in one well-formed `n` tag; those are `InboxRefusal`'s. Split on the inbox's own
+ * reading of the tag, so no seal falls to neither -- a malformed `n` lands here, and check 2
+ * declines it.
+ */
+ fun isOurs(event: Event): Boolean =
+ event.kind == SealEvent.KIND && mobi.giza.compose.nostr.inbox.InboxSeal.encryptionKeyOf(event.tags) == null
+
+ fun involves(events: List): Boolean = events.any(::isOurs)
fun involvesItems(items: List): Boolean =
- items.any { Event.fromJsonOrNull(it.unsignedEventJson)?.kind == SealEvent.KIND }
+ items.any { Event.fromJsonOrNull(it.unsignedEventJson)?.let(::isOurs) == true }
suspend fun check(
database: GizaDatabase,
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupDmRelays.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupDmRelays.kt
index 2be72c92..5aa1c02f 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupDmRelays.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupDmRelays.kt
@@ -4,7 +4,6 @@ import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import mobi.giza.compose.database.GizaDatabase
import mobi.giza.compose.database.model.FrostSigningSession
-import mobi.giza.compose.database.model.GroupDmOutbound
import mobi.giza.compose.database.model.GroupSignedEvent
import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
import mobi.giza.compose.nostr.RelayUrlInput
@@ -39,7 +38,7 @@ object GroupDmRelays {
* Asks the group to sign [relays] as where it receives messages.
*
* @throws IllegalArgumentException when a relay is not one [RelayUrlInput] accepts: the
- * signers would decline it ([GroupDmRelayRefusal]), so it is not proposed.
+ * signers would decline it (`InboxRefusal.RELAYS_SHAPE`), so it is not proposed.
*/
suspend fun propose(database: GizaDatabase, localChatRoom: LocalChatRoom, userPublicKey: HexKey, relays: List): FrostSigningSession {
val normalised = relaysIn(tagsFor(relays)) ?: throw IllegalArgumentException("Every relay has to be a public wss:// address")
@@ -62,48 +61,4 @@ object GroupDmRelays {
/** Where the group receives messages, or null while it has not opened them. */
suspend fun relaysOf(database: GizaDatabase, chatRoomId: HexKey): List? =
signedListOf(database, chatRoomId)?.let { relaysIn(it.tags) }
-
- /** The relays a signed 10050 is sent to: the publish set, and the relays it names. */
- fun publishTargets(listed: List): List =
- (Relays.eventPublishRelaySet.map { it.url } + listed).distinct()
-
- /**
- * A 10050 the group just signed: owed to relays by the device that proposed it, through
- * [GroupDmPublisher], with backoff. Any member can send it again from the broadcast screen.
- */
- suspend fun onSigned(database: GizaDatabase, session: FrostSigningSession, signedEvents: List) {
- if (!session.isCoordinator()) return
- signedEvents.filter { it.kind == KIND && it.pubKey.equals(session.chatRoomId, ignoreCase = true) }.forEach { signed ->
- val listed = relaysIn(signed.tags) ?: return@forEach
- database.groupDmDao().insertOutbound(
- GroupDmOutbound(
- signingSessionId = session.id,
- sealId = signed.id,
- chatRoomId = session.chatRoomId,
- recipient = session.chatRoomId,
- relays = publishTargets(listed).joinToString(","),
- wrapJson = signed.toJson(),
- )
- )
- }
- }
-}
-
-/**
- * A 10050 the group is asked to sign whose relays are not all public `wss://` addresses
- * (D8 of docs/group-threshold-ecdh.md). Declined out loud, in the four places every refusal
- * sits, for the reason a wallet's is: a device signs only what it can check, and a relay
- * list senders cannot reach is the group's mail going nowhere.
- */
-object GroupDmRelayRefusal {
- const val REASON = "Giza doesn't sign a list of message relays that are not public wss:// addresses"
-
- fun of(event: Event): String? =
- if (event.kind == GroupDmRelays.KIND && GroupDmRelays.relaysIn(event.tags) == null) {
- "lists a message relay that is not a public wss:// address"
- } else {
- null
- }
-
- fun of(events: List): String? = events.firstNotNullOfOrNull(::of)
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupInboxManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupInboxManager.kt
new file mode 100644
index 00000000..bfa4ff26
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupInboxManager.kt
@@ -0,0 +1,133 @@
+package mobi.giza.compose.managers
+
+import co.touchlab.kermit.Logger
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
+import kotlin.time.Clock
+import mobi.giza.compose.database.GizaDatabase
+import mobi.giza.compose.database.model.ChatMessage
+import mobi.giza.compose.database.model.GroupInboxMessage
+import mobi.giza.compose.database.model.GroupInboxWrap
+import mobi.giza.compose.database.model.InboxKey
+import mobi.giza.compose.nostr.inbox.InboxAnnouncement
+import mobi.giza.compose.nostr.inbox.InboxConversation
+import mobi.giza.compose.nostr.inbox.InboxSeal
+import mobi.giza.compose.nostr.inbox.InboxWrap
+
+/**
+ * Reading a group's inbox (docs/group-inbox.md, D8 and D9): every gift wrap addressed to a group
+ * this device holds an inbox key for is put in the ledger, opened if any key it holds opens it,
+ * and filed as one message per rumor.
+ *
+ * Its own path, beside the personal inbox and never inside it. The personal path tries only the
+ * active identity's key and files what it opens into the admin's own direct messages; the
+ * group's correspondents are not the admin's, and nothing here writes a `GiftWrapMessage` or a
+ * `NostrEvent`.
+ */
+object GroupInboxManager {
+ private val logger = Logger.withTag("GroupInboxManager")
+
+ /** The secrets this identity can open [chatRoomId]'s mail with, newest generation first. */
+ private suspend fun openers(database: GizaDatabase, chatRoomId: String, userPublicKey: HexKey): List =
+ database.inboxKeyDao().getKeys(chatRoomId, userPublicKey).filter { it.secretKey != null }
+
+ /**
+ * Files [wrap], heard on a relay, for whichever of [userPublicKey]'s groups it is addressed
+ * to. Returns the message it filed, or null when it filed none: not a group's, already
+ * known, or not one this device can open yet -- which is kept and counted, not dropped.
+ */
+ suspend fun receive(database: GizaDatabase, wrap: Event, userPublicKey: HexKey): GroupInboxMessage? {
+ if (wrap.kind != InboxWrap.KIND) return null
+ val tagged = InboxWrap.recipientOf(wrap)?.lowercase() ?: return null
+ // The group's npub, as #2361 has it; or one of its inbox keys, as an app that only
+ // encrypts to the announced key tags it.
+ val roomId = if (openers(database, tagged, userPublicKey).isNotEmpty()) {
+ tagged
+ } else {
+ database.inboxKeyDao().findHeldByPublicKey(userPublicKey, tagged)?.chatRoomId ?: return null
+ }
+ val keys = openers(database, roomId, userPublicKey)
+ if (keys.isEmpty()) return null
+
+ val inserted = database.groupInboxDao().insertWrap(
+ GroupInboxWrap(id = wrap.id, chatRoomId = roomId, wrapJson = wrap.toJson(), wrapCreatedAt = wrap.createdAt)
+ )
+ if (inserted < 0 && database.groupInboxDao().getWrap(wrap.id)?.openedGeneration != null) return null
+ return open(database, roomId, userPublicKey, wrap, keys)
+ }
+
+ /**
+ * Tries every wrap in [chatRoomId] no key has opened yet, with the keys held now: what a key
+ * that arrives after the mail -- a ceremony finishing, a restore -- is for. Returns how many
+ * it opened.
+ */
+ suspend fun reopen(database: GizaDatabase, chatRoomId: String, userPublicKey: HexKey): Int {
+ val keys = openers(database, chatRoomId, userPublicKey)
+ if (keys.isEmpty()) return 0
+ return database.groupInboxDao().getUnopenedWraps(chatRoomId).count { row ->
+ val wrap = Event.fromJsonOrNull(row.wrapJson) ?: return@count false
+ open(database, chatRoomId, userPublicKey, wrap, keys) != null
+ }
+ }
+
+ private suspend fun open(database: GizaDatabase, roomId: String, userPublicKey: HexKey, wrap: Event, keys: List): GroupInboxMessage? {
+ val secrets = keys.map { it.secretKey!!.hexToByteArray() }
+ val (index, seal) = InboxWrap.open(wrap, secrets) ?: return null
+ val key = keys[index]
+
+ // The sender's own 10044, if this device has heard it, for a seal from a decoupled
+ // sender whose app wrote no `n` tag.
+ val senderAnnounced = database.nostrEventDao().getNostrEventByPublicKeyAndKind(seal.pubKey, InboxAnnouncement.KEY_KIND)
+ ?.let { InboxAnnouncement.announcedKeyOf(it.toEvent()) }
+ val opened = InboxSeal.open(seal, secrets[index], senderAnnounced) ?: run {
+ logger.w("Wrap ${wrap.id.take(8)} to ${roomId.take(8)} opened, but its seal did not; leaving it counted")
+ return null
+ }
+ val rumor = opened.rumor
+ val participants = InboxConversation.participantsOf(rumor, roomId)
+ val message = GroupInboxMessage(
+ chatRoomId = roomId,
+ rumorId = rumor.id,
+ wrapId = wrap.id,
+ conversationId = InboxConversation.idOf(participants),
+ participants = participants.joinToString(","),
+ senderPublicKey = rumor.pubKey,
+ kind = rumor.kind,
+ rumorJson = InboxSeal.rumorJson(rumor),
+ createdAt = rumor.createdAt,
+ generation = key.generation,
+ outgoing = rumor.pubKey.equals(roomId, ignoreCase = true),
+ )
+ database.groupInboxDao().insertMessage(message)
+ database.groupInboxDao().markOpened(wrap.id, key.generation)
+ return database.groupInboxDao().getMessage(roomId, rumor.id)
+ }
+
+ /**
+ * Forgets [chatRoomId]'s inbox on this device when [userPublicKey] is no longer one of its
+ * admins (docs/group-inbox.md, D14): the keys' secrets and every message they opened. Said
+ * in the room, once. Cooperation, not enforcement: a device that does not run this keeps
+ * what it had, and the rotation that follows is what the group can do about it.
+ */
+ suspend fun forgetIfNotAdmin(database: GizaDatabase, chatRoomId: String, userPublicKey: HexKey, stillAdmin: Boolean) {
+ if (stillAdmin) return
+ if (openers(database, chatRoomId, userPublicKey).isEmpty()) return
+ database.inboxKeyDao().wipeKeys(chatRoomId, userPublicKey, Clock.System.now())
+ database.groupInboxDao().deleteMessages(chatRoomId)
+ database.groupInboxDao().deleteWraps(chatRoomId)
+ database.chatMessageDao().upsert(
+ ChatMessage(
+ senderPublicKey = userPublicKey,
+ isUserMessage = true,
+ giftWrapPayloadId = null,
+ marmotGroupEventId = null,
+ marmotInnerEventId = null,
+ chatRoomId = chatRoomId,
+ content = "This device forgot the group's inbox key and its mail, since you are no longer an admin.",
+ messageType = ChatMessage.TYPE_INBOX_FORGOTTEN,
+ )
+ )
+ logger.i("Forgot the inbox of ${chatRoomId.take(8)}: no longer an admin")
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupInboxPublisher.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupInboxPublisher.kt
new file mode 100644
index 00000000..0e53d98b
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GroupInboxPublisher.kt
@@ -0,0 +1,107 @@
+package mobi.giza.compose.managers
+
+import co.touchlab.kermit.Logger
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import kotlin.time.Clock
+import kotlin.time.Duration
+import kotlin.time.Duration.Companion.milliseconds
+import kotlin.time.Duration.Companion.minutes
+import kotlinx.coroutines.CancellationException
+import kotlinx.coroutines.TimeoutCancellationException
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.flow.collectLatest
+import kotlinx.coroutines.flow.take
+import kotlinx.coroutines.withTimeout
+import mobi.giza.compose.database.model.GroupInboxPublication
+import mobi.giza.compose.database.model.NostrEvent
+import mobi.giza.compose.network.dto.RelayDTO
+import mobi.giza.compose.network.relays.EventPublishTransport
+import mobi.giza.compose.network.relays.RelayPool
+import mobi.giza.compose.network.sockets.NostrIncomingMessage
+import mobi.giza.compose.nostr.Relays
+import mobi.giza.compose.repository.GroupInboxRepository
+
+/**
+ * Sends what this device owes relays for its groups' inboxes (docs/group-inbox.md, D7 and D10):
+ * the announcements it asked the group to sign, and the gift wraps around the replies it
+ * proposed. Keeps trying until a relay takes each, backing off from a minute to half an hour, as
+ * `ConfederationPublisher` does for its events and for the same reason: never through a
+ * `NostrEvent` row.
+ */
+class GroupInboxPublisher(
+ private val repository: GroupInboxRepository,
+ private val transport: EventPublishTransport,
+ private val firstRetry: Duration = 1.minutes,
+ private val lastRetry: Duration = 30.minutes,
+) {
+ private val logger = Logger.withTag("GroupInboxPublisher")
+
+ /** Runs until cancelled. */
+ suspend fun run() {
+ repository.observeUnpublished().collectLatest { owed ->
+ var wait = firstRetry
+ var remaining = owed
+ while (remaining.isNotEmpty()) {
+ remaining = remaining.filterNot { publish(it) }
+ if (remaining.isEmpty()) break
+ logger.w("${remaining.size} inbox event(s) not yet taken by any relay; trying again in $wait")
+ delay(wait)
+ wait = minOf(wait * 2, lastRetry)
+ }
+ }
+ }
+
+ /**
+ * Sends [owed] to its relays. An announcement goes to the publish set too, so a stranger's
+ * app finds it wherever it looks; a wrap goes only where its recipient reads, or the
+ * publish set when they have said nowhere. Whether any relay accepted it.
+ */
+ suspend fun publish(owed: GroupInboxPublication): Boolean {
+ val own = owed.relayList()
+ val targets = when {
+ owed.recipientPublicKey == null -> own + Relays.eventPublishRelaySet.map { it.url }
+ own.isEmpty() -> Relays.eventPublishRelaySet.map { it.url }
+ else -> own
+ }.map { it.trim() }.filter { it.startsWith("wss://") || it.startsWith("ws://") }.distinct()
+
+ val wire = wireEventOf(owed) ?: return false
+ var accepted = false
+ try {
+ withTimeout((RelayPool.PUBLISH_TIMEOUT * 2).milliseconds) {
+ transport.publishEvent(
+ nostrEvent = wire,
+ relays = targets.map { RelayDTO(url = it, read = false, write = true) }.toSet(),
+ ).take(targets.size).collect { result ->
+ val ok = result.result as? NostrIncomingMessage.OkMessage
+ if (result.error == null && ok?.success == true) accepted = true
+ }
+ }
+ } catch (e: TimeoutCancellationException) {
+ // A relay that never answers. Whatever answered in time counts.
+ } catch (e: CancellationException) {
+ throw e
+ } catch (e: Throwable) {
+ logger.e("Could not send inbox event ${owed.eventId.take(8)}", e)
+ }
+ if (accepted) {
+ repository.markPublished(owed.eventId, Clock.System.now())
+ logger.i("Inbox event ${owed.eventId.take(8)} of kind ${owed.kind} is on a relay")
+ }
+ return accepted
+ }
+
+ private companion object {
+ /** The event as the pool wants it. Never written to the `NostrEvent` table. */
+ fun wireEventOf(owed: GroupInboxPublication): NostrEvent? = Event.fromJsonOrNull(owed.eventJson)?.let {
+ NostrEvent(
+ id = it.id,
+ pubKey = it.pubKey,
+ kind = it.kind,
+ tags = it.tags,
+ content = it.content,
+ sig = it.sig,
+ createdAt = kotlin.time.Instant.fromEpochSeconds(it.createdAt),
+ )
+ }
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxAnnouncements.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxAnnouncements.kt
new file mode 100644
index 00000000..09749f91
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxAnnouncements.kt
@@ -0,0 +1,87 @@
+package mobi.giza.compose.managers
+
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
+import kotlin.time.Clock
+import mobi.giza.compose.database.GizaDatabase
+import mobi.giza.compose.database.model.FrostSigningSession
+import mobi.giza.compose.database.model.GroupInboxPublication
+import mobi.giza.compose.database.model.InboxKeyState
+import mobi.giza.compose.nostr.Relays
+import mobi.giza.compose.nostr.inbox.InboxAnnouncement
+
+/**
+ * What a signed announcement of the group's inbox changes on a device (docs/group-inbox.md, D7
+ * and D14): the key it names becomes the one replies are sealed from, the ones before it are
+ * kept to open with, and the device that proposed it owes it to relays.
+ */
+object InboxAnnouncements {
+ /** Called by [FrostSigningManager.complete] on every device, with what the session signed. */
+ suspend fun onSigned(database: GizaDatabase, session: FrostSigningSession, signedEvents: List) {
+ val roomId = session.chatRoomId
+ val ours = signedEvents.filter {
+ it.pubKey.equals(roomId, ignoreCase = true) &&
+ (it.kind == InboxAnnouncement.KEY_KIND || it.kind == InboxAnnouncement.RELAYS_KIND)
+ }
+ if (ours.isEmpty()) return
+
+ ours.firstOrNull { it.kind == InboxAnnouncement.KEY_KIND }?.let { announcement ->
+ InboxAnnouncement.groupKeyOf(announcement)?.let { key -> settle(database, roomId, session.userPublicKey, key, announcement.id) }
+ }
+
+ // Only the device that asked for the signature sends it, as for a confederation
+ // event: one sender, retrying until a relay takes it, rather than every signer racing.
+ if (!session.isCoordinator()) return
+ val relays = (relaysOf(database, roomId, signedEvents) + Relays.DefaultDMRelayList).distinct()
+ ours.forEach { event ->
+ database.groupInboxDao().upsertPublication(
+ GroupInboxPublication(
+ eventId = event.id,
+ chatRoomId = roomId,
+ kind = event.kind,
+ eventJson = event.toJson(),
+ relays = relays.joinToString(",") { it.url },
+ signingSessionId = session.id,
+ recipientPublicKey = null,
+ )
+ )
+ }
+ }
+
+ /**
+ * [key] is the group's announced inbox key now: its generation is [InboxKeyState.ANNOUNCED]
+ * and every earlier one this device still holds is [InboxKeyState.RETIRED]. A later
+ * generation made but not yet announced stays as it is.
+ */
+ private suspend fun settle(database: GizaDatabase, roomId: String, userPublicKey: String, key: String, eventId: String) {
+ val keys = database.inboxKeyDao().getKeys(roomId, userPublicKey)
+ val named = keys.firstOrNull { it.publicKey == key } ?: return
+ val now = Clock.System.now()
+ keys.forEach { held ->
+ val next = when {
+ held.generation == named.generation -> held.copy(state = InboxKeyState.ANNOUNCED, announcementEventId = eventId, announcedAt = now)
+ held.generation < named.generation && held.state != InboxKeyState.WIPED -> held.copy(state = InboxKeyState.RETIRED)
+ else -> held
+ }
+ if (next != held) database.inboxKeyDao().upsertKey(next)
+ }
+ }
+
+ /** The relays the group's mail should go to: this batch's 10050, else the newest one it signed. */
+ suspend fun relaysOf(database: GizaDatabase, roomId: String, batch: List = emptyList()): List {
+ batch.firstOrNull { it.kind == InboxAnnouncement.RELAYS_KIND && it.pubKey.equals(roomId, ignoreCase = true) }
+ ?.let { InboxAnnouncement.groupRelaysOf(it) }?.let { return it }
+ return database.groupSignedEventDao().getByChatRoomIdAndKind(roomId, InboxAnnouncement.RELAYS_KIND)
+ .filter { it.publicKey.equals(roomId, ignoreCase = true) }
+ .maxByOrNull { it.createdAt }
+ ?.let { InboxAnnouncement.groupRelaysOf(it.kind, it.tags, it.content) }
+ .orEmpty()
+ }
+
+ /** The key the group's newest signed 10044 names, or null if it has announced none. */
+ suspend fun announcedKey(database: GizaDatabase, roomId: String): String? =
+ database.groupSignedEventDao().getByChatRoomIdAndKind(roomId, InboxAnnouncement.KEY_KIND)
+ .filter { it.publicKey.equals(roomId, ignoreCase = true) }
+ .maxByOrNull { it.createdAt }
+ ?.let { InboxAnnouncement.groupKeyOf(it.kind, it.tags, it.content) }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxFollowThrough.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxFollowThrough.kt
new file mode 100644
index 00000000..41a262e8
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxFollowThrough.kt
@@ -0,0 +1,53 @@
+package mobi.giza.compose.managers
+
+import co.touchlab.kermit.Logger
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
+import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
+import kotlin.time.Clock
+import kotlinx.coroutines.CancellationException
+import mobi.giza.compose.database.GizaDatabase
+import mobi.giza.compose.database.model.InboxKeyCeremony
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.nostr.Relays
+import mobi.giza.compose.nostr.inbox.InboxAnnouncement
+
+/**
+ * What follows an inbox key ceremony on the device that coordinated it (docs/group-inbox.md,
+ * D5 and D6): asking the group to announce the key it made.
+ *
+ * The first time, that is a batch of two -- the 10044 naming the key and the 10050 naming where
+ * mail should arrive -- and the group's members are asked, since signing it is the group
+ * deciding to have an inbox at all. After that, a rotation's 10044 alone, which every admin's
+ * device can vouch for and signs unasked ([InboxRefusal.vouchesFor]).
+ */
+object InboxFollowThrough {
+ private val logger = Logger.withTag("InboxFollowThrough")
+
+ /** Called once, on every participant's device, when [ceremony] has made its key. */
+ suspend fun onKeyMade(database: GizaDatabase, localChatRoom: LocalChatRoom, ceremony: InboxKeyCeremony) {
+ if (!ceremony.isCoordinator()) return
+ val key = database.inboxKeyDao().getKey(ceremony.chatRoomId, ceremony.userPublicKey, ceremony.generation) ?: return
+ val now = Clock.System.now().epochSeconds
+
+ val events = buildList> {
+ add(InboxAnnouncement.keyTemplate(key.publicKey, now))
+ if (InboxAnnouncements.announcedKey(database, ceremony.chatRoomId) == null) {
+ val chosen = ceremony.announceRelays.orEmpty().split(",")
+ .mapNotNull { RelayUrlNormalizer.normalizeOrNull(it.trim()) }
+ add(InboxAnnouncement.relaysTemplate(chosen.ifEmpty { Relays.DefaultDMRelayList }, now))
+ }
+ }
+
+ try {
+ val session = FrostSigningManager.proposeSigningBatch(database, localChatRoom, ceremony.userPublicKey, events = events)
+ logger.i("Asked the group to announce inbox key generation ${ceremony.generation} in session ${session.id.take(8)}")
+ } catch (e: CancellationException) {
+ throw e
+ } catch (e: Throwable) {
+ // The key is made and kept either way; an admin can ask again from the inbox's
+ // settings. Not a ceremony failure, so not said as one.
+ logger.e("Made inbox key generation ${ceremony.generation} but could not ask the group to announce it", e)
+ }
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxKeyRitualManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxKeyRitualManager.kt
new file mode 100644
index 00000000..f2e05904
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxKeyRitualManager.kt
@@ -0,0 +1,614 @@
+package mobi.giza.compose.managers
+
+import co.touchlab.kermit.Logger
+import com.vitorpamplona.crypto.random.RandomInstance
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.Kind
+import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
+import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
+import fr.acinq.bitcoin.ByteVector
+import fr.acinq.bitcoin.ByteVector32
+import fr.acinq.bitcoin.ByteVector64
+import fr.acinq.bitcoin.Crypto
+import fr.acinq.bitcoin.PrivateKey
+import fr.acinq.bitcoin.PublicKey
+import fr.acinq.bitcoin.crypto.dkg.chill.ChillDKG
+import fr.acinq.secp256k1.ChilldkgFault
+import kotlin.time.Clock
+import kotlin.time.Instant
+import kotlinx.coroutines.CancellationException
+import mobi.giza.compose.ExperimentalFeatures
+import mobi.giza.compose.database.GizaDatabase
+import mobi.giza.compose.database.model.ChatMessage
+import mobi.giza.compose.database.model.InboxKey
+import mobi.giza.compose.database.model.InboxKeyCeremony
+import mobi.giza.compose.database.model.InboxKeyCeremonyMessage
+import mobi.giza.compose.database.model.InboxKeyCeremonyStage
+import mobi.giza.compose.database.model.MarmotInnerEvent
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.extensions.toHex
+import mobi.giza.compose.nostr.Relays
+import mobi.giza.compose.nostr.inbox.InboxKeyRitualEvents
+import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
+import mobi.giza.compose.nostr.inbox.InboxWire
+
+/**
+ * The group's inbox key ceremony (docs/group-inbox.md, D2, D3 and D4): ChillDKG at threshold 1
+ * over the room's admins, which leaves every one of them holding the same secret `e` and the
+ * group a public key `E` nobody chose alone.
+ *
+ * The rounds are [ChillDkgRitualManager]'s, on kinds and tables of their own, with three
+ * differences:
+ *
+ * - **The participants are the room's admins**, exactly. Every device checks the proposal's
+ * `p` tags against its own reading of the room's admin policy, and a disagreement ends the
+ * ceremony out loud with the difference named.
+ * - **Nobody is asked.** Being an admin is the decision to hold the key; deciding to *have* an
+ * inbox is the group signing its announcement (D5). An admin's device takes part on arrival.
+ * - **The output is a whole secret**, written once to [InboxKey]. Nothing that looks for a
+ * signing key reads that table.
+ *
+ * Every message is an MLS inner event in the group's own room. Every member receives them all;
+ * ChillDKG encrypts each contribution to its recipients' host keys, so a member who is not an
+ * admin learns `E` and nothing else, and files three lines in the transcript.
+ */
+object InboxKeyRitualManager {
+ private val logger = Logger.withTag("InboxKeyRitualManager")
+
+ /**
+ * A hash input, spelled the house way. Bound to the room so the host key an admin uses for
+ * one group's inbox says nothing about another's, and to nothing else, so the nsec alone
+ * recovers it.
+ */
+ private const val HOST_KEY_TAG = "mantra/inbox-key/host-key/v1"
+
+ const val MINIMUM_ADMINS = 2
+
+ const val ABANDONED = "Abandoned by an admin"
+
+ /** Why one of two crossing ceremonies ends: the other went on. */
+ const val CROSSED = "Another admin started the same ceremony at the same time, and that one went on"
+
+ fun deriveHostSecretKey(nostrPrivateKey: ByteArray, chatRoomId: String): PrivateKey =
+ PrivateKey(Crypto.sha256(HOST_KEY_TAG.encodeToByteArray() + nostrPrivateKey + chatRoomId.hexToByteArray()))
+
+ fun deriveHostPublicKey(nostrPrivateKey: ByteArray, chatRoomId: String): PublicKey =
+ ChillDKG.hostPublicKey(deriveHostSecretKey(nostrPrivateKey, chatRoomId))
+
+ /**
+ * Why [userPublicKey] cannot open an inbox key ceremony in [localChatRoom] now, or null if
+ * they can. Read by the screens, so a button that could only fail is never offered.
+ */
+ suspend fun refusal(database: GizaDatabase, localChatRoom: LocalChatRoom, userPublicKey: HexKey): String? {
+ if (!ExperimentalFeatures.groupInbox) return "This build has no group inbox"
+ val room = localChatRoom.chatRoom
+ if (room.mlsGroupState == null || room.leftGroupAt != null) return "Only a group's own room can have an inbox"
+ val key = FrostSigningManager.completedKey(database, room.id)
+ ?: return "The group has no key to announce an inbox with"
+ val admins = RoomAdmins.of(database, room.id)?.admins ?: return "This device cannot read who the group's admins are"
+ if (userPublicKey !in admins) return "Only an admin can set up the group's inbox"
+ if (admins.size < MINIMUM_ADMINS) return "The group needs at least $MINIMUM_ADMINS admins for an inbox"
+ when (val hold = ShareRefreshManager.rotationHold(database, localChatRoom, key)) {
+ is RotationHold.Running, is RotationHold.AdminChangeInFlight, is RotationHold.Enrolling -> return hold.reason.replaceFirstChar { it.uppercase() }
+ else -> Unit
+ }
+ return null
+ }
+
+ /** The generation a new ceremony in [chatRoomId] makes: one past any this device has seen. */
+ suspend fun nextGeneration(database: GizaDatabase, chatRoomId: String, userPublicKey: HexKey): Int {
+ val keys = database.inboxKeyDao().getKeys(chatRoomId, userPublicKey).maxOfOrNull { it.generation }
+ val ceremony = database.inboxKeyDao().getLatestCeremony(chatRoomId, userPublicKey)
+ ?.takeIf { it.stage == InboxKeyCeremonyStage.COMPLETE }?.generation
+ return listOfNotNull(keys, ceremony).maxOrNull()?.plus(1) ?: 0
+ }
+
+ /**
+ * Opens a ceremony over the room's current admins, making this device its coordinator. A
+ * ceremony already running in the room is handed back instead of a second one. Throws with
+ * [refusal]'s reason when the room cannot have one.
+ */
+ suspend fun propose(
+ database: GizaDatabase,
+ localChatRoom: LocalChatRoom,
+ userPublicKey: HexKey,
+ nostrPrivateKey: ByteArray,
+ /** Where the group's mail should arrive, for the first generation's 10050 (D6). */
+ relays: List = Relays.DefaultDMRelayList,
+ ): InboxKeyCeremony {
+ val roomId = localChatRoom.chatRoom.id
+ database.inboxKeyDao().getRunningCeremoniesIn(roomId).firstOrNull { it.userPublicKey == userPublicKey }?.let { return it }
+
+ refusal(database, localChatRoom, userPublicKey)?.let { throw IllegalStateException(it) }
+ val admins = RoomAdmins.of(database, roomId)!!.admins
+
+ val generation = nextGeneration(database, roomId, userPublicKey)
+ val ceremony = InboxKeyCeremony(
+ id = RandomInstance.bytes(32).toHex(),
+ chatRoomId = roomId,
+ generation = generation,
+ announceRelays = relays.takeIf { generation == 0 }?.joinToString(",") { it.url },
+ coordinatorPublicKey = userPublicKey,
+ userPublicKey = userPublicKey,
+ participantPublicKeys = InboxKeyCeremony.formatParticipants(admins),
+ hostPublicKey = deriveHostPublicKey(nostrPrivateKey, roomId).value.toHex(),
+ round1Random = RandomInstance.bytes(32).toHex(),
+ round2AuxRandom = RandomInstance.bytes(32).toHex(),
+ )
+ database.inboxKeyDao().upsertCeremony(ceremony)
+ announceStarted(database, ceremony)
+ logger.i("Proposing inbox key ceremony ${ceremony.id.take(8)} at generation ${ceremony.generation} over ${admins.size} admins")
+
+ broadcast(
+ database, localChatRoom, ceremony, InboxKeyRitualEvents.PROPOSAL, "",
+ proposal = true,
+ )
+ advance(database, localChatRoom, ceremony.id, nostrPrivateKey)
+ return database.inboxKeyDao().getCeremony(ceremony.id)!!
+ }
+
+ /**
+ * Feeds one inbound ceremony message in and moves the ceremony as far as it will go. Safe to
+ * call twice with the same message: every write is keyed and every step recomputed.
+ */
+ suspend fun process(
+ database: GizaDatabase,
+ localChatRoom: LocalChatRoom,
+ innerEvent: Event,
+ userPublicKey: HexKey,
+ nostrPrivateKey: ByteArray,
+ ) {
+ val sessionId = InboxKeyRitualEvents.parseSessionId(innerEvent.tags) ?: run {
+ logger.w("Inbox key message ${innerEvent.id.take(8)} names no session; dropping")
+ return
+ }
+
+ val ceremony = if (innerEvent.kind == InboxKeyRitualEvents.PROPOSAL) {
+ accept(database, localChatRoom, innerEvent, sessionId, userPublicKey, nostrPrivateKey)
+ } else {
+ // Relays and MLS hand messages back in no particular order; a round can arrive
+ // before its proposal. It is already stored as an inner event, and [accept]
+ // replays it once the proposal turns up.
+ database.inboxKeyDao().getCeremony(sessionId)
+ } ?: return
+
+ if (!ceremony.isRunning) return
+ if (!record(database, ceremony, innerEvent)) return
+ if (ceremony.isParticipant()) advance(database, localChatRoom, ceremony.id, nostrPrivateKey)
+ }
+
+ /**
+ * Moves every inbox key ceremony [userPublicKey] takes part in as far as its stored
+ * messages allow, for a ceremony left mid-round by a crash. Returns how many it looked at.
+ */
+ suspend fun resumeRunning(database: GizaDatabase, userPublicKey: HexKey, nostrPrivateKey: ByteArray): Int {
+ val running = database.inboxKeyDao().getRunningCeremonies(userPublicKey).filter { it.isParticipant() }
+ running.forEach { ceremony ->
+ val room = database.chatRoomDao().findChatRoomById(ceremony.chatRoomId) ?: return@forEach
+ advance(database, room, ceremony.id, nostrPrivateKey)
+ }
+ return running.size
+ }
+
+ /**
+ * Ends a running ceremony for everyone in it. Only an admin it names can: a member who was
+ * never in it walking away is not the ceremony failing. Returns whether it was ended.
+ */
+ suspend fun abandon(database: GizaDatabase, localChatRoom: LocalChatRoom, sessionId: String): Boolean {
+ val ceremony = database.inboxKeyDao().getCeremony(sessionId) ?: return false
+ if (!ceremony.isRunning || !ceremony.isParticipant()) return false
+ fail(database, ceremony, ABANDONED, ceremony.userPublicKey)
+ broadcast(database, localChatRoom, ceremony, InboxKeyRitualEvents.FAILURE, ABANDONED)
+ return true
+ }
+
+ // ---- arrival -------------------------------------------------------------------------------
+
+ private suspend fun accept(
+ database: GizaDatabase,
+ localChatRoom: LocalChatRoom,
+ innerEvent: Event,
+ sessionId: String,
+ userPublicKey: HexKey,
+ nostrPrivateKey: ByteArray,
+ ): InboxKeyCeremony? {
+ database.inboxKeyDao().getCeremony(sessionId)?.let { return it }
+ val roomId = localChatRoom.chatRoom.id
+
+ if (localChatRoom.chatRoom.mlsGroupState == null) {
+ logger.w("Inbox key proposal ${sessionId.take(8)} outside a Marmot room; dropping")
+ return null
+ }
+ val generation = InboxKeyRitualEvents.parseGeneration(innerEvent.tags)
+ val named = InboxKeyRitualEvents.parseParticipants(innerEvent.tags)
+ if (generation == null || named == null || InboxKeyRitualEvents.parseThreshold(innerEvent.tags) != InboxKeyRitualEvents.THRESHOLD) {
+ logger.w("Inbox key proposal ${sessionId.take(8)} is malformed; dropping")
+ return null
+ }
+ val participants = (named + innerEvent.pubKey).distinct().sorted()
+
+ // A generation this device already finished is not made twice: a late or replayed
+ // proposal for it opens nothing.
+ if (database.inboxKeyDao().getCompletedCeremonies(roomId, userPublicKey).any { it.generation >= generation }) {
+ logger.w("Inbox key proposal ${sessionId.take(8)} is for generation $generation, which this device has; dropping")
+ return null
+ }
+
+ val base = InboxKeyCeremony(
+ id = sessionId,
+ chatRoomId = roomId,
+ generation = generation,
+ coordinatorPublicKey = innerEvent.pubKey,
+ userPublicKey = userPublicKey,
+ participantPublicKeys = InboxKeyCeremony.formatParticipants(participants),
+ )
+
+ // A member who is not named only watches: it files the lines, and holds nothing.
+ val mine = if (userPublicKey in participants) {
+ base.copy(
+ hostPublicKey = deriveHostPublicKey(nostrPrivateKey, roomId).value.toHex(),
+ round1Random = RandomInstance.bytes(32).toHex(),
+ round2AuxRandom = RandomInstance.bytes(32).toHex(),
+ )
+ } else {
+ base
+ }
+ database.inboxKeyDao().upsertCeremony(mine)
+ announceStarted(database, mine)
+
+ // D4: the participants are the admins, exactly, as this device reads them. A
+ // ceremony over anyone else would hand the group's mail to whoever the coordinator
+ // put in it, or leave an admin without it. An admin the proposal left out says so as
+ // loudly as a named one does.
+ val admins = RoomAdmins.of(database, roomId)?.admins
+ val mismatch = when {
+ admins == null -> null // nothing to compare with; the others will
+ admins.toSet() != participants.toSet() -> describeMismatch(admins, participants)
+ else -> null
+ }
+ if (mismatch != null && (userPublicKey in participants || userPublicKey in admins.orEmpty())) {
+ logger.w("Inbox key ceremony ${sessionId.take(8)}: $mismatch")
+ fail(database, mine, mismatch, userPublicKey)
+ broadcast(database, localChatRoom, mine, InboxKeyRitualEvents.FAILURE, mismatch)
+ return database.inboxKeyDao().getCeremony(sessionId)
+ }
+
+ // Two admins who each started a rotation before hearing the other's: every device keeps
+ // the one whose session id sorts first and ends the other out loud, so all of them end
+ // up in the same ceremony and nobody holds a key the others do not.
+ val crossing = database.inboxKeyDao().getRunningCeremoniesIn(roomId)
+ .filter { it.userPublicKey == userPublicKey && it.id != sessionId }
+ crossing.forEach { other ->
+ val loser = if (other.id < sessionId) mine else other
+ val reason = CROSSED
+ fail(database, loser, reason, loser.coordinatorPublicKey)
+ if (loser.isParticipant()) broadcast(database, localChatRoom, loser, InboxKeyRitualEvents.FAILURE, reason)
+ }
+ if (database.inboxKeyDao().getCeremony(sessionId)?.isRunning != true) return database.inboxKeyDao().getCeremony(sessionId)
+
+ replayStored(database, localChatRoom, mine)
+ return database.inboxKeyDao().getCeremony(sessionId)
+ }
+
+ private fun describeMismatch(admins: Set, participants: List): String {
+ val missing = admins - participants.toSet()
+ val extra = participants.toSet() - admins
+ return buildList {
+ if (missing.isNotEmpty()) add("leaves out ${missing.size} admin${if (missing.size == 1) "" else "s"} (${missing.sorted().joinToString { it.take(8) }})")
+ if (extra.isNotEmpty()) add("names ${extra.size} who ${if (extra.size == 1) "is not an admin" else "are not admins"} (${extra.sorted().joinToString { it.take(8) }})")
+ }.joinToString(" and ", prefix = "The inbox key ceremony ")
+ }
+
+ /** Every message of [ceremony] that arrived before its proposal, read back out of the room's inner events. */
+ private suspend fun replayStored(database: GizaDatabase, localChatRoom: LocalChatRoom, ceremony: InboxKeyCeremony) {
+ val stored = database.marmotInnerEventDao()
+ .getByChatRoomAndKinds(chatRoomId = ceremony.chatRoomId, kinds = (InboxKeyRitualEvents.ALL - InboxKeyRitualEvents.PROPOSAL).toList())
+ .filter { InboxKeyRitualEvents.parseSessionId(it.tags) == ceremony.id }
+ stored.forEach { row ->
+ val event = Event(row.id, row.publicKey, row.createdAt.epochSeconds, row.kind, row.tags, row.content, "")
+ if (!record(database, ceremony, event)) return
+ }
+ }
+
+ /**
+ * Files one message. Returns false when it ends the ceremony. Round messages count only
+ * from a participant, the coordinator's aggregates only from the coordinator: taking either
+ * from anyone else would let any member stall the ceremony by getting a bogus one in first.
+ */
+ private suspend fun record(database: GizaDatabase, ceremony: InboxKeyCeremony, innerEvent: Event): Boolean {
+ val participants = ceremony.participants()
+ val sender = innerEvent.pubKey
+ when (innerEvent.kind) {
+ InboxKeyRitualEvents.PROPOSAL -> Unit
+ InboxKeyRitualEvents.HOST_KEY, InboxKeyRitualEvents.ROUND_1, InboxKeyRitualEvents.ROUND_2 -> {
+ if (sender !in participants) return true
+ store(database, ceremony, sender, innerEvent.kind, innerEvent.content)
+ }
+ InboxKeyRitualEvents.COORDINATOR_ROUND_1 -> {
+ if (sender != ceremony.coordinatorPublicKey) return true
+ store(database, ceremony, sender, innerEvent.kind, innerEvent.content)
+ }
+ InboxKeyRitualEvents.CERTIFICATE -> {
+ if (sender != ceremony.coordinatorPublicKey) return true
+ store(database, ceremony, sender, innerEvent.kind, innerEvent.content)
+ // A member who only watches holds no secret, but every message the
+ // coordinator aggregated is public in the room, so it can aggregate them too
+ // and learn the key the admins made -- which is what lets it check the
+ // group's announcement of that key before signing it (D5).
+ if (!ceremony.isParticipant()) {
+ val current = database.inboxKeyDao().getCeremony(ceremony.id) ?: ceremony
+ if (current.isRunning) {
+ val watched = runCatching { watchedKey(database, current) }.getOrNull()
+ database.inboxKeyDao().upsertCeremony(
+ current.copy(stage = InboxKeyCeremonyStage.COMPLETE, inboxPublicKey = watched, updatedAt = Clock.System.now())
+ )
+ announce(database, current, ChatMessage.TYPE_INBOX_KEY_COMPLETE, "The group's admins finished making its inbox key.", current.coordinatorPublicKey)
+ }
+ }
+ }
+ InboxKeyRitualEvents.FAILURE -> {
+ if (sender !in participants && sender !in (RoomAdmins.of(database, ceremony.chatRoomId)?.admins ?: emptySet())) return true
+ fail(database, ceremony, innerEvent.content.ifBlank { ABANDONED }, sender)
+ return false
+ }
+ }
+ return true
+ }
+
+ private suspend fun store(database: GizaDatabase, ceremony: InboxKeyCeremony, sender: HexKey, kind: Kind, payload: String) {
+ val inserted = database.inboxKeyDao().insertMessage(InboxKeyCeremonyMessage(ceremony.id, sender, kind, payload))
+ if (inserted > 0) {
+ database.inboxKeyDao().getCeremony(ceremony.id)?.let {
+ database.inboxKeyDao().upsertCeremony(it.copy(lastMessageAt = Clock.System.now(), updatedAt = Clock.System.now()))
+ }
+ }
+ }
+
+ // ---- the rounds ----------------------------------------------------------------------------
+
+ /**
+ * Takes every step the stored messages allow, stopping at the first one still waiting on
+ * somebody. Each step asks whether its output exists rather than what the stage says, so a
+ * re-entry repeats no work and skips none.
+ */
+ private suspend fun advance(database: GizaDatabase, localChatRoom: LocalChatRoom, sessionId: String, nostrPrivateKey: ByteArray) {
+ val start = database.inboxKeyDao().getCeremony(sessionId) ?: return
+ if (!start.isRunning || !start.isParticipant()) return
+ val roomId = start.chatRoomId
+ val hostSecret = deriveHostSecretKey(nostrPrivateKey, roomId)
+ val threshold = InboxKeyRitualEvents.THRESHOLD
+
+ try {
+ if (own(database, start, InboxKeyRitualEvents.HOST_KEY) == null) {
+ publishOwn(database, localChatRoom, start, InboxKeyRitualEvents.HOST_KEY, requireNotNull(start.hostPublicKey))
+ }
+ val hostPublicKeys = hostPublicKeys(database, start) ?: return
+
+ val step1 = ChillDKG.participantStep1(hostSecret, hostPublicKeys, threshold, ByteVector32(requireNotNull(start.round1Random)))
+ if (own(database, start, InboxKeyRitualEvents.ROUND_1) == null) {
+ publishOwn(database, localChatRoom, start, InboxKeyRitualEvents.ROUND_1, step1.message.toHex())
+ }
+ moveTo(database, start, InboxKeyCeremonyStage.ROUND_1)
+
+ if (start.isCoordinator() && coordinatorMessage(database, start, InboxKeyRitualEvents.COORDINATOR_ROUND_1) == null) {
+ val pmsgs1 = ordered(database, start, InboxKeyRitualEvents.ROUND_1) ?: return
+ val cmsg1 = coordinatorStep1(pmsgs1, hostPublicKeys).message.toHex()
+ publishOwn(database, localChatRoom, start, InboxKeyRitualEvents.COORDINATOR_ROUND_1, cmsg1)
+ }
+ val cmsg1 = coordinatorMessage(database, start, InboxKeyRitualEvents.COORDINATOR_ROUND_1) ?: return
+
+ // The check that stops a coordinator substituting a key the admins never
+ // contributed to: participantStep2 faults on a mismatch, and the catch below fails
+ // the ceremony for everyone.
+ val step2 = ChillDKG.participantStep2(hostSecret, step1.state, ByteVector(cmsg1.hexToByteArray()), ByteVector32(requireNotNull(start.round2AuxRandom)))
+ step2.fault.raiseIfFaulty("round 2")
+ if (own(database, start, InboxKeyRitualEvents.ROUND_2) == null) {
+ publishOwn(database, localChatRoom, start, InboxKeyRitualEvents.ROUND_2, step2.certEqSignature.toHex())
+ }
+ moveTo(database, start, InboxKeyCeremonyStage.ROUND_2)
+
+ if (start.isCoordinator() && coordinatorMessage(database, start, InboxKeyRitualEvents.CERTIFICATE) == null) {
+ val pmsgs2 = ordered(database, start, InboxKeyRitualEvents.ROUND_2) ?: return
+ val pmsgs1 = ordered(database, start, InboxKeyRitualEvents.ROUND_1) ?: return
+ val certified = ChillDKG.coordinatorFinalize(coordinatorStep1(pmsgs1, hostPublicKeys).state, pmsgs2.map { ByteVector64(it) }, threshold)
+ certified.fault.raiseIfFaulty("certificate")
+ publishOwn(database, localChatRoom, start, InboxKeyRitualEvents.CERTIFICATE, certified.certificate.toHex())
+ }
+ val certificate = coordinatorMessage(database, start, InboxKeyRitualEvents.CERTIFICATE) ?: return
+
+ val output = ChillDKG.participantFinalize(step2.state, ByteVector(certificate.hexToByteArray()), hostPublicKeys.size, threshold)
+ output.fault.raiseIfFaulty("finalize")
+
+ // D2's premise, checked on every run rather than trusted from Phase 0: at t = 1
+ // the share is the whole secret, so it has to be the discrete log of the key.
+ val secret = requireNotNull(output.secretShare) { "the ceremony left no secret" }
+ val thresholdKey = requireNotNull(output.thresholdPublicKey) { "the ceremony left no key" }
+ check(secret.publicKey() == thresholdKey) { "the inbox key's secret is not its key's: the ceremony was not at threshold 1" }
+ val secretBytes = secret.value.toByteArray()
+ val inboxKey = InboxWire.publicKeyOf(secretBytes)
+
+ database.inboxKeyDao().upsertKey(
+ InboxKey(
+ chatRoomId = roomId,
+ userPublicKey = start.userPublicKey,
+ generation = start.generation,
+ publicKey = inboxKey,
+ secretKey = secretBytes.toHex(),
+ recoveryData = output.recovery?.toHex(),
+ ceremonyId = start.id,
+ )
+ )
+ val done = (database.inboxKeyDao().getCeremony(sessionId) ?: start)
+ .copy(stage = InboxKeyCeremonyStage.COMPLETE, inboxPublicKey = inboxKey, updatedAt = Clock.System.now())
+ database.inboxKeyDao().upsertCeremony(done)
+ announce(
+ database, done, ChatMessage.TYPE_INBOX_KEY_COMPLETE,
+ "The group's admins made its inbox key. It reaches nobody until the group announces it.",
+ done.coordinatorPublicKey,
+ )
+ logger.i("Inbox key ceremony ${sessionId.take(8)} complete: generation ${done.generation}")
+ InboxFollowThrough.onKeyMade(database, localChatRoom, done)
+ FrostSigningManager.resumeInboxAnnouncements(database, localChatRoom, done.userPublicKey)
+ GroupInboxManager.reopen(database, roomId, done.userPublicKey)
+ } catch (e: CancellationException) {
+ throw e
+ } catch (e: Throwable) {
+ logger.e("Inbox key ceremony ${sessionId.take(8)} failed", e)
+ val reason = e.message ?: "The inbox key ceremony failed"
+ val current = database.inboxKeyDao().getCeremony(sessionId) ?: start
+ fail(database, current, reason, current.userPublicKey)
+ broadcast(database, localChatRoom, current, InboxKeyRitualEvents.FAILURE, reason)
+ }
+ }
+
+ /**
+ * The key a ceremony made, as a member who only watched it can compute: the coordinator's
+ * two aggregations need no secret, and every message they take is in the room. Null while
+ * any is missing, or if they do not aggregate.
+ */
+ internal suspend fun keyWatched(database: GizaDatabase, ceremony: InboxKeyCeremony): HexKey? =
+ runCatching { watchedKey(database, ceremony) }.getOrNull()?.also { key ->
+ database.inboxKeyDao().getCeremony(ceremony.id)?.let { database.inboxKeyDao().upsertCeremony(it.copy(inboxPublicKey = key)) }
+ }
+
+ private suspend fun watchedKey(database: GizaDatabase, ceremony: InboxKeyCeremony): HexKey? {
+ val hostPublicKeys = hostPublicKeys(database, ceremony) ?: return null
+ val pmsgs1 = ordered(database, ceremony, InboxKeyRitualEvents.ROUND_1) ?: return null
+ val pmsgs2 = ordered(database, ceremony, InboxKeyRitualEvents.ROUND_2) ?: return null
+ val state = ChillDKG.coordinatorStep1(pmsgs1.map { ByteVector(it) }, hostPublicKeys, InboxKeyRitualEvents.THRESHOLD)
+ .takeIf { it.fault.isOk }?.state ?: return null
+ val certified = ChillDKG.coordinatorFinalize(state, pmsgs2.map { ByteVector64(it) }, InboxKeyRitualEvents.THRESHOLD)
+ .takeIf { it.fault.isOk } ?: return null
+ return certified.thresholdPublicKey?.xOnly()?.value?.toHex()
+ }
+
+ /** The participants' host keys, sorted, or null while any is outstanding. */
+ private suspend fun hostPublicKeys(database: GizaDatabase, ceremony: InboxKeyCeremony): List? {
+ val participants = ceremony.participants()
+ val hostKeys = database.inboxKeyDao().getMessages(ceremony.id)
+ .filter { it.kind == InboxKeyRitualEvents.HOST_KEY && it.senderPublicKey in participants }
+ if (hostKeys.size < participants.size) return null
+ return hostKeys.map { it.payload.lowercase() }.sorted().map { PublicKey(ByteVector(it.hexToByteArray())) }
+ }
+
+ /** A round's messages, one per participant, in host-key order; null while any is missing. */
+ private suspend fun ordered(database: GizaDatabase, ceremony: InboxKeyCeremony, kind: Kind): List? {
+ val messages = database.inboxKeyDao().getMessages(ceremony.id)
+ val hostKeyOf = messages.filter { it.kind == InboxKeyRitualEvents.HOST_KEY }.associate { it.senderPublicKey to it.payload.lowercase() }
+ val participants = ceremony.participants()
+ val round = participants.map { participant ->
+ val message = messages.firstOrNull { it.kind == kind && it.senderPublicKey == participant } ?: return null
+ val hostKey = hostKeyOf[participant] ?: return null
+ hostKey to message.payload
+ }
+ return round.sortedBy { it.first }.map { it.second.hexToByteArray() }
+ }
+
+ private fun coordinatorStep1(pmsgs1: List, hostPublicKeys: List) =
+ ChillDKG.coordinatorStep1(pmsgs1.map { ByteVector(it) }, hostPublicKeys, InboxKeyRitualEvents.THRESHOLD)
+ .also { it.fault.raiseIfFaulty("coordinator round 1") }
+
+ private fun ChilldkgFault.raiseIfFaulty(step: String) {
+ if (isOk) return
+ val culprit = participantIndex?.let { " (participant $it)" } ?: ""
+ val reason = when (code) {
+ ChilldkgFault.FAULTY_COORDINATOR -> "the coordinator is faulty"
+ ChilldkgFault.FAULTY_PARTICIPANT -> "a participant is faulty"
+ ChilldkgFault.FAULTY_PARTICIPANT_OR_COORDINATOR -> "a participant or the coordinator is faulty"
+ ChilldkgFault.UNKNOWN_FAULTY_PARTICIPANT_OR_COORDINATOR -> "an unidentified participant or the coordinator is faulty"
+ ChilldkgFault.INVALID_INPUT -> "invalid input"
+ else -> "unrecognised fault code $code"
+ }
+ throw IllegalStateException("The inbox key ceremony's $step failed: $reason$culprit")
+ }
+
+ private suspend fun own(database: GizaDatabase, ceremony: InboxKeyCeremony, kind: Kind) =
+ database.inboxKeyDao().getMessage(ceremony.id, ceremony.userPublicKey, kind)
+
+ private suspend fun coordinatorMessage(database: GizaDatabase, ceremony: InboxKeyCeremony, kind: Kind): String? =
+ database.inboxKeyDao().getMessage(ceremony.id, ceremony.coordinatorPublicKey, kind)?.payload
+
+ private suspend fun moveTo(database: GizaDatabase, ceremony: InboxKeyCeremony, stage: InboxKeyCeremonyStage) {
+ val current = database.inboxKeyDao().getCeremony(ceremony.id) ?: return
+ if (!current.isRunning || current.stage.ordinal >= stage.ordinal) return
+ database.inboxKeyDao().upsertCeremony(current.copy(stage = stage, updatedAt = Clock.System.now()))
+ }
+
+ private suspend fun fail(database: GizaDatabase, ceremony: InboxKeyCeremony, reason: String, culprit: HexKey) {
+ val current = database.inboxKeyDao().getCeremony(ceremony.id) ?: ceremony
+ if (current.stage == InboxKeyCeremonyStage.FAILED) return
+ database.inboxKeyDao().upsertCeremony(
+ current.copy(stage = InboxKeyCeremonyStage.FAILED, failureReason = reason, culprit = culprit, updatedAt = Clock.System.now())
+ )
+ announce(database, current, ChatMessage.TYPE_INBOX_KEY_FAILED, "ended the inbox key ceremony: $reason. No key was made, and it is safe to run it again.", culprit)
+ }
+
+ // ---- the wire ------------------------------------------------------------------------------
+
+ /** Sends one of this device's messages and records it, so its own is in every aggregation. */
+ private suspend fun publishOwn(database: GizaDatabase, localChatRoom: LocalChatRoom, ceremony: InboxKeyCeremony, kind: Kind, content: String) {
+ broadcast(database, localChatRoom, ceremony, kind, content)
+ store(database, ceremony, ceremony.userPublicKey, kind, content)
+ }
+
+ /**
+ * Queues one ceremony message as an MLS inner event for the room, the path chat messages
+ * take. The proposal carries the admins as `p` tags, the participant set every device
+ * rebuilds; nothing later needs them.
+ */
+ private suspend fun broadcast(
+ database: GizaDatabase,
+ localChatRoom: LocalChatRoom,
+ ceremony: InboxKeyCeremony,
+ kind: Kind,
+ content: String,
+ proposal: Boolean = false,
+ ) {
+ val tags = InboxKeyRitualEvents.assembleTags(
+ sessionId = ceremony.id,
+ generation = if (proposal) ceremony.generation else null,
+ participants = if (proposal) ceremony.participants().filterNot { it == ceremony.userPublicKey } else emptyList(),
+ )
+ val createdAt = Clock.System.now().epochSeconds
+ val id = EventHasher.hashId(ceremony.userPublicKey, createdAt, kind, tags, content)
+ database.marmotInnerEventDao().upsert(
+ MarmotInnerEvent(
+ id = id,
+ publicKey = ceremony.userPublicKey,
+ kind = kind,
+ createdAt = Instant.fromEpochSeconds(createdAt),
+ tags = tags,
+ content = content,
+ chatRoomId = localChatRoom.chatRoom.id,
+ )
+ )
+ }
+
+ // ---- the transcript ------------------------------------------------------------------------
+
+ private suspend fun announceStarted(database: GizaDatabase, ceremony: InboxKeyCeremony) {
+ val n = ceremony.participants().size
+ val text = if (ceremony.generation == 0) {
+ "started making the group's inbox key with its $n admins. Every admin will hold it, and it finishes once all of them have taken part."
+ } else {
+ "started changing the group's inbox key with its $n admins. Every admin will hold the new one, and it finishes once all of them have taken part."
+ }
+ announce(database, ceremony, ChatMessage.TYPE_INBOX_KEY_STARTED, text, ceremony.coordinatorPublicKey)
+ }
+
+ private suspend fun announce(database: GizaDatabase, ceremony: InboxKeyCeremony, type: String, content: String, actor: HexKey) {
+ database.chatMessageDao().upsert(
+ ChatMessage(
+ senderPublicKey = actor,
+ isUserMessage = actor == ceremony.userPublicKey,
+ giftWrapPayloadId = null,
+ marmotGroupEventId = null,
+ marmotInnerEventId = null,
+ chatRoomId = ceremony.chatRoomId,
+ content = content,
+ messageType = type,
+ )
+ )
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxRefusal.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxRefusal.kt
new file mode 100644
index 00000000..1a41d77f
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxRefusal.kt
@@ -0,0 +1,239 @@
+package mobi.giza.compose.managers
+
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import mobi.giza.compose.database.GizaDatabase
+import mobi.giza.compose.database.model.FrostSigningItem
+import mobi.giza.compose.database.model.FrostSigningSession
+import mobi.giza.compose.database.model.InboxKeyCeremony
+import mobi.giza.compose.database.model.InboxSigning
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.nostr.inbox.InboxAnnouncement
+import mobi.giza.compose.nostr.inbox.InboxReplyManifest
+import mobi.giza.compose.nostr.inbox.InboxSeal
+import mobi.giza.compose.nostr.inbox.InboxWire
+import mobi.giza.compose.database.model.InboxKey
+import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
+import com.vitorpamplona.quartz.nip01Core.crypto.verify
+import kotlin.time.Clock
+
+/**
+ * What a device declines, out loud, when the group is asked to sign something about its inbox
+ * (docs/group-inbox.md, D5): the announcement of its key (10044) and of where its mail goes
+ * (10050).
+ *
+ * The signer has no allowlist, so without this a peer's 10044 reached the member as "Event of
+ * kind 10044" and could be signed whatever key it named -- including one a removed admin made,
+ * or one nobody in the group holds, either of which hands the group's mail to someone the
+ * group did not choose. Giza signs only what it can check.
+ *
+ * Checked in the four places every refusal sits in [FrostSigningManager]: on arrival, again at
+ * approval, as the decline's reason, and (for a session filed before this existed) at approval
+ * through the same call.
+ */
+object InboxRefusal {
+ const val KEY_NOT_MADE = "Giza doesn't sign an inbox key the group's admins didn't make together"
+ const val KEY_NOT_NEWEST = "Giza doesn't sign an inbox key the group has since replaced"
+ const val KEY_NOT_ADMINS = "Giza doesn't sign an inbox key made by anyone but the group's current admins"
+ const val KEY_SHAPE = "Giza doesn't sign an inbox key announcement it would not write"
+ const val RELAYS_SHAPE = "Giza doesn't sign a list of inbox relays a stranger could not reach"
+
+ // A reply (D12): every signer reads it before signing it.
+ const val REPLY_UNREADABLE = "Giza doesn't sign a sealed message it can't read"
+ const val REPLY_NO_KEY = "This device holds no inbox key for this group"
+ const val REPLY_MISMATCH = "Giza doesn't sign a reply whose copies don't all say the same thing to the people it names"
+ const val REPLY_WRONG_KEY = "Giza doesn't sign a reply sealed to a key its recipient didn't announce"
+ const val REPLY_BLANK = "Giza doesn't sign a reply with nothing in it"
+ const val REPLY_TIME = "Giza doesn't sign a reply dated outside the last two days"
+
+ private const val TWO_DAYS = 2 * 24 * 60 * 60L
+ private const val CLOCK_SLACK = 10 * 60L
+
+ /**
+ * Whether any of [events] is one this refusal is about. A seal only when it names an inbox
+ * key in its `n` tag, as every reply does: a seal without one is the group writing by
+ * threshold ECDH, which `GroupDmRefusal` reads (docs/group-threshold-ecdh.md, D13).
+ */
+ fun involves(events: List): Boolean =
+ events.any { it.kind == InboxAnnouncement.KEY_KIND || it.kind == InboxAnnouncement.RELAYS_KIND || isReplySeal(it) }
+
+ private fun isReplySeal(event: Event): Boolean = event.kind == InboxSeal.KIND && InboxSeal.encryptionKeyOf(event.tags) != null
+
+ /**
+ * Why this device declines to sign [events] in [localChatRoom] as [userPublicKey] sees it, or
+ * null when it would sign them.
+ */
+ suspend fun of(
+ database: GizaDatabase,
+ localChatRoom: LocalChatRoom,
+ userPublicKey: HexKey,
+ events: List,
+ /** A reply's sealed manifest, as its proposal carried it (D11). */
+ manifest: String? = null,
+ now: Long = Clock.System.now().epochSeconds,
+ ): String? {
+ if (events.any(::isReplySeal)) {
+ return replyRefusal(database, localChatRoom.chatRoom.id, userPublicKey, events, manifest, now)
+ }
+ for (event in events) {
+ when (event.kind) {
+ InboxAnnouncement.RELAYS_KIND ->
+ if (InboxAnnouncement.groupRelaysOf(event) == null) return RELAYS_SHAPE
+ InboxAnnouncement.KEY_KIND -> {
+ val key = InboxAnnouncement.groupKeyOf(event) ?: return KEY_SHAPE
+ keyRefusal(database, localChatRoom, userPublicKey, key)?.let { return it }
+ }
+ }
+ }
+ return null
+ }
+
+ /**
+ * D5's three checks on the key a 10044 names: it is what a ceremony in this room made, the
+ * newest one, and that ceremony was run over the admins the room has now.
+ */
+ private suspend fun keyRefusal(database: GizaDatabase, localChatRoom: LocalChatRoom, userPublicKey: HexKey, key: HexKey): String? {
+ val roomId = localChatRoom.chatRoom.id
+ val completed = database.inboxKeyDao().getCompletedCeremonies(roomId, userPublicKey)
+ val maker = completed.firstOrNull { keyOf(database, it) == key }
+ if (maker == null) {
+ // The coordinator asks for the announcement the moment its own copy of the key is
+ // made, which is routinely before this device has finished the same ceremony. Not a
+ // refusal yet: the session waits, approval checks again, and the ceremony finishing
+ // here asks again ([FrostSigningManager.resumeInboxAnnouncements]).
+ val running = database.inboxKeyDao().getRunningCeremoniesIn(roomId).any { it.userPublicKey == userPublicKey }
+ return if (running) null else KEY_NOT_MADE
+ }
+ if (completed.any { it.generation > maker.generation }) return KEY_NOT_NEWEST
+ val admins = RoomAdmins.of(database, roomId)?.admins ?: return null
+ if (admins != maker.participants().toSet()) return KEY_NOT_ADMINS
+ return null
+ }
+
+ /** What a signer reads a reply with: the key that opened its manifest, the manifest, and the one rumor. */
+ data class ReadReply(val key: InboxKey, val manifest: InboxReplyManifest, val rumor: Event)
+
+ /**
+ * D12's checks on a batch of seals. A signer reads the reply before signing it: it opens
+ * the manifest, checks every seal is sealed from the announced generation to the key its
+ * recipient announced (or their identity), opens every one, and refuses unless they all hold
+ * the same rumor, written by the group to exactly the people the manifest names.
+ */
+ private suspend fun replyRefusal(database: GizaDatabase, roomId: HexKey, userPublicKey: HexKey, events: List, manifest: String?, now: Long): String? {
+ if (events.any { it.kind != InboxSeal.KIND }) return REPLY_UNREADABLE
+ val read = when (val result = readReply(database, roomId, userPublicKey, events, manifest)) {
+ is Read.Refused -> return result.reason
+ is Read.Ok -> result.reply
+ }
+ if (read.rumor.content.isBlank()) return REPLY_BLANK
+ if (events.any { it.createdAt < now - TWO_DAYS - CLOCK_SLACK || it.createdAt > now + CLOCK_SLACK }) return REPLY_TIME
+ return null
+ }
+
+ private sealed interface Read {
+ data class Ok(val reply: ReadReply) : Read
+ data class Refused(val reason: String) : Read
+ }
+
+ private suspend fun readReply(database: GizaDatabase, roomId: HexKey, userPublicKey: HexKey, events: List, manifest: String?): Read {
+ val sealed = manifest ?: return Read.Refused(REPLY_UNREADABLE)
+ val keys = database.inboxKeyDao().getKeys(roomId, userPublicKey).filter { it.secretKey != null }
+ val (key, opened) = keys.firstNotNullOfOrNull { k ->
+ InboxReplyManifest.open(sealed, k.secretKey!!.hexToByteArray())?.let { k to it }
+ } ?: return Read.Refused(REPLY_NO_KEY)
+ if (opened.generation != key.generation || opened.seals.size != events.size) return Read.Refused(REPLY_UNREADABLE)
+ events.forEach { seal ->
+ if (!seal.pubKey.equals(roomId, ignoreCase = true) || seal.tags.size != 1 || InboxSeal.encryptionKeyOf(seal.tags) != key.publicKey) {
+ return Read.Refused(REPLY_UNREADABLE)
+ }
+ }
+ opened.seals.forEachIndexed { index, entry ->
+ val keyIsRight = if (index == opened.groupCopy) {
+ entry.recipient.equals(roomId, ignoreCase = true) && entry.key == key.publicKey && entry.announcement == null
+ } else {
+ !entry.recipient.equals(roomId, ignoreCase = true) && when (val json = entry.announcement) {
+ null -> entry.key == entry.recipient
+ else -> Event.fromJsonOrNull(json)?.let { announcement ->
+ announcement.verify() && announcement.pubKey == entry.recipient && InboxAnnouncement.announcedKeyOf(announcement) == entry.key
+ } == true
+ }
+ }
+ if (!keyIsRight) return Read.Refused(REPLY_WRONG_KEY)
+ }
+ val secret = key.secretKey!!.hexToByteArray()
+ val rumors = events.mapIndexed { index, seal ->
+ InboxSeal.rumorInside(seal.content, InboxWire.conversationKey(secret, opened.seals[index].key), roomId)
+ ?: return Read.Refused(REPLY_MISMATCH)
+ }
+ if (rumors.map { it.id }.distinct().size != 1) return Read.Refused(REPLY_MISMATCH)
+ val rumor = rumors.first()
+ if (rumor.kind != 14) return Read.Refused(REPLY_UNREADABLE)
+ val named = rumor.tags.filter { it.size >= 2 && it[0] == "p" }.map { it[1].lowercase() }.distinct().sorted()
+ val manifestRecipients = opened.seals.filterIndexed { index, _ -> index != opened.groupCopy }.map { it.recipient.lowercase() }.distinct().sorted()
+ if (named != manifestRecipients || opened.seals.size != manifestRecipients.size + 1) return Read.Refused(REPLY_MISMATCH)
+ return Read.Ok(ReadReply(key, opened, rumor))
+ }
+
+ /**
+ * What the approval screen says about a reply (D12): its words, who it goes to, and what this
+ * device could not check -- a recipient who has announced no key may have an app that cannot
+ * open a message from a group (D13).
+ */
+ suspend fun notes(database: GizaDatabase, chatRoomId: String, userPublicKey: HexKey, sessionId: String, events: List): List {
+ if (events.none(::isReplySeal)) return emptyList()
+ val manifest = database.groupInboxDao().getSigning(sessionId)?.manifest
+ val reply = (readReply(database, chatRoomId, userPublicKey, events, manifest) as? Read.Ok)?.reply
+ ?: return listOf("A private reply from the group's inbox, which this device cannot read")
+ val recipients = reply.manifest.seals.filterIndexed { index, _ -> index != reply.manifest.groupCopy }
+ val names = database.profileDao().getProfileByPublicKeys(recipients.map { it.recipient })
+ .associate { it.publicKey to it.humanReadableNameOrPubkey() }
+ return buildList {
+ add("The group would say: " + reply.rumor.content)
+ add("To " + recipients.joinToString(", ") { names[it.recipient] ?: it.recipient.take(8) })
+ recipients.filter { it.announcement == null }.forEach {
+ add((names[it.recipient] ?: it.recipient.take(8)) + " has announced no inbox key, so their app may not be able to open a message from a group")
+ }
+ }
+ }
+
+ /** The manifest a resent proposal has to carry again, as it came. */
+ suspend fun carriedTagsFor(database: GizaDatabase, sessionId: String): Array> =
+ database.groupInboxDao().getSigning(sessionId)?.manifest?.let { arrayOf(InboxReplyManifest.tag(it)) } ?: emptyArray()
+
+ /** The key [ceremony] made, recomputing it on a watcher's device that missed it at the time. */
+ private suspend fun keyOf(database: GizaDatabase, ceremony: InboxKeyCeremony): HexKey? =
+ ceremony.inboxPublicKey ?: InboxKeyRitualManager.keyWatched(database, ceremony)
+
+ /**
+ * Whether this device can sign [items] on its owner's behalf (D5): a rotation's 10044 alone,
+ * naming a key this device holds the secret of, in a room whose quorum has announced an
+ * inbox before. The decision to have an inbox was asked; keeping it is what a rotation is.
+ */
+ suspend fun vouchesFor(database: GizaDatabase, localChatRoom: LocalChatRoom, session: FrostSigningSession, items: List): Boolean {
+ val events = items.mapNotNull { Event.fromJsonOrNull(it.unsignedEventJson) }
+ val announcement = events.singleOrNull()?.takeIf { it.kind == InboxAnnouncement.KEY_KIND } ?: return false
+ if (of(database, localChatRoom, session.userPublicKey, events) != null) return false
+ val key = InboxAnnouncement.groupKeyOf(announcement) ?: return false
+ val roomId = localChatRoom.chatRoom.id
+ // Never on the strength of a ceremony still running: the refusal lets one wait, and
+ // vouching is for a key this device has.
+ val held = database.inboxKeyDao().getKeys(roomId, session.userPublicKey)
+ if (held.none { it.publicKey == key && it.secretKey != null }) return false
+ val announcedBefore = database.groupSignedEventDao().getByChatRoomIdAndKind(roomId, InboxAnnouncement.KEY_KIND)
+ return announcedBefore.any { it.publicKey == roomId && InboxAnnouncement.groupKeyOf(it.kind, it.tags, it.content) != key }
+ }
+
+ /** Keeps why [sessionId] was refused, so the decline can say it. */
+ suspend fun remember(database: GizaDatabase, sessionId: String, chatRoomId: String, refusal: String?, manifest: String? = null) {
+ val existing = database.groupInboxDao().getSigning(sessionId)
+ database.groupInboxDao().upsertSigning(
+ (existing ?: InboxSigning(sessionId = sessionId, chatRoomId = chatRoomId)).copy(
+ refusal = refusal ?: existing?.refusal,
+ manifest = manifest ?: existing?.manifest,
+ )
+ )
+ }
+
+ suspend fun reasonFor(database: GizaDatabase, sessionId: String): String? =
+ database.groupInboxDao().getSigning(sessionId)?.refusal
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxReplies.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxReplies.kt
new file mode 100644
index 00000000..11de5328
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxReplies.kt
@@ -0,0 +1,225 @@
+package mobi.giza.compose.managers
+
+import co.touchlab.kermit.Logger
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
+import com.vitorpamplona.quartz.nip01Core.crypto.verify
+import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
+import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
+import com.vitorpamplona.quartz.nip59Giftwrap.rumors.RumorAssembler
+import com.vitorpamplona.quartz.utils.TimeUtils
+import kotlin.time.Clock
+import mobi.giza.compose.database.GizaDatabase
+import mobi.giza.compose.database.model.FrostSigningSession
+import mobi.giza.compose.database.model.GroupInboxMessage
+import mobi.giza.compose.database.model.GroupInboxPublication
+import mobi.giza.compose.database.model.InboxKeyState
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.nostr.Relays
+import mobi.giza.compose.nostr.inbox.InboxAnnouncement
+import mobi.giza.compose.nostr.inbox.InboxConversation
+import mobi.giza.compose.nostr.inbox.InboxReplyManifest
+import mobi.giza.compose.nostr.inbox.InboxSeal
+import mobi.giza.compose.nostr.inbox.InboxWire
+import mobi.giza.compose.nostr.inbox.InboxWrap
+
+/**
+ * The group answering from its inbox (docs/group-inbox.md, D10 to D13).
+ *
+ * A reply is one rumor, authored by the group, sealed once per recipient and once to the group
+ * itself, from the inbox key the group announced. The seals are what the quorum signs; nothing
+ * leaves until it has. Then the device that proposed it wraps each signed seal and owes the
+ * wraps to the recipients' relays, and the group's copy to the group's, which is how every
+ * admin sees the reply.
+ */
+object InboxReplies {
+ private val logger = Logger.withTag("InboxReplies")
+
+ /** Who a seal is to and the key it is sealed with, and the 10044 that says so. */
+ data class Recipient(val publicKey: HexKey, val encryptionKey: HexKey, val announcement: Event?)
+
+ /** A reply ready to propose: the seals to sign, in order, and the manifest that explains them. */
+ data class Built(val rumor: Event, val seals: List>, val manifest: InboxReplyManifest)
+
+ /**
+ * Builds a reply from the group of [roomId] to [recipients], answering [replyTo], from the
+ * inbox key [inboxSecret] of [generation].
+ */
+ fun build(
+ roomId: HexKey,
+ recipients: List,
+ text: String,
+ replyTo: HexKey?,
+ inboxSecret: ByteArray,
+ generation: Int,
+ now: Long = TimeUtils.now(),
+ sealTime: () -> Long = { TimeUtils.randomWithTwoDays() },
+ ): Built {
+ require(text.isNotBlank()) { "A reply needs something to say" }
+ require(recipients.isNotEmpty()) { "A reply needs someone to go to" }
+ val ordered = recipients.distinctBy { it.publicKey }.sortedBy { it.publicKey }
+ val tags = buildList {
+ ordered.forEach { add(arrayOf("p", it.publicKey)) }
+ replyTo?.let { add(arrayOf("e", it, "", "reply")) }
+ }.toTypedArray()
+ val rumor = RumorAssembler.assembleRumor(pubKey = roomId, ev = EventTemplate(now, 14, tags, text))
+
+ val inboxKey = InboxWire.publicKeyOf(inboxSecret)
+ val entries = ordered.map { InboxReplyManifest.Entry(it.publicKey, it.encryptionKey, it.announcement?.toJson()) } +
+ InboxReplyManifest.Entry(roomId, inboxKey, null)
+ val seals = entries.map { InboxSeal.template(rumor, inboxSecret, it.key, sealTime()) }
+ return Built(rumor, seals, InboxReplyManifest(generation, entries, groupCopy = entries.lastIndex))
+ }
+
+ /** The key a person reads encrypted mail with, as this device last heard: their 10044, or their identity. */
+ suspend fun recipientOf(database: GizaDatabase, publicKey: HexKey): Recipient {
+ val announcement = database.nostrEventDao().getNostrEventByPublicKeyAndKind(publicKey, InboxAnnouncement.KEY_KIND)
+ ?.toEvent()?.takeIf { it.verify() }
+ val key = announcement?.let { InboxAnnouncement.announcedKeyOf(it) }
+ return Recipient(publicKey, key ?: publicKey, announcement.takeIf { key != null })
+ }
+
+ /** Whether [publicKey] has said, with a 10044, which key reads their mail (D13's warning when not). */
+ suspend fun hasAnnouncedKey(database: GizaDatabase, publicKey: HexKey): Boolean =
+ recipientOf(database, publicKey).announcement != null
+
+ /**
+ * Proposes a reply in [localChatRoom]'s conversation [conversationId], answering its newest
+ * message, from the key the group has announced. Throws with a reason a person can read when
+ * there is nothing to answer, or no announced key this device holds.
+ */
+ suspend fun propose(
+ database: GizaDatabase,
+ localChatRoom: LocalChatRoom,
+ userPublicKey: HexKey,
+ conversationId: String,
+ text: String,
+ ): FrostSigningSession {
+ val roomId = localChatRoom.chatRoom.id
+ val conversation = database.groupInboxDao().getConversation(roomId, conversationId)
+ val newest = conversation.lastOrNull() ?: throw IllegalStateException("There is nothing here to reply to")
+ // D14: sealed from the key the group announced, never a newer one it has not.
+ val key = database.inboxKeyDao().getKeys(roomId, userPublicKey)
+ .firstOrNull { it.state == InboxKeyState.ANNOUNCED && it.secretKey != null }
+ ?: throw IllegalStateException("The group has announced no inbox key this device holds")
+ val recipients = newest.participantList().map { recipientOf(database, it) }
+ val built = build(
+ roomId = roomId,
+ recipients = recipients,
+ text = text,
+ replyTo = conversation.lastOrNull { !it.outgoing }?.rumorId,
+ inboxSecret = key.secretKey!!.hexToByteArray(),
+ generation = key.generation,
+ )
+ val sealed = built.manifest.seal(key.secretKey.hexToByteArray())
+ val session = FrostSigningManager.proposeSigningBatch(
+ database, localChatRoom, userPublicKey,
+ events = built.seals,
+ proposalTags = arrayOf(InboxReplyManifest.tag(sealed)),
+ )
+ InboxRefusal.remember(database, session.id, roomId, refusal = null, manifest = sealed)
+ logger.i("Proposed a reply to ${recipients.size} in ${roomId.take(8)} as session ${session.id.take(8)}")
+ return session
+ }
+
+ /**
+ * What a signed reply leaves (D10), on every device that took part: on the device that
+ * proposed it, a wrap per seal owed to its recipient's relays and the group's copy filed as
+ * an outgoing message at once. Every other admin's device files the copy when it arrives.
+ */
+ suspend fun onSigned(database: GizaDatabase, session: FrostSigningSession, signedEvents: List) {
+ // A reply's seals name the inbox key in an `n` tag; a seal without one is the group
+ // writing by threshold ECDH, which `GroupDmSender` wraps (docs/group-threshold-ecdh.md).
+ val seals = signedEvents.filter {
+ it.kind == InboxSeal.KIND && it.pubKey.equals(session.chatRoomId, ignoreCase = true) && InboxSeal.encryptionKeyOf(it.tags) != null
+ }
+ if (seals.isEmpty() || !session.isCoordinator()) return
+ wrapAndOwe(database, session, seals)
+ }
+
+ /**
+ * Wraps [seals] again and owes them to relays: what a person does from the conversation when
+ * the device that proposed a reply never got it out. New wraps of the same seals; the group's
+ * side files them as the one message they are.
+ */
+ suspend fun sendAgain(database: GizaDatabase, sessionId: String): Boolean {
+ val session = database.frostSigningSessionDao().getSessionById(sessionId) ?: return false
+ val seals = database.groupSignedEventDao().getByChatRoomIdAndKind(session.chatRoomId, InboxSeal.KIND)
+ .filter { it.frostSigningSessionId == sessionId }
+ .map { it.toEvent() }
+ if (seals.isEmpty()) return false
+ wrapAndOwe(database, session, seals)
+ return true
+ }
+
+ private suspend fun wrapAndOwe(database: GizaDatabase, session: FrostSigningSession, seals: List) {
+ val roomId = session.chatRoomId
+ val signing = database.groupInboxDao().getSigning(session.id) ?: run {
+ logger.w("Signed reply ${session.id.take(8)} has no manifest here; not sending it")
+ return
+ }
+ val keys = database.inboxKeyDao().getKeys(roomId, session.userPublicKey).filter { it.secretKey != null }
+ val opened = keys.firstNotNullOfOrNull { key ->
+ signing.manifest?.let { InboxReplyManifest.open(it, key.secretKey!!.hexToByteArray()) }?.let { key to it }
+ } ?: run {
+ logger.w("Signed reply ${session.id.take(8)}: no key here opens its manifest; not sending it")
+ return
+ }
+ val (key, manifest) = opened
+ // In the order the proposal fixed, which is the manifest's.
+ val signedById = seals.associateBy { it.id }
+ val ordered = database.frostSigningSessionDao().getItems(session.id).sortedBy { it.itemIndex }.map { signedById[it.eventId] }
+ if (ordered.size != manifest.seals.size) return
+
+ manifest.seals.forEachIndexed { index, entry ->
+ val seal = ordered[index] ?: return@forEachIndexed
+ val relays = if (index == manifest.groupCopy) {
+ InboxAnnouncements.relaysOf(database, roomId)
+ } else {
+ relaysOf(database, entry.recipient)
+ }
+ val wrap = InboxWrap.wrap(seal, entry.recipient, entry.key, relays.firstOrNull())
+ database.groupInboxDao().upsertPublication(
+ GroupInboxPublication(
+ eventId = wrap.id,
+ chatRoomId = roomId,
+ kind = wrap.kind,
+ eventJson = wrap.toJson(),
+ relays = relays.joinToString(",") { it.url },
+ signingSessionId = session.id,
+ recipientPublicKey = entry.recipient,
+ )
+ )
+ }
+
+ // The group's copy, filed now so the reply is in the conversation before it comes back.
+ val copy = ordered[manifest.groupCopy] ?: return
+ val rumor = InboxSeal.rumorInside(copy.content, InboxReplyManifest.selfConversationKey(key.secretKey!!.hexToByteArray()), roomId) ?: return
+ val participants = InboxConversation.participantsOf(rumor, roomId)
+ database.groupInboxDao().insertMessage(
+ GroupInboxMessage(
+ chatRoomId = roomId,
+ rumorId = rumor.id,
+ wrapId = null,
+ conversationId = InboxConversation.idOf(participants),
+ participants = participants.joinToString(","),
+ senderPublicKey = roomId,
+ kind = rumor.kind,
+ rumorJson = InboxSeal.rumorJson(rumor),
+ createdAt = rumor.createdAt,
+ generation = manifest.generation,
+ outgoing = true,
+ signingSessionId = session.id,
+ readAt = Clock.System.now(),
+ )
+ )
+ }
+
+ /** Where [publicKey] reads private mail: their 10050, as this device last heard it. */
+ private suspend fun relaysOf(database: GizaDatabase, publicKey: HexKey): List =
+ database.nostrEventDao().getNostrEventByPublicKeyAndKind(publicKey, InboxAnnouncement.RELAYS_KIND)
+ ?.toEvent()?.let { InboxAnnouncement.announcedRelaysOf(it) }
+ ?.ifEmpty { null }
+ ?: Relays.DefaultDMRelayList
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxRotation.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxRotation.kt
new file mode 100644
index 00000000..348a44ca
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/InboxRotation.kt
@@ -0,0 +1,70 @@
+package mobi.giza.compose.managers
+
+import co.touchlab.kermit.Logger
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import kotlinx.coroutines.CancellationException
+import mobi.giza.compose.ExperimentalFeatures
+import mobi.giza.compose.database.GizaDatabase
+import mobi.giza.compose.database.model.InboxKeyState
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+
+/**
+ * When the group's inbox key has to change because its admins have (docs/group-inbox.md, D14).
+ *
+ * The rule is read off what every admin's device already holds, rather than off the change that
+ * caused it: the key was made by a ceremony over some set of admins, and the room's admin policy
+ * now names another. That covers a removal, a demotion, a step-down and a promotion the same way,
+ * and a change that landed while the app was closed.
+ *
+ * One admin starts it, so the devices do not race: the one whose key sorts first among the
+ * admins now. Nobody is asked -- the group's signature on the admin change was the decision --
+ * and if that admin's device is away, any admin can rotate by hand from the inbox's settings.
+ * It waits for whatever share rotation the same change owes ([InboxKeyRitualManager.refusal]
+ * reads the same hold), so the two run in turn.
+ */
+object InboxRotation {
+ private val logger = Logger.withTag("InboxRotation")
+
+ /**
+ * Whether [localChatRoom]'s inbox key was made over admins the room no longer has, as
+ * [userPublicKey]'s device sees it. False where there is no key, or the admins cannot be read.
+ */
+ suspend fun isOwed(database: GizaDatabase, localChatRoom: LocalChatRoom, userPublicKey: HexKey): Boolean {
+ val roomId = localChatRoom.chatRoom.id
+ val keys = database.inboxKeyDao().getKeys(roomId, userPublicKey).filter { it.state != InboxKeyState.WIPED }
+ if (keys.isEmpty()) return false
+ val newest = database.inboxKeyDao().getCompletedCeremonies(roomId, userPublicKey).firstOrNull() ?: return false
+ val admins = RoomAdmins.of(database, roomId)?.admins ?: return false
+ return admins != newest.participants().toSet()
+ }
+
+ /** Whether [userPublicKey] is the admin whose device starts an owed rotation in [chatRoomId]. */
+ suspend fun startsIt(database: GizaDatabase, chatRoomId: String, userPublicKey: HexKey): Boolean =
+ RoomAdmins.of(database, chatRoomId)?.admins?.minOrNull() == userPublicKey
+
+ /**
+ * Starts every rotation [userPublicKey]'s device owes. Run by the governance follow-through and
+ * the sweep; repeats nothing, since a running ceremony is not started twice. Returns how many it
+ * started.
+ */
+ suspend fun pass(database: GizaDatabase, userPublicKey: HexKey, nostrPrivateKey: ByteArray): Int {
+ if (!ExperimentalFeatures.groupInbox) return 0
+ var started = 0
+ database.inboxKeyDao().getHeldKeys(userPublicKey).map { it.chatRoomId }.distinct().forEach { roomId ->
+ val room = database.chatRoomDao().findChatRoomById(roomId) ?: return@forEach
+ if (!isOwed(database, room, userPublicKey) || !startsIt(database, roomId, userPublicKey)) return@forEach
+ if (database.inboxKeyDao().getRunningCeremoniesIn(roomId).any { it.userPublicKey == userPublicKey }) return@forEach
+ if (InboxKeyRitualManager.refusal(database, room, userPublicKey) != null) return@forEach
+ try {
+ InboxKeyRitualManager.propose(database, room, userPublicKey, nostrPrivateKey)
+ started += 1
+ logger.i("The admins of ${roomId.take(8)} changed; rotating its inbox key")
+ } catch (e: CancellationException) {
+ throw e
+ } catch (e: Throwable) {
+ logger.w("Could not rotate the inbox key of ${roomId.take(8)}: ${e.message}")
+ }
+ }
+ return started
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/LiveSubscriptionManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/LiveSubscriptionManager.kt
index 7d646f40..65f820a6 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/LiveSubscriptionManager.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/LiveSubscriptionManager.kt
@@ -41,6 +41,8 @@ import mobi.giza.compose.ExperimentalFeatures
import mobi.giza.compose.nostr.confederation.ConfederationKinds
import mobi.giza.compose.repository.ChatRepository
import mobi.giza.compose.repository.ConfederationRepository
+import mobi.giza.compose.repository.GroupInboxRepository
+import mobi.giza.compose.nostr.inbox.InboxWrap
import kotlinx.coroutines.flow.combine
import mobi.giza.compose.repository.NostrRepository
import kotlin.concurrent.Volatile
@@ -83,6 +85,12 @@ class LiveSubscriptionManager(
* Phase 7). Null, or the feature off, and nothing is asked for.
*/
private val groupDmRepository: mobi.giza.compose.repository.GroupDmRepository? = null,
+ /**
+ * Where gift wraps to a group this identity holds an inbox key for are filed
+ * (docs/group-inbox.md, D8), never as `NostrEvent` rows nor through the personal inbox.
+ * Null, or the feature off, and nothing is asked for.
+ */
+ private val groupInboxRepository: GroupInboxRepository? = null,
) {
private val logger = Logger.withTag(TAG)
@@ -129,6 +137,9 @@ class LiveSubscriptionManager(
/** The confederation's public events, on the public relays they are published to. */
const val CONFEDERATION_SUB_ID = "live-confederation"
+ /** Gift wraps to the groups whose inbox key this identity holds (docs/group-inbox.md, D8). */
+ const val GROUP_INBOX_SUB_ID = "live-group-inbox"
+
/** Ids per tag array in the confederation filter, for the reason [MAX_GROUPS_PER_SUBSCRIPTION] gives. */
private const val MAX_CONFEDERATION_IDS = 100
@@ -232,6 +243,18 @@ class LiveSubscriptionManager(
Filter(kinds = ConfederationKinds.ANSWERS.toList(), tags = mapOf("e" to chunk), limit = INITIAL_GROUP_HISTORY_LIMIT)
}
+ /**
+ * Every gift wrap `p`-tagged to one of [recipients]: a group's npub, which is its room's
+ * id and where nostr-protocol/nips#2361 has a sender tag it, and the group's inbox keys,
+ * where an app that only encrypts to the announced key tags it instead. No `since`, as
+ * for our own inbox: a wrap's `created_at` is back-dated by up to two days, and a
+ * `since` that looks safe is how mail goes missing.
+ */
+ internal fun groupInboxFilters(recipients: List): List =
+ recipients.distinct().sorted().chunked(MAX_CONFEDERATION_IDS).map { chunk ->
+ Filter(kinds = listOf(InboxWrap.KIND), tags = mapOf("p" to chunk), limit = INITIAL_GROUP_HISTORY_LIMIT)
+ }
+
/** The keyed rooms a confederation could name: Marmot rooms we are still in, by their own ids. */
internal fun confederationRoomIdsFrom(rooms: List): List =
rooms
@@ -325,6 +348,10 @@ class LiveSubscriptionManager(
groupDmRepository?.takeIf { ExperimentalFeatures.groupDirectMessages }?.let { repository ->
launch { followGroupDirectMessages(publicKey = publicKey, keyPair = keyPair, repository = repository) }
}
+
+ groupInboxRepository?.takeIf { ExperimentalFeatures.groupInbox }?.let { repository ->
+ launch { followGroupInboxes(publicKey = publicKey, keyPair = keyPair, repository = repository) }
+ }
}
/**
@@ -360,6 +387,39 @@ class LiveSubscriptionManager(
}
}
+ /**
+ * Keeps one subscription per relay a group's mail is announced to arrive on, for every
+ * group this identity holds an inbox key for, re-sent when that set changes. What arrives
+ * goes to [repository] (docs/group-inbox.md, D8).
+ */
+ @OptIn(FlowPreview::class)
+ private suspend fun followGroupInboxes(publicKey: HexKey, keyPair: KeyPair, repository: GroupInboxRepository) {
+ repository.observeRoutes(publicKey)
+ .distinctUntilChanged()
+ .debounce(GROUP_CHANGE_DEBOUNCE)
+ .collectLatest { routes ->
+ if (routes.isEmpty()) return@collectLatest
+ val filters = groupInboxFilters(routes.flatMap { listOf(it.chatRoomId) + it.keys })
+ val relays = (routes.flatMap { it.relays } + Relays.DefaultDMRelayList).map { it.url }.distinct()
+ coroutineScope {
+ relays.forEach { relay ->
+ launch {
+ runLiveSubscription(
+ subId = GROUP_INBOX_SUB_ID,
+ relayUrl = relay,
+ filters = { filters },
+ keyPair = keyPair,
+ onEvent = { nostrEvent, _ ->
+ runCatching { repository.receive(nostrEvent.toEvent(), publicKey) }
+ .onFailure { logger.w(throwable = it) { "Could not file inbox wrap ${nostrEvent.id}" } }
+ },
+ )
+ }
+ }
+ }
+ }
+ }
+
/**
* Keeps one subscription per public relay open on [confederationFilters], re-sent whenever
* the rooms or the open proposals change. Events go to [repository], never to the
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotInboundManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotInboundManager.kt
index 6360103e..d5d22228 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotInboundManager.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotInboundManager.kt
@@ -278,6 +278,14 @@ object MarmotInboundManager {
if ((disbanded || removedUs) && localChatRoom.chatRoom.leftGroupAt == null) {
database.chatRoomDao().upsert(localChatRoom.chatRoom.copy(leftGroupAt = Clock.System.now()))
}
+
+ // An admin no longer: this device lets go of the group's inbox (docs/group-inbox.md, D14).
+ GroupInboxManager.forgetIfNotAdmin(
+ database = database,
+ chatRoomId = localChatRoom.chatRoom.id,
+ userPublicKey = userPublicKey,
+ stillAdmin = !disbanded && !removedUs && userPublicKey in mlsGroup.currentAdminIdentities(),
+ )
}
private suspend fun memberName(database: GizaDatabase, publicKey: HexKey): String =
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/DirectMessagePeerSync.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/DirectMessagePeerSync.kt
index 1462420f..37b255b4 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/DirectMessagePeerSync.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/DirectMessagePeerSync.kt
@@ -5,6 +5,7 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
import com.vitorpamplona.quartz.nip17Dm.settings.DmRelayListEvent
import com.vitorpamplona.quartz.nip65RelayList.AdvertisedRelayListEvent
+import mobi.giza.compose.nostr.inbox.InboxAnnouncement
import mobi.giza.compose.database.model.NegentropySynchronizeRequest
import mobi.giza.compose.database.model.SynchronizeNostrEventRequest
import mobi.giza.compose.database.model.types.SynchronizationFilter
@@ -51,6 +52,9 @@ object DirectMessagePeerSync {
KeyPackageEvent.KIND,
DmRelayListEvent.KIND,
AdvertisedRelayListEvent.KIND,
+ // The key a peer reads encrypted mail with, if they decoupled it (NIP-4E): what a
+ // group's reply to them is sealed to (docs/group-inbox.md, D10).
+ InboxAnnouncement.KEY_KIND,
)
/**
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/confederation/ConfederationCharterEvent.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/confederation/ConfederationCharterEvent.kt
new file mode 100644
index 00000000..ee5fc770
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/confederation/ConfederationCharterEvent.kt
@@ -0,0 +1,51 @@
+package mobi.giza.compose.nostr.confederation
+
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.Kind
+import mobi.giza.compose.nostr.confederation.tags.ConfederationGroupTag
+
+/**
+ * A confederation saying, with its own key, which groups it is made of (docs/confederation.md,
+ * Phase 15).
+ *
+ * ```
+ * kind: 9434
+ * pubkey: set by the signing attempt
+ * content: a sentence for clients that know nothing of this kind
+ * tags:
+ * ["p", , "", "group"] one per member group
+ * ["name", ]
+ * ["alt", ...]
+ * ```
+ *
+ * The one public statement that the confederation exists, and the only way a group's members
+ * who are not its admins hear of it: the `p` tags reach every member group's devices through the
+ * same relay filter that brings them proposals. What it proves is that whoever holds the
+ * confederation's key named these groups -- a reader cannot check the roster behind the key, any
+ * more than it can tell a group's key from a person's.
+ */
+object ConfederationCharterEvent {
+ val KIND: Kind = ConfederationKinds.CHARTER
+ const val ALT = "A confederation of nostr groups, naming its member groups"
+
+ data class Charter(val id: HexKey, val confederation: HexKey, val name: String, val groups: List)
+
+ fun assembleTags(name: String, groups: List): Array> = (
+ groups.sorted().map { ConfederationGroupTag.assemble(it, null) } + listOf(
+ arrayOf(ConfederationProposalEvent.NAME_TAG, name),
+ arrayOf(ConfederationProposalEvent.ALT_TAG, ALT),
+ )
+ ).toTypedArray()
+
+ fun content(name: String, groupCount: Int): String = "$name, a confederation of $groupCount groups"
+
+ fun parse(event: Event): Charter? = runCatching {
+ if (event.kind != KIND || !ConfederationKinds.isPublicKey(event.pubKey)) return null
+ val groups = event.tags.mapNotNull(ConfederationGroupTag::parse).map { it.groupPublicKey }
+ if (groups.size !in ConfederationKinds.MIN_GROUPS..ConfederationKinds.MAX_GROUPS) return null
+ if (groups.any { !ConfederationKinds.isPublicKey(it) } || groups.toSet().size != groups.size) return null
+ val name = ConfederationProposalEvent.single(event.tags, ConfederationProposalEvent.NAME_TAG)?.takeIf { it.isNotBlank() } ?: return null
+ Charter(event.id, event.pubKey, name, groups)
+ }.getOrNull()
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/confederation/ConfederationKinds.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/confederation/ConfederationKinds.kt
index 01df2e11..9d8127c5 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/confederation/ConfederationKinds.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/confederation/ConfederationKinds.kt
@@ -20,7 +20,10 @@ object ConfederationKinds {
const val REJECTION: Kind = 9432
const val WITHDRAWAL: Kind = 9433
- val ALL: Set = setOf(PROPOSAL, ACCEPTANCE, REJECTION, WITHDRAWAL)
+ /** The confederation's own public statement of which groups it is made of (Phase 15). Signed by the confederation. */
+ const val CHARTER: Kind = 9434
+
+ val ALL: Set = setOf(PROPOSAL, ACCEPTANCE, REJECTION, WITHDRAWAL, CHARTER)
/** The answers a group can give, and the one a proposing group can take back. */
val ANSWERS: Set = setOf(ACCEPTANCE, REJECTION, WITHDRAWAL)
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/confederation/ConfederationSigningEvents.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/confederation/ConfederationSigningEvents.kt
new file mode 100644
index 00000000..e1ef3989
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/confederation/ConfederationSigningEvents.kt
@@ -0,0 +1,80 @@
+package mobi.giza.compose.nostr.confederation
+
+import com.vitorpamplona.quartz.nip01Core.core.Kind
+import kotlinx.serialization.json.Json
+import kotlinx.serialization.json.JsonArray
+import kotlinx.serialization.json.JsonObject
+import kotlinx.serialization.json.JsonPrimitive
+import kotlinx.serialization.json.buildJsonObject
+import kotlinx.serialization.json.int
+import kotlinx.serialization.json.put
+
+/**
+ * The confederation signing as itself, on the wire (docs/confederation.md, Phase 14): rumors in the
+ * confederation's own Marmot room, over upstream's Option A signing.
+ *
+ * | kind | from | carries |
+ * |-------|---------------|----------------------------------------------------------------------|
+ * | 30390 | the proposer | the unsigned event, authored by the confederation's room |
+ * | 30391 | each person | per role, by group: whether that role will sign ("yes" or "no") |
+ * | 30392 | the proposer | the selection it fixed from the yeses, and the D_sign it encodes |
+ * | 30393 | each selected | per role: its public nonce |
+ * | 30394 | each selected | per role: its confirmation of the transcript and the event |
+ * | 30395 | each selected | per role: its member partial |
+ * | 30399 | anyone | failure, with a reason |
+ *
+ * Only the selection needs a coordinator: approvals arrive in a different order on every device,
+ * and somebody has to say which of them sign. Everything after it -- the nonce transcript, the
+ * confirmation certificate, each group's partial and the signature -- takes no secret, so every
+ * device computes it from the public messages it holds, and nobody can be handed a wrong one.
+ * Group coordinators, which the protocol leaves to the application, are therefore every device.
+ */
+object ConfederationSigningEvents {
+ const val PROPOSAL: Kind = 30390
+ const val AVAILABILITY: Kind = 30391
+ const val SESSION: Kind = 30392
+ const val NONCES: Kind = 30393
+ const val CONFIRMATIONS: Kind = 30394
+ const val PARTIALS: Kind = 30395
+ const val FAILURE: Kind = 30399
+
+ val ALL: Set = setOf(PROPOSAL, AVAILABILITY, SESSION, NONCES, CONFIRMATIONS, PARTIALS, FAILURE)
+
+ /** Sent once per person, a value per role. */
+ val PER_PERSON: Set = setOf(AVAILABILITY, NONCES, CONFIRMATIONS, PARTIALS)
+
+ fun isSigningKind(kind: Kind): Boolean = kind in ALL
+
+ const val SESSION_TAG = "confederation_signing"
+ const val YES = "yes"
+ const val NO = "no"
+
+ fun sessionTag(sessionId: String): Array = arrayOf(SESSION_TAG, sessionId)
+
+ fun parseSessionId(tags: Array>): String? =
+ tags.firstOrNull { it.size >= 2 && it[0] == SESSION_TAG }?.get(1)?.takeIf(ConfederationKinds::isHex32)
+
+ private val json = Json { ignoreUnknownKeys = false }
+
+ /** The proposer's selection, by group id, and the D_sign it encodes. */
+ data class Session(val selection: Map>, val dSign: String) {
+ fun encode(): String = buildJsonObject {
+ put("selection", JsonObject(selection.toSortedMap().entries.associate { (g, admins) ->
+ g.toString() to JsonArray(admins.sorted().map { JsonPrimitive(it.toInt()) })
+ }))
+ put("dSign", dSign)
+ }.toString()
+
+ companion object {
+ fun decode(content: String): Session? = runCatching {
+ val obj = json.parseToJsonElement(content) as JsonObject
+ Session(
+ selection = (obj["selection"] as JsonObject).entries.associate { (g, admins) ->
+ g.toUInt() to (admins as JsonArray).map { (it as JsonPrimitive).int.toUInt() }.toSet()
+ },
+ dSign = (obj["dSign"] as JsonPrimitive).content,
+ )
+ }.getOrNull()
+ }
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxAnnouncement.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxAnnouncement.kt
new file mode 100644
index 00000000..30829f34
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxAnnouncement.kt
@@ -0,0 +1,85 @@
+package mobi.giza.compose.nostr.inbox
+
+import com.vitorpamplona.quartz.experimental.decoupling.setup.EncryptionKeyListEvent
+import com.vitorpamplona.quartz.experimental.decoupling.setup.tags.KeyTag
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
+import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
+import com.vitorpamplona.quartz.nip17Dm.settings.DmRelayListEvent
+import com.vitorpamplona.quartz.nip17Dm.settings.tags.RelayTag
+import mobi.giza.compose.nostr.RelayUrlInput
+
+/**
+ * The two public events that make a group writable to (docs/group-inbox.md, D5 and D6), both
+ * signed by the group's quorum:
+ *
+ * - a kind **10044**, NIP-4E's announcement (nostr-protocol/nips#1647): `[["n", E]]` and nothing
+ * else, where `E` is the inbox key;
+ * - a kind **10050**, NIP-17's DM relay list: where senders should put what they write.
+ *
+ * Read by quartz's own [EncryptionKeyListEvent] and [DmRelayListEvent], so the group's events
+ * parse the way every other client's do.
+ */
+object InboxAnnouncement {
+ const val KEY_KIND = EncryptionKeyListEvent.KIND
+ const val RELAYS_KIND = DmRelayListEvent.KIND
+
+ /** The group's 10044, naming [inboxKey] alone. */
+ fun keyTemplate(inboxKey: HexKey, createdAt: Long): EventTemplate {
+ require(InboxWire.isHex32(inboxKey)) { "an inbox key is a 32-byte x-only key" }
+ val built = EncryptionKeyListEvent.build(inboxKey, createdAt)
+ return EventTemplate(built.createdAt, built.kind, built.tags, built.content)
+ }
+
+ /** The group's 10050, listing [relays]. */
+ fun relaysTemplate(relays: List, createdAt: Long): EventTemplate {
+ require(relays.isNotEmpty()) { "an inbox nobody can deliver to is not an inbox" }
+ return EventTemplate(createdAt, RELAYS_KIND, DmRelayListEvent.createTagArray(relays), "")
+ }
+
+ /**
+ * The key a 10044 announces, read as any NIP-4E client reads it: the first well-formed `n`.
+ * For someone else's announcement, which may carry more than this app writes.
+ */
+ fun announcedKeyOf(event: Event): HexKey? {
+ if (event.kind != KEY_KIND) return null
+ return event.tags.firstNotNullOfOrNull(KeyTag::parse)?.pubkey
+ }
+
+ /**
+ * The key a group's own 10044 announces, or null if [event] is not shaped the way this app
+ * writes one: exactly one tag, an `n` with a key and no nonce, and no content. A signer
+ * refuses anything else (docs/group-inbox.md, D5): a second `n`, or a legacy nonce, would be
+ * the group announcing something nobody agreed to.
+ */
+ fun groupKeyOf(event: Event): HexKey? = groupKeyOf(event.kind, event.tags, event.content)
+
+ fun groupKeyOf(kind: Int, tags: Array>, content: String): HexKey? {
+ if (kind != KEY_KIND || content.isNotEmpty()) return null
+ val tag = tags.singleOrNull() ?: return null
+ if (tag.size != 2) return null
+ val key = KeyTag.parse(tag) ?: return null
+ return key.pubkey.takeIf { key.nonce == null && tag[1] == key.pubkey }
+ }
+
+ /**
+ * The relays a group's 10050 lists, or null if [event] is not one a group should sign: no
+ * relays, anything but `relay` tags, content, or a relay a stranger could not reach
+ * ([RelayUrlInput.relayUrlOrNull]: `wss://`, not loopback).
+ */
+ fun groupRelaysOf(event: Event): List? = groupRelaysOf(event.kind, event.tags, event.content)
+
+ fun groupRelaysOf(kind: Int, tags: Array>, content: String): List? {
+ if (kind != RELAYS_KIND || content.isNotEmpty() || tags.isEmpty()) return null
+ val relays = tags.map { tag ->
+ if (tag.size < 2 || tag[0] != RelayTag.TAG_NAME) return null
+ RelayUrlInput.relayUrlOrNull(tag[1]) ?: return null
+ }
+ return relays.distinct()
+ }
+
+ /** The relays anyone's 10050 lists, as NIP-17 senders read them. */
+ fun announcedRelaysOf(event: Event): List =
+ if (event.kind != RELAYS_KIND) emptyList() else event.tags.mapNotNull(RelayTag::parse)
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxConversation.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxConversation.kt
new file mode 100644
index 00000000..62bde27b
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxConversation.kt
@@ -0,0 +1,29 @@
+package mobi.giza.compose.nostr.inbox
+
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import fr.acinq.bitcoin.Crypto
+import mobi.giza.compose.extensions.toHex
+
+/**
+ * Which conversation a message in a group's inbox belongs to (docs/group-inbox.md, D8).
+ *
+ * NIP-17 defines a chat as the set of its author and its `p` tags. The group is in every one of
+ * its own, so it is left out: a message from Alice to the group and the group's reply to Alice
+ * are both the conversation `{Alice}`, whichever way round they were written.
+ */
+object InboxConversation {
+ /** The people in [rumor]'s conversation other than [group], sorted and without repeats. */
+ fun participantsOf(rumor: Event, group: HexKey): List =
+ (listOf(rumor.pubKey) + rumor.tags.filter { it.size >= 2 && it[0] == "p" }.map { it[1] })
+ .map { it.lowercase() }
+ .filter { it != group.lowercase() && InboxWire.isHex32(it) }
+ .distinct()
+ .sorted()
+
+ /** A stable id for a set of [participants]: the same set gives the same id on every device. */
+ fun idOf(participants: List): String =
+ Crypto.sha256(participants.map { it.lowercase() }.distinct().sorted().joinToString(",").encodeToByteArray()).toHex()
+
+ fun idOf(rumor: Event, group: HexKey): String = idOf(participantsOf(rumor, group))
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxKeyRitualEvents.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxKeyRitualEvents.kt
new file mode 100644
index 00000000..dcbdd777
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxKeyRitualEvents.kt
@@ -0,0 +1,86 @@
+package mobi.giza.compose.nostr.inbox
+
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.Kind
+
+/**
+ * The group's inbox key ceremony on the wire (docs/group-inbox.md, D2 and D3): a ChillDKG
+ * ceremony at threshold 1 over the room's admins, carried as MLS inner events in the group's
+ * own Marmot room.
+ *
+ * The same seven steps as the group's signing ceremony ([mobi.giza.compose.nostr.dkg.DkgRitualEvents]),
+ * on kinds of their own. A `t = 1` key must never be filed where a signing key could be found,
+ * and a device that knows only the signing ceremony's kinds -- an older build, or a Bennu
+ * admin's -- would take a 30310 over a subset of the room for a subgroup's ceremony. On kinds it
+ * does not know it takes it for nothing.
+ *
+ * Rumor kinds: they only ever travel inside the group's encryption, so the replaceable range
+ * means nothing for them. 30410-30416 are in no NIP, quartz, Curare or Bennu (Phase 0).
+ *
+ * ```
+ * coordinator --[ 30410 proposal ]-> the room "let's make the inbox key", p-tagging the admins
+ * admin --[ 30411 host key ]-> the room host pubkey
+ * admin --[ 30412 round 1 ]-> the room pmsg1: a contribution, encrypted to the admins' host keys
+ * coordinator --[ 30413 coord round 1 ]-> the room cmsg1
+ * admin --[ 30414 round 2 ]-> the room CertEq signature
+ * coordinator --[ 30415 certificate ]-> the room cmsg2
+ * anyone --[ 30416 failure ]-> the room abort, with a reason
+ * ```
+ *
+ * Every member of the room receives all of it. ChillDKG encrypts each contribution to its
+ * recipients' host keys, so a member who is not an admin learns the inbox's public key and
+ * nothing else.
+ */
+object InboxKeyRitualEvents {
+ const val PROPOSAL: Kind = 30410
+ const val HOST_KEY: Kind = 30411
+ const val ROUND_1: Kind = 30412
+ const val COORDINATOR_ROUND_1: Kind = 30413
+ const val ROUND_2: Kind = 30414
+ const val CERTIFICATE: Kind = 30415
+ const val FAILURE: Kind = 30416
+
+ val ALL: Set = setOf(PROPOSAL, HOST_KEY, ROUND_1, COORDINATOR_ROUND_1, ROUND_2, CERTIFICATE, FAILURE)
+
+ fun isInboxKeyKind(kind: Kind): Boolean = kind in ALL
+
+ /** Binds a message to one ceremony, so a late one from an abandoned attempt is dropped. */
+ const val SESSION_TAG = "inbox_key_session"
+
+ /** Which generation of the room's inbox key the ceremony makes. On the proposal only. */
+ const val GENERATION_TAG = "inbox_key_generation"
+
+ /** The ceremony's threshold. Always 1; carried so a device can refuse anything else. */
+ const val THRESHOLD_TAG = "inbox_key_threshold"
+
+ const val THRESHOLD = 1
+
+ fun assembleTags(
+ sessionId: String,
+ generation: Int? = null,
+ participants: List = emptyList(),
+ ): Array> = buildList {
+ add(arrayOf(SESSION_TAG, sessionId))
+ generation?.let {
+ add(arrayOf(GENERATION_TAG, it.toString()))
+ add(arrayOf(THRESHOLD_TAG, THRESHOLD.toString()))
+ }
+ participants.forEach { add(arrayOf("p", it)) }
+ }.toTypedArray()
+
+ fun parseSessionId(tags: Array>): String? =
+ tags.firstOrNull { it.size >= 2 && it[0] == SESSION_TAG }?.get(1)?.takeIf(InboxWire::isHex32)
+
+ fun parseGeneration(tags: Array>): Int? =
+ tags.firstOrNull { it.size >= 2 && it[0] == GENERATION_TAG }?.get(1)?.toIntOrNull()?.takeIf { it >= 0 }
+
+ fun parseThreshold(tags: Array>): Int? =
+ tags.firstOrNull { it.size >= 2 && it[0] == THRESHOLD_TAG }?.get(1)?.toIntOrNull()
+
+ /** The admins a proposal names, sorted and without repeats; null if any is malformed. */
+ fun parseParticipants(tags: Array>): List? {
+ val named = tags.filter { it.isNotEmpty() && it[0] == "p" }.map { it.getOrNull(1) }
+ if (named.any { !InboxWire.isHex32(it) }) return null
+ return named.filterNotNull().distinct().sorted()
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxReplyManifest.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxReplyManifest.kt
new file mode 100644
index 00000000..b02ec95c
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxReplyManifest.kt
@@ -0,0 +1,98 @@
+package mobi.giza.compose.nostr.inbox
+
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import kotlinx.serialization.json.Json
+import kotlinx.serialization.json.JsonArray
+import kotlinx.serialization.json.JsonNull
+import kotlinx.serialization.json.JsonObject
+import kotlinx.serialization.json.JsonPrimitive
+import kotlinx.serialization.json.buildJsonArray
+import kotlinx.serialization.json.buildJsonObject
+import kotlinx.serialization.json.put
+
+/**
+ * What a signer of a reply needs beside the seals themselves (docs/group-inbox.md, D11): which
+ * seal is for whom, the key each was sealed to, and the evidence for that key.
+ *
+ * It rides the FROST proposal as an `inbox_manifest` tag, encrypted to the inbox key, so a
+ * member of the room who is not an admin sees how many seals the group is signing and nothing
+ * else: not the reply, and not who it goes to.
+ *
+ * The encoding is this app's own and is decoded strictly: a manifest with a field it does not
+ * know, or one missing, is no manifest, and a reply carrying one is declined.
+ */
+data class InboxReplyManifest(
+ /** The inbox key generation every seal is sealed from. */
+ val generation: Int,
+ val seals: List,
+ /** Which of [seals] is the group's own copy, sealed to the inbox key itself. */
+ val groupCopy: Int,
+) {
+ data class Entry(
+ val recipient: HexKey,
+ /** The key the seal is encrypted to. */
+ val key: HexKey,
+ /** The recipient's signed 10044, as JSON, when [key] came from one; null when [key] is their identity. */
+ val announcement: String?,
+ )
+
+ fun encode(): String = buildJsonObject {
+ put("v", 1)
+ put("generation", generation)
+ put("seals", buildJsonArray {
+ seals.forEach { entry ->
+ add(buildJsonObject {
+ put("recipient", entry.recipient)
+ put("key", entry.key)
+ put("announcement", entry.announcement?.let(::JsonPrimitive) ?: JsonNull)
+ })
+ }
+ })
+ put("group_copy", groupCopy)
+ }.toString()
+
+ /** Encrypted under `conv(e, E)`: only a holder of this generation's key reads it. */
+ fun seal(inboxSecret: ByteArray): String =
+ InboxWire.encrypt(encode(), selfConversationKey(inboxSecret))
+
+ companion object {
+ const val TAG_NAME = "inbox_manifest"
+
+ private val json = Json { ignoreUnknownKeys = false }
+ private val TOP = setOf("v", "generation", "seals", "group_copy")
+ private val ENTRY = setOf("recipient", "key", "announcement")
+
+ fun tag(sealed: String): Array = arrayOf(TAG_NAME, sealed)
+
+ /** The sealed manifest among a proposal's tags, or null. More than one is none. */
+ fun sealedIn(tags: Array>): String? =
+ tags.filter { it.isNotEmpty() && it[0] == TAG_NAME }.singleOrNull()?.getOrNull(1)?.ifBlank { null }
+
+ fun selfConversationKey(inboxSecret: ByteArray): ByteArray =
+ InboxWire.conversationKey(inboxSecret, InboxWire.publicKeyOf(inboxSecret))
+
+ /** [sealed] opened with [inboxSecret], or null if that key does not open it or it is not a manifest. */
+ fun open(sealed: String, inboxSecret: ByteArray): InboxReplyManifest? =
+ InboxWire.decrypt(sealed, selfConversationKey(inboxSecret))?.let(::decode)
+
+ fun decode(text: String): InboxReplyManifest? = runCatching {
+ val obj = json.parseToJsonElement(text) as JsonObject
+ require(obj.keys == TOP)
+ require((obj["v"] as JsonPrimitive).content == "1")
+ val generation = (obj["generation"] as JsonPrimitive).content.toInt().also { require(it >= 0) }
+ val seals = (obj["seals"] as JsonArray).map { element ->
+ val entry = element as JsonObject
+ require(entry.keys == ENTRY)
+ val announcement = entry["announcement"]
+ Entry(
+ recipient = (entry["recipient"] as JsonPrimitive).content.also { require(InboxWire.isHex32(it)) },
+ key = (entry["key"] as JsonPrimitive).content.also { require(InboxWire.isHex32(it)) },
+ announcement = if (announcement is JsonNull) null else (announcement as JsonPrimitive).also { require(it.isString) }.content,
+ )
+ }
+ val groupCopy = (obj["group_copy"] as JsonPrimitive).content.toInt()
+ require(groupCopy in seals.indices)
+ InboxReplyManifest(generation, seals, groupCopy)
+ }.getOrNull()
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxSeal.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxSeal.kt
new file mode 100644
index 00000000..c4738c50
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxSeal.kt
@@ -0,0 +1,105 @@
+package mobi.giza.compose.nostr.inbox
+
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
+import com.vitorpamplona.quartz.nip01Core.crypto.verify
+import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
+import com.vitorpamplona.quartz.nip59Giftwrap.rumors.Rumor
+import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealEvent
+
+/**
+ * A NIP-17 seal with a decoupled encryption key, as nostr-protocol/nips#2361 has it
+ * (docs/group-inbox.md):
+ *
+ * ```
+ * seal (13) pubkey = the sender's identity signed by the identity
+ * tags = [["n", the sender's encryption key]] when it is not the identity
+ * content = nip44(rumor, conv(sender's encryption secret, receiver's encryption key))
+ * ```
+ *
+ * The split is what lets a group answer at all: the admins hold the encryption secret and can
+ * write the content; only the quorum can sign the seal. A group's seal is therefore built here
+ * as an unsigned template, and signed by the FROST session.
+ */
+object InboxSeal {
+ const val KIND = SealEvent.KIND
+ const val ENCRYPTION_KEY_TAG = "n"
+
+ /**
+ * The unsigned seal of [rumor] from the inbox key [inboxSecret] to [recipientEncryptionKey]:
+ * the recipient's announced 10044 key, their identity if they announce none, or the inbox
+ * key itself for the group's own copy.
+ */
+ fun template(
+ rumor: Event,
+ inboxSecret: ByteArray,
+ recipientEncryptionKey: HexKey,
+ createdAt: Long,
+ ): EventTemplate = EventTemplate(
+ createdAt = createdAt,
+ kind = KIND,
+ tags = arrayOf(arrayOf(ENCRYPTION_KEY_TAG, InboxWire.publicKeyOf(inboxSecret))),
+ content = InboxWire.encrypt(rumorJson(rumor), InboxWire.conversationKey(inboxSecret, recipientEncryptionKey)),
+ )
+
+ /** The rumor as NIP-59 puts it inside a seal: its id, no signature. */
+ fun rumorJson(rumor: Event): String = Rumor.toJson(Rumor.create(rumor))
+
+ /** The `n` a seal names, or null when it names none or a malformed one. */
+ fun encryptionKeyOf(tags: Array>): HexKey? {
+ val named = tags.filter { it.isNotEmpty() && it[0] == ENCRYPTION_KEY_TAG }
+ if (named.size != 1) return null
+ return named.single().getOrNull(1)?.lowercase()?.takeIf(InboxWire::isHex32)
+ }
+
+ /**
+ * Which key the sender encrypted with, by #2361's rule and quartz's: the seal's `n` if it
+ * has one, else the key the sender's own 10044 announces if this device has seen it, else
+ * the sender's identity.
+ */
+ fun senderEncryptionKey(seal: Event, senderAnnouncedKey: HexKey?): HexKey =
+ encryptionKeyOf(seal.tags) ?: senderAnnouncedKey ?: seal.pubKey
+
+ data class Opened(val seal: Event, val rumor: Event, val senderEncryptionKey: HexKey)
+
+ /**
+ * [seal], received, opened with [receiverSecret]. Null for every way that can fail: not a
+ * seal, a signature that does not verify, a key that does not open it, a rumor that is not
+ * one, or a rumor claiming an author the seal does not have -- NIP-17's impersonation check,
+ * the one thing that makes the seal's signature mean the rumor's author.
+ *
+ * If the seal names no `n`, [senderAnnouncedKey] is tried before the identity, and then the
+ * identity, since a sender's app may decouple without writing the tag.
+ */
+ fun open(seal: Event, receiverSecret: ByteArray, senderAnnouncedKey: HexKey? = null): Opened? {
+ if (seal.kind != KIND || !seal.verify()) return null
+ val candidates = buildList {
+ encryptionKeyOf(seal.tags)?.let(::add)
+ senderAnnouncedKey?.let(::add)
+ add(seal.pubKey)
+ }.distinct()
+ for (key in candidates) {
+ val rumor = rumorInside(seal.content, InboxWire.conversationKey(receiverSecret, key), seal.pubKey) ?: continue
+ return Opened(seal, rumor, key)
+ }
+ return null
+ }
+
+ /**
+ * The rumor inside a seal's [content] under [conversationKey], with its id computed rather
+ * than trusted, or null. [author] is the seal's pubkey: a rumor claiming anyone else is
+ * refused here, so no caller can forget to.
+ */
+ fun rumorInside(content: String, conversationKey: ByteArray, author: HexKey): Event? {
+ val json = InboxWire.decrypt(content, conversationKey) ?: return null
+ val rumor = runCatching { Rumor.fromJson(json) }.getOrNull() ?: return null
+ if (rumor.pubKey != author) return null
+ val kind = rumor.kind ?: return null
+ val createdAt = rumor.createdAt ?: return null
+ val tags = rumor.tags ?: emptyArray()
+ val content = rumor.content ?: ""
+ val id = EventHasher.hashId(author, createdAt, kind, tags, content)
+ return Event(id, author, createdAt, kind, tags, content, "")
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxWire.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxWire.kt
new file mode 100644
index 00000000..5c82137d
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxWire.kt
@@ -0,0 +1,41 @@
+package mobi.giza.compose.nostr.inbox
+
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
+import com.vitorpamplona.quartz.nip44Encryption.Nip44v2
+import fr.acinq.bitcoin.PrivateKey
+import mobi.giza.compose.extensions.toHex
+
+/**
+ * The arithmetic every piece of the group's inbox shares (docs/group-inbox.md).
+ *
+ * NIP-4E's keys are x-only, as every nostr key is. The inbox key's secret `e` comes out of a
+ * ChillDKG ceremony whose public key may have either parity; NIP-44 uses only the x of the
+ * shared point, which is the same for `e` and `-e`, so `e` is used as it is and nobody negates
+ * anything. `InboxKeyPremiseTest` checks that from both sides.
+ */
+object InboxWire {
+ /** One instance: [Nip44v2.computeConversationKey] is pure, and nothing here uses its cache. */
+ val nip44 = Nip44v2()
+
+ fun isHex32(hex: String?): Boolean =
+ hex != null && hex.length == 64 && hex.all { it in '0'..'9' || it in 'a'..'f' }
+
+ /** `E`, x-only, lowercase hex, as it goes in a 10044's `n` and a seal's `n`. */
+ fun publicKeyOf(secret: ByteArray): HexKey = PrivateKey(secret).publicKey().xOnly().value.toHex()
+
+ /**
+ * The NIP-44 conversation key between [secret] and [publicKey], uncached: an inbox key is
+ * held by several admins and retired on rotation, and a process-wide cache of conversation
+ * keys would keep a retired one alive in memory for no gain.
+ */
+ fun conversationKey(secret: ByteArray, publicKey: HexKey): ByteArray =
+ nip44.computeConversationKey(secret, publicKey.hexToByteArray())
+
+ fun encrypt(plaintext: String, conversationKey: ByteArray): String =
+ nip44.encrypt(plaintext, conversationKey).encodePayload()
+
+ /** [payload] opened under [conversationKey], or null for any way that can fail. */
+ fun decrypt(payload: String, conversationKey: ByteArray): String? =
+ runCatching { nip44.decrypt(payload, conversationKey) }.getOrNull()
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxWrap.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxWrap.kt
new file mode 100644
index 00000000..48201982
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/inbox/InboxWrap.kt
@@ -0,0 +1,70 @@
+package mobi.giza.compose.nostr.inbox
+
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
+import com.vitorpamplona.quartz.nip01Core.crypto.verify
+import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
+import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
+import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
+import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
+import com.vitorpamplona.quartz.utils.TimeUtils
+
+/**
+ * A NIP-59 gift wrap with a decoupled encryption key, as nostr-protocol/nips#2361 has it:
+ *
+ * ```
+ * gift wrap (1059) pubkey = a fresh random key
+ * tags = [["p", the recipient's identity, relay]]
+ * content = nip44(seal, conv(wrapper secret, the recipient's encryption key))
+ * ```
+ *
+ * quartz's [GiftWrapEvent.create] encrypts to the key it tags, which is right when they are the
+ * same and wrong here, so the wrap is built by hand. The `p` stays the identity: it is how a
+ * recipient's relays and apps find their mail, and it names nothing about which key opens it.
+ * That is also why a reader with several keys has to try them ([open]).
+ */
+object InboxWrap {
+ const val KIND = GiftWrapEvent.KIND
+
+ /**
+ * [seal], already signed, wrapped for [recipientIdentity] under [recipientEncryptionKey] with a
+ * throwaway key nobody keeps.
+ */
+ fun wrap(
+ seal: Event,
+ recipientIdentity: HexKey,
+ recipientEncryptionKey: HexKey,
+ relayHint: NormalizedRelayUrl? = null,
+ createdAt: Long = TimeUtils.randomWithTwoDays(),
+ ): Event {
+ val signer = NostrSignerSync(KeyPair())
+ val throwaway = requireNotNull(signer.keyPair.privKey)
+ val content = InboxWire.encrypt(seal.toJson(), InboxWire.conversationKey(throwaway, recipientEncryptionKey))
+ return signer.sign(
+ createdAt = createdAt,
+ kind = KIND,
+ tags = arrayOf(PTag.assemble(recipientIdentity, relayHint)),
+ content = content,
+ )
+ }
+
+ /** Who a wrap is addressed to: its first `p`, which is a routing hint and proves nothing. */
+ fun recipientOf(wrap: Event): HexKey? =
+ wrap.tags.firstOrNull { it.size >= 2 && it[0] == "p" }?.get(1)
+
+ /**
+ * The seal inside [wrap], and the index into [secrets] of the key that opened it, or null if
+ * none does. Newest key first is the caller's order to give: a wrap is far likelier to be to
+ * the key the group announces now than to one it retired.
+ */
+ fun open(wrap: Event, secrets: List): Pair? {
+ if (wrap.kind != KIND || !wrap.verify()) return null
+ secrets.forEachIndexed { index, secret ->
+ val json = InboxWire.decrypt(wrap.content, InboxWire.conversationKey(secret, wrap.pubKey)) ?: return@forEachIndexed
+ val seal = Event.fromJsonOrNull(json) ?: return@forEachIndexed
+ if (seal.kind == InboxSeal.KIND) return index to seal
+ }
+ return null
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt
index 3a1794e6..f12e10df 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt
@@ -135,12 +135,29 @@ interface ChatRepository {
/** How many confederation proposals naming [chatRoomId] this device holds. docs/confederation.md. */
suspend fun confederationProposalCount(chatRoomId: String): Int = 0
+ /**
+ * The group's inbox as its row on the group's screen shows it, or null where this device
+ * has nothing of it to show (docs/group-inbox.md, D9).
+ */
+ suspend fun inboxSummary(localChatRoom: LocalChatRoom): mobi.giza.compose.ui.view.state.InboxRowSummary? = null
+
/** The confederation whose room [chatRoomId] is, by name, if its record verifies here. docs/confederation.md, Phase 13. */
suspend fun confederationOfRoom(chatRoomId: String): String? = null
/** What [chatRoomId]'s screen says about its direct messages, to [userPublicKey]. docs/group-threshold-ecdh.md. */
suspend fun groupDmRow(chatRoomId: String, userPublicKey: HexKey): mobi.giza.compose.ui.view.state.GroupDmRow? = null
+ /** Whether this device holds a role in the confederation whose room [chatRoomId] is. docs/confederation.md, Phase 15. */
+ suspend fun canSignAsConfederation(chatRoomId: String): Boolean = false
+
+ /** Proposes that the confederation whose room [localChatRoom] is sign one event. The attempt's id. */
+ suspend fun proposeAsConfederation(localChatRoom: LocalChatRoom, kind: Kind, tags: Array>, content: String): String =
+ throw UnsupportedOperationException("No confederation here")
+
+ /** Proposes that the confederation sign its charter: its groups, under its name. The attempt's id. */
+ suspend fun proposeCharter(localChatRoom: LocalChatRoom): String =
+ throw UnsupportedOperationException("No confederation here")
+
/**
* Why these members cannot hold a subgroup ceremony together, or null when
* they can.
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ConfederationRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ConfederationRepository.kt
index 9e25b3a9..b7abbc20 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ConfederationRepository.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ConfederationRepository.kt
@@ -9,6 +9,8 @@ import mobi.giza.compose.database.model.Confederation
import mobi.giza.compose.database.model.ConfederationCeremony
import mobi.giza.compose.database.model.ConfederationCeremonyMessage
import mobi.giza.compose.database.model.ConfederationEvent
+import mobi.giza.compose.database.model.ConfederationSigningAttempt
+import mobi.giza.compose.database.model.ConfederationSigningMessage
import mobi.giza.compose.nostr.confederation.ConfederationRosterBuilder
import mobi.giza.compose.database.model.FrostSigningSession
import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
@@ -86,6 +88,18 @@ interface ConfederationRepository {
suspend fun abandonCeremony(sessionId: String)
+ /** One attempt by a confederation to sign an event, as it changes. docs/confederation.md, Phase 14. */
+ fun observeSigningAttempt(attemptId: String): Flow
+
+ fun observeSigningMessages(attemptId: String): Flow>
+
+ /** The roster's plan for the confederation whose room [confederationId] is, if this device holds it. */
+ suspend fun confederationPlan(confederationId: HexKey): ConfederationRosterBuilder.Plan?
+
+ suspend fun approveSigning(attemptId: String)
+
+ suspend fun declineSigning(attemptId: String)
+
/** The confederations [groupPublicKey] is part of, on this device. docs/confederation.md, Phase 12. */
fun observeConfederationsOf(groupPublicKey: HexKey): Flow>
@@ -126,6 +140,11 @@ interface ConfederationRepository {
override suspend fun joinCeremony(sessionId: String) = Unit
override suspend fun abandonCeremony(sessionId: String) = Unit
override fun observeConfederationsOf(groupPublicKey: HexKey): Flow> = flowOf(emptyList())
+ override fun observeSigningAttempt(attemptId: String): Flow = flowOf(null)
+ override fun observeSigningMessages(attemptId: String): Flow> = flowOf(emptyList())
+ override suspend fun confederationPlan(confederationId: HexKey): ConfederationRosterBuilder.Plan? = null
+ override suspend fun approveSigning(attemptId: String) = Unit
+ override suspend fun declineSigning(attemptId: String) = Unit
}
}
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/FrostSigningRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/FrostSigningRepository.kt
index 8f7e9022..1df371cc 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/FrostSigningRepository.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/FrostSigningRepository.kt
@@ -82,7 +82,12 @@ interface FrostSigningRepository {
suspend fun canSign(chatRoomId: String): Boolean
/** What to read before approving a confederation event in [sessionId] (docs/confederation.md, D6). */
- suspend fun confederationNotes(chatRoomId: String, sessionId: String, events: List): List = emptyList()
+ /**
+ * What the signing screen says beside a proposal: for a confederation event, what it names
+ * and discloses (docs/confederation.md, D6); for a reply from the group's inbox, its words,
+ * who it goes to and what could not be checked (docs/group-inbox.md, D12).
+ */
+ suspend fun proposalNotes(chatRoomId: String, sessionId: String, events: List): List = emptyList()
/**
* Opens a session asking the group to sign an event with these fields. The
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/GroupInboxRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/GroupInboxRepository.kt
new file mode 100644
index 00000000..58973034
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/GroupInboxRepository.kt
@@ -0,0 +1,109 @@
+package mobi.giza.compose.repository
+
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.emptyFlow
+import kotlinx.coroutines.flow.flowOf
+import kotlin.time.Instant
+import mobi.giza.compose.database.model.GroupInboxMessage
+import mobi.giza.compose.database.model.GroupInboxPublication
+import mobi.giza.compose.database.model.InboxKey
+import mobi.giza.compose.database.model.InboxKeyCeremony
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+
+/** The group's inbox, as the screens and the sync see it (docs/group-inbox.md). */
+interface GroupInboxRepository {
+ /** What this device owes relays on its groups' behalf and has not yet got onto one. */
+ fun observeUnpublished(): Flow>
+
+ suspend fun markPublished(eventId: HexKey, at: Instant)
+
+ /**
+ * A group whose mail this identity can open: its npub, the inbox keys this device holds for
+ * it, and where its mail is announced to arrive.
+ */
+ data class Route(val chatRoomId: String, val keys: List, val relays: List)
+
+ /** Every group [userPublicKey] holds an inbox key for, re-emitted when that changes (D8). */
+ fun observeRoutes(userPublicKey: HexKey): Flow>
+
+ /** Files a gift wrap heard on a relay for one of [userPublicKey]'s groups. */
+ suspend fun receive(wrap: Event, userPublicKey: HexKey): GroupInboxMessage?
+
+ // ---- the screens (Phase 7) ----------------------------------------------------------------
+
+ /** One conversation in a group's inbox, as its list shows it. */
+ data class ConversationSummary(
+ val conversationId: String,
+ val participants: List,
+ val names: List,
+ val lastText: String,
+ val lastAt: Long,
+ val lastOutgoing: Boolean,
+ val unread: Int,
+ )
+
+ /** What a group's inbox is on this device: its keys, its newest ceremony, what it announced. */
+ data class Status(
+ val keys: List,
+ val ceremony: InboxKeyCeremony?,
+ /** The key the group's newest signed 10044 names, or null if it has announced none. */
+ val announcedKey: HexKey?,
+ val relays: List,
+ /** Why this identity cannot start a ceremony now, or null if it can. */
+ val setUpRefusal: String?,
+ /** The admins a running ceremony waits on, by name. */
+ val waitingOn: List,
+ /** The key was made over admins the room no longer has (D14). */
+ val rotationOwed: Boolean = false,
+ ) {
+ val heldKey: InboxKey? get() = keys.firstOrNull { it.secretKey != null }
+ }
+
+ fun observeConversations(chatRoomId: String): Flow> = emptyFlow()
+
+ fun observeConversation(chatRoomId: String, conversationId: String): Flow> = flowOf(emptyList())
+
+ fun observeUnopenedCount(chatRoomId: String): Flow = flowOf(0)
+
+ fun observeStatus(localChatRoom: LocalChatRoom, userPublicKey: HexKey): Flow = emptyFlow()
+
+ suspend fun markRead(chatRoomId: String, conversationId: String) = Unit
+
+ suspend fun namesOf(publicKeys: List): Map = emptyMap()
+
+ /** Starts the first inbox key ceremony, with mail to arrive on [relays]. */
+ suspend fun setUp(localChatRoom: LocalChatRoom, relays: List): InboxKeyCeremony =
+ throw UnsupportedOperationException()
+
+ /** Starts a ceremony for the next generation of the key (D14). */
+ suspend fun rotate(localChatRoom: LocalChatRoom): InboxKeyCeremony = throw UnsupportedOperationException()
+
+ suspend fun abandon(localChatRoom: LocalChatRoom, ceremonyId: String): Boolean = false
+
+ // ---- replying (Phase 8) -------------------------------------------------------------------
+
+ /** Asks the group to sign a reply to [conversationId]; the signing session's id. */
+ suspend fun proposeReply(localChatRoom: LocalChatRoom, conversationId: String, text: String): String =
+ throw UnsupportedOperationException()
+
+ /** Of [publicKeys], those who have announced no inbox key (D13's warning). */
+ suspend fun withoutAnnouncedKey(publicKeys: List): List = emptyList()
+
+ /** The reply sessions in [chatRoomId] whose wraps no relay has taken yet. */
+ suspend fun unsentReplies(chatRoomId: String): Set = emptySet()
+
+ /** Wraps a signed reply again and owes it to relays. */
+ suspend fun sendAgain(sessionId: String): Boolean = false
+
+ companion object {
+ val NO_OP = object : GroupInboxRepository {
+ override fun observeUnpublished(): Flow> = flowOf(emptyList())
+ override suspend fun markPublished(eventId: HexKey, at: Instant) = Unit
+ override fun observeRoutes(userPublicKey: HexKey): Flow> = flowOf(emptyList())
+ override suspend fun receive(wrap: Event, userPublicKey: HexKey): GroupInboxMessage? = null
+ }
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/text/ProposedEvent.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/text/ProposedEvent.kt
index bff1b69a..1eabdb19 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/text/ProposedEvent.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/text/ProposedEvent.kt
@@ -4,13 +4,15 @@ import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
+import mobi.giza.compose.nostr.confederation.ConfederationCharterEvent
import mobi.giza.compose.nostr.confederation.ConfederationKinds
import mobi.giza.compose.nostr.confederation.ConfederationProposalEvent
import mobi.giza.compose.managers.SharedKeyDerivation
import mobi.giza.compose.managers.WalletRefusal
-import mobi.giza.compose.managers.GroupDmRelays
import mobi.giza.compose.nostr.RetiredKinds
import mobi.giza.compose.nostr.frost.GovernanceStatementEvent
+import mobi.giza.compose.nostr.inbox.InboxAnnouncement
+import mobi.giza.compose.nostr.inbox.InboxSeal
import mobi.giza.compose.nostr.frost.GroupKeyStateEvent
import mobi.giza.compose.nostr.subgroup.SubgroupBirthCertificateEvent
@@ -93,6 +95,33 @@ object ProposedEvent {
)
} ?: Summary(label = "A change to this group that cannot be read", detail = "")
+ // The group's inbox (docs/group-inbox.md, D5 and D6): the key anyone writing to
+ // the group will encrypt to, shown by its fingerprint, and the relays its mail is
+ // to arrive on. Deciding to sign the first is deciding the group has an inbox.
+ InboxAnnouncement.KEY_KIND -> Summary(
+ label = "The group's inbox key",
+ detail = InboxAnnouncement.announcedKeyOf(event)?.let { "Key ${it.take(8)}…${it.takeLast(8)}" }
+ ?: "Names no key",
+ )
+ // A reply from the group's inbox: sealed, so said for what it is. The signing screen
+ // reads it out for a device that holds the inbox key (docs/group-inbox.md, D12), and a
+ // member without one sees only that it exists (D11).
+ // A seal with no `n` tag is the group writing by threshold ECDH instead
+ // (docs/group-threshold-ecdh.md, D12): ciphertext to its recipient's own key.
+ InboxSeal.KIND -> if (InboxSeal.encryptionKeyOf(event.tags) != null) {
+ Summary(
+ label = "A private reply from the group's inbox",
+ detail = "Sealed: only the group's inbox key opens it",
+ )
+ } else {
+ Summary(label = "A private message from the group", detail = "Sealed to its recipient")
+ }
+ InboxAnnouncement.RELAYS_KIND -> Summary(
+ label = "Where the group receives private messages",
+ detail = InboxAnnouncement.announcedRelaysOf(event).joinToString(", ") { it.url.removePrefix("wss://").trimEnd('/') }
+ .ifEmpty { "No relays" },
+ )
+
// The group's own profile. Named by what the group would be called and
// what it would say about itself, which is the whole of what is being
// decided; the JSON in the content is the one thing a signer should not
@@ -125,6 +154,10 @@ object ProposedEvent {
)
} ?: Summary(label = "A confederation that cannot be read", detail = "")
+ ConfederationKinds.CHARTER -> ConfederationCharterEvent.parse(event)?.let { charter ->
+ Summary(label = "The confederation's charter", detail = "${charter.name}, naming its ${charter.groups.size} groups")
+ } ?: Summary(label = "A charter that cannot be read", detail = "")
+
ConfederationKinds.ACCEPTANCE -> Summary(
label = "Accepting a confederation",
detail = "Discloses this group's admins and threshold to the coordinator",
@@ -134,22 +167,6 @@ object ProposedEvent {
ConfederationKinds.WITHDRAWAL -> Summary(label = "Withdrawing a confederation proposal", detail = event.content)
- // A message from the group, sealed to one recipient: ciphertext. What it says is
- // on the signing screen of an admin's device, read from the manifest; to anyone
- // else this is all there is to say. docs/group-threshold-ecdh.md, D12.
- com.vitorpamplona.quartz.nip59Giftwrap.seals.SealEvent.KIND -> Summary(
- label = "A private message from the group",
- detail = "Sealed to its recipient",
- )
-
- // Where the group receives direct messages: the group's decision to be written
- // to at all, said as that, with the relays it names. docs/group-threshold-ecdh.md, D8.
- GroupDmRelays.KIND -> Summary(
- label = "Where the group receives messages",
- detail = GroupDmRelays.relaysIn(event.tags)?.joinToString(" · ")
- ?: "A relay that is not a public wss:// address",
- )
-
// A Bennu wallet's: declined on arrival, and said as what it is rather than
// as a number. docs/giza-wallet-removal.md.
in RetiredKinds.WALLET, in RetiredKinds.GROUP_LIGHTNING -> WALLET
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddGroupPostScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddGroupPostScreen.kt
index d6877905..ec70d970 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddGroupPostScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddGroupPostScreen.kt
@@ -41,6 +41,7 @@ import mobi.giza.compose.database.model.ChatRoom
import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
import mobi.giza.compose.repository.ChatRepository
import mobi.giza.compose.repository.FrostSigningRepository
+import mobi.giza.compose.ui.composable.navigation.routes.ConfederationSigningRoute
import mobi.giza.compose.ui.composable.navigation.routes.FrostSigningRoute
import mobi.giza.compose.ui.composable.navigation.routes.Route
import mobi.giza.compose.ui.composable.widgets.ErrorState
@@ -158,11 +159,18 @@ fun AddGroupPostScreen(
// on the list it is not in would
// read as a failure.
onNavigateToRouteAndPopUpInclusive.invoke(
- FrostSigningRoute(
- activeUserPublicKey = activeUserPublicKey,
- chatRoomId = chatRoomId,
- sessionId = sessionId
- )
+ if (addGroupPostViewModel.isConfederation) {
+ ConfederationSigningRoute(
+ activeUserPublicKey = activeUserPublicKey,
+ attemptId = sessionId
+ )
+ } else {
+ FrostSigningRoute(
+ activeUserPublicKey = activeUserPublicKey,
+ chatRoomId = chatRoomId,
+ sessionId = sessionId
+ )
+ }
)
},
// Both stay on the draft. One is an
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt
index 76180344..f43e8788 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt
@@ -9,6 +9,17 @@ import mobi.giza.compose.resources.one_post
import mobi.giza.compose.resources.no_posts_yet
import mobi.giza.compose.resources.posts
import mobi.giza.compose.ui.composable.navigation.routes.GroupPostsRoute
+import mobi.giza.compose.resources.inbox
+import mobi.giza.compose.resources.set_up_an_inbox
+import mobi.giza.compose.resources.no_new_messages
+import mobi.giza.compose.resources.one_new_message
+import mobi.giza.compose.resources.n_new_messages
+import mobi.giza.compose.resources.the_admins_are_making_the_inbox_key
+import mobi.giza.compose.resources.let_anyone_on_nostr_write_to_the_group_privately
+import mobi.giza.compose.ui.composable.navigation.routes.GroupInboxRoute
+import mobi.giza.compose.ui.composable.navigation.routes.GroupInboxSettingsRoute
+import mobi.giza.compose.ui.view.state.InboxRowSummary
+import androidx.compose.material.icons.filled.Mail
import mobi.giza.compose.ui.composable.navigation.routes.ConfederationsRoute
import mobi.giza.compose.ui.composable.navigation.routes.GroupDmSetupRoute
import mobi.giza.compose.ui.view.state.GroupDmRow
@@ -27,6 +38,9 @@ import mobi.giza.compose.resources.no_confederations_yet
import mobi.giza.compose.resources.one_confederation_proposal
import mobi.giza.compose.resources.n_confederation_proposals
import mobi.giza.compose.resources.this_is_the_confederations_room
+import mobi.giza.compose.resources.propose_the_charter
+import mobi.giza.compose.resources.the_charter_names_the_groups
+import mobi.giza.compose.ui.composable.navigation.routes.ConfederationSigningRoute
import androidx.compose.material.icons.filled.Campaign
import mobi.giza.compose.resources.not_described_yet
import mobi.giza.compose.resources.no_name_on_this_profile
@@ -723,6 +737,26 @@ fun ChatRoomDetailScreen(
)
}
+ // The group's inbox (docs/group-inbox.md, D9): on a device that
+ // holds its key, or whose identity could set one up. A member
+ // who is not an admin sees no row at all.
+ chatRoomDetailUIState.inbox?.let { inbox ->
+ item {
+ GroupInboxRow(
+ inbox = inbox,
+ onClick = {
+ onNavigateToRoute.invoke(
+ if (inbox.holdsKey) {
+ GroupInboxRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = chatRoomId, relayHint = relayHint)
+ } else {
+ GroupInboxSettingsRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = chatRoomId, relayHint = relayHint)
+ }
+ )
+ }
+ )
+ }
+ }
+
// The confederations naming this group, and the way into
// proposing one (docs/confederation.md). Every member can
// read them; the screen behind it gates proposing.
@@ -731,11 +765,35 @@ fun ChatRoomDetailScreen(
chatRoomDetailUIState.confederationName?.let { name ->
item {
Card(modifier = Modifier.fillMaxWidth()) {
- Text(
+ Column(
modifier = Modifier.padding(MaterialTheme.spacing.containerPadding),
- text = stringResource(Res.string.this_is_the_confederations_room, name),
- style = MaterialTheme.typography.bodyMedium,
- )
+ verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap),
+ ) {
+ Text(
+ text = stringResource(Res.string.this_is_the_confederations_room, name),
+ style = MaterialTheme.typography.bodyMedium,
+ )
+ // Its charter, which it signs itself (Phase 15).
+ if (chatRoomDetailUIState.canSignAsConfederation && identityCanSign) {
+ Text(
+ text = stringResource(Res.string.the_charter_names_the_groups),
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ TextButton(onClick = {
+ chatRoomDetailViewModel.proposeCharter(
+ onSuccess = { attemptId ->
+ onNavigateToRoute.invoke(
+ ConfederationSigningRoute(activeUserPublicKey = activeUserPublicKey, attemptId = attemptId)
+ )
+ },
+ onFailure = {},
+ )
+ }) {
+ Text(stringResource(Res.string.propose_the_charter))
+ }
+ }
+ }
}
}
}
@@ -2184,6 +2242,46 @@ private fun GroupPostsRow(
}
}
+/**
+ * The row that opens the group's inbox, with how much is unread; or, where this device holds no
+ * key yet, the way to set one up or the ceremony making it. docs/group-inbox.md.
+ */
+@Composable
+private fun GroupInboxRow(
+ inbox: InboxRowSummary,
+ onClick: () -> Unit,
+) {
+ Card(
+ modifier = Modifier.fillMaxWidth(),
+ onClick = onClick
+ ) {
+ ListItem(
+ leadingContent = {
+ Icon(Icons.Default.Mail, contentDescription = Decorative)
+ },
+ trailingContent = {
+ Icon(Icons.Default.ChevronRight, contentDescription = Decorative)
+ },
+ headlineContent = {
+ Text(text = stringResource(if (inbox.holdsKey || inbox.ceremonyRunning) Res.string.inbox else Res.string.set_up_an_inbox))
+ },
+ supportingContent = {
+ Text(
+ text = when {
+ inbox.holdsKey -> when (inbox.unread) {
+ 0 -> stringResource(Res.string.no_new_messages)
+ 1 -> stringResource(Res.string.one_new_message)
+ else -> stringResource(Res.string.n_new_messages, inbox.unread)
+ }
+ inbox.ceremonyRunning -> stringResource(Res.string.the_admins_are_making_the_inbox_key)
+ else -> stringResource(Res.string.let_anyone_on_nostr_write_to_the_group_privately)
+ }
+ )
+ }
+ )
+ }
+}
+
/** The row that opens a group's confederations: how many proposals name it. docs/confederation.md. */
@Composable
private fun ConfederationsRow(
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomMessagingScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomMessagingScreen.kt
index 45ac06e2..39b9166a 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomMessagingScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomMessagingScreen.kt
@@ -46,6 +46,7 @@ import mobi.giza.compose.repository.ChatRepository
import mobi.giza.compose.repository.DkgRepository
import mobi.giza.compose.repository.FrostSigningRepository
import mobi.giza.compose.repository.NostrRepository
+import mobi.giza.compose.ui.composable.navigation.routes.ConfederationSigningRoute
import mobi.giza.compose.ui.composable.navigation.routes.ChatRoomDetailRoute
import mobi.giza.compose.ui.composable.navigation.routes.DkgRitualRoute
import mobi.giza.compose.ui.composable.navigation.routes.ProposalListRoute
@@ -185,6 +186,11 @@ fun ChatRoomMessagingScreen(
)
)
},
+ onOpenConfederationSigning = { attemptId ->
+ onNavigateToRoute.invoke(
+ ConfederationSigningRoute(activeUserPublicKey = activeUserPublicKey, attemptId = attemptId)
+ )
+ },
onOpenSigning = { sessionId ->
onNavigateToRoute.invoke(
proposalDestination(
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationSigningScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationSigningScreen.kt
new file mode 100644
index 00000000..1c8d49ec
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationSigningScreen.kt
@@ -0,0 +1,169 @@
+package mobi.giza.compose.ui.composable
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Block
+import androidx.compose.material.icons.filled.CheckCircle
+import androidx.compose.material.icons.filled.HourglassEmpty
+import androidx.compose.material3.Button
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.HorizontalDivider
+import androidx.compose.material3.Icon
+import androidx.compose.material3.ListItem
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.OutlinedButton
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.SnackbarHost
+import androidx.compose.material3.Text
+import androidx.compose.material3.TopAppBar
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.getValue
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.lifecycle.viewmodel.compose.viewModel
+import mobi.giza.compose.database.model.ConfederationSigningStage
+import mobi.giza.compose.managers.ConfederationSigningManager
+import mobi.giza.compose.repository.ConfederationRepository
+import mobi.giza.compose.resources.Res
+import mobi.giza.compose.resources.answer_no
+import mobi.giza.compose.resources.answer_waiting
+import mobi.giza.compose.resources.answer_yes
+import mobi.giza.compose.resources.approve_for_the_confederation
+import mobi.giza.compose.resources.confederation_signing
+import mobi.giza.compose.resources.decline_for_the_confederation
+import mobi.giza.compose.resources.signed_by_admins_of_groups
+import mobi.giza.compose.resources.the_confederation_did_not_sign_it
+import mobi.giza.compose.resources.the_confederation_signed_it
+import mobi.giza.compose.resources.this_device_holds_no_such_request
+import mobi.giza.compose.resources.you_declined_this
+import mobi.giza.compose.text.ProposedEvent
+import mobi.giza.compose.ui.composable.widgets.Decorative
+import mobi.giza.compose.ui.composable.widgets.EmptyState
+import mobi.giza.compose.ui.composable.widgets.LoadingDataIndicator
+import mobi.giza.compose.ui.composable.widgets.LocalCanSign
+import mobi.giza.compose.ui.composable.widgets.LocalSnackbarHostState
+import mobi.giza.compose.ui.composable.widgets.NavigateBackButton
+import mobi.giza.compose.ui.composable.widgets.ScreenStateTransition
+import mobi.giza.compose.ui.theme.readableContent
+import mobi.giza.compose.ui.theme.spacing
+import mobi.giza.compose.ui.view.model.ConfederationSigningViewModel
+import mobi.giza.compose.ui.view.state.ConfederationSigningUIState
+import org.jetbrains.compose.resources.stringResource
+
+/**
+ * A confederation's request to sign one event (docs/confederation.md, Phase 15): what it would
+ * sign, said the way a group's signing screen says it, who has approved, and -- for a member not
+ * yet asked -- approve or decline, which counts for every group they are an admin of.
+ */
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun ConfederationSigningScreen(
+ attemptId: String,
+ initialConfederationSigningUIState: ConfederationSigningUIState = ConfederationSigningUIState.Loading,
+ confederationRepository: ConfederationRepository,
+ onNavigateBack: () -> Unit,
+) {
+ val viewModel: ConfederationSigningViewModel = viewModel(
+ factory = ConfederationSigningViewModel.factory(attemptId, initialConfederationSigningUIState, confederationRepository)
+ )
+ LaunchedEffect(true) {
+ if (initialConfederationSigningUIState == ConfederationSigningUIState.Loading) viewModel.initiate()
+ }
+ val state by viewModel.uiState.collectAsState()
+ val identityCanSign = LocalCanSign.current
+
+ Scaffold(
+ snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
+ topBar = {
+ TopAppBar(
+ title = { Text(text = stringResource(Res.string.confederation_signing), maxLines = 1, overflow = TextOverflow.Ellipsis) },
+ navigationIcon = { NavigateBackButton(onNavigateBack) },
+ )
+ },
+ ) { padding ->
+ ScreenStateTransition(state) { uiState ->
+ when (val current = uiState) {
+ ConfederationSigningUIState.Loading -> LoadingDataIndicator(modifier = Modifier.padding(padding))
+
+ ConfederationSigningUIState.NotHeld -> EmptyState(
+ modifier = Modifier.padding(padding),
+ message = stringResource(Res.string.this_device_holds_no_such_request),
+ )
+
+ is ConfederationSigningUIState.Loaded -> Column(
+ modifier = Modifier.padding(padding).readableContent().fillMaxSize()
+ .verticalScroll(rememberScrollState())
+ .padding(MaterialTheme.spacing.screenMargin),
+ verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap),
+ ) {
+ val attempt = current.attempt
+ val summary = ProposedEvent.summarize(current.event)
+ Text(text = summary.label, style = MaterialTheme.typography.labelMedium)
+ Text(text = summary.detail, style = MaterialTheme.typography.titleMedium)
+ Text(
+ text = stringResource(Res.string.signed_by_admins_of_groups, current.roleCount, current.groupCount),
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+
+ when {
+ attempt.stage == ConfederationSigningStage.COMPLETE ->
+ Text(text = stringResource(Res.string.the_confederation_signed_it), style = MaterialTheme.typography.titleSmall)
+ attempt.stage == ConfederationSigningStage.FAILED ->
+ Text(
+ text = stringResource(Res.string.the_confederation_did_not_sign_it, attempt.failureReason.orEmpty()),
+ color = MaterialTheme.colorScheme.error,
+ )
+ attempt.declinedAt != null ->
+ Text(text = stringResource(Res.string.you_declined_this))
+ }
+
+ if (ConfederationSigningManager.isAwaitingApproval(attempt) && identityCanSign) {
+ Button(modifier = Modifier.fillMaxWidth(), enabled = !current.isActing, onClick = viewModel::approve) {
+ Text(stringResource(Res.string.approve_for_the_confederation))
+ }
+ OutlinedButton(modifier = Modifier.fillMaxWidth(), enabled = !current.isActing, onClick = viewModel::decline) {
+ Text(stringResource(Res.string.decline_for_the_confederation))
+ }
+ }
+
+ HorizontalDivider()
+ current.answers.forEach { (name, answer) ->
+ ListItem(
+ leadingContent = {
+ Icon(
+ imageVector = when (answer) {
+ true -> Icons.Default.CheckCircle
+ false -> Icons.Default.Block
+ null -> Icons.Default.HourglassEmpty
+ },
+ contentDescription = Decorative,
+ )
+ },
+ headlineContent = { Text(name, maxLines = 1, overflow = TextOverflow.Ellipsis) },
+ supportingContent = {
+ Text(
+ stringResource(
+ when (answer) {
+ true -> Res.string.answer_yes
+ false -> Res.string.answer_no
+ null -> Res.string.answer_waiting
+ }
+ )
+ )
+ },
+ )
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/EditGroupNostrProfileScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/EditGroupNostrProfileScreen.kt
index 00211c4c..d59a79c1 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/EditGroupNostrProfileScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/EditGroupNostrProfileScreen.kt
@@ -47,6 +47,7 @@ import mobi.giza.compose.database.model.ChatRoom
import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
import mobi.giza.compose.repository.ChatRepository
import mobi.giza.compose.repository.FrostSigningRepository
+import mobi.giza.compose.ui.composable.navigation.routes.ConfederationSigningRoute
import mobi.giza.compose.ui.composable.navigation.routes.FrostSigningRoute
import mobi.giza.compose.ui.composable.navigation.routes.Route
import mobi.giza.compose.ui.composable.widgets.ErrorState
@@ -198,11 +199,18 @@ fun EditGroupNostrProfileScreen(
// group still showing the old one
// would read as a failure.
onNavigateToRouteAndPopUpInclusive.invoke(
- FrostSigningRoute(
- activeUserPublicKey = activeUserPublicKey,
- chatRoomId = chatRoomId,
- sessionId = sessionId
- )
+ if (editGroupNostrProfileViewModel.isConfederation) {
+ ConfederationSigningRoute(
+ activeUserPublicKey = activeUserPublicKey,
+ attemptId = sessionId
+ )
+ } else {
+ FrostSigningRoute(
+ activeUserPublicKey = activeUserPublicKey,
+ chatRoomId = chatRoomId,
+ sessionId = sessionId
+ )
+ }
)
},
// Stay on the form with what was typed
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/FrostSigningScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/FrostSigningScreen.kt
index 0a68b174..0bde2306 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/FrostSigningScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/FrostSigningScreen.kt
@@ -210,7 +210,7 @@ fun FrostSigningScreen(
// A confederation event's terms and what this device could not check
// about it, for the member to weigh. docs/confederation.md, D6.
- state.confederationNotes.forEach { note ->
+ state.proposalNotes.forEach { note ->
Text(text = note, style = MaterialTheme.typography.bodySmall)
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/GroupInboxConversationScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/GroupInboxConversationScreen.kt
new file mode 100644
index 00000000..f3c4af0a
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/GroupInboxConversationScreen.kt
@@ -0,0 +1,282 @@
+package mobi.giza.compose.ui.composable
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.widthIn
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.items
+import androidx.compose.material3.Button
+import androidx.compose.material3.Card
+import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.TextButton
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.saveable.rememberSaveable
+import androidx.compose.runtime.setValue
+import mobi.giza.compose.resources.ask_the_group_to_sign_this_reply
+import mobi.giza.compose.resources.could_not_ask_the_group_to_sign_this_reply
+import mobi.giza.compose.resources.has_announced_no_inbox_key
+import mobi.giza.compose.resources.not_yet_on_a_relay
+import mobi.giza.compose.resources.reply_as_the_group
+import mobi.giza.compose.resources.send_reply_again
+import mobi.giza.compose.resources.sent_again
+import mobi.giza.compose.resources.the_group_signs_a_reply
+import mobi.giza.compose.ui.composable.navigation.routes.FrostSigningRoute
+import mobi.giza.compose.ui.composable.widgets.LocalCanSign
+import mobi.giza.compose.ui.composable.widgets.rememberNotifier
+import androidx.compose.material3.CardDefaults
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.SnackbarHost
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.material3.TopAppBar
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.lifecycle.viewmodel.compose.viewModel
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import kotlin.time.Instant
+import mobi.giza.compose.database.model.ChatRoom
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.extensions.toFormattedTimeAndDateString
+import mobi.giza.compose.repository.ChatRepository
+import mobi.giza.compose.repository.GroupInboxRepository
+import mobi.giza.compose.resources.Res
+import mobi.giza.compose.resources.couldn_t_find_the_group
+import mobi.giza.compose.resources.nobody_has_written_to_the_group_yet
+import mobi.giza.compose.resources.the_group
+import mobi.giza.compose.resources.you_and_the_group
+import mobi.giza.compose.ui.composable.navigation.routes.Route
+import mobi.giza.compose.ui.composable.widgets.EmptyState
+import mobi.giza.compose.ui.composable.widgets.ErrorState
+import mobi.giza.compose.ui.composable.widgets.LoadingDataIndicator
+import mobi.giza.compose.ui.composable.widgets.LocalSnackbarHostState
+import mobi.giza.compose.ui.composable.widgets.NavigateBackButton
+import mobi.giza.compose.ui.composable.widgets.ScreenStateTransition
+import mobi.giza.compose.ui.theme.ConformancePreviews
+import mobi.giza.compose.ui.theme.GizaTheme
+import mobi.giza.compose.ui.theme.readableContent
+import mobi.giza.compose.ui.theme.spacing
+import mobi.giza.compose.ui.view.model.GroupInboxConversationViewModel
+import mobi.giza.compose.ui.view.state.GroupInboxConversationUIState
+import org.jetbrains.compose.resources.stringResource
+
+/**
+ * One conversation in the group's inbox (docs/group-inbox.md, D8 and D10): what the people in it
+ * wrote, and what the group answered, in the order they were written. A reply is the group's,
+ * not the admin's who drafted it, so it is marked as the group's.
+ */
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun GroupInboxConversationScreen(
+ activeUserPublicKey: HexKey,
+ chatRoomId: String,
+ relayHint: String?,
+ conversationId: String,
+ initialUIState: GroupInboxConversationUIState = GroupInboxConversationUIState.Loading,
+ chatRepository: ChatRepository,
+ inboxRepository: GroupInboxRepository,
+ onNavigateToRoute: (Route) -> Unit,
+ onNavigateBack: () -> Unit,
+) {
+ val viewModel: GroupInboxConversationViewModel = viewModel(
+ factory = GroupInboxConversationViewModel.factory(chatRoomId, conversationId, initialUIState, chatRepository, inboxRepository)
+ )
+ LaunchedEffect(true) {
+ if (initialUIState == GroupInboxConversationUIState.Loading) viewModel.initiate()
+ }
+ val notify = rememberNotifier(rememberCoroutineScope())
+ val couldNotPropose = stringResource(Res.string.could_not_ask_the_group_to_sign_this_reply)
+ val sentAgain = stringResource(Res.string.sent_again)
+ val canSign = LocalCanSign.current
+ var draft by rememberSaveable { mutableStateOf("") }
+ val title = (viewModel.uiState as? GroupInboxConversationUIState.Loaded)?.names?.joinToString(", ")
+ ?.let { stringResource(Res.string.you_and_the_group, it) }
+ ?: stringResource(Res.string.the_group)
+
+ Scaffold(
+ snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
+ topBar = {
+ TopAppBar(
+ title = { Text(title, maxLines = 1, overflow = TextOverflow.Ellipsis) },
+ navigationIcon = { NavigateBackButton(onNavigateBack) },
+ )
+ }
+ ) { padding ->
+ ScreenStateTransition(viewModel.uiState) { uiState ->
+ when (val state = uiState) {
+ is GroupInboxConversationUIState.Error -> ErrorState(
+ modifier = Modifier.padding(padding),
+ message = stringResource(Res.string.couldn_t_find_the_group),
+ onRetry = null,
+ )
+
+ GroupInboxConversationUIState.Loading -> Column(
+ modifier = Modifier.fillMaxWidth().padding(padding).padding(MaterialTheme.spacing.screenMargin),
+ horizontalAlignment = Alignment.CenterHorizontally,
+ ) {
+ Spacer(modifier = Modifier.height(MaterialTheme.spacing.emphasisGap))
+ LoadingDataIndicator(fillScreen = false)
+ }
+
+ is GroupInboxConversationUIState.Loaded -> Column(
+ modifier = Modifier.padding(padding).readableContent().fillMaxSize()
+ .padding(MaterialTheme.spacing.screenMargin),
+ verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap),
+ ) {
+ if (state.lines.isEmpty()) {
+ EmptyState(
+ modifier = Modifier.weight(1f),
+ message = stringResource(Res.string.nobody_has_written_to_the_group_yet),
+ )
+ } else {
+ LazyColumn(
+ modifier = Modifier.weight(1f).fillMaxWidth(),
+ verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap),
+ ) {
+ items(state.lines, key = { it.rumorId }) { line ->
+ MessageCard(line, onSendAgain = { session -> viewModel.sendAgain(session) { if (it) notify(sentAgain) } })
+ }
+ }
+ }
+ if (canSign && state.lines.isNotEmpty()) {
+ Composer(
+ draft = draft,
+ onDraft = { draft = it },
+ withoutKey = state.withoutKey,
+ proposing = state.proposing,
+ onPropose = {
+ viewModel.propose(draft) { session ->
+ if (session == null) {
+ notify(couldNotPropose)
+ } else {
+ draft = ""
+ onNavigateToRoute(FrostSigningRoute(activeUserPublicKey, chatRoomId, session))
+ }
+ }
+ },
+ )
+ }
+ }
+ }
+ }
+ }
+}
+
+/**
+ * The way to answer (D10, D13): the words, what signing it means, a warning for every recipient
+ * whose app may not open a message from a group, and the button that asks the quorum.
+ */
+@Composable
+private fun Composer(
+ draft: String,
+ onDraft: (String) -> Unit,
+ withoutKey: List,
+ proposing: Boolean,
+ onPropose: () -> Unit,
+) {
+ Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap)) {
+ withoutKey.forEach { name ->
+ Text(
+ stringResource(Res.string.has_announced_no_inbox_key, name),
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
+ OutlinedTextField(
+ modifier = Modifier.fillMaxWidth(),
+ value = draft,
+ onValueChange = onDraft,
+ label = { Text(stringResource(Res.string.reply_as_the_group)) },
+ minLines = 2,
+ )
+ Text(
+ stringResource(Res.string.the_group_signs_a_reply),
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ Button(onClick = onPropose, enabled = draft.isNotBlank() && !proposing) {
+ Text(stringResource(Res.string.ask_the_group_to_sign_this_reply))
+ }
+ }
+}
+
+/** One message: theirs on the leading edge, the group's on the trailing one, in its own colours. */
+@Composable
+private fun MessageCard(line: GroupInboxConversationUIState.Line, onSendAgain: (String) -> Unit) {
+ Column(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalAlignment = if (line.outgoing) Alignment.End else Alignment.Start,
+ ) {
+ Card(
+ modifier = Modifier.widthIn(max = MaterialTheme.spacing.space400 * 8),
+ colors = if (line.outgoing) {
+ CardDefaults.cardColors(
+ containerColor = MaterialTheme.colorScheme.primaryContainer,
+ contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
+ )
+ } else {
+ CardDefaults.cardColors()
+ },
+ ) {
+ Column(
+ modifier = Modifier.padding(MaterialTheme.spacing.containerPadding),
+ verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap),
+ ) {
+ Text(
+ text = if (line.outgoing) stringResource(Res.string.the_group) else line.senderName,
+ style = MaterialTheme.typography.labelMedium,
+ )
+ Text(text = line.text, style = MaterialTheme.typography.bodyMedium)
+ Text(
+ text = Instant.fromEpochSeconds(line.createdAt).toFormattedTimeAndDateString(),
+ style = MaterialTheme.typography.labelSmall,
+ )
+ line.unsentSessionId?.let { session ->
+ Text(stringResource(Res.string.not_yet_on_a_relay), style = MaterialTheme.typography.labelSmall)
+ TextButton(onClick = { onSendAgain(session) }) { Text(stringResource(Res.string.send_reply_again)) }
+ }
+ }
+ }
+ }
+}
+
+@ConformancePreviews
+@Composable
+private fun GroupInboxConversationScreenPreview() {
+ val chatRoomId = "d".repeat(64)
+ GizaTheme {
+ Surface(modifier = Modifier.fillMaxSize()) {
+ GroupInboxConversationScreen(
+ activeUserPublicKey = "a".repeat(64),
+ chatRoomId = chatRoomId,
+ relayHint = null,
+ conversationId = "c1",
+ initialUIState = GroupInboxConversationUIState.Loaded(
+ localChatRoom = LocalChatRoom(
+ chatRoom = ChatRoom(id = chatRoomId, userPublicKey = "a".repeat(64), subject = "#Ekklesia", description = null, mlsGroupState = "state")
+ ),
+ names = listOf("Zola"),
+ lines = listOf(
+ GroupInboxConversationUIState.Line("r1", "Can I join the reading group?", 1_700_000_000, outgoing = false, senderName = "Zola"),
+ GroupInboxConversationUIState.Line("r2", "Yes. We meet on Thursdays.", 1_700_003_600, outgoing = true, senderName = ""),
+ ),
+ ),
+ chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
+ inboxRepository = GroupInboxRepository.NO_OP,
+ onNavigateToRoute = {},
+ onNavigateBack = {},
+ )
+ }
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/GroupInboxScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/GroupInboxScreen.kt
new file mode 100644
index 00000000..63d110f9
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/GroupInboxScreen.kt
@@ -0,0 +1,255 @@
+package mobi.giza.compose.ui.composable
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.items
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.ChevronRight
+import androidx.compose.material.icons.filled.Lock
+import androidx.compose.material.icons.filled.Mail
+import androidx.compose.material.icons.filled.Settings
+import androidx.compose.material3.Badge
+import androidx.compose.material3.Card
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.ListItem
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.SnackbarHost
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.material3.TopAppBar
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.lifecycle.viewmodel.compose.viewModel
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import kotlin.time.Instant
+import mobi.giza.compose.database.model.ChatRoom
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.extensions.toFormattedTimeAndDateString
+import mobi.giza.compose.repository.ChatRepository
+import mobi.giza.compose.repository.GroupInboxRepository
+import mobi.giza.compose.resources.Res
+import mobi.giza.compose.resources.couldn_t_find_the_group
+import mobi.giza.compose.resources.earlier_mail_is_not_on_this_device
+import mobi.giza.compose.resources.inbox
+import mobi.giza.compose.resources.inbox_settings
+import mobi.giza.compose.resources.n_messages_this_device_can_t_open
+import mobi.giza.compose.resources.nobody_has_written_to_the_group_yet
+import mobi.giza.compose.resources.one_message_this_device_can_t_open
+import mobi.giza.compose.resources.the_group_wrote
+import mobi.giza.compose.resources.the_group_hasn_t_announced_its_inbox
+import mobi.giza.compose.resources.why_a_message_can_t_be_opened
+import mobi.giza.compose.ui.composable.navigation.routes.GroupInboxConversationRoute
+import mobi.giza.compose.ui.composable.navigation.routes.GroupInboxSettingsRoute
+import mobi.giza.compose.ui.composable.navigation.routes.Route
+import mobi.giza.compose.ui.composable.widgets.Decorative
+import mobi.giza.compose.ui.composable.widgets.EmptyState
+import mobi.giza.compose.ui.composable.widgets.ErrorState
+import mobi.giza.compose.ui.composable.widgets.LoadingDataIndicator
+import mobi.giza.compose.ui.composable.widgets.LocalSnackbarHostState
+import mobi.giza.compose.ui.composable.widgets.NavigateBackButton
+import mobi.giza.compose.ui.composable.widgets.ScreenStateTransition
+import mobi.giza.compose.ui.theme.ConformancePreviews
+import mobi.giza.compose.ui.theme.GizaTheme
+import mobi.giza.compose.ui.theme.readableContent
+import mobi.giza.compose.ui.theme.spacing
+import mobi.giza.compose.ui.view.model.GroupInboxViewModel
+import mobi.giza.compose.ui.view.state.GroupInboxUIState
+import org.jetbrains.compose.resources.stringResource
+
+/**
+ * The group's inbox: the conversations people have started with the group by writing to its
+ * npub, newest first (docs/group-inbox.md, D8 and D9).
+ *
+ * Reached from the group's screen, and only on a device that holds the inbox key. Says what it
+ * cannot do as plainly as what it can: mail no key here opens is counted with why, and an inbox
+ * the group has made but not yet announced says nobody can write to it yet.
+ */
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun GroupInboxScreen(
+ activeUserPublicKey: HexKey,
+ chatRoomId: String,
+ relayHint: String?,
+ initialUIState: GroupInboxUIState = GroupInboxUIState.Loading,
+ chatRepository: ChatRepository,
+ inboxRepository: GroupInboxRepository,
+ onNavigateToRoute: (Route) -> Unit,
+ onNavigateBack: () -> Unit,
+) {
+ val viewModel: GroupInboxViewModel = viewModel(
+ factory = GroupInboxViewModel.factory(chatRoomId, initialUIState, chatRepository, inboxRepository)
+ )
+ LaunchedEffect(true) {
+ if (initialUIState == GroupInboxUIState.Loading) viewModel.initiate()
+ }
+
+ Scaffold(
+ snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
+ topBar = {
+ TopAppBar(
+ title = { Text(stringResource(Res.string.inbox), maxLines = 1, overflow = TextOverflow.Ellipsis) },
+ navigationIcon = { NavigateBackButton(onNavigateBack) },
+ actions = {
+ IconButton(onClick = { onNavigateToRoute(GroupInboxSettingsRoute(activeUserPublicKey, chatRoomId, relayHint)) }) {
+ Icon(Icons.Default.Settings, contentDescription = stringResource(Res.string.inbox_settings))
+ }
+ },
+ )
+ }
+ ) { padding ->
+ ScreenStateTransition(viewModel.uiState) { uiState ->
+ when (val state = uiState) {
+ // Nothing to retry: the room came from a navigation argument.
+ is GroupInboxUIState.Error -> ErrorState(
+ modifier = Modifier.padding(padding),
+ message = stringResource(Res.string.couldn_t_find_the_group),
+ onRetry = null,
+ )
+
+ GroupInboxUIState.Loading -> Column(
+ modifier = Modifier.fillMaxWidth().padding(padding).padding(MaterialTheme.spacing.screenMargin),
+ horizontalAlignment = Alignment.CenterHorizontally,
+ ) {
+ Spacer(modifier = Modifier.height(MaterialTheme.spacing.emphasisGap))
+ LoadingDataIndicator(fillScreen = false)
+ }
+
+ is GroupInboxUIState.Loaded -> LazyColumn(
+ modifier = Modifier.padding(padding).readableContent().fillMaxSize()
+ .padding(MaterialTheme.spacing.screenMargin),
+ verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap),
+ ) {
+ val status = state.status
+ if (status.announcedKey == null) {
+ item { NoticeCard(Icons.Default.Lock, stringResource(Res.string.the_group_hasn_t_announced_its_inbox)) }
+ }
+ if (state.unopenable > 0) {
+ item {
+ NoticeCard(
+ Icons.Default.Lock,
+ if (state.unopenable == 1) stringResource(Res.string.one_message_this_device_can_t_open)
+ else stringResource(Res.string.n_messages_this_device_can_t_open, state.unopenable),
+ stringResource(Res.string.why_a_message_can_t_be_opened),
+ )
+ }
+ }
+ if (state.conversations.isEmpty()) {
+ item {
+ // D15: a promoted admin's first key opens nothing sent before it.
+ val joinedLate = status.keys.isNotEmpty() && status.keys.minOf { it.generation } > 0
+ EmptyState(
+ message = stringResource(
+ if (joinedLate) Res.string.earlier_mail_is_not_on_this_device
+ else Res.string.nobody_has_written_to_the_group_yet
+ )
+ )
+ }
+ } else {
+ items(state.conversations, key = { it.conversationId }) { conversation ->
+ ConversationRow(
+ conversation = conversation,
+ onClick = {
+ onNavigateToRoute(
+ GroupInboxConversationRoute(activeUserPublicKey, chatRoomId, relayHint, conversation.conversationId)
+ )
+ },
+ )
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+@Composable
+private fun NoticeCard(icon: androidx.compose.ui.graphics.vector.ImageVector, headline: String, supporting: String? = null) {
+ Card(modifier = Modifier.fillMaxWidth()) {
+ ListItem(
+ leadingContent = { Icon(icon, contentDescription = Decorative) },
+ headlineContent = { Text(headline) },
+ supportingContent = supporting?.let { { Text(it) } },
+ )
+ }
+}
+
+/** One conversation: who it is with, the last line and when, and how much is unread. */
+@Composable
+private fun ConversationRow(conversation: GroupInboxRepository.ConversationSummary, onClick: () -> Unit) {
+ val lastLine = if (conversation.lastOutgoing) {
+ stringResource(Res.string.the_group_wrote, conversation.lastText)
+ } else {
+ conversation.lastText
+ }
+ Card(modifier = Modifier.fillMaxWidth(), onClick = onClick) {
+ ListItem(
+ leadingContent = { Icon(Icons.Default.Mail, contentDescription = Decorative) },
+ headlineContent = {
+ Text(conversation.names.joinToString(", "), maxLines = 1, overflow = TextOverflow.Ellipsis)
+ },
+ supportingContent = {
+ Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap)) {
+ Text(lastLine, maxLines = 2, overflow = TextOverflow.Ellipsis)
+ Text(
+ Instant.fromEpochSeconds(conversation.lastAt).toFormattedTimeAndDateString(),
+ style = MaterialTheme.typography.labelSmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
+ },
+ trailingContent = {
+ if (conversation.unread > 0) {
+ Badge { Text(conversation.unread.toString()) }
+ } else {
+ Icon(Icons.Default.ChevronRight, contentDescription = Decorative)
+ }
+ },
+ )
+ }
+}
+
+@ConformancePreviews
+@Composable
+private fun GroupInboxScreenPreview() {
+ val chatRoomId = "d".repeat(64)
+ GizaTheme {
+ Surface(modifier = Modifier.fillMaxSize()) {
+ GroupInboxScreen(
+ activeUserPublicKey = "a".repeat(64),
+ chatRoomId = chatRoomId,
+ relayHint = null,
+ initialUIState = GroupInboxUIState.Loaded(
+ localChatRoom = LocalChatRoom(
+ chatRoom = ChatRoom(id = chatRoomId, userPublicKey = "a".repeat(64), subject = "#Ekklesia", description = null, mlsGroupState = "state")
+ ),
+ conversations = listOf(
+ GroupInboxRepository.ConversationSummary(
+ conversationId = "c1", participants = listOf("b".repeat(64)), names = listOf("Zola"),
+ lastText = "Can I join the reading group?", lastAt = 1_700_000_000, lastOutgoing = false, unread = 1,
+ )
+ ),
+ unopenable = 2,
+ status = GroupInboxRepository.Status(
+ keys = emptyList(), ceremony = null, announcedKey = null, relays = emptyList(), setUpRefusal = null, waitingOn = emptyList(),
+ ),
+ ),
+ chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
+ inboxRepository = GroupInboxRepository.NO_OP,
+ onNavigateToRoute = {},
+ onNavigateBack = {},
+ )
+ }
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/GroupInboxSettingsScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/GroupInboxSettingsScreen.kt
new file mode 100644
index 00000000..c9dea7fd
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/GroupInboxSettingsScreen.kt
@@ -0,0 +1,308 @@
+package mobi.giza.compose.ui.composable
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Autorenew
+import androidx.compose.material.icons.filled.HourglassTop
+import androidx.compose.material.icons.filled.Key
+import androidx.compose.material3.Button
+import androidx.compose.material3.Card
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.Icon
+import androidx.compose.material3.ListItem
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.OutlinedButton
+import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.SnackbarHost
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.material3.TopAppBar
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.lifecycle.viewmodel.compose.viewModel
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import mobi.giza.compose.database.model.ChatRoom
+import mobi.giza.compose.database.model.InboxKeyCeremonyStage
+import mobi.giza.compose.database.model.InboxKeyState
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.nostr.RelayUrlInput
+import mobi.giza.compose.nostr.Relays
+import mobi.giza.compose.repository.ChatRepository
+import mobi.giza.compose.repository.GroupInboxRepository
+import mobi.giza.compose.resources.Res
+import mobi.giza.compose.resources.abandon
+import mobi.giza.compose.resources.announced_anyone_can_write_to_it
+import mobi.giza.compose.resources.couldn_t_find_the_group
+import mobi.giza.compose.resources.couldn_t_start_the_ceremony
+import mobi.giza.compose.resources.inbox_key_generation
+import mobi.giza.compose.resources.inbox_settings
+import mobi.giza.compose.resources.inbox_setup_explainer
+import mobi.giza.compose.resources.mail_arrives_on
+import mobi.giza.compose.resources.no_inbox_relays_were_valid
+import mobi.giza.compose.resources.one_relay_per_line
+import mobi.giza.compose.resources.retired_kept_to_open_older_mail
+import mobi.giza.compose.resources.rotate_explainer
+import mobi.giza.compose.resources.rotate_the_inbox_key
+import mobi.giza.compose.resources.set_up_an_inbox
+import mobi.giza.compose.resources.the_admins_are_making_the_inbox_key
+import mobi.giza.compose.resources.the_ceremony_ended
+import mobi.giza.compose.resources.the_admins_have_changed_since_this_key_was_made
+import mobi.giza.compose.resources.the_inbox_key_ceremony_started
+import mobi.giza.compose.resources.try_again
+import mobi.giza.compose.resources.waiting_for_the_group_to_sign_its_announcement
+import mobi.giza.compose.resources.waiting_on
+import mobi.giza.compose.resources.where_mail_should_arrive
+import mobi.giza.compose.ui.composable.navigation.routes.Route
+import mobi.giza.compose.ui.composable.widgets.Decorative
+import mobi.giza.compose.ui.composable.widgets.ErrorState
+import mobi.giza.compose.ui.composable.widgets.LoadingDataIndicator
+import mobi.giza.compose.ui.composable.widgets.LocalCanSign
+import mobi.giza.compose.ui.composable.widgets.LocalSnackbarHostState
+import mobi.giza.compose.ui.composable.widgets.NavigateBackButton
+import mobi.giza.compose.ui.composable.widgets.ScreenStateTransition
+import mobi.giza.compose.ui.composable.widgets.rememberNotifier
+import mobi.giza.compose.ui.theme.ConformancePreviews
+import mobi.giza.compose.ui.theme.GizaTheme
+import mobi.giza.compose.ui.theme.readableContent
+import mobi.giza.compose.ui.theme.spacing
+import mobi.giza.compose.ui.view.model.GroupInboxSettingsViewModel
+import mobi.giza.compose.ui.view.state.GroupInboxSettingsUIState
+import org.jetbrains.compose.resources.stringResource
+
+/**
+ * The group's inbox key (docs/group-inbox.md, D2 to D7 and D14): setting one up, which is an
+ * admin starting the ceremony that makes it; where it stands, generation by generation; the
+ * ceremony while it runs, with who it waits on; and rotating it.
+ *
+ * Nothing here is the decision to have an inbox. That is the group signing its announcement,
+ * which the ceremony's coordinator asks for when the key is made, and which every member who
+ * holds a share is asked about on the signing screen.
+ */
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun GroupInboxSettingsScreen(
+ activeUserPublicKey: HexKey,
+ chatRoomId: String,
+ relayHint: String?,
+ initialUIState: GroupInboxSettingsUIState = GroupInboxSettingsUIState.Loading,
+ chatRepository: ChatRepository,
+ inboxRepository: GroupInboxRepository,
+ onNavigateToRoute: (Route) -> Unit,
+ onNavigateBack: () -> Unit,
+) {
+ val viewModel: GroupInboxSettingsViewModel = viewModel(
+ factory = GroupInboxSettingsViewModel.factory(chatRoomId, initialUIState, chatRepository, inboxRepository)
+ )
+ LaunchedEffect(true) {
+ if (initialUIState == GroupInboxSettingsUIState.Loading) viewModel.initiate()
+ }
+ val notify = rememberNotifier(rememberCoroutineScope())
+ val started = stringResource(Res.string.the_inbox_key_ceremony_started)
+ val noRelays = stringResource(Res.string.no_inbox_relays_were_valid)
+ val couldNotStart = stringResource(Res.string.couldn_t_start_the_ceremony)
+ val report: (String?) -> Unit = { failure -> notify(if (failure == null) started else couldNotStart) }
+ val canSign = LocalCanSign.current
+
+ Scaffold(
+ snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
+ topBar = {
+ TopAppBar(
+ title = { Text(stringResource(Res.string.inbox_settings), maxLines = 1, overflow = TextOverflow.Ellipsis) },
+ navigationIcon = { NavigateBackButton(onNavigateBack) },
+ )
+ }
+ ) { padding ->
+ ScreenStateTransition(viewModel.uiState) { uiState ->
+ when (val state = uiState) {
+ is GroupInboxSettingsUIState.Error -> ErrorState(
+ modifier = Modifier.padding(padding),
+ message = stringResource(Res.string.couldn_t_find_the_group),
+ onRetry = null,
+ )
+
+ GroupInboxSettingsUIState.Loading -> Column(
+ modifier = Modifier.fillMaxWidth().padding(padding).padding(MaterialTheme.spacing.screenMargin),
+ horizontalAlignment = Alignment.CenterHorizontally,
+ ) {
+ Spacer(modifier = Modifier.height(MaterialTheme.spacing.emphasisGap))
+ LoadingDataIndicator(fillScreen = false)
+ }
+
+ is GroupInboxSettingsUIState.Loaded -> Column(
+ modifier = Modifier.padding(padding).readableContent().fillMaxSize()
+ .verticalScroll(rememberScrollState())
+ .padding(MaterialTheme.spacing.screenMargin),
+ verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.sectionGap),
+ ) {
+ val status = state.status
+ val ceremony = status.ceremony
+ val running = ceremony?.isRunning == true
+ val visibleKeys = status.keys.filter { it.state != InboxKeyState.WIPED }
+
+ if (visibleKeys.isEmpty() && !running) {
+ SetUp(
+ busy = state.busy,
+ refusal = status.setUpRefusal,
+ canSign = canSign,
+ onSetUp = { text ->
+ val relays = text.lines().mapNotNull { RelayUrlInput.relayUrlOrNull(it) }
+ if (relays.isEmpty()) notify(noRelays) else viewModel.setUp(relays, report)
+ },
+ )
+ }
+
+ visibleKeys.forEach { key ->
+ Card(modifier = Modifier.fillMaxWidth()) {
+ ListItem(
+ leadingContent = { Icon(Icons.Default.Key, contentDescription = Decorative) },
+ headlineContent = {
+ Text(stringResource(Res.string.inbox_key_generation, key.generation, fingerprint(key.publicKey)))
+ },
+ supportingContent = {
+ Text(
+ when (key.state) {
+ InboxKeyState.ANNOUNCED -> stringResource(Res.string.announced_anyone_can_write_to_it)
+ InboxKeyState.RETIRED -> stringResource(Res.string.retired_kept_to_open_older_mail)
+ else -> stringResource(Res.string.waiting_for_the_group_to_sign_its_announcement)
+ }
+ )
+ },
+ )
+ }
+ }
+
+ if (status.relays.isNotEmpty()) {
+ Text(
+ text = stringResource(Res.string.mail_arrives_on, status.relays.joinToString(", ") { it.url.removePrefix("wss://").trimEnd('/') }),
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
+
+ if (ceremony != null && running) {
+ Card(modifier = Modifier.fillMaxWidth()) {
+ ListItem(
+ leadingContent = { Icon(Icons.Default.HourglassTop, contentDescription = Decorative) },
+ headlineContent = { Text(stringResource(Res.string.the_admins_are_making_the_inbox_key)) },
+ supportingContent = status.waitingOn.takeIf { it.isNotEmpty() }?.let { names ->
+ { Text(stringResource(Res.string.waiting_on, names.joinToString(", "))) }
+ },
+ trailingContent = if (ceremony.isParticipant() && canSign) {
+ { TextButton(onClick = { viewModel.abandon(ceremony.id) {} }, enabled = !state.busy) { Text(stringResource(Res.string.abandon)) } }
+ } else {
+ null
+ },
+ )
+ }
+ } else if (ceremony?.stage == InboxKeyCeremonyStage.FAILED && visibleKeys.isNotEmpty()) {
+ Text(
+ text = stringResource(Res.string.the_ceremony_ended, ceremony.failureReason.orEmpty()),
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.error,
+ )
+ }
+
+ if (visibleKeys.isNotEmpty() && !running) {
+ Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap)) {
+ if (status.rotationOwed) {
+ Text(
+ stringResource(Res.string.the_admins_have_changed_since_this_key_was_made),
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.error,
+ )
+ }
+ Text(stringResource(Res.string.rotate_explainer), style = MaterialTheme.typography.bodyMedium)
+ status.setUpRefusal?.let {
+ Text(it, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ OutlinedButton(
+ onClick = { viewModel.rotate(report) },
+ enabled = status.setUpRefusal == null && !state.busy && canSign,
+ ) {
+ Icon(Icons.Default.Autorenew, contentDescription = Decorative)
+ Spacer(modifier = Modifier.width(MaterialTheme.spacing.space125))
+ Text(
+ stringResource(
+ if (ceremony?.stage == InboxKeyCeremonyStage.FAILED) Res.string.try_again else Res.string.rotate_the_inbox_key
+ )
+ )
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+/** A key as a person can compare it across devices: its first and last eight characters. */
+private fun fingerprint(key: HexKey): String = key.take(8) + "\u2026" + key.takeLast(8)
+
+/** Starting the first ceremony: what it does, where mail should arrive, and the button. */
+@Composable
+private fun SetUp(busy: Boolean, refusal: String?, canSign: Boolean, onSetUp: (String) -> Unit) {
+ var relays by remember { mutableStateOf(Relays.DefaultDMRelayList.joinToString("\n") { it.url }) }
+ Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap)) {
+ Text(stringResource(Res.string.inbox_setup_explainer), style = MaterialTheme.typography.bodyLarge)
+ OutlinedTextField(
+ modifier = Modifier.fillMaxWidth(),
+ value = relays,
+ onValueChange = { relays = it },
+ label = { Text(stringResource(Res.string.where_mail_should_arrive)) },
+ supportingText = { Text(stringResource(Res.string.one_relay_per_line)) },
+ minLines = 2,
+ )
+ refusal?.let {
+ Text(it, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ Button(onClick = { onSetUp(relays) }, enabled = refusal == null && !busy && canSign) {
+ Text(stringResource(Res.string.set_up_an_inbox))
+ }
+ }
+}
+
+@ConformancePreviews
+@Composable
+private fun GroupInboxSettingsScreenPreview() {
+ val chatRoomId = "d".repeat(64)
+ GizaTheme {
+ Surface(modifier = Modifier.fillMaxSize()) {
+ GroupInboxSettingsScreen(
+ activeUserPublicKey = "a".repeat(64),
+ chatRoomId = chatRoomId,
+ relayHint = null,
+ initialUIState = GroupInboxSettingsUIState.Loaded(
+ localChatRoom = LocalChatRoom(
+ chatRoom = ChatRoom(id = chatRoomId, userPublicKey = "a".repeat(64), subject = "#Ekklesia", description = null, mlsGroupState = "state")
+ ),
+ status = GroupInboxRepository.Status(
+ keys = emptyList(), ceremony = null, announcedKey = null, relays = emptyList(), setUpRefusal = null, waitingOn = emptyList(),
+ ),
+ ),
+ chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
+ inboxRepository = GroupInboxRepository.NO_OP,
+ onNavigateToRoute = {},
+ onNavigateBack = {},
+ )
+ }
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/GizaNavHost.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/GizaNavHost.kt
index 7091824a..83072349 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/GizaNavHost.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/GizaNavHost.kt
@@ -8,12 +8,20 @@ import mobi.giza.compose.ui.composable.navigation.routes.AddGroupPostRoute
import mobi.giza.compose.ui.composable.navigation.routes.ConfederationsRoute
import mobi.giza.compose.ui.composable.navigation.routes.ConfederationProposalRoute
import mobi.giza.compose.ui.composable.navigation.routes.ConfederationRitualRoute
+import mobi.giza.compose.ui.composable.navigation.routes.ConfederationSigningRoute
+import mobi.giza.compose.ui.composable.ConfederationSigningScreen
import mobi.giza.compose.ui.composable.ConfederationRitualScreen
import mobi.giza.compose.ui.composable.ConfederationProposalScreen
import mobi.giza.compose.ui.composable.navigation.routes.ProposeConfederationRoute
import mobi.giza.compose.ui.composable.ConfederationsScreen
import mobi.giza.compose.ui.composable.ProposeConfederationScreen
import mobi.giza.compose.ui.composable.navigation.routes.GroupPostsRoute
+import mobi.giza.compose.ui.composable.navigation.routes.GroupInboxRoute
+import mobi.giza.compose.ui.composable.navigation.routes.GroupInboxConversationRoute
+import mobi.giza.compose.ui.composable.navigation.routes.GroupInboxSettingsRoute
+import mobi.giza.compose.ui.composable.GroupInboxScreen
+import mobi.giza.compose.ui.composable.GroupInboxConversationScreen
+import mobi.giza.compose.ui.composable.GroupInboxSettingsScreen
import mobi.giza.compose.ui.composable.AddGroupPostScreen
import mobi.giza.compose.ui.composable.GroupPostsScreen
import mobi.giza.compose.ui.composable.navigation.routes.EditGroupNostrProfileRoute
@@ -46,6 +54,7 @@ import mobi.giza.compose.GizaGlobal
import mobi.giza.compose.database.repository.DatabaseChatRepository
import mobi.giza.compose.database.repository.DatabaseDkgRepository
import mobi.giza.compose.database.repository.DatabaseConfederationRepository
+import mobi.giza.compose.database.repository.DatabaseGroupInboxRepository
import mobi.giza.compose.database.repository.DatabaseFrostSigningRepository
import mobi.giza.compose.database.repository.DatabaseMarmotRepository
import mobi.giza.compose.database.repository.DatabaseNostrRepository
@@ -229,6 +238,13 @@ fun GizaNavHost(
activeIdentity = sovereignWalletViewModel.activeIdentity,
)
}
+ val databaseGroupInboxRepository = remember {
+ DatabaseGroupInboxRepository(
+ database = auxDatabaseManager.auxDatabase,
+ applicationIOScope,
+ activeIdentity = sovereignWalletViewModel.activeIdentity,
+ )
+ }
val databaseMarmotRepository = remember {
DatabaseMarmotRepository(
database = auxDatabaseManager.auxDatabase,
@@ -271,6 +287,7 @@ fun GizaNavHost(
scope = applicationIOScope,
confederationRepository = databaseConfederationRepository,
groupDmRepository = databaseGroupDmRepository,
+ groupInboxRepository = databaseGroupInboxRepository,
)
)
@@ -1370,6 +1387,15 @@ fun GizaNavHost(
onNavigateBack = { navController.popBackStack() }
)
}
+ composable { backStackEntry ->
+ val route = backStackEntry.toRoute()
+
+ ConfederationSigningScreen(
+ attemptId = route.attemptId,
+ confederationRepository = databaseConfederationRepository,
+ onNavigateBack = { navController.popBackStack() }
+ )
+ }
composable { backStackEntry ->
val route = backStackEntry.toRoute()
@@ -1416,6 +1442,44 @@ fun GizaNavHost(
}
)
}
+ // The group's inbox (docs/group-inbox.md, Phase 7).
+ composable { backStackEntry ->
+ val route = backStackEntry.toRoute()
+ GroupInboxScreen(
+ activeUserPublicKey = route.activeUserPublicKey,
+ chatRoomId = route.chatRoomId,
+ relayHint = route.relayHint,
+ chatRepository = databaseChatRepository,
+ inboxRepository = databaseGroupInboxRepository,
+ onNavigateToRoute = { actionRoute -> navController.navigate(route = actionRoute) },
+ onNavigateBack = { navController.popBackStack() },
+ )
+ }
+ composable { backStackEntry ->
+ val route = backStackEntry.toRoute()
+ GroupInboxConversationScreen(
+ activeUserPublicKey = route.activeUserPublicKey,
+ chatRoomId = route.chatRoomId,
+ relayHint = route.relayHint,
+ conversationId = route.conversationId,
+ chatRepository = databaseChatRepository,
+ inboxRepository = databaseGroupInboxRepository,
+ onNavigateToRoute = { actionRoute -> navController.navigate(route = actionRoute) },
+ onNavigateBack = { navController.popBackStack() },
+ )
+ }
+ composable { backStackEntry ->
+ val route = backStackEntry.toRoute()
+ GroupInboxSettingsScreen(
+ activeUserPublicKey = route.activeUserPublicKey,
+ chatRoomId = route.chatRoomId,
+ relayHint = route.relayHint,
+ chatRepository = databaseChatRepository,
+ inboxRepository = databaseGroupInboxRepository,
+ onNavigateToRoute = { actionRoute -> navController.navigate(route = actionRoute) },
+ onNavigateBack = { navController.popBackStack() },
+ )
+ }
composable { backStackEntry ->
val route = backStackEntry.toRoute()
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/routes/ConfederationSigningRoute.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/routes/ConfederationSigningRoute.kt
new file mode 100644
index 00000000..82b3c028
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/routes/ConfederationSigningRoute.kt
@@ -0,0 +1,10 @@
+package mobi.giza.compose.ui.composable.navigation.routes
+
+import kotlinx.serialization.Serializable
+
+/** One attempt by a confederation to sign an event. docs/confederation.md, Phase 15. */
+@Serializable
+data class ConfederationSigningRoute(
+ val activeUserPublicKey: String,
+ val attemptId: String,
+): Route()
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/routes/GroupInboxRoute.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/routes/GroupInboxRoute.kt
new file mode 100644
index 00000000..009f732a
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/routes/GroupInboxRoute.kt
@@ -0,0 +1,31 @@
+package mobi.giza.compose.ui.composable.navigation.routes
+
+import kotlinx.serialization.Serializable
+
+/** The group's inbox: its conversations, on an admin's device. docs/group-inbox.md, Phase 7. */
+@Serializable
+data class GroupInboxRoute(
+ val activeUserPublicKey: String,
+ val chatRoomId: String,
+ val relayHint: String?
+): Route()
+
+/** One conversation in the group's inbox, and the way to reply to it. docs/group-inbox.md. */
+@Serializable
+data class GroupInboxConversationRoute(
+ val activeUserPublicKey: String,
+ val chatRoomId: String,
+ val relayHint: String?,
+ val conversationId: String,
+): Route()
+
+/**
+ * The group's inbox key: setting one up, the ceremony that makes it, what the group announced,
+ * and rotating it. docs/group-inbox.md.
+ */
+@Serializable
+data class GroupInboxSettingsRoute(
+ val activeUserPublicKey: String,
+ val chatRoomId: String,
+ val relayHint: String?
+): Route()
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/chat/ChatTranscript.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/chat/ChatTranscript.kt
index a0f3aa52..3bdbb693 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/chat/ChatTranscript.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/chat/ChatTranscript.kt
@@ -123,6 +123,8 @@ fun ChatTranscript(
* and cannot say which one it meant.
*/
onOpenSigning: (sessionId: String?) -> Unit,
+ /** Opens a confederation's request to sign: docs/confederation.md, Phase 15. */
+ onOpenConfederationSigning: (attemptId: String) -> Unit = {},
/** Opens the room's proposals, all of them, whatever their state. */
onOpenProposals: () -> Unit,
) {
@@ -375,6 +377,21 @@ fun ChatTranscript(
// settled because it reports rather than asks -- a
// quorum has already signed by the time this line
// exists. It leads nowhere.
+ // A request for the confederation to sign: it opens, since a
+ // member answers it there. docs/confederation.md, Phase 15.
+ if (localChatMessage.chatMessage.messageType == ChatMessage.TYPE_CONFEDERATION_SIGNING_PROPOSED) {
+ RitualNotice(
+ localChatMessage = localChatMessage,
+ isAnswered = false,
+ isSettled = true,
+ onClick = {
+ localChatMessage.chatMessage.frostSigningSessionId?.let(onOpenConfederationSigning)
+ },
+ opens = null,
+ )
+ return@items
+ }
+
if (localChatMessage.chatMessage.messageType in ChatMessage.GROUP_IDENTITY_TYPES) {
RitualNotice(
localChatMessage = localChatMessage,
@@ -897,6 +914,8 @@ private fun RitualNotice(
ChatMessage.TYPE_CONFEDERATION_CEREMONY_COMPLETE -> Icons.Default.CheckCircle
ChatMessage.TYPE_CONFEDERATION_CEREMONY_FAILED -> Icons.Default.ErrorOutline
ChatMessage.TYPE_CONFEDERATION_FORMED -> Icons.Default.Hub
+ ChatMessage.TYPE_CONFEDERATION_SIGNING_PROPOSED -> Icons.Default.Draw
+ ChatMessage.TYPE_CONFEDERATION_SIGNING_FAILED -> Icons.Default.ErrorOutline
else -> Icons.Default.PanTool
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/AddGroupPostViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/AddGroupPostViewModel.kt
index a696c125..7ae9b3fd 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/AddGroupPostViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/AddGroupPostViewModel.kt
@@ -51,6 +51,10 @@ class AddGroupPostViewModel(
val isActionPending: MutableState = mutableStateOf(false)
+ /** Whether this room is a confederation's, whose statements the confederation signs. Read at load. */
+ var isConfederation: Boolean = false
+ private set
+
fun initiateAddGroupPost() {
viewModelScope.launch(Dispatchers.IO) {
val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId)
@@ -64,7 +68,8 @@ class AddGroupPostViewModel(
// The same condition the group detail screen gates the entry
// point on.
canSign = GroupStatementCapability.roomIsOpen(localChatRoom) &&
- frostSigningRepository.canSign(chatRoomId),
+ (frostSigningRepository.canSign(chatRoomId) ||
+ chatRepository.canSignAsConfederation(chatRoomId).also { isConfederation = it }),
)
}
}
@@ -107,20 +112,26 @@ class AddGroupPostViewModel(
viewModelScope.launch(Dispatchers.IO) {
val session = runCatching {
- frostSigningRepository.proposeSigning(
- localChatRoom = localChatRoom,
- userPublicKey = activeUserPublicKey,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- )
+ // A confederation's room signs through the confederation, not a FROST
+ // key: docs/confederation.md, Phase 15.
+ if (isConfederation) {
+ chatRepository.proposeAsConfederation(localChatRoom, template.kind, template.tags, template.content)
+ } else {
+ frostSigningRepository.proposeSigning(
+ localChatRoom = localChatRoom,
+ userPublicKey = activeUserPublicKey,
+ kind = template.kind,
+ tags = template.tags,
+ content = template.content,
+ )?.id
+ }
}.onFailure { error ->
logger.e("Failed to propose a post for $chatRoomId", error)
}.getOrNull()
viewModelScope.launch(Dispatchers.Main) {
if (session != null) {
- onSuccess.invoke(session.id)
+ onSuccess.invoke(session)
} else {
onFailure.invoke()
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/BroadcastGroupSignedEventViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/BroadcastGroupSignedEventViewModel.kt
index 3ef5d611..fccf2892 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/BroadcastGroupSignedEventViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/BroadcastGroupSignedEventViewModel.kt
@@ -32,6 +32,7 @@ import mobi.giza.compose.exceptions.NostrPublishException
import mobi.giza.compose.network.dto.RelayDTO
import mobi.giza.compose.network.relays.EventPublishTransport
import mobi.giza.compose.nostr.confederation.ConfederationKinds
+import mobi.giza.compose.nostr.inbox.InboxAnnouncement
import mobi.giza.compose.network.relays.NostrPublishResult
import mobi.giza.compose.network.relays.RelayPool
import mobi.giza.compose.network.sockets.NostrIncomingMessage
@@ -298,9 +299,11 @@ class BroadcastGroupSignedEventViewModel(
/**
* The kinds this screen will put on a relay: the group's profile and posts, and its
* confederation events, which a member sends again by hand when the device that
- * signed for them never got them out (docs/confederation.md, D9).
+ * signed for them never got them out (docs/confederation.md, D9), and its inbox's key
+ * and relays, for the same reason (docs/group-inbox.md, D7).
*/
- val BROADCASTABLE_KINDS: Set = setOf(MetadataEvent.KIND, TextNoteEvent.KIND, mobi.giza.compose.managers.GroupDmRelays.KIND) + ConfederationKinds.ALL
+ val BROADCASTABLE_KINDS: Set = setOf(MetadataEvent.KIND, TextNoteEvent.KIND) + ConfederationKinds.ALL +
+ setOf(InboxAnnouncement.KEY_KIND, InboxAnnouncement.RELAYS_KIND)
/**
* Sends [signedEvent] to [targets] and says what each relay answered.
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt
index 96f22602..f71ca546 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt
@@ -133,10 +133,12 @@ class ChatRoomDetailViewModel(
groupNostrProfile = chatRepository.groupNostrProfile(chatRoomId),
groupPosts = chatRepository.groupPosts(chatRoomId),
confederationProposalCount = chatRepository.confederationProposalCount(chatRoomId),
+ inbox = chatRepository.inboxSummary(localChatRoom),
confederationName = chatRepository.confederationOfRoom(chatRoomId),
groupDmRow = runCatching { chatRepository.groupDmRow(chatRoomId, localChatRoom.chatRoom.userPublicKey) }
.onFailure { if (it is CancellationException) throw it else logger.w(throwable = it) { "Couldn't read $chatRoomId's messages row" } }
.getOrNull(),
+ canSignAsConfederation = chatRepository.canSignAsConfederation(chatRoomId),
canProposeAsGroup = canSign && roomIsOpen,
subgroupsNeedAWallet = canSign && subgroupsNeedAWallet,
canGovern = canGovern,
@@ -513,6 +515,17 @@ class ChatRoomDetailViewModel(
}
+ /** Proposes the confederation's charter, in its own room. docs/confederation.md, Phase 15. */
+ fun proposeCharter(onSuccess: (attemptId: String) -> Unit, onFailure: () -> Unit) {
+ val loaded = chatRoomDetailUIState as? ChatRoomDetailUIState.Loaded ?: return
+ viewModelScope.launch(Dispatchers.IO) {
+ val attemptId = runCatching { chatRepository.proposeCharter(loaded.localChatRoom) }
+ .onFailure { logger.e("Could not propose the charter for $chatRoomId", it) }
+ .getOrNull()
+ viewModelScope.launch(Dispatchers.Main) { if (attemptId != null) onSuccess(attemptId) else onFailure() }
+ }
+ }
+
companion object {
private const val TAG = "ChatRoomDetailViewModel"
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ConfederationSigningViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ConfederationSigningViewModel.kt
new file mode 100644
index 00000000..d299ac6e
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ConfederationSigningViewModel.kt
@@ -0,0 +1,85 @@
+package mobi.giza.compose.ui.view.model
+
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.ViewModelProvider
+import androidx.lifecycle.viewModelScope
+import androidx.lifecycle.viewmodel.initializer
+import androidx.lifecycle.viewmodel.viewModelFactory
+import co.touchlab.kermit.Logger
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.IO
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.asStateFlow
+import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.flow.update
+import kotlinx.coroutines.launch
+import mobi.giza.compose.nostr.confederation.ConfederationRitualEvents
+import mobi.giza.compose.nostr.confederation.ConfederationSigningEvents
+import mobi.giza.compose.repository.ConfederationRepository
+import mobi.giza.compose.ui.view.state.ConfederationSigningUIState
+
+/** One attempt by a confederation to sign an event, watched as answers arrive (docs/confederation.md, Phase 15). */
+class ConfederationSigningViewModel(
+ val attemptId: String,
+ initialConfederationSigningUIState: ConfederationSigningUIState,
+ val confederationRepository: ConfederationRepository,
+) : ViewModel() {
+ private val logger = Logger.withTag("ConfederationSigningViewModel")
+ private val state = MutableStateFlow(initialConfederationSigningUIState)
+ val uiState: StateFlow = state.asStateFlow()
+
+ fun initiate() {
+ viewModelScope.launch(Dispatchers.IO) {
+ combine(
+ confederationRepository.observeSigningAttempt(attemptId),
+ confederationRepository.observeSigningMessages(attemptId),
+ ) { attempt, messages -> attempt to messages }.collect { (attempt, messages) ->
+ if (attempt == null) {
+ state.value = ConfederationSigningUIState.NotHeld
+ return@collect
+ }
+ val plan = confederationRepository.confederationPlan(attempt.confederationId)
+ val event = Event.fromJsonOrNull(attempt.signedEventJson ?: attempt.eventJson) ?: return@collect
+ val said = messages.filter { it.kind == ConfederationSigningEvents.AVAILABILITY }.associate { message ->
+ message.senderPublicKey to (ConfederationRitualEvents.decodeByGroup(message.payload)?.values?.all { it == ConfederationSigningEvents.YES } == true)
+ }
+ val answers = plan?.people.orEmpty().map { person -> confederationRepository.nameOf(person) to said[person] }
+ val acting = (state.value as? ConfederationSigningUIState.Loaded)?.isActing == true
+ state.value = ConfederationSigningUIState.Loaded(
+ attempt = attempt,
+ event = event,
+ answers = answers,
+ roleCount = plan?.seats?.size ?: 0,
+ groupCount = plan?.groups?.size ?: 0,
+ isActing = acting,
+ )
+ }
+ }
+ }
+
+ fun approve() = act { confederationRepository.approveSigning(attemptId) }
+
+ fun decline() = act { confederationRepository.declineSigning(attemptId) }
+
+ private fun act(action: suspend () -> Unit) {
+ val loaded = state.value as? ConfederationSigningUIState.Loaded ?: return
+ if (loaded.isActing) return
+ state.update { (it as? ConfederationSigningUIState.Loaded)?.copy(isActing = true) ?: it }
+ viewModelScope.launch(Dispatchers.IO) {
+ runCatching { action() }.onFailure { logger.e("Signing action failed", it) }
+ state.update { (it as? ConfederationSigningUIState.Loaded)?.copy(isActing = false) ?: it }
+ }
+ }
+
+ companion object {
+ fun factory(
+ attemptId: String,
+ initialConfederationSigningUIState: ConfederationSigningUIState = ConfederationSigningUIState.Loading,
+ confederationRepository: ConfederationRepository,
+ ): ViewModelProvider.Factory = viewModelFactory {
+ initializer { ConfederationSigningViewModel(attemptId, initialConfederationSigningUIState, confederationRepository) }
+ }
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/EditGroupNostrProfileViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/EditGroupNostrProfileViewModel.kt
index fef838bc..15395d18 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/EditGroupNostrProfileViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/EditGroupNostrProfileViewModel.kt
@@ -48,6 +48,10 @@ class EditGroupNostrProfileViewModel(
val isActionPending: MutableState = mutableStateOf(false)
+ /** Whether this room is a confederation's, whose statements the confederation signs. Read at load. */
+ var isConfederation: Boolean = false
+ private set
+
fun initiateEditGroupNostrProfile() {
viewModelScope.launch(Dispatchers.IO) {
val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId)
@@ -61,7 +65,8 @@ class EditGroupNostrProfileViewModel(
// The same condition the group detail screen gates the entry
// point on.
canSign = GroupStatementCapability.roomIsOpen(localChatRoom) &&
- frostSigningRepository.canSign(chatRoomId),
+ (frostSigningRepository.canSign(chatRoomId) ||
+ chatRepository.canSignAsConfederation(chatRoomId).also { isConfederation = it }),
)
}
}
@@ -108,20 +113,26 @@ class EditGroupNostrProfileViewModel(
viewModelScope.launch(Dispatchers.IO) {
val session = runCatching {
- frostSigningRepository.proposeSigning(
- localChatRoom = localChatRoom,
- userPublicKey = activeUserPublicKey,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- )
+ // A confederation's room signs through the confederation, not a FROST
+ // key: docs/confederation.md, Phase 15.
+ if (isConfederation) {
+ chatRepository.proposeAsConfederation(localChatRoom, template.kind, template.tags, template.content)
+ } else {
+ frostSigningRepository.proposeSigning(
+ localChatRoom = localChatRoom,
+ userPublicKey = activeUserPublicKey,
+ kind = template.kind,
+ tags = template.tags,
+ content = template.content,
+ )?.id
+ }
}.onFailure { error ->
logger.e("Failed to propose a nostr profile for $chatRoomId", error)
}.getOrNull()
viewModelScope.launch(Dispatchers.Main) {
if (session != null) {
- onSuccess.invoke(session.id)
+ onSuccess.invoke(session)
} else {
onFailure.invoke()
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/FrostSigningViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/FrostSigningViewModel.kt
index ba42a39f..76835ff5 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/FrostSigningViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/FrostSigningViewModel.kt
@@ -81,7 +81,7 @@ class FrostSigningViewModel(
) { session, messages, items, holders -> Observed(session, messages, items, holders) }
.collect { (session, messages, items, holders) ->
if (notes == null && items.isNotEmpty()) {
- notes = frostSigningRepository.confederationNotes(chatRoomId, sessionId, proposedEvents(items))
+ notes = frostSigningRepository.proposalNotes(chatRoomId, sessionId, proposedEvents(items))
}
// Read per emission rather than derived from `messages`: who
// the session is waiting on is the manager's rule, and it is
@@ -107,7 +107,7 @@ class FrostSigningViewModel(
.map { it.signerPublicKey }
.toSet(),
silent = owed,
- confederationNotes = notes.orEmpty(),
+ proposalNotes = notes.orEmpty(),
)
}
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupInboxViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupInboxViewModel.kt
new file mode 100644
index 00000000..78349c1c
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupInboxViewModel.kt
@@ -0,0 +1,191 @@
+package mobi.giza.compose.ui.view.model
+
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.setValue
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.ViewModelProvider
+import androidx.lifecycle.viewModelScope
+import androidx.lifecycle.viewmodel.initializer
+import androidx.lifecycle.viewmodel.viewModelFactory
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.launch
+import mobi.giza.compose.repository.ChatRepository
+import mobi.giza.compose.repository.GroupInboxRepository
+import mobi.giza.compose.ui.view.state.GroupInboxConversationUIState
+import mobi.giza.compose.ui.view.state.GroupInboxSettingsUIState
+import mobi.giza.compose.ui.view.state.GroupInboxUIState
+
+/**
+ * The group's inbox, watched rather than read once: mail arrives while the screen is open, and
+ * the point of the screen is to see it (docs/group-inbox.md, Phase 7).
+ */
+class GroupInboxViewModel(
+ val chatRoomId: String,
+ initialUIState: GroupInboxUIState,
+ val chatRepository: ChatRepository,
+ val inboxRepository: GroupInboxRepository,
+): ViewModel() {
+ var uiState: GroupInboxUIState by mutableStateOf(initialUIState)
+ private set
+
+ fun initiate() {
+ viewModelScope.launch(Dispatchers.IO) {
+ val room = chatRepository.getChatRoomByIdentifier(chatRoomId) ?: run {
+ uiState = GroupInboxUIState.Error("Couldn't find the group")
+ return@launch
+ }
+ combine(
+ inboxRepository.observeConversations(chatRoomId),
+ inboxRepository.observeUnopenedCount(chatRoomId),
+ inboxRepository.observeStatus(room, room.chatRoom.userPublicKey),
+ ) { conversations, unopenable, status ->
+ GroupInboxUIState.Loaded(room, conversations, unopenable, status)
+ }.collect { uiState = it }
+ }
+ }
+
+ companion object {
+ fun factory(
+ chatRoomId: String,
+ initialUIState: GroupInboxUIState = GroupInboxUIState.Loading,
+ chatRepository: ChatRepository,
+ inboxRepository: GroupInboxRepository,
+ ): ViewModelProvider.Factory = viewModelFactory {
+ initializer { GroupInboxViewModel(chatRoomId, initialUIState, chatRepository, inboxRepository) }
+ }
+ }
+}
+
+/** One conversation in the group's inbox, marked read as it is shown (docs/group-inbox.md, Phase 7). */
+class GroupInboxConversationViewModel(
+ val chatRoomId: String,
+ val conversationId: String,
+ initialUIState: GroupInboxConversationUIState,
+ val chatRepository: ChatRepository,
+ val inboxRepository: GroupInboxRepository,
+): ViewModel() {
+ var uiState: GroupInboxConversationUIState by mutableStateOf(initialUIState)
+ private set
+
+ fun initiate() {
+ viewModelScope.launch(Dispatchers.IO) {
+ val room = chatRepository.getChatRoomByIdentifier(chatRoomId) ?: run {
+ uiState = GroupInboxConversationUIState.Error("Couldn't find the group")
+ return@launch
+ }
+ inboxRepository.observeConversation(chatRoomId, conversationId).collect { messages ->
+ val participants = messages.lastOrNull()?.participantList().orEmpty()
+ val names = inboxRepository.namesOf(participants)
+ val unsent = inboxRepository.unsentReplies(chatRoomId)
+ val withoutKey = inboxRepository.withoutAnnouncedKey(participants)
+ uiState = GroupInboxConversationUIState.Loaded(
+ localChatRoom = room,
+ names = participants.map { names[it] ?: it.take(8) },
+ withoutKey = withoutKey.map { names[it] ?: it.take(8) },
+ proposing = (uiState as? GroupInboxConversationUIState.Loaded)?.proposing ?: false,
+ lines = messages.map { message ->
+ GroupInboxConversationUIState.Line(
+ rumorId = message.rumorId,
+ text = Event.fromJsonOrNull(message.rumorJson)?.content.orEmpty(),
+ createdAt = message.createdAt,
+ outgoing = message.outgoing,
+ senderName = if (message.outgoing) "" else names[message.senderPublicKey] ?: message.senderPublicKey.take(8),
+ unsentSessionId = message.signingSessionId?.takeIf { it in unsent },
+ )
+ },
+ )
+ if (messages.any { !it.outgoing && it.readAt == null }) inboxRepository.markRead(chatRoomId, conversationId)
+ }
+ }
+ }
+
+ /**
+ * Asks the group to sign [text] as a reply. [onDone] gets the signing session's id, or null
+ * when it could not be asked.
+ */
+ fun propose(text: String, onDone: (String?) -> Unit) {
+ val loaded = uiState as? GroupInboxConversationUIState.Loaded ?: return
+ if (loaded.proposing || text.isBlank()) return
+ uiState = loaded.copy(proposing = true)
+ viewModelScope.launch(Dispatchers.IO) {
+ val session = runCatching { inboxRepository.proposeReply(loaded.localChatRoom, conversationId, text.trim()) }.getOrNull()
+ (uiState as? GroupInboxConversationUIState.Loaded)?.let { uiState = it.copy(proposing = false) }
+ onDone(session)
+ }
+ }
+
+ fun sendAgain(sessionId: String, onDone: (Boolean) -> Unit) {
+ viewModelScope.launch(Dispatchers.IO) { onDone(inboxRepository.sendAgain(sessionId)) }
+ }
+
+ companion object {
+ fun factory(
+ chatRoomId: String,
+ conversationId: String,
+ initialUIState: GroupInboxConversationUIState = GroupInboxConversationUIState.Loading,
+ chatRepository: ChatRepository,
+ inboxRepository: GroupInboxRepository,
+ ): ViewModelProvider.Factory = viewModelFactory {
+ initializer { GroupInboxConversationViewModel(chatRoomId, conversationId, initialUIState, chatRepository, inboxRepository) }
+ }
+ }
+}
+
+/** The group's inbox key: setting one up, its ceremony, rotating it (docs/group-inbox.md, Phase 7). */
+class GroupInboxSettingsViewModel(
+ val chatRoomId: String,
+ initialUIState: GroupInboxSettingsUIState,
+ val chatRepository: ChatRepository,
+ val inboxRepository: GroupInboxRepository,
+): ViewModel() {
+ var uiState: GroupInboxSettingsUIState by mutableStateOf(initialUIState)
+ private set
+
+ fun initiate() {
+ viewModelScope.launch(Dispatchers.IO) {
+ val room = chatRepository.getChatRoomByIdentifier(chatRoomId) ?: run {
+ uiState = GroupInboxSettingsUIState.Error("Couldn't find the group")
+ return@launch
+ }
+ inboxRepository.observeStatus(room, room.chatRoom.userPublicKey).collect { status ->
+ val busy = (uiState as? GroupInboxSettingsUIState.Loaded)?.busy ?: false
+ uiState = GroupInboxSettingsUIState.Loaded(room, status, busy)
+ }
+ }
+ }
+
+ private fun act(onDone: (String?) -> Unit, action: suspend (GroupInboxSettingsUIState.Loaded) -> Unit) {
+ val loaded = uiState as? GroupInboxSettingsUIState.Loaded ?: return
+ if (loaded.busy) return
+ uiState = loaded.copy(busy = true)
+ viewModelScope.launch(Dispatchers.IO) {
+ val failure = runCatching { action(loaded) }.exceptionOrNull()
+ (uiState as? GroupInboxSettingsUIState.Loaded)?.let { uiState = it.copy(busy = false) }
+ onDone(failure?.let { it.message ?: it::class.simpleName.orEmpty() })
+ }
+ }
+
+ /** Starts the first ceremony. [onDone] gets null, or why it could not. */
+ fun setUp(relays: List, onDone: (String?) -> Unit) =
+ act(onDone) { inboxRepository.setUp(it.localChatRoom, relays) }
+
+ fun rotate(onDone: (String?) -> Unit) = act(onDone) { inboxRepository.rotate(it.localChatRoom) }
+
+ fun abandon(ceremonyId: String, onDone: (String?) -> Unit) =
+ act(onDone) { inboxRepository.abandon(it.localChatRoom, ceremonyId) }
+
+ companion object {
+ fun factory(
+ chatRoomId: String,
+ initialUIState: GroupInboxSettingsUIState = GroupInboxSettingsUIState.Loading,
+ chatRepository: ChatRepository,
+ inboxRepository: GroupInboxRepository,
+ ): ViewModelProvider.Factory = viewModelFactory {
+ initializer { GroupInboxSettingsViewModel(chatRoomId, initialUIState, chatRepository, inboxRepository) }
+ }
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupNostrProfileViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupNostrProfileViewModel.kt
index b7a0ed79..f23b1e7e 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupNostrProfileViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupNostrProfileViewModel.kt
@@ -44,7 +44,7 @@ class GroupNostrProfileViewModel(
localChatRoom = localChatRoom,
groupNostrProfile = chatRepository.groupNostrProfile(chatRoomId),
canSign = GroupStatementCapability.roomIsOpen(localChatRoom) &&
- chatRepository.canSign(chatRoomId),
+ (chatRepository.canSign(chatRoomId) || chatRepository.canSignAsConfederation(chatRoomId)),
)
}
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupPostsViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupPostsViewModel.kt
index 7e7a9c29..164582a7 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupPostsViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupPostsViewModel.kt
@@ -40,7 +40,7 @@ class GroupPostsViewModel(
groupPosts = chatRepository.groupPosts(chatRoomId),
groupNostrProfile = chatRepository.groupNostrProfile(chatRoomId),
canSign = GroupStatementCapability.roomIsOpen(localChatRoom) &&
- chatRepository.canSign(chatRoomId),
+ (chatRepository.canSign(chatRoomId) || chatRepository.canSignAsConfederation(chatRoomId)),
)
}
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SynchronizationViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SynchronizationViewModel.kt
index b40c5610..443b67f4 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SynchronizationViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/SynchronizationViewModel.kt
@@ -61,6 +61,8 @@ import mobi.giza.compose.nostr.SignInSync
import kotlinx.coroutines.sync.withPermit
import mobi.giza.compose.ExperimentalFeatures
import mobi.giza.compose.managers.ConfederationPublisher
+import mobi.giza.compose.managers.GroupInboxPublisher
+import mobi.giza.compose.repository.GroupInboxRepository
import mobi.giza.compose.repository.ConfederationRepository
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
@@ -73,6 +75,7 @@ class SynchronizationViewModel(
val scope: CoroutineScope,
val confederationRepository: ConfederationRepository? = null,
val groupDmRepository: mobi.giza.compose.repository.GroupDmRepository? = null,
+ val groupInboxRepository: GroupInboxRepository? = null,
): ViewModel() {
val relaysSocketManager = RelaysSocketManager(
@@ -94,6 +97,7 @@ class SynchronizationViewModel(
isForeground = AppLifecycle.isForeground,
confederationRepository = confederationRepository,
groupDmRepository = groupDmRepository,
+ groupInboxRepository = groupInboxRepository,
)
/** Sends the confederation events this device signed for (docs/confederation.md, D9). */
@@ -106,6 +110,11 @@ class SynchronizationViewModel(
mobi.giza.compose.managers.GroupDmPublisher(repository = it, transport = relaysSocketManager)
}
+ /** Sends what this device owes relays for its groups' inboxes (docs/group-inbox.md, D7). */
+ private val groupInboxPublisher = groupInboxRepository?.let {
+ GroupInboxPublisher(repository = it, transport = relaysSocketManager)
+ }
+
companion object {
private const val TAG = "SynchronizationViewModel"
@@ -158,6 +167,7 @@ class SynchronizationViewModel(
scope: CoroutineScope,
confederationRepository: ConfederationRepository? = null,
groupDmRepository: mobi.giza.compose.repository.GroupDmRepository? = null,
+ groupInboxRepository: GroupInboxRepository? = null,
): ViewModelProvider.Factory = viewModelFactory {
initializer {
SynchronizationViewModel(
@@ -168,6 +178,7 @@ class SynchronizationViewModel(
scope = scope,
confederationRepository = confederationRepository,
groupDmRepository = groupDmRepository,
+ groupInboxRepository = groupInboxRepository,
)
}
}
@@ -303,6 +314,17 @@ class SynchronizationViewModel(
}
}
}
+ // The group inbox's announcements and replies this device
+ // owes relays. docs/group-inbox.md, D7 and D10.
+ groupInboxPublisher?.takeIf { ExperimentalFeatures.groupInbox }?.let { publisher ->
+ launch(Dispatchers.IO) {
+ runCatching { publisher.run() }
+ .onFailure {
+ if (it is CancellationException) throw it
+ logger.e("Publishing inbox events stopped", it)
+ }
+ }
+ }
// A key ceremony this profile opened, taken from a key to a
// working room without anybody pressing a button: the key
// state proposed, a subgroup's certificate asked for, the
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomDetailUIState.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomDetailUIState.kt
index c4961a65..b833998d 100755
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomDetailUIState.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomDetailUIState.kt
@@ -74,10 +74,14 @@ sealed interface ChatRoomDetailUIState {
val groupPosts: List = emptyList(),
/** How many confederation proposals naming this group this device holds. docs/confederation.md. */
val confederationProposalCount: Int = 0,
+ /** The group's inbox, for its row; null where this device has nothing of it to show. */
+ val inbox: InboxRowSummary? = null,
/** The confederation whose room this is, by name: its membership is fixed until it can sign. */
val confederationName: String? = null,
/** What the group's direct messages show here, or nothing. docs/group-threshold-ecdh.md. */
val groupDmRow: GroupDmRow? = null,
+ /** Whether this device holds a role in that confederation, and so can propose what it signs. */
+ val canSignAsConfederation: Boolean = false,
/**
* Whether this device could put a profile or a post to the group's quorum:
* a Marmot room it has not left, not disbanded, where it holds a share of
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ConfederationSigningUIState.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ConfederationSigningUIState.kt
new file mode 100644
index 00000000..cdc890ba
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ConfederationSigningUIState.kt
@@ -0,0 +1,21 @@
+package mobi.giza.compose.ui.view.state
+
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import mobi.giza.compose.database.model.ConfederationSigningAttempt
+
+/** One attempt by a confederation to sign an event (docs/confederation.md, Phase 15). */
+sealed interface ConfederationSigningUIState {
+ data class Loaded(
+ val attempt: ConfederationSigningAttempt,
+ val event: Event,
+ /** Every role holder by name, with their answer: true, false, or null while they have not said. */
+ val answers: List>,
+ val roleCount: Int,
+ val groupCount: Int,
+ val isActing: Boolean = false,
+ ) : ConfederationSigningUIState
+
+ data object NotHeld : ConfederationSigningUIState
+
+ data object Loading : ConfederationSigningUIState
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/FrostSigningUIState.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/FrostSigningUIState.kt
index 4244db04..f9d0c3e8 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/FrostSigningUIState.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/FrostSigningUIState.kt
@@ -24,8 +24,12 @@ sealed interface FrostSigningUIState {
*/
val items: List = emptyList(),
- /** For a confederation event: who it names, what it discloses, what could not be checked. docs/confederation.md, D6. */
- val confederationNotes: List = emptyList(),
+ /**
+ * What the screen says beside the events: for a confederation event, who it names, what it
+ * discloses and what could not be checked (docs/confederation.md, D6); for a reply from the
+ * group's inbox, its words and recipients (docs/group-inbox.md, D12).
+ */
+ val proposalNotes: List = emptyList(),
/** Who has offered a nonce, so the screen can name who it is waiting on. */
val offeredNonce: Set = emptySet(),
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/GroupInboxUIState.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/GroupInboxUIState.kt
new file mode 100644
index 00000000..ba226b95
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/GroupInboxUIState.kt
@@ -0,0 +1,60 @@
+package mobi.giza.compose.ui.view.state
+
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.repository.GroupInboxRepository
+
+/** The group's inbox screen (docs/group-inbox.md, Phase 7). */
+sealed interface GroupInboxUIState {
+ data class Loaded(
+ val localChatRoom: LocalChatRoom,
+ val conversations: List,
+ /** Wraps addressed to the group that no key this device holds opens (D8). */
+ val unopenable: Int,
+ val status: GroupInboxRepository.Status,
+ ): GroupInboxUIState
+
+ data class Error(val message: String): GroupInboxUIState
+
+ data object Loading: GroupInboxUIState
+}
+
+/** One conversation in the group's inbox (docs/group-inbox.md, Phase 7 and 8). */
+sealed interface GroupInboxConversationUIState {
+ data class Line(
+ val rumorId: String,
+ val text: String,
+ val createdAt: Long,
+ val outgoing: Boolean,
+ val senderName: String,
+ /** For a reply this device proposed: its signing session, while no relay has taken it. */
+ val unsentSessionId: String? = null,
+ )
+
+ data class Loaded(
+ val localChatRoom: LocalChatRoom,
+ val names: List,
+ val lines: List,
+ /** Recipients who have announced no inbox key (D13): their app may not open the reply. */
+ val withoutKey: List = emptyList(),
+ /** Whether a reply this screen asked for is still on its way to the signing session. */
+ val proposing: Boolean = false,
+ ): GroupInboxConversationUIState
+
+ data class Error(val message: String): GroupInboxConversationUIState
+
+ data object Loading: GroupInboxConversationUIState
+}
+
+/** The group's inbox key and its ceremony (docs/group-inbox.md, Phase 7). */
+sealed interface GroupInboxSettingsUIState {
+ data class Loaded(
+ val localChatRoom: LocalChatRoom,
+ val status: GroupInboxRepository.Status,
+ /** Whether a request this screen made is still on its way. */
+ val busy: Boolean = false,
+ ): GroupInboxSettingsUIState
+
+ data class Error(val message: String): GroupInboxSettingsUIState
+
+ data object Loading: GroupInboxSettingsUIState
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/InboxRowSummary.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/InboxRowSummary.kt
new file mode 100644
index 00000000..74e7854a
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/InboxRowSummary.kt
@@ -0,0 +1,13 @@
+package mobi.giza.compose.ui.view.state
+
+/**
+ * The group's inbox as its row on the group's screen shows it (docs/group-inbox.md, Phase 7).
+ * Only on a device that holds the inbox key, has a ceremony running, or could start one: a
+ * member who is not an admin sees nothing of the inbox (D9).
+ */
+data class InboxRowSummary(
+ val holdsKey: Boolean,
+ val unread: Int,
+ val ceremonyRunning: Boolean,
+ val canSetUp: Boolean,
+)
diff --git a/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/InboxKeyPremiseTest.kt b/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/InboxKeyPremiseTest.kt
new file mode 100644
index 00000000..c278b4a2
--- /dev/null
+++ b/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/InboxKeyPremiseTest.kt
@@ -0,0 +1,111 @@
+package mobi.giza.compose.managers
+
+import com.vitorpamplona.quartz.nip44Encryption.Nip44v2
+import fr.acinq.bitcoin.ByteVector32
+import fr.acinq.bitcoin.ByteVector64
+import fr.acinq.bitcoin.Crypto
+import fr.acinq.bitcoin.PrivateKey
+import fr.acinq.bitcoin.PublicKey
+import fr.acinq.bitcoin.crypto.dkg.chill.ChillDKG
+import kotlin.test.Test
+import kotlin.test.assertContentEquals
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
+import kotlin.test.assertTrue
+
+/**
+ * The premise docs/group-inbox.md (D2) rests on, run against real ChillDKG: a ceremony at
+ * threshold 1 leaves every participant holding the *same* secret, and that secret is the
+ * discrete log of the ceremony's threshold public key.
+ *
+ * At `t = 1` every participant's polynomial is a constant, so every share is the sum of
+ * everyone's constants. If the library ever refuses `t = 1`, or hands out different shares,
+ * the inbox key cannot be made this way and the plan's fallback (a `t = n` ceremony and a
+ * reveal round) applies instead.
+ */
+class InboxKeyPremiseTest {
+ private val admins = listOf(
+ "1c0ffee0000000000000000000000000000000000000000000000000000000a1",
+ "2badc0de0000000000000000000000000000000000000000000000000000005b",
+ "3deadbee00000000000000000000000000000000000000000000000000000c37",
+ ).map { Admin(it.hexToBytes()) }
+
+ @Test
+ fun `a threshold-1 ceremony leaves every admin the same secret`() {
+ val outputs = ceremony(admins)
+
+ val secrets = outputs.map { assertNotNull(it.secretShare).value.toByteArray().toList() }
+ assertEquals(1, secrets.distinct().size, "the admins came out of the ceremony holding different secrets")
+ }
+
+ @Test
+ fun `that secret is the key the ceremony announces`() {
+ val outputs = ceremony(admins)
+
+ outputs.forEach { output ->
+ val secret = assertNotNull(output.secretShare)
+ assertEquals(assertNotNull(output.thresholdPublicKey), secret.publicKey())
+ }
+ }
+
+ @Test
+ fun `a NIP-44 conversation with the inbox key works whichever way round it is computed`() {
+ // The key goes in a 10044 as an x-only hex key, which drops the parity. A sender
+ // computes ECDH against the even point; the admins compute it with `e`, whatever the
+ // ceremony's key's parity was. Both land on the same x, which is all NIP-44 uses.
+ val outputs = ceremony(admins)
+ val e = assertNotNull(outputs.first().secretShare)
+ val inboxXOnly = e.publicKey().xOnly().value.toByteArray()
+
+ val sender = PrivateKey(Crypto.sha256("a stranger".encodeToByteArray()))
+ val senderXOnly = sender.publicKey().xOnly().value.toByteArray()
+
+ val nip44 = Nip44v2()
+ val fromSender = nip44.computeConversationKey(sender.value.toByteArray(), inboxXOnly)
+ val fromAdmins = nip44.computeConversationKey(e.value.toByteArray(), senderXOnly)
+ assertContentEquals(fromSender, fromAdmins)
+
+ val payload = nip44.encrypt("hello, group", fromSender).encodePayload()
+ assertEquals("hello, group", nip44.decrypt(payload, fromAdmins))
+ }
+
+ /** One ceremony, every step in host-key order, as `ChillDkgRitualOrderingTest` runs one. */
+ private fun ceremony(members: List): List {
+ val threshold = 1
+ val ordered = members.sortedBy { it.hostPublicKey.toHex() }
+ val hostPublicKeys = ordered.map { it.hostPublicKey }
+
+ val step1 = ordered.map { admin ->
+ ChillDKG.participantStep1(admin.hostSecretKey, hostPublicKeys, threshold, admin.round1Random)
+ }
+ val coordinator = ChillDKG.coordinatorStep1(step1.map { it.message }, hostPublicKeys, threshold)
+ assertTrue(coordinator.fault.isOk, "coordinator round 1 faulted")
+
+ val step2 = ordered.mapIndexed { index, admin ->
+ ChillDKG.participantStep2(admin.hostSecretKey, step1[index].state, coordinator.message, admin.round2AuxRandom)
+ .also { assertTrue(it.fault.isOk, "round 2 faulted") }
+ }
+ val certified = ChillDKG.coordinatorFinalize(
+ coordinator.state,
+ step2.map { ByteVector64(it.certEqSignature) },
+ threshold,
+ )
+ assertTrue(certified.fault.isOk, "certificate faulted")
+
+ return step2.map { result ->
+ ChillDKG.participantFinalize(result.state, certified.certificate, ordered.size, threshold)
+ .also { assertTrue(it.fault.isOk, "finalize faulted") }
+ }
+ }
+
+ private class Admin(nostrPrivateKey: ByteArray) {
+ val hostSecretKey = ChillDkgRitualManager.deriveHostSecretKey(nostrPrivateKey)
+ val hostPublicKey: PublicKey = ChillDKG.hostPublicKey(hostSecretKey)
+ val round1Random = ByteVector32(Crypto.sha256(nostrPrivateKey + 1))
+ val round2AuxRandom = ByteVector32(Crypto.sha256(nostrPrivateKey + 2))
+ }
+
+ private companion object {
+ fun String.hexToBytes(): ByteArray = chunked(2).map { it.toInt(16).toByte() }.toByteArray()
+ }
+}
diff --git a/composeApp/src/commonTest/kotlin/mobi/giza/compose/nostr/DirectMessagePeerSyncTest.kt b/composeApp/src/commonTest/kotlin/mobi/giza/compose/nostr/DirectMessagePeerSyncTest.kt
index c9bf9bba..1adf0727 100644
--- a/composeApp/src/commonTest/kotlin/mobi/giza/compose/nostr/DirectMessagePeerSyncTest.kt
+++ b/composeApp/src/commonTest/kotlin/mobi/giza/compose/nostr/DirectMessagePeerSyncTest.kt
@@ -34,7 +34,9 @@ class DirectMessagePeerSyncTest {
// Level 0: somebody is waiting on this one.
assertEquals(0, request.level)
assertEquals(
- listOf(MetadataEvent.KIND, KeyPackageEvent.KIND, DmRelayListEvent.KIND, AdvertisedRelayListEvent.KIND),
+ // And the key they read encrypted mail with, if they announced one: what a
+ // group's reply to them is sealed to (docs/group-inbox.md, D10).
+ listOf(MetadataEvent.KIND, KeyPackageEvent.KIND, DmRelayListEvent.KIND, AdvertisedRelayListEvent.KIND, 10044),
request.synchronizationFilter.kinds?.toList(),
)
assertEquals(listOf(alice), request.synchronizationFilter.authors?.toList())
diff --git a/composeApp/src/commonTest/kotlin/mobi/giza/compose/nostr/inbox/InboxWireTest.kt b/composeApp/src/commonTest/kotlin/mobi/giza/compose/nostr/inbox/InboxWireTest.kt
new file mode 100644
index 00000000..0fa5fdea
--- /dev/null
+++ b/composeApp/src/commonTest/kotlin/mobi/giza/compose/nostr/inbox/InboxWireTest.kt
@@ -0,0 +1,264 @@
+package mobi.giza.compose.nostr.inbox
+
+import com.vitorpamplona.quartz.experimental.decoupling.setup.EncryptionKeyListEvent
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
+import com.vitorpamplona.quartz.nip01Core.core.toHexKey
+import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
+import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
+import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
+import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
+import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
+import com.vitorpamplona.quartz.nip59Giftwrap.rumors.RumorAssembler
+import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealEvent
+import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
+import fr.acinq.bitcoin.Crypto
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
+import kotlin.test.assertNull
+import kotlin.test.assertTrue
+import kotlinx.coroutines.test.runTest
+
+/**
+ * The group inbox's wire, byte for byte where it matters (docs/group-inbox.md, Phase 2). The
+ * group's FROST key is stood in for by a plain key here: what is under test is the layering, and
+ * `SignedGroupKeyStateTest` shows the quorum signs a seal as the room.
+ */
+class InboxWireTest {
+ private fun secret(label: String) = Crypto.sha256(label.encodeToByteArray())
+
+ private val group = KeyPair(secret("the group's identity"))
+ private val inboxSecret = secret("the inbox key")
+ private val inboxKey = InboxWire.publicKeyOf(inboxSecret)
+
+ private val alice = KeyPair(secret("alice"))
+ private val aliceEncryptionSecret = secret("alice's encryption key")
+ private val aliceEncryptionKey = InboxWire.publicKeyOf(aliceEncryptionSecret)
+
+ private fun KeyPair.hex(): HexKey = pubKey.toHexKey()
+
+ private fun rumor(author: HexKey, to: List, text: String, createdAt: Long = 1_700_000_000L): Event =
+ RumorAssembler.assembleRumor(
+ pubKey = author,
+ ev = EventTemplate(createdAt, 14, to.map { arrayOf("p", it) }.toTypedArray(), text),
+ )
+
+ // ---- the ceremony's tags
+
+ @Test
+ fun `a proposal's tags carry the session, the generation, threshold 1 and the admins`() {
+ val session = "ab".repeat(32)
+ val admins = listOf("c".repeat(64), "b".repeat(64), "c".repeat(64))
+ val tags = InboxKeyRitualEvents.assembleTags(session, generation = 2, participants = admins)
+
+ assertEquals(session, InboxKeyRitualEvents.parseSessionId(tags))
+ assertEquals(2, InboxKeyRitualEvents.parseGeneration(tags))
+ assertEquals(1, InboxKeyRitualEvents.parseThreshold(tags))
+ assertEquals(listOf("b".repeat(64), "c".repeat(64)), InboxKeyRitualEvents.parseParticipants(tags))
+ assertNull(InboxKeyRitualEvents.parseParticipants(tags + arrayOf(arrayOf("p", "not a key"))))
+ }
+
+ // ---- the announcement
+
+ @Test
+ fun `the group's 10044 names its key alone, and quartz reads it`() {
+ val template = InboxAnnouncement.keyTemplate(inboxKey, 1_700_000_000L)
+ val signed = NostrSignerSync(group).sign(template)
+
+ assertEquals(10044, signed.kind)
+ assertEquals(inboxKey, InboxAnnouncement.groupKeyOf(signed))
+ assertEquals(inboxKey, InboxAnnouncement.announcedKeyOf(signed))
+ assertEquals(inboxKey, (signed as EncryptionKeyListEvent).encryptionKey()?.pubkey)
+ }
+
+ @Test
+ fun `a 10044 with a second key, a nonce or content is not one the group would sign`() {
+ val other = "d".repeat(64)
+ assertNull(InboxAnnouncement.groupKeyOf(10044, arrayOf(arrayOf("n", inboxKey), arrayOf("n", other)), ""))
+ assertNull(InboxAnnouncement.groupKeyOf(10044, arrayOf(arrayOf("n", inboxKey, "ab".repeat(16))), ""))
+ assertNull(InboxAnnouncement.groupKeyOf(10044, arrayOf(arrayOf("n", inboxKey)), "hello"))
+ assertNull(InboxAnnouncement.groupKeyOf(10044, arrayOf(arrayOf("n", inboxKey.uppercase())), ""))
+ // Someone else's may carry more; the first key is still theirs.
+ assertEquals(inboxKey, InboxAnnouncement.announcedKeyOf(
+ Event("a".repeat(64), alice.hex(), 1, 10044, arrayOf(arrayOf("n", inboxKey), arrayOf("n", other)), "", ""),
+ ))
+ }
+
+ @Test
+ fun `the group's 10050 lists public relays only`() {
+ val relay = assertNotNull(RelayUrlNormalizer.normalizeOrNull("wss://relay.example.com"))
+ val template = InboxAnnouncement.relaysTemplate(listOf(relay), 1_700_000_000L)
+ assertEquals(listOf(relay), InboxAnnouncement.groupRelaysOf(template.kind, template.tags, template.content))
+
+ assertNull(InboxAnnouncement.groupRelaysOf(10050, arrayOf(arrayOf("relay", "ws://relay.example.com")), ""))
+ assertNull(InboxAnnouncement.groupRelaysOf(10050, emptyArray(), ""))
+ assertNull(InboxAnnouncement.groupRelaysOf(10050, arrayOf(arrayOf("r", "wss://relay.example.com")), ""))
+ }
+
+ // ---- the seal
+
+ @Test
+ fun `a seal from the inbox key opens with the recipient's encryption key`() {
+ val reply = rumor(group.hex(), listOf(alice.hex()), "Thank you for writing")
+ val seal = NostrSignerSync(group).sign(InboxSeal.template(reply, inboxSecret, aliceEncryptionKey, 1_700_000_000L))
+
+ assertEquals(listOf(listOf("n", inboxKey)), seal.tags.map { it.toList() })
+ val opened = assertNotNull(InboxSeal.open(seal, aliceEncryptionSecret))
+ assertEquals(reply.id, opened.rumor.id)
+ assertEquals("Thank you for writing", opened.rumor.content)
+ assertEquals(inboxKey, opened.senderEncryptionKey)
+ }
+
+ @Test
+ fun `a seal to a recipient with no 10044 opens with their identity`() {
+ val reply = rumor(group.hex(), listOf(alice.hex()), "Hello")
+ val seal = NostrSignerSync(group).sign(InboxSeal.template(reply, inboxSecret, alice.hex(), 1_700_000_000L))
+
+ assertNotNull(InboxSeal.open(seal, assertNotNull(alice.privKey)))
+ assertNull(InboxSeal.open(seal, aliceEncryptionSecret), "only the key it was sealed to opens it")
+ }
+
+ @Test
+ fun `the group's own copy opens with the inbox key`() {
+ val reply = rumor(group.hex(), listOf(alice.hex()), "Hello")
+ val seal = NostrSignerSync(group).sign(InboxSeal.template(reply, inboxSecret, inboxKey, 1_700_000_000L))
+ assertEquals("Hello", assertNotNull(InboxSeal.open(seal, inboxSecret)).rumor.content)
+ }
+
+ @Test
+ fun `a seal from a sender who does not decouple opens with their identity`() {
+ // A stock NIP-17 seal, as any app writes one, to the group's announced key.
+ val message = rumor(alice.hex(), listOf(group.hex()), "Can I join?")
+ val content = InboxWire.encrypt(InboxSeal.rumorJson(message), InboxWire.conversationKey(assertNotNull(alice.privKey), inboxKey))
+ val seal = NostrSignerSync(alice).sign(1_700_000_000L, 13, emptyArray(), content)
+
+ val opened = assertNotNull(InboxSeal.open(seal, inboxSecret))
+ assertEquals("Can I join?", opened.rumor.content)
+ assertEquals(alice.hex(), opened.senderEncryptionKey)
+ }
+
+ @Test
+ fun `a seal from a sender who decoupled opens by its n tag, or by their 10044 without one`() {
+ val message = rumor(alice.hex(), listOf(group.hex()), "From my other key")
+ val content = InboxWire.encrypt(InboxSeal.rumorJson(message), InboxWire.conversationKey(aliceEncryptionSecret, inboxKey))
+
+ val tagged = NostrSignerSync(alice).sign(1_700_000_000L, 13, arrayOf(arrayOf("n", aliceEncryptionKey)), content)
+ assertEquals(aliceEncryptionKey, assertNotNull(InboxSeal.open(tagged, inboxSecret)).senderEncryptionKey)
+
+ val untagged = NostrSignerSync(alice).sign(1_700_000_000L, 13, emptyArray(), content)
+ assertNull(InboxSeal.open(untagged, inboxSecret), "without the tag or the 10044 there is nothing to try but the identity")
+ assertNotNull(InboxSeal.open(untagged, inboxSecret, senderAnnouncedKey = aliceEncryptionKey))
+ }
+
+ @Test
+ fun `a rumor claiming another author is refused`() {
+ val forged = rumor(group.hex(), listOf(group.hex()), "I am the group")
+ val content = InboxWire.encrypt(InboxSeal.rumorJson(forged), InboxWire.conversationKey(assertNotNull(alice.privKey), inboxKey))
+ val seal = NostrSignerSync(alice).sign(1_700_000_000L, 13, emptyArray(), content)
+ assertNull(InboxSeal.open(seal, inboxSecret))
+ }
+
+ @Test
+ fun `an unsigned or tampered seal is refused`() {
+ val reply = rumor(group.hex(), listOf(alice.hex()), "Hello")
+ val template = InboxSeal.template(reply, inboxSecret, aliceEncryptionKey, 1_700_000_000L)
+ val unsigned = Event("a".repeat(64), group.hex(), template.createdAt, template.kind, template.tags, template.content, "")
+ assertNull(InboxSeal.open(unsigned, aliceEncryptionSecret))
+ }
+
+ // ---- the wrap
+
+ @Test
+ fun `a wrap names the identity and opens with the encryption key`() {
+ val seal = NostrSignerSync(group).sign(InboxSeal.template(rumor(group.hex(), listOf(alice.hex()), "Hi"), inboxSecret, aliceEncryptionKey, 1L))
+ val relay = RelayUrlNormalizer.normalizeOrNull("wss://inbox.example.com")
+ val wrap = InboxWrap.wrap(seal, alice.hex(), aliceEncryptionKey, relay, createdAt = 2L)
+
+ assertEquals(1059, wrap.kind)
+ assertEquals(alice.hex(), InboxWrap.recipientOf(wrap))
+ assertTrue(wrap.pubKey != group.hex() && wrap.pubKey != alice.hex(), "nothing outside names the sender")
+
+ val (index, opened) = assertNotNull(InboxWrap.open(wrap, listOf(secret("a retired key"), aliceEncryptionSecret)))
+ assertEquals(1, index)
+ assertEquals(seal.id, opened.id)
+ assertNull(InboxWrap.open(wrap, listOf(assertNotNull(alice.privKey))), "the identity does not open a wrap to the encryption key")
+ }
+
+ @Test
+ fun `a wrap built here is still a NIP-59 wrap to quartz, when the keys are the same`() = runTest {
+ val message = rumor(group.hex(), listOf(alice.hex()), "Plain NIP-17")
+ val content = InboxWire.encrypt(InboxSeal.rumorJson(message), InboxWire.conversationKey(assertNotNull(group.privKey), alice.hex()))
+ val seal = NostrSignerSync(group).sign(1L, 13, emptyArray(), content)
+ val wrap = InboxWrap.wrap(seal, alice.hex(), alice.hex(), createdAt = 2L) as GiftWrapEvent
+
+ val opened = assertNotNull(wrap.unwrapAndUnsealOrNull(NostrSignerInternal(alice)))
+ assertEquals("Plain NIP-17", opened.content)
+ assertEquals(group.hex(), opened.pubKey)
+ }
+
+ @Test
+ fun `a wrap quartz builds to the inbox key opens here`() = runTest {
+ // A sender whose app follows NIP-4E only so far as encrypting to the announced key.
+ val message = rumor(alice.hex(), listOf(group.hex()), "Quartz wrote this")
+ val seal = NostrSignerSync(alice).sign(
+ 1L, 13, emptyArray(),
+ InboxWire.encrypt(InboxSeal.rumorJson(message), InboxWire.conversationKey(assertNotNull(alice.privKey), inboxKey)),
+ )
+ val wrap = GiftWrapEvent.create(event = seal, recipientPubKey = inboxKey, createdAt = 2L)
+
+ val (_, unwrapped) = assertNotNull(InboxWrap.open(wrap, listOf(inboxSecret)))
+ assertEquals("Quartz wrote this", assertNotNull(InboxSeal.open(unwrapped, inboxSecret)).rumor.content)
+ }
+
+ // ---- the manifest
+
+ private val manifest = InboxReplyManifest(
+ generation = 3,
+ seals = listOf(
+ InboxReplyManifest.Entry(alice.hex(), aliceEncryptionKey, """{"kind":10044}"""),
+ InboxReplyManifest.Entry(group.hex(), inboxKey, null),
+ ),
+ groupCopy = 1,
+ )
+
+ @Test
+ fun `a manifest opens only with the inbox key it was sealed under`() {
+ val sealed = manifest.seal(inboxSecret)
+ assertEquals(manifest, InboxReplyManifest.open(sealed, inboxSecret))
+ assertNull(InboxReplyManifest.open(sealed, secret("another generation")))
+ assertEquals(sealed, InboxReplyManifest.sealedIn(arrayOf(InboxReplyManifest.tag(sealed), arrayOf("x", "y"))))
+ assertNull(InboxReplyManifest.sealedIn(arrayOf(InboxReplyManifest.tag(sealed), InboxReplyManifest.tag(sealed))))
+ }
+
+ @Test
+ fun `a manifest with a stray field, a missing one or a copy out of range is none`() {
+ val encoded = manifest.encode()
+ assertEquals(manifest, InboxReplyManifest.decode(encoded))
+ assertNull(InboxReplyManifest.decode(encoded.replaceFirst("{\"v\":1", "{\"v\":1,\"extra\":true")))
+ assertNull(InboxReplyManifest.decode(encoded.replace(",\"group_copy\":1", "")))
+ assertNull(InboxReplyManifest.decode(encoded.replace("\"group_copy\":1", "\"group_copy\":2")))
+ assertNull(InboxReplyManifest.decode(encoded.replace("\"v\":1", "\"v\":2")))
+ }
+
+ // ---- the conversation
+
+ @Test
+ fun `a message and its reply are one conversation, whatever the order of its people`() {
+ val bob = KeyPair(secret("bob")).hex()
+ val incoming = rumor(alice.hex(), listOf(group.hex(), bob), "To the group and Bob")
+ val reply = rumor(group.hex(), listOf(bob, alice.hex()), "To both")
+
+ assertEquals(listOf(alice.hex(), bob).sorted(), InboxConversation.participantsOf(incoming, group.hex()))
+ assertEquals(InboxConversation.idOf(incoming, group.hex()), InboxConversation.idOf(reply, group.hex()))
+ assertTrue(InboxConversation.idOf(rumor(alice.hex(), listOf(group.hex()), "Just us"), group.hex()) != InboxConversation.idOf(incoming, group.hex()))
+ }
+
+ @Test
+ fun `the inbox key's hex is the x-only key of its secret`() {
+ assertEquals(64, inboxKey.length)
+ assertEquals(32, inboxKey.hexToByteArray().size)
+ assertEquals(inboxKey, inboxKey.lowercase())
+ }
+}
diff --git a/composeApp/src/commonTest/kotlin/mobi/giza/compose/text/ProposedEventTest.kt b/composeApp/src/commonTest/kotlin/mobi/giza/compose/text/ProposedEventTest.kt
index 03bf3ef3..1ffd858e 100644
--- a/composeApp/src/commonTest/kotlin/mobi/giza/compose/text/ProposedEventTest.kt
+++ b/composeApp/src/commonTest/kotlin/mobi/giza/compose/text/ProposedEventTest.kt
@@ -111,6 +111,25 @@ class ProposedEventTest {
)
}
+ /**
+ * docs/group-inbox.md: the group's inbox key and its relays are said by what they are
+ * (Phase 5), and a seal as the sealed reply it is (Phase 8).
+ */
+ @Test
+ fun `an inbox key, its relays and a sealed reply are named`() {
+ val key = "e".repeat(64)
+ val announcement = ProposedEvent.summarize(event(10044, tags = arrayOf(arrayOf("n", key))))
+ assertEquals("The group's inbox key", announcement.label)
+ assertEquals("Key eeeeeeee…eeeeeeee", announcement.detail)
+ val relays = ProposedEvent.summarize(event(10050, tags = arrayOf(arrayOf("relay", "wss://inbox.example.com/"))))
+ assertEquals("Where the group receives private messages", relays.label)
+ assertEquals("inbox.example.com", relays.detail)
+ // A reply names the inbox key it is sealed from; a seal without that `n` tag is the
+ // group writing by threshold ECDH instead (docs/group-threshold-ecdh.md, D12).
+ assertEquals("A private reply from the group's inbox", ProposedEvent.summarize(event(13, tags = arrayOf(arrayOf("n", "c".repeat(64))))).label)
+ assertEquals("A private message from the group", ProposedEvent.summarize(event(13)).label)
+ }
+
private fun event(
kind: Int,
tags: Array> = emptyArray(),
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/database/InboxStorageJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/database/InboxStorageJvmTest.kt
new file mode 100644
index 00000000..c56b8628
--- /dev/null
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/database/InboxStorageJvmTest.kt
@@ -0,0 +1,131 @@
+package mobi.giza.compose.database
+
+import androidx.room3.Room
+import kotlin.test.AfterTest
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
+import kotlin.test.assertNull
+import kotlin.test.assertTrue
+import kotlin.time.Clock
+import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.runBlocking
+import mobi.giza.compose.database.builder.getRoomDatabase
+import mobi.giza.compose.database.model.ChatRoom
+import mobi.giza.compose.database.model.GroupInboxMessage
+import mobi.giza.compose.database.model.GroupInboxWrap
+import mobi.giza.compose.database.model.InboxKey
+import mobi.giza.compose.database.model.InboxKeyCeremony
+import mobi.giza.compose.database.model.InboxKeyCeremonyMessage
+import mobi.giza.compose.database.model.InboxKeyCeremonyStage
+import mobi.giza.compose.database.model.InboxKeyState
+import mobi.giza.compose.database.model.NostrEvent
+import mobi.giza.compose.database.model.Profile
+import mobi.giza.compose.managers.FrostSigningManager
+import mobi.giza.compose.nostr.inbox.InboxKeyRitualEvents
+
+/**
+ * Where a group's inbox is kept (docs/group-inbox.md, Phase 3): redelivery changes nothing,
+ * a wipe keeps the key's name and loses its secret, and nothing a signing path reads can find a
+ * threshold-1 key.
+ */
+class InboxStorageJvmTest {
+ private val db: GizaDatabase = getRoomDatabase(Room.inMemoryDatabaseBuilder())
+ private val room = "f".repeat(64)
+ private val admin = "a".repeat(64)
+
+ @AfterTest
+ fun close() = db.close()
+
+ private fun seedRoom() = runBlocking {
+ // A room belongs to a profile, which belongs to the event that made it.
+ val profileEvent = "9".repeat(64)
+ db.nostrEventDao().upsert(NostrEvent(id = profileEvent, pubKey = admin, kind = 0, tags = emptyArray(), content = "{}", sig = "0".repeat(128)))
+ db.profileDao().upsert(Profile(publicKey = admin, nostrEventId = profileEvent))
+ db.chatRoomDao().upsert(ChatRoom(id = room, userPublicKey = admin, subject = "#Ekklesia", description = "", mlsGroupState = null))
+ }
+
+ private fun completedCeremonyAndKey() = runBlocking {
+ seedRoom()
+ db.inboxKeyDao().upsertCeremony(
+ InboxKeyCeremony(
+ id = "c".repeat(64),
+ chatRoomId = room,
+ generation = 0,
+ coordinatorPublicKey = admin,
+ userPublicKey = admin,
+ participantPublicKeys = InboxKeyCeremony.formatParticipants(listOf(admin, "b".repeat(64))),
+ stage = InboxKeyCeremonyStage.COMPLETE,
+ hostPublicKey = "02" + "1".repeat(64),
+ round1Random = "2".repeat(64),
+ round2AuxRandom = "3".repeat(64),
+ inboxPublicKey = "e".repeat(64),
+ )
+ )
+ db.inboxKeyDao().upsertKey(
+ InboxKey(
+ chatRoomId = room,
+ userPublicKey = admin,
+ generation = 0,
+ publicKey = "e".repeat(64),
+ secretKey = "5".repeat(64),
+ recoveryData = "66",
+ ceremonyId = "c".repeat(64),
+ )
+ )
+ }
+
+ @Test
+ fun `a ceremony message delivered twice is kept once, as first received`() = runBlocking {
+ completedCeremonyAndKey()
+ val first = InboxKeyCeremonyMessage("c".repeat(64), admin, InboxKeyRitualEvents.HOST_KEY, "first")
+ assertTrue(db.inboxKeyDao().insertMessage(first) > 0)
+ assertEquals(-1L, db.inboxKeyDao().insertMessage(first.copy(payload = "second")))
+ assertEquals("first", db.inboxKeyDao().getMessage("c".repeat(64), admin, InboxKeyRitualEvents.HOST_KEY)?.payload)
+ }
+
+ @Test
+ fun `a wrap or a rumor delivered twice is one row`() = runBlocking {
+ seedRoom()
+ val wrap = GroupInboxWrap(id = "1".repeat(64), chatRoomId = room, wrapJson = "{}", wrapCreatedAt = 10)
+ db.groupInboxDao().insertWrap(wrap)
+ db.groupInboxDao().insertWrap(wrap.copy(wrapJson = "{\"again\":true}"))
+ assertEquals(listOf(wrap.id to wrap.wrapJson), db.groupInboxDao().getUnopenedWraps(room).map { it.id to it.wrapJson })
+
+ val message = GroupInboxMessage(
+ chatRoomId = room, rumorId = "2".repeat(64), wrapId = wrap.id, conversationId = "x",
+ participants = "b".repeat(64), senderPublicKey = "b".repeat(64), kind = 14,
+ rumorJson = "{}", createdAt = 5, generation = 0, outgoing = false,
+ )
+ db.groupInboxDao().insertMessage(message)
+ db.groupInboxDao().insertMessage(message.copy(wrapId = "3".repeat(64)))
+ assertEquals(listOf(message.wrapId), db.groupInboxDao().getMessages(room).map { it.wrapId })
+ assertEquals(1, db.groupInboxDao().observeUnreadCount(room).first())
+
+ db.groupInboxDao().markOpened(wrap.id, 0)
+ assertEquals(0, db.groupInboxDao().observeUnopenedCount(room).first())
+ }
+
+ @Test
+ fun `a wipe loses the secret and keeps the key's name`() = runBlocking {
+ completedCeremonyAndKey()
+ db.inboxKeyDao().wipeKeys(room, admin, Clock.System.now())
+
+ val key = assertNotNull(db.inboxKeyDao().getKey(room, admin, 0))
+ assertNull(key.secretKey)
+ assertNull(key.recoveryData)
+ assertEquals(InboxKeyState.WIPED, key.state)
+ assertEquals("e".repeat(64), key.publicKey)
+ assertEquals(emptyList(), db.inboxKeyDao().getHeldKeys(admin))
+ }
+
+ @Test
+ fun `no signing path can find an inbox key`() = runBlocking {
+ // D3: a threshold-1 key any one admin holds, found by the signing path, would let one
+ // admin sign as the group. It lives where nothing that signs looks.
+ completedCeremonyAndKey()
+ assertEquals(emptyList(), db.dkgSessionDao().getKeyHoldingSessions())
+ assertNull(FrostSigningManager.completedKey(db, room))
+ assertEquals(false, FrostSigningManager.canSign(db, room))
+ }
+}
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/database/migrations/ShippedProfileUpgradeJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/database/migrations/ShippedProfileUpgradeJvmTest.kt
index f3db3823..7b71d74f 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/database/migrations/ShippedProfileUpgradeJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/database/migrations/ShippedProfileUpgradeJvmTest.kt
@@ -66,11 +66,12 @@ class ShippedProfileUpgradeJvmTest {
* refresh and 40 for share repair (docs/frost-share-refresh.md, Phases 6, 7 and
* 10), 41 for governance proposals and 42 for what follows them
* (docs/member-admin-promotion.md, Phases 5, 8 and 9), 43 for the confederation
- * (docs/confederation.md, Phase 4), 44 for its key ceremony (Phase 11) and 45 for a
- * group's direct messages (docs/group-threshold-ecdh.md, Phase 4), so the upgrade crosses
- * nine generated migrations and the file has to come out at the last.
+ * (docs/confederation.md, Phase 4), 44 for its key ceremony (Phase 11), 45 for its signing
+ * (Phase 14), 46 for the group's inbox (docs/group-inbox.md, Phase 3) and 47 for a group's
+ * direct messages by threshold ECDH (docs/group-threshold-ecdh.md, Phase 4), so the upgrade
+ * crosses eleven generated migrations and the file has to come out at the last.
*/
- private val current = 45
+ private val current = 47
private val directory: File = Files.createTempDirectory("giza-shipped-profile").toFile()
private val file: File = File(directory, "aux.db")
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationSigningJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationSigningJvmTest.kt
new file mode 100644
index 00000000..85d50e9a
--- /dev/null
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationSigningJvmTest.kt
@@ -0,0 +1,259 @@
+package mobi.giza.compose.managers
+
+import androidx.room3.Room
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
+import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
+import fr.acinq.bitcoin.Crypto
+import fr.acinq.bitcoin.PrivateKey
+import kotlin.test.AfterTest
+import kotlin.test.BeforeTest
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
+import kotlin.test.assertNotNull
+import kotlin.test.assertTrue
+import kotlin.time.Clock
+import kotlin.time.Instant
+import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.runBlocking
+import mobi.giza.compose.database.GizaDatabase
+import mobi.giza.compose.database.builder.getRoomDatabase
+import mobi.giza.compose.database.model.ChatRoom
+import mobi.giza.compose.database.model.Confederation
+import mobi.giza.compose.database.model.ConfederationSigningStage
+import mobi.giza.compose.database.model.MarmotInnerEvent
+import mobi.giza.compose.database.model.NostrEvent
+import mobi.giza.compose.database.model.Profile
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.extensions.toHex
+import mobi.giza.compose.nostr.GroupNostrProfile
+import mobi.giza.compose.nostr.confederation.ConfederationCharterEvent
+import mobi.giza.compose.nostr.confederation.ConfederationRitualEvents
+import mobi.giza.compose.nostr.confederation.ConfederationSigningEvents
+import mobi.giza.compose.nostr.frost.GroupKeyStateEvent
+
+/**
+ * A confederation signing as itself, one person per device (docs/confederation.md, Phase 14): a
+ * confederation formed across nine devices, then a proposal in its room, approvals, and Option A
+ * signing with every signer's nonce held in memory -- ending, on every device, in the same event,
+ * signed as the room's id.
+ */
+class ConfederationSigningJvmTest {
+ private fun secret(n: Int) = PrivateKey(ByteArray(32).also { it[0] = 0x71; it[31] = n.toByte() })
+ private fun npub(key: PrivateKey): HexKey = key.publicKey().xOnly().value.toHex()
+
+ private val groupKeys = (1..3).map { secret(it) }
+ private val groups = groupKeys.map(::npub)
+ private val people = listOf(11, 12, 13, 21, 22, 23, 31, 32, 33)
+ private val admins = listOf(listOf(11, 12, 13), listOf(21, 22, 23), listOf(31, 32, 33))
+
+ private inner class Device(val secret: PrivateKey, val db: GizaDatabase) {
+ val person = npub(secret)
+ lateinit var ceremonyRoom: LocalChatRoom
+ lateinit var room: LocalChatRoom
+ val received = mutableSetOf()
+ val nsec get() = secret.value.toByteArray()
+ }
+
+ private val devices = linkedMapOf()
+ private lateinit var confederation: Confederation
+ private lateinit var proposer: Device
+
+ @BeforeTest
+ fun formed() = runBlocking {
+ val coordinator = npub(secret(11))
+ val now = Clock.System.now().epochSeconds
+ val proposal = ConfederationTestGroups.proposal(groupKeys[0], groups, coordinator, createdAt = now - 10, expiresAt = now + 1000)
+ val acceptances = groupKeys.mapIndexed { i, key -> ConfederationTestGroups.acceptance(key, proposal, admins[i].map { npub(secret(it)) }) }
+
+ people.map(::secret).forEach { key ->
+ val db = getRoomDatabase(Room.inMemoryDatabaseBuilder())
+ (people.map { npub(secret(it)) } + groups).forEach { member ->
+ val eventId = Crypto.sha256(member.encodeToByteArray()).toHex()
+ db.nostrEventDao().upsert(NostrEvent(id = eventId, pubKey = member, kind = 0, tags = emptyArray(), content = "{}", sig = "0".repeat(128)))
+ db.profileDao().upsert(Profile(publicKey = member, nostrEventId = eventId, displayName = member.take(6), createdAt = Instant.fromEpochSeconds(1_790_000_000)))
+ }
+ devices[npub(key)] = Device(key, db)
+ }
+ proposer = devices.getValue(coordinator)
+ (listOf(proposal) + acceptances).forEach { ConfederationManager.record(proposer.db, it) }
+
+ // Part B, across the devices: the ceremony, every device joining.
+ val ceremony = ConfederationRitualManager.open(proposer.db, proposal.id, proposer.secret)
+ proposer.ceremonyRoom = proposer.db.chatRoomDao().findChatRoomById(ceremony.chatRoomId)!!
+ devices.values.filter { it !== proposer }.forEach { d ->
+ d.ceremonyRoom = d.db.nostrNip17Dao().createNip17ChatRoom(d.person, devices.keys.filter { it != d.person }, "Atlas")!!
+ }
+ pumpCeremony()
+ devices.values.forEach { ConfederationRitualManager.join(it.db, ceremony.id, it.nsec) }
+ pumpCeremony()
+ confederation = assertNotNull(proposer.db.confederationCeremonyDao().getConfederationForProposal(proposal.id))
+
+ // The confederation's room on every device. Its MLS state is not this test's business; a
+ // room with group state is what makes signing travel as a group event.
+ devices.values.forEach { d ->
+ d.db.chatRoomDao().upsert(ChatRoom(id = confederation.id, userPublicKey = d.person, subject = "#Atlas", description = null, mlsGroupState = "00"))
+ d.room = d.db.chatRoomDao().findChatRoomById(confederation.id)!!
+ }
+ }
+
+ @AfterTest
+ fun close() {
+ ConfederationSigningManager.forgetSignersForTest()
+ devices.values.forEach { it.db.close() }
+ }
+
+ private suspend fun pumpCeremony() {
+ var moved = true
+ while (moved) {
+ moved = false
+ for (from in devices.values) for (to in devices.values) {
+ if (from === to) continue
+ from.db.giftWrapPayloadDao().getByChatRoomAndKinds(from.ceremonyRoom.chatRoom.id, ConfederationRitualEvents.ALL.toList())
+ .filter { it.publicKey == from.person }.sortedBy { it.createdAt }
+ .forEach { q ->
+ if (!to.received.add(q.id)) return@forEach
+ moved = true
+ to.db.giftWrapPayloadDao().upsert(q.copy(chatRoomId = to.ceremonyRoom.chatRoom.id))
+ ConfederationRitualManager.process(to.db, to.ceremonyRoom, Event(q.id, q.publicKey, q.createdAt.epochSeconds, q.kind, q.tags, q.content, ""), to.person, to.nsec)
+ }
+ }
+ }
+ }
+
+ /** Ferries the room's signing messages between devices until nothing moves; [hold] keeps some back. */
+ private fun pump(hold: (MarmotInnerEvent) -> Boolean = { false }) = runBlocking {
+ var moved = true
+ while (moved) {
+ moved = false
+ for (from in devices.values) for (to in devices.values) {
+ if (from === to) continue
+ from.db.marmotInnerEventDao().getByChatRoomAndKinds(confederation.id, ConfederationSigningEvents.ALL.toList())
+ .filter { it.publicKey == from.person }.sortedWith(compareBy({ it.createdAt }, { it.kind }))
+ .forEach { q ->
+ if (hold(q) || !to.received.add(q.id)) return@forEach
+ moved = true
+ to.db.marmotInnerEventDao().upsert(q)
+ ConfederationSigningManager.process(to.db, to.room, Event(q.id, q.publicKey, q.createdAt.epochSeconds, q.kind, q.tags, q.content, ""), to.person, to.nsec)
+ }
+ }
+ }
+ }
+
+ private fun propose(kind: Int = MetadataEvent.KIND, content: String = """{"name":"Atlas","about":"A group of groups"}""") = runBlocking {
+ ConfederationSigningManager.propose(proposer.db, proposer.room, proposer.person, kind, emptyArray(), content, proposer.nsec)
+ }
+
+ private fun approve(attemptId: String, who: List) = runBlocking {
+ who.map { devices.getValue(npub(secret(it))) }.forEach { ConfederationSigningManager.approve(it.db, attemptId, it.nsec) }
+ }
+
+ private fun attempts(attemptId: String) = runBlocking { devices.values.associate { it.person to it.db.confederationCeremonyDao().getAttempt(attemptId) } }
+
+ @Test
+ fun `the confederation signs its profile, and every device holds it signed as the room`() {
+ val attempt = propose()
+ pump()
+ approve(attempt.id, people - 11)
+ pump()
+
+ attempts(attempt.id).forEach { (person, a) -> assertEquals(ConfederationSigningStage.COMPLETE, a?.stage, "${person.take(6)}: ${a?.failureReason}") }
+ val signed = attempts(attempt.id).values.map { Event.fromJson(it!!.signedEventJson!!) }
+ assertEquals(1, signed.map { it.sig }.toSet().size, "the same signature on every device")
+ assertTrue(GroupKeyStateEvent.isSignedByRoom(signed.first(), confederation.id), "a plain nostr signature by the room's id")
+
+ runBlocking {
+ devices.values.forEach { d ->
+ val rows = d.db.groupSignedEventDao().getByChatRoomIdAndKind(confederation.id, MetadataEvent.KIND)
+ assertEquals("Atlas", assertNotNull(GroupNostrProfile.newestAmong(rows, confederation.id)).name())
+ }
+ }
+ }
+
+ @Test
+ fun `enough willing admins in enough groups is all it takes`() {
+ val attempt = propose(TextNoteEvent.KIND, "The first words of a group of groups")
+ pump()
+ // Two groups of three, two admins in each: Agora (11, 12) and Polis (21, 22). Nobody else answers.
+ approve(attempt.id, listOf(12, 21, 22))
+ pump()
+ listOf(11, 12, 21, 22, 33).forEach { n ->
+ assertEquals(ConfederationSigningStage.COMPLETE, attempts(attempt.id).getValue(npub(secret(n)))?.stage)
+ }
+ }
+
+ @Test
+ fun `a device that loses its nonces mid-attempt ends it for everybody`() {
+ val attempt = propose()
+ pump()
+ approve(attempt.id, people - 11)
+ pump(hold = { it.kind == ConfederationSigningEvents.NONCES })
+ ConfederationSigningManager.forgetSignersForTest() // every device restarts
+ pump()
+ attempts(attempt.id).values.forEach {
+ assertEquals(ConfederationSigningStage.FAILED, it?.stage)
+ assertTrue(it!!.failureReason!!.contains("restarted while signing"), it.failureReason)
+ }
+ }
+
+ @Test
+ fun `when too many decline, the proposer says so and it ends`() {
+ val attempt = propose()
+ pump()
+ runBlocking {
+ listOf(21, 22, 31, 32).map { devices.getValue(npub(secret(it))) }.forEach { ConfederationSigningManager.decline(it.db, attempt.id) }
+ }
+ pump()
+ val ended = attempts(attempt.id).getValue(proposer.person)
+ assertEquals(ConfederationSigningStage.FAILED, ended?.stage)
+ assertTrue(ended!!.failureReason!!.startsWith("Not enough admins"), ended.failureReason)
+ }
+
+ @Test
+ fun `a confederation signs only its profile and its posts`() {
+ assertFailsWith { propose(kind = 30023, content = "long form") }
+ assertFailsWith { propose(kind = TextNoteEvent.KIND, content = " ") }
+ }
+
+ // ---- Phase 15: the charter ------------------------------------------------------------
+
+ @Test
+ fun `a charter naming exactly its groups is signed, filed and owed to relays`() {
+ val polisMember = devices.getValue(npub(secret(22)))
+ runBlocking {
+ polisMember.db.chatRoomDao().upsert(ChatRoom(id = groups[1], userPublicKey = polisMember.person, subject = "#Polis", description = null, mlsGroupState = "00"))
+ }
+ val (kind, tags, content) = runBlocking { assertNotNull(ConfederationSigningManager.charterTemplate(proposer.db, confederation.id)) }
+ val attempt = runBlocking { ConfederationSigningManager.propose(proposer.db, proposer.room, proposer.person, kind, tags, content, proposer.nsec) }
+ pump()
+ approve(attempt.id, people - 11)
+ pump()
+
+ attempts(attempt.id).values.forEach { assertEquals(ConfederationSigningStage.COMPLETE, it?.stage, it?.failureReason) }
+ val signed = Event.fromJson(attempts(attempt.id).getValue(proposer.person)!!.signedEventJson!!)
+ runBlocking {
+ val owed = proposer.db.confederationDao().observeUnpublished().first()
+ assertEquals(listOf(signed.id), owed.map { it.id }, "the proposer's device owes it to relays")
+ assertEquals(groups.toSet(), proposer.db.confederationDao().getEvent(signed.id)?.let { listOf(it) }?.let {
+ ConfederationCharterEvent.parse(it.single().toEvent())?.groups?.toSet()
+ })
+ assertTrue(
+ polisMember.db.chatMessageDao().getChatMessagesByChatRoomId(groups[1])
+ .any { it.chatMessage.content.contains("signed its charter") },
+ "Polis's room hears of it",
+ )
+ }
+ }
+
+ @Test
+ fun `a charter that leaves out a group is refused`() {
+ val wrong = ConfederationCharterEvent.assembleTags(confederation.name, groups.take(2))
+ assertFailsWith {
+ runBlocking {
+ ConfederationSigningManager.propose(proposer.db, proposer.room, proposer.person, ConfederationCharterEvent.KIND, wrong, "x", proposer.nsec)
+ }
+ }
+ }
+}
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupDmRelaysJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupDmRelaysJvmTest.kt
index 915ceb37..d88a2fa0 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupDmRelaysJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupDmRelaysJvmTest.kt
@@ -8,17 +8,9 @@ import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue
-import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.runBlocking
import mobi.giza.compose.database.model.ChatMessage
-import mobi.giza.compose.database.model.NostrEvent
import mobi.giza.compose.database.model.types.FrostSigningStage
-import mobi.giza.compose.database.repository.DatabaseGroupDmRepository
-import mobi.giza.compose.network.dto.RelayDTO
-import mobi.giza.compose.network.relays.EventPublishTransport
-import mobi.giza.compose.network.relays.NostrPublishResult
-import mobi.giza.compose.network.sockets.NostrIncomingMessage
import mobi.giza.compose.nostr.frost.FrostSigningEvents
import mobi.giza.compose.text.ProposedEvent
@@ -33,14 +25,6 @@ class GroupDmRelaysJvmTest {
@AfterTest
fun tearDown() = net.close()
- private class Transport : EventPublishTransport {
- val sent = mutableListOf>>()
- override suspend fun publishEvent(nostrEvent: NostrEvent, relays: Set): Flow {
- sent += nostrEvent to relays.map { it.url }.toSet()
- return flowOf(*relays.map { NostrPublishResult(result = NostrIncomingMessage.OkMessage(eventId = nostrEvent.id, success = true), relayUrl = it.url) }.toTypedArray())
- }
- }
-
private suspend fun signRelays(relays: List): String {
val a = net.devices[0]
val b = net.devices[1]
@@ -53,28 +37,22 @@ class GroupDmRelaysJvmTest {
}
@Test
- fun `a signed 10050 is published unchanged by its proposer, and writes no NostrEvent row`(): Unit = runBlocking {
+ fun `a signed 10050 is owed to relays by its proposer alone, unchanged, and writes no NostrEvent row`(): Unit = runBlocking {
net.install()
net.all()
val a = net.devices[0]
val sessionId = signRelays(listOf("wss://dm.example.com/", "wss://inbox.example.org"))
- val owed = a.db.groupDmDao().getOutbound(sessionId).single()
- val signed = Event.fromJson(assertNotNull(owed.wrapJson))
+ // One publisher for every group-signed 10050, whichever feature proposed it: the group
+ // inbox's (docs/group-inbox.md, D7).
+ val owed = a.db.groupInboxDao().getPublicationsFor(sessionId).single()
+ val signed = Event.fromJson(owed.eventJson)
assertEquals(GroupDmRelays.KIND, signed.kind)
assertEquals(net.roomId, signed.pubKey)
assertTrue(signed.verify(), "the group's own signature")
assertEquals(listOf("wss://dm.example.com/", "wss://inbox.example.org/"), GroupDmRelays.relaysIn(signed.tags))
- // Only the proposer owes it.
- assertEquals(emptyList(), net.devices[1].db.groupDmDao().getOutbound(sessionId))
-
- val transport = Transport()
- assertTrue(GroupDmPublisher(DatabaseGroupDmRepository(a.db), transport).publish(owed))
- val (sent, to) = transport.sent.single()
- assertEquals(signed.id, sent.id)
- assertEquals(signed.sig, sent.sig)
- assertTrue("wss://dm.example.com/" in to && "wss://inbox.example.org/" in to)
- assertNotNull(a.db.groupDmDao().getOutbound(sessionId).single().publishedAt)
+ assertTrue("wss://dm.example.com/" in owed.relays && "wss://inbox.example.org/" in owed.relays)
+ assertEquals(emptyList(), net.devices[1].db.groupInboxDao().getPublicationsFor(sessionId), "only the proposer owes it")
net.devices.forEach { device ->
assertNull(device.db.nostrEventDao().getNostrEventById(signed.id), "no NostrEvent row on $device")
@@ -83,7 +61,7 @@ class GroupDmRelaysJvmTest {
}
@Test
- fun `the transcript says the group can receive messages, and then that it changed where`(): Unit = runBlocking {
+ fun `the transcript says where the group's mail arrives, each time it is signed`(): Unit = runBlocking {
net.install()
net.all()
signRelays(listOf("wss://dm.example.com"))
@@ -93,10 +71,8 @@ class GroupDmRelaysJvmTest {
net.devices.forEach { device ->
val lines = device.db.chatMessageDao().getChatMessagesByChatRoomId(net.roomId)
.map { it.chatMessage }
- .filter { it.messageType == ChatMessage.TYPE_GROUP_DM_RELAYS_SIGNED }
- .sortedBy { it.createdAt }
- .map { it.content }
- assertEquals(listOf("The group can now receive messages", "The group changed where it receives messages"), lines, "$device")
+ .filter { it.messageType == ChatMessage.TYPE_INBOX_RELAYS_ANNOUNCED }
+ assertEquals(2, lines.size, "$device")
assertEquals(listOf("wss://other.example.com/"), GroupDmRelays.relaysOf(device.db, net.roomId))
}
}
@@ -123,11 +99,12 @@ class GroupDmRelaysJvmTest {
harness.deliver(sent, harness.members[1])
val session = assertNotNull(harness.db.frostSigningSessionDao().getSessionById(sent.session.id))
assertNotNull(session.signDeclinedAt)
- assertEquals(listOf(GroupDmRelayRefusal.REASON), harness.queued(FrostSigningEvents.DECLINE).map { it.content })
+ // The group inbox's refusal, which reads every 10050 the group is asked to sign.
+ assertEquals(listOf(InboxRefusal.RELAYS_SHAPE), harness.queued(FrostSigningEvents.DECLINE).map { it.content })
val localhost = proposeRelayList(listOf("wss://localhost:7777"))
harness.deliver(localhost, harness.members[1])
- assertEquals(listOf(GroupDmRelayRefusal.REASON), harness.queued(FrostSigningEvents.DECLINE).map { it.content })
+ assertEquals(listOf(InboxRefusal.RELAYS_SHAPE), harness.queued(FrostSigningEvents.DECLINE).map { it.content })
}
@Test
@@ -139,7 +116,7 @@ class GroupDmRelaysJvmTest {
val items = harness.db.frostSigningSessionDao().getItems(session.id)
assertTrue(FrostSigningManager.isAwaitingApproval(session, items))
val summary = ProposedEvent.summarize(Event.fromJson(items.single().unsignedEventJson))
- assertEquals("Where the group receives messages", summary.label)
- assertEquals("wss://fine.example.com/", summary.detail)
+ assertEquals("Where the group receives private messages", summary.label)
+ assertEquals("fine.example.com", summary.detail)
}
}
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupDmTodayJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupDmTodayJvmTest.kt
index d94d2407..cde78c28 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupDmTodayJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupDmTodayJvmTest.kt
@@ -114,7 +114,7 @@ class GroupDmTodayJvmTest {
val sent = proposeKind(10050, "", arrayOf(arrayOf("relay", "wss://relay.example")))
harness.deliver(sent, bob)
val items = harness.db.frostSigningSessionDao().getItems(sent.session.id)
- assertEquals("Where the group receives messages", ProposedEvent.summarize(Event.fromJson(items.single().unsignedEventJson)).label)
+ assertEquals("Where the group receives private messages", ProposedEvent.summarize(Event.fromJson(items.single().unsignedEventJson)).label)
}
/** Flipped by Phase 7: the group's mail has its own subscription. */
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupInboxHarness.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupInboxHarness.kt
new file mode 100644
index 00000000..6dc7963d
--- /dev/null
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupInboxHarness.kt
@@ -0,0 +1,175 @@
+package mobi.giza.compose.managers
+
+import androidx.room3.Room
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.toHexKey
+import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
+import fr.acinq.bitcoin.ByteVector32
+import fr.acinq.bitcoin.Crypto
+import fr.acinq.bitcoin.PrivateKey
+import fr.acinq.bitcoin.crypto.frost.Frost
+import fr.acinq.bitcoin.crypto.frost.KeyMaterial
+import mobi.giza.compose.ExperimentalFeatures
+import mobi.giza.compose.database.GizaDatabase
+import mobi.giza.compose.database.builder.getRoomDatabase
+import mobi.giza.compose.database.model.ChatRoom
+import mobi.giza.compose.database.model.DkgParticipantMessage
+import mobi.giza.compose.database.model.DkgSession
+import mobi.giza.compose.database.model.MarmotInnerEvent
+import mobi.giza.compose.database.model.NostrEvent
+import mobi.giza.compose.database.model.Profile
+import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.database.model.types.DkgRitualStage
+import mobi.giza.compose.extensions.toHex
+import mobi.giza.compose.nostr.dkg.DkgRitualEvents
+import mobi.giza.compose.nostr.frost.FrostSigningEvents
+import mobi.giza.compose.nostr.inbox.InboxKeyRitualEvents
+
+/**
+ * One keyed group, a device per member, for the group inbox's tests (docs/group-inbox.md).
+ *
+ * Every member has a real nostr key, because the inbox ceremony derives its host keys from the
+ * nsec and the inbox opens NIP-44 with real secrets. The group's signing key stands in for a
+ * finished ceremony (a trusted dealer, as `SignedGroupKeyStateTest` has it), and the room is a
+ * Marmot one by its column -- nothing here runs MLS, so what a device sends is read off its
+ * inner events and handed to the others by [pump], stored first, as the inbound path would.
+ *
+ * Who a device sees as the room's admins is [admins], through [RoomAdmins.override].
+ */
+class GroupInboxHarness(
+ names: List = listOf("alice", "bob", "carol"),
+ /** Members of the room who are not admins and hold no share. */
+ watchers: List = emptyList(),
+ val threshold: Int = 2,
+) {
+ val secrets: Map = (names + watchers).associateWith { Crypto.sha256("giza inbox $it".encodeToByteArray()) }
+ val keyOf: Map = secrets.mapValues { KeyPair(it.value).pubKey.toHexKey() }
+ val signers: List = names.map { keyOf.getValue(it) }
+ val everyone: List = (names + watchers).map { keyOf.getValue(it) }
+
+ val keyMaterial: KeyMaterial = Frost.trustedDealerKeygen(
+ thresholdSecretKey = PrivateKey(ByteVector32("1c0ffee0000000000000000000000000000000000000000000000000000000a1")),
+ nParticipants = names.size,
+ threshold = threshold,
+ )
+ val thresholdPublicKey = keyMaterial.thresholdPublicKey.value.toHex()
+ val roomId: String = SharedKeyDerivation.marmotGroupId(thresholdPublicKey)
+ private val ceremonyId = "ceremony".padEnd(64, '0')
+ // Chosen to sort as the signers read, so signer i holds share i.
+ private val signingHostKeys = names.indices.map { "2${('a' + it)}".padEnd(66, '0') }
+
+ /** Who every device reads as the room's admins. */
+ var admins: Set = signers.toSet()
+
+ val devices = mutableListOf()
+
+ init {
+ ExperimentalFeatures.groupInboxOverride = true
+ RoomAdmins.override = { id -> if (id == roomId) RoomAdmins(admins, governed = false) else null }
+ }
+
+ fun close() {
+ devices.forEach { it.db.close() }
+ RoomAdmins.override = null
+ ExperimentalFeatures.groupInboxOverride = null
+ }
+
+ inner class Device(val name: String, val publicKey: HexKey, val secret: ByteArray, val db: GizaDatabase) {
+ /** Inner events already handed to this device, so a pump terminates. */
+ val received = mutableSetOf()
+
+ suspend fun room(): LocalChatRoom = db.chatRoomDao().findChatRoomById(roomId)!!
+
+ suspend fun keys() = db.inboxKeyDao().getKeys(roomId, publicKey)
+
+ suspend fun ceremony(id: String) = db.inboxKeyDao().getCeremony(id)
+
+ suspend fun lines(types: Set) =
+ db.chatMessageDao().getChatMessagesByChatRoomId(roomId).map { it.chatMessage }.filter { it.messageType in types }
+ }
+
+ suspend fun device(name: String): Device {
+ val publicKey = keyOf.getValue(name)
+ val db = getRoomDatabase(Room.inMemoryDatabaseBuilder())
+
+ everyone.forEach { member ->
+ val eventId = "e$member".take(64)
+ db.nostrEventDao().upsert(NostrEvent(id = eventId, pubKey = member, kind = 0, tags = emptyArray(), content = "{}", sig = "0".repeat(128)))
+ db.profileDao().upsert(Profile(publicKey = member, nostrEventId = eventId))
+ }
+ db.chatRoomDao().upsert(
+ ChatRoom(
+ id = roomId,
+ userPublicKey = publicKey,
+ subject = "#Ekklesia",
+ description = SharedKeyDerivation.describe("Admins of the group."),
+ mlsGroupState = "00",
+ )
+ )
+
+ val signerIndex = signers.indexOf(publicKey)
+ if (signerIndex >= 0) {
+ db.dkgSessionDao().upsert(
+ DkgSession(
+ id = ceremonyId,
+ chatRoomId = roomId,
+ coordinatorPublicKey = signers.first(),
+ userPublicKey = publicKey,
+ threshold = threshold,
+ participantCount = signers.size,
+ stage = DkgRitualStage.COMPLETE,
+ hostPublicKey = signingHostKeys[signerIndex],
+ round1Random = "1".repeat(64),
+ round2AuxRandom = "2".repeat(64),
+ thresholdPublicKey = thresholdPublicKey,
+ secretShare = keyMaterial.secretShares[signerIndex].value.toHex(),
+ publicShares = keyMaterial.publicShares.joinToString(",") { it.value.toHex() },
+ )
+ )
+ signers.forEachIndexed { index, signer ->
+ db.dkgSessionDao().upsert(
+ DkgParticipantMessage(sessionId = ceremonyId, participantPublicKey = signer, kind = DkgRitualEvents.HOST_KEY, payload = signingHostKeys[index])
+ )
+ }
+ }
+ return Device(name, publicKey, secrets.getValue(name), db).also { devices += it }
+ }
+
+ /** The kinds [pump] carries between devices. */
+ var carried: Set = FrostSigningEvents.ALL + InboxKeyRitualEvents.ALL
+
+ private suspend fun outbox(device: Device): List =
+ device.db.marmotInnerEventDao()
+ .getByChatRoomAndKinds(chatRoomId = roomId, kinds = carried.toList())
+ .filter { it.publicKey == device.publicKey }
+ .sortedWith(compareBy({ it.createdAt }, { it.kind }))
+
+ /**
+ * Hands everything each device has sent to every other, until nobody has anything new.
+ * [except] devices are offline: they neither send nor receive.
+ */
+ suspend fun pump(vararg between: Device = devices.toTypedArray(), except: Set = emptySet()) {
+ val online = between.filter { it !in except }
+ var moved = true
+ while (moved) {
+ moved = false
+ for (from in online) for (to in online) {
+ if (from === to) continue
+ outbox(from).forEach { row ->
+ if (!to.received.add(row.id)) return@forEach
+ moved = true
+ to.db.marmotInnerEventDao().upsert(row.copy())
+ val event = Event(row.id, row.publicKey, row.createdAt.epochSeconds, row.kind, row.tags, row.content, "")
+ val room = to.room()
+ when {
+ FrostSigningEvents.isFrostSigningKind(row.kind) ->
+ FrostSigningManager.processSigningPayload(to.db, room, event, to.publicKey)
+ InboxKeyRitualEvents.isInboxKeyKind(row.kind) ->
+ InboxKeyRitualManager.process(to.db, room, event, to.publicKey, to.secret)
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupInboxReadJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupInboxReadJvmTest.kt
new file mode 100644
index 00000000..8853d1fe
--- /dev/null
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupInboxReadJvmTest.kt
@@ -0,0 +1,180 @@
+package mobi.giza.compose.managers
+
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import com.vitorpamplona.quartz.nip01Core.core.toHexKey
+import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
+import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
+import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
+import com.vitorpamplona.quartz.nip59Giftwrap.rumors.RumorAssembler
+import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealEvent
+import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
+import fr.acinq.bitcoin.Crypto
+import kotlin.test.AfterTest
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertFalse
+import kotlin.test.assertNotNull
+import kotlin.test.assertNull
+import kotlin.test.assertTrue
+import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.runBlocking
+import mobi.giza.compose.database.model.ChatMessage
+import mobi.giza.compose.database.model.InboxKeyState
+import mobi.giza.compose.nostr.inbox.InboxConversation
+import mobi.giza.compose.nostr.inbox.InboxSeal
+import mobi.giza.compose.nostr.inbox.InboxWire
+import mobi.giza.compose.nostr.inbox.InboxWrap
+
+/**
+ * Reading the group's inbox (docs/group-inbox.md, Phase 6): mail a stranger writes to the group
+ * opens on every admin's device and on no other, whatever the stranger's app does with the
+ * announced key, and what nobody can open is counted rather than lost.
+ */
+class GroupInboxReadJvmTest {
+ private val harness = GroupInboxHarness(watchers = listOf("dineo"))
+ private val zola = KeyPair(Crypto.sha256("zola, who writes to the group".encodeToByteArray()))
+ private val zolaKey = zola.pubKey.toHexKey()
+
+ @AfterTest
+ fun close() = harness.close()
+
+ private suspend fun group() = listOf("alice", "bob", "carol", "dineo").map { harness.device(it) }
+
+ private suspend fun keyed(): List {
+ val devices = group()
+ val alice = devices[0]
+ InboxKeyRitualManager.propose(alice.db, alice.room(), alice.publicKey, alice.secret)
+ harness.pump()
+ return devices
+ }
+
+ private fun rumor(text: String, createdAt: Long = 1_700_000_000L): Event = RumorAssembler.assembleRumor(
+ pubKey = zolaKey,
+ ev = EventTemplate(createdAt, 14, arrayOf(arrayOf("p", harness.roomId)), text),
+ )
+
+ /** A stock NIP-17 seal from Zola's identity, to [toKey]. */
+ private fun seal(message: Event, toKey: HexKey): Event = NostrSignerSync(zola).sign(
+ 1_700_000_000L, 13, emptyArray(),
+ InboxWire.encrypt(InboxSeal.rumorJson(message), InboxWire.conversationKey(zola.privKey!!, toKey)),
+ )
+
+ private suspend fun GroupInboxHarness.Device.inboxKey(): HexKey = keys().first().publicKey
+
+ private suspend fun GroupInboxHarness.Device.receive(wrap: Event) = GroupInboxManager.receive(db, wrap, publicKey)
+
+ @Test
+ fun `mail written to the group opens on every admin's device and on nobody else's`() = runBlocking {
+ val (alice, bob, carol, dineo) = keyed()
+ val e = alice.inboxKey()
+ val message = rumor("Can I join the reading group?")
+ val wrap = InboxWrap.wrap(seal(message, e), harness.roomId, e)
+
+ listOf(alice, bob, carol).forEach { admin ->
+ val filed = assertNotNull(admin.receive(wrap), "${admin.name} opens it")
+ assertEquals(message.id, filed.rumorId)
+ assertEquals(zolaKey, filed.senderPublicKey)
+ assertFalse(filed.outgoing)
+ assertEquals(listOf(zolaKey), filed.participantList())
+ assertEquals(InboxConversation.idOf(listOf(zolaKey)), filed.conversationId)
+ assertEquals("Can I join the reading group?", Event.fromJson(filed.rumorJson).content)
+ }
+ assertNull(dineo.receive(wrap), "a member who is not an admin holds nothing to open it with")
+ assertEquals(emptyList(), dineo.db.groupInboxDao().getMessages(harness.roomId))
+ }
+
+ @Test
+ fun `a wrap tagged with the inbox key rather than the group still arrives`() = runBlocking {
+ val (alice, _, _, _) = keyed()
+ val e = alice.inboxKey()
+ // quartz's own builder tags the key it encrypts to: what an app that knows only the
+ // announcement, and not #2361, sends.
+ val wrap = GiftWrapEvent.create(event = seal(rumor("Tagged to the key"), e), recipientPubKey = e)
+ assertEquals("Tagged to the key", Event.fromJson(assertNotNull(alice.receive(wrap)).rumorJson).content)
+ }
+
+ @Test
+ fun `mail to the group's npub, which nobody can open, is counted and kept`() = runBlocking