Skip to main content
Deno 2 is finally here πŸŽ‰οΈ
Learn more
Module

x/earthstar/mod.ts

Earthstar is a tool for private, undiscoverable, offline-first networks.
Go to Latest
import * as earthstar from "https://deno.land/x/earthstar@v10.0.0-alpha.3/mod.ts";

Classes

An attachment driver which persists attachments using the local filesystem. Works with Deno and Node.

An attachment driver which persists attachments in memory. Works everywhere.

A pub won't accept writes

A replica driver which perists to LocalStorage, which stores a maximum of five megabytes per domain. If you're storing multiple shares, this limit will be divided among all their replicas. Works in browsers and Deno.

An in-memory replica driver. Its contents will be lost when it is closed. Works everywhere.

A strorage driver which persists to SQLite. Works in Deno and browsers.

Generic top-level error class that other Earthstar errors inherit from.

A replica holding a share's documents and attachments, used to read, write, and synchronise data to. Should be closed using the close method when no longer being used.

A pub URL is bad or the network is down

A syncing partner to be used with local instances of IPeer. Works everywhere.

A syncing partner to be used with replica servers reachable via the internet. Works everywhere.

A syncing partner created from an inbound HTTP connection. Works everywhere, but is really meant for Deno and Node.

Holds many shares' replicas and manages their synchronisation with other peers. Recommended as the point of contact between your application and Earthstar shares.

A cached, synchronous interface to a replica, useful for reactive abstractions. Always returns results from its cache, and proxies the query to the backing replica in case of a cache miss.

An IReplica or IReplicaDriver was used after close() was called on it.

An IReplica or IReplicaDriver was used after close() was called on it.

Syncs the contents of a Peer's replicas with that of another peer's.

Validation failed on a document, share address, author address, etc.

Variables

Lowercase alphabetical characters.

Uppercase alphabetical characters.

All characters allowed in an identity's public address.

All characters allowed in an identity's pub key.

All characters allowed in an identity's short name.

All characters allowed in base32.

Higher-level crypto functions. Not used directly for the most part, but useful for generating new keypairs.

A verison of the ICryptoDriver interface backed by noble/ed25519. The slowest crypto driver available. Works in the browser, Deno, and Node.

A verison of the ICryptoDriver interface backed a WASM wrapper of libsodium. Faster than noble by several magnitudes. Works in deno and the browser.

All digits.

Validator for the 'es.4' format. Checks if documents are spec-compliant before ingesting, and signs them according to spec.

Format for 'es.5' documents. Supports attachments.

All characters permitted in a document's path.

All special characters permitted in a document's path.

All characters allowed in a share's address.

All charaters allowed in a share's key.

All characters allowed in a share's name.

Functions

Put a short name and pub key together into an identity address.

Put a share name and encoded pub key together into a share address.

Encode uint8array bytes to base32 string

Decode base32 string to a uint8array of bytes. Throw a ValidationError if the string is bad.

Check that an identity address is valid.

Check that a share address is valid.

example usage: myArrayOfArrays.sort(arrayCompare)

Convert a keypair (author / share) back into a raw KeypairBytes for use in crypto operations.

Return whether a document is expired or not

Combine a shortname with a raw KeypairBytes to make an AuthorKeypair

Combine a name with a raw KeypairBytes to make an ShareKeypair

Returns a valid share address generated using a given name.

Given an array of format names, and an array of IFormat, returns an array of IFormat restricted to those with matching names.

Returns an object with format names as keys, and corresponding IFormat as values.

Returns the default formats if no formats are given.

Returns the default format if no formats are given.

Check if any value is a subclass of EarthstarError (return true) or not (return false)

Check that a string contains only printable ASCII

Check if any value is a subclass of EarthstarError (return false) or not (return true)

Check that a string only contains character from a string of allowed characters.

Parse an author address into its parts.

Parse a share or author address into its parts

Parse a workspace address into its parts.

Set the crypto driver used for all cryptographic operations.

Returns a promise which is fulfilled after a given number of milliseconds.

Syncs an earthstar replica with a directory on the filesystem, representing Earthstar documents as files and vice versa. Make sure you understand the changes this function could enact upon a given directory before using it, as it can delete files in certain circumstances.

  • Changes from the filesystem which are superseded by writes from the replica will still be synced to the replica as an older version of the document, provided they were authored by different identities.
  • If a document has a certain extension (e.g. .jpg, .mp3), the syncer assumes the contents are base64 encoded when writing data to the filesystem.
  • If a file has a path containing a ! (i.e. an ephemeral path), it will be deleted unless a correspending document is found in the replica.

Interfaces

A keypair used by individual entities to sign documents.

The core properties all documents must implement, regardless of format.

Contains data written and signed by an identity.

Contains data written and signed by an identity.

