computeDigest method

  1. @override
  2. @protected
Uint8List computeDigest(
  1. Tx tx,
  2. int index,
  3. AssemblerInput meta
)
override

Computes the sighash digest for the input, choosing the algorithm and - for segwit - the BIP-143 scriptCode based on AssemblerInput.type.

Subclasses (e.g. ForkedTxAssembler) override this to substitute an alternative sighash algorithm.

Implementation

@override
@protected
Uint8List computeDigest(Tx tx, int index, AssemblerInput meta) {
  final hasher = ForkedHasher(forkId: forkId);
  // For P2WPKH / nested P2WPKH the BIP-143-style scriptCode must still be the
  // P2PKH-form script over the pubkey hash; for legacy P2PKH it is the
  // scriptPubKey. (BCH is legacy-script + forkid, but mirror the parent's
  // scriptCode selection so witness-style inputs are handled correctly.)
  switch (meta.type) {
    case AssemblerInputType.p2wpkh:
    case AssemblerInputType.p2shP2wpkh:
      return hasher.hash(tx, index, meta.hashType,
          prevScript: p2wpkhScriptCode(meta), amount: meta.value);
    case AssemblerInputType.p2pkh:
      return hasher.hash(tx, index, meta.hashType,
          prevScript: meta.scriptPubKey, amount: meta.value);
    case AssemblerInputType.p2tr:
      throw UnsupportedError(
        'Taproot is not supported by ForkedTxAssembler.',
      );
  }
}