@jonny Yeah, so that is doable and actually should be a fairly standard thing for API clients to do, e.g. if they want to load raw data from the origin PDS, or have a login form and want to know what PDS to log into.
I wrote a pseudo-Ruby overview of the algorithm here: https://gist.github.com/mackuba/a6c2a922be8895c2b82c93e54272b86d, and an initial version of a library that does it here: https://github.com/mackuba/didkit/blob/master/lib/didkit/did.rb (I'm not using it yet because right now you can still get away with just calling bsky.social which proxies to actual PDSes).
@mackuba
How many profile take this path instead of the web method and why is it 99.9%
https://gist.github.com/mackuba/a6c2a922be8895c2b82c93e54272b86d#file-proper_way-rb-L15