How to use the ethereumjs-wallet.fromPrivateKey function in ethereumjs-wallet

To help you get started, we’ve selected a few ethereumjs-wallet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ethereum / web3.js / test / eth.accounts.create.js View on Github external
it('create eth.account, and compare to ethereumjs-wallet', function() {
                var ethAccounts = new Accounts();

                // create account
                var acc = ethAccounts.create();

                // create ethereumjs-wallet account
                var ethWall = ethereumWallet.fromPrivateKey(Buffer.from(acc.privateKey.replace('0x', ''), 'hex'));

                // compare addresses
                assert.equal(acc.address, ethWall.getChecksumAddressString());
            });
        });
github monerium / smart-contracts / truffle.js View on Github external
const ledger = process.env['LEDGER'];
const networkId = process.env['NETWORK_ID'];

var address;
var walletProvider;

function die(s) {
	console.error(s);
	process.exit();
}

if (key != undefined) {
	if (api == undefined) die('API not set')
	if (url == undefined) die('URL not set')
  address = `0xb912740f1389fa0c99965fcda9039b9e5638e5f7`;
  const wallet = Wallet.fromPrivateKey(Buffer.from(key, 'hex'));
  const walletAddress = wallet.getAddressString();
  if (walletAddress != address) die(`Key address ${walletAddress} does not match ${address}`);
  walletProvider = () => new WalletProvider(key, `${url}/v3/${api}`, 0);
} else if (mnemonic != undefined) {
	if (api == undefined) die('API not set')
	if (url == undefined) die('URL not set')
	// address = `0x808b6dB94ce973Bab908450E764Db7405A533FAa`;
	address = `0xe90319CBACc28aA19c12A7225322Ce64e5701D56`;

	if (!bip39.validateMnemonic(mnemonic)) die(`${mnemonic} not valid`);
	const seed = bip39.mnemonicToSeed(mnemonic);
	var wallet = HDKey.fromMasterSeed(seed).derivePath("m/44'/60'/0'/0/0").getWallet();
  const walletAddress = wallet.getAddress().toString('hex');
  if (`0x${walletAddress}` != address.toLowerCase()) die(`HDKey address 0x${walletAddress} does not match ${address}`);
  walletProvider = () => new WalletProvider(mnemonic, `${url}/v3/${api}`, 0);
} else if (testkey != undefined) {
github KeySplit / dapp / src / Keysplit / app.js View on Github external
} else if(window && window.web3) {
      // BUG: This never finds window.web3, and thus always falls back to localStorage keys
      this.web3 = new Web3(window.web3.currentProvider);
    } else {
      var privateKey = options.privateKey || localStorage.getItem("localPrivateKey");
      if(!privateKey) {
        privateKey = Wallet.generate().getPrivateKeyString().slice(2);
        if(localStorage) {
        localStorage.setItem("localPrivateKey", privateKey)}
      }
      // This uses web3-provider-engine and ethereumjs-wallet to construct a
      // wallet in-browser, without needing Metamask, Toshi, etc.
      //
      // Note that the current version of ethereumjs-wallet on npm has a bug,
      // but the latest on Github works just fine.
      var wallet = Wallet.fromPrivateKey(new Buffer(privateKey, "hex"));
      this.engine = new ProviderEngine();
      this.web3 = new Web3(this.engine);
      console.log(this.web3)
      // static results
      this.engine.addProvider(new FixtureSubprovider({
        web3_clientVersion: 'ProviderEngine/v0.0.0/javascript',
        net_listening: true,
        eth_hashrate: '0x00',
        eth_mining: false,
        eth_syncing: true,
      }))

      // filters
      this.engine.addProvider(new FilterSubprovider())

      // id mgmt
github hitchcott / spectrum / src / keystoreTypes / v3 / v3_keystore_actions.js View on Github external
if (!type) {
      throw new Error('Please select a wallet type');
    }
    if (!name) {
      throw new Error('You must provide a name');
    }
    if (!password || password.length < 6) {
      throw new Error('Password Must be at least 6 characters long (and ideally > 24)');
    }
    if (password !== confirmPassword) {
      throw new Error('Passwords do not match.');
    }
    // Generate wallet
    const { n, salt, iv, networks, tokens, privateKey } = formData;
    // use private key if it's given, otherwise generate
    const wallet = (privateKey && Wallet.fromPrivateKey(new Buffer(privateKey, 'hex'))) || Wallet.generate();
    const address = wallet.getChecksumAddressString();
    // ensure it doesnt already exist
    throwIfExistingAddress([address], getState);
    // let the UI update with a loading spinner...
    const params = {
      salt: salt && new Buffer(salt, 'hex'),
      iv: iv && new Buffer(iv, 'hex'),
      n: n || 16384, // maybe use profiling (profilev3Iterations)?
    };
    const data = JSON.stringify(wallet.toV3(password, params));
    // new keystore id
    const id = uuid();
    // create keystore instance
    dispatch({ type: keystoreActions.CREATE_KEYSTORE, payload: { type, data, id } });
    // create address instance
    dispatch({ type: addressActions.CREATE_ADDRESS, payload: { address, networks, name, tokens, keystore: id } });
github ethfinex / community-gateway / src / services / keystoreService.js View on Github external
const PrivKeyWallet = privkey => signWrapper(fromPrivateKey(privkey));
github brave / ethereum-remote-client / app / scripts / keyrings / simple.js View on Github external
this.wallets = privateKeys.map((privateKey) => {
          const stripped = ethUtil.stripHexPrefix(privateKey)
          const buffer = new Buffer(stripped, 'hex')
          const wallet = Wallet.fromPrivateKey(buffer)
          return wallet
        })
      } catch (e) {
github nosuchip / truffle-privatekey-provider / index.js View on Github external
function PrivateKeyProvider(privateKey, providerUrl) {
  if (!privateKey) {
    throw new Error(`Private Key missing, non-empty string expected, got "${privateKey}"`);
  }

  if (!providerUrl) {
    throw new Error(`Provider URL missing, non-empty string expected, got "${providerUrl}"`);
  }

  this.wallet = EthereumjsWallet.fromPrivateKey(new Buffer(privateKey, "hex"));
  this.address = "0x" + this.wallet.getAddress().toString("hex");

  this.engine = new ProviderEngine();

  this.engine.addProvider(new FiltersSubprovider());
  this.engine.addProvider(new NonceSubprovider());
  this.engine.addProvider(new WalletSubprovider(this.wallet, {}));
  this.engine.addProvider(new RpcSubprovider({ rpcUrl: providerUrl }));

  this.engine.start();
}
github MetaMask / eth-simple-keyring / index.js View on Github external
_getWalletForAccount (account, opts = {}) {
    const address = sigUtil.normalize(account)
    let wallet = this.wallets.find(w => ethUtil.bufferToHex(w.getAddress()) === address)
    if (!wallet) throw new Error('Simple Keyring - Unable to find matching address.')

    if (opts.withAppKeyOrigin) {
      const privKey = wallet.getPrivateKey()
      const appKeyOriginBuffer = Buffer.from(opts.withAppKeyOrigin, 'utf8')
      const appKeyBuffer = Buffer.concat([privKey, appKeyOriginBuffer])
      const appKeyPrivKey = ethUtil.keccak(appKeyBuffer, 256)
      wallet = Wallet.fromPrivateKey(appKeyPrivKey)
    }

    return wallet
  }
github lehuan94cntt / zeros-dice / truffle.js View on Github external
const getWalle = function (network) {
  let wallet;
  switch (network) {
    case 'ropsten':
      let ropstenPrivateKey = parsePrivateKey(process.env.ROPSTEN_PRIVATE_KEY)
      wallet = Wallet.fromPrivateKey(ropstenPrivateKey)
      break
    case 'rinkeby':
      let rinkebyPrivateKey = parsePrivateKey(process.env.RINKEBY_PRIVATE_KEY);
      wallet = Wallet.fromPrivateKey(rinkebyPrivateKey);
      break
    default:
      break
  }

  return wallet
}
github MyCryptoHQ / MyCrypto / common / libs / wallet / non-deterministic / wallets.ts View on Github external
const PrivKeyWallet = (privkey: Buffer) => signWrapper(fromPrivateKey(privkey));