diff --git a/index.js b/index.js index 842adda..fafbaee 100644 --- a/index.js +++ b/index.js @@ -311,7 +311,16 @@ Syscoin.prototype.fetchAndSanitizeUTXOs = async function (utxos, fromXpubOrAddre utxos = utils.sanitizeBlockbookUTXOs(fromXpubOrAddress, utxos, this.network, txOpts, assetMap, excludeZeroConf) } } else { - utxos = utils.sanitizeBlockbookUTXOs(fromXpubOrAddress, utxos, this.network, txOpts, assetMap, excludeZeroConf) + // Only sanitize if UTXOs are not already in sanitized format. + // Sanitized UTXOs have a .utxos array with BN values and camelCase txId fields. + // Re-sanitizing already-sanitized UTXOs causes txId to be lost because + // sanitizeBlockbookUTXOs reads utxo.txid (lowercase) which is undefined + // on already-sanitized objects, breaking PSBT construction for WIF signers. + const isAlreadySanitized = utxos && Array.isArray(utxos.utxos) && + utxos.utxos.length > 0 && utxos.utxos[0].txId !== undefined + if (!isAlreadySanitized) { + utxos = utils.sanitizeBlockbookUTXOs(fromXpubOrAddress, utxos, this.network, txOpts, assetMap, excludeZeroConf) + } } return utxos }