createHashesForSig method

Uint8List createHashesForSig({
  1. required int vin,
  2. int? hashType,
})

Implementation

Uint8List createHashesForSig({required int vin, int? hashType}) {
  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);
  return hashesForSig;
}