diff --git a/lib/model/copayer.js b/lib/model/copayer.js index 5fa31da..db9eef7 100644 --- a/lib/model/copayer.js +++ b/lib/model/copayer.js @@ -48,6 +48,8 @@ Copayer.create = function(opts) { copayerIndex: opts.copayerIndex }); + x.customData = opts.customData; + return x; }; @@ -73,6 +75,8 @@ Copayer.fromObj = function(obj) { } x.addressManager = AddressManager.fromObj(obj.addressManager); + x.customData = obj.customData; + return x; }; diff --git a/lib/server.js b/lib/server.js index b7f99d8..aa1ff39 100644 --- a/lib/server.js +++ b/lib/server.js @@ -291,8 +291,12 @@ WalletService.prototype.getStatus = function(opts, cb) { if (err) return next(err); var walletExtendedKeys = ['publicKeyRing', 'pubKey', 'addressManager']; - var copayerExtendedKeys = ['xPubKey', 'requestPubKey', 'signature', 'addressManager']; + var copayerExtendedKeys = ['xPubKey', 'requestPubKey', 'signature', 'addressManager', 'customData']; + wallet.copayers = _.map(wallet.copayers, function(copayer) { + if (copayer.id == self.copayerId) return copayer; + return _.omit(copayer, 'customData'); + }); if (!opts.includeExtendedInfo) { wallet = _.omit(wallet, walletExtendedKeys); wallet.copayers = _.map(wallet.copayers, function(copayer) { @@ -406,8 +410,8 @@ WalletService.prototype._addCopayerToWallet = function(wallet, opts, cb) { xPubKey: opts.xPubKey, requestPubKey: opts.requestPubKey, signature: opts.copayerSignature, + customData: opts.customData, }); - self.storage.fetchCopayerLookup(copayer.id, function(err, res) { if (err) return cb(err); if (res) return cb(Errors.COPAYER_REGISTERED); @@ -508,7 +512,8 @@ WalletService.prototype.addAccess = function(opts, cb) { * @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 the that the copayer joining knows the wallet secret. + * @param {string} opts.copayerSignature - S(name|xPubKey|requestPubKey). Used by other copayers to verify that the copayer joining knows the wallet secret. + * @param {string} opts.customData - (optional) Custom data for this copayer. */ WalletService.prototype.joinWallet = function(opts, cb) { var self = this; diff --git a/test/integration/server.js b/test/integration/server.js index 2fc2c91..80aab2f 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -104,6 +104,7 @@ helpers.createAndJoinWallet = function(m, n, opts, cb) { name: 'copayer ' + (i + 1), xPubKey: TestData.copayers[i + offset].xPubKey_45H, requestPubKey: TestData.copayers[i + offset].pubKey_1H_0, + customData: 'custom data ' + (i + 1), }); server.joinWallet(copayerOpts, function(err, result) { @@ -912,6 +913,7 @@ describe('Wallet service', function() { name: 'me', xPubKey: TestData.copayers[0].xPubKey_45H, requestPubKey: TestData.copayers[0].pubKey_1H_0, + customData: 'dummy custom data', }); server.joinWallet(copayerOpts, function(err, result) { should.not.exist(err); @@ -923,6 +925,7 @@ describe('Wallet service', function() { var copayer = wallet.copayers[0]; copayer.name.should.equal('me'); copayer.id.should.equal(copayerId); + copayer.customData.should.equal('dummy custom data'); server.getNotifications({}, function(err, notifications) { should.not.exist(err); var notif = _.find(notifications, { @@ -1117,7 +1120,7 @@ describe('Wallet service', function() { }); }); - describe.only('#getStatus', function() { + describe('#getStatus', function() { var server, wallet; beforeEach(function(done) { helpers.createAndJoinWallet(1, 1, function(s, w) { @@ -1144,12 +1147,14 @@ describe('Wallet service', function() { should.not.exist(status.wallet.publicKeyRing); should.not.exist(status.wallet.pubKey); should.not.exist(status.wallet.addressManager); - should.not.exist(status.wallet.copayers[0].xPubKey); - should.not.exist(status.wallet.copayers[0].requestPubKey); - should.not.exist(status.wallet.copayers[0].signature); - should.not.exist(status.wallet.copayers[0].requestPubKey); - should.not.exist(status.wallet.copayers[0].addressManager); - + _.each(status.wallet.copayers, function(copayer) { + should.not.exist(copayer.xPubKey); + should.not.exist(copayer.requestPubKey); + should.not.exist(copayer.signature); + should.not.exist(copayer.requestPubKey); + should.not.exist(copayer.addressManager); + should.not.exist(copayer.customData); + }); done(); }); }); @@ -1167,7 +1172,11 @@ describe('Wallet service', function() { should.exist(status.wallet.copayers[0].signature); should.exist(status.wallet.copayers[0].requestPubKey); should.exist(status.wallet.copayers[0].addressManager); - + should.exist(status.wallet.copayers[0].customData); + // Do not return other copayer's custom data + _.each(_.rest(status.wallet.copayers), function(copayer) { + should.not.exist(copayer.customData); + }); done(); }); }); @@ -1593,7 +1602,8 @@ describe('Wallet service', function() { it('should be able to re-gain access from xPrivKey', function(done) { ws.addAccess(opts, function(err, res) { should.not.exist(err); - server.getBalance(res.wallet.walletId, function(err, bal) { should.not.exist(err); + server.getBalance(res.wallet.walletId, function(err, bal) { + should.not.exist(err); bal.totalAmount.should.equal(1e8); getAuthServer(opts.copayerId, reqPrivKey, function(err, server2) { server2.getBalance(res.wallet.walletId, function(err, bal2) {