How to use the ethereumjs-util.bufferToHex function in ethereumjs-util

To help you get started, we’ve selected a few ethereumjs-util 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 / PlasmaContract / test / transactionSerialization.js View on Github external
it('should give proper information about the TX input', async () => {
        const tx = createTransaction(TxTypeSplit, 0, 
            [{
                blockNumber: 1,
                txNumberInBlock: 200,
                outputNumberInTransaction: 0,
                amount: 10
            }],
            [{
                amount: 10,
                to: alice
            }],
                aliceKey
        )
        const reencodedTX = tx.serialize();
        const info = await txTester.getInputInfo(ethUtil.bufferToHex(reencodedTX), 0);
        const blockNumber = info[0].toNumber();
        const txNumberInBlock = info[1].toNumber();
        const outputNumber = info[2].toNumber();
        const amount = info[3].toString(10);
        assert(blockNumber === 1);
        // assert(txNumberInBlock === 200);
        assert(outputNumber === 0);
        assert(amount === ""+10);
    });
github softwaremill / blockchain-schedule / src / cryptoutils.tsx View on Github external
export function signAddress(privKey, address) {
    const msg = new Buffer(address)
    const addressHash = eutil.hashPersonalMessage(Buffer.from(address)) // address+prefix, hashed
    const sig = eutil.ecsign(addressHash, Buffer.from(eutil.stripHexPrefix(privKey), 'hex'))

    return {
        h: eutil.bufferToHex(addressHash),
        r: eutil.bufferToHex(sig.r),
        s: eutil.bufferToHex(sig.s),
        v: sig.v
    }
}
github 0xProject / 0x-monorepo / packages / base-contract / src / utils / filter_utils.ts View on Github external
continue;
            }
            if (indexFilterValues[eventInput.name] === undefined) {
                // Null is a wildcard topic in a JSON-RPC call
                topics.push(null);
            } else {
                // tslint:disable: no-unnecessary-type-assertion
                let value = indexFilterValues[eventInput.name] as any;
                if (BigNumber.isBigNumber(value)) {
                    // tslint:disable-next-line custom-no-magic-numbers
                    value = ethUtil.fromSigned(value.toString(10) as any);
                }
                // tslint:enable: no-unnecessary-type-assertion
                const buffer = ethUtil.toBuffer(value);
                const paddedBuffer = ethUtil.setLengthLeft(buffer, TOPIC_LENGTH);
                const topic = ethUtil.bufferToHex(paddedBuffer);
                topics.push(topic);
            }
        }
        return topics;
    },
    matchesFilter(log: LogEntry, filter: FilterObject): boolean {
github spacesuit-extension / SpaceSuit / integration-test / tests.js View on Github external
return function validate(signed) {
    console.log(signed)
    let txBuf = toBuffer(signed.raw)
    let tx = new EthTx(txBuf)
    return norm(bufferToHex(tx.getSenderAddress())) === norm(account)
  }
}
github BANKEX / PlasmaParentContract / test / testInvalidBlockChallenges.js View on Github external
outputNumberInTransaction: 0,
                amount: 0
            }],
            [{
                amount: 10,
                to: alice
            }],
                operatorKey
        )
        let block = createBlock(1, 1, firstHash, [tx],  operatorKey)
        let blockArray = block.serialize();
        let blockHeader = Buffer.concat(blockArray).slice(0,137);
        let deserialization = ethUtil.rlp.decode(blockArray[7]);
        let lastBlockNumber = await plasma.lastBlockNumber()
        assert(lastBlockNumber.toString() == "0");
        let submissionReceipt = await plasma.submitBlockHeaders(ethUtil.bufferToHex(blockHeader));
        lastBlockNumber = await plasma.lastBlockNumber();
        assert(lastBlockNumber.toString() == "1");
        let allEvents = storage.allEvents({fromBlock: submissionReceipt.receipt.blockNumber, toBlock: submissionReceipt.receipt.blockNumber});
        let get = util.promisify(allEvents.get.bind(allEvents))
        let evs = await get()
        assert.web3Event({logs: evs}, {
            event: 'BlockHeaderSubmitted',
            args: {_blockNumber: 1,
                 _merkleRoot: ethUtil.bufferToHex(block.header.merkleRootHash)}
        }, 'The event is emitted');
        let bl = await storage.blocks(1);
        assert(bl[2] == ethUtil.bufferToHex(block.header.merkleRootHash));

        const newHash = await plasma.hashOfLastSubmittedBlock();
        tx = createTransaction(TxTypeSplit, 0, 
            [{
github ProjectOpenSea / opensea-js / src / utils.ts View on Github external
function _parseSignatureHexAsRSV(signatureHex: string) {
    const { v, r, s } = ethUtil.fromRpcSig(signatureHex)
    const ecSignature = {
        v,
        r: ethUtil.bufferToHex(r),
        s: ethUtil.bufferToHex(s),
    }
    return ecSignature
  }
}
github brave / ethereum-remote-client / app / scripts / eth-ledger-keyring-listener.js View on Github external
_normalize (buf) {
    return this._padLeftEven(ethUtil.bufferToHex(buf).toLowerCase())
  }
github leapdao / leap-node / src / utils / claimRewards.js View on Github external
function getPeriodRoot(consensus, cas, data, rest) {
  let buf = Buffer.alloc(64, 0);
  toBuffer(data).copy(buf);
  toBuffer(rest).copy(buf, 32);
  const dataBuf = keccak256(buf);

  buf = Buffer.alloc(64, 0);
  toBuffer(cas).copy(buf);
  dataBuf.copy(buf, 32);
  const casBuf = keccak256(buf);

  buf = Buffer.alloc(64, 0);
  toBuffer(consensus).copy(buf);
  casBuf.copy(buf, 32);
  return bufferToHex(keccak256(buf));
}
github joincivil / Civil / packages / utils / src / crypto.ts View on Github external
export function hashPersonalMessage(message: string): { rawMessage: string; messageHash: Hex } {
  const rawMessage = SIGN_PREFFIX + message.length.toString() + message;
  return {
    rawMessage,
    messageHash: bufferToHex(sha3(rawMessage)),
  };
}