From 0f8ee65033f3167f59be3496d8e5960409b0b597 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Mon, 22 Jun 2026 22:30:39 +0200 Subject: [PATCH] Bug fix on marmot keypackage bundle (Buggy nsec) --- .../1.json | 20 +++++++++---------- .../database/model/MarmotKeyPackageBundle.kt | 20 +++++++++++-------- .../repository/DatabaseMarmotRepository.kt | 6 +++--- .../repository/DatabaseNostrRepository.kt | 1 + 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/composeApp/schemas/at.torch.compose.database.TorchDatabase/1.json b/composeApp/schemas/at.torch.compose.database.TorchDatabase/1.json index 1be10ec1..f277b493 100644 --- a/composeApp/schemas/at.torch.compose.database.TorchDatabase/1.json +++ b/composeApp/schemas/at.torch.compose.database.TorchDatabase/1.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 1, - "identityHash": "f7045a56c021b062dd142cc9cd8513a3", + "identityHash": "6b621966e86b542862bb89991b2b3acb", "entities": [ { "tableName": "BroadcastNostrEventReceipt", @@ -1188,7 +1188,7 @@ }, { "tableName": "MarmotKeyPackageBundle", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `publicKey` TEXT NOT NULL, `tlsEncodedMarmotKeyPackage` TEXT NOT NULL, `ncryptsecInitPrivateKey` TEXT NOT NULL, `ncryptsecEncryptionPrivateKey` TEXT NOT NULL, `ncryptsecSignaturePrivateKey` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, FOREIGN KEY(`publicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE )", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `publicKey` TEXT NOT NULL, `tlsEncodedMarmotKeyPackage` TEXT NOT NULL, `ncryptsecInitPrivateKey` TEXT NOT NULL, `ncryptsecEncryptionPrivateKey` TEXT NOT NULL, `ncryptsecSignaturePrivateKey` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER)", "fields": [ { "fieldPath": "id", @@ -1261,17 +1261,15 @@ "id" ] }, - "foreignKeys": [ + "indices": [ { - "table": "Profile", - "onDelete": "CASCADE", - "onUpdate": "NO ACTION", - "columns": [ + "name": "index_MarmotKeyPackageBundle_publicKey", + "unique": false, + "columnNames": [ "publicKey" ], - "referencedColumns": [ - "publicKey" - ] + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_MarmotKeyPackageBundle_publicKey` ON `${TABLE_NAME}` (`publicKey`)" } ] }, @@ -3034,7 +3032,7 @@ ], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f7045a56c021b062dd142cc9cd8513a3')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '6b621966e86b542862bb89991b2b3acb')" ] } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/database/model/MarmotKeyPackageBundle.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/database/model/MarmotKeyPackageBundle.kt index a06f5876..84ead322 100644 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/database/model/MarmotKeyPackageBundle.kt +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/database/model/MarmotKeyPackageBundle.kt @@ -2,6 +2,7 @@ package at.torch.compose.database.model import androidx.room3.Entity import androidx.room3.ForeignKey +import androidx.room3.Index import androidx.room3.PrimaryKey import at.torch.compose.database.model.traits.BroadcastableEntity import at.torch.compose.database.model.traits.LocalStoreEntity @@ -12,14 +13,17 @@ import kotlin.time.Clock import kotlin.time.Instant @Entity( - foreignKeys = [ - ForeignKey( - entity = Profile::class, - parentColumns = ["publicKey"], - childColumns = ["publicKey"], - onDelete = ForeignKey.CASCADE, - ), - ] +// foreignKeys = [ +// ForeignKey( +// entity = Profile::class, +// parentColumns = ["publicKey"], +// childColumns = ["publicKey"], +// onDelete = ForeignKey.CASCADE, +// ), +// ], + indices = [ + Index("publicKey"), + ], ) data class MarmotKeyPackageBundle( @PrimaryKey(autoGenerate = true) diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/database/repository/DatabaseMarmotRepository.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/database/repository/DatabaseMarmotRepository.kt index 49870658..1e2dd513 100644 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/database/repository/DatabaseMarmotRepository.kt +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/database/repository/DatabaseMarmotRepository.kt @@ -29,9 +29,9 @@ class DatabaseMarmotRepository( MarmotKeyPackageBundle( publicKey = publicKey, tlsEncodedMarmotKeyPackage = tlsWriter.toByteArray().toHex(), - ncryptsecInitPrivateKey = nip49.encrypt(keyPackageBundle.initPrivateKey.toHex(), nsecPassword), // TODO: ncryptSec this using the private key - ncryptsecEncryptionPrivateKey = nip49.encrypt(keyPackageBundle.encryptionPrivateKey.toHex(), nsecPassword), // TODO: ncryptSec this using the private key - ncryptsecSignaturePrivateKey = nip49.encrypt(keyPackageBundle.signaturePrivateKey.toHex(), nsecPassword) // TODO: ncryptSec this using the private key + ncryptsecInitPrivateKey = keyPackageBundle.initPrivateKey.toHex(), // TODO: ncryptSec this using the private key + ncryptsecEncryptionPrivateKey = keyPackageBundle.encryptionPrivateKey.toHex(), // TODO: ncryptSec this using the private key + ncryptsecSignaturePrivateKey = keyPackageBundle.signaturePrivateKey.toHex() // TODO: ncryptSec this using the private key ) ) diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/database/repository/DatabaseNostrRepository.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/database/repository/DatabaseNostrRepository.kt index a070599e..be94a7dd 100644 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/database/repository/DatabaseNostrRepository.kt +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/database/repository/DatabaseNostrRepository.kt @@ -1,5 +1,6 @@ package at.torch.compose.database.repository +import at.torch.compose.database.model.Profile import at.torch.compose.database.model.UnsignedNostrEvent import at.torch.compose.nostr.Relays import co.touchlab.kermit.Logger