Marmot-TS
    Preparing search index...

    Class KeyPackageManager

    Manages the full lifecycle of MLS key packages — local private material and the Nostr kind-30443 events that advertise this client to potential inviters.

    A thin coordinator over a KeyPackageStore (persistence) and a KeyPackagePublisher (the sign/publish boundary).

    Hierarchy

    Index

    Client - Key Package Manager

    clientId: string | undefined

    Default slot identifier (d tag value) used by create when no explicit d is passed in options. Set this to a stable string (e.g. "my-app-desktop") so all key packages from this manager share a single addressable slot on relays.

    • Retrieves the private key material for a key package. Used internally by MarmotClient when processing Welcome messages.

      Parameters

      • ref: string | Uint8Array<ArrayBufferLike>

        The key package reference

      Returns Promise<PrivateKeyPackage | null>

      The private key package, or null if not found

    • Completely purges one or more key packages: publishes a NIP-09 deletion for all known relay event IDs, removes local private key material, and clears the publish records.

      Parameters

      • refs: string | Uint8Array<ArrayBufferLike> | (string | Uint8Array<ArrayBufferLike>)[]

        One or more key package references (hex string or Uint8Array)

      Returns Promise<void>

    • Removes a key package from local private key storage only.

      Does not publish a relay deletion and does not touch publish records. Use when the key package was never published, or when relay cleanup has already been handled separately.

      Parameters

      • ref: string | Uint8Array<ArrayBufferLike>

        The key package reference to remove

      Returns Promise<void>

    • Rotates a key package: publishes a new kind 30443 event (reusing the same d slot so relays replace the old event automatically), then removes the old private key material.

      Kind-30443 published events do not need explicit deletion — the new event supersedes them on relays.

      Parameters

      • ref: string | Uint8Array<ArrayBufferLike>

        The key package reference of the key package to rotate

      • Optionaloptions: RotateKeyPackageOptions

        Options for the new key package

      Returns Promise<ListedKeyPackage>

      The new stored key package (without private material)

      if the key package ref is not found in the local store

      if no relay URLs can be determined for the new key package

    • Selects the locally-held key packages that could receive a given Welcome, ordered with the RFC 9420 KeyPackageRef matches first.

      Filters to packages whose ciphersuite matches the Welcome and for which local private material is held, computes whether each package's ref matches one of the Welcome's encrypted secrets, and returns the matching packages before the non-matching ones so GroupsManager.joinFromWelcome tries the most likely candidate first. This is the TypeScript analog of the private key-bundle lookup the darkmatter engine performs inside do_join_welcome.

      Parameters

      • welcome: Welcome

        The decoded MLS Welcome message.

      Returns Promise<WelcomeKeyPackageCandidate[]>

      Candidate key packages in priority order (may be empty).

    • Observes a Nostr event and, if it is a kind 30443 key package event whose i tag (MIP-00 KeyPackageRef) matches its decoded body, records it in the store. Events with no i tag, an undecodable body, or an i tag that does not match the recomputed ref are rejected.

      Parameters

      • event: NostrEvent

        Any Nostr event; non-key-package events are silently ignored

      Returns Promise<boolean>

      true if the event was recorded, false if ignored or rejected

    Other

    prefixed: string | boolean
    • Type Parameters

      Parameters

      Returns this

    • Return an array listing the events for which the emitter has registered listeners.

      Returns (keyof KeyPackageManagerEvents)[]

    • Return the number of listeners listening to a given event.

      Parameters

      Returns number

    • Return the listeners registered for a given event.

      Type Parameters

      Parameters

      • event: T

      Returns (
          (
              ...args: ArgumentMap<KeyPackageManagerEvents>[Extract<
                  T,
                  keyof KeyPackageManagerEvents,
              >],
          ) => void
      )[]

    • Type Parameters

      Parameters

      Returns this

    • Add a listener for a given event.

      Type Parameters

      Parameters

      Returns this

    • Add a one-time listener for a given event.

      Type Parameters

      Parameters

      Returns this

    • Remove all listeners, or those of the specified event.

      Parameters

      • Optionalevent: keyof KeyPackageManagerEvents

      Returns this

    • Remove the listeners of a given event.

      Type Parameters

      Parameters

      Returns this