forked from TezosRio/taps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet.cfm
executable file
·539 lines (441 loc) · 20.1 KB
/
wallet.cfm
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
<cfif not isUserLoggedIn()>
<cflocation url="index.cfm">
</cfif>
<cfscript>
setLocale("English (us)");
</cfscript>
<cfset hasWallet = false>
<cfset passphrase = "">
<cfset mnemonicWords = "">
<cfset tezosJ = "">
<cfset isCreating = false>
<cfset isImporting = false>
<cfset save = false>
<cfset passdw = "">
<cfset wrongLogin = "">
<cfif isDefined('form.isCreating')>
<cfset isCreating = #form.isCreating#>
<cfelse>
<cfset isCreating = false>
</cfif>
<cfif isDefined('form.isImporting')>
<cfset isImporting = #form.isImporting#>
<cfelse>
<cfset isImporting = false>
</cfif>
<cfif isDefined('form.passphrase')>
<cfset passphrase = #trim(form.passphrase)#>
<cfelse>
<cfset passphrase = "">
</cfif>
<cfif isDefined('form.save')>
<cfset save = #form.save#>
<cfelse>
<cfset save = false>
</cfif>
<cfif isDefined('form.passdw')>
<cfset passdw = #trim(form.passdw)#>
<cfelse>
<cfset passdw = "">
</cfif>
<cfif isDefined('form.mnemonic')>
<cfset mnemonicWords = #trim(form.mnemonic)#>
<cfelse>
<cfset mnemonicWords = "">
</cfif>
<cfif #len(passphrase)# GT 0 and #save# EQ false and #isImporting# EQ false and #len(session.myWallet)# EQ 0>
<!--- Check if user password is right --->
<cfinvoke component="components.taps" method="authenticate" user="#getAuthUser()#" passdw="#passdw#" returnVariable="authResult" />
<cfif #authResult# EQ true>
<cfset wrongLogin = "">
<!--- Create a new, fresh native wallet and get its mnemonic words --->
<!--- Get TezosJ_SDK TezosWallet class --->
<cfset tezosJ = createObject("java", "milfont.com.tezosj.model.TezosWallet", "./#application.TezosJ_SDK_location#")>
<!--- Store TezosJ in session --->
<cfset session.tezosJ = #tezosJ#>
<!--- Instantiate a new wallet with the user passphrase --->
<cfset myWallet = session.tezosJ.init("#passphrase#")>
<!--- Change RPC provider --->
<cfset myWallet.setProvider("#application.provider#")>
<!--- Give an alias to the wallet --->
<cfset r = myWallet.setAlias("TAPS")>
<!--- Get Mnemonic words --->
<cfset mnemonicWords = "#myWallet.getMnemonicwords()#">
<!--- Saves the wallet in advance, so we don't have to pass sensitive information through html form submit --->
<cfset strPath = ExpandPath( "./" ) />
<cfif Not DirectoryExists("#strPath#/wallet")>
<cfdirectory action = "create" directory="#strPath#/wallet" />
</cfif>
<cfset saveResult = myWallet.save('#strPath#/wallet/wallet.taps')>
<cfelse>
<cfset wrongLogin = "true">
</cfif>
</cfif>
<cfif #len(passphrase)# GT 0 and #len(mnemonicWords)# GT 0 and #isImporting# EQ true and #len(session.myWallet)# EQ 0>
<!--- User is importing a previously created wallet --->
<!--- Check if user password is right --->
<cfinvoke component="components.taps" method="authenticate" user="#getAuthUser()#" passdw="#passdw#" returnVariable="authResult" />
<cfif #authResult# EQ true>
<cfset wrongLogin = "">
<!--- Restore the native wallet from its mnemonic words and passphrase --->
<!--- Get TezosJ_SDK TezosWallet class --->
<cfset tezosJ = createObject("java", "milfont.com.tezosj.model.TezosWallet", "./#application.TezosJ_SDK_location#")>
<!--- Store TezosJ in session --->
<cfset session.tezosJ = #tezosJ#>
<!--- Instantiate a new wallet with the user passphrase and mnemonic words --->
<cfset session.myWallet = session.tezosJ.init("#mnemonicWords#", "#passphrase#")>
<!--- Change RPC provider --->
<cfset session.myWallet.setProvider("#application.provider#")>
<!--- Saves the wallet in advance, so we don't have to pass sensitive information through html form submit --->
<cfset strPath = ExpandPath( "./" ) />
<cfif Not DirectoryExists("#strPath#/wallet")>
<cfdirectory action = "create" directory="#strPath#/wallet" />
</cfif>
<cfset saveResult = session.myWallet.save('#strPath#/wallet/wallet.taps')>
<!--- Register the wallet hashed passphrase in the local database --->
<cfinvoke component="components.database" method="saveWallet" bakerId="#application.bakerId#" passphrase="#passphrase#" passdw="#passdw#" returnVariable="resultSaveWallet">
<cfelse>
<cfset wrongLogin = "true">
</cfif>
</cfif>
<!--- If user confirmed by clicking NEXT button, then we will load the previosuly saved wallet --->
<cfif #save# EQ true and #len(session.myWallet)# EQ 0>
<!--- Register the wallet hashed passphrase in the local database --->
<cfinvoke component="components.database" method="saveWallet" bakerId="#application.bakerId#" passphrase="#passphrase#" passdw="#passdw#" returnVariable="resultSaveWallet">
<cfif #resultSaveWallet# EQ true>
<!--- Instantiate a new wallet (from media) with the user passphrase and mnemonic words --->
<cfset strPath = ExpandPath( "./" ) />
<cfset session.myWallet = session.tezosJ.init(true, "#strPath#/wallet/wallet.taps", "#passphrase#")>
<cfelse>
<cfset tezosJ = "">
<cfset myWallet = "">
</cfif>
</cfif>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta http-equiv="cache-control" content="no-cache">
<script src="js/angular.min.js"></script>
<!-- CSS Bootstrap-->
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<!-- CSS Page-->
<link rel="stylesheet" type="text/css" href="css/estilo.css">
<script src="js/jquery-3.2.1.min.js"></script>
<script language="javascript">
function copyToClipboard(id)
{
var copyText = document.getElementById(id);
copyText.select();
document.execCommand("copy");
alert(copyText.value + " copied to clipboard");
}
function validateCreate()
{
if (document.getElementById('idPassdw').value == '')
{
return 'idPassdw_req';
}
if (document.getElementById('idPassphrase').value == '')
{
return 'idPassphrase_req';
}
return true;
}
function validateImport()
{
if (document.getElementById('idPassdw').value == '')
{
return 'idPassdw_req';
}
if (document.getElementById('idPassphrase').value == '')
{
return 'idPassphrase_req';
}
if (document.getElementById('idMnemonic').value == '')
{
return 'idMnemonic_req';
}
if (document.getElementById('idMnemonic').value.match(/\S+/g).length < 15)
{
return 'idMnemonic_req';
}
return true;
}
function validateNext()
{
if (!confirm('Did you really write down the passphrase and mnemonic words and now wish to continue to next step?'))
return false;
document.getElementById('idMnemonic').value='';
document.form.save.value=true;
document.form.submit();
}
function hideButtonNext()
{
if (document.getElementById('idNext'))
{
document.getElementById('idNext').disabled = true;
document.getElementById('idNext').style.visibility='hidden';
}
}
function showRequiredField(field)
{
var inputFieldName = field.substring(0, field.indexOf('_'));
var sufix = field.substring( field.indexOf('_') + 1, field.length );
if (sufix == 'req')
{
document.getElementById(inputFieldName + '_req').value=' Required';
}
if (inputFieldName + '_req')
{
document.getElementById(inputFieldName + '_req').style.visibility = "visible";
document.getElementById(inputFieldName + '_req').focus();
}
document.getElementById(inputFieldName).focus();
}
function hideReqFields()
{
document.getElementById('idPassphrase_req').style.visibility = "hidden";
document.getElementById('idPassdw_req').style.visibility = "hidden";
if (document.getElementById('idMnemonic_req'))
document.getElementById('idMnemonic_req').style.visibility = "hidden";
}
</script>
<style>
a, a:active, a:focus, a:hover, input, input:focus { outline: none; !important; }
.nooutline, .nooutline:focus { outline: none; !important; }
.required
{
align:right;
color:red;
visibility:hidden;
border:hidden;
cursor:default;
}
</style>
</head>
<body ng-app="TAPSApp">
<section class="box-content-rewards">
<div style="width:550px;">
<cfoutput>
<h1 class="title-baker">
Wallet
</h1>
<!--- Get settings --->
<cfinvoke component="components.database" method="getSettings" returnVariable="settings">
<cfif #settings.recordCount# GT 0>
<cfif #len(session.myWallet)# GT 0>
<!--- User has configured TAPS successfully and also created a native wallet --->
<cfset hasWallet = true>
<cfelse>
<cfset hasWallet = false>
</cfif>
<!--- Change what it will display, according to if has wallet or not --->
<cfif #hasWallet# EQ false>
<cfform name="form" action="wallet.cfm" method="post">
<cfif #isCreating# EQ false and #isImporting# EQ false and #settings.funds_origin# EQ "native">
<br><br><br><br><br><br>
<center>  
<button type="button" class="botao-taps" style="width:300px;" onClick="document.getElementById('idCreating').value=true;document.form.submit();">CREATE NEW WALLET</button>
</center>
<br>
<center>  
<button type="button" class="botao-taps" style="width:300px;" onClick="document.getElementById('idImporting').value=true;document.form.submit();">IMPORT WALLET</button>
</center>
<cfelseif #isCreating# EQ true and #isImporting# EQ false>
WARNING: Write down in a piece of paper all information displayed on this page
(passphrase and mnemonic words) and store it in a safe place. It will be required
in order to access your wallet and move your funds in the future.<br>
<br>
<table>
<tr>
<td>
<label>
<cfif #len(wrongLogin)# EQ 0>
<cfset reqFieldContents = " Required">
<cfset reqVisibility = "hidden">
<cfelse>
<cfset reqFieldContents = "Wrong password">
<cfset reqVisibility = "visible">
</cfif>
<span class="text-input-taps">TAPS Login password</span><input type="text" class="required" id="idPassdw_req" value="#reqFieldContents#" readonly style="visibility: #reqVisibility#;">
<input type="password" id="idPassdw" name="passdw" class="input-taps" size="50" placeholder="Type your TAPS login password" value="#passdw#" />
</label>
</td>
</tr>
<tr>
<td>
<label>
<span class="text-input-taps">Wallet passphrase</span><input type="text" class="required" id="idPassphrase_req" value=" Required" readonly>
<input type="text" id="idPassphrase" name="passphrase" class="input-taps" size="50" placeholder="Type a passphrase" value="#passphrase#" onChange="hideButtonNext();" onKeyDown="hideButtonNext();" />
</label>
</td>
</tr>
<tr>
<td>
<button type="button" id="idCreate" class="botao-taps" onClick="javascript: var result = validateCreate(); if (result == true){ hideReqFields(); document.getElementById('idCreating').value=true; document.form.submit(); } else { showRequiredField(result); }">CREATE NEW WALLET</button>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td>
<label>
<span class="text-input-taps">Mnemonic words</span>
<textarea name="mnemonic" id="idMnemonic" cols="50" rows="3" style="padding-left:10px;padding-top:10px;" readonly>#mnemonicWords#</textarea>
</label>
</td>
</tr>
<tr>
<td>
<label>
<cfif #len(mnemonicWords)# GT 0>
<button type="button" id="idNext" class="botao-taps" onClick="validateNext();">NEXT</button>
</cfif>
</label>
</td>
</tr>
</table>
<cfelseif #isImporting# EQ true and #isCreating# EQ false>
Please enter your previously created wallet details: TAPS login password, passphrase,
and mnemonic words, separated by spaces.
<br>
<table>
<tr>
<td>
<label>
<cfif #len(wrongLogin)# EQ 0>
<cfset reqFieldContents = " Required">
<cfset reqVisibility = "hidden">
<cfelse>
<cfset reqFieldContents = "Wrong password">
<cfset reqVisibility = "visible">
</cfif>
<span class="text-input-taps">TAPS Login password</span><input type="text" class="required" id="idPassdw_req" value="#reqFieldContents#" readonly style="visibility: #reqVisibility#;">
<input type="password" id="idPassdw" name="passdw" class="input-taps" size="50" placeholder="Type your TAPS login password" value="#passdw#" />
</label>
</td>
</tr>
<tr>
<td>
<label>
<span class="text-input-taps">Wallet passphrase</span><input type="text" class="required" id="idPassphrase_req" value=" Required" readonly>
<input type="text" id="idPassphrase" name="passphrase" class="input-taps" size="50" placeholder="Type a passphrase" value="" />
</label>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td>
<label>
<span class="text-input-taps">Mnemonic words</span><input type="text" class="required" id="idMnemonic_req" value=" Required" readonly style="visibility:hidden;">
<textarea name="mnemonic" id="idMnemonic" cols="50" rows="3" style="padding-left:10px;padding-top:10px;"></textarea>
</label>
</td>
</tr>
<tr>
<td>
<label>
<button type="button" id="idImport" class="botao-taps" onClick="javascript: var result = validateImport(); if (result == true){ hideReqFields(); document.getElementById('idImporting').value=true; document.form.submit(); } else { showRequiredField(result); }">IMPORT WALLET</button>
</label>
Total word count: <span id="display_count">0</span> words.
</td>
</tr>
</table>
<script>
$(document).ready(function() {
$("##idMnemonic").on('keyup', function() {
var words = this.value.match(/\S+/g).length;
if (words > 15)
{
var trimmed = $(this).val().split(/\s+/, 15).join(" ");
$(this).val(trimmed + " ");
}
else
{
$('##display_count').text(words);
$('##word_left').text(15-words);
}
});
});
</script>
<cfelseif #settings.funds_origin# EQ "node">
<br><br><br>
TAPS has been configured to run with node resources.
</cfif>
<cfinput name="isCreating" id="idCreating" type="hidden" value="false">
<cfinput name="isImporting" id="idImporting" type="hidden" value="false">
<cfinput name="save" id="idSave" type="hidden" value="false">
</cfform>
<cfelse>
<cfif #len(session.myWallet)# GT 0>
<cfform name="form" action="wallet.cfm" method="post">
<table>
<tr><td> </td></tr>
<tr>
<td>
<span class="text-input-taps">Address</span><br>
<div class="input-group add-on" style="width:480px;">
<input type="text" id="idAddress" name="address" class="input-taps form-control" size="45" value="#session.myWallet.getPublicKeyHash()#" readonly >
<div class="input-group-btn">
<button style="background:none;border:none;margin-top:-2px;outline:none;" id="idCopyToClipboard" onClick="javascript:copyToClipboard('idAddress');"><img src="./imgs/clipboard.png" style="cursor:pointer;border:hidden;"></button>
</div>
</div>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td>
<label>
<span class="text-input-taps">Balance</span>
<div ng-controller="MainController">
<input type="text" id="idBalance" name="balance" class="input-taps" style="text-align:center;font-size:32px;height:100px;width:475px;" size="50" value="{{balance}}" readonly />
</div>
</label>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td>
<button type="button" class="botao-taps" onClick="document.location.href='send_funds.cfm';">SEND</button>
<button type="button" class="botao-taps" onClick="document.location.href='receive_funds.cfm';">RECEIVE</button>
</td>
</tr>
</table>
</cfform>
<cfelse>
Could not load the configured wallet.
</cfif>
</cfif>
<cfelse>
<br>
There is no configuration saved on settings.<br>
Please go to SETUP first.<br>
</cfif>
</cfoutput>
</div>
</section>
<!-- Controller -->
<cfoutput>
<script>
var app = angular.module("TAPSApp", []);
var MainController = function ($scope, $http, $interval)
{
$scope.balance = "Fetching...";
$interval(function (i)
{
$http.get('http://127.0.0.1:8888/taps/getBalance.cfm').success(function(data, status, headers, config)
{
$scope.balance = data;
}).error(function(data, status, headers, config)
{
// log error.
});
}, 5000);
};
app.controller("MainController", ["$scope", "$http", "$interval", MainController]);
</script>
</cfoutput>
</body>
</html>