Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const hash = sha512.mac(seed, SEED_SALT);
const left = hash.slice(0, 32);
const right = hash.slice(32, 64);
// Only a 1 in 2^127 chance of happening.
if (!secp256k1.privateKeyVerify(left))
throw new Error('Master private key is invalid.');
this.depth = 0;
this.parentFingerPrint = 0;
this.childIndex = 0;
this.chainCode = right;
this.privateKey = left;
this.publicKey = secp256k1.publicKeyCreate(left, true);
return this;
}
if (options.authPrivKey != null) {
assert(Buffer.isBuffer(options.authPrivKey),
'authPrivKey must be a buffer.');
assert(secp256k1.privateKeyVerify(options.authPrivKey),
'authPrivKey is not a private key.');
authPrivKey = options.authPrivKey;
} else {
authPrivKey = secp256k1.privateKeyGenerate();
}
this.joinPrivKey = joinPrivKey;
this.joinPubKey = secp256k1.publicKeyCreate(this.joinPrivKey, true);
this.authPrivKey = authPrivKey;
this.authPubKey = secp256k1.publicKeyCreate(this.authPrivKey, true);
this.master = master;
this.fingerPrint = getFingerprint(master);
this.accountPrivKey = this.master.deriveAccount(44, this.purpose, 0);
this.accountKey = this.accountPrivKey.toPublic();
}
fromKey(key, entropy) {
assert(Buffer.isBuffer(key) && key.length === 32);
assert(Buffer.isBuffer(entropy) && entropy.length === 32);
this.depth = 0;
this.parentFingerPrint = 0;
this.childIndex = 0;
this.chainCode = entropy;
this.privateKey = key;
this.publicKey = secp256k1.publicKeyCreate(key, true);
return this;
}
function getPublic(priv) {
return secp256k1.publicKeyCreate(priv, true);
}
readKey(data) {
const br = bio.read(data);
this.key = new HDPrivateKey();
this.key.chainCode = br.readBytes(32);
this.key.privateKey = br.readBytes(32);
this.key.publicKey = secp256k1.publicKeyCreate(this.key.privateKey, true);
if (br.readU8() === 1)
this.mnemonic = Mnemonic.read(br);
return this;
}
} catch (e) {
return this.derive(index + 1);
}
if (this.fingerPrint === -1) {
const fp = hash160.digest(this.publicKey);
this.fingerPrint = fp.readUInt32BE(0, true);
}
const child = new this.constructor();
child.depth = this.depth + 1;
child.parentFingerPrint = this.fingerPrint;
child.childIndex = index;
child.chainCode = right;
child.privateKey = key;
child.publicKey = secp256k1.publicKeyCreate(key, true);
common.cache.set(id, child);
return child;
}
fromOptions(options) {
assert(options, 'No options for HD private key.');
assert((options.depth & 0xff) === options.depth);
assert((options.parentFingerPrint >>> 0) === options.parentFingerPrint);
assert((options.childIndex >>> 0) === options.childIndex);
assert(Buffer.isBuffer(options.chainCode));
assert(Buffer.isBuffer(options.privateKey));
this.depth = options.depth;
this.parentFingerPrint = options.parentFingerPrint;
this.childIndex = options.childIndex;
this.chainCode = options.chainCode;
this.privateKey = options.privateKey;
this.publicKey = secp256k1.publicKeyCreate(options.privateKey, true);
return this;
}
} catch (e) {
return this.derive(index + 1);
}
if (this.fingerPrint === -1) {
const fp = hash160.digest(this.publicKey);
this.fingerPrint = fp.readUInt32BE(0, true);
}
const child = new this.constructor();
child.depth = this.depth + 1;
child.parentFingerPrint = this.fingerPrint;
child.childIndex = index;
child.chainCode = right;
child.privateKey = key;
child.publicKey = secp256k1.publicKeyCreate(key, true);
common.cache.set(id, child);
return child;
}