Example #1
0
def test_bitcoin_wallet_from_private_key():

    wallet = Wallet(network=_["bitcoin"]["network"])

    wallet.from_private_key(
        private_key=_["bitcoin"]["wallet"]["sender"]["private_key"])

    assert wallet.entropy() is None
    assert wallet.mnemonic() is None
    assert wallet.language() is None
    assert wallet.passphrase() is None
    assert wallet.seed() is None
    assert wallet.root_xprivate_key() is None
    assert wallet.root_xpublic_key() is None
    assert wallet.xprivate_key() is None
    assert wallet.xpublic_key() is None
    assert wallet.uncompressed(
    ) == _["bitcoin"]["wallet"]["sender"]["uncompressed"]
    assert wallet.compressed(
    ) == _["bitcoin"]["wallet"]["sender"]["compressed"]
    assert wallet.chain_code() is None
    assert wallet.private_key(
    ) == _["bitcoin"]["wallet"]["sender"]["private_key"]
    assert wallet.public_key(
    ) == _["bitcoin"]["wallet"]["sender"]["public_key"]
    assert wallet.wif() == _["bitcoin"]["wallet"]["sender"]["wif"]
    assert wallet.hash() == _["bitcoin"]["wallet"]["sender"]["hash"]
    assert wallet.finger_print(
    ) == _["bitcoin"]["wallet"]["sender"]["finger_print"]
    assert wallet.path() is None
    assert wallet.address() == _["bitcoin"]["wallet"]["sender"]["address"]
Example #2
0
def test_from_passphrase():
    passphrase = "meheret tesfaye batu bayou"
    # Initialize bitcoin wallet
    bitcoin_from_passphrase = Wallet(network="testnet") \
        .from_passphrase(passphrase)

    bitcoin_from_private_key = Wallet(network="testnet") \
        .from_private_key("92cbbc5990cb5090326a76feeb321cad01048635afe5756523bbf9f7a75bf38b")

    private_key = "92cbbc5990cb5090326a76feeb321cad01048635afe5756523bbf9f7a75bf38b"
    assert bitcoin_from_private_key.private_key() == private_key == bitcoin_from_passphrase.private_key()

    public_key = "03c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84"
    assert bitcoin_from_private_key.public_key() == public_key

    address = "mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q"
    assert bitcoin_from_private_key.address() == address

    # Initialize bitcoin wallet
    bitcoin_from_passphrase = Wallet(network="testnet")\
        .from_passphrase(passphrase, False)

    private_key = "92cbbc5990cb5090326a76feeb321cad01048635afe5756523bbf9f7a75bf38b"
    assert bitcoin_from_passphrase.private_key() == private_key

    public_key = "04c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84fee63d89a5979801c9659" \
                 "94963c77bfb470dff5afd351a442ebf329f3b2c2835"
    assert bitcoin_from_passphrase.public_key() == public_key

    compressed = "03c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84"
    assert bitcoin_from_passphrase.compressed() == compressed

    uncompressed = "04c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84fee63d89a5979801c96" \
                   "5994963c77bfb470dff5afd351a442ebf329f3b2c2835"
    assert bitcoin_from_passphrase.uncompressed() == uncompressed

    assert bitcoin_from_passphrase.uncompressed() == bitcoin_from_passphrase.public_key()

    address = "mqLyrNDjpENRMZAoDpspH7kR9RtgvhWzYE"
    assert bitcoin_from_passphrase.address() == address

    _hash = "6bce65e58a50b97989930e9a4ff1ac1a77515ef1"
    assert bitcoin_from_passphrase.hash() == _hash

    p2pkh = "76a9146bce65e58a50b97989930e9a4ff1ac1a77515ef188ac"
    assert bitcoin_from_passphrase.p2pkh() == p2pkh

    p2sh = "a914347283eee92ad685909044619adaa70370b2538787"
    assert bitcoin_from_passphrase.p2sh() == p2sh
Example #3
0
def test_bitcoin_wallet_from_entropy():

    wallet = Wallet(network=_["bitcoin"]["network"])

    wallet.from_entropy(
        entropy=_["bitcoin"]["wallet"]["sender"]["entropy"],
        language=_["bitcoin"]["wallet"]["sender"]["language"],
        passphrase=_["bitcoin"]["wallet"]["sender"]["passphrase"])

    wallet.from_path(
        path=_["bitcoin"]["wallet"]["sender"]["derivation"]["path"])

    assert wallet.entropy() == _["bitcoin"]["wallet"]["sender"]["entropy"]
    assert wallet.mnemonic() == _["bitcoin"]["wallet"]["sender"]["mnemonic"]
    assert wallet.language() == _["bitcoin"]["wallet"]["sender"]["language"]
    assert wallet.passphrase() is None
    assert wallet.seed() == _["bitcoin"]["wallet"]["sender"]["seed"]
    assert wallet.root_xprivate_key(
    ) == _["bitcoin"]["wallet"]["sender"]["root_xprivate_key"]
    assert wallet.root_xpublic_key(
    ) == _["bitcoin"]["wallet"]["sender"]["root_xpublic_key"]
    assert wallet.xprivate_key(
    ) == _["bitcoin"]["wallet"]["sender"]["xprivate_key"]
    assert wallet.xpublic_key(
    ) == _["bitcoin"]["wallet"]["sender"]["xpublic_key"]
    assert wallet.uncompressed(
    ) == _["bitcoin"]["wallet"]["sender"]["uncompressed"]
    assert wallet.compressed(
    ) == _["bitcoin"]["wallet"]["sender"]["compressed"]
    assert wallet.chain_code(
    ) == _["bitcoin"]["wallet"]["sender"]["chain_code"]
    assert wallet.private_key(
    ) == _["bitcoin"]["wallet"]["sender"]["private_key"]
    assert wallet.public_key(
    ) == _["bitcoin"]["wallet"]["sender"]["public_key"]
    assert wallet.wif() == _["bitcoin"]["wallet"]["sender"]["wif"]
    assert wallet.hash() == _["bitcoin"]["wallet"]["sender"]["hash"]
    assert wallet.p2pkh() == _["bitcoin"]["wallet"]["sender"]["p2pkh"]
    assert wallet.finger_print(
    ) == _["bitcoin"]["wallet"]["sender"]["finger_print"]
    assert wallet.path(
    ) == _["bitcoin"]["wallet"]["sender"]["derivation"]["path"]
    assert wallet.address() == _["bitcoin"]["wallet"]["sender"]["address"]

    assert isinstance(wallet.balance(), int)
    assert isinstance(wallet.utxos(), list)
