Wallet.fromPrivateKey constructor

Wallet.fromPrivateKey(
  1. Uint8List privateKey,
  2. NetworkInfo networkInfo
)

Implementation

factory Wallet.fromPrivateKey(
  Uint8List privateKey,
  NetworkInfo networkInfo
) {
  // Get the curve data
  final secp256k1 = ECCurve_secp256k1();
  final point = secp256k1.G;

  // Compute the curve point associated to the private key
  final bigInt = BigInt.parse(HEX.encode(privateKey), radix: 16);
  final curvePoint = point * bigInt;

  // Get the public key
  final publicKeyBytes = curvePoint!.getEncoded();

  // Get the address
  final sha256Digest = SHA256Digest().process(publicKeyBytes);
  final address = RIPEMD160Digest().process(sha256Digest);

  // Return the key bytes
  return Wallet(
    address: address,
    publicKey: publicKeyBytes,
    privateKey: privateKey,
    networkInfo: networkInfo,
  );
}