computeDigest method

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

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

@protected
Uint8List computeDigest(Tx tx, int index, AssemblerInput meta) {
  switch (meta.type) {
    case AssemblerInputType.p2pkh:
      final LegacySigHasher hasher = LegacySigHasher();
      return hasher.hash(tx, index, meta.hashType,
          prevScript: meta.scriptPubKey);
    case AssemblerInputType.p2wpkh:
    case AssemblerInputType.p2shP2wpkh:
      final WitnessSigHasher hasher = WitnessSigHasher();
      // BIP-143: the scriptCode for P2WPKH (incl. nested) is the P2PKH-form
      // script over the pubkey hash, NOT the witness program / redeemScript.
      return hasher.hash(tx, index, meta.hashType,
          prevScript: p2wpkhScriptCode(meta), amount: meta.value);
    case AssemblerInputType.p2tr:
      throw UnsupportedError(
        'Taproot key-path spends are not yet supported by TxAssembler. '
        'Use the segwit/legacy types, or sign taproot inputs directly.',
      );
  }
}