forked from BTCTaras/kristwallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkristwallet
1695 lines (1692 loc) · 56.1 KB
/
kristwallet
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
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[-----------------------------------------------
| KristWallet by cossacksson |
---------------------------------------------------
| This is the reference wallet for Krist. |
| It is the basic definition of a functional |
| Krist program, although it is not as old as the |
| network (we used to just use raw API calls). |
---------------------------------------------------
| (Almost) last bit of this program (except, of |
| course, SHA256 itself) was made entirely by |
| cossacksson and is "free software" and whatnot. |
| Do whatever you want with it, but if you make |
| it interact with a currency or network other |
| than Krist, please give me credit. Thanks <3 |
---------------------------------------------------
| This wallet will NEVER save passwords anywhere. |]]
-----------------------------------------------]]--
local versionstr = "11M"
local version = 9999
local latest = 0
local balance = 0
local balance2 = 0
local balance3 = 0
local MOD = 2^32
local MODM = MOD-1
local gui = 0
local page = 0
local lastpage = 0
local scroll = 0
local masterkey = ""
local doublekey = ""
local address = ""
local addressv1 = ""
local addressdv = ""
local addresslv = ""
local subject = ""
local name = ""
local subbal = 0
local subtxs = ""
local stdate = {}
local stpeer = {}
local stval = {}
local blkpeer = {}
local pagespace = ""
local maxspace = ""
local ar = 0
local amt = 0
local availability = 0
local function boot()
checkdir()
checkdir()
print("Starting KristWallet v"..tostring(versionstr))
log("Started KristWallet v"..tostring(versionstr))
update()
if readconfig("enabled") and latest <= version then
settle()
openwallet()
while page ~= 0 do
wallet()
end
term.setBackgroundColor(32768)
term.setTextColor(16)
term.clear()
term.setCursorPos(1,1)
log("KristWallet closed safely")
else
if not readconfig("enabled") then print("KristWallet is disabled on this computer.") log("Disabled, shutting down") end
end
if readconfig("rebootonexit") then
log("Rebooted computer")
os.reboot()
end
end
function update()
latest = tonumber(http.get(readconfig("versionserver")).readAll())
if latest > version then
print("An update is available!")
log("Discovered update")
if readconfig("autoupdate") then
local me = fs.open(fs.getName(shell.getRunningProgram()),"w")
local nextversion = http.get(readconfig("updateserver")).readAll()
print("Installed update. Run this program again to start v"..latest..".")
me.write(nextversion)
me.close()
log("Installed update")
else
log("Ignored update")
latest = -2
end
else
log("No updates found")
end
end
function log(text)
logfile = fs.open("kst/log_wallet","a")
logfile.writeLine(tostring(os.day()).."-"..tostring(os.time()).."/"..text)
logfile.close()
end
function checkfile(path,default)
if not fs.exists("kst/"..path) or path == "syncnode" then
file = fs.open("kst/"..path,"w")
file.writeLine(default)
file.close()
log("Created file "..path)
return false
else
return true
end
end
function readconfig(path)
if fs.exists("kst/"..path) then
file = fs.open("kst/"..path,"r")
local context = file.readAll()
file.close()
if context == "true" then return true end
if context == "false" then return false end
return context
else
print("An unknown error happened")
end
end
function settle()
if term.isColor() then gui = 1 end
if term.isColor() and pocket then gui = 2 end
end
local function drawKrist()
posx, posy = term.getCursorPos()
term.setBackgroundColor(1)
term.setTextColor(32)
term.write("/")
term.setBackgroundColor(32)
term.setTextColor(8192)
term.write("\\")
term.setCursorPos(posx,posy+1)
term.setBackgroundColor(32)
term.setTextColor(8192)
term.write("\\")
term.setBackgroundColor(8192)
term.setTextColor(32)
term.write("/")
term.setCursorPos(posx+2,posy)
end
local function memoize(f)
local mt = {}
local t = setmetatable({}, mt)
function mt:__index(k)
local v = f(k)
t[k] = v
return v
end
return t
end
local function make_bitop_uncached(t, m)
local function bitop(a, b)
local res,p = 0,1
while a ~= 0 and b ~= 0 do
local am, bm = a % m, b % m
res = res + t[am][bm] * p
a = (a - am) / m
b = (b - bm) / m
p = p*m
end
res = res + (a + b) * p
return res
end
return bitop
end
local function make_bitop(t)
local op1 = make_bitop_uncached(t,2^1)
local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end)
return make_bitop_uncached(op2, 2 ^ (t.n or 1))
end
local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})
local function bxor(a, b, c, ...)
local z = nil
if b then
a = a % MOD
b = b % MOD
z = bxor1(a, b)
if c then z = bxor(z, c, ...) end
return z
elseif a then return a % MOD
else return 0 end
end
local function band(a, b, c, ...)
local z
if b then
a = a % MOD
b = b % MOD
z = ((a + b) - bxor1(a,b)) / 2
if c then z = bit32_band(z, c, ...) end
return z
elseif a then return a % MOD
else return MODM end
end
local function bnot(x) return (-1 - x) % MOD end
local function rshift1(a, disp)
if disp < 0 then return lshift(a,-disp) end
return math.floor(a % 2 ^ 32 / 2 ^ disp)
end
local function rshift(x, disp)
if disp > 31 or disp < -31 then return 0 end
return rshift1(x % MOD, disp)
end
local function lshift(a, disp)
if disp < 0 then return rshift(a,-disp) end
return (a * 2 ^ disp) % 2 ^ 32
end
local function rrotate(x, disp)
x = x % MOD
disp = disp % 32
local low = band(x, 2 ^ disp - 1)
return rshift(x, disp) + lshift(low, 32 - disp)
end
local k = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
}
local function str2hexa(s)
return (string.gsub(s, ".", function(c) return string.format("%02x", string.byte(c)) end))
end
local function num2s(l, n)
local s = ""
for i = 1, n do
local rem = l % 256
s = string.char(rem) .. s
l = (l - rem) / 256
end
return s
end
local function s232num(s, i)
local n = 0
for i = i, i + 3 do n = n*256 + string.byte(s, i) end
return n
end
local function preproc(msg, len)
local extra = 64 - ((len + 9) % 64)
len = num2s(8 * len, 8)
msg = msg .. "\128" .. string.rep("\0", extra) .. len
assert(#msg % 64 == 0)
return msg
end
local function initH256(H)
H[1] = 0x6a09e667
H[2] = 0xbb67ae85
H[3] = 0x3c6ef372
H[4] = 0xa54ff53a
H[5] = 0x510e527f
H[6] = 0x9b05688c
H[7] = 0x1f83d9ab
H[8] = 0x5be0cd19
return H
end
local function digestblock(msg, i, H)
local w = {}
for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end
for j = 17, 64 do
local v = w[j - 15]
local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))
v = w[j - 2]
w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))
end
local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]
for i = 1, 64 do
local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))
local maj = bxor(band(a, b), band(a, c), band(b, c))
local t2 = s0 + maj
local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))
local ch = bxor (band(e, f), band(bnot(e), g))
local t1 = h + s1 + ch + k[i] + w[i]
h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2
end
H[1] = band(H[1] + a)
H[2] = band(H[2] + b)
H[3] = band(H[3] + c)
H[4] = band(H[4] + d)
H[5] = band(H[5] + e)
H[6] = band(H[6] + f)
H[7] = band(H[7] + g)
H[8] = band(H[8] + h)
end
local function sha256(msg)
msg = preproc(msg, #msg)
local H = initH256({})
for i = 1, #msg, 64 do digestblock(msg, i, H) end
return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..
num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))
end
local function panic()
page = 0
log("Panicking! Shutting down KristWallet.")
end
local function makeaddressbyte(j)
if j <= 6 then return "0"
elseif j <= 13 then return "1"
elseif j <= 20 then return "2"
elseif j <= 27 then return "3"
elseif j <= 34 then return "4"
elseif j <= 41 then return "5"
elseif j <= 48 then return "6"
elseif j <= 55 then return "7"
elseif j <= 62 then return "8"
elseif j <= 69 then return "9"
elseif j <= 76 then return "a"
elseif j <= 83 then return "b"
elseif j <= 90 then return "c"
elseif j <= 97 then return "d"
elseif j <= 104 then return "e"
elseif j <= 111 then return "f"
elseif j <= 118 then return "g"
elseif j <= 125 then return "h"
elseif j <= 132 then return "i"
elseif j <= 139 then return "j"
elseif j <= 146 then return "k"
elseif j <= 153 then return "l"
elseif j <= 160 then return "m"
elseif j <= 167 then return "n"
elseif j <= 174 then return "o"
elseif j <= 181 then return "p"
elseif j <= 188 then return "q"
elseif j <= 195 then return "r"
elseif j <= 202 then return "s"
elseif j <= 209 then return "t"
elseif j <= 216 then return "u"
elseif j <= 223 then return "v"
elseif j <= 230 then return "w"
elseif j <= 237 then return "x"
elseif j <= 244 then return "y"
elseif j <= 251 then return "z"
else return "e"
end
end
function checkdir()
if fs.isDir("kst") then
math.randomseed(os.time())
checkfile("log_wallet",[[-----KRISTWALLET LOG FILE-----
--If this file becomes excessively large, you
--should save a copy to a disk and stow it away.
--You should not destroy logs - they may help any
--detectives recover stolen krist, or at least find
--the perpetrator! Happy Kristmas! -cossacksson.
---------------------------------------------------]])
checkfile("enabled","true") --Disabling this just makes KristWallet refuse to start. No danger of Krist loss.
checkfile("sweepv1","true")
checkfile("appendhashes","true") --Disabling this makes it possible to use KristWallet with extremely old addresses. I doubt anyone but me ever will.
checkfile("autoupdate","true")
checkfile("whitelisted","false")
checkfile("rebootonexit","false")
checkfile("locksettings","false")
checkfile("usev1address","false")
checkfile("autologin","false") --Don't use autologin. Admittedly, it was a very stupid and dangerous idea. If you want a wallet exclusive to your address, use whitelist instead.
checkfile("keyAL",sha256("")) --This is meaningless gibberish
checkfile("keyLV",sha256(math.random(10)..os.time())) --This is where the local vault's krist is stored. DO NOT DESTROY EVER.
checkfile("versionserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/staticapi/version")
checkfile("updateserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/kristwallet")
checkfile("syncnode","http://ceriat.net/krist/") --A trusted A-class node to push transactions to.
checkfile("whitelist",[[kg5dc1lzo0
a5dfb396d3]])
checkfile("blacklist",[[ke3kjplzsz #Blank string (prevent accidents)
kojddz0uzw #RV main
8c11bb0d2d #Ransom virus
]])
else
fs.makeDir("kst")
end
end
function openwallet()
term.setBackgroundColor(8)
term.clear()
local krists = 0
repeat
term.setCursorPos(3+(3*krists),3)
drawKrist()
krists = krists + 1
until krists == 16
krists = 0
repeat
term.setCursorPos(3+(3*krists),16)
drawKrist()
krists = krists + 1
until krists == 16
term.setBackgroundColor(8)
term.setTextColor(32768)
term.setCursorPos(6,6)
term.write("Username: ")
local password = ""
if readconfig("autologin") then
password = readconfig("keyAL")
else
u = read()
term.setCursorPos(6,7)
term.write("Password: ")
pass = read("*")
password = sha256(sha256(u) .. "^" .. sha256(pass))
if readconfig("appendhashes") then password = sha256("KRISTWALLETEXTENSION"..password) end
end
term.clear()
term.setCursorPos(1,1)
page = 1+gui*(10*(gui-1))
if readconfig("appendhashes") then masterkey = password.."-000" else masterkey = password end
log("Read password")
addressv1 = string.sub(sha256(masterkey),0,10)
log("Derived address: "..addressv1)
address = makev2address(masterkey)
log("Derived address: "..address)
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..addressv1).readAll())
if balance > 0 and readconfig("sweepv1") then local transaction = http.get(readconfig("syncnode").."?pushtx&q="..address.."&pkey="..masterkey.."&amt="..balance).readAll() log("Swept hex address") end
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll())
if balance >= 100000 then log("Woah! There's a small fortune here!") elseif balance > 0 then log("There is some krist here!") end
if balance == 420 then log("This is such a blazing balance") end
if balance == 42 then log("Hey, Chuck") end
if readconfig("whitelisted") then
local whitelist = readconfig("whitelist")
if string.find(whitelist, address) == nil then
log(address.." is not on the whitelist!")
print("Sorry, this wallet is not on the whitelist for this computer!")
page = 0
os.sleep(3)
end
else
local blacklist = readconfig("blacklist")
if string.find(blacklist, addressv1) ~= nil then
log(addressv1.." is on the blacklist!")
print("Your wallet is blocked from this computer!")
page = 0
os.sleep(3)
elseif string.find(blacklist, address) ~= nil then
log(address.." is on the blacklist!")
print("Your wallet is blocked from this computer!")
page = 0
os.sleep(3)
end
end
if readconfig("usev1address") then address = addressv1 end
addresslv = makev2address(readconfig("keyLV"))
log("Loaded local vault")
end
function makev2address(key)
local protein = {}
local stick = sha256(sha256(key))
local n = 0
local link = 0
local v2 = "k"
repeat
if n < 9 then protein[n] = string.sub(stick,0,2)
stick = sha256(sha256(stick)) end
n = n + 1
until n == 9
n = 0
repeat
link = tonumber(string.sub(stick,1+(2*n),2+(2*n)),16) % 9
if string.len(protein[link]) ~= 0 then
v2 = v2 .. makeaddressbyte(tonumber(protein[link],16))
protein[link] = ''
n = n + 1
else
stick = sha256(stick)
end
until n == 9
return v2
end
local function postgraphic(px,py,id)
term.setCursorPos(px,py)
if id == 0 then drawKrist()
elseif id == 1 then
--Mined Krist
term.setCursorPos(px+1,py)
term.setBackgroundColor(256)
term.setTextColor(128)
term.write("/T\\")
term.setCursorPos(px,py+1)
term.write("/")
term.setCursorPos(px+2,py+1)
term.write("|")
term.setCursorPos(px+4,py+1)
term.write("\\")
term.setCursorPos(px+2,py+2)
term.write("|")
term.setCursorPos(px+2,py+3)
term.write("|")
term.setCursorPos(px+4,py+2)
drawKrist()
elseif id == 2 then
--Sent Krist
term.setCursorPos(px,py+2)
term.setBackgroundColor(256)
term.setTextColor(16384)
term.write(" ")
term.setCursorPos(px+1,py+3)
term.write(" ")
term.setCursorPos(px+5,py+2)
term.write(" ")
term.setBackgroundColor(1)
term.setCursorPos(px+2,py)
term.write("/\\")
term.setCursorPos(px+2,py+1)
term.write("||")
elseif id == 3 then
--Received Krist
term.setCursorPos(px,py+2)
term.setBackgroundColor(256)
term.setTextColor(8192)
term.write(" ")
term.setCursorPos(px+1,py+3)
term.write(" ")
term.setCursorPos(px+5,py+2)
term.write(" ")
term.setBackgroundColor(1)
term.setCursorPos(px+2,py)
term.write("||")
term.setCursorPos(px+2,py+1)
term.write("\\/")
elseif id == 4 then
--Sent to yourself
term.setCursorPos(px,py+2)
term.setBackgroundColor(256)
term.setTextColor(16)
term.write(" ")
term.setCursorPos(px+1,py+3)
term.write(" ")
term.setCursorPos(px+5,py+2)
term.write(" ")
term.setBackgroundColor(1)
term.setCursorPos(px+1,py)
term.write("/\\||")
term.setCursorPos(px+1,py+1)
term.write("||\\/")
elseif id == 5 then
--Swept from v1 address
term.setCursorPos(px+1,py)
term.setBackgroundColor(256)
term.setTextColor(128)
term.write(" v1 ")
term.setCursorPos(px+2,py+1)
term.setBackgroundColor(1)
term.setTextColor(2048)
term.write("||")
term.setCursorPos(px+2,py+2)
term.write("\\/")
term.setCursorPos(px+1,py+3)
term.setBackgroundColor(16)
term.setTextColor(32768)
term.write(" v2 ")
elseif id == 6 then
--Name registered
term.setBackgroundColor(32)
term.setTextColor(8192)
term.setCursorPos(px+4,py)
term.write("/")
term.setCursorPos(px+1,py+1)
term.write("\\")
term.setCursorPos(px+3,py+1)
term.write("/")
term.setCursorPos(px+2,py+2)
term.write("V")
term.setCursorPos(px+1,py+3)
term.setBackgroundColor(16384)
term.setTextColor(4)
term.write(".kst")
elseif id == 7 then
--Name operation
term.setBackgroundColor(8)
term.setTextColor(512)
term.setCursorPos(px+1,py)
term.write(" a ")
term.setBackgroundColor(1)
term.write("\\")
term.setBackgroundColor(8)
term.setCursorPos(px+1,py+1)
term.write("====")
term.setCursorPos(px+1,py+2)
term.write("====")
term.setCursorPos(px+1,py+3)
term.setBackgroundColor(16384)
term.setTextColor(4)
term.write(".kst")
elseif id == 8 then
--Name sent
elseif id == 9 then
--Name received
end
end
function wallet()
hud()
local pagebefore = page
local event, button, xPos, yPos = os.pullEvent("mouse_click")
if gui == 1 and xPos >= 3 and xPos <= 14 then
if yPos == 5 then
page = 1
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll())
end
if yPos == 7 then
page = 2
subject = address
scroll = 0
end
if yPos == 9 then
page = 3
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll())
end
if yPos == 11 then
page = 8
end
if yPos == 13 then
page = 4
end
if yPos == 15 then
page = 15
end
if yPos == 17 then
page = 0
end
elseif gui == 2 then
if yPos == 2 and xPos >= 19 and xPos <= 24 then
page = 0
end
end
if page == 1 then
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll())
if (yPos-7)%5 == 0 and yPos >= 7 and xPos >= 26 and xPos <= 35 then
subject = string.sub(http.get(readconfig("syncnode").."?listtx="..address.."&overview").readAll(),13+(31*((yPos-7)/5)),22+(31*((yPos-7)/5)))
if string.len(subject) == 10 and subject ~= "N/A(Mined)" and subject ~= "N/A(Names)" then
page = 2
end
end
elseif page == 2 then
if yPos > 2 and yPos <= 2+ar-(16*(scroll)) and xPos >= 31 and xPos < 41 then
if stpeer[(yPos-2)+(16*(scroll))] == "N/A(Mined)" then
--possibly link to a block later?
elseif stpeer[(yPos-2)+(16*(scroll))] == "N/A(Names)" then
--possibly link to a name later??
else
subject = stpeer[(yPos-2)+(16*(scroll))]
scroll = 0
end
end
if yPos == 19 and xPos >= 32 and xPos <= 36 then
scroll = 0
end
if yPos == 19 and xPos >= 38 and xPos <= 41 then
scroll = math.max(0,scroll-1)
end
if yPos == 19 and xPos >= 43 and xPos <= 46 then
scroll = math.min(lastpage,scroll+1)
end
if yPos == 19 and xPos >= 48 then
scroll = lastpage
end
if yPos == 1 and xPos >= 17 then
page = 6
end
log("Page index is "..scroll)
elseif page == 3 then
if xPos >= 17 then
term.setCursorPos(33,5)
local recipient = read()
term.setCursorPos(33,6)
log("Read recipient for transfer")
local amount = read()
log("Read amount for transfer")
local transaction = http.get(readconfig("syncnode").."?pushtx2&q="..recipient.."&pkey="..masterkey.."&amt="..amount).readAll()
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll())
log("Attempting to send "..amount.." KST to "..recipient)
term.setCursorPos(19,8)
if transaction == "Success" then
term.setTextColor(8192)
term.write("Transfer successful")
log("Transfer successful")
term.setTextColor(32768)
elseif string.sub(transaction,0,5) == "Error" then
local problem = "An unknown error happened"
local code = tonumber(string.sub(transaction,6,10))
if code == 1 then problem = "Insufficient funds available" end
if code == 2 then problem = "Not enough KST in transaction" end
if code == 3 then problem = "Can't comprehend amount to send" end
if code == 4 then problem = "Invalid recipient address" end
term.setTextColor(16384)
term.write(problem)
log(problem)
term.setTextColor(32768)
else
term.setTextColor(16384)
term.write(transaction)
term.setTextColor(32768)
end
os.sleep(2.5) --lower this if you do tons of transfers
log("Unfroze display")
end
elseif page == 4 then
if yPos == 3 and xPos >= 19 and xPos <= 31 then
page = 5
scroll = 0
end
if yPos == 4 and xPos >= 19 and xPos <= 31 then
page = 10
end
if yPos == 5 and xPos >= 19 and xPos <= 31 then
--page = 11
end
if yPos == 3 and xPos >= 35 and xPos <= 48 then
page = 6
end
if yPos == 4 and xPos >= 35 and xPos <= 46 then
page = 7
end
elseif page == 5 then
if yPos > 2 and xPos >= 27 and xPos <= 36 then
page = 2
subject = blkpeer[(yPos-2)]
scroll = 0
end
elseif page == 6 then
term.setCursorPos(18,1)
term.write(" ")
term.setCursorPos(18,1)
term.write("ADDRESS ")
subject = read()
if string.len(subject) == 10 then
page = 2
scroll = 0
else
page = 6
end
elseif page == 7 then
if yPos > 2 and yPos <= 18 and xPos >= 20 and xPos < 30 then
if blkpeer[(yPos-2)] ~= "N/A(Burnt)" then
page = 2
subject = blkpeer[(yPos-2)]
scroll = 0
end
end
elseif page == 15 then
if yPos == 1 and xPos >= 46 then
page = 16
elseif yPos >= 3 and xPos >= 39 and xPos <= 42 then
page = 17
local listofnames = http.get(readconfig("syncnode").."?listnames="..address).readAll()
local nameclicked = yPos - 3
if nameclicked > 0 then repeat
listofnames = listofnames:sub(1+listofnames:find(";"))
nameclicked = nameclicked - 1
until nameclicked == 0 end
subject = listofnames:sub(0,listofnames:find(";")-1)
elseif yPos >= 3 and xPos >= 44 and xPos <= 47 then
page = 18
local listofnames = http.get(readconfig("syncnode").."?listnames="..address).readAll()
local nameclicked = yPos - 3
if nameclicked > 0 then repeat
listofnames = listofnames:sub(1+listofnames:find(";"))
nameclicked = nameclicked - 1
until nameclicked == 0 end
subject = listofnames:sub(0,listofnames:find(";")-1)
end
elseif page == 8 then
if yPos == 3 and xPos >= 19 and xPos <= 30 then
page = 9
end
if yPos == 3 and xPos >= 35 and xPos <= 47 then
page = 16
end
if yPos == 4 and xPos >= 19 and xPos <= 29 then
page = 13
end
elseif page == 18 then
if yPos == 5 and xPos >= 30 then
term.setCursorPos(30,5)
term.write(" ")
term.setCursorPos(30,5)
maxspace = read():lower()
term.setCursorPos(19,7)
pagespace = http.get(readconfig("syncnode").."?name_transfer&pkey="..masterkey.."&name="..subject.."&q="..maxspace).readAll()
if pagespace == "Success" then
end
term.write("Transfer request broadcasted")
log("Tried sending a name to "..maxspace)
os.sleep(3)
page = 15
--im drunk on water right now
end
elseif page == 16 then
if yPos == 4 and xPos >= 25 then
term.setCursorPos(25,4)
term.write(" ")
term.setCursorPos(25,4)
name = read():lower():gsub(".kst",""):gsub(" ","")
term.setCursorPos(25,4)
term.write("Please wait... ")
if string.len(name) > 0 then
if name == "a" or name == "name" or name == "id" or name == "owner" or name == "registered" or name == "updated" or name == "expires" or name == "unpaid" then
availability = 0
else
availability = tonumber(http.get(readconfig("syncnode").."?name_check="..name).readAll())
log("Checked "..name..".kst for availability ("..availability..")")
term.setCursorPos(19,7)
if availability then
term.setTextColor(colors.green)
term.write("Available!")
else
term.setTextColor(colors.red)
term.write("Not available!")
end
end
else
name = ""
end
elseif yPos == 7 and xPos >= 30 and xPos <= 39 and availability == 1 and balance >= 500 then
availability = 2
local k = http.get(readconfig("syncnode").."?name_new&pkey="..masterkey.."&name="..name).readAll()
end
elseif page == 17 then
if yPos == 5 and xPos >= 25 then
term.setCursorPos(25,5)
term.write(" ")
term.setCursorPos(25,5)
zone = read():gsub("http://","")
term.setCursorPos(25,5)
term.write("Please wait... ")
local sevenminutesleftuntilmaystartsfuckihavetoreleasethisnow = http.get(readconfig("syncnode").."?name_update&pkey="..masterkey.."&name="..subject.."&ar="..zone).readAll()
elseif yPos == 7 and xPos >= 30 and xPos <= 39 and availability == 1 and balance >= 500 then
availability = 2
local k = http.get(readconfig("syncnode").."?name_new&pkey="..masterkey.."&name="..name).readAll()
end
elseif page == 9 then
if yPos == 4 and xPos >= 30 then
term.setCursorPos(30,4)
term.write(" ")
term.setCursorPos(30,4)
doublekey = read("*")
term.setCursorPos(30,4)
term.write("Please wait... ")
if string.len(doublekey) > 0 then
doublekey = sha256(masterkey.."-"..sha256(doublekey))
addressdv = makev2address(doublekey)
balance2 = tonumber(http.get(readconfig("syncnode").."?getbalance="..addressdv).readAll())
log("Derived double vault "..addressdv)
else
addressdv = ""
balance2 = 0
end
end
if yPos == 5 and xPos >= 33 then
term.setCursorPos(33,5)
term.write(" ")
term.setCursorPos(33,5)
amt = read()
if tonumber(amt) == nil then
amt = 0
elseif tonumber(amt) % 1 ~= 0 then
amt = 0
elseif tonumber(amt) <= 0 then
amt = 0
end
end
if yPos == 6 and xPos >= 25 and xPos <= 33 then
if tonumber(amt) > 0 and string.len(doublekey) > 0 then
if tonumber(amt) <= balance then
local transaction = http.get(readconfig("syncnode").."?pushtx2&q="..addressdv.."&pkey="..masterkey.."&amt="..tonumber(amt)).readAll()
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll())
balance2 = tonumber(http.get(readconfig("syncnode").."?getbalance="..addressdv).readAll())
log("Put "..amt.." KST in a double vault")
end
end
end
if yPos == 6 and xPos >= 35 and xPos <= 44 then
if tonumber(amt) > 0 and string.len(doublekey) > 0 then
if tonumber(amt) <= balance2 then
local transaction = http.get(readconfig("syncnode").."?pushtx2&q="..address.."&pkey="..doublekey.."&amt="..tonumber(amt)).readAll()
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll())
balance2 = tonumber(http.get(readconfig("syncnode").."?getbalance="..addressdv).readAll())
log("Took "..amt.." KST from a double vault")
end
end
end
elseif page == 13 then
if yPos == 5 and xPos >= 33 then
term.setCursorPos(33,5)
term.write(" ")
term.setCursorPos(33,5)
term.setTextColor(32768)
amt = read()
if tonumber(amt) == nil then
amt = 0
elseif tonumber(amt) % 1 ~= 0 then
amt = 0
elseif tonumber(amt) <= 0 then
amt = 0
end
end
if yPos == 6 and xPos >= 25 and xPos <= 33 then
if tonumber(amt) > 0 then
if tonumber(amt) <= balance then
local transaction = http.get(readconfig("syncnode").."?pushtx2&q="..addresslv.."&pkey="..masterkey.."&amt="..tonumber(amt)).readAll()
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll())
log("Put "..amt.." KST in a local vault")
end
end
end
if yPos == 6 and xPos >= 35 and xPos <= 44 then
if tonumber(amt) > 0 then
if tonumber(amt) <= balance3 then
local transaction = http.get(readconfig("syncnode").."?pushtx2&q="..address.."&pkey="..readconfig("keyLV").."&amt="..tonumber(amt)).readAll()
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll())
log("Took "..amt.." KST from a local vault")
end
end
end
end
if pagebefore ~= page then log("Switched to page "..page) end
end
function drawTab(text)
term.setBackgroundColor(512)
term.write(text)
end
function drawBtn(text)
term.setBackgroundColor(32)
term.write(text)
end
function hud()
term.setBackgroundColor(1)
term.setTextColor(32768)
term.clear()
if gui == 1 then
local sidebar = 1
while sidebar < 51 do
term.setCursorPos(1,sidebar)
term.setBackgroundColor(8)
term.write(" ")
sidebar = sidebar + 1
end
term.setCursorPos(2,2)
drawKrist()
term.setBackgroundColor(8)
term.setTextColor(32768)
term.write(" KristWallet")
term.setCursorPos(5,3)
term.setTextColor(2048)
term.write("release "..versionstr.."")
term.setCursorPos(2,19)
term.write("by cossacksson")
term.setTextColor(32768)
term.setCursorPos(3,5)
drawTab(" Overview ")
term.setCursorPos(3,7)
drawTab("Transactions")
term.setCursorPos(3,9)
drawTab(" Send Krist ")
term.setCursorPos(3,11)
drawTab(" Special TX ")
term.setCursorPos(3,13)
drawTab(" Economicon ")
term.setCursorPos(3,15)
drawTab("Name Manager")
term.setCursorPos(3,17)
drawTab(" Exit ")
term.setBackgroundColor(1)
elseif gui == 2 then
term.setCursorPos(1,1)
term.setBackgroundColor(8)
term.write(" ")
term.setCursorPos(1,2)
term.write(" ")
term.setCursorPos(1,3)
term.write(" ")
term.setCursorPos(1,4)
term.write(" ")
term.setCursorPos(2,2)
drawKrist()
term.setBackgroundColor(8)
term.setTextColor(32768)
term.write(" KristWallet")
term.setCursorPos(5,3)
term.setTextColor(2048)
term.write("release "..version.."")
term.setCursorPos(19,2)
term.setBackgroundColor(16384)
term.setTextColor(32768)
term.write(" Exit ")
end
if page == 1 then
term.setCursorPos(19,2)
term.write("Your address: ")
term.setTextColor(16384)
term.write(address)