mirror of
https://github.com/basicswap/basicswap.git
synced 2024-11-17 00:07:56 +00:00
Use unique key_nos for getPathKey.
This commit is contained in:
parent
e502a00341
commit
f289bcf2e8
5 changed files with 56 additions and 28 deletions
|
@ -101,6 +101,7 @@ import basicswap.config as cfg
|
||||||
import basicswap.network as bsn
|
import basicswap.network as bsn
|
||||||
import basicswap.protocols.atomic_swap_1 as atomic_swap_1
|
import basicswap.protocols.atomic_swap_1 as atomic_swap_1
|
||||||
from .basicswap_util import (
|
from .basicswap_util import (
|
||||||
|
KeyTypes,
|
||||||
TxLockTypes,
|
TxLockTypes,
|
||||||
AddressTypes,
|
AddressTypes,
|
||||||
MessageTypes,
|
MessageTypes,
|
||||||
|
@ -2031,10 +2032,10 @@ class BasicSwap(BaseApp):
|
||||||
xmr_swap.dest_af = msg_buf.dest_af
|
xmr_swap.dest_af = msg_buf.dest_af
|
||||||
|
|
||||||
for_ed25519 = True if coin_to == Coins.XMR else False
|
for_ed25519 = True if coin_to == Coins.XMR else False
|
||||||
kbvf = self.getPathKey(coin_from, coin_to, bid_created_at, xmr_swap.contract_count, 1, for_ed25519)
|
kbvf = self.getPathKey(coin_from, coin_to, bid_created_at, xmr_swap.contract_count, KeyTypes.KBVF, for_ed25519)
|
||||||
kbsf = self.getPathKey(coin_from, coin_to, bid_created_at, xmr_swap.contract_count, 2, for_ed25519)
|
kbsf = self.getPathKey(coin_from, coin_to, bid_created_at, xmr_swap.contract_count, KeyTypes.KBSF, for_ed25519)
|
||||||
|
|
||||||
kaf = self.getPathKey(coin_from, coin_to, bid_created_at, xmr_swap.contract_count, 3)
|
kaf = self.getPathKey(coin_from, coin_to, bid_created_at, xmr_swap.contract_count, KeyTypes.KAF)
|
||||||
|
|
||||||
xmr_swap.vkbvf = kbvf
|
xmr_swap.vkbvf = kbvf
|
||||||
xmr_swap.pkbvf = ci_to.getPubkey(kbvf)
|
xmr_swap.pkbvf = ci_to.getPubkey(kbvf)
|
||||||
|
@ -2158,10 +2159,10 @@ class BasicSwap(BaseApp):
|
||||||
xmr_swap.contract_count = self.getNewContractId()
|
xmr_swap.contract_count = self.getNewContractId()
|
||||||
|
|
||||||
for_ed25519 = True if coin_to == Coins.XMR else False
|
for_ed25519 = True if coin_to == Coins.XMR else False
|
||||||
kbvl = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, 1, for_ed25519)
|
kbvl = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KBVL, for_ed25519)
|
||||||
kbsl = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, 2, for_ed25519)
|
kbsl = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KBSL, for_ed25519)
|
||||||
|
|
||||||
kal = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, 3)
|
kal = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KAL)
|
||||||
|
|
||||||
xmr_swap.vkbvl = kbvl
|
xmr_swap.vkbvl = kbvl
|
||||||
xmr_swap.pkbvl = ci_to.getPubkey(kbvl)
|
xmr_swap.pkbvl = ci_to.getPubkey(kbvl)
|
||||||
|
@ -4260,7 +4261,7 @@ class BasicSwap(BaseApp):
|
||||||
ci_to = self.ci(coin_to)
|
ci_to = self.ci(coin_to)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
kaf = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, 3)
|
kaf = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KAF)
|
||||||
|
|
||||||
prevout_amount = ci_from.getLockRefundTxSwapOutputValue(bid, xmr_swap)
|
prevout_amount = ci_from.getLockRefundTxSwapOutputValue(bid, xmr_swap)
|
||||||
xmr_swap.af_lock_refund_spend_tx_esig = ci_from.signTxOtVES(kaf, xmr_swap.pkasl, xmr_swap.a_lock_refund_spend_tx, 0, xmr_swap.a_lock_refund_tx_script, prevout_amount)
|
xmr_swap.af_lock_refund_spend_tx_esig = ci_from.signTxOtVES(kaf, xmr_swap.pkasl, xmr_swap.a_lock_refund_spend_tx, 0, xmr_swap.a_lock_refund_tx_script, prevout_amount)
|
||||||
|
@ -4320,7 +4321,7 @@ class BasicSwap(BaseApp):
|
||||||
ci_from = self.ci(coin_from)
|
ci_from = self.ci(coin_from)
|
||||||
ci_to = self.ci(coin_to)
|
ci_to = self.ci(coin_to)
|
||||||
|
|
||||||
kal = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, 3)
|
kal = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KAL)
|
||||||
|
|
||||||
xmr_swap.a_lock_spend_tx = ci_from.createScriptLockSpendTx(
|
xmr_swap.a_lock_spend_tx = ci_from.createScriptLockSpendTx(
|
||||||
xmr_swap.a_lock_tx, xmr_swap.a_lock_tx_script,
|
xmr_swap.a_lock_tx, xmr_swap.a_lock_tx_script,
|
||||||
|
@ -4477,8 +4478,8 @@ class BasicSwap(BaseApp):
|
||||||
ci_to = self.ci(coin_to)
|
ci_to = self.ci(coin_to)
|
||||||
|
|
||||||
for_ed25519 = True if coin_to == Coins.XMR else False
|
for_ed25519 = True if coin_to == Coins.XMR else False
|
||||||
kbsf = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, 2, for_ed25519)
|
kbsf = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KBSF, for_ed25519)
|
||||||
kaf = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, 3)
|
kaf = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KAF)
|
||||||
|
|
||||||
al_lock_spend_sig = ci_from.decryptOtVES(kbsf, xmr_swap.al_lock_spend_tx_esig)
|
al_lock_spend_sig = ci_from.decryptOtVES(kbsf, xmr_swap.al_lock_spend_tx_esig)
|
||||||
prevout_amount = ci_from.getLockTxSwapOutputValue(bid, xmr_swap)
|
prevout_amount = ci_from.getLockTxSwapOutputValue(bid, xmr_swap)
|
||||||
|
@ -4539,7 +4540,7 @@ class BasicSwap(BaseApp):
|
||||||
assert(kbsf is not None)
|
assert(kbsf is not None)
|
||||||
|
|
||||||
for_ed25519 = True if coin_to == Coins.XMR else False
|
for_ed25519 = True if coin_to == Coins.XMR else False
|
||||||
kbsl = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, 2, for_ed25519)
|
kbsl = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KBSL, for_ed25519)
|
||||||
vkbs = ci_to.sumKeys(kbsl, kbsf)
|
vkbs = ci_to.sumKeys(kbsl, kbsf)
|
||||||
|
|
||||||
if coin_to == Coins.XMR:
|
if coin_to == Coins.XMR:
|
||||||
|
@ -4595,7 +4596,7 @@ class BasicSwap(BaseApp):
|
||||||
assert(kbsl is not None)
|
assert(kbsl is not None)
|
||||||
|
|
||||||
for_ed25519 = True if coin_to == Coins.XMR else False
|
for_ed25519 = True if coin_to == Coins.XMR else False
|
||||||
kbsf = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, 2, for_ed25519)
|
kbsf = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KBSF, for_ed25519)
|
||||||
vkbs = ci_to.sumKeys(kbsl, kbsf)
|
vkbs = ci_to.sumKeys(kbsl, kbsf)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -4656,8 +4657,8 @@ class BasicSwap(BaseApp):
|
||||||
xmr_swap.af_lock_refund_tx_sig = msg_data.af_lock_refund_tx_sig
|
xmr_swap.af_lock_refund_tx_sig = msg_data.af_lock_refund_tx_sig
|
||||||
|
|
||||||
for_ed25519 = True if coin_to == Coins.XMR else False
|
for_ed25519 = True if coin_to == Coins.XMR else False
|
||||||
kbsl = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, 2, for_ed25519)
|
kbsl = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KBSL, for_ed25519)
|
||||||
kal = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, 3)
|
kal = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KAL)
|
||||||
|
|
||||||
xmr_swap.af_lock_refund_spend_tx_sig = ci_from.decryptOtVES(kbsl, xmr_swap.af_lock_refund_spend_tx_esig)
|
xmr_swap.af_lock_refund_spend_tx_sig = ci_from.decryptOtVES(kbsl, xmr_swap.af_lock_refund_spend_tx_esig)
|
||||||
prevout_amount = ci_from.getLockRefundTxSwapOutputValue(bid, xmr_swap)
|
prevout_amount = ci_from.getLockRefundTxSwapOutputValue(bid, xmr_swap)
|
||||||
|
@ -4941,9 +4942,9 @@ class BasicSwap(BaseApp):
|
||||||
for_ed25519 = True if Coins(offer.coin_to) == Coins.XMR else False
|
for_ed25519 = True if Coins(offer.coin_to) == Coins.XMR else False
|
||||||
if bid.was_sent:
|
if bid.was_sent:
|
||||||
kbsl = ci_to.decodeKey(encoded_key)
|
kbsl = ci_to.decodeKey(encoded_key)
|
||||||
kbsf = self.getPathKey(offer.coin_from, offer.coin_to, bid.created_at, xmr_swap.contract_count, 2, for_ed25519)
|
kbsf = self.getPathKey(offer.coin_from, offer.coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KBSF, for_ed25519)
|
||||||
else:
|
else:
|
||||||
kbsl = self.getPathKey(offer.coin_from, offer.coin_to, bid.created_at, xmr_swap.contract_count, 2, for_ed25519)
|
kbsl = self.getPathKey(offer.coin_from, offer.coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KBSL, for_ed25519)
|
||||||
kbsf = ci_to.decodeKey(encoded_key)
|
kbsf = ci_to.decodeKey(encoded_key)
|
||||||
ensure(ci_to.verifyKey(kbsl), 'Invalid kbsl')
|
ensure(ci_to.verifyKey(kbsl), 'Invalid kbsl')
|
||||||
ensure(ci_to.verifyKey(kbsf), 'Invalid kbsf')
|
ensure(ci_to.verifyKey(kbsf), 'Invalid kbsf')
|
||||||
|
@ -5581,7 +5582,7 @@ class BasicSwap(BaseApp):
|
||||||
pkh_dest,
|
pkh_dest,
|
||||||
xmr_offer.a_fee_rate, xmr_swap.vkbv)
|
xmr_offer.a_fee_rate, xmr_swap.vkbv)
|
||||||
|
|
||||||
vkaf = self.getPathKey(offer.coin_from, offer.coin_to, bid.created_at, xmr_swap.contract_count, 3)
|
vkaf = self.getPathKey(offer.coin_from, offer.coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KAF)
|
||||||
prevout_amount = ci.getLockRefundTxSwapOutputValue(bid, xmr_swap)
|
prevout_amount = ci.getLockRefundTxSwapOutputValue(bid, xmr_swap)
|
||||||
sig = ci.signTx(vkaf, spend_tx, 0, xmr_swap.a_lock_refund_tx_script, prevout_amount)
|
sig = ci.signTx(vkaf, spend_tx, 0, xmr_swap.a_lock_refund_tx_script, prevout_amount)
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,15 @@ class TxLockTypes(IntEnum):
|
||||||
ABS_LOCK_TIME = 4
|
ABS_LOCK_TIME = 4
|
||||||
|
|
||||||
|
|
||||||
|
class KeyTypes(IntEnum):
|
||||||
|
KBVL = 1
|
||||||
|
KBSL = 2
|
||||||
|
KAL = 3
|
||||||
|
KBVF = 4
|
||||||
|
KBSF = 5
|
||||||
|
KAF = 6
|
||||||
|
|
||||||
|
|
||||||
class MessageTypes(IntEnum):
|
class MessageTypes(IntEnum):
|
||||||
OFFER = auto()
|
OFFER = auto()
|
||||||
BID = auto()
|
BID = auto()
|
||||||
|
|
|
@ -13,15 +13,16 @@ from .chainparams import (
|
||||||
Coins,
|
Coins,
|
||||||
)
|
)
|
||||||
from .basicswap_util import (
|
from .basicswap_util import (
|
||||||
TxLockTypes,
|
|
||||||
DebugTypes,
|
|
||||||
SwapTypes,
|
|
||||||
BidStates,
|
|
||||||
TxStates,
|
|
||||||
TxTypes,
|
TxTypes,
|
||||||
|
KeyTypes,
|
||||||
|
TxStates,
|
||||||
|
BidStates,
|
||||||
|
SwapTypes,
|
||||||
strTxType,
|
strTxType,
|
||||||
strBidState,
|
DebugTypes,
|
||||||
strTxState,
|
strTxState,
|
||||||
|
strBidState,
|
||||||
|
TxLockTypes,
|
||||||
getLastBidState,
|
getLastBidState,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -207,10 +208,9 @@ def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_b
|
||||||
state_description = f'Waiting for {ticker_to} lock tx spend tx to confirm in chain'
|
state_description = f'Waiting for {ticker_to} lock tx spend tx to confirm in chain'
|
||||||
elif bid.state == BidStates.XMR_SWAP_SCRIPT_TX_PREREFUND:
|
elif bid.state == BidStates.XMR_SWAP_SCRIPT_TX_PREREFUND:
|
||||||
if bid.was_sent:
|
if bid.was_sent:
|
||||||
state_description = f'Waiting for offerer to redeem or locktime to expire'
|
state_description = 'Waiting for offerer to redeem or locktime to expire'
|
||||||
else:
|
else:
|
||||||
state_description = f'Redeeming output'
|
state_description = 'Redeeming output'
|
||||||
|
|
||||||
|
|
||||||
addr_label = swap_client.getAddressLabel([bid.bid_addr, ])[0]
|
addr_label = swap_client.getAddressLabel([bid.bid_addr, ])[0]
|
||||||
bid_rate = offer.rate if bid.rate is None else bid.rate
|
bid_rate = offer.rate if bid.rate is None else bid.rate
|
||||||
|
@ -283,7 +283,8 @@ def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_b
|
||||||
data['xmr_b_shared_address'] = ci_to.encodeSharedAddress(xmr_swap.pkbv, xmr_swap.pkbs) if xmr_swap.pkbs else None
|
data['xmr_b_shared_address'] = ci_to.encodeSharedAddress(xmr_swap.pkbv, xmr_swap.pkbs) if xmr_swap.pkbs else None
|
||||||
|
|
||||||
if swap_client.debug_ui:
|
if swap_client.debug_ui:
|
||||||
data['xmr_b_half_privatekey'] = ci_to.encodeKey(swap_client.getPathKey(offer.coin_from, offer.coin_to, bid.created_at, xmr_swap.contract_count, 2, True if offer.coin_to == Coins.XMR else False))
|
key_type = KeyTypes.KBSF if bid.was_sent else KeyTypes.KBSL
|
||||||
|
data['xmr_b_half_privatekey'] = ci_to.encodeKey(swap_client.getPathKey(offer.coin_from, offer.coin_to, bid.created_at, xmr_swap.contract_count, key_type, True if offer.coin_to == Coins.XMR else False))
|
||||||
|
|
||||||
if show_lock_transfers:
|
if show_lock_transfers:
|
||||||
if xmr_swap.pkbs:
|
if xmr_swap.pkbs:
|
||||||
|
|
|
@ -1,7 +1,24 @@
|
||||||
|
|
||||||
0.0.x
|
0.0.x
|
||||||
==============
|
==============
|
||||||
|
|
||||||
|
|
||||||
|
0.0.29
|
||||||
|
==============
|
||||||
|
|
||||||
|
- Use unique key path per key type.
|
||||||
|
- Incompatible with previous versions.
|
||||||
|
- XMR swaps: Can manually spend chain B lock tx if both keys are known.
|
||||||
|
|
||||||
|
|
||||||
|
0.0.28
|
||||||
|
==============
|
||||||
|
|
||||||
- Set working dir to datadir for daemons.
|
- Set working dir to datadir for daemons.
|
||||||
|
- Remove requests module dependency by implementing HTTP digest authentication client.
|
||||||
|
- Reduces log messages
|
||||||
|
- New 'debug_ui' mode, locktime can be specified in minutes.
|
||||||
|
- Must also reduce the 'min_sequence_lock_seconds' setting.
|
||||||
|
|
||||||
|
|
||||||
0.0.27
|
0.0.27
|
||||||
|
|
|
@ -171,7 +171,7 @@ class Test(BaseTest):
|
||||||
bid, xmr_swap = swap_clients[0].getXmrBid(bid_id)
|
bid, xmr_swap = swap_clients[0].getXmrBid(bid_id)
|
||||||
assert(xmr_swap)
|
assert(xmr_swap)
|
||||||
|
|
||||||
swap_clients[1].setBidDebugInd(bid_id, DebugTypes.BID_STOP_AFTER_COIN_A_LOCK)
|
swap_clients[1].setBidDebugInd(bid_id, DebugTypes.CREATE_INVALID_COIN_B_LOCK)
|
||||||
swap_clients[0].setBidDebugInd(bid_id, DebugTypes.BID_DONT_SPEND_COIN_A_LOCK_REFUND)
|
swap_clients[0].setBidDebugInd(bid_id, DebugTypes.BID_DONT_SPEND_COIN_A_LOCK_REFUND)
|
||||||
|
|
||||||
swap_clients[0].acceptXmrBid(bid_id)
|
swap_clients[0].acceptXmrBid(bid_id)
|
||||||
|
|
Loading…
Reference in a new issue