Can someone please explain the difference between a secret and public view key. I think I get it but want to be sure I understand it correctly. Can you give me an example of how secret key would be used vs. a public key.
It's a general concept called public key cryptography common to many crypto systems including cryptocurrencies like Bitcoin and Monero. Abstractly speaking, a secret key is some random secret data of sufficient length (so that others can't reproduce it by attack or accident), and a public key is the result of some transformation of the secret key defined by the protocol:
P := COMPUTE_PUBKEY(x)
Importantly, you can't reverse-compute the secret key 'x' from the public key 'P'. Public keys are meant to be posted publicly, and in cryptocurrencies, they constitute wallet addresses.
The most critical role of the scheme for cryptocurrencies is message signing. Here, a message is essentially a transaction itself:
m := HASH("I, who owns funds assigned to these public keys, approve their transfer to those public keys")
The signer (i.e. the wallet owner) can generate some special piece of data called signature by using both the message and his secret key:
s := SIGN(m, x)
and importantly, this data satisfies the following special condition:
CHECK(m, P, s) == 1
Here, these functions (HASH, SIGN, CHECK) are all defined by the protocol. Importantly, the correct signature (with respect to a public key 'P') can be generated only by the one who knows its secret key 'x'. In other words, for any other wrong keys y != x, the resulting (fake) signature will always fail to check:
CHECK(m, P, SIGN(m, y)) == 0
Each transaction is accompanied by its signature, and each node in the network independently verifies that all the signatures are valid, ensuring the integrity of the system.
Another feature which is particularly important to Monero is key exchange (DiffieHellman, often called ECDH). This allows two parties to generate a shared secret key without ever transmitting their secret keys:
d1 := SHARED_SECRET(r, A)
d2 := SHARED_SECRET(a, R)
Here, 'a' and 'r' are secret keys and 'A' and 'R' are their corresponding public keys. Thanks to the design of the crypto scheme, 'd1' and 'd2' are guaranteed to be equal. In Monero, 'a' is the view secret key held by the receiver, and 'r' is the transaction secret key generated by the sender. This is the basis of the stealth addressing scheme which randomly generates destination public keys even when sending to the same wallet address.