reticulum-js
    Preparing search index...

    Represents a Reticulum destination — an addressable endpoint that can announce, receive packets, encrypt/decrypt, and establish Links.

    Hierarchy

    • EventTarget
      • Destination
    Index
    • Low-level constructor. Prefer the static factories (Destination.IN, Destination.OUT, etc.) which also compute the destination hashes.

      Parameters

      • name: string

        The application name.

      • direction: number

        The direction of this destination.

      • type: number

        The type of this destination.

      • identity: Identity | null = null

        The identity associated with this destination.

      • interfaceLayer: Reticulum | null = null

        An object that manages destinations and dispatches link requests.

      Returns Destination

    _announceGeneration: number
    _announceIntervalMs: number
    _announceTimer: Timeout | null
    appData: Uint8Array<ArrayBufferLike> | null

    Per-destination app_data override (§4.5). When set it takes precedence over identity.appData in announces, so destinations sharing an identity (e.g. lxmf.delivery and lxmf.propagation) can each advertise their own app_data.

    destinationHash: Uint8Array<ArrayBufferLike> | null
    direction: number
    identity: Identity | null
    interfaceLayer: Reticulum | null
    latestRatchetTime: number
    name: string
    nameHash: Uint8Array<ArrayBufferLike> | null
    pathResponses: Map<
        string,
        { announceData: Uint8Array; hasRatchet: boolean; time: number },
    >
    ratchetInterval: number
    ratchets: { privateKey: Uint8Array; publicKey: Uint8Array }[] | null
    ratchetsEnabled: boolean
    requestHandlers: Map<string, RequestHandler>

    Registered REQUEST handlers keyed by hex(SHA-256(path)[:16]) (PROTOCOL-SPEC.md §11.3). The path string itself is never sent on the wire — only its 16-byte truncated hash — so a client must already know the path to fetch the resource at it.

    type: number
    DEFAULT_ANNOUNCE_INTERVAL_MS: number = ...

    Default periodic re-announce interval. The Python reference has no upstream-mandated default for application destinations — its Transport.mgmt_announce_interval (2 h) and interface-discovery cadence (6 h) are transport-internal, not what end-user destinations announce at. PROTOCOL-SPEC.md §9.7 recommends 30–60 min for a desktop client and notes Sideband emits roughly every 30 min; 30 min keeps cached mesh paths fresh against transit-relay TTLs without dominating airtime.

    knownDestinations: Map<string, any[]> = ...

    Storage for known destinations.

    knownRatchets: Map<string, { ratchet: Uint8Array; received: number }> = ...

    Known ratchet X25519 public key per peer destination (SPEC.md §4.5 step 6.2, §7.4) — the single newest ratchet learned from that peer's validated announces. Maps hex destination hash → { ratchet, received }. Only the newest ratchet is retained (a newer announce overwrites); entries expire after Destination.RATCHET_EXPIRY_MS. Consumed by the outbound encrypt path for forward secrecy.

    MAX_RATCHETS: number = 512

    Maximum number of retained ratchet keys for decryption tolerance.

    MIN_ANNOUNCE_INTERVAL_MS: number = ...

    Floor below which a requested interval is clamped. PROTOCOL-SPEC.md §9.7: "AVOID < 60 s — short intervals trigger ingress rate limiting (§4.5 step 8) and burn ratchet-ring slots without benefit". Sub-minute intervals are clamped to this value with a warning rather than rejected outright.

    PR_TAG_WINDOW: number = 30

    Seconds a path-response announce payload stays reusable for retransmitted path? requests with the same tag (Python Destination.PR_TAG_WINDOW).

    RATCHET_EXPIRY_MS: number = ...

    How long a learned peer ratchet stays valid, in milliseconds (default 30 days). Mirrors RNS.Identity.RATCHET_EXPIRY. Past this a peer ratchet is dropped and the long-term key is used until a fresh announce arrives.

    RATCHET_INTERVAL_MS: number = ...

    Default ratchet rotation interval (Destination.RATCHET_INTERVAL = 30 min). A destination with ratchets enabled rotates its key at most this often.

    • The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

      MDN Reference

      Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | AddEventListenerOptions

      Returns void

    • Broadcasts an Announce packet advertising this destination's public key, name hash and signed metadata so peers can learn and remember it.

      Emits with context = NONE (a regular periodic announce). Use announcePathResponse to answer a path? request.

      Returns Promise<void>

    • Broadcasts a path-response announce — identical body to a regular announce (§4.1) but with the outer packet's context byte set to PATH_RESPONSE = 0x0B (§7.2.4). Emitted in answer to an inbound path? request so the requester can learn a route back to us. The announce body validates identically under §4.5; only the context byte distinguishes it.

      When called with the requesting PR's tag, the signed announce payload is cached for PR_TAG_WINDOW seconds and retransmissions with the same tag reuse it — mirroring the Python reference's path_responses cache, which keeps PR floods from forcing a fresh signature (and ratchet rotation) per retransmitted request.

      Parameters

      • Optionaltag: Uint8Array<ArrayBufferLike> | null = null

        The path? request tag that triggered this response, when known.

      Returns Promise<void>

    • Initiates an encrypted link to this remote (OUT) destination.

      Delegates to Link.initiate, which generates the ephemeral keypair, builds and sends the LINKREQUEST, registers the link with the transport, and transitions to HANDSHAKE. This method then awaits Link.whenActive() so that the returned link is fully established (LRPROOF validated, session keys derived) and ready to carry application DATA — e.g. it is safe to call link.identify(...) immediately on the resolved value.

      Returns Promise<Link>

    • Decrypts data that was encrypted for this destination's identity.

      Tries each owned ratchet private key (newest first) before the long-term key (§7.4), so messages encrypted to a just-rotated ratchet still decrypt. Returns null when decryption fails (wrong recipient / unknown key).

      Parameters

      • data: Uint8Array<ArrayBufferLike>

      Returns Promise<Uint8Array<ArrayBufferLike> | null>

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      MDN Reference

      Parameters

      • event: Event

      Returns boolean

    • Enables forward-secrecy ratchets on this destination (§7.4).

      The owned ratchet private-key ring is persisted (signed by this destination's identity) so a restart can still decrypt messages encrypted to prior ratchets. On the first run (no persisted ring) an initial key is generated immediately; otherwise the persisted ring is loaded and a fresh key is rotated on the next announce. Inbound packets are decrypted against the private ring before the long-term key.

      Returns Promise<void>

    • Encrypts data for this destination's identity.

      Parameters

      • data: Uint8Array<ArrayBufferLike>

      Returns Promise<Uint8Array<ArrayBufferLike>>

    • Registers a server-side REQUEST handler for a path string (PROTOCOL-SPEC.md §11.3, §11.4).

      The path is hashed to SHA-256(path)[:16] and stored keyed by that hash; the path string itself never appears on the wire. When a REQUEST arrives on a Link whose responder destination is this one, Link._handleRequest looks the handler up by the path hash, enforces the allow mode, and invokes responseGenerator to produce the response value.

      Parameters

      • path: string

        Opaque path token (e.g. "/page/index.mu").

      • options: {
            allow?: number;
            allowedList?: Uint8Array<ArrayBufferLike>[];
            autoCompress?: boolean;
            responseGenerator: RequestGenerator;
        }
        • Optionalallow?: number

          Authorization mode.

        • OptionalallowedList?: Uint8Array<ArrayBufferLike>[]

          Identity hashes permitted under Allow.LIST.

        • OptionalautoCompress?: boolean

          Hint for the (future) Resource response path.

        • responseGenerator: RequestGenerator

          Produces the response value.

      Returns Promise<Uint8Array<ArrayBufferLike>>

      the 16-byte path hash the handler is keyed under.

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

      MDN Reference

      Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | EventListenerOptions

      Returns void

    • Removes a previously registered REQUEST handler.

      Parameters

      • path: string

      Returns Promise<boolean>

      true if a handler was removed.

    • Responds to an incoming LINKREQUEST by accepting the link.

      Delegates to Link.accept, which derives the link_id, generates the responder ephemeral key, derives the session keys, builds and sends the LRPROOF, and registers the link with the transport.

      Parameters

      Returns Promise<Link>

    • Rotates the ratchet ring when the interval has elapsed (Destination.RATCHET_INTERVAL), inserting the newest key at index 0 and capping the ring to Destination.MAX_RATCHETS. Pass force to generate a key unconditionally (used for the initial key). The rotated ring is persisted (signed by the identity) so a restart retains the private keys.

      No-op when ratchets are not enabled.

      Parameters

      • Optionalforce: boolean = false

      Returns Promise<void>

    • Starts periodically re-announcing this destination so cached mesh paths stay fresh (PROTOCOL-SPEC.md §7.5 / §9.7 — "non-optional": without it, transit relays evict the path within minutes and peers can no longer reach you).

      The first announce fires immediately (so the destination becomes reachable as soon as the loop starts), then repeats every intervalMs. Each tick emits an announce (context NONE); a failed tick is logged and does not stop the loop. An announce whose cadence is superseded while it is mid-flight (restart/stop) is dropped before broadcasting, so updating the cadence never emits a straggler.

      Calling this while the loop is already running updates the cadence: the existing timer is cleared and a new one armed at the (possibly new) interval, without emitting an extra immediate announce.

      intervalMs defaults to DEFAULT_ANNOUNCE_INTERVAL_MS and is clamped to MIN_ANNOUNCE_INTERVAL_MS (sub-minute intervals trigger ingress rate limiting and waste airtime — §9.7).

      Parameters

      • Optionaloptions: { intervalMs?: number } = {}
        • OptionalintervalMs?: number

          Cadence in ms (clamped to the floor).

      Returns void

    • Drops expired and obsolete peer ratchets from a known-ratchets map. Called once at startup after persistence hydration (mirrors RNS.Identity._clean_ratchets): an entry is removed when it is past Destination.RATCHET_EXPIRY_MS or its destination is no longer in knownDestinations (the peer was forgotten).

      Parameters

      • OptionalknownRatchets: Map<string, { ratchet: Uint8Array; received: number }> = Destination.knownRatchets

        Defaults to Destination.knownRatchets.

      • OptionalknownDestinations: Map<string, any> = Destination.knownDestinations

        Defaults to Destination.knownDestinations.

      Returns number

      the number of entries removed.

    • Static factory for creating a destination.

      Parameters

      • name: string
      • direction: number
      • type: number
      • identity: Identity | null = null
      • interfaceLayer: Reticulum | null = null

        An object that manages destinations and dispatches link requests.

      Returns Promise<Destination>

    • Recall an identity for a destination or identity hash.

      Parameters

      • targetHash: Uint8Array<ArrayBufferLike>
      • fromIdentityHash: boolean = false

      Returns Promise<Identity | null>

    • Recalls the newest non-expired ratchet public key for a destination, or null. Expired entries (past Destination.RATCHET_EXPIRY_MS) are dropped on read. Consumed by the outbound encrypt path (§7.4).

      Parameters

      • destinationHash: Uint8Array<ArrayBufferLike>

      Returns Uint8Array<ArrayBufferLike> | null

    • Remember a destination.

      Parameters

      • packetHash: Uint8Array<ArrayBufferLike>
      • destinationHash: Uint8Array<ArrayBufferLike>
      • publicKey: Uint8Array<ArrayBufferLike>
      • appData: any = null

      Returns Promise<void>

    • Remembers a ratchet X25519 public key announced for a destination (SPEC.md §4.5 step 6.2). Called only for validated announces where context_flag was set and the ratchet is non-empty. Only the single newest ratchet is retained per destination; re-announcing the SAME ratchet is a no-op (the received time is not refreshed), matching RNS.Identity._remember_ratchet.

      Parameters

      • destinationHash: Uint8Array<ArrayBufferLike>
      • ratchet: Uint8Array<ArrayBufferLike>

        32-byte ratchet X25519 public key.

      Returns void