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


Python BIP32Node.BIP32Node类代码示例

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


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

示例1: test_refill_main_wallet

def test_refill_main_wallet(spool_regtest, rpconn):
    src_wallet_passowrd = uuid1().hex.encode('utf-8')
    src_wallet = BIP32Node.from_master_secret(src_wallet_passowrd,
                                              netcode='XTN')
    dest_wallet_passowrd = uuid1().hex.encode('utf-8')
    dest_wallet = BIP32Node.from_master_secret(dest_wallet_passowrd,
                                               netcode='XTN')
    src_address = src_wallet.bitcoin_address()
    dest_address = dest_wallet.bitcoin_address()
    rpconn.importaddress(src_address)
    rpconn.importaddress(dest_address)
    rpconn.sendtoaddress(src_address, 1)
    rpconn.generate(1)
    txid = spool_regtest.refill_main_wallet(
        ('', src_address),
        dest_address,
        1,
        1,
        src_wallet_passowrd,
        min_confirmations=1,
    )
    rpconn.generate(1)
    raw_txid = rpconn.getrawtransaction(txid)
    raw_tx = rpconn.decoderawtransaction(raw_txid)
    values = (vout['value'] * 100000000 for vout in raw_tx['vout'] if
              vout['scriptPubKey']['addresses'].pop() == dest_address)
    assert spool_regtest.FEE in values
    assert spool_regtest.TOKEN in values
    assert (rpconn.getreceivedbyaddress(dest_address) * 100000000 ==
            spool_regtest.FEE + spool_regtest.TOKEN)
开发者ID:sbellem,项目名称:pyspool,代码行数:30,代码来源:test_spool.py

示例2: test_streams

 def test_streams(self):
     m0 = BIP32Node.from_master_secret("foo bar baz".encode("utf8"))
     pm0 = m0.public_copy()
     self.assertEqual(m0.wallet_key(), pm0.wallet_key())
     m1 = m0.subkey()
     pm1 = pm0.subkey()
     for i in range(4):
         m = m1.subkey(i=i)
         pm = pm1.subkey(i=i)
         self.assertEqual(m.wallet_key(), pm.wallet_key())
         self.assertEqual(m.bitcoin_address(), pm.bitcoin_address())
         m2 = BIP32Node.from_wallet_key(m.wallet_key(as_private=True))
         m3 = m2.public_copy()
         self.assertEqual(m.wallet_key(as_private=True), m2.wallet_key(as_private=True))
         self.assertEqual(m.wallet_key(), m3.wallet_key())
         print(m.wallet_key(as_private=True))
         for j in range(2):
             k = m.subkey(i=j)
             k2 = BIP32Node.from_wallet_key(k.wallet_key(as_private=True))
             k3 = BIP32Node.from_wallet_key(k.wallet_key())
             k4 = k.public_copy()
             self.assertEqual(k.wallet_key(as_private=True), k2.wallet_key(as_private=True))
             self.assertEqual(k.wallet_key(), k2.wallet_key())
             self.assertEqual(k.wallet_key(), k3.wallet_key())
             self.assertEqual(k.wallet_key(), k4.wallet_key())
             print("   %s %s" % (k.bitcoin_address(), k.wif()))
开发者ID:DomSteil,项目名称:pycoin,代码行数:26,代码来源:bip32_test.py

示例3: sign_transaction

    def sign_transaction(self, tx, master_password, path=''):
        """
        Args:
            tx: hex transaction to sign
            master_password: master password for BIP32 wallets. Can be either a
                master_secret or a wif
            path (Optional[str]): optional path to the leaf address of the
                BIP32 wallet. This allows us to retrieve private key for the
                leaf address if one was used to construct the transaction.
        Returns:
            signed transaction

        .. note:: Only BIP32 hierarchical deterministic wallets are currently
            supported.

        """
        netcode = 'XTN' if self.testnet else 'BTC'

        # TODO review
        # check if its a wif
        try:
            BIP32Node.from_text(master_password)
            return bitcoin.signall(tx, master_password)
        except (AttributeError, EncodingError):
            # if its not get the wif from the master secret
            return bitcoin.signall(tx, BIP32Node.from_master_secret(master_password, netcode=netcode).subkey_for_path(path).wif())
开发者ID:amiromayer,项目名称:transactions,代码行数:26,代码来源:transactions.py

示例4: sign_transaction

    def sign_transaction(self, tx, master_password, path=''):
        # master_password can be either a master_secret or a wif
        netcode = 'XTN' if self.testnet else 'BTC'

        # check if its a wif
        try:
            BIP32Node.from_text(master_password)
            return pybitcointools.signall(tx, master_password)
        except EncodingError:
            # if its not get the wif from the master secret
            return pybitcointools.signall(tx, BIP32Node.from_master_secret(master_password, netcode=netcode).subkey_for_path(path).wif())
