Пример #1
0
def test_bytom_wallet_error():

    with pytest.raises(ValueError, match=r"invalid network, .*"):
        Wallet(network="unknown")

    with pytest.raises(TypeError, match="derivation change must be boolean format."):
        Wallet(network="solonet", change=1)
Пример #2
0
def test_solonet_from_xprivate_key():
    # Initialize bytom sender wallet
    bytom_testnet_wallet = Wallet(network="solonet",
                                  indexes=["2c000000", "99000000", "01000000", "00000000", "01000000"]) \
        .from_xprivate_key("205b15f70e253399da90b127b074ea02904594be9d54678207872ec1ba31ee51ef4490504bd2b6f997113671892458830de09518e6bd5958d5d5dd97624cfa4b")

    xpublic_key = bytom_testnet_wallet.xpublic_key()
    assert xpublic_key == "16476b7fd68ca2acd92cfc38fa353e75d6103f828276f44d587e660a6bd7a5c5ef4490504bd2b6f997113671892458830de09518e6bd5958d5d5dd97624cfa4b"

    assert bytom_testnet_wallet.path() == "m/44/153/1/0/1"

    expand_xprivate_key = bytom_testnet_wallet.expand_xprivate_key()
    assert expand_xprivate_key == "205b15f70e253399da90b127b074ea02904594be9d54678207872ec1ba31ee5102416c643cfb46ab1ae5a524c8b4aaa002eb771d0d9cfc7490c0c3a8177e053e"

    public_key = bytom_testnet_wallet.public_key()
    assert public_key == "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2"

    assert bytom_testnet_wallet.indexes() == ["2c000000", "99000000", "01000000", "00000000", "01000000"]

    program = bytom_testnet_wallet.program()
    assert program == "00142cda4f99ea8112e6fa61cdd26157ed6dc408332a"

    address = bytom_testnet_wallet.address()
    assert address == "sm1q9ndylx02syfwd7npehfxz4lddhzqsve2gdsdcs"

    private_key = bytom_testnet_wallet.private_key()
    assert private_key == "e07af52746e7cccd0a7d1fba6651a6f474bada481f34b1c5bab5e2d71e36ee515803ee0a6682fb19e279d8f4f7acebee8abd0fc74771c71565f9a9643fd77141"
Пример #3
0
def test_mainnet_from_mnemonic():
    
    # Initialize bytom sender wallet
    bytom_wallet = Wallet(network="mainnet")\
        .from_mnemonic("indicate warm sock mistake code spot acid ribbon sing over taxi toast")
    
    seed = bytom_wallet.seed()
    assert seed == "baff3e1fe60e1f2a2d840d304acc98d1818140c79354a353b400fb019bfb256bc392d7aa9047adff1f14bce0342e14605c6743a6c08e02150588375eb2eb7d49"

    xprivate_key = bytom_wallet.xprivate_key()
    assert xprivate_key == "205b15f70e253399da90b127b074ea02904594be9d54678207872ec1ba31ee51ef4490504bd2b6f997113671892458830de09518e6bd5958d5d5dd97624cfa4b"

    xpublic_key = bytom_wallet.xpublic_key()
    assert xpublic_key == "16476b7fd68ca2acd92cfc38fa353e75d6103f828276f44d587e660a6bd7a5c5ef4490504bd2b6f997113671892458830de09518e6bd5958d5d5dd97624cfa4b"

    expand_xprivate_key = bytom_wallet.expand_xprivate_key()
    assert expand_xprivate_key == "205b15f70e253399da90b127b074ea02904594be9d54678207872ec1ba31ee5102416c643cfb46ab1ae5a524c8b4aaa002eb771d0d9cfc7490c0c3a8177e053e"

    public_key = bytom_wallet.public_key()
    assert public_key == "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2"

    program = bytom_wallet.program()
    assert program == "00142cda4f99ea8112e6fa61cdd26157ed6dc408332a"

    address = bytom_wallet.address()
    assert address == "bm1q9ndylx02syfwd7npehfxz4lddhzqsve2fu6vc7"
