"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 operational_exports = {};
__export(operational_exports, {
  MAX_TLV_CERTIFICATE_SIZE: () => MAX_TLV_CERTIFICATE_SIZE,
  OperationalCertificate: () => OperationalCertificate,
  TlvCertificateExtension: () => TlvCertificateExtension
});
module.exports = __toCommonJS(operational_exports);
var import_types = require("@matter/types");
var import_base = require("./base.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const MAX_TLV_CERTIFICATE_SIZE = 400;
const TlvCertificateExtension = (0, import_types.TlvTaggedList)({
  basicConstraints: (0, import_types.TlvField)(
    1,
    (0, import_types.TlvObject)({
      isCa: (0, import_types.TlvField)(1, import_types.TlvBoolean),
      pathLen: (0, import_types.TlvOptionalField)(2, import_types.TlvUInt8)
    })
  ),
  keyUsage: (0, import_types.TlvField)(2, (0, import_types.TlvBitmap)(import_types.TlvUInt16, import_base.ExtensionKeyUsageBitmap)),
  extendedKeyUsage: (0, import_types.TlvOptionalField)(3, (0, import_types.TlvArray)(import_types.TlvUInt8)),
  subjectKeyIdentifier: (0, import_types.TlvField)(4, import_types.TlvByteString.bound({ length: 20 })),
  authorityKeyIdentifier: (0, import_types.TlvField)(5, import_types.TlvByteString.bound({ length: 20 })),
  futureExtension: (0, import_types.TlvOptionalRepeatedField)(6, import_types.TlvByteString)
});
var OperationalCertificate;
((OperationalCertificate2) => {
  const AllowedSubjectAndIssuerMatterFields = {
    nodeId: (0, import_types.TlvOptionalField)(17, import_types.TlvNodeId),
    firmwareSigningId: (0, import_types.TlvOptionalField)(18, import_types.TlvUInt32),
    icacId: (0, import_types.TlvOptionalField)(19, import_types.TlvUInt64),
    rcacId: (0, import_types.TlvOptionalField)(20, import_types.TlvUInt64),
    fabricId: (0, import_types.TlvOptionalField)(21, import_types.TlvFabricId),
    caseAuthenticatedTags: (0, import_types.TlvOptionalRepeatedField)(22, import_types.TlvCaseAuthenticatedTag, { maxLength: 3 })
  };
  const TlvGenericMatterSubjectOrIssuerTaggedList = (matterFields) => {
    const fields = {
      // Standard DNs
      commonName: (0, import_types.TlvOptionalField)(1, import_types.TlvString),
      surName: (0, import_types.TlvOptionalField)(2, import_types.TlvString),
      serialNum: (0, import_types.TlvOptionalField)(3, import_types.TlvString),
      countryName: (0, import_types.TlvOptionalField)(4, import_types.TlvString),
      localityName: (0, import_types.TlvOptionalField)(5, import_types.TlvString),
      stateOrProvinceName: (0, import_types.TlvOptionalField)(6, import_types.TlvString),
      orgName: (0, import_types.TlvOptionalField)(7, import_types.TlvString),
      orgUnitName: (0, import_types.TlvOptionalField)(8, import_types.TlvString),
      title: (0, import_types.TlvOptionalField)(9, import_types.TlvString),
      name: (0, import_types.TlvOptionalField)(10, import_types.TlvString),
      givenName: (0, import_types.TlvOptionalField)(11, import_types.TlvString),
      initials: (0, import_types.TlvOptionalField)(12, import_types.TlvString),
      genQualifier: (0, import_types.TlvOptionalField)(13, import_types.TlvString),
      dnQualifier: (0, import_types.TlvOptionalField)(14, import_types.TlvString),
      pseudonym: (0, import_types.TlvOptionalField)(15, import_types.TlvString),
      domainComponent: (0, import_types.TlvOptionalField)(16, import_types.TlvString),
      // Matter specific DNs
      ...matterFields,
      // Standard DNs when encoded as Printable String
      commonNamePs: (0, import_types.TlvOptionalField)(129, import_types.TlvString),
      surNamePs: (0, import_types.TlvOptionalField)(130, import_types.TlvString),
      serialNumPs: (0, import_types.TlvOptionalField)(131, import_types.TlvString),
      countryNamePs: (0, import_types.TlvOptionalField)(132, import_types.TlvString),
      localityNamePs: (0, import_types.TlvOptionalField)(133, import_types.TlvString),
      stateOrProvinceNamePs: (0, import_types.TlvOptionalField)(134, import_types.TlvString),
      orgNamePs: (0, import_types.TlvOptionalField)(135, import_types.TlvString),
      orgUnitNamePs: (0, import_types.TlvOptionalField)(136, import_types.TlvString),
      titlePs: (0, import_types.TlvOptionalField)(137, import_types.TlvString),
      namePs: (0, import_types.TlvOptionalField)(138, import_types.TlvString),
      givenNamePs: (0, import_types.TlvOptionalField)(139, import_types.TlvString),
      initialsPs: (0, import_types.TlvOptionalField)(140, import_types.TlvString),
      genQualifierPs: (0, import_types.TlvOptionalField)(141, import_types.TlvString),
      dnQualifierPs: (0, import_types.TlvOptionalField)(142, import_types.TlvString),
      pseudonymPs: (0, import_types.TlvOptionalField)(143, import_types.TlvString)
    };
    return (0, import_types.TlvTaggedList)(fields);
  };
  const BaseMatterCertificate = (matterFields) => (0, import_types.TlvObjectWithMaxSize)(
    {
      serialNumber: (0, import_types.TlvField)(1, import_types.TlvByteString.bound({ maxLength: 20 })),
      signatureAlgorithm: (0, import_types.TlvField)(2, import_types.TlvUInt8),
      issuer: (0, import_types.TlvField)(
        3,
        TlvGenericMatterSubjectOrIssuerTaggedList({
          ...AllowedSubjectAndIssuerMatterFields,
          ...matterFields?.issuer ?? {}
        })
      ),
      notBefore: (0, import_types.TlvField)(4, import_types.TlvUInt32),
      notAfter: (0, import_types.TlvField)(5, import_types.TlvUInt32),
      subject: (0, import_types.TlvField)(
        6,
        TlvGenericMatterSubjectOrIssuerTaggedList({
          ...AllowedSubjectAndIssuerMatterFields,
          ...matterFields?.subject ?? {}
        })
      ),
      publicKeyAlgorithm: (0, import_types.TlvField)(7, import_types.TlvUInt8),
      ellipticCurveIdentifier: (0, import_types.TlvField)(8, import_types.TlvUInt8),
      ellipticCurvePublicKey: (0, import_types.TlvField)(9, import_types.TlvByteString),
      extensions: (0, import_types.TlvField)(10, TlvCertificateExtension),
      signature: (0, import_types.TlvField)(11, import_types.TlvByteString)
    },
    MAX_TLV_CERTIFICATE_SIZE
  );
  OperationalCertificate2.TlvRcac = BaseMatterCertificate({
    subject: {
      rcacId: (0, import_types.TlvField)(20, import_types.TlvUInt64),
      fabricId: (0, import_types.TlvOptionalField)(21, import_types.TlvFabricId)
    },
    issuer: AllowedSubjectAndIssuerMatterFields
  });
  OperationalCertificate2.TlvNoc = BaseMatterCertificate({
    subject: {
      nodeId: (0, import_types.TlvField)(17, import_types.TlvNodeId),
      fabricId: (0, import_types.TlvField)(21, import_types.TlvFabricId),
      caseAuthenticatedTags: (0, import_types.TlvOptionalRepeatedField)(22, import_types.TlvCaseAuthenticatedTag, { maxLength: 3 })
    },
    issuer: AllowedSubjectAndIssuerMatterFields
  });
  OperationalCertificate2.TlvIcac = BaseMatterCertificate({
    subject: {
      icacId: (0, import_types.TlvField)(19, import_types.TlvUInt64),
      fabricId: (0, import_types.TlvOptionalField)(21, import_types.TlvFabricId)
    },
    issuer: AllowedSubjectAndIssuerMatterFields
  });
  OperationalCertificate2.TlvVvsc = BaseMatterCertificate({
    subject: {
      vvsId: (0, import_types.TlvField)(23, import_types.TlvUInt64)
    },
    issuer: AllowedSubjectAndIssuerMatterFields
  });
})(OperationalCertificate || (OperationalCertificate = {}));
//# sourceMappingURL=operational.js.map
