near / near-api-js

JavaScript library to interact with NEAR Protocol via RPC API
https://near.github.io/near-api-js
MIT License
388 stars 240 forks source link

Biometric createKey failing with Bitwarden password manager "expected ‘id’ or ‘rawId’ field" #1330

Closed SurgeCode closed 2 months ago

SurgeCode commented 3 months ago

Prerequisites

Description

When calling the createKey() method with the Bitwarden password manager extension that uses passkey the crendetials Id seems to have an incorrect format causing an error

telegram-cloud-photo-size-4-5796583529239396695-y

On the left side you see a working payload that contains an ArrayBuffer and on the right side a Uint8Array

Reproducible demo

No response

Steps to reproduce

  1. Install bitwarden password manager extension
  2. Call createKey() method

Expected behavior

Create key should not throw an error

Actual behavior

“Error: Type error: expected ‘id’ or ‘rawId’ field of request to be ArrayBuffer, got rawId object and id string”

Your environment

No response

Self-service

hcho112 commented 3 months ago

Hello @SurgeCode thank you for reporting this. So I have conduct a small experiment on this in my local environment and try to focus on the error message: Error: Type error: expected ‘id’ or ‘rawId’ field of request to be ArrayBuffer, got rawId object and id string

The ones that are currently working:

There is slight difference, but we can see that rawId is in ArrayBuffer

Not working:

In here, 'rawId' is in Uint8Array format where it aligns with error message. So I have taken the investigation further and see what it should be: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential/rawId In terms of definition, it is expecting ArrayBuffer NOT Uint8Array.

So at this point, Bitwarden is mutating the format that is set by W3C standard.

I will continue to seek for solution on getting Bitwarden working by injecting a thin logic to re-construct fido2 friendly format

hcho112 commented 3 months ago

Progress update: I manage to get the creation working via data format conversion. However using them to sign in isn't working with no error. (1Password works with signin flow as well)

Will continue investigate the issue on sign in..

hcho112 commented 3 months ago

I have created PR for the solution. Basically Bitwarden converts some of the properties from ArrayBuffer to Uint8Array and it was simple enough to convert them back.

Once this PR gets merged and deployed, then I will update fast-auth-signer package with latest version and from there, it should work as expected.

Will continue to update on this PR

hcho112 commented 3 months ago

If you are using @near-js/biometric-ed25519 directly, please update the version number to 1.1.2 and try above issue again. If it is not fixed, please let me know. (If it works for you, please also leave a comment here if then, will lose this issue)

We will also aim to update fast-auth-signer soon.

vikinatora commented 2 months ago

@SurgeCode we just release a new version of biometric package(@near-js/biometric-ed25519@1.2.1). Can you see if this issue is resolved?

hcho112 commented 2 months ago

Since there was no further feedback, will close this ticket.