Browse Source

copayer id = uuid

activeAddress
Matias Alejo Garcia 10 years ago
parent
commit
97b6ebdc97
  1. 5
      TODO.txt
  2. 7
      lib/model/copayer.js
  3. 4
      lib/model/txproposal.js
  4. 2
      lib/model/wallet.js
  5. 7
      lib/server.js
  6. 1
      lib/storage.js
  7. 4
      package.json
  8. 23
      test/integration.js

5
TODO.txt

@ -1,5 +1,8 @@
- When creating a wallet, the id should be generated by the server and returned to the client to be used as part of the wallet secret.
- Copayer id should be auto-generated.
- Check not blank & length < 100 for both wallet.name & copayer.name
- Proposal with spent input should be tagged as invalid or removed
- Cron job to broadcast accepted txps that failed to broadcast (we may need to track broadcast attempts for this).
- check parameters for KEY at storage

7
lib/model/copayer.js

@ -5,7 +5,7 @@ var util = require('util');
var Bitcore = require('bitcore');
var HDPublicKey = Bitcore.HDPublicKey;
var Uuid = require('uuid');
var AddressManager = require('./addressmanager');
@ -16,13 +16,14 @@ function Copayer(opts) {
opts = opts || {};
opts.copayerIndex = opts.copayerIndex || 0;
this.id = Uuid.v4();
this.version = VERSION;
this.createdOn = Math.floor(Date.now() / 1000);
this.id = opts.id;
this.name = opts.name;
this.xPubKey = opts.xPubKey;
this.xPubKeySignature = opts.xPubKeySignature; // So third parties can check independently
this.signingPubKey = this.getSigningPubKey();
if (this.xPubKey)
this.signingPubKey = this.getSigningPubKey();
this.addressManager = new AddressManager({ copayerIndex: opts.copayerIndex });
};

4
lib/model/txproposal.js

