completes pkr
This commit is contained in:
parent
2121565070
commit
d56dcd41de
|
@ -62,7 +62,43 @@ function API(opts) {
|
|||
};
|
||||
|
||||
|
||||
API.prototype._loadAndCheck = function(opts, cb) {
|
||||
API.prototype._tryToComplete = function(data, cb) {
|
||||
var self = this;
|
||||
var isCorrupted;
|
||||
|
||||
var url = '/v1/wallets/';
|
||||
self._doGetRequest(url, data, function(err, wallet) {
|
||||
if (err) return cb(err);
|
||||
if (wallet.n > 0 && wallet.status === 'complete' && !data.verified) {
|
||||
var pubKey = Bitcore.PrivateKey.fromString(data.walletPrivKey).toPublicKey().toString();
|
||||
var fake = [];
|
||||
_.each(wallet.copayers, function(copayer) {
|
||||
if (!SignUtils.verify(copayer.xPubKey, copayer.xPubKeySignature, pubKey)) {
|
||||
fake.push(copayer);
|
||||
}
|
||||
});
|
||||
if (fake.length > 0) {
|
||||
isCorrupted = true;
|
||||
data.verified = 'corrupt';
|
||||
} else {
|
||||
data.verified = 'ok';
|
||||
}
|
||||
self.storage.save(data, function(err) {
|
||||
if (isCorrupted) {
|
||||
return cb('Some copayers in the wallet could not be verified to have known the wallet secret');
|
||||
}
|
||||
return cb(err, data);
|
||||
});
|
||||
}
|
||||
return cb(null, data);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
API.prototype._loadAndCheck = function(cb) {
|
||||
var self = this;
|
||||
this.storage.load(function(err, data) {
|
||||
if (err || !data) {
|
||||
return cb(err || 'Wallet file not found.');
|
||||
|
@ -74,8 +110,8 @@ API.prototype._loadAndCheck = function(opts, cb) {
|
|||
if (data.n > 1) {
|
||||
var pkrComplete = data.publicKeyRing && data.m && data.publicKeyRing.length === data.n;
|
||||
|
||||
if (opts.requireCompletePKR && !pkrComplete) {
|
||||
return cb('Wallet Incomplete, cannot derive address');
|
||||
if (!pkrComplete) {
|
||||
return self._tryToComplete(data, cb);
|
||||
}
|
||||
}
|
||||
return cb(null, data);
|
||||
|
@ -222,39 +258,12 @@ API.prototype.joinWallet = function(secret, copayerName, cb) {
|
|||
API.prototype.getStatus = function(cb) {
|
||||
var self = this;
|
||||
|
||||
this._loadAndCheck({}, function(err, data) {
|
||||
this._loadAndCheck(function(err, data) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var url = '/v1/wallets/';
|
||||
self._doGetRequest(url, data, function(err, body) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var wallet = body;
|
||||
if (wallet.n > 0 && wallet.status === 'complete' && !data.verified) {
|
||||
var pubKey = Bitcore.PrivateKey.fromString(data.walletPrivKey).toPublicKey().toString();
|
||||
var fake = [];
|
||||
_.each(wallet.copayers, function(copayer) {
|
||||
|
||||
|
||||
console.log('[clilib.js.224]', copayer.xPubKey, copayer.xPubKeySignature, pubKey); //TODO
|
||||
if (!SignUtils.verify(copayer.xPubKey, copayer.xPubKeySignature, pubKey)) {
|
||||
|
||||
console.log('[clilib.js.227] FAKE'); //TODO
|
||||
fake.push(copayer);
|
||||
}
|
||||
});
|
||||
if (fake.length > 0) {
|
||||
log.error('Some copayers in the wallet could not be verified to have known the wallet secret');
|
||||
data.verified = 'corrupt';
|
||||
} else {
|
||||
data.verified = 'ok';
|
||||
}
|
||||
self.storage.save(data, function(err) {
|
||||
return cb(err, wallet);
|
||||
});
|
||||
}
|
||||
|
||||
return cb(null, wallet);
|
||||
return cb(err, body);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -270,9 +279,8 @@ API.prototype.getStatus = function(cb) {
|
|||
API.prototype.sendTxProposal = function(inArgs, cb) {
|
||||
var self = this;
|
||||
|
||||
this._loadAndCheck({
|
||||
requireCompletePKR: true
|
||||
}, function(err, data) {
|
||||
this._loadAndCheck(
|
||||
function(err, data) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var args = _createProposalOpts(inArgs, data.signingPrivKey);
|
||||
|
@ -285,9 +293,8 @@ API.prototype.sendTxProposal = function(inArgs, cb) {
|
|||
API.prototype.createAddress = function(cb) {
|
||||
var self = this;
|
||||
|
||||
this._loadAndCheck({
|
||||
requireCompletePKR: true
|
||||
}, function(err, data) {
|
||||
this._loadAndCheck(
|
||||
function(err, data) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var url = '/v1/addresses/';
|
||||
|
@ -309,7 +316,7 @@ API.prototype.history = function(limit, cb) {
|
|||
API.prototype.getBalance = function(cb) {
|
||||
var self = this;
|
||||
|
||||
this._loadAndCheck({}, function(err, data) {
|
||||
this._loadAndCheck(function(err, data) {
|
||||
if (err) return cb(err);
|
||||
var url = '/v1/balance/';
|
||||
self._doGetRequest(url, data, cb);
|
||||
|
@ -320,9 +327,8 @@ API.prototype.getBalance = function(cb) {
|
|||
API.prototype.getTxProposals = function(opts, cb) {
|
||||
var self = this;
|
||||
|
||||
this._loadAndCheck({
|
||||
requireCompletePKR: true
|
||||
}, function(err, data) {
|
||||
this._loadAndCheck(
|
||||
function(err, data) {
|
||||
if (err) return cb(err);
|
||||
var url = '/v1/txproposals/';
|
||||
self._doGetRequest(url, data, cb);
|
||||
|
@ -332,9 +338,8 @@ API.prototype.getTxProposals = function(opts, cb) {
|
|||
API.prototype.signTxProposal = function(txp, cb) {
|
||||
var self = this;
|
||||
|
||||
this._loadAndCheck({
|
||||
requireCompletePKR: true
|
||||
}, function(err, data) {
|
||||
this._loadAndCheck(
|
||||
function(err, data) {
|
||||
if (err) return cb(err);
|
||||
|
||||
|
||||
|
@ -379,9 +384,8 @@ API.prototype.signTxProposal = function(txp, cb) {
|
|||
API.prototype.rejectTxProposal = function(txp, reason, cb) {
|
||||
var self = this;
|
||||
|
||||
this._loadAndCheck({
|
||||
requireCompletePKR: true
|
||||
}, function(err, data) {
|
||||
this._loadAndCheck(
|
||||
function(err, data) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var url = '/v1/txproposals/' + txp.id + '/rejections/';
|
||||
|
@ -395,9 +399,8 @@ API.prototype.rejectTxProposal = function(txp, reason, cb) {
|
|||
API.prototype.broadcastTxProposal = function(txp, cb) {
|
||||
var self = this;
|
||||
|
||||
this._loadAndCheck({
|
||||
requireCompletePKR: true
|
||||
}, function(err, data) {
|
||||
this._loadAndCheck(
|
||||
function(err, data) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var url = '/v1/txproposals/' + txp.id + '/broadcast/';
|
||||
|
@ -409,9 +412,8 @@ API.prototype.broadcastTxProposal = function(txp, cb) {
|
|||
|
||||
API.prototype.removeTxProposal = function(txp, cb) {
|
||||
var self = this;
|
||||
this._loadAndCheck({
|
||||
requireCompletePKR: true
|
||||
}, function(err, data) {
|
||||
this._loadAndCheck(
|
||||
function(err, data) {
|
||||
if (err) return cb(err);
|
||||
var url = '/v1/txproposals/' + txp.id;
|
||||
self._doRequest('delete', url, {}, data, cb);
|
||||
|
|
Loading…
Reference in New Issue