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"))
};
4 Likes

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

4 Likes

Yes please. That would be helpful.

@Motokoder It’s there, now slightly modified: https://github.com/dfinity/motoko-base/blob/9947712f044ff5d535b0390389bd63992668875c/src/Principal.mo#L26

2 Likes

Wonderful! Thank you. :slight_smile:

1 Like