getPublicKey static method

Uint8List getPublicKey(
  1. Uint8List privateKey
)

Derives the x-only public key from a private key.

Returns a 32-byte x-only public key.

Implementation

static Uint8List getPublicKey(Uint8List privateKey) {
  if (privateKey.length != 32) {
    throw ArgumentError('Private key must be 32 bytes');
  }

  final d = _bytesToBigInt(privateKey);
  if (d == BigInt.zero || d >= _n) {
    throw ArgumentError('Invalid private key');
  }

  final P = _scalarMult(d, [_Gx, _Gy]);
  return _bigIntToBytes(P[0], 32);
}