From 1021cbc4fa31c3893fa8ef3047c81d56544469ce Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 30 Dec 2014 15:12:01 -0300 Subject: [PATCH] added checksum methods to profile --- js/models/Identity.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/js/models/Identity.js b/js/models/Identity.js index 51d8c4191..23796c78f 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -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}