src/create.js
function (uuids) {
    var walletJSON = {
      guid: uuids.guid,
      sharedKey: uuids.sharedKey,
      double_encryption: false,
      options: {
        pbkdf2_iterations: 5000,
        html5_notifications: false,
        fee_per_kb: 10000,
        logout_time: 600000
      }
    }

    var createHdWallet = function (label) {
      label = label == null ? 'My Bitcoin Wallet' : label
      var mnemonic = BIP39.generateMnemonic(undefined, Blockchain.RNG.run.bind(Blockchain.RNG))
      var hd = HDWallet.new(mnemonic)
      hd.newAccount(label)
      return hd
    }

    var createLegacyAddress = function (priv, label) {
      return priv ? Address.import(priv, label) : Address.new(label)
    }

    if (isHdWallet) {
      var hdJSON = createHdWallet(firstLabel).toJSON()
      hdJSON.accounts = hdJSON.accounts.map(function (a) { return a.toJSON() })
      walletJSON.hd_wallets = [hdJSON]
    } else {
      winston.warn(warnings.CREATED_NON_HD)
      var firstAddress = createLegacyAddress(privateKey, firstLabel)
      walletJSON.keys = [firstAddress.toJSON()]
    }

    if (typeof secPass === 'string' && secPass.length) {
      walletJSON = JSON.parse(JSON.stringify(new Wallet(walletJSON).encrypt(secPass)))
    }

    return walletJSON
  }
function (uuids) {
    var walletJSON = {
      guid: uuids.guid,
      sharedKey: uuids.sharedKey,
      double_encryption: false,
      options: {
        pbkdf2_iterations: 5000,
        html5_notifications: false,
        fee_per_kb: 10000,
        logout_time: 600000
      }
    }

    var createHdWallet = function (label) {
      label = label == null ? 'My Bitcoin Wallet' : label
      var mnemonic = BIP39.generateMnemonic(undefined, Blockchain.RNG.run.bind(Blockchain.RNG))
      var hd = HDWallet.new(mnemonic)
      hd.newAccount(label)
      return hd
    }

    var createLegacyAddress = function (priv, label) {
      return priv ? Address.import(priv, label) : Address.new(label)
    }

    if (isHdWallet) {
      var hdJSON = createHdWallet(firstLabel).toJSON()
      hdJSON.accounts = hdJSON.accounts.map(function (a) { return a.toJSON() })
      walletJSON.hd_wallets = [hdJSON]
    } else {
      winston.warn(warnings.CREATED_NON_HD)
      var firstAddress = createLegacyAddress(privateKey, firstLabel)
      walletJSON.keys = [firstAddress.toJSON()]
    }

    if (typeof secPass === 'string' && secPass.length) {
      walletJSON = JSON.parse(JSON.stringify(new Wallet(walletJSON).encrypt(secPass)))
    }

    return walletJSON
  }
function ( uuids ) { var walletJSON = { guid : uuids . guid , sharedKey : uuids . sharedKey , double_encryption : false , options : { pbkdf2_iterations : 5000 , html5_notifications : false , fee_per_kb : 10000 , logout_time : 600000 } } var createHdWallet = function ( label ) { label = label == null ? 'My Bitcoin Wallet' : label var mnemonic = BIP39 . generateMnemonic ( undefined , Blockchain . RNG . run . bind ( Blockchain . RNG ) ) var hd = HDWallet . new ( mnemonic ) hd . newAccount ( label ) return hd } var createLegacyAddress = function ( priv , label ) { return priv ? Address . import ( priv , label ) : Address . new ( label ) } if ( isHdWallet ) { var hdJSON = createHdWallet ( firstLabel ) . toJSON ( ) hdJSON . accounts = hdJSON . accounts . map ( function ( a ) { return a . toJSON ( ) } ) walletJSON . hd_wallets = [ hdJSON ] } else { winston . warn ( warnings . CREATED_NON_HD ) var firstAddress = createLegacyAddress ( privateKey , firstLabel ) walletJSON . keys = [ firstAddress . toJSON ( ) ] } if ( typeof secPass === 'string' && secPass . length ) { walletJSON = JSON . parse ( JSON . stringify ( new Wallet ( walletJSON ) . encrypt ( secPass ) ) ) } return walletJSON }
Generate new Wallet JSON, add first key
Generate new Wallet JSON add first key