mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
* ui sideloading * remove subtlecrypto import * fix parser * misc fixes * allow docker pull during compat conversion
25 lines
675 B
TypeScript
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
|
|
}
|
|
}
|