本文整理汇总了Python中pycoin.key.Key.from_text方法的典型用法代码示例。如果您正苦于以下问题:Python Key.from_text方法的具体用法?Python Key.from_text怎么用?Python Key.from_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycoin.key.Key
的用法示例。
在下文中一共展示了Key.from_text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_initial_key
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def test_initial_key(self):
RECEIVING_ADDRESSES = [
"1LDkC1H438qSnJLHCYkQ3WTZQkSEwoYGHc",
"12mENAcc8ZhZbR6hv7LGm3jV7PwbYeF8Xk",
"1A3NpABFd6YHvwr1ti1r8brU3BzQuV2Nr4",
"1Gn6nWAoZrpmtV9zuNbyivWvRBpcygWaQX",
"1M5i5P3DhtDbnvSTfmnUbcrTVgF8GDWQW9",
]
CHANGE_ADDRESSES = [
"1iiAbyBTh1J69UzD1JcrfW8JSVJ9ve9gT",
"146wnqmsQNYCZ6AXRCqLkzZyGM1ZU6nr3F",
"1Mwexajvia3s8AcaGUkyEg9ZZJPJeTbKTZ",
]
wallet = ElectrumWallet(initial_key="00000000000000000000000000000001")
for idx, address in enumerate(RECEIVING_ADDRESSES):
subkey = wallet.subkey("%s/0" % idx)
calculated_address = subkey.address()
self.assertEqual(address, calculated_address)
wif = subkey.wif()
key = Key.from_text(wif)
self.assertEqual(key.address(use_uncompressed=True), address)
for idx, address in enumerate(CHANGE_ADDRESSES):
subkey = wallet.subkey("%s/1" % idx)
calculated_address = subkey.address()
self.assertEqual(address, calculated_address)
wif = subkey.wif()
key = Key.from_text(wif)
self.assertEqual(key.address(use_uncompressed=True), address)
示例2: test_repr
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def test_repr(self):
key = Key(secret_exponent=273, netcode='XTN')
address = key.address()
pub_k = Key.from_text(address)
self.assertEqual(repr(pub_k), '<mhDVBkZBWLtJkpbszdjZRkH1o5RZxMwxca>')
wif = key.wif()
priv_k = Key.from_text(wif)
self.assertEqual(repr(priv_k), 'private_for <0264e1b1969f9102977691a40431b0b672055dcf31163897d996434420e6c95dc9>')
示例3: do_test
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def do_test(exp_hex, wif, c_wif, public_pair_sec, c_public_pair_sec, address_b58, c_address_b58):
secret_exponent = int(exp_hex, 16)
sec = h2b(public_pair_sec)
c_sec = h2b(c_public_pair_sec)
keys_wif = [
Key(secret_exponent=secret_exponent),
Key.from_text(wif),
Key.from_text(c_wif),
]
key_sec = Key.from_sec(sec)
key_sec_c = Key.from_sec(c_sec)
keys_sec = [key_sec, key_sec_c]
for key in keys_wif:
self.assertEqual(key.secret_exponent(), secret_exponent)
self.assertEqual(key.public_copy().secret_exponent(), None)
repr(key)
if key._prefer_uncompressed:
self.assertEqual(key.wif(), wif)
else:
self.assertEqual(key.wif(), c_wif)
self.assertEqual(key.wif(use_uncompressed=True), wif)
self.assertEqual(key.wif(use_uncompressed=False), c_wif)
for key in keys_wif + keys_sec:
if key._prefer_uncompressed:
self.assertEqual(key.sec(), sec)
else:
self.assertEqual(key.sec(), c_sec)
self.assertEqual(key.sec(use_uncompressed=True), sec)
self.assertEqual(key.sec(use_uncompressed=False), c_sec)
if key._prefer_uncompressed:
self.assertEqual(key.address(), address_b58)
else:
self.assertEqual(key.address(), c_address_b58)
self.assertEqual(key.address(use_uncompressed=False), c_address_b58)
self.assertEqual(key.address(use_uncompressed=True), address_b58)
key_pub = Key.from_text(address_b58, is_compressed=False)
key_pub_c = Key.from_text(c_address_b58, is_compressed=True)
self.assertEqual(key_pub.address(), address_b58)
self.assertEqual(key_pub.address(use_uncompressed=True), address_b58)
self.assertEqual(key_pub.address(use_uncompressed=False), None)
self.assertEqual(key_pub_c.address(), c_address_b58)
self.assertEqual(key_pub_c.address(use_uncompressed=True), None)
self.assertEqual(key_pub_c.address(use_uncompressed=False), c_address_b58)
示例4: __init__
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def __init__(self, mainnet, dashrpc):
self.dashrpc = dashrpc
self.mainnet = mainnet
self._init_state_dir(os.path.join(DASHVEND_DIR, 'state'))
self.key = Key.from_text(
mainnet and BIP32_MAINNET_SEED or BIP32_TESTNET_SEED)
self._init_next_address()
示例5: test_1
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def test_1(self):
wallet = ElectrumWallet(initial_key="00000000000000000000000000000001")
for idx, address in enumerate(RECEIVING_ADDRESSES):
subkey = wallet.subkey("%s/0" % idx)
calculated_address = subkey.address()
self.assertEqual(address, calculated_address)
wif = subkey.wif()
key = Key.from_text(wif)
self.assertEqual(key.address(use_uncompressed=True), address)
for idx, address in enumerate(CHANGE_ADDRESSES):
subkey = wallet.subkey("%s/1" % idx)
calculated_address = subkey.address()
self.assertEqual(address, calculated_address)
wif = subkey.wif()
key = Key.from_text(wif)
self.assertEqual(key.address(use_uncompressed=True), address)
示例6: getOrCreateAddress
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def getOrCreateAddress(self, subpath_number):
try:
return Address.objects.get(wallet=self, subpath_number=subpath_number)
except Address.DoesNotExist:
pass
new_address_full_path = self.path + [subpath_number]
new_address_full_path_str = '/'.join([str(i) for i in new_address_full_path])
# Create raw bitcoin address and key
key = Key.from_text(settings.MASTERWALLET_BIP32_KEY)
subkey = key.subkeys(new_address_full_path_str).next()
btc_address = subkey.address(use_uncompressed=False)
btc_private_key = subkey.wif(use_uncompressed=False)
# Make sure private key is stored to the database of bitcoind
rpc = AuthServiceProxy('http://' + settings.BITCOIN_RPC_USERNAME + ':' + settings.BITCOIN_RPC_PASSWORD + '@' + settings.BITCOIN_RPC_IP + ':' + str(settings.BITCOIN_RPC_PORT))
try:
rpc.importprivkey(btc_private_key, '', False)
except:
raise Exception('Unable to store Bitcoin address to Bitcoin node!')
# Create new Address and return it
new_address = Address(wallet=self, subpath_number=subpath_number, address=btc_address)
new_address.save()
return new_address
示例7: handle
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def handle(self, *args, **options):
rpc = AuthServiceProxy('http://' + settings.BITCOIN_RPC_USERNAME + ':' + settings.BITCOIN_RPC_PASSWORD + '@' + settings.BITCOIN_RPC_IP + ':' + str(settings.BITCOIN_RPC_PORT))
private_keys_imported = False
for address in Address.objects.all():
address_found = True
try:
rpc.dumpprivkey(address.address)
except JSONRPCException as e:
if e.code == -4:
# Address is not found
print 'Address ' + address.address + ' was not found. Importing it...'
# Do some key magic
new_address_full_path = address.wallet.path + [address.subpath_number]
new_address_full_path_str = '/'.join([str(i) for i in new_address_full_path])
key = Key.from_text(settings.MASTERWALLET_BIP32_KEY)
subkey = key.subkeys(new_address_full_path_str).next()
# Check address and form the private key
btc_address = subkey.address(use_uncompressed=False)
assert btc_address == address.address
btc_private_key = subkey.wif(use_uncompressed=False)
# Do the importing
rpc.importprivkey(btc_private_key, '', False)
private_keys_imported = True
if private_keys_imported:
print 'Note! Private keys were added, but they were not scanned! Please restart bitcoin with -rescan option!'
示例8: test_master_public_and_private
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def test_master_public_and_private(self):
# these addresses were generated by hand using electrum with a master public key
# corresponding to secret exponent 1
RECEIVING_ADDRESSES = [
"1AYPdHLna6bKFUbeXoAEVbaXUxifUwCMay",
"13UeuWJba5epizAKyfCfiFKY5Kbxfdxe7B",
"19f6KJUTL5AGBRvLBGiL6Zpcx53QA7zaKT",
"1Cm33VuSkoUETwx5nsF1wgmGqYwJZxpZdY",
"14Z6ErkETixQMUeivsYbrdoUFns2J1iSct",
]
CHANGE_ADDRESSES = [
"1JVYsmjrqSy1BKvo1gYpNjX7AYea74nQYe",
"1Cc7itfQaDqZK3vHYphFsySujQjBNba8mw",
"15wrXvrAnyv3usGeQRohnnZ8tz9XAekbag",
"1MnWCEjE5YiZpZrkP8HcXEeDqwg43RxLwu",
"1Fgyp3PUx9AAg8yJe1zGXHP5dVC6i1tXbs",
"12XTLd4u9jeqw4egLAUhoKLxHARCdKWkty",
]
k = Key(secret_exponent=1)
master_public_key = k.sec(use_uncompressed=True)[1:]
wallet = ElectrumWallet(master_public_key=master_public_key)
for idx, address in enumerate(RECEIVING_ADDRESSES):
subkey = wallet.subkey("%s/0" % idx)
calculated_address = subkey.address()
self.assertEqual(address, calculated_address)
for idx, address in enumerate(CHANGE_ADDRESSES):
subkey = wallet.subkey("%s/1" % idx)
calculated_address = subkey.address()
self.assertEqual(address, calculated_address)
wallet = ElectrumWallet(master_private_key=1)
for idx, address in enumerate(RECEIVING_ADDRESSES):
subkey = wallet.subkey("%s/0" % idx)
calculated_address = subkey.address()
self.assertEqual(address, calculated_address)
wif = subkey.wif()
key = Key.from_text(wif)
self.assertEqual(key.address(use_uncompressed=True), address)
for idx, address in enumerate(CHANGE_ADDRESSES):
subkey = wallet.subkey("%s/1" % idx)
calculated_address = subkey.address()
self.assertEqual(address, calculated_address)
wif = subkey.wif()
key = Key.from_text(wif)
self.assertEqual(key.address(use_uncompressed=True), address)
示例9: mk_notif_tx
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def mk_notif_tx(my_pcode_node, payee_pcode_node, wallet_nodes, change_nodes, fee):
amount = Decimal('0.00000600')
payee_notif_node = payee_pcode_node.subkey_for_path("0/0")
txio_tuple = create_tx_io(amount, payee_notif_node.address(), wallet_nodes, change_nodes, fee)
first_exp = Key.from_text(txio_tuple[3][0]).secret_exponent()
my_masked_pcode = node_to_masked_pcode(my_pcode_node, payee_notif_node, first_exp)
op_return_script = pay_to.ScriptNulldata(my_masked_pcode)
op_return_txout = TxOut(0, op_return_script.script())
txio_tuple[1].append(op_return_txout)
return create_signed_tx(txio_tuple)
示例10: key_found
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def key_found(arg, payables, key_iters):
try:
key = Key.from_text(arg)
# TODO: check network
if key.wif() is None:
payables.append((key.address(), 0))
return True
key_iters.append(iter([key.wif()]))
return True
except Exception:
pass
return False
示例11: parse_prefixes
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def parse_prefixes(item, PREFIX_TRANSFORMS):
for k, f in PREFIX_TRANSFORMS:
if item.startswith(k):
try:
return f(item[len(k):])
except Exception:
pass
try:
return Key.from_text(item)
except encoding.EncodingError:
pass
return None
示例12: test_sign_bitcoind_partially_signed_2_of_2
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def test_sign_bitcoind_partially_signed_2_of_2(self):
# Finish signing a 2 of 2 transaction, that already has one signature signed by bitcoind
# This tx can be found on testnet3 blockchain, txid: 9618820d7037d2f32db798c92665231cd4599326f5bd99cb59d0b723be2a13a2
raw_script = "522103e33b41f5ed67a77d4c4c54b3e946bd30d15b8f66e42cb29fde059c16885116552102b92cb20a9fb1eb9656a74eeb7387636cf64cdf502ff50511830328c1b479986452ae"
p2sh_lookup = build_p2sh_lookup([h2b(raw_script)])
partially_signed_raw_tx = "010000000196238f11a5fd3ceef4efd5a186a7e6b9217d900418e72aca917cd6a6e634e74100000000910047304402201b41b471d9dd93cf97eed7cfc39a5767a546f6bfbf3e0c91ff9ad23ab9770f1f02205ce565666271d055be1f25a7e52e34cbf659f6c70770ff59bd783a6fcd1be3dd0147522103e33b41f5ed67a77d4c4c54b3e946bd30d15b8f66e42cb29fde059c16885116552102b92cb20a9fb1eb9656a74eeb7387636cf64cdf502ff50511830328c1b479986452aeffffffff01a0bb0d00000000001976a9143b3beefd6f7802fa8706983a76a51467bfa36f8b88ac00000000"
tx = Tx.from_hex(partially_signed_raw_tx)
tx_out = TxOut(1000000, h2b("a914a10dfa21ee8c33b028b92562f6fe04e60563d3c087"))
tx.set_unspents([tx_out])
key = Key.from_text("cThRBRu2jAeshWL3sH3qbqdq9f4jDiDbd1SVz4qjTZD2xL1pdbsx")
hash160_lookup = build_hash160_lookup([key.secret_exponent()])
self.assertEqual(tx.bad_signature_count(), 1)
tx.sign(hash160_lookup=hash160_lookup, p2sh_lookup=p2sh_lookup)
self.assertEqual(tx.bad_signature_count(), 0)
self.assertEqual(tx.id(), "9618820d7037d2f32db798c92665231cd4599326f5bd99cb59d0b723be2a13a2")
示例13: generate
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def generate(context, request, api_version,
xpub=None, start=0, count=1):
if not xpub:
raise MyBitsException('Parameter `xpub` missing')
start = int(start)
count = int(count)
if not 0 < count <= 20:
raise MyBitsException('Parameter `count` must be between 1 and 20')
try:
mpk = Key.from_text(xpub)
except EncodingError:
raise MyBitsException('Invalid `xpub`')
return [str(key.address()) for key in mpk.subkeys("0/{}-{}".format(start, start+count))]
示例14: answer
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
def answer(private_key, expected_address):
private_key_digits = []
for d in private_key:
private_key_digits.append(BASE58_LOOKUP[d])
#print(private_key)
#print(private_key_digits)
prefix = private_key_digits[0]
suffix = private_key_digits[1:]
test_suffix = tuple(suffix)
if not private_key_suffix_is_valid(test_suffix):
test_suffix = find_winner(tuple(suffix))
print('WINNER!')
private_key = b2a_base58(suffix_to_bytes(test_suffix))
print(private_key)
return Key.from_text(private_key).address()
示例15: main
# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import from_text [as 别名]
#.........这里部分代码省略.........
key_iters = []
TX_ID_RE = re.compile(r"^[0-9a-fA-F]{64}$")
# there are a few warnings we might optionally print out, but only if
# they are relevant. We don't want to print them out multiple times, so we
# collect them here and print them at the end if they ever kick in.
warning_tx_cache = None
warning_get_tx = None
warning_spendables = None
if args.private_key_file:
wif_re = re.compile(r"[1-9a-km-zA-LMNP-Z]{51,111}")
# address_re = re.compile(r"[1-9a-kmnp-zA-KMNP-Z]{27-31}")
for f in args.private_key_file:
if f.name.endswith(".gpg"):
gpg_args = ["gpg", "-d"]
if args.gpg_argument:
gpg_args.extend(args.gpg_argument.split())
gpg_args.append(f.name)
popen = subprocess.Popen(gpg_args, stdout=subprocess.PIPE)
f = popen.stdout
for line in f.readlines():
# decode
if isinstance(line, bytes):
line = line.decode("utf8")
# look for WIFs
possible_keys = wif_re.findall(line)
def make_key(x):
try:
return Key.from_text(x)
except Exception:
return None
keys = [make_key(x) for x in possible_keys]
for key in keys:
if key:
key_iters.append((k.wif() for k in key.subkeys("")))
# if len(keys) == 1 and key.hierarchical_wallet() is None:
# # we have exactly 1 WIF. Let's look for an address
# potential_addresses = address_re.findall(line)
# we create the tx_db lazily
tx_db = None
for arg in args.argument:
# hex transaction id
if TX_ID_RE.match(arg):
if tx_db is None:
warning_tx_cache = message_about_tx_cache_env()
warning_get_tx = message_about_get_tx_env()
tx_db = get_tx_db()
tx = tx_db.get(h2b_rev(arg))
if not tx:
for m in [warning_tx_cache, warning_get_tx, warning_spendables]:
if m:
print("warning: %s" % m, file=sys.stderr)
parser.error("can't find Tx with id %s" % arg)
txs.append(tx)
continue