/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { ImplementationError } from "#MatterError.js";
import { Bytes } from "#util/Bytes.js";
import { ec } from "./Crypto.js";
import { CurveType, Key, KeyType } from "./Key.js";
import { StandardCrypto } from "./StandardCrypto.js";
function MockCrypto(index = 128, implementation = StandardCrypto) {
  if (index < 0 || index > 255) {
    throw new ImplementationError(`Index for stable crypto must be 0-255`);
  }
  const crypto = new implementation();
  const { randomBytes, createKeyPair } = crypto;
  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 = ec.mapHashToField(Bytes.of(crypto.randomBytes(48)), ec.p256.Point.CURVE().n);
      return Key({
        kty: KeyType.EC,
        crv: CurveType.p256,
        privateBits
      });
    };
  }
}
export {
  MockCrypto
};
//# sourceMappingURL=MockCrypto.js.map
