@yiuayiu/functions 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,2 @@
1
- /// <reference types="node" />
2
- import crypto from "crypto";
3
- export declare function sha1(string: crypto.BinaryLike): string;
4
- export declare function md5(string: crypto.BinaryLike): string;
5
- declare const _default: {
6
- sha1: typeof sha1;
7
- md5: typeof md5;
8
- };
9
- export default _default;
1
+ export declare function sha1(string: string): Promise<string>;
2
+ export declare function md5(string: string): Promise<string>;
package/dist/functions.js CHANGED
@@ -1,8 +1,14 @@
1
- import crypto from "crypto";
2
- export function sha1(string) {
3
- return crypto.createHash("sha1").update(string).digest("hex");
1
+ const { subtle } = globalThis.crypto;
2
+ export async function sha1(string) {
3
+ const encoder = new TextEncoder();
4
+ const data = encoder.encode(string);
5
+ const hashBuffer = await subtle.digest("SHA-1", data);
6
+ return Array.from(new Uint8Array(hashBuffer))
7
+ .map((b) => b.toString(16).padStart(2, "0"))
8
+ .join("");
4
9
  }
5
- export function md5(string) {
6
- return crypto.createHash("md5").update(string).digest("hex");
10
+ export async function md5(string) {
11
+ // Web Crypto API doesn't support MD5 directly as it's considered insecure
12
+ // This would require a separate implementation or a library
13
+ throw new Error("MD5 is not supported by Web Crypto API due to security concerns");
7
14
  }
8
- export default { sha1, md5 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yiuayiu/functions",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "",
5
5
  "main": "dist/functions.js",
6
6
  "type": "module",