near-api-js icon indicating copy to clipboard operation
near-api-js copied to clipboard

Error: Length of buffer does not match length of ASN.1 sequence

Open microchipgnu opened this issue 1 year ago • 31 comments

Prerequisites

  • [X] I'm using the latest version of near-api-js.
  • [x] I have tried to start with a fresh project and reproduce the defect with minimal code changes.
  • [x] I have read the console error messages carefully (if applicable).

Description

We have several users using Chromium-based browsers (v120+) like Brave, Chrome and Edge on Windows machines.

We integrated @near-js/biometric-ed25519 and the getKeys method throws an error when executed in this environment.

Reproducible demo

https://wallet.mintbase.xyz

Steps to reproduce

  1. Open any browser based on Chromium (v120+) on a Windows machine
  2. Create an account (this should work)
  3. Try signing any transaction with the wallet

Expected behavior

Not to throw an error and return keys.

Actual behavior

Error: Length of buffer does not match length of ASN.1 sequence.
at V.parse (4011-d66488a438fc0322.js:477:36669)
at 4011-d66488a438fc0322.js:470:51173
at Generator.next (<anonymous>)
at 4011-d66488a438fc0322.js:470:49049
at new Promise (<anonymous>)
at en (4011-d66488a438fc0322.js:470:48830)
at 4011-d66488a438fc0322.js:470:50853
at async i (page-4ae5a0be2a9f3743.js:1:20136)
at async sendTransaction (page-4ae5a0be2a9f3743.js:1:15438)
at async send (page-4ae5a0be2a9f3743.js:1:16668) 'error'

Your environment

  • NEAR JavaScript API version used: 1.0.1
  • Frontend framework (if applicable): NextJS (client rendered component)
  • OS: Windows

Self-service

  • [ ] I'd be willing to fix this bug myself.

microchipgnu avatar Jan 10 '24 13:01 microchipgnu

Hey @microchipgnu, we have updated the package, the problem should be solved.

gtsonevv avatar Jan 11 '24 09:01 gtsonevv

Thanks @gtsonevv we are testing now.

microchipgnu avatar Jan 11 '24 10:01 microchipgnu

Hey @gtsonevv we are seeing a new error now. This happens on all devices now.

Error: r must be 0 < r < CURVE.n 
    at eO.assertValidity (6887-25fc58e43eeff16f.js:471:77431)
    at new eO (6887-25fc58e43eeff16f.js:471:77159)
    at 6887-25fc58e43eeff16f.js:470:54149
    at Generator.next (<anonymous>)
    at 6887-25fc58e43eeff16f.js:470:52568
    at new Promise (<anonymous>)
    at en (6887-25fc58e43eeff16f.js:470:52349)
    at em (6887-25fc58e43eeff16f.js:470:54012)
    at 6887-25fc58e43eeff16f.js:470:51450
    at Generator.next (<anonymous>) 'error'

microchipgnu avatar Jan 11 '24 11:01 microchipgnu

Hey @microchipgnu, we will investigate why this is happening.

gtsonevv avatar Jan 11 '24 12:01 gtsonevv

@microchipgnu, is this error coming from the getKeys method again?

gtsonevv avatar Jan 11 '24 13:01 gtsonevv

Hey @microchipgnu, could you provide a minimal reproducible example of the issue?

vikinatora avatar Jan 11 '24 14:01 vikinatora

Yes.

https://near-biometric-issue-repro.vercel.app/

microchipgnu avatar Jan 12 '24 10:01 microchipgnu

Any update @vikinatora @gtsonevv?

microchipgnu avatar Jan 15 '24 11:01 microchipgnu

Hey @microchipgnu, we are still investigating the issue, please use version 2.1.4 until we resolve the issue.

gtsonevv avatar Jan 15 '24 11:01 gtsonevv

Any update?

SurgeCode avatar Jan 18 '24 12:01 SurgeCode

@SurgeCode, @microchipgnu Does the issues still persist on near-api-js v2.1.4? This issue is on our priority list, but we have a few other stuff to do, before we dive deep here. Thank you for your patience.

vikinatora avatar Jan 19 '24 07:01 vikinatora

1.0.1 -> Doesn't work on any window machines - Error: Length of buffer does not match length of ASN.1 sequence.

1.1.0 -> Doesn't work in general (all machines we tested)- Error: r must be 0 < r < CURVE.n

