|
|
@ -299,7 +299,7 @@ class HDAccountsHelper { |
|
|
|
* @param {bitcoin.bip32.BIP32Interface} chainNode - Parent bip32 used for derivation |
|
|
|
* @param {number} index - index to be derived |
|
|
|
* @param {number} type - type of derivation |
|
|
|
* @returns {Promise<object>} returns an object {address: '...', chain: <int>, index: <int>, publicKey: <Buffer>, address: string } |
|
|
|
* @returns {Promise<object>} returns an object {address: '...', chain: <int>, index: <int>, address: string } |
|
|
|
*/ |
|
|
|
async deriveAddress(chain, chainNode, index, type) { |
|
|
|
// Derive M/chain/index
|
|
|
@ -308,7 +308,6 @@ class HDAccountsHelper { |
|
|
|
const addr = { |
|
|
|
chain: chain, |
|
|
|
index: index, |
|
|
|
publicKey: indexNode.publicKey |
|
|
|
} |
|
|
|
|
|
|
|
switch (type) { |
|
|
@ -363,17 +362,20 @@ class HDAccountsHelper { |
|
|
|
) { |
|
|
|
// Few addresses to be derived or external derivation deactivated
|
|
|
|
// Let's do it here
|
|
|
|
const addresses = await Promise.all(indices.map(index => { |
|
|
|
const promises = indices.map(index => { |
|
|
|
return this.deriveAddress(chain, chainNode, index, info.type) |
|
|
|
})) |
|
|
|
}) |
|
|
|
|
|
|
|
// Generate additional change address types for postmix account
|
|
|
|
if (this.isPostmixAcct(node) && chain === 1) { |
|
|
|
const additionalPostmixAddresses = this._generateAdditionalChangeAddresses(addresses) |
|
|
|
|
|
|
|
addresses.push(...additionalPostmixAddresses) |
|
|
|
indices.forEach((index) => { |
|
|
|
promises.push(this.deriveAddress(chain, chainNode, index, this.BIP44)) |
|
|
|
promises.push(this.deriveAddress(chain, chainNode, index, this.BIP49)) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
const addresses = await Promise.all(promises) |
|
|
|
|
|
|
|
return addresses; |
|
|
|
|
|
|
|
} else { |
|
|
@ -385,19 +387,13 @@ class HDAccountsHelper { |
|
|
|
xpub: this.xlatXPUB(xpub), |
|
|
|
chain: chain, |
|
|
|
indices: indices, |
|
|
|
type: info.type |
|
|
|
type: info.type, |
|
|
|
isPostmixChange: this.isPostmixAcct(node) && chain === 1 |
|
|
|
} |
|
|
|
|
|
|
|
const msg = await this.derivationPool.exec('deriveAddresses', [data]) |
|
|
|
|
|
|
|
if (msg.status === 'ok') { |
|
|
|
// Generate additional change address types for postmix account
|
|
|
|
if (this.isPostmixAcct(node) && chain === 1) { |
|
|
|
const additionalPostmixAddresses = this._generateAdditionalChangeAddresses(msg.addresses) |
|
|
|
|
|
|
|
msg.addresses.push(...additionalPostmixAddresses) |
|
|
|
} |
|
|
|
|
|
|
|
resolve(msg.addresses) |
|
|
|
} else { |
|
|
|
Logger.error(null, 'HdAccountsHelper : A problem was met during parallel addresses derivation') |
|
|
@ -416,26 +412,6 @@ class HDAccountsHelper { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description Derive additional change addresses (P2PKH & P2SH) for postmix account |
|
|
|
* @param addresses {{ chain: number, index: number, publicKey: Buffer, address: string }[]} - list of derived addresses |
|
|
|
* @returns {{ chain: number, index: number, publicKey: Buffer, address: string }[]} - array of additional address types |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
_generateAdditionalChangeAddresses(addresses) { |
|
|
|
const additionalPostmixAddresses = addresses.map((address) => { |
|
|
|
const newP2PKHAddress = {...address} |
|
|
|
const newP2SHAddress = {...address} |
|
|
|
|
|
|
|
newP2PKHAddress.address = addrHelper.p2pkhAddress(address.publicKey) |
|
|
|
newP2SHAddress.address = addrHelper.p2wpkhP2shAddress(address.publicKey) |
|
|
|
|
|
|
|
return [newP2PKHAddress, newP2SHAddress]; |
|
|
|
}) |
|
|
|
|
|
|
|
return additionalPostmixAddresses.flat() |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description Detect postmix account |
|
|
|
* @param {[bitcoin.bip32.BIP32Interface, bitcoin.bip32.BIP32Interface, bitcoin.bip32.BIP32Interface]} node - array of BIP32 node interfaces |
|
|
|