ECDSARecoverableSignature.sign constructor

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

Creates a recoverable signature using a private key (privkey) for a given 32-byte hash.

Implementation

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

  final sigAndId = secp256k1.ecdsaSignRecoverable(hash, privkey.data);
  final recSig = ECDSARecoverableSignature._(
    sigAndId.signature, sigAndId.recid, privkey.compressed,
  );

  // Verify signature to protect against computation errors. Cosmic rays etc.
  if (privkey.pubkey != recSig.recover(hash)) {
    throw InvalidECDSARecoverableSignature();
  }

  return recSig;

}