migrate wallet compat test to wallet :D :D :D
This commit is contained in:
parent
c9a4046759
commit
3e968129de
3 changed files with 72 additions and 146 deletions
|
|
@ -55,6 +55,7 @@ function Identity(email, password, opts) {
|
||||||
this.walletDefaults = opts.wallet || {};
|
this.walletDefaults = opts.wallet || {};
|
||||||
this.version = opts.version || version;
|
this.version = opts.version || version;
|
||||||
|
|
||||||
|
// open wallets
|
||||||
this.wallets = [];
|
this.wallets = [];
|
||||||
this.profile = Identity._newProfile({
|
this.profile = Identity._newProfile({
|
||||||
email: email,
|
email: email,
|
||||||
|
|
@ -67,37 +68,34 @@ Identity._newProfile = function(info, password, storage) {
|
||||||
return new Profile(info, password, storage);
|
return new Profile(info, password, storage);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* for stubbing */
|
|
||||||
Identity._newInsight = function(opts) {
|
Identity._newInsight = function(opts) {
|
||||||
return new Insight(opts);
|
return new Insight(opts);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* for stubbing */
|
|
||||||
Identity._newStorage = function(opts) {
|
Identity._newStorage = function(opts) {
|
||||||
return new Storage(opts);
|
return new Storage(opts);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* for stubbing */
|
|
||||||
Identity._newWallet = function(opts) {
|
Identity._newWallet = function(opts) {
|
||||||
return new Wallet(opts);
|
return new Wallet(opts);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* for stubbing */
|
|
||||||
Identity._walletFromObj = function(o, s, n, b, skip) {
|
Identity._walletFromObj = function(o, s, n, b, skip) {
|
||||||
return Wallet.fromObj(o, s, n, b, skip);
|
return Wallet.fromObj(o, s, n, b, skip);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* for stubbing */
|
|
||||||
Identity._walletRead = function(id, s, n, b, skip, cb) {
|
Identity._walletRead = function(id, s, n, b, skip, cb) {
|
||||||
return Wallet.read(id, s, n, b, skip, cb);
|
return Wallet.read(id, s, n, b, skip, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* for stubbing */
|
|
||||||
Identity._walletDelete = function(id, cb) {
|
Identity._walletDelete = function(id, cb) {
|
||||||
return Wallet.delete(id, cb);
|
return Wallet.delete(id, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Identity._profileOpen = function(e, p, s, cb) {
|
||||||
|
return Profile.open(e, p, s, cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -145,8 +143,12 @@ Identity.prototype.validate = function(authcode, cb) {
|
||||||
*/
|
*/
|
||||||
Identity.open = function(email, password, opts, cb) {
|
Identity.open = function(email, password, opts, cb) {
|
||||||
var iden = new Identity(email, password, opts);
|
var iden = new Identity(email, password, opts);
|
||||||
iden.read(function(err) {
|
|
||||||
return cb(err, iden);
|
Identity._profileOpen(email, password, iden.storage, function(err, profile){
|
||||||
|
if (err) return cb(err);
|
||||||
|
iden.profile = profile;
|
||||||
|
|
||||||
|
return cb(null, iden);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -191,35 +193,6 @@ Identity.prototype.store = function(opts, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* read
|
|
||||||
*
|
|
||||||
* @param opts
|
|
||||||
* @param cb
|
|
||||||
* @return {undefined}
|
|
||||||
*/
|
|
||||||
Identity.prototype.read = function(opts, cb) {
|
|
||||||
var self = this;
|
|
||||||
self.profile.read(opts, function(err) {
|
|
||||||
if (err) return cb(err);
|
|
||||||
|
|
||||||
var l = self.wallets.length,
|
|
||||||
i = 0;
|
|
||||||
if (!l) return cb();
|
|
||||||
|
|
||||||
_.each(self.wallets, function(w) {
|
|
||||||
w.store(function(err) {
|
|
||||||
if (err) return cb(err);
|
|
||||||
|
|
||||||
if (++i == l)
|
|
||||||
return cb();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Imports a wallet from an encrypted base64 object
|
* @desc Imports a wallet from an encrypted base64 object
|
||||||
* @param {string} base64 - the base64 encoded object
|
* @param {string} base64 - the base64 encoded object
|
||||||
|
|
@ -324,6 +297,7 @@ Identity.prototype.createWallet = function(opts, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// add open wallet?
|
||||||
Identity.prototype.addWallet = function(wallet, cb) {
|
Identity.prototype.addWallet = function(wallet, cb) {
|
||||||
preconditions.checkArgument(wallet);
|
preconditions.checkArgument(wallet);
|
||||||
preconditions.checkArgument(wallet.getId);
|
preconditions.checkArgument(wallet.getId);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue