-
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
feat: add cns-js library #80
base: main
Are you sure you want to change the base?
Conversation
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.
This is the main file where the client logic lives, every other file is just boilerplate and less important.
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.
Would it be possible to add a test for this functionality to CI? (potentially in a follow-up PR)
} | ||
} | ||
|
||
function normalizeDomain(domain: string): string { |
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.
I opted to make these normalization functions pretty resilient, so you can lookup NC record for any of the following:
.foo.icp.
foo.icp.
foo.icp
.icp.
.icp
icp.
Sub domains like foo.bar.icp
should also work with the same variations of .
pre/post fixes.
And similarly you can lookup the CID record for any of the following:
.sub.icp.
sub.icp.
sub.icp
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.
Nice!
nits:
- maybe this function should be a part of
utils.ts
? - would it be possible to add some unit tests for this function? (a follow-up PR would be also fine)
public async lookupCanisterId(domain: string): Promise<Principal> { | ||
const normalizedDomain = normalizeDomain(domain); | ||
const existingCanisterId = this.#canisterIds.get(normalizedDomain); | ||
if (isNotNil(existingCanisterId)) { |
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.
This is just a very simple cache that doesn't persist between page loads.
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.
This is just some utils
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.
And the rest is boilerplate nonsense
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, thanks!
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.
Would it be possible to add a test for this functionality to CI? (potentially in a follow-up PR)
} | ||
} | ||
|
||
function normalizeDomain(domain: string): string { |
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.
Nice!
nits:
- maybe this function should be a part of
utils.ts
? - would it be possible to add some unit tests for this function? (a follow-up PR would be also fine)
This has been tested with a TS script as follows:
The CNS Root and TLD Operator were setup and configured with a TLD and domain manually.