more fixes.
This commit is contained in:
parent
97bcdd79c2
commit
cf50502238
@ -70,7 +70,7 @@ function Wallet(options) {
|
||||
this.accountIndex = options.accountIndex || 0;
|
||||
this.addressDepth = options.addressDepth || 0;
|
||||
this.changeDepth = options.changeDepth || 0;
|
||||
this.cosignerIndex = 0;
|
||||
this.cosignerIndex = -1;
|
||||
this.purposeKeys = options.purposeKeys || [];
|
||||
this.keys = options.keys || [];
|
||||
|
||||
@ -350,12 +350,23 @@ Wallet.prototype.finalizeKeys = function finalizeKeys(key) {
|
||||
}
|
||||
}
|
||||
|
||||
assert(this.cosignerIndex !== -1);
|
||||
|
||||
this._initAddresses();
|
||||
return;
|
||||
}
|
||||
|
||||
this.keys = utils.sortKeys(this.keys);
|
||||
|
||||
for (i = 0; i < this.keys.length; i++) {
|
||||
if (utils.isEqual(this.keys[i], this.current.publicKey)) {
|
||||
this.cosignerIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(this.cosignerIndex !== -1);
|
||||
|
||||
this._initAddresses();
|
||||
};
|
||||
|
||||
@ -509,22 +520,8 @@ Wallet.prototype.createAddress = function createAddress(change, index) {
|
||||
change: change
|
||||
};
|
||||
|
||||
if (this.bip45) {
|
||||
this.purposeKeys.forEach(function(key, cosignerIndex) {
|
||||
key = key
|
||||
.derive(cosignerIndex)
|
||||
.derive(change ? 1 : 0)
|
||||
.derive(change ? self.changeDepth : self.addressDepth);
|
||||
options.keys.push(key.publicKey);
|
||||
});
|
||||
this.keys = utils.sortKeys(options.keys);
|
||||
} else {
|
||||
this.keys.forEach(function(key, i) {
|
||||
options.keys.push(key);
|
||||
});
|
||||
}
|
||||
|
||||
if (index == null) {
|
||||
index = change ? self.changeDepth : self.addressDepth;
|
||||
if (this.hd) {
|
||||
if (change)
|
||||
this.changeDepth++;
|
||||
@ -533,6 +530,23 @@ Wallet.prototype.createAddress = function createAddress(change, index) {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.bip45) {
|
||||
this.purposeKeys.forEach(function(key, cosignerIndex) {
|
||||
key = key
|
||||
.derive(cosignerIndex)
|
||||
.derive(change ? 1 : 0)
|
||||
.derive(index);
|
||||
options.keys.push(key.publicKey);
|
||||
});
|
||||
this.keys = utils.sortKeys(options.keys);
|
||||
} else {
|
||||
this.keys.forEach(function(key, i) {
|
||||
if (i !== this.cosignerIndex)
|
||||
options.keys.push(key);
|
||||
}, this);
|
||||
options.keys.push(key.pub);
|
||||
}
|
||||
|
||||
address = this.addAddress(options);
|
||||
|
||||
return address;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user