|
|
@ -105,7 +105,7 @@ class HDAccountsHelper { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Translates |
|
|
|
* Translates |
|
|
|
* - a xpub/ypub/zpub into a xpub |
|
|
|
* - a tpub/upub/vpub into a tpub |
|
|
|
* @param {string} xpub - extended public key to be translated |
|
|
@ -120,7 +120,7 @@ class HDAccountsHelper { |
|
|
|
&& ver != this.MAGIC_TPUB |
|
|
|
&& ver != this.MAGIC_YPUB |
|
|
|
&& ver != this.MAGIC_UPUB |
|
|
|
&& ver != this.MAGIC_ZPUB |
|
|
|
&& ver != this.MAGIC_ZPUB |
|
|
|
&& ver != this.MAGIC_VPUB |
|
|
|
) { |
|
|
|
//Logger.error(null, 'HdAccountsHelper.xlatXPUB() : Incorrect format')
|
|
|
@ -177,12 +177,12 @@ class HDAccountsHelper { |
|
|
|
} |
|
|
|
|
|
|
|
let p = v |
|
|
|
|
|
|
|
|
|
|
|
if (p >= this.LOCKED) { |
|
|
|
ret.locked = true |
|
|
|
p -= this.LOCKED |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (p) { |
|
|
|
case this.BIP44: |
|
|
|
case this.BIP49: |
|
|
@ -190,7 +190,7 @@ class HDAccountsHelper { |
|
|
|
ret.type = p |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ret |
|
|
|
} |
|
|
|
|
|
|
@ -201,16 +201,16 @@ class HDAccountsHelper { |
|
|
|
* @returns {integer} |
|
|
|
*/ |
|
|
|
makeType(type, locked) { |
|
|
|
let p = |
|
|
|
let p = |
|
|
|
(type >= this.LOCKED) |
|
|
|
? type - this.LOCKED |
|
|
|
: type |
|
|
|
|
|
|
|
|
|
|
|
locked = !!locked |
|
|
|
|
|
|
|
|
|
|
|
if (locked) |
|
|
|
p += this.LOCKED |
|
|
|
|
|
|
|
|
|
|
|
return p |
|
|
|
} |
|
|
|
|
|
|
@ -245,7 +245,7 @@ class HDAccountsHelper { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Checks if a hd account is a valid hdnode |
|
|
|
* Checks if a hd account is a valid bip32 |
|
|
|
* @param {string} xpub - hd account |
|
|
|
* @returns {boolean} returns true if hd account is valid, false otherwise |
|
|
|
*/ |
|
|
@ -258,7 +258,7 @@ class HDAccountsHelper { |
|
|
|
const xlatedXpub = this.xlatXPUB(xpub) |
|
|
|
|
|
|
|
// Parse input as an HD Node. Throws if invalid
|
|
|
|
const node = bitcoin.HDNode.fromBase58(xlatedXpub, activeNet) |
|
|
|
const node = bitcoin.bip32.fromBase58(xlatedXpub, activeNet) |
|
|
|
|
|
|
|
// Check and see if this is a private key
|
|
|
|
if (!node.isNeutered()) |
|
|
@ -278,7 +278,7 @@ class HDAccountsHelper { |
|
|
|
/** |
|
|
|
* Get the hd node associated to an hd account |
|
|
|
* @param {string} xpub - hd account |
|
|
|
* @returns {HDNode} |
|
|
|
* @returns {bip32} |
|
|
|
*/ |
|
|
|
getNode(xpub) { |
|
|
|
if (this.isValid(xpub)) |
|
|
@ -291,7 +291,7 @@ class HDAccountsHelper { |
|
|
|
* Derives an address for an hd account |
|
|
|
* @param {int} chain - chain to be derived |
|
|
|
* must have a value on [0,1] for BIP44/BIP49/BIP84 derivation |
|
|
|
* @param {HDNode} chainNode - Parent HDNode used for derivation |
|
|
|
* @param {bip32} chainNode - Parent bip32 used for derivation |
|
|
|
* @param {int} index - index to be derived |
|
|
|
* @param {int} type - type of derivation |
|
|
|
* @returns {Promise - object} returns an object {address: '...', chain: <int>, index: <int>} |
|
|
@ -307,13 +307,13 @@ class HDAccountsHelper { |
|
|
|
|
|
|
|
switch (type) { |
|
|
|
case this.BIP44: |
|
|
|
addr.address = indexNode.getAddress() |
|
|
|
addr.address = bitcoin.payments.p2pkh({ pubkey: indexNode.publicKey, network: activeNet }).address |
|
|
|
break |
|
|
|
case this.BIP49: |
|
|
|
addr.address = addrHelper.p2wpkhP2shAddress(indexNode.getPublicKeyBuffer()) |
|
|
|
addr.address = addrHelper.p2wpkhP2shAddress(indexNode.publicKey) |
|
|
|
break |
|
|
|
case this.BIP84: |
|
|
|
addr.address = addrHelper.p2wpkhAddress(indexNode.getPublicKeyBuffer()) |
|
|
|
addr.address = addrHelper.p2wpkhAddress(indexNode.publicKey) |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
@ -382,7 +382,7 @@ class HDAccountsHelper { |
|
|
|
Logger.error(null, 'A problem was met during parallel addresses derivation') |
|
|
|
reject() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch(e) { |
|
|
|
Logger.error(e, 'A problem was met during parallel addresses derivation') |
|
|
|
reject(e) |
|
|
|