From 04b6aa40036d4a4b3eca389451b226983e88ba8a Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Thu, 3 Jul 2014 11:18:01 -0300 Subject: [PATCH] PublicKeyRing handles one index for each cosigner --- js/models/core/PrivateKey.js | 11 +++-- js/models/core/PublicKeyRing.js | 72 +++++++++++++++++++--------- js/models/core/Structure.js | 1 + js/models/core/Wallet.js | 4 +- test/test.PublicKeyRing.js | 39 ++++++++------- test/test.TxProposals.js | 85 ++++++++++++++++++++------------- test/test.Wallet.js | 18 +++---- 7 files changed, 140 insertions(+), 90 deletions(-) diff --git a/js/models/core/PrivateKey.js b/js/models/core/PrivateKey.js index b1149f28b..9abd30e95 100644 --- a/js/models/core/PrivateKey.js +++ b/js/models/core/PrivateKey.js @@ -16,6 +16,7 @@ function PrivateKey(opts) { var init = opts.extendedPrivateKeyString || this.network.name; this.bip = opts.HK || new HK(init); this.privateKeyCache = opts.privateKeyCache || {}; + this.publicHex = this.deriveBIP45Branch().eckey.public.toString('hex'); }; PrivateKey.prototype.getId = function() { @@ -101,21 +102,21 @@ PrivateKey.prototype.getForPath = function(path) { return wk; }; -PrivateKey.prototype.get = function(index, isChange) { - var path = Structure.FullBranch(index, isChange); +PrivateKey.prototype.get = function(index, isChange, cosigner) { + var path = Structure.FullBranch(index, isChange, cosigner); return this.getForPath(path); }; -PrivateKey.prototype.getAll = function(receiveIndex, changeIndex) { +PrivateKey.prototype.getAll = function(receiveIndex, changeIndex, cosigner) { if (typeof receiveIndex === 'undefined' || typeof changeIndex === 'undefined') throw new Error('Invalid parameters'); var ret = []; for (var i = 0; i < receiveIndex; i++) { - ret.push(this.get(i, false)); + ret.push(this.get(i, false, cosigner)); } for (var i = 0; i < changeIndex; i++) { - ret.push(this.get(i, true)); + ret.push(this.get(i, true, cosigner)); } return ret; }; diff --git a/js/models/core/PublicKeyRing.js b/js/models/core/PublicKeyRing.js index 627706128..b82c76365 100644 --- a/js/models/core/PublicKeyRing.js +++ b/js/models/core/PublicKeyRing.js @@ -148,10 +148,10 @@ PublicKeyRing.prototype.addCopayer = function(newEpk, nickname) { return newEpk; }; -PublicKeyRing.prototype.getPubKeys = function(index, isChange) { +PublicKeyRing.prototype.getPubKeys = function(index, isChange, cosigner) { this._checkKeys(); - var path = Structure.Branch(index, isChange); + var path = Structure.Branch(index, isChange, cosigner); var pubKeys = this.publicKeysCache[path]; if (!pubKeys) { pubKeys = []; @@ -174,17 +174,19 @@ PublicKeyRing.prototype.getPubKeys = function(index, isChange) { }; // TODO this could be cached -PublicKeyRing.prototype.getRedeemScript = function(index, isChange) { - var pubKeys = this.getPubKeys(index, isChange); +PublicKeyRing.prototype.getRedeemScript = function(index, isChange, cosigner) { + var pubKeys = this.getPubKeys(index, isChange, cosigner); var script = Script.createMultisig(this.requiredCopayers, pubKeys); return script; }; // TODO this could be cached -PublicKeyRing.prototype.getAddress = function(index, isChange) { - var script = this.getRedeemScript(index, isChange); +PublicKeyRing.prototype.getAddress = function(index, isChange, id) { + var cosigner = typeof id === 'string' ? this.getCosigner(id) : id; + + var script = this.getRedeemScript(index, isChange, cosigner); var address = Address.fromScript(script, this.network.name); - this.addressToPath[address.toString()] = Structure.FullBranch(index, isChange); + this.addressToPath[address.toString()] = Structure.FullBranch(index, isChange, cosigner); return address; }; @@ -192,7 +194,10 @@ PublicKeyRing.prototype.getSharedIndex = function() { return this.getIndex(Structure.SHARED_INDEX); }; -PublicKeyRing.prototype.getIndex = function(cosigner) { +// Overloaded to receive a PubkeyString or a consigner index +PublicKeyRing.prototype.getIndex = function(id) { + var cosigner = typeof id === 'string' ? this.getCosigner(id) : id; + var index = this.indexes.filter(function(i) { return i.cosigner == cosigner }); if (index.length != 1) throw new Error('no index for cosigner'); return index[0]; @@ -205,18 +210,20 @@ PublicKeyRing.prototype.pathForAddress = function(address) { }; // TODO this could be cached -PublicKeyRing.prototype.getScriptPubKeyHex = function(index, isChange) { - var addr = this.getAddress(index, isChange); +PublicKeyRing.prototype.getScriptPubKeyHex = function(index, isChange, pubkey) { + var cosigner = this.getCosigner(pubkey); + var addr = this.getAddress(index, isChange, cosigner); return Script.createP2SH(addr.payload()).getBuffer().toString('hex'); }; //generate a new address, update index. -PublicKeyRing.prototype.generateAddress = function(isChange) { +PublicKeyRing.prototype.generateAddress = function(isChange, pubkey) { isChange = !!isChange; - var shared = this.getIndex(Structure.SHARED_INDEX); - var index = isChange ? shared.getChangeIndex() : shared.getReceiveIndex(); - var ret = this.getAddress(index, isChange); - shared.increment(isChange); + var cosigner = this.getCosigner(pubkey); + var addrIndex = this.getIndex(cosigner); + var index = isChange ? addrIndex.getChangeIndex() : addrIndex.getReceiveIndex(); + var ret = this.getAddress(index, isChange, cosigner); + addrIndex.increment(isChange); return ret; }; @@ -226,16 +233,37 @@ PublicKeyRing.prototype.getAddresses = function(opts) { }); }; +PublicKeyRing.prototype.getCosigner = function(pubKey) { + preconditions.checkArgument(pubKey); + var sorted = this.copayersHK.map(function(h, i){ + return h.eckey.public.toString('hex'); + }).sort(function(h1, h2){ return h1.localeCompare(h2); }); + + var index = sorted.indexOf(pubKey); + if (index == -1) throw new Error('no public key in ring'); + + return index; +} + + PublicKeyRing.prototype.getAddressesInfo = function(opts) { + var ret = []; + var self = this; + this.indexes.forEach(function(index) { + ret = ret.concat(self.getAddressesInfoForIndex(index, opts)); + }); + return ret; +} + +PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts) { opts = opts || {}; - var shared = this.getIndex(Structure.SHARED_INDEX); var ret = []; if (!opts.excludeChange) { - for (var i = 0; i < shared.getChangeIndex(); i++) { - var a = this.getAddress(i, true); + for (var i = 0; i < index.changeIndex; i++) { + var a = this.getAddress(i, true, index.cosigner); ret.unshift({ - address: this.getAddress(i, true), + address: a, addressStr: a.toString(), isChange: true }); @@ -243,8 +271,8 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts) { } if (!opts.excludeMain) { - for (var i = 0; i < shared.getReceiveIndex(); i++) { - var a = this.getAddress(i, false); + for (var i = 0; i < index.receiveIndex; i++) { + var a = this.getAddress(i, false, index.cosigner); ret.unshift({ address: a, addressStr: a.toString(), @@ -259,7 +287,7 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts) { // TODO this could be cached PublicKeyRing.prototype._addScriptMap = function(map, path) { var p = Structure.indicesForPath(path); - var script = this.getRedeemScript(p.index, p.isChange); + var script = this.getRedeemScript(p.index, p.isChange, p.cosigner); map[Address.fromScript(script, this.network.name).toString()] = script.getBuffer().toString('hex'); }; diff --git a/js/models/core/Structure.js b/js/models/core/Structure.js index aafee4c0f..ff47c43f0 100644 --- a/js/models/core/Structure.js +++ b/js/models/core/Structure.js @@ -40,6 +40,7 @@ Structure.indicesForPath = function(path) { return { isChange: s[3] === '1', index: parseInt(s[4]), + cosigner: parseInt(s[2]) }; }; diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 20e5d1b1f..800ef5d8e 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -51,6 +51,7 @@ function Wallet(opts) { this.registeredPeerIds = []; this.addressBook = opts.addressBook || {}; this.backupOffered = opts.backupOffered || false; + this.publicKey = this.privateKey.publicHex; } Wallet.parent = EventEmitter; @@ -462,7 +463,7 @@ Wallet.prototype.getName = function() { }; Wallet.prototype._doGenerateAddress = function(isChange) { - return this.publicKeyRing.generateAddress(isChange); + return this.publicKeyRing.generateAddress(isChange, this.publicKey); }; @@ -516,7 +517,6 @@ Wallet.prototype.sign = function(ntxid, cb) { if (cb) cb(false); } - var pkr = self.publicKeyRing; var keys = self.privateKey.getForPaths(txp.inputChainPaths); var b = txp.builder; diff --git a/test/test.PublicKeyRing.js b/test/test.PublicKeyRing.js index 0bb2523a5..11051de07 100644 --- a/test/test.PublicKeyRing.js +++ b/test/test.PublicKeyRing.js @@ -36,7 +36,8 @@ var createW = function(networkName) { return { w: w, - copayers: copayers + copayers: copayers, + pub: w.copayersHK[0].eckey.public.toString('hex') }; }; @@ -88,7 +89,7 @@ describe('PublicKeyRing model', function() { } }); - it('show be able to to store and read', function() { + it('should be able to to store and read', function() { var k = createW(); var w = k.w; var copayers = k.copayers; @@ -96,10 +97,10 @@ describe('PublicKeyRing model', function() { var addressN = 2; var start = new Date().getTime(); for (var i = 0; i < changeN; i++) { - w.generateAddress(true); + w.generateAddress(true, k.pub); } for (var i = 0; i < addressN; i++) { - w.generateAddress(false); + w.generateAddress(false, k.pub); } var data = w.toObj(); @@ -115,8 +116,8 @@ describe('PublicKeyRing model', function() { }).should.throw(); } - w2.getSharedIndex().getChangeIndex().should.equal(changeN); - w2.getSharedIndex().getReceiveIndex().should.equal(addressN); + w2.getIndex(k.pub).getChangeIndex().should.equal(changeN); + w2.getIndex(k.pub).getReceiveIndex().should.equal(addressN); }); @@ -126,7 +127,7 @@ describe('PublicKeyRing model', function() { [true, false].forEach(function(isChange){ for (var i = 0; i < 2; i++) { - var a = w.generateAddress(isChange); + var a = w.generateAddress(isChange, k.pub); a.isValid().should.equal(true); a.isScript().should.equal(true); a.network().name.should.equal('livenet'); @@ -148,7 +149,7 @@ describe('PublicKeyRing model', function() { [true, false].forEach(function(isChange){ for (var i = 0; i < 2; i++) { - w.generateAddress(isChange); + w.generateAddress(isChange, k.pub); } }); @@ -167,12 +168,12 @@ describe('PublicKeyRing model', function() { var w = k.w; for (var i = 0; i < 3; i++) - w.generateAddress(true); + w.generateAddress(true, k.pub); for (var i = 0; i < 2; i++) - w.generateAddress(false); + w.generateAddress(false, k.pub); - w.getSharedIndex().getChangeIndex().should.equal(3); - w.getSharedIndex().getReceiveIndex().should.equal(2); + w.getIndex(k.pub).getChangeIndex().should.equal(3); + w.getIndex(k.pub).getReceiveIndex().should.equal(2); }); it('#merge index tests', function() { @@ -180,9 +181,9 @@ describe('PublicKeyRing model', function() { var w = k.w; for (var i = 0; i < 2; i++) - w.generateAddress(true); + w.generateAddress(true, k.pub); for (var i = 0; i < 3; i++) - w.generateAddress(false); + w.generateAddress(false, k.pub); var w2 = new PublicKeyRing({ networkName: 'livenet', @@ -191,8 +192,8 @@ describe('PublicKeyRing model', function() { w2.merge(w).should.equal(true); w2.requiredCopayers.should.equal(3); w2.totalCopayers.should.equal(5); - w2.getSharedIndex().getChangeIndex().should.equal(2); - w2.getSharedIndex().getReceiveIndex().should.equal(3); + w2.getIndex(k.pub).getChangeIndex().should.equal(2); + w2.getIndex(k.pub).getReceiveIndex().should.equal(3); // w2.merge(w).should.equal(false); @@ -391,8 +392,6 @@ describe('PublicKeyRing model', function() { var i = p.getIndex(Structure.SHARED_INDEX); should.exist(i); i.cosigner.should.equal(Structure.SHARED_INDEX); - var shared = p.getSharedIndex(); - shared.should.equal(i); }); it('#getIndex should throw error', function() { @@ -412,9 +411,9 @@ describe('PublicKeyRing model', function() { var amount = 2; for (var i = 0; i < amount; i++) - w.generateAddress(true); + w.generateAddress(true, k.pub); for (var i = 0; i < amount; i++) - w.generateAddress(false); + w.generateAddress(false, k.pub); var m = w.getRedeemScriptMap([ 'm/45\'/2147483647/1/0', diff --git a/test/test.TxProposals.js b/test/test.TxProposals.js index b0aa3a622..de069446d 100644 --- a/test/test.TxProposals.js +++ b/test/test.TxProposals.js @@ -51,12 +51,15 @@ var createPKR = function(bip32s) { w.addCopayer(); } } - w.generateAddress(false); - w.generateAddress(false); - w.generateAddress(false); - w.generateAddress(true); - w.generateAddress(true); - w.generateAddress(true); + + var pubkey = bip32s[0].publicHex; + + w.generateAddress(false, pubkey); + w.generateAddress(false, pubkey); + w.generateAddress(false, pubkey); + w.generateAddress(true, pubkey); + w.generateAddress(true, pubkey); + w.generateAddress(true, pubkey); return w; }; @@ -77,19 +80,22 @@ describe('TxProposals model', function() { var priv = new PrivateKey(config); var priv2 = new PrivateKey(config); var priv3 = new PrivateKey(config); + var pub = priv.publicHex; + var ts = Date.now(); var pkr = createPKR([priv, priv2, priv3]); var opts = { remainderOut: { - address: pkr.generateAddress(true).toString() + address: pkr.generateAddress(true, pub).toString() } }; var w = new TxProposals({ networkName: config.networkName, }); - unspentTest[0].address = pkr.getAddress(index, isChange).toString(); - unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange); + + unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); + unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); w.add(createTx( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '123456789', @@ -102,8 +108,10 @@ describe('TxProposals model', function() { var b = w.txps[ntxid].builder; var tx = b.build(); tx.isComplete().should.equal(false); - b.sign(priv2.getAll(pkr.getSharedIndex().getReceiveIndex(), pkr.getSharedIndex().getChangeIndex())); - b.sign(priv3.getAll(pkr.getSharedIndex().getReceiveIndex(), pkr.getSharedIndex().getChangeIndex())); + + var ringIndex = pkr.getIndex(pub); + b.sign(priv2.getAll(ringIndex.getReceiveIndex(), ringIndex.getChangeIndex(), ringIndex.cosigner)); + b.sign(priv3.getAll(ringIndex.getReceiveIndex(), ringIndex.getChangeIndex(), ringIndex.cosigner)); tx = b.build(); tx.isComplete().should.equal(true); @@ -132,6 +140,7 @@ describe('TxProposals model', function() { opts = opts || {}; var amountSat = bitcore.Bignum(amountSatStr); + var pub = priv.publicHex; if (!pkr.isComplete()) { throw new Error('publicKeyRing is not complete'); @@ -139,7 +148,7 @@ describe('TxProposals model', function() { if (!opts.remainderOut) { opts.remainderOut = { - address: pkr.generateAddress(true).toString() + address: pkr.generateAddress(true, pub).toString() }; }; @@ -181,14 +190,16 @@ describe('TxProposals model', function() { it('#getUsedUnspend', function() { var priv = new PrivateKey(config); + var pub = priv.publicHex; + var w = new TxProposals({ networkName: config.networkName, }); var start = new Date().getTime(); var pkr = createPKR([priv]); var ts = Date.now(); - unspentTest[0].address = pkr.getAddress(index, isChange).toString(); - unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange); + unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); + unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); w.add(createTx( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '123456789', @@ -204,6 +215,8 @@ describe('TxProposals model', function() { it('#merge with self', function() { var priv = new PrivateKey(config); + var pub = priv.publicHex; + var w = new TxProposals({ networkName: config.networkName, }); @@ -211,8 +224,8 @@ describe('TxProposals model', function() { var pkr = createPKR([priv]); var ts = Date.now(); - unspentTest[0].address = pkr.getAddress(index, isChange).toString(); - unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange); + unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); + unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); w.add(createTx( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '123456789', @@ -246,11 +259,13 @@ describe('TxProposals model', function() { it('#merge, merge signatures case 1', function() { var priv2 = new PrivateKey(config); var priv = new PrivateKey(config); + var pub = priv.publicHex; + var ts = Date.now(); var pkr = createPKR([priv]); var opts = { remainderOut: { - address: pkr.generateAddress(true).toString() + address: pkr.generateAddress(true, pub).toString() } }; @@ -258,8 +273,8 @@ describe('TxProposals model', function() { var w = new TxProposals({ networkName: config.networkName, }); - unspentTest[0].address = pkr.getAddress(index, isChange).toString(); - unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange); + unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); + unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); w.add(createTx( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '123456789', @@ -282,8 +297,8 @@ describe('TxProposals model', function() { networkName: config.networkName, publicKeyRing: w.publicKeyRing, }); - unspentTest[0].address = pkr.getAddress(index, isChange).toString(); - unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange); + unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); + unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); w2.add(createTx( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '123456789', @@ -346,6 +361,7 @@ describe('TxProposals model', function() { var priv = PrivateKey.fromObj(o1); var priv2 = PrivateKey.fromObj(o2); var priv3 = PrivateKey.fromObj(o3); + var pub = priv.publicHex; var ts = Date.now(); var pkr = createPKR([priv, priv2]); @@ -354,9 +370,9 @@ describe('TxProposals model', function() { address: '2MxK2m7cPtEwjZBB8Ksq7ppjkgJyFPJGemr' } }; - var addressToSign = pkr.generateAddress(false); + var addressToSign = pkr.generateAddress(false, pub); unspentTest[0].address = addressToSign.toString(); - unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange); + unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); var tx, txb; var w = new TxProposals({ @@ -459,19 +475,22 @@ describe('TxProposals model', function() { var priv = new PrivateKey(config); var priv2 = new PrivateKey(config); var priv3 = new PrivateKey(config); + var pub = priv.publicHex; + + var ts = Date.now(); var pkr = createPKR([priv, priv2, priv3]); var opts = { remainderOut: { - address: pkr.generateAddress(true).toString() + address: pkr.generateAddress(true, pub).toString() } }; var w = new TxProposals({ networkName: config.networkName, }); - unspentTest[0].address = pkr.getAddress(index, isChange).toString(); - unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange); + unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); + unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); w.add(createTx( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '123456789', @@ -491,8 +510,8 @@ describe('TxProposals model', function() { var w2 = new TxProposals({ networkName: config.networkName, }); - unspentTest[0].address = pkr.getAddress(index, isChange).toString(); - unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange); + unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); + unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); w2.add(createTx( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '123456789', @@ -511,8 +530,8 @@ describe('TxProposals model', function() { var w3 = new TxProposals({ networkName: config.networkName, }); - unspentTest[0].address = pkr.getAddress(index, isChange).toString(); - unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange); + unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); + unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); w3.add(createTx( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '123456789', @@ -558,6 +577,8 @@ describe('TxProposals model', function() { it('#toObj #fromObj roundtrip', function() { var priv = new PrivateKey(config); + var pub = priv.publicHex; + var pkr = createPKR([priv]); var w = new TxProposals({ walletId: 'qwerty', @@ -565,8 +586,8 @@ describe('TxProposals model', function() { }); var ts = Date.now(); - unspentTest[0].address = pkr.getAddress(index, isChange).toString(); - unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange); + unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); + unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); w.add(createTx( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '123456789', diff --git a/test/test.Wallet.js b/test/test.Wallet.js index 3e392833c..ce4196a0b 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -123,7 +123,7 @@ describe('Wallet model', function() { var opts = {}; var w = cachedCreateW(); addCopayers(w); - w.publicKeyRing.generateAddress(false); + w.publicKeyRing.generateAddress(false, w.publicKey); w.publicKeyRing.isComplete().should.equal(true); w.generateAddress(true).isValid().should.equal(true); w.generateAddress(true, function(addr) { @@ -177,8 +177,8 @@ describe('Wallet model', function() { var w = cachedCreateW2(); - unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString(); - unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true); + unspentTest[0].address = w.publicKeyRing.getAddress(1, true, w.publicKey).toString(); + unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true, w.publicKey); var ntxid = w.createTxSync( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', @@ -202,8 +202,8 @@ describe('Wallet model', function() { var w = cachedCreateW2(); var comment = 'This is a comment'; - unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString(); - unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true); + unspentTest[0].address = w.publicKeyRing.getAddress(1, true, w.publicKey).toString(); + unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true, w.publicKey); var ntxid = w.createTxSync( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', @@ -224,8 +224,8 @@ describe('Wallet model', function() { var w = cachedCreateW2(); var comment = 'Lorem ipsum dolor sit amet, suas euismod vis te, velit deleniti vix an. Pri ex suscipit similique, inermis per'; - unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString(); - unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true); + unspentTest[0].address = w.publicKeyRing.getAddress(1, true, w.publicKey).toString(); + unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true, w.publicKey); var badCreate = function() { w.createTxSync( @@ -260,8 +260,8 @@ describe('Wallet model', function() { var ts = Date.now(); for (var isChange = false; !isChange; isChange = true) { for (var index = 0; index < 3; index++) { - unspentTest[0].address = w.publicKeyRing.getAddress(index, isChange).toString(); - unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange); + unspentTest[0].address = w.publicKeyRing.getAddress(index, isChange, w.publicKey).toString(); + unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange, w.publicKey); w.createTxSync( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '123456789',