Skip to content

Commit

Permalink
more RPA nits
Browse files Browse the repository at this point in the history
  • Loading branch information
fyookball committed Oct 17, 2020
1 parent 35e621f commit 060ca8f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
6 changes: 3 additions & 3 deletions lib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,13 +552,13 @@ def rpa_generate_paycode(self):
return rpa_paycode.rpa_generate_paycode(self.wallet)

@command('wp')
def rpa_generate_transaction_from_paycode(self, amount, paycode=None, fee= None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, password=None, locktime=None,
op_return=None, op_return_raw=None):
def rpa_generate_transaction_from_paycode(self, amount, paycode=None, fee= None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, password=None, locktime=None,
op_return=None, op_return_raw=None):
# WARNING: Amount is in full Bitcoin Cash units
return rpa_paycode.rpa_generate_transaction_from_paycode(self.wallet, self.config, amount, paycode)

@command('wp')
def rpa_extract_private_key_from_transaction(self,raw_tx, password=None):
def rpa_extract_private_key_from_transaction(self, raw_tx, password=None):
return rpa_paycode.rpa_extract_private_key_from_transaction(self.wallet, raw_tx, password)

@command('wp')
Expand Down
27 changes: 15 additions & 12 deletions lib/rpa_paycode.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
This implements the functionality for RPA (Reusable Payment Address) aka Paycodes
'''

from . import rpaaddr

from . import address
from . import bitcoin
from . import rpaaddr
from . import transaction
from . import address
from decimal import Decimal as PyDecimal
from .bitcoin import COIN, TYPE_ADDRESS, sha256

from .address import Address, AddressError, Base58, PublicKey
from .bitcoin import COIN, TYPE_ADDRESS, sha256
from .transaction import Transaction

from decimal import Decimal as PyDecimal

def satoshis(amount):
# satoshi conversion must not be performed by the parser
return int(COIN*PyDecimal(amount)) if amount not in ['!', None] else amount
Expand Down Expand Up @@ -64,10 +67,10 @@ def mktx(wallet, config, outputs, fee=None, change_addr=None, domain=None, noche

def calculate_paycode_shared_secret(private_key, public_key, outpoint):

# private key is expected to be an integer.
# public_key is expected to be bytes.
# outpoint is expected to be a string.
# returns the paycode shared secret as bytes
"""private key is expected to be an integer.
public_key is expected to be bytes.
outpoint is expected to be a string.
returns the paycode shared secret as bytes"""

from fastecdsa import keys, curve
from fastecdsa.point import Point
Expand Down Expand Up @@ -100,8 +103,8 @@ def calculate_paycode_shared_secret(private_key, public_key, outpoint):

def generate_address_from_pubkey_and_secret(parent_pubkey, secret):

# parent_pubkey and secret are expected to be bytes
# This function generates a receiving address based on CKD.
"""parent_pubkey and secret are expected to be bytes
This function generates a receiving address based on CKD."""

new_pubkey = bitcoin.CKD_pub(parent_pubkey, secret, 0)[0]

Expand All @@ -121,8 +124,8 @@ def generate_address_from_pubkey_and_secret(parent_pubkey, secret):

def generate_privkey_from_secret(parent_privkey, secret):

# parent_privkey and secret are expected to be bytes
# This function generates a receiving address based on CKD.
"""parent_privkey and secret are expected to be bytes
This function generates a receiving address based on CKD."""

new_privkey = bitcoin.CKD_priv(parent_privkey, secret, 0)[0].hex()
return new_privkey
Expand Down
2 changes: 1 addition & 1 deletion lib/schnorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def sign(privkey, message_hash, *, ndata=None):
'''

if ndata is not None:
assert len(bytearray(ndata)) == 32
assert len(ndata) == 32

if not isinstance(privkey, bytes) or len(privkey) != 32:
raise ValueError('privkey must be a bytes object of length 32')
Expand Down
9 changes: 4 additions & 5 deletions lib/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,8 @@ def rpa_paycode_swap_dummy_for_destination(self, rpa_dummy_address, rpa_destinat
# be dangerous to change the destination address of a transaction.

# This method expects cashaddr strings for parameters rpa_dummy_address and rpa_destination_address

x=range(len(self._outputs))
for i in x:

for i in range(len(self._outputs)):
# Grab the address of each output...
loop_iteration_output = self._outputs[i]
loop_iteration_address = loop_iteration_output[1]
Expand All @@ -530,8 +529,8 @@ def rpa_paycode_swap_dummy_for_destination(self, rpa_dummy_address, rpa_destinat
# Do the swap
rpa_replacement_address = Address.from_string(rpa_destination_address)
rpa_replacement_output = list(loop_iteration_output)
rpa_replacement_output[1]= rpa_replacement_address
self._outputs[i]=tuple(rpa_replacement_output)
rpa_replacement_output[1] = rpa_replacement_address
self._outputs[i] = tuple(rpa_replacement_output)

# It is necessary to re-initialize "raw" so the output swap becomes part of transaction when it is later serialized
self.raw = None
Expand Down
3 changes: 1 addition & 2 deletions lib/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2247,8 +2247,7 @@ def sign_transaction(self, tx, password, *, use_cache=False, ndata=None):
k.sign_transaction(tx, password, use_cache=use_cache, ndata=ndata)
else:
# keystore does not understand `ndata` (possibly because hw wallet)
raise BaseException("Keystore does not understand ndata parameter. Possibly wrong wallet type attemping special operation.")
continue
raise RuntimeError("Keystore does not understand ndata parameter. Possibly wrong wallet type attemping special operation.")
else: # regular normal operation
k.sign_transaction(tx, password, use_cache=use_cache)
except UserCancelled:
Expand Down

0 comments on commit 060ca8f

Please sign in to comment.