Error using React Native using bitcoinjs-lib and ECpair / tiny-secp256k1

2.1k Views Asked by At

I'm trying to use bitcoinjs-lib, but I get errors, I think it has to do with the explanation to use browserify.

For this:

import BIP32Factory from 'bip32';
const tinysecp = require('tiny-secp256k1')
const bip32 = BIP32Factory(tinysecp);

I get the following:

Uncaught TypeError: ecc.isPoint is not a function
    at Object.testEcc (testecc.js:5:1)
    at BIP32Factory (bip32.js:9:1)

Here's an alternative, and I get a different error:

import { Signer, SignerAsync, ECPairInterface, ECPairFactory, ECPairAPI, TinySecp256k1Interface } from 'ecpair';
const tinysecp: TinySecp256k1Interface = require('tiny-secp256k1');
const bip32: ECPairAPI = ECPairFactory(tinysecp);

Results in following error:

./node_modules/ecpair/src/ecpair.js 66:7
Module parse failed: Unexpected token (66:7)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|   }
|   class ECPair {
>     __D;
|     __Q;
|     compressed;

Separately I tried to browserify bitcoinjs-lib and ecpair, but I think I'm doing something wrong.

1

There are 1 best solutions below

1
On

I think bitcoin-js and tinysec are not going to work as is, because they are using some Node Js Core Features that are not Available at Runtime in an react-native app.

You can take a look at:

https://github.com/novalabio/react-native-bitcoinjs-lib as a substitute

or

https://gist.github.com/coreyphillips/4d45160fed016417a5f583f179c2cbdb a discussion about how to add bitcoin-js to react-native using a shim file