ECDSAPrivateKey.fromBytesConst constructor
ECDSAPrivateKey.fromBytesConst({
- required List<
int> bytes, - EllipticCurveTypes type = EllipticCurveTypes.secp256k1,
Creates an ECDSA private key from bytes.
Parameters:
- bytes: A byte representation of the private key.
- curve: The elliptic curve used for the key pair.
Returns: An ECDSA private key.
Implementation
factory ECDSAPrivateKey.fromBytesConst(
{required List<int> bytes,
EllipticCurveTypes type = EllipticCurveTypes.secp256k1}) {
if (type != EllipticCurveTypes.secp256k1) {
throw CryptoException(
"Unsuported constant public key generation for curve ${type.name}");
}
final generator = Curves.generatorSecp256k1;
if (bytes.length != generator.curve.baselen) {
throw const CryptoException("Invalid length of private key");
}
final pubkeyBytes = Secp256k1Utils.generatePublicKeyBlind(bytes);
if (pubkeyBytes == null) {
throw const CryptoException("Invalid secp256k1 private key.");
}
final publicKey = ECDSAPublicKey.fromBytes(pubkeyBytes, generator);
final secexp = BigintUtils.fromBytes(bytes, byteOrder: Endian.big);
return ECDSAPrivateKey(publicKey, secexp);
}