From 078c6bea16464f1c06aa28f73de5fbb484e8bff8 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Thu, 14 Nov 2019 09:45:41 +0300 Subject: [PATCH] eip-155 signing --- app/build.gradle | 2 +- .../im/status/keycard/connect/net/WalletConnect.kt | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f6dfd7d..bc2cda0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -68,7 +68,7 @@ dependencies { implementation "com.github.komputing.kethereum:model:$kethereum_version" implementation "com.github.komputing.kethereum:functions:$kethereum_version" implementation "com.github.komputing.kethereum:rpc:$kethereum_version" - implementation "com.github.komputing.kethereum:rlp:$kethereum_version" + implementation "com.github.komputing.kethereum:keccak_shortcut:$kethereum_version" implementation 'com.github.komputing:khex:0.6' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' diff --git a/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt b/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt index 4cb665d..b600565 100644 --- a/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt +++ b/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt @@ -16,12 +16,11 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.MainScope import kotlinx.coroutines.launch import okhttp3.OkHttpClient -import org.bouncycastle.jcajce.provider.digest.Keccak import org.kethereum.DEFAULT_GAS_LIMIT import org.kethereum.extensions.maybeHexToBigInteger import org.kethereum.extensions.toBigInteger -import org.kethereum.functions.calculateHash import org.kethereum.functions.encodeRLP +import org.kethereum.keccakshortcut.keccak import org.kethereum.model.* import org.walletconnect.Session import org.walletconnect.Session.Config.Companion.fromWCUri @@ -120,8 +119,7 @@ class WalletConnect : ExportKeyCommand.Listener, SignCommand.Listener, Session.C requestId = id uiAction = { - val keccak256 = Keccak.Digest256() - val hash = keccak256.digest(byteArrayOf(0x19) + "Ethereum Signed Message:\n${msg.size}".toByteArray() + msg) + val hash = (byteArrayOf(0x19) + "Ethereum Signed Message:\n${msg.size}".toByteArray() + msg).keccak() Registry.scriptExecutor.runScript(scriptWithAuthentication().plus(SignCommand(Registry.walletConnect, hash))) } @@ -143,13 +141,13 @@ class WalletConnect : ExportKeyCommand.Listener, SignCommand.Listener, Session.C requestId = id uiAction = { - val hash = tx.calculateHash() + val hash = tx.encodeRLP(SignatureData(v = chainID.toBigInteger())).keccak() Registry.scriptExecutor.runScript(scriptWithAuthentication().plus(SignCommand(Registry.walletConnect, hash))) } signAction = { try { - val signedTx = SignedTransaction(tx, SignatureData(it.r.toBigInteger(), it.s.toBigInteger(), (it.recId + 27).toBigInteger())).encodeRLP().toHexString() + val signedTx = SignedTransaction(tx, SignatureData(it.r.toBigInteger(), it.s.toBigInteger(), (it.recId + (chainID * 2) + 35).toBigInteger())).encodeRLP().toHexString() val res = if (send) Registry.ethereumRPC.ethSendRawTransaction(signedTx) else signedTx session?.approveRequest(requestId, res) } catch(e: Exception) {