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


Python key.Key类代码示例

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


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

示例1: _build_signature

def _build_signature(key, certreqinfo, network):
    secret_exponent = encoding.to_long(256, encoding.byte_to_int, key[0][1].asOctets())[0]
    coin  = Key(secret_exponent=secret_exponent, netcode=network)
    print "building signature for %s address: %s" % (network, coin.address())
    pubkeybitstring = (key[0].getComponentByPosition(2), key[0].getComponentByPosition(3))
    certreqinfoder = encoder.encode(certreqinfo)
    hashvalue = SHA256.new(certreqinfoder)
    dgst = hashvalue.digest()
    dgstaslong = encoding.to_long(256, encoding.byte_to_int, dgst)[0]
    order2 = pycoin.ecdsa.generator_secp256k1.order()
    ## random sign
    generator = pycoin.ecdsa.generator_secp256k1
    rawsig2 = randomsign(generator, secret_exponent, dgstaslong)
    ## deterministic sign
    ##rawsig2 = pycoin.ecdsa.sign(pycoin.ecdsa.generator_secp256k1, secret_exponent, dgstaslong)
    r2, s2 = rawsig2
    print "signature: r: %x s: %x" % (r2, s2)
    if not pycoin.ecdsa.verify(generator, coin.public_pair(), dgstaslong, rawsig2):
        raise SignatureVerifyException("Generated signature r: %x s: %x does not verify against public key %s" % (r2, s2, public_pair))
    signature = ECDSASigValue()
    signature.setComponentByName('r', r2)
    signature.setComponentByName('s', s2)
    dersig = encoder.encode(signature)
    signaturevalue = "'{0}'H".format(binascii.hexlify(dersig))
    bitstring = univ.BitString( value=signaturevalue )
    return rfc2314.Signature( bitstring )
开发者ID:1-Hash,项目名称:UTXOC,代码行数:26,代码来源:utxocsr.py

示例2: test_initial_key

 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)
开发者ID:mperklin,项目名称:pycoin,代码行数:28,代码来源:electrum_test.py

示例3: vanitygen

def vanitygen(s):
    s = '1' + s.lower()
    l = len(s)
    while True:
        r = int.from_bytes(os.urandom(32), 'big')
        k = Key(secret_exponent=r)
        if k.address()[:l] == s:
            print('Address:', k.address())
            print('WIF:'. k.wif())
开发者ID:tortxof,项目名称:python-sandbox,代码行数:9,代码来源:btc_vanitygen.py

示例4: test_script_type_pay_to_address

 def test_script_type_pay_to_address(self):
     for se in range(1, 100):
         key = Key(secret_exponent=se)
         for b in [True, False]:
             addr = key.address(use_uncompressed=b)
             st = script_obj_from_address(addr)
             self.assertEqual(st.address(), addr)
             sc = st.script()
             st = script_obj_from_script(sc)
             self.assertEqual(st.address(), addr)
开发者ID:Bluejudy,项目名称:pycoin,代码行数:10,代码来源:pay_to_test.py

示例5: test_repr

    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,代码行数:10,代码来源:key_validate_test.py

示例6: test_script_type_pay_to_public_pair

 def test_script_type_pay_to_public_pair(self):
     for se in range(1, 100):
         key = Key(secret_exponent=se)
         for b in [True, False]:
             st = ScriptPayToPublicKey.from_key(key, use_uncompressed=b)
             addr = key.address(use_uncompressed=b)
             self.assertEqual(st.address(), addr)
             sc = st.script()
             st = script_obj_from_script(sc)
             self.assertEqual(st.address(), addr)
开发者ID:Bluejudy,项目名称:pycoin,代码行数:10,代码来源:pay_to_test.py

示例7: test_repr

    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,代码行数:13,代码来源:bip32_test.py

示例8: test_solve_pay_to_public_pair

 def test_solve_pay_to_public_pair(self):
     for se in range(1, 10):
         key = Key(secret_exponent=se)
         for b in [True, False]:
             addr = key.address(use_uncompressed=b)
             st = ScriptPayToPublicKey.from_key(key, use_uncompressed=b)
             self.assertEqual(st.address(), addr)
             hl = build_hash160_lookup([se])
             sv = 100
             solution = st.solve(hash160_lookup=hl, sign_value=sv, signature_type=SIGHASH_ALL)
             sc = st.script()
             st = script_obj_from_script(sc)
             self.assertEqual(st.address(), addr)
开发者ID:Bluejudy,项目名称:pycoin,代码行数:13,代码来源:pay_to_test.py

示例9: test_solve_pay_to_address

 def test_solve_pay_to_address(self):
     for se in range(1, 10):
         key = Key(secret_exponent=se)
         for b in [True, False]:
             addr = key.address(use_uncompressed=b)
             st = script_obj_from_address(addr)
             self.assertEqual(st.address(), addr)
             hl = build_hash160_lookup([se])
             sv = 100
             solution = st.solve(hash160_lookup=hl, signature_for_hash_type_f=const_f(sv), signature_type=SIGHASH_ALL)
             sc = st.script()
             st = script_obj_from_script(sc)
             self.assertEqual(st.address(), addr)
开发者ID:Stevengu999,项目名称:pycoin,代码行数:13,代码来源:pay_to_test.py

示例10: test_segwit_create_tx

    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,代码行数:27,代码来源:segwit_test.py

示例11: getOrCreateAddress

    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
开发者ID:bitcredit-currency,项目名称:django_bitcoin_webwallet,代码行数:28,代码来源:models.py

示例12: __init__

 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()
开发者ID:moocowmoo,项目名称:dashvend,代码行数:7,代码来源:addresses.py

示例13: handle

    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!'
开发者ID:bitcredit-currency,项目名称:django_bitcoin_webwallet,代码行数:32,代码来源:check_addresses.py

示例14: test_1

 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)
开发者ID:Bluejudy,项目名称:pycoin,代码行数:16,代码来源:electrum_test.py

示例15: test_master_public_and_private

    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)
开发者ID:mperklin,项目名称:pycoin,代码行数:46,代码来源:electrum_test.py


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