Log marmot key packages
This commit is contained in:
1 parent
9edcc87d55
commit
daba18ecc6
1 file changed
+13
-3
+13
-3
@@ -6,6 +6,7 @@ import at.torch.compose.database.model.UnsignedNostrEvent
|
|||||||
import at.torch.compose.extensions.toHex
|
import at.torch.compose.extensions.toHex
|
||||||
import at.torch.compose.nostr.Relays
|
import at.torch.compose.nostr.Relays
|
||||||
import at.torch.compose.repository.MarmotRepository
|
import at.torch.compose.repository.MarmotRepository
|
||||||
|
import co.touchlab.kermit.Logger
|
||||||
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageEvent
|
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageEvent
|
||||||
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageRotationManager.Companion.KEY_PACKAGE_LIFETIME_SECONDS
|
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageRotationManager.Companion.KEY_PACKAGE_LIFETIME_SECONDS
|
||||||
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageUtils
|
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageUtils
|
||||||
@@ -27,15 +28,19 @@ import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
|
|||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlin.io.encoding.Base64
|
import kotlin.io.encoding.Base64
|
||||||
|
import kotlin.time.Instant
|
||||||
|
|
||||||
class DatabaseMarmotRepository(
|
class DatabaseMarmotRepository(
|
||||||
val database: TorchDatabase,
|
val database: TorchDatabase,
|
||||||
val scope: CoroutineScope
|
val scope: CoroutineScope
|
||||||
): MarmotRepository {
|
): MarmotRepository {
|
||||||
|
private val logger = Logger.withTag(TAG)
|
||||||
|
|
||||||
override suspend fun saveMarmotKeyPackageBundle(
|
override suspend fun saveMarmotKeyPackageBundle(
|
||||||
publicKey: HexKey,
|
publicKey: HexKey,
|
||||||
nsecPassword: String
|
nsecPassword: String
|
||||||
) {
|
) {
|
||||||
|
logger.d("saveMarmotKeyPackageBundle: $publicKey")
|
||||||
// KeyPackage...
|
// KeyPackage...
|
||||||
val dTag = KeyPackageUtils.generateRandomDTag() // TODO: Persist this...
|
val dTag = KeyPackageUtils.generateRandomDTag() // TODO: Persist this...
|
||||||
val identity = publicKey.hexToByteArray()
|
val identity = publicKey.hexToByteArray()
|
||||||
@@ -57,21 +62,23 @@ class DatabaseMarmotRepository(
|
|||||||
pubKey = publicKey,
|
pubKey = publicKey,
|
||||||
kind = keyPackageTemplate.kind,
|
kind = keyPackageTemplate.kind,
|
||||||
tags = keyPackageTemplate.tags,
|
tags = keyPackageTemplate.tags,
|
||||||
|
createdAt = Instant.fromEpochSeconds(keyPackageTemplate.createdAt),
|
||||||
content = keyPackageTemplate.content
|
content = keyPackageTemplate.content
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
val id = EventHasher.hashIdBytes(
|
val id = EventHasher.hashId(
|
||||||
pubKey =publicKey,
|
pubKey = publicKey,
|
||||||
createdAt = keyPackageTemplate.createdAt,
|
createdAt = keyPackageTemplate.createdAt,
|
||||||
kind = keyPackageTemplate.kind,
|
kind = keyPackageTemplate.kind,
|
||||||
tags = keyPackageTemplate.tags,
|
tags = keyPackageTemplate.tags,
|
||||||
content = keyPackageTemplate.content
|
content = keyPackageTemplate.content
|
||||||
)
|
)
|
||||||
|
logger.d("keyPackageEventId: $id")
|
||||||
|
|
||||||
database.marmotKeyPackageBundleDao().upsert(
|
database.marmotKeyPackageBundleDao().upsert(
|
||||||
MarmotKeyPackageBundle(
|
MarmotKeyPackageBundle(
|
||||||
id = id.toHexKey(),
|
id = id,
|
||||||
publicKey = publicKey,
|
publicKey = publicKey,
|
||||||
tlsEncodedMarmotKeyPackage = bundle.keyPackage.toTlsBytes(),
|
tlsEncodedMarmotKeyPackage = bundle.keyPackage.toTlsBytes(),
|
||||||
ncryptsecInitPrivateKey = bundle.initPrivateKey.toHex(), // TODO: ncryptSec this using the private key
|
ncryptsecInitPrivateKey = bundle.initPrivateKey.toHex(), // TODO: ncryptSec this using the private key
|
||||||
@@ -171,4 +178,7 @@ class DatabaseMarmotRepository(
|
|||||||
return unsigned.copy(signature = signature)
|
return unsigned.copy(signature = signature)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "DatabaseMarmotRepository"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user