| … | … | @@ -2180,13 +2180,62 @@ function exportTransactions() { |
| 2180 | 2180 | showSuccess(`Exported ${allTransactions.length} transactions`) |
| 2181 | 2181 | } |
| 2182 | 2182 | |
| 2183 | // Check if wallet needs password setup (plaintext mnemonics) |
| 2184 | async function checkEncryptionStatus() { |
| 2185 | try { |
| 2186 | const res = await fetch(`${API_BASE}/wallet/encryption-status`) |
| 2187 | if (res.ok) { |
| 2188 | const data = await res.json() |
| 2189 | return data.encrypted |
| 2190 | } |
| 2191 | } catch (err) { |
| 2192 | console.error('Failed to check encryption status:', err) |
| 2193 | } |
| 2194 | return null // Unknown status |
| 2195 | } |
| 2196 | |
| 2183 | 2197 | // Prompt for password to unlock wallet |
| 2184 | 2198 | async function promptForPassword() { |
| 2185 | 2199 | let attempts = 0 |
| 2186 | 2200 | const maxAttempts = 3 |
| 2187 | 2201 | |
| 2202 | // Check if this is first-time password setup or regular unlock |
| 2203 | const isEncrypted = await checkEncryptionStatus() |
| 2204 | const isFirstTimeSetup = isEncrypted === false |
| 2205 | |
| 2188 | 2206 | while (attempts < maxAttempts) { |
| 2189 | | const password = prompt(`🔐 Unlock Wallet\n\nEnter your password to access the wallet:\n\n(Attempt ${attempts + 1}/${maxAttempts})`) |
| 2207 | let promptMessage |
| 2208 | |
| 2209 | if (isFirstTimeSetup && attempts === 0) { |
| 2210 | // First-time password setup - clear warning |
| 2211 | promptMessage = `⚠️ SET WALLET PASSWORD (First Time Setup) |
| 2212 | |
| 2213 | This will ENCRYPT your wallet mnemonics with a password. |
| 2214 | |
| 2215 | IMPORTANT: |
| 2216 | • You MUST remember this password |
| 2217 | • Required every time you access the wallet |
| 2218 | • Cannot be recovered if forgotten |
| 2219 | • Minimum 8 characters |
| 2220 | |
| 2221 | Enter a strong password:` |
| 2222 | } else if (isFirstTimeSetup) { |
| 2223 | // First-time setup, retry attempt |
| 2224 | promptMessage = `⚠️ SET WALLET PASSWORD |
| 2225 | |
| 2226 | Enter a strong password (min 8 characters): |
| 2227 | |
| 2228 | (Attempt ${attempts + 1}/${maxAttempts})` |
| 2229 | } else { |
| 2230 | // Regular unlock |
| 2231 | promptMessage = `🔐 Unlock Wallet |
| 2232 | |
| 2233 | Enter your wallet password: |
| 2234 | |
| 2235 | (Attempt ${attempts + 1}/${maxAttempts})` |
| 2236 | } |
| 2237 | |
| 2238 | const password = prompt(promptMessage) |
| 2190 | 2239 | |
| 2191 | 2240 | // User cancelled |
| 2192 | 2241 | if (password === null) { |
| … | … | @@ -2214,7 +2263,11 @@ async function promptForPassword() { |
| 2214 | 2263 | if (!res.ok) { |
| 2215 | 2264 | const error = await res.json() |
| 2216 | 2265 | if (res.status === 401) { |
| 2217 | | alert('❌ Invalid password. Please try again.') |
| 2266 | if (isFirstTimeSetup) { |
| 2267 | alert('❌ Failed to set password. Please try again.') |
| 2268 | } else { |
| 2269 | alert('❌ Invalid password. Please try again.') |
| 2270 | } |
| 2218 | 2271 | attempts++ |
| 2219 | 2272 | continue |
| 2220 | 2273 | } |
| … | … | @@ -2228,7 +2281,8 @@ async function promptForPassword() { |
| 2228 | 2281 | |
| 2229 | 2282 | // Show success message |
| 2230 | 2283 | if (data.migrated) { |
| 2231 | | showSuccess('✅ Wallet unlocked and mnemonics encrypted!') |
| 2284 | alert('✅ SUCCESS!\n\nYour wallet mnemonics have been encrypted.\n\nREMEMBER YOUR PASSWORD - you will need it every time you access the wallet!') |
| 2285 | showSuccess('✅ Wallet encrypted and unlocked!') |
| 2232 | 2286 | } else { |
| 2233 | 2287 | showSuccess('✅ Wallet unlocked successfully') |
| 2234 | 2288 | } |