Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
bits = '0'.repeat(bitlen - bits.length) + bits
bitstr += bits
}
const value = Long.fromString(bitstr, true, 2)
// convert to LITTLE_ENDIAN
let leHex = ''
const bytes = littleEndian ? value.toBytesLE() : value.toBytesBE()
for(const b of bytes) {
const n = Number(b).toString(16)
leHex += (n.length === 1 ? '0' : '') + n
}
const ulName = Long.fromString(leHex, true, 16).toString()
// console.log('encodeName', name, value.toString(), ulName.toString(), JSON.stringify(bitstr.split(/(.....)/).slice(1)))
return ulName.toString()
}
if(name.length > 12)
throw new TypeError('A name can be up to 12 characters long')
let bitstr = ''
for(let i = 0; i <= 12; i++) { // process all 64 bits (even if name is short)
const c = i < name.length ? charidx(name[i]) : 0
const bitlen = i < 12 ? 5 : 4
let bits = Number(c).toString(2)
if(bits.length > bitlen) {
throw new TypeError('Invalid name ' + name)
}
bits = '0'.repeat(bitlen - bits.length) + bits
bitstr += bits
}
const value = Long.fromString(bitstr, true, 2)
// convert to LITTLE_ENDIAN
let leHex = ''
const bytes = littleEndian ? value.toBytesLE() : value.toBytesBE()
for(const b of bytes) {
const n = Number(b).toString(16)
leHex += (n.length === 1 ? '0' : '') + n
}
const ulName = Long.fromString(leHex, true, 16).toString()
// console.log('encodeName', name, value.toString(), ulName.toString(), JSON.stringify(bitstr.split(/(.....)/).slice(1)))
return ulName.toString()
}
function decodeName(value, littleEndian = true) {
value = ULong(value)
// convert from LITTLE_ENDIAN
let beHex = ''
const bytes = littleEndian ? value.toBytesLE() : value.toBytesBE()
for(const b of bytes) {
const n = Number(b).toString(16)
beHex += (n.length === 1 ? '0' : '') + n
}
beHex += '0'.repeat(16 - beHex.length)
const fiveBits = Long.fromNumber(0x1f, true)
const fourBits = Long.fromNumber(0x0f, true)
const beValue = Long.fromString(beHex, true, 16)
let str = ''
let tmp = beValue
for(let i = 0; i <= 12; i++) {
const c = charmap[tmp.and(i === 0 ? fourBits : fiveBits)]
str = c + str
tmp = tmp.shiftRight(i === 0 ? 4 : 5)
}
str = str.replace(/\.+$/, '') // remove trailing dots (all of them)
// console.log('decodeName', str, beValue.toString(), value.toString(), JSON.stringify(beValue.toString(2).split(/(.....)/).slice(1)))
return str
function decodeName(value, littleEndian = true) {
value = ULong(value)
// convert from LITTLE_ENDIAN
let beHex = ''
const bytes = littleEndian ? value.toBytesLE() : value.toBytesBE()
for(const b of bytes) {
const n = Number(b).toString(16)
beHex += (n.length === 1 ? '0' : '') + n
}
beHex += '0'.repeat(16 - beHex.length)
const fiveBits = Long.fromNumber(0x1f, true)
const fourBits = Long.fromNumber(0x0f, true)
const beValue = Long.fromString(beHex, true, 16)
let str = ''
let tmp = beValue
for(let i = 0; i <= 12; i++) {
const c = charmap[tmp.and(i === 0 ? fourBits : fiveBits)]
str = c + str
tmp = tmp.shiftRight(i === 0 ? 4 : 5)
}
str = str.replace(/\.+$/, '') // remove trailing dots (all of them)
// console.log('decodeName', str, beValue.toString(), value.toString(), JSON.stringify(beValue.toString(2).split(/(.....)/).slice(1)))
return str
}
SteamUser.prototype._handlerManager.add(SteamUser.EMsg.ClientFromGC, function(body) {
let msgType = body.msgtype & ~PROTO_MASK;
let targetJobID;
let payload;
if (body.msgtype & PROTO_MASK) {
// This is a protobuf message
let headerLength = body.payload.readInt32LE(4);
let protoHeader = Messages.decodeProto(Schema.CMsgProtoBufHeader, body.payload.slice(8, 8 + headerLength));
targetJobID = protoHeader.job_id_target || JOBID_NONE;
payload = body.payload.slice(8 + headerLength);
} else {
let header = ByteBuffer.wrap(body.payload.slice(0, 18));
targetJobID = header.readUint64(2);
payload = body.payload.slice(18);
}
this.emit('debug', `Received ${body.appid} GC message ${msgType}`);
if (targetJobID && this._jobsGC[targetJobID]) {
this._jobsGC[targetJobID].call(this, body.appid, msgType, payload);
} else {
this.emit('receivedFromGC', body.appid, msgType, payload);
this.emit('recievedFromGC', body.appid, msgType, payload);
}
});
export function encode(private_key, public_key, memo, testNonce) {
assert(memo, 'memo is required')
assert.equal(typeof memo, 'string', 'memo')
if(!/^#/.test(memo)) return memo
memo = memo.substring(1)
assert(private_key, 'private_key is required')
assert(public_key, 'public_key is required')
checkEncryption()
private_key = toPrivateObj(private_key)
public_key = toPublicObj(public_key)
const mbuf = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)
mbuf.writeVString(memo)
memo = new Buffer(mbuf.copy(0, mbuf.offset).toBinary(), 'binary')
const {nonce, message, checksum} = Aes.encrypt(private_key, public_key, memo, testNonce)
memo = encMemo.fromObject({
from: private_key.toPublicKey(),
to: public_key,
nonce,
check: checksum,
encrypted: message
})
// serialize
memo = encMemo.toBuffer(memo)
return '#' + base58.encode(new Buffer(memo, 'binary'))
}
export function encode(private_key, public_key, memo, testNonce) {
assert(memo, 'memo is required')
assert.equal(typeof memo, 'string', 'memo')
if(!/^#/.test(memo)) return memo
memo = memo.substring(1)
assert(private_key, 'private_key is required')
assert(public_key, 'public_key is required')
const mbuf = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)
mbuf.writeVString(memo)
memo = new Buffer(mbuf.copy(0, mbuf.offset).toBinary(), 'binary')
const {nonce, message, checksum} = Aes.encrypt(private_key, public_key, memo, testNonce)
memo = encMemo.fromObject({
from: private_key.toPublicKey(),
to: public_key,
nonce,
check: checksum,
encrypted: message
})
// serialize
memo = encMemo.toBuffer(memo)
return '#' + base58.encode(new Buffer(memo, 'binary'))
}
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.get_shared_secret(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.toPublicKey().toString(),
// pub: public_key.toString(),
// nonce: nonce.toString(),
// message: message.length,
// checksum,
// S: S.toString('hex'),
// encryption_key: encryption_key.toString('hex'),
// })
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);
}
};
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'),
// })