Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: TVF #46

Merged
merged 30 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
61bfd8c
add correlationId
jakubuid Jan 21, 2025
23e7089
add tvf fields on session request
jakubuid Jan 21, 2025
65d37ea
calculate wallet responses
jakubuid Jan 23, 2025
cf4f928
clean up
jakubuid Jan 23, 2025
d48c8f1
Add TVF tests
jakubuid Jan 23, 2025
27b9185
clean up
jakubuid Jan 23, 2025
721a319
add session request use case tests
jakubuid Jan 24, 2025
643633f
add session request respond tests
jakubuid Jan 24, 2025
06b19a2
clean up
jakubuid Jan 27, 2025
82f82c2
handle tx receipt result
jakubuid Jan 29, 2025
3c0b838
Merge pull request #48 from reown-com/fix/handle_status
jakubuid Jan 30, 2025
e746f5f
send to if data is present
jakubuid Jan 31, 2025
1a29463
Merge branch 'develop' of github.com:reown-com/reown-kotlin into feat…
jakubuid Feb 3, 2025
a6dc7bf
use long for correlation id
jakubuid Feb 3, 2025
6793d2e
disable smart accounts integration
jakubuid Feb 3, 2025
95e154e
scope ca methods
jakubuid Feb 3, 2025
04dccfd
add execute method
jakubuid Feb 4, 2025
f66e4a6
Merge branch 'feat/tvf' of github.com:reown-com/reown-kotlin into ca_…
jakubuid Feb 4, 2025
63369c5
add pulse metadata
jakubuid Feb 5, 2025
d104d93
use prepare detailed
jakubuid Feb 6, 2025
ec8b15e
yttrium test
jakubuid Feb 7, 2025
e8bfc07
update yttrium
jakubuid Feb 10, 2025
14a917e
add tvf params test
jakubuid Feb 10, 2025
b32ed53
change name
jakubuid Feb 10, 2025
9b12e15
change name
jakubuid Feb 10, 2025
8ad2041
names update
jakubuid Feb 12, 2025
810021d
Merge branch 'develop' of github.com:reown-com/reown-kotlin into feat…
jakubuid Feb 12, 2025
c9ad21a
Merge branch 'feat/tvf' of github.com:reown-com/reown-kotlin into ca_…
jakubuid Feb 12, 2025
938a76b
bump yttrium
jakubuid Feb 13, 2025
45e6c17
Merge pull request #50 from reown-com/ca_execute
jakubuid Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal fun JsonRpcHistoryRecord.toWCResponse(result: JsonRpcResponse, params:

@JvmSynthetic
internal fun IrnParams.toRelay(): Relay.Model.IrnParams =
Relay.Model.IrnParams(tag.id, ttl.seconds, prompt)
Relay.Model.IrnParams(tag.id, ttl.seconds, correlationId, rpcMethods, chainId, txHashes, contractAddresses, prompt)

internal fun Subscription.toWCRequest(clientJsonRpc: ClientJsonRpc, params: ClientParams, transportType: TransportType): WCRequest =
WCRequest(topic, clientJsonRpc.id, clientJsonRpc.method, params, decryptedMessage, publishedAt, encryptedMessage, attestation, transportType)
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ package com.reown.android.internal.common.model

import com.reown.foundation.common.model.Ttl

data class IrnParams(val tag: Tags, val ttl: Ttl, val prompt: Boolean = false)
data class IrnParams(
val tag: Tags,
val ttl: Ttl,
val correlationId: String? = null,
val rpcMethods: List<String>? = null,
val chainId: String? = null,
val txHashes: List<String>? = null,
val contractAddresses: List<String>? = null,
jakubuid marked this conversation as resolved.
Show resolved Hide resolved
val prompt: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package com.reown.android.internal.common.model
enum class Tags(val id: Int) {
UNSUPPORTED_METHOD(0),

//Pairing Tags
PAIRING_DELETE(1000),
PAIRING_DELETE_RESPONSE(1001),

PAIRING_PING(1002),
PAIRING_PING_RESPONSE(1003),

//Sign Tags
SESSION_PROPOSE(1100),
SESSION_PROPOSE_RESPONSE_APPROVE(1101),
SESSION_PROPOSE_RESPONSE_REJECT(1120),
Expand Down Expand Up @@ -47,6 +49,7 @@ enum class Tags(val id: Int) {
SESSION_REQUEST_LINK_MODE(1125),
SESSION_REQUEST_LINK_MODE_RESPONSE(1126),

//Notify Tags
NOTIFY_SUBSCRIBE(4000),
NOTIFY_SUBSCRIBE_RESPONSE(4001),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ internal class PairingEngine(
jsonRpcInteractor.clientSyncJsonRpc
.filter { request -> request.method !in setOfRegisteredMethods }
.onEach { request ->
val irnParams = IrnParams(Tags.UNSUPPORTED_METHOD, Ttl(dayInSeconds))
val irnParams = IrnParams(Tags.UNSUPPORTED_METHOD, Ttl(dayInSeconds), correlationId = request.id.toString())
jsonRpcInteractor.respondWithError(request, Invalid.MethodUnsupported(request.method), irnParams)
}.map { request ->
SDKError(Exception(Invalid.MethodUnsupported(request.method).message))
Expand Down Expand Up @@ -237,10 +237,9 @@ internal class PairingEngine(
return onFailure(CannotFindSequenceForTopic("$NO_SEQUENCE_FOR_TOPIC_MESSAGE$topic"))
}

val pairing = pairingRepository.getPairingOrNullByTopic(Topic(topic))
val deleteParams = PairingParams.DeleteParams(6000, "User disconnected")
val pairingDelete = PairingRpc.PairingDelete(params = deleteParams)
val irnParams = IrnParams(Tags.PAIRING_DELETE, Ttl(dayInSeconds))
val irnParams = IrnParams(Tags.PAIRING_DELETE, Ttl(dayInSeconds), correlationId = pairingDelete.id.toString())
logger.log("Sending Pairing disconnect")
jsonRpcInteractor.publishJsonRpcRequest(Topic(topic), irnParams, pairingDelete,
onSuccess = {
Expand All @@ -264,7 +263,7 @@ internal class PairingEngine(
fun ping(topic: String, onSuccess: (String) -> Unit, onFailure: (Throwable) -> Unit) {
if (isPairingValid(topic)) {
val pingPayload = PairingRpc.PairingPing(params = PairingParams.PingParams())
val irnParams = IrnParams(Tags.PAIRING_PING, Ttl(thirtySeconds))
val irnParams = IrnParams(Tags.PAIRING_PING, Ttl(thirtySeconds), correlationId = pingPayload.id.toString())

jsonRpcInteractor.publishJsonRpcRequest(Topic(topic), irnParams, pingPayload,
onSuccess = { onPingSuccess(pingPayload, onSuccess, topic, onFailure) },
Expand Down Expand Up @@ -379,9 +378,8 @@ internal class PairingEngine(

@Deprecated(message = "This method has been deprecated. It will be removed soon.")
private suspend fun onPairingDelete(request: WCRequest, params: PairingParams.DeleteParams) {
val irnParams = IrnParams(Tags.PAIRING_DELETE_RESPONSE, Ttl(dayInSeconds))
val irnParams = IrnParams(Tags.PAIRING_DELETE_RESPONSE, Ttl(dayInSeconds), correlationId = request.id.toString())
try {
val pairing = pairingRepository.getPairingOrNullByTopic(request.topic)
if (!isPairingValid(request.topic.value)) {
jsonRpcInteractor.respondWithError(request, Uncategorized.NoMatchingTopic("Pairing", request.topic.value), irnParams)
return
Expand All @@ -401,7 +399,7 @@ internal class PairingEngine(

@Deprecated(message = "Ping method has been deprecated. It will be removed soon.")
private fun onPing(request: WCRequest) {
val irnParams = IrnParams(Tags.PAIRING_PING, Ttl(thirtySeconds))
val irnParams = IrnParams(Tags.PAIRING_PING, Ttl(thirtySeconds), correlationId = request.id.toString())
jsonRpcInteractor.respondWithSuccess(request, irnParams)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ internal class RelayerInteractorTest {
}

private fun publishJsonRpcRequests() {
val irnParamsVO = IrnParams(Tags.SESSION_PING, Ttl(300))
val irnParamsVO = IrnParams(Tags.SESSION_PING, Ttl(300), correlationId = "1234", prompt = true)
sut.publishJsonRpcRequest(
topicVO,
irnParamsVO,
Expand Down Expand Up @@ -193,7 +193,7 @@ internal class RelayerInteractorTest {
fun `RespondWithParams publishes result with params and request id on request topic`() {
val params: ClientParams = mockk()
val result = JsonRpcResponse.JsonRpcResult(request.id, result = params)
val irnParams = IrnParams(Tags.SESSION_PING, Ttl(300))
val irnParams = IrnParams(Tags.SESSION_PING, Ttl(300), correlationId = "1234", prompt = true)
mockRelayPublishSuccess()
sut.respondWithParams(request, params, irnParams, onSuccess = {}, onFailure = {})
verify { sut.publishJsonRpcResponse(topic = topicVO, response = result, params = irnParams, onSuccess = any(), onFailure = any()) }
Expand All @@ -202,7 +202,7 @@ internal class RelayerInteractorTest {
@Test
fun `RespondWithSuccess publishes result as true with request id on request topic`() {
val result = JsonRpcResponse.JsonRpcResult(request.id, result = true)
val irnParams = IrnParams(Tags.SESSION_PING, Ttl(300))
val irnParams = IrnParams(Tags.SESSION_PING, Ttl(300), correlationId = "1234", prompt = true)
mockRelayPublishSuccess()
sut.respondWithSuccess(request, irnParams)
verify { sut.publishJsonRpcResponse(topic = topicVO, response = result, params = irnParams, onSuccess = any(), onFailure = any()) }
Expand All @@ -212,7 +212,7 @@ internal class RelayerInteractorTest {
fun `RespondWithError publishes result as error with request id on request topic`() {
val error = JsonRpcResponse.Error(peerError.code, peerError.message)
val result = JsonRpcResponse.JsonRpcError(request.id, error = error)
val irnParams = IrnParams(Tags.SESSION_PING, Ttl(300))
val irnParams = IrnParams(Tags.SESSION_PING, Ttl(300), correlationId = "1234", prompt = true)
mockRelayPublishSuccess()
sut.respondWithError(request, peerError, irnParams)
verify { sut.publishJsonRpcResponse(topic = topicVO, response = result, params = irnParams, onSuccess = any(), onFailure = any()) }
Expand All @@ -221,7 +221,7 @@ internal class RelayerInteractorTest {
@Test
fun `OnFailure callback called when respondWithError encounters error`() {
mockRelayPublishFailure()
val irnParams = IrnParams(Tags.SESSION_PING, Ttl(300))
val irnParams = IrnParams(Tags.SESSION_PING, Ttl(300), correlationId = "1234", prompt = true)
sut.respondWithError(request = request, error = peerError, irnParams = irnParams, onFailure = onFailure)
verify { onFailure(any()) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ abstract class BaseRelayClient : RelayInterface {
) {
connectAndCallRelay(
onConnected = {
val (tag, ttl, prompt) = params
val publishParams = RelayDTO.Publish.Request.Params(Topic(topic), message, Ttl(ttl), tag, prompt)
val publishRequest = RelayDTO.Publish.Request(id = id ?: generateClientToServerId(), params = publishParams)
observePublishResult(publishRequest.id, onResult)
relayService.publishRequest(publishRequest)
with(params) {
val publishParams = RelayDTO.Publish.Request.Params(Topic(topic), message, Ttl(ttl), tag, prompt, correlationId, rpcMethods, chainId, txHashes, contractAddresses)
val publishRequest = RelayDTO.Publish.Request(id = id ?: generateClientToServerId(), params = publishParams)
observePublishResult(publishRequest.id, onResult)
println("kobe: IRN publish: $publishRequest")
relayService.publishRequest(publishRequest)
}
},
onFailure = { onResult(Result.failure(it)) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ object Relay {

data class ShutdownReason(val code: Int, val reason: String) : Model()

data class IrnParams(val tag: Int, val ttl: Long, val prompt: Boolean = false) : Model()
data class IrnParams(
val tag: Int,
val ttl: Long,
val correlationId: String?,
val rpcMethods: List<String>? = null,
val chainId: String? = null,
val txHashes: List<String>? = null,
val contractAddresses: List<String>? = null,
val prompt: Boolean = false
) : Model()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ sealed class RelayDTO {
val tag: Int,
@Json(name = "prompt")
val prompt: Boolean?,
@Json(name = "correlationId")
val correlationId: String?,
@Json(name = "rpcMethods")
val rpcMethods: List<String>?,
@Json(name = "chainId")
val chainId: String?,
@Json(name = "txHashes")
val txHashes: List<String>?,
@Json(name = "contractAddresses")
val contractAddresses: List<String>?,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class BaseRelayClientTest {

val topic = "testTopic"
val message = "testMessage"
val params = Relay.Model.IrnParams(1, 60, true)
val params = Relay.Model.IrnParams(1, 60, correlationId = "1234", prompt = true)
val ack = RelayDTO.Publish.Result.Acknowledgement(123L, result = true)

val publishRequestSlot = slot<RelayDTO.Publish.Request>()
Expand All @@ -95,7 +95,7 @@ class BaseRelayClientTest {
fun `test publish success`() = testScope.runTest {
val topic = "testTopic"
val message = "testMessage"
val params = Relay.Model.IrnParams(1, 60, true)
val params = Relay.Model.IrnParams(1, 60, correlationId = "1234", prompt = true)
val ack = RelayDTO.Publish.Result.Acknowledgement(123L, result = true)

coEvery { relayServiceMock.publishRequest(any()) } returns Unit
Expand All @@ -118,10 +118,10 @@ class BaseRelayClientTest {


@Test
fun `test publish error due to time out`() = testScope.runTest() {
fun `test publish error due to time out`() = testScope.runTest {
val topic = "testTopic"
val message = "testMessage"
val params = Relay.Model.IrnParams(1, 60, true)
val params = Relay.Model.IrnParams(1, 60, correlationId = "1234", prompt = true)

coEvery { relayServiceMock.publishRequest(any()) } returns Unit
coEvery { relayServiceMock.observePublishAcknowledgement() } returns flow { delay(15000L) }
Expand Down
4 changes: 2 additions & 2 deletions foundation/src/test/kotlin/com/reown/foundation/RelayTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class RelayTest {
)
}

clientA.publish(testTopic, testMessage, Relay.Model.IrnParams(1114, 300)) { result ->
clientA.publish(testTopic, testMessage, Relay.Model.IrnParams(1114, 300, correlationId = "1234", prompt = true)) { result ->
result.fold(
onSuccess = { println("ClientA publish on topic: $testTopic; message: $testMessage") },
onFailure = { error ->
Expand Down Expand Up @@ -223,7 +223,7 @@ class RelayTest {
measureAwaitingForConnection(clientA, clientB)

//Publish message
clientA.publish(testTopic, testMessage, Relay.Model.IrnParams(1114, ttl)) { result ->
clientA.publish(testTopic, testMessage, Relay.Model.IrnParams(1114, ttl, correlationId = "1234", prompt = true)) { result ->
result.fold(
onSuccess = {
testState.compareAndSet(expect = TestState.Idle, update = TestState.Error("ClientA publish on topic: $testTopic with ttl: $ttl"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ internal sealed class SignRpc : JsonRpcClientSync<SignParams> {
override val method: String = JsonRpcMethod.WC_SESSION_REQUEST,
@Json(name = "params")
override val params: SignParams.SessionRequestParams
) : SignRpc()
) : SignRpc() {
val rpcMethod = params.request.method
val rpcParams = params.request.params
}

@JsonClass(generateAdapter = true)
internal data class SessionDelete(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ internal sealed class SignParams : CoreSignParams() {
val request: SessionRequestVO,
@Json(name = "chainId")
val chainId: String,
) : SignParams()
) : SignParams() {
val expiry = request.expiryTimestamp
val rpcMethod = request.method
val rpcParams = request.params
}

@JsonClass(generateAdapter = true)
internal data class EventParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ internal fun callsModule() = module {
verifyContextStorageRepository = get(),
proposalStorageRepository = get(),
jsonRpcInteractor = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
pairingController = get()
logger = get(named(AndroidCommonDITags.LOGGER))
)
}

Expand All @@ -151,7 +150,8 @@ internal fun callsModule() = module {
metadataStorageRepository = get(),
insertEventUseCase = get(),
clientId = get(named(AndroidCommonDITags.CLIENT_ID)),
logger = get(named(AndroidCommonDITags.LOGGER))
logger = get(named(AndroidCommonDITags.LOGGER)),
tvf = get()
)
}

Expand All @@ -166,6 +166,7 @@ internal fun callsModule() = module {
metadataStorageRepository = get(),
insertEventUseCase = get(),
clientId = get(named(AndroidCommonDITags.CLIENT_ID)),
tvf = get()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.reown.sign.di
import com.reown.android.internal.common.di.AndroidCommonDITags
import com.reown.android.internal.common.signing.cacao.CacaoVerifier
import com.reown.sign.engine.domain.SignEngine
import com.reown.sign.engine.model.tvf.TVF
import com.reown.sign.engine.use_case.calls.GetPendingAuthenticateRequestUseCase
import com.reown.sign.engine.use_case.calls.GetPendingAuthenticateRequestUseCaseInterface
import com.reown.sign.json_rpc.domain.DeleteRequestByIdUseCase
Expand All @@ -21,6 +22,8 @@ internal fun engineModule() = module {

includes(callsModule(), requestsModule(), responsesModule())

single { TVF(moshi = get(named(AndroidCommonDITags.MOSHI))) }

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

single<GetPendingAuthenticateRequestUseCaseInterface> { GetPendingAuthenticateRequestUseCase(jsonRpcHistory = get(), serializer = get()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.reown.sign.engine.model.tvf

import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class EthSendTransaction(
val from: String,
val to: String,
val data: String?,
val gasLimit: String?,
val gasPrice: String?,
val value: String?,
val nonce: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.reown.sign.engine.model.tvf

import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class SolanaSignAndSendTransactionResult(
val signature: String
)

@JsonClass(generateAdapter = true)
data class SolanaSignTransactionResult(
val signature: String,
val transaction: String? = null
)

@JsonClass(generateAdapter = true)
data class SolanaSignAllTransactionsResult(
val transactions: List<String>
)
Loading
Loading