-
Notifications
You must be signed in to change notification settings - Fork 0
/
hiss-gui.py
249 lines (192 loc) · 9.35 KB
/
hiss-gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog, messagebox
from eth_keys import keys
from ecies import encrypt, decrypt
import web3
from eth_account._utils.signing import extract_chain_id, to_standard_v
from eth_account._utils.legacy_transactions import serializable_unsigned_transaction_from_dict
import os
import requests
class CryptoApp:
def __init__(self, root):
self.root = root
self.root.title("Hissssss")
# Create a Notebook for tabbed interface
self.notebook = ttk.Notebook(self.root)
self.notebook.pack(fill=tk.BOTH, expand=True)
# Create tabs
self.tab1 = tk.Frame(self.notebook)
self.tab2 = tk.Frame(self.notebook)
self.tab3 = tk.Frame(self.notebook)
self.notebook.add(self.tab1, text="EVM/ECIES") # Updated tab name
self.notebook.add(self.tab2, text="Lookup") # Updated tab name
self.notebook.add(self.tab3, text="Vault")
self.encrypt_file_button = tk.Button(self.tab1, text="Encrypt File", command=self.encrypt_file)
self.encrypt_file_button.pack()
self.decrypt_file_button = tk.Button(self.tab1, text="Decrypt File", command=self.decrypt_file)
self.decrypt_file_button.pack()
self.get_provider_label = tk.Label(self.tab3, text="Provider:")
self.get_provider_label.pack()
self.get_provider_label_entry = tk.Entry(self.tab3)
self.get_provider_label_entry.pack()
self.get_txn_hash_label = tk.Label(self.tab1, text="Transaction Hash:")
self.get_txn_hash_label.pack()
self.get_txn_hash_label_entry = tk.Entry(self.tab1)
self.get_txn_hash_label_entry.pack()
self.get_public_key_txn_button = tk.Button(self.tab1, text="Get Public Key from Transaction", command=self.get_public_key_txn)
self.get_public_key_txn_button.pack()
self.public_key_label = tk.Label(self.tab1, text="Recipient's Public Key:")
self.public_key_label.pack()
self.public_key_entry = tk.Entry(self.tab1)
self.public_key_entry.pack()
self.message_label = tk.Label(self.tab1, text="Message:")
self.message_label.pack()
self.message_entry = tk.Entry(self.tab1)
self.message_entry.pack()
self.encrypt_button = tk.Button(self.tab1, text="Encrypt", command=self.encrypt_message)
self.encrypt_button.pack()
self.private_key_label = tk.Label(self.tab3, text="Your Private Key:")
self.private_key_label.pack()
self.private_key_entry = tk.Entry(self.tab3)
self.private_key_entry.pack()
self.encrypted_message_label = tk.Label(self.tab1, text="Encrypted Message:")
self.encrypted_message_label.pack()
self.encrypted_message_entry = tk.Entry(self.tab1)
self.encrypted_message_entry.pack()
self.decrypt_button = tk.Button(self.tab1, text="Decrypt", command=self.decrypt_message)
self.decrypt_button.pack()
self.result_label = tk.Label(self.tab1, text="Result:")
self.result_label.pack()
self.result_text = tk.Text(self.tab1, height=5, width=40)
self.result_text.pack()
self.copy_button = tk.Button(self.tab1, text="Copy Result", command=self.copy_result)
self.copy_button.pack()
self.transaction_hashes_button = tk.Button(self.tab2, text="Get Transaction Hashes", command=self.get_transaction_hashes)
self.transaction_hashes_button.pack()
# Create an entry field for the Etherscan API key
self.api_key_label = tk.Label(self.tab3, text="Etherscan API Key:")
self.api_key_label.pack()
self.api_key_entry = tk.Entry(self.tab3)
self.api_key_entry.pack()
# Create an entry field for the address
self.address_label = tk.Label(self.tab2, text="Address:")
self.address_label.pack()
self.address_entry = tk.Entry(self.tab2)
self.address_entry.pack()
def get_transaction_hashes(self):
address = self.address_entry.get() # Get the address from the entry field
api_key = self.api_key_entry.get() # Get the API key from the entry field
txn_hashes = get_transaction_hashes(address, api_key)
# Display the transaction hashes in the result_text widget
self.show_result('\n'.join(txn_hashes))
def get_public_key_txn(self):
provider = self.get_provider_label_entry.get()
tx_hash = self.get_txn_hash_label_entry.get()
recovered_public_key, from_address = pubkey_txn(provider, tx_hash)
self.public_key_entry.delete(0, tk.END)
self.public_key_entry.insert(0, recovered_public_key.to_hex())
self.show_result(recovered_public_key.to_hex())
def show_result(self, result):
self.result_text.delete(1.0, tk.END)
self.result_text.insert(tk.END, result)
def copy_result(self):
result = self.result_text.get(1.0, tk.END).strip() # Remove trailing newline
self.root.clipboard_clear()
self.root.clipboard_append(result)
messagebox.showinfo("Copied", "Result has been copied to the clipboard!")
def encrypt_file(self):
public_key_hex = self.public_key_entry.get()
input_file_path = filedialog.askopenfilename()
output_file_path = filedialog.asksaveasfilename()
encrypt_file(public_key_hex, input_file_path, output_file_path)
messagebox.showinfo("Success", "File has been encrypted!")
def decrypt_file(self):
private_key = self.private_key_entry.get()
input_file_path = filedialog.askopenfilename()
output_file_path = filedialog.asksaveasfilename()
decrypt_file(private_key, input_file_path, output_file_path)
messagebox.showinfo("Success", "File has been decrypted!")
def encrypt_message(self):
public_key_hex = self.public_key_entry.get()
message = self.message_entry.get()
encrypted_data = encrypt(public_key_hex, message.encode())
self.encrypted_message_entry.delete(0, tk.END)
self.encrypted_message_entry.insert(0, encrypted_data.hex())
self.show_result(encrypted_data.hex())
def decrypt_message(self):
private_key = self.private_key_entry.get()
encrypted_data = bytes.fromhex(self.encrypted_message_entry.get())
decrypted_data = decrypt(private_key, encrypted_data)
self.show_result(decrypted_data.decode())
def get_transaction_hashes(address, api_key):
url = f"https://api.etherscan.io/api?module=account&action=txlist&address={address}&startblock=0&endblock=99999999&page=1&offset=10&sort=asc&apikey={api_key}"
try:
response = requests.get(url)
response.raise_for_status() # Check for HTTP errors
data = response.json()
if data['status'] == "1":
transactions = data['result']
txn_hashes = [txn['hash'] for txn in transactions]
return txn_hashes
else:
print("API request was not successful.")
return []
except requests.exceptions.RequestException as e:
print(f"Request error: {e}")
return []
def pubkey_txn(provider, tx_hash):
w3 = web3.Web3(web3.HTTPProvider(provider))
tx = w3.eth.get_transaction(tx_hash)
tx = dict(tx)
type_0_keys = ['chainId', 'gas', 'gasPrice', 'nonce', 'to', 'value']
type_1_keys = ["to", "nonce", "value", "gas", 'gasPrice', "chainId", "type"]
type_2_keys = ["to", "nonce", "value", "gas", "chainId", "maxFeePerGas", "maxPriorityFeePerGas", "type"]
s = w3.eth.account._keys.Signature(vrs=(
to_standard_v(extract_chain_id(tx["v"])[1]),
w3.to_int(tx["r"]),
w3.to_int(tx["s"])
))
if tx["type"] == 0:
keys_to_get = type_0_keys
elif tx["type"] == 1:
keys_to_get = type_1_keys
elif tx["type"] == 2:
keys_to_get = type_2_keys
if "chainId" not in tx:
# !! This is hardcoded for ETH
tx["chainId"] = 1
tt = {k: tx[k] for k in keys_to_get}
tt["data"] = tx["input"]
ut = serializable_unsigned_transaction_from_dict(tt)
recovered_public_key = s.recover_public_key_from_msg_hash(ut.hash())
from_address = recovered_public_key.to_checksum_address()
return recovered_public_key, from_address
def recover_public_key_from_private(private_key):
private_key_bytes = bytes.fromhex(private_key)
private_key_object = keys.PrivateKey(private_key_bytes)
public_key = private_key_object.public_key
uncompressed_public_key = public_key.to_hex()
return uncompressed_public_key
def encrypt_with_public_key(public_key, message):
encrypted = encrypt(public_key, message.encode())
return encrypted
def decrypt_with_private_key(private_key, encrypted):
decrypted = decrypt(private_key, encrypted)
return decrypted.decode()
def encrypt_file(public_key_hex, input_file_path, output_file_path):
with open(input_file_path, 'rb') as f:
file_data = f.read()
encrypted_data = encrypt(public_key_hex, file_data)
with open(output_file_path, 'wb') as f:
f.write(encrypted_data)
def decrypt_file(private_key_hex, input_file_path, output_file_path):
with open(input_file_path, 'rb') as f:
encrypted_data = f.read()
decrypted_data = decrypt(private_key_hex, encrypted_data)
with open(output_file_path, 'wb') as f:
f.write(decrypted_data)
if __name__ == "__main__":
root = tk.Tk()
app = CryptoApp(root)
root.mainloop()