当前位置: 首页>>代码示例>>Python>>正文


Python Key.wif方法代码示例

本文整理汇总了Python中pycoin.key.Key.wif方法的典型用法代码示例。如果您正苦于以下问题:Python Key.wif方法的具体用法?Python Key.wif怎么用?Python Key.wif使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycoin.key.Key的用法示例。


在下文中一共展示了Key.wif方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_segwit_create_tx

# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import wif [as 别名]
    def test_segwit_create_tx(self):
        from pycoin.tx.tx_utils import create_tx, sign_tx
        from pycoin.tx.Spendable import Spendable
        from pycoin.tx.pay_to.ScriptPayToAddress import ScriptPayToAddress
        from pycoin.tx.pay_to.ScriptPayToAddressWit import ScriptPayToAddressWit
        from pycoin.tx.pay_to.ScriptPayToScriptWit import ScriptPayToScriptWit
        from pycoin.ui import address_for_pay_to_script_wit, script_obj_from_address
        key1 = Key(1)
        coin_value = 5000000
        script = ScriptPayToAddressWit(b'\0', key1.hash160()).script()
        tx_hash = b'\ee' * 32
        tx_out_index = 0
        spendable = Spendable(coin_value, script, tx_hash, tx_out_index)
        key2 = Key(2)
        tx = create_tx([spendable], [(key2.address(), coin_value)])
        self.check_unsigned(tx)
        sign_tx(tx, [key1.wif()])
        self.check_signed(tx)
        self.assertEqual(len(tx.txs_in[0].witness), 2)

        s1 = ScriptPayToAddress(key1.hash160()).script()
        address = address_for_pay_to_script_wit(s1)
        spendable.script = script_obj_from_address(address).script()
        tx = create_tx([spendable], [(key2.address(), coin_value)])
        self.check_unsigned(tx)
        sign_tx(tx, [key1.wif()], p2sh_lookup=build_p2sh_lookup([s1]))
        self.check_signed(tx)
开发者ID:Stevengu999,项目名称:pycoin,代码行数:29,代码来源:segwit_test.py

示例2: test_repr

# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import wif [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>')
开发者ID:Stevengu999,项目名称:pycoin,代码行数:12,代码来源:key_validate_test.py

示例3: test_repr

# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import wif [as 别名]
    def test_repr(self):
        from pycoin.key import Key
        netcode = 'XTN'
        key = Key(secret_exponent=273, netcode=netcode)
        wallet = BIP32Node.from_master_secret(bytes(key.wif().encode('ascii')), netcode)

        address = wallet.address()
        pub_k = wallet.from_text(address)
        self.assertEqual(repr(pub_k),  '<myb5gZNXePNf2E2ksrjnHRFCwyuvt7oEay>')

        wif = wallet.wif()
        priv_k = wallet.from_text(wif)
        self.assertEqual(repr(priv_k), 'private_for <03ad094b1dc9fdce5d3648ca359b4e210a89d049532fdd39d9ccdd8ca393ac82f4>')
开发者ID:DomSteil,项目名称:pycoin,代码行数:15,代码来源:bip32_test.py

示例4: _gen

# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import wif [as 别名]
	def _gen (self):
		logger.debug ('Generating entropy for new wallet...')

		# Generate entropy
		entropy = bytearray()
		try:
			entropy.extend(open("/dev/random", "rb").read(64))
		except Exception:
			print("warning: can't use /dev/random as entropy source")
		entropy = bytes(entropy)

		if len(entropy) < 64:
			raise OSError("can't find sources of entropy")

		secret_exponent = int(binascii.hexlify (entropy)[0:32], 16)
		wif = secret_exponent_to_wif(secret_exponent, compressed=True, wif_prefix=wif_prefix_for_netcode (self.chain))
		key = Key (secret_exponent=secret_exponent, netcode=self.chain)
		return (str (key.address ()), str (key.wif ()))
开发者ID:contractvm,项目名称:libcontractvm,代码行数:20,代码来源:Wallet.py

示例5: test_is_wif_valid

# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import wif [as 别名]
    def test_is_wif_valid(self):
        WIFS = ["KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn",
                "5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf",
                "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU74NMTptX4",
                "5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAvUcVfH"]

        for wif in WIFS:
            self.assertEqual(is_wif_valid(wif), "BTC")
            a = wif[:-1] + chr(ord(wif[-1])+1)
            self.assertEqual(is_wif_valid(a), None)

        for netcode in NETWORK_NAMES:
            for se in range(1, 10):
                key = Key(secret_exponent=se, netcode=netcode)
                for tv in [True, False]:
                    wif = key.wif(use_uncompressed=tv)
                    self.assertEqual(is_wif_valid(wif, allowable_netcodes=[netcode]), netcode)
                    a = wif[:-1] + chr(ord(wif[-1])+1)
                    self.assertEqual(is_wif_valid(a, allowable_netcodes=[netcode]), None)
