diff --git a/copay.js b/copay.js index 5b2a2951c..389ae66dc 100644 --- a/copay.js +++ b/copay.js @@ -1,5 +1,6 @@ module.exports.Storage = require('./js/models/Storage'); module.exports.PublicKeyRing = require('./js/models/PublicKeyRing'); +module.exports.TxProposals = require('./js/models/TxProposals'); module.exports.CopayPeer = require('./js/models/CopayPeer'); module.exports.FakeStorage = require('./test/FakeStorage'); diff --git a/js/models/CopayPeer.js b/js/models/CopayPeer.js index 5a25206de..eecbca8e7 100644 --- a/js/models/CopayPeer.js +++ b/js/models/CopayPeer.js @@ -236,7 +236,6 @@ CopayPeer.prototype.send = function(peerIds, data, cb) { peerIds = this.connectedPeers; data.isBroadcast = 1; } -console.log('[CopayPeer.js.216:SENDD:]',data); //TODO if (Array.isArray(peerIds)) { var l = peerIds.length; diff --git a/js/models/PublicKeyRing.js b/js/models/PublicKeyRing.js index ec159403b..42e6fa626 100644 --- a/js/models/PublicKeyRing.js +++ b/js/models/PublicKeyRing.js @@ -123,7 +123,6 @@ PublicKeyRing.prototype.store = function (passphrase) { if (!this.id) throw new Error('wallet has no id'); - storage.set(this.id, PublicKeyRing.encrypt(passphrase,this.serialize())); this.dirty = 0; @@ -136,13 +135,13 @@ PublicKeyRing.prototype.registeredCopayers = function () { -PublicKeyRing.prototype.haveAllRequiredPubKeys = function () { +PublicKeyRing.prototype.isComplete = function () { return this.registeredCopayers() >= this.totalCopayers; }; PublicKeyRing.prototype._checkKeys = function() { - if (!this.haveAllRequiredPubKeys()) + if (!this.isComplete()) throw new Error('dont have required keys yet'); }; @@ -154,7 +153,7 @@ PublicKeyRing.prototype._newExtendedPublicKey = function () { PublicKeyRing.prototype.addCopayer = function (newEpk) { - if (this.haveAllRequiredPubKeys()) + if (this.isComplete()) throw new Error('already have all required key:' + this.totalCopayers); if (!newEpk) { @@ -172,7 +171,7 @@ PublicKeyRing.prototype.addCopayer = function (newEpk) { }; -PublicKeyRing.prototype.getCopayersPubKeys = function (index, isChange) { +PublicKeyRing.prototype.getPubKeys = function (index, isChange) { this._checkKeys(); var pubKeys = []; @@ -197,7 +196,7 @@ PublicKeyRing.prototype._checkIndexRange = function (index, isChange) { PublicKeyRing.prototype.getRedeemScript = function (index, isChange) { this._checkIndexRange(index, isChange); - var pubKeys = this.getCopayersPubKeys(index, isChange); + var pubKeys = this.getPubKeys(index, isChange); var script = Script.createMultisig(this.requiredCopayers, pubKeys); return script; }; diff --git a/test/FakeStorage.js b/test/FakeStorage.js index f12fc6f95..dd3af45cf 100644 --- a/test/FakeStorage.js +++ b/test/FakeStorage.js @@ -3,12 +3,12 @@ var FakeStorage = function(){ this.storage = {}; }; -FakeStorage.prototype.set = function (id) { - return this.storage[id]; +FakeStorage.prototype.set = function (id, payload) { + this.storage[id] = payload; }; -FakeStorage.prototype.get = function(id, payload) { - this.storage[id] = payload; +FakeStorage.prototype.get = function(id) { + return this.storage[id]; } module.exports = require('soop')(FakeStorage); diff --git a/test/test.publickeyring.js b/test/test.publickeyring.js index b78896aeb..9c4bb2cac 100644 --- a/test/test.publickeyring.js +++ b/test/test.publickeyring.js @@ -7,7 +7,9 @@ var Address = bitcore.Address; var buffertools = bitcore.buffertools; var copay = copay || require('../copay'); var fakeStorage = copay.FakeStorage; -var PublicKeyRing = copay.PublicKeyRing || require('soop').load('../js/models/PublicKeyRing', {Storage: fakeStorage}); + +var PublicKeyRing = (typeof process.versions === 'undefined') ? copay.PublicKeyRing : + require('soop').load('../js/models/PublicKeyRing', {Storage: fakeStorage}); var aMasterPubKey = 'tprv8ZgxMBicQKsPdSVTiWXEqCCzqRaRr9EAQdn5UVMpT9UHX67Dh1FmzEMbavPumpAicsUm2XvC6NTdcWB89yN5DUWx5HQ7z3KByUg7Ht74VRZ'; @@ -17,7 +19,6 @@ var config = { }; var createW = function (networkName) { - var config = { networkName: networkName || 'livenet', }; @@ -27,7 +28,7 @@ var createW = function (networkName) { var copayers = []; for(var i=0; i<5; i++) { - w.haveAllRequiredPubKeys().should.equal(false); + w.isComplete().should.equal(false); var newEpk = w.addCopayer(); copayers.push(newEpk); } @@ -55,7 +56,7 @@ describe('PublicKeyRing model', function() { should.exist(w2); w2.registeredCopayers().should.equal(0); - w2.haveAllRequiredPubKeys().should.equal(false); + w2.isComplete().should.equal(false); w2.getAddress.bind(false).should.throw(); }); @@ -65,7 +66,7 @@ describe('PublicKeyRing model', function() { var w = k.w; var copayers = k.copayers; - w.haveAllRequiredPubKeys().should.equal(true); + w.isComplete().should.equal(true); w.addCopayer.bind().should.throw(); for(var i =0; i<5; i++) w.addCopayer.bind(copayers[i]).should.throw(); @@ -86,7 +87,7 @@ describe('PublicKeyRing model', function() { w.store.bind().should.throw(); var w2 = PublicKeyRing.read(ID); - w2.haveAllRequiredPubKeys().should.equal(true); + w2.isComplete().should.equal(true); w2.addCopayer.bind().should.throw(); for(var i =0; i<5; i++) w2.addCopayer.bind(copayers[i]).should.throw(); @@ -188,12 +189,8 @@ describe('PublicKeyRing model', function() { }); (function() { w2.merge(w.toObj());}).should.throw(); (function() { w2.merge(w,true);}).should.throw(); - -console.log('[test.publickeyring.js.190]'); //TODO w2.merge(w.toObj(),true).should.equal(true); -console.log('[test.publickeyring.js.193]'); //TODO - var w3 = new PublicKeyRing({ networkName: 'livenet', @@ -232,7 +229,7 @@ console.log('[test.publickeyring.js.193]'); //TODO should.exist(w); var copayers = []; for(var i=0; i<2; i++) { - w.haveAllRequiredPubKeys().should.equal(false); + w.isComplete().should.equal(false); w.addCopayer(); } @@ -243,16 +240,16 @@ console.log('[test.publickeyring.js.193]'); //TODO should.exist(w); var copayers = []; for(var i=0; i<3; i++) { - w2.haveAllRequiredPubKeys().should.equal(false); + w2.isComplete().should.equal(false); w2.addCopayer(); } w2.merge(w.toObj()).should.equal(true); - w2.haveAllRequiredPubKeys().should.equal(true); + w2.isComplete().should.equal(true); w2.merge(w.toObj()).should.equal(false); - w.haveAllRequiredPubKeys().should.equal(false); + w.isComplete().should.equal(false); w.merge(w2.toObj()).should.equal(true); - w.haveAllRequiredPubKeys().should.equal(true); + w.isComplete().should.equal(true); w.merge(w2.toObj()).should.equal(false); }); @@ -261,7 +258,7 @@ console.log('[test.publickeyring.js.193]'); //TODO should.exist(w); for(var i=0; i<5; i++) { - w.haveAllRequiredPubKeys().should.equal(false); + w.isComplete().should.equal(false); var w2 = new PublicKeyRing({ networkName: 'livenet', id: w.id, @@ -269,7 +266,7 @@ console.log('[test.publickeyring.js.193]'); //TODO w2.addCopayer(); w.merge(w2.toObj()).should.equal(true); } - w.haveAllRequiredPubKeys().should.equal(true); + w.isComplete().should.equal(true); }); });