Browse Source

allow p2pkh addresses in 1-of-1

activeAddress
Ivan Socolsky 10 years ago
parent
commit
45b7b65e99
  1. 2
      lib/model/copayer.js
  2. 5
      lib/model/wallet.js
  3. 5
      lib/server.js
  4. 14
      test/integration/server.js

2
lib/model/copayer.js

@ -82,7 +82,7 @@ Copayer.prototype.createAddress = function(wallet, isChange) {
$.checkState(wallet.isComplete()); $.checkState(wallet.isComplete());
var path = this.addressManager.getNewAddressPath(isChange); 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, { var address = Address.create(_.extend(raw, {
walletId: wallet.id, walletId: wallet.id,
})); }));

5
lib/model/wallet.js

@ -30,6 +30,8 @@ Wallet.create = function(opts) {
x.pubKey = opts.pubKey; x.pubKey = opts.pubKey;
x.network = opts.network; x.network = opts.network;
x.derivationStrategy = opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45; x.derivationStrategy = opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45;
x.addressType = opts.addressType || WalletUtils.SCRIPT_TYPES.P2SH;
x.addressManager = AddressManager.create({ x.addressManager = AddressManager.create({
derivationStrategy: x.derivationStrategy, derivationStrategy: x.derivationStrategy,
}); });
@ -55,6 +57,7 @@ Wallet.fromObj = function(obj) {
x.pubKey = obj.pubKey; x.pubKey = obj.pubKey;
x.network = obj.network; x.network = obj.network;
x.derivationStrategy = obj.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45; x.derivationStrategy = obj.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45;
x.addressType = obj.addressType || WalletUtils.SCRIPT_TYPES.P2SH;
x.addressManager = AddressManager.fromObj(obj.addressManager); x.addressManager = AddressManager.fromObj(obj.addressManager);
x.scanStatus = obj.scanStatus; x.scanStatus = obj.scanStatus;
@ -148,7 +151,7 @@ Wallet.prototype.createAddress = function(isChange) {
$.checkState(this.isComplete()); $.checkState(this.isComplete());
var path = this.addressManager.getNewAddressPath(isChange); 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, { var address = Address.create(_.extend(raw, {
walletId: this.id, walletId: this.id,
})); }));

5
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.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.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.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) { WalletService.prototype.createWallet = function(opts, cb) {
var self = this, var self = this,
@ -223,6 +224,9 @@ WalletService.prototype.createWallet = function(opts, cb) {
var derivationStrategy = (opts.n == 1 && opts.supportBIP44) ? var derivationStrategy = (opts.n == 1 && opts.supportBIP44) ?
WalletUtils.DERIVATION_STRATEGIES.BIP44 : WalletUtils.DERIVATION_STRATEGIES.BIP45; WalletUtils.DERIVATION_STRATEGIES.BIP44 : WalletUtils.DERIVATION_STRATEGIES.BIP45;
var addressType = (opts.n == 1 && opts.supportP2PKH) ?
WalletUtils.SCRIPT_TYPES.P2PKH : WalletUtils.SCRIPT_TYPES.P2SH;
try { try {
pubKey = new PublicKey.fromString(opts.pubKey); pubKey = new PublicKey.fromString(opts.pubKey);
} catch (ex) { } catch (ex) {
@ -250,6 +254,7 @@ WalletService.prototype.createWallet = function(opts, cb) {
network: opts.network, network: opts.network,
pubKey: pubKey.toString(), pubKey: pubKey.toString(),
derivationStrategy: derivationStrategy, derivationStrategy: derivationStrategy,
addressType: addressType,
}); });
self.storage.storeWallet(wallet, function(err) { self.storage.storeWallet(wallet, function(err) {
log.debug('Wallet created', wallet.id, opts.network); log.debug('Wallet created', wallet.id, opts.network);

14
test/integration/server.js

@ -97,12 +97,14 @@ helpers.createAndJoinWallet = function(m, n, opts, cb) {
var offset = opts.offset || 0; var offset = opts.offset || 0;
var supportBIP44 = _.isBoolean(opts.supportBIP44) ? opts.supportBIP44 : true var supportBIP44 = _.isBoolean(opts.supportBIP44) ? opts.supportBIP44 : true
var supportP2PKH = _.isBoolean(opts.supportP2PKH) ? opts.supportP2PKH : true
var walletOpts = { var walletOpts = {
name: 'a wallet', name: 'a wallet',
m: m, m: m,
n: n, n: n,
pubKey: TestData.keyPair.pub, pubKey: TestData.keyPair.pub,
supportBIP44: supportBIP44, supportBIP44: supportBIP44,
supportP2PKH: supportP2PKH,
}; };
server.createWallet(walletOpts, function(err, walletId) { server.createWallet(walletOpts, function(err, walletId) {
if (err) return cb(err); if (err) return cb(err);
@ -1412,7 +1414,7 @@ describe('Wallet service', function() {
should.exist(address); should.exist(address);
address.walletId.should.equal(wallet.id); address.walletId.should.equal(wallet.id);
address.network.should.equal('livenet'); address.network.should.equal('livenet');
address.address.should.equal('3J4J9nkFpzQjUGDh5hLKMKztFSPWMKejKE'); address.address.should.equal('1L3z9LPd861FWQhf3vDn89Fnc9dkdBo2CG');
address.isChange.should.be.false; address.isChange.should.be.false;
address.path.should.equal('m/0/0'); address.path.should.equal('m/0/0');
server.getNotifications({}, function(err, notifications) { server.getNotifications({}, function(err, notifications) {
@ -4376,9 +4378,9 @@ describe('Wallet service', function() {
it('should scan main addresses', function(done) { it('should scan main addresses', function(done) {
helpers.stubAddressActivity( helpers.stubAddressActivity(
['3J4J9nkFpzQjUGDh5hLKMKztFSPWMKejKE', // m/0/0 ['1L3z9LPd861FWQhf3vDn89Fnc9dkdBo2CG', // m/0/0
'384JHSf9kVBs3yXsPwCzEScRs395u8hwxj', // m/0/2 '1GdXraZ1gtoVAvBh49D4hK9xLm6SKgesoE', // m/0/2
'3NgXBiMQvwcRU8khVoPFJ6gsbGg9ZYrRzH', // m/1/0 '1FUzgKcyPJsYwDLUEVJYeE2N3KVaoxTjGS', // m/1/0
]); ]);
var expectedPaths = [ var expectedPaths = [
'm/0/0', 'm/0/0',
@ -4562,7 +4564,9 @@ describe('Wallet service', function() {
WalletService.SCAN_CONFIG.scanWindow = 2; WalletService.SCAN_CONFIG.scanWindow = 2;
WalletService.SCAN_CONFIG.derivationDelay = 0; WalletService.SCAN_CONFIG.derivationDelay = 0;
helpers.createAndJoinWallet(1, 1, function(s, w) { helpers.createAndJoinWallet(1, 1, {
supportP2PKH: false
}, function(s, w) {
server = s; server = s;
wallet = w; wallet = w;
done(); done();

Loading…
Cancel
Save