@startuml
database Bitcoin
actor Bob as "Bob (User)"
Actor Alice as "Alice (Service Provider)"
database Monero

group Negotiation

    Bob --> Alice: Establish connection

    group Request Response Channel
        Bob -> Alice: Quote request
        note left: Btc Amount\naddress hints
        note right: Alice stores peer id & address hints\nto contact Bob

        Alice --> Bob: Quote response
        note right: Exact XMR amount
    end
end

group Execution Setup
    group Phase A [Messages can be exchanged in any order]
        Bob -> Alice: Message0
        note left: Pubkeys\ndleq proof s_b\nxmr viewkey v_b\nbtc refund addr

        Alice -> Bob: Message1
        note right: Pubkeys\ndleq proof s_a\nxmr view key v_a\nbtc redeem addr\nbtc punish addr
    end

    group Phase B [Messages must be exchanged in the given order]

        Bob -> Alice: Message2
        note left: unsigned btc lock tx

        Alice -> Bob: Message3
        note right: btc cancel tx sig\nbtc refund tx enc sig S_b

        Bob -> Alice: Message4
        note left: btc punish tx sig\nbtc cancel tx sig

    end
end

group Execution
    Bob ->> Bitcoin: Lock

    Alice ->> Monero: Lock

    Alice -> Bob: TransferProof
    note right: xmr lock tx transfer proof\nThis can be removed if Bob watches the blockchain.

    Bob -> Alice: EncryptedSignature
    note left: redeem tx enc sig S_a

    Alice ->> Bitcoin: Redeem

    Bitcoin ->> Bob: Signature

    Bob -> Bob: Extract s_a

    Bob ->> Monero: Redeem
end

@enduml