开发者ID:jaksco,项目名称:transactions,代码行数:11,代码来源:transactions.py

示例5: test_vector_1

    def test_vector_1(self):
        master = BIP32Node.from_master_secret(h2b("000102030405060708090a0b0c0d0e0f"))
        self.assertEqual(master.wallet_key(as_private=True), "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi")
        self.assertEqual(master.bitcoin_address(), "15mKKb2eos1hWa6tisdPwwDC1a5J1y9nma")
        self.assertEqual(master.wif(), "L52XzL2cMkHxqxBXRyEpnPQZGUs3uKiL3R11XbAdHigRzDozKZeW")

        self.assertEqual(master.wallet_key(), "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8")

        m0p = master.subkey(is_hardened=True)
        self.assertEqual(m0p.wallet_key(), "xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw")
        self.assertEqual(m0p.wallet_key(as_private=True), "xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7")
        self.assertEqual(master.subkey_for_path("0p").wallet_key(), m0p.wallet_key())

        pub_mp0 = master.subkey(is_hardened=True, as_private=False)
        self.assertEqual(pub_mp0.wallet_key(), m0p.wallet_key())
        self.assertEqual(master.subkey_for_path("0p.pub").wallet_key(), pub_mp0.wallet_key())

        m0p1 = m0p.subkey(i=1)
        self.assertEqual(m0p1.wallet_key(), "xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ")
        self.assertEqual(m0p1.wallet_key(as_private=True), "xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs")
        self.assertEqual(master.subkey_for_path("0p/1").wallet_key(), m0p1.wallet_key())

        pub_m0p1 = m0p.subkey(i=1, as_private=False)
        self.assertEqual(pub_m0p1.wallet_key(), m0p1.wallet_key())
        self.assertEqual(master.subkey_for_path("0p/1.pub").wallet_key(), pub_m0p1.wallet_key())

        m0p1_1_2p = m0p1.subkey(i=2, is_hardened=True)
        self.assertEqual(m0p1_1_2p.wallet_key(), "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5")
        self.assertEqual(m0p1_1_2p.wallet_key(as_private=True), "xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM")
        self.assertEqual(master.subkey_for_path("0p/1/2p").wallet_key(), m0p1_1_2p.wallet_key())

        pub_m0p1_1_2p = m0p1.subkey(i=2, as_private=False, is_hardened=True)
        self.assertEqual(pub_m0p1_1_2p.wallet_key(), m0p1_1_2p.wallet_key())
        self.assertEqual(master.subkey_for_path("0p/1/2p.pub").wallet_key(), pub_m0p1_1_2p.wallet_key())

        m0p1_1_2p_2 = m0p1_1_2p.subkey(i=2)
        self.assertEqual(m0p1_1_2p_2.wallet_key(), "xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV")
        self.assertEqual(m0p1_1_2p_2.wallet_key(as_private=True), "xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334")
        self.assertEqual(master.subkey_for_path("0p/1/2p/2").wallet_key(), m0p1_1_2p_2.wallet_key())

        pub_m0p1_1_2p_2 = m0p1_1_2p.subkey(i=2, as_private=False)
        self.assertEqual(pub_m0p1_1_2p_2.wallet_key(), m0p1_1_2p_2.wallet_key())
        self.assertEqual(master.subkey_for_path("0p/1/2p/2.pub").wallet_key(), pub_m0p1_1_2p_2.wallet_key())

        m0p1_1_2p_2_1000000000 = m0p1_1_2p_2.subkey(i=1000000000)
        self.assertEqual(m0p1_1_2p_2_1000000000.wallet_key(), "xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy")
        self.assertEqual(m0p1_1_2p_2_1000000000.wallet_key(as_private=True), "xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76")
        self.assertEqual(master.subkey_for_path("0p/1/2p/2/1000000000").wallet_key(), m0p1_1_2p_2_1000000000.wallet_key())

        pub_m0p1_1_2p_2_1000000000 = m0p1_1_2p_2.subkey(i=1000000000, as_private=False)
        self.assertEqual(pub_m0p1_1_2p_2_1000000000.wallet_key(), m0p1_1_2p_2_1000000000.wallet_key())
        self.assertEqual(master.subkey_for_path("0p/1/2p/2/1000000000.pub").wallet_key(), pub_m0p1_1_2p_2_1000000000.wallet_key())
