Skip to content

Commit

Permalink
fix up the formating and the test issues with ci
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Dec 16, 2023
1 parent 8ca10e4 commit 1b93063
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.xmtp.android.library
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Assert.fail
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.xmtp.android.library.messages.PrivateKeyBuilder
Expand Down Expand Up @@ -104,12 +105,12 @@ class ClientTest {
}

@Test
@Ignore("CI Issues")
fun testPreEnableIdentityCallback() {
val fakeWallet = PrivateKeyBuilder()
val expectation = CompletableFuture<Unit>()

val preEnableIdentityCallback: suspend () -> Unit = {
println("preEnableIdentityCallback called")
expectation.complete(Unit)
}

Expand All @@ -127,12 +128,12 @@ class ClientTest {
}

@Test
@Ignore("CI Issues")
fun testPreCreateIdentityCallback() {
val fakeWallet = PrivateKeyBuilder()
val expectation = CompletableFuture<Unit>()

val preCreateIdentityCallback: suspend () -> Unit = {
println("preCreateIdentityCallback called")
expectation.complete(Unit)
}

Expand Down
10 changes: 7 additions & 3 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ typealias PublishResponse = org.xmtp.proto.message.api.v1.MessageApiOuterClass.P
typealias QueryResponse = org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryResponse
typealias PreEventCallback = suspend () -> Unit

data class ClientOptions(val api: Api = Api(), val preCreateIdentityCallback: PreEventCallback? = null, val preEnableIdentityCallback: PreEventCallback? = null) {
data class ClientOptions(
val api: Api = Api(),
val preCreateIdentityCallback: PreEventCallback? = null,
val preEnableIdentityCallback: PreEventCallback? = null,
) {
data class Api(
val env: XMTPEnvironment = XMTPEnvironment.DEV,
val isSecure: Boolean = true,
Expand Down Expand Up @@ -183,7 +187,7 @@ class Client() {
private suspend fun loadOrCreateKeys(
account: SigningKey,
apiClient: ApiClient,
options: ClientOptions? = null
options: ClientOptions? = null,
): PrivateKeyBundleV1 {
val keys = loadPrivateKeys(account, apiClient, options)
return if (keys != null) {
Expand All @@ -200,7 +204,7 @@ class Client() {
private suspend fun loadPrivateKeys(
account: SigningKey,
apiClient: ApiClient,
options: ClientOptions? = null
options: ClientOptions? = null,
): PrivateKeyBundleV1? {
val encryptedBundles = authCheck(apiClient, account.address)
for (encryptedBundle in encryptedBundles) {
Expand Down
5 changes: 4 additions & 1 deletion library/src/main/java/org/xmtp/android/library/SigningKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ interface SigningKey {
suspend fun sign(message: String): SignatureOuterClass.Signature?
}

fun SigningKey.createIdentity(identity: PrivateKeyOuterClass.PrivateKey, preCreateIdentityCallback: PreEventCallback? = null): AuthorizedIdentity {
fun SigningKey.createIdentity(
identity: PrivateKeyOuterClass.PrivateKey,
preCreateIdentityCallback: PreEventCallback? = null,
): AuthorizedIdentity {
val slimKey = PublicKeyOuterClass.PublicKey.newBuilder().apply {
timestamp = Date().time
secp256K1Uncompressed = identity.publicKey.secp256K1Uncompressed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import org.xmtp.android.library.XMTPException

typealias EncryptedPrivateKeyBundle = org.xmtp.proto.message.contents.PrivateKeyOuterClass.EncryptedPrivateKeyBundle

fun EncryptedPrivateKeyBundle.decrypted(key: SigningKey, preEnableIdentityCallback: PreEventCallback? = null): PrivateKeyBundle {
fun EncryptedPrivateKeyBundle.decrypted(
key: SigningKey,
preEnableIdentityCallback: PreEventCallback? = null,
): PrivateKeyBundle {
runBlocking {
preEnableIdentityCallback?.invoke()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class PrivateKeyBundleBuilder {
}
}

fun PrivateKeyBundle.encrypted(key: SigningKey, preEnableIdentityCallback: PreEventCallback? = null): EncryptedPrivateKeyBundle {
fun PrivateKeyBundle.encrypted(
key: SigningKey,
preEnableIdentityCallback: PreEventCallback? = null,
): EncryptedPrivateKeyBundle {
val bundleBytes = toByteArray()
val walletPreKey = SecureRandom().generateSeed(32)
runBlocking {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ class PrivateKeyBundleV1Builder {
}
}

fun PrivateKeyBundleV1.generate(wallet: SigningKey, options: ClientOptions? = null): PrivateKeyBundleV1 {
fun PrivateKeyBundleV1.generate(
wallet: SigningKey,
options: ClientOptions? = null,
): PrivateKeyBundleV1 {
val privateKey = PrivateKeyBuilder()
val authorizedIdentity = wallet.createIdentity(privateKey.getPrivateKey(), options?.preCreateIdentityCallback)
val authorizedIdentity =
wallet.createIdentity(privateKey.getPrivateKey(), options?.preCreateIdentityCallback)
var bundle = authorizedIdentity.toBundle
var preKey = PrivateKey.newBuilder().build().generate()
val bytesToSign = UnsignedPublicKeyBuilder.buildFromPublicKey(preKey.publicKey).toByteArray()
Expand Down

0 comments on commit 1b93063

Please sign in to comment.