Checking if Principal is anonymous in Motoko?

Is it ok to check Principal.toText(principal) == "2vxsx-fae"?
It would be helpful to have a method like Principal.isAnonymous(principal)
agent.js has such method principal.isAnonymous()

1 Like

Yes that’s fine to do, so you could just make your own small helper function…

public func isAnonymous(caller: Principal): Bool {
    Principal.equal(caller, Principal.fromText("2vxsx-fae"))
};
3 Likes

This might be a worthwhile addition to the Principal module in motoko-base.

3 Likes