Пример #4
0
def test_bytom_sign_and_verify():
    wallet = Wallet(network="mainnet",  account=1, change=False, address=1)\
        .from_mnemonic("indicate warm sock mistake code spot acid ribbon sing over taxi toast")
    private_key = wallet.private_key()
    public_key = wallet.public_key()
    # Message or Unsigned data
    message = "ecaba401a6df9cffbed37d1abcf23b91b3c84ec7aa9411d481cbef2e437ef7b1"

    signature = sign(private_key, message)
    assert signature == "5bd906d6829b1679c1b6e987849e5f8432a1dd7114b026908f675dafb9a9526e25a7a23f451e08695c133e67a89" \
                        "9079cf75410cc055b937158fc473e8154130a"

    assert verify(public_key, signature, message)
    assert not verify(public_key, signature, "4ec7aa9411d481cbef2e437ef7b1ecaba401a6df9cffbed37d1abcf23b91b3c8")
Пример #5
0
def claim(transaction, recipient_guid, amount, asset, network):
    try:
        click.echo(
            ClaimTransaction(network=network).build_transaction(
                transaction_id=transaction,
                wallet=Wallet(network=network).from_guid(guid=recipient_guid),
                amount=int(amount),
                asset=asset).unsigned_raw())
    except Exception as exception:
        click.echo(click.style("Error: {}").format(str(exception)), err=True)
        sys.exit()
Пример #6
0
def fund(sender_guid, amount, asset, bytecode, network):
    try:
        click.echo(
            FundTransaction(network=network).build_transaction(
                wallet=Wallet(network=network).from_guid(guid=sender_guid),
                htlc=HTLC(network=network).from_bytecode(bytecode=bytecode),
                amount=int(amount),
                asset=asset).unsigned_raw())
    except Exception as exception:
        click.echo(click.style("Error: {}").format(str(exception)), err=True)
        sys.exit()
Пример #7
0
def refund(transaction, sender_guid, sender_public, amount, asset, network):
    try:
        click.echo(
            RefundTransaction(network=network).build_transaction(
                transaction_id=transaction,
                wallet=Wallet(network=network).from_public_key(
                    public=sender_public).from_guid(guid=sender_guid),
                amount=int(amount),
                asset=asset).unsigned_raw())
    except Exception as exception:
        click.echo(click.style("Error: {}").format(str(exception)), err=True)
        sys.exit()
Пример #8
0
def test_testnet_from_xprivate_key():
    # Initialize bytom sender wallet
    bytom_testnet_wallet = Wallet(network="testnet", path="m/44/153/1/0/1") \
        .from_xprivate_key("205b15f70e253399da90b127b074ea02904594be9d54678207872ec1ba31ee51ef4490504bd2b6f997113671892458830de09518e6bd5958d5d5dd97624cfa4b")

    xpublic_key = bytom_testnet_wallet.xpublic_key()
    assert xpublic_key == "16476b7fd68ca2acd92cfc38fa353e75d6103f828276f44d587e660a6bd7a5c5ef4490504bd2b6f997113671892458830de09518e6bd5958d5d5dd97624cfa4b"

    assert bytom_testnet_wallet.path() == "m/44/153/1/0/1"

    expand_xprivate_key = bytom_testnet_wallet.expand_xprivate_key()
    assert expand_xprivate_key == "205b15f70e253399da90b127b074ea02904594be9d54678207872ec1ba31ee5102416c643cfb46ab1ae5a524c8b4aaa002eb771d0d9cfc7490c0c3a8177e053e"

    public_key = bytom_testnet_wallet.public_key()
    assert public_key == "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2"

    program = bytom_testnet_wallet.program()
    assert program == "00142cda4f99ea8112e6fa61cdd26157ed6dc408332a"

    address = bytom_testnet_wallet.address()
    assert address == "tm1q9ndylx02syfwd7npehfxz4lddhzqsve2d2mgc0"
Пример #9
0
NETWORK = "mainnet"
# Bytom transaction id/hash
TRANSACTION_ID = "5ec2547c7aece45af6b4b97fabcc42cb6b1ecfa9c7d30a0b3c4655888284b1bd"
# Sender 12 word mnemonic
SENDER_MNEMONIC = "indicate warm sock mistake code spot acid ribbon sing over taxi toast"
# Recipient Bytom public key
RECIPIENT_PUBLIC_KEY = "3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e"
# Bytom fund asset id
ASSET = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
# Bytom fund amount
AMOUNT = 10_000

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