开发者ID:DomSteil,项目名称:pycoin,代码行数:52,代码来源:bip32_test.py

示例6: treegen

 def treegen(value, entropy=False):
     if entropy:
         # this method also takes a netcode parameter, but we don't care
         # what network pycoin thinks this node is, because we only use it
         # for key derivation.
         return BIP32Node.from_master_secret(unhexlify(value))
     else:
         # this method will infer a network from the header bytes. We
         # don't care right now for the same reason as above, but we will
         # if Gem's API stops returning 'xpub' as the pubkey header bytes
         # because if pycoin doesn't recognize a header it will error.
         return BIP32Node.from_hwif(value)
开发者ID:GemHQ,项目名称:coinop-py,代码行数:12,代码来源:multiwallet.py

示例7: test_refill_fuel

def test_refill_fuel(spool_regtest, rpconn):
    src_wallet_passowrd = uuid1().hex.encode('utf-8')
    src_wallet = BIP32Node.from_master_secret(src_wallet_passowrd,
                                              netcode='XTN')
    dest_wallet_passowrd = uuid1().hex.encode('utf-8')
    dest_wallet = BIP32Node.from_master_secret(dest_wallet_passowrd,
                                               netcode='XTN')
    src_address = src_wallet.bitcoin_address()
    dest_address = dest_wallet.bitcoin_address()
    rpconn.importaddress(src_address)
    rpconn.importaddress(dest_address)
    rpconn.sendtoaddress(src_address, spool_regtest.FEE/100000000)
    rpconn.sendtoaddress(src_address, spool_regtest.FEE/100000000)
    rpconn.sendtoaddress(
        src_address, spool_regtest.TOKEN/100000000)
    rpconn.generate(1)
    txid = spool_regtest.refill(
        ('', src_address),
        dest_address,
        1,
        1,
        src_wallet_passowrd,
        min_confirmations=1,
    )
    rpconn.generate(1)
    raw_txid = rpconn.getrawtransaction(txid)
    raw_tx = rpconn.decoderawtransaction(raw_txid)
    values = (vout['value'] * 100000000 for vout in raw_tx['vout'] if
              vout['scriptPubKey']['addresses'].pop() == dest_address)
    values = []
    asm = None
    for vout in raw_tx['vout']:
        try:
            addr = vout['scriptPubKey']['addresses'].pop()
        except KeyError:
            asm = vout['scriptPubKey']['asm']
        else:
            if addr == dest_address:
                values.append(vout['value'] * 100000000)

    assert spool_regtest.FEE in values
    assert spool_regtest.TOKEN in values
    assert asm.split(' ')[0] == 'OP_RETURN'
    assert asm.split(' ')[1] == '4153435249424553504f4f4c30314655454c'
    assert spool_regtest.FEE in values
    assert spool_regtest.TOKEN in values
    assert (rpconn.getreceivedbyaddress(dest_address) * 100000000 ==
            spool_regtest.FEE + spool_regtest.TOKEN)
开发者ID:sbellem,项目名称:pyspool,代码行数:48,代码来源:test_spool.py

示例8: create_key

def create_key(asset, netcode="BTC"):
    secure_random_data = os.urandom(32)
    key = BIP32Node.from_master_secret(secure_random_data, netcode=netcode)
    return {
        "asset": asset, "pubkey": b2h(key.sec()),
        "wif": key.wif(), "address": key.address(),
    }
开发者ID:StorjRND,项目名称:picopayments,代码行数:7,代码来源:lib.py

示例9: test_create_sign_push_transaction

def test_create_sign_push_transaction(transactions, rpcconn):
    alice = BIP32Node.from_master_secret(b"alice-secret", netcode="XTN").bitcoin_address()
    bob = BIP32Node.from_master_secret(b"bob-secret", netcode="XTN").bitcoin_address()
    rpcconn.importaddress(alice)
    rpcconn.importaddress(bob)
    rpcconn.sendtoaddress(alice, 3)
    rpcconn.generate(1)
    raw_tx = transactions.create(alice, (bob, 200000000), min_confirmations=1)
    assert raw_tx
    signed_tx = transactions.sign(raw_tx, b"alice-secret")
    assert signed_tx
    bob_before = rpcconn.getreceivedbyaddress(bob)
    pushed_tx = transactions.push(signed_tx)
    assert pushed_tx
    rpcconn.generate(1)  # pack the transaction into a block
    assert rpcconn.getreceivedbyaddress(bob) - bob_before == 2
开发者ID:cjauvin,项目名称:transactions,代码行数:16,代码来源:test_transactions.py

