-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
609 lines (508 loc) · 30.2 KB
/
Copy pathindex.html
File metadata and controls
609 lines (508 loc) · 30.2 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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tor Hidden Service Setup - RanchiMall</title>
<link rel="shortcut icon" href="assets/messenger-favicon_1.png" type="image/png">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/main.min.css">
<script src="scripts/lib.min.js"></script>
<script src="scripts/floCrypto.js"></script>
<script src="scripts/components.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/tweetnacl@1.0.3/nacl.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-sha3@0.8.0/build/sha3.min.js"></script>
<style>
.instructions-list li {
margin-bottom: 1rem;
line-height: 1.6;
}
.code-block {
background: #1e1e1e;
padding: 1rem;
border-radius: 6px;
font-family: monospace;
overflow-x: auto;
color: #d4d4d4;
margin-top: 0.5rem;
font-size: 0.9rem;
}
.code-inline {
background: #1e1e1e;
padding: 0.2rem 0.4rem;
border-radius: 4px;
font-family: monospace;
color: #d4d4d4;
font-size: 0.9em;
}
</style>
</head>
<body data-theme="dark">
<div id="secondary_pages" class="page">
<header class="flex align-center gap-1 space-between" style="padding: 1rem 2rem;">
<div class="app-brand flex align-center gap-1">
<svg id="main_logo" class="icon" viewBox="0 0 27.25 32" style="width:32px; height:32px; fill: white;">
<title>RanchiMall</title>
<path d="M27.14,30.86c-.74-2.48-3-4.36-8.25-6.94a20,20,0,0,1-4.2-2.49,6,6,0,0,1-1.25-1.67,4,4,0,0,1,0-2.26c.37-1.08.79-1.57,3.89-4.55a11.66,11.66,0,0,0,3.34-4.67,6.54,6.54,0,0,0,.05-2.82C20,3.6,18.58,2,16.16.49c-.89-.56-1.29-.64-1.3-.24a3,3,0,0,1-.3.72l-.3.55L13.42.94C13,.62,12.4.26,12.19.15c-.4-.2-.73-.18-.72.05a9.39,9.39,0,0,1-.61,1.33s-.14,0-.27-.13C8.76.09,8-.27,8,.23A11.73,11.73,0,0,1,6.76,2.6C4.81,5.87,2.83,7.49.77,7.49c-.89,0-.88,0-.61,1,.22.85.33.92,1.09.69A5.29,5.29,0,0,0,3,8.33c.23-.17.45-.29.49-.26a2,2,0,0,1,.22.63A1.31,1.31,0,0,0,4,9.34a5.62,5.62,0,0,0,2.27-.87L7,8l.13.55c.19.74.32.82,1,.65a7.06,7.06,0,0,0,3.46-2.47l.6-.71-.06.64c-.17,1.63-1.3,3.42-3.39,5.42L6.73,14c-3.21,3.06-3,5.59.6,8a46.77,46.77,0,0,0,4.6,2.41c.28.13,1,.52,1.59.87,3.31,2,4.95,3.92,4.95,5.93a2.49,2.49,0,0,0,.07.77h0c.09.09,0,.1.9-.14a2.61,2.61,0,0,0,.83-.32,3.69,3.69,0,0,0-.55-1.83A11.14,11.14,0,0,0,17,26.81a35.7,35.7,0,0,0-5.1-2.91C9.37,22.64,8.38,22,7.52,21.17a3.53,3.53,0,0,1-1.18-2.48c0-1.38.71-2.58,2.5-4.23,2.84-2.6,3.92-3.91,4.67-5.65a3.64,3.64,0,0,0,.42-2A3.37,3.37,0,0,0,13.61,5l-.32-.74.29-.48c.17-.27.37-.63.46-.8l.15-.3.44.64a5.92,5.92,0,0,1,1,2.81,5.86,5.86,0,0,1-.42,1.94c0,.12-.12.3-.15.4a9.49,9.49,0,0,1-.67,1.1,28,28,0,0,1-4,4.29C8.62,15.49,8.05,16.44,8,17.78a3.28,3.28,0,0,0,1.11,2.76c.95,1,2.07,1.74,5.25,3.32,3.64,1.82,5.22,2.9,6.41,4.38A4.78,4.78,0,0,1,21.94,31a3.21,3.21,0,0,0,.14.92,1.06,1.06,0,0,0,.43-.05l.83-.22.46-.12-.06-.46c-.21-1.53-1.62-3.25-3.94-4.8a37.57,37.57,0,0,0-5.22-2.82A13.36,13.36,0,0,1,11,21.19a3.36,3.36,0,0,1-.8-4.19c.41-.85.83-1.31,3.77-4.15,2.39-2.31,3.43-4.13,3.43-6a5.85,5.85,0,0,0-2.08-4.29c-.23-.21-.44-.43-.65-.65A2.5,2.5,0,0,1,15.27.69a10.6,10.6,0,0,1,2.91,2.78A4.16,4.16,0,0,1,19,6.16a4.91,4.91,0,0,1-.87,3c-.71,1.22-1.26,1.82-4.27,4.67a9.47,9.47,0,0,0-2.07,2.6,2.76,2.76,0,0,0-.33,1.54,2.76,2.76,0,0,0,.29,1.47c.57,1.21,2.23,2.55,4.65,3.73a32.41,32.41,0,0,1,5.82,3.24c2.16,1.6,3.2,3.16,3.2,4.8a1.94,1.94,0,0,0,.09.76,4.54,4.54,0,0,0,1.66-.4C27.29,31.42,27.29,31.37,27.14,30.86ZM6.1,7h0a3.77,3.77,0,0,1-1.46.45L4,7.51l.68-.83a25.09,25.09,0,0,0,3-4.82A12,12,0,0,1,8.28.76c.11-.12.77.32,1.53,1l.63.58-.57.84A10.34,10.34,0,0,1,6.1,7Zm5.71-1.78A9.77,9.77,0,0,1,9.24,7.18h0a5.25,5.25,0,0,1-1.17.28l-.58,0,.65-.78a21.29,21.29,0,0,0,2.1-3.12c.22-.41.42-.76.44-.79s.5.43.9,1.24L12,5ZM13.41,3a2.84,2.84,0,0,1-.45.64,11,11,0,0,1-.9-.91l-.84-.9.19-.45c.34-.79.39-.8,1-.31A9.4,9.4,0,0,1,13.8,2.33q-.18.34-.39.69Z" />
</svg>
<div class="app-name">
<div class="app-name__company">RanchiMall</div>
<h4 class="app-name__title">Tor Keys Generator</h4>
</div>
</div>
</header>
<div id="landing" class="grid inner-page" style="height: 100%; overflow-y: auto;">
<div class="left" style="padding-top: 2rem;">
<div class="flex" style="gap: 1rem; margin-bottom: 2rem;">
<button id="tab_generate" class="button button--primary" style="flex: 1;" onclick="switchTab('generate')">Generate</button>
<button id="tab_recover" class="button" style="flex: 1; background: rgba(255,255,255,0.1);" onclick="switchTab('recover')">Recover</button>
</div>
<div id="view_generate">
<p style="margin-bottom: 1.5rem;">Generate a fresh FLO Private Key and automatically configure your Tor Hidden Service.</p>
<button id="btn_generate_new" class="button button--primary w-100" onclick="handleGenerateNewKeys()">Generate New Keys</button>
<div id="new_keys_display" style="display: none; margin-top: 2rem;">
<section class="grid gap-1-5">
<div id="flo_id_warning" class="flex gap-1" style="padding: 1.5rem; background-color: rgba(255, 193, 7, 0.1); color: #ffc107; border-radius: 0.5rem; align-items: flex-start;">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#ffc107" style="flex-shrink: 0; height: 1.5rem; width: 1.5rem;">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z" />
</svg>
<div class="grid gap-0-5">
<strong>
<h3 style="margin: 0; font-size: 1.1rem; color: #ffc107;"> Keep your keys safe! </h3>
</strong>
<p style="margin: 0; font-size: 0.9rem; color: #ffc107; opacity: 0.9;">Don't share with anyone. Once lost private key can't be recovered.</p>
</div>
</div>
<div class="grid gap-1-5 generated-keys-wrapper" style="padding: 1.5rem; background-color: rgba(255, 255, 255, 0.03); border-radius: 0.5rem; border: 1px solid rgba(255,255,255,0.1);">
<div class="grid gap-0-5">
<h5 style="margin: 0; opacity: 0.8; font-size: 0.9rem; font-weight: normal;">FLO address</h5>
<sm-copy id="new_flo_address" value=""></sm-copy>
</div>
<div class="grid gap-0-5">
<h5 style="margin: 0; opacity: 0.8; font-size: 0.9rem; font-weight: normal;">Private key</h5>
<sm-copy id="new_flo_wif" value=""></sm-copy>
</div>
</div>
<button id="btn_generate_tor" class="button button--primary w-100" onclick="handleGenerateTorWithNewKeys()" style="margin-top: 0.5rem;">Generate Tor Configuration</button>
</section>
</div>
</div>
<div id="view_recover" style="display: none;">
<p style="margin-bottom: 2rem;">Enter your WIF private key to deterministically recover and download your Tor v3 Onion address and key files.</p>
<sm-form id="tor_form">
<sm-input id="wif_input" class="password-field" type="password" placeholder="Enter WIF Private Key" required>
<label slot="right" class="interact">
<input type="checkbox" class="hidden" autocomplete="off" readonly onchange="togglePrivateKeyVisibility(this)">
<svg class="icon invisible" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000">
<path d="M0 0h24v24H0zm0 0h24v24H0zm0 0h24v24H0zm0 0h24v24H0z" fill="none" />
<path d="M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z" />
</svg>
<svg class="icon visible" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" />
</svg>
</label>
</sm-input>
<button id="submit_button" class="button button--primary w-100" type="submit" onclick="generateAndDownload(event)" style="margin-top: 1rem;">Recover & Download Keys</button>
</sm-form>
</div>
<div id="error_message" style="color: #ff5252; margin-top: 1rem; text-align: center; display: none;"></div>
<div id="result_section" style="display: none; margin-top: 2rem;">
<div class="grid gap-0-5" style="margin-bottom: 2rem;">
<b>Your Onion Address</b>
<sm-copy id="onion_address_display" value=""></sm-copy>
</div>
<h4 style="margin-top: 1rem; margin-bottom: 1rem;">Automated Setup Scripts</h4>
<p style="opacity: 0.8; margin-bottom: 1rem;">Choose your Operating System to download an automated setup script that installs Tor and configures your keys instantly.</p>
<div class="grid gap-1" style="grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));">
<button class="button button--primary" onclick="downloadOsScript('linux')">Linux (.sh)</button>
<button class="button button--primary" onclick="downloadOsScript('mac')">Mac OS (.sh)</button>
<button class="button button--primary" onclick="downloadOsScript('windows')">Windows (.bat)</button>
</div>
<div style="margin-top: 2rem; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 1.5rem;">
<h4 style="margin-bottom: 0.5rem;">Manual Configuration</h4>
<p style="opacity: 0.8; margin-bottom: 1rem; font-size: 0.9rem;">Download only your raw Tor keys to configure everything yourself.</p>
<button class="button" style="background: rgba(255,255,255,0.1);" onclick="downloadRawKeys()">Download Backup Keys</button>
</div>
</div>
</div>
<div id="landing_illustration" class="right flex flex-direction-column gap-2 align-center justify-center text-center">
<img src="assets/message-background.svg" alt="Illustration" style="max-width: 80%;">
<p class="title-font" style="margin-top: 1rem; font-size: 1.1rem; color: rgba(255,255,255,0.8);">Secure, Private and Reliable.</p>
</div>
</div>
</div>
<script>
function togglePrivateKeyVisibility(checkbox) {
const input = checkbox.closest('sm-input');
const type = checkbox.checked ? 'text' : 'password';
input.setAttribute('type', type);
}
function switchTab(tab) {
const btnGen = document.getElementById('tab_generate');
const btnRec = document.getElementById('tab_recover');
const viewGen = document.getElementById('view_generate');
const viewRec = document.getElementById('view_recover');
const resultSection = document.getElementById('result_section');
const errorMsg = document.getElementById('error_message');
resultSection.style.display = 'none';
errorMsg.style.display = 'none';
if (tab === 'generate') {
btnGen.classList.add('button--primary');
btnGen.style.background = '';
btnRec.classList.remove('button--primary');
btnRec.style.background = 'rgba(255,255,255,0.1)';
viewGen.style.display = 'block';
viewRec.style.display = 'none';
} else {
btnRec.classList.add('button--primary');
btnRec.style.background = '';
btnGen.classList.remove('button--primary');
btnGen.style.background = 'rgba(255,255,255,0.1)';
viewRec.style.display = 'block';
viewGen.style.display = 'none';
}
}
async function handleGenerateNewKeys() {
try {
// generateNewID creates { floID, pubKey, privKey (which is the WIF) }
const newIdentity = floCrypto.generateNewID();
// Display the new keys
document.getElementById('new_keys_display').style.display = 'block';
document.getElementById('new_flo_address').setAttribute('value', newIdentity.floID);
document.getElementById('new_flo_wif').setAttribute('value', newIdentity.privKey);
// Remove automatic generation so user can read their keys first.
// Hide the main "Generate New Keys" button to reduce confusion
document.getElementById('btn_generate_new').style.display = 'none';
} catch (error) {
console.error(error);
const errorMsg = document.getElementById('error_message');
errorMsg.textContent = "Failed to generate new keys. Please try again.";
errorMsg.style.display = 'block';
}
}
async function handleGenerateTorWithNewKeys() {
try {
// Fetch the generated WIF from the UI component
const wif = document.getElementById('new_flo_wif').getAttribute('value');
if (!wif) throw new Error("No WIF generated yet.");
await processWIFForTor(wif);
} catch (error) {
console.error(error);
const errorMsg = document.getElementById('error_message');
errorMsg.textContent = error.message;
errorMsg.style.display = 'block';
}
}
function convertWIFtoTOR(wif) {
try {
const hexToBytes = (hex) => {
const bytes = new Uint8Array(hex.length / 2);
for (let i = 0; i < hex.length; i += 2) {
bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
}
return bytes;
};
// 1. WIF -> 32-byte seed
const decoded = Bitcoin.Base58.decode(wif);
const keyWithVersion = decoded.slice(0, decoded.length - 4);
let key = keyWithVersion.slice(1);
if (key.length >= 33 && key[key.length - 1] === 0x01) {
key = key.slice(0, key.length - 1);
}
let privKeyHex = '';
for (let i = 0; i < key.length; i++) {
privKeyHex += key[i].toString(16).padStart(2, '0');
}
const seed = hexToBytes(privKeyHex.substring(0, 64));
// 2. Expand the seed using SHA-512 (Tor protocol style)
const hash = nacl.hash(seed); // Returns 64-byte Uint8Array
const secretScalar = hash.slice(0, 32);
const rightHalfRH = hash.slice(32, 64);
// 3. "Clamp" the secret scalar (Ed25519 standard requirement)
secretScalar[0] &= 248;
secretScalar[31] &= 127;
secretScalar[31] |= 64;
// 4. Derive Public Key from the Clamped Secret Scalar
const kp = nacl.sign.keyPair.fromSeed(seed);
const publicKey = kp.publicKey;
// 5. Corrected Tor headers
const secretHeader = new Uint8Array([
0x3d,0x3d,0x20,0x65, 0x64,0x32,0x35,0x35,
0x31,0x39,0x76,0x31, 0x2d,0x73,0x65,0x63,
0x72,0x65,0x74,0x3a, 0x20,0x74,0x79,0x70,
0x65,0x30,0x20,0x3d, 0x3d,0x00,0x00,0x00
]);
const publicHeader = new Uint8Array([
0x3d,0x3d,0x20,0x65, 0x64,0x32,0x35,0x35,
0x31,0x39,0x76,0x31, 0x2d,0x70,0x75,0x62,
0x6c,0x69,0x63,0x3a, 0x20,0x74,0x79,0x70,
0x65,0x30,0x20,0x3d, 0x3d,0x00,0x00,0x00
]);
// 6. Build genuine Tor secret file layout
const secretFile = new Uint8Array(96);
secretFile.set(secretHeader, 0);
secretFile.set(secretScalar, 32);
secretFile.set(rightHalfRH, 64);
// 7. Build Tor public file layout
const publicFile = new Uint8Array(64);
publicFile.set(publicHeader, 0);
publicFile.set(publicKey, 32);
// 8. Generate Onion address
const alphabet = "abcdefghijklmnopqrstuvwxyz234567";
const prefix = new TextEncoder().encode(".onion checksum");
const version = new Uint8Array([0x03]);
const checksumInput = new Uint8Array(prefix.length + publicKey.length + version.length);
checksumInput.set(prefix, 0);
checksumInput.set(publicKey, prefix.length);
checksumInput.set(version, prefix.length + publicKey.length);
// SHA3-256 (requires js-sha3 library)
const hashHex = sha3_256(checksumInput);
const checksum = new Uint8Array([
parseInt(hashHex.substring(0, 2), 16),
parseInt(hashHex.substring(2, 4), 16)
]);
const onionBytes = new Uint8Array(publicKey.length + checksum.length + version.length);
onionBytes.set(publicKey, 0);
onionBytes.set(checksum, publicKey.length);
onionBytes.set(version, publicKey.length + checksum.length);
let bits = 0;
let value = 0;
let output = "";
for (const b of onionBytes) {
value = (value << 8) | b;
bits += 8;
while (bits >= 5) {
output += alphabet[(value >>> (bits - 5)) & 31];
bits -= 5;
}
}
if (bits > 0) {
output += alphabet[(value << (5 - bits)) & 31];
}
const onionAddress = output.toLowerCase() + ".onion";
return {
address: onionAddress,
secretFile: secretFile,
publicFile: publicFile
};
} catch (e) {
console.error(e);
throw new Error("Invalid WIF format or conversion error.");
}
}
function arrayBufferToBase64(buffer) {
let binary = '';
const bytes = new Uint8Array(buffer);
const len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
function downloadBinary(filename, bytes) {
const blob = new Blob([bytes], { type: "application/octet-stream" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.click();
setTimeout(() => URL.revokeObjectURL(url), 1000);
}
function downloadText(filename, text) {
const blob = new Blob([text], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.click();
setTimeout(() => URL.revokeObjectURL(url), 1000);
}
let generatedScripts = {};
let generatedKeys = {};
function downloadOsScript(os) {
if (!generatedScripts[os]) return;
downloadText(generatedScripts[os].filename, generatedScripts[os].content);
}
function downloadRawKeys() {
if (!generatedKeys.address) return;
downloadBinary("hs_ed25519_secret_key", generatedKeys.secretFile);
setTimeout(() => downloadBinary("hs_ed25519_public_key", generatedKeys.publicFile), 500);
setTimeout(() => downloadText("hostname", generatedKeys.address), 1000);
}
async function processWIFForTor(wifInput) {
const errorElement = document.getElementById("error_message");
const resultSection = document.getElementById("result_section");
const onionDisplay = document.getElementById("onion_address_display");
const submitButton = document.getElementById("submit_button");
errorElement.style.display = "none";
resultSection.style.display = "none";
submitButton.disabled = true;
submitButton.textContent = "Processing...";
try {
// Yield thread to allow UI to update
await new Promise(resolve => setTimeout(resolve, 100));
const torKeys = convertWIFtoTOR(wifInput);
onionDisplay.setAttribute('value', torKeys.address);
onionDisplay.value = torKeys.address; // ensure web component updates
resultSection.style.display = "block";
const secretBase64 = arrayBufferToBase64(torKeys.secretFile);
const publicBase64 = arrayBufferToBase64(torKeys.publicFile);
// Store keys for manual download
generatedKeys = torKeys;
// 1. Linux Script
generatedScripts['linux'] = {
filename: 'setup_tor_linux.sh',
content: `#!/bin/bash
# RanchiMall Tor Hidden Service Automated Setup for Linux
# Generated for: ${torKeys.address}
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root (e.g. sudo bash setup_tor_linux.sh)"
exit 1
fi
echo "Installing Tor if not present..."
apt update && apt install -y tor
echo "Configuring Hidden Service directories..."
mkdir -p /var/lib/tor/myservice/
chmod 700 /var/lib/tor/myservice/
echo "Installing deterministic Tor keys..."
echo "${secretBase64}" | base64 -d > /var/lib/tor/myservice/hs_ed25519_secret_key
echo "${publicBase64}" | base64 -d > /var/lib/tor/myservice/hs_ed25519_public_key
echo "${torKeys.address}" > /var/lib/tor/myservice/hostname
chown -R debian-tor:debian-tor /var/lib/tor/myservice/
chmod 600 /var/lib/tor/myservice/hs_ed25519_secret_key
echo "Updating Tor configuration..."
if ! grep -q "HiddenServiceDir /var/lib/tor/myservice/" /etc/tor/torrc; then
echo "" >> /etc/tor/torrc
echo "HiddenServiceDir /var/lib/tor/myservice/" >> /etc/tor/torrc
echo "HiddenServicePort 80 127.0.0.1:8765" >> /etc/tor/torrc
fi
echo "Restarting Tor daemon..."
systemctl restart tor
echo "---------------------------------------------------------"
echo "Tor Hidden Service is LIVE!"
echo "Your Onion Address: ${torKeys.address}"
echo "---------------------------------------------------------"
`
};
// 2. Mac Script
generatedScripts['mac'] = {
filename: 'setup_tor_mac.sh',
content: `#!/bin/bash
# RanchiMall Tor Hidden Service Automated Setup for MacOS
# Generated for: ${torKeys.address}
echo "Checking for Homebrew..."
if ! command -v brew &> /dev/null; then
echo "Homebrew is required. Please install it from https://brew.sh/"
exit 1
fi
echo "Installing Tor via Homebrew..."
brew install tor
TOR_DIR="$(brew --prefix)/var/tor/myservice"
TORRC="$(brew --prefix)/etc/tor/torrc"
echo "Configuring Hidden Service directories..."
mkdir -p "$TOR_DIR"
chmod 700 "$TOR_DIR"
echo "Installing deterministic Tor keys..."
echo "${secretBase64}" | base64 -d > "$TOR_DIR/hs_ed25519_secret_key"
echo "${publicBase64}" | base64 -d > "$TOR_DIR/hs_ed25519_public_key"
echo "${torKeys.address}" > "$TOR_DIR/hostname"
chmod 600 "$TOR_DIR/hs_ed25519_secret_key"
echo "Updating Tor configuration..."
if ! grep -q "HiddenServiceDir $TOR_DIR" "$TORRC"; then
echo "" >> "$TORRC"
echo "HiddenServiceDir $TOR_DIR" >> "$TORRC"
echo "HiddenServicePort 80 127.0.0.1:8765" >> "$TORRC"
fi
echo "Restarting Tor service..."
brew services restart tor
echo "---------------------------------------------------------"
echo "Tor Hidden Service is LIVE!"
echo "Your Onion Address: ${torKeys.address}"
echo "---------------------------------------------------------"
`
};
// 3. Windows Script
generatedScripts['windows'] = {
filename: 'setup_tor_windows.bat',
content: `@echo off
setlocal
echo RanchiMall Tor Hidden Service Automated Setup for Windows
echo.
set TOR_DIR=%CD%\\tor-expert
set MY_SERVICE=%TOR_DIR%\\myservice
if not exist "%TOR_DIR%\\tor\\tor.exe" (
echo Downloading Tor Expert Bundle...
curl -# -L -o tor.tar.gz "https://archive.torproject.org/tor-package-archive/torbrowser/13.0.15/tor-expert-bundle-windows-x86_64-13.0.15.tar.gz"
echo Extracting Tor...
mkdir "%TOR_DIR%"
tar -xf tor.tar.gz -C "%TOR_DIR%"
del tor.tar.gz
)
echo Configuring Hidden Service directories...
mkdir "%MY_SERVICE%" 2>nul
echo Installing deterministic Tor keys...
powershell -Command "[IO.File]::WriteAllBytes('%MY_SERVICE%\\hs_ed25519_secret_key', [Convert]::FromBase64String('${secretBase64}'))"
powershell -Command "[IO.File]::WriteAllBytes('%MY_SERVICE%\\hs_ed25519_public_key', [Convert]::FromBase64String('${publicBase64}'))"
echo ${torKeys.address} > "%MY_SERVICE%\\hostname"
echo Updating Tor configuration...
set TORRC=%TOR_DIR%\\torrc
echo HiddenServiceDir %MY_SERVICE% > "%TORRC%"
echo HiddenServicePort 80 127.0.0.1:8765 >> "%TORRC%"
echo.
echo ---------------------------------------------------------
echo Tor Hidden Service is LIVE!
echo Your Onion Address: ${torKeys.address}
echo ---------------------------------------------------------
"%TOR_DIR%\\tor\\tor.exe" -f "%TORRC%"
`
};
// Remove automatic downloads to prevent blocking. User will click the buttons.
} catch (e) {
const errorElement = document.getElementById("error_message");
errorElement.textContent = e.message;
errorElement.style.display = "block";
} finally {
const submitButton = document.getElementById("submit_button");
submitButton.disabled = false;
submitButton.textContent = "Recover & Download Keys";
}
}
async function generateAndDownload(event) {
event.preventDefault();
const wifInput = document.getElementById("wif_input").value.trim();
await processWIFForTor(wifInput);
}
// Handle copy events from sm-copy components (Fallback + Notifications)
document.addEventListener('copy', (e) => {
if (e.target && e.target.tagName === 'SM-COPY') {
const textToCopy = e.target.value;
const notificationDrawer = document.getElementById('notification_drawer');
// Fallback copying method
const textArea = document.createElement("textarea");
textArea.value = textToCopy;
textArea.style.position = "fixed";
textArea.style.left = "-9999px";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
if (notificationDrawer && typeof notificationDrawer.push === 'function') {
notificationDrawer.push("Copied to clipboard");
}
} catch (err) {
console.error('Fallback copy failed', err);
if (notificationDrawer && typeof notificationDrawer.push === 'function') {
notificationDrawer.push("Failed to copy");
}
}
document.body.removeChild(textArea);
}
});
</script>
<sm-notifications id="notification_drawer"></sm-notifications>
</body>
</html>