How to use the rlp.encode function in rlp

To help you get started, we’ve selected a few rlp 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 rocket-pool / rocketpool / test / rocket-node / rocket-node-validator / rocket-node-validator-scenarios.js View on Github external
export async function scenarioNodeVoteCast({nodeAddress, minipoolAddress, gas, signingAddress = nodeAddress, emptyVoteMessage = false, gotoEpochSecondQuarter = true, expectCanVote}){
    const casper = await CasperInstance();
    const rocketNodeValidator = await RocketNodeValidator.deployed();

    // Get the current validator index and vote    
    let currentEpoch = parseInt(await casper.methods.current_epoch().call({from: nodeAddress}));
    let validatorIndex = parseInt(await casper.methods.validator_indexes(minipoolAddress).call({from: nodeAddress}));
    let targetHash = Buffer.from(removeTrailing0x(await casper.methods.recommended_target_hash().call({from: nodeAddress})), 'hex');
    let sourceEpoch = parseInt(await casper.methods.recommended_source_epoch().call({from: nodeAddress}));
    
    // RLP encode the required vote message
    let sigHash = $web3.utils.keccak256(abi.encodePacked(RLP.encode([validatorIndex,targetHash,currentEpoch,sourceEpoch])));
    // Sign it
    let signature = signRaw(sigHash, getGanachePrivateKey(signingAddress));
    // Combine and pad to 32 int length (same as casper python code)
    let combinedSig = Buffer.from(paddy(signature.v, 64) + paddy(signature.r, 64) +  paddy(signature.s, 64), 'hex');
    // RLP encode the message params now
    let voteMessage = !emptyVoteMessage ? RLP.encode([validatorIndex, targetHash, currentEpoch, sourceEpoch, combinedSig]) : '';

    // Proceed to second quarter of epoch to allow voting
    if (gotoEpochSecondQuarter) {
        let blockNumber = parseInt(await $web3.eth.getBlockNumber());
        let epochLength = parseInt(await casper.methods.EPOCH_LENGTH().call({from: nodeAddress}));
        let epochBlockNumber = blockNumber % epochLength;
        let epochFirstQuarter = Math.floor(epochLength / 4);
        let blockAmount = (epochFirstQuarter - epochBlockNumber) + 1;
        if (blockAmount > 0) await mineBlockAmount(blockAmount);
    }
github clearmatics / ion / test / clique.js View on Github external
block.stateRoot,
          block.transactionsRoot,
          block.receiptsRoot,
          block.logsBloom,
          Web3Utils.toBN(block.difficulty),
          Web3Utils.toBN(block.number),
          block.gasLimit,
          block.gasUsed,
          Web3Utils.toBN(block.timestamp),
          newExtraData, // Off-chain signed block
          block.mixHash,
          block.nonce
        ];

        // Encode the offchain signed header
        const offchainSignedHeader = '0x' + rlp.encode(newSignedHeader).toString('hex');
        const offchainHeaderHash = Web3Utils.sha3(offchainSignedHeader);

        await clique.SubmitBlock(TESTCHAINID, unsignedHeader, offchainSignedHeader, storage.address).should.be.rejected;

      })
github xf00f / web3x / web3x-evm / src / blockchain / blockchain.ts View on Github external
evaluatedTxs.map(async ({ txHash, sender, serializedTx, serializedReceipt }, i) => {
        await receiptTrie.put(sha3Buffer(i.toString()), serializedReceipt);
        await txTrie.put(sha3Buffer(i.toString()), serializedTx);

        // Add lookup for transactions. txHash => [blockHash, txIndex, from].
        await this.db.put(txHash, rlp.encode([blockHash, Buffer.from(i.toString()), sender.toBuffer()]));
      }),
    );
