|
|
@ -83,8 +83,7 @@ function API(opts) { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
API.prototype._tryToComplete = function(data, cb) { |
|
|
|
API.prototype._tryToCompleteFromServer = function(data, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var url = '/v1/wallets/'; |
|
|
@ -112,6 +111,24 @@ API.prototype._tryToComplete = function(data, cb) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
API.prototype._tryToComplete = function(opts, data, cb) { |
|
|
|
if (opts.pkr) { |
|
|
|
var pkr = _decryptMessage(opts.pkr, data.sharedEncryptingKey); |
|
|
|
|
|
|
|
if (!pkr) |
|
|
|
return cb('Could not complete wallet'); |
|
|
|
|
|
|
|
data.publicKeyRing = JSON.parse(pkr); |
|
|
|
this.storage.save(data, function(err) { |
|
|
|
return cb(err, data); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
this._tryToCompleteFromServer(data,cb); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
API.prototype._load = function(cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
@ -124,7 +141,12 @@ API.prototype._load = function(cb) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
API.prototype._loadAndCheck = function(cb) { |
|
|
|
/** |
|
|
|
* _loadAndCheck |
|
|
|
* |
|
|
|
* @param opts.pkr |
|
|
|
*/ |
|
|
|
API.prototype._loadAndCheck = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._load(function(err, data) { |
|
|
@ -133,7 +155,7 @@ API.prototype._loadAndCheck = function(cb) { |
|
|
|
var pkrComplete = data.publicKeyRing && data.m && data.publicKeyRing.length === data.n; |
|
|
|
|
|
|
|
if (!pkrComplete) { |
|
|
|
return self._tryToComplete(data, cb); |
|
|
|
return self._tryToComplete(opts, data, cb); |
|
|
|
} |
|
|
|
} |
|
|
|
return cb(null, data); |
|
|
@ -270,7 +292,7 @@ API.prototype.createWallet = function(walletName, copayerName, m, n, network, cb |
|
|
|
|
|
|
|
API.prototype.reCreateWallet = function(walletName, cb) { |
|
|
|
var self = this; |
|
|
|
this._loadAndCheck(function(err, data) { |
|
|
|
this._loadAndCheck({}, function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
var walletPrivKey = new Bitcore.PrivateKey(); |
|
|
@ -351,7 +373,7 @@ API.prototype.sendTxProposal = function(opts, cb) { |
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._loadAndCheck(function(err, data) { |
|
|
|
this._loadAndCheck({}, function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
if (!data.rwPrivKey) |
|
|
@ -374,7 +396,7 @@ API.prototype.sendTxProposal = function(opts, cb) { |
|
|
|
API.prototype.createAddress = function(cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._loadAndCheck(function(err, data) { |
|
|
|
this._loadAndCheck({}, function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
var url = '/v1/addresses/'; |
|
|
@ -396,7 +418,7 @@ API.prototype.createAddress = function(cb) { |
|
|
|
API.prototype.getMainAddresses = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._loadAndCheck(function(err, data) { |
|
|
|
this._loadAndCheck({}, function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
var url = '/v1/addresses/'; |
|
|
@ -422,7 +444,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); |
|
|
@ -440,7 +462,7 @@ API.prototype.export = function(opts, cb) { |
|
|
|
opts = opts || {}; |
|
|
|
var access = opts.access || 'full'; |
|
|
|
|
|
|
|
this._loadAndCheck(function(err, data) { |
|
|
|
this._loadAndCheck({}, function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
var v = []; |
|
|
|
|
|
|
@ -517,19 +539,12 @@ API.prototype.import = function(str, cb) { |
|
|
|
* |
|
|
|
*/ |
|
|
|
|
|
|
|
API.prototype.parseTxProposals = function(txps, cb) { |
|
|
|
API.prototype.parseTxProposals = function(txData, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._load(function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (data.n > 1) { |
|
|
|
var pkrComplete = data.publicKeyRing && data.m && data.publicKeyRing.length === data.n; |
|
|
|
if (!pkrComplete) { |
|
|
|
return cb('Wallet Incomplete'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this._loadAndCheck({pkr: txData.pkr},function(err, data) { |
|
|
|
|
|
|
|
var txps = txData.txps; |
|
|
|
_processTxps(txps, data.sharedEncryptingKey); |
|
|
|
|
|
|
|
var fake = _.any(txps, function(txp) { |
|
|
@ -555,7 +570,7 @@ API.prototype.parseTxProposals = function(txps, cb) { |
|
|
|
API.prototype.getTxProposals = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._loadAndCheck(function(err, data) { |
|
|
|
this._loadAndCheck({}, function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
var url = '/v1/txproposals/'; |
|
|
|
self._doGetRequest(url, data, function(err, txps) { |
|
|
@ -619,7 +634,7 @@ API.prototype.getSignatures = function(txp, cb) { |
|
|
|
$.checkArgument(txp.creatorId); |
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._loadAndCheck(function(err, data) { |
|
|
|
this._loadAndCheck({}, function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
if (!Verifier.checkTxProposal(data, txp)) { |
|
|
@ -630,12 +645,25 @@ API.prototype.getSignatures = function(txp, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
API.prototype.getEncryptedPublicKeyRing = function(cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._loadAndCheck({}, function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
var pkr = JSON.stringify(data.publicKeyRing); |
|
|
|
return cb(null, _encryptMessage(pkr, data.sharedEncryptingKey)); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
API.prototype.signTxProposal = function(txp, cb) { |
|
|
|
$.checkArgument(txp.creatorId); |
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._loadAndCheck(function(err, data) { |
|
|
|
this._loadAndCheck({}, function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
if (!Verifier.checkTxProposal(data, txp)) { |
|
|
@ -658,7 +686,7 @@ API.prototype.rejectTxProposal = function(txp, reason, cb) { |
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._loadAndCheck( |
|
|
|
this._loadAndCheck({}, |
|
|
|
function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
@ -673,7 +701,7 @@ API.prototype.rejectTxProposal = function(txp, reason, cb) { |
|
|
|
API.prototype.broadcastTxProposal = function(txp, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._loadAndCheck( |
|
|
|
this._loadAndCheck({}, |
|
|
|
function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
@ -686,7 +714,7 @@ API.prototype.broadcastTxProposal = function(txp, cb) { |
|
|
|
|
|
|
|
API.prototype.removeTxProposal = function(txp, cb) { |
|
|
|
var self = this; |
|
|
|
this._loadAndCheck( |
|
|
|
this._loadAndCheck({}, |
|
|
|
function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
var url = '/v1/txproposals/' + txp.id; |
|
|
|