diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/marmotGroup/CreateGroupScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/marmotGroup/CreateGroupScreen.kt index a44befce5a..87df49bde0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/marmotGroup/CreateGroupScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/marmotGroup/CreateGroupScreen.kt @@ -41,6 +41,7 @@ import com.vitorpamplona.amethyst.ui.navigation.navs.INav import com.vitorpamplona.amethyst.ui.navigation.routes.Route import com.vitorpamplona.amethyst.ui.navigation.topbars.CreatingTopBar import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel +import com.vitorpamplona.quartz.nip01Core.core.toHexKey import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlin.random.Random @@ -61,7 +62,7 @@ fun CreateGroupScreen( onPost = { isCreating = true scope.launch(Dispatchers.IO) { - val nostrGroupId = Random.nextBytes(32).joinToString("") { "%02x".format(it) } + val nostrGroupId = Random.nextBytes(32).toHexKey() accountViewModel.createMarmotGroup(nostrGroupId) if (groupName.isNotBlank()) { accountViewModel.account.marmotGroupList diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/marmot/mip00KeyPackages/KeyPackageRotationManager.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/marmot/mip00KeyPackages/KeyPackageRotationManager.kt index 196c8eeb31..33e3c81ea5 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/marmot/mip00KeyPackages/KeyPackageRotationManager.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/marmot/mip00KeyPackages/KeyPackageRotationManager.kt @@ -30,6 +30,7 @@ import com.vitorpamplona.quartz.marmot.mls.tree.Credential import com.vitorpamplona.quartz.marmot.mls.tree.LeafNode import com.vitorpamplona.quartz.marmot.mls.tree.LeafNodeSource import com.vitorpamplona.quartz.marmot.mls.tree.Lifetime +import com.vitorpamplona.quartz.utils.TimeUtils /** * Manages KeyPackage creation and rotation lifecycle (MIP-00). @@ -190,7 +191,7 @@ class KeyPackageRotationManager { identity: ByteArray, signingKey: ByteArray, ): LeafNode { - val now = System.currentTimeMillis() / 1000 + val now = TimeUtils.now() val unsigned = LeafNode( encryptionKey = encryptionKey, diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/marmot/mls/group/MlsGroup.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/marmot/mls/group/MlsGroup.kt index def17d256d..d44b4a993e 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/marmot/mls/group/MlsGroup.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/marmot/mls/group/MlsGroup.kt @@ -55,6 +55,8 @@ import com.vitorpamplona.quartz.marmot.mls.tree.LeafNodeSource import com.vitorpamplona.quartz.marmot.mls.tree.Lifetime import com.vitorpamplona.quartz.marmot.mls.tree.RatchetTree import com.vitorpamplona.quartz.marmot.mls.tree.UpdatePathNode +import com.vitorpamplona.quartz.nip01Core.core.toHexKey +import com.vitorpamplona.quartz.utils.TimeUtils import com.vitorpamplona.quartz.utils.mac.MacInstance /** @@ -170,11 +172,9 @@ class MlsGroup private constructor( pskId: ByteArray, psk: ByteArray, ) { - pskStore[pskId.toHexId()] = psk + pskStore[pskId.toHexKey()] = psk } - private fun ByteArray.toHexId(): String = joinToString("") { "%02x".format(it) } - /** * Get the list of members (leaf index -> LeafNode). */ @@ -845,7 +845,7 @@ class MlsGroup private constructor( var pskSecret = ByteArray(MlsCryptoProvider.HASH_OUTPUT_LENGTH) for (pskProposal in pskProposals) { val pskValue = - pskStore[pskProposal.pskId.toHexId()] + pskStore[pskProposal.pskId.toHexKey()] ?: ByteArray(MlsCryptoProvider.HASH_OUTPUT_LENGTH) // Unknown PSK = zeros pskSecret = MlsCryptoProvider.hkdfExtract(pskSecret, pskValue) } @@ -990,7 +990,7 @@ class MlsGroup private constructor( // Validate KeyPackage lifetime (RFC 9420 Section 10.1) val lifetime = proposal.keyPackage.leafNode.lifetime if (lifetime != null) { - val now = System.currentTimeMillis() / 1000 + val now = TimeUtils.now() require(now >= lifetime.notBefore && now <= lifetime.notAfter) { "KeyPackage lifetime expired or not yet valid" }