Skip to content
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: added isPassKeyAvailable on biometric-ed25519 package #1139

Merged
merged 3 commits into from May 31, 2023
Merged

Conversation

hcho112
Copy link
Contributor

@hcho112 hcho112 commented May 30, 2023

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • Commit messages follow the conventional commits spec
  • If this is a code change: I have written unit tests.
  • If this changes code in a published package: I have run pnpm changeset to create a changeset JSON document appropriate for this change.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

This PR contains a new util function isPassKeyAvailable where it will be used to validate the availability of passKey usage of user's current browser.

Test Plan

I have conducted manual test on running above code on latest Chrome browser (returns promise true) vs latest Firefox (returns promise false)

@changeset-bot
Copy link

changeset-bot bot commented May 30, 2023

🦋 Changeset detected

Latest commit: 4f7f890

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@near-js/biometric-ed25519 Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Collaborator

@andy-haynes andy-haynes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one small comment on the util function

Comment on lines 118 to 121
if (!PublicKeyCredential || !PublicKeyCredential?.isUserVerifyingPlatformAuthenticatorAvailable) {
return Promise.resolve(false);
}
return PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!PublicKeyCredential || !PublicKeyCredential?.isUserVerifyingPlatformAuthenticatorAvailable) {
return Promise.resolve(false);
}
return PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
return PublicKeyCredential?.isUserVerifyingPlatformAuthenticatorAvailable?.() || false;

The return value of an async function is always a Promise, so it doesn't need to be wrapped in Promise.resolve. Also you can use optional chaining to call the PublicKeyCredential method to avoid needing to reference it more than once 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this still work if PublicKeyCredential is not available? From Ref, on WebView Android, it doesn't support at all. Assuming that PublicKeyCredential can be undefined, should we use

if (typeof PublicKeyCredential !== 'undefined') {
  return PublicKeyCredential?.isUserVerifyingPlatformAuthenticatorAvailable?.();
}
return false;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this still work if PublicKeyCredential is not available?

👍 if it's an invalid reference then it must be guarded.

Other alternatives to your solution would be a try/catch or, my personal preference, referencing via window, i.e.

return window.PublicKeyCredential?.isUserVerifyingPlatformAuthenticatorAvailable?.() || false;

@hcho112 hcho112 requested a review from andy-haynes May 30, 2023 23:46
@andy-haynes andy-haynes merged commit fece01a into master May 31, 2023
1 check passed
@andy-haynes andy-haynes deleted the ONB-87 branch May 31, 2023 00:02
@github-actions github-actions bot mentioned this pull request May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants