HD / Deterministic Wallets and public key I understand the basic concept of generating an unlimited number of public key addresses from a master public key. What I won't understand is how to get the wallet balance. Do I have to query unspent outputs for every public key in the wallet that I have generated?

Is it possible to iterate through the addresses in the utxo and determine whether they are within the public set of addresses that could be generated by the wallet?

If I hand the server a public key and it generates more on my behalf, how do I know which addresses received coin? It seems like there must be a way to determine if an address is spendable by the master key pair.

Any ideas? Seems that you would have to check the entire utxo set somehow. Much appreciated.
Clients that use an HD wallet generate a fairly large number of the keys in advance (e.g. Armory does 100 by default). When it scans the blockchain for relevant transactions, it checks for transactions to all of the keys that it's generated so far.

Typically, you do transactions off the next address in the list (there's a certain order to it, and it's easier to just generate the next one than 100 next ones). Let's say your client has generated the first 100 keys, and someone sends money to the 150th address in your list. You'd have to wait for the client to decide to generate the 150th key (probably because you hit your 50th key used and it pregenerated out to 150), or tell your client to generate out to the 150th key, and then rescan the blockchain, in order to know that you received money there.


  It seems like there must be a way to determine if an address is spendable by the master key pair.


Not necessarily: you can generate a very long series of addresses (2^32, if I'm reading BIP 0032 right) from a master key pair, but doing so would take a substantial amount of time. I'm not sure if there's a theoretical way to do what you're asking (without actually calculating all of them), but in practice it's clear that you just generate the set of addresses you think will be useful in the near future, and go from there.