fix(build): 补齐 hash 工具并新增 AGENTS 规范

This commit is contained in:
liumangmang
2026-03-06 14:32:52 +08:00
parent 1c99136944
commit ffb22e6f3b
2 changed files with 162 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
export async function sha256HexOfBlob(blob: Blob): Promise<string | null> {
if (!('crypto' in globalThis) || !globalThis.crypto?.subtle) {
return null;
}
try {
const buffer = await blob.arrayBuffer();
const digest = await globalThis.crypto.subtle.digest('SHA-256', buffer);
return bytesToHex(new Uint8Array(digest));
} catch {
return null;
}
}
function bytesToHex(bytes: Uint8Array): string {
let hex = '';
for (const byte of bytes) {
hex += byte.toString(16).padStart(2, '0');
}
return hex;
}