@ -1,7 +1,7 @@
'use strict';
var _ = require('lodash');
var Guid = require('guid');
var Uuid = require('uuid');
var Bitcore = require('bitcore');
var Address = Bitcore.Address;
@ -14,7 +14,7 @@ function TxProposal(opts) {
this.version = VERSION;
this.createdOn = Math.floor(Date.now() / 1000);
this.id = Guid.raw();
this.id = Uuid.v4();
this.creatorId = opts.creatorId;
this.toAddress = opts.toAddress;
this.amount = opts.amount;

2
lib/model/wallet.js

@ -71,7 +71,7 @@ Wallet.fromObj = function(obj) {
x.status = obj.status;
x.publicKeyRing = obj.publicKeyRing;
x.copayers = _.map(obj.copayers, function(copayer) {
return new Copayer(copayer);
return Copayer.fromObj(copayer);
});
x.pubKey = obj.pubKey;
x.isTestnet = obj.isTestnet;

7
lib/server.js

@ -147,7 +147,6 @@ CopayServer.prototype._verifySignature = function(text, signature, pubKey) {
* Joins a wallet in creation.
* @param {Object} opts
* @param {string} opts.walletId - The wallet id.
* @param {string} opts.id - The copayer id.
* @param {string} opts.name - The copayer name.
* @param {number} opts.xPubKey - Extended Public Key for this copayer.
* @param {number} opts.xPubKeySignature - Signature of xPubKey using the wallet pubKey.
@ -155,7 +154,7 @@ CopayServer.prototype._verifySignature = function(text, signature, pubKey) {
CopayServer.prototype.joinWallet = function(opts, cb) {
var self = this;
Utils.checkRequired(opts, ['walletId', 'id', 'name', 'xPubKey', 'xPubKeySignature']);
Utils.checkRequired(opts, ['walletId', 'name', 'xPubKey', 'xPubKeySignature']);
Utils.runLocked(opts.walletId, cb, function(cb) {
self.storage.fetchWallet(opts.walletId, function(err, wallet) {
@ -172,7 +171,6 @@ CopayServer.prototype.joinWallet = function(opts, cb) {
if (wallet.copayers.length == wallet.n) return cb(new ClientError('WFULL', 'Wallet full'));
var copayer = new Copayer({
id: opts.id,
name: opts.name,
xPubKey: opts.xPubKey,
xPubKeySignature: opts.xPubKeySignature,
@ -180,9 +178,8 @@ CopayServer.prototype.joinWallet = function(opts, cb) {
});
wallet.addCopayer(copayer);
self.storage.storeWalletAndUpdateCopayersLookup(wallet, function(err) {
return cb(err);
return cb(err, copayer.id);
});
});
});

1
lib/storage.js

@ -29,7 +29,6 @@ var opKeyTs = function(key) {
};
var KEY = {
WALLET: function(id) {
return 'wallet!' + id;

4
package.json

@ -18,7 +18,7 @@
},
"dependencies": {
"async": "^0.9.0",
"bitcore": "0.9.6",
"bitcore": "*",
"bitcore-explorers": "^0.9.1",
"express": "^4.10.0",
"inherits": "^2.0.1",
@ -27,7 +27,7 @@
"lodash": "^2.4.1",
"npmlog": "^0.1.1",
"preconditions": "^1.0.7",
"guid":"*"
"uuid":"*"
},
"devDependencies": {
"chai": "^1.9.1",

23
test/integration.js

@ -75,6 +75,7 @@ helpers.getAuthServer = function(copayerId, cb) {
helpers.createAndJoinWallet = function(id, m, n, cb) {
var server = new CopayServer();
var copayerIds = [];
var walletOpts = {
id: id,
@ -90,19 +91,19 @@ helpers.createAndJoinWallet = function(id, m, n, cb) {
var copayerOpts = {
walletId: id,
id: '' + i,
name: 'copayer ' + i,
xPubKey: someXPubKeys[i - 1],
xPubKeySignature: someXPubKeysSignatures[i - 1],
};
server.joinWallet(copayerOpts, function(err) {
server.joinWallet(copayerOpts, function(err, copayerId) {
copayerIds.push(copayerId);
return cb(err);
});
}, function(err) {
if (err) return new Error('Could not generate wallet');
helpers.getAuthServer('1', function(s) {
helpers.getAuthServer(copayerIds[0], function(s) {
s.getWallet({}, function(err, w) {
cb(s, w);
});
@ -333,20 +334,19 @@ describe('Copay server', function() {
should.not.exist(err);
var copayerOpts = {
walletId: '123',
id: '999',
name: 'me',
xPubKey: aXPubKey,
xPubKeySignature: aXPubKeySignature,
};
server.joinWallet(copayerOpts, function(err) {
server.joinWallet(copayerOpts, function(err, copayerId) {
should.not.exist(err);
helpers.getAuthServer('999', function(server) {
helpers.getAuthServer(copayerId, function(server) {
server.getWallet({}, function(err, wallet) {
wallet.id.should.equal('123');
wallet.copayers.length.should.equal(1);
var copayer = wallet.copayers[0];
copayer.id.should.equal('999');
copayer.name.should.equal('me');
copayer.id.should.equal(copayerId);
done();
});
});
@ -366,7 +366,6 @@ describe('Copay server', function() {
should.not.exist(err);
var copayerOpts = {
walletId: '234',
id: '999',
name: 'me',
xPubKey: 'dummy',
xPubKeySignature: 'dummy',
@ -402,12 +401,12 @@ describe('Copay server', function() {
xPubKey: someXPubKeys[1],
xPubKeySignature: someXPubKeysSignatures[1],
};
server.joinWallet(copayer1Opts, function(err) {
server.joinWallet(copayer1Opts, function(err, copayer1Id) {
should.not.exist(err);
helpers.getAuthServer('111', function(server) {
helpers.getAuthServer(copayer1Id, function(server) {
server.getWallet({}, function(err, wallet) {
wallet.status.should.equal('complete');
server.joinWallet(copayer2Opts, function(err) {
server.joinWallet(copayer2Opts, function(err, copayer2Id) {
should.exist(err);
err.code.should.equal('WFULL');
err.message.should.equal('Wallet full');
@ -563,7 +562,7 @@ describe('Copay server', function() {
message: aText,
signature: aTextSignature,
};
helpers.getAuthServer('2', function (server) {
helpers.getAuthServer(wallet.copayers[1].id, function (server) {
server.verifyMessageSignature(opts, function(err, isValid) {
should.not.exist(err);
isValid.should.be.false;

Loading…
Cancel
Save