This commit is contained in:
fyears 2021-11-05 01:29:44 +08:00
parent 7c4a981434
commit 774e31ef27
4 changed files with 4 additions and 16 deletions

View File

@ -7,7 +7,7 @@
"build": "webpack --mode production", "build": "webpack --mode production",
"format": "npx prettier --write .", "format": "npx prettier --write .",
"clean": "npx rimraf main.js", "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", "source": "main.ts",
"keywords": [], "keywords": [],

View File

@ -1,12 +1,6 @@
import * as base32 from "hi-base32"; import * as base32 from "hi-base32";
import { bufferToArrayBuffer, arrayBufferToBuffer } from "./misc"; import { bufferToArrayBuffer, arrayBufferToBuffer } from "./misc";
if (window === undefined) {
global.window = {
crypto: require("crypto").webcrypto,
} as any;
}
const DEFAULT_ITER = 10000; const DEFAULT_ITER = 10000;
const getKeyIVFromPassword = async ( const getKeyIVFromPassword = async (

View File

@ -1,21 +1,16 @@
const webcrypto = require("crypto").webcrypto;
import { expect } from "chai"; import { expect } from "chai";
import { encryptStringToBase32 } from "../src/encrypt"; import { encryptStringToBase32 } from "../src/encrypt";
describe("Encryption tests", () => { describe("Encryption tests", () => {
beforeEach(function () { beforeEach(function () {
const window = { global.window = {
crypto: webcrypto, crypto: require("crypto").webcrypto,
}; } as any;
global.window = window as any;
}); });
it("should encrypt string", async () => { it("should encrypt string", async () => {
const k = "dkjdhkfhdkjgsdklxxd"; const k = "dkjdhkfhdkjgsdklxxd";
const password = "hey"; const password = "hey";
//console.log(window.crypto.getRandomValues)
expect(await encryptStringToBase32(k, password)).to.not.equal(k); expect(await encryptStringToBase32(k, password)).to.not.equal(k);
}); });
}); });

View File

@ -38,7 +38,6 @@ module.exports = {
// console: require.resolve("console-browserify"), // console: require.resolve("console-browserify"),
// constants: require.resolve("constants-browserify"), // constants: require.resolve("constants-browserify"),
// crypto: require.resolve("crypto-browserify"), // crypto: require.resolve("crypto-browserify"),
crypto: false, // deliberately set to false, since we use webcrypto here
// domain: require.resolve("domain-browser"), // domain: require.resolve("domain-browser"),
// events: require.resolve("events"), // events: require.resolve("events"),
// http: require.resolve("stream-http"), // http: require.resolve("stream-http"),