Files
start-os/sdk/base/lib/s9pk/merkleArchive/fileContents.ts
Aiden McClelland 855c1f1b07 style(sdk): apply prettier with single quotes
Run prettier across sdk/base and sdk/package to apply the
standardized quote style (single quotes matching web).
2026-02-05 13:34:01 -07:00

25 lines
675 B
TypeScript

import { blake3 } from '@noble/hashes/blake3'
import { ArrayBufferReader } from '.'
import { compare } from '..'
export class FileContents {
private constructor(readonly contents: Blob) {}
static deserialize(
source: Blob,
header: ArrayBufferReader,
size: bigint,
): FileContents {
const position = header.nextU64()
return new FileContents(
source.slice(Number(position), Number(position + size)),
)
}
async verified(hash: Uint8Array): Promise<ArrayBuffer> {
const res = await this.contents.arrayBuffer()
if (!compare(hash, blake3(new Uint8Array(res)))) {
throw new Error('hash sum mismatch')
}
return res
}
}