How to use the bytebuffer.DEFAULT_CAPACITY 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 steemit / steem-js / src / auth / memo.js View on Github external
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'))
}
github EOSIO / eosjs / src / structs.js View on Github external
'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')
    }
  },
github peerplays-network / peerplays-core-gui / lib / serializer / src / convert.ts View on Github external
function toByteBuffer(type, object) {
  let b = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
  type.appendByteBuffer(b, object);
  return b.copy(0, b.offset);
}
github steemit / steem-js / src / auth / serializer / src / convert.js View on Github external
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);
};
github dcatanzaro / argentumonlineweb-servidor / package.js View on Github external
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);
    };
github bitshares / bitshares-ui / plasma / libraries / @graphene / serializer / src / serializer.js View on Github external
toByteBuffer(object) {
        var b = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
        this.appendByteBuffer(b, object);
        return b.copy(0, b.offset);
    }