UserIdentity currently cannot fully represent the identity of users from another wiki: it cannot expose the user's ID on that wiki (see T222212: RevisionStore must not expose user IDs from a foreign wiki), and there is no good way to distinguish "local" from "remote" users.
The primary issue is that UserIdentity::getId (which inherites the usage and semantics of User::getId) is currenty interpreted to return a user ID on the local wiki. Returning from this method an ID that related to another wiki's database might be very confusing. Just adding a getWikiId() (or getDBDomain) method on UserIdentity will not fix this, since existing callers would be unaware that they need to check the new method.
One (somewhat hacky) option would be to return a string from getId(), and add a prefix to that string when the ID refers to a user from another wiki. We are already doing something similar with user names from imports, see https://gerrit.wikimedia.org/r/c/mediawiki/core/+/386625 (T111605, T20209, T9240). This would be backwards compatible thanks to the fact that PHP will interpret non-numerical strings as 0 when used in a numerical context. Though this would require user IDs to always cast to int before comparisons, or comparisons to use == and not ===.
A cleaner solution would be to leave getId() to return only local user IDs, and introduce new methods for the user's ID "at home". Finding good names may be tricky, though.