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

TypeError: data.readUIntBE is not a function #37

Closed
zxpectre opened this issue Jul 6, 2023 · 13 comments
Closed

TypeError: data.readUIntBE is not a function #37

zxpectre opened this issue Jul 6, 2023 · 13 comments

Comments

@zxpectre
Copy link

zxpectre commented Jul 6, 2023

Hi, we are currently hitting TypeError: data.readUIntBE is not a function error when calling basic methods like ledgerAppAda.getSerial() and ledgerAppAda.getVersion(), testing on a Nano S.

Aparently on this too lines:

return data.readUIntBE(0, 2) as Uint16_t

and

return data.readUIntBE(0, 4) as Uint32_t

We are using version @cardano-foundation/[email protected]
and because of too many dependencies to keep we are stuck in an old react-scripts 4 and node, npm versions old as well.

Is there any workaround to this posible rather than updating everything on our side please?
Big project, small community team here!

Downgrading to @cardano-foundation/[email protected] is incompatible with latest Ledger Cardano App

@refi93
Copy link
Collaborator

refi93 commented Jul 7, 2023

the code you are referencing was present also in version 5 of this lib:

return data.readUIntBE(0, 2) as Uint16_t
Are you sure your app would work with v5?

To pinpoint the actual issue I'd suggest trying to debug the data variable by adding console.log() into the lib (the compiled js, should be +- straightforward to get the right place, the code shouldn't be obfuscated) in node_modules around the place where the error happens and it should be clear from it what kind of object (apparently not a Buffer, otherwise it would have the method available) is entering the functions which should help you pinpoint the root cause on your end. I'd suspect something weird going on with the Buffer polyfill/webpack config around Buffer on the project level

@zxpectre
Copy link
Author

Hi @refi93, thanks for the answer, thought I had replied to you already, srry.
Finally downgrading to
"@cardano-foundation/ledgerjs-hw-app-cardano": "^5.1.0",
worked fine.

Still will be facing this in the future i guess, need to spend more time to deal with it.

@janmazak
Copy link
Collaborator

janmazak commented Aug 5, 2023

I'm closing this for now since I don't see what we can do to improve the situation (we also have limited resources).

@janmazak janmazak closed this as completed Aug 5, 2023
@hedi-edelbloute
Copy link

Hello, it seems like we have the same problem when trying to update version from 5 to 6 on Ledger Live mobile

Weirdly no error on Ledger Live desktop, we use a require to add buffer lib so it might be related to it, I am investigating

@janmazak
Copy link
Collaborator

@janmazak janmazak reopened this Jan 22, 2024
@hedi-edelbloute
Copy link

hedi-edelbloute commented Jan 29, 2024

Hey @janmazak,

Thanks to the investigation of Strica, we found out that the culprit is subarray method. Buffer.subarray returns UInt8Array instead of Buffer, so data.readUIntBE is undefined. This only happens in our Ledger Live Mobile usage and not on Ledger Live Desktop.

This is not expected behavior, see :
feross/buffer#260
feross/buffer#263
feross/buffer#329

Subarray usage has been introduced in v6 and is not present in v5, that's why we had no problem until now.

I don't know what's really causing the difference between those environments but maybe it's related to int64-buffer, "It uses Buffer on Node.js and Uint8Array on modern Web browsers" as stated in the readme

Since v7 uses subarray aswell, I am confident we will have the issue.

Maybe we could go back and use slice instead of subarray ?

Have a nice day

@janmazak
Copy link
Collaborator

janmazak commented Feb 1, 2024

@hedi-edelbloute
Do I understand correctly that the following change would solve the problem?
https://github.com/vacuumlabs/ledgerjs-cardano-shelley/pull/204/files
Or perhaps other instances of subarray should be replaced too? (I don't have anything to reproduce it with, so have to rely on your input; then I can do a new release.)

@hedi-edelbloute
Copy link

Hey @janmazak that's it, other instances should be replaced too, thanks !

@janmazak
Copy link
Collaborator

janmazak commented Feb 2, 2024

The issue should be fixed in 7.0.1:
https://www.npmjs.com/package/@cardano-foundation/ledgerjs-hw-app-cardano/v/7.0.1
Please try it.

@hedi-edelbloute
Copy link

Hey @janmazak, thanks

Can you please provide a fix for version 6 ? We did not do the required evolutions yet to support v7

v6 is already ready but has been reverted because of this issue

@janmazak
Copy link
Collaborator

janmazak commented Feb 7, 2024

@hedi-edelbloute
Try: https://www.npmjs.com/package/@cardano-foundation/ledgerjs-hw-app-cardano/v/6.0.1
(should be v6 with subarray replaced with slice).

@hedi-edelbloute
Copy link

Hi @janmazak , it fixed our issues on mobile (iOS & Android), thank you very much !

Have a nice weekend :)

@hedi-edelbloute
Copy link

FYI @zxpectre

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

No branches or pull requests

4 participants