Skip to content

Commit

Permalink
make optional
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Oct 18, 2024
1 parent 15488ce commit a252ccd
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SmartContractWalletTest {
val davonSCWClient2 = runBlocking {
Client().buildV3(
address = davonSCW.address,
contractChainId = davonSCW.chainId,
chainId = davonSCW.chainId,
options = options
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FakeSCWWallet : SigningKey {
override val isSmartContractWallet: Boolean
get() = true

override var chainId: Long = 31337L
override var chainId: Long? = 31337L

companion object {
fun generate(): FakeSCWWallet {
Expand All @@ -76,7 +76,7 @@ class FakeSCWWallet : SigningKey {
}
}

override suspend fun signSmartContract(message: String): ByteArray {
override suspend fun signSCW(message: String): ByteArray {
val smartWallet = CoinbaseSmartWallet.load(
walletAddress,
web3j,
Expand Down
9 changes: 5 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 @@ -336,13 +336,13 @@ class Client() {
// Function to build a V3 client without a signing key (using only address (& chainId for SCW))
suspend fun buildV3(
address: String,
contractChainId: Long? = null,
chainId: Long? = null,
options: ClientOptions? = null,
): Client {
this.hasV2Client = false
val clientOptions = options ?: ClientOptions(enableV3 = true)
val accountAddress =
if (contractChainId != null) "eip155:$contractChainId:${address.lowercase()}" else address.lowercase()
if (chainId != null) "eip155:$chainId:${address.lowercase()}" else address.lowercase()
return try {
initializeV3Client(accountAddress, clientOptions)
} catch (e: Exception) {
Expand Down Expand Up @@ -449,10 +449,11 @@ 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")
signatureRequest.addScwSignature(
account.signSmartContract(signatureRequest.signatureText()),
account.signSCW(signatureRequest.signatureText()),
account.address.lowercase(),
account.chainId.toULong(),
chainId.toULong(),
account.blockNumber?.toULong()
)
} else {
Expand Down
8 changes: 4 additions & 4 deletions library/src/main/java/org/xmtp/android/library/SigningKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ interface SigningKey {
get() = false

// Default chainId value set to 1
var chainId: Long
get() = 1
var chainId: Long?
get() = null
set(_) {}

// Default blockNumber value set to null
Expand All @@ -41,8 +41,8 @@ interface SigningKey {
throw NotImplementedError("sign(String) is not implemented.")
}

suspend fun signSmartContract(message: String): ByteArray {
throw NotImplementedError("signSmartContract(String) is not implemented.")
suspend fun signSCW(message: String): ByteArray {
throw NotImplementedError("signSCW(String) is not implemented.")
}
}

Expand Down
Binary file modified library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/x86/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so
Binary file not shown.

0 comments on commit a252ccd

Please sign in to comment.