How to use the rlp.decode 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 clearmatics / ion / test / ibft.js View on Github external
it('Fail Submit Block with Insufficient Seals', async () => {
        await ibft.RegisterChain(TESTCHAINID, VALIDATORS_BEFORE, GENESIS_HASH, storage.address);

        let badExtraData = "0xf90164f854944335d75841d8b85187cf651ed130774143927c799461d7d88dbc76259fcf1f26bc0b5763aebd67aead94955425273ef777d6430d910f9a8b10adbe95fff694f00d3c728929e42000c8d92d1a7e6a666f12e6edb8410c11022a97fcb2248a2d757a845b4804755702125f8b7ec6c06503ae0277ad996dc22f81431e8036b6cf9ef7d3c1ff1b65a255c9cb70dd2f4925951503a6fdbf01f8c9b8412d3849c86c8ba3ed9a79cdd71b1684364c4c4efb1f01e83ca8cf663f3c95f7ac64b711cd297527d42fb3111b8f78d5227182f38ccc442be5ac4dcb52efede89a01b84135de3661d0191247c7f835c8eb6d7939052c0da8ae234baf8bd208c00225e706112df9bad5bf773120ba4bbc55f6d18e478de43712c0cd3de7a3e2bfd65abb7c01b841735f482a051e6ad7fb76a815907e68d903b73eff4e472006e56fdeca8155cb575f4c1d3e98cf3a4b013331c1bd171d0d500243ac0e073a5fd382294c4fe996f000";

        // Remove seal from extradata
        const decodedExtraData = rlp.decode(badExtraData);
        decodedExtraData[2].pop()

        // Reapply the rlp encoded istanbul extra minus single seal
        encodedExtraData = rlp.encode(decodedExtraData).toString('hex');
        block.extraData = "0xdc83010000886175746f6e69747988676f312e31302e34856c696e7578000000" + encodedExtraData;
        rlpHeader = encoder.encodeIbftHeader(block);

        // Submit block should not succeed
        await ibft.SubmitBlock(TESTCHAINID, rlpHeader.unsigned, rlpHeader.signed, rlpHeader.seal, storage.address).should.be.rejected;
        
      })
