aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/pkg/encryption.test.ts
diff options
context:
space:
mode:
authorHsiangNianian <admin@jyunko.cn>2023-04-17 18:53:55 +0000
committerHsiangNianian <admin@jyunko.cn>2023-04-17 18:53:55 +0000
commitb135aac8531c1e1488147ad8c6f98eddbdbe0c99 (patch)
tree189e9fea7109564d63207e231d5b0e5624243072 /pkg/encryption.test.ts
downloadHydroRoll-b135aac8531c1e1488147ad8c6f98eddbdbe0c99.tar.gz
HydroRoll-b135aac8531c1e1488147ad8c6f98eddbdbe0c99.zip
Initial commit
Created from https://vercel.com/new
Diffstat (limited to 'pkg/encryption.test.ts')
-rw-r--r--pkg/encryption.test.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/pkg/encryption.test.ts b/pkg/encryption.test.ts
new file mode 100644
index 0000000..5d4cf15
--- /dev/null
+++ b/pkg/encryption.test.ts
@@ -0,0 +1,24 @@
+import { describe, it, expect, beforeAll } from "@jest/globals";
+import { decrypt, encrypt } from "./encryption";
+import crypto from "node:crypto";
+import { toBase58 } from "../util/base58";
+
+beforeAll(() => {
+ global.crypto = crypto.webcrypto;
+});
+describe("aes", () => {
+ it("encrypts and decrypts correctly", async () => {
+ for (let i = 0; i < 500; i++) {
+ const buf = new Uint8Array(Math.ceil(Math.random() * 10 * i));
+ crypto.getRandomValues(buf);
+
+ const text = toBase58(buf);
+
+ const { encrypted, key, iv } = await encrypt(text);
+
+ const decrypted = await decrypt(toBase58(encrypted), key, toBase58(iv), 2);
+
+ expect(decrypted).toEqual(text);
+ }
+ }, 30_000);
+});