def run(send_to_node=False):
    """
    Generate signed PATCH request
    """

    # Signed request
    sk = read_signing_key_file(os.path.join(SIGNING_KEY_DIR, 'bank_nid'))

    payload = {
        'trust': 76.26
    }

    target_nid = BANK_NID_ACCOUNT_NUMBER

    signed_request = generate_signed_request(
        data=payload,
        nid_signing_key=sk
    )

    if send_to_node:
        send_request_to_node(signed_request, target_nid)

    write_json(
        os.path.join(SIGNED_REQUESTS_DIR, 'bank-patch-request.json'),
        signed_request
    )
Beispiel #2
0
def run(send_to_bank=False):
    """
    Create block used for:
    - POST /blocks
    """

    signing_key = read_signing_key_file(
        os.path.join(SIGNING_KEY_DIR, 'treasury'))
    account_number = get_verify_key(signing_key=signing_key)

    balance_lock = get_account_balance_lock(
        account_number=TREASURY_ACCOUNT_NUMBER, live_pv=True)
    transactions = [{
        'amount': BANK_TX_FEE,
        'recipient': BANK_ACCOUNT_NUMBER,
    }, {
        'amount': PV_TX_FEE,
        'recipient': PV_ACCOUNT_NUMBER,
    }, {
        'amount': 5.50,
        'recipient': BUCKY_ACCOUNT_NUMBER,
    }]
    block = generate_block(account_number=account_number,
                           balance_lock=balance_lock,
                           signing_key=signing_key,
                           transactions=transactions)

    write_json(os.path.join(BLOCKS_DIR, 'blocks.json'), block)

    if send_to_bank:
        send_block_to_bank(block)
Beispiel #3
0
def run():
    """
    Create block used for:
    - POST /blocks
    """

    signing_key = read_signing_key_file(os.path.join(SIGNING_KEY_DIR, 'bucky'))
    account_number = get_verify_key(signing_key=signing_key)
    transactions = [{
        'amount': BANK_TX_FEE,
        'recipient': BANK_ACCOUNT_NUMBER,
    }, {
        'amount': PV_TX_FEE,
        'recipient': PV_ACCOUNT_NUMBER,
    }, {
        'amount': 2.5,
        'recipient': BUCKY_ACCOUNT_NUMBER,
    }]
    block = generate_block(
        account_number=account_number,
        balance_lock=
        '8db1bd4404eadce824b8f7af2461976e1fde8ebd7a279a2ccec2614479ede338',
        signing_key=signing_key,
        transactions=transactions)

    print(block)

    write_json(os.path.join(BLOCKS_DIR, 'upw.json'), block)
Beispiel #4
0
def test_create_account_and_save_signing_key_file(tmpdir):
    file_path = tmpdir.join('signing_key_file')
    signing_key, account_number = create_account_and_save_signing_key_file(file_path)

    assert isinstance(signing_key, SigningKey)
    assert isinstance(account_number, VerifyKey)
    assert signing_key == read_signing_key_file(file_path)
Beispiel #5
0
def run(send_to_cv=False):
    """
    Generate primary validator updated notice (from bank)
    """

    # Signed request
    sk = read_signing_key_file(os.path.join(SIGNING_KEY_DIR, 'bank_nid'))

    new_pv_data = {
        'ip_address': '192.168.1.20',
        'port': '8000',
        'protocol': 'http'
    }

    signed_request = generate_signed_request(
        data=new_pv_data,
        nid_signing_key=sk
    )

    if send_to_cv:
        send_request_to_cv(signed_request)

    write_json(
        os.path.join(SIGNED_REQUESTS_DIR, 'primary-validator-updated-request.json'),
        signed_request
    )
Beispiel #6
0
def run(send_to_pv=False):
    """
    Create block used for:
    - POST /bank_blocks
    - Bank > PV
    """

    treasury_signing_key = read_signing_key_file(
        os.path.join(SIGNING_KEY_DIR, 'treasury'))
    account_number = get_verify_key(signing_key=treasury_signing_key)

    balance_lock = get_account_balance_lock(
        account_number=TREASURY_ACCOUNT_NUMBER, live_pv=True)
    transactions = [{
        'amount': BANK_TX_FEE,
        'recipient': BANK_ACCOUNT_NUMBER,
    }, {
        'amount': PV_TX_FEE,
        'recipient': PV_ACCOUNT_NUMBER,
    }, {
        'amount': 1.0,
        'recipient': BUCKY_ACCOUNT_NUMBER,
    }]
    block = generate_block(account_number=account_number,
                           balance_lock=balance_lock,
                           signing_key=treasury_signing_key,
                           transactions=transactions)

    bank_nid_sk = read_signing_key_file(
        os.path.join(SIGNING_KEY_DIR, 'bank_nid'))
    bank_nid = get_verify_key(signing_key=bank_nid_sk)
    bank_nid = encode_verify_key(verify_key=bank_nid)
    message = sort_and_encode(block)

    signed_block = {
        'block': block,
        'node_identifier': bank_nid,
        'signature': generate_signature(message=message,
                                        signing_key=bank_nid_sk)
    }

    write_json(os.path.join(BLOCKS_DIR, 'bank-blocks-request.json'),
               signed_block)

    if send_to_pv:
        send_request_to_pv(signed_block)
