eip-155 signing

This commit is contained in:
Michele Balistreri 2019-11-14 09:45:41 +03:00
parent 8981c705cf
commit 078c6bea16
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
2 changed files with 5 additions and 7 deletions

View File

@ -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'

View File

@ -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) {