当前位置: 首页>>代码示例>>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;未经允许,请勿转载。