Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/xmtp/xmtp-android into np/V…
Browse files Browse the repository at this point in the history
…3-only-dms
  • Loading branch information
nplasterer committed Oct 22, 2024
2 parents 88e2024 + 492c797 commit 29e60e4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class FakeSCWWallet : SigningKey {
override val address: String
get() = walletAddress

override val isSmartContractWallet: Boolean
get() = true
override val type: WalletType
get() = WalletType.SCW

override var chainId: Long? = 31337L

Expand Down
7 changes: 3 additions & 4 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class Client() {
this.hasV2Client = false
val clientOptions = options ?: ClientOptions(enableV3 = true)
val accountAddress =
if (account.isSmartContractWallet) "eip155:${account.chainId}:${account.address.lowercase()}" else account.address.lowercase()
if (account.chainId != null) "eip155:${account.chainId}:${account.address.lowercase()}" else account.address.lowercase()
return try {
initializeV3Client(accountAddress, clientOptions, account)
} catch (e: Exception) {
Expand Down Expand Up @@ -448,9 +448,8 @@ class Client() {
}
v3Client.signatureRequest()?.let { signatureRequest ->
if (account != null) {
if (account.isSmartContractWallet) {
val chainId = account.chainId
?: throw XMTPException("ChainId is required for smart contract wallets")
if (account.type == WalletType.SCW) {
val chainId = account.chainId ?: throw XMTPException("ChainId is required for smart contract wallets")
signatureRequest.addScwSignature(
account.signSCW(signatureRequest.signatureText()),
account.address.lowercase(),
Expand Down
26 changes: 12 additions & 14 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import org.xmtp.proto.keystore.api.v1.Keystore.GetConversationHmacKeysResponse.H
import org.xmtp.proto.keystore.api.v1.Keystore.TopicMap.TopicData
import org.xmtp.proto.message.contents.Contact
import org.xmtp.proto.message.contents.Invitation
import uniffi.xmtpv3.FfiConsentState
import uniffi.xmtpv3.FfiConversation
import uniffi.xmtpv3.FfiConversationCallback
import uniffi.xmtpv3.FfiConversations
Expand Down Expand Up @@ -554,10 +553,20 @@ data class Conversations(
}
}
}

val stream = libXMTPConversations?.stream(conversationCallback)
?: throw XMTPException("Client does not support V3")
?: throw XMTPException("Client does not support Groups")
awaitClose { stream.end() }
}

private fun streamGroupConversations(): Flow<Conversation> = callbackFlow {
val groupCallback = object : FfiConversationCallback {
override fun onConversation(conversation: FfiConversation) {
trySend(Conversation.Group(Group(client, conversation)))
}
}

val stream = libXMTPConversations?.streamGroups(groupCallback)
?: throw XMTPException("Client does not support Groups")
awaitClose { stream.end() }
}

Expand Down Expand Up @@ -665,17 +674,6 @@ data class Conversations(
awaitClose { stream.end() }
}

private fun streamGroupConversations(): Flow<Conversation> = callbackFlow {
val groupCallback = object : FfiConversationCallback {
override fun onConversation(conversation: FfiConversation) {
trySend(Conversation.Group(Group(client, conversation)))
}
}
val stream = libXMTPConversations?.streamGroups(groupCallback)
?: throw XMTPException("Client does not support Groups")
awaitClose { stream.end() }
}

// ------- V1 V2 to be deprecated ------

/**
Expand Down
11 changes: 8 additions & 3 deletions library/src/main/java/org/xmtp/android/library/SigningKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import java.util.Date
interface SigningKey {
val address: String

// If this signing key is a smart contract wallet
val isSmartContractWallet: Boolean
get() = false
// The wallet type if Smart Contract Wallet this should be type SCW.
val type: WalletType
get() = WalletType.EOA

// The chainId of the Smart Contract Wallet value should be null if not SCW
var chainId: Long?
Expand All @@ -46,6 +46,11 @@ interface SigningKey {
}
}

enum class WalletType {
SCW, // Smart Contract Wallet
EOA // Externally Owned Account *Default
}

/**
* This prompts the wallet to sign a personal message.
* It authorizes the `identity` key to act on behalf of this wallet.
Expand Down

0 comments on commit 29e60e4

Please sign in to comment.