I was just wondering what function does the public keys in a wallet address have in creating a transaction or receiving a transaction from someone?
You have a public and private spend key, and a public and private view key.
The public spend and view keys are used to create an output that only you can see that exists, and that only you can spend.
You use your private view key and public spend key to detect the existence of that output.
You use your private view key and private spend key to spend the output.
In algebra, your public view and spend keys are
Your private view and spend keys are
The output created for you is
P = Hs(rA)G+B, where
r is a random value known only to the sender.
You detect it by calculating
P' = Hs(aR)G+B, and checking if
R is a value published with the transaction, and is calculated as
rG. Note that just as
Hs() is a hashing function that returns a type of number called a scalar).
The reason that
P'==P is because
rA==arG==aR, and this is called an Elliptic Curve Diffie Hellman Exchange.
P is actually a public key, for which you need the corresponding output private key to spend.
The corresponding output private key is
x = Hs(aR) + b, according to the laws of Elliptic Curve Cryptography algebra.
P is also known as a stealth address, because it is a one-time value written into the blockchain instead of your wallet address being written into the blockchain (as it would be in Bitcoin). An observer cannot determine that
P is linked to your public view or spend keys, because this can only be determined if your private view key
a is known.