sign method

  1. @override
TaprootKeyInput sign({
  1. required Transaction tx,
  2. required int inputN,
  3. required ECPrivateKey key,
  4. required List<Output> prevOuts,
  5. SigHashType hashType = const SigHashType.all(),
})
override

Return a signed Taproot input using tweaked private key for the key-path spend. The key should be tweaked by Taproot.tweakScalar.

Implementation

@override
/// Return a signed Taproot input using tweaked private key for the key-path
/// spend. The [key] should be tweaked by [Taproot.tweakScalar].
TaprootKeyInput sign({
  required Transaction tx,
  required int inputN,
  required ECPrivateKey key,
  required List<Output> prevOuts,
  SigHashType hashType = const SigHashType.all(),
}) {

  if (inputN >= prevOuts.length) {
    throw CannotSignInput(
      "Input is out of range of the previous outputs provided",
    );
  }

  // Check key corresponds to matching prevOut
  final program = prevOuts[inputN].program;
  if (program is! P2TR || key.pubkey.xonly != program.tweakedKey) {
    throw CannotSignInput(
      "Key cannot sign for Taproot input's tweaked key",
    );
  }

  return addSignature(
    createInputSignature(
      tx: tx,
      inputN: inputN,
      key: key,
      prevOuts: prevOuts,
      hashType: hashType,
    ),
  );

}