"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 PaseMessenger_exports = {};
__export(PaseMessenger_exports, {
  DEFAULT_PASSCODE_ID: () => DEFAULT_PASSCODE_ID,
  PaseClientMessenger: () => PaseClientMessenger,
  PaseServerMessenger: () => PaseServerMessenger,
  SPAKE_CONTEXT: () => SPAKE_CONTEXT
});
module.exports = __toCommonJS(PaseMessenger_exports);
var import_general = require("#general");
var import_types = require("#types");
var import_SecureChannelMessenger = require("../../securechannel/SecureChannelMessenger.js");
var import_PaseMessages = require("./PaseMessages.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const DEFAULT_PASSCODE_ID = 0;
const SPAKE_CONTEXT = import_general.Bytes.fromString("CHIP PAKE V1 Commissioning");
class PaseServerMessenger extends import_SecureChannelMessenger.SecureChannelMessenger {
  #closed = false;
  async readPbkdfParamRequest() {
    const { payload } = await this.nextMessage(import_types.SecureMessageType.PbkdfParamRequest, import_SecureChannelMessenger.DEFAULT_NORMAL_PROCESSING_TIME);
    return { requestPayload: payload, request: import_PaseMessages.TlvPbkdfParamRequest.decode(payload) };
  }
  async sendPbkdfParamResponse(response) {
    return this.send(response, import_types.SecureMessageType.PbkdfParamResponse, import_PaseMessages.TlvPbkdfParamResponse, {
      expectedProcessingTime: import_SecureChannelMessenger.DEFAULT_NORMAL_PROCESSING_TIME
    });
  }
  readPasePake1() {
    return this.nextMessageDecoded(import_types.SecureMessageType.PasePake1, import_PaseMessages.TlvPasePake1);
  }
  sendPasePake2(pasePake2) {
    return this.send(pasePake2, import_types.SecureMessageType.PasePake2, import_PaseMessages.TlvPasePake2);
  }
  readPasePake3() {
    return this.nextMessageDecoded(import_types.SecureMessageType.PasePake3, import_PaseMessages.TlvPasePake3);
  }
  close() {
    this.#closed = true;
    return super.close();
  }
  send(message, type, schema, options) {
    if (this.#closed) {
      throw new import_general.UnexpectedDataError("Cannot send message, messenger is closed");
    }
    return super.send(message, type, schema, options);
  }
  async nextMessage(expectedMessageType, expectedProcessingTimeMs, expectedMessageInfo) {
    if (this.#closed) {
      throw new import_general.UnexpectedDataError("Cannot read message, messenger is closed");
    }
    const result = await super.nextMessage(expectedMessageType, expectedProcessingTimeMs, expectedMessageInfo);
    if (this.#closed) {
      throw new import_general.UnexpectedDataError("Cannot read message, messenger is closed");
    }
    return result;
  }
}
class PaseClientMessenger extends import_SecureChannelMessenger.SecureChannelMessenger {
  sendPbkdfParamRequest(request) {
    return this.send(request, import_types.SecureMessageType.PbkdfParamRequest, import_PaseMessages.TlvPbkdfParamRequest, {
      expectedProcessingTime: import_SecureChannelMessenger.DEFAULT_NORMAL_PROCESSING_TIME
    });
  }
  async readPbkdfParamResponse() {
    const { payload } = await this.nextMessage(
      import_types.SecureMessageType.PbkdfParamResponse,
      import_SecureChannelMessenger.DEFAULT_NORMAL_PROCESSING_TIME
    );
    return { responsePayload: payload, response: import_PaseMessages.TlvPbkdfParamResponse.decode(payload) };
  }
  sendPasePake1(pasePake1) {
    return this.send(pasePake1, import_types.SecureMessageType.PasePake1, import_PaseMessages.TlvPasePake1);
  }
  readPasePake2() {
    return this.nextMessageDecoded(import_types.SecureMessageType.PasePake2, import_PaseMessages.TlvPasePake2);
  }
  sendPasePake3(pasePake3) {
    return this.send(pasePake3, import_types.SecureMessageType.PasePake3, import_PaseMessages.TlvPasePake3);
  }
}
//# sourceMappingURL=PaseMessenger.js.map
