cleanup request signing
This commit is contained in:
parent
074872afbc
commit
acbd434f76
|
@ -730,7 +730,6 @@ class ElectrumWindow(QMainWindow):
|
||||||
menu.exec_(self.receive_list.viewport().mapToGlobal(position))
|
menu.exec_(self.receive_list.viewport().mapToGlobal(position))
|
||||||
|
|
||||||
def sign_payment_request(self, addr):
|
def sign_payment_request(self, addr):
|
||||||
req = self.wallet.receive_requests.get(addr)
|
|
||||||
alias = self.config.get('alias')
|
alias = self.config.get('alias')
|
||||||
alias_privkey = None
|
alias_privkey = None
|
||||||
if alias and self.alias_info:
|
if alias and self.alias_info:
|
||||||
|
@ -741,7 +740,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
password = self.password_dialog(msg)
|
password = self.password_dialog(msg)
|
||||||
if password:
|
if password:
|
||||||
try:
|
try:
|
||||||
alias_privkey = self.wallet.get_private_key(alias_addr, password)[0]
|
self.wallet.sign_payment_request(addr, alias, alias_addr, password)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
QMessageBox.warning(self, _('Error'), str(e), _('OK'))
|
QMessageBox.warning(self, _('Error'), str(e), _('OK'))
|
||||||
return
|
return
|
||||||
|
@ -749,11 +748,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
pr, requestor = paymentrequest.make_request(self.config, req, alias, alias_privkey)
|
|
||||||
if requestor:
|
|
||||||
req['name'] = requestor
|
|
||||||
req['sig'] = pr.signature.encode('hex')
|
|
||||||
self.wallet.add_payment_request(req, self.config)
|
|
||||||
|
|
||||||
def save_payment_request(self):
|
def save_payment_request(self):
|
||||||
addr = str(self.receive_address_e.text())
|
addr = str(self.receive_address_e.text())
|
||||||
|
|
|
@ -578,6 +578,13 @@ class Commands:
|
||||||
self.wallet.add_payment_request(req, self.config)
|
self.wallet.add_payment_request(req, self.config)
|
||||||
return self._format_request(req)
|
return self._format_request(req)
|
||||||
|
|
||||||
|
@command('wp')
|
||||||
|
def signrequest(self, key):
|
||||||
|
"Sign payment request with an OpenAlias"
|
||||||
|
alias = self.config.get('alias')
|
||||||
|
alias_addr = self.contacts.resolve(alias)['address']
|
||||||
|
self.wallet.sign_payment_request(key, alias, alias_addr, self.password)
|
||||||
|
|
||||||
@command('w')
|
@command('w')
|
||||||
def rmrequest(self, key):
|
def rmrequest(self, key):
|
||||||
"""Remove a payment request"""
|
"""Remove a payment request"""
|
||||||
|
|
|
@ -348,21 +348,13 @@ def serialize_request(req):
|
||||||
return pr
|
return pr
|
||||||
|
|
||||||
|
|
||||||
def make_request(config, req, alias=None, alias_privkey=None):
|
def make_request(config, req):
|
||||||
pr = make_unsigned_request(req)
|
pr = make_unsigned_request(req)
|
||||||
key_path = config.get('ssl_privkey')
|
key_path = config.get('ssl_privkey')
|
||||||
cert_path = config.get('ssl_chain')
|
cert_path = config.get('ssl_chain')
|
||||||
requestor = None
|
|
||||||
|
|
||||||
if key_path and cert_path:
|
if key_path and cert_path:
|
||||||
sign_request_with_x509(pr, key_path, cert_path)
|
sign_request_with_x509(pr, key_path, cert_path)
|
||||||
requestor = 'x'
|
return pr
|
||||||
|
|
||||||
elif alias and alias_privkey:
|
|
||||||
requestor = alias
|
|
||||||
sign_request_with_alias(pr, alias, alias_privkey)
|
|
||||||
|
|
||||||
return pr, requestor
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ import bitcoin
|
||||||
from synchronizer import WalletSynchronizer
|
from synchronizer import WalletSynchronizer
|
||||||
from mnemonic import Mnemonic
|
from mnemonic import Mnemonic
|
||||||
|
|
||||||
|
import paymentrequest
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# internal ID for imported account
|
# internal ID for imported account
|
||||||
|
@ -1262,8 +1264,18 @@ class Abstract_Wallet(object):
|
||||||
r = {'time':timestamp, 'amount':amount, 'exp':expiration, 'address':addr, 'memo':message, 'id':_id}
|
r = {'time':timestamp, 'amount':amount, 'exp':expiration, 'address':addr, 'memo':message, 'id':_id}
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def sign_payment_request(self, key, alias, alias_addr, password):
|
||||||
|
req = self.receive_requests.get(key)
|
||||||
|
alias_privkey = self.get_private_key(alias_addr, password)[0]
|
||||||
|
pr = paymentrequest.make_unsigned_request(req)
|
||||||
|
paymentrequest.sign_request_with_alias(pr, alias, alias_privkey)
|
||||||
|
req['name'] = pr.pki_data
|
||||||
|
req['sig'] = pr.signature.encode('hex')
|
||||||
|
self.receive_requests[key] = req
|
||||||
|
self.storage.put('payment_requests', self.receive_requests)
|
||||||
|
|
||||||
def add_payment_request(self, req, config):
|
def add_payment_request(self, req, config):
|
||||||
import paymentrequest, shutil, os
|
import shutil, os
|
||||||
addr = req['address']
|
addr = req['address']
|
||||||
amount = req.get('amount')
|
amount = req.get('amount')
|
||||||
message = req.get('memo')
|
message = req.get('memo')
|
||||||
|
@ -1280,7 +1292,7 @@ class Abstract_Wallet(object):
|
||||||
src = os.path.join(os.path.dirname(__file__), 'www', 'index.html')
|
src = os.path.join(os.path.dirname(__file__), 'www', 'index.html')
|
||||||
shutil.copy(src, index)
|
shutil.copy(src, index)
|
||||||
key = req.get('id', addr)
|
key = req.get('id', addr)
|
||||||
pr, requestor = paymentrequest.make_request(config, req)
|
pr = paymentrequest.make_request(config, req)
|
||||||
path = os.path.join(rdir, key + '.bip70')
|
path = os.path.join(rdir, key + '.bip70')
|
||||||
with open(path, 'w') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(pr.SerializeToString())
|
f.write(pr.SerializeToString())
|
||||||
|
|
Loading…
Reference in New Issue