host/stream_comm.c
/** nanopb field callback for signature data of SignTransaction message. This
  * does (or more accurately, delegates) all the "work" of transaction
  * signing: parsing the transaction, asking the user for approval, generating
  * the signature and sending the signature.
  * \param stream Input stream to read from.
  * \param field Field which contains the signature data.
  * \param arg Unused.
  * \return true on success, false on failure (nanopb convention).
  */
nanopb field callback for signature data of SignTransaction message. This
does (or more accurately, delegates) all the "work" of transaction
signing: parsing the transaction, asking the user for approval, generating
the signature and sending the signature.
\param stream Input stream to read from.
\param field Field which contains the signature data.
\param arg Unused.
\return true on success, false on failure (nanopb convention).
nanopb field callback for signature data of SignTransaction message . This does ( or more accurately delegates ) all the " work " of transaction signing : parsing the transaction asking the user for approval generating the signature and sending the signature . \ param stream Input stream to read from . \ param field Field which contains the signature data . \ param arg Unused . \ return true on success false on failure ( nanopb convention ) .
bool signTransactionCallback(pb_istream_t *stream, const pb_field_t *field, void **arg)
{
	TransactionErrors response;
	uint8_t sig_hash[32];
	uint8_t transaction_hash[32];
	bool approved;
	uint8_t signature_length;
	bool permission_denied;
	AddressHandle ah;
	Signature message_buffer;
	WalletErrors wallet_return;
	clearOutputsSeen();
	response = parseTransaction(sig_hash, transaction_hash, stream->bytes_left);
	payload_length -= stream->bytes_left;
	stream->bytes_left = 0;
	if (response != TRANSACTION_NO_ERROR)
	{
		writeFailureString(STRINGSET_TRANSACTION, (uint8_t)response);
		return true;
	}
	approved = false;
	if (prev_transaction_hash_valid)
	{
		if (bigCompare(transaction_hash, prev_transaction_hash) == BIGCMP_EQUAL)
			approved = true;
	}
	if (!approved)
	{
		permission_denied = buttonInterjection(ASKUSER_SIGN_TRANSACTION);
		if (!permission_denied)
		{
			approved = true;
			memcpy(prev_transaction_hash, transaction_hash, 32);
			prev_transaction_hash_valid = true;
		}
	}
	if (approved)
	{
		signature_length = 0;
		ah = sign_transaction.address_handle;
		if (signTransaction2(message_buffer.signature_data.bytes, &signature_length, sig_hash, ah) == WALLET_NO_ERROR)
		{
			if (sizeof(message_buffer.signature_data.bytes) < MAX_SIGNATURE_LENGTH)
				fatalError();	
			message_buffer.signature_data.size = signature_length;
			sendPacket(PACKET_TYPE_SIGNATURE, Signature_fields, &message_buffer);
		}
		else
		{
			wallet_return = walletGetLastError();
			translateWalletError(wallet_return);
		}
	}
	return true;
}
bool signTransactionCallback ( pb_istream_t * stream , const pb_field_t * field , void * * arg ) { TransactionErrors response ; uint8_t sig_hash [ 32 ] ; uint8_t transaction_hash [ 32 ] ; bool approved ; uint8_t signature_length ; bool permission_denied ; AddressHandle ah ; Signature message_buffer ; WalletErrors wallet_return ; clearOutputsSeen ( ) ; response = parseTransaction ( sig_hash , transaction_hash , stream -> bytes_left ) ; payload_length -= stream -> bytes_left ; stream -> bytes_left = 0 ; if ( response != TRANSACTION_NO_ERROR ) { writeFailureString ( STRINGSET_TRANSACTION , ( uint8_t ) response ) ; return true ; } approved = false ; if ( prev_transaction_hash_valid ) { if ( bigCompare ( transaction_hash , prev_transaction_hash ) == BIGCMP_EQUAL ) approved = true ; } if ( ! approved ) { permission_denied = buttonInterjection ( ASKUSER_SIGN_TRANSACTION ) ; if ( ! permission_denied ) { approved = true ; memcpy ( prev_transaction_hash , transaction_hash , 32 ) ; prev_transaction_hash_valid = true ; } } if ( approved ) { signature_length = 0 ; ah = sign_transaction . address_handle ; if ( signTransaction2 ( message_buffer . signature_data . bytes , & signature_length , sig_hash , ah ) == WALLET_NO_ERROR ) { if ( sizeof ( message_buffer . signature_data . bytes ) < MAX_SIGNATURE_LENGTH ) fatalError ( ) ; message_buffer . signature_data . size = signature_length ; sendPacket ( PACKET_TYPE_SIGNATURE , Signature_fields , & message_buffer ) ; } else { wallet_return = walletGetLastError ( ) ; translateWalletError ( wallet_return ) ; } } return true ; }
nanopb field callback for signature data of SignTransaction message.
nanopb field callback for signature data of SignTransaction message .
//uint8_t private_key[32]; /* Validate transaction and calculate hashes of it*/ /*
	 * parseTransaction() always reads transaction_length bytes, even if parse
	 * errors occurs. These next two lines are a bit of a hack to account for
	 * differences between streamGetOneByte() and pb_read(stream, buf, 1).
	 * The intention is that transaction.c doesn't have to know anything about
	 * protocol buffers.
	 */ /* Transaction parse error. */ /* Get permission from user. */ /* Does transaction_hash match previous approved transaction? */ /*
		 * Need to explicitly get permission from user.
		 * The call to parseTransaction() should have logged all the outputs
		 * to the user interface.
		 */ /* User approved transaction. */ // if (approved) // { // 	/* Okay to sign transaction. */ // 	signature_length = 0; // 	ah = sign_transaction.address_handle; // 	if (getPrivateKey(private_key, ah) == WALLET_NO_ERROR) // 	{ // 		if (sizeof(message_buffer.signature_data.bytes) < MAX_SIGNATURE_LENGTH) // 			fatalError();	/* This should never happen. */ // 		signTransaction(message_buffer.signature_data.bytes, &signature_length, sig_hash, private_key); // 		message_buffer.signature_data.size = signature_length; // 		sendPacket(PACKET_TYPE_SIGNATURE, Signature_fields, &message_buffer); // 	} // 	else // 	{ // 		wallet_return = walletGetLastError(); // 		translateWalletError(wallet_return); // 	} // } /* Okay to sign transaction. */ /* This should never happen. */