How to use the bytebuffer.fromBinary 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 Someguy123 / understeem / shared / chain / memo.js View on Github external
assert.equal(typeof memo, 'string', 'memo')
    if(!/^#/.test(memo)) return memo
    memo = memo.substring(1)

    assert(private_key, 'private_key is required')

    memo = base58.decode(memo)
    memo = encMemo.fromBuffer(new Buffer(memo, 'binary'))

    const {from, to, nonce, check, encrypted} = memo
    const pubkey = private_key.toPublicKey().toString()
    const otherpub = pubkey === from.toString() ? to.toString() : from.toString()
    memo = Aes.decrypt(private_key, otherpub, nonce, encrypted, check)

    // remove varint length prefix
    const mbuf = ByteBuffer.fromBinary(memo.toString('binary'), ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)
    try {
        mbuf.mark()
        return mbuf.readVString()
    } catch(e) {
        mbuf.reset()
        // Sender did not length-prefix the memo
        memo = new Buffer(mbuf.toString('binary'), 'binary').toString('utf-8')
        return memo
    }
}
github steemit / steem-js / src / auth / memo.js View on Github external
assert(private_key, 'private_key is required')
    checkEncryption()

    private_key = toPrivateObj(private_key)

    memo = base58.decode(memo)
    memo = encMemo.fromBuffer(new Buffer(memo, 'binary'))

    const {from, to, nonce, check, encrypted} = memo
    const pubkey = private_key.toPublicKey().toString()
    const otherpub = pubkey === from.toString() ? to.toString() : from.toString()
    memo = Aes.decrypt(private_key, otherpub, nonce, encrypted, check)

    // remove varint length prefix
    const mbuf = ByteBuffer.fromBinary(memo.toString('binary'), ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)
    try {
        mbuf.mark()
        return '#' + mbuf.readVString()
    } catch(e) {
        mbuf.reset()
        // Sender did not length-prefix the memo
        memo = new Buffer(mbuf.toString('binary'), 'binary').toString('utf-8')
        return '#' + memo
    }
}
github steemit / steem-js / src / auth / ecc / src / aes.js View on Github external
//     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'),
    // })

    const iv = encryption_key.slice(32, 48)
    const key = encryption_key.slice(0, 32)

    // check is first 64 bit of sha256 hash treated as uint64_t truncated to 32 bits.
    let check = hash.sha256(encryption_key)
    check = check.slice(0, 4)
    const cbuf = ByteBuffer.fromBinary(check.toString('binary'), ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)
    check = cbuf.readUint32()

    if (checksum) {
        if (check !== checksum)
            throw new Error('Invalid key')
        message = cryptoJsDecrypt(message, key, iv)
    } else {
        message = cryptoJsEncrypt(message, key, iv)
    }
    return {nonce, message, checksum: check}
}
github EOSIO / eosjs-ecc / src / aes.js View on Github external
//     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'),
    // })

    const iv = encryption_key.slice(32, 48)
    const key = encryption_key.slice(0, 32)

    // check is first 64 bit of sha256 hash treated as uint64_t truncated to 32 bits.
    let check = hash.sha256(encryption_key)
    check = check.slice(0, 4)
    const cbuf = ByteBuffer.fromBinary(check.toString('binary'), ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)
    check = cbuf.readUint32()

    if (checksum) {
        if (check !== checksum)
            throw new Error('Invalid key')
        message = cryptoJsDecrypt(message, key, iv)
    } else {
        message = cryptoJsEncrypt(message, key, iv)
    }
    return {nonce, message, checksum: check}
}
github peerplays-network / peerplays-core-gui / lib / serializer / src / convert.ts View on Github external
fromBuffer(buffer) {
      let b = ByteBuffer.fromBinary(buffer.toString(), ByteBuffer.LITTLE_ENDIAN);
      return type.fromByteBuffer(b);
    },
github bitshares / bitshares-ui / plasma / libraries / @graphene / serializer / src / serializer.js View on Github external
fromBuffer(buffer){
        var b = ByteBuffer.fromBinary(buffer.toString("binary"), ByteBuffer.LITTLE_ENDIAN);
        return this.fromByteBuffer(b);
    }
github steemit / steem-js / src / auth / serializer / src / convert.js View on Github external
fromBuffer(buffer){
        var b = ByteBuffer.fromBinary(buffer.toString(), ByteBuffer.LITTLE_ENDIAN);
        return type.fromByteBuffer(b);
    },
github peerplays-network / peerplays-core-gui / lib / serializer / src / convert.ts View on Github external
fromBinary(string) {
      let b = ByteBuffer.fromBinary(string, ByteBuffer.LITTLE_ENDIAN);
      return type.fromByteBuffer(b);
    },
github bitshares / bitsharesjs / lib / serializer / src / convert.js View on Github external
fromBinary(string) {
            var b = ByteBuffer.fromBinary(string, ByteBuffer.LITTLE_ENDIAN);
            return type.fromByteBuffer(b);
        },
github bitshares / bitshares-ui / plasma / libraries / @graphene / wallet-client / src / ConfidentialWallet.js View on Github external
let bufferToNumber = (buf, type = "Uint32") => 
    ByteBuffer.fromBinary(buf.toString("binary"), ByteBuffer.LITTLE_ENDIAN)["read" + type]()