@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.
- package/dist/functions.d.ts +2 -9
- package/dist/functions.js +12 -6
- package/package.json +1 -1
package/dist/functions.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
2
|
-
export function sha1(string) {
|
|
3
|
-
|
|
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
|
-
|
|
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 };
|