I had 2 quick ques. I'm trying to use the monero PHP library to decrypt a transaction pulled from a block explorer so that I can avoid sending my private view key to 3rd parties.
(We'd add a box for the user to submit their own transaction IDs after paying, and store admins can load txids from their own RPC wallets every 2 days or so since our script won't be checking every new transaction. But this way we wouldn't have to set up an RPC client on public facing servers.) We'd only be pulling encrypted transactions from 3rd parties, and ideally (optionally) we'd like to have some way of knowing, in addition to the transaction being ours and the amount, being able to validate the transaction signature and being able to validate its inclusion in a block. Setting up additional lservers to run all these RPCs properly added a lot of project complexity; A third party at worst would only have the list of addresses we checked but wouldn't know whether we were able to decrypt it.
use MoneroIntegrations\MoneroPhp\Cryptonote;
use MoneroIntegrations\MoneroPhp\ed25519;
require_once('Cryptonote.php');
require_once('ed25519.php');
require_once('SHA3.php');
require_once('base58.php');
require_once('Varint.php');
$cn = new Cryptonote();
$tx = json_decode(file_get_contents('https://moneroblocks.info/api/get_transaction_data/insert txid here'), true);
$extra = implode(array_map(function($x){ return str_pad(dechex($x), 2, '0', STR_PAD_LEFT); }, $tx['transaction_data']['extra']));
$derived = $cn->gen_key_derivation($cn->txpub_from_extra($extra), 'insert private view key here');
if( $cn->derive_public_key($derived, 'transaction ioutput index', 'insert public spend key here') == $tx['transaction_data']['vout'][0]['target']['key']){
`$sec1 = $cn->derivation_to_scalar($derived, 'transaction ioutput index');`
`$sec2 = $cn->hash_to_scalar($sec1);`
`$ec = new ed25519();`
`echo bcsub($ec->decodeint(hex2bin($tx['transaction_data']['rct_signatures']['ecdhInfo'][0]['mask'])), $ec->decodeint(hex2bin($sec1)));`
`echo bcsub($ec->decodeint(hex2bin($tx['transaction_data']['rct_signatures']['ecdhInfo'][0]['amount'])), $ec->decodeint(hex2bin($sec2)));`
}
This sample code given a public spend key/private view key/transaction ID, checks whether any output belongs to us.
1- How are subaddresses handled? From this code so far my best guess is just looping through the public spend keys of all subaddresses but I assume that isn't correct.
2- How do I decode amounts? It seems like there's a few variations of it, I'd want to support both the 64 character long mask/amount as well as the 16 character long amount; most examples I've seen seem to be incomplete or missing portions of the code.
3- Is there a good way to sanity check the received transactions? (so we limit the 3rd party API to only possibly omitting transactions, but make sure they aren't able to send fake transactions). In Bitcoin both of these checks are easy to implement using the merkle hash system, and EC signatures likewise easy to validate.
4- Is there a proper anonymous light wallet API I could use to just query for the encrypted tx info from the network? similar to the Electrum rpc API for Bitcoin.