How to use the bytebuffer.LITTLE_ENDIAN function in bytebuffer

To help you get started, we’ve selected a few bytebuffer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eoscannon / eoscannon-online-tool / js / lib / structs.js View on Github external
result = _ref6.result,
          config = _ref6.config;

      var _ref7 = object || {},
          data = _ref7.data,
          name = _ref7.name;

      var ser = (name || '') == '' ? fields.data : structLookup(name, object.account);
      if (!ser) {
        // Types without an ABI will accept hex
        result.data = Buffer.isBuffer(data) ? data.toString('hex') : data;
        return;
      }

      if (forceActionDataHex) {
        var b2 = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
        if (data) {
          ser.appendByteBuffer(b2, data);
        }
        result.data = b2.copy(0, b2.offset).toString('hex');
        // console.log('result.data', result.data)
        return;
      }

      // Serializable JSON
      result.data = ser.toObject(data, config);
    }
  };
github EOSIO / eosjs-ecc / src / aes.js View on Github external
throw new TypeError('public_key is required')

    nonce = toLongObj(nonce)
    if (!nonce)
        throw new TypeError('nonce is required')

    if (!Buffer.isBuffer(message)) {
        if (typeof message !== 'string')
            throw new TypeError('message should be buffer or string')
        message = new Buffer(message, 'binary')
    }
    if (checksum && typeof checksum !== 'number')
        throw new TypeError('checksum should be a number')

    const S = private_key.getSharedSecret(public_key);
    let ebuf = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)
    ebuf.writeUint64(nonce)
    ebuf.append(S.toString('binary'), 'binary')
    ebuf = new Buffer(ebuf.copy(0, ebuf.offset).toBinary(), 'binary')
    const encryption_key = hash.sha512(ebuf)

    // D E B U G
    // console.log('crypt', {
    //     priv_to_pub: private_key.toPublic().toString(),
    //     pub: public_key.toString(),
    //     nonce: nonce.toString(),
    //     message: message.length,
    //     checksum,
    //     S: S.toString('hex'),
    //     encryption_key: encryption_key.toString('hex'),
    // })
github DoctorMcKay / node-steam-client / lib / cm_client.js View on Github external
var nonce = null;

	if (buffer.remaining() >= 16) {
		nonce = buffer.slice(buffer.offset, buffer.offset + 16).toBuffer();
		buffer.skip(16);
	}

	this.emit('debug', 'encrypt request: protocol ' + protocol + ', universe ' + universe + ', ' + (nonce ? 'nonce, ' : '') + (buffer.remaining()) + ' remaining bytes');

	var sessionKey = SteamCrypto.generateSessionKey(nonce);
	this._tempUseHmac = !!nonce;
	this._tempSessionKey = sessionKey.plain;
	var keyCrc = BufferCRC32.signed(sessionKey.encrypted);

	var encResp = new Schema.MsgChannelEncryptResponse().encode();
	var body = new ByteBuffer(encResp.limit + 128 + 4 + 4, ByteBuffer.LITTLE_ENDIAN); // key, crc, trailer

	body.append(encResp);
	body.append(sessionKey.encrypted);
	body.writeInt32(keyCrc);
	body.writeUint32(0); // TODO: check if the trailer is required
	body.flip();

	this.send({"msg": EMsg.ChannelEncryptResponse}, body.toBuffer());
};
github DoctorMcKay / node-steam-user / components / chat.js View on Github external
SteamUser.prototype.kickFromChat = function(chatID, userID) {
	userID = Helpers.steamID(userID);

	var msg = new ByteBuffer(20, ByteBuffer.LITTLE_ENDIAN);
	msg.writeUint64(toChatID(chatID).getSteamID64()); // steamIdChat
	msg.writeUint64(userID.getSteamID64()); // steamIdUserToActOn
	msg.writeUint32(SteamUser.EChatAction.Kick);
	this._send(SteamUser.EMsg.ClientChatAction, msg.flip());
};
github DoctorMcKay / node-tf2 / index.js View on Github external
TeamFortress2.prototype.deleteItem = function(item) {
	let buffer = new ByteBuffer(8, ByteBuffer.LITTLE_ENDIAN);
	buffer.writeUint64(coerceToLong(item));
	this._send(Language.Delete, null, buffer);
};
github DoctorMcKay / node-steam-user / components / content_manifest.js View on Github external
exports.parse = function(buffer) {
	if (!ByteBuffer.isByteBuffer(buffer)) {
		buffer = ByteBuffer.wrap(buffer, ByteBuffer.LITTLE_ENDIAN);
	}

	var manifest = {};
	var magic;
	var meta;
	var length;

	while (buffer.remaining() > 0) {
		magic = buffer.readUint32();
		switch (magic) {
			case PROTOBUF_PAYLOAD_MAGIC:
				length = buffer.readUint32();
				manifest.files = Protos.ContentManifestPayload.decode(buffer.slice(buffer.offset, buffer.offset + length)).mappings;
				buffer.skip(length);
				break;
github seishun / node-steam / lib / steam_client.js View on Github external
SteamClient.prototype._netMsgReceived = function(data) {
  var rawEMsg = data.readUInt32LE(0);
  var eMsg = rawEMsg & ~protoMask;
  
  data = ByteBuffer.wrap(data, ByteBuffer.LITTLE_ENDIAN);
  
  var header, sourceJobID, targetJobID;
  if (eMsg == EMsg.ChannelEncryptRequest || eMsg == EMsg.ChannelEncryptResult) {
    header = schema.MsgHdr.decode(data);
    sourceJobID = header.sourceJobID;
    targetJobID = header.targetJobID;
  
  } else if (rawEMsg & protoMask) {
    header = schema.MsgHdrProtoBuf.decode(data);
    header.proto = Steam._processProto(header.proto);
    if (!this.sessionID && header.headerLength > 0) {
      this.sessionID = header.proto.client_sessionid;
      this.steamID = header.proto.steamid;
    }
    sourceJobID = header.proto.jobid_source;
    targetJobID = header.proto.jobid_target;