Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
authClientSocket.on('data', function (data) {
console.log('data received from auth');
var buf = new buffer.Buffer(data);
if (!expectingMoreData) {
obj = exports.parseIoTSP(buf);
if (obj.payload.length < obj.payloadLen) {
expectingMoreData = true;
console.log('more data will come. current: ' + obj.payload.length +
' expected: ' + obj.payloadLen);
}
} else {
obj.payload = buffer.concat([obj.payload, new buffer.Buffer(data)]);
if (obj.payload.length == obj.payloadLen) {
expectingMoreData = false;
} else {
console.log('more data will come. current: ' + obj.payload.length +
' expected: ' + obj.payloadLen);
}
}
if (expectingMoreData) {
// do not process the packet yet
return;
} else if (obj.msgType == msgType.AUTH_HELLO) {
var authHello = parseAuthHello(obj.payload);
myNonce = new buffer.Buffer(crypto.randomBytes(AUTH_NONCE_SIZE));
var sessionKeyReq = {
entityClientSocket.on('data', function (data) {
console.log('data received from server');
var buf = new buffer.Buffer(data);
var ret;
if (!expectingMoreData) {
obj = exports.parseIoTSP(buf);
if (obj.payload.length < obj.payloadLen) {
expectingMoreData = true;
console.log('more data will come. current: ' + obj.payload.length +
' expected: ' + obj.payloadLen);
}
} else {
obj.payload = buffer.concat([obj.payload, new buffer.Buffer(data)]);
if (obj.payload.length == obj.payloadLen) {
expectingMoreData = false;
} else {
console.log('more data will come. current: ' + obj.payload.length +
' expected: ' + obj.payloadLen);
}
}
if (expectingMoreData) {
// do not process the packet yet
return;
} else if (obj.msgType == msgType.SKEY_HANDSHAKE_2) {
console.log('received session key handshake2!');
if (entityClientState != entityClientCommState.HANDSHAKE_1_SENT) {
eventHandlers.onError('Comm init failed: Wrong sequence of handshake, disconnecting...');
entityClientSocket.close();
export const registerTransaction = ($assetName, $assetAmount, $publicKeyEncoded) => {
var ecparams = ecurve.getCurveByName('secp256r1');
var curvePt = ecurve.Point.decodeFrom(ecparams,new Buffer($publicKeyEncoded,"hex"));
var curvePtX = curvePt.affineX.toBuffer(32);
var curvePtY = curvePt.affineY.toBuffer(32);
var publicKey = buffer.concat([new Buffer([0x04]), curvePtX, curvePtY]);
var signatureScript = createSignatureScript($publicKeyEncoded);
var myProgramHash = getHash(signatureScript);
// data
var data = "40";
// version
data = data + "00";
// asset name
var assetName = ab2hexstring(stringToBytes($assetName));
var assetNameLen = (assetName.length / 2).toString()
if (assetNameLen.length == 1) assetNameLen = "0" + assetNameLen;
data = data + assetNameLen + assetName;
var serializeSessionKeyReq = function (obj) {
if (typeof obj.nonce === 'undefined' || typeof obj.replyNonce === 'undefined' ||
typeof obj.sender === 'undefined' || typeof obj.purpose === 'undefined' ||
typeof obj.numKeysPerRequest === 'undefined') {
console.log('Error: SessionKeyReq nonce or replyNonce ' +
'or purpose or numKeysPerRequest is missing.');
return;
}
var buf = new buffer.Buffer(AUTH_NONCE_SIZE * 2 + 4);
obj.nonce.copy(buf, 0);
obj.replyNonce.copy(buf, AUTH_NONCE_SIZE);
buf.writeUInt32BE(obj.numKeysPerRequest, AUTH_NONCE_SIZE * 2);
var senderBuf = serializeStringParam(obj.sender);
var purposeBuf = serializeStringParam(JSON.stringify(obj.purpose));
return buffer.concat([buf, senderBuf, purposeBuf]);
};
var serializeSessionMessage = function (obj) {
if (typeof obj.seqNum === 'undefined' || typeof obj.data === 'undefined') {
console.log('Error: Secure session message seqNum or data is missing.');
return;
}
var seqNumBuf = new buffer.Buffer(SEQ_NUM_SIZE);
seqNumBuf.writeUIntBE(obj.seqNum, 0, SEQ_NUM_SIZE);
return buffer.concat([seqNumBuf, obj.data]);
};
var parseSessionMessage = function (buf) {
function numToVarLenInt(num) {
var extraBuf;
var buf = new buffer.Buffer(0);
while (num > 127) {
extraBuf = new buffer.Buffer(1);
extraBuf.writeUInt8(128 | num & 127);
buf = buffer.concat([buf, extraBuf]);
num >>= 7;
}
extraBuf = new buffer.Buffer(1);
extraBuf.writeUInt8(num);
buf = buffer.concat([buf, extraBuf]);
return buf;
}
var serializeSessionKeyReqWithDistributionKey = function (senderName,
encryptedSessionKeyReqBuf) {
var senderBuf = new buffer.Buffer(senderName);
var lengthBuf = new buffer.Buffer(1);
lengthBuf.writeUInt8(senderBuf.length);
return buffer.concat([lengthBuf, senderBuf, encryptedSessionKeyReqBuf]);
};
function serializeStringParam(stringParam) {
var result;
if (stringParam === null) {
result = numToVarLenInt(0);
} else {
var strLenBuf = numToVarLenInt(stringParam.length);
var strBuf = new buffer.Buffer(stringParam);
result = buffer.concat([strLenBuf, strBuf]);
}
return result;
}