-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
950 lines (780 loc) · 37 KB
/
index.html
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
<!DOCTYPE html>
<!-- saved from url=(0039)https://multiexplorer.com/paper_wallet/ -->
<!-- And modified...-->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>MultiExplorer</title>
<link rel="stylesheet" type="text/css" href="./index_files/MultiExplorer.css">
<link rel="stylesheet" type="text/css" href="./index_files/wallets.css">
<link rel="stylesheet" type="text/css" href="./index_files/zoom_qr_code.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./index_files/jquery-3.3.1.min.js"></script>
<script src="./index_files/jquery.qrcode.min.js"></script>
<script src="./index_files/qrcode-generator.js"></script>
<script src="./index_files/moment.min.js"></script>
<script src="./index_files/bn.js"></script>
<script src="./index_files/bitcoinjs-min.js"></script>
<script src="./index_files/COINS_ARRAY.js"></script>
<script src="./index_files/web3-eth-accounts.js">//generate ethereum address from the same hex, corresponding bitcoin priv WIF</script>
</head>
<body>
<div id="header">
<div style="margin: 20px 0px 20px 10px;">
<input id="address_lookup" class="address" name="address" type="text" size="60" value="" placeholder="Enter any cryptocoin address or private key."
title = "This searching working on client-side, and will do search coin in array,
and show you info about prefixes and corresponding coins exists in array.">
<input id="address_lookup_button" type="submit" value="Go" onclick="search_coin();">
<!--next block here, to display salt info inline.-->
<!-- visualization randomization -->
<!-- gif for mouse cursor with random coordinates -->
<img id="cursor" title="eventListener onmousemove indication.
Display when salt changed."
style="display: none; position: absolute; width:64px; heigth:64px; /*by default 64x64 square*/"
src = "#">
<!--uncomment pathway with your picture for pic.src-->
</img>
<font title="See more info in the source code sha256_randomize_Math.Random.js">
Partial value of salt for modified Math.random() function:
<div id="partial_salt_value" style="display: inline; "></div>
</font>
<!--end visualization-->
<script src="./index_files/sha256_randomize_Math.Random.js"></script>
<div id="address_info"></div>
<!-- <a href="/block">Block Data</a>
<a href="./index_files/MultiExplorer.htm">Paper Wallet</a>-->
</div>
</div>
<script>
//set spinner gif-image:
var pic = document.getElementById("cursor"); //get element with picture
//set picture
//pic.src = './index_files/static/spinners/old_spin.gif'; //was been 32x32
//pic.src = './index_files/static/spinners/old_spin_full.gif'; //good for 64x64
//pic.src = './index_files/static/spinners/numbers_generation.gif';
//pic.src = './index_files/static/spinners/hex_generation.gif';
//pic.src = './index_files/static/spinners/color_noise.gif';
//pic.src = './index_files/static/spinners/color_noise_128x128_2x2.gif';
//pic.src = './index_files/static/spinners/white_noise.gif';
//pic.src = './index_files/static/spinners/white_noise_64x64.gif';
//pic.src = './index_files/static/spinners/dice_generation.gif';
//pic.src = './index_files/static/spinners/dice_transparent.gif';
//pic.src = './index_files/static/spinners/dice_transparent2.gif';
//pic.src = './index_files/static/spinners/dise_with_background.gif';
//pic.src = './index_files/static/spinners/square_spin.gif';
//pic.src = './index_files/static/spinners/sqruares_moving_spin.gif';
//pic.src = './index_files/static/spinners/sqruares_moving2_spin.gif';
//pic.src = './index_files/static/spinners/paints_spin.gif';
//pic.src = './index_files/static/spinners/Green_spin.gif';
//pic.src = './index_files/static/spinners/lawa_spin.gif';
//pic.src = './index_files/static/spinners/many_spin.gif';
//pic.src = './index_files/static/spinners/new_spin.gif';
//pic.src = './index_files/static/spinners/orange_spin.gif';
//pic.src = './index_files/static/spinners/cycle_spin.gif';
//pic.src = './index_files/static/spinners/water_spin.gif';
//pic.src = './index_files/static/spinners/spiral_spin.gif';
//pic.src = './index_files/static/spinners/spiral2_spin.gif';
//pic.src = './index_files/static/spinners/3d_spin.gif';
//pic.src = './index_files/static/spinners/ball_spin.gif';
//pic.src = './index_files/static/spinners/Rubic_spin.gif';
//pic.src = './index_files/static/spinners/fractal_mechanics.gif';
//pic.src = './index_files/static/spinners/slow_spin.gif';
//pic.src = './index_files/static/spinners/rainbow_spin.gif';
//pic.src = './index_files/static/spinners/snake_spin.gif';
//pic.src = './index_files/static/spinners/carbon_wheel.gif';
//pic.src = './index_files/static/spinners/finger_spinner_spin.gif';
//pic.src = './index_files/static/spinners/metal_finger_spinner_spin.gif';
//pic.src = './index_files/static/spinners/hypno_spin.gif';
//pic.src = './index_files/static/spinners/sphere_spin.gif';
//pic.src = './index_files/static/spinners/jewel_spin.gif';
//pic.src = './index_files/static/spinners/diamond_spin.gif';
//pic.src = './index_files/static/spinners/bitcoin_spin.gif';
pic.src = './index_files/static/spinners/proteine_spin.gif';
//sha-256 function already exists in bitcoinjs-min.js Crypto
//and can be called as Crypto.SHA256('string_unicode_supporting')
//test unicode string
//console.log(Crypto.SHA256('Unicode: 守护村子')); //31293dcebfcc7f417b6ec6af730e1fbb171f3dfb3e9d0cab4c8c905f8937a0d7 //correct;
//But in this script used SHA256() function, declared in sha256-randomization.js
/*
var string = '---BEGIN MULTISTRING---\
Unicode symbols: 守护村子\
tabulation symbol: t\
multistring slash n: \n\
test CR LF: \r\n\
test br HTML <br>\
test another tags <p>p</p><span>span</span>守护村子\
test tab symbol before\
---END STRING---\
';
//copy this in console to converter https://username1565.github.io/brainwallet.github.io/#converter
//from --- at beginning to --- in thie end
console.log(
'string:\n______________________________________________________\n'+string
//sha may be: 2cbbcfe61b717f721af540f04cadc14c3af38c7c3a3e1d82e7807460f174efa7
//https://username1565.github.io/brainwallet.github.io/#converter
+'\n______________________________________________________\n SHA256(string);', SHA256(string) //THIS CORRECTLY
//SHA256(string); 2cbbcfe61b717f721af540f04cadc14c3af38c7c3a3e1d82e7807460f174efa7
//window.Crypto.SHA256 test:
, '\n Crypto.SHA256(string)', Crypto.SHA256(string) //9544eea06ae7ad3de97516a3013bee8cd7778b32e8155aeb675af1cce0308e7c - incorrect
, '\n window.Crypto.SHA256(string)', window.Crypto.SHA256(string) //The same function - incorrect: 9544eea06ae7ad3de97516a3013bee8cd7778b32e8155aeb675af1cce0308e7c
);
//So just will be SHA256
*/
//function to repeat strings (need for asterisk's string '******...')
function repeatStringNumTimes(string, times) {
var repeatedString = "";
while (times > 0) {
repeatedString += string;
times--;
}
return repeatedString;
}
//run
//console.log(repeatStringNumTimes("*", 3));
//nonce for randomize hashes
//This saving cryptographic strength for simply and easy to remember passphrases
//and make bruteforce so hard.
//Reccommend to change this value, and save this
//to do client-side generation keys and addresses, generated from simple passwords.
var nonce =
'your \
own\
____nonce____\
can \r\n\
be \n\
multistring <br>\
';
//in next function using sha256(passphrase+nonce).
function hash(passphrase) {
if(typeof passphrase==='undefined'){// || $('#pass').hasClass('is_generated')){//check hash
var hash = document.getElementById("hash");
var pass = document.getElementById('Passphrase');
var visibleHash = document.getElementById("visibleHash");
passphrase = pass.value+nonce; //+ nonce
if(SHA256(passphrase)!==visibleHash.innerHTML){
//console.log(Math.random(), Math.random().toString(36).slice(2));
/*
This returning different values in different browsers.
You can test this, using string with fixed number:
console.log((0.12345678987654321).toString(36).slice(2));
*/
//random 75 base36 symbols in one string, using 1 call Math.random()
var len = 75;/*<--String Length ...*/for(var s = "", rem = 100000000, n = Math.random()*10*rem; s.length < len;){rem=10*rem%n; s+= (rem%10!==0)?rem.toString(36).replace(".", "").substr(0, len-s.length):"";}//document.write("<br>", 's.length: ', s.length, 's: ', s);
var randvalue = s;
/*
var randvalue =
//using modified Math.Random()
//See more in the comments of code for included script sha256_randomize_Math.Random.js
Math.random().toString(36).slice(2)+
Math.random().toString(36).slice(2)+
Math.random().toString(36).slice(2) //concatenate 3 random values as base36 strings to one generated string (without first two symbols "0.")
;
*/
/*
console.log(
'randvalue', randvalue
, '\nnonce', nonce
, '\nrandvalue+nonce', randvalue+nonce
, '\nSHA256(randvalue+nonce)', SHA256(randvalue+nonce)
, '\nwindow.Crypto.SHA256(randvalue+nonce)', window.Crypto.SHA256(randvalue+nonce)
, '\nCrypto.SHA256(randvalue+nonce)', Crypto.SHA256(randvalue+nonce)
);
//And now, when I see incorrect hashes, here will be used SHA256() from sha256_randomize_Math.Random.js
*/
var secret_expontent = SHA256(randvalue+nonce);
var hidden_passphrase = repeatStringNumTimes("*", randvalue.length);
var hidden_secret_expontent = repeatStringNumTimes("*", secret_expontent.length);
hash.innerHTML =
'<font id="block" onMouseOver="show_sidebar()" onMouseOut="hide_sidebar()">'+
'Hash: '+
'<font id="visibleHash" style="display: inline color: #2b9118; background-color: #ffffa2">'+secret_expontent+'</font>'+
'<font id="hiddenHash" style="display: none">'+hidden_secret_expontent+'</font>'+
'</font>';
hash.classList.add("is_generated");
pass.classList.add("is_generated");
document.getElementById('Passphrase').value = randvalue;
document.getElementById('Passphrase').type = "text";
document.getElementById("generated_passphrase").innerHTML =
'<font id="block" onMouseOver="show_sidebar()" onMouseOut="hide_sidebar()">'+
"Generated passphrase: <font id='visiblePassphrase' style='display: inline; color: #2b9118; background-color: #ffffa2'>"+randvalue+"</font>"+
"<font id='hiddenPassphrase' style='display: none;'>"+hidden_passphrase+'</font>'+
'</font>';
/*
console.log(
' randvalue:', randvalue
, '\n visiblePassphrase: ', document.getElementById('visiblePassphrase').innerHTML
, '\n visibleHash', document.getElementById('visibleHash').innerHTML
);
*/
}
else{
document.getElementById("generated_passphrase").innerHTML = //=''
'<font id="block2" onMouseOver="show_sidebar()" onMouseOut="hide_sidebar()">'+
'<font id="visiblePassphrase" style="display: inline;" style="display: inline; color: #2b9118; background-color: #ffffa2"></font>'+
'<font id="hiddenPassphrase" style="display: none;"></font>'+
'</font>';
if($('#hash').hasClass('is_generated')){
hash.classList.remove('is_generated');
hash.removeAttribute("class")
}
}
}else{ //or generate hash
if(passphrase===''){ //passphrase is empty
document.getElementById("visibleHash").innerHTML = 'No hash, empty string. Generate paperwallets randomly...';
document.getElementById("hiddenHash").innerHTML = 'No hash, empty string. Generate paperwallets randomly...';
document.getElementById("visiblePassphrase").innerHTML = 'No passphrase specified. Click on the buttons to generate this.';
document.getElementById("hiddenPassphrase").innerHTML = 'No passphrase specified. Click on the buttons to generate this.';
}
else{
passphrase = passphrase+nonce; //add nonce
hash = SHA256(passphrase);
document.getElementById("visibleHash").innerHTML = hash; //display hash and save this as HTML
document.getElementById("hiddenHash").innerHTML = repeatStringNumTimes("*", hash.length); //display hash and save this as HTML
document.getElementById("generated_passphrase").innerHTML = //= '';
'<font id="block2" onMouseOver="show_sidebar()" onMouseOut="hide_sidebar()">'+
'<font id="visiblePassphrase" style="display: inline;"></font>'+
'<font id="hiddenPassphrase" style="display: none;"></font>'+
'</font>';
}
}
}
function show_sidebar(){
document.getElementById('Passphrase').type = "text";
document.getElementById("visiblePassphrase").style.display = "inline";
document.getElementById("hiddenPassphrase").style.display = "none";
document.getElementById("visibleHash").style.display = "inline";
document.getElementById("hiddenHash").style.display = "none";
var privs = document.getElementsByClassName("priv_wif");
for(i=0; i<privs.length; i++){
privs[i].style.display = 'inline-block';
}
var hidden_wifs = document.getElementsByClassName("hidden_wif");
for(i=0; i<hidden_wifs.length; i++){
hidden_wifs[i].style.display = 'none';
}
var WIF_qr_code = document.getElementsByClassName("visible_qr_code");
for(i=0; i<WIF_qr_code.length; i++){
WIF_qr_code[i].style.display = 'inline';
}
var hidden_qr_code = document.getElementsByClassName("hidden_qr_code");
for(i=0; i<hidden_qr_code.length; i++){
hidden_qr_code[i].style.display = 'none';
}
}
function hide_sidebar(){
document.getElementById('Passphrase').type = "password";
document.getElementById("visiblePassphrase").style.display = "none";
document.getElementById("hiddenPassphrase").style.display = "inline";
document.getElementById("visibleHash").style.display = "none";
document.getElementById("hiddenHash").style.display = "inline";
var privs = document.getElementsByClassName("priv_wif");
for(i=0; i<privs.length; i++){
privs[i].style.display = 'none';
}
var hidden_wifs = document.getElementsByClassName("hidden_wif");
for(i=0; i<hidden_wifs.length; i++){
hidden_wifs[i].style.display = 'inline-block';
}
var WIF_qr_code = document.getElementsByClassName("visible_qr_code");
for(i=0; i<WIF_qr_code.length; i++){
WIF_qr_code[i].style.display = 'none';
}
var hidden_qr_code = document.getElementsByClassName("hidden_qr_code");
for(i=0; i<hidden_qr_code.length; i++){
hidden_qr_code[i].style.display = 'inline';
}
}
</script>
<section id="generator">
<h2>Paper Wallet Generator</h2>
Select which currencies you want included in your paper wallet:<br><br>
<table id="checkbox_table" style="border: 1; text-align: left; margin: 0 auto 0 auto;">
</table>
<br><br>
<font id="block0" onMouseOver="show_sidebar()" onMouseOut="hide_sidebar()">
Passphrase:
<input type="text" id="Passphrase" size="100" placeholder="Type passphrase to get static value, or leave this field empty to generate hash."
title="Type passphrase to get brain-wallets as paperwallet (sha256 hash using as priv),
or leave this field empty to generate this data randomly."
value="123" oninput="hash(this.value);"/>
</font>
<button onclick="
document.getElementById('Passphrase').value =
document.getElementById('visibleHash').innerHTML =
document.getElementById('hiddenHash').innerHTML =
document.getElementById('visiblePassphrase').innerHTML =
document.getElementById('hiddenPassphrase').innerHTML =
'';
"
title="Just clear this field.">Clear</button>
<br>
<br>
<b>
<div id="generated_passphrase" title="Generated passphrase.
Double-click to highlight text and copy values.">
<font id="block" onMouseOver="show_sidebar()" onMouseOut="hide_sidebar()">
<font id="visiblePassphrase" style="display: inline;"></font>
<font id="hiddenPassphrase" style="display: none;"></font>
</font>
</div>
<div id="hash" title="SHA256 hash(passphrase + nonce).
This is your private key hex (secret exponent).
This value will be converted to different WIF private keys for different coins.">
<font id="block" onMouseOver="show_sidebar()" onMouseOut="hide_sidebar()">
Hash:
<font id="visibleHash" style="display: inline; color: #2b9118; background-color: #ffffa2"></font>
<font id="hiddenHash" style="display: none;">No hash, empty string. Generate paperwallets randomly...</font>
</font><!--END FONT id="block"-->
</div>
</b>
<button id="generate" title="Generate wallets, using hash from pass, as private key.
Move your mouse to automatically change salt for Math.random()">Generate!</button>
<button id="regenerate" onclick="document.getElementById('Passphrase').value = ''; document.getElementById('generate').click()"
title="To generate random pass and hash, field 'pass' must be empty...
Click to clear this field and regenerate pass and hash and regenerate wallets, then.">Regenerate!</button>
</section>
<div id="wallets" style="">
</div>
<script src="./index_files/altcore-lib.min.js"></script>
<script>
hash(document.getElementById('Passphrase').value); //calculate hash from passprase, if this was been specified as default...
var bitcore = require('bitcore-lib');
function toggle(source, start, end) {
var checkboxes = document.querySelectorAll('input[type="checkbox"]');
for (var i = start; i <= end; i++) {
if (checkboxes[i] != source){
checkboxes[i].checked = source.checked;
}
}
}
var checkbox_table = document.getElementById("checkbox_table");
var coin_parameters;
checkbox_table.innerHTML += '<tr><th for="select_all"><input type="checkbox" id="select_all" onclick="toggle(this, 0, '+(crypto_data.length+Math.floor((crypto_data.length/10))+(crypto_data.length%10>0))+');" title="All?"/><label for="select_all" title="All?">Select?</label></th><th colspan="10" style="text-align: center;">Select coins...</th><tr>'
var input_num = 0;
var row, end_row;
for(i=0; i<crypto_data.length; i++){
if(i%10==0){
if((input_num+1)>Math.floor(crypto_data.length/10)){
end_row = i+1+input_num+(crypto_data.length%10);
}
else{
end_row = i+11+input_num;
}
var row_N = (input_num+1); //row number = ((i/10)+1)
var tr_id = 'row'+row_N;
var input_id = 'select_row'+row_N;
checkbox_table.innerHTML += '\
</tr><tr class="checkbox" id="'+tr_id+'">\
<td>\
<input type="checkbox" id="'+input_id+'"'+
'onclick="toggle(this, '+(i+1+input_num)+', '+end_row+');"'+
'title="Select row '+row_N+'" />'+
'<label for="'+'select_row'+row_N+'" title="Select row '+row_N+'" />'+
row_N+' '+
'</label>'+
'</td>';
input_num++;
}
row = document.getElementById('row'+input_num);
coin_parameters = crypto_data[i];
row.innerHTML += '<td><input type="checkbox" name="coin" id="'+i+'" value="'+coin_parameters.code+'" title="Select '+coin_parameters.name+'" /><label for="'+i+'" title="Select '+coin_parameters.name+'" />'+coin_parameters.name+'</label></td>';
if (coin_parameters.my===true){
document.getElementById(i).setAttribute('checked', true);
}
}
for(li=0; li<(10-(crypto_data.length%10))%10; li++){
row.innerHTML += '<td></td>';
}
checkbox_table.innerHTML += '</tr>';
$.each(crypto_data, function(i, data) {
var network = {};
network.alias = data['code'];
network.name = data['name'];
network.pubkeyhash = data['address_byte'];
network.privatekey = data['private_key_prefix'];
if(data['code'] != 'btc') {
bitcore.Networks.add(network);
}
});
function get_coin_data(coin) {
ret = undefined;
$.each(crypto_data, function(i, data){
if(data['code'] == coin) {
ret = data
return false;
}
});
return ret
}
//get compressed or uncompressed public key from Elliptic Curve point
function getEncoded(pt, compressed) {
var x = pt.getX().toBigInteger();
var y = pt.getY().toBigInteger();
var enc = integerToBytes(x, 32);
if (compressed) {
if (y.isEven()) {
enc.unshift(0x02);
} else {
enc.unshift(0x03);
}
} else {
enc.unshift(0x04);
enc = enc.concat(integerToBytes(y, 32));
}
return enc;
}
function isBase58(str) {
return !/[^123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+/.test(str);
}
//get bytes from WIF, with checking base58 encoding.
function parseBase58Check(address) {
if(!isBase58(address)){return 'String not have base58 encoding.'}
var bytes = Bitcoin.Base58.decode(address);
var end = bytes.length - 4;
var hash = bytes.slice(0, end);
var checksum = Crypto.SHA256(Crypto.SHA256(hash, {asBytes: true}), {asBytes: true}); //Here used Crypto.SHA256, not SHA256('string'). Values, as bytes
//console.log(hash); //bytes you can see here
if (checksum[0] != bytes[end] ||
checksum[1] != bytes[end+1] ||
checksum[2] != bytes[end+2] ||
checksum[3] != bytes[end+3]){
return "Wrong Base58Check checksum.";
}
var version = hash.shift();
return [version, hash];
}
//function to search coins in array, by address or private key.
function search_coin(){
var coin_address = document.getElementById('address_lookup').value;
var result_div = document.getElementById('address_info');
result_div.innerHTML = '';
var res = parseBase58Check(coin_address);
if(res==='Wrong Base58Check checksum.' || res==='String not have base58 encoding.'){
result_div.innerHTML = res+' This is not correct address or private key. '
}
var prefix_byte = res[0];
var priv, addr;
var founded_coins = [];
//var prefix_byte = Crypto.util.bytesToHex([res[0]]);
var bytes = res[1];
if(bytes.length>=32){//this is private key
priv = true;
result_div.innerHTML += 'Private key. ';
if(bytes.length===33 && bytes[32]===1){
result_div.innerHTML += 'Compressed. ';
}
else if(bytes.length===32 && bytes[32]!==1){
result_div.innerHTML += 'Uncompressed. ';
}else{
result_div.innerHTML += "Unknown length and cann't understand is compressed or uncompressed. ";
}
for(i=0; i<crypto_data.length; i++){
if(crypto_data[i].private_key_prefix===prefix_byte){founded_coins.push('['+i+'] '+crypto_data[i].name);}
}
}
if(bytes.length===20){
addr = true;
result_div.innerHTML += 'Address. ';
for(j=0; j<crypto_data.length; j++){
if(crypto_data[j]["address_byte"]===prefix_byte){founded_coins.push('['+j+'] '+crypto_data[j].name);}
}
}
result_div.innerHTML += 'Prefix_byte: <b title="decimal value">'+prefix_byte+'</b> '+
'(<b title="hexadecimal value">0x'+Crypto.util.bytesToHex([prefix_byte])+'</b>)'+
'<br> Founded coins with '+((addr) ? 'address_byte' : (priv) ? 'private_key_prefix' : 'undefined_byte')+
' equals to this prefix_byte <b title="decimal value as specified in array">('+prefix_byte+')</b>: '+
'<div style="display: inline; background-color: #ffffa2" title="(array) crypto_data { [index] coin_name, [index2] coin_name2, etc... }">{'+founded_coins.join(', ')+'}.';
/*
console.log(
'res', res
, 'prefix_byte', prefix_byte
, 'bytes', bytes
, 'bytes.length', bytes.length
);
*/
//addresses and priv for test
//Vertcoin:
//address: VnLEnG7VV94wiwtbHCeYDP2V4AfMRX2tqd
//priv: L3F5GxwCz5GhsaXWkorwad5arVowFyb6fubgYowXvbtept51hc7w
//1337 coin
//address: LZ2Putsy2Hhfhu5vaSXx7NJHxBgBzX9at1
//priv: 6u8SyyYBC5AfQCbZ5BhLr6pJmnQgdwGbKpwrHC8voUzVyzFTgr6
}
//generate brainwallet with specified hash
function generate_priv_addr(hash, compressed, PUBLIC_KEY_VERSION, PRIVATE_KEY_VERSION){
//console.log(hash);
//gen priv and addr
if(hash===null){
//random 75 base36 symbols in one string, using 1 call Math.random()
var len = 75;/*<--String Length ...*/for(var s = "", rem = 100000000, n = Math.random()*10*rem; s.length < len;){rem=10*rem%n; s+= (rem%10!==0)?rem.toString(36).replace(".", "").substr(0, len-s.length):"";}//document.write("<br>", 's.length: ', s.length, 's: ', s);
var randvalue = s;
/*
var randvalue = Math.random().toString(36).slice(2)+ //base36 encoded values without '0.'
Math.random().toString(36).slice(2)+ //concatenate as string.
Math.random().toString(36).slice(2); //3 times
*/
hash = SHA256(
randvalue
);
//console.log('randvalue', randvalue, 'hash = ', hash);
document.getElementById("visibleHash").innerHTML = hash;
}
var payload = Crypto.util.hexToBytes(hash);
if (compressed){
payload.push(0x01);
}
var sec = new Bitcoin.Address(payload);
sec.version = PRIVATE_KEY_VERSION; //altcoin private key prefix
//console.log('sec.toString()', sec.toString());
var hex_priv = parseBase58Check(sec.toString());
//console.log('hex_priv', hex_priv);
//console.log('hash from priv WIF: ', hex_priv, 'version', hex_priv[0], 'priv_bytes', hex_priv[1]);
//var hex_bytes = Crypto.util.hexToBytes(hash); //hash as byte code integers array hex -> to bytes
//var hash = Crypto.util.bytesToHex(payload);
var hash_from_priv_WIF = Crypto.util.bytesToHex(hex_priv[1]);
//console.log('\n\n 01 byte in the end for if key is compressed. \n hash from priv WIF: ', hash_from_priv_WIF);
//if(compressed){
// hex_bytes.push(0x01)
//}
var hash_priv_bytes = Crypto.util.hexToBytes(hash); //hash as bytes
var eckey = new Bitcoin.ECKey(hash_priv_bytes); //eckey //hash is hex string
/*
console.log(
//'hex_bytes', hex_bytes,
'\n hash', hash_priv_bytes,
'\n eckey', eckey
);
*/
try {
var curve = getSECCurveByName("secp256k1");
gen_pt = curve.getG().multiply(eckey.priv);
//console.log('gen_pt', gen_pt);
//eckey.pub = getEncoded(gen_pt); //uncompressed
eckey.pub = getEncoded(gen_pt, compressed); //compressed if compressed true
//console.log('eckey.pub', eckey.pub);
eckey.pubKeyHash = Bitcoin.Util.sha256ripe160(eckey.pub);
addr = new Bitcoin.Address(eckey.getPubKeyHash());
addr.version = PUBLIC_KEY_VERSION;
//console.log('eckey.pub', Crypto.util.bytesToHex(eckey.pub), 'addr.toString()', addr.toString());
} catch (err) {
console.info(err, 'Invalid secret exponent (must be non-zero value);');
return;
}
var hash160 = eckey.getPubKeyHash();
var h160 = Crypto.util.bytesToHex(hash160); //as hex
var addr = new Bitcoin.Address(hash160);
addr.version = PUBLIC_KEY_VERSION;
/*
//test display values
console.log(
'hash160', hash160,
'\n hash160 hex ', Crypto.util.bytesToHex(hash160),
'\n h160', h160,
'\n addr', addr,
'\n addr.toString()', addr.toString()
);
*/
//console.log('addr.toString()', addr.toString());
return [sec.toString(), addr.toString()];
}
function getpriv_addr(hash, coin){
//check is compressed?
var coin_id;
for(i=0; i<crypto_data.length; i++){
if(crypto_data[i]["code"]===coin){coin_id = i;} //search coin code and copy index
}
var compressed = crypto_data[coin_id]["compressed"]; //get compressed parameter, true or false
var PUBLIC_KEY_VERSION = crypto_data[coin_id]["address_byte"]; //get public key byte
var PRIVATE_KEY_VERSION = crypto_data[coin_id]["private_key_prefix"]; //get private key byte
//return generate_priv_addr(hash, compressed, PUBLIC_KEY_VERSION, PRIVATE_KEY_VERSION);
var priv_addr = []; //define empty array
if(coin.toLowerCase() === 'eth' || crypto_data[coin_id]["name"] === "Ethereum"){ //if Ethereum, using web3-eth-accounts.js
var account = new Web3EthAccounts();
var priv0x = '0x0000000000000000000000000000000000000000000000000000000000000000';
var priv_keys_i_length = hash.length;
var start_position = 2+64-priv_keys_i_length;
var nulled_0x_priv = '';
nulled_0x_priv = priv0x.substring(0, start_position)+hash;
var keyPair = account.privateKeyToAccount(nulled_0x_priv);
var pubKey = JSON.parse(JSON.stringify(keyPair.address)); //pub
var privKey = JSON.parse(JSON.stringify(keyPair.privateKey)); //priv
priv_addr.push(privKey, pubKey); //push to response
}
else{
priv_addr = generate_priv_addr(hash, compressed, PUBLIC_KEY_VERSION, PRIVATE_KEY_VERSION);
}
//console.log(priv_addr);
//console.log(coin);
return priv_addr;
}
//This function need to generate qr-code as gif-image and append img tag to inside a-element.
function generate_qr_code(aElement, text, width, height){
var qrCode = qrcode_gen(8, 'H'); //generate big qr-code with High value of error correction capability
var text2; //define temp variable
text2 = text.replace(/^[\s\u3000]+|[\s\u3000]+$/g, ''); //replace this characters.
if(text2!==text){ //compare text
console.log('(replaced text) '+text2+' !== '+text+' (input text)'); //show notification if not equal
}
qrCode.addData(text); //generate qr-code from text
qrCode.make(); //make this
var link = aElement; //using specified aElement
link.innerHTML = qrCode.createImgTag(6); //append HTML
//get value of "src"-attribute for child tag "img" of "link" element and copy to "href"
var img = link.getElementsByTagName('img')[0]; //get image element
img.width = width; //change width to specified
img.height = height; //change heigth to specified
link.href = img.src; //add full size base64 qr-code from src to href of aElement
}
//end function to generate gif qr-code.
$("#generate").click(function() {
if(document.getElementById('Passphrase').value===''){ //if passphrase field empty
hash(); //regenerate pass and hash
}
else{//if passphrase field filled
hash(document.getElementById('Passphrase').value); //check is hash in this field + nonce, corresponding sha256 from (passphrase+nonce) or not;
}//then generate wallets
$("#wallets").empty();
var selected = [];
$("input[name=coin]:checked").each(function(){
var coin = $(this).val();
selected.push(coin)
});
$.each(selected, function(i, coin) {
if(coin == 'btc') {
//coin = 'livenet'
}
//old generate
//var priv = bitcore.PrivateKey(null, coin)
//var passphrase = 'my passphrase';
//sha256 function added before
//var hash = SHA256(passphrase);
var HTML_hash = document.getElementById("visibleHash").innerHTML;
//console.log('HTML_hash', HTML_hash);
if(HTML_hash==='No hash, empty string. Generate paperwallets randomly...'){ //if default value - passphrase is empty
//var priv = bitcore.PrivateKey(null, coin); //generate private key
var paperwallet = getpriv_addr(null, coin);
}
else{//else, passphrase was been specified. Use hash as private key.
//null was been replaced to HTML_hash. This may be hex string.
//to using your own nonce see "function hash(passphrase)"
//var priv = bitcore.PrivateKey(HTML_hash, coin);
var paperwallet = getpriv_addr(HTML_hash, coin);
}
//var wif = priv.toWIF();
//var address = priv.toAddress(coin).toString();
var wif = paperwallet[0]; //private key WIF
var address = paperwallet[1]; //Address
//before using - check this by commands "importprivkey PRIVATE_KEY" and "dumpprivkey ADDRESS"
//in console of your qt.exe program or another client
//check and compare prefixes of this values there,
//BECAUSE YOU CAN LOST YOUR COINS IF THIS DATA WILL BE INCORRECT.
if(coin == 'livenet') {
//coin = 'btc'
}
var data = get_coin_data(coin);
coin = coin.toUpperCase();
var wallet = render_template({
name: data['name'],
logo: data['logo'],
wif: wif,
address: address,
code: coin
});
$('#wallets').append(wallet);
/*
//qr-code as gif file in img tag
var aElement_pub = $("#" + coin + " .pub.qr.link");
aElement_pub.attr("id", coin+'_pub_qr'); //add ID for aElement_pub
aElement_pub.attr("download", coin+'_pub_qr_code'+'.gif'); //set filename
generate_qr_code(document.getElementById(coin+'_pub_qr'), address, 128, 128); //getElementById, text, witdth, heigth
var aElement_priv = $("#" + coin + " .priv.qr.link");
aElement_priv.attr("id", coin+'_priv_qr'); //add ID for aElement_priv
aElement_priv.attr("download", coin+'_priv_qr_code'+'.gif');
generate_qr_code(document.getElementById(coin+'_priv_qr'), wif, 128, 128); //getElementById, text, witdth, heigth
*/
//qrcode as PNG-picture, which is good readable by qr-code scanners
//This downloaded from canvas, so canvas is displaing full size.
$("#" + coin + " .pub.qr.link").qrcode(
{
render: 'canvas',
width: 256,
height: 256,
text: address,
id: coin+'_pub_qr_code'
}
);
$("#" + coin + " .pub.qr.link").attr("href", document.getElementById(coin+'_pub_qr_code').toDataURL("image/png"));
$("#" + coin + " .pub.qr.link").attr("download", coin+'_pub_qr_code'+'.png');
$("#" + coin+'_pub_qr_code').addClass("zoom");
$("#" + coin + " .priv.qr.link").qrcode(
{
render: 'canvas',
width: 256,
height: 256,
text: wif,
id: coin+'_priv_qr_code'
}
);
$("#" + coin + " .priv.qr.link").attr("href", document.getElementById(coin+'_priv_qr_code').toDataURL("image/png"));
$("#" + coin + " .priv.qr.link").attr("download", coin+'_priv_qr_code'+'.png');
$("#" + coin+'_priv_qr_code').addClass("zoom");
//$("#" + coin+'_priv_qr_code').attr('width', 112);
//$("#" + coin+'_priv_qr_code').attr('height', 112);
//canvas cann't be resized, after drawing.
});
$("#wallets").show();
hide_sidebar();
});
function render_template(context) {
var contents = $("#paper_wallet_template").html();
contents = contents.replace(/{{ name }}/g, context.name);
contents = contents.replace(/{{ logo }}/g, context.logo);
contents = contents.replace(/{{ address }}/g, context.address);
contents = contents.replace(/{{ wif }}/g, context.wif);
contents = contents.replace(/{{ code }}/g, context.code);
return contents
}
</script>
<script type="text/template" id="paper_wallet_template">
<table class="wide" id="{{ code }}">
<tr class="no_border">
<td class="no_border">
<div title="Address QR-code.">
<a class="pub qr link" href="#" download="coin_pub.png">
</a>
</div>
</td>
<td class="no_border">
<div class="title">
{{ code }} - {{ name }}<br>
<img src="./index_files/static/{{ logo }}" style="width: 50px; height: 50px" title="To make icons 100x100 you can using photo resizer, like this: http://picasion.com/create-avatar/">
</div>
<div class="pub words">← Address (receive): {{ address }} </div>
<div class="priv words">Private Key (spend):
<div class="priv_wif" style="display:inline-block;" onclick="hide_sidebar();">
{{ wif }}
</div>
<div class="hidden_wif" style="display:none;" onclick="show_sidebar();">
***HIDDEN*********************HIDDEN*********************HIDDEN***
</div>
→
</div>
</td>
<td class="no_border">
<div class="hidden_qr_code" style="display:none; width:112px; height:112px" onclick="hide_sidebar();">
<img src="./index_files/static/hidden_qr_512x512.png" class="zoom" title="QR-code is hidden. Click on priv to show.">
</div>
<div class="visible_qr_code" style="display:inline-block; width:112px; height:112px" title="Private key QR-code." onclick="show_sidebar();">
<a class="priv qr link" href="#" download="coin_priv.png">
</a>
</div>
</td>
</tr>
</table>
</script>
<section id="footer">
</section>
</body>
<hr>
<div align="center">To sign messages and verify signatures, you can using <a href="https://username1565.github.io/brainwallet.github.io/#sign">this client-side script</a> (just select in dropdown menu or set there - your coin).</div>
</html>