diff --git a/package.json b/package.json index 7df6eab..e901660 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "webpack --mode production", "format": "npx prettier --write .", "clean": "npx rimraf main.js", - "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register -r jsdom-global/register 'tests/**/*.ts'" + "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'tests/**/*.ts'" }, "source": "main.ts", "keywords": [], diff --git a/src/encrypt.ts b/src/encrypt.ts index d5e58ca..50d6e64 100644 --- a/src/encrypt.ts +++ b/src/encrypt.ts @@ -1,12 +1,6 @@ import * as base32 from "hi-base32"; import { bufferToArrayBuffer, arrayBufferToBuffer } from "./misc"; -if (window === undefined) { - global.window = { - crypto: require("crypto").webcrypto, - } as any; -} - const DEFAULT_ITER = 10000; const getKeyIVFromPassword = async ( diff --git a/tests/test-encrypt.ts b/tests/test-encrypt.ts index a7a805f..bfcc070 100644 --- a/tests/test-encrypt.ts +++ b/tests/test-encrypt.ts @@ -1,21 +1,16 @@ -const webcrypto = require("crypto").webcrypto; - import { expect } from "chai"; import { encryptStringToBase32 } from "../src/encrypt"; describe("Encryption tests", () => { beforeEach(function () { - const window = { - crypto: webcrypto, - }; - - global.window = window as any; + global.window = { + crypto: require("crypto").webcrypto, + } as any; }); it("should encrypt string", async () => { const k = "dkjdhkfhdkjgsdklxxd"; const password = "hey"; - //console.log(window.crypto.getRandomValues) expect(await encryptStringToBase32(k, password)).to.not.equal(k); }); }); diff --git a/webpack.config.js b/webpack.config.js index b450699..7c17227 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -38,7 +38,6 @@ module.exports = { // console: require.resolve("console-browserify"), // constants: require.resolve("constants-browserify"), // crypto: require.resolve("crypto-browserify"), - crypto: false, // deliberately set to false, since we use webcrypto here // domain: require.resolve("domain-browser"), // events: require.resolve("events"), // http: require.resolve("stream-http"),