refactor(relay): remove unnecessary awaits from synchronous crypto functions (#687)
This commit is contained in:
@@ -104,17 +104,14 @@ describe("Live relay (relay.paseo.sh) E2E", () => {
|
||||
)}&role=client&connectionId=${encodeURIComponent(connectionId)}&v=2`;
|
||||
|
||||
// === Key setup ===
|
||||
const daemonKeyPair = await generateKeyPair();
|
||||
const daemonPubKeyB64 = await exportPublicKey(daemonKeyPair.publicKey);
|
||||
const daemonKeyPair = generateKeyPair();
|
||||
const daemonPubKeyB64 = exportPublicKey(daemonKeyPair.publicKey);
|
||||
|
||||
const clientKeyPair = await generateKeyPair();
|
||||
const clientPubKeyB64 = await exportPublicKey(clientKeyPair.publicKey);
|
||||
const clientKeyPair = generateKeyPair();
|
||||
const clientPubKeyB64 = exportPublicKey(clientKeyPair.publicKey);
|
||||
|
||||
const daemonPubKeyOnClient = await importPublicKey(daemonPubKeyB64);
|
||||
const clientSharedKey = await deriveSharedKey(
|
||||
clientKeyPair.secretKey,
|
||||
daemonPubKeyOnClient,
|
||||
);
|
||||
const daemonPubKeyOnClient = importPublicKey(daemonPubKeyB64);
|
||||
const clientSharedKey = deriveSharedKey(clientKeyPair.secretKey, daemonPubKeyOnClient);
|
||||
|
||||
// === Connect ===
|
||||
const daemonControlWs = new WebSocket(serverControlUrl);
|
||||
@@ -149,15 +146,12 @@ describe("Live relay (relay.paseo.sh) E2E", () => {
|
||||
expect(hello.type).toBe("hello");
|
||||
expect(typeof hello.key).toBe("string");
|
||||
|
||||
const clientPubKeyOnDaemon = await importPublicKey(hello.key!);
|
||||
const daemonSharedKey = await deriveSharedKey(
|
||||
daemonKeyPair.secretKey,
|
||||
clientPubKeyOnDaemon,
|
||||
);
|
||||
const clientPubKeyOnDaemon = importPublicKey(hello.key!);
|
||||
const daemonSharedKey = deriveSharedKey(daemonKeyPair.secretKey, clientPubKeyOnDaemon);
|
||||
|
||||
// === Encrypted exchange ===
|
||||
const plaintextFromClient = "hello-from-client";
|
||||
const ciphertextFromClient = await encrypt(clientSharedKey, plaintextFromClient);
|
||||
const ciphertextFromClient = encrypt(clientSharedKey, plaintextFromClient);
|
||||
clientWs.send(Buffer.from(ciphertextFromClient));
|
||||
|
||||
const daemonReceivedCiphertext = await waitForOnceMessage(
|
||||
@@ -166,7 +160,7 @@ describe("Live relay (relay.paseo.sh) E2E", () => {
|
||||
"Timed out waiting for encrypted message",
|
||||
);
|
||||
|
||||
const decryptedOnDaemon = await decrypt(
|
||||
const decryptedOnDaemon = decrypt(
|
||||
daemonSharedKey,
|
||||
daemonReceivedCiphertext.buffer.slice(
|
||||
daemonReceivedCiphertext.byteOffset,
|
||||
@@ -176,7 +170,7 @@ describe("Live relay (relay.paseo.sh) E2E", () => {
|
||||
expect(decryptedOnDaemon).toBe(plaintextFromClient);
|
||||
|
||||
const plaintextFromDaemon = "hello-from-daemon";
|
||||
const ciphertextFromDaemon = await encrypt(daemonSharedKey, plaintextFromDaemon);
|
||||
const ciphertextFromDaemon = encrypt(daemonSharedKey, plaintextFromDaemon);
|
||||
daemonWs.send(Buffer.from(ciphertextFromDaemon));
|
||||
|
||||
const clientReceivedCiphertext = await waitForOnceMessage(
|
||||
@@ -185,7 +179,7 @@ describe("Live relay (relay.paseo.sh) E2E", () => {
|
||||
"Timed out waiting for encrypted response",
|
||||
);
|
||||
|
||||
const decryptedOnClient = await decrypt(
|
||||
const decryptedOnClient = decrypt(
|
||||
clientSharedKey,
|
||||
clientReceivedCiphertext.buffer.slice(
|
||||
clientReceivedCiphertext.byteOffset,
|
||||
|
||||
Reference in New Issue
Block a user