Skip to content

Commit

Permalink
fix: ensure the correct type when signing a message using eth-account (
Browse files Browse the repository at this point in the history
…#366)

* fix: ensure the correct type when signing a message using eth-account

* fix: update tester accounts as well

Co-authored-by: Juliya Smith <[email protected]>
  • Loading branch information
fubuloubu and antazoey authored Jan 3, 2022
1 parent 5cd34b6 commit 38794c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/ape_accounts/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import click
from eth_account import Account as EthAccount # type: ignore
from eth_utils import to_bytes

from ape.api import AccountAPI, AccountContainerAPI, TransactionAPI
from ape.convert import to_address
Expand Down Expand Up @@ -131,11 +132,19 @@ def sign_message(self, msg: SignableMessage) -> Optional[MessageSignature]:
return None

signed_msg = EthAccount.sign_message(msg, self.__key)
return MessageSignature(v=signed_msg.v, r=signed_msg.r, s=signed_msg.s) # type: ignore
return MessageSignature( # type: ignore
v=signed_msg.v,
r=to_bytes(signed_msg.r),
s=to_bytes(signed_msg.s),
)

def sign_transaction(self, txn: TransactionAPI) -> Optional[TransactionSignature]:
if self.locked and not click.confirm(f"{txn}\n\nSign: "):
return None

signed_txn = EthAccount.sign_transaction(txn.as_dict(), self.__key)
return TransactionSignature(v=signed_txn.v, r=signed_txn.r, s=signed_txn.s) # type: ignore
return TransactionSignature( # type: ignore
v=signed_txn.v,
r=to_bytes(signed_txn.r),
s=to_bytes(signed_txn.s),
)
13 changes: 11 additions & 2 deletions src/ape_test/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from eth_account import Account as EthAccount # type: ignore
from eth_account.messages import SignableMessage
from eth_utils import to_bytes

from ape.api import TestAccountAPI, TestAccountContainerAPI, TransactionAPI
from ape.convert import to_address
Expand Down Expand Up @@ -50,8 +51,16 @@ def address(self) -> AddressType:

def sign_message(self, msg: SignableMessage) -> Optional[MessageSignature]:
signed_msg = EthAccount.sign_message(msg, self._private_key)
return MessageSignature(v=signed_msg.v, r=signed_msg.r, s=signed_msg.s) # type: ignore
return MessageSignature( # type: ignore
v=signed_msg.v,
r=to_bytes(signed_msg.r),
s=to_bytes(signed_msg.s),
)

def sign_transaction(self, txn: TransactionAPI) -> Optional[TransactionSignature]:
signed_txn = EthAccount.sign_transaction(txn.as_dict(), self._private_key)
return TransactionSignature(v=signed_txn.v, r=signed_txn.r, s=signed_txn.s) # type: ignore
return TransactionSignature( # type: ignore
v=signed_txn.v,
r=to_bytes(signed_txn.r),
s=to_bytes(signed_txn.s),
)

0 comments on commit 38794c4

Please sign in to comment.