Skip to content

Commit

Permalink
Use Int value of chainId in signature
Browse files Browse the repository at this point in the history
  • Loading branch information
esen committed Aug 4, 2022
1 parent 0980ae9 commit 865ed1c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TransactionBuilder(
fun encode(rawTransaction: RawTransaction, signature: Signature?, chainId: Int = 1): ByteArray {
val signatureArray = signature?.let {
arrayOf(
RLP.encodeByte(it.v),
RLP.encodeInt(it.v),
RLP.encodeBigInteger(it.r.toBigInteger()),
RLP.encodeBigInteger(it.s.toBigInteger())
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class TransactionSigner(

private fun signatureLegacy(signatureData: ByteArray): Signature {
return Signature(
v = (signatureData[64] + if (chainId == 0) 27 else (35 + 2 * chainId)).toByte(),
v = signatureData[64] + if (chainId == 0) 27 else (35 + 2 * chainId),
r = signatureData.copyOfRange(0, 32),
s = signatureData.copyOfRange(32, 64)
)
}

private fun signatureEip1559(signatureData: ByteArray): Signature {
return Signature(
v = signatureData[64],
v = signatureData[64].toInt(),
r = signatureData.copyOfRange(0, 32),
s = signatureData.copyOfRange(32, 64)
)
Expand All @@ -49,7 +49,7 @@ class TransactionSigner(
RLP.encodeElement(rawTransaction.to.raw),
RLP.encodeBigInteger(rawTransaction.value),
RLP.encodeElement(rawTransaction.data),
RLP.encodeByte(chainId.toByte()),
RLP.encodeInt(chainId),
RLP.encodeElement(ByteArray(0)),
RLP.encodeElement(ByteArray(0)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.horizontalsystems.ethereumkit.models

import io.horizontalsystems.ethereumkit.core.toHexString

class Signature(val v: Byte,
class Signature(val v: Int,
val r: ByteArray,
val s: ByteArray) {
override fun toString(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SendTransactionMessage(val requestID: Long, val rawTransaction: RawTransac
RLP.encodeElement(rawTransaction.to.raw),
RLP.encodeBigInteger(rawTransaction.value),
RLP.encodeElement(rawTransaction.data),
RLP.encodeByte(signature.v),
RLP.encodeInt(signature.v),
RLP.encodeElement(signature.r),
RLP.encodeElement(signature.s)
)
Expand Down

0 comments on commit 865ed1c

Please sign in to comment.