Exemple #1
0
def newbppid():
    if bppclient.cfgmain["priv_seed"] == "":
        QtGui.QMessageBox.critical(bppclient, 'Registration', "No seed in config file to generate password.", QtGui.QMessageBox.Ok)
        return
    bppid, ok = QtGui.QInputDialog.getText(bppclient, 'Create a new BPP ID', 'Enter your new BPP ID: (like [email protected])')
    if ok and bppid != '':
        password = Btclib.bip32_ckd(bppclient.mpkbpp, Btclib.decode(Btclib.sha256(bppid)[0:6],16))[-28:]
        bppclient.bppcnx = BPPxmpp(bppid, password)
        bppclient.bppcnx.register_plugin('xep_0030') # Service Discovery
        bppclient.bppcnx.register_plugin('xep_0004') # Data forms
        bppclient.bppcnx.register_plugin('xep_0066') # Out-of-band Data
        bppclient.bppcnx.register_plugin('xep_0077') # In-band Registration
        bppclient.bppcnx.register_plugin('xep_0054') # Vcard
        bppclient.bppcnx['xep_0077'].force_registration = True
	bppclient.bppcnx.connect(reattempt=False)
        bppclient.bppcnx.process()
        mutex.lock()
        waitCondition.wait(mutex)
        mutex.unlock()
        if bppclient.bppcnx.regstatus == 1:
            bppclient.cfgbpp.append({"bppid" : str(bppid), "password" : password})
            save_cfg()
            bppclient.ui.bppidcb.addItem(str(bppid))
            bppclient.ui.bppidcb.setCurrentIndex(bppclient.ui.bppidcb.count()-1)
            QtGui.QMessageBox.warning(bppclient, 'Registration', "Your BPP ID have been created.", QtGui.QMessageBox.Ok)
	    user = bppid.split('@')[0]
    	    sec = Btclib.hex_to_b58check(Btclib.privkey_to_pubkey(bppclient.keysign)[2:32])[1:]
    	    if user == sec:
        	bppclient.ui.bppidsec.setText(bppid)
    	    else:
        	bppclient.ui.bppidsec.setText(bppid + '&' + sec)
        elif bppclient.bppcnx.regstatus == 2:
            QtGui.QMessageBox.warning(bppclient, 'Registration', "This BPP ID is already in use.", QtGui.QMessageBox.Ok)
        elif bppclient.bppcnx.regstatus == 3:
            QtGui.QMessageBox.warning(bppclient, 'Registration', "No response frome the server. TimeOut.", QtGui.QMessageBox.Ok)
Exemple #2
0
def start():
    try:
        f = open(os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), 'bpp_data', 'bppcnx.cfg'),'r')
        c = json.load(f)
        f.close()
        bppclient.cfgmain = c["main"]
        bppclient.cfgbpp = c["bpp"]
        for bppid in bppclient.cfgbpp:
            bppclient.ui.bppidcb.addItem(bppid["bppid"])
        if bppclient.cfgmain["master_pub_key"] != "":
            bppclient.mpkbtc = Btclib.bip32_ckd(bppclient.cfgmain["master_pub_key"], 2)
        if bppclient.cfgmain["priv_seed"] != "":
            bppclient.mpkbpp = Btclib.subkey_for_path(Btclib.bip32_master_key(bppclient.cfgmain["priv_seed"]), "1/1/1")
	    bppclient.wallet.privbtc = Btclib.subkey_for_path(Btclib.bip32_master_key(bppclient.cfgmain["priv_seed"]), "1/1/2")
        if bppclient.cfgmain["keysign"] != "":
            bppclient.keysign = bppclient.cfgmain["keysign"]
        if bppclient.cfgbpp != []:
            bppidcnt()
    except IOError:
        create_mpk()
    updateStatusBar()
    updateReceiveAddrs()
