forked from bcgame-project/verify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_jade.html
More file actions
162 lines (149 loc) · 5.76 KB
/
Copy pathnew_jade.html
File metadata and controls
162 lines (149 loc) · 5.76 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Jade verify</title>
<link rel="stylesheet" href="./lib/main.css" />
<link rel="stylesheet" href="./lib/bootstrap/css/bootstrap.min.css" />
<script src="./lib/GoogleAnalytics.js"></script>
<script src="./lib/vue.min.js"></script>
<script src="./lib/crypto-js.js"></script>
<script src="./lib/tools.js"></script>
<script src="./lib/utils.js"></script>
</head>
<body>
<div id="app" class="main">
<h1 class="text-center pb-5">Jade verify</h1>
<p>
Starting from {{ localTimeString }},
the hash algorithm for Jade has been updated.
</p>
<p>
As a result, this verification page can only be used to validate Jade game results generated after {{
localTimeString }}.
</p>
<p>
If you need to verify game results from before {{ localTimeString }}, please visit:
<a :href="`./jade.html?s=${server_seed}&c=${client_seed}&n=nonce&he=4&m=0`">here</a>
</p>
<hr />
<form class="py-5">
<h2 class="text-center">Input</h2>
<div class="form-group">
<input :value="server_seed" @change="server_seed = $event.target.value" class="form-control"
placeholder="Server Seed" />
</div>
<div class="form-group">
<input :value="client_seed" @change="client_seed = $event.target.value" class="form-control"
placeholder="Client Seed" />
</div>
<div class="form-group">
<input :value="nonce" @change="nonce = $event.target.value" class="form-control" placeholder="Nonce" />
</div>
</form>
<hr />
<form class="py-5">
<h2 class="text-center pb-5">Output</h2>
<div class="form-group">
<label>sha256(server_seed)</label>
<input class="form-control" readonly
:value="CryptoJS.SHA256(CryptoJS.enc.Utf8.parse(server_seed)).toString()" />
</div>
<div class="form-group">
<label>hmac_sha256(client_seed:nonce, server_seed)</label>
<input class="form-control" readonly :value="result_hash" />
</div>
</form>
<hr />
<form class="py-5">
<h2 class="text-center pb-5">Final Result</h2>
<span>{{ resultList }}</span>
</form>
</div>
</body>
<script>
let qs = tools.queryString();
var app = new Vue({
el: "#app",
data: {
/** inputs */
client_seed: qs.c || "",
server_seed: qs.s || "",
nonce: parseInt(qs.n) || 0,
count: qs.count || 0,
localTimeString: new Date('2025-07-15T15:00:00+08:00').toLocaleString(undefined, {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
timeZoneName: 'short',
})
},
computed: {
result_hash() {
return CryptoJS.HmacSHA256(
this.client_seed + ":" + this.nonce,
this.server_seed
);
},
result_hash_list() {
return String(this.result_hash);
},
sha256ServerSeed() {
return CryptoJS.SHA256(CryptoJS.enc.Utf8.parse(this.server_seed)).toString();
},
hmacSha256Result() {
return CryptoJS.HmacSHA256(
`${this.client_seed}:${this.nonce}`,
this.server_seed
).toString();
},
resultList() {
return this.getResultList(this.server_seed, this.client_seed, this.nonce, this.count);
},
},
watch: {
"this.gameResult"() {
ga("send", "event", "Color", "verify", this.server_seed, {
metric0: this.client_seed,
metric1: this.nonce,
});
},
},
methods: {
getResultList(serverSeed, clientSeed, nonce, count) {
const results = [];
for (let round = 0; round < count; round++) {
const result = this.getResult(serverSeed, clientSeed, nonce, round);
results.push(result);
}
return results;
},
getResult(serverSeed, clientSeed, nonce, round) {
const BASE_RANGE = 1000000;
const key = `${clientSeed}:${nonce}:${round}`;
const hash = this.hmacSHA256(key, serverSeed);
return Math.floor(slideWindowNumber(hash, BASE_RANGE));
},
hmacSHA256(key, seed) {
const res = CryptoJS.HmacSHA256(key, seed).toString(CryptoJS.enc.Hex);
return res;
},
slideWindowNumber(hash, events) {
const index = parseInt(hash.substring(0, 15), 16) % 47;
return this.calNumberFromIndex(hash, index, events);
},
calNumberFromIndex(hash, beginIndex, events) {
const MAX_BORDER = 1.0 / Math.pow(2, 53);
const safeIndex = Math.min(hash.length - 14, beginIndex);
const num = parseInt(hash.substring(safeIndex, safeIndex + 14), 16) >> 3;
const normalized = num * MAX_BORDER;
return Math.floor(normalized * events);
}
},
});
</script>
</html>