From 0706a618173ccd5617a5c695218aed6ec92633c8 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 28 Jul 2023 21:28:53 -0400 Subject: [PATCH] refactor: switch to use exchangeCommunicationKeys and setLoginKey --- ui/apps/account/App.tsx | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/ui/apps/account/App.tsx b/ui/apps/account/App.tsx index 0016978..b507bbc 100644 --- a/ui/apps/account/App.tsx +++ b/ui/apps/account/App.tsx @@ -12,6 +12,10 @@ 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'"; @@ -123,37 +127,8 @@ export default function App() { const seed = await bip39.mnemonicToSeed(wordSeed); const key = HDKey.fromMasterSeed(seed).derive(BIP44_PATH); - let pubKey; - let privKey = x25519.utils.randomPrivateKey(); - - try { - pubKey = await browser.runtime.sendMessage({ - method: "exchangeCommunicationKeys", - data: bytesToHex(x25519.getPublicKey(privKey)), - }); - } catch (e) { - alert(`Failed to login: ${e.message}`); - return; - } - - if (!pubKey) { - alert(`Failed to login: could not get communication key`); - return; - } - pubKey = hexToBytes(pubKey); - - const secret = x25519.getSharedSecret(privKey, pubKey); - const nonce = randomBytes(24); - const box = secretbox(secret, nonce); - const ciphertext = box.seal(key.privateKey); - - await browser.runtime.sendMessage({ - method: "setLoginKey", - data: { - data: bytesToHex(ciphertext), - nonce: bytesToHex(nonce), - }, - }); + await exchangeCommunicationKeys(); + await setLoginKey(key.privateKey); window.setTimeout(() => { window.location.href = "/dashboard.html";