diff --git a/composeApp/schemas/to.curare.compose.database.CurareDatabase/25.json b/composeApp/schemas/to.curare.compose.database.CurareDatabase/25.json new file mode 100644 index 00000000..ad9349c6 --- /dev/null +++ b/composeApp/schemas/to.curare.compose.database.CurareDatabase/25.json @@ -0,0 +1,5835 @@ +{ + "formatVersion": 1, + "database": { + "version": 25, + "identityHash": "b8e051243c6c16c1ebefd2e9f7f56ccb", + "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": "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, `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": "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, `stage` TEXT NOT NULL, `signerIds` TEXT, `failureReason` TEXT, `signApprovedAt` INTEGER, `signDeclinedAt` INTEGER, `approvalRequestedAt` INTEGER, `resentAt` 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": "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": "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": "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": "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, `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": "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": "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": "MantraArtifact", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, `visibility` TEXT NOT NULL, `dialectId` TEXT NOT NULL, `license` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `signature` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`dialectId`) REFERENCES `MantraDialect`(`id`) 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": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "url", + "columnName": "url", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "visibility", + "columnName": "visibility", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "dialectId", + "columnName": "dialectId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "license", + "columnName": "license", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "signature", + "columnName": "signature", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "relayHint", + "columnName": "relayHint", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "groupSignedEventId", + "columnName": "groupSignedEventId", + "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" + ] + }, + "foreignKeys": [ + { + "table": "MantraDialect", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "dialectId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "ChatRoom", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chatRoomId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "MantraArtifactVersion", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `artifactId` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `versionLabel` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`artifactId`) REFERENCES `MantraArtifact`(`id`) 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": "TEXT", + "notNull": true + }, + { + "fieldPath": "artifactId", + "columnName": "artifactId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "versionLabel", + "columnName": "versionLabel", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "signature", + "columnName": "signature", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "relayHint", + "columnName": "relayHint", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "groupSignedEventId", + "columnName": "groupSignedEventId", + "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" + ] + }, + "foreignKeys": [ + { + "table": "MantraArtifact", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "artifactId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "ChatRoom", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chatRoomId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "MantraChapter", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `artifactVersionId` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `name` TEXT NOT NULL, `originalText` TEXT NOT NULL, `index` INTEGER NOT NULL, `wordCount` INTEGER NOT NULL, `characterCount` INTEGER NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`artifactVersionId`) REFERENCES `MantraArtifactVersion`(`id`) 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": "TEXT", + "notNull": true + }, + { + "fieldPath": "artifactVersionId", + "columnName": "artifactVersionId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "originalText", + "columnName": "originalText", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "index", + "columnName": "index", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "wordCount", + "columnName": "wordCount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "characterCount", + "columnName": "characterCount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "signature", + "columnName": "signature", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "relayHint", + "columnName": "relayHint", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "groupSignedEventId", + "columnName": "groupSignedEventId", + "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" + ] + }, + "foreignKeys": [ + { + "table": "MantraArtifactVersion", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "artifactVersionId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "ChatRoom", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chatRoomId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "MantraChunk", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chapterId` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `text` TEXT NOT NULL, `index` INTEGER NOT NULL, `wordCount` INTEGER NOT NULL, `characterCount` INTEGER NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chapterId`) REFERENCES `MantraChapter`(`id`) 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": "TEXT", + "notNull": true + }, + { + "fieldPath": "chapterId", + "columnName": "chapterId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "text", + "columnName": "text", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "index", + "columnName": "index", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "wordCount", + "columnName": "wordCount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "characterCount", + "columnName": "characterCount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "signature", + "columnName": "signature", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "relayHint", + "columnName": "relayHint", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "groupSignedEventId", + "columnName": "groupSignedEventId", + "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" + ] + }, + "foreignKeys": [ + { + "table": "MantraChapter", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chapterId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "ChatRoom", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chatRoomId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "MantraDialect", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `name` TEXT NOT NULL, `country` TEXT NOT NULL, `language` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` 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": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "country", + "columnName": "country", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "language", + "columnName": "language", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "signature", + "columnName": "signature", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "relayHint", + "columnName": "relayHint", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "groupSignedEventId", + "columnName": "groupSignedEventId", + "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" + ] + }, + "foreignKeys": [ + { + "table": "ChatRoom", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chatRoomId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "MantraTranslation", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `translationChunkId` TEXT NOT NULL, `translationArtifactVersionId` TEXT NOT NULL, `text` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`translationChunkId`) REFERENCES `MantraTranslationChunk`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`translationArtifactVersionId`) REFERENCES `MantraTranslationArtifactVersion`(`id`) 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": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "translationChunkId", + "columnName": "translationChunkId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "translationArtifactVersionId", + "columnName": "translationArtifactVersionId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "text", + "columnName": "text", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "signature", + "columnName": "signature", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "relayHint", + "columnName": "relayHint", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "groupSignedEventId", + "columnName": "groupSignedEventId", + "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" + ] + }, + "foreignKeys": [ + { + "table": "MantraTranslationChunk", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "translationChunkId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "MantraTranslationArtifactVersion", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "translationArtifactVersionId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "ChatRoom", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chatRoomId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "MantraTranslationArtifactVersion", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `artifactVersionId` TEXT NOT NULL, `dialectId` TEXT NOT NULL, `name` TEXT NOT NULL, `visibility` TEXT NOT NULL, `license` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`artifactVersionId`) REFERENCES `MantraArtifactVersion`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`dialectId`) REFERENCES `MantraDialect`(`id`) 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": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "artifactVersionId", + "columnName": "artifactVersionId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "dialectId", + "columnName": "dialectId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "visibility", + "columnName": "visibility", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "license", + "columnName": "license", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "signature", + "columnName": "signature", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "relayHint", + "columnName": "relayHint", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "groupSignedEventId", + "columnName": "groupSignedEventId", + "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" + ] + }, + "foreignKeys": [ + { + "table": "MantraArtifactVersion", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "artifactVersionId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "MantraDialect", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "dialectId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "ChatRoom", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chatRoomId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "MantraTranslationArtifactVersionContributor", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `translationArtifactVersionId` TEXT NOT NULL, `editorPublicKey` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`translationArtifactVersionId`) REFERENCES `MantraTranslationArtifactVersionContributor`(`id`) 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": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "translationArtifactVersionId", + "columnName": "translationArtifactVersionId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "editorPublicKey", + "columnName": "editorPublicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "signature", + "columnName": "signature", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "relayHint", + "columnName": "relayHint", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "groupSignedEventId", + "columnName": "groupSignedEventId", + "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" + ] + }, + "foreignKeys": [ + { + "table": "MantraTranslationArtifactVersionContributor", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "translationArtifactVersionId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "ChatRoom", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chatRoomId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "MantraTranslationChapter", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `chapterId` TEXT NOT NULL, `translationArtifactVersionId` TEXT NOT NULL, `index` INTEGER NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`translationArtifactVersionId`) REFERENCES `MantraTranslationArtifactVersion`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chapterId`) REFERENCES `MantraChapter`(`id`) 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": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chapterId", + "columnName": "chapterId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "translationArtifactVersionId", + "columnName": "translationArtifactVersionId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "index", + "columnName": "index", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "signature", + "columnName": "signature", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "relayHint", + "columnName": "relayHint", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "groupSignedEventId", + "columnName": "groupSignedEventId", + "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" + ] + }, + "foreignKeys": [ + { + "table": "MantraTranslationArtifactVersion", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "translationArtifactVersionId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "MantraChapter", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chapterId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "ChatRoom", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chatRoomId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "MantraTranslationChapterContributor", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `translationChapterId` TEXT NOT NULL, `translatorPublicKey` TEXT NOT NULL, `role` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`translationChapterId`) REFERENCES `MantraTranslationChapter`(`id`) 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": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "translationChapterId", + "columnName": "translationChapterId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "translatorPublicKey", + "columnName": "translatorPublicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "role", + "columnName": "role", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "signature", + "columnName": "signature", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "relayHint", + "columnName": "relayHint", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "groupSignedEventId", + "columnName": "groupSignedEventId", + "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" + ] + }, + "foreignKeys": [ + { + "table": "MantraTranslationChapter", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "translationChapterId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "ChatRoom", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chatRoomId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "MantraTranslationChunk", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `chunkId` TEXT NOT NULL, `translationChapterId` TEXT NOT NULL, `text` TEXT NOT NULL, `index` INTEGER NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chunkId`) REFERENCES `MantraChunk`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`translationChapterId`) REFERENCES `MantraTranslationChapter`(`id`) 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": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chunkId", + "columnName": "chunkId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "translationChapterId", + "columnName": "translationChapterId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "text", + "columnName": "text", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "index", + "columnName": "index", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "signature", + "columnName": "signature", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "relayHint", + "columnName": "relayHint", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "groupSignedEventId", + "columnName": "groupSignedEventId", + "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" + ] + }, + "foreignKeys": [ + { + "table": "MantraChunk", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chunkId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "MantraTranslationChapter", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "translationChapterId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "ChatRoom", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chatRoomId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "MantraTranslationContributor", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `dTag` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `translationId` TEXT NOT NULL, `translatorPublicKey` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`translationId`) REFERENCES `MantraTranslation`(`id`) 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": "TEXT", + "notNull": true + }, + { + "fieldPath": "dTag", + "columnName": "dTag", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "translationId", + "columnName": "translationId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "translatorPublicKey", + "columnName": "translatorPublicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "signature", + "columnName": "signature", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "relayHint", + "columnName": "relayHint", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "groupSignedEventId", + "columnName": "groupSignedEventId", + "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" + ] + }, + "foreignKeys": [ + { + "table": "MantraTranslation", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "translationId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "ChatRoom", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "chatRoomId" + ], + "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, `payloadEventId` 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": "payloadEventId", + "columnName": "payloadEventId", + "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": "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, 'b8e051243c6c16c1ebefd2e9f7f56ccb')" + ] + } +} \ 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 fa7d0073..7232b68b 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -196,6 +196,11 @@ Propose translation Publish new key package Re-broadcast + Asked the members who have not answered to take another look + Everyone has answered. There is nobody left to ask. + One member has not answered. They may never have received it. + %1$s members have not answered. They may never have received it. + Asked again just now. You can ask again in a few minutes. Read to the end of the list to sign. Recovery phrase Ready to sign diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/database/CurareDatabase.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/database/CurareDatabase.kt index 7293adc0..c28e6ba3 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/database/CurareDatabase.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/database/CurareDatabase.kt @@ -187,7 +187,7 @@ val GENESIS_AT = Instant.fromEpochMilliseconds(1231006505000L) UnsignedNostrEvent::class, Zap::class ], - version = 24, + version = 25, autoMigrations = [ // v2 only adds the DkgSession/DkgParticipantMessage tables, so Room can // generate the migration itself — nothing existing changes shape. @@ -362,6 +362,12 @@ val GENESIS_AT = Instant.fromEpochMilliseconds(1231006505000L) // an obligation forgotten at a crash is a replacement commit at the next // start, which forks the group against whoever took the first one. AutoMigration(from = 23, to = 24), + // v25 adds FrostSigningSession.resentAt: when the coordinator last + // re-published a signing session for the members it had heard nothing + // from (docs/frost-session-resend.md, Phase 2). Nullable and nothing is + // backfilled -- a session that has never been resent reads null, which + // is what every session before the column was. + AutoMigration(from = 24, to = 25), ] ) @ConstructedBy(CurareDatabaseConstructor::class) diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/database/dao/FrostSigningSessionDao.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/database/dao/FrostSigningSessionDao.kt index da75571e..57fcd390 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/database/dao/FrostSigningSessionDao.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/database/dao/FrostSigningSessionDao.kt @@ -91,6 +91,17 @@ interface FrostSigningSessionDao { @Query("SELECT * FROM FrostSignerMessage WHERE sessionId = :sessionId ORDER BY createdAt ASC") fun observeMessages(sessionId: String): Flow> + /** + * Every message a session has received, of every kind. + * + * What a resend reads to work out who has said nothing at all: a member with + * any row here has answered -- offered a nonce, signed their part, or + * refused -- and is not somebody to knock on the door of. See + * `FrostSigningManager.silentMembers`. + */ + @Query("SELECT * FROM FrostSignerMessage WHERE sessionId = :sessionId ORDER BY createdAt ASC") + suspend fun getMessagesForSession(sessionId: String): List + @Query("SELECT COUNT(*) FROM FrostSignerMessage WHERE sessionId = :sessionId AND kind = :kind") suspend fun countMessagesByKind(sessionId: String, kind: Kind): Int diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/database/dao/GiftWrapPayloadDao.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/database/dao/GiftWrapPayloadDao.kt index ff0ceaac..fe5c1037 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/database/dao/GiftWrapPayloadDao.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/database/dao/GiftWrapPayloadDao.kt @@ -53,6 +53,15 @@ interface GiftWrapPayloadDao { @Upsert suspend fun upsert(giftWrapPayload: GiftWrapPayload) + /** + * One row by its id. The same job as `MarmotInnerEventDao.getById`, for the + * other transport: an id is a hash over `created_at` to the second, so a + * re-publish inside that second collides with the copy it is repeating and + * an upsert would un-send it. + */ + @Query("SELECT * FROM GiftWrapPayload WHERE id = :id") + suspend fun getById(id: String): GiftWrapPayload? + @Insert suspend fun insert(giftWrapPayload: GiftWrapPayload) } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/database/dao/MarmotInnerEventDao.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/database/dao/MarmotInnerEventDao.kt index 685cba7e..17723db4 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/database/dao/MarmotInnerEventDao.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/database/dao/MarmotInnerEventDao.kt @@ -37,6 +37,21 @@ interface MarmotInnerEventDao { @Upsert suspend fun upsert(marmotInnerEvent: MarmotInnerEvent) + /** + * One row by its id, for a caller that has to know whether an id is taken + * before it writes one. + * + * An outbound row's id is a hash over the fields the rumor will be assembled + * from, `created_at` among them and stored to the second -- so re-publishing + * the same message inside the same second as the first copy computes the + * same id. Upserting it would put an already-sent row back on the queue with + * `marmotGroupEventId` cleared, which double-sends it and loses its mapping + * to the group event it became. `FrostSigningManager.broadcast` checks here + * first. + */ + @Query("SELECT * FROM MarmotInnerEvent WHERE id = :id") + suspend fun getById(id: String): MarmotInnerEvent? + /** * A room's inner events of the given kinds, oldest first. * diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/database/model/ChatMessage.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/database/model/ChatMessage.kt index 002c673e..22048622 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/database/model/ChatMessage.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/database/model/ChatMessage.kt @@ -291,6 +291,19 @@ data class ChatMessage( */ const val TYPE_FROST_DECLINED = "frostDeclined" + /** + * The coordinator re-published a session for the members it had heard + * nothing from. + * + * Its own type rather than a step, because nothing moved: somebody + * knocked. A session can be left waiting on a member whose copy of the + * proposal never arrived -- MLS dropped the generation, or a + * disappearing-message group expired it off the relay -- and a resend is + * the only thing that reaches them. The line exists so a second knock + * reads as a second knock. See docs/frost-session-resend.md. + */ + const val TYPE_FROST_RESENT = "frostResent" + /** Addressed to the reader rather than said by anyone -- see [DKG_REQUEST_TYPES]. */ const val TYPE_FROST_APPROVAL_NEEDED = "frostApprovalNeeded" @@ -337,6 +350,7 @@ data class ChatMessage( TYPE_FROST_COMPLETE, TYPE_FROST_FAILED, TYPE_FROST_DECLINED, + TYPE_FROST_RESENT, TYPE_FROST_APPROVAL_NEEDED, ) @@ -354,6 +368,7 @@ data class ChatMessage( TYPE_FROST_SIGNATURE, TYPE_FROST_FAILED, TYPE_FROST_DECLINED, + TYPE_FROST_RESENT, ) val DKG_AUTHORED_TYPES = setOf( diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/database/model/FrostSigningSession.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/database/model/FrostSigningSession.kt index b0f6df74..b5b4b86e 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/database/model/FrostSigningSession.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/database/model/FrostSigningSession.kt @@ -152,6 +152,21 @@ data class FrostSigningSession( /** Whether the chat line asking for that approval has been written. */ val approvalRequestedAt: Instant? = null, + /** + * When the coordinator last re-published this session, or null if never. + * + * Two jobs, and the second one is not cosmetic. It is the cooldown -- a + * resend is a publish, and a control that publishes on every tap fills a + * room with duplicates. And it keeps a second resend out of the same second + * as the first, where an outbound row's primary key is a hash over + * `createdAt` and a collision would replace a sent row with an unsent one; + * see `FrostSigningManager.broadcast`. + * + * Only ever written on the coordinator's own row. Null is what every + * session predating the column reads back as, which is what they all were. + */ + val resentAt: Instant? = null, + override val createdAt: Instant = Clock.System.now(), override val updatedAt: Instant = createdAt, override val savedAt: Instant = createdAt, diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/database/repository/DatabaseFrostSigningRepository.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/database/repository/DatabaseFrostSigningRepository.kt index 1cb928e8..aa9daa47 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/database/repository/DatabaseFrostSigningRepository.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/database/repository/DatabaseFrostSigningRepository.kt @@ -114,6 +114,20 @@ class DatabaseFrostSigningRepository( null } + override suspend fun resend(localChatRoom: LocalChatRoom, sessionId: String): Boolean = try { + FrostSigningManager.resend( + database = database, + localChatRoom = localChatRoom, + sessionId = sessionId + ) + } catch (e: Throwable) { + // False rather than rethrown, for the reason `approve` swallows: a + // resend is a repair, and a repair that takes the screen down with it is + // worse than one that did not happen. + logger.e("Error resending signing session $sessionId", e) + false + } + override suspend fun approve(localChatRoom: LocalChatRoom, sessionId: String) { try { FrostSigningManager.approve( diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/managers/FrostSigningManager.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/managers/FrostSigningManager.kt index 36721e62..26b82557 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/managers/FrostSigningManager.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/managers/FrostSigningManager.kt @@ -20,7 +20,9 @@ import fr.acinq.bitcoin.crypto.frost.SecretNonce import fr.acinq.bitcoin.crypto.frost.Session import fr.acinq.bitcoin.utils.Either import kotlin.time.Clock +import kotlin.time.Duration import kotlin.time.Instant +import kotlin.time.Duration.Companion.minutes import kotlinx.coroutines.CancellationException import to.curare.compose.database.CurareDatabase import to.curare.compose.database.model.ChatMessage @@ -152,6 +154,39 @@ object FrostSigningManager { */ const val MAX_BATCH_SIZE: Int = 64 + /** + * How many seconds [broadcast] will step forward looking for an unused + * outbound row id before giving up and publishing nothing. + * + * Only a repeat can collide at all -- a first publish differs from every + * stored row in its content or its kind -- so this is the number of times + * the same message can be re-published within one second. Four is past + * anything a person pressing a button can do, and the cooldown on + * `FrostSigningSession.resentAt` keeps it far from the limit. + */ + private const val MAX_ID_SEARCH: Int = 4 + + /** + * How long after a resend the coordinator may send another. + * + * A resend is a publish. Without a floor under it a control that repeats a + * 64-event proposal becomes a control that fills a room with them, and two + * taps inside one second collide on the outbound row id -- see [broadcast]. + * Long enough that a second knock means a person decided to knock again, + * short enough to be useful while somebody is watching the screen. + */ + val RESEND_COOLDOWN: Duration = 5.minutes + + /** + * The kinds a member authors for a session, and so the ones [republishOwn] + * may repeat. Everything else on the session is the coordinator's. + */ + private val OWN_KINDS: List = listOf( + FrostSigningEvents.NONCE, + FrostSigningEvents.PARTIAL_SIGNATURE, + FrostSigningEvents.DECLINE + ) + /** * Opens a signing session, making this device the coordinator. * @@ -357,6 +392,22 @@ object FrostSigningManager { return } + // A resent proposal can carry the coordinator saying it has heard nothing + // from this device. If it has, this device says it again -- the same + // bytes, under its own key, because nobody else can send them for it. + // + // Ahead of [record] and [advance] so that a nonce lost on its way to the + // coordinator goes out on the same pass that learns it was lost. Only + // from the coordinator, and only messages already on file: see + // [republishOwn]. + if (innerEvent.kind == FrostSigningEvents.PROPOSAL && + innerEvent.pubKey == session.coordinatorPublicKey && + FrostSigningEvents.parseSilentMembers(innerEvent.tags) + ?.contains(session.userPublicKey) == true + ) { + republishOwn(database, localChatRoom, session) + } + if (!record(database, session, innerEvent)) return advance(database, localChatRoom, session.id) @@ -1816,6 +1867,260 @@ object FrostSigningManager { * because the local copy is not just a copy: filing it is what may end the * session, and [recordDecline] is the one place that decides. */ + /** + * Re-publishes what this device wrote for a session, for the members it has + * heard nothing from. Returns whether anything went out. + * + * A member can be left with nothing at all for a session they would have + * agreed to. Several ways, and only some of them heal on their own: a group + * event that decrypted to nothing because MLS had moved its ratchet past the + * generation it arrived at, which is terminal at the receiver and invisible + * to the sender (`docs/mls-skipped-keys.md`); a disappearing-message group + * whose kind:445 expired off the relay before they synced; a member added to + * the room after the proposal, holding a share from an earlier ceremony. In + * each of them the session sits in [FrostSigningStage.COLLECTING_NONCES] + * until somebody gives up, and the member it was waiting on never knew. + * + * A resend repairs all three because a resent message is a *new* message: + * new `created_at`, new id, encrypted at a generation the receiver has not + * passed, carrying a fresh expiry. + * + * ### Only this device's own messages, and only the coordinator's + * + * What goes out is the proposal, the signer set and the signature -- the + * three the coordinator authors. A member's nonce, partial signature or + * refusal is not resent and cannot be: [record] files a signer's message + * under the inner event's own `pubKey`, so a relayed copy would be filed + * under the relayer, and for a refusal that is a way to manufacture one. + * Nor is there a need. A nonce and a partial signature are read by nobody + * but the coordinator -- [orderedNonces] and [orderedPartialSignatures] are + * both called under `isCoordinator` -- and the coordinator already holds + * them, which is how it knows who is quiet. What the resend does for a + * silent member instead is name them, in `FrostSilentMembersTag`, so their + * own device republishes what it already said. See [republishOwn]. + * + * Coordinator-only, and that is correctness rather than etiquette. + * [acceptProposal] takes `coordinatorPublicKey` from the proposal's author, + * so a non-coordinator resending it to a member with no session row would + * have that member believe the resender coordinates -- and then drop the + * real coordinator's signer set through [isFromCoordinator]. + * + * ### The minimum the stage requires + * + * | stage | what goes out | + * |---|---| + * | [FrostSigningStage.COLLECTING_NONCES] | the proposal | + * | [FrostSigningStage.COLLECTING_PARTIAL_SIGNATURES] | the proposal, then the signer set | + * | [FrostSigningStage.COMPLETE] | the proposal, then the signature | + * | [FrostSigningStage.FAILED] | nothing -- refused | + * + * The proposal goes in every case because a device with no session row can + * apply nothing else: a signer set naming ids it has no items for, and a + * signature over events it has never seen, are both dropped. + * [FrostSigningStage.COMPLETE] is worth repeating rather than skipping -- + * a member who never received the signature never ran [complete], so the + * signed events were never applied to their store. + * + * Two and not three, deliberately. Publishing in bursts is what the + * skipped-keys bug feeds on, and a recovery for it that re-creates it is no + * recovery. `MlsGroupCache` covers a burst decrypted in one sync, which is + * what makes [proposeSigningBatch]'s own two-message burst work; this stays + * inside the same budget. + * + * A failed session is refused rather than repaired. Its items' nonce seeds + * have been published against an aggregate already, so the retry is a fresh + * proposal and never this one again -- which is what [fail] tells the group. + */ + suspend fun resend( + database: CurareDatabase, + localChatRoom: LocalChatRoom, + sessionId: String + ): Boolean { + val session = database.frostSigningSessionDao().getSessionById(sessionId) ?: return false + + if (!session.isCoordinator()) { + logger.i("Session $sessionId was not proposed by this device; it is not ours to resend") + return false + } + + if (session.stage == FrostSigningStage.FAILED) { + logger.i("Session $sessionId was abandoned; nothing to resend. Propose afresh instead") + return false + } + + val items = database.frostSigningSessionDao().getItems(sessionId) + if (items.isEmpty()) { + logger.w("Session $sessionId holds no items; nothing to resend") + return false + } + + val now = Clock.System.now() + session.resentAt?.let { last -> + if (now - last < RESEND_COOLDOWN) { + logger.i("Session $sessionId was resent less than $RESEND_COOLDOWN ago; not again yet") + return false + } + } + + val silent = silentMembers(database, session) + if (silent.isEmpty()) { + logger.i("Session $sessionId has heard from every share holder; nothing to resend") + return false + } + + val unsigned = items.mapNotNull { Event.fromJsonOrNull(it.unsignedEventJson) } + if (unsigned.size != items.size) { + // Refused rather than shortened. A proposal that quietly lost an + // event would have every signer's contribution rejected for being + // the wrong length, which is a stall with nothing to blame. + logger.w( + "Session $sessionId: only ${unsigned.size} of ${items.size} stored events could " + + "be read; not resending a proposal that is missing one" + ) + return false + } + + logger.i( + "Resending session $sessionId at ${session.stage} to ${silent.size} member(s) " + + "(${silent.joinToString { it.take(8) }})" + ) + + // The proposal first, so a device that has nothing has somewhere to file + // what follows it. + broadcast( + database = database, + localChatRoom = localChatRoom, + session = session, + kind = FrostSigningEvents.PROPOSAL, + content = FrostSigningEvents.encodeProposal(unsigned), + includeKey = true, + silentMembers = silent.toList(), + recipients = silent + ) + + when (session.stage) { + FrostSigningStage.COLLECTING_PARTIAL_SIGNATURES -> { + val chosen = session.signerIdList() + val aggregated = items.map { it.aggregatedNonce } + if (chosen != null && aggregated.all { it != null }) { + broadcast( + database = database, + localChatRoom = localChatRoom, + session = session, + kind = FrostSigningEvents.SIGNER_SET, + content = joinPayload(aggregated.map { it!! }), + signerIds = chosen, + recipients = silent + ) + } + } + + FrostSigningStage.COMPLETE -> { + val signatures = items.map { it.signature } + if (signatures.all { it != null }) { + broadcast( + database = database, + localChatRoom = localChatRoom, + session = session, + kind = FrostSigningEvents.SIGNATURE, + content = joinPayload(signatures.map { it!! }), + recipients = silent + ) + } + } + + FrostSigningStage.COLLECTING_NONCES, FrostSigningStage.FAILED -> Unit + } + + update(database, session) { it.copy(resentAt = now) } + announceResent(database, session, silent.size) + + return true + } + + /** + * The share holders this session has heard nothing at all from. + * + * Off the ceremony rather than off the room, like [recordDecline]'s own + * count and `FrostSigningUIState.Loaded.members`: a room can hold members + * added after its key was made who hold no share, and a subgroup's ceremony + * room is the parent, which holds everybody the subgroup is not. A door that + * cannot answer is not one to knock on. + * + * A member who declined is not silent. They answered, and the session is + * counting their refusal; knocking again would be asking a question they + * have already closed. + */ + private suspend fun silentMembers( + database: CurareDatabase, + session: FrostSigningSession + ): Set { + val key = database.dkgSessionDao().getSessionById(session.dkgSessionId) ?: return emptySet() + val holders = signerIds(database, key).keys + + val heardFrom = database.frostSigningSessionDao() + .getMessagesForSession(session.id) + .map { it.signerPublicKey } + .toSet() + + return holders - heardFrom - session.userPublicKey + } + + /** + * Re-publishes the messages *this* device authored for a session, because + * the coordinator says it never received them. + * + * The other half of a resend, and the only half that can repair a signal + * lost on its way *to* the coordinator. [advance] republishes a message it + * has no local copy of; a device that published its nonce and recorded it + * has a copy, so it will never send that nonce again however long the + * coordinator waits. This is how it learns to. + * + * The stored bytes, never regenerated. They are byte-identical either way -- + * `SecretNonce.generate` is deterministic in the seed and the message, and + * an item's message cannot change -- so this cannot produce a second nonce + * for one message, which is the thing the whole design is arranged to make + * impossible. Reading the row just avoids k native key generations to arrive + * at the same answer. + * + * **It publishes nothing new.** Only messages already on file go out, so a + * device whose owner has not decided sends nothing and falls through to + * [advance], which does what it always does: write the approval request and + * wait on a person. A message from the coordinator must never be able to + * talk a device into putting its share behind events its owner has not + * agreed to -- that is [acceptProposal]'s "publishes nothing" rule, and the + * gate enforcing it is untouched. + * + * Caller checks that the request came from the coordinator. A member who + * could name another member as silent could make them publish on demand -- + * the same bytes they already sent, so nothing on the wire changes, but it + * is not a trigger to leave lying around. + */ + private suspend fun republishOwn( + database: CurareDatabase, + localChatRoom: LocalChatRoom, + session: FrostSigningSession + ) { + val own = OWN_KINDS.mapNotNull { kind -> ownMessage(database, session, kind) } + if (own.isEmpty()) return + + logger.i( + "Session ${session.id}: the coordinator has not heard from this device; " + + "republishing ${own.size} message(s) it already sent" + ) + + own.forEach { message -> + broadcast( + database = database, + localChatRoom = localChatRoom, + session = session, + kind = message.kind, + content = message.payload, + recipients = setOf(session.coordinatorPublicKey) + ) + } + } + private suspend fun publishDecline( database: CurareDatabase, localChatRoom: LocalChatRoom, @@ -1839,6 +2144,34 @@ object FrostSigningManager { ) } + /** + * The line saying the coordinator knocked again. + * + * Its own type rather than another step: nothing moved, somebody asked. The + * ladder should show that the knock happened so that a second one reads as a + * second one -- which `FrostSigningSession.resentAt` makes true, since it is + * what stops a tap from writing a line without publishing anything. + * + * Counted rather than named. Who is quiet is on the screen above this line, + * member by member, and a transcript line listing four pubkeys is a line + * nobody reads. + */ + private suspend fun announceResent( + database: CurareDatabase, + session: FrostSigningSession, + silent: Int + ) { + announce( + database = database, + session = session, + messageType = ChatMessage.TYPE_FROST_RESENT, + content = "asked " + + (if (silent == 1) "the member" else "the $silent members") + + " who have not answered to take another look.", + actor = session.coordinatorPublicKey + ) + } + private suspend fun announceStarted(database: CurareDatabase, session: FrostSigningSession) { val count = database.frostSigningSessionDao().countItems(session.id) @@ -1979,6 +2312,10 @@ object FrostSigningManager { * has no local copy of. A crash between the two therefore costs a duplicate * broadcast — which every receiver folds away — rather than a message the * group waits on forever. + * + * Which cuts both ways, so a [broadcast] that queued nothing records + * nothing: the local copy is the thing that stops the next pass from trying + * again. */ private suspend fun publishOwn( database: CurareDatabase, @@ -1987,7 +2324,11 @@ object FrostSigningManager { kind: Kind, content: String ) { - broadcast(database, localChatRoom, session, kind, content) + // Nothing is recorded if nothing was queued. The local copy is what stops + // [advance] from publishing this again, so writing one for a message that + // did not go out would be a message the group waits on forever -- the + // opposite of the trade this order is for. + if (!broadcast(database, localChatRoom, session, kind, content)) return val known = ownMessage(database, session, kind) != null @@ -2033,12 +2374,15 @@ object FrostSigningManager { kind: Kind, content: String, includeKey: Boolean = false, - signerIds: List? = null - ) { + signerIds: List? = null, + silentMembers: List? = null, + recipients: Set? = null + ): Boolean { val sessionTags = FrostSigningEvents.assembleTags( sessionId = session.id, dkgSessionId = if (includeKey) session.dkgSessionId else null, - signerIds = signerIds + signerIds = signerIds, + silentMembers = silentMembers ) // No MLS state is what marks a room NIP-17 -- the same reading @@ -2049,20 +2393,55 @@ object FrostSigningManager { val tags = if (isMarmotRoom) { sessionTags } else { - recipientTags(localChatRoom, session.userPublicKey) + sessionTags + recipientTags(localChatRoom, session.userPublicKey, recipients) + sessionTags } - val createdAt = Clock.System.now().epochSeconds - // The rumor id the outbound pipeline will recompute from these same - // fields when it assembles the event to encrypt, on either transport. - val id = EventHasher.hashId( + // fields when it assembles the event to encrypt, on either transport -- + // and with it the second this message claims to have been written in, + // because that second is one of the fields. + // + // Which is why this is a search and not an assignment. `created_at` is + // stored to the second, so a message re-published inside the same second + // as the copy it repeats hashes to the same id; upserting that would put + // an already-sent row back on the outbound queue with its + // `marmotGroupEventId` cleared -- sending the message twice and losing + // the row's mapping to the group event it became. So an id already in + // the store is stepped past rather than written over. One second of drift + // per collision is nothing a protocol message reads, and no caller + // publishes faster than [MAX_ID_SEARCH] identical messages a second. + var createdAt = Clock.System.now().epochSeconds + var id = EventHasher.hashId( pubKey = session.userPublicKey, createdAt = createdAt, tags = tags, content = content, kind = kind ) + var attempts = 0 + + while (attempts < MAX_ID_SEARCH && isQueued(database, isMarmotRoom, id)) { + createdAt += 1 + id = EventHasher.hashId( + pubKey = session.userPublicKey, + createdAt = createdAt, + tags = tags, + content = content, + kind = kind + ) + attempts += 1 + } + + // Refused rather than written over. The row this would replace is a + // message this device has already queued or sent, and clearing its + // mapping is strictly worse than not repeating it. + if (attempts >= MAX_ID_SEARCH) { + logger.w( + "Session ${session.id}: kind $kind already queued at every second tried; " + + "not publishing it again" + ) + return false + } if (isMarmotRoom) { database.marmotInnerEventDao().upsert( @@ -2089,6 +2468,19 @@ object FrostSigningManager { ) ) } + + return true + } + + /** Whether this id is already an outbound row on the room's transport. */ + private suspend fun isQueued( + database: CurareDatabase, + isMarmotRoom: Boolean, + id: HexKey + ): Boolean = if (isMarmotRoom) { + database.marmotInnerEventDao().getById(id) != null + } else { + database.giftWrapPayloadDao().getById(id) != null } /** @@ -2098,13 +2490,22 @@ object FrostSigningManager { * per recipient and this device already has its own copy -- `publishOwn` * records it locally. Deduplicated by member, since `localParticipants` is a * row list and a room can carry the same person twice. + * + * [only] narrows it, for a resend: a wrap is sealed per recipient, so + * repeating a message for the two members who missed it costs two wraps + * rather than the room's worth. Null means everybody, which is what every + * first-time publish wants -- and a narrowing that matched nobody is read as + * null rather than as a message addressed to no one, since an untagged + * NIP-17 payload reaches nobody at all. */ private fun recipientTags( localChatRoom: LocalChatRoom, - senderPublicKey: HexKey + senderPublicKey: HexKey, + only: Set? = null ): Array> = localChatRoom.localParticipants .distinctBy { it.participant.participantPublicKey } .filter { it.participant.participantPublicKey != senderPublicKey } + .filter { only.isNullOrEmpty() || it.participant.participantPublicKey in only } .map { localParticipant -> PTag.assemble( localParticipant.participant.participantPublicKey, diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/nostr/frost/FrostSigningEvents.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/nostr/frost/FrostSigningEvents.kt index 1bdfcf97..5dc55b0a 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/nostr/frost/FrostSigningEvents.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/nostr/frost/FrostSigningEvents.kt @@ -1,12 +1,14 @@ package to.curare.compose.nostr.frost import com.vitorpamplona.quartz.nip01Core.core.Event +import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.core.Kind import kotlinx.serialization.json.jsonArray import to.curare.compose.network.serialization.CommonJson import to.curare.compose.nostr.frost.tags.FrostKeyTag import to.curare.compose.nostr.frost.tags.FrostSessionIdTag import to.curare.compose.nostr.frost.tags.FrostSignerIdsTag +import to.curare.compose.nostr.frost.tags.FrostSilentMembersTag /** * The nostr kinds a FROST signing session is carried on. @@ -121,15 +123,22 @@ object FrostSigningEvents { /** * Tags for a signing message. The session id is on every kind so a message * from an abandoned attempt can be dropped rather than mixed in. + * + * [silentMembers] rides a resent proposal and nothing else. It is additive + * in the only sense that matters: a build that does not know the tag ignores + * it and accepts the proposal it is attached to, which is the half of a + * resend that fixes the common case anyway. See [FrostSilentMembersTag]. */ fun assembleTags( sessionId: String, dkgSessionId: String? = null, - signerIds: List? = null + signerIds: List? = null, + silentMembers: List? = null ): Array> = buildList { add(FrostSessionIdTag.assemble(sessionId)) dkgSessionId?.let { add(FrostKeyTag.assemble(it)) } signerIds?.let { add(FrostSignerIdsTag.assemble(it)) } + silentMembers?.takeIf { it.isNotEmpty() }?.let { add(FrostSilentMembersTag.assemble(it)) } }.toTypedArray() fun parseSessionId(tags: Array>): String? = @@ -141,6 +150,13 @@ object FrostSigningEvents { fun parseSignerIds(tags: Array>): List? = tags.firstNotNullOfOrNull(FrostSignerIdsTag::parse)?.signerIds + /** + * Who the coordinator says it has not heard from, or null on any proposal + * that is not a resend. + */ + fun parseSilentMembers(tags: Array>): List? = + tags.firstNotNullOfOrNull(FrostSilentMembersTag::parse)?.members + /** * The unsigned events of a proposal, as its content. * diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/nostr/frost/tags/FrostSilentMembersTag.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/nostr/frost/tags/FrostSilentMembersTag.kt new file mode 100644 index 00000000..e2638d0c --- /dev/null +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/nostr/frost/tags/FrostSilentMembersTag.kt @@ -0,0 +1,74 @@ +package to.curare.compose.nostr.frost.tags + +import com.vitorpamplona.quartz.nip01Core.core.HexKey +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +/** + * The share holders a coordinator has heard nothing from, carried on a resent + * proposal. + * + * A proposer can resend what the proposer wrote, and nothing else: a nonce or a + * refusal relayed by somebody else is filed under the relayer -- see + * `FrostSigningManager.record`, which keys a signer's message on the inner + * event's own `pubKey` -- and for a refusal that is a way to manufacture one. + * So the resend names the quiet members instead, and their own devices + * republish what they already said, under the keys that said it. + * + * It names rather than counts because a count cannot be acted on. A device + * reading this tag is asking one question -- am I in it -- and the answer has + * to be about them specifically. + * + * Only the coordinator's tag is honoured, and only to republish messages that + * are already on file. Nothing here can talk a device into publishing a nonce + * its owner has not approved; that gate is `advance`'s, and this does not reach + * it. See `FrostSigningManager.republishOwn`. + * + * Carrying it leaks nothing. On Marmot every nonce is a group event the whole + * room received, and on NIP-17 every member is p-tagged on every message, so + * who has spoken is not a secret this could give away. + */ +class FrostSilentMembersTag( + val members: List, +) { + fun toTagArray() = assemble(members = members) + + companion object { + const val TAG_NAME = "frost_silent" + + /** The length of a nostr public key in hex, which is what this list holds. */ + private const val KEY_LENGTH = 64 + + /** + * All or nothing, like [FrostSignerIdsTag]: a list naming the wrong + * people is worse than no list. One unreadable entry means the whole tag + * is dropped -- and the resend then simply nudges nobody, which is the + * same as a build that does not write the tag at all. + */ + fun parse(tag: Array): FrostSilentMembersTag? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + + val members = tag[1].split(",").map { entry -> + entry.trim().lowercase().takeIf { it.isHexKey() } ?: return null + } + if (members.isEmpty()) return null + + return FrostSilentMembersTag(members = members) + } + + /** + * Lowercased, because a pubkey is compared against + * `FrostSigningSession.userPublicKey` by string equality and a tag that + * shouted would name nobody. + */ + fun assemble(members: List): Array = + arrayOf(TAG_NAME, members.joinToString(",") { it.lowercase() }) + + fun assemble(frostSilentMembersTag: FrostSilentMembersTag) = + assemble(members = frostSilentMembersTag.members) + + private fun String.isHexKey(): Boolean = + length == KEY_LENGTH && all { it in '0'..'9' || it in 'a'..'f' } + } +} diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/repository/FrostSigningRepository.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/repository/FrostSigningRepository.kt index f16c42ba..41ec4783 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/repository/FrostSigningRepository.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/repository/FrostSigningRepository.kt @@ -126,6 +126,30 @@ interface FrostSigningRepository { dependents: (lead: Event) -> List> ): FrostSigningSession? + /** + * Re-publishes the messages this device wrote for a session, for the members + * it has heard nothing from. + * + * For a session left waiting on a member who has nothing to answer with: a + * group event that decrypted to nothing because MLS had moved past the + * generation it arrived at, a disappearing-message group that expired it off + * the relay, a member added to the room after the proposal was made. A + * resent message is a new message, so it is readable where the first one was + * not. + * + * **The coordinator's own messages, and nobody else's.** A member's nonce is + * read by nobody but the coordinator, who already has it -- which is how it + * knows who is quiet -- so there is nothing of theirs to repeat. And a + * message relayed by somebody else would be filed under the relayer, which + * for a refusal is a way to manufacture one. What the resend does for a + * silent member is name them, so their own device republishes what it + * already said. + * + * Returns false when there was nothing to do: not this device's session, + * already abandoned, nobody quiet, or inside the cooldown. + */ + suspend fun resend(localChatRoom: LocalChatRoom, sessionId: String): Boolean + /** Agrees to sign, letting the session publish this device's part and run on. */ suspend fun approve(localChatRoom: LocalChatRoom, sessionId: String) @@ -189,6 +213,11 @@ interface FrostSigningRepository { dependents: (lead: Event) -> List> ): FrostSigningSession? = null + override suspend fun resend( + localChatRoom: LocalChatRoom, + sessionId: String + ): Boolean = false + override suspend fun approve(localChatRoom: LocalChatRoom, sessionId: String) = Unit override suspend fun decline(localChatRoom: LocalChatRoom, sessionId: String) = Unit diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/FrostSigningScreen.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/FrostSigningScreen.kt index 0bf81af2..f1254e56 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/FrostSigningScreen.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/FrostSigningScreen.kt @@ -13,6 +13,7 @@ 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.Campaign import androidx.compose.material.icons.filled.CheckCircle import androidx.compose.material.icons.filled.Draw import androidx.compose.material.icons.filled.ErrorOutline @@ -34,6 +35,7 @@ import androidx.compose.material3.TextButton import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextAlign @@ -58,7 +60,13 @@ import to.curare.compose.ui.theme.spacing import to.curare.compose.ui.composable.widgets.Decorative import curare.composeapp.generated.resources.Res import org.jetbrains.compose.resources.stringResource +import curare.composeapp.generated.resources.ask_again +import curare.composeapp.generated.resources.asked_again +import curare.composeapp.generated.resources.asked_again_recently import curare.composeapp.generated.resources.declined_to_sign +import curare.composeapp.generated.resources.everyone_has_answered_this_session +import curare.composeapp.generated.resources.members_have_not_answered +import curare.composeapp.generated.resources.one_member_has_not_answered import curare.composeapp.generated.resources.don_t_sign import curare.composeapp.generated.resources.has_not_taken_part_yet import curare.composeapp.generated.resources.members @@ -70,6 +78,7 @@ import curare.composeapp.generated.resources.signed_their_part import curare.composeapp.generated.resources.events_signed_together import androidx.compose.material3.SnackbarHost import to.curare.compose.ui.composable.widgets.LocalSnackbarHostState +import to.curare.compose.ui.composable.widgets.rememberNotifier import to.curare.compose.ui.composable.widgets.NavigateBackButton import to.curare.compose.ui.theme.readableContent import to.curare.compose.ui.theme.ConformancePreviews @@ -115,6 +124,13 @@ fun FrostSigningScreen( } } + // Both of these are composable and an onClick lambda is not, so they are + // read here rather than in the handler. The notifier takes the caller's + // scope on purpose -- see rememberNotifier. + val notify = rememberNotifier(rememberCoroutineScope()) + val askedAgain = stringResource(Res.string.asked_again) + val everyoneAnswered = stringResource(Res.string.everyone_has_answered_this_session) + Scaffold( snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) }, topBar = { @@ -261,6 +277,57 @@ fun FrostSigningScreen( } } + // The coordinator's knock, under the list of doors it is for. + // + // A session can wait forever on a member whose copy of the + // proposal never arrived -- MLS dropped the generation it came + // in at, or a disappearing-message group expired it off the + // relay -- and neither heals on its own. Repeating the proposal + // is the only thing that reaches them, and it also names them, + // so that a member whose own answer went missing on the way + // here says it again. + if (state.canResend) { + HorizontalDivider() + + Text( + text = if (state.silent.size == 1) { + stringResource(Res.string.one_member_has_not_answered) + } else { + stringResource( + Res.string.members_have_not_answered, + state.silent.size + ) + }, + style = MaterialTheme.typography.bodySmall + ) + + // Disabled rather than hidden while the cooldown runs. A + // control that vanishes after a tap reads as one that + // failed, and what happened is that it worked. + val waiting = state.resendAvailableAt != null + + if (waiting) { + Text( + text = stringResource(Res.string.asked_again_recently), + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + } + + Button( + enabled = !waiting && !frostSigningViewModel.isActionPending.value, + onClick = { + frostSigningViewModel.resend { sent -> + notify(if (sent) askedAgain else everyoneAnswered) + } + } + ) { + Icon(Icons.Default.Campaign, contentDescription = Decorative) + Spacer(modifier = Modifier.width(MaterialTheme.spacing.space125)) + Text(stringResource(Res.string.ask_again)) + } + } + // Asked rather than re-derived: the manager owns when a session // is still waiting on its owner, and a second copy of that rule // here is a second copy to keep in step. diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/widgets/chat/ChatTranscript.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/widgets/chat/ChatTranscript.kt index c3da195e..d7631fc2 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/widgets/chat/ChatTranscript.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/widgets/chat/ChatTranscript.kt @@ -33,6 +33,7 @@ import androidx.compose.material.icons.filled.CheckCircle import androidx.compose.material.icons.filled.ChevronRight import androidx.compose.material.icons.filled.ErrorOutline import androidx.compose.material.icons.filled.CallMerge +import androidx.compose.material.icons.filled.Campaign import androidx.compose.material.icons.filled.FactCheck import androidx.compose.material.icons.filled.Draw import androidx.compose.material.icons.filled.Download @@ -825,6 +826,10 @@ private fun RitualNotice( // A refusal the session survived. Quiet on purpose: it is not an error, // and the one that ends a session is written as a failure instead. ChatMessage.TYPE_FROST_DECLINED -> Icons.Default.Block + // Nothing moved; somebody knocked. Its own icon rather than the + // proposal's, so that a resend does not read as a second proposal -- + // which is the one thing a session must never have. + ChatMessage.TYPE_FROST_RESENT -> Icons.Default.Campaign ChatMessage.TYPE_FROST_APPROVAL_NEEDED -> Icons.Default.Draw ChatMessage.TYPE_CHRONICLE_REQUESTED -> Icons.Default.History diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/model/FrostSigningViewModel.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/model/FrostSigningViewModel.kt index 1f730feb..08c0a212 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/model/FrostSigningViewModel.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/model/FrostSigningViewModel.kt @@ -133,6 +133,35 @@ class FrostSigningViewModel( } } + /** + * Asks the members this session has heard nothing from to take another look. + * + * Unlike [approve] and [decline] this does not navigate away: the point of + * pressing it is to go on watching whether anybody answers, and the screen + * is the only place that says who has. [onResult] is handed whether anything + * actually went out, so the caller can say which happened -- a resend inside + * the cooldown, or one where everybody has since answered, publishes nothing + * and should not claim to have. + */ + fun resend(onResult: (sent: Boolean) -> Unit) { + val state = frostSigningUIState as? FrostSigningUIState.Loaded ?: return + val sessionId = state.session?.id ?: return + + if (isActionPending.value) return + isActionPending.value = true + + viewModelScope.launch(Dispatchers.IO) { + val sent = frostSigningRepository.resend( + localChatRoom = state.localChatRoom, + sessionId = sessionId + ) + + isActionPending.value = false + + viewModelScope.launch(Dispatchers.Main) { onResult.invoke(sent) } + } + } + fun decline(onDone: () -> Unit) { val state = frostSigningUIState as? FrostSigningUIState.Loaded ?: return val sessionId = state.session?.id ?: return diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/state/FrostSigningUIState.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/state/FrostSigningUIState.kt index cbcedb3b..55e267a3 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/state/FrostSigningUIState.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/state/FrostSigningUIState.kt @@ -1,11 +1,15 @@ package to.curare.compose.ui.view.state import com.vitorpamplona.quartz.nip01Core.core.HexKey +import kotlin.time.Clock +import kotlin.time.Instant import to.curare.compose.database.model.FrostSigningItem import to.curare.compose.database.model.FrostSigningSession import to.curare.compose.database.model.Participant import to.curare.compose.database.model.intermdiate.LocalChatRoom import to.curare.compose.database.model.intermdiate.LocalParticipant +import to.curare.compose.database.model.types.FrostSigningStage +import to.curare.compose.managers.FrostSigningManager sealed interface FrostSigningUIState { data class Loaded( @@ -76,6 +80,52 @@ sealed interface FrostSigningUIState { return inRoom + elsewhere } + + /** + * The share holders this session has heard nothing at all from. + * + * Whose door to knock on, as a set rather than as a list of rows: it is + * what decides whether there is anything to knock about. A member who + * refused is not here -- they answered, and asking again would be asking + * a question they have closed. + * + * Derived rather than collected. Everything it is made of is already on + * this state, and a second flow for it would be a second thing that can + * disagree with the rows the screen draws. + */ + val silent: Set get() = + shareHolders - offeredNonce - signed - declined - localChatRoom.chatRoom.userPublicKey + + /** + * Whether this device may ask the quiet members to take another look. + * + * The coordinator's, and nobody else's: `acceptProposal` takes a + * session's coordinator from the author of the proposal that opened it, + * so a resend from anybody else would have a member who was missing the + * session believe the resender coordinates -- and then drop the real + * coordinator's signer set. See `FrostSigningManager.resend`. + * + * An abandoned session is not resent either. Its nonce seeds have been + * published against an aggregate already, so the retry is a fresh + * proposal, which is what the status line says. + * + * The cooldown is deliberately not read here. A control that vanishes + * after a tap reads as one that failed, so the section stays and the + * button inside it is what goes quiet -- see [resendAvailableAt]. + */ + val canResend: Boolean get() { + val session = session ?: return false + + return session.isCoordinator() && + session.stage != FrostSigningStage.FAILED && + items.isNotEmpty() && + silent.isNotEmpty() + } + + /** When the next resend may go out, or null when one may go out now. */ + val resendAvailableAt: Instant? get() = session?.resentAt + ?.plus(FrostSigningManager.RESEND_COOLDOWN) + ?.takeIf { it > Clock.System.now() } } data class Error( diff --git a/composeApp/src/commonTest/kotlin/to/curare/compose/nostr/frost/FrostSilentMembersTagTest.kt b/composeApp/src/commonTest/kotlin/to/curare/compose/nostr/frost/FrostSilentMembersTagTest.kt new file mode 100644 index 00000000..d6b9b8ca --- /dev/null +++ b/composeApp/src/commonTest/kotlin/to/curare/compose/nostr/frost/FrostSilentMembersTagTest.kt @@ -0,0 +1,109 @@ +package to.curare.compose.nostr.frost + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull +import kotlin.test.assertTrue +import to.curare.compose.nostr.frost.tags.FrostSilentMembersTag + +/** + * The tag a resent proposal carries, and what a reader makes of a bad one. + * + * It names the members a coordinator has heard nothing from, and a device reads + * it to decide whether to republish its own messages. So the thing worth + * testing is not the happy round trip but the failure: a list that named the + * wrong people would have the wrong device speak, and a tag that is dropped + * nudges nobody -- which is exactly what a build predating the tag does, and so + * the safe way to fail. + */ +class FrostSilentMembersTagTest { + private val alice = "a".repeat(64) + private val bob = "b".repeat(64) + + @Test + fun `a list of members round trips in order`() { + val assembled = FrostSilentMembersTag.assemble(listOf(alice, bob)) + + val parsed = FrostSilentMembersTag.parse(assembled) + + assertEquals(listOf(alice, bob), parsed?.members) + } + + @Test + fun `one member round trips`() { + val parsed = FrostSilentMembersTag.parse(FrostSilentMembersTag.assemble(listOf(alice))) + + assertEquals(listOf(alice), parsed?.members) + } + + @Test + fun `an uppercase key is lowercased, because it is compared by string equality`() { + // userPublicKey on a session is lowercase hex, and `contains` on the + // parsed list is how a device decides whether it is being asked to + // speak. A tag that shouted would name nobody. + val assembled = FrostSilentMembersTag.assemble(listOf(alice.uppercase())) + + assertEquals(listOf(alice), FrostSilentMembersTag.parse(assembled)?.members) + } + + @Test + fun `one unreadable entry drops the whole tag`() { + // All or nothing, like FrostSignerIdsTag. Keeping the readable half + // would be nudging a subset the coordinator never chose. + assertNull(FrostSilentMembersTag.parse(arrayOf(FrostSilentMembersTag.TAG_NAME, "$alice,nonsense"))) + } + + @Test + fun `a key of the wrong length is not a key`() { + assertNull(FrostSilentMembersTag.parse(arrayOf(FrostSilentMembersTag.TAG_NAME, "ab"))) + } + + @Test + fun `an empty list is not a tag`() { + assertNull(FrostSilentMembersTag.parse(arrayOf(FrostSilentMembersTag.TAG_NAME, ""))) + } + + @Test + fun `a tag of another name is not this one`() { + assertNull(FrostSilentMembersTag.parse(arrayOf("p", alice))) + } + + @Test + fun `a tag with no value is not this one`() { + assertNull(FrostSilentMembersTag.parse(arrayOf(FrostSilentMembersTag.TAG_NAME))) + } + + @Test + fun `assembleTags carries the silent members and parses them back`() { + val tags = FrostSigningEvents.assembleTags( + sessionId = "session".padEnd(64, '0'), + silentMembers = listOf(bob) + ) + + assertEquals(listOf(bob), FrostSigningEvents.parseSilentMembers(tags)) + } + + @Test + fun `assembleTags writes no tag when nobody is silent`() { + // An empty list is not a resend that nudges nobody, it is a resend with + // nothing to say -- and an empty tag would parse to null anyway, so + // writing one would only put a lie on the wire. + val tags = FrostSigningEvents.assembleTags( + sessionId = "session".padEnd(64, '0'), + silentMembers = emptyList() + ) + + assertTrue(tags.none { it[0] == FrostSilentMembersTag.TAG_NAME }) + assertNull(FrostSigningEvents.parseSilentMembers(tags)) + } + + @Test + fun `an ordinary proposal's tags name nobody`() { + val tags = FrostSigningEvents.assembleTags( + sessionId = "session".padEnd(64, '0'), + dkgSessionId = "ceremony".padEnd(64, '0') + ) + + assertNull(FrostSigningEvents.parseSilentMembers(tags)) + } +} diff --git a/composeApp/src/commonTest/kotlin/to/curare/compose/ui/view/state/FrostSigningResendStateTest.kt b/composeApp/src/commonTest/kotlin/to/curare/compose/ui/view/state/FrostSigningResendStateTest.kt new file mode 100644 index 00000000..322ca688 --- /dev/null +++ b/composeApp/src/commonTest/kotlin/to/curare/compose/ui/view/state/FrostSigningResendStateTest.kt @@ -0,0 +1,203 @@ +package to.curare.compose.ui.view.state + +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 kotlin.time.Clock +import to.curare.compose.database.model.ChatRoom +import to.curare.compose.database.model.FrostSigningItem +import to.curare.compose.database.model.FrostSigningSession +import to.curare.compose.database.model.Participant +import to.curare.compose.database.model.intermdiate.LocalChatRoom +import to.curare.compose.database.model.intermdiate.LocalParticipant +import to.curare.compose.database.model.types.FrostSigningStage +import to.curare.compose.managers.FrostSigningManager + +/** + * When the signing screen offers to ask the quiet members again, and who it + * counts as quiet. + * + * Both are derived on the state rather than collected, because everything they + * are made of is already there -- the share holders, who offered a nonce, who + * signed, who refused. A second flow for either would be a second thing that + * can disagree with the rows drawn right above the button. + * + * The limits are what this pins. The offer is the coordinator's and nobody + * else's: `acceptProposal` takes a session's coordinator from the author of the + * proposal that opened it, so a resend from anybody else would have a member who + * was missing the session believe the resender coordinates -- and then drop the + * real coordinator's signer set. + */ +class FrostSigningResendStateTest { + private val roomId = "11".repeat(32) + + private val alice = "a".repeat(64) + private val bob = "b".repeat(64) + private val carol = "c".repeat(64) + + private val holders = setOf(alice, bob, carol) + + private fun room(owner: String) = LocalChatRoom( + chatRoom = ChatRoom( + id = roomId, + userPublicKey = owner, + subject = "#Ekklesia", + description = null, + mlsGroupState = null, + ), + localParticipants = holders.sorted().map { publicKey -> + LocalParticipant( + participant = Participant( + participantPublicKey = publicKey, + chatRoomId = roomId, + relayHint = null, + ), + profile = null, + ) + }, + ) + + private fun session( + owner: String = alice, + coordinator: String = alice, + stage: FrostSigningStage = FrostSigningStage.COLLECTING_NONCES, + resentAt: kotlin.time.Instant? = null, + ) = FrostSigningSession( + id = "s".repeat(64), + chatRoomId = roomId, + coordinatorPublicKey = coordinator, + userPublicKey = owner, + dkgSessionId = "ceremony".padEnd(64, '0'), + threshold = 2, + participantCount = 3, + signerId = 0, + resentAt = resentAt, + stage = stage, + ) + + private val item = FrostSigningItem( + sessionId = "s".repeat(64), + itemIndex = 0, + unsignedEventJson = "{}", + eventId = "e".repeat(64), + nonceRandom = "f".repeat(64), + ) + + private fun loaded( + owner: String = alice, + coordinator: String = alice, + stage: FrostSigningStage = FrostSigningStage.COLLECTING_NONCES, + resentAt: kotlin.time.Instant? = null, + offeredNonce: Set = emptySet(), + signed: Set = emptySet(), + declined: Set = emptySet(), + items: List = listOf(item), + ) = FrostSigningUIState.Loaded( + localChatRoom = room(owner), + session = session(owner, coordinator, stage, resentAt), + items = items, + shareHolders = holders, + offeredNonce = offeredNonce, + signed = signed, + declined = declined, + ) + + @Test + fun `the quiet members are the share holders nobody has heard from`() { + val state = loaded(offeredNonce = setOf(bob)) + + // Alice is this device: her own answer is not something to knock about. + assertEquals(setOf(carol), state.silent) + } + + @Test + fun `a member who refused is not quiet`() { + // They answered. Asking again would be asking a question they closed. + assertEquals(setOf(carol), loaded(declined = setOf(bob)).silent) + } + + @Test + fun `a member who signed their part is not quiet`() { + assertEquals(setOf(carol), loaded(signed = setOf(bob)).silent) + } + + @Test + fun `a session nobody has answered is quiet in everybody but its proposer`() { + assertEquals(setOf(bob, carol), loaded().silent) + } + + @Test + fun `the coordinator is offered the resend`() { + assertTrue(loaded().canResend) + } + + @Test + fun `a member who did not propose is not offered it`() { + // Correctness rather than etiquette -- see the class note. + assertFalse(loaded(owner = bob, coordinator = alice).canResend) + } + + @Test + fun `a session everybody has answered has nothing to resend`() { + val state = loaded(offeredNonce = setOf(bob), declined = setOf(carol)) + + assertTrue(state.silent.isEmpty()) + assertFalse(state.canResend) + } + + @Test + fun `an abandoned session is not resent`() { + // Its items' nonce seeds have been published against an aggregate + // already. The retry is a fresh proposal, never this one again. + assertFalse(loaded(stage = FrostSigningStage.FAILED).canResend) + } + + @Test + fun `a signed session can still be resent`() { + // A member who never received the signature never applied the events. + assertTrue(loaded(stage = FrostSigningStage.COMPLETE).canResend) + } + + @Test + fun `a session with no items yet is not resent`() { + assertFalse(loaded(items = emptyList()).canResend) + } + + @Test + fun `a session not yet collected offers nothing`() { + val state = FrostSigningUIState.Loaded(localChatRoom = room(alice)) + + assertFalse(state.canResend) + assertNull(state.resendAvailableAt) + } + + @Test + fun `a session never resent may be resent now`() { + assertNull(loaded().resendAvailableAt) + } + + @Test + fun `a session just resent says when it may go again`() { + val now = Clock.System.now() + val state = loaded(resentAt = now) + + // Read by the screen to disable the button rather than hide the section: + // a control that vanishes after a tap reads as one that failed. + val availableAt = state.resendAvailableAt + assertNotNull(availableAt) + assertEquals(now + FrostSigningManager.RESEND_COOLDOWN, availableAt) + assertTrue(state.canResend, "the offer stands; it is the button that goes quiet") + } + + @Test + fun `a session resent long ago may be resent again`() { + val state = loaded( + resentAt = Clock.System.now() - FrostSigningManager.RESEND_COOLDOWN * 2 + ) + + assertNull(state.resendAvailableAt) + } +} diff --git a/composeApp/src/jvmTest/kotlin/to/curare/compose/managers/FrostSigningResendJvmTest.kt b/composeApp/src/jvmTest/kotlin/to/curare/compose/managers/FrostSigningResendJvmTest.kt new file mode 100644 index 00000000..ffc1df59 --- /dev/null +++ b/composeApp/src/jvmTest/kotlin/to/curare/compose/managers/FrostSigningResendJvmTest.kt @@ -0,0 +1,772 @@ +package to.curare.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.Kind +import fr.acinq.bitcoin.ByteVector32 +import fr.acinq.bitcoin.PrivateKey +import fr.acinq.bitcoin.crypto.frost.Frost +import fr.acinq.bitcoin.crypto.frost.KeyMaterial +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 kotlin.time.Clock +import kotlinx.coroutines.runBlocking +import to.curare.compose.database.CurareDatabase +import to.curare.compose.database.builder.getRoomDatabase +import to.curare.compose.database.model.ChatMessage +import to.curare.compose.database.model.ChatRoom +import to.curare.compose.database.model.DkgParticipantMessage +import to.curare.compose.database.model.DkgSession +import to.curare.compose.database.model.FrostSignerMessage +import to.curare.compose.database.model.FrostSigningItem +import to.curare.compose.database.model.FrostSigningSession +import to.curare.compose.database.model.GiftWrapPayload +import to.curare.compose.database.model.NostrEvent +import to.curare.compose.database.model.Participant +import to.curare.compose.database.model.Profile +import to.curare.compose.database.model.intermdiate.LocalChatRoom +import to.curare.compose.database.model.intermdiate.LocalParticipant +import to.curare.compose.database.model.types.DkgRitualStage +import to.curare.compose.database.model.types.FrostSigningStage +import to.curare.compose.extensions.toHex +import to.curare.compose.nostr.dkg.DkgRitualEvents +import to.curare.compose.nostr.frost.FrostSigningEvents + +/** + * What a resend does, against a real database and the real manager. + * + * A session can be left waiting forever on a member who would have agreed, + * because the message asking them never arrived -- MLS moved its ratchet past + * the generation it came in at (`docs/mls-skipped-keys.md`), or a + * disappearing-message group expired it off the relay. Neither heals on its own + * and neither is visible to the sender. + * + * Two halves, and the second is the one worth testing hardest. The coordinator + * repeats what the coordinator wrote; a member named as silent repeats what + * *they* wrote, because a relayed copy would be filed under the relayer. The + * tests below are mostly about the limits of that: the same bytes and not new + * ones, nothing at all from a device whose owner has not decided, and nothing + * from a nudge that did not come from the coordinator. + */ +class FrostSigningResendJvmTest { + private val participants = 3 + private val threshold = 2 + + /** Stands in for a completed ceremony; the test is about resending, not the DKG. */ + private val keyMaterial: KeyMaterial = Frost.trustedDealerKeygen( + thresholdSecretKey = PrivateKey( + ByteVector32("1c0ffee0000000000000000000000000000000000000000000000000000000a1") + ), + nParticipants = participants, + threshold = threshold + ) + + private val thresholdPublicKey = keyMaterial.thresholdPublicKey.value.toHex() + + /** The admin room: the group's key walked to the admin path, which is its id. */ + private val roomId = SharedKeyDerivation.marmotGroupId(thresholdPublicKey) + + private val ceremonyId = "ceremony".padEnd(64, '0') + private val members = listOf("a", "b", "c").map { it.repeat(64) } + private val hostKeys = listOf("2a", "2b", "2c").map { it.padEnd(66, '0') } + + private val alice = members[0] + private val bob = members[1] + private val carol = members[2] + + private lateinit var db: CurareDatabase + private lateinit var room: LocalChatRoom + + @AfterTest + fun closeDatabase() { + if (::db.isInitialized) db.close() + } + + /** + * One member's device: a room it can sign in, and their share to sign with. + * + * The room carries its roster, unlike the decline test's, because this one + * is about who a message is addressed to: the room here is NIP-17 -- no MLS + * state -- so a payload is sealed per p-tag, and narrowing a resend to the + * quiet members is visible only if there is somebody to leave out. + */ + private suspend fun openDevice(owner: HexKey = alice) { + db = getRoomDatabase(Room.inMemoryDatabaseBuilder()) + + val index = members.indexOf(owner) + + val nostrEventId = "e$owner".take(64) + db.nostrEventDao().upsert( + NostrEvent( + id = nostrEventId, + pubKey = owner, + kind = 0, + tags = emptyArray(), + content = "{}", + sig = "0".repeat(128) + ) + ) + db.profileDao().upsert(Profile(publicKey = owner, nostrEventId = nostrEventId)) + + val chatRoom = ChatRoom( + id = roomId, + userPublicKey = owner, + subject = "#Ekklesia", + description = SharedKeyDerivation.describe("Admins of the group."), + mlsGroupState = null + ) + db.chatRoomDao().upsert(chatRoom) + + db.dkgSessionDao().upsert( + DkgSession( + id = ceremonyId, + chatRoomId = roomId, + coordinatorPublicKey = alice, + userPublicKey = owner, + threshold = threshold, + participantCount = participants, + stage = DkgRitualStage.COMPLETE, + hostPublicKey = hostKeys[index], + round1Random = "1".repeat(64), + round2AuxRandom = "2".repeat(64), + thresholdPublicKey = thresholdPublicKey, + secretShare = keyMaterial.secretShares[index].value.toHex(), + publicShares = keyMaterial.publicShares.joinToString(",") { it.value.toHex() } + ) + ) + + members.forEachIndexed { i, member -> + db.dkgSessionDao().upsert( + DkgParticipantMessage( + sessionId = ceremonyId, + participantPublicKey = member, + kind = DkgRitualEvents.HOST_KEY, + payload = hostKeys[i] + ) + ) + } + + room = LocalChatRoom( + chatRoom = chatRoom, + localParticipants = members.map { member -> + LocalParticipant( + Participant( + participantPublicKey = member, + chatRoomId = roomId, + relayHint = null + ), + null + ) + } + ) + } + + /** Alice proposes, which makes her device the coordinator and agrees on her behalf. */ + private suspend fun propose(): FrostSigningSession = FrostSigningManager.proposeSigning( + database = db, + localChatRoom = room, + userPublicKey = alice, + kind = 1, + tags = arrayOf(), + content = "Something for the group to say" + ) + + /** + * A session as it sits on a member's device once Alice's proposal has + * arrived: recorded, awaiting the owner's answer, and nothing published. + * + * The item carries a real unsigned event rather than `{}`, because a resend + * refuses to repeat a proposal whose stored events will not parse -- a + * proposal that quietly lost one would have every signer's contribution + * rejected for being the wrong length. + */ + private suspend fun proposalArrivedAt(owner: HexKey): FrostSigningSession { + val session = FrostSigningSession( + id = "s".repeat(64), + chatRoomId = roomId, + coordinatorPublicKey = alice, + userPublicKey = owner, + dkgSessionId = ceremonyId, + threshold = threshold, + participantCount = participants, + signerId = members.indexOf(owner), + derivationPath = SharedKeyDerivation.formatPath(SharedKeyDerivation.MARMOT_ADMIN_GROUP_PATH) + ) + db.frostSigningSessionDao().upsert(session) + db.frostSigningSessionDao().upsertItems( + listOf( + FrostSigningItem( + sessionId = session.id, + itemIndex = 0, + unsignedEventJson = unsignedEvent().toJson(), + eventId = unsignedEvent().id, + nonceRandom = "f".repeat(64) + ) + ) + ) + return session + } + + /** The one event these sessions sign, as the room's own key would author it. */ + private fun unsignedEvent(): Event = Event( + id = "e".repeat(64), + pubKey = roomId, + createdAt = 1_700_000_000L, + kind = 1, + tags = arrayOf(), + content = "Something for the group to say", + sig = "" + ) + + /** + * One signing message, as the inbound path would hand it over. + * + * [silent] is what a resent proposal carries: the members the coordinator + * says it has heard nothing from. + */ + private suspend fun receive( + sessionId: String, + kind: Kind, + member: HexKey, + content: String = "", + silent: List? = null, + includeKey: Boolean = false + ) { + FrostSigningManager.processSigningPayload( + database = db, + localChatRoom = room, + innerEvent = Event( + id = "$kind$member$content$silent".hashCode().toUInt().toString(16).padStart(64, '0'), + pubKey = member, + createdAt = Clock.System.now().epochSeconds, + kind = kind, + tags = FrostSigningEvents.assembleTags( + sessionId = sessionId, + dkgSessionId = if (includeKey) ceremonyId else null, + silentMembers = silent + ), + content = content, + sig = "" + ), + userPublicKey = room.chatRoom.userPublicKey + ) + } + + private suspend fun resend(sessionId: String) = + FrostSigningManager.resend(database = db, localChatRoom = room, sessionId = sessionId) + + private suspend fun session(id: String) = db.frostSigningSessionDao().getSessionById(id)!! + + private suspend fun transcript(type: String) = db.chatMessageDao() + .getChatMessagesByChatRoomId(roomId) + .map { it.chatMessage } + .filter { it.messageType == type } + + /** What this device has queued for the group, of one kind. The room is NIP-17 here. */ + private suspend fun queued(kind: Kind) = db.giftWrapPayloadDao() + .getByChatRoomAndKinds(roomId, listOf(kind)) + .filter { it.publicKey == room.chatRoom.userPublicKey } + + private fun pTags(tags: Array>): Set = + tags.filter { it[0] == "p" }.map { it[1] }.toSet() + + /** + * The row [publish] added to the queue, found by id rather than by time. + * + * `createdAt` is stored to the second, so a resend and the publish it + * repeats routinely share one -- picking "the newest" is a coin toss + * between them, and the coin came up wrong often enough to be worth not + * tossing. + */ + private suspend fun queuedBy(kind: Kind, publish: suspend () -> Unit): GiftWrapPayload { + val before = queued(kind).map { it.id }.toSet() + publish() + val after = queued(kind).filter { it.id !in before } + assertEquals(1, after.size, "expected exactly one new queued row of kind $kind") + return after.single() + } + + // ---- the coordinator's half ------------------------------------------- + + @Test + fun `a resend repeats the proposal and names who has not answered`() = runBlocking { + openDevice() + val session = propose() + + // Alice proposed, so her nonce is on file. Nobody else has said anything. + assertEquals(1, queued(FrostSigningEvents.PROPOSAL).size) + + val resent = queuedBy(FrostSigningEvents.PROPOSAL) { assertTrue(resend(session.id)) } + + assertEquals( + 2, + queued(FrostSigningEvents.PROPOSAL).size, + "the resend is a second proposal, not an edit of the first" + ) + + assertEquals( + setOf(bob, carol), + FrostSigningEvents.parseSilentMembers(resent.tags)?.toSet(), + "both members who have said nothing are named" + ) + + // The proposer is never in the silent set: it is their own session. + assertFalse(alice in FrostSigningEvents.parseSilentMembers(resent.tags)!!) + } + + @Test + fun `a resend carries the key, so a device with no session can open one`() = runBlocking { + openDevice() + val session = propose() + + val resent = queuedBy(FrostSigningEvents.PROPOSAL) { assertTrue(resend(session.id)) } + + // Without this a receiver that never saw the first proposal drops the + // second: `acceptProposal` refuses a proposal that names no key. + assertEquals(ceremonyId, FrostSigningEvents.parseKey(resent.tags)) + } + + @Test + fun `a resend repeats the same events, not new ones`() = runBlocking { + openDevice() + val session = propose() + val signing = db.frostSigningSessionDao().getItems(session.id).map { it.eventId } + + val resent = queuedBy(FrostSigningEvents.PROPOSAL) { assertTrue(resend(session.id)) } + val proposed = FrostSigningEvents.decodeProposal(resent.content) + + // The load-bearing one. A resend that proposed different events under the + // same session id would be asking for two signatures out of one secret + // nonce, which `acceptProposal` refuses -- so it would be a resend that + // repairs nothing while looking like it worked. + assertEquals(signing, proposed?.map { it.id }) + assertEquals(signing, db.frostSigningSessionDao().getItems(session.id).map { it.eventId }) + } + + @Test + fun `a resend is narrowed to the members it is for`() = runBlocking { + openDevice() + val session = propose() + + val first = queued(FrostSigningEvents.PROPOSAL).single() + + // Bob answers; Carol does not. A refusal rather than a nonce, because + // Alice already holds her own: a second nonce reaches the threshold and + // sends her off to aggregate, which this test has nothing valid to give + // her. One refusal in a 2-of-3 group leaves the session open. + receive(session.id, FrostSigningEvents.DECLINE, bob, "Declined to sign") + assertEquals(FrostSigningStage.COLLECTING_NONCES, session(session.id).stage) + + val resent = queuedBy(FrostSigningEvents.PROPOSAL) { assertTrue(resend(session.id)) } + + // A NIP-17 payload is sealed once per p-tag, so repeating a message for + // the one member who missed it should cost one wrap and not the room's + // worth. The first proposal named everybody; this one names Carol. + assertEquals(setOf(carol), pTags(resent.tags)) + assertEquals(setOf(bob, carol), pTags(first.tags)) + } + + @Test + fun `a member who declined is not silent`() = runBlocking { + openDevice() + val session = propose() + + receive(session.id, FrostSigningEvents.DECLINE, bob, "Declined to sign") + + val resent = queuedBy(FrostSigningEvents.PROPOSAL) { assertTrue(resend(session.id)) } + + // Bob answered. Knocking again would be asking a question he has closed. + assertEquals(setOf(carol), FrostSigningEvents.parseSilentMembers(resent.tags)?.toSet()) + } + + @Test + fun `a resend with nobody silent does nothing`() = runBlocking { + openDevice() + val session = propose() + + // Bob refuses, and Carol's nonce is written straight to the message table + // rather than delivered: a second nonce reaching Alice would send her off + // to aggregate it, and this test has no valid nonce to give her. What is + // being checked is who counts as silent, which is read from these rows. + receive(session.id, FrostSigningEvents.DECLINE, bob, "Declined to sign") + db.frostSigningSessionDao().upsert( + FrostSignerMessage( + sessionId = session.id, + signerPublicKey = carol, + kind = FrostSigningEvents.NONCE, + payload = "c".repeat(132) + ) + ) + + assertFalse(resend(session.id)) + assertEquals(1, queued(FrostSigningEvents.PROPOSAL).size) + assertTrue(transcript(ChatMessage.TYPE_FROST_RESENT).isEmpty()) + assertNull(session(session.id).resentAt) + } + + @Test + fun `only the device that proposed may resend`() = runBlocking { + openDevice(bob) + val session = proposalArrivedAt(bob) + + assertFalse(resend(session.id)) + assertTrue(queued(FrostSigningEvents.PROPOSAL).isEmpty()) + } + + @Test + fun `an abandoned session is not resent`() = runBlocking { + openDevice() + val session = propose() + + receive(session.id, FrostSigningEvents.FAILURE, bob, "Something went wrong") + assertEquals(FrostSigningStage.FAILED, session(session.id).stage) + + // Its items' nonce seeds have been published against an aggregate + // already. The retry is a fresh proposal, never this one again. + assertFalse(resend(session.id)) + assertEquals(1, queued(FrostSigningEvents.PROPOSAL).size) + } + + @Test + fun `the cooldown stops a second resend`() = runBlocking { + openDevice() + val session = propose() + + assertTrue(resend(session.id)) + val resentAt = session(session.id).resentAt + assertNotNull(resentAt) + + assertFalse(resend(session.id), "a second tap inside the cooldown publishes nothing") + assertEquals(2, queued(FrostSigningEvents.PROPOSAL).size) + assertEquals(1, transcript(ChatMessage.TYPE_FROST_RESENT).size) + assertEquals(resentAt, session(session.id).resentAt) + } + + @Test + fun `a resend past the cooldown goes out again`() = runBlocking { + openDevice() + val session = propose() + + assertTrue(resend(session.id)) + + // Wound back rather than waited out: the cooldown is minutes. + db.frostSigningSessionDao().upsert( + session(session.id).copy( + resentAt = Clock.System.now() - FrostSigningManager.RESEND_COOLDOWN * 2 + ) + ) + + assertTrue(resend(session.id)) + assertEquals(3, queued(FrostSigningEvents.PROPOSAL).size) + assertEquals(2, transcript(ChatMessage.TYPE_FROST_RESENT).size) + } + + @Test + fun `two resends in the same second do not collide`() = runBlocking { + openDevice() + val session = propose() + + assertTrue(resend(session.id)) + db.frostSigningSessionDao().upsert(session(session.id).copy(resentAt = null)) + assertTrue(resend(session.id)) + + val proposals = queued(FrostSigningEvents.PROPOSAL) + + // An outbound row's id is a hash over its `created_at`, which is stored + // to the second. Two identical publishes inside one second would hash + // the same, and the upsert would put the already-sent row back on the + // queue with its mapping cleared -- double-sending it and losing the + // group event it became. So the second steps a second forward instead. + assertEquals(3, proposals.size) + assertEquals(3, proposals.map { it.id }.toSet().size, "three rows, three ids") + } + + @Test + fun `a resend writes one line in the transcript`() = runBlocking { + openDevice() + val session = propose() + + assertTrue(resend(session.id)) + + val lines = transcript(ChatMessage.TYPE_FROST_RESENT) + assertEquals(1, lines.size) + assertEquals(alice, lines.single().senderPublicKey) + assertTrue(lines.single().content.contains("2 members")) + } + + // ---- the member's half ------------------------------------------------ + + @Test + fun `a member named as silent republishes the nonce they already sent`() = runBlocking { + openDevice(bob) + val session = proposalArrivedAt(bob) + + FrostSigningManager.approve(database = db, localChatRoom = room, sessionId = session.id) + + val first = queued(FrostSigningEvents.NONCE) + assertEquals(1, first.size) + + // Alice never got it, and says so. + val resent = queuedBy(FrostSigningEvents.NONCE) { + receive(session.id, FrostSigningEvents.PROPOSAL, alice, proposalContent(), silent = listOf(bob)) + } + + assertEquals(2, queued(FrostSigningEvents.NONCE).size, "the nonce goes out a second time") + + // The load-bearing assertion in this file. Two different nonces for one + // message against two aggregates is how a secret share is extracted, so + // a republish has to be the same bytes and not a fresh nonce. + assertEquals(first.single().content, resent.content, "the same bytes, not a new nonce") + } + + @Test + fun `a republished nonce goes only to the coordinator`() = runBlocking { + openDevice(bob) + val session = proposalArrivedAt(bob) + + FrostSigningManager.approve(database = db, localChatRoom = room, sessionId = session.id) + + val resent = queuedBy(FrostSigningEvents.NONCE) { + receive(session.id, FrostSigningEvents.PROPOSAL, alice, proposalContent(), silent = listOf(bob)) + } + + // A nonce is read by nobody but the coordinator -- `orderedNonces` is + // called under `isCoordinator` -- so repeating it for the room would be + // two wraps spent telling people who do not look. + assertEquals(setOf(alice), pTags(resent.tags)) + } + + @Test + fun `a member named as silent who has not decided publishes nothing`() = runBlocking { + openDevice(bob) + val session = proposalArrivedAt(bob) + + assertTrue(queued(FrostSigningEvents.NONCE).isEmpty()) + + receive(session.id, FrostSigningEvents.PROPOSAL, alice, proposalContent(), silent = listOf(bob)) + + // The strongest limit here. A message from the coordinator must never be + // able to put this device's share behind events its owner has not agreed + // to; the session is still waiting on a person, and says so. + assertTrue(queued(FrostSigningEvents.NONCE).isEmpty()) + assertNull(session(session.id).signApprovedAt) + assertTrue( + FrostSigningManager.isAwaitingApproval( + session(session.id), + db.frostSigningSessionDao().getItems(session.id) + ) + ) + } + + @Test + fun `a member named as silent republishes the refusal they already sent`() = runBlocking { + openDevice(bob) + val session = proposalArrivedAt(bob) + + FrostSigningManager.decline(database = db, localChatRoom = room, sessionId = session.id) + val first = queued(FrostSigningEvents.DECLINE) + assertEquals(1, first.size) + + val resent = queuedBy(FrostSigningEvents.DECLINE) { + receive(session.id, FrostSigningEvents.PROPOSAL, alice, proposalContent(), silent = listOf(bob)) + } + + assertEquals(2, queued(FrostSigningEvents.DECLINE).size) + assertEquals(first.single().content, resent.content) + } + + @Test + fun `a member not named stays quiet`() = runBlocking { + openDevice(bob) + val session = proposalArrivedAt(bob) + + FrostSigningManager.approve(database = db, localChatRoom = room, sessionId = session.id) + assertEquals(1, queued(FrostSigningEvents.NONCE).size) + + receive(session.id, FrostSigningEvents.PROPOSAL, alice, proposalContent(), silent = listOf(carol)) + + assertEquals(1, queued(FrostSigningEvents.NONCE).size) + } + + @Test + fun `a nudge from somebody who is not the coordinator is ignored`() = runBlocking { + openDevice(bob) + val session = proposalArrivedAt(bob) + + FrostSigningManager.approve(database = db, localChatRoom = room, sessionId = session.id) + assertEquals(1, queued(FrostSigningEvents.NONCE).size) + + // Carol naming Bob as silent. The bytes Bob would send are ones he has + // already sent, so nothing on the wire changes -- but a publish anybody + // in the room can trigger is not a thing to leave lying around. + receive(session.id, FrostSigningEvents.PROPOSAL, carol, proposalContent(), silent = listOf(bob)) + + assertEquals(1, queued(FrostSigningEvents.NONCE).size) + } + + @Test + fun `a resent proposal for a session already held changes nothing about it`() = runBlocking { + openDevice(bob) + val session = proposalArrivedAt(bob) + val before = db.frostSigningSessionDao().getItems(session.id) + + receive(session.id, FrostSigningEvents.PROPOSAL, alice, proposalContent(), silent = listOf(bob)) + + val after = db.frostSigningSessionDao().getItems(session.id) + assertEquals(before.map { it.eventId }, after.map { it.eventId }) + assertEquals(before.map { it.nonceRandom }, after.map { it.nonceRandom }) + // `acceptProposal` returns the session it already holds before it + // announces anything, so a resend writes no second "asked the group" + // line -- and this device's session was written straight to the row, + // so there is no first one either. + assertTrue(transcript(ChatMessage.TYPE_FROST_STARTED).isEmpty()) + } + + /** What a resent proposal carries: the events of [proposalArrivedAt]'s session. */ + private fun proposalContent(): String = + FrostSigningEvents.encodeProposal(listOf(unsignedEvent())) + + // ---- the case the feature exists for ---------------------------------- + + /** + * A real resent proposal, taken off a coordinator device and handed to a + * member's. + * + * Two databases rather than a hand-written row, because this is the one test + * that goes through [FrostSigningManager.acceptProposal] from the outside. An + * event's id is rebuilt from its own fields under the author the *receiver* + * resolves -- the room's key at the room's derivation path, never the + * proposer's word for it -- and a proposal whose id does not survive that is + * dropped. A fabricated event cannot pass it, which is the point of the + * check, so the proposal has to be one a coordinator really made. + * + * Returns the session id and the resent proposal's content, with [db] and + * [room] left pointing at [owner]'s freshly opened device. + */ + private suspend fun resentProposalFor(owner: HexKey): Pair { + openDevice(alice) + val session = propose() + val resent = queuedBy(FrostSigningEvents.PROPOSAL) { + assertTrue(FrostSigningManager.resend(db, room, session.id)) + } + val content = resent.content + db.close() + + openDevice(owner) + return session.id to content + } + + @Test + fun `a resend opens the session on a device that never saw the proposal`() = runBlocking { + val (sessionId, content) = resentProposalFor(bob) + + // The case the whole feature exists for. Bob's copy of the first + // proposal decrypted to nothing -- MLS had moved its ratchet past the + // generation it arrived at, which is terminal and which the sender + // cannot see (docs/mls-skipped-keys.md). He has no session at all. + assertNull(db.frostSigningSessionDao().getSessionById(sessionId)) + + receive(sessionId, FrostSigningEvents.PROPOSAL, alice, content, silent = listOf(bob), includeKey = true) + + val session = db.frostSigningSessionDao().getSessionById(sessionId) + assertNotNull(session, "the resent proposal opens the session Bob was missing") + assertEquals(alice, session.coordinatorPublicKey) + assertEquals(bob, session.userPublicKey) + assertEquals(1, db.frostSigningSessionDao().getItems(sessionId).size) + + // And he is asked, rather than signed for. A relay delivering an event + // to a phone in a pocket must not be enough to make a signature happen. + assertTrue( + FrostSigningManager.isAwaitingApproval( + session, + db.frostSigningSessionDao().getItems(sessionId) + ) + ) + assertTrue(queued(FrostSigningEvents.NONCE).isEmpty()) + assertEquals(1, transcript(ChatMessage.TYPE_FROST_APPROVAL_NEEDED).size) + } + + @Test + fun `being named as silent does not sign for a device that has just learned of the session`() = + runBlocking { + val (sessionId, content) = resentProposalFor(bob) + + receive(sessionId, FrostSigningEvents.PROPOSAL, alice, content, silent = listOf(bob), includeKey = true) + + // Named *and* new. There is nothing of Bob's on file to republish, + // so the nudge finds nothing -- and must not reach for the nonce it + // could generate instead. + assertTrue(queued(FrostSigningEvents.NONCE).isEmpty()) + assertTrue(queued(FrostSigningEvents.DECLINE).isEmpty()) + assertNull(db.frostSigningSessionDao().getSessionById(sessionId)!!.signApprovedAt) + } + + @Test + fun `a resent proposal delivered twice opens one session`() = runBlocking { + val (sessionId, content) = resentProposalFor(bob) + + receive(sessionId, FrostSigningEvents.PROPOSAL, alice, content, silent = listOf(bob), includeKey = true) + val items = db.frostSigningSessionDao().getItems(sessionId) + + // Relays redeliver, and a resend makes duplicates routine rather than + // exceptional. A second copy must not mint new nonce seeds: that is one + // secret nonce replaced under a message that has not changed, which is + // the stall the write-once rule exists to prevent. + receive(sessionId, FrostSigningEvents.PROPOSAL, alice, content, silent = listOf(bob), includeKey = true) + + val after = db.frostSigningSessionDao().getItems(sessionId) + assertEquals(items.map { it.nonceRandom }, after.map { it.nonceRandom }) + assertEquals(items.map { it.eventId }, after.map { it.eventId }) + assertEquals(1, transcript(ChatMessage.TYPE_FROST_STARTED).size) + assertEquals(1, transcript(ChatMessage.TYPE_FROST_APPROVAL_NEEDED).size) + } + + @Test + fun `a republished refusal is counted once`() = runBlocking { + openDevice() + val session = propose() + + // What the coordinator sees when a nudged member says their refusal + // again: the same message twice. Counting it twice would abandon a + // 2-of-3 session on one member's single no. + receive(session.id, FrostSigningEvents.DECLINE, bob, "Declined to sign") + receive(session.id, FrostSigningEvents.DECLINE, bob, "Declined to sign") + + assertEquals(FrostSigningStage.COLLECTING_NONCES, session(session.id).stage) + assertEquals(1, transcript(ChatMessage.TYPE_FROST_DECLINED).size) + assertEquals( + 1, + db.frostSigningSessionDao() + .getMessagesByKind(session.id, FrostSigningEvents.DECLINE) + .size + ) + } + + @Test + fun `a session the group has already signed can still be resent`() = runBlocking { + openDevice() + val session = propose() + + // A member who never received the signature never applied the events. + // Repeating it is the only thing that gets their store right, so COMPLETE + // is worth resending rather than treated as finished business. + db.frostSigningSessionDao().upsert( + session(session.id).copy(stage = FrostSigningStage.COMPLETE) + ) + db.frostSigningSessionDao().upsertItems( + db.frostSigningSessionDao().getItems(session.id).map { + it.copy(signature = "d".repeat(128)) + } + ) + + assertTrue(resend(session.id)) + assertEquals(1, queued(FrostSigningEvents.SIGNATURE).size) + assertEquals(2, queued(FrostSigningEvents.PROPOSAL).size) + } +} diff --git a/docs/README.md b/docs/README.md index d91c3004..4121e777 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,6 +10,7 @@ silent, or a decision that looked arbitrary and was not. | [shared-key-derivation.md](./shared-key-derivation.md) | deriving further keys from the group's threshold key with FROST tweaks — why not BIP32, why no chain code, and the one rule that must not be broken | | [subgroups.md](./subgroups.md) | a group making another group — the four ceremonies, what the parent's signature actually covers, and why the child's key is fresh rather than derived | | [frost-batch-signing.md](./frost-batch-signing.md) | signing several events in one ceremony — why one nonce can never cover two messages, and the phased schema, wire and UI work that follows from it | +| [frost-session-resend.md](./frost-session-resend.md) | asking the members who never got a signing proposal to look again — why a proposer can repeat only what it wrote, why a member's availability signal needs no repeating, and the one half that has to come from the silent member's own device | | [marmot-membership.md](./marmot-membership.md) | how members join an MLS group, and the epoch race that makes a missing member look like a successful invite | | [member-chronicle.md](./member-chronicle.md) | handing a member added after the work was done the group's signed record — why the events are not on the wire at all, and why the room's id is enough to verify them | | [marmot-direct-messages.md](./marmot-direct-messages.md) | a one-to-one message inside a group as a stock NIP-59 gift wrap — what its MIP-03 carve-out costs, why the sender cannot read their own, and the one query that would broadcast it | @@ -27,6 +28,8 @@ silent, or a decision that looked arbitrary and was not. Start with the ceremony if you are new to this area; the Marmot notes all assume it. Read the skipped-keys note before debugging any "the other device never got it" report — it is silent, and it looks like every other kind of delivery failure. The +resend note is the recovery for it on a signing session, and says which delivery +failures a resend repairs and which heal on their own. The sync note stands alone, and the dead-code inventory reads as a follow-up to it. The batch-signing note is a phased plan that has been built: read it after the derivation note, whose one rule is the same one it is built around. The member diff --git a/docs/frost-session-resend.md b/docs/frost-session-resend.md new file mode 100644 index 00000000..9fbd9ea6 --- /dev/null +++ b/docs/frost-session-resend.md @@ -0,0 +1,616 @@ +# Resending a signing session + +A proposer can ask the group to sign something and never hear back from a member +who would have agreed, because the message asking them never arrived. Today there +is nothing to do about it. The session sits in `COLLECTING_NONCES` until somebody +abandons it and proposes afresh, and the member it was waiting on never knew they +were being waited on. + +This is the plan for a resend: the proposer re-publishing what they authored for a +session, and — the half that is not obvious — the silent member republishing what +*they* authored, because the proposer cannot do it for them and must not be able to. + +Read [`docs/mls-skipped-keys.md`](mls-skipped-keys.md) first. It documents the +failure that makes this necessary and ends with the sentence this plan is a reply +to: *"nothing asks the sender to resend."* + +## The problem + +"Missed it" is five different things, and only some of them are a resend's business. + +| why a member has nothing | does a resend help? | +|---|---| +| offline, and the relay still holds the kind:445 | no — ordinary sync catches up | +| **MLS skipped keys**: the group event decrypted to nothing | **yes, and nothing else does** | +| NIP-40 expiration: a disappearing-message group dropped it off the relay | **yes, and nothing else does** | +| the member's read relays never had it | **yes** | +| the member was not in the room when it was sent | **yes** | +| the session already failed | no — `fail` already says "it is safe to ask again" | + +The second row is the one that forces the feature. From the skipped-keys doc: + +> the key is derived from a ratchet that has moved past it and cannot be +> recovered + +Terminal at the receiver, invisible to the sender, and the doc's own worked +example is this exact flow — a FROST proposal lost to it, leaving the proposer's +nonce filed against a session that will never exist. `MlsGroupCache` narrows the +window; it does not close it, and a restart or another writer reopens it. + +A resend fixes it because a resent message is a *new* application message at a +*new* generation. The old generation's key is gone; the new one is derivable. The +same is true of the expiration case: a fresh event carries a fresh expiry. + +## What is safe to resend, and what is not + +Every kind in a session has a direction, and the direction decides whether a +resend is even meaningful. + +| kind | author | who must actually receive it | proposer can resend? | +|---|---|---|---| +| 30320 `PROPOSAL` | proposer | every share holder | **yes** | +| 30321 `NONCE` | a signer | **only the coordinator** | no, and not needed | +| 30322 `SIGNER_SET` | coordinator | the chosen signers | **yes** | +| 30323 `PARTIAL_SIGNATURE` | a signer | **only the coordinator** | no, and not needed | +| 30324 `SIGNATURE` | coordinator | every share holder | **yes** | +| 30325 `FAILURE` | anyone | everyone | n/a — the session is over | +| 30330 `DECLINE` | a share holder | every share holder, for the count | no — see below | + +The third column is read off the code, not guessed. `orderedNonces` and +`orderedPartialSignatures` are both called under `session.isCoordinator()`; +nothing else in `advance` reads another member's nonce or partial. A non-coordinator +device uses other members' nonces for exactly one thing — the "Ready to sign" row +in `FrostSigningUIState.offeredNonce` — which is cosmetic. + +**So the parenthetical in the request is the right answer.** A nonce is a signal only +the proposer needs, and the proposer already has it, which is how they know the +member is not silent. There is nothing to resend. + +### Receiver-side idempotence already holds + +A resend is only cheap because every arm of `record` is already write-once. This is +an audit of the gates, not a wish list; each one is a line that exists today. + +- `PROPOSAL` → `acceptProposal` finds the session, compares the proposed ids against + the stored `FrostSigningItem.eventId`s, finds them equal, returns the existing + session. No write, no log line. +- `SIGNER_SET` → `isFromCoordinator`, then `if (current(database, session).signerIds != null) return true`. +- `SIGNATURE` → `if (isSigned(database, session)) return true`. +- `NONCE` / `PARTIAL_SIGNATURE` → upsert keyed on `(sessionId, signerPublicKey, kind)`; + `known` is true, so no second transcript line. +- `DECLINE` → `recordDecline` recomputes a `toSet()` count; `fail` has its own + already-settled guard. + +`publishOwn` already states the policy this plan generalises: + +> A crash between the two therefore costs a duplicate broadcast — which every +> receiver folds away + +**No protocol change is required for the proposer to resend its own messages.** That +is the whole of Phase 2. + +### Why the proposer cannot resend another member's message + +Three reasons, in increasing order of seriousness. + +**It would be filed under the wrong author.** `record` writes +`FrostSignerMessage(signerPublicKey = innerEvent.pubKey, …)`. A forwarded copy is +authored by the forwarder, so a nonce the proposer relayed on Bob's behalf is filed +as the *proposer's* nonce, overwriting their own. On Marmot there is no way around +this: MIP-03 rejects an inner event whose `pubKey` is not the MLS sender's identity, +and `docs/marmot-direct-messages.md` describes the single carve-out that exists and +why it is narrow. + +**For a decline it is a forgery primitive.** `recordDecline` counts distinct +`signerPublicKey`s against `declinesThatAbandon()`. A proposer who could relay a +decline under their own key would be able to manufacture refusals; in an n-of-n +group one is enough to abandon a session nobody refused. Forwarding would have to +carry a signature over the original, verified before counting — a new envelope kind, +new verification code, and a new way to get it wrong, to deliver a message that +nobody but the coordinator needed in the first place. + +**For the proposal it is already load-bearing.** `acceptProposal` sets +`coordinatorPublicKey = innerEvent.pubKey` for a session it has never seen. A +non-coordinator who resends the proposal to a member with no session row makes that +member believe the *resender* coordinates — and that member will then drop the real +coordinator's signer set through `isFromCoordinator`. **Resend is coordinator-only, +and the restriction is correctness rather than etiquette.** (A member could already +mint a proposal under someone else's session id today; resend does not widen that, +but it must not make it a routine code path either.) + +## The half the request is actually about + +The request asks whether the proposer needs to resend a member's availability +signal. It does not, but there is a real gap hiding behind the question, and it is +the mirror image: + +> A nonce lost on the way to the proposer is a permanent stall, and no device will +> ever republish it. + +`advance` republishes a message it has **no local copy of** — `if (ownNonces == null)`. +Bob's device, having published and recorded its nonce, will never send it again, +however long the proposer waits. The member who can fix it is Bob, and Bob has no +way to know. + +So the resend has two halves: + +1. the proposer republishes what the proposer authored (Phase 2), and +2. the resent proposal **names the members the proposer has not heard from**, and a + named device republishes what *it* authored (Phase 3). + +Half 2 is what the request is reaching for, reached from the only side that can +author the message. It needs no forwarding, no new envelope and no signature +checking, because every message still travels under the key that made it. + +## Phase 1 — a tag for the silent set + +`FrostSilentMembersTag`, in `nostr/frost/tags/`, following `FrostSignerIdsTag` +exactly: a `TAG_NAME` const, `parse`/`assemble`, and all-or-nothing parsing because +a partially-read list is a list naming the wrong people. + +```kotlin +const val TAG_NAME = "frost_silent" +``` + +Hex pubkeys, comma separated, in `tag[1]`. An entry that is not 64 hex characters +invalidates the whole tag. + +`FrostSigningEvents.assembleTags` grows a fourth optional parameter: + +```kotlin +fun assembleTags( + sessionId: String, + dkgSessionId: String? = null, + signerIds: List? = null, + silentMembers: List? = null +): Array> +``` + +and a `parseSilentMembers` beside the other three parsers. `broadcast` gains a +matching optional parameter and passes it through. + +**Why a tag on the proposal rather than a kind of its own.** A bare nudge reaches a +device with no session to apply it to and is dropped — +`getSessionById` returns null and `processSigningPayload` logs *"leaving it stored"*. +That is exactly the device we are trying to reach. The member who is silent is +overwhelmingly silent *because* they never got the proposal, so the nudge and the +thing they are missing have to travel in one message or the common case is not +fixed. See the appendix for the kind-30331 version and why it loses. + +**It is invisible to the id check.** `acceptProposal` rebuilds the signed events from +`innerEvent.content`; the carrier's tags are not part of any id. Adding a tag cannot +change what a signer is putting their share behind. + +**It leaks nothing.** On Marmot every nonce is a group event the room already saw; +on NIP-17 every member is p-tagged on every message. Who has signalled is not a +secret the tag gives away. + +**The silent set comes off the ceremony, not the room.** `signerIds(database, key).keys` +minus everyone with any `FrostSignerMessage` for the session — the same source +`recordDecline` counts against and `observeShareHolders` draws. The room's roster is +wrong twice over, for the reasons `FrostSigningUIState.Loaded.members` already gives: +it can hold members added after the key was made, and a subgroup's ceremony room is +the parent. + +## Phase 2 — the proposer resends what it authored + +```kotlin +suspend fun resend( + database: CurareDatabase, + localChatRoom: LocalChatRoom, + sessionId: String +): Boolean +``` + +Returns whether anything went out, so the caller can say so. + +**Refused unless it is this device's session to resend.** `session.isCoordinator()`, +for the `acceptProposal` reason above. Refused for `FAILED` — nothing can be +resent into a dead session and `fail` already tells the group to ask again — and +refused for a session whose items are empty. + +**It sends the minimum the stage requires**, which is at most two events: + +| stage | what goes out | +|---|---| +| `COLLECTING_NONCES` | the proposal | +| `COLLECTING_PARTIAL_SIGNATURES` | the proposal, then the signer set | +| `COMPLETE` | the proposal, then the signature | +| `FAILED` | refused | + +The proposal goes in every case because a device with no session row cannot apply +anything else: a signer set naming ids it has no items for, or a signature over +events it has never seen, are both dropped. `COMPLETE` is worth resending rather +than skipping — a member who never received the signature never ran `complete`, so +the signed events were never applied to their local store. + +The proposal's content is `FrostSigningEvents.encodeProposal` over the stored +items' `unsignedEventJson`. Re-serialising is safe: the receiver compares rebuilt +ids, and an id is over the canonical form, so any JSON with the same fields hashes +the same. A batch of one must still go out as a bare object — `encodeProposal` +guarantees it, and `decodeProposal` dispatching on a leading `[` is why it matters. + +### Two hazards worth naming before writing the code + +**The id collision.** `broadcast` derives the queue row's primary key from +`EventHasher.hashId(pubKey, createdAt, tags, content, kind)` with `createdAt` in +whole seconds. A resend whose content, tags and second all match the original +produces the **same id**, and `@Upsert` then replaces the sent row with an +unsent one: `marmotGroupEventId` goes back to null, the already-delivered event is +queued a second time, and its mapping to the group event it became is lost. The +cooldown in Phase 4 makes this improbable; it must not be the only defence. +`broadcast` should refuse to overwrite a row whose `marmotGroupEventId` is already +set, and the resend path should carry `createdAt` forward a second at a time until +the id is unused. Worth a test of its own. + +**The burst.** Resending two events back-to-back recreates precisely the condition +the skipped-keys bug needs. `MlsGroupCache` covers a burst decrypted in one sync, +which is what makes `proposeSigningBatch`'s own two-message burst work today, so +the mitigation is the existing one — send in protocol order, in one pass, and do not +add a third event. It is the strongest argument for the stage table above being a +minimum rather than "send everything". + +### Transport + +`broadcast` already knows the difference and needs no new branch for Marmot: one +group event reaches everybody, and every receiver folds the duplicate away, which +is cheaper than one message per silent member and tells the room nothing it does not +already know. + +NIP-17 is the opposite — `recipientTags` seals one wrap per recipient — so there the +resend narrows to the silent set plus the chosen signers, which is a real saving in +a room where one member out of nine is quiet. This is the first signature a group +makes, on gift wraps, per `GroupKeyStateManager.propose`. + +## Phase 3 — a named member republishes what it authored + +In `processSigningPayload`, after the session is in hand and before `advance`: + +```kotlin +if (FrostSigningEvents.parseSilentMembers(innerEvent.tags) + ?.contains(session.userPublicKey) == true && + isFromCoordinator(session, innerEvent) +) { + republishOwn(database, localChatRoom, session) +} +``` + +`republishOwn` re-broadcasts this device's own stored `FrostSignerMessage` rows for +`NONCE`, `PARTIAL_SIGNATURE` and `DECLINE` — **the stored bytes, never regenerated**. +They are byte-identical by construction, so they cannot produce a second aggregate, +and reading the row avoids k native `SecretNonce.generate` calls to arrive at the +same answer. + +Three constraints, each of which is a rule that already exists somewhere else: + +**Only from the coordinator.** A member who could name another member as silent could +make them republish on demand. It changes nothing on the wire — the bytes are the +same ones already sent — but it is a publish anybody could trigger, and that is not +a thing to leave lying around. + +**Nothing new is published.** `republishOwn` sends only what is already on file. A +device with no `FrostSignerMessage` of its own sends nothing and falls through to +`advance`, which does what it has always done: ask whether the owner has decided, +and if they have not, write the approval request and stop. **A message from the +proposer must never be able to talk a device into publishing a nonce its owner has +not approved** — that is `acceptProposal`'s "Publishes nothing" rule, and the gate +that enforces it is `advance`'s `if (session.signApprovedAt == null)`, untouched. + +**Once per delivery.** A redelivered resend has the same inner-event id and is +deduplicated upstream; a *second* resend from the proposer is a new id and will +republish again, which costs a duplicate everybody folds away. The Phase 4 cooldown +bounds how often that can happen. + +### What this fixes, concretely + +- Bob approved, published a nonce, and the proposer never got it. Bob is named, + republishes the same bytes, and the proposer's `orderedNonces` finds a quorum. +- Bob approved and his device died before `publishOwn` queued anything. Today the + resent proposal alone already fixes this, because `acceptProposal` → `record` → + `advance` re-enters the `ownNonces == null` branch. Worth knowing: part of the + fix is free. +- Bob declined and the refusal was lost. He republishes it, and every device's count + converges on the same arithmetic instead of waiting on a member who has answered. +- Bob never saw the proposal at all. He sees it now, and `announceApprovalNeeded` + puts the request in his transcript. + +## Phase 4 — schema 24 → 25: `resentAt` + +*Landed with Phase 2 rather than after it: `resend` needs the column for its +cooldown, and writing it twice to keep the phases apart would have been +ceremony.* + +A nullable `Instant?` on `FrostSigningSession`, written by `resend`: + +```kotlin +/** + * When the coordinator last re-published this session, or null if never. + * + * Two jobs. It is the cooldown -- a resend is a publish, and a button that + * publishes on every tap is a button that fills a room with duplicates. And it + * keeps a second resend from landing in the same second as the first, where the + * queue row's id is a hash over `createdAt` and a collision un-sends the + * message it collides with. + */ +val resentAt: Instant? = null +``` + +`AutoMigration(from = 24, to = 25)` with the comment the others carry, and the +generated `composeApp/schemas/25.json` committed. Nothing is backfilled: a session +that has never been resent reads null, which is what every session before the column +was. + +A cooldown of five minutes, as a `const` on the manager beside `MAX_BATCH_SIZE`, +with the reasoning on it. `resend` returns false inside the window rather than +throwing; the screen disables the button and says when it may be used again. + +The alternative — deriving the last resend from the `TYPE_FROST_RESENT` transcript +row — needs no migration but makes the manager read the chat table to decide a +protocol question, and makes a user-deletable row load-bearing. The column is +cheaper than that. + +## Phase 5 — the transcript + +`ChatMessage.TYPE_FROST_RESENT = "frostResent"`, added to the frost block and to +`FROST_TYPES` (whatever the rendering set is called where `TYPE_FROST_DECLINED` +appears), with the house comment explaining why it is its own type: it is not a +protocol step, it is the proposer knocking, and the ladder should show that the +knock happened so a second one is visibly a second one. + +The line is the `announce` shape the other frost lines use, with the actor as the +coordinator: + +> asked the 2 members who have not answered to take another look. + +Named rather than counted when there are few, for the reason `FrostSigningScreen` +already gives — *"1 of 2" does not tell anyone whose door to knock on*. Written +once per resend, which `resentAt` makes true. + +A resent message must **not** write a second step line. That is already how it +works: `announceStep` is called from `publishOwn` and `record` only when `known` is +false, and `resend` calls `broadcast` directly rather than `publishOwn` — which is +also why `resend` must not be routed through `publishOwn`, whose whole job is to +record a local copy that already exists. + +## Phase 6 — repository and view model + +`FrostSigningRepository` grows one method, documented with the directionality that +makes it one method rather than two: + +```kotlin +/** + * Re-publishes the messages this device authored for a session, for the members + * it has not heard from. + * + * Coordinator only, and a resend of *this device's* messages only. A member's + * nonce is read by nobody but the coordinator, who already has it; and a message + * relayed by somebody else would be filed under the relayer, which for a refusal + * is a way to manufacture one. What the resend does for a silent member is name + * them, so their own device republishes what it already said. + * + * Returns false when there was nothing to do: not the coordinator, already + * failed, nobody silent, or inside the cooldown. + */ +suspend fun resend(localChatRoom: LocalChatRoom, sessionId: String): Boolean +``` + +`NO_OP_FROST_SIGNING_REPOSITORY` returns false. `DatabaseFrostSigningRepository` +delegates to the manager, as its other methods do. + +`FrostSigningUIState.Loaded` gains two derived values rather than two fields: + +```kotlin +/** Share holders this session has heard nothing from. Whose door to knock on. */ +val silent: Set get() = shareHolders - offeredNonce - signed - declined + +/** Whether this device may knock: it proposed, the session is open, somebody is quiet. */ +val canResend: Boolean get() = … +``` + +`silent` is already computable from what the view model collects — `offeredNonce`, +`signed`, `declined` and `shareHolders` are all there — so the screen needs no new +flow. `FrostSigningViewModel` gains a `resend(onDone:)` on the `approve`/`decline` +pattern, guarded by the same `isActionPending`. + +## Phase 7 — UI + +The affordance belongs on `FrostSigningScreen`, below the member list and above the +approval block, in a section the coordinator alone sees. The member list is already +the screen's answer to "whose door to knock on"; this is the knock, and it goes +where the doors are. + +```kotlin +if (state.canResend) { + HorizontalDivider() + + Text( + text = stringResource(Res.string.these_members_have_not_answered), + style = MaterialTheme.typography.bodySmall + ) + + Button( + enabled = !frostSigningViewModel.isActionPending.value, + onClick = { frostSigningViewModel.resend { notify(resent) } } + ) { + Icon(Icons.Default.Send, contentDescription = Decorative) + Spacer(modifier = Modifier.width(MaterialTheme.spacing.space125)) + Text(stringResource(Res.string.ask_again)) + } +} +``` + +Per `CLAUDE.md`, and each of these is enforced by `./gradlew :composeApp:m3Audit`: + +- strings in `composeApp/src/commonMain/composeResources/values/strings.xml`, in + **sentence case**: `asked_again`, `one_member_has_not_answered`, + `members_have_not_answered`, `asked_again_recently`, + `everyone_has_answered_this_session`. The count interpolates as `%1$s`, which + is what the catalogue's other counted strings use. `ask_again` was already + there for re-querying a list's relays and means exactly this, so it is reused + rather than duplicated — two keys with one label is how a translator comes to + pick two different words for one idea. +- spacing from `MaterialTheme.spacing`; no `.dp` literal in a spacing position. +- the icon is beside its label, so `contentDescription = Decorative` — decided, not + `null`. +- the outcome goes through `rememberNotifier(rememberCoroutineScope())`, with the + `stringResource` read **above** the handler, since `onClick` is not composable. +- no new state branch: the screen keeps its four, and this sits inside `Loaded`. + +`ProposalListScreen` gets nothing. A resend is a decision about one session made +while looking at who has answered, and the list shows neither. + +Within the cooldown the button is disabled with a supporting line saying so, rather +than hidden — a control that vanishes after a tap reads as a control that failed. + +## Phase 8 — the tests + +`FrostSigningResendJvmTest`, on `FrostSigningDeclineJvmTest`'s harness: a 2-of-3 +`Frost.trustedDealerKeygen`, a room at `SharedKeyDerivation.marmotGroupId`, and its +`openDevice` / `propose` / `proposalArrivedAt` / `receive` / `queued(kind)` helpers. +That test is already a two-device simulation over one real database, which is what +this needs. + +The properties, each one a thing that would otherwise be found in a group: + +1. **A resend reaches a device that missed the proposal.** Propose on Alice, never + deliver, resend, deliver the resent proposal to Bob: Bob has a session and an + approval request. This is the skipped-keys case. +2. **A resend is idempotent on a device that has the session.** Deliver the proposal, + approve, then deliver the resend: the item ids are unchanged, no second + transcript line, no second nonce row, and `signerIds` unchanged once set. +3. **A named member republishes their nonce.** Bob approves, his nonce is dropped, + the proposer resends naming Bob, and Bob's device queues the **same payload** a + second time. Assert byte equality against the first — a different nonce for the + same message against two aggregates is the share extraction the whole design + forbids. +4. **A named member who has not decided publishes nothing.** The strongest test here. + Bob is named without having approved: nothing is queued, and + `isAwaitingApproval` is still true. +5. **A named member republishes their refusal**, and counts converge. +6. **A non-coordinator cannot resend**, and a resend tag from a non-coordinator is + ignored. +7. **A resend of a `FAILED` session is refused**, and nothing is queued. +8. **Two resends in the same second do not collide.** Two ids, both rows unsent, the + first not reverted. The hazard from Phase 2. +9. **The cooldown holds**: the second call inside the window returns false and queues + nothing. + +A pure `commonTest` for `FrostSilentMembersTag` round-tripping, beside +`FrostProposalCodecTest`: an empty list, a malformed entry invalidating the whole +tag, and an unknown tag surviving `assembleTags`/`parse` untouched. + +Then the project's two gates: + +```bash +./gradlew :composeApp:m3Audit +``` + +```bash +./gradlew :composeApp:compileDebugKotlinAndroid :composeApp:jvmTest +``` + +One unrelated 5-second-timeout failure per full `jvmTest` run is a known flake; +re-run the suite alone before investigating. + +## Rollout and compatibility + +Nothing here is a wire break, and that is by design. + +**A build predating this plan receiving a resent proposal** reads an unknown +`frost_silent` tag, ignores it, and runs `acceptProposal` — which either creates the +session it was missing or returns the one it has. **The half that matters works on +old builds without a change.** Only the republish-when-named half needs both ends. + +**A build predating this plan receiving a resent signer set or signature** applies +them if it was missing them and hits its own write-once gate if it was not. Both +behaviours are today's. + +**An old coordinator** never resends, which is today's behaviour exactly. + +The one ordering constraint: Phase 1's tag must ship no later than Phase 2, because +a resent proposal with no silent tag is a resend whose second half silently does +nothing. Phases 4 through 7 can land after, and Phase 8's tests should land with the +phase they test rather than at the end. + +### What landing it turned up + +Two things worth recording, both of them in `broadcast` and neither of them about +resend as such. + +**The id collision was real, and the guard needed a second half.** `broadcast` +now steps past a taken id rather than upserting over it, and returns whether it +queued anything. That return is load-bearing: `publishOwn` writes the local copy +that stops [advance] from publishing a message again, so a `broadcast` that +queued nothing must record nothing, or the group waits forever on a message that +never went out. The comment on `publishOwn` had the trade written down in one +direction only. + +**Narrowing is a `recipientTags` change, not a `broadcast` branch.** On NIP-17 a +resend names the quiet members and the signers; on Marmot the parameter is +ignored, because a group event is encrypted to the group and names nobody. One +optional argument covers both, which is the shape `broadcast` already had for +the transports. + +## What this does not do + +- **It does not retry automatically.** See the appendix. +- **It does not resend another member's message**, and cannot be extended to without + a signed forwarding envelope. The appendix says why that is not worth building. +- **It does not recover a failed session.** A retry is a new batch, always: + `proposeSigningBatch`'s own notes say why, and `itemsOver` mints fresh nonce seeds + so a retry is a new session by construction. +- **It does not change the quorum arithmetic.** A resend publishes nothing new and + counts nothing twice; `declinesThatAbandon` is untouched. +- **It does not help a member who holds no share.** They were never in the session. + `signerIds(database, key)` is the list, for the reason + `FrostSigningUIState.Loaded.members` gives. +- **It does not fix the skipped-keys bug.** It is a recovery for it, driven by a + person who noticed. The fix is in quartz, and `docs/mls-skipped-keys.md` has it. + +## Appendix — what was considered and rejected + +**A resend kind of its own (30331).** Cleaner to read, and it could nudge without +re-sending a proposal carrying up to `MAX_BATCH_SIZE` events. It loses on the common +case: a bare nudge arriving at a device with no session for it is dropped — +`getSessionById` returns null, `processSigningPayload` logs *"leaving it stored"* — +and that device is the one we are trying to reach. It would also be unrouted by any +build predating it, since `ALL` is what the inbound path dispatches on, which is the +same degradation the decline kind at 30330 documents. If the proposal's size ever +becomes the binding cost, the nudge can be added *alongside* the resent proposal +rather than instead of it. + +**Forwarding another member's message in a signed envelope.** Technically possible: +wrap the original event, verify the inner signature before `record` files it under +the inner author. Rejected on cost against benefit. It is new verification code on +the path that decides whether a refusal counts — see the forgery note above — and it +exists to deliver nonces and partial signatures that nobody but the coordinator ever +needed. The coordinator already has them. Naming the silent member and letting their +own device speak costs one tag. + +**Automatic resend on a timer.** A background publisher that fires on a stalled +session. Rejected: it publishes without anybody deciding to, it would write a +transcript line per tick in a room whose protocol lines are deliberately one per +step, and every amplification bug in the app's history has been something that +published on a schedule. A person noticing a stalled session and knocking is the +same shape as everything else on this screen. The cooldown column would make a timer +straightforward to add later if a group asks for it. + +**A Marmot direct message per silent member.** `MarmotInnerEvent` has +`directMessageRecipientPublicKey` and it would work. Rejected twice over: it is m +events where one does, and per `docs/marmot-direct-messages.md` every member of the +group sees that a private message was sent and to whom — so a nudge would read as a +side channel in a room where the nudge is public information anyway. + +**Narrowing the Marmot resend to the silent set.** There is no narrowing to do: a +group event is encrypted to the group and names nobody, which is the point +`broadcast` makes about why its p-tags are not cosmetic. Narrowing is real on +NIP-17, where a wrap is sealed per recipient, and Phase 2 does it there. + +**Resetting the queue row instead of writing a new one.** `@Upsert` of a +`MarmotInnerEvent` with `marmotGroupEventId = null` puts an already-sent row back on +the outbound queue, which looks like a free resend. Rejected: it destroys the row's +mapping to the group event it became, which the transcript and +`MarmotPublishObligation` both read, and it re-sends the *old* ciphertext's plaintext +at an id that no longer describes a new event. A resend is a new message with a new +`created_at`, which is also what makes it decryptable at a generation the receiver +has not passed. diff --git a/docs/mls-skipped-keys.md b/docs/mls-skipped-keys.md index 597eff2a..ca7a533f 100644 --- a/docs/mls-skipped-keys.md +++ b/docs/mls-skipped-keys.md @@ -85,7 +85,14 @@ back afterwards. So the sequence is 4. the exception is swallowed, the event yields no `ApplicationMessage` Step 3 is terminal. The key is derived from a ratchet that has moved past it and -cannot be recovered, and nothing asks the sender to resend. +cannot be recovered. + +Nothing *asked* the sender to resend, either, which is a second gap and a +narrower one. A FROST signing session now has a resend: the proposer repeats what +it wrote, and the repeat names the members it has heard nothing from so their own +devices repeat what they wrote. See +[frost-session-resend.md](./frost-session-resend.md). It is a recovery driven by +somebody noticing, not a fix — the fix is below, and it is in quartz. Verified against the published artifact rather than a checkout: `quartz-1.14.0-sources.jar`, `commonMain/com/vitorpamplona/quartz/marmot/mls/schedule/SecretTree.kt`. @@ -195,6 +202,13 @@ It is not the fix, and it is worth being precise about what it leaves broken: - **Nothing helps a long reorder.** A message the relay holds back until after a restart or an outbound send is gone. +A message lost this way is gone for good, but it is not necessarily +unrecoverable: a *new* message carrying the same payload is encrypted at a +generation the receiver has not passed, so it decrypts normally. That is the +whole mechanism behind +[frost-session-resend.md](./frost-session-resend.md), and the same move would +work for any other flow in the table above that someone can be asked to repeat. + The staleness check is what keeps the cache from being *worse* than no cache: a group that has been overtaken by another writer is never carried on with, so the fallback is always the old behaviour rather than a diverged ratchet.