Comparing version 3.0.6 to 3.1.0
@@ -50,3 +50,3 @@ /** | ||
* @prop {HDVersions} versions - magic bytes for base58 prefix | ||
* @prop {Number} depth - of hd path - typically 0 is seed, 1-3 hardened, 4-5 are not | ||
* @prop {Number} depth - of hd path - typically 0 is seed, 1-3 hardened, 4-5 public | ||
* @prop {Number} parentFingerprint - 32-bit int, slice of id, stored in child xkeys | ||
@@ -378,3 +378,4 @@ * @prop {Number} index - the final segment of an HD Path, the index of the wif/addr | ||
DashHd.deriveChild = async function (hdkey, index, hardened = HARDENED) { | ||
let seed = new Uint8Array(INDEXED_KEY_SIZE); | ||
// seed = indexedKey | ||
let indexedKey = new Uint8Array(INDEXED_KEY_SIZE); | ||
if (hardened) { | ||
@@ -385,9 +386,9 @@ if (!hdkey.privateKey) { | ||
index += HARDENED_OFFSET; | ||
seed.set([0], 0); | ||
seed.set(hdkey.privateKey, 1); | ||
indexedKey.set([0], 0); | ||
indexedKey.set(hdkey.privateKey, 1); | ||
} else { | ||
seed.set(hdkey.publicKey, 0); | ||
indexedKey.set(hdkey.publicKey, 0); | ||
} | ||
_indexDv.setUint32(0, index, BUFFER_BE); | ||
seed.set(_indexBuffer, KEY_SIZE); | ||
indexedKey.set(_indexBuffer, KEY_SIZE); | ||
@@ -397,3 +398,3 @@ let chainAndKeys; | ||
//@ts-ignore | ||
chainAndKeys = await DashHd._derive(seed, hdkey); | ||
chainAndKeys = await DashHd._derive(indexedKey, hdkey); | ||
} catch (e) { | ||
@@ -431,29 +432,24 @@ // In essence: | ||
//@ts-ignore | ||
DashHd._derive = async function (seed, chainParts) { | ||
//let I = await Utils.sha512hmac(ROOT_CHAIN, seedBuffer); | ||
//let IL = I.subarray(0, 32); | ||
//let IR = I.subarray(32); | ||
//let publicKey = await Utils.toPublicKey(IL); | ||
DashHd._derive = async function (indexedKey, xParent) { | ||
// seed = indexedKey | ||
// I = hash | ||
// IL = keyTweak | ||
// IR = nextChainCode | ||
let hash = await Utils.sha512hmac(xParent.chainCode, indexedKey); | ||
let keyTweak = hash.slice(0, 32); | ||
let hashedChainCode = hash.slice(32); | ||
let I = await Utils.sha512hmac(chainParts.chainCode, seed); | ||
let IL = I.slice(0, 32); | ||
let IR = I.slice(32); | ||
let nextPrivKey; | ||
let nextPubkey; | ||
if (chainParts.privateKey) { | ||
nextPrivKey = await Utils.privateKeyTweakAdd(chainParts.privateKey, IL); | ||
nextPubkey = await Utils.toPublicKey(nextPrivKey); | ||
} else if (chainParts.publicKey) { | ||
nextPubkey = await Utils.publicKeyTweakAdd(chainParts.publicKey, IL); | ||
} else { | ||
// TODO | ||
nextPrivKey = IL; | ||
nextPubkey = await Utils.toPublicKey(IL); | ||
let tweakedPrivKey; | ||
if (xParent.privateKey) { | ||
let priv = xParent.privateKey; | ||
tweakedPrivKey = await Utils.privateKeyTweakAdd(priv, keyTweak); | ||
} | ||
let pub = xParent.publicKey; | ||
let tweakedPubkey = await Utils.publicKeyTweakAdd(pub, keyTweak); | ||
return { | ||
chainCode: IR, | ||
privateKey: nextPrivKey, | ||
publicKey: nextPubkey, | ||
chainCode: hashedChainCode, | ||
privateKey: tweakedPrivKey, | ||
publicKey: tweakedPubkey, | ||
}; | ||
@@ -521,6 +517,16 @@ }; | ||
let chainAndKeys = await DashHd._derive(seed, { | ||
chainCode: ROOT_CHAIN, | ||
}); | ||
// I = hash | ||
// IL = rootPrivKey | ||
// IR = rootChainCode | ||
let hash = await Utils.sha512hmac(ROOT_CHAIN, seed); | ||
let rootPrivKey = hash.slice(0, 32); | ||
let rootChainCode = hash.slice(32); | ||
let rootPubkey = await Utils.toPublicKey(rootPrivKey); | ||
let chainAndKeys = { | ||
chainCode: rootChainCode, | ||
privateKey: rootPrivKey, | ||
publicKey: rootPubkey, | ||
}; | ||
let hdkey = Object.assign( | ||
@@ -748,4 +754,4 @@ { | ||
* @callback HDDeriveHelper | ||
* @param {Uint8Array} seed - derived from index and chain code, or root | ||
* @param {HDDeriveHelperOptions} chainParts | ||
* @param {Uint8Array} indexedKey - (misnomer "seed") the parent key bytes + index bytes | ||
* @param {HDDeriveHelperOptions} xParent - the xKey parent (keys, chain code, etc) | ||
* returns {Promise<HDDeriveHelperOptions>} | ||
@@ -759,3 +765,3 @@ * @throws Error - in the rare case the index can't produce a valid public key | ||
* @prop {Uint8Array|undefined?} [privateKey] | ||
* @prop {Uint8Array|undefined?} [publicKey] | ||
* @prop {Uint8Array} publicKey | ||
*/ | ||
@@ -762,0 +768,0 @@ |
{ | ||
"name": "dashhd", | ||
"version": "3.0.6", | ||
"version": "3.1.0", | ||
"description": "Manage HD Keys from HD Wallet Seed and Extended (xprv, xpub) Key Paths. Part of $DASH Tools.", | ||
@@ -5,0 +5,0 @@ "main": "dashhd.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73762
885