Skip to main content
Module

x/earthstar/mod.browser.ts>IFormatValidator

A specification and Javascript library for building online tools you can truly call your own.
Go to Latest
interface IFormatValidator
Re-export
import { type IFormatValidator } from "https://deno.land/x/earthstar@v9.3.3/mod.browser.ts";

Validators are each responsible for one document format such as "es.4". They are used by Storage instances to check if documents are valid before accepting them and sign new documents.

Properties

format: FormatName

The string name of the format, like "es.4"

Methods

hashDocument(doc: Doc): Promise<Base32String | ValidationError>

Deterministic hash of this version of the document

signDocument(keypair: AuthorKeypair, doc: Doc): Promise<Doc | ValidationError>

Add an author signature to the document. The input document needs a signature field to satisfy Typescript, but it will be overwritten here, so you may as well just set signature: '' on the input. Return a copy of the original document with the signature field changed, or return a ValidationError.

removeExtraFields(doc: Doc): { doc: Doc; extras: Record<string, any>; } | ValidationError

Return a copy of the doc without extra fields, plus the extra fields as a separate object. If the input is not a plain javascript object, return a ValidationError. This should be run before checkDocumentIsValid. The output doc will be more likely to be valid once the extra fields have been removed.

checkDocumentIsValid(doc: Doc, now?: number): true | ValidationError

This calls all the more detailed functions which start with underscores. Returns true if the document is ok.

_checkBasicDocumentValidity(doc: Doc): true | ValidationError
_checkAuthorCanWriteToPath(author: AuthorAddress, path: Path): true | ValidationError
_checkTimestampIsOk(
timestamp: number,
deleteAfter: number | null,
now: number,
): true | ValidationError
_checkPathIsValid(path: Path, deleteAfter?: number | null): true | ValidationError
_checkAuthorSignatureIsValid(doc: Doc): Promise<true | ValidationError>
_checkContentMatchesHash(content: string, contentHash: Base32String): Promise<true | ValidationError>