Files
Endoleap/src/lib/canvas-runtime/import-integrity.ts
T

9 lines
576 B
TypeScript

import { fault } from '../canvas-core/values.ts';
/** Bind durable preparation/parse checkpoints to the complete immutable byte source. */
export async function importSourceDigest(bytes:Blob,signal?:AbortSignal):Promise<string>{
if(signal?.aborted)throw fault('import_aborted');
const buffer=await bytes.arrayBuffer();if(signal?.aborted)throw fault('import_aborted');
const digest=await crypto.subtle.digest('SHA-256',buffer);if(signal?.aborted)throw fault('import_aborted');
return [...new Uint8Array(digest)].map(byte=>byte.toString(16).padStart(2,'0')).join('');
}