Bitcoinjs-lib: React-native use RELEASE scheme crash, HDNode.fromSeedBuffer

Created on 22 Feb 2018  路  5Comments  路  Source: bitcoinjs/bitcoinjs-lib

React-native, iOS, RELEASE

Hi, I got a crash on iOS platform only use release scheme.

function generatorBIP44() {
    const mnemonic = bip39.generateMnemonic();
    assert(bip39.validateMnemonic(mnemonic));

    const seed = bip39.mnemonicToSeed(mnemonic);
    const bitcoinNetwork = bitcoin.networks.bitcoin;
    const master = bitcoin.HDNode.fromSeedBuffer(seed, bitcoinNetwork);

    const derivePath = `m/44'/0'/0'/0/0`;
    const node = master.derivePath(derivePath);

    const keyPair = node.keyPair;

    const privateKey = keyPair.toWIF();

    const publicKeyBuffer = keyPair.getPublicKeyBuffer();
    const publicKey = publicKeyBuffer.toString('hex');

    const address = keyPair.getAddress();

    return {
        mnemonic,
        address,
        privateKey,
        publicKey,
    };
}

I found crash here

    const master = bitcoin.HDNode.fromSeedBuffer(seed, bitcoinNetwork);

    typeforce(types.tuple('ECPair', types.Buffer256bit), arguments)

If i remove typeforce check code, it's OK.

It's amazing when i run it OK on debug scheme, but always crash on release scheme.
Someone please help me?
Thx.

how to / question / docs

Most helpful comment

Thx, and I fixed this issue.

Modify node_modules/metro-bundler/src/JSTransformer/worker/minify.js

mangle: {
      toplevel: true,
      reserved: [
        'Buffer',
        'BigInteger',
        'Point',
        'ECPubKey',
        'ECKey',
        'sha512_asm',
        'asm',
        'ECPair',
        'HDNode'
      ]
    },

All 5 comments

Read the README, please.

Add reserve rules to uglifyjs.

Thx, and I fixed this issue.

Modify node_modules/metro-bundler/src/JSTransformer/worker/minify.js

mangle: {
      toplevel: true,
      reserved: [
        'Buffer',
        'BigInteger',
        'Point',
        'ECPubKey',
        'ECKey',
        'sha512_asm',
        'asm',
        'ECPair',
        'HDNode'
      ]
    },

@dabura667 hopefully this is less of an issue in 4.0.0.

where the "README" talk about "uglifyjs"?

@JamesZhange Currently released version is 3.3.2

https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/README.md

NOTE: If you uglify the javascript, you must exclude the following variable names from being mangled: BigInteger, ECPair, Point. This is because of the function-name-duck-typing used in typeforce.

Example:

uglifyjs ... --mangle reserved=['BigInteger','ECPair','Point']

NOTE: This library tracks Node LTS features, if you need strict ES5, use --transform babelify in conjunction with your browserify step (using an es2015 preset).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

silence-may picture silence-may  路  3Comments

askucher picture askucher  路  3Comments

ghost picture ghost  路  3Comments

hoshsadiq picture hoshsadiq  路  3Comments

dcousens picture dcousens  路  3Comments