-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathoffline.html
More file actions
1041 lines (893 loc) · 44.9 KB
/
offline.html
File metadata and controls
1041 lines (893 loc) · 44.9 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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Solana Wallet Toolkit (Offline)</title>
<style>
:root {
--bg: #000;
--fg: #fff;
--border: #333;
--muted: #888;
--accent: #9945FF;
}
.light-mode {
--bg: #fff;
--fg: #000;
--border: #ccc;
--muted: #666;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, monospace;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
padding: 1rem;
transition: background 0.2s, color 0.2s;
}
.container { max-width: 800px; margin: 0 auto; }
header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 1rem; }
h1 { font-size: 1.25rem; font-weight: 600; }
.theme-toggle { background: none; border: 1px solid var(--border); color: var(--fg); padding: 0.5rem; cursor: pointer; font-size: 1rem; }
.warning { border: 1px solid var(--border); padding: 0.75rem; margin-bottom: 1rem; font-size: 0.8rem; }
.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.tab { background: none; border: 1px solid var(--border); color: var(--muted); padding: 0.5rem 0.75rem; cursor: pointer; font-size: 0.75rem; transition: all 0.2s; }
.tab:hover { color: var(--fg); }
.tab.active { background: var(--fg); color: var(--bg); }
.panel { display: none; }
.panel.active { display: block; }
.card { border: 1px solid var(--border); padding: 1rem; margin-bottom: 1rem; }
.card-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
label { display: block; margin-bottom: 0.25rem; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; }
input, textarea, select {
width: 100%;
padding: 0.5rem;
border: 1px solid var(--border);
background: var(--bg);
color: var(--fg);
font-family: monospace;
font-size: 0.85rem;
margin-bottom: 0.75rem;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--fg); }
textarea { resize: vertical; min-height: 80px; }
button {
padding: 0.6rem 1rem;
border: 1px solid var(--fg);
background: var(--fg);
color: var(--bg);
font-size: 0.85rem;
font-weight: 600;
cursor: pointer;
transition: all 0.1s;
}
button:hover { opacity: 0.9; }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--bg); color: var(--fg); }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.7rem; }
.btn-group { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 200px; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.checkbox-row input { width: auto; margin: 0; }
.checkbox-row label { margin: 0; text-transform: none; color: var(--fg); }
.result { margin-top: 1rem; padding: 1rem; border: 1px solid var(--border); background: var(--bg); }
.result-title { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; margin-bottom: 0.25rem; }
.result-value { font-family: monospace; font-size: 0.8rem; word-break: break-all; padding: 0.5rem; border: 1px solid var(--border); margin-bottom: 0.75rem; background: var(--bg); }
.status { color: var(--muted); font-size: 0.8rem; margin-top: 0.5rem; }
.success { color: #00ff00; }
.error { color: #ff4444; font-weight: bold; }
.hidden { display: none !important; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.5rem; }
footer { text-align: center; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.7rem; }
footer a { color: var(--fg); }
.lib-status { font-size: 0.7rem; padding: 0.25rem 0.5rem; border-radius: 3px; }
.lib-status.loaded { color: #00ff00; }
.lib-status.error { color: #ff4444; }
@media (max-width: 600px) {
.tabs { gap: 0.15rem; }
.tab { padding: 0.4rem 0.5rem; font-size: 0.65rem; }
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>◎ Solana Wallet Toolkit</h1>
<div style="display: flex; align-items: center; gap: 0.5rem;">
<span id="lib-status" class="lib-status">Loading...</span>
<button class="theme-toggle" onclick="toggleTheme()" title="Toggle theme">◐</button>
</div>
</header>
<div class="warning">
<strong>⚠ OFFLINE USE:</strong> Disconnect from internet before use. Save page (Ctrl+S) for offline access. Never share private keys. Uses official @solana/web3.js only.
</div>
<div class="tabs">
<button class="tab active" data-panel="generate">Generate</button>
<button class="tab" data-panel="vanity">Vanity</button>
<button class="tab" data-panel="restore">Restore</button>
<button class="tab" data-panel="sign">Sign</button>
<button class="tab" data-panel="verify">Verify</button>
<button class="tab" data-panel="validate">Validate</button>
<button class="tab" data-panel="estimate">Estimate</button>
</div>
<!-- GENERATE PANEL -->
<div class="panel active" id="panel-generate">
<div class="card">
<div class="card-title">Generate Random Wallet</div>
<p style="color: var(--muted); font-size: 0.8rem; margin-bottom: 1rem;">
Generates a new Ed25519 keypair using @solana/web3.js Keypair.generate()
</p>
<button onclick="generateWallet()">Generate New Wallet</button>
<div id="generate-result" class="result hidden"></div>
</div>
</div>
<!-- VANITY PANEL -->
<div class="panel" id="panel-vanity">
<div class="card">
<div class="card-title">Vanity Address Generator</div>
<p style="color: var(--muted); font-size: 0.8rem; margin-bottom: 1rem;">
Generate addresses with custom prefixes/suffixes. Solana addresses use Base58 encoding.
</p>
<div class="row">
<div>
<label>Prefix (start of address)</label>
<input type="text" id="vanity-prefix" placeholder="e.g., So1" maxlength="6">
</div>
<div>
<label>Suffix (end of address)</label>
<input type="text" id="vanity-suffix" placeholder="e.g., xyz" maxlength="6">
</div>
</div>
<div class="grid-2" style="margin: 0.75rem 0;">
<div class="checkbox-row">
<input type="checkbox" id="vanity-ignore-case">
<label for="vanity-ignore-case">Case-insensitive</label>
</div>
</div>
<div class="btn-group">
<button id="vanity-btn" onclick="startVanity()">Start Mining</button>
<button class="btn-secondary" onclick="stopVanity()">Stop</button>
</div>
<p class="status" id="vanity-status"></p>
<div id="vanity-result" class="result hidden"></div>
</div>
</div>
<!-- RESTORE PANEL -->
<div class="panel" id="panel-restore">
<div class="card">
<div class="card-title">Restore from Secret Key (JSON Array)</div>
<p style="color: var(--muted); font-size: 0.8rem; margin-bottom: 1rem;">
Paste a Solana CLI compatible keypair JSON (64-byte array)
</p>
<label>Secret Key JSON Array</label>
<textarea id="restore-json" placeholder="[174,47,154,16,202,193,206,113,199,190,53,133,...]"></textarea>
<button onclick="restoreFromJson()">Restore Wallet</button>
<div id="restore-json-result" class="result hidden"></div>
</div>
<div class="card">
<div class="card-title">Restore from Base58 Secret Key</div>
<p style="color: var(--muted); font-size: 0.8rem; margin-bottom: 1rem;">
Enter a Base58-encoded secret key (as exported by some wallets)
</p>
<label>Base58 Secret Key</label>
<input type="text" id="restore-base58" placeholder="Base58 encoded secret key...">
<button onclick="restoreFromBase58()">Restore Wallet</button>
<div id="restore-base58-result" class="result hidden"></div>
</div>
</div>
<!-- SIGN PANEL -->
<div class="panel" id="panel-sign">
<div class="card">
<div class="card-title">Sign Message</div>
<p style="color: var(--muted); font-size: 0.8rem; margin-bottom: 1rem;">
Sign a message using Ed25519 (via @solana/web3.js)
</p>
<label>Message</label>
<textarea id="sign-message" placeholder="Enter message to sign"></textarea>
<label>Secret Key (JSON Array)</label>
<textarea id="sign-key" placeholder="[174,47,154,16,202,193,206,113,199,190,53,133,...]"></textarea>
<button onclick="signMessageAction()">Sign Message</button>
<div id="sign-result" class="result hidden"></div>
</div>
</div>
<!-- VERIFY PANEL -->
<div class="panel" id="panel-verify">
<div class="card">
<div class="card-title">Verify Message Signature</div>
<p style="color: var(--muted); font-size: 0.8rem; margin-bottom: 1rem;">
Verify an Ed25519 signature against a public key
</p>
<label>Message</label>
<textarea id="verify-message" placeholder="Original message"></textarea>
<label>Signature (Base58 or Hex)</label>
<input type="text" id="verify-signature" placeholder="Signature...">
<label>Public Key (Address)</label>
<input type="text" id="verify-address" placeholder="Address (Base58)...">
<button onclick="verifyMessageAction()">Verify Signature</button>
<div id="verify-result" class="result hidden"></div>
</div>
</div>
<!-- VALIDATE PANEL -->
<div class="panel" id="panel-validate">
<div class="card">
<div class="card-title">Validate Address</div>
<p style="color: var(--muted); font-size: 0.8rem; margin-bottom: 1rem;">
Check if a Solana address is valid Base58
</p>
<label>Solana Address</label>
<input type="text" id="validate-address" placeholder="Address (Base58)...">
<button onclick="validateAddress()">Validate Address</button>
<div id="validate-address-result" class="result hidden"></div>
</div>
<div class="card">
<div class="card-title">Validate Keypair JSON</div>
<p style="color: var(--muted); font-size: 0.8rem; margin-bottom: 1rem;">
Verify a keypair JSON file is valid and can construct a Keypair
</p>
<label>Keypair JSON Array</label>
<textarea id="validate-keypair" placeholder="[174,47,154,16,202,193,206,113,199,190,53,133,...]"></textarea>
<button onclick="validateKeypair()">Validate Keypair</button>
<div id="validate-keypair-result" class="result hidden"></div>
</div>
<div class="card">
<div class="card-title">Verify Key-Address Pair</div>
<p style="color: var(--muted); font-size: 0.8rem; margin-bottom: 1rem;">
Verify that a secret key derives to the expected address
</p>
<label>Secret Key (JSON Array)</label>
<textarea id="pair-key" placeholder="[174,47,154,16,202,193,206,113,199,190,53,133,...]"></textarea>
<label>Expected Address</label>
<input type="text" id="pair-address" placeholder="Address (Base58)...">
<button onclick="validatePair()">Verify Match</button>
<div id="pair-result" class="result hidden"></div>
</div>
</div>
<!-- ESTIMATE PANEL -->
<div class="panel" id="panel-estimate">
<div class="card">
<div class="card-title">Difficulty Estimation (Dry Run)</div>
<p style="color: var(--muted); font-size: 0.8rem; margin-bottom: 1rem;">
Estimate how long it will take to find a vanity address
</p>
<div class="row">
<div>
<label>Prefix</label>
<input type="text" id="estimate-prefix" placeholder="e.g., ABC" maxlength="8">
</div>
<div>
<label>Suffix</label>
<input type="text" id="estimate-suffix" placeholder="e.g., xyz" maxlength="8">
</div>
</div>
<div class="checkbox-row">
<input type="checkbox" id="estimate-ignore-case">
<label for="estimate-ignore-case">Case-insensitive</label>
</div>
<button onclick="runBenchmark()">Run Benchmark & Estimate</button>
<div id="estimate-result" class="result hidden"></div>
</div>
<div class="card">
<div class="card-title">Base58 Character Reference</div>
<p style="color: var(--muted); font-size: 0.8rem; margin-bottom: 0.5rem;">
Solana addresses use Base58 encoding (58 characters):
</p>
<div class="result-value" style="margin-bottom: 0;">
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
</div>
<p style="color: var(--muted); font-size: 0.75rem; margin-top: 0.5rem;">
Note: No 0 (zero), O (capital o), I (capital i), or l (lowercase L)
</p>
</div>
</div>
<footer>
Solana Wallet Toolkit — Uses official <a href="https://github.com/solana-labs/solana-web3.js" target="_blank">@solana/web3.js</a> — <a href="https://github.com/nirholas/solana-wallet-toolkit" target="_blank">GitHub</a>
</footer>
</div>
<!-- Official @solana/web3.js from Solana Labs -->
<script src="https://unpkg.com/@solana/[email protected]/lib/index.iife.min.js"></script>
<script>
// ============================================================
// INITIALIZATION & LIBRARY CHECK
// ============================================================
let solana = null;
let nacl = null;
function initLibrary() {
const statusEl = document.getElementById('lib-status');
if (typeof solanaWeb3 !== 'undefined') {
solana = solanaWeb3;
// nacl is included in @solana/web3.js bundle
statusEl.textContent = '✓ @solana/web3.js loaded';
statusEl.className = 'lib-status loaded';
return true;
} else {
statusEl.textContent = '✗ Library not loaded';
statusEl.className = 'lib-status error';
return false;
}
}
// Initialize on load
document.addEventListener('DOMContentLoaded', () => {
setTimeout(initLibrary, 100);
});
function checkLibrary() {
if (!solana) {
if (!initLibrary()) {
alert('Error: @solana/web3.js not loaded. Please refresh the page or check your internet connection.');
return false;
}
}
return true;
}
// ============================================================
// THEME TOGGLE
// ============================================================
function toggleTheme() {
document.body.classList.toggle('light-mode');
}
// ============================================================
// TAB NAVIGATION
// ============================================================
document.querySelectorAll('.tab').forEach(tab => {
tab.addEventListener('click', () => {
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.panel').forEach(p => p.classList.remove('active'));
tab.classList.add('active');
document.getElementById('panel-' + tab.dataset.panel).classList.add('active');
});
});
// ============================================================
// UTILITY FUNCTIONS
// ============================================================
const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
function isValidBase58(str) {
for (const char of str) {
if (!BASE58_ALPHABET.includes(char)) {
return false;
}
}
return true;
}
function bytesToHex(bytes) {
return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
}
function hexToBytes(hex) {
const bytes = [];
for (let i = 0; i < hex.length; i += 2) {
bytes.push(parseInt(hex.substr(i, 2), 16));
}
return new Uint8Array(bytes);
}
function formatNumber(n) {
return n.toLocaleString();
}
function formatDuration(seconds) {
if (seconds < 1) return '< 1 second';
if (seconds < 60) return `${Math.round(seconds)} seconds`;
if (seconds < 3600) return `${Math.round(seconds / 60)} minutes`;
if (seconds < 86400) return `${(seconds / 3600).toFixed(1)} hours`;
return `${(seconds / 86400).toFixed(1)} days`;
}
function copyToClipboard(text) {
navigator.clipboard.writeText(text).catch(() => {
const ta = document.createElement('textarea');
ta.value = text;
document.body.appendChild(ta);
ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
});
}
function showResult(elementId, html) {
const el = document.getElementById(elementId);
el.innerHTML = html;
el.classList.remove('hidden');
}
function resultField(label, value, copyable = true) {
const escapedValue = value.replace(/'/g, "\\'").replace(/"/g, '"');
const copyBtn = copyable ? `<button class="btn-small btn-secondary" onclick="copyToClipboard('${escapedValue}')">Copy</button>` : '';
return `<div class="result-title">${label}</div><div class="result-value">${value}</div>${copyBtn}`;
}
function downloadKeypair(secretKeyArray, address) {
const json = JSON.stringify(Array.from(secretKeyArray));
const blob = new Blob([json], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${address}.json`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
// ============================================================
// GENERATE WALLET
// ============================================================
function generateWallet() {
if (!checkLibrary()) return;
try {
const keypair = solana.Keypair.generate();
const address = keypair.publicKey.toBase58();
const secretKeyArray = Array.from(keypair.secretKey);
const secretKeyJson = JSON.stringify(secretKeyArray);
showResult('generate-result', `
${resultField('Public Key (Address)', address)}
${resultField('Secret Key (JSON Array)', secretKeyJson)}
<div style="margin-top: 0.5rem;">
<button class="btn-small" onclick='downloadKeypair(${secretKeyJson}, "${address}")'>Download Keypair JSON</button>
</div>
<p style="color: var(--muted); font-size: 0.75rem; margin-top: 0.75rem;">
⚠ Save this keypair securely. The secret key is needed to sign transactions.
</p>
`);
} catch (e) {
showResult('generate-result', `<p class="error">Error: ${e.message}</p>`);
}
}
// ============================================================
// VANITY ADDRESS GENERATION
// ============================================================
let vanityRunning = false;
let vanityAttempts = 0;
let vanityStartTime = 0;
function matchesPattern(address, prefix, suffix, ignoreCase) {
let addr = address;
let pre = prefix || '';
let suf = suffix || '';
if (ignoreCase) {
addr = addr.toLowerCase();
pre = pre.toLowerCase();
suf = suf.toLowerCase();
}
if (pre && !addr.startsWith(pre)) return false;
if (suf && !addr.endsWith(suf)) return false;
return true;
}
function startVanity() {
if (!checkLibrary()) return;
if (vanityRunning) return;
const prefix = document.getElementById('vanity-prefix').value.trim();
const suffix = document.getElementById('vanity-suffix').value.trim();
const ignoreCase = document.getElementById('vanity-ignore-case').checked;
const statusEl = document.getElementById('vanity-status');
const resultEl = document.getElementById('vanity-result');
// Validate inputs
if (!prefix && !suffix) {
statusEl.textContent = '❌ Please enter a prefix or suffix';
return;
}
if (prefix && !isValidBase58(prefix)) {
statusEl.textContent = '❌ Prefix contains invalid Base58 characters';
return;
}
if (suffix && !isValidBase58(suffix)) {
statusEl.textContent = '❌ Suffix contains invalid Base58 characters';
return;
}
const totalLength = (prefix?.length || 0) + (suffix?.length || 0);
if (totalLength > 6) {
statusEl.textContent = '⚠ Warning: Long patterns may take a very long time';
}
vanityRunning = true;
vanityAttempts = 0;
vanityStartTime = performance.now();
resultEl.classList.add('hidden');
document.getElementById('vanity-btn').disabled = true;
const batchSize = 100;
function search() {
if (!vanityRunning) {
document.getElementById('vanity-btn').disabled = false;
return;
}
for (let i = 0; i < batchSize; i++) {
vanityAttempts++;
const keypair = solana.Keypair.generate();
const address = keypair.publicKey.toBase58();
if (matchesPattern(address, prefix, suffix, ignoreCase)) {
// Found!
vanityRunning = false;
document.getElementById('vanity-btn').disabled = false;
const elapsed = (performance.now() - vanityStartTime) / 1000;
const rate = Math.round(vanityAttempts / elapsed);
const secretKeyArray = Array.from(keypair.secretKey);
const secretKeyJson = JSON.stringify(secretKeyArray);
statusEl.textContent = `✅ Found in ${formatNumber(vanityAttempts)} attempts (${elapsed.toFixed(2)}s, ${formatNumber(rate)}/sec)`;
showResult('vanity-result', `
${resultField('Public Key (Address)', address)}
${resultField('Secret Key (JSON Array)', secretKeyJson)}
<div style="margin-top: 0.5rem;">
<button class="btn-small" onclick='downloadKeypair(${secretKeyJson}, "${address}")'>Download Keypair JSON</button>
</div>
`);
return;
}
}
// Update status
const elapsed = (performance.now() - vanityStartTime) / 1000;
const rate = Math.round(vanityAttempts / elapsed);
statusEl.textContent = `Mining... ${formatNumber(vanityAttempts)} attempts (${elapsed.toFixed(1)}s, ~${formatNumber(rate)}/sec)`;
// Continue searching
setTimeout(search, 0);
}
setTimeout(search, 10);
}
function stopVanity() {
vanityRunning = false;
document.getElementById('vanity-btn').disabled = false;
document.getElementById('vanity-status').textContent = 'Stopped';
}
// ============================================================
// RESTORE FROM SECRET KEY
// ============================================================
function restoreFromJson() {
if (!checkLibrary()) return;
const jsonInput = document.getElementById('restore-json').value.trim();
try {
const secretKeyArray = JSON.parse(jsonInput);
if (!Array.isArray(secretKeyArray)) {
throw new Error('Input must be a JSON array');
}
if (secretKeyArray.length !== 64) {
throw new Error(`Expected 64 bytes, got ${secretKeyArray.length}`);
}
const secretKey = new Uint8Array(secretKeyArray);
const keypair = solana.Keypair.fromSecretKey(secretKey);
const address = keypair.publicKey.toBase58();
showResult('restore-json-result', `
${resultField('Public Key (Address)', address)}
<p class="success" style="margin-top: 0.5rem;">✅ Keypair restored successfully</p>
`);
} catch (e) {
showResult('restore-json-result', `<p class="error">Error: ${e.message}</p>`);
}
}
function restoreFromBase58() {
if (!checkLibrary()) return;
const base58Input = document.getElementById('restore-base58').value.trim();
try {
if (!isValidBase58(base58Input)) {
throw new Error('Invalid Base58 characters in input');
}
// Decode Base58 to bytes using PublicKey's internal decoder
// This is a workaround since @solana/web3.js doesn't expose bs58 directly
const decoded = solana.bs58.decode(base58Input);
if (decoded.length !== 64) {
throw new Error(`Expected 64 bytes, got ${decoded.length}`);
}
const keypair = solana.Keypair.fromSecretKey(decoded);
const address = keypair.publicKey.toBase58();
const secretKeyJson = JSON.stringify(Array.from(keypair.secretKey));
showResult('restore-base58-result', `
${resultField('Public Key (Address)', address)}
${resultField('Secret Key (JSON Array)', secretKeyJson)}
<p class="success" style="margin-top: 0.5rem;">✅ Keypair restored successfully</p>
`);
} catch (e) {
showResult('restore-base58-result', `<p class="error">Error: ${e.message}</p>`);
}
}
// ============================================================
// SIGN MESSAGE
// ============================================================
function signMessageAction() {
if (!checkLibrary()) return;
const message = document.getElementById('sign-message').value;
const keyJson = document.getElementById('sign-key').value.trim();
try {
const secretKeyArray = JSON.parse(keyJson);
const secretKey = new Uint8Array(secretKeyArray);
const keypair = solana.Keypair.fromSecretKey(secretKey);
// Encode message as bytes
const messageBytes = new TextEncoder().encode(message);
// Sign using nacl (included in @solana/web3.js)
const signature = solana.nacl.sign.detached(messageBytes, keypair.secretKey);
const signatureHex = bytesToHex(signature);
const signatureBase58 = solana.bs58.encode(signature);
showResult('sign-result', `
${resultField('Signer Address', keypair.publicKey.toBase58())}
${resultField('Signature (Base58)', signatureBase58)}
${resultField('Signature (Hex)', signatureHex)}
`);
} catch (e) {
showResult('sign-result', `<p class="error">Error: ${e.message}</p>`);
}
}
// ============================================================
// VERIFY SIGNATURE
// ============================================================
function verifyMessageAction() {
if (!checkLibrary()) return;
const message = document.getElementById('verify-message').value;
const signatureInput = document.getElementById('verify-signature').value.trim();
const addressInput = document.getElementById('verify-address').value.trim();
try {
// Parse public key
const publicKey = new solana.PublicKey(addressInput);
// Parse signature (try Base58 first, then hex)
let signatureBytes;
if (signatureInput.startsWith('0x') || /^[0-9a-fA-F]+$/.test(signatureInput)) {
// Hex format
const hex = signatureInput.replace('0x', '');
signatureBytes = hexToBytes(hex);
} else {
// Base58 format
signatureBytes = solana.bs58.decode(signatureInput);
}
if (signatureBytes.length !== 64) {
throw new Error(`Signature must be 64 bytes, got ${signatureBytes.length}`);
}
// Encode message as bytes
const messageBytes = new TextEncoder().encode(message);
// Verify using nacl
const isValid = solana.nacl.sign.detached.verify(
messageBytes,
signatureBytes,
publicKey.toBytes()
);
if (isValid) {
showResult('verify-result', `
<p class="success" style="font-size: 1.1rem;">✅ SIGNATURE VALID</p>
<p style="color: var(--muted); margin-top: 0.5rem;">
The message was signed by ${addressInput}
</p>
`);
} else {
showResult('verify-result', `
<p class="error" style="font-size: 1.1rem;">❌ SIGNATURE INVALID</p>
<p style="color: var(--muted); margin-top: 0.5rem;">
The signature does not match the message and address
</p>
`);
}
} catch (e) {
showResult('verify-result', `<p class="error">Error: ${e.message}</p>`);
}
}
// ============================================================
// VALIDATE ADDRESS
// ============================================================
function validateAddress() {
if (!checkLibrary()) return;
const address = document.getElementById('validate-address').value.trim();
try {
// Check Base58 characters
if (!isValidBase58(address)) {
throw new Error('Contains invalid Base58 characters');
}
// Try to create PublicKey (this validates the address)
const publicKey = new solana.PublicKey(address);
const bytes = publicKey.toBytes();
// Check it's on the Ed25519 curve (32 bytes)
if (bytes.length !== 32) {
throw new Error('Invalid public key length');
}
showResult('validate-address-result', `
<p class="success" style="font-size: 1.1rem;">✅ VALID SOLANA ADDRESS</p>
<div style="margin-top: 0.75rem;">
${resultField('Address', address)}
${resultField('Bytes (Hex)', bytesToHex(bytes))}
<div class="result-title">Length</div>
<div class="result-value">${address.length} characters (${bytes.length} bytes)</div>
</div>
`);
} catch (e) {
showResult('validate-address-result', `
<p class="error" style="font-size: 1.1rem;">❌ INVALID ADDRESS</p>
<p style="color: var(--muted); margin-top: 0.5rem;">${e.message}</p>
`);
}
}
// ============================================================
// VALIDATE KEYPAIR
// ============================================================
function validateKeypair() {
if (!checkLibrary()) return;
const jsonInput = document.getElementById('validate-keypair').value.trim();
const checks = [];
try {
// Check 1: Valid JSON
let secretKeyArray;
try {
secretKeyArray = JSON.parse(jsonInput);
checks.push({ name: 'Valid JSON', passed: true, message: 'Input is valid JSON' });
} catch {
checks.push({ name: 'Valid JSON', passed: false, message: 'Input is not valid JSON' });
throw new Error('Invalid JSON');
}
// Check 2: Is array
if (Array.isArray(secretKeyArray)) {
checks.push({ name: 'Is Array', passed: true, message: 'Input is an array' });
} else {
checks.push({ name: 'Is Array', passed: false, message: 'Input must be an array' });
throw new Error('Not an array');
}
// Check 3: Correct length (64 bytes)
if (secretKeyArray.length === 64) {
checks.push({ name: 'Correct Length', passed: true, message: '64 bytes (correct)' });
} else {
checks.push({ name: 'Correct Length', passed: false, message: `${secretKeyArray.length} bytes (expected 64)` });
throw new Error('Invalid length');
}
// Check 4: All values are valid bytes (0-255)
const allBytes = secretKeyArray.every(v => Number.isInteger(v) && v >= 0 && v <= 255);
if (allBytes) {
checks.push({ name: 'Valid Bytes', passed: true, message: 'All values are 0-255' });
} else {
checks.push({ name: 'Valid Bytes', passed: false, message: 'Some values are not valid bytes (0-255)' });
throw new Error('Invalid byte values');
}
// Check 5: Can construct Keypair
const secretKey = new Uint8Array(secretKeyArray);
let keypair;
try {
keypair = solana.Keypair.fromSecretKey(secretKey);
checks.push({ name: 'Keypair Construction', passed: true, message: 'Successfully created Keypair' });
} catch (e) {
checks.push({ name: 'Keypair Construction', passed: false, message: e.message });
throw e;
}
// Check 6: Public key derivation
const derivedPubkey = keypair.publicKey.toBase58();
const storedPubkeyBytes = secretKey.slice(32);
const storedPubkey = new solana.PublicKey(storedPubkeyBytes).toBase58();
if (derivedPubkey === storedPubkey) {
checks.push({ name: 'Public Key Derivation', passed: true, message: 'Stored public key matches derived' });
} else {
checks.push({ name: 'Public Key Derivation', passed: false, message: 'Public key mismatch' });
}
// Check 7: Sign and verify test
try {
const testMessage = new TextEncoder().encode('test message');
const signature = solana.nacl.sign.detached(testMessage, keypair.secretKey);
const verified = solana.nacl.sign.detached.verify(testMessage, signature, keypair.publicKey.toBytes());
if (verified) {
checks.push({ name: 'Sign/Verify Test', passed: true, message: 'Can sign and verify messages' });
} else {
checks.push({ name: 'Sign/Verify Test', passed: false, message: 'Signature verification failed' });
}
} catch (e) {
checks.push({ name: 'Sign/Verify Test', passed: false, message: e.message });
}
// Display results
const allPassed = checks.every(c => c.passed);
const checksHtml = checks.map(c =>
`<div style="margin-bottom: 0.25rem;">${c.passed ? '✅' : '❌'} <strong>${c.name}</strong>: ${c.message}</div>`
).join('');
showResult('validate-keypair-result', `
<p class="${allPassed ? 'success' : 'error'}" style="font-size: 1.1rem; margin-bottom: 0.75rem;">
${allPassed ? '✅ KEYPAIR VALID' : '❌ KEYPAIR INVALID'}
</p>
${checksHtml}
${allPassed ? `
<div style="margin-top: 0.75rem;">
${resultField('Public Key', derivedPubkey)}
</div>
` : ''}
`);
} catch (e) {
const checksHtml = checks.map(c =>
`<div style="margin-bottom: 0.25rem;">${c.passed ? '✅' : '❌'} <strong>${c.name}</strong>: ${c.message}</div>`
).join('');
showResult('validate-keypair-result', `
<p class="error" style="font-size: 1.1rem; margin-bottom: 0.75rem;">❌ KEYPAIR INVALID</p>
${checksHtml}
`);
}
}
// ============================================================
// VERIFY KEY-ADDRESS PAIR
// ============================================================
function validatePair() {
if (!checkLibrary()) return;
const keyJson = document.getElementById('pair-key').value.trim();
const expectedAddress = document.getElementById('pair-address').value.trim();
try {
const secretKeyArray = JSON.parse(keyJson);
const secretKey = new Uint8Array(secretKeyArray);
const keypair = solana.Keypair.fromSecretKey(secretKey);
const derivedAddress = keypair.publicKey.toBase58();
if (derivedAddress === expectedAddress) {
showResult('pair-result', `
<p class="success" style="font-size: 1.1rem;">✅ MATCH</p>
<p style="color: var(--muted); margin-top: 0.5rem;">
The secret key correctly derives to the expected address.
</p>
${resultField('Derived Address', derivedAddress)}
`);
} else {
showResult('pair-result', `
<p class="error" style="font-size: 1.1rem;">❌ MISMATCH</p>
<p style="color: var(--muted); margin-top: 0.5rem;">
The secret key does not derive to the expected address.
</p>
${resultField('Expected', expectedAddress)}
${resultField('Derived', derivedAddress)}
`);
}
} catch (e) {
showResult('pair-result', `<p class="error">Error: ${e.message}</p>`);
}
}
// ============================================================
// BENCHMARK & ESTIMATE
// ============================================================
function runBenchmark() {
if (!checkLibrary()) return;
const prefix = document.getElementById('estimate-prefix').value.trim();
const suffix = document.getElementById('estimate-suffix').value.trim();
const ignoreCase = document.getElementById('estimate-ignore-case').checked;
if (!prefix && !suffix) {
showResult('estimate-result', `<p class="error">Please enter a prefix or suffix</p>`);
return;
}
// Validate Base58
if (prefix && !isValidBase58(prefix)) {
showResult('estimate-result', `<p class="error">Prefix contains invalid Base58 characters</p>`);
return;
}
if (suffix && !isValidBase58(suffix)) {
showResult('estimate-result', `<p class="error">Suffix contains invalid Base58 characters</p>`);
return;
}
// Run 1-second benchmark
const benchmarkDuration = 1000; // 1 second
const startTime = performance.now();
let count = 0;
while (performance.now() - startTime < benchmarkDuration) {
solana.Keypair.generate();
count++;
}
const actualDuration = (performance.now() - startTime) / 1000;
const rate = Math.round(count / actualDuration);
// Calculate difficulty
const alphabetSize = 58;
const prefixLen = prefix?.length || 0;
const suffixLen = suffix?.length || 0;
// If case-insensitive, effective alphabet is smaller for letters
// Letters in Base58: A-H, J-N, P-Z (25 uppercase) + a-k, m-z (24 lowercase) = 49 letters
// Numbers: 1-9 (9 numbers)
// Case-insensitive means upper and lower are equivalent, so ~25 distinct letters + 9 numbers = 34
let effectiveAlphabetSize = ignoreCase ? 34 : 58;
const prefixDifficulty = Math.pow(effectiveAlphabetSize, prefixLen);
const suffixDifficulty = Math.pow(effectiveAlphabetSize, suffixLen);
const totalDifficulty = prefixDifficulty * suffixDifficulty;
const expectedAttempts = totalDifficulty;
const expectedSeconds = expectedAttempts / rate;
// Probability calculations
const probabilities = [0.5, 1.0, 2.0, 5.0].map(mult => ({