Exemple #3
0
def sendpay():
    sendaddr = bppclient.ui.sendaddr.text().split('&')
    sendval = bppclient.ui.sendval.text()
    sendref = bppclient.ui.sendref.text()
    if len(sendaddr) == 2:
        check = '1'+sendaddr[1]
    else:
        check = '1'+sendaddr[0].split('@')[0]
    sendaddr = sendaddr[0]
    try: #Bitcoin Address
	if Btclib.get_version_byte(sendaddr) == 0:
	    check = 'B'
    except AssertionError:
        pass
    if not '@' in sendaddr and check != 'B':
	QtGui.QMessageBox.warning(bppclient, 'Payment', "%s is not a BPP valid address." % sendaddr, QtGui.QMessageBox.Ok)
        return
    try: #BPP ID
        if check != 'B' and Btclib.get_version_byte(check) != 0:
            check = ""
    except AssertionError:
        check = ""
    if check == "":
        if QtGui.QMessageBox.Cancel == QtGui.QMessageBox.warning(bppclient, 'Payment', "There are not a valid security code entered. Do you want to send the payment without asserting the destination address ?", QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel):
            return
    try:
        result = json.loads(bppclient.bppcnx['xep_0054'].get_vcard(sendaddr)['vcard_temp']['NOTE']) if check != 'B' else None
        if check != "" and check != 'B' and Btclib.hex_to_b58check(Btclib.ecdsa_recover(str(result['BITCOIN_MPK']), str(result['BITCOIN_SIGN']))[2:32]) != check:
            QtGui.QMessageBox.critical(bppclient, 'Payment', "The security of the payment address is corrupted.", QtGui.QMessageBox.Ok)
            return
	try:
            amount = int(Decimal(sendval) * 100000000)
	    if amount == 0: raise Exception
        except Exception:
            QtGui.QMessageBox.warning(bppclient, 'Payment', "Invalid Amount.", QtGui.QMessageBox.Ok)
            return
	if check != 'B':
            p1, p2, mpk = result['BITCOIN_MPK'].split('/')
            p3 = random.randrange(2**31-1)
        addr = Btclib.pubkey_to_address(Btclib.bip32_extract_key(Btclib.bip32_ckd(mpk, p3))) if check != 'B' else sendaddr
	try:
	    tx = bppclient.wallet.mktx([(addr,amount)],None)
	except ValueError:
	    QtGui.QMessageBox.warning(bppclient, 'Payment', "Not enough funds.", QtGui.QMessageBox.Ok)
            return
	txin = tx.inputs[0].get('prevout_hash')
	if check != 'B':
            paymsg = json.dumps({"TYPE" : "PAYMENT", "DATA" : {"PATH" : p1+'/'+p2+'/'+str(p3)+'/'+addr,
                             "TXIN" : txin, "REF" : sendref,
                             "RETADDR" : bppclient.ui.bppidsec.text()}})
            bppclient.bppcnx.send_message(mto=sendaddr, mbody=paymsg)
	    insertPendPay((txin,p1+'/'+p2+'/'+str(p3)+'/'+addr,bppclient.bppcnx.boundjid.bare,sendaddr,sendref,bppclient.ui.bppidsec.text()),)
	    bppclient.pendpayhist[txin] = (p1+'/'+p2+'/'+str(p3)+'/'+addr,bppclient.bppcnx.boundjid.bare,sendaddr,sendref,bppclient.ui.bppidsec.text())
	else:
	    insertPendPay((txin,'',tx.inputs[0].get('address'),addr,sendref,''),)
	    bppclient.pendpayhist[txin] = ('',tx.inputs[0].get('address'),addr,sendref,'')
	g, o = bppclient.wallet.sendtx(tx)
	if g:  
            QtGui.QMessageBox.information(bppclient, 'Payment', "Your payment have been sent.", QtGui.QMessageBox.Ok)
	else:
	    QtGui.QMessageBox.information(bppclient, 'Payment', o, QtGui.QMessageBox.Ok)
    except (sleekxmpp.exceptions.XMPPError, KeyError, TypeError):
        QtGui.QMessageBox.warning(bppclient, 'Payment', "%s is not a BPP valid address." % sendaddr, QtGui.QMessageBox.Ok)
        return