github clearmatics / ion / test / integration-clique_ethereum.js View on Github external
function generateMalformedProof() {
    decodedPath = rlp.decode(Buffer.from(TEST_PATH.slice(2), 'hex'));
    decodedTx = rlp.decode(Buffer.from(TEST_TX_VALUE.slice(2), 'hex'));
    decodedTxNodes = rlp.decode(Buffer.from(TEST_TX_NODES.slice(2), 'hex'));
    decodedReceipt = rlp.decode(Buffer.from(TEST_RECEIPT_VALUE.slice(2), 'hex'));
    // Exclude receipt nodes
//    decodedReceiptNodes = rlp.decode(Buffer.from(TEST_RECEIPT_NODES.slice(2), 'hex'));

    proof = rlp.encode([decodedPath, decodedTx, decodedTxNodes, decodedReceipt]);
    return proof;
}
github ethereumclassic / explorer / routes / filters.js View on Github external
var hex2ascii = function (hexIn) {
  var hex = hexIn.toString();
  var str = '';

  try {
    var ba = RLP.decode(hex);
    var test = ba[1].toString('ascii');

    if (test == 'geth' || test == 'Parity') {
      // FIXME
      ba[0] = ba[0].toString('hex');
    }
    str = baToString(ba);
  } catch(e) {
    for (var i = 0; i < hex.length; i += 2)
        str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
  }
  return str;
}
github clearmatics / ion / test / storage-ethereum.js View on Github external
function generateTestReceiptRLPNodes() {
    let root = Buffer.from("f871a012d378fe6800bc18f22e715a31971ef7e73ac5d1d85384f4b66ac32036ae43dea004d6e2678656a957ac776dbef512a04d266c1af3e2c5587fd233261a3d423213808080808080a05fac317a4d6d78181319fbc7e2cae4a9260f1a6afb5c6fea066e2308eed416818080808080808080", 'hex');
    second = Buffer.from("f90151a03da235c6dd0fbdaf208c60cbdca0d609dee2ba107495aa7adaa658362616c8aaa09ebf378a9064aa4da0512c55c790a5e007ac79d2713e4533771cd2c95be47a4da0c06fed36ffe1f2ec164ba88f73b353960448d2decbb65355c5298a33555de742a0e057afe423ee17e5499c570a56880b0f5b5c1884b90ff9b9b5baa827f72fc816a093e06093cd2fdb67e0f87cfcc35ded2f445cc1309a0ff178e59f932aeadb6d73a0193e4e939fbc5d34a570bea3fff7c6d54adcb1c3ab7ef07510e7bd5fcef2d4b3a0a17a0c71c0118092367220f65b67f2ba2eb9068ff5270baeabe8184a01a37f14a03479a38e63123d497588ad5c31d781276ec8c11352dd3895c8add34f9a2b786ba042254728bb9ab94b58adeb75d2238da6f30382969c00c65e55d4cc4aa474c0a6a03c088484aa1c73b8fb291354f80e9557ab75a01c65d046c2471d19bd7f2543d880808080808080", 'hex');
    leaf = Buffer.from("f9016b20b90167f901640183252867b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000010000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000f85af8589461621bcf02914668f8404c1f860e92fc1893f74ce1a027a9902e06885f7c187501d61990eae923b37634a8d6dda55a04dc7078395340a0000000000000000000000000279884e133f9346f2fad9cc158222068221b613e", 'hex');

    decodedRoot = rlp.decode(root);
    decodedSecond = rlp.decode(second);
    decodedLeaf = rlp.decode(leaf);

    nodes = rlp.encode([decodedRoot, decodedSecond, decodedLeaf]);
    return nodes;
}
github clearmatics / ion / test / integration-clique_ethereum.js View on Github external
function generateProof() {
    decodedPath = rlp.decode(Buffer.from(TEST_PATH.slice(2), 'hex'));
    decodedTx = rlp.decode(Buffer.from(TEST_TX_VALUE.slice(2), 'hex'));
    decodedTxNodes = rlp.decode(Buffer.from(TEST_TX_NODES.slice(2), 'hex'));
    decodedReceipt = rlp.decode(Buffer.from(TEST_RECEIPT_VALUE.slice(2), 'hex'));
    decodedReceiptNodes = rlp.decode(Buffer.from(TEST_RECEIPT_NODES.slice(2), 'hex'));

    proof = rlp.encode([decodedPath, decodedTx, decodedTxNodes, decodedReceipt, decodedReceiptNodes]);
    return proof;
}
github clearmatics / ion / test / integration-clique_ethereum.js View on Github external
function generateProof() {
    decodedPath = rlp.decode(Buffer.from(TEST_PATH.slice(2), 'hex'));
    decodedTx = rlp.decode(Buffer.from(TEST_TX_VALUE.slice(2), 'hex'));
    decodedTxNodes = rlp.decode(Buffer.from(TEST_TX_NODES.slice(2), 'hex'));
    decodedReceipt = rlp.decode(Buffer.from(TEST_RECEIPT_VALUE.slice(2), 'hex'));
    decodedReceiptNodes = rlp.decode(Buffer.from(TEST_RECEIPT_NODES.slice(2), 'hex'));

    proof = rlp.encode([decodedPath, decodedTx, decodedTxNodes, decodedReceipt, decodedReceiptNodes]);
    return proof;
}
github clearmatics / ion / test / integration-clique_ethereum.js View on Github external
function generateProof() {
    decodedPath = rlp.decode(Buffer.from(TEST_PATH.slice(2), 'hex'));
    decodedTx = rlp.decode(Buffer.from(TEST_TX_VALUE.slice(2), 'hex'));
    decodedTxNodes = rlp.decode(Buffer.from(TEST_TX_NODES.slice(2), 'hex'));
    decodedReceipt = rlp.decode(Buffer.from(TEST_RECEIPT_VALUE.slice(2), 'hex'));
    decodedReceiptNodes = rlp.decode(Buffer.from(TEST_RECEIPT_NODES.slice(2), 'hex'));

    proof = rlp.encode([decodedPath, decodedTx, decodedTxNodes, decodedReceipt, decodedReceiptNodes]);
    return proof;
}
github SoraSuegami / Vreath / core / merkle_patricia.ts View on Github external
const de_value = (value:any)=>{
  return JSON.parse(rlp.decode(value));
}
github airgap-it / airgap-coin-lib / lib / serializer / serializer.ts View on Github external
public async deserialize(serializedSyncProtocol: string): Promise {
    const base58Decoded = bs58check.decode(serializedSyncProtocol)
    const rlpDecodedTx: SerializedSyncProtocol = (rlp.decode(base58Decoded as any) as {}) as SerializedSyncProtocol

    const version = parseInt(rlpDecodedTx[SyncProtocolKeys.VERSION].toString(), 10)

    if (version !== SERIALIZER_VERSION) {
      throw new SerializerVersionMismatch()
    }

    const type = parseInt(rlpDecodedTx[SyncProtocolKeys.TYPE].toString(), 10)
    const protocol = rlpDecodedTx[SyncProtocolKeys.PROTOCOL].toString()
    const payload = rlpDecodedTx[SyncProtocolKeys.PAYLOAD]

    let typedPayload

    switch (type) {
      case EncodedType.UNSIGNED_TRANSACTION:
        typedPayload = unsignedTransactionSerializerByProtocolIdentifier(protocol).deserialize(payload as SerializedSyncProtocolTransaction)
github opporty-com / Plasma-Cash / plasma-core / cli / transaction.js View on Github external
function initFields(self, fields, data) {
  if (data instanceof Buffer) {
    let decodedData = RLP.decode(data)
    fields.forEach((field, i) => {
      if (field.int) {
        if (decodedData[i].length) {
          self[field.name] = decodedData[i].readUIntBE()
        } else {
          self[field.name] = 0
        }
      } else {
        self[field.name] = decodedData[i]
      }
    })
  } else if (Array.isArray(data) && data.length) {
    fields.forEach((field, i) => {
      self[field.name] = data[i]
    })
  } else if (data && typeof data === 'object') {

rlp

Recursive Length Prefix Encoding Module

MPL-2.0
Latest version published 3 years ago

Package Health Score

82 / 100
Full package analysis

Popular rlp functions