diba-io / bitmask-core

Core functionality for the BitMask wallet
https://bitmask.app
Other
95 stars 21 forks source link

RGB Swaps with presig #385

Closed crisdut closed 1 year ago

crisdut commented 1 year ago

Description

This PR allow the seller sign the PSBT in the create offer step and buyer co-sign and broadcast, without requiring third-party control.

To achievement that, we needed create a new method to construct PSBT file, without the need to have all inputs previously added, reducing the number of interactions between parties (from 2 to 3).

How to works

  1. The seller creates an offer
    • The BMC registry the offer in a public orderbook.
  2. The seller and co-sign the psbt file.
    • The BMC updates the offer in a public orderbook.
  3. The buyer retrieves the offer, create bid and complete and co-sign psbt file.
  4. The buyer publish the the swap transaction directly.

Improviments

!!! UPDATE https://github.com/diba-io/bitmask-core/pull/385/commits/a4adbce82ff4989489bc751ca500e0e5e4e585f0 !!!

I had problems with balance consistency after swap operations, mainly because according to traditional RGB logic, the seller would be the last to work on the file and, consequently, generate the transaction and store the taptweak.

But how to do this if the buyer will be the last participant involved?

The solution for now without many changes was to share the taptweak via swap file so that the seller can receive it as soon as the transaction is registered.

Another problem encountered is how to guarantee that payments will be asynchronous: I basically use the swap file, where every time the user "goes online", I search the orders (offers/bids) behind pending transactions in monitoring and update them. For BME it is transparent, as this logic is in verify_transfers

Closes #382

cryptoquick commented 1 year ago

Do you think you'll add the changes we discussed to this PR regarding a trusted swap coordinator?

cryptoquick commented 1 year ago

The solution for now without many changes was to share the taptweak via swap file so that the seller can receive it as soon as the transaction is registered.

This is very clever!

Another problem encountered is how to guarantee that payments will be asynchronous: I basically use the swap file, where every time the user "goes online", I search the orders (offers/bids) behind pending transactions in monitoring and update them. For BME it is transparent, as this logic is in verify_transfers

Hopefully this won't be too difficult to integrate into the extension.