"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 Vvsc_exports = {};
__export(Vvsc_exports, {
  Vvsc: () => Vvsc
});
module.exports = __toCommonJS(Vvsc_exports);
var import_general = require("#general");
var import_operational = require("./definitions/operational.js");
var import_OperationalBase = require("./OperationalBase.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class Vvsc extends import_OperationalBase.OperationalBase {
  /** Construct the class from a Tlv version of the certificate */
  static fromTlv(tlv) {
    return new Vvsc(import_operational.OperationalCertificate.TlvVvsc.decode(tlv));
  }
  /** Validates all basic certificate fields on construction. */
  validateFields() {
    const {
      extensions: {
        basicConstraints: { isCa }
      }
    } = this.cert;
    if (!isCa) {
      throw new import_general.CertificateError("Intermediate certificate must be a CA.");
    }
  }
  /**
   * Encodes the certificate with the signature as Matter Tlv.
   * If the certificate is not signed, it throws a CertificateError.
   */
  asSignedTlv() {
    return import_operational.OperationalCertificate.TlvVvsc.encode({ ...this.cert, signature: this.signature.bytes });
  }
  /**
   * Verify requirements a Matter Intermediate CA certificate must fulfill.
   * Rules for this are listed in @see {@link MatterSpecification.v12.Core} §6.5.x
   * // TODO ADD Verification once we know more about the chain
   */
  async verify(_crypto) {
    this.generalVerify();
    const { subject } = this.cert;
    const { vvsId } = subject;
    if (vvsId === void 0 || Array.isArray(vvsId)) {
      throw new import_general.CertificateError(`Invalid vvsId in Vsc certificate: ${import_general.Diagnostic.json(vvsId)}`);
    }
    if ("nodeId" in subject) {
      throw new import_general.CertificateError(`Vsc certificate must not contain a nodeId.`);
    }
    if ("fabricId" in subject) {
      throw new import_general.CertificateError(`Vsc certificate must not contain a fabricId.`);
    }
    if ("caseAuthenticatedTags" in subject) {
      throw new import_general.CertificateError(`Vvsc certificate must not contain a caseAuthenticatedTags.`);
    }
  }
}
//# sourceMappingURL=Vvsc.js.map
