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


Python BIP32Node.from_master_secret方法代码示例

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


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

示例1: test_refill_main_wallet

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
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,代码行数:32,代码来源:test_spool.py

示例2: test_refill_fuel

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
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,代码行数:50,代码来源:test_spool.py

示例3: test_create_sign_push_transaction

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
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,代码行数:18,代码来源:test_transactions.py

示例4: create_key

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
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,代码行数:9,代码来源:lib.py

示例5: sign_transaction

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
    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,代码行数:28,代码来源:transactions.py

示例6: test_streams

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
 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,代码行数:28,代码来源:bip32_test.py

示例7: prefix_transforms_for_network

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
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,代码行数:19,代码来源:ku.py

示例8: test_testnet

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
 def test_testnet(self):
     # WARNING: these values have not been verified independently. TODO: do so
     master = BIP32Node.from_master_secret(h2b("000102030405060708090a0b0c0d0e0f"), netcode='XTN')
     self.assertEqual(
         master.wallet_key(as_private=True),
         "tprv8ZgxMBicQKsPeDgjzdC36fs6bMjGApWDNLR9erAXMs5skhMv36j9MV5ecvfavji5kh"
         "qjWaWSFhN3YcCUUdiKH6isR4Pwy3U5y5egddBr16m")
     self.assertEqual(master.bitcoin_address(), "mkHGce7dctSxHgaWSSbmmrRWsZfzz7MxMk")
     self.assertEqual(master.wif(), "cVPXTF2TnozE1PenpP3x9huctiATZmp27T9Ue1d8nqLSExoPwfN5")
开发者ID:onestarshang,项目名称:pycoin,代码行数:11,代码来源:bip32_test.py

示例9: create

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
 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,代码行数:11,代码来源:bitgo.py

示例10: _create_bip32

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
 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,代码行数:11,代码来源:ku.py

示例11: _create

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
 def _create(_):
     max_retries = 64
     for _ in range(max_retries):
         try:
             return BIP32Node.from_master_secret(get_entropy(), netcode=args.network)
         except ValueError as e:
             continue
     # Probably a bug if we get here
     raise e
开发者ID:cryptoproofinfo,项目名称:pycoin,代码行数:11,代码来源:ku.py

示例12: sign_transaction

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
    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,代码行数:13,代码来源:transactions.py

示例13: treegen

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
 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,代码行数:14,代码来源:multiwallet.py

示例14: test_vector_1

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [as 别名]
    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,代码行数:54,代码来源:bip32_test.py

示例15: test_repr

# 需要导入模块: from pycoin.key.BIP32Node import BIP32Node [as 别名]
# 或者: from pycoin.key.BIP32Node.BIP32Node import from_master_secret [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


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