Exemple #1
0
    def scanForBip32(self, account, address, starting_spath=0, spath_count=10, isTestnet=False):
        found = False
        spath = -1
        
        printOK("Scanning for Bip32 path of address: %s" % address)
        for i in range(starting_spath, starting_spath+spath_count):
            curr_path = MPATH + "%d'/0/%d" % (account, i)
            printDbg("checking path... %s" % curr_path)
            self.lock.acquire()
            try:
                if not isTestnet:
                    curr_addr = self.chip.getWalletPublicKey(curr_path).get('address')[12:-2]
                else:
                    pubkey = compress_public_key(self.chip.getWalletPublicKey(curr_path).get('publicKey')).hex()          
                    curr_addr = pubkey_to_address(pubkey, isTestnet)     

                             
                if curr_addr == address:
                    found = True
                    spath = i
                    break
                
                sleep(0.01)
            
            except Exception as e:
                err_msg = 'error in scanForBip32'
                printException(getCallerName(), getFunctionName(), err_msg, e.args)
                
            finally:
                self.lock.release()
                
        return (found, spath)
Exemple #2
0
def ecdsa_verify_addr(msg, sig, addr):
    isTestnet = addr[0] not in P2PKH_PREFIXES
    if not checkPivxAddr(addr, isTestnet):
        return False
    v, r, s = decode_sig(sig)
    Q = ecdsa_raw_recover(electrum_sig_hash(msg), (v, r, s))
    Qenc = encode_pubkey(Q, 'hex_compressed') if v >= 31 else encode_pubkey(
        Q, 'hex')

    return pubkey_to_address(Qenc, isTestnet) == addr
 def test_pubkey_to_address(self):
     # generate random private key and convert to public
     randomPubKey = bitcoin.privkey_to_pubkey(generate_privkey())
     # compute address
     randomPivxAddr = pubkey_to_address(randomPubKey)
     # check leading char 'D'
     self.assertEqual(randomPivxAddr[0], 'D')
     # decode and verify checksum
     randomPivxAddr_bin = bytes.fromhex(b58decode(randomPivxAddr).hex())
     randomPivxAddr_bin_check = bitcoin.bin_dbl_sha256(randomPivxAddr_bin[0:-4])[0:4]
     self.assertEqual(randomPivxAddr_bin[-4:], randomPivxAddr_bin_check)
Exemple #4
0
    def scanForAddress(self, hwAcc, spath, intExt=0, isTestnet=False):
        with self.lock:
            if not isTestnet:
                curr_path = MPATH + "%d'/%d/%d" % (hwAcc, intExt, spath)
                curr_addr = self.chip.getWalletPublicKey(curr_path).get('address')[12:-2]
            else:
                curr_path = MPATH_TESTNET + "%d'/%d/%d" % (hwAcc, intExt, spath)
                pubkey = compress_public_key(self.chip.getWalletPublicKey(curr_path).get('publicKey')).hex()
                curr_addr = pubkey_to_address(pubkey, isTestnet)

        return curr_addr
Exemple #5
0
    def scanForAddress(self, account, spath, isTestnet=False):
        curr_addr = None
        curr_path = MPATH + "%d'/0/%d" % (account, spath)
        printOK("Scanning for Address n. %d on account n. %d" % (spath, account))
        
        with self.lock:
            if not isTestnet:
                curr_addr = self.chip.getWalletPublicKey(curr_path).get('address')[12:-2]
            else:
                pubkey = compress_public_key(self.chip.getWalletPublicKey(curr_path).get('publicKey')).hex()
                curr_addr = pubkey_to_address(pubkey, isTestnet)

        return curr_addr
Exemple #6
0
 def test_checkPivxAddr(self):
     # Generate Valid PIVX address
     pK = privkey_to_pubkey(generate_privkey())
     pivxAddr = pubkey_to_address(pK)
     # Check valid address
     self.assertTrue(checkPivxAddr(pivxAddr))
     # Check malformed address 1: change leading char
     pivxAddr2 = self.getRandomChar() + pivxAddr[1:]
     while pivxAddr2[0] == 'D':
         pivxAddr2 = self.getRandomChar() + pivxAddr[1:]
     self.assertFalse(checkPivxAddr(pivxAddr2))
     # Check malformed address 1: add random chars
     pivxAddr3 = pivxAddr
     for _ in range(10):
         pivxAddr3 += self.getRandomChar()
     self.assertFalse(checkPivxAddr(pivxAddr3))
Exemple #7
0
 def updateGenericAddress(self, pk):
     genericAddy = pubkey_to_address(pk, self.currIsTestnet)
     if self.ui.fromAddressRadioBtn.isChecked():
         # double check address
         addy = self.ui.addressLineEdit.text().strip()
         if addy != genericAddy:
             mess = "Error! retrieved address (%s) different from input (%s)" % (genericAddy, addy)
             myPopUp_sb(self.main_wnd, QMessageBox.Critical, 'SPMT - address mismatch', mess)
             self.ui.addressLabel.setText("")
             return
     # update generic address
     self.setSignEnabled(True)
     self.currAddress = genericAddy
     self.currHwPath = "%d'/0/%d" % (self.hwAcc, self.spath)
     self.ui.addressLabel.setText(self.currAddress)
     self.ui.editBtn.setVisible(True)
Exemple #8
0
 def test_compose_tx_locking_script(self):
     # check with P2PKH addresses
     # Generate Valid PIVX address
     pK = privkey_to_pubkey(generate_privkey())
     pivxAddr = pubkey_to_address(pK)
     # compose TX script
     result = compose_tx_locking_script(pivxAddr)
     print(result)
     # check OP_DUP
     self.assertEqual(result[0], int('76', 16))
     # check OP_HASH160
     self.assertEqual(result[1], int('A9', 16))
     pubkey_hash = bytearray.fromhex(b58check_to_hex(pivxAddr))
     self.assertEqual(result[2], len(pubkey_hash))
     self.assertEqual(result[3:23], pubkey_hash)
     # check OP_QEUALVERIFY
     self.assertEqual(result[23], int('88', 16))
     # check OP_CHECKSIG
     self.assertEqual(result[24], int('AC', 16))
Exemple #9
0
 def scanForAddress(self, account, spath, isTestnet=False):
     printOK("Scanning for Address n. %d on account n. %d" % (spath, account))
     curr_path = MPATH + "%d'/0/%d" % (account, spath) 
     self.lock.acquire()
     try:
         if not isTestnet:
             curr_addr = self.chip.getWalletPublicKey(curr_path).get('address')[12:-2]
         else:
             pubkey = compress_public_key(self.chip.getWalletPublicKey(curr_path).get('publicKey')).hex()
             curr_addr = pubkey_to_address(pubkey, isTestnet) 
             
                                      
     except Exception as e:
         err_msg = 'error in scanForAddress'
         printException(getCallerName(), getFunctionName(), err_msg, e.args)
         return None
     finally:
         self.lock.release()
     return curr_addr
Exemple #10
0
 def scanForBip32(self, account, address, starting_spath=0, spath_count=10, isTestnet=False):
     found = False
     spath = -1       
     printOK("Scanning for Bip32 path of address: %s" % address)
     
     for i in range(starting_spath, starting_spath+spath_count):
         curr_path = MPATH + "%d'/0/%d" % (account, i)
         printDbg("checking path... %s" % curr_path)
         with self.lock: 
             if not isTestnet:
                 curr_addr = self.chip.getWalletPublicKey(curr_path).get('address')[12:-2]
             else:
                 pubkey = compress_public_key(self.chip.getWalletPublicKey(curr_path).get('publicKey')).hex()          
                 curr_addr = pubkey_to_address(pubkey, isTestnet)
                          
             if curr_addr == address:
                 found = True
                 spath = i
                 break
             
             sleep(0.01)
         
     return (found, spath)
 def finalizeStartMessage_end(self, text):
     # decode message
     ret = self.caller.rpcClient.decodemasternodebroadcast(text)
     # find masternode in list and check
     for mnode in self.mnode_list:
         ip_addr = mnode.ip + ":" + mnode.port
         if ret['addr'] == ip_addr:
             # check ping signature
             ping_sig = b64encode(text[638:768])
             self.assertEqual(ret['lastPing'].get('vchSig'), ping_sig)
             # check nLastDsq
             self.assertEqual(ret['nLastDsq'], 0)
             # check protocol version
             pv = self.rpcClient.getProtocolVersion()
             self.assertEqual(ret['protocolVersion'], pv)
             # check masternode pubkey1
             self.assertEqual(ret['pubkey'], mnode['collateral'].get('address'))
             # check masternode pubkey2
             pk2 = pubkey_to_address(privkey_to_pubkey(mnode.mnPrivKey))
             self.assertEqual(ret['pubkey2'], pk2)
             # check masternode signature
             node_sig = b64encode(text[320:450])
             self.assertEqual(ret['vchSig'], node_sig)