reproduction -> create, get, check console https://near-biometric-issue-repro.vercel.app/

This issue is quite critical for us at the moment

SurgeCode avatar Jan 19 '24 15:01 SurgeCode

Hey, no update here unfortunately. Most likely the asn-parser library is causing the issue. Replacing it would require refactoring of the existing functionality, so I can't give you an estimate of when you can expect this issue to be resolved.

vikinatora avatar Jan 23 '24 14:01 vikinatora

This seems pretty critical as it makes the library entirely unusable in a lot of cases. Could you give me some information on how much of a priority this is for your team or if we should explore our own implementation?

SurgeCode avatar Jan 23 '24 18:01 SurgeCode

It's high priority. @gtsonevv is on it.

vikinatora avatar Jan 24 '24 07:01 vikinatora

Any update?

microchipgnu avatar Feb 09 '24 12:02 microchipgnu

Hey, we’ve been investigating the issue in the past weeks. Unfortunately, no substantial progress has been made and this issue won't be a quick fix. We're researching currently what it will take to make the module working.

For the time being, please use v1.0.1 which doesn't work on Windows as per your comments.

vikinatora avatar Feb 13 '24 12:02 vikinatora

#1309 Should resolve the issue, waiting for the CI node to be back up, so that checks can pass and we will release it. Thank you for the patience.

vikinatora avatar Mar 07 '24 06:03 vikinatora

We will give this a try. Thanks!

microchipgnu avatar Mar 07 '24 09:03 microchipgnu

Please let us know if the issue is resolved. Package is @near-js/[email protected]

vikinatora avatar Mar 07 '24 13:03 vikinatora

The issue is still happening on Windows.

Tested on: Windows 11 Pro 23H2 Chrome 122.0.6261.112 Edge 122.0.2365.66

Can you please reopen the issue!

microchipgnu avatar Mar 13 '24 15:03 microchipgnu

Reproducing the issue with the transaction that Micro provided above

https://github.com/near/near-api-js/assets/408953/0ff78885-4bee-4f93-8e0a-aebe8cc4e918

starpause avatar Mar 13 '24 18:03 starpause

Seems like the issue is there, since I got the same error message. That means noone using a windows machine can transaction currently? I expect most of our users (we are addressing normies) will not be able to use this mintbase wallet then...or am I missing something? Is there a workaround?

myweb3gift avatar Mar 18 '24 16:03 myweb3gift

@vikinatora , do you want to jam on this one over a call & close this? its been a while and Mintbase is getting a lot of not-so-happy users coz of it.

vikpande avatar Mar 19 '24 15:03 vikpande

I'm also happy to contribute to get this fixed

SurgeCode avatar Mar 19 '24 16:03 SurgeCode

Contributions are more than welcome, our team has comittment on a different group of functionalities and we're trying to solve this issue with the time we have to spare between tasks.

Unfortunately, the issue here is not an easy one.

vikinatora avatar Mar 19 '24 16:03 vikinatora

My thoughts are to resolve the windows issue, the whole fido2-lib will have to be replaced with an alternative.

Regarding the signing issue, that's probably a hard to spot bug. We've not worked on the initial implementation and it's hard to debug as there are no tests for the biometric module.

vikinatora avatar Mar 19 '24 16:03 vikinatora

@starpause, @myweb3gift can you try out the logic here? I've replaced the ASN.1 parsing library, maybe that will help as I couldn't reproduce the issue on my windows machine.

In the app you just have to press the "Create and Get Key" button and check the console for errors.

vikinatora avatar Mar 20 '24 14:03 vikinatora

@vikinatora we had been chatting on telegram but thought to update the issue with my findings after you replaced the ASN.1 library.

I still get an error in console: Error initializing NEAR: Length over 48 bits not supported at position 1

https://github.com/near/near-api-js/assets/408953/9578fbf4-6dca-4fdd-b218-18691be1db08

starpause avatar Apr 03 '24 15:04 starpause

Hi, I try to log in the account with the Windows passkey, when I type the PIN it doesn't tell me it's incorrect, but it won't loge me in. Also, I have another account I'm logged on, but it's impossible to get the seed phrase. I'm using Windows 10 and latest version of Chrome. After I put the PIN, I'm back to the connection page, nothing happens. Please, advise.

image image

ssplashh avatar Apr 15 '24 21:04 ssplashh