bytesForSigning property
Doesnt include weight
Implementation
Uint8List get bytesForSigning {
/// Double SHA256 Hash of all inputs
final inputBuffers = inputs.map(
(input) => input.bytesForSigning(
withWeight: true,
withScript: false,
),
);
final combinedInputBuffers = inputBuffers.fold(
Uint8List(0),
(prev, buffer) => Uint8List.fromList(prev + buffer),
);
final hashInputs = sha256Sha256Hash(combinedInputBuffers);
/// Double SHA256 Hash of all outputs
final outputBuffers = outputs.map((output) => output.bytes);
final combinedOutputBuffers = outputBuffers.fold(
Uint8List(0),
(prev, buffer) => Uint8List.fromList(prev + buffer),
);
final hashOutputs = sha256Sha256Hash(combinedOutputBuffers);
///
/// Input to be signed
///
/// Input to be signed has a scriptSig all other inputs have empty scriptSigs
final input = inputs.singleWhereOrNull(
(input) => input.scriptSig.length != 0,
);
if (input == null) {
throw Exception('No input to be signed');
}
final inputBytes = input.bytesForSigning(
withWeight: false,
withScript: true,
);
///
/// Construct Buffer
///
final txByteLength = 4 + hashInputs.length + hashOutputs.length + inputBytes.length + 8 + 8 + 4;
final buffer = Uint8List(txByteLength);
var offset = 0;
/// Version
offset += buffer.bytes.writeUint32(offset, version);
/// HashInputs
offset += buffer.writeSlice(offset, hashInputs);
/// Input to be signed
offset += buffer.writeSlice(
offset,
inputBytes,
);
/// HashOutputs
offset += buffer.writeSlice(offset, hashOutputs);
/// Fee
offset += buffer.bytes.writeUint64(offset, fee.toInt());
/// ValidFrom
offset += buffer.bytes.writeUint64(offset, validFrom);
/// ValidUntil
offset += buffer.bytes.writeUint32(offset, validUntil);
return buffer;
}