Multi-body transaction with 2 different private keys

Hey everyone.

I’m interested in building a transaction that is half-signed by someone and half-signed by another person. Two different private keys signing the same transaction, but they only being responsible of signing their own inputs.

The thing is, I want that every private key just sign their “part” of the transaction, because not everyone knows what the whole transaction be.

In other words:

Address A sends X amount of ADA to Address B
Address B sends Y amount of ADA to Address A

In the same transaction

But as I said, Address A does not know what Address B will be sending, so they cannot sign the whole transaction, just their own part.

Is it possible?

I’m not sure I understand your use case’s precise requirements for privacy, knowledge, and coordination, but here are a few thoughts on transactions like this:

  1. It is not possible for two signed “half transactions” to be assembled into a whole transaction, but it is possible for two parties to separately sign (witness) their portion of a whole transaction. The cardano-cli transaction witness command lets the parties create separate, detached signatures for a transaction, and cardano-cli transaction assemble lets one combine those witnesses with the transaction body into a fully signed transaction that can be submitted. However, each party will be able to inspect the transaction before they sign it and see what it contains. It sounds in your post that the parties don’t or shouldn’t have this knowledge and level of coordination.
  2. If you want to ensure that each party doesn’t know how much the other will be sending beforehand (or even to whom), you would probably have to construct an elaborate scenario involving a smart contract and an oracle, and perhaps have the parties use addresses that are not delegated to stake pools. A smart contract could manage an atomic swap, but it wouldn’t provide privacy, since the second party would see what the first party put into the contract (unless they somehow submit exactly simultaneously) and could renege. If you wanted privacy prior to the transaction, then each party would have to privately escrow the funds into separate smart contracts constructed by a trusted third party, after which an oracle (i.e., the third party) could trigger the transfer from the contracts.