fix: use newBootloaderQuery
This commit is contained in:
parent
85615350f0
commit
25d2f6b1c0
|
@ -5,6 +5,7 @@ import {
|
||||||
kernelLoadedDefer,
|
kernelLoadedDefer,
|
||||||
loginDefer,
|
loginDefer,
|
||||||
logoutDefer,
|
logoutDefer,
|
||||||
|
newBootloaderQuery,
|
||||||
newKernelQuery,
|
newKernelQuery,
|
||||||
} from "./queries.js";
|
} from "./queries.js";
|
||||||
import { Err } from "#types.js";
|
import { Err } from "#types.js";
|
||||||
|
@ -85,35 +86,25 @@ async function login(key: Uint8Array) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pubKeyRet = await newKernelQuery(
|
let pubKeyRet = await newBootloaderQuery("exchangeCommunicationKeys", {
|
||||||
"exchangeCommunicationKeys",
|
|
||||||
{
|
|
||||||
data: bytesToHex(x25519.getPublicKey(privKey)),
|
data: bytesToHex(x25519.getPublicKey(privKey)),
|
||||||
},
|
});
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
let pubKeyT = await pubKeyRet[1];
|
if (pubKeyRet.err) {
|
||||||
|
alert(`Failed to login: could not get communication key: ${pubKeyRet.err}`);
|
||||||
if (pubKeyT[1]) {
|
|
||||||
alert(`Failed to login: could not get communication key: ${pubKeyT}`);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pubKey = hexToBytes(pubKeyT[1]?.[0] as string);
|
let pubKey = hexToBytes(pubKeyRet.data);
|
||||||
|
|
||||||
const secret = x25519.getSharedSecret(privKey, pubKey);
|
const secret = x25519.getSharedSecret(privKey, pubKey);
|
||||||
const nonce = randomBytes(24);
|
const nonce = randomBytes(24);
|
||||||
const box = secretbox(secret, nonce);
|
const box = secretbox(secret, nonce);
|
||||||
const ciphertext = box.seal(key);
|
const ciphertext = box.seal(key);
|
||||||
await newKernelQuery(
|
await newBootloaderQuery("setLoginKey", {
|
||||||
"setLoginKey",
|
|
||||||
{
|
|
||||||
data: bytesToHex(ciphertext),
|
data: bytesToHex(ciphertext),
|
||||||
nonce: bytesToHex(nonce),
|
nonce: bytesToHex(nonce),
|
||||||
},
|
});
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { loginComplete, kernelLoaded, logoutComplete, openAuthWindow, login };
|
export { loginComplete, kernelLoaded, logoutComplete, openAuthWindow, login };
|
||||||
|
|
Loading…
Reference in New Issue