V0.5.0 added principalId to the standard library allowing you to work with a shared function’s {caller} object, here’s an example retrieving an external caller’s id:
import PrincipalId "mo:stdlib/principalId";
import Hash "mo:stdlib/hash";
import Prim "mo:prim";
type Id = Hash.Hash;
actor {
func getUserId(user: Principal) : Id {
return PrincipalId.hash(user);
};
public shared x func main() {
Prim.debugPrint(debug_show( getUserId(x.caller) ));
};
};