Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function stealthDualReceive (d, r, eG) {
const eQ = ecc.pointMultiply(eG, d) // shared secret
const c = bitcoin.crypto.sha256(eQ)
const rc = ecc.privateAdd(r, c)
const v = bitcoin.ECPair.fromPrivateKey(rc)
return v
}
function stealthReceive (d, eG) {
const eQ = ecc.pointMultiply(eG, d) // shared secret
const c = bitcoin.crypto.sha256(eQ)
const dc = ecc.privateAdd(d, c)
const v = bitcoin.ECPair.fromPrivateKey(dc)
return v
}
this.publicKey.copy(data, 0);
data.writeUInt32BE(index, 33);
}
const I = crypto.hmacSHA512(this.chainCode, data);
const IL = I.slice(0, 32);
const IR = I.slice(32);
// if parse256(IL) >= n, proceed with the next value for i
if (!ecc.isPrivate(IL)) return this.derive(index + 1);
// Private parent key -> private child key
let hd: BIP32Interface;
if (!this.isNeutered()) {
// ki = parse256(IL) + kpar (mod n)
const ki = ecc.privateAdd(this.privateKey, IL);
// In case ki == 0, proceed with the next value for i
if (ki == null) return this.derive(index + 1);
hd = fromPrivateKeyLocal(
ki,
IR,
this.network,
this.depth + 1,
index,
this.fingerprint.readUInt32BE(0),
);
// Public parent key -> public child key
} else {
// Ki = point(parse256(IL)) + Kpar
// data = serP(point(kpar)) || ser32(index)
// = serP(Kpar) || ser32(index)
this.publicKey.copy(data, 0);
data.writeUInt32BE(index, 33);
}
const I = crypto.hmacSHA512(this.chainCode, data);
const IL = I.slice(0, 32);
const IR = I.slice(32);
// if parse256(IL) >= n, proceed with the next value for i
if (!ecc.isPrivate(IL))
return this.derive(index + 1);
// Private parent key -> private child key
let hd;
if (!this.isNeutered()) {
// ki = parse256(IL) + kpar (mod n)
const ki = ecc.privateAdd(this.privateKey, IL);
// In case ki == 0, proceed with the next value for i
if (ki == null)
return this.derive(index + 1);
hd = fromPrivateKeyLocal(ki, IR, this.network, this.depth + 1, index, this.fingerprint.readUInt32BE(0));
// Public parent key -> public child key
}
else {
// Ki = point(parse256(IL)) + Kpar
// = G*IL + Kpar
const Ki = ecc.pointAddScalar(this.publicKey, IL, true);
// In case Ki is the point at infinity, proceed with the next value for i
if (Ki === null)
return this.derive(index + 1);
hd = fromPublicKeyLocal(Ki, IR, this.network, this.depth + 1, index, this.fingerprint.readUInt32BE(0));
}
return hd;