Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Data = 0x00 || ser_256(k_par)
data.set(arrayify(this.privateKey), 1);
// Hardened path
if (path) {
path += "'";
}
}
else {
// Data = ser_p(point(k_par))
data.set(arrayify(this.publicKey));
}
// Data += ser_32(i)
for (let i = 24; i >= 0; i -= 8) {
data[33 + (i >> 3)] = ((index >> (24 - i)) & 0xff);
}
const I = arrayify(computeHmac(SupportedAlgorithms.sha512, this.chainCode, data));
const IL = I.slice(0, 32);
const IR = I.slice(32);
// The private key
let ki = null;
// The public key
let Ki = null;
if (this.privateKey) {
ki = bytes32(BigNumber.from(IL).add(this.privateKey).mod(N));
}
else {
const ek = new SigningKey(hexlify(IL));
Ki = ek._addPoint(this.publicKey);
}
return new HDNode(_constructorGuard, ki, Ki, this.fingerprint, bytes32(IR), index, this.depth + 1, this.mnemonic, path);
}
derivePath(path) {
// Data = 0x00 || ser_256(k_par)
data.set(arrayify(this.privateKey), 1);
// Hardened path
if (path) { path += "'"; }
} else {
// Data = ser_p(point(k_par))
data.set(arrayify(this.publicKey));
}
// Data += ser_32(i)
for (let i = 24; i >= 0; i -= 8) { data[33 + (i >> 3)] = ((index >> (24 - i)) & 0xff); }
const I = arrayify(computeHmac(SupportedAlgorithms.sha512, this.chainCode, data));
const IL = I.slice(0, 32);
const IR = I.slice(32);
// The private key
let ki: string = null
// The public key
let Ki: string = null;
if (this.privateKey) {
ki = bytes32(BigNumber.from(IL).add(this.privateKey).mod(N));
} else {
const ek = new SigningKey(hexlify(IL));
Ki = ek._addPoint(this.publicKey);
}
// Data = 0x00 || ser_256(k_par)
data.set(bytes_1.arrayify(this.privateKey), 1);
// Hardened path
if (path) {
path += "'";
}
}
else {
// Data = ser_p(point(k_par))
data.set(bytes_1.arrayify(this.publicKey));
}
// Data += ser_32(i)
for (var i = 24; i >= 0; i -= 8) {
data[33 + (i >> 3)] = ((index >> (24 - i)) & 0xff);
}
var I = bytes_1.arrayify(sha2_1.computeHmac(sha2_1.SupportedAlgorithms.sha512, this.chainCode, data));
var IL = I.slice(0, 32);
var IR = I.slice(32);
// The private key
var ki = null;
// The public key
var Ki = null;
if (this.privateKey) {
ki = bytes32(bignumber_1.BigNumber.from(IL).add(this.privateKey).mod(N));
}
else {
var ek = new signing_key_1.SigningKey(bytes_1.hexlify(IL));
Ki = ek._addPoint(this.publicKey);
}
return new HDNode(_constructorGuard, ki, Ki, this.fingerprint, bytes32(IR), index, this.depth + 1, this.mnemonic, path);
};
HDNode.prototype.derivePath = function (path) {
const block1 = new Uint8Array(salt.length + 4)
block1.set(salt);
//salt.copy(block1, 0, 0, salt.length)
let r: number;
let T: Uint8Array;
for (let i = 1; i <= l; i++) {
//block1.writeUInt32BE(i, salt.length)
block1[salt.length] = (i >> 24) & 0xff;
block1[salt.length + 1] = (i >> 16) & 0xff;
block1[salt.length + 2] = (i >> 8) & 0xff;
block1[salt.length + 3] = i & 0xff;
//let U = createHmac(password).update(block1).digest();
let U = arrayify(computeHmac(hashAlgorithm, password, block1));
if (!hLen) {
hLen = U.length
T = new Uint8Array(hLen)
l = Math.ceil(keylen / hLen)
r = keylen - (l - 1) * hLen
}
//U.copy(T, 0, 0, hLen)
T.set(U);
for (let j = 1; j < iterations; j++) {
//U = createHmac(password).update(U).digest();
U = arrayify(computeHmac(hashAlgorithm, password, U));
for (let k = 0; k < hLen; k++) T[k] ^= U[k]
block1[salt.length + 1] = (i >> 16) & 0xff;
block1[salt.length + 2] = (i >> 8) & 0xff;
block1[salt.length + 3] = i & 0xff;
//let U = createHmac(password).update(block1).digest();
let U = arrayify(computeHmac(hashAlgorithm, password, block1));
if (!hLen) {
hLen = U.length;
T = new Uint8Array(hLen);
l = Math.ceil(keylen / hLen);
r = keylen - (l - 1) * hLen;
}
//U.copy(T, 0, 0, hLen)
T.set(U);
for (let j = 1; j < iterations; j++) {
//U = createHmac(password).update(U).digest();
U = arrayify(computeHmac(hashAlgorithm, password, U));
for (let k = 0; k < hLen; k++)
T[k] ^= U[k];
}
const destPos = (i - 1) * hLen;
const len = (i === l ? r : hLen);
//T.copy(DK, destPos, 0, len)
DK.set(arrayify(T).slice(0, len), destPos);
}
return hexlify(DK);
}
let hLen;
let l = 1;
const DK = new Uint8Array(keylen);
const block1 = new Uint8Array(salt.length + 4);
block1.set(salt);
//salt.copy(block1, 0, 0, salt.length)
let r;
let T;
for (let i = 1; i <= l; i++) {
//block1.writeUInt32BE(i, salt.length)
block1[salt.length] = (i >> 24) & 0xff;
block1[salt.length + 1] = (i >> 16) & 0xff;
block1[salt.length + 2] = (i >> 8) & 0xff;
block1[salt.length + 3] = i & 0xff;
//let U = createHmac(password).update(block1).digest();
let U = arrayify(computeHmac(hashAlgorithm, password, block1));
if (!hLen) {
hLen = U.length;
T = new Uint8Array(hLen);
l = Math.ceil(keylen / hLen);
r = keylen - (l - 1) * hLen;
}
//U.copy(T, 0, 0, hLen)
T.set(U);
for (let j = 1; j < iterations; j++) {
//U = createHmac(password).update(U).digest();
U = arrayify(computeHmac(hashAlgorithm, password, U));
for (let k = 0; k < hLen; k++)
T[k] ^= U[k];
}
const destPos = (i - 1) * hLen;
const len = (i === l ? r : hLen);
var hLen;
var l = 1;
var DK = new Uint8Array(keylen);
var block1 = new Uint8Array(salt.length + 4);
block1.set(salt);
//salt.copy(block1, 0, 0, salt.length)
var r;
var T;
for (var i = 1; i <= l; i++) {
//block1.writeUInt32BE(i, salt.length)
block1[salt.length] = (i >> 24) & 0xff;
block1[salt.length + 1] = (i >> 16) & 0xff;
block1[salt.length + 2] = (i >> 8) & 0xff;
block1[salt.length + 3] = i & 0xff;
//let U = createHmac(password).update(block1).digest();
var U = bytes_1.arrayify(sha2_1.computeHmac(hashAlgorithm, password, block1));
if (!hLen) {
hLen = U.length;
T = new Uint8Array(hLen);
l = Math.ceil(keylen / hLen);
r = keylen - (l - 1) * hLen;
}
//U.copy(T, 0, 0, hLen)
T.set(U);
for (var j = 1; j < iterations; j++) {
//U = createHmac(password).update(U).digest();
U = bytes_1.arrayify(sha2_1.computeHmac(hashAlgorithm, password, U));
for (var k = 0; k < hLen; k++)
T[k] ^= U[k];
}
var destPos = (i - 1) * hLen;
var len = (i === l ? r : hLen);