New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lite-merkle-patricia-tree

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lite-merkle-patricia-tree

  • 1.0.1-rc.1
  • v1.0.1-rc.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
61
increased by10.91%
Maintainers
2
Weekly downloads
 
Created
Source

lite-merkle-patricia-tree

lite-merkle-patricia-tree Version

A simplified and synchronous implementation of the Ethereum modified Merkle Patricia Tree from ethereumjs-monorepo.

This browser friendly implementation is for one-time use cases of data verification.

For example: put serialized BlockReceipts in the Trie and build an inclusion proof with findPath, and that's it, data is not persisted.

It replaces the database and async logic with a simple Map to temporarily store trie nodes.

Installation

yarn add lite-merkle-patricia-tree
"dependencies": {
  "lite-merkle-patricia-tree": "^1.0.0",
}

Usage

import { Trie } from 'lite-merkle-patricia-tree'
import { Proof } from 'eth-object'

const block = await web3.eth.getBlock()
const blockReceipts = await Promise.all(
  block.transactions.map(t => web3.eth.getTransactionReceipt(t))
)

// Build the receipts Trie
const trie = new Trie()
blockReceipts.forEach(receipt => {
  const path = rlp.encode(receipt.transactionIndex)
  const serializedReceipt = Receipt.fromWeb3(receipt).serialize()
  trie.put(path, serializedReceipt)
})
if (trie.root.toString('hex') !== block.receiptsRoot.slice(2)) {
  throw new Error('Failed to build receipts trie root.')
}

// Prove a receipt inclusion inside the Trie
const stack = trie.findPath(rlp.encode(transactionIndex)).stack.map(
  node => { return { raw: node.raw() } }
)
const receiptProof = Proof.fromStack(stack),

FAQs

Package last updated on 08 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc