/** GBP-layer group node wrapper (the IP-like base). */ import * as N from "./native"; import { PayloadCodec } from "./native"; import { MlsContext } from "./mls"; /** Stream class. */ export declare enum StreamType { Control = 0, Audio = 1, Text = 2, Signal = 3 } /** Node FSM state. */ export declare enum NodeState { Idle = 0, Connecting = 1, EstablishingGroup = 2, Active = 3, Resyncing = 4, Failed = 5, Closed = 6 } /** Control plane opcode. */ export declare enum ControlOpcode { PrepareTransition = 1, ReadyForTransition = 2, ExecuteTransition = 3, AbortTransition = 4, GroupStateDigestRequest = 5, GroupStateDigestResponse = 6, ReportInvalidCommit = 7, CapabilitiesAdvertise = 8, Ack = 9, Nack = 10 } /** Wire frame produced by the native library. */ export interface OutboundFrame { target: number; wire: Buffer; } /** * Event surfaced by the GBP layer. * * `kind` determines which optional fields are set: * - `state_changed` — `fromState`, `toState` * - `payload_received` — `streamTypeName`, `streamType`, `streamId`, `sequenceNo`, `flags`, `plaintext` * - `control` — `sender`, `opcode`, `opcodeCode`, `transitionId` * - `error` — `code`, `codeHex`, `classCode`, `retryable`, `fatal`, `reason` * - `epoch_advanced` — `epoch`, `transitionId` * - `coordinator_election_needed` — no extra fields; the local node should start the coordinator-election handshake * - `became_coordinator` — no extra fields; this node won the election * - `coordinator_claim` — `claimant` (member id of the peer that sent COORDINATOR_CLAIM) */ export interface NodeEvent { kind: string; fromState?: string; toState?: string; streamTypeName?: string; streamType?: StreamType; streamId?: number; sequenceNo?: number; flags?: number; codec?: PayloadCodec; plaintext?: Buffer; sender?: number; opcode?: string; opcodeCode?: number; transitionId?: number; code?: number; codeHex?: string; classCode?: number; retryable?: boolean; fatal?: boolean; reason?: string; epoch?: bigint; claimant?: number; } /** * Encode a raw GBP frame to CBOR bytes. * * Low-level helper — most callers should use {@link GroupNode.sendControl} * or the sub-protocol `send` methods instead. */ export declare function encodeGbpFrame(version: number, groupId: Buffer, epoch: bigint | number, transitionId: number, streamType: number, streamId: number, flags: number, sequenceNo: number, payload: Buffer): Buffer; /** * Return the CBOR-encoded `ErrorObject` for `code`, or `null` if unknown. */ export declare function lookupError(code: number): Buffer | null; /** @internal Decode the (target, wire) pair returned by ``send_*``. */ export declare function unpackOutbound(buf: N.GbpBuffer, what: string): OutboundFrame; /** * GBP-layer group node. * * Owns the framing, AEAD, replay window, FSM and control plane. * Sub-protocol semantics live in {@link GtpClient}, {@link GapClient} and * {@link GspClient}. */ export declare class GroupNode { /** Native handle (i32). */ handle: number; /** This node's member id. */ readonly memberId: number; private readonly _groupId; private constructor(); /** Create a node bound to ``groupId`` (which MUST be 16 bytes). */ static create(memberId: number, groupId: Buffer): GroupNode; /** Current FSM state. */ get state(): NodeState; /** Current node epoch. */ get epoch(): bigint; /** Last applied ``transition_id``. */ get lastTransitionId(): number; /** 16-byte group identifier. */ get groupId(): Buffer; /** Drive the node from ``IDLE`` to ``ACTIVE`` as a creator. */ bootstrapAsCreator(epoch: bigint | number): void; /** * Drive the node from ``IDLE`` to ``ACTIVE`` as a joiner. * * `expectedFirstTid` pre-arms `pending_transition_id` so the next * `EXECUTE_TRANSITION` is accepted by `handle_control`'s validation * matrix. The matching PREPARE was sealed under the pre-Welcome MLS * epoch and is therefore undecryptable to the joiner; the joiner is * brought into the group when EXECUTE arrives on the new shared epoch. * Pass `0` if the joiner recovered out-of-band and is already current. */ bootstrapAsJoiner(epoch: bigint | number, expectedFirstTid?: number): void; /** Forcibly override ``current_epoch`` (intended for tests of late peers). */ setEpochForTesting(epoch: bigint | number): void; /** Apply an epoch transition locally. */ applyTransition(transitionId: number): void; /** Send a control plane message on Stream 0. */ sendControl(mls: MlsContext, target: number, opcode: ControlOpcode, transitionId: number, requestId: number, args?: Buffer): OutboundFrame; /** Feed wire bytes to the node and return the resulting events. */ onWire(mls: MlsContext, wire: Buffer): NodeEvent[]; /** Drain queued events without consuming any wire bytes. */ drainEvents(): NodeEvent[]; /** Release the native handle. Idempotent. */ close(): void; [Symbol.dispose](): void; } //# sourceMappingURL=node.d.ts.map