-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
482 lines (463 loc) · 16.5 KB
/
index.html
File metadata and controls
482 lines (463 loc) · 16.5 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>KeyChain test page</title>
<link rel="shortcut icon" href="../assets/favicon.ico">
<style>
button {
width: 100%;
}
a {
color: white;
font-weight: bold;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
.btn_command {
transition-duration: 0.5s;
}
.btn_transform {
transform: translateX(30px);
transition-duration: 0.5s;
}
label {
color: rgb(0, 104, 153);
line-height: 1.982;
text-align: left;
display: block
}
body {
margin: 0;
font-family: -apple-system,system-ui,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",sans-serif;
font-size: .8rem;
overflow-x: hidden;
text-rendering: optimizeLegibility;
color: white;
}
.page_title {
color: rgb(85, 85, 85);
font-weight: bold;
margin-bottom: 15px;
}
.page {
display: none;
}
.page-active {
display: block;
}
.container {
display: grid;
grid-template-columns: 1fr 500px 1fr;
grid-template-rows: 131px 89px auto 50px 24px 6px;
}
.header {
background-image: -moz-linear-gradient( -96deg, rgb(32,135,184) 0%, rgb(16,120,169) 47%, rgb(0,104,153) 100%);
background-image: -webkit-linear-gradient( -96deg, rgb(32,135,184) 0%, rgb(16,120,169) 47%, rgb(0,104,153) 100%);
background-image: -ms-linear-gradient( -96deg, rgb(32,135,184) 0%, rgb(16,120,169) 47%, rgb(0,104,153) 100%);
grid-column: 1 / 4;
grid-row: 1;
z-index: 15;
display: grid;
grid-template-columns: 1fr 320px 1fr;
justify-content: center;
}
.header-center-logo {
align-self: end;
justify-self: end;
}
.header-center {
display: grid;
grid-template-columns: 70px auto;
grid-template-rows: 85px 46px;
}
.header-center-name {
align-self: center;
justify-self: center;
}
.header-center-bottom {
align-self: center;
justify-self: start;
text-align: center;
grid-column: 1 / 3;
grid-row: 2;
}
.address {
border-radius: 12px;
background-color: rgb(38, 138, 186);
box-shadow: inset 0 53px 46px 0 rgba(0, 0, 0, 0.17);
height: 139px;
grid-column: 2;
grid-row: 2;
margin-top: -80px;
z-index: 10;
padding-left: 15px;
}
.middle {
grid-row: 3;
grid-column: 1 / 4;
display: grid;
grid-template-columns: 200px 1fr 1fr 120px;
grid-template-rows: 200px 200px 50px auto;
grid-column-gap: 65px;
}
.menu {
grid-column: 1;
grid-row: 1 / 3;
display: grid;
margin-left: -60px;
}
.form {
grid-column: 2 / 4;
grid-row: 1;
}
.right_menu {
grid-column: 4;
grid-row: 1 / 3;
display: grid;
}
.run_request {
grid-column: 2;
grid-row: 3;
justify-self: end;
}
.btn {
border-radius: 2px;
background-image: -moz-linear-gradient( -90deg, rgb(32,135,184) 0%, rgb(16,120,169) 47%, rgb(0,104,153) 100%);
background-image: -webkit-linear-gradient( -90deg, rgb(32,135,184) 0%, rgb(16,120,169) 47%, rgb(0,104,153) 100%);
background-image: -ms-linear-gradient( -90deg, rgb(32,135,184) 0%, rgb(16,120,169) 47%, rgb(0,104,153) 100%);
color: white;
text-align: right;
display: block;
font-weight: normal;
padding: 4px 6px 4px 6px;
}
.btn_run_request {
text-align: center;
}
.gap {
grid-column: 1 / 4;
}
.warning_bottom {
background-image: -moz-linear-gradient( -90deg, rgb(32,135,184) 0%, rgb(16,120,169) 47%, rgb(0,104,153) 100%);
background-image: -webkit-linear-gradient( -90deg, rgb(32,135,184) 0%, rgb(16,120,169) 47%, rgb(0,104,153) 100%);
background-image: -ms-linear-gradient( -90deg, rgb(32,135,184) 0%, rgb(16,120,169) 47%, rgb(0,104,153) 100%);
display: flex;
justify-content: center;
align-items: center;
color: white;
grid-column: 1 / 4;
}
.warning_bottom_divider {
background-color: rgb(209, 18, 80);
grid-column: 1 / 4;
}
.modal {
display: none;
position: fixed;
z-index: 1;
padding-top: 250px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
}
.modal-content {
text-align: center;
font-size: 1.8rem;
background-color: #fefefe;
color: rgb(85, 85, 85);
margin: auto;
padding: 20px;
border: 1px solid #888;
}
.form-label {
color: #006899;
display: inline-block;
width: 100px;
}
.form-input {
border-radius: 2px;
border-style:solid;
border-width:1px;
width: 200px;
padding: 3px;
}
textarea {
border-radius: 2px;
}
</style>
</head>
<body>
<div id="error" class="modal">
<div class="modal-content">
<p>WebSocket connection failed. Check if KeyChain is installed.</p>
</div>
</div>
<div class="container">
<div class="header">
<div></div>
<div class="header-center">
<div class="header-center-logo">
<img src="../assets/logo.png" alt="KeyChain logo" width="70px">
</div>
<div class="header-center-name">
<span style="font-size: 1.8rem; font-weight: bold">KeyChain</span><span style="position: relative;top:-20px">Demo</span>
</div>
<div class="header-center-bottom">
Test the WebSocket commands of KeyChain <span id="version"></span> <br>
Read more: <a href="https://arrayio.github.io/KeyChain/">KeyChain Documentation</a>
</div>
</div>
<div></div>
</div>
<div class="address">
<div style="margin-top: 90px"> <!-- todo fix the layout and avoid margin-top -->
<b>Your Ethereum address:</b> <span id="address"></span> <br>
<b>Your public key:</b> <span id="selectedKey"></span>
</div>
</div>
<div class="middle">
<div class="menu">
<div><a href="#select_key" class="btn btn_command" data-hash="select_key" data-left="1">Select key</a></div>
<div><a href="#unlock" class="btn btn_command" data-hash="unlock" data-left="1">Unlock</a></div>
<div><a href="#lock" class="btn btn_command" data-hash="lock" data-left="1">Lock</a></div>
<div><a href="#sign_trx" class="btn btn_command" data-hash="sign_trx" data-left="1">Sign transaction</a></div>
<div><a href="#sign_hash" class="btn btn_command" data-hash="sign_hash" data-left="1">Sign hash</a></div>
<div><a href="#about" class="btn btn_command" data-hash="about" data-left="1">About</a></div>
<div><a href="#version" class="btn btn_command" data-hash="version" data-left="1">Version</a></div>
</div>
<div class="form">
<div class="page" id="page_select_key">
<div class="page_title">Select key</div>
</div>
<div class="page" id="page_lock">
<div class="page_title">Lock</div>
</div>
<div class="page" id="page_unlock">
<div class="page_title">Unlock</div>
<div class="form-group">
<label class="form-label" for="public_key_UNLOCK">Public key:</label>
<input class="form-input" type="text" name="public_key" id="public_key_UNLOCK">
</div>
<div class="form-group">
<label class="form-label">Unlock time:</label>
<input class="form-input" type="number" placeholder="45" value="45" name="unlock_time">
</div>
</div>
<div class="page" id="page_sign_trx">
<div class="page_title">Sign transaction</div>
<div class="form-group">
<label class="form-label">Transaction:</label>
<input class="form-input" type="text" value="eb0885098bca5a00825208948ec6977b1255854169e5f9f8f163f371bcf1ffd287038d7ea4c6800080038080" placeholder="eb0885098bca5a00825208948ec6977b1255854169e5f9f8f163f371bcf1ffd287038d7ea4c6800080038080" name="transaction">
</div>
<div class="form-group">
<label class="form-label">Blockchain type:</label>
<input class="form-input" type="text" placeholder="ethereum" value="ethereum" name="blockchain_type">
</div>
<div class="form-group">
<label class="form-label" for="public_key_SIGN_TRX">Public key:</label>
<input class="form-input" type="text" name="public_key" id="public_key_SIGN_TRX">
</div>
<div class="form-group">
<label class="form-label">Unlock time:</label>
<input class="form-input" type="number" name="unlock_time" placeholder="45" readonly id="unlock_time_SIGN_TRX">
<input type="checkbox" id="checkbox_SIGN_TRX">
</div>
</div>
<div class="page" id="page_sign_hash">
<div class="page_title">Sign hash</div>
<div class="form-group">
<label class="form-label">Hash:</label>
<input class="form-input" type="text" value="fe5e4a8974715e20f47c8bb609547c9e66b0b9e31d521199b3d8d6af6da74cb1" placeholder="fe5e4a8974715e20f47c8bb609547c9e66b0b9e31d521199b3d8d6af6da74cb1" name="hash">
</div>
<div class="form-group">
<label class="form-label">Sign type:</label>
<input class="form-input" type="text" placeholder="VRS_canonical" value="VRS_canonical" name="sign_type">
</div>
<div class="form-group">
<label class="form-label" for="public_key_SIGN_HASH">Public key:</label>
<input class="form-input" type="text" name="public_key" id="public_key_SIGN_HASH">
</div>
</div>
<div class="page" id="page_about">
<div class="page_title">About</div>
</div>
<div class="page" id="page_version">
<div class="page_title">Version</div>
</div>
</div>
<div class="right_menu">
<div><a href="#select_key" class="btn btn_command" data-hash="select_key" data-left="0"> </a></div>
<div><a href="#unlock" class="btn btn_command" data-hash="unlock" data-left="0"> </a></div>
<div><a href="#lock" class="btn btn_command" data-hash="lock" data-left="0"> </a></div>
<div><a href="#sign_trx" class="btn btn_command" data-hash="sign_trx" data-left="0"> </a></div>
<div><a href="#sign_hash" class="btn btn_command" data-hash="sign_hash" data-left="0"> </a></div>
<div><a href="#about" class="btn btn_command" data-hash="about" data-left="0"> </a></div>
<div><a href="#version" class="btn btn_command" data-hash="version" data-left="0"> </a></div>
</div>
<div class="request">
<textarea style="width: 100%; height: 90%" id="request" placeholder="{}"></textarea>
</div>
<div class="response">
<textarea style="width: 100%; height: 90%" id="response" placeholder="{}"></textarea>
</div>
<div class="run_request">
<a href="#" class="btn btn_run_request" id="btn_RUN_REQUEST">Run request</a>
</div>
</div>
<div class="gap"></div>
<div class="warning_bottom">Warning! unlock_time parameter is experimental and optional</div>
<div class="warning_bottom_divider"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/keychain.js@0.0.6/dist/keychain.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/ethereumjs/browser-builds/dist/ethereumjs-tx/ethereumjs-tx-1.3.3.min.js"></script>
<script>
const keychain = new Keychain();
keychain.command({command: 'version'}, function(data) {
document.getElementById('version').innerText = data.result ? data.result : '';
});
onHash(true);
keychain.ws.onclose = function() {
document.getElementById('error').style.display = 'block';
};
function buttonEnter(button) {
button.classList.add('btn_transform');
const oppositeElement = getOppositeElementId(button);
oppositeElement.classList.add('btn_transform');
}
function buttonLeave(button) {
if ("#" + button.dataset.hash === window.location.hash) {
return;
}
button.classList.remove('btn_transform');
const oppositeElement = getOppositeElementId(button);
oppositeElement.classList.remove('btn_transform');
}
function onHash(runRequestParam) {
if(!window.location.hash) {
return;
}
const hash = window.location.hash.substr(1);
const el = document.getElementById('page_' + hash);
if (el) {
const pageActive = document.getElementsByClassName('page-active');
if (pageActive.length > 0) {
document.getElementsByClassName('page-active')[0].classList.remove('page-active');
}
el.classList.add('page-active');
document.querySelectorAll('.btn_transform').forEach(function(button) {
button.classList.remove('btn_transform')
});
const button = document.querySelector('[data-hash=' + hash + '][data-left="1"]');
buttonEnter(button);
const request = fieldsToJson();
document.getElementById('request').value = JSON.stringify(request, undefined, 2);
if (runRequestParam) {
runRequest();
}
}
}
function fieldsToJson() {
const hash = window.location.hash.substr(1);
const el = document.getElementById('page_' + hash);
const inputs = el.getElementsByClassName('form-input');
const params = {};
for (let i=0; i<inputs.length; i++) {
const name = inputs[i].getAttribute('name');
if (!inputs[i].readOnly) {
params[name] = inputs[i].value;
}
}
const request = {command: hash};
if (Object.keys(params).length > 0) {
request.params = params;
}
return request;
}
function jsonToFields() {
const request = getRequest();
if (request && request.params) {
const hash = window.location.hash.substr(1);
const el = document.getElementById('page_' + hash);
const inputs = el.getElementsByClassName('form-input');
for (let i=0; i<inputs.length; i++) {
const name = inputs[i].getAttribute('name');
if (!inputs[i].readOnly) {
inputs[i].value = request.params[name];
}
}
}
}
window.onhashchange = onHash;
window.onload = function () {
document.getElementById('checkbox_SIGN_TRX').addEventListener('click', function(e) {
document.getElementById('unlock_time_SIGN_TRX').readOnly = !e.target.checked;
const request = getRequest();
if (request) {
if (!e.target.checked) {
delete request.params['unlock_time'];
} else {
request.params['unlock_time'] = document.getElementById('unlock_time_SIGN_TRX').value;
}
document.getElementById('request').value = JSON.stringify(request, undefined, 2)
}
});
document.getElementById('btn_RUN_REQUEST').addEventListener('click', function() {
event.preventDefault();
runRequest();
});
const inputs = document.getElementsByClassName('form-input');
for (let i=0; i<inputs.length; i++) {
inputs[i].addEventListener('keyup', function() { onHash(false) });
inputs[i].addEventListener('change', function() { onHash(false) });
}
document.getElementById('request').addEventListener('keyup', function () {
jsonToFields();
});
const buttons = document.getElementsByClassName('btn_command');
for (let i=0; i<buttons.length; i++) {
buttons[i].addEventListener('mouseenter', function () {
buttonEnter(buttons[i]);
});
buttons[i].addEventListener('mouseleave', function () {
buttonLeave(buttons[i]);
});
}
};
function getOppositeElementId(button) {
const oppositeDataLeft = +button.dataset.left^1;
return document.querySelector('[data-left="' + oppositeDataLeft + '"][data-hash="' + button.dataset.hash + '"]');
}
function getRequest() {
try {
return JSON.parse(document.getElementById('request').value);
} catch (e) {
document.getElementById('response').value = e;
}
}
function runRequest() {
const request = getRequest();
if (!request) {
return;
}
keychain.command(request, function(data) {
document.getElementById('response').value = JSON.stringify(data, undefined, 2);
if (request.command === 'select_key' && data.result) {
document.getElementById('public_key_UNLOCK').value = data.result;
document.getElementById('public_key_SIGN_HASH').value = data.result;
document.getElementById('public_key_SIGN_TRX').value = data.result;
document.getElementById('selectedKey').innerHTML = '0x' + data.result.substr(0, 35) + '<...>' + data.result.substr(-8, 8);
document.getElementById('address').innerHTML = '0x' + ethereumjs.Util.publicToAddress('0x' + data.result).toString('hex');
}
})
}
</script>
</body>
</html>