當前位置: 首頁>>代碼示例>>Python>>正文


Python bitcoin.privkey_to_pubkey方法代碼示例

本文整理匯總了Python中bitcoin.privkey_to_pubkey方法的典型用法代碼示例。如果您正苦於以下問題:Python bitcoin.privkey_to_pubkey方法的具體用法?Python bitcoin.privkey_to_pubkey怎麽用?Python bitcoin.privkey_to_pubkey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bitcoin的用法示例。


在下文中一共展示了bitcoin.privkey_to_pubkey方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: refresh_adresses_preview

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import privkey_to_pubkey [as 別名]
def refresh_adresses_preview(self):
        if self.mnemonic:
            bip32_path = self.edtHwOptionsBip32Path.text()
            passphrase = self.edtHwOptionsPassphrase.text()
            passphrase = self.mnemonic.normalize_string(passphrase)
            mnem_str = ' '.join(self.get_cur_mnemonic_words())
            bip32_seed = self.mnemonic.to_seed(mnem_str, passphrase)
            bip32_master_key = bitcoin.bip32_master_key(bip32_seed)
            bip32_path_n = dash_utils.bip32_path_string_to_n(bip32_path)
            if len(bip32_path_n) > 0:
                last_idx = bip32_path_n[-1]
                addresses = []
                for idx in range(10):
                    bip32_path_n[-1] = last_idx + idx
                    pk = self.get_bip32_private_key(bip32_path_n, bip32_master_key)
                    pubkey = bitcoin.privkey_to_pubkey(pk)
                    addr = pubkey_to_address(pubkey, self.app_config.dash_network)
                    path_str = bip32_path_n_to_string(bip32_path_n)
                    addresses.append((path_str, addr))
                self.address_preview_model.apply_addresses(addresses)
                self.address_preview_model.refresh_view()
                self.viewAddresses.resizeColumnsToContents() 
開發者ID:Bertrand256,項目名稱:dash-masternode-tool,代碼行數:24,代碼來源:initialize_hw_dlg.py

示例2: test_checkPivxAddr

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import privkey_to_pubkey [as 別名]
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)) 
開發者ID:PIVX-Project,項目名稱:PIVX-SPMT,代碼行數:18,代碼來源:testUtilsMethods.py

示例3: test_compose_tx_locking_script

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import privkey_to_pubkey [as 別名]
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)) 
開發者ID:PIVX-Project,項目名稱:PIVX-SPMT,代碼行數:21,代碼來源:testUtilsMethods.py

示例4: finalizeStartMessage_end

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import privkey_to_pubkey [as 別名]
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) 
開發者ID:PIVX-Project,項目名稱:PIVX-SPMT,代碼行數:25,代碼來源:testMasternodeMethods.py

示例5: __init__

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import privkey_to_pubkey [as 別名]
def __init__(self, tab_main, name, ip, port, mnPrivKey, hwAcc, collateral = {}, isTestnet=False, *args, **kwargs):
        QObject.__init__(self, *args, **kwargs)
        self.tab_main = tab_main
        self.name = name
        self.ip = ip
        self.port = str(port)
        self.mnPrivKey = wif_to_privkey(mnPrivKey)
        self.mnWIF = mnPrivKey
        self.mnPubKey = bitcoin.privkey_to_pubkey(self.mnPrivKey)
        self.hwAcc = hwAcc
        self.spath = collateral['spath']
        self.nodePath = "%d'/0/%d" % (self.hwAcc, self.spath)
        self.collateral = collateral
        self.isTestnet = isTestnet
        self.currHeight = 0
        Masternode.mnCount += 1
        printOK("Initializing MNode with collateral: %s" % self.nodePath) 
開發者ID:PIVX-Project,項目名稱:PIVX-SPMT,代碼行數:19,代碼來源:masternode.py

示例6: wif_privkey_to_pubkey

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import privkey_to_pubkey [as 別名]
def wif_privkey_to_pubkey(privkey):
    pub = bitcoin.privkey_to_pubkey(privkey)
    return pub 
開發者ID:Bertrand256,項目名稱:dash-masternode-tool,代碼行數:5,代碼來源:dash_utils.py

示例7: ecdsa_sign

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import privkey_to_pubkey [as 別名]
def ecdsa_sign(msg: str, wif_priv_key: str, dash_network: str):
    """Signs a message with the Elliptic Curve algorithm.
    """

    v, r, s = bitcoin.ecdsa_raw_sign(electrum_sig_hash(msg), wif_priv_key)
    sig = bitcoin.encode_sig(v, r, s)
    pubkey = bitcoin.privkey_to_pubkey(wif_to_privkey(wif_priv_key, dash_network))

    ok = bitcoin.ecdsa_raw_verify(electrum_sig_hash(msg), bitcoin.decode_sig(sig), pubkey)
    if not ok:
        raise Exception('Bad signature!')
    return sig 
