This is a revisit of an issue raised a couple years ago in #1595 however it's now also causing an issue in signing for the new ledger bitcoin app with nested segwit inputs.
While it was noted in the previous ticket that the witnessUtxo can be derived from the nonWitnessUtxo and therefore both are technically unnecessary, this error Error: Can not add duplicate data to input seems to be a violation of the simple signer algorithm from BIP174. Unfortunately, the pseudocode in the BIP itself might be wrong based on this conversation in an issue in Electrum on the same subject.
The conclusion of that issue based on feedback from achow101 is that witnessUtxo must be present for segwitv0 or above and that the presence or lack thereof of nonWitnessUtxo data determines which signing algorithm to use. For a nested segwit transaction, since bitcoinjs-lib doesn't allow both, if you send a PSBT with nonWitnessUtxo only, then the non-segwit signature algorithm is chosen which produces incorrect signatures for nested segwit.
This is a revisit of an issue raised a couple years ago in #1595 however it's now also causing an issue in signing for the new ledger bitcoin app with nested segwit inputs.
While it was noted in the previous ticket that the witnessUtxo can be derived from the nonWitnessUtxo and therefore both are technically unnecessary, this error
Error: Can not add duplicate data to inputseems to be a violation of the simple signer algorithm from BIP174. Unfortunately, the pseudocode in the BIP itself might be wrong based on this conversation in an issue in Electrum on the same subject.The conclusion of that issue based on feedback from achow101 is that witnessUtxo must be present for segwitv0 or above and that the presence or lack thereof of nonWitnessUtxo data determines which signing algorithm to use. For a nested segwit transaction, since bitcoinjs-lib doesn't allow both, if you send a PSBT with nonWitnessUtxo only, then the non-segwit signature algorithm is chosen which produces incorrect signatures for nested segwit.