-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
951 lines (822 loc) · 41.9 KB
/
main.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
from hashlib import new
from os import remove
import csv
from google.protobuf import message
from models import Slaves
import time
from time import time
from views.view_ui import Ui_mainWindow
from PyQt5 import QtWidgets
from PyQt5 import QtCore
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from views.view_ui import Ui_mainWindow
from views.about_ui import Ui_Form
from views.donate_ui import Ui_Form2
import sys
from models.model import *
import models.TransferTransaction
from models.aes import AESModel
from pyqrllib.pyqrllib import hstr2bin, SHAKE_128, SHAKE_256, SHA2_256
from qrl.crypto.xmss import XMSS
from qrl.crypto.xmss import XMSS
import qrcode
from PIL import Image
import simplejson as json
from pyqrllib.pyqrllib import hstr2bin, XmssFast, QRLDescriptor
from qrl.crypto.xmss import XMSS
from qrl.crypto.doctest_data import *
import random
from models.GetMiniTransactionsByAddress import TableOutput
from datetime import datetime
from multiprocessing.dummy import Pool as ThreadPool
QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
options = []
qrl_network = []
explorer_network = []
class MyWizard(QtWidgets.QWizard):
def __init__(self, parent=None):
super().__init__(parent)
self.setFixedSize(550, 400)
self.introPage = IntroPage()
self.createWallet = CreateWallet()
self.walletDetails = WalletDetails()
self.createSeedByMouse = CreateSeedByMouse()
self.walletDetailsExperimental = WalletDetailsExperimental()
self.slavesJsonOptions = SlaveJsonOptions()
self.createSlavesJson = CreateSlavesJson()
self.openWalletFileSlaves = OpenWalletFileSlaves()
self.openWalletFile = OpenWalletFile()
self.restoreWallet = RestoreWallet()
self.restoreWalletSlaves = RestoreWalletSlaves()
self.lastPage = LastPage()
self.addPage(self.introPage)
self.addPage(self.createWallet)
self.addPage(self.walletDetails)
self.addPage(self.createSeedByMouse)
self.addPage(self.walletDetailsExperimental)
self.addPage(self.openWalletFile)
self.addPage(self.restoreWallet)
self.addPage(self.slavesJsonOptions)
self.addPage(self.createSlavesJson)
self.addPage(self.openWalletFileSlaves)
self.addPage(self.restoreWalletSlaves)
self.addPage(self.lastPage)
self.currentIdChanged.connect(self.next_callback)
self.walletDetails.save_wallet_file.clicked.connect(self.saveFile)
self.walletDetailsExperimental.save_wallet_file.clicked.connect(self.saveFileExperimental)
self.openWalletFile.openFileBtn.clicked.connect(self.openFile)
self.openWalletFileSlaves.openFileBtn.clicked.connect(self.openFileSlaves)
self.finished.connect(self.onFinished)
seed_data = []
data = []
def next_callback(self, page_id: int):
if page_id == 2 and self.last_page_id == 1:
combo_height_short = main.createWallet.combo_height
combo_hash_short = main.createWallet.combo_hash
if combo_height_short.currentIndexChanged or combo_hash_short.currentIndexChanged:
options.clear()
options.append(combo_height_short.currentIndex())
options.append(combo_hash_short.currentIndex())
main.thread = QThread()
# Step 3: Create a worker object
main.worker = Worker()
# Step 4: Move worker to the thread
main.worker.moveToThread(main.thread)
# Step 5: Connect signals and slots
main.thread.started.connect(main.worker.run)
main.worker.finished.connect(main.thread.quit)
main.worker.finished.connect(main.worker.deleteLater)
main.thread.finished.connect(main.thread.deleteLater)
# Step 6: Start the thread
main.thread.start()
main.button(QWizard.NextButton).setEnabled(False)
main.button(QWizard.BackButton).setEnabled(False)
main.button(QWizard.CancelButton).setEnabled(False)
main.worker.update_text.connect(self.evt_set_text)
main.thread.finished.connect(
lambda: main.button(QWizard.NextButton).setEnabled(True)
)
main.thread.finished.connect(
lambda: main.button(QWizard.BackButton).setEnabled(True)
)
main.thread.finished.connect(
lambda: main.button(QWizard.CancelButton).setEnabled(True)
)
main.thread.finished.connect(main.finishedThread)
if page_id == 4 and self.last_page_id == 3:
combo_height_short = self.createSeedByMouse.combo_height
combo_hash_short = self.createSeedByMouse.combo_hash
if combo_height_short.currentIndexChanged or combo_hash_short.currentIndexChanged:
combo_height_options = {0: 8, 1: 10, 2: 12, 3: 14, 4: 16, 5: 18}
combo_hash_options = {0: SHAKE_128, 1: SHAKE_256, 2: SHA2_256}
seed_data = [i for i in self.seed_data if int(i) < 255]
random.shuffle(seed_data)
new_seed_data = [int(g) for g in seed_data[:48]]
qaddress, mnemonic, hexseed = Model.getAddressExperimental(combo_height_options[combo_height_short.currentIndex()], combo_hash_options[combo_hash_short.currentIndex()], tuple(new_seed_data[:48]))
self.walletDetailsExperimental.qaddress.setText(qaddress)
self.walletDetailsExperimental.mnemonic.setText(mnemonic + "\n" + "\n")
self.walletDetailsExperimental.hexseed.setText(hexseed)
if page_id == 8 and self.last_page_id == 9:
qrl_address = []
mnemonic = []
hexseed = []
qrl_address.append(main.data[0].split(" ")[0])
mnemonic.append(" ".join(main.data[0].split(" ")[1:-1]))
hexseed.append(main.data[0].split(" ")[35])
xmss_pk = XMSS.from_extended_seed(hstr2bin(hexseed[0])).pk
src_xmss = XMSS.from_extended_seed(hstr2bin(hexseed[0]))
xmss_height = src_xmss.height
xmss = XMSS.from_height(xmss_height)
xmss_extended_seed = xmss.extended_seed
Slaves.slave_tx_generate(xmss_pk, src_xmss, xmss_extended_seed)
if page_id == 8 and self.last_page_id == 10:
qrl_address = []
mnemonic = []
hexseed = []
if QWizard.hasVisitedPage(main, 7):
if main.restoreWalletSlaves.seedline_edit.text()[:6] == "absorb":
qrl_address.append(Model.recoverAddressMnemonic(main.restoreWalletSlaves.seedline_edit.text()))
mnemonic.append(main.restoreWalletSlaves.seedline_edit.text())
hexseed.append(Model.recoverHexseedMnemonic(main.restoreWalletSlaves.seedline_edit.text()))
elif main.restoreWalletSlaves.seedline_edit.text()[:2] == "01":
qrl_address.append(Model.recoverAddressHexseed(main.restoreWalletSlaves.seedline_edit.text()))
mnemonic.append(Model.recoverMnemonicHexseed(main.restoreWalletSlaves.seedline_edit.text()))
hexseed.append(main.restoreWalletSlaves.seedline_edit.text())
xmss_pk = XMSS.from_extended_seed(hstr2bin(hexseed[0])).pk
src_xmss = XMSS.from_extended_seed(hstr2bin(hexseed[0]))
xmss_height = src_xmss.height
xmss = XMSS.from_height(xmss_height)
xmss_extended_seed = xmss.extended_seed
Slaves.slave_tx_generate(xmss_pk, src_xmss, xmss_extended_seed)
self.last_page_id = page_id
def finishedThread(self):
print("Wallet generated!")
def evt_set_text(self, qadress, mnemonic, hexseed):
main.walletDetails.qaddress.setText(qadress)
main.walletDetails.mnemonic.setText(mnemonic)
main.walletDetails.hexseed.setText(hexseed)
def saveFile(self):
file_filter = 'Json file (*.json)'
dialog_save_file_name = QFileDialog.getSaveFileName(
parent=self,
caption='Save file',
directory= 'wallet.json',
filter=file_filter,
initialFilter='Json file (*.json)')
dialog = open(dialog_save_file_name[0], "w")
dialog.write(json.dumps(AESModel.encrypt(self.walletDetails.qaddress.toPlainText() + " " + self.walletDetails.mnemonic.text().rstrip() + " " + self.walletDetails.hexseed.text(), self.createWallet.passwordline_edit.text())))
dialog.close()
def saveFileExperimental(self):
file_filter = 'Json file (*.json)'
dialog_save_file_name = QFileDialog.getSaveFileName(
parent=self,
caption='Save file',
directory= 'wallet.json',
filter=file_filter,
initialFilter='Json file (*.json)')
dialog = open(dialog_save_file_name[0], "w")
dialog.write(json.dumps(AESModel.encrypt(self.walletDetailsExperimental.qaddress.toPlainText() + " " + self.walletDetailsExperimental.mnemonic.text().rstrip() + " " + self.walletDetailsExperimental.hexseed.text(), self.createSeedByMouse.passwordline_edit.text())))
dialog.close()
def openFile(self) -> int:
file_filter = 'Json file (*.json)'
dialog_save_file_name = QFileDialog.getOpenFileName(
parent=self,
caption='Open file',
directory= '.json',
filter=file_filter,
initialFilter='Json file (*.json)')
try:
dialog = open(dialog_save_file_name[0], "r")
main.data.append(bytes.decode(AESModel.decrypt(json.load(dialog), self.openWalletFile.passwordline_edit.text())))
dialog.close()
QMessageBox.about(self, "Success!", "Correct password!")
except ValueError:
QMessageBox.warning(self, "Wrong password!", "You have entered the wrong password!")
def openFileSlaves(self) -> int:
file_filter = 'Json file (*.json)'
dialog_save_file_name = QFileDialog.getOpenFileName(
parent=self,
caption='Open file',
directory= '.json',
filter=file_filter,
initialFilter='Json file (*.json)')
try:
dialog = open(dialog_save_file_name[0], "r")
main.data.append(bytes.decode(AESModel.decrypt(json.load(dialog), self.openWalletFileSlaves.passwordline_edit.text())))
dialog.close()
QMessageBox.about(self, "Success!", "Correct password!")
except ValueError:
QMessageBox.warning(self, "Wrong password!", "You have entered the wrong password!")
def onFinished(self):
qrl_address = []
mnemonic = []
hexseed = []
if QWizard.hasVisitedPage(main, 2):
qrl_address.append(main.walletDetails.qaddress.toPlainText())
mnemonic.append(main.walletDetails.mnemonic.text().rstrip())
hexseed.append(main.walletDetails.hexseed.text())
if main.introPage.combo.currentText() == "Mainnet":
qrl_network.append("Mainnet")
explorer_network.append("")
elif main.introPage.combo.currentText() == "Testnet":
qrl_network.append("Testnet")
explorer_network.append("testnet-")
elif QWizard.hasVisitedPage(main, 5):
qrl_address.append(main.data[0].split(" ")[0])
mnemonic.append(" ".join(main.data[0].split(" ")[1:-1]))
hexseed.append(main.data[0].split(" ")[35])
if main.introPage.combo.currentText() == "Mainnet":
qrl_network.append("Mainnet")
explorer_network.append("")
elif main.introPage.combo.currentText() == "Testnet":
qrl_network.append("Testnet")
explorer_network.append("testnet-")
elif QWizard.hasVisitedPage(main, 6):
if main.restoreWallet.seedline_edit.text()[:6] == "absorb":
qrl_address.append(Model.recoverAddressMnemonic(main.restoreWallet.seedline_edit.text()))
mnemonic.append(main.restoreWallet.seedline_edit.text())
hexseed.append(Model.recoverHexseedMnemonic(main.restoreWallet.seedline_edit.text()))
elif main.restoreWallet.seedline_edit.text()[:2] == "01":
qrl_address.append(Model.recoverAddressHexseed(main.restoreWallet.seedline_edit.text()))
mnemonic.append(Model.recoverMnemonicHexseed(main.restoreWallet.seedline_edit.text()))
hexseed.append(main.restoreWallet.seedline_edit.text())
if main.introPage.combo.currentText() == "Mainnet":
qrl_network.append("Mainnet")
explorer_network.append("")
elif main.introPage.combo.currentText() == "Testnet":
qrl_network.append("Testnet")
explorer_network.append("testnet-")
elif QWizard.hasVisitedPage(main, 3):
qrl_address.append(main.walletDetailsExperimental.qaddress.toPlainText())
mnemonic.append(main.walletDetailsExperimental.mnemonic.text().rstrip())
hexseed.append(main.walletDetailsExperimental.hexseed.text())
if main.introPage.combo.currentText() == "Mainnet":
qrl_network.append("Mainnet")
explorer_network.append("")
elif main.introPage.combo.currentText() == "Testnet":
qrl_network.append("Testnet")
explorer_network.append("testnet-")
mainWindow.public_label_description.setText(qrl_address[0])
mainWindow.public_label_description.setTextInteractionFlags(Qt.TextSelectableByMouse)
img = qrcode.make(qrl_address[0])
img_saved = img.save("qr_code.png")
mainWindow.pixmap = QPixmap('qr_code.png')
mainWindow.qr_image_label.setPixmap(mainWindow.pixmap)
mainWindow.qr_image_label.setScaledContents(True)
mainWindow.ots_key_index_input.setText(str(int(Model.getAddressOtsKeyIndex(qrl_address[0], explorer_network[0]))))
mainWindow.balance_label.setText("Balance: " + str(float(Model.getAddressBalance(qrl_address[0], explorer_network[0])) / 1000000000) + " QUANTA")
recoveryWindow.mnemonic_label_text.setText(mnemonic[0])
recoveryWindow.hexseed_label_text.setText(hexseed[0])
rowPosition = mainWindow.transaction_table.rowCount()
transaction_hashes = []
transaction_hashes.append(TableOutput.getMiniTransactionsByAddressHashes(qrl_address[0], qrl_network[0]))
timestamp_seconds = []
amount = TableOutput.GetTransactionsByAddressAmounts(qrl_address[0], qrl_network[0])
addr_from = TableOutput.GetTransactionsByAddressAddrFrom(qrl_address[0], qrl_network[0])
message_tx = []
date_time = []
for x in transaction_hashes[0]:
resp = Model.getTransactionByHash(x, explorer_network[0])
try:
timestamp_seconds.append(resp["transaction"]["header"]["timestamp_seconds"])
except KeyError:
pass
try:
message_tx.append(resp["transaction"]["tx"]["message"]["message_hash"])
except KeyError:
message_tx.append(" ")
for i in timestamp_seconds:
date_time.append(datetime.fromtimestamp(int(i)).strftime("%Y-%m-%d %I:%M:%S"))
x = 0
y = 1
z = 2
for _ in range(len(date_time)):
mainWindow.transaction_table.insertRow(rowPosition)
for date_box, description_box, amount_box_sent, plusminus in zip(date_time, message_tx, amount, addr_from):
mainWindow.transaction_table.setItem(x, 0, QTableWidgetItem(date_box))
mainWindow.transaction_table.setItem(0, y, QTableWidgetItem(str(description_box)))
mainWindow.transaction_table.setItem(0, z, QTableWidgetItem(amount_box_sent))
x += 1
y += 3
z += 3
class Worker(QObject):
finished = pyqtSignal()
update_text = pyqtSignal(str, str, str)
def run(self):
"""Long-running task."""
combo_height_options = {0: 8, 1: 10, 2: 12, 3: 14, 4: 16, 5: 18}
combo_hash_options = {0: SHAKE_128, 1: SHAKE_256, 2: SHA2_256}
qaddress, mnemonic, hexseed = Model.getAddress(combo_height_options[options[0]], combo_hash_options[options[1]])
self.update_text.emit(qaddress, mnemonic, hexseed)
self.finished.emit()
class IntroPage(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Welcome to Qrllight Wallet v1.4!")
self.combo = QComboBox(self)
self.combo.setMaximumWidth(100)
self.combo.addItem("Mainnet")
self.combo.addItem("Testnet")
self.label_description = QLabel("Select option:")
self.radiobutton_1 = QRadioButton("Create new wallet")
self.radiobutton_2 = QRadioButton("Open wallet file")
self.radiobutton_3 = QRadioButton("Restore wallet from seed")
self.Separador = QFrame()
self.Separador.Shape(QFrame.HLine)
self.Separador.setLineWidth(1)
self.Separador.setFrameShape(QFrame.HLine)
self.radiobutton_4 = QRadioButton("Create a Slaves.json")
self.radiobutton_5 = QRadioButton("Create wallet by random mouse movements [Experimental] [Not safe]")
self.radiobutton_2.setChecked(True)
layout = QVBoxLayout(self)
layout.addWidget(self.combo)
layout.addWidget(self.label_description)
layout.addWidget(self.radiobutton_1)
layout.addWidget(self.radiobutton_2)
layout.addWidget(self.radiobutton_3)
layout.addWidget(self.Separador)
layout.addWidget(self.radiobutton_4)
layout.addWidget(self.radiobutton_5)
def nextId(self) -> int:
if self.radiobutton_1.isChecked():
return 1
if self.radiobutton_2.isChecked():
return 5
if self.radiobutton_3.isChecked():
return 6
if self.radiobutton_4.isChecked():
return 7
if self.radiobutton_5.isChecked():
return 3
return 0
class CreateWallet(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Create wallet")
self.password_label = QLabel("Password (optional):")
self.passwordline_edit = QLineEdit(self)
self.passwordline_edit.setEchoMode(2)
self.passwordline_edit.setPlaceholderText("Enter password")
self.combo_height = QComboBox(self)
self.combo_height.addItem("Tree height: 8 | Signatures: 256")
self.combo_height.addItem("Tree height: 10 | Signatures: 1,024")
self.combo_height.addItem("Tree height: 12 | Signatures: 4,096")
self.combo_height.addItem("Tree height: 14 | Signatures: 16,384")
self.combo_height.addItem("Tree height: 16 | Signatures: 65,536")
self.combo_height.addItem("Tree height: 18 | Signatures: 262,144")
self.note = QLabel("\nButtons will be automatically disabled while generating wallet.\nThey will be enabled again once finished.\n\nTree height larger than 14 will take longer than usual.\nPlease be patient.")
self.combo_hash = QComboBox(self)
self.combo_hash.addItem("Hash function: SHAKE_128")
self.combo_hash.addItem("Hash function: SHAKE_256")
self.combo_hash.addItem("Hash function: SHA2_256")
layout = QVBoxLayout(self)
layout.addWidget(self.password_label)
layout.addWidget(self.passwordline_edit)
layout.addWidget(self.combo_height)
layout.addWidget(self.combo_hash)
layout.addWidget(self.note)
def nextId(self) -> int:
return 2
class WalletDetails(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Wallet details")
self.qaddress_description = QLabel("QRL Public address:")
self.qaddress = QTextEdit()
self.qaddress.setTextInteractionFlags(Qt.TextSelectableByMouse)
self.mnemonic_description = QLabel("Mnemonic phrase:")
self.mnemonic = QLabel()
self.hexseed_description = QLabel("Hexseed:")
self.hexseed = QLabel()
self.save_wallet_file = QPushButton('Save secure wallet file')
self.scroll = QScrollArea()
self.scroll.setWidgetResizable(True)
self.frame = QFrame(self)
self.qaddress.setFrameStyle(QFrame.Panel | QFrame.Raised)
self.qaddress.setFrameShadow(QFrame.Plain)
self.qaddress.setLineWidth(1)
self.mnemonic.setFrameStyle(QFrame.Panel | QFrame.Raised)
self.mnemonic.setFrameShadow(QFrame.Plain)
self.mnemonic.setLineWidth(1)
self.mnemonic.setWordWrap(True)
self.hexseed.setFrameStyle(QFrame.Panel | QFrame.Raised)
self.hexseed.setFrameShadow(QFrame.Plain)
self.hexseed.setLineWidth(1)
layout = QVBoxLayout(self)
layout.addWidget(self.qaddress_description)
layout.addWidget(self.qaddress)
layout.addWidget(self.mnemonic_description)
layout.addWidget(self.mnemonic)
layout.addWidget(self.hexseed_description)
layout.addWidget(self.hexseed)
layout.addWidget(self.save_wallet_file)
def nextId(self) -> int:
return 11
class CreateSeedByMouse(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Generate entropy by mouse!")
self.password_label = QLabel("Password (optional):")
self.passwordline_edit = QLineEdit(self)
self.passwordline_edit.setEchoMode(2)
self.passwordline_edit.setPlaceholderText("Enter password")
self.combo_height = QComboBox(self)
self.combo_height.addItem("Tree height: 8 | Signatures: 256")
self.combo_height.addItem("Tree height: 10 | Signatures: 1,024")
self.combo_height.addItem("Tree height: 12 | Signatures: 4,096")
self.combo_height.addItem("Tree height: 14 | Signatures: 16,384")
self.combo_height.addItem("Tree height: 16 | Signatures: 65,536")
self.combo_height.addItem("Tree height: 18 | Signatures: 262,144")
self.combo_hash = QComboBox(self)
self.combo_hash.addItem("Hash function: SHAKE_128")
self.combo_hash.addItem("Hash function: SHAKE_256")
self.combo_hash.addItem("Hash function: SHA2_256")
self.video_label = QtWidgets.QLabel()
self.video_label.setStyleSheet("background-color: white; border: 1px solid black")
self.video_label.setFixedWidth(510)
self.video_label.setFixedHeight(175)
tracker = MouseTracker(self.video_label)
tracker.positionChanged.connect(self.on_positionChanged)
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.password_label)
layout.addWidget(self.passwordline_edit)
layout.addWidget(self.combo_height)
layout.addWidget(self.combo_hash)
layout.addWidget(self.video_label)
self.label_position = QtWidgets.QLabel(
self.video_label, alignment=QtCore.Qt.AlignCenter
)
self.label_position.setStyleSheet('background-color: white; border: 1px solid black')
@QtCore.pyqtSlot(QtCore.QPoint)
def on_positionChanged(self, pos):
delta = QtCore.QPoint(30, -15)
self.label_position.show()
self.label_position.move(pos + delta)
self.label_position.setText("(%d, %d)" % (pos.x(), pos.y()))
self.label_position.adjustSize()
main.seed_data.append("%d" % (pos.x()))
main.seed_data.append("%d" % (pos.y()))
print(main.seed_data)
def nextId(self) -> int:
return 4
class MouseTracker(QtCore.QObject):
positionChanged = QtCore.pyqtSignal(QtCore.QPoint)
def __init__(self, widget):
super().__init__(widget)
self._widget = widget
self.widget.setMouseTracking(True)
self.widget.installEventFilter(self)
@property
def widget(self):
return self._widget
def eventFilter(self, o, e):
if o is self.widget and e.type() == QtCore.QEvent.MouseMove:
self.positionChanged.emit(e.pos())
return super().eventFilter(o, e)
class WalletDetailsExperimental(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Wallet details")
self.qaddress_description = QLabel("QRL Public address:")
self.qaddress = QTextEdit()
self.qaddress.setTextInteractionFlags(Qt.TextSelectableByMouse)
self.mnemonic_description = QLabel("Mnemonic phrase:")
self.mnemonic = QLabel()
self.hexseed_description = QLabel("Hexseed:")
self.hexseed = QLabel()
self.save_wallet_file = QPushButton('Save secure wallet file')
self.scroll = QScrollArea()
self.scroll.setWidgetResizable(True)
self.frame = QFrame(self)
self.qaddress.setFrameStyle(QFrame.Panel | QFrame.Raised)
self.qaddress.setFrameShadow(QFrame.Plain)
self.qaddress.setLineWidth(1)
self.mnemonic.setFrameStyle(QFrame.Panel | QFrame.Raised)
self.mnemonic.setFrameShadow(QFrame.Plain)
self.mnemonic.setLineWidth(1)
self.mnemonic.setWordWrap(True)
self.hexseed.setFrameStyle(QFrame.Panel | QFrame.Raised)
self.hexseed.setFrameShadow(QFrame.Plain)
self.hexseed.setLineWidth(1)
layout = QVBoxLayout(self)
layout.addWidget(self.qaddress_description)
layout.addWidget(self.qaddress)
layout.addWidget(self.mnemonic_description)
layout.addWidget(self.mnemonic)
layout.addWidget(self.hexseed_description)
layout.addWidget(self.hexseed)
layout.addWidget(self.save_wallet_file)
def nextId(self) -> int:
return 11
class SlaveJsonOptions(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Slaves.json requires a wallet")
self.label_description = QLabel("Select option:")
self.radiobutton_1 = QRadioButton("Open wallet file")
self.radiobutton_2 = QRadioButton("Restore wallet from seed")
layout = QVBoxLayout(self)
layout.addWidget(self.label_description)
layout.addWidget(self.radiobutton_1)
layout.addWidget(self.radiobutton_2)
def nextId(self) -> int:
if self.radiobutton_1.isChecked():
return 9
if self.radiobutton_2.isChecked():
return 10
return 0
class CreateSlavesJson(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Slaves.json is finished!")
self.generatedslave_label = QLabel("Move slaves.json file from current directory to the mining node inside ~/.qrl/\n\nYou can close the wallet now.")
self.slave_number_label = QLabel()
layout = QVBoxLayout(self)
layout.addWidget(self.generatedslave_label)
layout.addWidget(self.slave_number_label)
def nextId(self) -> int:
return 11
class OpenWalletFile(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Open wallet file")
self.password_qlabel = QLabel("Password (optional):")
self.passwordline_edit = QLineEdit()
self.passwordline_edit.setEchoMode(2)
self.passwordline_edit.setPlaceholderText("Enter password")
self.openFileBtn = QPushButton("Import secure wallet file")
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.password_qlabel)
layout.addWidget(self.passwordline_edit)
layout.addWidget(self.openFileBtn)
self.setLayout(layout)
def nextId(self) -> int:
return 11
class OpenWalletFileSlaves(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Open wallet file")
self.password_qlabel = QLabel("Password (optional):")
self.passwordline_edit = QLineEdit()
self.passwordline_edit.setEchoMode(2)
self.passwordline_edit.setPlaceholderText("Enter password")
self.openFileBtn = QPushButton("Import secure wallet file")
self.warning_label = QLabel("After clicking 'Next' button to begin, the slaves will be generated which will\ntake about 10 minutes. See the console for progress.\n\nPlease be patient.")
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.password_qlabel)
layout.addWidget(self.passwordline_edit)
layout.addWidget(self.openFileBtn)
layout.addWidget(self.warning_label)
self.setLayout(layout)
def nextId(self) -> int:
return 8
class RegExpValidator(QtGui.QRegularExpressionValidator):
validationChanged = QtCore.pyqtSignal(QtGui.QValidator.State)
def validate(self, input, pos):
state, input, pos = super().validate(input, pos)
self.validationChanged.emit(state)
return state, input, pos
class RestoreWallet(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Restore your wallet")
self.seed_label = QLabel("Enter your seed:")
self.seedline_edit = QLineEdit()
layout = QtWidgets.QHBoxLayout(self)
layout.addWidget(self.seed_label)
layout.addWidget(self.seedline_edit)
regexp_mnemonic = QtCore.QRegularExpression(r'((\b|\s)+\w+(\b|\s)+){34}|.{102}') #QRL address regex
validator = RegExpValidator(regexp_mnemonic, self)
validator.validationChanged.connect(self.handleValidationChange)
self.seedline_edit.setValidator(validator)
def handleValidationChange(self, state):
if state == QtGui.QValidator.Invalid:
colour = 'red'
elif state == QtGui.QValidator.Intermediate:
colour = 'gold'
elif state == QtGui.QValidator.Acceptable:
colour = 'lime'
self.seedline_edit.setStyleSheet('border: 1px solid %s' % colour)
def nextId(self) -> int:
return 11
class RestoreWalletSlaves(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Restore your wallet")
self.seed_label = QLabel("Enter your seed:")
self.seedline_edit = QLineEdit()
self.warning_label = QLabel("After clicking 'Next' button to begin, the slaves will be generated which will\ntake about 10 minutes. See the console for progress.\n\nPlease be patient.")
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.seed_label)
layout.addWidget(self.seedline_edit)
layout.addWidget(self.warning_label)
regexp_mnemonic = QtCore.QRegularExpression(r'((\b|\s)+\w+(\b|\s)+){34}|.{102}') #QRL address regex
validator = RegExpValidator(regexp_mnemonic, self)
validator.validationChanged.connect(self.handleValidationChange)
self.seedline_edit.setValidator(validator)
def handleValidationChange(self, state):
if state == QtGui.QValidator.Invalid:
colour = 'red'
elif state == QtGui.QValidator.Intermediate:
colour = 'gold'
elif state == QtGui.QValidator.Acceptable:
colour = 'lime'
self.seedline_edit.setStyleSheet('border: 1px solid %s' % colour)
def nextId(self) -> int:
return 8
class LastPage(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Success!")
slider_values = []
class QrlWallet(QtWidgets.QMainWindow, Ui_mainWindow, Ui_Form, Ui_Form2 , QtWidgets.QWizard, QTableWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setupUi(self)
self.model = Model()
regexp_ots_key = QRegExp(r'^[0-9]*$')
self.ots_key_validator = QRegExpValidator(regexp_ots_key)
header = self.transaction_table.horizontalHeader()
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
header.setSectionResizeMode(2, QtWidgets.QHeaderView.Stretch)
self.save_history.clicked.connect(self.handleSavehistory)
self.horizontalSlider.valueChanged.connect(self.sliderChanged)
self.custom_fee.clicked.connect(self.setCustomFee)
self.fee_edit.hide()
self.send_button.clicked.connect(self.button_clicked)
self.actionAbout.triggered.connect(self.about_popup)
self.view_recovery_seed_btn.clicked.connect(self.recovery_seed_pop_up)
self.actionCheck_for_updates.triggered.connect(lambda: QDesktopServices.openUrl(QUrl("https://github.com/successor1/qrllight/releases")))
self.actionOfficial_website.triggered.connect(lambda: QDesktopServices.openUrl(QUrl("https://theqrl.org")))
self.actionDocumentation.triggered.connect(lambda: QDesktopServices.openUrl(QUrl("https://docs.theqrl.org/")))
self.actionQRL_whitepaper.triggered.connect(lambda: QDesktopServices.openUrl(QUrl("https://raw.githubusercontent.com/theQRL/Whitepaper/master/QRL_whitepaper.pdf")))
self.actionReport_bug.triggered.connect(lambda: QDesktopServices.openUrl(QUrl("https://github.com/successor1/qrllight/issues")))
self.actionDonate_to_development.triggered.connect(self.donate_popup)
def setCustomFee(self):
if self.custom_fee.isChecked():
self.horizontalSlider.hide()
self.slider_label.hide()
self.fee_edit.show()
else:
self.fee_edit.hide()
self.horizontalSlider.show()
self.slider_label.show()
def sliderChanged(self, value):
try:
slider_values.pop(0)
except:
pass
slider_values.append(value)
def handleSavehistory(self):
# with open('monschedule.csv', 'wb') as stream:
with open('mytransactionhistory.csv', 'w') as stream: # 'w'
writer = csv.writer(stream, lineterminator='\n') # + , lineterminator='\n'
for row in range(self.transaction_table.rowCount()):
rowdata = []
for column in range(self.transaction_table.columnCount()):
item = self.transaction_table.item(row, column)
if item is not None:
# rowdata.append(unicode(item.text()).encode('utf8'))
rowdata.append(item.text()) # +
else:
rowdata.append('')
writer.writerow(rowdata)
def button_clicked(self):
qrl_address = []
mnemonic = []
hexseed = []
if QWizard.hasVisitedPage(main, 2):
qrl_address.append(main.walletDetails.qaddress.toPlainText())
mnemonic.append(main.walletDetails.mnemonic.text().rstrip())
hexseed.append(main.walletDetails.hexseed.text())
elif QWizard.hasVisitedPage(main, 5):
qrl_address.append(main.data[0].split(" ")[0])
mnemonic.append(" ".join(main.data[0].split(" ")[1:-1]))
hexseed.append(main.data[0].split(" ")[35])
elif QWizard.hasVisitedPage(main, 6):
if main.restoreWallet.seedline_edit.text()[:6] == "absorb":
qrl_address.append(Model.recoverAddressMnemonic(main.restoreWallet.seedline_edit.text()))
mnemonic.append(main.restoreWallet.seedline_edit.text())
hexseed.append(Model.recoverHexseedMnemonic(main.restoreWallet.seedline_edit.text()))
elif main.restoreWallet.seedline_edit.text()[:2] == "01":
qrl_address.append(Model.recoverAddressHexseed(main.restoreWallet.seedline_edit.text()))
mnemonic.append(Model.recoverMnemonicHexseed(main.restoreWallet.seedline_edit.text()))
hexseed.append(main.restoreWallet.seedline_edit.text())
elif QWizard.hasVisitedPage(main, 3):
qrl_address.append(main.walletDetailsExperimental.qaddress.toPlainText())
mnemonic.append(main.walletDetailsExperimental.mnemonic.text().rstrip())
hexseed.append(main.walletDetailsExperimental.hexseed.text())
ots_key_validator = self.ots_key_validator.validate(self.ots_key_index_input.text(), 0)
if ots_key_validator[0] != 2:
QMessageBox.warning(self, "Warning: Incorrect Input!", "Wrong or empty OTS key input")
else:
remove_first_char_addrs = [e[1:] for e in self.send_input.text().split()]
amount_string = self.amount_input.text().split()
amount_list = [float(i) for i in list(amount_string)]
addrs_to = remove_first_char_addrs
amounts = amount_list
message_data = self.description_input.text().encode() if self.description_input.text() else None
if self.fee_edit.text() == None or self.fee_edit.text() == "":
try:
if slider_values[0] < 33:
slider_values.pop(0)
slider_values.append(0.001)
elif slider_values[0] > 33 and slider_values[0] < 66:
slider_values.pop(0)
slider_values.append(0.01)
elif slider_values[0] > 50:
slider_values.pop(0)
slider_values.append(1)
except:
slider_values.append(0.01)
else:
slider_values.clear()
slider_values.append(self.fee_edit.text())
print(slider_values[0])
fee = str(float(slider_values[0]) * 1000000000)[:-2]
xmss_pk = XMSS.from_extended_seed(hstr2bin(hexseed[0])).pk
src_xmss = XMSS.from_extended_seed(hstr2bin(hexseed[0]))
ots_key = int(self.ots_key_index_input.text())
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText("Do you want to proceed?")
msg.setInformativeText("Send to: " + self.send_input.text() +"\nAmount: " + self.amount_input.text() + "\nFee: " + str(slider_values[0]) + "\nOTS Key Index: " + self.ots_key_index_input.text())
msg.setWindowTitle("QRL Confirmation")
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
returnValue = msg.exec()
if returnValue == QMessageBox.Cancel:
pass
else:
models.TransferTransaction.tx_transfer(
addrs_to,
amounts,
message_data,
fee,
xmss_pk,
src_xmss,
ots_key,
qrl_network[0])
QMessageBox.about(self, "Succesful transaction", "Sent!")
def update(self):
self.balance_label.adjustSize()
def about_popup(self):
self.dialog=QtWidgets.QMainWindow()
self.ui = Ui_Form()
self.ui.setupUi(self.dialog)
self.dialog.show()
def recovery_seed_pop_up(self):
self.t = recoveryWindow
self.t.show()
def donate_popup(self):
self.dialog=QtWidgets.QMainWindow()
self.ui = Ui_Form2()
self.ui.setupUi(self.dialog)
self.dialog.show()
class RecoverySeedView(QWidget):
def __init__(self):
super(RecoverySeedView, self).__init__()
self.setWindowTitle("Wallet details")
self.warning_label = QLabel('Warning: If someone unauthorized gains access to these, your funds will be lost!', self )
myFont=QtGui.QFont()
self.warning_label.setAlignment(Qt.AlignCenter)
self.warning_label.setStyleSheet('color: red')
myFont.setBold(True)
self.warning_label.setFont(myFont)
self.mnemonic_label = QLabel('Mnemonic phrase', self )
self.mnemonic_label.setAlignment(Qt.AlignCenter)
self.mnemonic_label_text = QLabel()
self.mnemonic_label_text.setTextInteractionFlags(Qt.TextSelectableByMouse)
self.hexseed_label = QLabel('Hexseed', self )
self.hexseed_label.setAlignment(Qt.AlignCenter)
self.hexseed_label_text = QLabel()
self.hexseed_label_text.setTextInteractionFlags(Qt.TextSelectableByMouse)
self.mnemonic_label_text.setFrameStyle(QFrame.Panel | QFrame.Raised)
self.mnemonic_label_text.setFrameShadow(QFrame.Plain)
self.mnemonic_label_text.setLineWidth(1)
self.mnemonic_label_text.setWordWrap(True)
self.hexseed_label_text.setFrameStyle(QFrame.Panel | QFrame.Raised)
self.hexseed_label_text.setFrameShadow(QFrame.Plain)
self.hexseed_label_text.setLineWidth(1)
layout = QVBoxLayout(self)
layout.addWidget(self.warning_label)
layout.addWidget(self.mnemonic_label)
layout.addWidget(self.mnemonic_label_text)
layout.addWidget(self.hexseed_label)
layout.addWidget(self.hexseed_label_text)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
main = MyWizard()
mainWindow = QrlWallet()
recoveryWindow = RecoverySeedView()
app.setWindowIcon(QtGui.QIcon('logocircle.ico'))
main.hide()
main.setWindowModality(QtCore.Qt.ApplicationModal)
mainWindow.show()
main.show()
sys.exit(app.exec_())