Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
authenticationHelper.getPasswordAuthenticationKey(_this6.deviceKey, _this6.randomPassword, serverBValue, salt, function (errHkdf, hkdf) {
// getPasswordAuthenticationKey callback start
if (errHkdf) {
return callback.onFailure(errHkdf);
}
var dateNow = dateHelper.getNowString();
var signatureString = createHmac('sha256', hkdf).update(Buffer.concat([Buffer.from(_this6.deviceGroupKey, 'utf8'), Buffer.from(_this6.deviceKey, 'utf8'), Buffer.from(challengeParameters.SECRET_BLOCK, 'base64'), Buffer.from(dateNow, 'utf8')])).digest('base64');
var challengeResponses = {};
challengeResponses.USERNAME = _this6.username;
challengeResponses.PASSWORD_CLAIM_SECRET_BLOCK = challengeParameters.SECRET_BLOCK;
challengeResponses.TIMESTAMP = dateNow;
challengeResponses.PASSWORD_CLAIM_SIGNATURE = signatureString;
challengeResponses.DEVICE_KEY = _this6.deviceKey;
var jsonReqResp = {
ChallengeName: 'DEVICE_PASSWORD_VERIFIER',
ClientId: _this6.pool.getClientId(),
ChallengeResponses: challengeResponses,
Session: data.Session
};
if (_this6.getUserContextData()) {
_buildEncRequest(enc_request_code, payload) {
// Get the ephemeral id - all encrypted requests require there to be an
// epehemeral public key in order to send
const ephemId = parseInt(this._getEphemId().toString('hex'), 16)
let i = 0;
// Build the payload and checksum
const payloadPreCs = Buffer.concat([Buffer.from([enc_request_code]), payload]);
const cs = checksum(payloadPreCs);
const payloadBuf = Buffer.alloc(payloadPreCs.length + 4);
// Lattice validates checksums in little endian
payloadPreCs.copy(payloadBuf, 0);
payloadBuf.writeUInt32LE(cs, payloadPreCs.length);
// Encrypt this payload
const secret = this._getSharedSecret();
const newEncPayload = aes256_encrypt(payloadBuf, secret);
// Write to the overall payload. We must use the same length
// for every encrypted request and must include a 32-bit ephemId
// along with the encrypted data
const newPayload = Buffer.alloc(ENC_MSG_LEN + 4);
// First 4 bytes are the ephemeral id (in little endian)
buf = Buffer.concat([
buf,
Buffer.from(
encodeFieldNumberAndTyp3(fopts.binFieldNum, Typ3.ByteLength)
)
]);
// TODO: handling default https://github.com/tendermint/go-amino/blob/master/binary-encode.go#L311
const efopts = {
...fopts,
...{
binFieldNum: 1
}
};
buf = Buffer.concat([
buf,
Buffer.from(encodeReflectBinary(codec, einfo, v, efopts, false))
]);
}
}
}
if (bare) {
return buf;
}
return Encoder.encodeByteSlice(buf);
}
// TODO: handling default https://github.com/tendermint/go-amino/blob/master/binary-encode.go#L404
// TODO: handling unpacked list https://github.com/tendermint/go-amino/blob/master/binary-encode.go#L409
buf = Buffer.concat([
buf,
Buffer.from(
encodeFieldNumberAndTyp3(
field.fieldOptions.binFieldNum,
typeToTyp3(finfo!.type, field.fieldOptions)
)
)
]);
buf = Buffer.concat([
buf,
Buffer.from(
encodeReflectBinary(codec, finfo, frv, field.fieldOptions, false)
)
]);
// TODO: ??? https://github.com/tendermint/go-amino/blob/master/binary-encode.go#L431
}
}
if (bare) {
return buf;
}
return Encoder.encodeByteSlice(buf);
}
throw new Error("Cannot encode unregistered concrete type");
}
let buf: Buffer = Buffer.alloc(0);
let needDisamb = false;
if (
iinfo.interfaceInfo &&
iinfo.interfaceInfo.interfaceOptions.alwaysDisambiguate
) {
needDisamb = true;
}
// TODO: judge whether disamb is necessary https://github.com/tendermint/go-amino/blob/master/binary-encode.go#L211
if (needDisamb) {
buf = Buffer.concat([
Buffer.alloc(1),
Buffer.from(cinfo.concreteInfo.disamb)
]);
}
buf = Buffer.concat([buf, Buffer.from(cinfo.concreteInfo.prefix)]);
buf = Buffer.concat([
buf,
Buffer.from(encodeReflectBinary(codec, cinfo, value, fopts, true))
]);
if (bare) {
return buf;
}
return Encoder.encodeByteSlice(buf);
if (value.length > 0) {
const [deferedInfo] = deferTypeInfo(codec, einfo, value[0], "");
einfo = deferedInfo;
const typ3 = typeToTyp3(deferedInfo.type, fopts);
if (typ3 !== Typ3.ByteLength) {
for (const v of value) {
buf = Buffer.concat([
buf,
Buffer.from(encodeReflectBinary(codec, einfo, v, fopts, false))
]);
}
} else {
for (const v of value) {
buf = Buffer.concat([
buf,
Buffer.from(
encodeFieldNumberAndTyp3(fopts.binFieldNum, Typ3.ByteLength)
)
]);
// TODO: handling default https://github.com/tendermint/go-amino/blob/master/binary-encode.go#L311
const efopts = {
...fopts,
...{
binFieldNum: 1
}
};
buf = Buffer.concat([
buf,
export function encodeInt64(i: number | bigInteger.BigInteger): Uint8Array {
constants.mustInt64(i);
let int = constants.numberToInt(i);
if (int.isNegative()) {
int = int.negate();
int = int.minus(bigInteger(1));
int = constants.MAX_UINT64.minus(int);
}
let buf = Buffer.from(int.toArray(256).value.reverse());
if (buf.length > 8) {
throw new Error("buffer overflowed");
}
buf = Buffer.concat([buf, Buffer.alloc(8 - buf.length)], 8);
return buf;
}
function buildSig(sig, pubkey) {
sig = Buffer.concat([sig, DEFAULT_SIGHASH_BUFFER])
const sigLen = getVarInt(sig.length);
const pubkeyLen = getVarInt(pubkey.length);
const slice = Buffer.concat([sigLen, sig, pubkeyLen, pubkey]);
const len = getVarInt(slice.length);
return Buffer.concat([len, slice]);
}
function buildSig(sig, pubkey) {
sig = Buffer.concat([sig, DEFAULT_SIGHASH_BUFFER])
const sigLen = getVarInt(sig.length);
const pubkeyLen = getVarInt(pubkey.length);
const slice = Buffer.concat([sigLen, sig, pubkeyLen, pubkey]);
const len = getVarInt(slice.length);
return Buffer.concat([len, slice]);
}