# Initializing Bytom sender wallet
sender_wallet = Wallet(network=NETWORK)
# Initializing Bytom wallet from mnemonic
sender_wallet.from_mnemonic(mnemonic=SENDER_MNEMONIC)
# Getting sender wallet information's
sender_seed = sender_wallet.seed()
print("Sender Seed:", sender_seed)
sender_xprivate_key = sender_wallet.xprivate_key()
print("Sender XPrivate Key:", sender_xprivate_key)
sender_xpublic_key = sender_wallet.xpublic_key()
print("Sender XPublic Key:", sender_xpublic_key)
sender_expand_xprivate_key = sender_wallet.expand_xprivate_key()
print("Sender Expand XPrivate Key:", sender_expand_xprivate_key)
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)
Пример #10
0
from shuttle.providers.bytom.wallet import Wallet
from shuttle.providers.bytom.htlc import HTLC
from shuttle.providers.bytom.transaction import FundTransaction
from shuttle.providers.bytom.solver import FundSolver
from shuttle.providers.bytom.signature import FundSignature
from shuttle.utils import sha256

import json


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

sender_mnemonic = "indicate warm sock mistake code spot acid ribbon sing over taxi toast"
print("Sender Mnemonic:", sender_mnemonic)
# Initialize bytom sender wallet
sender_bytom_wallet = Wallet(network="mainnet").from_mnemonic(sender_mnemonic)
# Sender wallet information's
sender_seed = sender_bytom_wallet.seed()
print("Sender Seed:", sender_seed)
sender_xprivate_key = sender_bytom_wallet.xprivate_key()
print("Sender XPrivate Key:", sender_xprivate_key)
sender_xpublic_key = sender_bytom_wallet.xpublic_key()
print("Sender XPublic Key:", sender_xpublic_key)
sender_expand_xprivate_key = sender_bytom_wallet.expand_xprivate_key()
print("Sender Expand XPrivate Key:", sender_expand_xprivate_key)
sender_private_key = sender_bytom_wallet.private_key()
print("Sender Private Key:", sender_private_key)
sender_public_key = sender_bytom_wallet.public_key()
print("Sender Public Key:", sender_public_key)
sender_program = sender_bytom_wallet.program()
print("Sender Program:", sender_program)
Пример #11
0
#!/usr/bin/env python3

from shuttle.providers.bytom.wallet import Wallet
from shuttle.cli.__main__ import main as cli_main

network = "mainnet"
sender_wallet = Wallet(network=network).from_mnemonic(
    mnemonic=
    "hint excuse upgrade sleep easily deputy erase cluster section other ugly limit"
).from_guid(guid="571784a8-0945-4d78-b973-aac4b09d6439")
recipient_wallet = Wallet(network=network).from_mnemonic(
    mnemonic=
    "indicate warm sock mistake code spot acid ribbon sing over taxi toast"
).from_guid(guid="f0ed6ddd-9d6b-49fd-8866-a52d1083a13b")
htlc_bytecode = "02e803203e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e2091ff" \
                "7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2203a26da82ead15a80" \
                "533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb741f547a6416000000557aa888537a" \
                "7cae7cac631f000000537acd9f6972ae7cac00c0"
asset = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
amount = 10_000


def test_bytom_cli_fund(cli_tester):

    fund = cli_tester.invoke(cli_main, [
        "bytom", "fund", "--sender-guid",
        sender_wallet.guid(), "--amount", amount, "--asset", asset,
        "--bytecode", htlc_bytecode, "--network", network
    ])
    assert fund.exit_code == 0
    assert fund.output == "eyJmZWUiOiAxMDAwMDAwMCwgImd1aWQiOiAiNTcxNzg0YTgtMDk0NS00ZDc4LWI5NzMtYWFjN" \
Пример #12
0
#!/usr/bin/env python3

from shuttle.providers.bytom.wallet import Wallet
from shuttle.providers.bytom.htlc import HTLC
from shuttle.providers.bytom.transaction import FundTransaction
from shuttle.providers.bytom.solver import FundSolver
from shuttle.providers.bytom.signature import FundSignature, Signature

import pytest

network = "mainnet"

# Initialize bytom sender wallet
sender_mnemonic = "indicate warm sock mistake code spot acid ribbon sing over taxi toast"
sender_bytom_wallet = Wallet(network=network).from_mnemonic(sender_mnemonic)
sender_xprivate_key = sender_bytom_wallet.xprivate_key()

# Initialize bytom recipient wallet
recipient_public = "ac13c0bb1445423a641754182d53f0677cd4351a0e743e6f10b35122c3d7ea01"
recipient_bytom_wallet = Wallet(
    network=network).from_public_key(recipient_public)
recipient_public_key = recipient_bytom_wallet.public_key()
recipient_program = recipient_bytom_wallet.program()