Beispiel #7
0
def run():
    """
    Create new account and save signing key
    """

    file_path = os.path.join(SIGNING_KEY_DIR, 'cv_nid')
    create_account_and_save_signing_key_file(file=file_path)

    signing_key = read_signing_key_file(file_path)
    verify_key = get_verify_key(signing_key=signing_key)
    verify_key = encode_verify_key(verify_key=verify_key)

    print(f'verify_key: {verify_key}')
def run(send_to_node=False):
    """
    Generate signed PATCH request
    """

    # Signed request
    sk = read_signing_key_file(os.path.join(SIGNING_KEY_DIR, 'bank_nid'))

    payload = {'trust': 99.98}

    signed_request = generate_signed_request(data=payload, nid_signing_key=sk)

    if send_to_node:
        send_request_to_node(signed_request)

    write_json(os.path.join(SIGNED_REQUESTS_DIR, 'account-patch-request.json'),
               signed_request)
Beispiel #9
0
def run(send_to_bank=False):
    """
    Generate invalid block
    """

    # Signed request
    sk = read_signing_key_file(os.path.join(SIGNING_KEY_DIR, 'cv_nid'))
    signed_request = generate_signed_request(data={
        'block': {
            'account_number':
            '0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb',
            'message': {
                'balance_key':
                'ce51f0d9facaa7d3e69657429dd3f961ce70077a8efb53dcda508c7c0a19d2e3',
                'txs': [{
                    'amount':
                    12.5,
                    'recipient':
                    '484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc'
                }, {
                    'amount':
                    1,
                    'recipient':
                    '5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8'
                }, {
                    'amount':
                    4,
                    'recipient':
                    'ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314'
                }]
            },
            'signature':
            'ee5a2f2a2f5261c1b633e08dd61182fd0db5604c853ebd8498f6f28ce8e2ccbbc38093918610ea88a7ad47c7f3192ed955d9d1529e7e390013e43f25a5915c0f'
        },
        'block_identifier':
        '65ae26192dfb9ec41f88c6d582b374a9b42ab58833e1612452d7a8f685dcd4d5',
        'primary_validator_node_identifier':
        PV_NID_ACCOUNT_NUMBER
    },
                                             nid_signing_key=sk)

    if send_to_bank:
        send_request_to_bank(signed_request)

    write_json(os.path.join(SIGNED_REQUESTS_DIR, 'invalid-block-request.json'),
               signed_request)
def run(send_to_cv=False):
    """
    Bank asking a confirmation validator to upgrade to a primary validator
    """

    # Signed request
    sk = read_signing_key_file(os.path.join(SIGNING_KEY_DIR, 'bank_nid'))

    new_pv_data = {'validator_node_identifier': CV_NID_ACCOUNT_NUMBER}

    signed_request = generate_signed_request(data=new_pv_data,
                                             nid_signing_key=sk)

    if send_to_cv:
        send_request_to_cv(signed_request)

    write_json(
        os.path.join(SIGNED_REQUESTS_DIR, 'upgrade-request-request.json'),
        signed_request)
def run(send_to_node=False):
    """
    Generate signed connection request
    """

    # Signed request
    sk = read_signing_key_file(os.path.join(SIGNING_KEY_DIR, 'bank_nid'))
    signed_request = generate_signed_request(data={
        'ip_address': '167.99.173.247',
        'port': '80',
        'protocol': 'http'
    },
                                             nid_signing_key=sk)

    if send_to_node:
        send_request_to_node(signed_request)

    write_json(os.path.join(SIGNED_REQUESTS_DIR, 'connection-request.json'),
               signed_request)
Beispiel #12
0
def run(send_to_node=False):
    """
    Generate signed connection request
    """

    # Signed request
    sk = read_signing_key_file(os.path.join(SIGNING_KEY_DIR, 'cv_nid'))
    signed_request = generate_signed_request(data={
        'ip_address': '138.68.233.185',
        'port': None,
        'protocol': 'http'
    },
                                             nid_signing_key=sk)

    if send_to_node:
        send_request_to_node(signed_request, live_pv=True)

    write_json(os.path.join(SIGNED_REQUESTS_DIR, 'connection-request.json'),
               signed_request)
def run(send_to_bank=False):
    """
    Generate validator confirmation service
    """

    # Signed request
    sk = read_signing_key_file(os.path.join(SIGNING_KEY_DIR, 'cv_nid'))
    signed_request = generate_signed_request(data={
        'end': '2020-07-09T22:10:25Z',
        'start': '2020-08-09T22:10:25Z'
    },
                                             nid_signing_key=sk)

    if send_to_bank:
        send_request_to_bank(signed_request)

    write_json(
        os.path.join(SIGNED_REQUESTS_DIR,
                     'signed-validator-confirmation-services-request.json'),
        signed_request)
Beispiel #14
0
from thenewboston.accounts.key_files import read_signing_key_file

from config import SIGNED_MESSAGE_FILE, SIGNING_KEY_FILE
from utils import generate_signed_message, write_json

SIGNING_KEY = read_signing_key_file(SIGNING_KEY_FILE)
MESSAGE = 'My name is Bucky Roberts'

account_number = SIGNING_KEY.verify_key
signed_message = generate_signed_message(account_number=account_number,
                                         message=MESSAGE,
                                         signing_key=SIGNING_KEY)
write_json(file=SIGNED_MESSAGE_FILE, data=signed_message)
Beispiel #15
0
def test_write_signing_key_file(tmpdir):
    file_path = tmpdir.join('signing_key_file')
    signing_key, account_number = create_account()
    write_signing_key_file(signing_key, file_path)

    assert signing_key == read_signing_key_file(file_path)