2

Let's assume I have an address, a secret view key for it, and a transaction. The transaction has been checked by a daemon to be valid.

How do I figure out if the transaction pays something (and how much) to the address? What are the operations I need to perform?

PS: I'm asking only about v11 and v12 protocol.

Additional info:

It's not obvious in the explanation below that some transactions have more than one pubkey. Specifically, it happens when the tx pays out to multiple subaddresses. A good explanation of what additional data should be processed is in this question

emesik
  • 620
  • 3
  • 11

1 Answers1

3

Extract the tx public key R from the tx extra field, and for each output, it's key K and index i, then using your private view key a and public spend key B, you own the output if:

Hs(8aR||i)G+B == K

To find out how much you received, take the encrypted amount e for that output index from the transaction's ecdhInfo field and decrypt:

xor8(e, keccak("amount"||Hs(8aR||i))

Note, xor8 is XOR'ing the first parameter with the first 8 bytes of the second parameter, the result is the decrypted amount.

jtgrassie
  • 19,111
  • 4
  • 14
  • 51