0

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.

miketery
  • 111
  • 1
  • 7

1 Answers1

0

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

Laurenz Honauer
  • 254
  • 1
  • 12
  • In this example here https://github.com/bitcoinjs/tiny-secp256k1#examples (see React App) they get it to work for web. So I think it should execute fine. I think it has something to do with browserify https://github.com/bitcoinjs/bitcoinjs-lib#browser they mention iOS too, so should be ok with RN. I just don't know how browserify works. – miketery May 23 '22 at 20:12