"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var administrator_commissioning_exports = {};
__export(administrator_commissioning_exports, {
  AdministratorCommissioning: () => AdministratorCommissioning,
  AdministratorCommissioningCluster: () => AdministratorCommissioningCluster
});
module.exports = __toCommonJS(administrator_commissioning_exports);
var import_MutableCluster = require("../cluster/mutation/MutableCluster.js");
var import_Cluster = require("../cluster/Cluster.js");
var import_TlvObject = require("../tlv/TlvObject.js");
var import_TlvNumber = require("../tlv/TlvNumber.js");
var import_model = require("#model");
var import_BitmapSchema = require("../schema/BitmapSchema.js");
var import_FabricIndex = require("../datatype/FabricIndex.js");
var import_TlvNullable = require("../tlv/TlvNullable.js");
var import_VendorId = require("../datatype/VendorId.js");
var import_TlvString = require("../tlv/TlvString.js");
var import_TlvNoArguments = require("../tlv/TlvNoArguments.js");
var import_StatusResponseError = require("../common/StatusResponseError.js");
var import_Status = require("../globals/Status.js");
var import_ClusterRegistry = require("../cluster/ClusterRegistry.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
var AdministratorCommissioning;
((AdministratorCommissioning2) => {
  let Feature;
  ((Feature2) => {
    Feature2["Basic"] = "Basic";
  })(Feature = AdministratorCommissioning2.Feature || (AdministratorCommissioning2.Feature = {}));
  AdministratorCommissioning2.TlvOpenBasicCommissioningWindowRequest = (0, import_TlvObject.TlvObject)({
    /**
     * This field shall specify the time in seconds during which commissioning session establishment is allowed by
     * the Node. This timeout shall follow guidance as specified in the initial Announcement Duration.
     *
     * When a Node receives the OpenBasicCommissioningWindow command, it shall begin advertising on DNS-SD as
     * described in Section 4.3.1, “Commissionable Node Discovery” and for a time period as
     * describedinCommissioningTimeout. When the command is received by a ICD, it shall enter into active mode. The
     * ICD shall remain in Active Mode as long as one of these conditions is met:
     *
     *   - A commissioning window is open.
     *
     *   - There is an armed fail-safe timer.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.19.8.2.1
     */
    commissioningTimeout: (0, import_TlvObject.TlvField)(0, import_TlvNumber.TlvUInt16)
  });
  let CommissioningWindowStatus;
  ((CommissioningWindowStatus2) => {
    CommissioningWindowStatus2[CommissioningWindowStatus2["WindowNotOpen"] = 0] = "WindowNotOpen";
    CommissioningWindowStatus2[CommissioningWindowStatus2["EnhancedWindowOpen"] = 1] = "EnhancedWindowOpen";
    CommissioningWindowStatus2[CommissioningWindowStatus2["BasicWindowOpen"] = 2] = "BasicWindowOpen";
  })(CommissioningWindowStatus = AdministratorCommissioning2.CommissioningWindowStatus || (AdministratorCommissioning2.CommissioningWindowStatus = {}));
  AdministratorCommissioning2.TlvOpenCommissioningWindowRequest = (0, import_TlvObject.TlvObject)({
    /**
     * This field shall specify the time in seconds during which commissioning session establishment is allowed by
     * the Node. This timeout value shall follow guidance as specified in the initial Announcement Duration. The
     * CommissioningTimeout applies only to cessation of any announcements and to accepting of new commissioning
     * sessions; it does not apply to abortion of connections, i.e., a commissioning session SHOULD NOT abort
     * prematurely upon expiration of this timeout.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.19.8.1.1
     */
    commissioningTimeout: (0, import_TlvObject.TlvField)(0, import_TlvNumber.TlvUInt16),
    /**
     * This field shall specify an ephemeral PAKE passcode verifier (see Section 3.10, “Password-Authenticated Key
     * Exchange (PAKE)”) computed by the existing Administrator to be used for this commissioning. The field is
     * concatenation of two values (w0 || L) shall be (CRYPTO_GROUP_SIZE_BYTES +
     * CRYPTO_PUBLIC_KEY_SIZE_BYTES)-octets long as detailed in Crypto_PAKEValues_Responder. It shall be derived
     * from an ephemeral passcode (See PAKE). It shall be deleted by the Node at the end of commissioning or
     * expiration of the OpenCommissioningWindow command, and shall be deleted by the existing Administrator after
     * sending it to the Node(s).
     *
     * @see {@link MatterSpecification.v142.Core} § 11.19.8.1.2
     */
    pakePasscodeVerifier: (0, import_TlvObject.TlvField)(1, import_TlvString.TlvByteString.bound({ length: 97 })),
    /**
     * This field shall be used by the Node as the long discriminator for DNS-SD advertisement (see Section 4.3.1.5,
     * “TXT key for discriminator (D)”) for discovery by the new Administrator. The new Administrator can find and
     * filter DNS-SD records by long discriminator to locate and initiate commissioning with the appropriate Node.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.19.8.1.3
     */
    discriminator: (0, import_TlvObject.TlvField)(2, import_TlvNumber.TlvUInt16.bound({ max: 4095 })),
    /**
     * This field shall be used by the Node as the PAKE iteration count associated with the ephemeral PAKE passcode
     * verifier to be used for this commissioning, which shall be sent by the Node to the new Administrator’s
     * software as response to the PBKDFParamRequest during PASE negotiation. The permitted range of values shall
     * match the range specified in Section 3.9, “Password-Based Key Derivation Function (PBKDF)”, within the
     * definition of the Crypto_PBKDFParameterSet.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.19.8.1.4
     */
    iterations: (0, import_TlvObject.TlvField)(3, import_TlvNumber.TlvUInt32.bound({ min: 1e3, max: 1e5 })),
    /**
     * This field shall be used by the Node as the PAKE Salt associated with the ephemeral PAKE passcode verifier to
     * be used for this commissioning, which shall be sent by the Node to the new Administrator’s software as
     * response to the PBKDFParamRequest during PASE negotiation. The constraints on the value shall match those
     * specified in Section 3.9, “Password-Based Key Derivation Function (PBKDF)”, within the definition of the
     * Crypto_PBKDFParameterSet.
     *
     * When a Node receives the OpenCommissioningWindow command, it shall begin advertising on DNS-SD as described
     * in Section 4.3.1, “Commissionable Node Discovery” and for a time period as described in CommissioningTimeout.
     *
     * When the command is received by a ICD, it shall enter into active mode. The ICD shall remain in Active Mode
     * as long as one of these conditions is met:
     *
     *   - A commissioning window is open.
     *
     *   - There is an armed fail-safe timer.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.19.8.1.5
     */
    salt: (0, import_TlvObject.TlvField)(4, import_TlvString.TlvByteString.bound({ minLength: 16, maxLength: 32 }))
  });
  let StatusCode;
  ((StatusCode2) => {
    StatusCode2[StatusCode2["Busy"] = 2] = "Busy";
    StatusCode2[StatusCode2["PakeParameterError"] = 3] = "PakeParameterError";
    StatusCode2[StatusCode2["WindowNotOpen"] = 4] = "WindowNotOpen";
  })(StatusCode = AdministratorCommissioning2.StatusCode || (AdministratorCommissioning2.StatusCode = {}));
  class BusyError extends import_StatusResponseError.StatusResponseError {
    constructor(message = "Could not be completed because another commissioning is in progress", code = import_Status.Status.Failure, clusterCode = 2 /* Busy */) {
      super(message, code, clusterCode);
    }
  }
  AdministratorCommissioning2.BusyError = BusyError;
  class PakeParameterError extends import_StatusResponseError.StatusResponseError {
    constructor(message = "Provided PAKE parameters were incorrectly formatted or otherwise invalid", code = import_Status.Status.Failure, clusterCode = 3 /* PakeParameterError */) {
      super(message, code, clusterCode);
    }
  }
  AdministratorCommissioning2.PakeParameterError = PakeParameterError;
  class WindowNotOpenError extends import_StatusResponseError.StatusResponseError {
    constructor(message = "No commissioning window was currently open", code = import_Status.Status.Failure, clusterCode = 4 /* WindowNotOpen */) {
      super(message, code, clusterCode);
    }
  }
  AdministratorCommissioning2.WindowNotOpenError = WindowNotOpenError;
  AdministratorCommissioning2.BasicComponent = import_MutableCluster.MutableCluster.Component({
    commands: {
      /**
       * This command may be used by a current Administrator to instruct a Node to go into commissioning mode, if
       * the node supports the Basic Commissioning Method. The Basic Commissioning Method specifies a window of
       * time during which an already commissioned Node accepts PASE sessions. The current Administrator shall
       * specify a timeout value for the duration of the OpenBasicCommissioningWindow command.
       *
       * If a commissioning window is already currently open, this command shall fail with a cluster specific
       * status code of Busy.
       *
       * If the fail-safe timer is currently armed, this command shall fail with a cluster specific status code of
       * Busy, since it is likely that concurrent commissioning operations from multiple separate Commissioners
       * are about to take place.
       *
       * In case of any other parameter error, this command shall fail with a status code of COMMAND_INVALID.
       *
       * The commissioning into a new Fabric completes when the Node successfully receives a CommissioningComplete
       * command, see Section 5.5, “Commissioning Flows”. The new Administrator shall discover the Node on the IP
       * network using DNS-based Service Discovery (DNS-SD) for commissioning.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.19.8.2
       */
      openBasicCommissioningWindow: (0, import_Cluster.Command)(
        1,
        AdministratorCommissioning2.TlvOpenBasicCommissioningWindowRequest,
        1,
        import_Cluster.TlvNoResponse,
        { invokeAcl: import_model.AccessLevel.Administer, timed: true }
      )
    }
  });
  AdministratorCommissioning2.Base = import_MutableCluster.MutableCluster.Component({
    id: 60,
    name: "AdministratorCommissioning",
    revision: 1,
    features: {
      /**
       * Node supports Basic Commissioning Method.
       */
      basic: (0, import_BitmapSchema.BitFlag)(0)
    },
    attributes: {
      /**
       * Indicates whether a new Commissioning window has been opened by an Administrator, using either the
       * OpenCommissioningWindow command or the OpenBasicCommissioningWindow command.
       *
       * This attribute shall revert to WindowNotOpen upon expiry of a commissioning window.
       *
       * > [!NOTE]
       *
       * > An initial commissioning window is not opened using either the OpenCommissioningWindow command or the
       *   OpenBasicCommissioningWindow command, and therefore this attribute shall be set to WindowNotOpen on
       *   initial commissioning.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.19.7.1
       */
      windowStatus: (0, import_Cluster.Attribute)(0, (0, import_TlvNumber.TlvEnum)()),
      /**
       * When the WindowStatus attribute is not set to WindowNotOpen, this attribute shall indicate the
       * FabricIndex associated with the Fabric scoping of the Administrator that opened the window. This may be
       * used to cross-reference in the Fabrics attribute of the Operational Credentials cluster.
       *
       * If, during an open commissioning window, the fabric for the Administrator that opened the window is
       * removed, then this attribute shall be set to null.
       *
       * When the WindowStatus attribute is set to WindowNotOpen, this attribute shall be set to null.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.19.7.2
       */
      adminFabricIndex: (0, import_Cluster.Attribute)(1, (0, import_TlvNullable.TlvNullable)(import_FabricIndex.TlvFabricIndex)),
      /**
       * When the WindowStatus attribute is not set to WindowNotOpen, this attribute shall indicate the Vendor ID
       * associated with the Fabric scoping of the Administrator that opened the window. This field shall match
       * the VendorID field of the Fabrics attribute list entry associated with the Administrator having opened
       * the window, at the time of window opening. If the fabric for the Administrator that opened the window is
       * removed from the node while the commissioning window is still open, this attribute shall NOT be updated.
       *
       * When the WindowStatus attribute is set to WindowNotOpen, this attribute shall be set to null.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.19.7.3
       */
      adminVendorId: (0, import_Cluster.Attribute)(2, (0, import_TlvNullable.TlvNullable)(import_VendorId.TlvVendorId))
    },
    commands: {
      /**
       * This command is used by a current Administrator to instruct a Node to go into commissioning mode. The
       * Enhanced Commissioning Method specifies a window of time during which an already commissioned Node
       * accepts PASE sessions. The current Administrator MUST specify a timeout value for the duration of the
       * OpenCommissioningWindow command.
       *
       * When the OpenCommissioningWindow command expires or commissioning completes, the Node shall remove the
       * Passcode by deleting the PAKE passcode verifier as well as stop publishing the DNS-SD record
       * corresponding to this command as described in Section 4.3.1, “Commissionable Node Discovery”. The
       * commissioning into a new Fabric completes when the Node successfully receives a CommissioningComplete
       * command, see Section 5.5, “Commissioning Flows”.
       *
       * The parameters for OpenCommissioningWindow command are as follows:
       *
       * A current Administrator may invoke this command to put a node in commissioning mode for
       * thenextAdministrator. On completion, the command shall return a cluster specific status code from the
       * Section 11.19.6, “Status Codes” below reflecting success or reasons for failure of the operation. The new
       * Administrator shall discover the Node on the IP network using DNS-based Service Discovery (DNS-SD) for
       * commissioning.
       *
       * If any format or validity errors related to the PAKEPasscodeVerifier, Iterations or Salt arguments arise,
       * this command shall fail with a cluster specific status code of PAKEParameterError.
       *
       * If a commissioning window is already currently open, this command shall fail with a cluster specific
       * status code of Busy.
       *
       * If the fail-safe timer is currently armed, this command shall fail with a cluster specific status code of
       * Busy, since it is likely that concurrent commissioning operations from multiple separate Commissioners
       * are about to take place.
       *
       * In case of any other parameter error, this command shall fail with a status code of COMMAND_INVALID.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.19.8.1
       */
      openCommissioningWindow: (0, import_Cluster.Command)(
        0,
        AdministratorCommissioning2.TlvOpenCommissioningWindowRequest,
        0,
        import_Cluster.TlvNoResponse,
        { invokeAcl: import_model.AccessLevel.Administer, timed: true }
      ),
      /**
       * This command is used by a current Administrator to instruct a Node to revoke any active
       * OpenCommissioningWindow or OpenBasicCommissioningWindow command. This is an idempotent command and the
       * Node shall (for ECM) delete the temporary PAKEPasscodeVerifier and associated data, and stop publishing
       * the DNS-SD record associated with the OpenCommissioningWindow or OpenBasicCommissioningWindow command,
       * see Section 4.3.1, “Commissionable Node Discovery”.
       *
       * If no commissioning window was open at time of receipt, this command shall fail with a cluster specific
       * status code of WindowNotOpen.
       *
       * If the commissioning window was open and the fail-safe was armed when this command is received, the
       * device shall immediately expire the fail-safe and perform the cleanup steps outlined in Section
       * 11.10.7.2.2, “Behavior on expiry of Fail-Safe timer”.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.19.8.3
       */
      revokeCommissioning: (0, import_Cluster.Command)(
        2,
        import_TlvNoArguments.TlvNoArguments,
        2,
        import_Cluster.TlvNoResponse,
        { invokeAcl: import_model.AccessLevel.Administer, timed: true }
      )
    },
    /**
     * This metadata controls which AdministratorCommissioningCluster elements matter.js activates for specific
     * feature combinations.
     */
    extensions: import_MutableCluster.MutableCluster.Extensions({ flags: { basic: true }, component: AdministratorCommissioning2.BasicComponent })
  });
  AdministratorCommissioning2.ClusterInstance = (0, import_MutableCluster.MutableCluster)(AdministratorCommissioning2.Base);
  AdministratorCommissioning2.Cluster = AdministratorCommissioning2.ClusterInstance;
  const BC = { basic: true };
  AdministratorCommissioning2.CompleteInstance = (0, import_MutableCluster.MutableCluster)({
    id: AdministratorCommissioning2.Cluster.id,
    name: AdministratorCommissioning2.Cluster.name,
    revision: AdministratorCommissioning2.Cluster.revision,
    features: AdministratorCommissioning2.Cluster.features,
    attributes: AdministratorCommissioning2.Cluster.attributes,
    commands: {
      ...AdministratorCommissioning2.Cluster.commands,
      openBasicCommissioningWindow: import_MutableCluster.MutableCluster.AsConditional(
        AdministratorCommissioning2.BasicComponent.commands.openBasicCommissioningWindow,
        { mandatoryIf: [BC] }
      )
    }
  });
  AdministratorCommissioning2.Complete = AdministratorCommissioning2.CompleteInstance;
})(AdministratorCommissioning || (AdministratorCommissioning = {}));
const AdministratorCommissioningCluster = AdministratorCommissioning.Cluster;
import_ClusterRegistry.ClusterRegistry.register(AdministratorCommissioning.Complete);
//# sourceMappingURL=administrator-commissioning.js.map
