src/create.js
function (wallet) {
    var data = JSON.stringify(wallet, null, 2)
    var enc = Blockchain.WalletCrypto.encryptWallet(data, password, wallet.options.pbkdf2_iterations, 2.0)
    var check = sha256(enc).toString('hex')

    // Throws if there is an encryption error
    Blockchain.WalletCrypto.decryptWallet(enc, password, function () {}, function () {
      throw 'Failed to confirm successful encryption when generating new wallet'
    })

    var postData = {
      guid: wallet.guid,
      sharedKey: wallet.sharedKey,
      length: enc.length,
      payload: enc,
      checksum: check,
      method: 'insert',
      format: 'plain'
    }

    if (email) postData.email = email

    return Blockchain.API.securePost('wallet', postData).then(function () {
      if (isHdWallet) {
        var account = wallet.hd_wallets[0].accounts[0]
        return { guid: wallet.guid, address: account.xpub, label: account.label }
      } else {
        var firstKey = wallet.keys[0]
        return { guid: wallet.guid, address: firstKey.addr, label: firstKey.label, warning: warnings.CREATED_NON_HD }
      }
    })
  }
function (wallet) {
    var data = JSON.stringify(wallet, null, 2)
    var enc = Blockchain.WalletCrypto.encryptWallet(data, password, wallet.options.pbkdf2_iterations, 2.0)
    var check = sha256(enc).toString('hex')

    // Throws if there is an encryption error
    Blockchain.WalletCrypto.decryptWallet(enc, password, function () {}, function () {
      throw 'Failed to confirm successful encryption when generating new wallet'
    })

    var postData = {
      guid: wallet.guid,
      sharedKey: wallet.sharedKey,
      length: enc.length,
      payload: enc,
      checksum: check,
      method: 'insert',
      format: 'plain'
    }

    if (email) postData.email = email

    return Blockchain.API.securePost('wallet', postData).then(function () {
      if (isHdWallet) {
        var account = wallet.hd_wallets[0].accounts[0]
        return { guid: wallet.guid, address: account.xpub, label: account.label }
      } else {
        var firstKey = wallet.keys[0]
        return { guid: wallet.guid, address: firstKey.addr, label: firstKey.label, warning: warnings.CREATED_NON_HD }
      }
    })
  }
function ( wallet ) { var data = JSON . stringify ( wallet , null , 2 ) var enc = Blockchain . WalletCrypto . encryptWallet ( data , password , wallet . options . pbkdf2_iterations , 2.0 ) var check = sha256 ( enc ) . toString ( 'hex' ) // Throws if there is an encryption error Blockchain . WalletCrypto . decryptWallet ( enc , password , function ( ) { } , function ( ) { throw 'Failed to confirm successful encryption when generating new wallet' } ) var postData = { guid : wallet . guid , sharedKey : wallet . sharedKey , length : enc . length , payload : enc , checksum : check , method : 'insert' , format : 'plain' } if ( email ) postData . email = email return Blockchain . API . securePost ( 'wallet' , postData ) . then ( function ( ) { if ( isHdWallet ) { var account = wallet . hd_wallets [ 0 ] . accounts [ 0 ] return { guid : wallet . guid , address : account . xpub , label : account . label } } else { var firstKey = wallet . keys [ 0 ] return { guid : wallet . guid , address : firstKey . addr , label : firstKey . label , warning : warnings . CREATED_NON_HD } } } ) }
Encrypt and push new wallet to server
Encrypt and push new wallet to server