Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'))
}
'action.data.appendByteBuffer': ({fields, object, b}) => {
const ser = (object.name || '') == '' ? fields.data : structLookup(object.name, object.account)
if(ser) {
const b2 = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)
ser.appendByteBuffer(b2, object.data)
b.writeVarint32(b2.offset)
b.append(b2.copy(0, b2.offset), 'binary')
} else {
// console.log(`Unknown Action.name ${object.name}`)
const data = typeof object.data === 'string' ? Buffer.from(object.data, 'hex') : object.data
if(!Buffer.isBuffer(data)) {
throw new TypeError(`Unknown struct '${object.name}' for contract '${object.account}', locate this struct or provide serialized action.data`)
}
b.writeVarint32(data.length)
b.append(data.toString('binary'), 'binary')
}
},
function toByteBuffer(type, object) {
let b = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
type.appendByteBuffer(b, object);
return b.copy(0, b.offset);
}
var toByteBuffer=function(type, object){
var b = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
type.appendByteBuffer(b, object);
return b.copy(0, b.offset);
};
connectCharacter: 5,
position: 6,
dialog: 7,
ping: 8,
attackMele: 9,
attackRange: 10,
attackSpell: 11,
tirarItem: 12,
agarrarItem: 13,
buyItem: 14,
sellItem: 15,
changeSeguro: 17
};
this.bufferRcv = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, true);
this.bufferSnd = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, true);
this.setData = function(data) {
this.bufferRcv = new ByteBuffer.wrap(data, 'utf8', true);
};
this.getPackageID = function() {
var packageID = this.getByte();
return packageID;
};
this.setPackageID = function(packageID) {
this.bufferSnd = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, true);
this.writeByte(packageID);
};
toByteBuffer(object) {
var b = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
this.appendByteBuffer(b, object);
return b.copy(0, b.offset);
}