removed backup step in wallet creation
This commit is contained in:
parent
0853632827
commit
d5b04d7ad8
5 changed files with 6 additions and 256 deletions
|
|
@ -23,7 +23,6 @@ var HDParams = require('./HDParams');
|
|||
* @param {Object[]} [opts.indexes] - an array to be deserialized using {@link HDParams#fromList}
|
||||
* (defaults to all indexes in zero)
|
||||
* @param {Object=} opts.nicknameFor - nicknames for other copayers
|
||||
* @param {boolean[]} [opts.copayersBackup] - whether other copayers have backed up their wallets
|
||||
*/
|
||||
function PublicKeyRing(opts) {
|
||||
opts = opts || {};
|
||||
|
|
@ -43,7 +42,6 @@ function PublicKeyRing(opts) {
|
|||
this.publicKeysCache = {};
|
||||
this.nicknameFor = opts.nicknameFor || {};
|
||||
this.copayerIds = [];
|
||||
this.copayersBackup = opts.copayersBackup || [];
|
||||
this.addressToPath = {};
|
||||
|
||||
};
|
||||
|
|
@ -63,7 +61,6 @@ function PublicKeyRing(opts) {
|
|||
* @param {Object[]} data.indexes - an array of objects that can be turned into
|
||||
* an array of HDParams
|
||||
* @param {Object} data.nicknameFor - a registry of nicknames for other copayers
|
||||
* @param {boolean[]} data.copayersBackup - whether copayers have backed up their wallets
|
||||
* @param {string[]} data.copayersExtPubKeys - the extended public keys of copayers
|
||||
* @returns {Object} a trimmed down version of PublicKeyRing that can be used
|
||||
* as a parameter
|
||||
|
|
@ -71,7 +68,7 @@ function PublicKeyRing(opts) {
|
|||
PublicKeyRing.trim = function(data) {
|
||||
var opts = {};
|
||||
['walletId', 'networkName', 'requiredCopayers', 'totalCopayers',
|
||||
'indexes', 'nicknameFor', 'copayersBackup', 'copayersExtPubKeys'
|
||||
'indexes', 'nicknameFor', 'copayersExtPubKeys'
|
||||
].forEach(function(k) {
|
||||
opts[k] = data[k];
|
||||
});
|
||||
|
|
@ -119,7 +116,6 @@ PublicKeyRing.prototype.toObj = function() {
|
|||
requiredCopayers: this.requiredCopayers,
|
||||
totalCopayers: this.totalCopayers,
|
||||
indexes: HDParams.serialize(this.indexes),
|
||||
copayersBackup: this.copayersBackup,
|
||||
|
||||
copayersExtPubKeys: this.copayersHK.map(function(b) {
|
||||
return b.extendedPublicKeyString();
|
||||
|
|
@ -685,48 +681,6 @@ PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
|
|||
return hasChanged;
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc
|
||||
* Mark backup as done for us
|
||||
*
|
||||
* @TODO: REVIEW FUNCTIONALITY - it used to have a parameter that was not used at all!
|
||||
*
|
||||
* @return {boolean} true if everybody has backed up their wallet
|
||||
*/
|
||||
PublicKeyRing.prototype.setBackupReady = function() {
|
||||
if (this.isBackupReady()) return false;
|
||||
|
||||
var cid = this.myCopayerId();
|
||||
this.copayersBackup.push(cid);
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc returns true if a copayer has backed up his wallet
|
||||
* @param {string=} copayerId - the pubkey of a copayer, defaults to our own's
|
||||
* @return {boolean} if this copayer has backed up
|
||||
*/
|
||||
PublicKeyRing.prototype.isBackupReady = function(copayerId) {
|
||||
var cid = copayerId || this.myCopayerId();
|
||||
return this.copayersBackup.indexOf(cid) != -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc returns true if all copayers have backed up their wallets
|
||||
* @return {boolean}
|
||||
*/
|
||||
PublicKeyRing.prototype.isFullyBackup = function() {
|
||||
return this.remainingBackups() == 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc returns the amount of backups remaining
|
||||
* @return {boolean}
|
||||
*/
|
||||
PublicKeyRing.prototype.remainingBackups = function() {
|
||||
return this.totalCopayers - this.copayersBackup.length;
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc
|
||||
* Merges this public key ring with another one, optionally ignoring the
|
||||
|
|
@ -742,7 +696,6 @@ PublicKeyRing.prototype.merge = function(inPKR, ignoreId) {
|
|||
var hasChanged = false;
|
||||
hasChanged |= this.mergeIndexes(inPKR.indexes);
|
||||
hasChanged |= this._mergePubkeys(inPKR);
|
||||
hasChanged |= this._mergeBackups(inPKR.copayersBackup);
|
||||
|
||||
return !!hasChanged;
|
||||
};
|
||||
|
|
@ -768,22 +721,5 @@ PublicKeyRing.prototype.mergeIndexes = function(indexes) {
|
|||
return !!hasChanged
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc merges information about backups done by another copy of PublicKeyRing
|
||||
* @param {string[]} backups - another copy of backups
|
||||
* @return {boolean} true if the internal state has changed
|
||||
*/
|
||||
PublicKeyRing.prototype._mergeBackups = function(backups) {
|
||||
var self = this;
|
||||
var hasChanged = false;
|
||||
|
||||
backups.forEach(function(cid) {
|
||||
var isNew = self.copayersBackup.indexOf(cid) == -1;
|
||||
if (isNew) self.copayersBackup.push(cid);
|
||||
hasChanged |= isNew;
|
||||
});
|
||||
|
||||
return !!hasChanged
|
||||
};
|
||||
|
||||
module.exports = PublicKeyRing;
|
||||
|
|
|
|||
|
|
@ -94,13 +94,6 @@ function Wallet(opts) {
|
|||
this.lastTimestamp = opts.lastTimestamp || 0;
|
||||
this.lastMessageFrom = {};
|
||||
|
||||
//to avoid confirmation of copayer's backups if is imported from a file
|
||||
this.isImported = opts.isImported || false;
|
||||
|
||||
|
||||
//to avoid waiting others copayers to make a backup and login immediatly
|
||||
this.forcedLogin = opts.forcedLogin || false;
|
||||
|
||||
this.paymentRequests = opts.paymentRequests || {};
|
||||
|
||||
var networkName = Wallet.obtainNetworkName(opts);
|
||||
|
|
@ -153,7 +146,6 @@ Wallet.PERSISTED_PROPERTIES = [
|
|||
'txProposals',
|
||||
'privateKey',
|
||||
'addressBook',
|
||||
'backupOffered',
|
||||
'lastTimestamp',
|
||||
'secretNumber',
|
||||
];
|
||||
|
|
@ -1000,7 +992,6 @@ Wallet.fromUntrustedObj = function(obj, readOpts) {
|
|||
*
|
||||
* @param readOpts.network
|
||||
* @param readOpts.blockchain
|
||||
* @param readOpts.isImported {boolean} - tag wallet as 'imported' (skip forced backup step)
|
||||
* @param readOpts.{string[]} skipFields - parameters to ignore when importing
|
||||
*/
|
||||
Wallet.fromObj = function(o, readOpts) {
|
||||
|
|
@ -1071,7 +1062,6 @@ Wallet.fromObj = function(o, readOpts) {
|
|||
|
||||
opts.blockchainOpts = readOpts.blockchainOpts;
|
||||
opts.networkOpts = readOpts.networkOpts;
|
||||
opts.isImported = readOpts.isImported || false;
|
||||
|
||||
return new Wallet(opts);
|
||||
};
|
||||
|
|
@ -2617,24 +2607,11 @@ Wallet.prototype.requiresMultipleSignatures = function() {
|
|||
};
|
||||
|
||||
/**
|
||||
* @desc Returns true if the keyring is complete and all users have backed up the wallet
|
||||
* @desc Returns true if the keyring is complete
|
||||
* @return {boolean}
|
||||
*/
|
||||
Wallet.prototype.isReady = function() {
|
||||
var ret = this.publicKeyRing.isComplete() && (this.publicKeyRing.isFullyBackup() || this.isImported || this.forcedLogin);
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc Mark that our backup is ready and send a sync to other users.
|
||||
*
|
||||
* Also backs up the wallet
|
||||
*/
|
||||
Wallet.prototype.setBackupReady = function(forcedLogin) {
|
||||
this.forcedLogin = forcedLogin;
|
||||
this.publicKeyRing.setBackupReady();
|
||||
this.sendPublicKeyRing();
|
||||
this.emitAndKeepAlive('txProposalsUpdated');
|
||||
return this.publicKeyRing.isComplete();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue