Skip to content

Commit

Permalink
get the tests passing with a account
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jan 26, 2024
1 parent 3ed13f1 commit 44666b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ClientTest {
)

val bundle = client.privateKeyBundle
val clientFromV1Bundle = Client().buildFromBundle(bundle, options = options)
val clientFromV1Bundle = Client().buildFromBundle(bundle, account = fakeWallet, options = options)
assertEquals(client.address, clientFromV1Bundle.address)
assertEquals(
client.privateKeyBundleV1.identityKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class LocalInstrumentedTest {
// When Alice's device wakes up, it uses her saved credentials
val alice2 = Client().buildFromBundle(
PrivateKeyBundle.parseFrom(keyBundle),
null,
options
)
// And it uses the saved topic data for the conversation
Expand Down
15 changes: 9 additions & 6 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,17 @@ class Client() {
this.conversations = Conversations(client = this)
}

fun buildFrom(bundle: PrivateKeyBundleV1, options: ClientOptions? = null): Client {
fun buildFrom(bundle: PrivateKeyBundleV1, account: SigningKey? = null, options: ClientOptions? = null): Client {
val address = bundle.identityKey.publicKey.recoverWalletSignerPublicKey().walletAddress
val clientOptions = options ?: ClientOptions()
val apiClient =
GRPCApiClient(environment = clientOptions.api.env, secure = clientOptions.api.isSecure)
val v3Client: FfiXmtpClient? = if (isAlphaMlsEnabled(options)) {
if (account == null) throw XMTPException("Signing Key required to use groups.")
runBlocking {
ffiXmtpClient(
options,
PrivateKeyBuilder(bundle.identityKey),
account,
options?.appContext,
bundle,
LegacyIdentitySource.STATIC
Expand Down Expand Up @@ -235,25 +236,27 @@ class Client() {
}
}

fun buildFromBundle(bundle: PrivateKeyBundle, options: ClientOptions? = null): Client =
buildFromV1Bundle(v1Bundle = bundle.v1, options = options)
fun buildFromBundle(bundle: PrivateKeyBundle, account: SigningKey? = null, options: ClientOptions? = null): Client =
buildFromV1Bundle(v1Bundle = bundle.v1, account= account, options = options)

fun buildFromV1Bundle(v1Bundle: PrivateKeyBundleV1, options: ClientOptions? = null): Client {
fun buildFromV1Bundle(v1Bundle: PrivateKeyBundleV1, account: SigningKey? = null, options: ClientOptions? = null): Client {
val address = v1Bundle.identityKey.publicKey.recoverWalletSignerPublicKey().walletAddress
val newOptions = options ?: ClientOptions()
val apiClient =
GRPCApiClient(environment = newOptions.api.env, secure = newOptions.api.isSecure)
val v3Client: FfiXmtpClient? = if (isAlphaMlsEnabled(options)) {
if (account == null) throw XMTPException("Signing Key required to use groups.")
runBlocking {
ffiXmtpClient(
options,
PrivateKeyBuilder(v1Bundle.identityKey),
account,
options?.appContext,
v1Bundle,
LegacyIdentitySource.STATIC
)
}
} else null

return Client(
address = address,
privateKeyBundleV1 = v1Bundle,
Expand Down

0 comments on commit 44666b4

Please sign in to comment.