/
createiota.html
871 lines (743 loc) · 44.4 KB
/
createiota.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Capture Coins is a skill-based challenge where you answer questions to find a wallet's seed.">
<meta name="author" content="Capture Coins">
<title>Capture the Coins - Create Challenge</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom fonts for this template -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
<!-- Custom styles for this template -->
<link href="css/landing-page.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/portfolio-item.css" rel="stylesheet">
<link href="css/modern-business.css" rel="stylesheet">
<link href="css/2-col-portfolio.css" rel="stylesheet">
<link rel="icon" href="./img/favicon.ico" />
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-119562302-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-119562302-1');
</script>
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<a class="navbar-brand" href="./index.html">Capture Coins</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
Solve the Challenge. Capture the Coins.
</li>
</ul>
</div>
</nav>
<!-- Header -->
<header class="intro-header">
<div class="container">
<div class="intro-message">
<br><br>
<h2 style="padding-bottom:10px;" class="createStart">The 3 steps to create a challenge:</h2>
<h2 style="padding-bottom:10px;display:none" class="step1">Step 1: Create an 81 Character Seed Made of Words</h2>
<h2 style="padding-bottom:10px;display:none" class="step2a">Step 2a: Login to the Official IOTA Wallet Using Your Seed and Generate a Public Receiving Address</h2>
<h2 style="padding-bottom:10px;display:none" class="step2b">Step 2b: Send 1-2 Iotas to Public Receiving Address</h2>
<h2 style="padding-bottom:10px;display:none" class="step3">Step 3: Create All the Questions and Then Upload to Tangle</h2>
<h3 style="padding-bottom:10px;" class="createStart"><code>1) Create a wallet's seed made up of words.</code></h3>
<h3 style="padding-bottom:10px;" class="createStart"><code>2) Send 1-2 iotas to an address in the wallet from #1.</code></h3>
<h3 style="padding-bottom:10px;" class="createStart"><code>3) Upload the questions to solve the seed into the Tangle.</code></h3>
<h3 style="padding-bottom:10px;display:none" class="step1"><code>Your words should contain only the letters A-Z and the number 9.</code></h3>
<h3 style="padding-bottom:10px;display:none" class="step1"><code>You should create this seed outside of Capture Coins.</code></h3>
<h3 style="padding-bottom:10px;display:none" class="step1"><code>Keep the seed private and do not share it with anyone (not even Capture Coins)!</code></h3>
<h3 style="padding-bottom:10px;display:none" class="step2a">Enter the public IOTA address below (NOT THE SEED):</h3>
<h3 class="page-header sendQuestions" style="display:none">
<img id="loading" src="./img/loading.gif" alt="loading" height="40" width="40"> <div id="loadingText" style="display:inline">Please Wait. Connecting to the Tangle.</div>
</h3>
<div class="col-lg-12 step2a" style="display:none">
<form class="form-horizontal">
<fieldset>
<div class="form-group">
<div class="col-xs-10">
<input type="text" class="form-control" style="width:80%;margin: 0 auto;" id="addressCoin" placeholder="IOTA Address">
</div>
</div>
</fieldset>
</form>
</div>
<div class="col-lg-12 step3" style="display:none">
<input type="hidden" id="taskCount" value="0">
<h6>Enter each question separately. Questions should end with a "?" (question mark). 2100 characters max.</h6>
<div class="form-group row" id="qGroup1">
<div class="col-lg-12">
<input class="form-control" id="question1" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #1 for Word #1 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup2" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question2" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #2 for Word #2 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup3" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question3" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #3 for Word #3 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup4" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question4" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #4 for Word #4 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup5" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question5" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #5 for Word #5 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup6" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question6" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #6 for Word #6 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup7" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question7" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #7 for Word #7 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup8" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question8" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #8 for Word #8 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup9" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question9" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #9 for Word #9 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup10" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question10" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #10 for Word #10 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup11" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question11" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #11 for Word #11 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup12" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question12" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #12 for Word #12 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup13" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question13" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #13 for Word #13 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup14" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question14" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #14 for Word #14 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup15" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question15" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #15 for Word #15 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup16" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question16" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #16 for Word #16 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup17" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question17" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #17 for Word #17 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup18" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question18" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #18 for Word #18 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup19" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question19" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #19 for Word #19 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup20" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question20" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #20 for Word #20 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup21" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question21" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #21 for Word #21 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup22" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question22" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #22 for Word #22 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup23" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question23" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #23 for Word #23 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup24" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question24" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #24 for Word #24 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup25" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question25" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #25 for Word #25 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup26" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question26" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #26 for Word #26 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup27" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question27" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #27 for Word #27 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup28" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question28" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #28 for Word #28 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup29" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question29" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #29 for Word #29 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup30" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question30" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #30 for Word #30 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup31" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question31" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #31 for Word #31 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup32" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question32" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #32 for Word #32 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup33" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question33" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #33 for Word #33 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup34" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question34" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #34 for Word #34 in Your Seed">
</div>
</div>
<div class="form-group row" id="qGroup35" style="display:none">
<div class="col-lg-12">
<input class="form-control" id="question35" style="width:80%;margin: 0 auto;" type="text" placeholder="Question #35 for Word #35 in Your Seed">
</div>
</div>
<div class="form-group text-center">
<button type="submit" class="btn btn-primary" id="addButton">Add Another Question</button>
<button type="submit" class="btn btn-primary" id="removeButton">Remove Last Question</button>
</div>
</div>
<h3 style="padding-bottom:10px;display:none" class="step2b"><code>Logout of the wallet that uses your Capture Coin seed.</code></h3>
<h3 style="padding-bottom:10px;display:none" class="step2b"><code>Login to a wallet you control that has at least 1 iota.</code></h3>
<h3 style="padding-bottom:10px;display:none" class="step2b"><code>Send 1 or 2 iotas to the public address you just created.</code></h3>
<h3 style="padding-bottom:10px;display:none" class="step2b"><code>Make sure the transaction confirms. Promote if necessary.</code></h3>
<ul class="list-inline intro-social-buttons">
<div id="start">
<button type="submit" class="btn btn-primary" id="startButton" style="border-style:solid;border-color: #ffffff;"><h3 style="margin-top:5px;">Let's Create a Challenge. I'm Ready.</h3></button>
<button type="submit" class="btn btn-primary" id="step1Button" style="border-style:solid;border-color: #ffffff;display:none"><h3 style="margin-top:5px;">I've Got My Seed. Let's Go to Step 2</h3></button>
<button type="submit" class="btn btn-primary" id="step2aButton" style="border-style:solid;border-color: #ffffff;display:none"><h3 style="margin-top:5px;">Let's Move on to Send 1-2 Iotas to this Address.</h3></button>
<button type="submit" class="btn btn-primary" id="step2bButton" style="border-style:solid;border-color: #ffffff;display:none"><h3 style="margin-top:5px;">Transaction Confirmed. Let's Upload the Questions.</h3></button>
<button type="submit" class="btn btn-primary" id="step3Button" style="border-style:solid;border-color: #ffffff;display:none"><h3 style="margin-top:5px;">I'm Finished. Send All Questions to Tangle.</h3></button>
</div>
</ul>
</div>
</div>
</header>
<!-- Internet Explorer and Mobile Check-->
<script type="text/javascript">
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
// redirect to no curl
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
console.log("curl not supported in ie");
let url = "./nocurl.html";
window.location.href = url;
}
</script>
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/popper/popper.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/xss.js"></script>
<script type="text/javascript" src="js/iota.curl.min.js"></script>
<script type="text/javascript" src="js/curl.min.js"></script>
<!-- Page-Level Demo Scripts -->
<script>
$(document).ready(function() {
// check that curl library is supported with webgl2
try {
curl;
} catch(err){
console.log("curl not supported",err);
let url = "./nocurl.html";
window.location.href = url;
return false;
}
// set the initial question display
let questionDisplay = 1;
// handle the start button
$("#startButton").on( "click", function() {
// hide the start, show step1
$("#startButton").fadeOut("slow");
$(".createStart").fadeOut("slow");
$(".step1").fadeIn("slow");
$("#step1Button").fadeIn("slow");
return false;
});
// handle the step1 button
$("#step1Button").on( "click", function() {
// hide step1, show step2
$("#step1Button").fadeOut("slow");
$(".step1").fadeOut("slow");
$(".step2a").fadeIn("slow");
$("#step2aButton").fadeIn("slow");
return false;
});
// handle the step2a button
$("#step2aButton").on( "click", function() {
// set the inputs
let addressCoin = $("#addressCoin").val();
// check coin address exists
if (!addressCoin) {
alert("Coin address is invalid. Please enter a value.");
return false;
}
// validate the address length
if ((addressCoin.length === 90) || (addressCoin.length === 81)) {
// do nothing
} else {
alert("Coin address is invalid. Addresses should be 90 characters.");
return false;
}
// validate the address content
for (var j = 0; j < addressCoin.length; j++) {
if (("9ABCDEFGHIJKLMNOPQRSTUVWXYZ").indexOf(addressCoin.charAt(j)) < 0) {
alert("Coin address should contain only letters A-Z or the number 9. Address is invalid.");
return false;
}
}
// hide step2a, show step2b
$("#step2aButton").fadeOut("slow");
$(".step2a").fadeOut("slow");
$(".step2b").fadeIn("slow");
$("#step2bButton").fadeIn("slow");
return false;
});
// handle the step2b button
$("#step2bButton").on( "click", function() {
// hide step2b, show step3
$("#step2bButton").fadeOut("slow");
$(".step2b").fadeOut("slow");
$(".step3").fadeIn("slow");
$("#step3Button").fadeIn("slow");
return false;
});
// handle the add question button
$("#addButton").on( "click", function() {
// increment the questionDisplay
questionDisplay++;
// validate the question display is between 1 and 30 (max)
if (questionDisplay < 1) {
questionDisplay = 1;
alert("You need to have at least 1 question");
$("#qGroup1").show();
return false;
}
// validate the question display is between 1 and 35 (max)
if (questionDisplay > 35) {
questionDisplay = 35;
alert("Sorry. Max of 35 questions.");
return false;
}
// show the next question input
$("#qGroup" + questionDisplay).show();
return false;
});
// handle the remove question button
$("#removeButton").on( "click", function() {
// decrement the questionDisplay
questionDisplay--;
// validate the question display is between 1 and 30 (max)
if (questionDisplay < 1) {
questionDisplay = 1;
alert("You need to have at least 1 question");
$("#qGroup1").show();
return false;
}
// validate the question display is between 1 and 35 (max)
if (questionDisplay > 35) {
questionDisplay = 35;
alert("Sorry. Max of 35 questions.");
return false;
}
// hide the last question input, clear the val
let lastQuestionNo = questionDisplay + 1;
$("#qGroup" + lastQuestionNo).hide();
$("#question" + lastQuestionNo).val("");
return false;
});
// handle the step3 button
$("#step3Button").on( "click", function() {
// set the inputs
let addressCoin = $("#addressCoin").val();
let questions = "";
let tempQuestion = "";
// loop through questions
let t = 0;
let tNext = 1;
while (t < questionDisplay) {
tempQuestion = $("#question" + tNext).val();
// check question exists
if (!tempQuestion) {
alert("Question #" + tNext + " does not have valid text. Please correct and try again.");
return false;
}
// check question has positive length
if (tempQuestion.length < 2) {
alert("Question #" + tNext + " does not have valid length. Please add some text and try again.");
return false;
}
// check only 1 question mark in the text
if ((tempQuestion.match(/\?/g) || []).length > 1) {
alert("Question #" + tNext + " has more than 1 question mark. Please correct and try again.");
return false;
}
// check 1 question mark at the end only
if (tempQuestion.slice(-1) !== "?") {
alert("Question #" + tNext + " needs question mark at the end. Please correct and try again.");
return false;
}
// sanitize
tempQuestion = filterXSS(tempQuestion);
// append to question string
questions = questions + tempQuestion;
t++;
tNext++;
}
// sanitize inputs
addressCoin = filterXSS(addressCoin);
questions = filterXSS(questions);
// check questions exist
if (!questions) {
alert("There are no questions. Please enter at least 1 question.");
return false;
}
// validate the question length
if (questions.length > 2100) {
alert("Your questions are too long. They should be less than 2100 characters in total.");
return false;
}
// check coin address exists
if (!addressCoin) {
alert("Coin address is invalid. Please enter a value.");
return false;
}
// validate the address length
if (addressCoin.length !== 90) {
alert("Coin address is invalid. Addresses should be 90 characters.");
return false;
}
// validate the address content
for (var j = 0; j < addressCoin.length; j++) {
if (("9ABCDEFGHIJKLMNOPQRSTUVWXYZ").indexOf(addressCoin.charAt(j)) < 0) {
alert("Coin address should contain only letters A-Z or the number 9. Address is invalid.");
return false;
}
}
// show proof work spinners, send to tangle
$(".sendQuestions").fadeIn("slow");
sendToTangle(addressCoin,questions);
return false;
});
function sendToTangle(addressCoin,questions) {
// create a list of https nodes
let hostHttps = ['https://nodes.iota.cafe', 'https://node.tangle.works:443', 'https://iota.thathost.net:443'];
let portHttps = [443, 443, 443];
// initialize host and port
let host = hostHttps[0];
let port = portHttps[0];
// pull a random https node to rotate usage (if nodes.iota gets overloaded)
if (Math.random() > 1) {
host = hostHttps[1];
port = port[1];
}
// initialize curl library values
curl.init();
const MAX_TIMESTAMP_VALUE = (Math.pow(3,27) - 1) / 2;
// instantiate IOTA object
var iota = new IOTA({
'host': host,
'port': port
});
// initialize transfer data
let seed = generateSeed();
let address = iota.utils.addChecksum(generateSeed());
let value = 0;
let message = questions + "???";
let tag = "";
let depth = 10;
let weight = 14;
// WARNING: Not cryptographically secure. Do not use any seeds generated by this generator to actually store any value.
function generateSeed() {
const validChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ9';
return Array.from(new Array(81), (x, i) => validChars[Math.floor(Math.random() * validChars.length)]).join('');
}
// returns a depth in [4, 12] inclusive
function generateDepth() {
depth = Math.floor(Math.random() * (12 - 4 + 1)) + 4;
return depth;
}
// adapted from https://github.com/iotaledger/wallet/blob/master/ui/js/iota.lightwallet.js
const localAttachToTangle = function(trunkTransaction, branchTransaction, minWeightMagnitude, trytes, callback) {
$('.step3').fadeOut("slow");
$('#step3Button').fadeOut("slow");
$('#loadingText').text("Attaching Answer to Tangle");
const ccurlHashing = function(trunkTransaction, branchTransaction, minWeightMagnitude, trytes, callback) {
const iotaObj = iota;
$('#loadingText').text("Now Starting Curl Hashing");
// inputValidator: Check if correct hash
if (!iotaObj.valid.isHash(trunkTransaction)) {
return callback(new Error("Invalid trunkTransaction"));
}
// inputValidator: Check if correct hash
if (!iotaObj.valid.isHash(branchTransaction)) {
return callback(new Error("Invalid branchTransaction"));
}
// inputValidator: Check if int
if (!iotaObj.valid.isValue(minWeightMagnitude)) {
return callback(new Error("Invalid minWeightMagnitude"));
}
let finalBundleTrytes = [];
let previousTxHash;
let i = 0;
function loopTrytes() {
getBundleTrytes(trytes[i], function(error) {
if (error) {
return callback(error);
} else {
i++;
if (i < trytes.length) {
loopTrytes();
} else {
// reverse the order so that it's ascending from currentIndex
return callback(null, finalBundleTrytes.reverse());
}
}
});
}
function getBundleTrytes(thisTrytes, callback) {
// PROCESS LOGIC:
// Start with last index transaction
// Assign it the trunk / branch which the user has supplied
// IF there is a bundle, chain the bundle transactions via
// trunkTransaction together
let txObject = iotaObj.utils.transactionObject(thisTrytes);
txObject.tag = txObject.tag || txObject.obsoleteTag;
txObject.attachmentTimestamp = Date.now();
txObject.attachmentTimestampLowerBound = 0;
txObject.attachmentTimestampUpperBound = MAX_TIMESTAMP_VALUE;
// If this is the first transaction, to be processed
// Make sure that it's the last in the bundle and then
// assign it the supplied trunk and branch transactions
if (!previousTxHash) {
// Check if last transaction in the bundle
if (txObject.lastIndex !== txObject.currentIndex) {
return callback(new Error("Wrong bundle order. The bundle should be ordered in descending order from currentIndex"));
}
txObject.trunkTransaction = trunkTransaction;
txObject.branchTransaction = branchTransaction;
} else {
// Chain the bundle together via the trunkTransaction (previous tx in the bundle)
// Assign the supplied trunkTransaciton as branchTransaction
txObject.trunkTransaction = previousTxHash;
txObject.branchTransaction = trunkTransaction;
}
let newTrytes = iotaObj.utils.transactionTrytes(txObject);
curl.pow({trytes: newTrytes, minWeight: minWeightMagnitude}).then(function(nonce) {
var returnedTrytes = newTrytes.substr(0, 2673-81).concat(nonce);
var newTxObject= iotaObj.utils.transactionObject(returnedTrytes);
// Assign the previousTxHash to this tx
var txHash = newTxObject.hash;
previousTxHash = txHash;
finalBundleTrytes.push(returnedTrytes);
callback(null);
}).catch(callback);
}
loopTrytes()
}
ccurlHashing(trunkTransaction, branchTransaction, minWeightMagnitude, trytes, function(error, success) {
if (error) {
console.log(error);
$('#loadingText').text("Hashing error. Try Starting Over.");
} else {
console.log(success);
$('#loadingText').text("Hashing Succeeded. Let's Move On.");
}
if (callback) {
return callback(error, success);
} else {
return success;
}
})
}
sendMessages(address);
function sendMessages(address) {
// using this because of bug with using curl.overrideAttachToTangle()
iota.api.attachToTangle = localAttachToTangle;
// bundle the transfers for all the tasks
let transfers = [];
transfers.push({
address: address,
value: value,
message: iota.utils.toTrytes(message),
tag: tag
});
$('#loadingText').text("Doing PoW (Proof of Work)");
iota.api.sendTransfer(seed, generateDepth(), weight, transfers, function(error, success){
if (error) {
console.log("error in send transfer, api could be down",error);
$('#loadingText').text("Error Sending Transfer. Try Starting Over.");
alert("Public Node Could Be Down. Try Again Later.");
return false;
}
// on success, post address/transaction so Capture Coins users can now solve
let transactionHash = success[0]["hash"];
let addressTransaction = success[0]["address"];
postData(addressCoin,transactionHash,addressTransaction);
})
}
}
function postData(addressCoin,transactionHash,addressTransaction) {
// get the data
var address1 = addressCoin;
var transaction = transactionHash;
var address2 = addressTransaction;
// set the sponsor, sponsorcode
var sponsor = "nosponsor";
var sponsordesc = "nodesc";
// sanitize
address1 = filterXSS(address1);
transaction = filterXSS(transaction);
address2 = filterXSS(address2);
sponsor = filterXSS(sponsor);
sponsordesc = filterXSS(sponsordesc);
// check address exists
if (!address1) {
$('#loading').hide();
$('#loadingText').text("Success. Challenge is Now In the Tangle.");
return false;
}
// validate the address length
if ((address1.length === 90) || (address1.length === 81)) {
// do nothing
} else {
$('#loading').hide();
$('#loadingText').text("Success. Challenge is Now In the Tangle.");
return false;
}
// validate the address content
for (var j = 0; j < address1.length; j++) {
if (("9ABCDEFGHIJKLMNOPQRSTUVWXYZ").indexOf(address1.charAt(j)) < 0) {
$('#loading').hide();
$('#loadingText').text("Success. Challenge is Now In the Tangle.");
return false;
}
}
// check transaction exists
if (!transaction) {
$('#loading').hide();
$('#loadingText').text("Success. Challenge is Now In the Tangle.");
return false;
}
// validate the transaction length
if (transaction.length !== 81) {
$('#loading').hide();
$('#loadingText').text("Success. Challenge is Now In the Tangle.");
return false;
}
// validate the transaction content
for (var j = 0; j < transaction.length; j++) {
if (("9ABCDEFGHIJKLMNOPQRSTUVWXYZ").indexOf(transaction.charAt(j)) < 0) {
$('#loading').hide();
$('#loadingText').text("Success. Challenge is Now In the Tangle.");
return false;
}
}
// check address exists
if (!address2) {
$('#loading').hide();
$('#loadingText').text("Success. Challenge is Now In the Tangle.");
return false;
}
// validate the address length
if ((address2.length === 90) || (address2.length === 81)) {
// do nothing
} else {
$('#loading').hide();
$('#loadingText').text("Success. Challenge is Now In the Tangle.");
return false;
}
// validate the address content
for (var j = 0; j < address2.length; j++) {
if (("9ABCDEFGHIJKLMNOPQRSTUVWXYZ").indexOf(address2.charAt(j)) < 0) {
$('#loading').hide();
$('#loadingText').text("Success. Challenge is Now In the Tangle.");
return false;
}
}
$.ajax({
type: "POST",
url: 'https://q7po1in1zd.execute-api.us-east-1.amazonaws.com/coinStage',
contentType: 'application/json',
data: JSON.stringify({
'address1': address1,
'transaction': transaction,
'address2': address2,
'sponsor': sponsor,
'sponsordesc': sponsordesc
}),
success: function(res){
$('#loading').hide();
$('#loadingText').text("Success. Challenge is Now In the Tangle and Can be Found at https://capturecoins.com/viewiota.html?q=" + transactionHash + "&r=" + address2);
},
error: function(){
// challenge is in tangle, but error with post
$('#loading').hide();
$('#loadingText').text("Success. Challenge is Now In the Tangle and Can be Found at https://capturecoins.com/viewiota.html?q=" + transactionHash + "&r=" + address2);
}
});
return false;
}
});
</script>
</body>
</html>