示例10: from_text

    def from_text(class_, text, is_compressed=True):
        """
        This function will accept a BIP0032 wallet string, a WIF, or a bitcoin address.

        The "is_compressed" parameter is ignored unless a public address is passed in.
        """

        data = a2b_hashed_base58(text)
        netcode, key_type = netcode_and_type_for_data(data)
        data = data[1:]

        if key_type in ("pub32", "prv32"):
            # TODO: fix this... it doesn't belong here
            from pycoin.key.BIP32Node import BIP32Node
            return BIP32Node.from_wallet_key(text)

        if key_type == 'wif':
            is_compressed = (len(data) > 32)
            if is_compressed:
                data = data[:-1]
            return Key(
                secret_exponent=from_bytes_32(data),
                prefer_uncompressed=not is_compressed, netcode=netcode)
        if key_type == 'address':
            return Key(hash160=data, is_compressed=is_compressed, netcode=netcode)
        raise EncodingError("unknown text: %s" % text)
开发者ID:Zibbo,项目名称:pycoin,代码行数:26,代码来源:Key.py

示例11: __init__

    def __init__(self, private={}, public={}, private_seeds={}):
        # It is possible to distinguish between private and public seeds
        # based on the string content.  Consider modifying this function
        # to take merely one dict of seeds.  Trees should still be stored
        # separately.
        self.trees = {}
        self.private_trees = {}
        self.public_trees = {}

        def treegen(value, entropy=False):
            if entropy:
                # this method also takes a netcode parameter, but we don't care
                # what network pycoin thinks this node is, because we only use it
                # for key derivation.
                return BIP32Node.from_master_secret(unhexlify(value))
            else:
                # this method will infer a network from the header bytes. We
                # don't care right now for the same reason as above, but we will
                # if Gem's API stops returning 'xpub' as the pubkey header bytes
                # because if pycoin doesn't recognize a header it will error.
                return BIP32Node.from_hwif(value)

        for name, seed in iteritems(private):
            tree = treegen(seed)
            self.private_trees[name] = self.trees[name] = tree

        for name, seed in iteritems(private_seeds):
            tree = treegen(seed, True)
            self.private_trees[name] = self.trees[name] = tree

        for name, seed in iteritems(public):
            tree = BIP32Node.from_hwif(seed)
            self.public_trees[name] = self.trees[name] = tree
开发者ID:GemHQ,项目名称:coinop-py,代码行数:33,代码来源:multiwallet.py

示例12: bip32node_for_slug

 def bip32node_for_slug(self, slug):
     c = self._exec_sql("select id, as_text from BIP32Key where slug=?", slug)
     r = c.fetchone()
     if r is None:
         return None
     bip32_node = BIP32Node.from_hwif(r[1])
     bip32_node.id = r[0]
     return bip32_node
开发者ID:DOGEtools,项目名称:doge-millionaire,代码行数:8,代码来源:SQLite3Persistence.py

示例13: prefix_transforms_for_network

def prefix_transforms_for_network(network):
    def _create_bip32(_):
        max_retries = 64
        for _ in range(max_retries):
            try:
                return BIP32Node.from_master_secret(get_entropy(), netcode=network)
            except ValueError as e:
                continue
        # Probably a bug if we get here
        raise RuntimeError("can't create BIP32 key")

    return (
        ("P:", lambda s: BIP32Node.from_master_secret(s.encode("utf8"), netcode=network)),
        ("H:", lambda s: BIP32Node.from_master_secret(h2b(s), netcode=network)),
        ("E:", lambda s: key_from_text(s)),
        ("create", _create_bip32),
    )
开发者ID:onestarshang,项目名称:pycoin,代码行数:17,代码来源:ku.py

示例14: _create_bip32

 def _create_bip32(_):
     max_retries = 64
     for _ in range(max_retries):
         try:
             return BIP32Node.from_master_secret(get_entropy(), netcode=network)
         except ValueError as e:
             continue
     # Probably a bug if we get here
     raise RuntimeError("can't create BIP32 key")
开发者ID:onestarshang,项目名称:pycoin,代码行数:9,代码来源:ku.py

示例15: create

 def create(self):
     network = "BTC"
     if not self.proxy.use_production:
         network = "XTN"
     entropy = "".join([chr(random.getrandbits(8)) for i in range(32)])
     key = BIP32Node.from_master_secret(entropy, network)
     private = key.wallet_key(as_private=True).encode("utf-8")
     public = key.wallet_key(as_private=False).encode("utf-8")
     return {"xpub": public, "xprv": private}
开发者ID:faheem-cliqz,项目名称:bitgo,代码行数:9,代码来源:bitgo.py


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