Package: @btc-vision/rust-merkle-tree
This project aims to develop a high-performance, secure Merkle tree library in Rust, with seamless integration for both Rust and Node.js applications. The library leverages SHA-256 as its cryptographic hash function and is designed to be secure against known vulnerabilities, ensuring robust state proof validations. Optimized for both performance and security, this library is intended for use in applications that require strong data integrity and validation mechanisms.
This library has been professionally audited by Verichains, a leading blockchain security firm. The audit confirms that the codebase is secure and ready for production use.
For audit reports and details, see the AUDIT directory.
- SHA-256 Hashing: Utilizes the SHA-256 hashing algorithm to ensure cryptographic security.
- Cross-Platform: Designed for both Rust and Node.js environments, providing bindings for easy integration.
- Secure Against Exploits: Implements protections against known vulnerabilities like hash collisions and tree manipulation.
- Optimized Performance: Significantly improved speed and efficiency compared to existing Merkle tree
implementations like
merkle-tree-sha256. - Comprehensive Testing: Includes a suite of tests to ensure the library performs securely and accurately.
- Node.js: Version 24/25+ or higher is required.
- Rust: You must have Rust installed to compile and develop this project.
-
Clone the repository:
git clone git://github.com/btc-vision/rust-merkle-tree.git cd rust-merkle-tree -
Install dependencies:
npm install
-
Build the project:
For production build:
npm run build
For debug build:
npm run build:debug
-
Run tests:
npm test
For Node.js integration, the library provides bindings via N-API.
-
Install the package:
npm install @btc-vision/rust-merkle-tree
-
Example of creating a Merkle tree:
import { MerkleTree } from '@btc-vision/rust-merkle-tree'; const leaves: Uint8Array[] = [ Uint8Array.from([100, 97, 116, 97, 49]), Uint8Array.from([100, 97, 116, 97, 50]), Uint8Array.from([100, 97, 116, 97, 51]), ]; const tree = new MerkleTree(leaves); console.log('Merkle Root:', tree.root());
npm run build: Compiles the Rust code into a release binary.npm run build:debug: Compiles the Rust code with debug information.npm test: Runs the test suite.npm run coverage: Generates Rust code coverage report.
- Current Rust Merkle Tree Implementation: rs-merkle
- SHA-256 Merkle Tree for Node.js: merkle-tree-sha256
- N-API for Rust Integration: napi.rs
Contributions are welcome! If you encounter any issues or have suggestions for improvement, feel free to open an issue or submit a pull request. Signed commits are required, and please adhere to the project's code of conduct.
This project is licensed under the MIT License. For more details, please see the LICENSE file.
For more information, visit the OP_NET homepage or reach out via the repository's GitHub page.