Skip to content

Commit

Permalink
replace-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
uriva committed Sep 26, 2024
1 parent 4782f11 commit e773618
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 3 additions & 4 deletions client/src/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import {
hexToBuffer,
} from "https://deno.land/x/[email protected]/mod.ts";
import { jsonStringify } from "https://deno.land/x/[email protected]/jsonStringify.ts";

import sjcl from "npm:sjcl";
import { decode as base64UrlDecode } from "https://deno.land/[email protected]/encoding/base64url.ts";
import { sha256 } from "https://denopkg.com/chiefbiiko/[email protected]/mod.ts";

const algo = "AES-CBC";

const getKey = (scope: "encrypt" | "decrypt", key: string) =>
crypto.subtle.importKey("raw", base64UrlDecode(key), algo, true, [scope]);

const hash = (x: string): string => sha256(x, "utf8", "hex") as string;
const sha256 = (x: string) => sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(x));

export const encrypt =
(key: string) => async (plainText: string): Promise<Encrypted> => {
Expand Down Expand Up @@ -57,4 +56,4 @@ export const inputToCacheKey =
// deno-lint-ignore no-explicit-any
<Args extends any[]>(secret: string, customKeyFn: CustomKeyFn | undefined) =>
(...x: Args): string =>
hash(jsonStableStringify(customKeyFn ? customKeyFn(...x) : x) + secret);
sha256(jsonStableStringify(customKeyFn ? customKeyFn(...x) : x) + secret);
7 changes: 6 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e773618

Please sign in to comment.