本文整理汇总了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()
示例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))
示例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))
示例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)
示例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)
示例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
示例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
示例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
示例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)
示例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)
示例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)