added checksum methods to profile

This commit is contained in:
Ivan Socolsky 2014-12-30 15:12:01 -03:00
parent 1c6cc3eb20
commit 1021cbc4fa
1 changed files with 20 additions and 0 deletions

View File

@ -76,6 +76,10 @@ Identity.getKeyForEmail = function(email) {
return Identity.getStoragePrefix() + bitcore.util.sha256ripe160(email).toString('hex');
};
Identity.prototype.getChecksumForStorage = function() {
return JSON.stringify(this.walletIds);
};
Identity.prototype.getId = function() {
return Identity.getKeyForEmail(this.email);
};
@ -148,6 +152,22 @@ Identity.open = function(opts, cb) {
});
};
Identity.prototype.verifyChecksum = function (cb) {
var self = this;
self.storage.getItem(Identity.getKeyForEmail(self.email), function(err, data, headers) {
var iden;
if (err) return cb(err);
try {
iden = JSON.parse(data);
} catch (e) {
return cb(e);
}
return cb(null, self.getChecksumForStorage() == self.getChecksumForStorage.call(iden));
};
/**
* @param {string} walletId
* @returns {Wallet}