diff --git a/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt index 45b0eb209..76700254e 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt @@ -331,7 +331,80 @@ class ClientTest { listOf(fixtures.boClient.inboxId, fixtures.caroClient.inboxId) ) } - assertEquals(states.first().recoveryAddress.lowercase(), fixtures.bo.walletAddress.lowercase()) - assertEquals(states.last().recoveryAddress.lowercase(), fixtures.caro.walletAddress.lowercase()) + assertEquals( + states.first().recoveryAddress.lowercase(), + fixtures.bo.walletAddress.lowercase() + ) + assertEquals( + states.last().recoveryAddress.lowercase(), + fixtures.caro.walletAddress.lowercase() + ) + } + + @Test + fun testsSignatures() { + val fixtures = fixtures() + val signature = fixtures.alixClient.signWithInstallationKey("Testing") + assertEquals(fixtures.alixClient.verifySignature("Testing", signature), true) + assertEquals(fixtures.alixClient.verifySignature("Not Testing", signature), false) + + val alixInstallationId = fixtures.alixClient.installationId + assertEquals( + fixtures.alixClient.verifySignatureWithInstallationId( + "Testing", + signature, + alixInstallationId + ), true + ) + assertEquals( + fixtures.alixClient.verifySignatureWithInstallationId( + "Not Testing", + signature, + alixInstallationId + ), false + ) + assertEquals( + fixtures.alixClient.verifySignatureWithInstallationId( + "Testing", + signature, + fixtures.boClient.installationId + ), false + ) + assertEquals( + fixtures.boClient.verifySignatureWithInstallationId( + "Testing", + signature, + alixInstallationId + ), true + ) + fixtures.alixClient.deleteLocalDatabase() + + val key = SecureRandom().generateSeed(32) + val context = InstrumentationRegistry.getInstrumentation().targetContext + val alixClient2 = runBlocking { + Client().create( + account = fixtures.alixAccount, + options = ClientOptions( + ClientOptions.Api(XMTPEnvironment.LOCAL, false), + appContext = context, + dbEncryptionKey = key + ) + ) + } + + assertEquals( + alixClient2.verifySignatureWithInstallationId( + "Testing", + signature, + alixInstallationId + ), true + ) + assertEquals( + alixClient2.verifySignatureWithInstallationId( + "Testing2", + signature, + alixInstallationId + ), false + ) } } diff --git a/library/src/main/java/org/xmtp/android/library/Client.kt b/library/src/main/java/org/xmtp/android/library/Client.kt index e2dc101f5..773b8fd87 100644 --- a/library/src/main/java/org/xmtp/android/library/Client.kt +++ b/library/src/main/java/org/xmtp/android/library/Client.kt @@ -212,6 +212,24 @@ class Client() { return ffiClient.signWithInstallationKey(message) } + fun verifySignature(message: String, signature: ByteArray): Boolean { + return try { + ffiClient.verifySignedWithInstallationKey(message, signature) + true + } catch (e: Exception) { + false + } + } + + fun verifySignatureWithInstallationId(message: String, signature: ByteArray, installationId: String): Boolean { + return try { + ffiClient.verifySignedWithPublicKey(message, signature, installationId.hexToByteArray()) + true + } catch (e: Exception) { + false + } + } + fun findGroup(groupId: String): Group? { return try { Group(this, ffiClient.conversation(groupId.hexToByteArray()))