From a535d93b6fa9211599e77223774ac3301aa05876 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Sun, 15 Jun 2014 20:55:23 -0700 Subject: [PATCH 01/15] make mocha browser tests all run with no console errors ...except Wallet and WalletFactory. --- test/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/test/index.html b/test/index.html index f34a867bf..4d6424d38 100644 --- a/test/index.html +++ b/test/index.html @@ -19,7 +19,6 @@ - From 31d601b2a68cea6498e72c7ee0ac80b89695a1fd Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Sun, 8 Jun 2014 12:59:48 -0700 Subject: [PATCH 02/15] initial work replacing symmetric shared secret with ECIES --- js/models/core/PrivateKey.js | 18 ++++++++++++++--- js/models/core/Wallet.js | 22 ++++++++++----------- js/models/core/WalletFactory.js | 3 ++- js/models/network/WebRTC.js | 35 +++++++++++++++++++++++++-------- 4 files changed, 55 insertions(+), 23 deletions(-) diff --git a/js/models/core/PrivateKey.js b/js/models/core/PrivateKey.js index 1efe93694..09411ab05 100644 --- a/js/models/core/PrivateKey.js +++ b/js/models/core/PrivateKey.js @@ -20,13 +20,25 @@ function PrivateKey(opts) { PrivateKey.prototype.getId = function() { if (!this.id) { - var path = Structure.IdFullBranch; - var idhk = this.bip.derive(path); - this.id= idhk.eckey.public.toString('hex'); + this.cacheId(); } return this.id; }; +PrivateKey.prototype.getIdPriv = function() { + if (!this.idpriv) { + this.cacheId(); + } + return this.idpriv; +}; + +PrivateKey.prototype.cacheId = function() { + var path = Structure.IdFullBranch; + var idhk = this.bip.derive(path); + this.id = idhk.eckey.public.toString('hex'); + this.idpriv = idhk.eckey.private.toString('hex'); +}; + PrivateKey.prototype.deriveBIP45Branch = function() { if (!this.bip45Branch) { this.bip45Branch = this.bip.derive(Structure.BIP45_PUBLIC_PREFIX); diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 98a19d416..58fc1249b 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -38,7 +38,7 @@ function Wallet(opts) { this.id = opts.id || Wallet.getRandomId(); this.name = opts.name; - this.netKey = opts.netKey || SecureRandom.getRandomBuffer(8).toString('base64'); + //this.netKey = opts.netKey || SecureRandom.getRandomBuffer(8).toString('base64'); // Renew token every 24hs if (opts.tokenTime && new Date().getTime() - opts.tokenTime < 86400000) { @@ -216,7 +216,7 @@ Wallet.prototype._optsToObj = function() { requiredCopayers: this.requiredCopayers, totalCopayers: this.totalCopayers, name: this.name, - netKey: this.netKey, + //netKey: this.netKey, version: this.version, }; @@ -240,21 +240,21 @@ Wallet.prototype.getMyCopayerId = function() { Wallet.prototype.getSecret = function() { - var i = new Buffer(this.getMyCopayerId(), 'hex'); - var k = new Buffer(this.netKey, 'base64'); - var b = Buffer.concat([i, k]); - var str = Base58Check.encode(b); + var pubkeybuf = new Buffer(this.getMyCopayerId(), 'hex'); + //var k = new Buffer(this.netKey, 'base64'); + //var b = Buffer.concat([i, k]); + var str = Base58Check.encode(pubkeybuf); return str; }; Wallet.decodeSecret = function(secretB) { var secret = Base58Check.decode(secretB); - var netKeyBuf = secret.slice(-8); + //var netKeyBuf = secret.slice(-8); var pubKeyBuf = secret.slice(0, 33); return { - pubKey: pubKeyBuf.toString('hex'), - netKey: netKeyBuf.toString('base64'), + pubKey: pubKeyBuf.toString('hex')//, + //netKey: netKeyBuf.toString('base64'), } }; @@ -280,8 +280,8 @@ Wallet.prototype.netStart = function() { var startOpts = { copayerId: myId, token: self.token, - maxPeers: self.totalCopayers, - netKey: this.netKey, + maxPeers: self.totalCopayers//, + //netKey: this.netKey, }; if (this.publicKeyRing.isComplete()) { diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index 28f3454f2..02c67dc70 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -220,7 +220,8 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras this.log('\t### PrivateKey Initialized'); var opts = { copayerId: privateKey.getId(), - netKey: s.netKey, + //netKey: s.netKey, + privkey: privateKey.getIdPriv() }; self.network.cleanUp(); self.network.start(opts, function() { diff --git a/js/models/network/WebRTC.js b/js/models/network/WebRTC.js index fad273b1f..715f74d78 100644 --- a/js/models/network/WebRTC.js +++ b/js/models/network/WebRTC.js @@ -43,7 +43,8 @@ Network.prototype.cleanUp = function() { this.started = false; this.connectedPeers = []; this.peerId = null; - this.netKey = null; + //this.netKey = null; + this.privkey = null; //TODO: hide privkey in a closure this.copayerId = null; this.signingKey = null; this.allowedCopayerIds=null; @@ -150,11 +151,14 @@ Network.prototype._addConnectedCopayer = function(copayerId, isInbound) { this.emit('connect', copayerId); }; -Network.prototype._onData = function(encStr, isInbound, peerId) { +Network.prototype._onData = function(enchex, isInbound, peerId) { var sig, payload; + var encbuf = new Buffer(enchex, 'hex'); + + var privkey = this.privkey; try { - var data = this._decrypt(encStr); + var data = this._decrypt(privkey, encbuf); payload= JSON.parse(data); } catch (e) { this._deletePeer(peerId); @@ -300,7 +304,8 @@ Network.prototype.start = function(opts, openCallback) { if (this.started) return openCallback(); - this.netKey = opts.netKey; + //this.netKey = opts.netKey; + this.privkey = opts.privkey; this.maxPeers = opts.maxPeers || this.maxPeers; if (opts.token) @@ -344,7 +349,11 @@ Network.prototype.getPeer = function() { return this.peer; }; -Network.prototype._encrypt = function(payloadStr) { +Network.prototype._encrypt = function(pubkey, payload) { + var encrypted = bitcore.ECIES.encrypt(pubkey, payload); + return encrypted; + + /* var plainText = sjcl.codec.utf8String.toBits(payloadStr); var p = this.sjclParams; ct = sjcl.encrypt(this.netKey, plainText, p);//,p, rp); @@ -354,10 +363,15 @@ Network.prototype._encrypt = function(payloadStr) { ct: c.ct, }; return JSON.stringify(toSend); + */ }; -Network.prototype._decrypt = function(encStr) { +Network.prototype._decrypt = function(privkey, encrypted) { + var decrypted = bitcore.ECIES.decrypt(privkey, encrypted); + return decrypted; + + /* var i = JSON.parse(encStr); for (var k in this.sjclParams) { i[k] = this.sjclParams[k]; @@ -365,6 +379,7 @@ Network.prototype._decrypt = function(encStr) { var str= JSON.stringify(i); var pt = sjcl.decrypt(this.netKey, str); return pt; + */ }; Network.prototype._sendToOne = function(copayerId, payload, sig, cb) { @@ -379,7 +394,8 @@ Network.prototype._sendToOne = function(copayerId, payload, sig, cb) { }; Network.prototype.send = function(copayerIds, payload, cb) { - if (!payload || !this.netKey) return cb(); + //if (!payload || !this.netKey) return cb(); + if (!payload) return cb(); var self=this; if (!copayerIds) { @@ -389,11 +405,14 @@ Network.prototype.send = function(copayerIds, payload, cb) { var sig; var payloadStr = JSON.stringify(payload); - var encPayload = this._encrypt(payloadStr); + var payloadBuf = new Buffer(payloadStr); + //var encPayload = this._encrypt(payloadStr); if (Array.isArray(copayerIds)) { var l = copayerIds.length; var i = 0; copayerIds.forEach(function(copayerId) { + var copayerIdBuf = new Buffer(copayerId, 'hex'); + var encPayload = self._encrypt(copayerIdBuf, payloadBuf); self._sendToOne(copayerId, encPayload, sig, function () { if (++i === l && typeof cb === 'function') cb(); }); From c78b7101db8a9c44bb89905c1edcb0adaf5eb9e0 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Wed, 11 Jun 2014 17:50:02 -0700 Subject: [PATCH 03/15] add tests for changes to private key --- test/test.PrivateKey.js | 45 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/test/test.PrivateKey.js b/test/test.PrivateKey.js index 7e002759c..661b6860c 100644 --- a/test/test.PrivateKey.js +++ b/test/test.PrivateKey.js @@ -70,11 +70,6 @@ describe('PrivateKey model', function() { } }); - it('should calculate .id', function () { - var w1 = new PrivateKey(config); - should.exist(w1.getId()); - w1.getId().length.should.equal(66); - }); it('fromObj toObj roundtrip', function () { var w1 = new PrivateKey(config); var o = JSON.parse(JSON.stringify(w1.toObj())) @@ -89,5 +84,45 @@ describe('PrivateKey model', function() { .equal(JSON.stringify(w1.get(1,0).storeObj())); }); + describe('#getId', function() { + it('should calculate the copayerId', function() { + var w1 = new PrivateKey(config); + should.exist(w1.getId()); + w1.getId().length.should.equal(33*2); + }); + }); + + describe('#getIdPriv', function() { + it('should calculate .id', function() { + var w1 = new PrivateKey(config); + should.exist(w1.getIdPriv()); + w1.getIdPriv().length.should.equal(32*2); + }); + }); + + describe('#cacheId', function() { + it('should set .id and .idpriv', function() { + var w1 = new PrivateKey(config); + w1.cacheId(); + var pub = w1.id; + var priv = w1.idpriv; + pub.length.should.equal(33*2); + priv.length.should.equal(32*2); + }); + + it('should set the id equal to the public key of the idpriv private key', function() { + var w1 = new PrivateKey(config); + w1.cacheId(); + var pub = w1.id; + var priv = w1.idpriv; + pub.length.should.equal(33*2); + priv.length.should.equal(32*2); + + var key1 = new bitcore.Key(); + key1.private = new bitcore.Buffer(priv, 'hex'); + key1.regenerateSync(); + key1.public.toString('hex').should.equal(pub); + }); + }); }); From 434dad831dade6d194af89e87def9c4e11d78034 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Wed, 11 Jun 2014 19:39:13 -0700 Subject: [PATCH 04/15] add tests for WebRTC and fix some mocha browser test problems from now on you need to run "grunt shell --target=dev" to build the test version of copay which you can run the mocha browser tests on, which includes packages like sinon and soop. --- package.json | 4 ++-- test/index.html | 1 + test/test.network.WebRTC.js | 38 +++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 test/test.network.WebRTC.js diff --git a/package.json b/package.json index bec53ce4f..8fde93aa3 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "mocha": "1.18.2", "mocha-lcov-reporter": "0.0.1", "node-cryptojs-aes": "0.4.0", - "sinon": "1.9.1", "soop": "0.1.5", "travis-cov": "0.2.5", "uglifyify": "1.2.3" @@ -60,6 +59,7 @@ "dependencies": { "mocha": "^1.18.2", "mocha-lcov-reporter": "0.0.1", - "preconditions": "^1.0.7" + "preconditions": "^1.0.7", + "sinon": "1.9.1" } } diff --git a/test/index.html b/test/index.html index 4d6424d38..127df85f3 100644 --- a/test/index.html +++ b/test/index.html @@ -15,6 +15,7 @@ + diff --git a/test/test.network.WebRTC.js b/test/test.network.WebRTC.js new file mode 100644 index 000000000..28394b51c --- /dev/null +++ b/test/test.network.WebRTC.js @@ -0,0 +1,38 @@ +'use strict'; + +var chai = chai || require('chai'); +var should = chai.should(); +var expect = chai.expect; +var sinon = sinon || require('sinon'); +var bitcore = bitcore || require('bitcore'); +var copay = copay || require('../copay'); +var Network = copay.WebRTC || require('../js/models/network/WebRTC.js'); + +describe('Network / WebRTC', function() { + + it('should create an instance', function () { + var n = new Network(); + should.exist(n); + }); + +/* + describe('#Network constructor', function() { + it('should call cleanUp', function() { + var save = Network.prototype.cleanUp; + Network.prototype.cleanUp = sinon.spy(); + var n = new Network(); + n.cleanUp.calledOnce.should.equal(true); + Network.prototype.cleanUp = save; + }); + }); + + describe('#cleanUp', function() { + it('should set privkey to null', function() { + var n = new Network(); + n.cleanUp(); + expect(n.privkey).to.equal(null); + }); + }); + */ + +}); From 8bba98297888d248f1f6f84e5ccf0d90da7b1370 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Mon, 16 Jun 2014 14:41:33 -0700 Subject: [PATCH 05/15] make WebRTC tests work --- js/models/network/WebRTC.js | 1 + test/test.network.WebRTC.js | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/js/models/network/WebRTC.js b/js/models/network/WebRTC.js index 715f74d78..14ef73b30 100644 --- a/js/models/network/WebRTC.js +++ b/js/models/network/WebRTC.js @@ -1,3 +1,4 @@ +'use strict'; var imports = require('soop').imports(); var EventEmitter= imports.EventEmitter || require('events').EventEmitter; diff --git a/test/test.network.WebRTC.js b/test/test.network.WebRTC.js index 28394b51c..8a79d02fe 100644 --- a/test/test.network.WebRTC.js +++ b/test/test.network.WebRTC.js @@ -5,34 +5,41 @@ var should = chai.should(); var expect = chai.expect; var sinon = sinon || require('sinon'); var bitcore = bitcore || require('bitcore'); -var copay = copay || require('../copay'); -var Network = copay.WebRTC || require('../js/models/network/WebRTC.js'); +try { + var copay = require('copay'); //browser +} catch (e) { + var copay = require('../copay'); //node +} +var WebRTC = require('../js/models/network/WebRTC'); describe('Network / WebRTC', function() { it('should create an instance', function () { - var n = new Network(); + var n = new WebRTC(); should.exist(n); }); -/* - describe('#Network constructor', function() { + describe('#WebRTC constructor', function() { + it('should set reconnect attempts', function() { + var n = new WebRTC(); + n.reconnectAttempts.should.equal(3); + }); + it('should call cleanUp', function() { - var save = Network.prototype.cleanUp; - Network.prototype.cleanUp = sinon.spy(); - var n = new Network(); + var save = WebRTC.prototype.cleanUp; + WebRTC.prototype.cleanUp = sinon.spy(); + var n = new WebRTC(); n.cleanUp.calledOnce.should.equal(true); - Network.prototype.cleanUp = save; + WebRTC.prototype.cleanUp = save; }); }); describe('#cleanUp', function() { it('should set privkey to null', function() { - var n = new Network(); + var n = new WebRTC(); n.cleanUp(); expect(n.privkey).to.equal(null); }); }); - */ }); From 2b2a807f7c1c238406f3de5a0a98c7feaf4b0d69 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Mon, 16 Jun 2014 14:42:33 -0700 Subject: [PATCH 06/15] remove unused "copay" dependency --- test/test.network.WebRTC.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/test.network.WebRTC.js b/test/test.network.WebRTC.js index 8a79d02fe..83a94ee11 100644 --- a/test/test.network.WebRTC.js +++ b/test/test.network.WebRTC.js @@ -5,11 +5,6 @@ var should = chai.should(); var expect = chai.expect; var sinon = sinon || require('sinon'); var bitcore = bitcore || require('bitcore'); -try { - var copay = require('copay'); //browser -} catch (e) { - var copay = require('../copay'); //node -} var WebRTC = require('../js/models/network/WebRTC'); describe('Network / WebRTC', function() { From 98b864454fe8b38b2a09bf2aa42c13390672dc97 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Mon, 16 Jun 2014 15:35:54 -0700 Subject: [PATCH 07/15] add some basic tests for WebRTC --- js/models/network/WebRTC.js | 25 +++++------ test/test.network.WebRTC.js | 87 +++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 13 deletions(-) diff --git a/js/models/network/WebRTC.js b/js/models/network/WebRTC.js index 14ef73b30..5056c642b 100644 --- a/js/models/network/WebRTC.js +++ b/js/models/network/WebRTC.js @@ -404,23 +404,22 @@ Network.prototype.send = function(copayerIds, payload, cb) { payload.isBroadcast = 1; } + if (typeof copayerIds === 'string') + copayerIds = [copayerIds]; + var sig; var payloadStr = JSON.stringify(payload); var payloadBuf = new Buffer(payloadStr); - //var encPayload = this._encrypt(payloadStr); - if (Array.isArray(copayerIds)) { - var l = copayerIds.length; - var i = 0; - copayerIds.forEach(function(copayerId) { - var copayerIdBuf = new Buffer(copayerId, 'hex'); - var encPayload = self._encrypt(copayerIdBuf, payloadBuf); - self._sendToOne(copayerId, encPayload, sig, function () { - if (++i === l && typeof cb === 'function') cb(); - }); + + var l = copayerIds.length; + var i = 0; + copayerIds.forEach(function(copayerId) { + var copayerIdBuf = new Buffer(copayerId, 'hex'); + var encPayload = self._encrypt(copayerIdBuf, payloadBuf); + self._sendToOne(copayerId, encPayload, sig, function () { + if (++i === l && typeof cb === 'function') cb(); }); - } - else if (typeof copayerIds === 'string') - self._sendToOne(copayerIds, encPayload, sig, cb); + }); }; diff --git a/test/test.network.WebRTC.js b/test/test.network.WebRTC.js index 83a94ee11..53cd241c6 100644 --- a/test/test.network.WebRTC.js +++ b/test/test.network.WebRTC.js @@ -15,6 +15,7 @@ describe('Network / WebRTC', function() { }); describe('#WebRTC constructor', function() { + it('should set reconnect attempts', function() { var n = new WebRTC(); n.reconnectAttempts.should.equal(3); @@ -27,14 +28,100 @@ describe('Network / WebRTC', function() { n.cleanUp.calledOnce.should.equal(true); WebRTC.prototype.cleanUp = save; }); + }); describe('#cleanUp', function() { + + it('should not set netKey', function() { + var n = new WebRTC(); + (n.netKey === undefined).should.equal(true); + }); + it('should set privkey to null', function() { var n = new WebRTC(); n.cleanUp(); expect(n.privkey).to.equal(null); }); + + }); + + describe('#_encrypt', function() { + + it('should encrypt data successfully', function() { + var n = new WebRTC(); + var data = new bitcore.Buffer('my data to encrypt'); + var privkeystr = new bitcore.Buffer('test privkey'); + var privkey = bitcore.util.sha256(privkeystr); + var key = new bitcore.Key(); + key.private = privkey; + key.regenerateSync(); + var encrypted = n._encrypt(key.public, data); + encrypted.length.should.not.equal(0); + encrypted.length.should.equal(145); + }); + + }); + + describe('#_decrypt', function() { + + it('should decrypt that which was encrypted', function() { + var n = new WebRTC(); + var data = new bitcore.Buffer('my data to encrypt'); + var privkeystr = new bitcore.Buffer('test privkey'); + var privkey = bitcore.util.sha256(privkeystr); + var key = new bitcore.Key(); + key.private = privkey; + key.regenerateSync(); + var encrypted = n._encrypt(key.public, data); + var decrypted = n._decrypt(key.private, encrypted); + encrypted.length.should.not.equal(0); + decrypted.toString().should.equal('my data to encrypt'); + }); + + }); + + describe('#send', function() { + + it('should call _sendToOne for a copayer', function(done) { + var n = new WebRTC(); + + var data = new bitcore.Buffer('my data to send'); + + var privkeystr = new bitcore.Buffer('test privkey'); + var privkey = bitcore.util.sha256(privkeystr); + var key = new bitcore.Key(); + key.private = privkey; + key.regenerateSync(); + + var copayerId = key.public.toString('hex'); + n._sendToOne = function(a1, a2, a3, cb) {cb();}; + var sig = undefined; + n.send(copayerId, data, function() { + done(); + }); + + }); + + it('should call _sendToOne for a list of copayers', function(done) { + var n = new WebRTC(); + + var data = new bitcore.Buffer('my data to send'); + + var privkeystr = new bitcore.Buffer('test privkey'); + var privkey = bitcore.util.sha256(privkeystr); + var key = new bitcore.Key(); + key.private = privkey; + key.regenerateSync(); + + var copayerIds = [key.public.toString('hex')]; + n._sendToOne = function(a1, a2, a3, cb) {cb();}; + var sig = undefined; + n.send(copayerIds, data, function() { + done(); + }); + + }); }); }); From 435e5c3e1309a303e4580b874bb21de3f21cd45d Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Mon, 16 Jun 2014 15:55:40 -0700 Subject: [PATCH 08/15] another test for WebRTC --- test/test.network.WebRTC.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/test.network.WebRTC.js b/test/test.network.WebRTC.js index 53cd241c6..0eb21b247 100644 --- a/test/test.network.WebRTC.js +++ b/test/test.network.WebRTC.js @@ -103,6 +103,29 @@ describe('Network / WebRTC', function() { }); + it('should call _sendToOne with encrypted data for a copayer', function(done) { + var n = new WebRTC(); + + var data = new bitcore.Buffer('my data to send'); + + var privkeystr = new bitcore.Buffer('test privkey'); + var privkey = bitcore.util.sha256(privkeystr); + var key = new bitcore.Key(); + key.private = privkey; + key.regenerateSync(); + + var copayerId = key.public.toString('hex'); + n._sendToOne = function(a1, encPayload, a3, cb) { + encPayload.length.should.be.greaterThan(0); + cb(); + }; + var sig = undefined; + n.send(copayerId, data, function() { + done(); + }); + + }); + it('should call _sendToOne for a list of copayers', function(done) { var n = new WebRTC(); From 57417287bd1c643fee712b8594306e17286ac431 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Mon, 16 Jun 2014 16:07:24 -0700 Subject: [PATCH 09/15] fix Wallet tests ...by removing references to now-nonexistent netKey --- test/test.Wallet.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/test.Wallet.js b/test/test.Wallet.js index 16605da98..5af27914f 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -97,10 +97,7 @@ describe('Wallet model', function() { should.exist(w.publicKeyRing); should.exist(w.privateKey); should.exist(w.txProposals); - should.exist(w.netKey); should.exist(w.addressBook); - var b = new bitcore.Buffer(w.netKey, 'base64'); - b.toString('hex').length.should.equal(16); }); it('should provide some basic features', function(done) { @@ -284,13 +281,11 @@ describe('Wallet model', function() { it('#getSecret decodeSecret', function() { var w = createW2(); var id = w.getMyCopayerId(); - var nk = w.netKey; var sb = w.getSecret(); should.exist(sb); var s = Wallet.decodeSecret(sb); s.pubKey.should.equal(id); - s.netKey.should.equal(nk); }); it('decodeSecret check', function() { From bf36376dda7378081b6765e05ffd51562e19c968 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Mon, 16 Jun 2014 16:13:32 -0700 Subject: [PATCH 10/15] got WalletFactory tests to work ...by removing the reference to netKey --- test/test.WalletFactory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.WalletFactory.js b/test/test.WalletFactory.js index 93adb7812..f9098d8be 100644 --- a/test/test.WalletFactory.js +++ b/test/test.WalletFactory.js @@ -80,7 +80,7 @@ describe('WalletFactory model', function() { }); it('#fromObj #toObj round trip', function() { - var o = '{"opts":{"id":"dbfe10c3fae71cea","spendUnconfirmed":1,"requiredCopayers":3,"totalCopayers":5,"netKey":"LppzFYqlgT0=","version":"0.0.5"},"publicKeyRing":{"walletId":"dbfe10c3fae71cea","networkName":"testnet","requiredCopayers":3,"totalCopayers":5,"indexes":{"changeIndex":0,"receiveIndex":0},"copayersExtPubKeys":["tpubD6NzVbkrYhZ4YGK8ZhZ8WVeBXNAAoTYjjpw9twCPiNGrGQYFktP3iVQkKmZNiFnUcAFMJRxJVJF6Nq9MDv2kiRceExJaHFbxUCGUiRhmy97","tpubD6NzVbkrYhZ4YKGDJkzWdQsQV3AcFemaQKiwNhV4RL8FHnBFvinidGdQtP8RKj3h34E65RkdtxjrggZYqsEwJ8RhhN2zz9VrjLnrnwbXYNc","tpubD6NzVbkrYhZ4YkDiewjb32Pp3Sz9WK2jpp37KnL7RCrHAyPpnLfgdfRnTdpn6DTWmPS7niywfgWiT42aJb1J6CjWVNmkgsMCxuw7j9DaGKB","tpubD6NzVbkrYhZ4XEtUAz4UUTWbprewbLTaMhR8NUvSJUEAh4Sidxr6rRPFdqqVRR73btKf13wUjds2i8vVCNo8sbKrAnyoTr3o5Y6QSbboQjk","tpubD6NzVbkrYhZ4Yj9AAt6xUVuGPVd8jXCrEE6V2wp7U3PFh8jYYvVad31b4VUXEYXzSnkco4fktu8r4icBsB2t3pCR3WnhVLedY2hxGcPFLKD"],"nicknameFor":{},"publicKeysCache":{"m/0/1/0":["0314368b8efa07e8c7dad30498d0a7e3aa575db1fef833347c6d381c1a33a17b17","02cfd95f89ab46bd3bd86954dd9f83dbab0cd2e4466dee587e8e4d8d733fc0d748","02568969eb6212fe946450be6c5b3353fc754a40b2cdc4aed501a8976fec371da8","0360f870a088ae0ef1c37035a9b6a462ca8dcdd5da275f4e2dcd19f44b81d3e7e4","0300ad8f1bded838b02e127bb25961fbcee718db2df81f680f889692acdcbdd73d"],"m/0/1/1":["024f97a9adb2fa9306c4e3d9244f5e5355c7e2c6b3dd4122ba804e17dc9729df5d","0214834a5adcbc4ad0f3bbbc1c280b8ac480387fcc9a1fd988c1526ed496d923c4","024e72338bd5e976375d076bd71a9649e9141b4cbfc9e16cb7109b354b3e913a05","0322045ea35c3118aa7ab9f2c9f182b0120956b0aa65cc72b9d093f145327a4b17","030dc2450c72df366c1960739c577a2efd4451070bd78effcb6f71d1bcd7dfc7a8"],"m/0/1/2":["0247de59deb66783b8f9b0c326234a9569d00866c2a73f599e77a4d0cab5cbce8f","0376e49f0ac3647404034aae0dc8dd927c34a634ef24ea36f56a272f75fce9539b","032fbaa2593bd1eea4a46e7ac15f15802cdd1eb65a7d5bc4364ddd9d52f0838234","03a81f2a7e1f7191aa0b0c6e0a4ccefc71edd3564e86014972fe338045f68d5a5a","02eb8a012ea9a709392502cacda6ef5115d6d2319ab470d546d9068ab941621a99"],"m/0/0/0":["036dcbd378b4352120d6b720b6294dd2d0dd02801fcf010bb69dadbec1f3999279","022089eedb85dc45d1efa418e1ea226588deedebc1d85acca15ff72783e33636c0","0388aa5fd432b74c56427396f350d236c3ca8f7b2f62da513ce4c2e6ff04a67e9c","02fc4caa7449db7483d2e1fccdacac6fa2f736278c758af9966402589b5632f13e","02e4a15b885d8b2d586f82fa85d16179644e60a154674bde0ec3004810b1bdab99"],"m/0/0/1":["039afa26b2f341c76c7b3c3d0672438f35ac6ebb67b1ddfefac9cd79b7b24418c1","021acaaf500d431ebc396f50630767b01c91ce98ae48e968775ceaad932b7e3b8e","022a947259c4a9f76d5e95c0849df31d01233df41d0d75d631b89317a48d8cddce","03d38d9f94217da780303d9a8987c86d737ef39683febc0cd6632cddbfa62186fd","0394d2581b307fe2af19721888d922aab58ab198ef88cedf9506177e30d807811e"],"m/0/0/2":["037825ffce15d34f9bd6c02bcda7701826706471a4d6ab5004eb965f98811c2098","023768dd6d3c71b7df5733ccda5b2d8b454d5b4c4179d91a6fda74db8b869a2406","021a79e91f003f308764d43039e9b5d56bc8f33ca2f4d30ec6cc5a37c0d09dc273","02437f1e388b273936319f79a5d22958ef5ebff9c8cd7b6f6f72518445b1e30867","0373b0881cb4fd02baa62589023fdfe9739c6148cf104d907549f2528eb80146f5"]}},"txProposals":{"txps":[],"walletId":"dbfe10c3fae71cea","networkName":"testnet"},"privateKey":{"extendedPrivateKeyString":"tprv8ZgxMBicQKsPeoHLg3tY75z4xLeEe8MqAXLNcRA6J6UTRvHV8VZTXznt9eoTmSk1fwSrwZtMhY3XkNsceJ14h6sCXHSWinRqMSSbY8tfhHi","networkName":"testnet","privateKeyCache":{}},"addressBook":{}}'; + var o = '{"opts":{"id":"dbfe10c3fae71cea","spendUnconfirmed":1,"requiredCopayers":3,"totalCopayers":5,"version":"0.0.5"},"publicKeyRing":{"walletId":"dbfe10c3fae71cea","networkName":"testnet","requiredCopayers":3,"totalCopayers":5,"indexes":{"changeIndex":0,"receiveIndex":0},"copayersExtPubKeys":["tpubD6NzVbkrYhZ4YGK8ZhZ8WVeBXNAAoTYjjpw9twCPiNGrGQYFktP3iVQkKmZNiFnUcAFMJRxJVJF6Nq9MDv2kiRceExJaHFbxUCGUiRhmy97","tpubD6NzVbkrYhZ4YKGDJkzWdQsQV3AcFemaQKiwNhV4RL8FHnBFvinidGdQtP8RKj3h34E65RkdtxjrggZYqsEwJ8RhhN2zz9VrjLnrnwbXYNc","tpubD6NzVbkrYhZ4YkDiewjb32Pp3Sz9WK2jpp37KnL7RCrHAyPpnLfgdfRnTdpn6DTWmPS7niywfgWiT42aJb1J6CjWVNmkgsMCxuw7j9DaGKB","tpubD6NzVbkrYhZ4XEtUAz4UUTWbprewbLTaMhR8NUvSJUEAh4Sidxr6rRPFdqqVRR73btKf13wUjds2i8vVCNo8sbKrAnyoTr3o5Y6QSbboQjk","tpubD6NzVbkrYhZ4Yj9AAt6xUVuGPVd8jXCrEE6V2wp7U3PFh8jYYvVad31b4VUXEYXzSnkco4fktu8r4icBsB2t3pCR3WnhVLedY2hxGcPFLKD"],"nicknameFor":{},"publicKeysCache":{"m/0/1/0":["0314368b8efa07e8c7dad30498d0a7e3aa575db1fef833347c6d381c1a33a17b17","02cfd95f89ab46bd3bd86954dd9f83dbab0cd2e4466dee587e8e4d8d733fc0d748","02568969eb6212fe946450be6c5b3353fc754a40b2cdc4aed501a8976fec371da8","0360f870a088ae0ef1c37035a9b6a462ca8dcdd5da275f4e2dcd19f44b81d3e7e4","0300ad8f1bded838b02e127bb25961fbcee718db2df81f680f889692acdcbdd73d"],"m/0/1/1":["024f97a9adb2fa9306c4e3d9244f5e5355c7e2c6b3dd4122ba804e17dc9729df5d","0214834a5adcbc4ad0f3bbbc1c280b8ac480387fcc9a1fd988c1526ed496d923c4","024e72338bd5e976375d076bd71a9649e9141b4cbfc9e16cb7109b354b3e913a05","0322045ea35c3118aa7ab9f2c9f182b0120956b0aa65cc72b9d093f145327a4b17","030dc2450c72df366c1960739c577a2efd4451070bd78effcb6f71d1bcd7dfc7a8"],"m/0/1/2":["0247de59deb66783b8f9b0c326234a9569d00866c2a73f599e77a4d0cab5cbce8f","0376e49f0ac3647404034aae0dc8dd927c34a634ef24ea36f56a272f75fce9539b","032fbaa2593bd1eea4a46e7ac15f15802cdd1eb65a7d5bc4364ddd9d52f0838234","03a81f2a7e1f7191aa0b0c6e0a4ccefc71edd3564e86014972fe338045f68d5a5a","02eb8a012ea9a709392502cacda6ef5115d6d2319ab470d546d9068ab941621a99"],"m/0/0/0":["036dcbd378b4352120d6b720b6294dd2d0dd02801fcf010bb69dadbec1f3999279","022089eedb85dc45d1efa418e1ea226588deedebc1d85acca15ff72783e33636c0","0388aa5fd432b74c56427396f350d236c3ca8f7b2f62da513ce4c2e6ff04a67e9c","02fc4caa7449db7483d2e1fccdacac6fa2f736278c758af9966402589b5632f13e","02e4a15b885d8b2d586f82fa85d16179644e60a154674bde0ec3004810b1bdab99"],"m/0/0/1":["039afa26b2f341c76c7b3c3d0672438f35ac6ebb67b1ddfefac9cd79b7b24418c1","021acaaf500d431ebc396f50630767b01c91ce98ae48e968775ceaad932b7e3b8e","022a947259c4a9f76d5e95c0849df31d01233df41d0d75d631b89317a48d8cddce","03d38d9f94217da780303d9a8987c86d737ef39683febc0cd6632cddbfa62186fd","0394d2581b307fe2af19721888d922aab58ab198ef88cedf9506177e30d807811e"],"m/0/0/2":["037825ffce15d34f9bd6c02bcda7701826706471a4d6ab5004eb965f98811c2098","023768dd6d3c71b7df5733ccda5b2d8b454d5b4c4179d91a6fda74db8b869a2406","021a79e91f003f308764d43039e9b5d56bc8f33ca2f4d30ec6cc5a37c0d09dc273","02437f1e388b273936319f79a5d22958ef5ebff9c8cd7b6f6f72518445b1e30867","0373b0881cb4fd02baa62589023fdfe9739c6148cf104d907549f2528eb80146f5"]}},"txProposals":{"txps":[],"walletId":"dbfe10c3fae71cea","networkName":"testnet"},"privateKey":{"extendedPrivateKeyString":"tprv8ZgxMBicQKsPeoHLg3tY75z4xLeEe8MqAXLNcRA6J6UTRvHV8VZTXznt9eoTmSk1fwSrwZtMhY3XkNsceJ14h6sCXHSWinRqMSSbY8tfhHi","networkName":"testnet","privateKeyCache":{}},"addressBook":{}}'; var wf = new WalletFactory(config, '0.0.5'); var w = wf.fromObj(JSON.parse(o)); From b9ecab9b923dcc9a397833faa06ae7de9f7ccda7 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Wed, 18 Jun 2014 10:24:33 -0700 Subject: [PATCH 11/15] remove commented-out references to obsolete netKey --- js/models/core/Wallet.js | 11 ++--------- js/models/core/WalletFactory.js | 1 - js/models/network/WebRTC.js | 25 ------------------------- 3 files changed, 2 insertions(+), 35 deletions(-) diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 58fc1249b..099c3cf74 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -38,7 +38,6 @@ function Wallet(opts) { this.id = opts.id || Wallet.getRandomId(); this.name = opts.name; - //this.netKey = opts.netKey || SecureRandom.getRandomBuffer(8).toString('base64'); // Renew token every 24hs if (opts.tokenTime && new Date().getTime() - opts.tokenTime < 86400000) { @@ -216,7 +215,6 @@ Wallet.prototype._optsToObj = function() { requiredCopayers: this.requiredCopayers, totalCopayers: this.totalCopayers, name: this.name, - //netKey: this.netKey, version: this.version, }; @@ -241,8 +239,6 @@ Wallet.prototype.getMyCopayerId = function() { Wallet.prototype.getSecret = function() { var pubkeybuf = new Buffer(this.getMyCopayerId(), 'hex'); - //var k = new Buffer(this.netKey, 'base64'); - //var b = Buffer.concat([i, k]); var str = Base58Check.encode(pubkeybuf); return str; }; @@ -250,11 +246,9 @@ Wallet.prototype.getSecret = function() { Wallet.decodeSecret = function(secretB) { var secret = Base58Check.decode(secretB); - //var netKeyBuf = secret.slice(-8); var pubKeyBuf = secret.slice(0, 33); return { - pubKey: pubKeyBuf.toString('hex')//, - //netKey: netKeyBuf.toString('base64'), + pubKey: pubKeyBuf.toString('hex') } }; @@ -280,8 +274,7 @@ Wallet.prototype.netStart = function() { var startOpts = { copayerId: myId, token: self.token, - maxPeers: self.totalCopayers//, - //netKey: this.netKey, + maxPeers: self.totalCopayers }; if (this.publicKeyRing.isComplete()) { diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index 02c67dc70..3d4381d46 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -220,7 +220,6 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras this.log('\t### PrivateKey Initialized'); var opts = { copayerId: privateKey.getId(), - //netKey: s.netKey, privkey: privateKey.getIdPriv() }; self.network.cleanUp(); diff --git a/js/models/network/WebRTC.js b/js/models/network/WebRTC.js index 5056c642b..445ed4a13 100644 --- a/js/models/network/WebRTC.js +++ b/js/models/network/WebRTC.js @@ -44,7 +44,6 @@ Network.prototype.cleanUp = function() { this.started = false; this.connectedPeers = []; this.peerId = null; - //this.netKey = null; this.privkey = null; //TODO: hide privkey in a closure this.copayerId = null; this.signingKey = null; @@ -305,7 +304,6 @@ Network.prototype.start = function(opts, openCallback) { if (this.started) return openCallback(); - //this.netKey = opts.netKey; this.privkey = opts.privkey; this.maxPeers = opts.maxPeers || this.maxPeers; @@ -353,34 +351,12 @@ Network.prototype.getPeer = function() { Network.prototype._encrypt = function(pubkey, payload) { var encrypted = bitcore.ECIES.encrypt(pubkey, payload); return encrypted; - - /* - var plainText = sjcl.codec.utf8String.toBits(payloadStr); - var p = this.sjclParams; - ct = sjcl.encrypt(this.netKey, plainText, p);//,p, rp); - var c = JSON.parse(ct); - var toSend = { - iv: c.iv, - ct: c.ct, - }; - return JSON.stringify(toSend); - */ }; Network.prototype._decrypt = function(privkey, encrypted) { var decrypted = bitcore.ECIES.decrypt(privkey, encrypted); return decrypted; - - /* - var i = JSON.parse(encStr); - for (var k in this.sjclParams) { - i[k] = this.sjclParams[k]; - } - var str= JSON.stringify(i); - var pt = sjcl.decrypt(this.netKey, str); - return pt; - */ }; Network.prototype._sendToOne = function(copayerId, payload, sig, cb) { @@ -395,7 +371,6 @@ Network.prototype._sendToOne = function(copayerId, payload, sig, cb) { }; Network.prototype.send = function(copayerIds, payload, cb) { - //if (!payload || !this.netKey) return cb(); if (!payload) return cb(); var self=this; From 8e81e9108fda9e250d834302f15c40ea5c1e92ed Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Wed, 18 Jun 2014 20:12:38 -0700 Subject: [PATCH 12/15] add private key in Wallet call to network start --- js/models/core/Wallet.js | 6 ++++++ js/models/network/WebRTC.js | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 099c3cf74..aa5cd6155 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -236,6 +236,10 @@ Wallet.prototype.getMyCopayerId = function() { return this.getCopayerId(0); }; +Wallet.prototype.getMyCopayerIdPriv = function() { + return this.privateKey.getIdPriv(); +}; + Wallet.prototype.getSecret = function() { var pubkeybuf = new Buffer(this.getMyCopayerId(), 'hex'); @@ -271,8 +275,10 @@ Wallet.prototype.netStart = function() { }); var myId = self.getMyCopayerId(); + var myIdPriv = self.getMyCopayerIdPriv(); var startOpts = { copayerId: myId, + privkey: myIdPriv, token: self.token, maxPeers: self.totalCopayers }; diff --git a/js/models/network/WebRTC.js b/js/models/network/WebRTC.js index 445ed4a13..c77800274 100644 --- a/js/models/network/WebRTC.js +++ b/js/models/network/WebRTC.js @@ -153,7 +153,8 @@ Network.prototype._addConnectedCopayer = function(copayerId, isInbound) { Network.prototype._onData = function(enchex, isInbound, peerId) { var sig, payload; - var encbuf = new Buffer(enchex, 'hex'); + var encUint8Array = new Uint8Array(enchex); + var encbuf = new Buffer(encUint8Array); var privkey = this.privkey; @@ -304,7 +305,9 @@ Network.prototype.start = function(opts, openCallback) { if (this.started) return openCallback(); - this.privkey = opts.privkey; + if (!this.privkey) + this.privkey = opts.privkey; + this.maxPeers = opts.maxPeers || this.maxPeers; if (opts.token) From 7ae643847883dfd8530276de59eab3df6b1d6f1a Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Thu, 19 Jun 2014 11:03:31 -0700 Subject: [PATCH 13/15] add tests for Wallet --- js/models/core/Wallet.js | 6 +++--- test/test.Wallet.js | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index aa5cd6155..f0e94993d 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -233,11 +233,11 @@ Wallet.prototype.getCopayerId = function(index) { Wallet.prototype.getMyCopayerId = function() { - return this.getCopayerId(0); + return this.getCopayerId(0); //copayer id is hex of a public key }; Wallet.prototype.getMyCopayerIdPriv = function() { - return this.privateKey.getIdPriv(); + return this.privateKey.getIdPriv(); //copayer idpriv is hex of a private key }; @@ -260,7 +260,7 @@ Wallet.prototype._lockIncomming = function() { this.network.lockIncommingConnections(this.publicKeyRing.getAllCopayerIds()); }; -Wallet.prototype.netStart = function() { +Wallet.prototype.netStart = function(callback) { var self = this; var net = this.network; net.removeAllListeners(); diff --git a/test/test.Wallet.js b/test/test.Wallet.js index 5af27914f..4c89a54b4 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -755,4 +755,49 @@ describe('Wallet model', function() { Object.keys(w.addressBook).length.should.equal(3); }); + it('#getNetworkName', function() { + var w = createW(); + w.getNetworkName().should.equal('testnet'); + }); + + describe('#getMyCopayerId', function() { + it('should call getCopayerId', function() { + //this.timeout(10000); + var w = createW2(); + w.getCopayerId = sinon.spy(); + w.getMyCopayerId(); + w.getCopayerId.calledOnce.should.equal(true); + }); + }); + + describe('#getMyCopayerIdPriv', function() { + it('should call privateKey.getIdPriv', function() { + //this.timeout(10000); + var w = createW2(); + w.privateKey.getIdPriv = sinon.spy(); + w.getMyCopayerIdPriv(); + w.privateKey.getIdPriv.calledOnce.should.equal(true); + }); + }); + + describe('#netStart', function() { + + it('should call Network.start', function() { + //this.timeout(10000); + var w = createW2(); + w.network.start = sinon.spy(); + w.netStart(); + w.network.start.calledOnce.should.equal(true); + }); + + it('should call Network.start with a private key', function() { + //this.timeout(10000); + var w = createW2(); + w.network.start = sinon.spy(); + w.netStart(); + w.network.start.getCall(0).args[0].privkey.length.should.equal(64); + }); + + }); + }); From 952b2a6d36f9f964d1ea55c7a16668af0f4f9b6c Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Thu, 19 Jun 2014 12:34:05 -0700 Subject: [PATCH 14/15] add tests for WalletFactory --- test/test.WalletFactory.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/test.WalletFactory.js b/test/test.WalletFactory.js index f9098d8be..c9f8bde5c 100644 --- a/test/test.WalletFactory.js +++ b/test/test.WalletFactory.js @@ -169,4 +169,21 @@ describe('WalletFactory model', function() { }); }); + describe('#joinCreateSession', function() { + it('should call network.start', function() { + var wf = new WalletFactory(config, '0.0.1'); + wf.network.cleanUp = sinon.spy(); + wf.network.start = sinon.spy(); + wf.joinCreateSession('8WtTuiFTkhP5ao7AF2QErSwV39Cbur6pdMebKzQXFqL59RscXM', 'test', null, undefined); + wf.network.start.calledOnce.should.equal(true); + }); + it('should call network.start with private key', function() { + var wf = new WalletFactory(config, '0.0.1'); + wf.network.cleanUp = sinon.spy(); + wf.network.start = sinon.spy(); + wf.joinCreateSession('8WtTuiFTkhP5ao7AF2QErSwV39Cbur6pdMebKzQXFqL59RscXM', 'test', null, undefined); + wf.network.start.getCall(0).args[0].privkey.length.should.equal(64); //privkey is hex of private key buffer + }); + }); + }); From 8a89e687e1e45058109cb45d46125127797f19f4 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Thu, 19 Jun 2014 14:26:34 -0700 Subject: [PATCH 15/15] bug: this -> self --- js/models/network/WebRTC.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/models/network/WebRTC.js b/js/models/network/WebRTC.js index c77800274..169bfe570 100644 --- a/js/models/network/WebRTC.js +++ b/js/models/network/WebRTC.js @@ -126,11 +126,11 @@ Network.prototype._onClose = function(peerID) { Network.prototype.connectToCopayers = function(copayerIds) { var self = this; - var arrayDiff= Network._arrayDiff(copayerIds, this.connectedCopayers()); + var arrayDiff= Network._arrayDiff(copayerIds, self.connectedCopayers()); arrayDiff.forEach(function(copayerId) { - if (this.allowedCopayerIds && !this.allowedCopayerIds[copayerId]) { - this._deletePeer(this.peerFromCopayer(copayerId)); + if (self.allowedCopayerIds && !self.allowedCopayerIds[copayerId]) { + self._deletePeer(self.peerFromCopayer(copayerId)); } else { self.connectTo(copayerId); }