Skip to content

Commit

Permalink
Merge pull request #1490 from WalletConnect/develop
Browse files Browse the repository at this point in the history
BOM_1.35.1
  • Loading branch information
jakubuid authored Aug 28, 2024
2 parents f9a7369 + de3b6fc commit 87179ce
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 32 deletions.
1 change: 1 addition & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {

| BOM | [Core SDK](core/android) | [Sign SDK](protocol/sign) | [Auth SDK](protocol/auth) | [Chat SDK](protocol/chat) | [Notify SDK](protocol/notify) | [web3wallet](product/web3wallet) | [web3modal](product/web3modal) | [WalletConnectModal](product/walletconnectmodal) |
|-----------------------------------------------------------------------------------------|--------------------------|---------------------------|---------------------------|---------------------------|:------------------------------|----------------------------------|--------------------------------|--------------------------------------------------|
| 1.35.1 | 1.35.1 | 2.35.1 | 1.28.9 | 1.0.0.beta36 | 1.3.10 | 1.35.1 | 1.6.5 | 1.5.10 |
| 1.35.0 | 1.35.0 | 2.35.0 | 1.28.8 | 1.0.0.beta35 | 1.3.9 | 1.35.0 | 1.6.4 | 1.5.9 |
| 1.34.1 | 1.34.1 | 2.34.1 | 1.28.7 | 1.0.0.beta34 | 1.3.8 | 1.34.1 | 1.6.3 | 1.5.8 |
| 1.34.0 | 1.34.0 | 2.34.0 | 1.28.6 | 1.0.0.beta33 | 1.3.7 | 1.34.0 | 1.6.2 | 1.5.7 |
Expand Down
22 changes: 11 additions & 11 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ const val KEY_PUBLISH_ARTIFACT_ID = "PUBLISH_ARTIFACT_ID"
const val KEY_SDK_NAME = "SDK_NAME"

//Latest versions
const val BOM_VERSION = "1.35.0"
const val FOUNDATION_VERSION = "1.18.2"
const val CORE_VERSION = "1.35.0"
const val SIGN_VERSION = "2.35.0"
const val AUTH_VERSION = "1.28.8"
const val CHAT_VERSION = "1.0.0-beta35"
const val NOTIFY_VERSION = "1.3.9"
const val WEB_3_WALLET_VERSION = "1.35.0"
const val WEB_3_MODAL_VERSION = "1.6.4"
const val WC_MODAL_VERSION = "1.5.9"
const val MODAL_CORE_VERSION = "1.6.4"
const val BOM_VERSION = "1.35.1"
const val FOUNDATION_VERSION = "1.18.3"
const val CORE_VERSION = "1.35.1"
const val SIGN_VERSION = "2.35.1"
const val AUTH_VERSION = "1.28.9"
const val CHAT_VERSION = "1.0.0-beta36"
const val NOTIFY_VERSION = "1.3.10"
const val WEB_3_WALLET_VERSION = "1.35.1"
const val WEB_3_MODAL_VERSION = "1.6.5"
const val WC_MODAL_VERSION = "1.5.10"
const val MODAL_CORE_VERSION = "1.6.5"

//Artifact ids
const val ANDROID_BOM = "android-bom"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ internal class GetSampleWalletsUseCase(
"com.walletconnect.sample.wallet.debug" to SampleWalletDebug,
"com.walletconnect.sample.wallet.internal" to SampleWalletInternal,
"com.walletconnect.sample.wallet" to SampleWalletRelease,
"com.walletconnect.web3wallet.rnsample.internal" to RNSampleWallet
"com.walletconnect.web3wallet.rnsample.internal" to RNSampleWallet,
"com.walletconnect.flutterwallet" to FLSampleWallet,
"com.walletconnect.flutterwallet.internal" to FLSampleWalletInternal
)
samples.forEach { (walletPackage, wallet) ->
wallet.apply {
Expand Down Expand Up @@ -78,4 +80,30 @@ private val RNSampleWallet = Wallet(
webAppLink = null,
linkMode = "https://lab.web3modal.com/rn_walletkit",
true
)

private val FLSampleWallet = Wallet(
id = "FLSampleWallet",
name = "FL Sample",
homePage = "https://walletconnect.com",
imageUrl = "https://raw.githubusercontent.com/WalletConnect/WalletConnectKotlinV2/develop/sample/wallet/src/main/res/drawable-xxxhdpi/wc_icon.png",
order = "5",
mobileLink = "wcflutterwallet://",
playStore = null,
webAppLink = null,
linkMode = "https://lab.web3modal.com/flutter_walletkit",
true
)

private val FLSampleWalletInternal = Wallet(
id = "FLSampleWalletInternal",
name = "FL Sample Internal",
homePage = "https://walletconnect.com",
imageUrl = "https://raw.githubusercontent.com/WalletConnect/WalletConnectKotlinV2/develop/sample/wallet/src/main/res/drawable-xxxhdpi/wc_icon.png",
order = "6",
mobileLink = "wcflutterwallet-internal://",
playStore = null,
webAppLink = null,
linkMode = "https://dev.lab.web3modal.com/flutter_walletkit_internal",
true
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ internal class VerifyClient(
}
}

override fun resolveV2(attestation: String, metadataUrl: String, onSuccess: (VerifyResult) -> Unit, onError: (Throwable) -> Unit) {
override fun resolveV2(attestationId: String, attestationJWT: String, metadataUrl: String, onSuccess: (VerifyResult) -> Unit, onError: (Throwable) -> Unit) {
try {
verifyRepository.resolveV2(attestation, metadataUrl, onSuccess, onError)
verifyRepository.resolveV2(attestationId, attestationJWT, metadataUrl, onSuccess, onError)
} catch (e: Exception) {
onError(e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ interface VerifyInterface {
fun initialize()
fun register(attestationId: String, onSuccess: () -> Unit, onError: (Throwable) -> Unit)
fun resolve(attestationId: String, metadataUrl: String, onSuccess: (VerifyResult) -> Unit, onError: (Throwable) -> Unit)
fun resolveV2(attestation: String, metadataUrl: String, onSuccess: (VerifyResult) -> Unit, onError: (Throwable) -> Unit)
fun resolveV2(attestationId: String, attestationJWT: String, metadataUrl: String, onSuccess: (VerifyResult) -> Unit, onError: (Throwable) -> Unit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ResolveAttestationIdUseCase(private val verifyInterface: VerifyInterface,
request: WCRequest,
onResolve: (VerifyContext) -> Unit
) {
verifyInterface.resolveV2(request.attestation!!, metadataUrl,
verifyInterface.resolveV2(sha256(request.encryptedMessage.toByteArray()), request.attestation!!, metadataUrl,
onSuccess = { result ->
insertContext(VerifyContext(request.id, result.origin, result.validation, verifyUrl, result.isScam)) { verifyContext -> onResolve(verifyContext) }
},
Expand Down Expand Up @@ -64,8 +64,12 @@ class ResolveAttestationIdUseCase(private val verifyInterface: VerifyInterface,
private fun insertContext(context: VerifyContext, onResolve: (VerifyContext) -> Unit) {
scope.launch {
supervisorScope {
repository.insertOrAbort(context)
onResolve(context)
try {
repository.insertOrAbort(context)
onResolve(context)
} catch (e: Exception) {
onResolve(context)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class VerifyRepository(
}
}

fun resolveV2(attestationJWT: String, metadataUrl: String, onSuccess: (VerifyResult) -> Unit, onError: (Throwable) -> Unit) {
fun resolveV2(attestationId: String, attestationJWT: String, metadataUrl: String, onSuccess: (VerifyResult) -> Unit, onError: (Throwable) -> Unit) {
scope.launch {
supervisorScope {
getVerifyPublicKey().fold(
Expand All @@ -47,7 +47,7 @@ internal class VerifyRepository(
return@supervisorScope
}

onSuccess(VerifyResult(getValidation(claims, metadataUrl), claims.isScam, claims.origin))
checkIds(attestationId, claims, metadataUrl, onSuccess, onError)
} catch (e: Exception) {
onError(e)
}
Expand Down Expand Up @@ -78,6 +78,20 @@ internal class VerifyRepository(
}
}

private fun checkIds(
attestationId: String,
claims: VerifyClaims,
metadataUrl: String,
onSuccess: (VerifyResult) -> Unit,
onError: (Throwable) -> Unit
) {
if (attestationId != claims.id) {
resolve(attestationId, metadataUrl, onSuccess, onError)
} else {
onSuccess(VerifyResult(getValidation(claims, metadataUrl), claims.isScam, claims.origin))
}
}

private fun getValidation(claims: VerifyClaims, metadataUrl: String): Validation =
when {
!claims.isVerified || currentTimeInSeconds >= claims.expiration -> Validation.UNKNOWN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.walletconnect.utils.Empty
import io.mockk.Runs
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.invoke
import io.mockk.just
import io.mockk.mockk
import io.mockk.verify
Expand Down Expand Up @@ -77,8 +78,8 @@ class ResolveAttestationUseCaseTest {
isScam = false
)

coEvery { verifyInterface.resolveV2(any(), any(), any(), any()) } answers {
thirdArg<(VerifyResult) -> Unit>().invoke(result)
coEvery { verifyInterface.resolveV2(any(), any(), any(), captureLambda(), any()) } answers {
lambda<(VerifyResult) -> Unit>().invoke(result)
}

coEvery { repository.insertOrAbort(any()) } just Runs
Expand All @@ -90,7 +91,7 @@ class ResolveAttestationUseCaseTest {
}

coVerify {
verifyInterface.resolveV2("jwt", metadataUrl, any(), any())
verifyInterface.resolveV2(any(), "jwt", metadataUrl, any(), any())
}
coVerify {
repository.insertOrAbort(withArg { context ->
Expand Down Expand Up @@ -121,8 +122,8 @@ class ResolveAttestationUseCaseTest {
)
val metadataUrl = "https://metadata.url"

coEvery { verifyInterface.resolveV2(any(), any(), any(), any()) } answers {
thirdArg<(VerifyResult) -> Unit>().invoke(result)
coEvery { verifyInterface.resolveV2(any(), any(), any(), captureLambda(), any()) } answers {
lambda<(VerifyResult) -> Unit>().invoke(result)
}

coEvery { repository.insertOrAbort(any()) } just Runs
Expand All @@ -134,7 +135,7 @@ class ResolveAttestationUseCaseTest {
}

coVerify {
verifyInterface.resolveV2("jwt", metadataUrl, any(), any())
verifyInterface.resolveV2(any(), "jwt", metadataUrl, any(), any())
}
coVerify {
repository.insertOrAbort(withArg { context ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class VerifyClientTest {
val onSuccess = mockk<(VerifyResult) -> Unit>(relaxed = true)
val onError = mockk<(Throwable) -> Unit>(relaxed = true)

verifyClient.resolveV2(attestation, metadataUrl, onSuccess, onError)
verifyClient.resolveV2("id", attestation, metadataUrl, onSuccess, onError)

coVerify { verifyRepository.resolveV2(attestation, metadataUrl, onSuccess, onError) }
coVerify { verifyRepository.resolveV2("id", attestation, metadataUrl, onSuccess, onError) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ class VerifyRepositoryTest {
coVerify { verifyPublicKeyStorageRepository.upsertPublicKey(newKey, any()) }
}


@Test
fun `resolveV2 calls onSuccess when JWT is valid`() = testScope.runTest {
fun `resolveV2 calls onSuccess when JWT is valid and ids match`() = testScope.runTest {
val attestationId = "5106a25552e89acfb5bed83ee21bf4e80dbcd51b0b203f6925a369aacb1c860b"
val attestationJWT = "attestationJWT"
val metadataUrl = "https://metadata.url"
val publicKey = "0409b2f80ce60e6f59ed77ef0e984c4efa84b40d608c0b4d039edaf2989a01f2d92931708c7b50c464c347dd55b0eca971d05fbdba3ab00323e69e166fef61440d"
Expand All @@ -93,7 +95,38 @@ class VerifyRepositoryTest {
val onSuccess = mockk<(VerifyResult) -> Unit>(relaxed = true)
val onError = mockk<(Throwable) -> Unit>(relaxed = true)

verifyRepository.resolveV2(attestationJWT, metadataUrl, onSuccess, onError)
verifyRepository.resolveV2(attestationId, attestationJWT, metadataUrl, onSuccess, onError)

advanceUntilIdle()

verify { onSuccess(verifyResult) }
}

@Test
fun `resolveV2 calls onSuccess when JWT is valid and ids do not match`() = testScope.runTest {
val attestationId = "test"
val attestationJWT = "attestationJWT"
val metadataUrl = "https://metadata.url"
val publicKey = "0409b2f80ce60e6f59ed77ef0e984c4efa84b40d608c0b4d039edaf2989a01f2d92931708c7b50c464c347dd55b0eca971d05fbdba3ab00323e69e166fef61440d"
val verifyResult = VerifyResult(Validation.INVALID, false, "https://react-dapp-v2-git-chore-verify-v2-samples-walletconnect1.vercel.app")
val claimsJson =
"""{"exp":1722579908,"id":"5106a25552e89acfb5bed83ee21bf4e80dbcd51b0b203f6925a369aacb1c860b","origin":"https://react-dapp-v2-git-chore-verify-v2-samples-walletconnect1.vercel.app","isScam":null,"isVerified":true}"""

coEvery { verifyPublicKeyStorageRepository.getPublicKey() } returns Pair(publicKey, currentTimeInSeconds + 1000)
every { jwtRepository.verifyJWT(any(), any()) } returns true
every { jwtRepository.decodeClaimsJWT(any()) } returns claimsJson
coEvery { verifyService.resolveAttestation(attestationId) } returns Response.success(
Origin(
"attId",
origin = "https://react-dapp-v2-git-chore-verify-v2-samples-walletconnect1.vercel.app",
isScam = false
)
)

val onSuccess = mockk<(VerifyResult) -> Unit>(relaxed = true)
val onError = mockk<(Throwable) -> Unit>(relaxed = true)

verifyRepository.resolveV2(attestationId, attestationJWT, metadataUrl, onSuccess, onError)

advanceUntilIdle()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal fun engineModule() = module {

single<GetPendingAuthenticateRequestUseCaseInterface> { GetPendingAuthenticateRequestUseCase(jsonRpcHistory = get(), serializer = get()) }

single { DeleteRequestByIdUseCase(jsonRpcHistory = get()) }
single { DeleteRequestByIdUseCase(jsonRpcHistory = get(), verifyContextStorageRepository = get()) }

single { GetPendingJsonRpcHistoryEntryByIdUseCase(jsonRpcHistory = get(), serializer = get()) }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.walletconnect.sign.json_rpc.domain

import com.walletconnect.android.internal.common.storage.rpc.JsonRpcHistory
import com.walletconnect.android.internal.common.storage.verify.VerifyContextStorageRepository
import kotlinx.coroutines.supervisorScope

internal class DeleteRequestByIdUseCase(private val jsonRpcHistory: JsonRpcHistory) {
internal class DeleteRequestByIdUseCase(
private val jsonRpcHistory: JsonRpcHistory,
private val verifyContextStorageRepository: VerifyContextStorageRepository
) {

suspend operator fun invoke(id: Long) {
supervisorScope {
jsonRpcHistory.deleteRecordById(id)
verifyContextStorageRepository.delete(id)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.walletconnect.sign

import com.walletconnect.android.internal.common.storage.rpc.JsonRpcHistory
import com.walletconnect.android.internal.common.storage.verify.VerifyContextStorageRepository
import com.walletconnect.sign.json_rpc.domain.DeleteRequestByIdUseCase
import io.mockk.coVerify
import io.mockk.mockk
import io.mockk.slot
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Test

class DeleteRequestByIdUseCaseTest {
private lateinit var jsonRpcHistory: JsonRpcHistory
private lateinit var verifyContextStorageRepository: VerifyContextStorageRepository
private lateinit var deleteRequestByIdUseCase: DeleteRequestByIdUseCase

@Before
fun setup() {
jsonRpcHistory = mockk(relaxed = true)
verifyContextStorageRepository = mockk(relaxed = true)
deleteRequestByIdUseCase = DeleteRequestByIdUseCase(jsonRpcHistory, verifyContextStorageRepository)
}

@Test
fun `invoke should delete record by id from jsonRpcHistory and verifyContextStorageRepository`() = runBlocking {
val idSlot = slot<Long>()
val id = 123L

deleteRequestByIdUseCase.invoke(id)

coVerify(exactly = 1) { jsonRpcHistory.deleteRecordById(capture(idSlot)) }
coVerify(exactly = 1) { verifyContextStorageRepository.delete(capture(idSlot)) }
}
}
3 changes: 3 additions & 0 deletions sample/dapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<package android:name="com.walletconnect.sample.wallet"/>
<package android:name="com.walletconnect.sample.wallet.debug"/>
<package android:name="com.walletconnect.sample.wallet.internal"/>
<package android:name="com.walletconnect.web3wallet.rnsample.internal"/>
<package android:name="com.walletconnect.flutterwallet"/>
<package android:name="com.walletconnect.flutterwallet.internal"/>
</queries>

<application
Expand Down
6 changes: 6 additions & 0 deletions sample/modal/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
<package android:name="com.ripio.android" />
<package android:name="kh.com.sabay.sabaywallet" />
<package android:name="com.tokoin.wallet" />
<package android:name="com.walletconnect.sample.wallet"/>
<package android:name="com.walletconnect.sample.wallet.debug"/>
<package android:name="com.walletconnect.sample.wallet.internal"/>
<package android:name="com.walletconnect.web3wallet.rnsample.internal"/>
<package android:name="com.walletconnect.flutterwallet"/>
<package android:name="com.walletconnect.flutterwallet.internal"/>
</queries>

<application
Expand Down

0 comments on commit 87179ce

Please sign in to comment.