-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateResult.html
More file actions
481 lines (444 loc) · 17.3 KB
/
createResult.html
File metadata and controls
481 lines (444 loc) · 17.3 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<script src="./js/vue.min.js"></script>
<script src="./js/jquery-3.2.1.min.js"></script>
<script src="./js/lodash.min.js"></script>
<script src="./js/elastos-wallet-api-min.js"></script>
<script>
Vue.prototype.$verify = this.verify;
Vue.prototype.$getAddress = this.getAddress;
</script>
<script>
var sha256 = function sha256(ascii) {
function rightRotate(value, amount) {
return (value >>> amount) | (value << (32 - amount));
};
var mathPow = Math.pow;
var maxWord = mathPow(2, 32);
var lengthProperty = 'length'
var i, j; // Used as a counter across the whole file
var result = ''
var words = [];
var asciiBitLength = ascii[lengthProperty] * 8;
//* caching results is optional - remove/add slash from front of this line to toggle
// Initial hash value: first 32 bits of the fractional parts of the square roots of the first 8 primes
// (we actually calculate the first 64, but extra values are just ignored)
var hash = sha256.h = sha256.h || [];
// Round constants: first 32 bits of the fractional parts of the cube roots of the first 64 primes
var k = sha256.k = sha256.k || [];
var primeCounter = k[lengthProperty];
/*/
var hash = [], k = [];
var primeCounter = 0;
//*/
var isComposite = {};
for (var candidate = 2; primeCounter < 64; candidate++) {
if (!isComposite[candidate]) {
for (i = 0; i < 313; i += candidate) {
isComposite[i] = candidate;
}
hash[primeCounter] = (mathPow(candidate, .5) * maxWord) | 0;
k[primeCounter++] = (mathPow(candidate, 1 / 3) * maxWord) | 0;
}
}
ascii += '\x80' // Append Ƈ' bit (plus zero padding)
while (ascii[lengthProperty] % 64 - 56) ascii += '\x00' // More zero padding
for (i = 0; i < ascii[lengthProperty]; i++) {
j = ascii.charCodeAt(i);
if (j >> 8) return; // ASCII check: only accept characters in range 0-255
words[i >> 2] |= j << ((3 - i) % 4) * 8;
}
words[words[lengthProperty]] = ((asciiBitLength / maxWord) | 0);
words[words[lengthProperty]] = (asciiBitLength)
// process each chunk
for (j = 0; j < words[lengthProperty];) {
var w = words.slice(j, j += 16); // The message is expanded into 64 words as part of the iteration
var oldHash = hash;
// This is now the undefinedworking hash", often labelled as variables a...g
// (we have to truncate as well, otherwise extra entries at the end accumulate
hash = hash.slice(0, 8);
for (i = 0; i < 64; i++) {
var i2 = i + j;
// Expand the message into 64 words
// Used below if
var w15 = w[i - 15],
w2 = w[i - 2];
// Iterate
var a = hash[0],
e = hash[4];
var temp1 = hash[7] +
(rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25)) // S1
+
((e & hash[5]) ^ ((~e) & hash[6])) // ch
+
k[i]
// Expand the message schedule if needed
+
(w[i] = (i < 16) ? w[i] : (
w[i - 16] +
(rightRotate(w15, 7) ^ rightRotate(w15, 18) ^ (w15 >>> 3)) // s0
+
w[i - 7] +
(rightRotate(w2, 17) ^ rightRotate(w2, 19) ^ (w2 >>> 10)) // s1
) | 0);
// This is only used once, so *could* be moved below, but it only saves 4 bytes and makes things unreadble
var temp2 = (rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22)) // S0
+
((a & hash[1]) ^ (a & hash[2]) ^ (hash[1] & hash[2])); // maj
hash = [(temp1 + temp2) | 0].concat(hash); // We don't bother trimming off the extra ones, they're harmless as long as we're truncating when we do the slice()
hash[4] = (hash[4] + temp1) | 0;
}
for (i = 0; i < 8; i++) {
hash[i] = (hash[i] + oldHash[i]) | 0;
}
}
for (i = 0; i < 8; i++) {
for (j = 3; j + 1; j--) {
var b = (hash[i] >> (j * 8)) & 255;
result += ((b < 16) ? 0 : '') + b.toString(16);
}
}
return result;
};
Vue.prototype.$sha256 = sha256;
</script>
<link rel="stylesheet" type="text/css" href="./css/reset.css">
<link rel="stylesheet" type="text/css" href="./css/bootstrap.min.css">
</head>
<style type="text/css">
body {
background: #F2F9FF;
}
.xiaoshuo {
cursor: pointer;
}
.xiaoshuo {
cursor: pointer;
}
.spinner {
display: block;
margin: 100px auto 0;
width: 150px;
text-align: center;
}
.spinner>div {
width: 30px;
height: 30px;
background-color: #67CF22;
border-radius: 100%;
display: inline-block;
-webkit-animation: bouncedelay 1.4s infinite ease-in-out;
animation: bouncedelay 1.4s infinite ease-in-out;
/* Prevent first frame from flickering when animation starts */
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.spinner .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.spinner .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
@-webkit-keyframes bouncedelay {
0%,
80%,
100% {
-webkit-transform: scale(0.0)
}
40% {
-webkit-transform: scale(1.0)
}
}
@keyframes bouncedelay {
0%,
80%,
100% {
transform: scale(0.0);
-webkit-transform: scale(0.0);
}
40% {
transform: scale(1.0);
-webkit-transform: scale(1.0);
}
}
.four {
position: fixed;
width: 300px;
margin: 0px auto;
left: 0;
right: 0;
top: 107px;
z-index: 999;
}
.four .left {
display: inline-block;
width: 130px;
margin-right: 15px;
font-family: Bio Sans;
font-size: 16px;
text-align: center;
color: #ffffff;
height: 48px;
line-height: 48px;
background: #31AEFF;
border-radius: 200px;
}
.four .right {
display: inline-block;
width: 130px;
margin-left: 15px;
font-family: Bio Sans;
font-size: 16px;
text-align: center;
color: #ffffff;
height: 48px;
line-height: 48px;
background: #31AEFF;
border-radius: 200px;
}
.toast {
position: fixed;
z-index: 2000;
left: 50%;
top: 25%;
transition: all .5s;
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
-o-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
text-align: center;
border-radius: 5px;
color: #FFF;
background: rgba(17, 17, 17, 0.7);
height: 45px;
line-height: 45px;
padding: 0 15px;
width: 100%;
}
[v-cloak] {
display: none;
}
</style>
<body>
<div id="app" v-cloak>
<div class="toast" v-show="toastShow">
{{toastText}}
</div>
<div class="spinner" v-if="loading">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
<div style="margin-top: 30px;font-size: 18px;text-align: center;color: red;" v-if="!isBalance || !isVerified || isFail&&!loading">{{curLangule['key9']}}</div>
<div style="margin-top: 5px;font-size: 16px;text-align: center" v-if="!isVerified">{{curLangule['key5']}}</div>
<div style="margin-top: 30px;font-size: 16px;text-align: center" v-if="!isFail&&isVerified">{{curLangule['key2']}}</div>
<div style="margin-top: 5px;font-size: 16px;text-align: center" v-if="isFail&&!loading">{{curLangule['key3']}}</div>
<div class="four" v-if="isFail&&!loading">
<span @click="back" class="left">
{{curLangule['key4']}}
</span>
<span @click="shanglian" class="right">
{{curLangule['key']}}
</span>
</div>
<div class="four" v-if="!isVerified" style="text-align: center">
<span @click="back" class="left">
{{curLangule['key4']}}
</span>
<!-- <span @click="shanglian" class="right">
{{curLangule['key']}}
</span> -->
</div>
</div>
</body>
<script>
var app = new Vue({
el: '#app',
data: {
zh: {
title: '投票',
key: '提交',
key1: '已签名成功',
key2: '投票数据正在上链,请稍候。',
key3: '发送交易失败',
key4: '返回主页',
key5: '验签失败',
key6: '无效参数',
key7: '服务器异常,请稍后再试',
key8: '网络异常,请稍后再试',
key9: '投票失败',
},
en: {
title: 'Voting',
key: 'Submit',
key1: 'Signed successfully',
key2: 'Voting data is being submitted to the blockchain, please wait.',
key3: 'Sending transaction failed',
key4: 'Back Home',
key5: 'Verification failed',
key6: 'Invalid parameter',
key7: 'Server exception, please try again later.',
key8: 'Network exception, please try again later.',
key9: 'Failed to vote',
},
curLangule: {},
toastText: "",
toastShow: false,
chainObj: {},
sign: "",
DataStr: "",
loading: true,
isFail: false,
isVerified: true,
createPacket: "",
ownDid: ""
},
methods: {
back() {
location.href = "./index.html";
},
postAjax(url, parms) {
return new Promise((resovle, reject) => {
$.ajax({
url: url,
dataType: 'json',
contentType: 'application/json;charset=UTF-8',
type: 'POST',
data: JSON.stringify(parms),
success: function(data) { //成功回调函数
resovle(data);
},
error: function(err) { //失败回调函数
reject(err);
}
});
});
},
shanglian() {
this.loading = true;
this.isFail = false;
var url = "https://api-voteforme.elaphant.net/api/1/didvoting/save";
var obj = {};
obj["Signature"] = this.sign;
obj["DataStr"] = this.DataStr;
if (this.createPacket != "") {
//this.createPacket['packet_creator'] = this.ownDid;
obj["CreatePacket"] = this.createPacket;
}
var topicId = this.$sha256(encodeURIComponent((JSON.stringify(this.chainObj))));
var parms = {
"address": "did-voting/" + topicId + "/" + "topic_object",
"data": JSON.stringify(obj)
};
this.postAjax(url, parms).then((res) => {
if (res.state === 0) {
let payAddress = "";
let packet = res.data.packet || "";
if (packet != "") {
packet = JSON.parse(packet);
if (packet.status === 200) {
let result = packet["result"];
payAddress = result['pay_address'];
}
}
if (payAddress != "") {
let banance = this.createPacket['packet_amt'];
location.href = "./result.html?txId=" + res.data.txid + '&payAddress=' + payAddress + '&payBalance=' + banance;
} else {
location.href = "./result.html?txId=" + res.data.txid;
}
} else if (res.state === 10000) {
this.loading = false;
this.isFail = true;
this.toast(curLangule['key7']);
} else if (res.state === 10001) {
this.loading = false;
this.isFail = true;
this.toast(curLangule['key8']);
} else if (res.state === 10002) {
this.loading = false;
this.isFail = true;
this.toast(curLangule['key6']);
} else {
this.loading = false;
this.isFail = true;
this.toast(JSON.stringify(res));
}
}).catch((err) => {
this.loading = false;
this.isFail = true;
console.log("====err====" + JSON.stringify(err));
})
},
getUrlParam: function(name) {
//正则表达式过滤
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
//正则规则
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]);
return null;
},
toast(str) {
var v = this;
v.toastText = str
v.toastShow = true
setTimeout(function() {
v.toastShow = false;
}, 1500)
},
getLanugle: function() {
this.curLangule = this.en;
this.curLanguleKey = 'en';
var JsSrc = (navigator.language || navigator.browserLanguage).toLowerCase();
if (JsSrc.indexOf('zh') >= 0) {
// 假如浏览器语言是中文
this.curLanguleKey = 'zh';
this.curLangule = this.zh;
} else if (JsSrc.indexOf('en') >= 0) {
this.curLangule = this.en;
this.curLanguleKey = 'en';
} else {
// 假如浏览器语言是其它语言
this.curLangule = this.en;
this.curLanguleKey = 'en';
}
}
},
created: function() {
let createPacket = this.getUrlParam("createPacket") || "";
if (createPacket != "") {
this.createPacket = JSON.parse(decodeURIComponent(createPacket));
this.createPacket['packet_num'] = parseInt(this.createPacket['packet_num']);
this.createPacket['packet_amt'] = parseFloat(this.createPacket['packet_amt']);
}
this.DataStr = this.getUrlParam("Data");
this.sign = this.getUrlParam("Sign");
var dataStr = decodeURIComponent(this.getUrlParam("Data"));
let publicKey = JSON.parse(dataStr)['PublicKey'] || "";
this.ownDid = JSON.parse(dataStr)["DID"] || "";
let verified = this.$verify(dataStr, this.sign, publicKey);
if (verified) {
this.isVerified = true;
var chainStr = JSON.parse(dataStr)["RequestedConent"] || JSON.parse(dataStr)["RequestedContent"];
this.chainObj = JSON.parse(chainStr);
this.shanglian();
} else {
this.isVerified = false;
this.loading = false;
}
},
mounted() {
this.getLanugle();
document.title = this.curLangule["title"];
}
});
</script>
</html>