Files
start-os/sdk/lib/s9pk/merkleArchive/fileContents.ts
Aiden McClelland 822dd5e100 Feature/UI sideload (#2658)
* ui sideloading

* remove subtlecrypto import

* fix parser

* misc fixes

* allow docker pull during compat conversion
2024-06-28 21:03:01 +00: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
}
}