protocol: Enable private offers

Users can send private offers that will only be seen by one address.

To send a private offer:
 1. recipient creates a new address to receive offers on
 2. recipient sends the pubkey for the newly created address to the offerer
 3. offerer imports the recipient's pubkey
 4. offerer sends a new offer to the recipients key instead of the public network

Nodes will ignore offers sent on keys other than the network key or keys created for offer-receiving.
This commit is contained in:
tecnovert
2021-10-20 19:47:49 +02:00
parent f63815b26b
commit a40519737d
15 changed files with 217 additions and 38 deletions

View File

@@ -21,7 +21,7 @@ from coincurve.ecdsaotves import (
from coincurve.keys import (
PrivateKey)
from basicswap.ecc_util import i2b
from basicswap.ecc_util import i2b, h2b
from basicswap.interface_btc import BTCInterface
from basicswap.interface_xmr import XMRInterface
@@ -206,6 +206,13 @@ class Test(unittest.TestCase):
assert(len(sig) == 64)
ci.verifyCompact(pk, 'test signing message', sig)
def test_pubkey_to_address(self):
coin_settings = {'rpcport': 0, 'rpcauth': 'none', 'blocks_confirmed': 1, 'conf_target': 1}
ci = BTCInterface(coin_settings, 'regtest')
pk = h2b('02c26a344e7d21bcc6f291532679559f2fd234c881271ff98714855edc753763a6')
addr = ci.pubkey_to_address(pk)
assert(addr == 'mj6SdSxmWRmdDqR5R3FfZmRiLmQfQAsLE8')
def test_dleag(self):
coin_settings = {'rpcport': 0, 'walletrpcport': 0, 'walletrpcauth': 'none', 'blocks_confirmed': 1, 'conf_target': 1}
ci = XMRInterface(coin_settings, 'regtest')

View File

@@ -466,8 +466,9 @@ class Test(unittest.TestCase):
end_xmr = float(js_0_end['6']['balance']) + float(js_0_end['6']['unconfirmed'])
assert(end_xmr > 10.9 and end_xmr < 11.0)
def test_011_smsgaddresses(self):
logging.info('---------- Test address management and private offers')
swap_clients = self.swap_clients
js_1 = json.loads(urlopen('http://127.0.0.1:1801/json/smsgaddresses').read())
post_json = {
@@ -475,6 +476,7 @@ class Test(unittest.TestCase):
}
json_rv = json.loads(post_json_req('http://127.0.0.1:1801/json/smsgaddresses/new', post_json))
new_address = json_rv['new_address']
new_address_pk = json_rv['pubkey']
js_2 = json.loads(urlopen('http://127.0.0.1:1801/json/smsgaddresses').read())
assert(len(js_2) == len(js_1) + 1)
@@ -534,6 +536,33 @@ class Test(unittest.TestCase):
found = True
assert(found is True)
post_json = {
'addresspubkey': new_address_pk,
'addressnote': 'testing_add_addr',
}
json_rv = json.loads(post_json_req('http://127.0.0.1:1800/json/smsgaddresses/add', post_json))
assert(json_rv['added_address'] == new_address)
post_json = {
'addr_to': new_address,
'addr_from': -1,
'coin_from': 1,
'coin_to': 6,
'amt_from': 1,
'amt_to': 1,
'lockhrs': 24,
'autoaccept': True}
rv = json.loads(post_json_req('http://127.0.0.1:1800/json/offers/new', post_json))
offer_id_hex = rv['offer_id']
wait_for_offer(test_delay_event, swap_clients[1], bytes.fromhex(offer_id_hex))
rv = json.loads(urlopen(f'http://127.0.0.1:1801/json/offers/{offer_id_hex}').read())
assert(rv[0]['addr_to'] == new_address)
rv = json.loads(urlopen(f'http://127.0.0.1:1800/json/offers/{offer_id_hex}').read())
assert(rv[0]['addr_to'] == new_address)
def test_02_leader_recover_a_lock_tx(self):
logging.info('---------- Test PART to XMR leader recovers coin a lock tx')
swap_clients = self.swap_clients