开发者ID:Fiada,项目名称:pycoin,代码行数:21,代码来源:key_validate_test.py

示例6: secret_to_address

# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import wif [as 别名]
def secret_to_address(secret_exponent):
    k = Key(secret_exponent=secret_exponent)
    addr = k.address(use_uncompressed=True)
    caddr = k.address()
    wif = k.wif(use_uncompressed=True)
    return secret_exponent, wif, addr, caddr
开发者ID:billy8407,项目名称:bitcoin-privatekey-db,代码行数:8,代码来源:server.py

示例7: main

# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import wif [as 别名]
def main():
    parser = argparse.ArgumentParser(
        description='ECkey2coin.py by [email protected] for UTXO based Certificates UTXOC.',
        epilog='Known networks codes:\n  ' \
                + ', '.join(['%s (%s)'%(i, full_network_name_for_netcode(i)) for i in NETWORK_NAMES])
    )
    parser.add_argument('-k', '--key', required=False, type=argparse.FileType('r'), help='The EC private key in PEM format')
    parser.add_argument('-q', '--qrfilename', required=False, help='QR code output filename')
    parser.add_argument('-n', "--network", help='specify network (default: BTC = Bitcoin)',
                                default='BTC', choices=NETWORK_NAMES)
    args = parser.parse_args()
    network = args.network
    inputprivatekey = ''
    if args.key:
        keyfile = args.key        
        while True:
            line = keyfile.readline().strip()
            if not line: break
            inputprivatekey += line + '\n'
        print 'Loaded EC Key from %s' % keyfile
    else:    
        print ('Please enter EC KEY in pem format:')
        inputprivatekey  = ''
        while True:
            line = raw_input().strip()
            if not line: break
            inputprivatekey += line + '\n'
    if not args.qrfilename:
        qrfilename = raw_input("Please enter qrcode output filename: ")
    else:
        qrfilename = args.qrfilename
    pkey = decoder.decode(read_pem(inputprivatekey), asn1Spec=ECPrivateKey())
    print 'Key loaded'
    if not isValidECKey(pkey[0]):
        print "EC Key Supplied cannot be used"
        exit
    print "Key Validated OK"
    inputkey = encoding.to_long(256, pycoin.encoding.byte_to_int, pkey[0][1].asOctets())[0]
    if inputkey:
        key = Key(secret_exponent=inputkey, netcode=network)
        btcsecret = key.secret_exponent()
        btcpublic = key.public_pair()
        hash160_c = key.hash160(use_uncompressed=False)
        hash160_u = key.hash160(use_uncompressed=True)
        qrimg = qrcode.QRCode (
            version=1,
            error_correction=qrcode.constants.ERROR_CORRECT_L,
            box_size=10,
            border=4,
        )
        qrimg.add_data(key.address(use_uncompressed=False))
        qrimg.make(fit=True)
        img = qrimg.make_image()
        img.save(qrfilename)
    print"----------------- BEGIN EC PRIVATE KEYS -----------------"
    print "Secret:     %d" % btcsecret
    print "Secret hex: %x" % btcsecret
    print "wif:        %s" % key.wif(use_uncompressed=False)
    print "----------------- END EC PRIVATE KEYS -----------------------------"
    print "----------------- BEGIN PUBLIC KEY -----------------------------"
    print "Public X: %d" % btcpublic[0]
    print "Public Y: %d" % btcpublic[1]
    print "hash160 uncompressed: %s" % b2h(hash160_u)
    print "Sec: (uncompressed): %s" % b2h(key.sec(use_uncompressed=True))
    print "%s address: %s (uncompressed)" % (key._netcode, key.address(use_uncompressed=True))
    print "Public X (hex): %x" % btcpublic[0]
    print "Public Y (hex): %x" % btcpublic[1]
    print "Sec: %s" % b2h(key.sec(use_uncompressed=False))
    print "hash160 compressed: %s" % b2h(hash160_c)
    print "----------------- END PUBLIC KEYS -----------------------------"
    print "------------------ BEGIN %s ADDRESSES -------------------------" % key._netcode
    print "%s address: %s" % (key._netcode, key.address(use_uncompressed=False))
    print "------------------ END %s ADDRESSES -------------------------" % key._netcode
开发者ID:1-Hash,项目名称:UTXOC,代码行数:75,代码来源:eckey2coin.py


注:本文中的pycoin.key.Key.wif方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。