signSchnorr method
void
signSchnorr(
{ - required int vin,
- required ECPair keyPair,
- int? hashType,
- bool hd = false,
})
Implementation
void signSchnorr(
{required int vin,
required ECPair keyPair,
int? hashType,
bool hd = false}) {
if (vin >= ins.length) throw ArgumentError('No input at index: $vin');
hashType = hashType ?? SIGHASH_DEFAULT;
final input = ins[vin];
final prevouts =
ins.where((e) => e.prevOutScript != null && e.value != null);
final scripts = prevouts.map((e) {
if (e.witnessUtxo != null) return e.witnessUtxo!;
return e.prevOutScript!;
}).toList();
final values = prevouts.map((e) => e.value!).toList();
final leafHash = tapLeafHash((input.tapLeafScript?.isNotEmpty ?? false)
? input.tapLeafScript!.first
: null);
final hashesForSig =
hashForWitnessV1(vin, scripts, values, hashType, leafHash, null);
final sig = keyPair.signSchnorr(message: hashesForSig);
final witness = [_serializeTaprootSignature(sig, hashType)];
if (input.tapLeafScript?.isNotEmpty ?? false) {
final item = input.tapLeafScript!.first;
witness.addAll([item.script, item.controlBlock]);
}
input.update(witness: witness);
}