From eca1621568172756c92ee843737c31e7098eed9c Mon Sep 17 00:00:00 2001 From: Danny Cho Date: Thu, 12 Oct 2023 15:33:01 +1300 Subject: [PATCH 1/4] feat: handling null response from navigator.credentials.create --- packages/biometric-ed25519/package.json | 2 +- packages/biometric-ed25519/src/index.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/biometric-ed25519/package.json b/packages/biometric-ed25519/package.json index d846d51fcb..6941767de5 100644 --- a/packages/biometric-ed25519/package.json +++ b/packages/biometric-ed25519/package.json @@ -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": { diff --git a/packages/biometric-ed25519/src/index.ts b/packages/biometric-ed25519/src/index.ts index 4076e1fb94..111fc4be71 100644 --- a/packages/biometric-ed25519/src/index.ts +++ b/packages/biometric-ed25519/src/index.ts @@ -51,6 +51,11 @@ export const createKey = async (username: string): Promise => { setBufferIfUndefined(); return navigator.credentials.create({ publicKey }) .then(async (res) => { + if (!res) { + alert('Passkey process was cancelled, retry to continue account setup.'); + throw new Error('Fail to retrieve respnose from navigator.credentials.create'); + } + const result = await f2l.attestation({ clientAttestationResponse: res, origin, From 6a67ce35a688c6cfa4105adf0e3b06fff19f0892 Mon Sep 17 00:00:00 2001 From: Danny Cho Date: Thu, 12 Oct 2023 16:04:08 +1300 Subject: [PATCH 2/4] chore: changeset update --- .changeset/nice-worms-arrive.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nice-worms-arrive.md diff --git a/.changeset/nice-worms-arrive.md b/.changeset/nice-worms-arrive.md new file mode 100644 index 0000000000..f70e8e5881 --- /dev/null +++ b/.changeset/nice-worms-arrive.md @@ -0,0 +1,5 @@ +--- +"@near-js/biometric-ed25519": minor +--- + +Handing null response on create key flow From e8e33166562ea1d7e0c54408e1c1da696d781253 Mon Sep 17 00:00:00 2001 From: Danny Cho Date: Wed, 25 Oct 2023 15:08:05 +1300 Subject: [PATCH 3/4] fix: error handling on createKey call --- packages/biometric-ed25519/src/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/biometric-ed25519/src/index.ts b/packages/biometric-ed25519/src/index.ts index 111fc4be71..bfd8e0c98e 100644 --- a/packages/biometric-ed25519/src/index.ts +++ b/packages/biometric-ed25519/src/index.ts @@ -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 => { const cleanUserName = validateUsername(username); if (!f2l.f2l) { @@ -52,8 +59,7 @@ export const createKey = async (username: string): Promise => { return navigator.credentials.create({ publicKey }) .then(async (res) => { if (!res) { - alert('Passkey process was cancelled, retry to continue account setup.'); - throw new Error('Fail to retrieve respnose from navigator.credentials.create'); + throw new PasskeyProcessCanceled('Failed to retrieve response from navigator.credentials.create'); } const result = await f2l.attestation({ From e9005e4cca6eae59429e092dca1a4d3e0a5b1502 Mon Sep 17 00:00:00 2001 From: Danny Cho Date: Wed, 25 Oct 2023 15:10:00 +1300 Subject: [PATCH 4/4] chore: lint fixes --- packages/biometric-ed25519/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/biometric-ed25519/src/index.ts b/packages/biometric-ed25519/src/index.ts index bfd8e0c98e..b67ce0990e 100644 --- a/packages/biometric-ed25519/src/index.ts +++ b/packages/biometric-ed25519/src/index.ts @@ -37,7 +37,7 @@ function setBufferIfUndefined() { export class PasskeyProcessCanceled extends Error { constructor(message) { super(message); - this.name = "PasskeyProcessCanceled"; + this.name = 'PasskeyProcessCanceled'; } }