How to use the ethereumjs-wallet/hdkey.fromMasterSeed 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 appliedblockchain / k0 / js / demo / deposit.js View on Github external
)
  console.log('private key', u.buf2hex(secretStore.getASk()))
  console.log('public key', u.buf2hex(secretStore.getAPk()))
  initEventHandlers(platformState, secretStore, k0Eth)

  const k0 = await makeK0(serverPorts[who])

  const artefacts = await compileContracts()
  const dollarCoin = new web3.eth.Contract(
    artefacts.DollarCoin.abi,
    addresses.DollarCoin
  )

  const mnemonic = mnemonics[who]
  const seed = bip39.mnemonicToSeed(mnemonic)
  const root = hdkey.fromMasterSeed(seed)
  const path = "m/44'/60'/0'/0/0" // eslint-disable-line
  const wallet = root.derivePath(path).getWallet()

  const values = _.times(3, () => new BN(_.random(50).toString() + '000'))

  const total = values.reduce((acc, el) => acc.add(el), new BN('0'))

  await demoUtil.prompt()

  const platformRoot = await k0Eth.merkleTreeRoot()
  console.log(`Platform Merkle tree root: ${u.buf2hex(platformRoot)}`)
  const localRoot = await platformState.merkleTreeRoot()
  console.log(`Local Merkle tree root: ${u.buf2hex(localRoot)}`)
  assert(localRoot.equals(platformRoot))

  // approve
github secret-tech / backend-ico-dashboard / src / services / web3.client.ts View on Github external
getPrivateKeyByMnemonicAndSalt(mnemonic: string, salt: string) {
    // get seed
    const hdWallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic, salt));

    // get first of available wallets
    const path = 'm/44\'/60\'/0\'/0/0';

    // get wallet
    const wallet = hdWallet.derivePath(path).getWallet();

    // get private key
    return '0x' + wallet.getPrivateKey().toString('hex');
  }
github trufflesuite / ganache-core / lib / statemanager.js View on Github external
this.total_accounts = options.total_accounts;
  this.coinbase = null;

  this.latest_filter_id = 1;

  // This queue manages actions that shouldn't be run in parallel.
  // The action_processing flag ensures new actions are queued instead of
  // run immediately.
  this.action_queue = [];
  this.action_processing = false;

  this.snapshots = [];
  this.logger = options.logger;
  this.net_version = options.network_id;
  this.mnemonic = options.mnemonic;
  this.wallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(this.mnemonic));
  this.wallet_hdpath = options.hdPath;

  this.gasPriceVal = to.rpcQuantityHexString(options.gasPrice);

  this.is_mining = true;
  this.blockTime = options.blockTime;
  this.is_mining_on_interval = !!options.blockTime;
  this.mining_interval_timeout = null;

  this._provider = provider;
}
github trufflesuite / truffle / packages / hdwallet-provider / src / index.ts View on Github external
const checkBIP39Mnemonic = (mnemonic: string) => {
      this.hdwallet = EthereumHDKey.fromMasterSeed(
        bip39.mnemonicToSeed(mnemonic)
      );

      if (!bip39.validateMnemonic(mnemonic)) {
        throw new Error("Mnemonic invalid or undefined");
      }

      // crank the addresses out
      for (let i = addressIndex; i < addressIndex + numAddresses; i++) {
        const wallet = this.hdwallet
          .derivePath(this.walletHdpath + i)
          .getWallet();
        const addr = `0x${wallet.getAddress().toString("hex")}`;
        this.addresses.push(addr);
        this.wallets[addr] = wallet;
      }
github GridPlus / cryptobridge-contracts / test / bridge.js View on Github external
function generateFirstWallets(n, _wallets, hdPathIndex) {
    const hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(secrets.mnemonic));
    const node = hdwallet.derivePath(secrets.hdPath + hdPathIndex.toString());
    const secretKey = node.getWallet().getPrivateKeyString();
    const addr = node.getWallet().getAddressString();
    _wallets.push([addr, secretKey]);
    const nextHDPathIndex = hdPathIndex + 1;
    if (nextHDPathIndex >= n) {
      return _wallets;
    }
    return generateFirstWallets(n, _wallets, nextHDPathIndex);
  }
github rate-engineering / rate3-monorepo / packages / wallet / WalletManager.js View on Github external
setWallet() {
    switch (this.network) {
      case 'stellar':
        this.wallet = stellarHDWallet.fromMnemonic(this.seed);
        break;
      case 'ethereum':
        this.wallet = hdkey.fromMasterSeed(this.seed);
        break;
      default:
        this.wallet = null;
        console.log(setting.networkError);
    }
    return this.wallet;
  }
github levelkdev / crypto-flash / service / utils / getGuardianAccount.js View on Github external
function getGuardianAccount() {
  let bip39 = require('bip39');
  let hdkey = require('ethereumjs-wallet/hdkey');
  let hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic));
  let wallet_hdpath = "m/44'/60'/0'/0/";
  let wallet = hdwallet.derivePath(wallet_hdpath + 0).getWallet();
  let privateKey = wallet.getPrivateKey().toString("hex")
  let guardian = web3.eth.accounts.privateKeyToAccount("0x" + privateKey)
  return guardian
}
github floating / frame / main / signers / hot / Seed / index.js View on Github external
signMessage (index, message, cb) {
    if (!this.unlockedSeed) return cb(new Error('Account locked'))
    const hash = hashPersonalMessage(toBuffer(message))
    const pk = hdKey.fromMasterSeed(Buffer.from(this.unlockedSeed, 'hex')).derivePath('m/44\'/60\'/0\'/0').deriveChild(index).getWallet().getPrivateKey()
    const signed = ecsign(hash, pk)
    const hex = Buffer.concat([Buffer.from(signed.r), Buffer.from(signed.s), Buffer.from([signed.v])]).toString('hex')
    cb(null, addHexPrefix(hex))
  }
  signTransaction (index, rawTx, cb) {
github paritytech / fether / packages / fether-react / src / stores / createAccountStore.js View on Github external
setBip39Phrase = async phrase => {
    this.clear();

    if (!bip39.validateMnemonic(phrase)) throw new Error('Not a BIP39 phrase');

    const hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(phrase));
    const wallet = hdwallet.derivePath(DERIVATION_PATH).getWallet();

    this.address = `0x${wallet.getAddress().toString('hex')}`;
    this.bip39Phrase = phrase;
  };