Skip to content

Commit f36ad94

Browse files
committed
Reduce dependency on rlp.utils
1 parent d0e231f commit f36ad94

File tree

7 files changed

+18
-19
lines changed

7 files changed

+18
-19
lines changed

keepkeylib/client.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,7 @@ def ethereum_get_address(self, n, show_display=False, multisig=None):
568568

569569
@session
570570
def ethereum_sign_tx(self, n, nonce, gas_price, gas_limit, value, to=None, to_n=None, address_type=None, exchange_type=None, data=None, chain_id=None, token_shortcut=None, token_value=None, token_to=None):
571-
import rlp.utils
572-
573-
def int_to_big_endian(value):
574-
if value == 0:
575-
return b''
576-
return rlp.utils.int_to_big_endian(value)
571+
from keepkeylib.tools import int_to_big_endian
577572

578573
n = self._convert_prime(n)
579574
if address_type == types.TRANSFER: #Ethereum transfer transaction
@@ -623,7 +618,7 @@ def int_to_big_endian(value):
623618
else:
624619
#erc20 token transfer
625620
value_array = bytearray([0]*32)
626-
for ii,i in enumerate(rlp.utils.int_to_big_endian(token_value)[::-1]):
621+
for ii,i in enumerate(int_to_big_endian(token_value)[::-1]):
627622
value_array[31 - ii] = i
628623
msg = proto.EthereumSignTx(
629624
address_n=n,

keepkeylib/eos.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
import binascii
33
import struct
44
from datetime import datetime
5-
from .tools import b58decode, b58encode, parse_path
5+
from .tools import b58decode, b58encode, parse_path, int_to_big_endian
66
from . import messages_eos_pb2 as proto
77

8-
def int_to_big_endian(value):
9-
return value.to_bytes((value.bit_length() + 7) // 8, "big")
10-
118
def name_to_number(name):
129
length = len(name)
1310
value = 0

keepkeylib/tools.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,14 @@ def _customPrintFieldValue(field, value, out, indent=0, as_utf8=False, as_one_li
159159

160160
google.protobuf.text_format.PrintFieldValue = _customPrintFieldValue
161161

162+
163+
def int_to_big_endian(value):
164+
import struct
165+
166+
res = b''
167+
while 0 < value:
168+
res = struct.pack("B", value & 0xff) + res
169+
value = value >> 8
170+
171+
return res
172+

tests/test_msg_ethereum_erc20_signtx_exchange.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
import keepkeylib.types_pb2 as proto_types
2828
import keepkeylib.exchange_pb2 as proto_exchange
2929
from keepkeylib.client import CallException
30-
31-
from rlp.utils import int_to_big_endian
30+
from keepkeylib.tools import int_to_big_endian
3231

3332
class TestMsgEthereumtxERC20_exch(common.KeepKeyTest):
3433

tests/test_msg_ethereum_signtx.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
import keepkeylib.messages_pb2 as proto
2626
import keepkeylib.types_pb2 as proto_types
2727
from keepkeylib.client import CallException
28-
29-
from rlp.utils import int_to_big_endian
28+
from keepkeylib.tools import int_to_big_endian
3029

3130
class TestMsgEthereumSigntx(common.KeepKeyTest):
3231

tests/test_msg_ethereum_signtx_exchange.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
import keepkeylib.types_pb2 as proto_types
2828
import keepkeylib.exchange_pb2 as proto_exchange
2929
from keepkeylib.client import CallException
30-
31-
from rlp.utils import int_to_big_endian
30+
from keepkeylib.tools import int_to_big_endian
3231

3332
class TestMsgEthereumtx_exch(common.KeepKeyTest):
3433

tests/test_msg_ethereum_signtx_xfer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
import keepkeylib.types_pb2 as proto_types
2828
import keepkeylib.exchange_pb2 as proto_exchange
2929
from keepkeylib.client import CallException
30-
31-
from rlp.utils import int_to_big_endian
30+
from keepkeylib.tools import int_to_big_endian
3231

3332
class TestMsgEthereumSigntx(common.KeepKeyTest):
3433
def test_ethereum_tx_xfer_acc1(self):

0 commit comments

Comments
 (0)