From: Chris Duncan Date: Mon, 4 Nov 2024 02:39:59 +0000 (-0800) Subject: Start building mnemonic and seed export functions. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=c8d214d4d16a60f2af058bf56bde1631178e8938;p=nemo-wallet.git Start building mnemonic and seed export functions. --- diff --git a/nemo-wallet.html b/nemo-wallet.html index 464c944..a6b554f 100644 --- a/nemo-wallet.html +++ b/nemo-wallet.html @@ -69,6 +69,12 @@ clearStorage() } }) + const exportMnemonicButton = document.getElementById('export-mnemonic-button') + exportMnemonicButton.addEventListener('click', async (event) => { + if (event.detail === 1) { + await exportMnemonic() + } + }) setTimeout(() => { document.body.style.visibility = 'visible' }, 250) @@ -513,7 +519,7 @@ } async function clearStorage () { - const btn = document.querySelector('#clear-storage-button') + const btn = document.getElementById('clear-storage-button') btn.setAttribute('disabled', '') sessionStorage.clear() const options = document.querySelectorAll('#wallet option, #account option') @@ -522,12 +528,13 @@ option.remove() } } - document.querySelector('#wallet').value = '' - document.querySelector('#account').value = '' + document.getElementById('wallet').value = '' + document.getElementById('account').value = '' await selectWallet() notify.ok(`Session storage cleared`) btn.removeAttribute('disabled') } + function selectTheme () { const body = document.querySelector('body') const themeCheckbox = document.getElementById('theme-checkbox') @@ -577,6 +584,52 @@ const qrCode = document.getElementById('qr-code') qrCode.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABDgAAAQ4AQMAAADW3v7MAAAABlBMVEUAAAD///+l2Z/dAAAC0klEQVR42u3cPQ6CMBiAYYWFjStwE6+mN+Mq3oCVxKQO4k8N6ABNWvK8G1+HPuuXNBzDIYuOHBwcHBwcHBwcHBwcHMU6rt3cyanf/raxmZu2AwcHBwcHBwcHBwcHR3GOdoiPLudUjvoWj6bLOTg4ODg4ODg4ODg4ynO8d62Q2BGqj52Rg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4Oj986Rg4ODg4ODg4ODg4NjlWMm///g4ODg4ODg4ODg4OBYcuQQBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHB8e+Hdcu/g4cHBwcHBwcHBwcHBz5Otrhaag4ODg4ODg4ODg4ODjKdnzvWo9O/faOsTnUNw4ODg4ODg4ODg4Ojj04XrvW1OWcxPF3n+Pg4ODg4ODg4ODg4CjIMTbPWUjjiOLg4ODg4ODg4ODg4OBYFwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHB8feHVEcHBwcHBwcHBwcHBwcvx0zcXBwcHBwcHBwcHBwcCw5coiDg4ODg4ODg4ODg4ODY013wW3C00//4ZIAAAAASUVORK5CYII=' } + + async function exportMnemonic (password) { + const dialog = document.createElement('dialog') + document.body.appendChild(dialog) + + const form = document.createElement('form') + form.method = 'dialog' + dialog.appendChild(form) + + const input = document.createElement('input') + input.placeholder = 'Password' + form.appendChild(input) + + const submit = document.createElement('input') + submit.type = 'submit' + submit.textContent = 'OK' + form.appendChild(submit) + + dialog.addEventListener('close', async () => { + const password = dialog.returnValue + try { + const wallet = await loadWallet() + await wallet.unlock(password) + const mnemonic = wallet.mnemonic + await wallet.lock(password) + notify.info(mnemonic) + } catch (err) { + console.error(err) + notify.error(`Error exporting mnemonic`) + } + }) + dialog.showModal() + } + + async function exportSeed (password) { + try { + const wallet = await loadWallet() + await wallet.unlock(password) + const seed = wallet.seed + await wallet.lock(password) + return seed + } catch (err) { + console.error(err) + notify.error(`Error exporting seed`) + } + }