Example #4
0
def test_bitcoin_wallet_tools():
    wallet = Wallet(network="testnet")
    private_key = "92cbbc5990cb5090326a76feeb321cad01048635afe5756523bbf9f7a75bf38b"
    public_key = wallet.public_key(private_key=private_key)
    assert public_key == "03c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84"
    public_key = "04c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84fee63d89a5979801c96" \
                 "5994963c77bfb470dff5afd351a442ebf329f3b2c2835"

    compressed = wallet.compressed(public_key=public_key)
    assert compressed == "03c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84"
    uncompressed = wallet.uncompressed(public_key=public_key)
    assert uncompressed == public_key
    address = wallet.address(public_key=uncompressed)
    assert address == "mqLyrNDjpENRMZAoDpspH7kR9RtgvhWzYE"
    _hash = wallet.hash(public_key=uncompressed)
    assert _hash == "6bce65e58a50b97989930e9a4ff1ac1a77515ef1"
    p2pkh = wallet.p2pkh(address=address)
    assert p2pkh == "76a9146bce65e58a50b97989930e9a4ff1ac1a77515ef188ac"
    p2sh = wallet.p2sh(address=address)
    assert p2sh == "a914347283eee92ad685909044619adaa70370b2538787"
    balance = wallet.balance(address=address, network="testnet")
    assert isinstance(balance, int)
    unspent = wallet.unspent(address=address, network="testnet", limit=1)
    assert isinstance(unspent, list)
Example #5
0
                "26a3ef7a865d1eda0fbd085e98adcc2388ac68"
# Bitcoin fund amount
AMOUNT = 10_000

print("=" * 10, "Sender Bitcoin Account")

# Initializing sender Bitcoin wallet
sender_wallet = Wallet(network=NETWORK)
# Initializing Bitcoin wallet from passphrase
sender_wallet.from_passphrase(passphrase=SENDER_PASSPHRASE)
# Getting sender wallet information's
sender_private_key = sender_wallet.private_key()
print("Sender Private Key:", sender_private_key)
sender_public_key = sender_wallet.public_key()
print("Sender Public Key:", sender_public_key)
sender_compressed = sender_wallet.compressed()
print("Sender Compressed:", sender_compressed)
sender_uncompressed = sender_wallet.uncompressed()
print("Sender Uncompressed:", sender_uncompressed)
sender_address = sender_wallet.address()
print("Sender Address:", sender_address)
sender_hash = sender_wallet.hash()
print("Sender Hash:", sender_hash)
sender_p2pkh = sender_wallet.p2pkh()
print("Sender P2PKH:", sender_p2pkh)
sender_p2sh = sender_wallet.p2sh()
print("Sender P2SH:", sender_p2sh)
# sender_balance = sender_wallet.balance()
# print("Sender Balance:", sender_balance)

print("=" * 10, "Hash Time Lock Contract (HTLC) from Bytecode")
Example #6
0
SENDER_ADDRESS = "miAcLpYbaqE8KowBu2PwvqXG6y6vpQcfTJ"
# Bitcoin claim amount
AMOUNT = 10_000

print("=" * 10, "Recipient Bitcoin Account")

# Initializing recipient Bitcoin wallet
recipient_wallet = Wallet(network=NETWORK)
# Initializing Bitcoin wallet from passphrase
recipient_wallet.from_passphrase(passphrase=RECIPIENT_PASSPHRASE)
# Getting recipient wallet information's
recipient_private_key = recipient_wallet.private_key()
print("Recipient Private Key:", recipient_private_key)
recipient_public_key = recipient_wallet.public_key()
print("Recipient Public Key:", recipient_public_key)
recipient_compressed = recipient_wallet.compressed()
print("Recipient Compressed:", recipient_compressed)
recipient_uncompressed = recipient_wallet.uncompressed()
print("Recipient Uncompressed:", recipient_uncompressed)
recipient_address = recipient_wallet.address()
print("Recipient Address:", recipient_address)
recipient_hash = recipient_wallet.hash()
print("Recipient Hash:", recipient_hash)
recipient_p2pkh = recipient_wallet.p2pkh()
print("Recipient P2PKH:", recipient_p2pkh)
recipient_p2sh = recipient_wallet.p2sh()
print("Recipient P2SH:", recipient_p2sh)
# recipient_balance = recipient_wallet.balance()
# print("Recipient Balance:", recipient_balance)

print("=" * 10, "Sender Bitcoin Account")