crypto: eagerly init sodium in dev mode

This commit is contained in:
Abdullah Atta
2023-06-12 12:57:39 +05:00
parent 942c9556f6
commit f3a03dc813
2 changed files with 13 additions and 6 deletions

View File

@@ -19,8 +19,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import sodium from "libsodium-wrappers-sumo";
export function initialize() {
return sodium.ready;
if (process.env.NODE_ENV === "development") {
// this is necessary in development otherwise all the exported functions
// are undefined. Since vite supports direct top-level awaits in development
// we forcefully ignore typescript.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await sodium.ready;
}
export async function initialize() {
await sodium.ready;
}
export {

View File

@@ -54,10 +54,7 @@ export interface StringMessageTag {
tag: number;
}
export function initialize() {
console.log("Calling node.js API.");
return Promise.resolve();
}
export async function initialize() {}
export function crypto_pwhash(
keyLength: number,