ethereumjs / ethereumjs-wallet

Utilities for handling Ethereum keys
MIT License
986 stars 295 forks source link

crypto library not found in ethereumjs-wallet #22

Closed helxsz closed 6 years ago

helxsz commented 6 years ago

I am importing ethereumjs-wallet in angular4,

import EthereumWallet from 'ethereumjs-wallet';
var wallet = EthereumWallet.generate();
const jsV3 = wallet.toV3(passwd);
the code inside the library shown as below
var privKey = crypto.randomBytes(32)
throws out an error

ERROR Error: Uncaught (in promise): TypeError: crypto.randomBytes is not a function TypeError: crypto.randomBytes is not a function TypeError: crypto.randomBytes is not a function at Function.webpackJsonp.../../../../ethereumjs-wallet/index.js.Wallet.generate

The same problem applies to

  var mnemonic = bip39.generateMnemonic();
  var privateKey = hdkey.fromMasterSeed(mnemonic)._hdkey._privateKey
  const wallet = EthereumWallet.fromPrivateKey(privateKey)

TradePageComponent.html:1 ERROR TypeError: crypto.createHmac is not a function at Function.webpackJsonp.../../../../hdkey/lib/hdkey.js.HDKey.fromMasterSeed (hdkey.js:162) at Function.webpackJsonp.../../../../ethereumjs-wallet/hdkey.js.EthereumHDKey.fromMasterSeed (hdkey.js:17)

how to solve the crypto library ?

fanatid commented 6 years ago

how to solve the crypto library ?

Setup webpack config properly?

helxsz commented 6 years ago

how would config webpack with angular-cli, I don't know much about webpack, any idea?

Asone commented 6 years ago

crypto is not maintained anymore and when installing the dependency, it won't launch the package.json downloaded so it has become useless.

Instead you have to install crypto-browserify in order to have access to the same functions. However, i can't manage yet myself to make ethereumjs-wallet call crypto-browserify instead of crypto package. Maybe there's a way to make an alias from one name to another but i don't know how.

Any idea ?

EDIT : i found this problematic using fromV3 ( i'm not using toV3 yet )