ECDSAPrivateKey.fromBytesConst constructor

ECDSAPrivateKey.fromBytesConst({
  1. required List<int> secretKey,
  2. EllipticCurveTypes type = EllipticCurveTypes.secp256k1,
})

Creates an ECDSA private key from bytes.

Parameters:

  • secretKey: A byte representation of the private key.
  • type: The elliptic curve used for the key pair.

Implementation

factory ECDSAPrivateKey.fromBytesConst({
  required List<int> secretKey,
  EllipticCurveTypes type = EllipticCurveTypes.secp256k1,
}) {
  if (type != EllipticCurveTypes.secp256k1) {
    throw ArgumentException.invalidOperationArguments(
      "ECDSAPrivateKey",
      name: "secretKey",
      reason:
          "Unsupported curve. constant-time ECDSA private key derivation is restricted to secp256k1.",
    );
  }
  final generator = Curves.generatorSecp256k1;
  if (secretKey.length != generator.curve.baselen) {
    throw ArgumentException.invalidOperationArguments(
      "ECDSAPrivateKey",
      name: "secretKey",
      reason: "Invalid secret key bytes length.",
      expecteLen: generator.curve.baselen,
    );
  }
  final pubkeyBytes = Secp256k1Utils.generatePublicKeyBlind(
    scalarBytes: secretKey,
    secp: true,
  );
  if (pubkeyBytes == null) {
    throw ArgumentException.invalidOperationArguments(
      "ECDSAPrivateKey",
      name: "secretKey",
      reason: "Invalid secret key.",
    );
  }
  final publicKey = ECDSAPublicKey.fromBytes(pubkeyBytes, generator);
  final secexp = BigintUtils.fromBytes(secretKey, byteOrder: Endian.big);
  return ECDSAPrivateKey(publicKey, secexp);
}