crypto: make imports esm compatible

This commit is contained in:
Abdullah Atta
2024-09-23 12:24:22 +05:00
parent 21573d6cc8
commit 239781eabd
4 changed files with 8 additions and 18 deletions

View File

@@ -16,8 +16,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import * as browser from "../src/browser";
import * as node from "../src/node";
import * as browser from "../src/browser.js";
import * as node from "../src/node.js";
import benny from "benny";
import {
decrypt,
@@ -25,7 +25,7 @@ import {
getKey,
hash,
streamingEncrypt
} from "../tests/utils";
} from "../tests/utils.js";
async function main() {
await browser.initialize();

View File

@@ -19,16 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import sodium from "libsodium-wrappers-sumo";
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;
}

View File

@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import * as browser from "../src/browser";
import * as node from "../src/node";
import * as browser from "../src/browser.js";
import * as node from "../src/node.js";
import { test } from "vitest";
import {
decrypt,
@@ -27,7 +27,7 @@ import {
hash,
streamingDecrypt,
streamingEncrypt
} from "./utils";
} from "./utils.js";
test("secretstream tags should be equal on node & browser variants", async (t) => {
t.expect(browser.crypto_secretstream_xchacha20poly1305_TAG_FINAL).toBe(

View File

@@ -16,8 +16,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import * as browser from "../src/browser";
import * as node from "../src/node";
import * as browser from "../src/browser.js";
import * as node from "../src/node.js";
export async function streamingEncrypt(
crypto: typeof node | typeof browser,