-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDLCX.html
368 lines (294 loc) · 9.47 KB
/
DLCX.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
<!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" />
<title>区块链私钥碰撞</title>
<script src="1.js"></script>
<script src="2.js"></script>
<link
rel="stylesheet"
href="3.css"
/>
<style>
body {
font-family: "Arial", sans-serif;
background: linear-gradient(135deg, #ffffff, #6dd5fa, #2980b9);
padding: 50px 0;
overflow-x: hidden;
background-attachment: fixed;
background-size: cover;
}
.container {
max-width: 650px;
margin: 0 auto;
background-color: #ffffff;
padding: 30px;
box-shadow: 0 15px 25px rgba(0, 0, 0, 0.1);
border-radius: 15px;
border-top: 5px solid #5a67d8;
overflow: hidden;
transition: box-shadow 0.3s;
}
.container:hover {
box-shadow: 0 20px 30px rgba(0, 0, 0, 0.15);
}
.operation {
border-bottom: 2px solid rgba(226, 232, 240, 0.5);
padding-bottom: 20px;
margin-bottom: 20px;
position: relative;
}
.operation:last-child {
border-bottom: none;
margin-bottom: 0;
}
h3 {
color: #2c3e50;
margin-bottom: 20px;
font-size: 24px;
position: relative;
}
h3:after {
content: "";
position: absolute;
bottom: 0;
left: 0;
height: 3px;
width: 70px;
background: linear-gradient(135deg, #5a67d8, #8e44ad);
}
label {
font-weight: bold;
display: block;
margin-bottom: 10px; /* 调整外边距 */
color: #4a5568;
}
input[type="text"] {
width: 100%;
padding: 12px;
margin-bottom: 15px; /* 调整外边距 */
border: 2px solid #cbd5e0;
border-radius: 10px;
transition: border-color 0.3s, box-shadow 0.3s;
}
input[type="text"]:focus {
border-color: #8e44ad;
box-shadow: 0 0 8px rgba(142, 68, 173, 0.3);
outline: none;
}
button {
background: linear-gradient(135deg, #5a67d8, #8e44ad);
color: #fff;
padding: 12px 24px;
border: none;
border-radius: 50px;
cursor: pointer;
transition: background-color 0.3s, transform 0.3s, box-shadow 0.3s;
position: relative;
overflow: hidden;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}
button:before {
content: "";
position: absolute;
top: 0;
left: -50%;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.15);
transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
}
button:hover:before {
left: 150%;
}
#message {
color: #e53e3e;
margin-bottom: 15px;
margin-top: 15px;
padding: 10px;
background-color: #fed7d7;
border-radius: 8px;
border-left: 5px solid #e53e3e;
display: none;
transition: opacity 0.3s, transform 0.3s;
transform: translateY(20px);
}
.result-container {
padding: 20px 25px;
border: 1px solid #ddd;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.05);
border-radius: 10px;
margin-top: 20px;
background-color: rgba(245, 245, 245, 0.9);
opacity: 0;
transform: translateY(20px);
transition: opacity 0.3s, transform 0.3s;
margin-bottom: 20px;
display: none;
}
#result {
display: none;
opacity: 0;
transform: translateY(20px);
}
.result-list {
list-style-type: none;
padding: 0;
margin: 0;
}
.result-item {
}
.result-label {
font-weight: bold;
font-size: 15px;
color: #333;
}
.result-value {
font-size: 14px;
color: #555;
word-wrap: break-word;
}
a {
color: #5a67d8;
text-decoration: none;
}
a:hover {
text-decoration: underline;
color: #8e44ad;
}
</style>
</head>
<body>
<div class="container">
<div class="operation">
<h3>随机生成私钥</h3>
<label for="privateKey">输入私钥:</label>
<input type="text" id="privateKey" name="privateKey" />
<button id="deriveAddressBtn" onclick="deriveAddressFromPrivateKey()">
生成地址
</button>
<div id="message"></div>
<div class="result-container" id="result">
<ul class="result-list">
<li class="result-item">
<strong class="result-label">Address:</strong>
<span class="result-value" id="addressDisplay"></span>
</li>
<li class="result-item">
<strong class="result-label">Private Key:</strong>
<span class="result-value" id="privateKeyDisplay"></span>
</li>
</ul>
</div>
<a id="etherscanLink" href="#" style="display: none" target="_blank">
点击查看详情
</a>
</div>
<div class="operation">
<h3>生成随机私钥地址</h3>
<button
id="generateRandomBtn"
onclick="generateRandomPrivateKeyAndAddress()"
>
随机私钥生成
</button>
</div>
</div>
<script>
const web3 = new Web3();
function deriveAddressFromPrivateKey() {
const privateKeyInputElem = document.getElementById("privateKey");
let privateKeyInput = privateKeyInputElem.value.trim();
if (privateKeyInput === "") {
displayError("Please enter a private key.");
return;
}
if (!privateKeyInput.startsWith("0x")) {
privateKeyInput = "0x" + privateKeyInput;
}
if (privateKeyInput.length !== 66) {
displayError(
"The private key must be 64 characters long (66 with the 0x prefix)."
);
return;
}
const ethAddress = deriveEthereumAddress(privateKeyInput);
displayResult(privateKeyInput, ethAddress);
}
function generateRandomPrivateKeyAndAddress() {
const randomPrivateKey =
"0x" +
Array.from(window.crypto.getRandomValues(new Uint8Array(32)))
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
document.getElementById("privateKey").value = randomPrivateKey;
deriveAddressFromPrivateKey();
}
function deriveEthereumAddress(privateKey) {
const ec = new elliptic.ec("secp256k1");
const publicKey = ec.keyFromPrivate(privateKey.slice(2)).getPublic(); // Remove 0x prefix
// Convert x and y coordinates to bytes
const xBytes = publicKey.getX().toArray("be", 32);
const yBytes = publicKey.getY().toArray("be", 32);
// Concatenate the byte arrays
const concatBytes = new Uint8Array([...xBytes, ...yBytes]);
// Convert bytes to hex string
const concatHex = Array.from(concatBytes)
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
// Hash the concatenated hex string using web3's soliditySha3
const hashed = web3.utils.soliditySha3({
type: "bytes",
value: concatHex,
});
// Take the last 20 bytes of the hash to create the Ethereum address
return "0x" + hashed.slice(-40);
}
function displayError(message) {
const messageElem = document.getElementById("message");
const resultElem = document.getElementById("result");
const etherscanLink = document.getElementById("etherscanLink");
messageElem.innerHTML = message;
messageElem.style.display = "block";
setTimeout(() => {
messageElem.style.opacity = "1";
messageElem.style.transform = "translateY(0)";
}, 10);
// Hide results when displaying an error
resultElem.style.opacity = "0";
resultElem.style.transform = "translateY(20px)";
setTimeout(() => {
resultElem.style.display = "none";
}, 300);
etherscanLink.style.display = "none";
}
function displayResult(privateKey, address) {
document.getElementById("privateKeyDisplay").textContent = privateKey;
document.getElementById("addressDisplay").textContent = address;
const resultElem = document.getElementById("result");
const etherscanLink = document.getElementById("etherscanLink");
const messageElem = document.getElementById("message");
// Hide error message if it was displayed
messageElem.style.opacity = "0";
messageElem.style.transform = "translateY(20px)";
setTimeout(() => {
messageElem.style.display = "none";
}, 300);
resultElem.style.display = "block";
setTimeout(() => {
resultElem.style.opacity = "1";
resultElem.style.transform = "translateY(0)";
}, 10);
etherscanLink.href = `
https://www.oklink.com/zh-hans/multi-search#key=
${address}`;
etherscanLink.style.display = "block";
}
</script>
</body>
</html>