-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBTC.html
More file actions
353 lines (303 loc) · 9.21 KB
/
Copy pathBTC.html
File metadata and controls
353 lines (303 loc) · 9.21 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
<!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>
<script src="elliptic.min.js"></script>
<script src="crypto-js.min.js"></script>
<script src="ripemd160.min.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">
<h2>BTC随机私钥生成,在线查询!</h2>
<!-- 手动输入区域 -->
<div class="input-group">
<label for="privateKeyInput">手动输入私钥(HEX格式):</label>
<input
type="text"
id="privateKeyInput"
placeholder="请输入64位十六进制私钥"
maxlength="64"
autocomplete="off"
/>
<div id="inputError" class="error-message"></div>
<button onclick="handleManualKey()" style="margin-top: 10px;">导入私钥</button>
</div>
<p>
<button onclick="generateRandom()">随机生成</button>
<button onclick="queryBalance()">查询余额</button>
<div class="result-box">
<div>
<strong>私钥 (HEX):</strong>
<div class="result-value" id="privateKey"></div>
</div>
<p>
<div>
<strong>比特币地址:</strong>
<div class="result-value" id="address"></div>
</div>
</div>
</div>
<script>
// 初始化椭圆曲线
const ec = new elliptic.ec('secp256k1')
// 基础函数保持不变
function base58Encode(bytes) {
const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
let bigInt = BigInt('0x' + Array.from(bytes)
.map(b => b.toString(16).padStart(2, '0'))
.join(''))
let result = ""
while (bigInt > 0n) {
const mod = bigInt % 58n
result = alphabet[Number(mod)] + result
bigInt = bigInt / 58n
}
for (let i = 0; i < bytes.length; i++) {
if (bytes[i] !== 0) break
result = '1' + result
}
return result
}
function hexToBytes(hex) {
const bytes = new Uint8Array(hex.length / 2)
for (let i = 0; i < hex.length; i += 2) {
bytes[i/2] = parseInt(hex.substr(i, 2), 16)
}
return bytes
}
function bytesToHex(bytes) {
return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('')
}
function hash160(pubKeyBytes) {
const sha256Hash = CryptoJS.SHA256(CryptoJS.lib.WordArray.create(pubKeyBytes))
const ripeHash = CryptoJS.RIPEMD160(sha256Hash)
return hexToBytes(ripeHash.toString())
}
function sha256x2(buffer) {
const first = CryptoJS.SHA256(CryptoJS.lib.WordArray.create(buffer))
const second = CryptoJS.SHA256(first)
return hexToBytes(second.toString()).slice(0, 4)
}
// 地址生成函数(修复作用域问题)
function getAddress(privateKeyHex) {
if (!/^[0-9a-f]{64}$/.test(privateKeyHex)) {
throw new Error("无效的私钥格式")
}
const keyPair = ec.keyFromPrivate(privateKeyHex, 'hex')
const pubKeyCompressed = keyPair.getPublic().encode('hex', true)
const pubKeyBytes = hexToBytes(pubKeyCompressed)
const hash160Bytes = hash160(pubKeyBytes)
const version = new Uint8Array([0x00])
const payload = new Uint8Array([...version, ...hash160Bytes])
const checksum = sha256x2(payload)
const addressBytes = new Uint8Array([...payload, ...checksum])
return base58Encode(addressBytes)
}
// 处理手动输入
function handleManualKey() {
const errorElement = document.getElementById('inputError')
errorElement.style.display = 'none'
const input = document.getElementById('privateKeyInput').value
.trim()
.toLowerCase()
.replace(/[^a-f0-9]/g, '')
if (input.length !== 64) {
errorElement.textContent = '无效的私钥:必须为64位十六进制字符'
errorElement.style.display = 'block'
return
}
try {
document.getElementById('privateKey').textContent = input
const address = getAddress(input)
document.getElementById('address').textContent = address
} catch (error) {
errorElement.textContent = '地址生成错误:' + error.message
errorElement.style.display = 'block'
}
}
// 随机生成功能(修复后的版本)
function generateRandom() {
try {
const privateKeyBytes = new Uint8Array(32)
window.crypto.getRandomValues(privateKeyBytes)
const privateKeyHex = bytesToHex(privateKeyBytes)
document.getElementById("privateKey").textContent = privateKeyHex
document.getElementById("address").textContent = getAddress(privateKeyHex)
document.getElementById('inputError').style.display = 'none'
} catch (error) {
document.getElementById('inputError').textContent = "生成错误: " + error.message
document.getElementById('inputError').style.display = 'block'
}
}
// 余额查询功能
function queryBalance() {
const address = document.getElementById('address').textContent
if (!address) {
alert('请先生成钱包地址')
return
}
window.open(`https://www.oklink.com/zh-hans/btc/address/${address}`, '_blank')
}
</script>
</body>
</html>