A partial es.4 doc that is about to get written. The rest of the properties will be computed automatically.

A partial es.5 doc that is about to get written. The rest of the properties will be computed automatically.

Higher-level crypto functions. Not used directly for the most part, but useful for generating new keypairs.

A crypto driver provides low-level access to an implementation providing ed25519 cryptography, e.g. Chloride, noble/ed25519, Node crypto.

Formats are each responsible for one document format such as "es.4". They are used for signing and validating documents, as well as generating new documents from a given input.

Holds many shares' replicas and manages their synchronisation with other peers. Recommended as the point of contact between your application and Earthstar shares.

An attachment driver provides low-level access to a replica's attachments. ReplicaAttachmentDrivers are not meant to be used directly by users; let the Replica talk to it for you.

A document driver provides low-level access to a replica's documents. ReplicaDocDrivers are not meant to be used directly by users; let the Replica talk to it for you.

A replica driver provides low-level access to a replica's documents and attachments. ReplicaDrivers are not meant to be used directly by users; let the Replica talk to it for you.

Provides a syncer with the means to connect the peer being synced with (the partner).

Options for configuring a new replica.

  • validators: Validators for the kinds of documents this replica will replicate, e.g. FormatValidatorEs4.
  • driver: A driver the replica will use to read and persist documents.

Describes a query for fetching documents from a replica.

Filters a query by document attributes.

A compressed description of a group of docs a sync agent possesses

Options to initialise a Syncer with.

  • peer - The peer to synchronise.
  • partner - Determines who you'll be syncing with (e.g. a remote peer on a server, a local peer)
  • mode - Determines what kind of sync to carry out.
  • formats - An optional array of formats to sync. Defaults to just es.5.

Type Aliases

An identity's public address.

The human-identifiable portion of an identity's public address, e.g. suzy.

An attachment associated with a document.

A document with it's attachment merged onto a new attachment property.

Verifies a given type is of type IFormat

Extracts a IFormat's config type

Extracts a IFormat's document type, e.g. DocEs5

Extracts a IFormat's input type, used to generate a new document.

Extracts a IFormat's name, e.g. es.5

Verifies a given type is an array of IFormat

Describes a group of docs under a common path which a syncing replica possesses.

A mode describing whether the HaveEntryKeeper should process only existing docs, or also live ones.

  • IngestEventSuccess β€” a new doc was written
  • IngestEventFailure β€” refused an invalid doc
  • IngestEventNothingHappened β€” ingested an obsolete or duplicate doc

The path of a document, e.g. /images/teapot.png.

An event representing when a QuerySource has processed all existing documents.

  • ExpireEvent - An ephemeral document has expired
  • IngestEvent β€” the result of a replica ingesting a document
  • DocAlreadyExists β€” processing an old doc as you catch up

A mode representing what kind of docs are desired from a query stream.

  • existing - Only pre-existing documents.
  • new - Only documents written after the stream is initiated
  • everything - Both pre-existing and incoming documents.
  • DocAlreadyExists β€” processing an old doc as you catch up
  • IngestEvent β€” the result of a replica ingesting a document
  • ExpireEvent - An ephemeral document has expired
  • AttachmentIngestEvent - A new attachment has been ingested
  • AttachmentPruneEvent - An attachment without a corresponding document has been pruned.
  • ReplicaEventWillClose β€” the replica is about to close
  • ReplicaEventDidClose β€” the replica has closed

A share's public address.

A keypair used to write to a specific share

The human-identifiable portion of a share's address, e.g. gardening.

An event with an Earthstar document and corresponding ID.

A type of message one SyncAgent can send to another.

An event sent when a SyncAgent doesn't want anything anymore, though it'll still serve HAVE requests.

A hash of a replica's entire store of documents, used to quickly check equivalence.

Options used for initialisng a SyncAgent.

  • replica: The replica to represent.
  • mode: Whether to sync only existing docs or keep the connection open for new docs too.

The current status of a SyncAgent

  • requested: The number of documents requested
  • received: The number of requests responded to
  • status: An overall status of the agent. preparing is when it is calculating its HAVE entries, syncing when it has unfulfilled requests, idling when there are no active requests, and done when it has been closed, or received all documents it was interested in.

Signals that a SyncAgent wants a document/documents from another SyncAgent

An event for disclosing which shares a Peer has without actually revealing them. Another peer can use the salt to hash their own shares' addresses and see if they match.

An event a Syncer can send or receive.

A mode which determines when the syncer will stop syncing.

  • once - The syncer will only attempt to sync existing docs and then stop.
  • live - Indefinite syncing, including existing docs and new ones as they are ingested into the replica.

A map of sync statuses by the share address they're associated with.

A SyncAgentEvent addressed to a specific share address.

A UNIX timestamp in microseconds.