UNSIGNED_FUND = \
       "eyJmZWUiOiAxMDAwMDAwMCwgImd1aWQiOiAiZjBlZDZkZGQtOWQ2Yi00OWZkLTg4NjYtYTUyZDEwODNhMTNiIiwgInVuc2lnbmVk" \
       "IjogW3siZGF0YXMiOiBbImIxYzVlYTFkNjAwNjY0Y2U4MTAwNzMxNmQ2Zjg5NThlMjQ4ZWZhNjk3YWRhN2Q0M2E4YzI2YjJkNjE1" \
       "NjAxNDgiXSwgInB1YmxpY19rZXkiOiAiOTFmZjdmNTI1ZmY0MDg3NGM0ZjQ3ZjBjYWI0MmU0NmUzYmY1M2FkYWQ1OWFkZWY5NTU4" \
       "YWQxYjY0NDhmMjJlMiIsICJuZXR3b3JrIjogIm1haW5uZXQiLCAicGF0aCI6ICJtLzQ0LzE1My8xLzAvMSJ9LCB7ImRhdGFzIjog" \
       "WyIyNTFmYmQ4YTAzMmM3MmJmMjkwN2VjNGFmYzk1ZGYxZTE2Mzg5NDZiODE5MGQwYjIxZTk1MjA2YmU2YzZhOTYyIl0sICJwdWJs" \
Пример #13
0
#!/usr/bin/env python3

from shuttle.providers.bytom.wallet import Wallet
from shuttle.providers.bytom.transaction import RefundTransaction
from shuttle.providers.bytom.solver import RefundSolver
from shuttle.providers.bytom.signature import RefundSignature, Signature

sender_mnemonic = "indicate warm sock mistake code spot acid ribbon sing over taxi toast"
sender_bytom_wallet = Wallet(network="mainnet").from_mnemonic(sender_mnemonic)
sender_xprivate_key = sender_bytom_wallet.xprivate_key()

# Funded hash time lock contract transaction id/hash
fund_transaction_id = "8843bca172ed4685b511c0f106fd3f6889a42fa3f9383d057ea4e587f7db0cbe"


# Testing bytom refund
def test_bytom_refund():
    # Initialization refund transaction
    unsigned_refund_transaction = RefundTransaction(network="mainnet")
    # Building refund transaction
    unsigned_refund_transaction.build_transaction(
        transaction_id=fund_transaction_id,
        wallet=sender_bytom_wallet,
        amount=100,
        asset="f37dea62efd2965174b84bbb59a0bd0a671cf5fb2857303ffd77c1b482b84bdf"
    )

    assert unsigned_refund_transaction.fee == 10000000
    assert unsigned_refund_transaction.hash()
    assert unsigned_refund_transaction.raw()
    assert unsigned_refund_transaction.unsigned()
Пример #14
0
def test_bytom_wallet_tools():
    wallet = Wallet(network="mainnet", indexes=["2c000000", "99000000", "01000000", "00000000", "01000000"])
    wallet.from_xpublic_key("16476b7fd68ca2acd92cfc38fa353e75d6103f828276f44d587e660a6bd7a5c5ef4490504bd2b"
                            "6f997113671892458830de09518e6bd5958d5d5dd97624cfa4b")
    assert wallet.address() == "bm1q9ndylx02syfwd7npehfxz4lddhzqsve2fu6vc7"

    assert wallet.path() == "m/44/153/1/0/1"
    assert isinstance(wallet.guid(), str)

    wallet = Wallet(network="solonet")
    wallet.from_entropy("063679ca1b28b5cfda9c186b367e271e")
    assert wallet.address() == "sm1qzq3k0cg89qudwnlxs7frykxg0r357kupzccnzv"
    assert wallet.path() == "m/44/153/1/0/1"

    wallet = Wallet(network="testnet")
    wallet.from_guid(guid="f0ed6ddd-9d6b-49fd-8866-a52d1083a13b")

    wallet = Wallet(network="mainnet")
    wallet.from_public_key("91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2")
    assert wallet.address() == "bm1q9ndylx02syfwd7npehfxz4lddhzqsve2fu6vc7"

    assert wallet.path() is None
    assert wallet.seed() is None
    assert wallet.xprivate_key() is None
    assert wallet.xpublic_key() is None
    assert wallet.expand_xprivate_key() is None
    assert isinstance(wallet.balance(), int)