44from cryptography .hazmat .primitives import serialization
55from cryptography .hazmat .primitives .asymmetric import padding
66from cryptography .hazmat .primitives .asymmetric import rsa
7+ from eth_account import Account
78from eth_keys import keys
9+ from .types import ItString , ItUint
810
911block_size = AES .block_size
1012address_size = 20
@@ -71,7 +73,7 @@ def generate_aes_key():
7173 return key
7274
7375
74- def sign_input_text (sender , addr , function_selector , ct , key ):
76+ def sign_input_text (sender : Account , addr : str , function_selector : str , ct , key ):
7577 function_selector_bytes = bytes .fromhex (function_selector [2 :])
7678
7779 # Ensure all input sizes are the correct length
@@ -101,7 +103,7 @@ def sign(message, key):
101103 return signature
102104
103105
104- def build_input_text (plaintext , user_aes_key , sender , contract , function_selector , signing_key ):
106+ def build_input_text (plaintext : int , user_aes_key , sender : Account , contract , function_selector : str , signing_key ) -> ItUint :
105107 sender_address_bytes = bytes .fromhex (sender .address [2 :])
106108 contract_address_bytes = bytes .fromhex (contract .address [2 :])
107109
@@ -124,7 +126,7 @@ def build_input_text(plaintext, user_aes_key, sender, contract, function_selecto
124126 }
125127
126128
127- def build_string_input_text (plaintext , user_aes_key , sender , contract , function_selector , signing_key ):
129+ def build_string_input_text (plaintext , user_aes_key , sender , contract , function_selector , signing_key ) -> ItString :
128130 input_text = {
129131 'ciphertext' : {
130132 'value' : []
@@ -154,7 +156,7 @@ def build_string_input_text(plaintext, user_aes_key, sender, contract, function_
154156 return input_text
155157
156158
157- def decrypt_uint (ciphertext , user_key ):
159+ def decrypt_uint (ciphertext , user_key ) -> int :
158160 # Convert ct to bytes (big-endian)
159161 byte_array = ciphertext .to_bytes (32 , byteorder = 'big' )
160162
@@ -171,7 +173,7 @@ def decrypt_uint(ciphertext, user_key):
171173 return decrypted_uint
172174
173175
174- def decrypt_string (ciphertext , user_key ):
176+ def decrypt_string (ciphertext , user_key ) -> str :
175177 if 'value' in ciphertext or hasattr (ciphertext , 'value' ): # format when reading ciphertext from an event
176178 __ciphertext = ciphertext ['value' ]
177179 elif isinstance (ciphertext , tuple ): # format when reading ciphertext from state variable
0 commit comments