|
|
@ -11,6 +11,7 @@ var Explorers = require('bitcore-explorers'); |
|
|
|
|
|
|
|
var Lock = require('./lock'); |
|
|
|
var Storage = require('./storage'); |
|
|
|
var SignUtils = require('./signutils'); |
|
|
|
|
|
|
|
var Wallet = require('./model/wallet'); |
|
|
|
var Copayer = require('./model/copayer'); |
|
|
@ -77,7 +78,6 @@ CopayServer.prototype.createWallet = function (opts, cb) { |
|
|
|
self.storage.fetchWallet(opts.id, function (err, wallet) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (!wallet) return cb('Wallet not found'); |
|
|
|
|
|
|
|
return cb(null, wallet); |
|
|
|
}); |
|
|
|
}; |
|
|
@ -95,6 +95,16 @@ CopayServer.prototype._runLocked = function (walletId, cb, task) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Verifies a signature |
|
|
|
* @param text |
|
|
|
* @param signature |
|
|
|
* @param pubKey |
|
|
|
*/ |
|
|
|
CopayServer.prototype._verifySignature = function (text, signature, pubKey) { |
|
|
|
return SignUtils.verify( text, signature, pubKey); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Joins a wallet in creation. |
|
|
|
* @param {Object} opts |
|
|
@ -110,11 +120,13 @@ CopayServer.prototype._runLocked = function (walletId, cb, task) { |
|
|
|
self._runLocked(opts.walletId, cb, function (cb) { |
|
|
|
self.getWallet({ id: opts.walletId }, function (err, wallet) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
if (!self._verifySignature(opts.xPubKey, opts.xPubKeySignature, wallet.pubKey)) { |
|
|
|
return cb('Bad request'); |
|
|
|
} |
|
|
|
|
|
|
|
if (_.find(wallet.copayers, { xPubKey: opts.xPubKey })) return cb('Copayer already in wallet'); |
|
|
|
if (wallet.copayers.length == wallet.n) return cb('Wallet full'); |
|
|
|
// TODO: validate copayer's extended public key using the public key from this wallet
|
|
|
|
// Note: use Bitcore.crypto.ecdsa .verify()
|
|
|
|
|
|
|
|
var copayer = new Copayer({ |
|
|
|
id: opts.id, |
|
|
|
name: opts.name, |
|
|
|