diff --git a/lib/model/copayer.js b/lib/model/copayer.js index d7cfd3b..0e25001 100644 --- a/lib/model/copayer.js +++ b/lib/model/copayer.js @@ -82,7 +82,7 @@ Copayer.prototype.createAddress = function(wallet, isChange) { $.checkState(wallet.isComplete()); var path = this.addressManager.getNewAddressPath(isChange); - var raw = Address.create(WalletUtils.deriveAddress(wallet.publicKeyRing, path, wallet.m, wallet.network)); + var raw = Address.create(WalletUtils.deriveAddress(wallet.addressType, wallet.publicKeyRing, path, wallet.m, wallet.network)); var address = Address.create(_.extend(raw, { walletId: wallet.id, })); diff --git a/lib/model/wallet.js b/lib/model/wallet.js index 4639073..64bb775 100644 --- a/lib/model/wallet.js +++ b/lib/model/wallet.js @@ -30,6 +30,8 @@ Wallet.create = function(opts) { x.pubKey = opts.pubKey; x.network = opts.network; x.derivationStrategy = opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45; + x.addressType = opts.addressType || WalletUtils.SCRIPT_TYPES.P2SH; + x.addressManager = AddressManager.create({ derivationStrategy: x.derivationStrategy, }); @@ -55,6 +57,7 @@ Wallet.fromObj = function(obj) { x.pubKey = obj.pubKey; x.network = obj.network; x.derivationStrategy = obj.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45; + x.addressType = obj.addressType || WalletUtils.SCRIPT_TYPES.P2SH; x.addressManager = AddressManager.fromObj(obj.addressManager); x.scanStatus = obj.scanStatus; @@ -148,7 +151,7 @@ Wallet.prototype.createAddress = function(isChange) { $.checkState(this.isComplete()); var path = this.addressManager.getNewAddressPath(isChange); - var raw = WalletUtils.deriveAddress(this.publicKeyRing, path, this.m, this.network); + var raw = WalletUtils.deriveAddress(this.addressType, this.publicKeyRing, path, this.m, this.network); var address = Address.create(_.extend(raw, { walletId: this.id, })); diff --git a/lib/server.js b/lib/server.js index 7855e0c..379fefc 100644 --- a/lib/server.js +++ b/lib/server.js @@ -204,6 +204,7 @@ WalletService.prototype._runLocked = function(cb, task) { * @param {string} opts.pubKey - Public key to verify copayers joining have access to the wallet secret. * @param {string} [opts.network = 'livenet'] - The Bitcoin network for this wallet. * @param {string} [opts.supportBIP44 = false] - Client supports BIP44 paths for 1-of-1 wallets. + * @param {string} [opts.supportP2PKH = false] - Client supports P2PKH address type for 1-of-1 wallets. */ WalletService.prototype.createWallet = function(opts, cb) { var self = this, @@ -223,6 +224,9 @@ WalletService.prototype.createWallet = function(opts, cb) { var derivationStrategy = (opts.n == 1 && opts.supportBIP44) ? WalletUtils.DERIVATION_STRATEGIES.BIP44 : WalletUtils.DERIVATION_STRATEGIES.BIP45; + var addressType = (opts.n == 1 && opts.supportP2PKH) ? + WalletUtils.SCRIPT_TYPES.P2PKH : WalletUtils.SCRIPT_TYPES.P2SH; + try { pubKey = new PublicKey.fromString(opts.pubKey); } catch (ex) { @@ -250,6 +254,7 @@ WalletService.prototype.createWallet = function(opts, cb) { network: opts.network, pubKey: pubKey.toString(), derivationStrategy: derivationStrategy, + addressType: addressType, }); self.storage.storeWallet(wallet, function(err) { log.debug('Wallet created', wallet.id, opts.network); diff --git a/test/integration/server.js b/test/integration/server.js index 93eafa6..0b93e6c 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -97,12 +97,14 @@ helpers.createAndJoinWallet = function(m, n, opts, cb) { var offset = opts.offset || 0; var supportBIP44 = _.isBoolean(opts.supportBIP44) ? opts.supportBIP44 : true + var supportP2PKH = _.isBoolean(opts.supportP2PKH) ? opts.supportP2PKH : true var walletOpts = { name: 'a wallet', m: m, n: n, pubKey: TestData.keyPair.pub, supportBIP44: supportBIP44, + supportP2PKH: supportP2PKH, }; server.createWallet(walletOpts, function(err, walletId) { if (err) return cb(err); @@ -1412,7 +1414,7 @@ describe('Wallet service', function() { should.exist(address); address.walletId.should.equal(wallet.id); address.network.should.equal('livenet'); - address.address.should.equal('3J4J9nkFpzQjUGDh5hLKMKztFSPWMKejKE'); + address.address.should.equal('1L3z9LPd861FWQhf3vDn89Fnc9dkdBo2CG'); address.isChange.should.be.false; address.path.should.equal('m/0/0'); server.getNotifications({}, function(err, notifications) { @@ -4376,9 +4378,9 @@ describe('Wallet service', function() { it('should scan main addresses', function(done) { helpers.stubAddressActivity( - ['3J4J9nkFpzQjUGDh5hLKMKztFSPWMKejKE', // m/0/0 - '384JHSf9kVBs3yXsPwCzEScRs395u8hwxj', // m/0/2 - '3NgXBiMQvwcRU8khVoPFJ6gsbGg9ZYrRzH', // m/1/0 + ['1L3z9LPd861FWQhf3vDn89Fnc9dkdBo2CG', // m/0/0 + '1GdXraZ1gtoVAvBh49D4hK9xLm6SKgesoE', // m/0/2 + '1FUzgKcyPJsYwDLUEVJYeE2N3KVaoxTjGS', // m/1/0 ]); var expectedPaths = [ 'm/0/0', @@ -4562,7 +4564,9 @@ describe('Wallet service', function() { WalletService.SCAN_CONFIG.scanWindow = 2; WalletService.SCAN_CONFIG.derivationDelay = 0; - helpers.createAndJoinWallet(1, 1, function(s, w) { + helpers.createAndJoinWallet(1, 1, { + supportP2PKH: false + }, function(s, w) { server = s; wallet = w; done();