Skip to content

Commit 86c6e08

Browse files
committed
Fix bug with signable bytes - wasn't including encoded data!
1 parent fa3577e commit 86c6e08

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

eip712_structs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from eip712_structs.types import Address, Array, Boolean, Bytes, Int, String, Uint
44

55
name = 'eip712-structs'
6-
version = '0.1.4'
6+
version = '0.1.5'

eip712_structs/struct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def struct_to_message(primary_struct: EIP712Struct, domain: EIP712Struct):
163163
'message': primary_struct.data_dict(),
164164
}
165165

166-
typed_data_hash = b'\x19\x01' + domain.type_hash() + primary_struct.type_hash()
166+
typed_data_hash = b'\x19\x01' + domain.hash_struct() + primary_struct.hash_struct()
167167

168168
return result, typed_data_hash
169169

tests/test_encode_data.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from eth_utils.crypto import keccak
66

7-
from eip712_structs import Address, Array, Boolean, Bytes, Int, String, Uint, EIP712Struct
7+
from eip712_structs import Address, Array, Boolean, Bytes, Int, String, Uint, EIP712Struct, make_domain, struct_to_message
88

99

1010
def signed_min_max(bits):
@@ -123,3 +123,21 @@ class Bar(EIP712Struct):
123123
'b': b'\xff'
124124
}
125125
assert bar.data_dict() == expected_result
126+
127+
128+
def test_signable_bytes():
129+
class Foo(EIP712Struct):
130+
s = String()
131+
i = Int(256)
132+
133+
domain = make_domain(name='hello')
134+
foo = Foo(s='hello', i=1234)
135+
136+
start_bytes = b'\x19\x01'
137+
exp_domain_bytes = keccak(domain.type_hash() + domain.encode_value())
138+
exp_struct_bytes = keccak(foo.type_hash() + foo.encode_value())
139+
140+
msg, sign_bytes = struct_to_message(foo, domain)
141+
assert sign_bytes[0:2] == start_bytes
142+
assert sign_bytes[2:34] == exp_domain_bytes
143+
assert sign_bytes[34:] == exp_struct_bytes

0 commit comments

Comments
 (0)