Example #1
0
def _blake2b_ed25519_deploy_data(current_height,
                                 bytecode,
                                 privatekey,
                                 receiver=None):
    sender = get_sender(private_key, True)
    print(sender)
    nonce = get_nonce(sender)
    print("nonce is {}".format(nonce))

    tx = Transaction()
    tx.valid_until_block = current_height + 88
    tx.nonce = nonce
    if receiver is not None:
        tx.to = receiver
    tx.data = hex2bytes(bytecode)

    message = _blake2b(tx.SerializeToString())
    print("msg is {}".format(message))
    sig = pysodium.crypto_sign_detached(message, hex2bytes(privatekey))
    print("sig {}".format(binascii.b2a_hex(sig)))

    pubkey = pysodium.crypto_sign_sk_to_pk(hex2bytes(privatekey))
    print("pubkey is {}".format(binascii.b2a_hex(pubkey)))
    signature = binascii.hexlify(sig[:]) + binascii.hexlify(pubkey[:])
    print("signature is {}".format(signature))

    unverify_tx = UnverifiedTransaction()
    unverify_tx.transaction.CopyFrom(tx)
    unverify_tx.signature = hex2bytes(signature)
    unverify_tx.crypto = Crypto.Value('SECP')

    print("unverify_tx is {}".format(
        binascii.hexlify(unverify_tx.SerializeToString())))
    return binascii.hexlify(unverify_tx.SerializeToString())
Example #2
0
def generate_deploy_data(bytecode, privatekey, receiver=None):
    privkey = PrivateKey(hex2bytes(privatekey))
    sender = get_sender()
    print(sender)
    nonce = get_nonce(sender)
    print("nonce is {}".format(nonce))

    tx = Transaction()
    tx.valid_until_block = 4294967296
    tx.nonce = nonce
    if receiver is not None:
        tx.to = receiver
    tx.data = hex2bytes(bytecode)

    message = sha3(tx.SerializeToString())
    sign_recover = privkey.ecdsa_sign_recoverable(message, raw=True)
    sig = privkey.ecdsa_recoverable_serialize(sign_recover)
    signature = binascii.hexlify(
        sig[0]) + binascii.hexlify(bytes(bytearray([sig[1]])))

    unverify_tx = UnverifiedTransaction()
    unverify_tx.transaction.CopyFrom(tx)
    unverify_tx.signature = hex2bytes(signature)
    unverify_tx.crypto = Crypto.Value('SECP')

    signed_transaction = SignedTransaction()
    signed_transaction.transaction_with_sig.CopyFrom(unverify_tx)
    signed_transaction.tx_hash = sha3(unverify_tx.SerializeToString())
    pub = recover_pub(hex2bytes(privatekey))
    signed_transaction.signer = pub
    #print(binascii.hexlify(pub))

    return binascii.hexlify(signed_transaction.SerializeToString())
Example #3
0
    def send_message(self, message_type):
        url = 'http://{}:{}/'.format(self.address,
                                     self.port)  # Set destination URL here
        message = Transaction()
        method = ''

        if message_type == 'balance_start':
            method = 'broadcast_tx_sync'
            message.balance_start.timestamp = int(time.time())
            message.balance_start.round_number = self.round

        elif message_type == 'balance':
            method = 'broadcast_tx_sync'
            message.balance.timestamp = int(time.time())
            message.balance.round_number = self.round
            for trade in self.last_trade_list:
                new_trade = message.balance.trades.add()
                new_trade.uuid = trade.uuid
                new_trade.order_id = trade.order_id
                new_trade.order_type = trade.order_type
                new_trade.volume = trade.volume
                new_trade.price = trade.price

        elif message_type == 'balance_end':
            method = 'broadcast_tx_sync'
            message.balance_end.timestamp = int(time.time())
            message.balance_end.round_number = self.round

        print("Sending message: {}".format(message))
        binarystring = message.SerializeToString()
        request = Request(
            url,
            json.dumps({
                "method":
                method,
                "params": [base64.b64encode(binarystring).decode('ascii')],
                "jsonrpc":
                "2.0",
                "id":
                "not_important"
            }).encode())
        result = urlopen(request, None, 10)
        print(result.read().decode())
Example #4
0
def _sha3_secp256k1_deploy_data(current_height,
                                bytecode,
                                privatekey,
                                receiver=None):
    sender = get_sender(privatekey, False)
    if privatekey is None:
        temp = private_key()
        privkey = PrivateKey(hex2bytes(temp))
    else:
        privkey = PrivateKey(hex2bytes(privatekey))

    print(sender)
    nonce = get_nonce(sender)
    print("nonce is {}".format(nonce))

    tx = Transaction()
    tx.valid_until_block = current_height + 88
    tx.nonce = nonce
    tx.quota = 9999999
    if receiver is not None:
        tx.to = receiver
    tx.data = hex2bytes(bytecode)

    message = sha3(tx.SerializeToString())

    print("message: {}".format(message))
    sign_recover = privkey.ecdsa_sign_recoverable(message, raw=True)
    sig = privkey.ecdsa_recoverable_serialize(sign_recover)

    signature = binascii.hexlify(sig[0]) + binascii.hexlify(
        bytes(bytearray([sig[1]])))

    unverify_tx = UnverifiedTransaction()
    unverify_tx.transaction.CopyFrom(tx)
    unverify_tx.signature = hex2bytes(signature)
    unverify_tx.crypto = Crypto.Value('SECP')

    print("unverify_tx is {}".format(
        binascii.hexlify(unverify_tx.SerializeToString())))
    return binascii.hexlify(unverify_tx.SerializeToString())