Example #1
0
def parse_draw(msg_payload, sender_public_key):
    previous_txid_bytes = msg_payload[:32]

    sizes_offset = 32
    msg_bytes_size_bytes = msg_payload[sizes_offset:sizes_offset + 2]
    msg_size = int.from_bytes(msg_bytes_size_bytes, byteorder='big')
    signed_previous_txid_size = msg_payload[sizes_offset + 2]

    after_sizes_offset = 32 + 3
    game_turn_ops = msg_payload[after_sizes_offset:after_sizes_offset +
                                msg_size]

    after_game_turn_ops_offset = after_sizes_offset + msg_size
    signed_previous_txid = msg_payload[
        after_game_turn_ops_offset:after_game_turn_ops_offset +
        signed_previous_txid_size + 1]

    valid = format.verify_sig(signed_previous_txid, previous_txid_bytes,
                              sender_public_key)
    if valid:
        game_turn_ops_str = game_turn_ops.decode()
        msg_draw = gc_message.MsgTmt(game_turn_ops_str)
        previous_txid = previous_txid_bytes.hex()
        return gc_message.MSG_DRW, msg_draw, previous_txid

    return None
Example #2
0
def parse_stt(msg_payload):
    initiator_key_bytes = msg_payload[:33]
    game_id_bytes = msg_payload[33:33 + 32]

    sizes_offset = 33 + 32
    signed_game_id_size = msg_payload[sizes_offset]
    msg_bytes_size_bytes = msg_payload[sizes_offset + 1:sizes_offset + 1 + 2]
    msg_size = int.from_bytes(msg_bytes_size_bytes, byteorder='big')

    messages_offset = sizes_offset + 3
    signed_game_id = msg_payload[messages_offset:messages_offset +
                                 signed_game_id_size]
    msg_data = msg_payload[messages_offset +
                           signed_game_id_size:messages_offset +
                           signed_game_id_size + msg_size]

    valid = format.verify_sig(signed_game_id, game_id_bytes,
                              initiator_key_bytes)
    if valid:
        msg_data_str = msg_data.decode()
        msg_stt = gc_message.MsgStt(initiator_key_bytes, msg_data_str)
        return gc_message.MSG_STT, msg_stt, None

    return None
Example #3
0
 def test_sign(self):
     base_key = BaseKey()
     data = os.urandom(200)
     signature = base_key.sign(data)
     assert verify_sig(signature, data, base_key.public_key)
Example #4
0
 def test_invalid(self):
     assert not verify_sig(INVALID_SIGNATURE, DATA, PUBLIC_KEY_COMPRESSED)
Example #5
0
from bitcash import PrivateKeyTestnet, format

import gcl_secrets

initiator_key = PrivateKeyTestnet(gcl_secrets.INITIATOR_PRIVATE_KEY)
print(initiator_key.public_key)
print(len(initiator_key.public_key))

message = b"123fsafsafsfsfsafsaffsafse3223gsdgbdbJGoeffffddw23abc"

sig = initiator_key.sign(message)
print(sig)
print(len(sig))
pubkey = initiator_key.public_key
print(len(initiator_key.public_key))

verified = format.verify_sig(sig, message, pubkey)

print(verified)