SchnorrSignature.sign constructor

SchnorrSignature.sign(
  1. ECPrivateKey privkey,
  2. Uint8List hash
)

Creates a signature using a private key (privkey) for a given 32-byte hash. The signature will be generated deterministically and shall be the same for a given hash and key. InvalidSchnorrSignature is thrown if the resulting signature is invalid. This shouldn't happen unless there is a computation error.

Implementation

factory SchnorrSignature.sign(ECPrivateKey privkey, Uint8List hash) {
  checkBytes(hash, 32);

  final sig = SchnorrSignature(secp256k1.schnorrSign(hash, privkey.data));

  // Verify signature to protect against computation errors. Cosmic rays etc.
  if (!sig.verify(privkey.pubkey, hash)) throw InvalidSchnorrSignature();

  return sig;

}