There should be an API to get an unspecified public key compatible with the current TLS version.
It should be rate-limited and should look something like this:
var key;
try {
key = make_pubkey(username);
send_key_to_server(key);
} catch (e) {
alert("you're doing that too much");
}
And then the server can associate the key with the user account, eliminating the need for logins. The browser should automatically use the key on next visit to the server, and may provide choice for multiple keys, but preferably should try every key and the server may provide a choice for all identities it detects.
It should only be available on HTTPS ofc.
Malicious scripts can generate keys but considering the rate limit + the extra keys don’t do anything except slow down loading slightly, and they can’t access the private keys at all, this should be just fine.
(Alternatively shove this into HTTPS headers somehow. That could be (more) dangerous on public computers tho, if they’re configured to auto-accept all public key generation, as you’d expect the user to “link current computer” from a settings/preferences pane.)