|
|
@ -62,53 +62,28 @@ function API(opts) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
API.prototype._isWalletCorrupt = function(wallet, data) { |
|
|
|
var pubKey = Bitcore.PrivateKey.fromString(data.walletPrivKey).toPublicKey().toString(); |
|
|
|
var fake = []; |
|
|
|
|
|
|
|
if (data.n != wallet.copayers.length) |
|
|
|
return true; |
|
|
|
|
|
|
|
var uniq = []; |
|
|
|
_.each(wallet.copayers, function(copayer) { |
|
|
|
if (uniq[copayer.xPubKey]++) |
|
|
|
return true; |
|
|
|
|
|
|
|
if (!SignUtils.verify(copayer.xPubKey, copayer.xPubKeySignature, pubKey)) { |
|
|
|
fake.push(copayer); |
|
|
|
} |
|
|
|
}); |
|
|
|
return fake.length > 0; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
API.prototype._tryToComplete = function(data, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var url = '/v1/wallets/'; |
|
|
|
self._doGetRequest(url, data, function(err, wallet) { |
|
|
|
self._doGetRequest(url, data, function(err, ret) { |
|
|
|
if (err) return cb(err); |
|
|
|
var wallet = ret.wallet; |
|
|
|
|
|
|
|
if (wallet.status === 'complete' && !data.verified) { |
|
|
|
|
|
|
|
if (self._isWalletCorrupt(wallet, data)) { |
|
|
|
data.verified = 'corrupt'; |
|
|
|
} else { |
|
|
|
data.verified = 'ok'; |
|
|
|
} |
|
|
|
self.storage.save(data, function(err) { |
|
|
|
if (data.verified == 'corrupt') { |
|
|
|
return cb('Some copayers in the wallet could not be verified to have known the wallet secret'); |
|
|
|
} |
|
|
|
return cb(err, data); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
if (wallet.status != 'complete') |
|
|
|
return cb('Wallet Incomplete'); |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
if (!Verifier.checkCopayers(wallet.copayers, data.walletPrivKey, data.xPrivKey, data.n)) |
|
|
|
return cb('Some copayers in the wallet could not be verified to have known the wallet secret'); |
|
|
|
|
|
|
|
data.publicKeyRing = _.pluck(wallet.copayers, 'xPubKey') |
|
|
|
|
|
|
|
self.storage.save(data, function(err) { |
|
|
|
return cb(err, data); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
API.prototype._loadAndCheck = function(cb) { |
|
|
@ -118,9 +93,6 @@ API.prototype._loadAndCheck = function(cb) { |
|
|
|
if (err || !data) { |
|
|
|
return cb(err || 'Wallet file not found.'); |
|
|
|
} |
|
|
|
if (data.verified == 'corrupt') { |
|
|
|
return cb('The wallet is tagged as corrupt. Some of the copayers cannot be verified to have known the wallet secret.'); |
|
|
|
} |
|
|
|
if (data.n > 1) { |
|
|
|
var pkrComplete = data.publicKeyRing && data.m && data.publicKeyRing.length === data.n; |
|
|
|
|
|
|
|