]> zoso.dev Git - nemo-wallet.git/commitdiff
Start building mnemonic and seed export functions.
authorChris Duncan <chris@zoso.dev>
Mon, 4 Nov 2024 02:39:59 +0000 (18:39 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 4 Nov 2024 02:39:59 +0000 (18:39 -0800)
nemo-wallet.html

index 464c944b0833a8b4041ffd28f61febd39fcaa2ec..a6b554f53d177430b0b901cbb60f419825363ecb 100644 (file)
                                        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)
                }
 
                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')
                                        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')
                        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`)
+                       }
+               }
        </script>
        <style>
                *{border:0;box-sizing:border-box;font:normal normal normal calc(16px + 0.1dvh) 'sans-serif';margin:0;}
                                <button id="clear-storage-button">
                                        Clear Storage
                                </button>
+                               <button id="export-mnemonic-button">
+                                       Export Mnemonic
+                               </button>
                        </div>
                        <article>
                                <h2>Licenses</h2>