Ejemplo n.º 1
0
def test_features():
    assert unsigned.is_delegated() == False
    assert delegated_tx.is_delegated() == True

    # Sender
    # priv_1 = cry.secp256k1.generate_privateKey()
    priv_1 = bytes.fromhex(
        '58e444d4fe08b0f4d9d86ec42f26cf15072af3ddc29a78e33b0ceaaa292bcf6b')
    addr_1 = cry.public_key_to_address(cry.secp256k1.derive_publicKey(priv_1))

    # Gas payer
    # priv_2 = cry.secp256k1.generate_privateKey()
    priv_2 = bytes.fromhex(
        '0bfd6a863f347f4ef2cf2d09c3db7b343d84bb3e6fc8c201afee62de6381dc65')
    addr_2 = cry.public_key_to_address(cry.secp256k1.derive_publicKey(priv_2))

    h = delegated_tx.get_signing_hash()
    dh = delegated_tx.get_signing_hash('0x' + addr_1.hex())

    # Concat two parts to forge a signature.
    sig = cry.secp256k1.sign(h, priv_1) + cry.secp256k1.sign(dh, priv_2)

    delegated_tx.set_signature(sig)

    assert delegated_tx.get_origin() == '0x' + addr_1.hex()
    assert delegated_tx.get_delegator() == '0x' + addr_2.hex()
Ejemplo n.º 2
0
def run(private_key: bytes, target: str, network: str):
    public_key = secp256k1.derive_publicKey(private_key)
    _address_bytes = cry.public_key_to_address(public_key)
    my_address = '0x' + _address_bytes.hex()

    print(f"Target contract address: {target}")
    print(f"Your address: {my_address}")
    print(f"Working on: {network}-net")
    print("#" * 30)

    target_vtho_in_wei = check_vtho_balance_of(target, my_address, network)
    print(f"Target has: {target_vtho_in_wei / (10**18)} vtho")

    if target_vtho_in_wei == 0:
        print("Target contract doesn't have vtho, abort!")
        exit()

    my_vtho_in_wei = check_vtho_balance_of(my_address, my_address, network)
    print(f"You have: {my_vtho_in_wei / (10**18)} vtho")

    # At least 60 vtho is needed to call move()
    if my_vtho_in_wei / (10 ** 18) < 60:
        print("You need at least 60 vtho to call move(), abort!")
        exit()

    print()

    master_of_target = check_master_of(target, my_address, network)
    print(f"Target's master: {master_of_target}")

    if master_of_target.lower() != my_address.lower():
        print("Target's master is NOT you. Abort!")
        exit(1)

    # Do a round of simulation on move(). Check if can pass the simulation.
    simulate_move(target, my_address, target_vtho_in_wei, my_address, network)

    # Do the real move()
    do_move(target, my_address, target_vtho_in_wei, private_key, network)
Ejemplo n.º 3
0
def test_public_key_to_address():
    pub = bytes.fromhex(
        '04b90e9bb2617387eba4502c730de65a33878ef384a46f1096d86f2da19043304afa67d0ad09cf2bea0c6f2d1767a9e62a7a7ecc41facf18f2fa505d92243a658f')
    address = cry.public_key_to_address(pub)
    assert '0x' + address.hex() == '0xd989829d88b0ed1b06edf5c50174ecfa64f14a64'
Ejemplo n.º 4
0
    gas_price_coef=128,
    gas=21000,
    depends_on=None,
    nonce=12345678
)

unsigned = transaction.Transaction(body)
unsigned_encoded = bytes.fromhex('f8540184aabbccdd20f840df947567d83b7b8d80addcb281a71d54fc7b3364ffed82271086000000606060df947567d83b7b8d80addcb281a71d54fc7b3364ffed824e208600000060606081808252088083bc614ec0')

signed = transaction.Transaction(body)
signed_encoded = bytes.fromhex('f8970184aabbccdd20f840df947567d83b7b8d80addcb281a71d54fc7b3364ffed82271086000000606060df947567d83b7b8d80addcb281a71d54fc7b3364ffed824e208600000060606081808252088083bc614ec0b841f76f3c91a834165872aa9464fc55b03a13f46ea8d3b858e528fcceaf371ad6884193c3f313ff8effbb57fe4d1adc13dceb933bedbf9dbb528d2936203d5511df00')
priv_key = bytes.fromhex('7582be841ca040aa940fff6c05773129e135623e41acce3e0b8ba520dc1ae26a')
_a, _ = cry.blake2b256([signed.encode()])
_b = cry.secp256k1.sign(_a, priv_key)
signed.set_signature(_b)
signer = cry.public_key_to_address(cry.secp256k1.derive_publicKey(priv_key))

def test_unsigned():
    x = unsigned.encode()
    signing_hash, _ = cry.blake2b256([x])
    assert signing_hash.hex() == '2a1c25ce0d66f45276a5f308b99bf410e2fc7d5b6ea37a49f2ab9f1da9446478'

    assert unsigned.get_signing_hash().hex() == '2a1c25ce0d66f45276a5f308b99bf410e2fc7d5b6ea37a49f2ab9f1da9446478'

    assert unsigned.get_id() is None

    assert unsigned.get_intrinsic_gas() == 37432

    body_1 = copy.deepcopy(body)
    body_1.clauses = []
Ejemplo n.º 5
0
def _calc_address(priv: bytes) -> str:
    public_key = secp256k1.derive_publicKey(priv)
    _address_bytes = cry.public_key_to_address(public_key)
    address = '0x' + _address_bytes.hex()
    return address
Ejemplo n.º 6
0
import copy
import pytest
from thor_devkit import certificate
from thor_devkit import cry

PRIV_KEY = bytes.fromhex(
    '7582be841ca040aa940fff6c05773129e135623e41acce3e0b8ba520dc1ae26a')
SIGNER = '0x' + \
    cry.public_key_to_address(cry.secp256k1.derive_publicKey(PRIV_KEY)).hex()

cert_dict = {
    'purpose': 'identification',
    'payload': {
        'type': 'text',
        'content': 'fyi'
    },
    'domain': 'localhost',
    'timestamp': 1545035330,
    'signer': SIGNER
}
cert = certificate.Certificate(**cert_dict)

cert2_dict = {
    'domain': 'localhost',
    'timestamp': 1545035330,
    'purpose': 'identification',
    'signer': SIGNER,
    'payload': {
        'content': 'fyi',
        'type': 'text'
    }