publicKey method
The publicKey
method derives the corresponding public key from the Schnorrkel secret key.
This method follows the process of computing the public key by first converting the secret key to a big integer,
performing scalar multiplication with the Ed25519 generator point, and converting the resulting point
to a RistrettoPoint format. Finally, the public key is returned as a SchnorrkelPublicKey
instance.
Returns:
A SchnorrkelPublicKey
representing the derived public key associated with this Schnorrkel secret key.
Implementation
SchnorrkelPublicKey publicKey() {
/// Convert the secret key to a big integer in little-endian byte order.
final tobig = BigintUtils.fromBytes(key(), byteOrder: Endian.little);
/// Perform scalar multiplication with the Ed25519 generator point.
final gn = Curves.generatorED25519 * tobig;
/// Convert the result to a RistrettoPoint format.
final pubPoint = RistrettoPoint.fromEdwardsPoint(gn);
/// Convert the RistrettoPoint point to bytes and create a Schnorrkel public key.
final pubBytes = pubPoint.toBytes();
return SchnorrkelPublicKey(pubBytes);
}