/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { Construction, Crypto, StorageContext } from "@matter/general"; /** Maximum 32 bit counter value. Per Matter spec the counter wraps from 0xFFFFFFFF to 0. */ export declare const MAX_COUNTER_VALUE_32BIT = 4294967295; export declare enum MessageCounterTypes { /** * Used for "Unsecure" sessions * Rollover allowed, Persistence: Optional */ GlobalUnencrypted = 0, /** * Used for "Group" sessions to encode regular data messages encrypted with a group key. * Lifetime: Operational Group Key, Rollover allowed, Persistence: Mandatory */ GlobalEncryptedData = 1, /** * Used for "Group" sessions to encode control messages encrypted with a group key. * Lifetime: Operational Group Key, Rollover allowed, Persistence: Mandatory */ GlobalEncryptedControl = 2, /** * Used for "Unicast" sessions * Lifetime: Session Key, Rollover expires, Persistence: Optional */ SecureSession = 3 } /** * Represents a message counter which gets randomly initialized and then incremented for each message. * Rollover can be allowed or forbidden and a callback can be provided to be notified before a rollover would happen. */ export declare class MessageCounter { protected readonly onRollover?: (() => Promise) | undefined; protected readonly rolloverInfoDifference: number; protected messageCounter: number; /** * Creates a new message counter with a random start value. If a aboutToRolloverCallback is provided this * counter is not allowed to rollover and the callback is called before a rollover would happen. Optionally provide * a number of messages before the rollover callback is called (Default 1000). */ constructor(crypto: Crypto, onRollover?: (() => Promise) | undefined, rolloverInfoDifference?: number); getIncrementedCounter(): Promise; } /** Options for {@link PersistedMessageCounter}. */ export interface PersistedMessageCounterOptions { aboutToRolloverCallback?: () => Promise; rolloverInfoDifference?: number; /** * When set, persist the counter a block of this size ahead instead of on every increment: the stored value is kept * `reserve` above the in-RAM counter and only re-written when the counter crosses it. An unclean restart then * resumes at the reserved mark — above any value already issued — so the counter never rolls back (Matter spec * §4.6.1.3 for the group data counter; matches CHIP `GROUP_MSG_COUNTER_MIN_INCREMENT`). Up to `reserve` values are * skipped per unclean restart. */ reserve?: number; /** Initial counter value to use when no value is persisted yet, instead of a random start. */ seed?: number; } /** Enhanced Message counter that can be persisted and will be initialized from the persisted value (if existing). */ export declare class PersistedMessageCounter extends MessageCounter { #private; private readonly storageContext; private readonly storageKey; get construction(): Construction; static create(crypto: Crypto, storageContext: StorageContext, storageKey: string, options?: PersistedMessageCounterOptions): Promise; constructor(crypto: Crypto, storageContext: StorageContext, storageKey: string, options?: PersistedMessageCounterOptions); /** Release the counter's lifetime. The counter keeps counting. */ close(): import("@matter/general").MaybePromise; getIncrementedCounter(): Promise; } //# sourceMappingURL=MessageCounter.d.ts.map