Skip to content

Commit

Permalink
version 0.3.0 -- updated signing for strings to be correct
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Peyfuss committed Jun 1, 2022
1 parent 169d93d commit 2d8abfb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 30 deletions.
3 changes: 1 addition & 2 deletions evm_sc_utils/signers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def __pack_data(abi_types: List[str], values: List) -> bytearray:
length = 20
val = int(value, 16)
elif "string" in abi_type.lower():
length = len(value)
data.extend(value.encode("utf-8")) # extend in place
data.extend(bytes(value, "utf-8")) # extend in place

if isinstance(val, int):
data.extend(bytearray(val.to_bytes(length=length, byteorder="big")))
Expand Down
70 changes: 42 additions & 28 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/test_signers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def test_address_uint256(self, random_signer):
) == sig.messageHash
)

def test_string(self, random_signer):
assert EIP191Signer.get_signable_message(["string"], ["I have 100€"]).body.hex() == "49206861766520313030e282ac"


class Test_Known_Signer:
# test sending empty lists to sign
Expand Down

0 comments on commit 2d8abfb

Please sign in to comment.