Bitcoinjs-lib: Invalid checksum on iOS devices

Created on 25 Mar 2017  路  8Comments  路  Source: bitcoinjs/bitcoinjs-lib

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

bug

All 8 comments

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...

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

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.

Got it!
I found the solution here (https://github.com/feross/buffer/issues/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.

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

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

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

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

namnv04 picture namnv04  路  3Comments

thrastarson picture thrastarson  路  3Comments

panpan2 picture panpan2  路  3Comments

yakitorifoodie picture yakitorifoodie  路  3Comments

coingeek picture coingeek  路  4Comments