"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 MockCrypto_exports = {};
__export(MockCrypto_exports, {
  MockCrypto: () => MockCrypto
});
module.exports = __toCommonJS(MockCrypto_exports);
var import_MatterError = require("#MatterError.js");
var import_Bytes = require("#util/Bytes.js");
var import_Crypto = require("./Crypto.js");
var import_Key = require("./Key.js");
var import_NodeJsStyleCrypto = require("./NodeJsStyleCrypto.js");
var import_StandardCrypto = require("./StandardCrypto.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function MockCrypto(index = 128, implementation = import_NodeJsStyleCrypto.NodeJsStyleCrypto.detectedCrypto ? import_NodeJsStyleCrypto.NodeJsStyleCrypto : import_StandardCrypto.StandardCrypto) {
  if (index < 0 || index > 255) {
    throw new import_MatterError.ImplementationError(`Index for stable crypto must be 0-255`);
  }
  const crypto = new implementation();
  const { randomBytes, createKeyPair } = crypto;
  const origCreatePbkdf2Key = crypto.createPbkdf2Key;
  crypto.createPbkdf2Key = function(secret, salt, _iteration, keyLength) {
    return origCreatePbkdf2Key.call(crypto, secret, salt, 1, keyLength);
  };
  Object.defineProperties(crypto, {
    index: {
      get() {
        return index;
      },
      set(newIndex) {
        index = newIndex % 256;
      }
    },
    entropic: {
      get() {
        return crypto.randomBytes === randomBytes;
      },
      set(entropic) {
        if (entropic) {
          crypto.randomBytes = randomBytes;
          crypto.createKeyPair = createKeyPair;
        } else {
          disableEntropy();
        }
      }
    }
  });
  disableEntropy();
  return crypto;
  function disableEntropy() {
    crypto.randomBytes = function getRandomDataNONENTROPIC(length) {
      const result = new Uint8Array(length);
      result.fill(index);
      return result;
    };
    crypto.createKeyPair = function getRandomDataNONENTROPIC() {
      const privateBits = import_Crypto.ec.mapHashToField(import_Bytes.Bytes.of(crypto.randomBytes(48)), import_Crypto.ec.p256.Point.CURVE().n);
      return (0, import_Key.Key)({
        kty: import_Key.KeyType.EC,
        crv: import_Key.CurveType.p256,
        privateBits
      });
    };
  }
}
//# sourceMappingURL=MockCrypto.js.map
