remove AddressManager from copayers on BIP44
This commit is contained in:
parent
d1e318a5b7
commit
e11da7cec5
|
@ -3,7 +3,7 @@ var $ = require('preconditions').singleton();
|
||||||
|
|
||||||
var WalletUtils = require('bitcore-wallet-utils');
|
var WalletUtils = require('bitcore-wallet-utils');
|
||||||
|
|
||||||
var SHARED_INDEX = 0x80000000 - 1;
|
var BIP45_SHARED_INDEX = 0x80000000 - 1;
|
||||||
|
|
||||||
function AddressManager() {};
|
function AddressManager() {};
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ AddressManager.create = function(opts) {
|
||||||
|
|
||||||
x.receiveAddressIndex = 0;
|
x.receiveAddressIndex = 0;
|
||||||
x.changeAddressIndex = 0;
|
x.changeAddressIndex = 0;
|
||||||
x.copayerIndex = (opts && _.isNumber(opts.copayerIndex)) ? opts.copayerIndex : SHARED_INDEX;
|
x.copayerIndex = _.isNumber(opts.copayerIndex) ? opts.copayerIndex : BIP45_SHARED_INDEX;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
@ -35,9 +35,8 @@ AddressManager.fromObj = function(obj) {
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressManager.prototype.supportsDerivation = function() {
|
AddressManager.supportsCopayerBranches = function(derivationStrategy) {
|
||||||
// BIP44 does not support copayer specific indexes
|
return derivationStrategy == WalletUtils.DERIVATION_STRATEGIES.BIP45;
|
||||||
return !(this.derivationStrategy == WalletUtils.DERIVATION_STRATEGIES.BIP44 && this.copayerIndex != SHARED_INDEX);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressManager.prototype._incrementIndex = function(isChange) {
|
AddressManager.prototype._incrementIndex = function(isChange) {
|
||||||
|
|
|
@ -36,10 +36,13 @@ Copayer.create = function(opts) {
|
||||||
signature: opts.signature,
|
signature: opts.signature,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
var derivationStrategy = opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45;
|
||||||
|
if (AddressManager.supportsCopayerBranches(derivationStrategy)) {
|
||||||
x.addressManager = AddressManager.create({
|
x.addressManager = AddressManager.create({
|
||||||
derivationStrategy: opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45,
|
derivationStrategy: derivationStrategy,
|
||||||
copayerIndex: opts.copayerIndex,
|
copayerIndex: opts.copayerIndex,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
x.customData = opts.customData;
|
x.customData = opts.customData;
|
||||||
|
|
||||||
|
@ -67,7 +70,9 @@ Copayer.fromObj = function(obj) {
|
||||||
x.requestPubKeys = obj.requestPubKeys;
|
x.requestPubKeys = obj.requestPubKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (obj.addressManager) {
|
||||||
x.addressManager = AddressManager.fromObj(obj.addressManager);
|
x.addressManager = AddressManager.fromObj(obj.addressManager);
|
||||||
|
}
|
||||||
x.customData = obj.customData;
|
x.customData = obj.customData;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
|
|
|
@ -1842,7 +1842,7 @@ WalletService.prototype.scan = function(opts, cb) {
|
||||||
});
|
});
|
||||||
if (opts.includeCopayerBranches) {
|
if (opts.includeCopayerBranches) {
|
||||||
_.each(wallet.copayers, function(copayer) {
|
_.each(wallet.copayers, function(copayer) {
|
||||||
if (copayer.addressManager.supportsDerivation()) {
|
if (copayer.addressManager) {
|
||||||
derivators.push({
|
derivators.push({
|
||||||
derive: _.bind(copayer.createAddress, copayer, wallet, isChange),
|
derive: _.bind(copayer.createAddress, copayer, wallet, isChange),
|
||||||
rewind: _.bind(copayer.addressManager.rewindIndex, copayer.addressManager, isChange),
|
rewind: _.bind(copayer.addressManager.rewindIndex, copayer.addressManager, isChange),
|
||||||
|
|
|
@ -1222,7 +1222,9 @@ describe('Wallet service', function() {
|
||||||
describe('#getStatus', function() {
|
describe('#getStatus', function() {
|
||||||
var server, wallet;
|
var server, wallet;
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
helpers.createAndJoinWallet(1, 1, function(s, w) {
|
helpers.createAndJoinWallet(1, 1, {
|
||||||
|
derivationStrategy: 'BIP45'
|
||||||
|
}, function(s, w) {
|
||||||
server = s;
|
server = s;
|
||||||
wallet = w;
|
wallet = w;
|
||||||
done();
|
done();
|
||||||
|
|
|
@ -27,6 +27,12 @@ describe('AddressManager', function() {
|
||||||
am.getCurrentAddressPath(false).should.equal('m/4/0/2');
|
am.getCurrentAddressPath(false).should.equal('m/4/0/2');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('#supportsCopayerBranches', function() {
|
||||||
|
it('should return true for BIP45 & false for BIP44', function() {
|
||||||
|
AddressManager.supportsCopayerBranches('BIP45').should.be.true;
|
||||||
|
AddressManager.supportsCopayerBranches('BIP44').should.be.false;
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('BIP45', function() {
|
describe('BIP45', function() {
|
||||||
describe('#getCurrentAddressPath', function() {
|
describe('#getCurrentAddressPath', function() {
|
||||||
it('should return a valid BIP32 path for given index', function() {
|
it('should return a valid BIP32 path for given index', function() {
|
||||||
|
@ -34,7 +40,6 @@ describe('AddressManager', function() {
|
||||||
derivationStrategy: 'BIP45',
|
derivationStrategy: 'BIP45',
|
||||||
copayerIndex: 4,
|
copayerIndex: 4,
|
||||||
});
|
});
|
||||||
am.supportsDerivation().should.be.true;
|
|
||||||
am.getCurrentAddressPath(false).should.equal('m/4/0/0');
|
am.getCurrentAddressPath(false).should.equal('m/4/0/0');
|
||||||
am.getCurrentAddressPath(true).should.equal('m/4/1/0');
|
am.getCurrentAddressPath(true).should.equal('m/4/1/0');
|
||||||
});
|
});
|
||||||
|
@ -43,7 +48,6 @@ describe('AddressManager', function() {
|
||||||
var am = AddressManager.create({
|
var am = AddressManager.create({
|
||||||
derivationStrategy: 'BIP45',
|
derivationStrategy: 'BIP45',
|
||||||
});
|
});
|
||||||
am.supportsDerivation().should.be.true;
|
|
||||||
am.getCurrentAddressPath(false).should.equal('m/2147483647/0/0');
|
am.getCurrentAddressPath(false).should.equal('m/2147483647/0/0');
|
||||||
am.getCurrentAddressPath(true).should.equal('m/2147483647/1/0');
|
am.getCurrentAddressPath(true).should.equal('m/2147483647/1/0');
|
||||||
});
|
});
|
||||||
|
@ -94,7 +98,6 @@ describe('AddressManager', function() {
|
||||||
describe('#getCurrentAddressPath', function() {
|
describe('#getCurrentAddressPath', function() {
|
||||||
it('should return first address path', function() {
|
it('should return first address path', function() {
|
||||||
var am = AddressManager.create();
|
var am = AddressManager.create();
|
||||||
am.supportsDerivation().should.be.true;
|
|
||||||
am.getCurrentAddressPath(false).should.equal('m/0/0');
|
am.getCurrentAddressPath(false).should.equal('m/0/0');
|
||||||
am.getCurrentAddressPath(true).should.equal('m/1/0');
|
am.getCurrentAddressPath(true).should.equal('m/1/0');
|
||||||
});
|
});
|
||||||
|
@ -102,7 +105,6 @@ describe('AddressManager', function() {
|
||||||
var am = AddressManager.create({
|
var am = AddressManager.create({
|
||||||
copayerIndex: 4,
|
copayerIndex: 4,
|
||||||
});
|
});
|
||||||
am.supportsDerivation().should.be.false;
|
|
||||||
am.getCurrentAddressPath(false).should.equal('m/0/0');
|
am.getCurrentAddressPath(false).should.equal('m/0/0');
|
||||||
am.getCurrentAddressPath(true).should.equal('m/1/0');
|
am.getCurrentAddressPath(true).should.equal('m/1/0');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue