const app = document.getElementById('app');
let pendingMnemonic = null; // held briefly in renderer memory during onboarding only
let accounts = null;
async function boot() {
const hasKeystore = await window.macu.hasKeystore();
hasKeystore ? renderUnlock() : renderWelcome();
}
// ---------- Welcome / choose create vs import ----------
function renderWelcome() {
app.innerHTML = `
Welcome to macu
A non-custodial wallet. Your keys are generated and encrypted on this device only — macu never sees them, and there's no account recovery if you lose your recovery phrase and password.
`;
document.getElementById('btn-create').onclick = startCreate;
document.getElementById('btn-import').onclick = renderImport;
}
// ---------- Create: generate + show backup phrase ----------
async function startCreate() {
pendingMnemonic = await window.macu.generateMnemonic();
renderBackup();
}
function renderBackup() {
const words = pendingMnemonic.split(' ');
app.innerHTML = `
Your recovery phrase
Write these 24 words down in order and store them somewhere safe and offline. Anyone with this phrase can access your funds on every chain — including you, if you lose it.
macu cannot recover this for you. There is no "forgot password" for a recovery phrase.
Enter your existing 12 or 24-word recovery phrase, separated by spaces.
`;
document.getElementById('btn-back').onclick = renderWelcome;
document.getElementById('btn-continue').onclick = () => {
const value = document.getElementById('mnemonic-input').value.trim();
if (value.split(/\s+/).length < 12) {
document.getElementById('import-error').textContent = 'That phrase looks too short — check the word count.';
return;
}
pendingMnemonic = value;
renderSetPassword();
};
}
// ---------- Set a password to encrypt the phrase at rest ----------
function renderSetPassword() {
app.innerHTML = `
Set a password
This encrypts your recovery phrase on this device. You'll need it every time you open macu.
`;
document.getElementById('btn-finish').onclick = async () => {
const pw1 = document.getElementById('pw1').value;
const pw2 = document.getElementById('pw2').value;
const errEl = document.getElementById('pw-error');
if (pw1.length < 8) { errEl.textContent = 'Use at least 8 characters.'; return; }
if (pw1 !== pw2) { errEl.textContent = 'Passwords do not match.'; return; }
try {
accounts = await window.macu.createWallet(pendingMnemonic, pw1);
pendingMnemonic = null; // drop it from renderer memory as soon as we're done with it
renderDashboard();
} catch (e) {
errEl.textContent = e.message;
}
};
}
// ---------- Unlock existing keystore ----------
function renderUnlock() {
app.innerHTML = `