Wallet/js/models/Identity.js

651 lines
17 KiB
JavaScript
Raw Normal View History

2014-04-16 17:50:10 -03:00
'use strict';
2014-09-03 01:25:08 -03:00
var preconditions = require('preconditions').singleton();
2014-04-16 17:50:10 -03:00
2014-10-10 12:02:46 -03:00
var _ = require('underscore');
var bitcore = require('bitcore');
2014-10-10 12:02:46 -03:00
var log = require('../log');
var async = require('async');
2014-10-10 12:02:46 -03:00
var version = require('../../version').version;
2014-08-01 01:09:46 -03:00
var TxProposals = require('./TxProposals');
2014-04-16 17:50:10 -03:00
var PublicKeyRing = require('./PublicKeyRing');
var PrivateKey = require('./PrivateKey');
var Wallet = require('./Wallet');
2014-09-03 01:25:08 -03:00
var PluginManager = require('./PluginManager');
2014-09-30 20:12:02 -03:00
var Async = module.exports.Async = require('./Async');
/**
* @desc
* Identity - stores the state for a wallet in creation
*
* @param {Object} opts - configuration for this wallet
* @param {string} opts.fullName
* @param {string} opts.email
* @param {string} opts.password
* @param {string} opts.storage
* @param {string} opts.pluginManager
* @param {Object} opts.walletDefaults
* @param {string} opts.version
* @param {Object} opts.wallets
* @param {Object} opts.network
* @param {string} opts.network.testnet
* @param {string} opts.network.livenet
2014-09-08 15:42:55 -03:00
* @constructor
2014-04-16 17:50:10 -03:00
*/
function Identity(opts) {
2014-09-28 18:38:06 -03:00
preconditions.checkArgument(opts);
2014-10-22 00:14:48 -03:00
opts = _.extend({}, opts);
2014-10-07 18:33:55 -03:00
this.networkOpts = {
'livenet': opts.network.livenet,
'testnet': opts.network.testnet,
};
2014-10-07 18:33:55 -03:00
this.blockchainOpts = {
'livenet': opts.network.livenet,
'testnet': opts.network.testnet,
};
2014-04-16 17:50:10 -03:00
this.fullName = opts.fullName || opts.email;
this.email = opts.email;
this.password = opts.password;
2014-09-28 18:38:06 -03:00
this.storage = opts.storage || opts.pluginManager.get('DB');
this.storage.setCredentials(this.email, this.password, {});
2014-09-27 18:53:34 -03:00
this.walletDefaults = opts.walletDefaults || {};
this.version = opts.version || version;
2014-09-29 12:11:10 -03:00
this.wallets = opts.wallets || {};
2014-09-29 12:11:10 -03:00
};
Identity.getKeyForEmail = function(email) {
return 'profile::' + bitcore.util.sha256ripe160(email).toString('hex');
2014-09-29 19:58:00 -03:00
};
Identity.prototype.getId = function() {
return Identity.getKeyForEmail(this.email);
2014-10-01 08:35:17 -03:00
};
Identity.prototype.getName = function() {
return this.fullName || this.email;
2014-10-07 18:33:55 -03:00
};
/**
* Creates an Identity
*
* @param opts
* @param cb
* @return {undefined}
*/
Identity.create = function(opts, cb) {
opts = _.extend({}, opts);
var iden = new Identity(opts);
if (opts.noWallets) {
return cb(null, iden);
} else {
return iden.createDefaultWallet(opts, cb);
}
};
/**
* Create a wallet, 1-of-1 named general
*
* @param {Object} opts
* @param {Object} opts.walletDefaults
* @param {string} opts.walletDefaults.networkName
*/
Identity.prototype.createDefaultWallet = function(opts, callback) {
var self = this;
var walletOptions = _.extend(opts.walletDefaults, {
nickname: this.fullName || this.email,
networkName: opts.networkName,
requiredCopayers: 1,
totalCopayers: 1,
password: this.password,
name: 'general'
});
this.createWallet(walletOptions, function(err, wallet) {
if (err) {
return callback(err);
}
return callback(null, self);
2014-10-24 09:36:28 -03:00
});
};
2014-10-01 08:35:17 -03:00
2014-10-11 14:33:45 -03:00
/**
* Open an Identity from the given storage
2014-10-11 14:33:45 -03:00
*
* @param {string} email
* @param {string} password
* @param {Object} opts
* @param {Object} opts.storage
* @param {Function} cb
2014-10-11 14:33:45 -03:00
*/
Identity.open = function(email, password, opts, cb) {
var storage = opts.storage || opts.pluginManager.get('DB');
storage.setCredentials(email, password, opts);
storage.getItem(Identity.getKeyForEmail(email), function(err, data) {
if (err) {
return cb(err);
}
return Identity.createFromPartialJson(data, opts, cb);
2014-10-24 09:36:28 -03:00
});
2014-10-11 14:33:45 -03:00
};
2014-09-28 18:38:06 -03:00
/**
* Creates an Identity, retrieves all Wallets remotely, and activates network
2014-09-28 18:38:06 -03:00
*
* @param {string} jsonString - a string containing a json object with options to rebuild the identity
* @param {Object} opts
* @param {Function} cb
2014-09-28 18:38:06 -03:00
*/
Identity.createFromPartialJson = function(jsonString, opts, callback) {
var exported;
try {
exported = JSON.parse(jsonString);
} catch (e) {
return callback('Invalid JSON');
}
var identity = new Identity(_.extend(opts, exported));
async.map(exported.walletIds, function(walletId, callback) {
identity.retrieveWalletFromStorage(walletId, function(error, wallet) {
if (!error) {
identity.wallets[wallet.getId()] = wallet;
wallet.netStart();
2014-10-23 17:26:32 -03:00
}
callback(error, wallet);
2014-09-30 16:04:17 -03:00
});
}, function(err) {
return callback(err, identity);
2014-09-28 18:38:06 -03:00
});
};
/**
* @param {string} walletId
* @param {Function} callback
2014-09-28 18:38:06 -03:00
*/
Identity.prototype.retrieveWalletFromStorage = function(walletId, callback) {
var self = this;
this.storage.getItem(Wallet.getStorageKey(walletId), function(error, walletData) {
if (error) {
return callback(error);
}
try {
log.debug('## OPENING Wallet: ' + walletId);
if (_.isString(walletData)) {
walletData = JSON.parse(walletData);
}
var readOpts = {
networkOpts: self.networkOpts,
blockchainOpts: self.blockchainOpts,
skipFields: []
};
return callback(null, Wallet.fromUntrustedObj(walletData, readOpts));
2014-09-28 18:38:06 -03:00
} catch (e) {
log.debug("ERROR: ", e.message);
if (e && e.message && e.message.indexOf('MISSOPTS') !== -1) {
return callback(new Error('WERROR: Could not read: ' + walletId + ': ' + e.message));
} else {
return callback(e);
2014-10-22 00:14:48 -03:00
}
}
2014-09-28 18:38:06 -03:00
});
};
/**
* TODO (matiu): What is this supposed to do?
2014-09-28 18:38:06 -03:00
*/
Identity.isAvailable = function(email, opts, cb) {
return cb();
};
/**
* @param {Wallet} wallet
* @param {Function} cb
*/
Identity.prototype.storeWallet = function(wallet, cb) {
preconditions.checkArgument(w && _.isObject(wallet));
2014-10-24 09:36:28 -03:00
var val = wallet.toObj();
var key = wallet.getStorageKey();
2014-10-24 09:36:28 -03:00
this.storage.setItem(key, val, function(err) {
if (err) {
log.debug('Wallet:' + w.getName() + ' couldnt be stored');
return cb(err);
2014-10-24 09:36:28 -03:00
}
return cb();
2014-10-24 09:36:28 -03:00
});
};
2014-09-28 18:38:06 -03:00
Identity.prototype.toObj = function() {
return _.extend({walletIds: _.keys(this.wallets)},
_.pick(this, 'version', 'fullName', 'password', 'email'));
2014-10-24 08:37:40 -03:00
};
Identity.prototype.exportWithWalletInfo = function() {
return _.extend({wallets: _.map(this.wallets, function(wallet) { return wallet.toObj(); })},
_.pick(this, 'version', 'fullName', 'password', 'email'));
};
2014-10-24 08:37:40 -03:00
/**
* @param {Object} opts
* @param {Function} cb
*/
2014-09-28 18:38:06 -03:00
Identity.prototype.store = function(opts, cb) {
2014-09-28 20:50:37 -03:00
var self = this;
self.storage.setItem(this.getStorageKey(), this.toObj(), function(err) {
2014-09-28 21:22:53 -03:00
if (err) return cb(err);
async.map(self.wallets, self.storeWallet, cb);
2014-09-28 20:50:37 -03:00
});
2014-09-28 18:38:06 -03:00
};
Identity.prototype._cleanUp = function() {
2014-10-07 18:33:55 -03:00
// NOP
};
2014-09-30 21:16:46 -03:00
/**
* @desc Closes the wallet and disconnects all services
*/
Identity.prototype.close = function(cb) {
async.map(this.wallets, function(wallet, callback) {
wallet.close(callback);
}, cb);
2014-09-30 21:16:46 -03:00
};
/**
* @desc Imports a wallet from an encrypted base64 object
* @param {string} base64 - the base64 encoded object
2014-09-18 18:29:00 -03:00
* @param {string} passphrase - passphrase to decrypt it
* @param {string[]} skipFields - fields to ignore when importing
* @return {Wallet}
*/
2014-09-30 21:16:46 -03:00
Identity.prototype.importWallet = function(base64, password, skipFields, cb) {
2014-10-16 17:39:22 -03:00
var self = this;
2014-10-14 09:58:12 -03:00
preconditions.checkArgument(password);
2014-09-29 16:55:45 -03:00
preconditions.checkArgument(cb);
2014-10-21 09:57:54 -03:00
var obj = this.storage.decrypt(base64, password);
2014-09-29 11:35:04 -03:00
2014-10-16 17:39:22 -03:00
var readOpts = {
networkOpts: this.networkOpts,
blockchainOpts: this.blockchainOpts,
skipFields: skipFields
};
if (!obj) return cb(null);
var w = Identity._walletFromObj(obj, readOpts);
2014-09-29 11:35:04 -03:00
this._checkVersion(w.version);
2014-09-29 16:55:45 -03:00
this.addWallet(w, function(err) {
2014-10-16 17:39:22 -03:00
if (err) return cb(err, null);
2014-10-24 08:37:40 -03:00
self.wallets[w.getId()] = w;
2014-10-16 17:39:22 -03:00
self.store(null, function(err) {
return cb(err, w);
});
2014-09-29 11:35:04 -03:00
});
2014-05-01 18:32:22 -03:00
};
/**
* @param {Wallet} wallet
* @param {Function} cb
*/
Identity.prototype.closeWallet = function(wallet, cb) {
preconditions.checkState(wallet, 'Wallet not found');
wallet.close(function(err) {
2014-10-24 08:37:40 -03:00
delete self.wallets[wid];
return cb(err);
});
};
Identity.importFromFullJson = function(str, password, opts, cb) {
2014-10-21 09:57:54 -03:00
preconditions.checkArgument(str);
2014-10-22 00:14:48 -03:00
var json;
try {
json = JSON.parse(str);
} catch (e) {
return cb('Unable to retrieve json from string', str);
}
2014-10-21 09:57:54 -03:00
2014-10-21 12:03:09 -03:00
if (!_.isNumber(json.iterations))
2014-10-24 08:37:40 -03:00
return cb('BADSTR: Missing iterations');
2014-10-21 09:57:54 -03:00
var email = json.email;
var iden = new Identity(email, password, opts);
2014-10-21 09:57:54 -03:00
json.wallets = json.wallets || {};
async.map(json.wallets, function(walletData, callback) {
2014-10-22 00:14:48 -03:00
iden.importWallet(wstr, password, opts.skipFields, function(err, w) {
if (err) return callback(err);
2014-10-21 09:57:54 -03:00
log.debug('Wallet ' + w.getId() + ' imported');
callback();
});
}, function(err, results) {
if (err) {
return cb(err);
}
iden.store(function(err) {
if (err) {
return cb(err);
2014-10-22 00:14:48 -03:00
}
return cb(null, iden, iden.openWallets[0]);
});
2014-10-15 16:24:21 -03:00
});
2014-10-15 15:02:14 -03:00
};
2014-10-24 08:37:40 -03:00
Identity.prototype.bindWallet = function(w) {
var self = this;
self.wallets[w.getId()] = w;
log.debug('Binding wallet ' + w.getName());
w.on('hasChange', function() {
log.debug('<hasChange> Wallet' + w.getName());
self.storeWallet(w);
});
};
/**
2014-09-14 13:52:43 -03:00
* @desc This method prepares options for a new Wallet
*
* @param {Object} opts
* @param {string} opts.id
* @param {PrivateKey=} opts.privateKey
* @param {string=} opts.privateKeyHex
* @param {number} opts.requiredCopayers
* @param {number} opts.totalCopayers
* @param {PublicKeyRing=} opts.publicKeyRing
* @param {string} opts.nickname
2014-09-30 21:16:46 -03:00
* @param {string} opts.password
* @TODO: Figure out what is this parameter
* @param {?} opts.spendUnconfirmed this.walletDefaults.spendUnconfirmed ??
* @TODO: Figure out in what unit is this reconnect delay.
* @param {number} opts.reconnectDelay milliseconds?
* @param {number=} opts.version
2014-09-03 15:43:27 -03:00
* @param {callback} opts.version
* @return {Wallet}
*/
2014-09-27 18:56:25 -03:00
Identity.prototype.createWallet = function(opts, cb) {
2014-09-08 10:46:57 -03:00
preconditions.checkArgument(cb);
2014-09-10 13:56:49 -07:00
opts = opts || {};
opts.networkName = opts.networkName || 'testnet';
2014-09-01 12:35:40 -03:00
log.debug('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID') + (opts.privateKey ? ' USING PrivateKey: ' + opts.privateKey.getId() : ' NEW PrivateKey'));
2014-04-16 17:50:10 -03:00
2014-08-21 14:54:36 -04:00
var privOpts = {
networkName: opts.networkName,
2014-08-21 14:54:36 -04:00
};
2014-09-04 16:13:30 -03:00
if (opts.privateKeyHex && opts.privateKeyHex.length > 1) {
2014-08-21 14:54:36 -04:00
privOpts.extendedPrivateKeyString = opts.privateKeyHex;
}
opts.privateKey = opts.privateKey || new PrivateKey(privOpts);
2014-04-20 12:41:28 -03:00
2014-04-16 17:50:10 -03:00
var requiredCopayers = opts.requiredCopayers || this.walletDefaults.requiredCopayers;
2014-06-16 15:51:19 -03:00
var totalCopayers = opts.totalCopayers || this.walletDefaults.totalCopayers;
2014-08-14 18:46:42 -04:00
opts.lockTimeoutMin = this.walletDefaults.idleDurationMin;
2014-04-16 17:50:10 -03:00
opts.publicKeyRing = opts.publicKeyRing || new PublicKeyRing({
networkName: opts.networkName,
2014-04-16 17:50:10 -03:00
requiredCopayers: requiredCopayers,
totalCopayers: totalCopayers,
});
opts.publicKeyRing.addCopayer(
opts.privateKey.deriveBIP45Branch().extendedPublicKeyString(),
opts.nickname || this.getName()
2014-08-01 11:24:16 -03:00
);
2014-09-01 12:35:40 -03:00
log.debug('\t### PublicKeyRing Initialized');
2014-04-16 17:50:10 -03:00
2014-08-05 16:42:51 -03:00
opts.txProposals = opts.txProposals || new TxProposals({
networkName: opts.networkName,
2014-04-16 17:50:10 -03:00
});
2014-09-01 12:35:40 -03:00
log.debug('\t### TxProposals Initialized');
2014-04-16 17:50:10 -03:00
2014-10-07 18:33:55 -03:00
opts.networkOpts = this.networkOpts;
opts.blockchainOpts = this.blockchainOpts;
2014-04-16 20:58:57 -03:00
2014-04-16 17:50:10 -03:00
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
2014-06-16 15:51:19 -03:00
opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay;
2014-04-16 17:50:10 -03:00
opts.requiredCopayers = requiredCopayers;
2014-06-16 15:51:19 -03:00
opts.totalCopayers = totalCopayers;
opts.version = opts.version || this.version;
2014-08-14 18:46:42 -04:00
2014-09-29 06:31:04 -03:00
var self = this;
var w = new Wallet(opts);
2014-09-29 11:35:04 -03:00
this.addWallet(w, function(err) {
2014-09-14 13:52:43 -03:00
if (err) return cb(err);
2014-10-24 08:37:40 -03:00
self.bindWallet(w);
self.storage.setItem(self.getId(), self.toObj(), function(error) {
if (error) {
return callback(error);
}
w.netStart();
return cb(null, w);
});
2014-10-22 00:14:48 -03:00
});
};
2014-09-29 11:35:04 -03:00
Identity.prototype.addWallet = function(wallet, cb) {
2014-09-29 12:11:10 -03:00
preconditions.checkArgument(wallet);
2014-09-29 16:55:45 -03:00
preconditions.checkArgument(wallet.getId);
2014-09-29 11:35:04 -03:00
preconditions.checkArgument(cb);
this.wallets[wallet.getId()] = wallet;
// TODO (eordano): Consider not saving automatically after this
this.storage.setItem(wallet.getStorageKey(), wallet.toObj(), cb);
2014-09-29 11:35:04 -03:00
};
/**
* @desc Checks if a version is compatible with the current version
* @param {string} inVersion - a version, with major, minor, and revision, period-separated (x.y.z)
* @throws {Error} if there's a major version difference
*/
Identity.prototype._checkVersion = function(inVersion) {
2014-09-29 12:11:10 -03:00
if (inVersion) {
var thisV = this.version.split('.');
var thisV0 = parseInt(thisV[0]);
var inV = inVersion.split('.');
var inV0 = parseInt(inV[0]);
}
2014-05-14 21:02:01 -03:00
//We only check for major version differences
2014-06-16 15:51:19 -03:00
if (thisV0 < inV0) {
2014-05-14 21:02:01 -03:00
throw new Error('Major difference in software versions' +
2014-09-04 16:13:30 -03:00
'. Received:' + inVersion +
'. Current version:' + this.version +
'. Aborting.');
2014-05-14 21:02:01 -03:00
}
};
/**
* @desc Retrieve a wallet from the storage
* @param {string} walletId - the id of the wallet
2014-09-03 01:25:08 -03:00
* @param {function} callback (err, {Wallet})
* @return
*/
Identity.prototype.openWallet = function(walletId, cb) {
2014-09-08 10:46:57 -03:00
preconditions.checkArgument(cb);
preconditions.checkState(this.storage.hasPassphrase());
var self = this;
2014-10-01 08:35:17 -03:00
// TODO
// self.migrateWallet(walletId, password, function() {
2014-10-07 18:33:55 -03:00
//
2014-09-29 19:58:00 -03:00
2014-10-24 09:36:28 -03:00
self.readWallet(walletId, {
networkOpts: this.networkOpts,
2014-10-07 18:33:55 -03:00
blockchainOpts: this.blockchainOpts
}, function(err, w) {
2014-10-01 08:35:17 -03:00
if (err) return cb(err);
2014-10-24 08:37:40 -03:00
self.bindWallet(w);
self.storeWallet(w, function(err) {
w.netStart();
return cb(err, w);
2014-09-03 01:25:08 -03:00
});
});
2014-10-01 08:35:17 -03:00
// });
2014-04-16 20:58:57 -03:00
};
2014-09-29 06:31:04 -03:00
/**
* @param {string} walletId
* @returns {Wallet}
*/
Identity.prototype.getWalletById = function(walletId) {
return this.wallets[walletId];
};
/**
* @returns {Wallet[]}
*/
2014-10-14 13:22:28 -03:00
Identity.prototype.listWallets = function() {
return _.values(this.wallets);
};
2014-04-16 17:50:10 -03:00
/**
* @desc Deletes a wallet. This involves removing it from the storage instance
*
* @param {string} walletId
* @callback cb
* @return {err}
*/
2014-09-28 18:38:06 -03:00
Identity.prototype.deleteWallet = function(walletId, cb) {
var self = this;
delete this.wallets[walletId];
this.storage.deleteItem(walletId, function(err) {
if (err) {
return cb(err);
}
self.store(cb);
});
2014-04-16 17:50:10 -03:00
};
/**
* @desc Pass through to {@link Wallet#secret}
*/
Identity.prototype.decodeSecret = function(secret) {
2014-05-14 14:24:24 -07:00
try {
return Wallet.decodeSecret(secret);
} catch (e) {
return false;
}
2014-06-09 18:01:15 -03:00
};
2014-04-16 20:58:57 -03:00
Identity.prototype.getLastFocusedWallet = function() {
return _.max(this.wallets, function(wallet) {
return wallet.lastTimestamp || 0;
});
};
/**
* @callback walletCreationCallback
2014-09-08 15:42:55 -03:00
* @param {?} err - an error, if any, that happened during the wallet creation
* @param {Wallet=} wallet - the wallet created
*/
2014-04-20 12:41:28 -03:00
/**
* @desc Start the network functionality.
*
* Start up the Network instance and try to join a wallet defined by the
* parameter <tt>secret</tt> using the parameter <tt>nickname</tt>. Encode
* information locally using <tt>passphrase</tt>. <tt>privateHex</tt> is the
* private extended master key. <tt>cb</tt> has two params: error and wallet.
*
2014-09-14 13:52:43 -03:00
* @param {object} opts
* @param {string} opts.secret - the wallet secret
* @param {string} opts.nickname - a nickname for the current user
* @param {string} opts.privateHex - the private extended master key
* @param {walletCreationCallback} cb - a callback
*/
2014-09-27 18:56:25 -03:00
Identity.prototype.joinWallet = function(opts, cb) {
2014-09-14 13:52:43 -03:00
preconditions.checkArgument(opts);
preconditions.checkArgument(opts.secret);
2014-09-08 10:46:57 -03:00
preconditions.checkArgument(cb);
2014-08-20 18:00:33 -04:00
var self = this;
2014-09-14 13:52:43 -03:00
var decodedSecret = this.decodeSecret(opts.secret);
2014-09-10 14:01:10 -07:00
if (!decodedSecret || !decodedSecret.networkName || !decodedSecret.pubKey) {
return cb('badSecret');
}
2014-06-16 15:51:19 -03:00
2014-08-20 18:00:33 -04:00
var privOpts = {
networkName: decodedSecret.networkName,
2014-08-20 18:00:33 -04:00
};
2014-09-14 13:52:43 -03:00
if (opts.privateHex && opts.privateHex.length > 1) {
2014-10-04 11:30:08 -03:00
privOpts.extendedPrivateKeyString = opts.privateHex;
2014-08-20 18:00:33 -04:00
}
2014-04-20 12:41:28 -03:00
//Create our PrivateK
2014-08-20 18:00:33 -04:00
var privateKey = new PrivateKey(privOpts);
2014-09-01 12:35:40 -03:00
log.debug('\t### PrivateKey Initialized');
2014-09-18 18:29:00 -03:00
var joinOpts = {
2014-04-24 23:13:55 -03:00
copayerId: privateKey.getId(),
privkey: privateKey.getIdPriv(),
2014-09-03 16:51:02 -03:00
key: privateKey.getIdKey(),
secretNumber: decodedSecret.secretNumber,
2014-04-24 23:13:55 -03:00
};
2014-10-07 18:33:55 -03:00
var joinNetwork = opts.Async || new Async(this.networkOpts[decodedSecret.networkName]);
// This is a hack to reconize if the connection was rejected or the peer wasn't there.
var connectedOnce = false;
joinNetwork.on('connected', function(sender, data) {
connectedOnce = true;
});
joinNetwork.on('connect_error', function() {
return cb('connectionError');
});
joinNetwork.on('serverError', function() {
return cb('joinError');
});
2014-09-18 18:29:00 -03:00
joinNetwork.start(joinOpts, function() {
joinNetwork.greet(decodedSecret.pubKey, joinOpts.secretNumber);
joinNetwork.on('data', function(sender, data) {
2014-09-15 14:25:09 -03:00
if (data.type === 'walletId' && data.opts) {
2014-10-04 19:52:43 -03:00
if (!data.networkName || data.networkName !== decodedSecret.networkName) {
return cb('badNetwork');
}
2014-10-04 19:52:43 -03:00
data.opts.networkName = data.networkName;
2014-09-23 15:24:57 -03:00
var walletOpts = _.clone(data.opts);
2014-09-18 18:29:00 -03:00
walletOpts.id = data.walletId;
2014-10-14 19:49:29 -03:00
walletOpts.network = joinNetwork;
2014-09-18 18:29:00 -03:00
walletOpts.privateKey = privateKey;
walletOpts.nickname = opts.nickname || self.getName();
if (opts.password)
walletOpts.password = opts.password;
2014-09-18 18:29:00 -03:00
2014-09-28 18:38:06 -03:00
self.createWallet(walletOpts, function(err, w) {
2014-09-18 18:29:00 -03:00
if (w) {
w.sendWalletReady(decodedSecret.pubKey);
2014-09-15 14:25:09 -03:00
} else {
if (!err) err = 'walletFull';
2014-09-18 18:29:00 -03:00
log.info(err);
2014-09-15 14:25:09 -03:00
}
return cb(err, w);
});
2014-04-20 16:16:09 -03:00
}
2014-04-16 20:58:57 -03:00
});
});
};
2014-09-27 17:14:49 -03:00
module.exports = Identity;