Skip to content

Commit 7e0b30f

Browse files
fix: correctly resolve / reject promise for encrypt
1 parent c819a1f commit 7e0b30f

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

index.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -259,23 +259,26 @@ export default class Phase {
259259
await _sodium.ready;
260260
const sodium = _sodium;
261261

262-
try {
263-
const oneTimeKeyPair = await randomKeyPair();
264-
265-
const symmetricKeys = await clientSessionKeys(
266-
oneTimeKeyPair,
267-
sodium.from_hex(this.appPubKey)
268-
);
269-
270-
const ciphertext = await encryptString(plaintext, symmetricKeys.sharedTx);
271-
272-
return `ph:${PH_VERSION}:${sodium.to_hex(
273-
oneTimeKeyPair.publicKey
274-
)}:${ciphertext}:${tag}`;
275-
} catch (error) {
276-
console.log(`Something went wrong: ${error}`);
277-
return undefined;
278-
}
262+
return new Promise<PhaseCiphertext>(async (resolve, reject) => {
263+
try {
264+
const oneTimeKeyPair = await randomKeyPair();
265+
266+
const symmetricKeys = await clientSessionKeys(
267+
oneTimeKeyPair,
268+
sodium.from_hex(this.appPubKey)
269+
);
270+
271+
const ciphertext = await encryptString(plaintext, symmetricKeys.sharedTx);
272+
273+
resolve(`ph:${PH_VERSION}:${sodium.to_hex(
274+
oneTimeKeyPair.publicKey
275+
)}:${ciphertext}:${tag}`);
276+
} catch (error) {
277+
reject(`Something went wrong: ${error}`)
278+
}
279+
})
280+
281+
279282
};
280283

281284
decrypt = async (phaseCiphertext: PhaseCiphertext): Promise<string> => {

0 commit comments

Comments
 (0)