// @ts-ignore import lumeLogo from "../../assets/lume-logo.png"; // @ts-ignore import classNames from "classnames"; import { useEffect, useRef, useState } from "react"; import * as bip39 from "@scure/bip39"; import { wordlist } from "@scure/bip39/wordlists/english"; import { HDKey } from "ed25519-keygen/hdkey"; import { x25519 } from "@noble/curves/ed25519"; // @ts-ignore import browser from "webextension-polyfill"; import { bytesToHex, hexToBytes, randomBytes } from "@lumeweb/libweb"; import { secretbox } from "@noble/ciphers/salsa"; import "./App.scss"; import { exchangeCommunicationKeys, setLoginKey, } from "../../../shared/keys.js"; const BIP44_PATH = "m/44'/1627'/0'/0'/0'"; export default function App() { let [currentAction, setCurrentAction] = useState< "sign-in" | "create-account" | null >(null); let [createAccountStep, setCreateAccountStep] = useState(0); let [generatedKey, setGeneratedKey] = useState([]); let [copyKeySuccess, setCopyKeySuccess] = useState(false); let [copyKeyError, setCopyKeyError] = useState(false); let elSwitch = useRef(); let elSwitchDefault = useRef(); let elSwitchShowKey = useRef(); let elContentTextActive = useRef(); let elContentTextDefault = useRef(); let elContentTextCreateAccount = useRef(); let elContentTextWrapper = useRef(); let elContentTextShowKey = useRef(); let resizeTimeout = useRef(); let copyKeyTimeout = useRef(); let copyKeyCallback = useRef(); let elInputKey = useRef(); function createAccount() { setCurrentAction("create-account"); setCreateAccountStep(1); } function createAccountCancel() { setCurrentAction(null); setCreateAccountStep(0); } function signIn() { setCurrentAction("sign-in"); } function inputKeySignIn() { if (!bip39.validateMnemonic(elInputKey.current.value, wordlist)) { alert("invalid key"); return; } processSignIn(elInputKey.current.value); } function createAccountReady() { if (createAccountStep !== 1) { return; } setCreateAccountStep(2); } function showKey() { if (createAccountStep !== 2) { return; } // generate key setGeneratedKey(bip39.generateMnemonic(wordlist).split(" ")); setCreateAccountStep(3); elSwitch.current.style.height = elSwitchDefault.current.offsetHeight + "px"; elSwitchDefault.current.style.position = "absolute"; setTimeout(() => { setContentTextHeight(elContentTextShowKey); elSwitch.current.style.height = elSwitchShowKey.current.offsetHeight + "px"; elSwitch.current.addEventListener("transitionend", (event) => { if (event.target !== elSwitch.current) { return; } elSwitchShowKey.current.style.position = "static"; elSwitch.current.style.height = ""; }); }, 0); } function createAccountBack() { setCreateAccountStep(1); } function showKeyWarning() { if (createAccountStep !== 3) { return; } setCreateAccountStep(4); } function generatedKeySignIn() { const seed = generatedKey.join(" "); if (!bip39.validateMnemonic(seed, wordlist)) { alert("invalid key"); return; } processSignIn(seed); } const processSignIn = async (wordSeed) => { const seed = await bip39.mnemonicToSeed(wordSeed); const key = HDKey.fromMasterSeed(seed).derive(BIP44_PATH); await setLoginKey(key.privateKey); window.setTimeout(() => { window.location.href = "/dashboard.html"; }, 1000); }; function setContentTextHeight(element) { elContentTextActive.current = element; elContentTextWrapper.current.style.height = element.offsetHeight + "px"; } function copyKey() { clearTimeout(copyKeyTimeout.current); navigator.clipboard .writeText(generatedKey.join(" ")) .then(() => { copyKeyCallback.current?.(); setCopyKeySuccess(true); copyKeyCallback.current = () => { copyKeyCallback.current = undefined; setCopyKeySuccess(null); }; copyKeyTimeout.current = setTimeout(copyKeyCallback.current, 750); }) .catch((error) => { console.error(error); copyKeyCallback.current?.(); setCopyKeyError(true); copyKeyCallback.current = () => { copyKeyCallback.current = undefined; setCopyKeyError(false); }; copyKeyTimeout.current = setTimeout(copyKeyCallback.current, 750); }); } useEffect(() => { const onResize = () => { clearTimeout(resizeTimeout.current); resizeTimeout.current = setTimeout(() => { setContentTextHeight(elContentTextActive); }, 25); }; window.addEventListener("resize", onResize); }); return ( <>
Lume

Access the open web with ease

Seamless access to your favorite networks

Set up your account key

Let’s create your account key or seed phrase. This phrase will be used to access your Lume account. Make sure to keep it safe at all times.

Here’s your account key

Make sure to keep it safe at all times.

Should you lose this key, you will be forced to create a new account.
OR
{createAccountStep > 2 && (
{generatedKey.map((word, index) => (
{index + 1} {word}
))}
Make sure to write this key down for safe keeping.
)}
); }