From 23a5e8dcd0211857d86d24f8f108719671ea185d Mon Sep 17 00:00:00 2001 From: nolash Date: Mon, 12 Apr 2021 19:09:11 +0200 Subject: [PATCH] Export canonical order method --- crypto_dev_signer/eth/encoding.py | 5 +++++ crypto_dev_signer/eth/transaction.py | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 crypto_dev_signer/eth/encoding.py diff --git a/crypto_dev_signer/eth/encoding.py b/crypto_dev_signer/eth/encoding.py new file mode 100644 index 0000000..666f41d --- /dev/null +++ b/crypto_dev_signer/eth/encoding.py @@ -0,0 +1,5 @@ +ethereum_recid_modifier = 35 + +def chain_id_to_v(chain_id, signature): + v = signature[64] + return (chain_id * 2) + ethereum_recid_modifier + v diff --git a/crypto_dev_signer/eth/transaction.py b/crypto_dev_signer/eth/transaction.py index cbe7cf6..99488a9 100644 --- a/crypto_dev_signer/eth/transaction.py +++ b/crypto_dev_signer/eth/transaction.py @@ -13,10 +13,12 @@ from hexathon import ( # local imports from crypto_dev_signer.eth.encoding import chain_id_to_v -from crypto_dev_signer.eth.rlp import rlp_encode +#from crypto_dev_signer.eth.rlp import rlp_encode +import rlp logg = logging.getLogger().getChild(__name__) +rlp_encode = rlp.encode class Transaction: @@ -91,7 +93,7 @@ class EIP155Transaction: self.sender = strip_0x(tx['from']) - def __canonical_order(self): + def canonical_order(self): s = [ self.nonce, self.gas_price, @@ -108,7 +110,7 @@ class EIP155Transaction: def bytes_serialize(self): - s = self.__canonical_order() + s = self.canonical_order() b = b'' for e in s: b += e @@ -116,7 +118,7 @@ class EIP155Transaction: def rlp_serialize(self): - s = self.__canonical_order() + s = self.canonical_order() return rlp_encode(s)