Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getFingerprint(master) {
const fp = hash160.digest(master.publicKey);
return fp.readUInt32BE(0, true);
}
getID() {
assert(this.master.key, 'Cannot derive id.');
const key = this.master.key.derive(44);
const bw = bio.write(37);
bw.writeBytes(key.publicKey);
bw.writeU32(this.network.magic);
const hash = hash160.digest(bw.render());
const b58 = bio.write(27);
b58.writeU8(0x03);
b58.writeU8(0xbe);
b58.writeU8(0x04);
b58.writeBytes(hash);
b58.writeChecksum(hash256.digest);
return base58.encode(b58.render());
}
const data = bw.render();
const hash = sha512.mac(data, this.chainCode);
const left = hash.slice(0, 32);
const right = hash.slice(32, 64);
let key;
try {
key = secp256k1.privateKeyTweakAdd(this.privateKey, left);
} 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;
}
static address(key) {
const bw = bio.write(27);
bw.writeU8(0x0f);
bw.writeU16BE(0xff01);
bw.writeBytes(hash160.digest(key));
bw.writeChecksum(hash256.digest);
return base58.encode(bw.render());
}
}
const data = bw.render();
const hash = sha512.mac(data, this.chainCode);
const left = hash.slice(0, 32);
const right = hash.slice(32, 64);
let key;
try {
key = secp256k1.privateKeyTweakAdd(this.privateKey, left);
} 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;
}
const data = bw.render();
const hash = sha512.mac(data, this.chainCode);
const left = hash.slice(0, 32);
const right = hash.slice(32, 64);
let key;
try {
key = secp256k1.publicKeyTweakAdd(this.publicKey, left, true);
} 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.publicKey = key;
common.cache.set(id, child);
return child;
}