Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/earthstar/src/entries/npm.ts>SharedSettings

Storage for private, distributed, offline-first applications.
Go to Latest
class SharedSettings
import { SharedSettings } from "https://deno.land/x/earthstar@v10.2.0/src/entries/npm.ts";

Get and set values from a common pool of settings for Earthstar clients, such as an author, shares, share secrets, and servers.

Uses the Storage API, so only clients on the same origin will share the same settings.

Constructors

new
SharedSettings(opts?: SharedSettingsOpts)

Properties

private
authorChangedCbs: Set<(keypair: AuthorKeypair | null) => void>
private
namespace: string | undefined
private
serversChangedCbs: Set<(shares: string[]) => void>
private
sharesChangedCbs: Set<(shares: ShareAddress[]) => void>
private
shareSecretsChangedCbs: Set<(secrets: Record<ShareAddress, string>) => void>
private
storage
author: AuthorKeypair | null

The currently persisted author keypair.

readonly
servers: string[]

An array of server URLs stored by these settings.

readonly
shares: ShareAddress[]

An array of shares stored by these settings.

readonly
shareSecrets

A record of known shares and their corresponding secret, if known.

Methods

addSecret(shareAddress: ShareAddress, secret: string)

Add a secret for a share already known to the settings.

addServer(address: string): string[] | ValidationError

Add a server URL to be stored by settings.

Add a share to the settings.

Delete all stored settings.

getPeer(unnamed 0: { sync: "once" | "continuous" | false; onCreateReplica: (addr: ShareAddress, secret?: string) => Replica; }): { peer: Peer; unsubscribeFromSettings: () => void; }

Get a new Peer preconfigured with shares, secrets, and syncers derived from these settings.

When settings are updated, the peer's replicas and syncers will be updated too.

onAuthorChanged(cb: (keypair: AuthorKeypair | null) => void)

Fires the given callback when the stored author changes.

onServersChanged(cb: (shares: string[]) => void)

Fires the given callback when the stored list of server URLs changes.

onSharesChanged(cb: (shares: ShareAddress[]) => void)

Fires the given callback when the stored list of shares changes.

onShareSecretsChanged(cb: (secrets: Record<ShareAddress, string>) => void)

Fires the given callback when the stored record of share secrets changes.

redeemInvitationURL(url: string): Promise<true | ValidationError>

Add a new share (and possibly secret) and servers using an Earthstar invitation URL.

removeSecret(shareAddress: ShareAddress)

Remove a secret from settings.

removeServer(addressToRemove: string)

Remove a server URL from the settings' stored list of servers..

removeShare(addressToRemove: string)

Removes a share from settings.