/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { CertificateAuthority } from "#certificate/CertificateAuthority.js";
import { ImplementationError, MockCrypto } from "#general";
import { FabricId, FabricIndex, VendorId } from "#types";
import { FabricAuthority } from "./FabricAuthority.js";
import { FabricManager } from "./FabricManager.js";
async function TestFabric(options = {}) {
  const authority = await TestFabric.Authority(options);
  const { index } = options;
  return authority.createFabric({
    adminFabricLabel: `mock-fabric-${index}`,
    adminVendorId: VendorId(65521),
    adminFabricIndex: index !== void 0 ? FabricIndex(index) : void 0,
    adminFabricId: FabricId(1)
  });
}
((TestFabric2) => {
  async function Authority(options = {}) {
    let { fabrics } = options;
    if (options.index === void 0) {
      if (fabrics) {
        options.index = fabrics.allocateFabricIndex();
      } else {
        options.index = 1;
      }
    }
    if (options.index < 1 || options.index > 254) {
      throw new ImplementationError("Test fabric indexes must be in the range 1-254");
    }
    if (!fabrics) {
      fabrics = new FabricManager(MockCrypto(options.index));
    }
    return new FabricAuthority({
      ca: await CertificateAuthority.create(fabrics.crypto),
      fabrics
    });
  }
  TestFabric2.Authority = Authority;
})(TestFabric || (TestFabric = {}));
export {
  TestFabric
};
//# sourceMappingURL=TestFabric.js.map