github zmitton / eth-proof / lib / ethVerify.js View on Github external
EV.trieValue = (path, value, parentNodes, root) => {
  try{
    var currentNode;
    var len = parentNodes.length;
    var rlpTxFromPrf = parentNodes[len - 1][parentNodes[len - 1].length - 1];
    var nodeKey = root;
    var pathPtr = 0;

    path = path.toString('hex')

    for (var i = 0 ; i < len ; i++) {
      currentNode = parentNodes[i];
      if(!nodeKey.equals( new Buffer(sha3(rlp.encode(currentNode)),'hex'))){
        console.log("nodeKey != sha3(rlp.encode(currentNode)): ", nodeKey, new Buffer(sha3(rlp.encode(currentNode)),'hex'))
        return false;
      }
      if(pathPtr > path.length){
        console.log("pathPtr >= path.length ", pathPtr,  path.length)
        return false
      }

      switch(currentNode.length){
        case 17://branch node
          if(pathPtr == path.length){
            if(currentNode[16] == rlp.encode(value)){
              return true;
            }else{
              console.log('currentNode[16],rlp.encode(value): ', currentNode[16], rlp.encode(value))
              return false
github SoraSuegami / Vreath / core / merkle_patricia.ts View on Github external
const en_key = (key:string):string=>{
  return rlp.encode(key);
}
github opporty-com / Plasma-Cash / plasma-core / child-chain / transaction.js View on Github external
return this[fieldName]
    }
    let dataToEncode = [
      this.prevHash instanceof Buffer ?
        this.prevHash :
        ethUtil.addHexPrefix(this.prevHash),
      this.prevBlock,
      ethUtil.toBuffer(this.tokenId),
      this.newOwner,
      this.type,
    ]
    if (!(excludeSignature)) {
      dataToEncode.push(this.signature)
    }

    this[fieldName] = RLP.encode(dataToEncode)
    return this[fieldName]
  }
github opporty-com / Plasma-Cash / plasma-core / cli / transaction.js View on Github external
return this[fieldName]
    }
    let dataToEncode = [
      this.prevHash instanceof Buffer ?
        this.prevHash :
        ethUtil.addHexPrefix(this.prevHash),
      this.prevBlock,
      ethUtil.toBuffer(this.tokenId),
      this.newOwner,
      this.type,
    ]
    if (!(excludeSignature)) {
      dataToEncode.push(this.signature)
    }

    this[fieldName] = RLP.encode(dataToEncode)
    return this[fieldName]
  }
github CodeChain-io / codechain-sdk-js / src / core / transaction / UnwrapCCC.ts View on Github external
public rlpBytes(): Buffer {
        return RLP.encode(this.toEncodeObject());
    }
github airgap-it / airgap-coin-lib / lib / protocols / AEProtocol.ts View on Github external
const recipient = bs58check.decode(recipients[0].replace('ak_', ''))

    const txObj = {
      tag: this.toHexBuffer(12),
      version: this.toHexBuffer(1),
      sender_id: Buffer.concat([this.toHexBuffer(1), Buffer.from(sender, 'hex')]),
      recipient_id: Buffer.concat([this.toHexBuffer(1), recipient]),
      amount: this.toHexBuffer(values[0]),
      fee: this.toHexBuffer(fee),
      ttl: this.toHexBuffer(10000),
      nonce: this.toHexBuffer(nonce),
      payload: Buffer.from('')
    }

    const txArray = Object.keys(txObj).map(a => txObj[a])
    const rlpEncodedTx = rlp.encode(txArray)
    const preparedTx = 'tx_' + bs58check.encode(rlpEncodedTx)

    return {
      transaction: preparedTx,
      networkId: this.defaultNetworkId
    }
  }
github KyberNetwork / smart-contracts / web3deployment / liquidityReserveDeployer.js View on Github external
async function deployContract(solcOutput, contractName, ctorArgs) {

  const actualName = contractName;
  const bytecode = solcOutput.contracts[actualName].bytecode;

  const abi = solcOutput.contracts[actualName].interface;
  const myContract = new web3.eth.Contract(JSON.parse(abi));
  const deploy = myContract.deploy({data:"0x" + bytecode, arguments: ctorArgs});
  let address = "0x" + web3.utils.sha3(RLP.encode([sender,nonce])).slice(12).substring(14);
  address = web3.utils.toChecksumAddress(address);

  await sendTx(deploy);

  myContract.options.address = address;


  return [address,myContract];
}

rlp

Recursive Length Prefix Encoding Module

MPL-2.0
Latest version published 3 years ago

Package Health Score

77 / 100
Full package analysis

Popular rlp functions