Principal
Reference for mo:core/Principal in the core library.
Principal is the IC identity type used for callers, canisters, and ownership
checks. The comparison helpers are useful when principals become map keys or
when a contract needs explicit ordering facts.
Import
mo:core/Principal
Status
- Runtime module
Public API
Types
Principal
Functions
fromBlob(blob : Blob) : Principal
Converts between the module type and the target representation.
Use when: crossing between this module's value and another representation.
toBlob(p : Principal) : Blob
Converts between the module type and the target representation.
Use when: crossing between this module's value and another representation.
toText(p : Principal) : Text
Returns the canonical textual principal id.
Use when: converting a principal into the text accepted by actor references,
for example actor(Principal.toText(canisterId)).
ofActor(a : actor {}) : Principal
Returns the principal associated with an actor reference.
Use when: code or specifications need this operation with the documented contract.
compare(principal1 : Principal, principal2 : Principal) : Types.Order
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == #less ==> principal1 < principal2;
ensures result == #equal ==> principal1 == principal2;
ensures result == #greater ==> principal2 < principal1;
ensures principal1 < principal2 ==> result == #less;
ensures principal1 == principal2 ==> result == #equal;
ensures principal2 < principal1 ==> result == #greater;
Use when: code or contracts need an explicit comparison helper instead of an operator.
equal(principal1 : Principal, principal2 : Principal) : Bool
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == (principal1 == principal2);
Use when: code or contracts need an explicit comparison helper instead of an operator.
notEqual(principal1 : Principal, principal2 : Principal) : Bool
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == (principal1 != principal2);
Use when: code or contracts need an explicit comparison helper instead of an operator.
less(principal1 : Principal, principal2 : Principal) : Bool
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == (principal1 < principal2);
Use when: code or contracts need an explicit comparison helper instead of an operator.
lessOrEqual(principal1 : Principal, principal2 : Principal) : Bool
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == (principal1 < principal2 or principal1 == principal2);
Use when: code or contracts need an explicit comparison helper instead of an operator.
greater(principal1 : Principal, principal2 : Principal) : Bool
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == (principal2 < principal1);
Use when: code or contracts need an explicit comparison helper instead of an operator.
greaterOrEqual(principal1 : Principal, principal2 : Principal) : Bool
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == (principal2 < principal1 or principal1 == principal2);
Use when: code or contracts need an explicit comparison helper instead of an operator.
Summary
- Runtime module under
mo:core/Principal. - Exposes 11 public functions.