-
Notifications
You must be signed in to change notification settings - Fork 0
/
lottery.html
408 lines (363 loc) · 10.5 KB
/
lottery.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
<!DOCTYPE html>
<html>
<head>
<title>Lottery - Game Verification code</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noindex, nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;800&display=swap" rel="stylesheet">
<script src="./libs/crypto.js"></script>
<style>
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
font-family: 'Inter', sans-serif;
line-height: 1;
background-color: var(--bg-main);
padding: 60px 0;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
* {
box-sizing: border-box;
color: var(--body-light);
}
.container {
width: 100%;
max-width: 1240px;
padding: 0 20px;
margin: 0 auto;
}
:root {
--body-primary: rgb(225, 231, 228);
--body-light: rgb(184, 184, 184);
--body-default: rgb(138, 138, 138);
/* // input */
--input-text: rgb(127, 127, 127);
--input-light: rgb(80, 80, 80);
--input-default: rgb(41, 41, 41);
/* // bg */
--bg-light: rgb(35, 35, 35);
--bg-secondary: rgb(27, 27, 27);
--bg-primary: rgb(24, 24, 24);
--bg-main: rgb(13, 13, 13);
/* // success */
--success-800: rgb(28, 109, 37);
--success-700: rgb(38, 145, 49);
--success-600: rgb(47, 181, 61);
--success-500: rgb(52, 199, 67);
--success-400: rgb(70, 204, 84);
--success-300: rgb(107, 214, 118);
--success-200: rgb(144, 224, 152);
--success-100: rgb(225, 247, 230);
/* // accent */
--accent-800: rgb(70, 20, 135);
--accent-700: rgb(88, 21, 174);
--accent-600: rgb(105, 22, 213);
--accent-500: rgb(114, 22, 232);
--accent-400: rgb(127, 43, 234);
--accent-300: rgb(152, 86, 238);
--accent-200: rgb(178, 128, 242);
--accent-100: rgb(241, 232, 255);
--accent-logo: rgb(142, 53, 255);
/* // error */
--error: rgb(255, 127, 2);
--error-800: rgb(139, 27, 27);
--error-700: rgb(185, 36, 36);
--error-600: rgb(232, 45, 45);
--error-500: rgb(255, 50, 50);
--error-400: rgb(255, 69, 69);
--error-300: rgb(255, 106, 106);
--error-200: rgb(255, 143, 143);
--error-100: rgb(253, 232, 232);
/* // warning */
--warning-800: rgb(196, 183, 57);
--warning-700: rgb(220, 202, 35);
--warning-600: rgb(243, 221, 12);
--warning-500: rgb(255, 231, 1);
--warning-400: rgb(255, 233, 24);
--warning-300: rgb(255, 240, 93);
--warning-200: rgb(255, 244, 140);
--warning-100: rgb(253, 246, 178);
/* // base */
--white: rgb(255, 255, 255);
--black: rgb(0, 0, 0);
}
.title {
font-size: 24px;
margin-bottom: 20px;
}
.label {
font-size: 16px;
color: var(--body-light);
margin-bottom: 8px;
}
.input {
border-radius: 8px;
background-color: var(--input-default);
padding: 12px 16px;
font-size: 14px;
border: none;
}
.block {
width: 100%;
border-radius: 16px;
background-color: var(--bg-primary);
padding: 24px 16px;
}
.col {
display: flex;
flex-direction: column;
margin-bottom: 15px;
}
.row {
display: flex;
justify-content: space-between;
}
.button {
padding: 12px 20px;
border-radius: 8px;
background-color: var(--accent-500);
color: #fff;
border: none;
cursor: pointer;
width: 100%;
transition: transform .2s ease;
}
.button:active {
transform: scale(0.95)
}
.button:hover {
opacity: .8;
}
.submit-btn {
display: flex;
justify-content: flex-end;
margin-top: 20px;
}
.sizedBoxHeight {
height: 12px;
width: 100%;
}
.table {
width: 100%;
}
tr {
text-align: left;
/* border-bottom: 1px solid var(--body-default); */
}
thead {
background-color: var(--bg-light);
}
th {
padding: 20px 16px;
}
td {
padding: 20px 16px;
width: 50%;
}
.main-block {
display: flex;
}
.form-block {
width: 70%;
margin-right: 14px;
}
.desc-block {
width: 30%;
}
.p-tag {
font-size: 14px;
}
.link {
width: fit-content;
display: block;
color: var(--accent-200);
margin-bottom: 20px;
}
.link:hover {
color: var(--accent-100);
}
</style>
</head>
<body>
<div id="app">
<section class="section">
<div class="container">
<h1 class="title">Lottery - Game Verification</h1>
</div>
<div class="container">
<div class="block">
<div class="main-block">
<div class="form-block">
<div class="col">
<div class="row">
<label class="label">Server seed (eth block hash)</label>
</div>
<input v-model="serverSeed" class="input" type="text" placeholder="Server seed (SHA256)">
</div>
<div class="col">
<div class="row">
<label class="label">Client seed (eth block hash)</label>
</div>
<input v-model="clientSeed" class="input" type="text" placeholder="Salt">
</div>
</div>
<!-- Lottery is drawn in 5+1 balls rule, with five regular balls taken from 36 numbers and a jackpot ball taken from 10 numbers.
Server seed: Each game generates a new server seed and publishes the string after Hash256. Client Seeds: Get the ETH height at the end of the daily ticket purchase deadline, and use Hash after 10 blocks as the client seed.
First, use HMAC_SHA256 to calculate the hash value, which gives us a 64-bit character hex string: -->
<div class="desc-block">
<h3 class="label">How does it work:</h3>
<p class="p-tag">Firstly, we taking 2 hashes from etherscan (client, server) and mixing them via Lottery algorithm</p>
<div class="sizedBoxHeight"></div>
<p class="p-tag">
Secondly, we mixing seeds via HmacSHA256, and taking every 8 chars of hash, converting them to number, and getting results
</p>
<div class="sizedBoxHeight"></div>
<p class="p-tag">Eventually, algorithm produce 5 balls (based on 36 numbers) + 1 jackpot ball (based on 10 numbers)</p>
</div>
</div>
<div class="field is-grouped">
<p class="submit-btn">
<button class="button is-primary" @click="triggerGameResult()">Verify</button>
</p>
</div>
</div>
</div>
<div class="sizedBoxHeight"></div>
<div class="container">
<div class="block">
<table class="table">
<thead>
<tr>
<th colspan="7"><b>First 5 numbers</b></th>
<th colspan="7"><b>Jackpot number</b></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7">{{ gameResult }}</td>
<td colspan="7">{{ gameResult[gameResult.length - 1] }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
</div>
<script type="module">
const query = locationRead.queryString();
import { createApp, ref, watch } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js';
createApp({
data() {
return {
serverSeed: query.ss ?? "",
clientSeed: query.cs ?? "",
gameResult: []
}
},
mounted() {
if (this.serverSeed && this.clientSeed) this.triggerGameResult()
},
methods: {
triggerGameResult() {
this.gameResult = this.lotteryResult(this.clientSeed, this.serverSeed)
},
getRandomByHash(hash) {
if (!hash) return 0;
return hash
.match(/.{2}/g)
.map((_) => parseInt(_, 16))
.reduce(
(res, it, i) => res + it / 256 ** (i + 1),
0
);
},
getBalls(hash) {
if (!hash) return;
const remainingBalls = Array(36)
.fill(null)
.map((v, i) => i + 1);
const balls = [];
for (let i = 0; i < 5; i++) {
const random = this.getRandomByHash(hash.substr(i * 8, 8));
if (!random) return;
const ballIndex = Math.floor(random * remainingBalls.length);
balls.push(remainingBalls.splice(ballIndex, 1)[0]);
}
const jackpot = Math.floor(this.getRandomByHash(hash.substr(5 * 8, 8)) * 10) + 1;
return balls.concat(jackpot);
},
lotteryResult(client, server) {
const hmac = CryptoJS.HmacSHA256(client, server);
const result = this.getBalls(hmac.toString());
return result;
},
},
}).mount('#app')
</script>
<script>
window.locationRead = (() => {
function queryString() {
return window.location.search.replace('?', '')
.split('&')
.reduce(function (res, item) {
let kv = item.split('=');
res[kv[0]] = kv[1];
return res;
}, {})
}
function sha256 (value) {
return CryptoJS.SHA256(CryptoJS.enc.Utf8.parse(value));
}
return {
queryString,
sha256,
}
})();
</script>
</body>
</html>