Skip to content

Commit

Permalink
Merge pull request #1191 from near/biometric-handling-null
Browse files Browse the repository at this point in the history
feat: handling null response from navigator.credentials.create
  • Loading branch information
andy-haynes authored Oct 31, 2023
2 parents 695220e + b3617f9 commit b5dcd8a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/nice-worms-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@near-js/biometric-ed25519": minor
---

Handing null response on create key flow
2 changes: 1 addition & 1 deletion packages/biometric-ed25519/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@near-js/biometric-ed25519",
"description": "JavaScript library to handle webauthn and biometric keys",
"version": "0.3.0",
"version": "0.4.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions packages/biometric-ed25519/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ function setBufferIfUndefined() {
}
}

export class PasskeyProcessCanceled extends Error {
constructor(message) {
super(message);
this.name = 'PasskeyProcessCanceled';
}
}

export const createKey = async (username: string): Promise<KeyPair> => {
const cleanUserName = validateUsername(username);
if (!f2l.f2l) {
Expand All @@ -51,6 +58,10 @@ export const createKey = async (username: string): Promise<KeyPair> => {
setBufferIfUndefined();
return navigator.credentials.create({ publicKey })
.then(async (res) => {
if (!res) {
throw new PasskeyProcessCanceled('Failed to retrieve response from navigator.credentials.create');
}

const result = await f2l.attestation({
clientAttestationResponse: res,
origin,
Expand Down

0 comments on commit b5dcd8a

Please sign in to comment.