開發者ID:Bertrand256,項目名稱:dash-masternode-tool,代碼行數:14,代碼來源:dash_utils.py

示例8: ecdsa_sign_raw

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import privkey_to_pubkey [as 別名]
def ecdsa_sign_raw(msg_raw: bytes, wif_priv_key: str, dash_network: str):
    """Signs raw bytes (a message hash) with the Elliptic Curve algorithm.
    """

    v, r, s = bitcoin.ecdsa_raw_sign(msg_raw, wif_priv_key)
    sig = bitcoin.encode_sig(v, r, s)
    pubkey = bitcoin.privkey_to_pubkey(wif_to_privkey(wif_priv_key, dash_network))

    ok = bitcoin.ecdsa_raw_verify(msg_raw, bitcoin.decode_sig(sig), pubkey)
    if not ok:
        raise Exception('Bad signature!')
    return sig 
開發者ID:Bertrand256,項目名稱:dash-masternode-tool,代碼行數:14,代碼來源:dash_utils.py

示例9: test_pubkey_to_address

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import privkey_to_pubkey [as 別名]
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) 
開發者ID:PIVX-Project,項目名稱:PIVX-SPMT,代碼行數:13,代碼來源:testPivx_hashlibMethods.py

示例10: __init__

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import privkey_to_pubkey [as 別名]
def __init__(self, priv_key):
        """
        Create an instance.

        Args:
            priv_key (bytes): a private key.
        """
        self.setup_curve()

        length = len(priv_key)

        if length != 32 and length != 96 and length != 104:
            raise ValueError("Invalid private key")

        self.PrivateKey = bytearray(priv_key[-32:])

        pubkey_encoded_not_compressed = None

        if length == 32:
            try:
                pubkey_encoded_not_compressed = bitcoin.privkey_to_pubkey(priv_key)
            except Exception as e:
                raise Exception("Could not determine public key")

        elif length == 96 or length == 104:
            skip = length - 96
            pubkey_encoded_not_compressed = bytearray(b'\x04') + bytearray(priv_key[skip:skip + 64])

        if pubkey_encoded_not_compressed:
            pubkey_points = bitcoin.decode_pubkey(pubkey_encoded_not_compressed, 'bin')

            pubx = pubkey_points[0]
            puby = pubkey_points[1]
            edcsa = ECDSA.secp256r1()
            self.PublicKey = edcsa.Curve.point(pubx, puby)

        self.PublicKeyHash = Crypto.ToScriptHash(self.PublicKey.encode_point(True), unhex=True) 
開發者ID:CityOfZion,項目名稱:neo-python-core,代碼行數:39,代碼來源:KeyPair.py

示例11: __init__

# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import privkey_to_pubkey [as 別名]
def __init__(self, priv_key):
        """
        Create an instance.

        Args:
            priv_key (bytes): a private key.

        Raises:
            ValueError:
                if the input `priv_key` length is not 32, 96, or 104
                if the input `priv_key` length is 32 but the public key still could not be determined
        """
        self.setup_curve()
        self.PublicKeyHash = None
        self.PublicKey = None
        self.PrivateKey = None

        length = len(priv_key)

        if length != 32 and length != 96 and length != 104:
            raise ValueError("Invalid private key")

        self.PrivateKey = bytearray(priv_key[-32:])

        pubkey_encoded_not_compressed = None

        if length == 32:
            try:
                pubkey_encoded_not_compressed = bitcoin.privkey_to_pubkey(priv_key)
            except Exception:
                raise ValueError("Could not determine public key")

        elif length == 96 or length == 104:
            skip = length - 96
            pubkey_encoded_not_compressed = bytearray(b'\x04') + bytearray(priv_key[skip:skip + 64])

        if pubkey_encoded_not_compressed:
            pubkey_points = bitcoin.decode_pubkey(pubkey_encoded_not_compressed, 'bin')

            pubx = pubkey_points[0]
            puby = pubkey_points[1]
            edcsa = ECDSA.secp256r1()
            self.PublicKey = edcsa.Curve.point(pubx, puby)

        self.PublicKeyHash = Crypto.ToScriptHash(self.PublicKey.encode_point(True), unhex=True) 
開發者ID:CityOfZion,項目名稱:neo-python,代碼行數:47,代碼來源:KeyPair.py


注:本文中的bitcoin.privkey_to_pubkey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。