* @param message - 需要计算哈希值的消息(字符串或ArrayBuffer)
* @returns 返回消息的SHA-256哈希值(十六进制字符串)
*/
export async function sha256(message: ArrayBuffer | string): Promise<string> {
const isArrayBuffer: boolean = Object.prototype.toString.call(message) === '[object ArrayBuffer]'
const msgUint8: ArrayBuffer = isArrayBuffer ? (message as ArrayBuffer) : new TextEncoder().encode(message as string)
const hashBuffer: ArrayBuffer = await globalThis.crypto.subtle.digest('SHA-256', msgUint8)
const hashArray: number[] = Array.from(new Uint8Array(hashBuffer))
const hashHex: string = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')
return hashHex
}