How to use the buffer/.Buffer function in buffer

To help you get started, we’ve selected a few buffer 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 matter-labs / FranklinPay-iOS / Plasma / transaction.js View on Github external
assert(fee.bitLength() <= 128);
    assert(nonce.bitLength() <= 32);
    assert(good_until_block.bitLength() <= 32);

    // const components = [];
    // components.push(packBnLe(from, 24));
    // components.push(packBnLe(to, 24));
    let amountFloatBytes = integerToFloat(amount, 5, 11, 10);
    // components.push(amountFloatBytes);
    let feeFloatBytes = integerToFloat(fee, 5, 3, 10);
    // components.push(feeFloatBytes);
    // components.push(packBnLe(nonce, 32));
    // components.push(packBnLe(good_until_block, 32));

    const components = [
        good_until_block.toArrayLike(Buffer, "be", 4),
        nonce.toArrayLike(Buffer, "be", 4),
        packBnLe(new BN(feeFloatBytes, 16, "be"), 8),
        packBnLe(new BN(amountFloatBytes, 16, "be"), 16),
        to.toArrayLike(Buffer, "be", 3),
        from.toArrayLike(Buffer, "be", 3)
    ];

    let serialized = Buffer.concat(components);

    let newAmount = floatToInteger(amountFloatBytes, 5, 11, 10);
    console.log("Reparsed amount = " + newAmount.toString(10));
    let newFee = floatToInteger(feeFloatBytes, 5, 3, 10);

    return {
        bytes: serialized,
        from: from,
github AschPlatform / asch-js / test / tests.js View on Github external
it("should have publicKey in 32 bytes", function () {
						var publicKey = new Buffer(sgn.asset.signature.publicKey, "hex");
						(publicKey.length).should.be.equal(32);
					});
				});
github Ebookcoin / ebookcoin-js / test / tests.js View on Github external
(trs.signSignature).should.be.type('string').and.match(function () {
						try {
							new Buffer(trs.signSignature, 'hex');
						} catch (e) {
							return false;
						}

						return true;
					});
				});
github LiskHQ / lisk-sdk / test / tests.js View on Github external
(sgn.asset.signature.publicKey).should.be.type("string").and.match(function () {
							try {
								new Buffer(sgn.asset.signature.publicKey);
							} catch (e) {
								return false;
							}

							return true;
						});
					});
github vacuumlabs / adalite / utils.js View on Github external
exports.hashBlake2b256 = function(input) {
  const context = blake2.blake2bInit(32)
  blake2.blake2bUpdate(context, new Buffer(cbor.encode(input), 'hex'))

  return new Buffer(blake2.blake2bFinal(context)).toString('hex')
}
github AraiEzzra / DDKCORE / public / js / controllers / modals / multisignatureModalController.js View on Github external
$scope.addMember = function (member) {
        $scope.addingError = '';
        var isAddress = /^[0-9]+[L|l]$/g;
        var correctAddress = isAddress.test(member);
        if ($scope.member.trim() == '') {
            $scope.addingError = 'Empty address';
        } else {
            var Buffer = require('buffer/').Buffer;
            var buffer =  []
            try {
                buffer = Buffer(member, "hex")}
            catch(err) {

            }
            if (buffer.length == 32) {
                var ETP = require('lisk-js');
                var address = ETP.crypto.getAddress($scope.member);
                if ($scope.members[$scope.address] || address == userService.address) {
                    return;
                }
                $scope.members[$scope.member] = {address: address, publicKey: $scope.member};
                $scope.totalCount = $scope.totalCount + 1;
                $scope.member = '';
            } else {
                if (correctAddress) {
                    $http.get("/api/accounts?address=" + member).then(function (response) {
                        if (response.data.success) {
github ArkEcosystem / core / packages / client / lib / builder / legacy-crypto.js View on Github external
for (let i = 0; i < 21; i++) {
        bb.writeByte(0)
      }
    }

    if (transaction.vendorFieldHex) {
      const vf = new Buffer(transaction.vendorFieldHex, 'hex')
      const fillstart = vf.length
      for (let i = 0; i < fillstart; i++) {
        bb.writeByte(vf[i])
      }
      for (let i = fillstart; i < 64; i++) {
        bb.writeByte(0)
      }
    } else if (transaction.vendorField) {
      const vf = new Buffer(transaction.vendorField)
      const fillstart = vf.length
      for (let i = 0; i < fillstart; i++) {
        bb.writeByte(vf[i])
      }
      for (let i = fillstart; i < 64; i++) {
        bb.writeByte(0)
      }
    } else {
      for (let i = 0; i < 64; i++) {
        bb.writeByte(0)
      }
    }

    bb.writeLong(transaction.amount)

    bb.writeLong(transaction.fee)
github treasure-data / digdag / digdag-ui / model.js View on Github external
getFileContents (name: string): ?Buffer {
    const file = this.fileMap.get(name)
    if (!file) {
      return null
    }
    return new Buffer(file.buffer)
  }
github ArkEcosystem / core / packages / client / lib / builder / legacy-crypto.js View on Github external
bb.writeByte(0)
      }
    }

    bb.writeLong(transaction.amount)

    bb.writeLong(transaction.fee)

    if (assetSize > 0) {
      for (let i = 0; i < assetSize; i++) {
        bb.writeByte(assetBytes[i])
      }
    }

    if (!skipSignature && transaction.signature) {
      const signatureBuffer = new Buffer(transaction.signature, 'hex')
      for (let i = 0; i < signatureBuffer.length; i++) {
        bb.writeByte(signatureBuffer[i])
      }
    }

    if (!skipSecondSignature && transaction.signSignature) {
      const signSignatureBuffer = new Buffer(transaction.signSignature, 'hex')
      for (let i = 0; i < signSignatureBuffer.length; i++) {
        bb.writeByte(signSignatureBuffer[i])
      }
    }

    bb.flip()
    const arrayBuffer = new Uint8Array(bb.toArrayBuffer())
    const buffer = []
github alexeisavca / webtorrentapp / lib / promised-request.js View on Github external
function toBuffer(ab) {
    var buffer = new Buffer(ab.byteLength);
    var view = new Uint8Array(ab);
    for (var i = 0; i < buffer.length; ++i) {
        buffer[i] = view[i];
    }
    return buffer;
}
module.exports = function(url){