removes isTemporaryRequestKey and replaceTemporaryRequestKey feature. No longer supports joining legacy (<0.9) copayers

This commit is contained in:
Matias Alejo Garcia 2015-08-04 11:19:08 -03:00
parent 2582872d3e
commit cfbf184502
4 changed files with 16 additions and 273 deletions

View File

@ -16,6 +16,8 @@ function Copayer() {
this.version = '1.0.0';
};
// requestPubKey could be one or an array of keys
Copayer.create = function(opts) {
opts = opts || {};
$.checkArgument(opts.xPubKey, 'Missing copayer extended public key');

View File

@ -94,7 +94,7 @@ Wallet.prototype.isShared = function() {
Wallet.prototype._updatePublicKeyRing = function() {
this.publicKeyRing = _.map(this.copayers, function(copayer) {
return _.pick(copayer, ['xPubKey', 'requestPubKey', 'isTemporaryRequestKey']);
return _.pick(copayer, ['xPubKey']);
});
};
@ -107,20 +107,24 @@ Wallet.prototype.addCopayer = function(copayer) {
this._updatePublicKeyRing();
};
Wallet.prototype.updateCopayerRequestKey = function(copayerId, requestPubKey, signature) {
Wallet.prototype.addCopayerRequestKey = function(copayerId, requestPubKey, signature) {
$.checkState(this.copayers.length == this.n);
var c = _.find(this.copayers, {
id: copayerId,
});
$.checkState(c);
$.checkState(c)
.checkState(c.isTemporaryRequestKey);
if (_.isArray(c.requestPubKey)) {
$.checkState(_.isArray(c.signature));
c.requestPubKey = requestPubKey;
c.isTemporaryRequestKey = false;
c.signature = signature;
this._updatePublicKeyRing();
c.requestPubKey.push(requestPubKey);
c.signature.push(signature);
} else {
c.requestPubKey = requestPubKey;
c.signature = signature;
}
//this._updatePublicKeyRing();
};
Wallet.prototype.getCopayer = function(copayerId) {

View File

@ -272,71 +272,7 @@ WalletService.prototype.getWallet = function(opts, cb) {
});
};
/**
* Replace temporary request key
* @param {Object} opts
* @param {string} opts.name - The copayer name.
* @param {string} opts.xPubKey - Extended Public Key for this copayer.
* @param {string} opts.requestPubKey - Public Key used to check requests from this copayer.
* @param {string} opts.copayerSignature - S(name|xPubKey|requestPubKey). Used by other copayers to verify that the copayer joining knows the wallet secret.
*/
WalletService.prototype.replaceTemporaryRequestKey = function(opts, cb) {
var self = this;
if (!Utils.checkRequired(opts, ['name', 'xPubKey', 'requestPubKey', 'copayerSignature']))
return cb(new ClientError('Required argument missing'));
if (_.isEmpty(opts.name))
return cb(new ClientError('Invalid copayer name'));
if (opts.isTemporaryRequestKey)
return cb(new ClientError('Bad arguments'));
self._runLocked(cb, function(cb) {
self.storage.fetchWallet(self.walletId, function(err, wallet) {
if (err) return cb(err);
if (!wallet) return cb(Errors.WALLET_NOT_FOUND);
var hash = WalletUtils.getCopayerHash(opts.name, opts.xPubKey, opts.requestPubKey);
if (!self._verifySignature(hash, opts.copayerSignature, wallet.pubKey)) {
return cb(new ClientError());
}
var oldCopayerData = _.find(wallet.copayers, {
id: self.copayerId
});
$.checkState(oldCopayerData);
if (oldCopayerData.xPubKey !== opts.xPubKey || !oldCopayerData.isTemporaryRequestKey)
return cb(Errors.COPAYER_DATA_MISMATCH);
if (wallet.copayers.length != wallet.n)
return cb(Errors.WALLET_NOT_COMPLETE);
wallet.updateCopayerRequestKey(self.copayerId, opts.requestPubKey, opts.copayerSignature);
self.storage.storeWalletAndUpdateCopayersLookup(wallet, function(err) {
if (err) return cb(err);
self._notify('CopayerUpdated', {
walletId: opts.walletId,
copayerId: self.copayerId,
copayerName: opts.name,
}, function() {
return cb(null, {
copayerId: self.copayerId,
wallet: wallet
});
});
});
});
});
};
/**
/*
* Verifies a signature
* @param text
* @param signature

View File

@ -4116,205 +4116,6 @@ describe('Wallet service', function() {
});
});
describe('#replaceTemporaryRequestKey', function() {
var server, walletId;
beforeEach(function(done) {
server = new WalletService();
var walletOpts = {
name: 'my wallet',
m: 2,
n: 2,
pubKey: TestData.keyPair.pub,
};
server.createWallet(walletOpts, function(err, wId) {
should.not.exist(err);
should.exist.walletId;
walletId = wId;
done();
});
});
it('should join existing wallet with temporaryRequestKey', function(done) {
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H,
requestPubKey: TestData.copayers[0].pubKey_1H_0,
});
copayerOpts.isTemporaryRequestKey = true;
server.joinWallet(copayerOpts, function(err, result) {
should.not.exist(err);
var copayerId = result.copayerId;
helpers.getAuthServer(copayerId, function(server) {
server.getWallet({}, function(err, wallet) {
wallet.id.should.equal(walletId);
var copayer = wallet.copayers[0];
copayer.isTemporaryRequestKey.should.equal(true);
done();
});
});
});
});
it('should fail to replace a temporaryRequestKey on a not-complete wallet', function(done) {
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H,
requestPubKey: TestData.copayers[0].pubKey_1_0,
});
copayerOpts.isTemporaryRequestKey = true;
server.joinWallet(copayerOpts, function(err, result) {
should.not.exist(err);
var copayerId = result.copayerId;
helpers.getAuthServer(copayerId, function(server) {
server.getWallet({}, function(err, wallet) {
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H,
requestPubKey: TestData.copayers[0].pubKey_1H_0,
});
copayerOpts.isTemporaryRequestKey = false;
server.replaceTemporaryRequestKey(copayerOpts, function(err, wallet) {
err.code.should.equal('WALLET_NOT_COMPLETE');
done();
});
});
});
});
});
it('should fail to replace a temporaryRequestKey is Copayer is not in wallet', function(done) {
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H,
requestPubKey: TestData.copayers[0].pubKey_1_0,
});
copayerOpts.isTemporaryRequestKey = true;
server.joinWallet(copayerOpts, function(err, result) {
should.not.exist(err);
var copayerId = result.copayerId;
helpers.getAuthServer(copayerId, function(server) {
server.getWallet({}, function(err, wallet) {
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[1].xPubKey_45H,
requestPubKey: TestData.copayers[1].pubKey_1H_0,
});
copayerOpts.isTemporaryRequestKey = false;
server.replaceTemporaryRequestKey(copayerOpts, function(err, wallet) {
err.code.should.equal('COPAYER_DATA_MISMATCH');
done();
});
});
});
});
});
it('should fail replace a temporaryRequestKey with invalid copayer', function(done) {
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H,
requestPubKey: TestData.copayers[0].pubKey_1_0,
});
copayerOpts.isTemporaryRequestKey = true;
server.joinWallet(copayerOpts, function(err, result) {
should.not.exist(err);
var copayerOpts2 = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[1].xPubKey_45H,
requestPubKey: TestData.copayers[1].pubKey_1H_0,
});
copayerOpts2.isTemporaryRequestKey = false;
server.joinWallet(copayerOpts2, function(err, result) {
should.not.exist(err);
var copayerId = result.copayerId;
helpers.getAuthServer(copayerId, function(server) {
server.getWallet({}, function(err, wallet) {
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[1].xPubKey_45H,
requestPubKey: TestData.copayers[1].pubKey_1H_0,
});
copayerOpts.isTemporaryRequestKey = false;
server.replaceTemporaryRequestKey(copayerOpts, function(err, wallet) {
err.code.should.equal('COPAYER_DATA_MISMATCH');
done();
});
});
});
});
});
});
it('should replace a temporaryRequestKey', function(done) {
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H,
requestPubKey: TestData.copayers[0].pubKey_1_0,
});
copayerOpts.isTemporaryRequestKey = true;
server.joinWallet(copayerOpts, function(err, result) {
should.not.exist(err);
var copayerId = result.copayerId;
var copayerOpts2 = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[1].xPubKey_45H,
requestPubKey: TestData.copayers[1].pubKey_1H_0,
});
copayerOpts2.isTemporaryRequestKey = false;
server.joinWallet(copayerOpts2, function(err, result) {
should.not.exist(err);
var copayerId2 = result.copayerId;
helpers.getAuthServer(copayerId, function(server) {
server.getWallet({}, function(err, wallet) {
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H,
requestPubKey: TestData.copayers[0].pubKey_1H_0,
});
copayerOpts.isTemporaryRequestKey = false;
server.replaceTemporaryRequestKey(copayerOpts, function(err, wallet) {
should.not.exist(err);
server.getWallet({}, function(err, wallet) {
wallet.copayers[0].isTemporaryRequestKey.should.equal(false);
wallet.copayers[1].isTemporaryRequestKey.should.equal(false);
done();
});
});
});
});
});
});
});
});
describe('Legacy', function() {
describe('Fees', function() {
var server, wallet;