
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
@fairdatasociety/bmt-js
Advanced tools
This JavaScript library does Binary Merkle Tree (BMT) operations on data.
The library calculates the content address of any data and also offers functions for performing cheap compact inclusion proof of any 32 bytes segments in it.
npm install @fairdatasociety/bmt-js --save
First, it splits the data into chunks
that have maximum 4KB payload by default, but this condition can modified as well as its span
byte length (8 bytes) that indicates how long byte payload subsumed under the chunk.
If the payload byte length cannot fit exactly to this chunk division, the rightmost chunk's data will be padded with zeros in order to have fixed length data for the BMT operations.
This basic unit is also required to effectively distribute data on decentralized storage systems with regard to plausible deniability, garbage collection, load balancing and else. For more details, please visit Etherem Swarm webpage that has full implementation of this logic.
The used hashing algorithm is the keccak256
function that results in a 32 bytes long segment
.
Performing BMT hashing on the chunk data will define the BMT root hash
of the chunk.
Then, for integrity considerations, the BMT root hash is hashed with the chunk's span from the left which takes the Chunk address
.
In order to refer files also with a single 32 byte segment, the chunk addresses of the payload have to be hashed in the same way until the File address
:
chunks can encapsulate 128 chunk addresses on the subsequent BMT tree level by default. These kind of chunks are called Intermediate chunks
By the properties of a BMT tree, the chunks will end in a Root chunk
that refers all chunks below (directly or indirectly) and its address will be the File address
as well.
One can realize, the BMT levels can have an orphan chunk on the rightmost-side that cannot be hashed with a neighbour chunk, because it does not have a neighbour chunk (e.g. 129/129 chunk).
When it occurs, it does not have a sense to hash this orphan chunk on every BMT level since it will be BMT hashed with zero data.
That's why the the algorithm handles orphan chunk as Carrier chunk
and tries to place it into that BMT tree level where the chunk address can be encapsulated with other addresses.
This BMT hashing of data allows to reference any file with unified 32 bytes unique address which is called content addressing.
Nevertheless, it also allows to perform lightweight compact inclusion proof on data. This proof requires little amount of data to be provided for proving whether any particular segment (32 bytes) of the data is present at a particular offset under the file address.
This feature allows to create a logic around data referenced by 32 bytes file addresses where the data segment values have to meet some conditions.
The first/best use-case for this can happen via smart contracts that implement the validation functions that check the provided inclusion proof segments
are indeed subsumed under the commited file references.
To get these inclusion segments, the library collects all required segments from the BMT tree that can be used for input of smart contract validation parameters.
You can import the followings directly from @fairdatasociety/bmt-js
:
maxPayloadLength
longChunk
helper object for performing BMT actions on file dataChunk
helper object for performing BMT actions on chunk dataSpan
byte array that indicates how much data subsumed under the Chunk/Filenumber
carrier by Span
In order to compile code run
npm run compile
You can find the resulted code under the dist
folder.
For types compilation, run
npm run compile:types
The testing needs running Bee client node for integration testing.
You can set BEE_POSTAGE
environment variable with a valid Postage batch or the test will create one for you.
The default value of the Bee Debug API endpoint is http://localhost:1635
.
If your address diverges from that, please, set BEE_DEBUG_API_URL
system environment variable with yours.
To run test execute
npm run test
FAQs
Binary Merkle Tree operations on data
The npm package @fairdatasociety/bmt-js receives a total of 0 weekly downloads. As such, @fairdatasociety/bmt-js popularity was classified as not popular.
We found that @fairdatasociety/bmt-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.