From e7736188ddc110e73af44073e2115d09c7bfeac9 Mon Sep 17 00:00:00 2001 From: uri Date: Fri, 27 Sep 2024 06:51:39 +0900 Subject: [PATCH] replace-lib --- client/src/crypto.ts | 7 +++---- deno.lock | 7 ++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client/src/crypto.ts b/client/src/crypto.ts index 1d854cd..3fe396a 100644 --- a/client/src/crypto.ts +++ b/client/src/crypto.ts @@ -3,16 +3,15 @@ import { hexToBuffer, } from "https://deno.land/x/hextools@v1.0.0/mod.ts"; import { jsonStringify } from "https://deno.land/x/stable_stringify@v0.2.1/jsonStringify.ts"; - +import sjcl from "npm:sjcl"; import { decode as base64UrlDecode } from "https://deno.land/std@0.82.0/encoding/base64url.ts"; -import { sha256 } from "https://denopkg.com/chiefbiiko/sha256@v1.0.0/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 => { @@ -57,4 +56,4 @@ export const inputToCacheKey = // deno-lint-ignore no-explicit-any (secret: string, customKeyFn: CustomKeyFn | undefined) => (...x: Args): string => - hash(jsonStableStringify(customKeyFn ? customKeyFn(...x) : x) + secret); + sha256(jsonStableStringify(customKeyFn ? customKeyFn(...x) : x) + secret); diff --git a/deno.lock b/deno.lock index 7f24a25..937a678 100644 --- a/deno.lock +++ b/deno.lock @@ -2,7 +2,8 @@ "version": "3", "packages": { "specifiers": { - "npm:open@9.1.0": "npm:open@9.1.0" + "npm:open@9.1.0": "npm:open@9.1.0", + "npm:sjcl": "npm:sjcl@1.0.8" }, "npm": { "big-integer@1.6.51": { @@ -194,6 +195,10 @@ "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", "dependencies": {} }, + "sjcl@1.0.8": { + "integrity": "sha512-LzIjEQ0S0DpIgnxMEayM1rq9aGwGRG4OnZhCdjx7glTaJtf4zRfpg87ImfjSJjoW9vKpagd82McDOwbRT5kQKQ==", + "dependencies": {} + }, "strip-final-newline@2.0.0": { "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", "dependencies": {}