-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add utilities for principal type identification #127
Conversation
@rvanasa tagging for review when time permits, no rush! |
6201d7d
to
6456946
Compare
Thank you for the PR! We are looking this over internally (might be some delays due to time zone differences, etc). A few quick notes:
|
src/Principal.mo
Outdated
public func isSelfAuthenticating(p: Principal) : Bool { | ||
let byteArray = toByteArray(p); | ||
|
||
byteArray.size() <= 29 and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops, need to fix this to be
byteArray.size() <= 29 and | |
byteArray.size() == 29 and |
…g principal condition to be 29 bytes
af86235
to
4e8c4dd
Compare
Done!
Rebased and added. Note that we've been using a mix of https://github.com/aviate-labs/testing.mo and matchers in our testing. These tests should be easy enough to move over to matchers if you'd prefer everyone use that library. The testing library does have some significant advantages in being able to mock async behavior (say if you wanted to test out async library additions, such as parallel futures, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I like the idea of gradually migrating the base library to use testing.mo
in place of matchers
.
As we already have
Principal.isAnonymous()
, it's a pretty standard use case to want to know if a call was made by an opaque, self identifying, or reserved principal.This has been asked for by a few different developers on the forum, and comes up in our code often.
You may want to consider whether or not to rename
isCanister()
toisOpaque()
, although I believeisCanister()
reads better. The documentation doesn't provide cases where non-canister ids are opaque.We also have our own test suite here (this code if from a util package that we have) with the following cases (all pass)