Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private computeSignature(auth: string | undefined, location: string, method: string, url: string, timestamp: string,
query: { [key: string]: any }, data: string) {
const u = this.parseUrl(url);
let path = u.pathname;
if (!path.startsWith('/')) {
path = '/' + path;
}
const queryPart = Object.keys(query)
.filter(key => query[key] !== undefined)
.map(key => encodeURIComponent(key) + '%' + encodeURIComponent(query[key]))
.join('%');
const raw = `${method}%${u.hostname}%${443}%${path}%${auth || ''}%${location}%${timestamp}%${queryPart}%${data}`;
const hmac = createHmac('sha1', Settings.KEY);
hmac.setEncoding('hex');
hmac.write(raw);
hmac.end();
return hmac.read();
}
computehkdf(ikm, salt) {
const prk = createHmac('sha256', salt).update(ikm).digest();
const infoBitsUpdate = Buffer.concat([
this.infoBits,
Buffer.from(String.fromCharCode(1), 'utf8'),
]);
const hmac = createHmac('sha256', prk).update(infoBitsUpdate).digest();
return hmac.slice(0, 16);
}
computehkdf(ikm, salt) {
const prk = createHmac('sha256', salt).update(ikm).digest();
const infoBitsUpdate = Buffer.concat([
this.infoBits,
Buffer.from(String.fromCharCode(1), 'utf8'),
]);
const hmac = createHmac('sha256', prk).update(infoBitsUpdate).digest();
return hmac.slice(0, 16);
}
addAppSecretProofModifier (appSecret) {
const accessToken = this.getModifier(GraphNode.PARAM_ACCESS_TOKEN)
if (!accessToken) return
this._modifiers[GraphNode.PARAM_APP_SECRET_PROOF] = createHmac('sha256', appSecret).update(accessToken).digest('hex')
}
}
function CKDPriv ({ key, chainCode }, index) {
const indexBuffer = Buffer.allocUnsafe(4);
indexBuffer.writeUInt32BE(index, 0);
const data = Buffer.concat([Buffer.alloc(1, 0), key, indexBuffer]);
const I = createHmac('sha512', chainCode).update(data).digest();
const IL = I.slice(0, 32);
const IR = I.slice(32);
return {
key: IL,
chainCode: IR,
};
}
function getChildKeyMultiplier(parentKeypair, entropyBuffer) {
const parentPublicKeyBuffer = parentKeypair.getPublicKeyBuffer()
const childKeyMultiplier = BigInteger.fromBuffer(
createHmac('sha256',
Buffer.concat([parentPublicKeyBuffer, entropyBuffer])
).digest()
)
if (childKeyMultiplier.compareTo(secp256k1.n) >= 0) {
throw new TypeError('Entropy is resulting in an invalid child scalar')
}
return childKeyMultiplier
}
function getMasterKeyFromSeed (seed) {
const hmac = createHmac('sha512', ED25519_CURVE);
const I = hmac.update(Buffer.from(seed, 'hex')).digest();
const IL = I.slice(0, 32);
const IR = I.slice(32);
return {
key: IL,
chainCode: IR,
};
}