Class CoreManager

Hierarchy

  • TypedEmitter
    • CoreManager

Constructors

  • Parameters

    • options: {
          autoDownload: undefined | boolean;
          db: BetterSQLite3Database<Record<string, never>>;
          encryptionKeys: undefined | Partial<Record<
              | "auth"
              | "config"
              | "data"
              | "blobIndex"
              | "blob", Buffer>>;
          keyManager: KeyManager;
          logger: undefined | Logger;
          projectKey: Buffer;
          projectSecretKey: undefined | Buffer;
          storage: HypercoreStorage;
      }
      • autoDownload: undefined | boolean

        Immediately start downloading cores - should only be set to false for tests

      • db: BetterSQLite3Database<Record<string, never>>

        Drizzle better-sqlite3 database instance

      • encryptionKeys: undefined | Partial<Record<
            | "auth"
            | "config"
            | "data"
            | "blobIndex"
            | "blob", Buffer>>

        Encryption keys for each namespace

      • keyManager: KeyManager

        mapeo/crypto KeyManager instance

      • logger: undefined | Logger
      • projectKey: Buffer

        32-byte public key of the project creator core

      • projectSecretKey: undefined | Buffer

        32-byte secret key of the project creator core

      • storage: HypercoreStorage

        Folder to store all hypercore data

    Returns CoreManager

Accessors

  • get deviceId(): string
  • Returns string

  • get namespaces(): readonly ["auth", "config", "data", "blobIndex", "blob"]
  • Returns readonly ["auth", "config", "data", "blobIndex", "blob"]

Methods

  • ONLY FOR TESTING Replicate all cores in core manager

    NB: Remote peers need to be manually added when unit testing core manager without the Sync API

    Parameters

    • stream: any

    Returns ReplicationStream

  • Add a core to the manager (will be persisted across restarts)

    Parameters

    • key: Buffer

      32-byte public key of core to add

    • namespace:
          | "auth"
          | "config"
          | "data"
          | "blobIndex"
          | "blob"

    Returns CoreRecord

  • Close all open cores and end any replication streams TODO: gracefully close replication streams

    Returns Promise<void>

  • Parameters

    • namespace:
          | "config"
          | "data"
          | "blobIndex"
          | "blob"

    Returns Promise<void>

  • Get a core by its discovery key

    Parameters

    • discoveryKey: Buffer

    Returns undefined | CoreRecord

  • Get a core by its public key

    Parameters

    • key: Buffer

    Returns undefined | Core

  • Get an array of all cores in the given namespace

    Parameters

    • namespace:
          | "auth"
          | "config"
          | "data"
          | "blobIndex"
          | "blob"

    Returns CoreRecord[]

  • Get the writer core for the given namespace

    Parameters

    • namespace:
          | "auth"
          | "config"
          | "data"
          | "blobIndex"
          | "blob"

    Returns CoreRecord

  • Resolves when all cores have finished loading

    Returns Promise<void>