/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import type { DecodedPacket } from "#codec/MessageCodec.js";
import { FabricManager } from "#fabric/FabricManager.js";
import type { Subscription } from "#interaction/Subscription.js";
import { PeerAddress } from "#peer/PeerAddress.js";
import { GroupSession } from "#session/GroupSession.js";
import { BasicSet, Bytes, Channel, ClosedError, ConnectionlessTransport, Construction, Crypto, Environment, Environmental, Observable, StorageContext, Timestamp } from "@matter/general";
import { CaseAuthenticatedTag, FabricId, FabricIndex, NodeId } from "@matter/types";
import type { ExposedFabricInformation, Fabric } from "../fabric/Fabric.js";
import { NodeSession } from "./NodeSession.js";
import type { Session } from "./Session.js";
import { SessionParameters } from "./SessionParameters.js";
import { UnsecuredSession } from "./UnsecuredSession.js";
/** Resumption record without a fabric reference but relevant lookup data used internally in SessionManager */
interface InternalResumptionRecord {
    sharedSecret: Bytes;
    resumptionId: Bytes;
    fabricId: FabricId;
    fabricIndex: FabricIndex;
    peerNodeId: NodeId;
    sessionParameters: SessionParameters;
    caseAuthenticatedTags?: readonly CaseAuthenticatedTag[];
}
/** Resumption record with Fabric reference. */
export interface ResumptionRecord extends Omit<InternalResumptionRecord, "fabricId" | "fabricIndex"> {
    fabric: Fabric;
}
export interface ActiveSessionInformation {
    name: string;
    nodeId: NodeId;
    peerNodeId: NodeId;
    fabric?: ExposedFabricInformation;
    isPeerActive: boolean;
    secure: boolean;
    lastInteractionTimestamp?: number;
    lastActiveTimestamp?: number;
    numberOfActiveSubscriptions: number;
}
/**
 * Interfaces {@link SessionManager} with other components.
 */
export interface SessionManagerContext {
    fabrics: FabricManager;
    storage: StorageContext;
    /**
     * Parameter overrides.
     */
    parameters?: SessionParameters.Config;
    /**
     * This is an arbitrary contextual object attached to sessions used for compatibility with legacy APIs.
     *
     * @deprecated
     */
    owner?: unknown;
}
/**
 * Thrown when communication terminates due node shutdown.
 */
export declare class ShutdownError extends ClosedError {
    constructor(message?: string, options?: ErrorOptions);
}
/**
 * Manages Matter sessions associated with peer connections.
 */
export declare class SessionManager {
    #private;
    constructor(context: SessionManagerContext);
    static [Environmental.create](env: Environment): SessionManager;
    get construction(): Construction<SessionManager>;
    get context(): SessionManagerContext;
    get crypto(): Crypto;
    /**
     * Active secure sessions.
     */
    get sessions(): BasicSet<NodeSession, NodeSession>;
    /**
     * Active unsecured sessions.
     */
    get unsecuredSessions(): Map<NodeId, UnsecuredSession>;
    /**
     * Our session parameters.  These are the parameters we provide during session negotiation.  The peer may specify
     * different parameters.
     */
    get sessionParameters(): SessionParameters;
    /**
     * Change session parameters.
     *
     * Parameters values you omit in {@link parameters} will retain their current values.  This only affects new
     * sessions.
     */
    set sessionParameters(parameters: Partial<SessionParameters>);
    /**
     * Emits when there is a change to the subscription set.
     */
    get subscriptionsChanged(): Observable<[session: NodeSession, subscription: Subscription], void>;
    /**
     * Emits when resubmission is necessary due to timeout or network error.
     */
    get retry(): Observable<[session: Session, number: number], void>;
    /**
     * Convenience function for accessing a fabric by address.
     */
    fabricFor(address: FabricIndex | PeerAddress): Fabric;
    /**
     * @deprecated
     */
    get owner(): unknown;
    createUnsecuredSession(options: {
        channel: Channel<Bytes>;
        initiatorNodeId?: NodeId;
        sessionParameters?: SessionParameters.Config;
        isInitiator?: boolean;
    }): UnsecuredSession;
    createSecureSession(config: Omit<NodeSession.CreateConfig, "crypto"> & {
        crypto?: Crypto;
    }): Promise<NodeSession>;
    /**
     * Deletes a resumption record for a given address.  Returns true if the record was deleted, false if it did not
     * exist.
     */
    deleteResumptionRecord(address: PeerAddress): Promise<boolean>;
    /**
     * Deletes all resumption records for a given fabric.  Returns true if any records were deleted, false if none
     * existed.
     */
    deleteResumptionRecordsForFabric(fabric: Fabric): Promise<boolean>;
    findOldestInactiveSession(): NodeSession;
    getNextAvailableSessionId(): Promise<number>;
    getSession(sessionId: number): NodeSession | undefined;
    getPaseSession(): NodeSession | undefined;
    forFabric(fabric: Fabric): NodeSession[];
    sessionFor(peer: PeerAddress): NodeSession;
    maybeSessionFor(address: PeerAddress): NodeSession | undefined;
    sessionsFor(address: PeerAddress): NodeSession[];
    sessionsForFabricIndex(fabricIndex: FabricIndex): NodeSession[];
    /**
     * Removes all Peer sessions but keeps subscriptions intact because they could be refreshed on restart when the
     * device supports persistent subscriptions.
     */
    handlePeerShutdown(address: PeerAddress, asOf?: Timestamp): Promise<void>;
    /**
     * Removes all Peer sessions and closes subscriptions.
     */
    handlePeerLoss(address: PeerAddress, cause: Error, asOf?: Timestamp): Promise<void>;
    getUnsecuredSession(sourceNodeId?: NodeId): UnsecuredSession | undefined;
    /**
     * Obtain an outbound group session for a specific group.
     *
     * Returns the session for the current group epoch key.  The source is this node and the peer is the group.
     */
    groupSessionForAddress(address: PeerAddress, transports: ConnectionlessTransport.Provider): Promise<GroupSession>;
    /**
     * Obtain a Group session for an incoming packet.
     *
     * The session ID is determined by decrypting the packet with possible keys.
     *
     * Note that the resulting session is non-operational in the sense that attempting outbound communication will
     * result in an error.
     */
    groupSessionFromPacket(packet: DecodedPacket, aad: Bytes): {
        session: GroupSession;
        message: import("#codec/MessageCodec.js").DecodedMessage;
        key: AllowSharedBufferSource;
    };
    registerGroupSession(session: GroupSession): void;
    removeGroupSession(session: GroupSession): void;
    findResumptionRecordById(resumptionId: Bytes): ResumptionRecord | undefined;
    findResumptionRecordByAddress(address: PeerAddress): ResumptionRecord | undefined;
    saveResumptionRecord(resumptionRecord: ResumptionRecord): Promise<void>;
    getActiveSessionInformation(): ActiveSessionInformation[];
    close(): Promise<void>;
    clear(): Promise<void>;
    closeAllSessions(): Promise<void>;
    /**
     * Compress range of IDs.  This is intended for testing.
     */
    compressIdRange(upperBound: number): void;
}
export {};
//# sourceMappingURL=SessionManager.d.ts.map