-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
202 lines (174 loc) · 9.16 KB
/
index.html
File metadata and controls
202 lines (174 loc) · 9.16 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Blocto Wallet Decrypt</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body { font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; margin: 2rem; background: #0f172a; color: #e5e7eb; }
.card { max-width: 520px; margin: 0 auto; padding: 1.75rem 2rem; border-radius: 0.9rem; background: radial-gradient(circle at top left, #1f2937, #020617 55%); box-shadow: 0 24px 60px rgba(15,23,42,0.9); border: 1px solid rgba(148,163,184,0.25); }
h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
p { font-size: 0.9rem; color: #9ca3af; margin-top: 0; }
.subtitle { font-size: 0.85rem; color: #60a5fa; margin-top: 0.25rem; margin-bottom: 0.5rem; }
label { display: block; font-size: 0.85rem; margin-top: 1rem; margin-bottom: 0.25rem; }
input[type="file"], input[type="password"] { width: 100%; font-size: 0.9rem; padding: 0.6rem 0.7rem; border-radius: 0.5rem; border: 1px solid #374151; background: #020617; color: #e5e7eb; box-sizing: border-box; }
input[type="file"] { padding: 0.3rem 0.1rem; background: transparent; border: none; }
button { margin-top: 1.25rem; width: 100%; padding: 0.65rem 0.75rem; border-radius: 0.5rem; border: none; background: linear-gradient(to right, #4f46e5, #0ea5e9); color: white; font-weight: 600; font-size: 0.95rem; cursor: pointer; box-shadow: 0 10px 20px rgba(37,99,235,0.4); }
button:disabled { opacity: 0.5; cursor: default; box-shadow: none; }
.status { margin-top: 0.75rem; font-size: 0.85rem; min-height: 1.1em; }
.status.error { color: #fca5a5; }
.status.success { color: #6ee7b7; }
.status-label { font-weight: 600; text-transform: uppercase; font-size: 0.7rem; letter-spacing: 0.08em; margin-right: 0.35rem; opacity: 0.8; }
.steps { margin: 0.5rem 0 0.5rem; padding-left: 1.2rem; font-size: 0.82rem; color: #9ca3af; }
.steps li { margin-bottom: 0.25rem; }
.warning-box { margin-top: 1rem; padding: 0.6rem 0.7rem; border-radius: 0.6rem; background: rgba(127,29,29,0.2); border: 1px solid rgba(248,113,113,0.5); font-size: 0.8rem; color: #fecaca; }
.warning-box strong { color: #fed7aa; }
.copy-row { display: flex; justify-content: space-between; align-items: center; margin-top: 0.4rem; gap: 0.5rem; }
.copy-row button { width: auto; padding-inline: 0.8rem; flex-shrink: 0; }
textarea { margin-top: 0.75rem; width: 100%; min-height: 80px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 0.8rem; padding: 0.6rem 0.7rem; border-radius: 0.5rem; border: 1px solid #374151; background: #020617; color: #e5e7eb; resize: vertical; box-sizing: border-box; }
small { font-size: 0.75rem; color: #6b7280; display: block; margin-top: 0.25rem; }
footer { margin-top: 1.5rem; text-align: center; font-size: 0.75rem; color: #6b7280; }
footer span { color: #e5e7eb; }
</style>
<!-- Ethers v6 UMD build -->
<script src="https://cdn.jsdelivr.net/npm/ethers@6.13.4/dist/ethers.umd.min.js"></script>
<!-- pdf.js for reading JSON embedded inside recovery PDFs -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"></script>
</head>
<body>
<div class="card">
<h1>Blocto Account Recovery</h1>
<p class="subtitle">Move your Blocto account into non-custodial mode and import into a Flow-compatible wallet.</p>
<p>Use this tool to decrypt your **Blocto recovery keystore** and reveal the underlying private key locally. You can then import that private key into a non-custodial Flow wallet.</p>
<ol class="steps">
<li><strong>Select your recovery file:</strong> choose your Blocto recovery <code>.json</code> keystore or recovery <code>.pdf</code>.</li>
<li><strong>Enter your password:</strong> use the same password you used when the recovery file was created.</li>
<li><strong>Decrypt and import:</strong> decrypt, copy the private key (without <code>0x</code>), and paste it into your Flow wallet.</li>
</ol>
<label for="jsonFile">Blocto recovery file (JSON or PDF)</label>
<input id="jsonFile" type="file" accept="application/json,.json,application/pdf,.pdf" />
<label for="password">Recovery password</label>
<input id="password" type="password" autocomplete="off" />
<small>Decryption is performed locally in your browser. Do not use this on a shared or untrusted device.</small>
<button id="decryptBtn">Decrypt Wallet</button>
<div id="status" class="status"></div>
<label for="privateKey">Recovered private key (Flow)</label>
<textarea id="privateKey" readonly placeholder="Decrypted private key (without 0x) will appear here"></textarea>
<div class="copy-row" id="copyRow" style="display:none;">
<small>Copy this value into your Flow wallet when importing as a private key.</small>
<button id="copyBtn" type="button">Copy private key</button>
</div>
<div class="warning-box">
<strong>Warning:</strong> Anyone with this private key can fully control your Flow account. Store it securely, and only paste it into wallets you trust. Close this page when you are done.
</div>
</div>
<footer>
<span>Lovingly created by Luke at Find Labs</span>
</footer>
<script>
const fileInput = document.getElementById('jsonFile');
const passwordInput = document.getElementById('password');
const decryptBtn = document.getElementById('decryptBtn');
const statusEl = document.getElementById('status');
const pkTextarea = document.getElementById('privateKey');
const copyRow = document.getElementById('copyRow');
const copyBtn = document.getElementById('copyBtn');
function setStatus(message, type) {
statusEl.textContent = message || '';
statusEl.className = 'status' + (type ? ' ' + type : '');
}
async function extractJsonFromPdf(file) {
if (!window['pdfjsLib']) {
throw new Error('PDF library not loaded');
}
const arrayBuffer = await file.arrayBuffer();
const pdf = await pdfjsLib.getDocument({ data: arrayBuffer }).promise;
let fullText = '';
for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) {
const page = await pdf.getPage(pageNum);
const textContent = await page.getTextContent();
const pageText = textContent.items.map((item) => item.str).join(' ');
fullText += ' ' + pageText;
}
const start = fullText.indexOf('{');
const end = fullText.lastIndexOf('}');
if (start === -1 || end === -1 || end <= start) {
throw new Error('Could not locate JSON in PDF');
}
const candidate = fullText.slice(start, end + 1);
try {
JSON.parse(candidate);
} catch (e) {
throw new Error('Found text in PDF but it is not valid JSON');
}
return candidate;
}
decryptBtn.addEventListener('click', async () => {
setStatus('', '');
pkTextarea.value = '';
const file = fileInput.files[0];
const password = passwordInput.value;
if (!file) {
setStatus('Please select an encrypted JSON file or recovery PDF.', 'error');
return;
}
if (!password) {
setStatus('Please enter the wallet password.', 'error');
return;
}
decryptBtn.disabled = true;
setStatus('Reading file…', '');
try {
let json;
const isPdf = file.type === 'application/pdf' || file.name.toLowerCase().endsWith('.pdf');
if (isPdf) {
setStatus('Extracting JSON from PDF…', '');
json = await extractJsonFromPdf(file);
} else {
json = await file.text();
}
setStatus('Decrypting wallet…', '');
const wallet = await ethers.Wallet.fromEncryptedJson(json, password);
const pk = wallet.privateKey && wallet.privateKey.startsWith('0x')
? wallet.privateKey.slice(2)
: wallet.privateKey;
pkTextarea.value = pk;
copyRow.style.display = 'flex';
setStatus('Wallet decrypted successfully.', 'success');
} catch (err) {
console.error(err);
setStatus('Failed to decrypt wallet: ' + (err && err.message ? err.message : String(err)), 'error');
} finally {
decryptBtn.disabled = false;
}
});
passwordInput.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
event.preventDefault();
decryptBtn.click();
}
});
copyBtn.addEventListener('click', async () => {
const value = pkTextarea.value.trim();
if (!value) {
copyRow.style.display = 'none';
setStatus('Nothing to copy yet. Decrypt a key first.', 'error');
return;
}
try {
if (navigator.clipboard && navigator.clipboard.writeText) {
await navigator.clipboard.writeText(value);
} else {
// Fallback for very old browsers
pkTextarea.select();
document.execCommand('copy');
}
setStatus('Private key copied to clipboard.', 'success');
} catch (err) {
console.error(err);
setStatus('Failed to copy private key. You may need to copy it manually.', 'error');
}
});
</script>
</body>
</html>