Updated on 2026-08-14

This commit is contained in:
Tangem 2022-11-30 16:43:27 +04:00
parent 9eab9e1a6e
commit 7f8c5cd23a
4 changed files with 20 additions and 44 deletions

Binary file not shown.

Binary file not shown.

View file

@ -475,40 +475,6 @@ class WalletConnectManager {
store.dispatchOnMain(WalletConnectAction.SwitchBlockchain(blockchain, session))
}
}
client.onCustomRequest = { id: Long, data: String ->
Timber.d("Custom Request")
Timber.d(data)
val request = EthSignHelper.parseCustomRequest(data)
when (request.method) {
WCMethodExtended.ETH_SIGN_TYPE_DATA_V4 -> handleTypedDataV4(request, client, id)
else -> {
Timber.d("WC: unrecognized custom request")
}
}
}
}
private fun handleTypedDataV4(request: CustomJsonRpcRequest, client: WCClient, id: Long) {
val message = EthSignHelper.tryToParseEthTypedMessage(request)
if (message != null) {
Timber.d("onEthSign_v4: $message")
// Analytics.logWcEvent(
// AnalyticsAnOld.WcAnalyticsEvent.Action(
// AnalyticsAnOld.WcAction.PersonalSign
// )
// )
sessions[client.session]?.toWalletConnectSession()?.let { sessionData ->
store.dispatchOnMain(
WalletConnectAction.HandlePersonalSignRequest(
message,
sessionData,
id
)
)
}
}
}
companion object {

View file

@ -39,6 +39,9 @@ import com.tangem.tap.store
import com.tangem.tap.tangemSdk
import com.tangem.tap.tangemSdkManager
import com.trustwallet.walletconnect.models.ethereum.WCEthereumSignMessage
import com.trustwallet.walletconnect.models.ethereum.WCEthereumSignMessage.WCSignType.MESSAGE
import com.trustwallet.walletconnect.models.ethereum.WCEthereumSignMessage.WCSignType.PERSONAL_MESSAGE
import com.trustwallet.walletconnect.models.ethereum.WCEthereumSignMessage.WCSignType.TYPED_MESSAGE
import com.trustwallet.walletconnect.models.ethereum.WCEthereumTransaction
import timber.log.Timber
import java.math.BigDecimal
@ -206,19 +209,15 @@ class WalletConnectSdkHelper {
session: WalletConnectSession,
id: Long,
): WcPersonalSignData {
val messageData =
try {
message.data.removePrefix(HEX_PREFIX).hexToBytes()
} catch (exception: Exception) {
message.data.asciiToHex()!!.hexToBytes()
}
val messageData = when (message.type) {
MESSAGE, PERSONAL_MESSAGE -> createMessageData(message)
TYPED_MESSAGE -> EthereumUtils.makeTypedDataHash(message.data)
}
val messageString = message.data.hexToAscii()
?: EthSignHelper.tryToParseEthTypedMessageString(message.data)
?: message.data
val prefixData = (ETH_MESSAGE_PREFIX + messageData.size.toString()).toByteArray()
val hashToSign = (prefixData + messageData).toKeccak()
val dialogData = PersonalSignDialogData(
dAppName = session.peerMeta.name,
message = messageString,
@ -226,13 +225,24 @@ class WalletConnectSdkHelper {
id = id,
)
return WcPersonalSignData(
hash = hashToSign,
hash = messageData,
session = session,
id = id,
dialogData = dialogData,
)
}
private fun createMessageData(message: WCEthereumSignMessage): ByteArray {
val messageData = try {
message.data.removePrefix(HEX_PREFIX).hexToBytes()
} catch (exception: Exception) {
message.data.asciiToHex()?.hexToBytes() ?: byteArrayOf()
}
val prefixData = (ETH_MESSAGE_PREFIX + messageData.size.toString()).toByteArray()
return (prefixData + messageData).toKeccak()
}
private fun String.hexToAscii(): String? {
return try {
removePrefix(HEX_PREFIX).hexToBytes()