Where Spreadwallet is in charge of two daemons.
There is already a process to swap coins between two chains, so the trick here will be to automate the process as part of Proof of X's chains node. We just need to replace swapping coins (or we might keep it) with swapping instructions to do stuff, like broadcast a message to the Bitcoin network:
Public keys must be serialized using strict SEC format:
byte(0x02) byte_array(32): Compressed even key
byte(0x03) byte_array(32): Compressed odd key
Compressed keys are mandatory.
When included in transactions, hash_type must be set to 1.
Signatures must be serialized using strict DER format.
byte(0x30) byte(total_length) byte(0x02) byte(len(R)) byte_array(len(R)) byte(len(s)) byte_array(len(s)
Request Message
Each message shall have the following format.
{"id":1, "method": "method.name", "params": [param1, param2]}
Result Message
The server shall reply to Request methods with a response message.
{"id": 1, "result": result, "error: Null}
Give error message, if request fails
Trade Request
This method is used to initiate the protocol.
{"id":1, "method": "trade.request", [version, long_deposit, [third_parties], k_client,
sell_magic_value, sell_coin_amount, sell_coin_fee,
sell_locktime,
buy_magic_value, buy_coin_amount, buy_coin_fee,
buy_locktime]}
// wtf?
version: Integer version of the handshake (should be set to 1)
slow_trader (boolean): True if the server is the slow trader, false otherwise
third_party (list of string): Hex encoding of acceptable 3rd parties' public key (or Null for no 3rd party)
k_client (string): A random hex encoded byte array (32 bytes)
sell_coin_magic_value (string): Hex encoding of the network magic value for the coin being sold
sell_coin_amount (number): An integer count of the number of coins being sold (in the smallest units)
sell_locktime (number): The int locktime for the client's refund transaction
buy_coin_magic_value (string): Hex encoding of the network magic value for the coin being bought
buy_coin_amount (number): An integer count of the number of coins being bought (in the smallest units)
buy_locktime (number): The int locktime for the server's refund transaction
The response for the method has a subset of the trade information.
{"id":1, "result": [version, slow_trader, [third_parties], k_server,
sell_coin_amount, sell_coin_fee, sell_locktime,
buy_coin_amount, buy_coin_fee, buy_locktime]
"error": Null}
If it goes through and accepted, Houston, we have the start of the proof.
A trade-id is generated for each transaction (| means concatenation).
tr_id = SHA-256(k_client | k_server)
The third party's public key is modified to give
third_party_key_modified = tr-id * third_party_key
This method is used to exchange public keys between the parties. Each party has to provide 5 public keys and the long trader must provide hash_x. The slow trader should set hash_x to Null.
{"id": 1, "method":"keys.request", "params": [tr_id, key1, key2, ... key5, hash_x]}
The server responds with 5 public keys and hash_x.
{"id": 1, "result": [key1, key2, ... key5, hash_x], "error": Null}
This method is for the parties to exchange signatures.
//server_payout_signature: This is the signature for the server's payout transaction (input A)
server_refund_signature: This is the signature for the server's timelocked refund transactions
server_third_party_signature: This is the signature for the server's transaction to direct the output to a third party
{"id": 1, "method": "exchange.signatures", "params": [tr_id, server_payout_signature, server_refund_signature, server_third_party_signature]
//response
{"id": 1, "result": [client_payout_signature, client_refund_signature, client_third_party_signature], "error": Null}
//client_payout_signature: This is the signature for the client's payout transaction (input A)
client_refund_signature: This is the signature for the client's timelocked refund transactions
client_third_party_signature: This is the signature for the client's transaction to direct the output to a third party
Segwit should help with any signature malleability issues to help prevent malware fucking up the process.
If I were in a bar and I had just drank 10 pints of beer, I'd be saying '
I love you Tier Nolan' right about now.