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

Invalid checksum on iOS devices #769

Closed
coreyphillips opened this issue Mar 25, 2017 · 8 comments · Fixed by #770
Closed

Invalid checksum on iOS devices #769

coreyphillips opened this issue Mar 25, 2017 · 8 comments · Fixed by #770
Labels

Comments

@coreyphillips
Copy link

I'm currently receiving the following error on an iOS device for a React Native project ("Invalid checksum"). The error is triggered when attempting to use the following:

const HDNode = require("./bitcoinjs-lib/src/hdnode");
const xpub = "xpub6AoynT2YixgjHK2yNTDPJGmbFaNfiKTVNb4zVygVmSfhWktotj8woL2nT7FALSFEhggNemiy5KEGWxRpNYtsHVVvWCC99WuhzvAvZTJD1SH";
let node = HDNode.fromBase58(xpub);

The error appears to be coming from base58check.decode where decodeRaw doesn't pass the checksum check.

One important thing to note is that this error does not occur within the iOS simulator, Android emulator or on an Android device. It appears to be isolated to iOS devices only. Does anyone have any thoughts as to why this error seems to only pop up on iOS devices?

screen shot 2017-03-25 at 4 42 32 pm

@dcousens
Copy link
Contributor

dcousens commented Mar 26, 2017

Check your sha implementation.
Specifically, run the tests in https://github.com/crypto-browserify/sha.js on device and see what happens.

Probably something related to Buffer being treated as 0 somewhere...

@dcousens
Copy link
Contributor

What iOS version?
And how have you shimmed Buffer for react-native?

@dcousens dcousens added the bug label Mar 26, 2017
@coreyphillips
Copy link
Author

I'm currently using iOS v10.2 and rn-nodeify to shim buffer.

Thanks for the suggestions, dcousens. After some more digging, I'm fairly certain I know where the issue is coming from. It appears that iOS does not want to slice the buffer in bs58check's decodeRaw. Specifically, var payload = buffer.slice(0, -4) does not appear to be called at all on iOS resulting in the invalid checksum error. Currently looking into possible workarounds, but that behavior is throwing me for loop.

@coreyphillips
Copy link
Author

Got it!
I found the solution here (feross/buffer#136). It appears that iOS 10 devices have difficulty with buffer.slice. To resolve this issue I had to update buffer to v5.0.5.

@dcousens
Copy link
Contributor

@coreyphillips perhaps you'd be willing to PR a README note here for our users under "#browserify"?

@silence-may
Copy link

excuse me
I update my buffer to 5.1.0
howere, It still doesn't work,
what should i do ???

@Brain-tech
Copy link

Updated to 5.1.0 too and it's not working either...

@coreyphillips
Copy link
Author

@Brain-tech, I've since created a gist to help get bitcoinjs-lib working in a RN project here. Feel free to ping me if you have any trouble getting it setup.

Also, hdnode has been removed from bitcoinjs-lib. You'll want to use bip32 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants