generated from Dalkak/sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
24 lines (22 loc) · 958 Bytes
/
index.ts
File metadata and controls
24 lines (22 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import {
Pack, Block, Literal, Type, Dict
} from "dalkak";
declare var TextEncoder: any;
declare var crypto: any;
export default new Pack({
name: "hash",
blocks: {
generateHash: new Block({
name: "generateHash",
template: "((data)로 Hash 생성하기)",
func: async (param, project, platform) => {
const message = param.data;
const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); // hash the message
const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
return hashHex;
}
})
}
});