Giter Site home page Giter Site logo

merkletree's Introduction

Merkle Tree Dart

Updated copy of https://github.com/ethereumdart/merkletree that was itself originally Ported from https://github.com/miguelmota/merkletreejs

Construct a Merkle Tree.

All nodes and leaves are stored as Uint8List. Lonely leaf nodes are promoted to the next level up without being hashed again.

leaves is a list of hashed leaves. Each leaf must be a Uint8List. hashAlgo is a HashAlgo function used for hashing leaves and nodes defined. isBitcoinTree decides whether to construct the MerkleTree using the Bitcoin Merkle Tree implementation. Enable it when you need to replicate Bitcoin constructed Merkle Trees. In Bitcoin Merkle Trees, single nodes are combined with themselves, and each output hash is hashed again.

import 'dart:typed_data';

import 'package:merkletree/hypi_merkletree.dart';
import 'package:pointycastle/pointycastle.dart';

  Uint8List sha256(Uint8List data) {
    var sha256 = Digest('SHA-256');
    return sha256.process(data);
  }
  
  Uint8List sha3(Uint8List data) {
    var sha3 = Digest('SHA-3/256');
    return sha3.process(data);
  }

  var leaves = ['a', 'b', 'c'].map((x) => Uint8List.fromList(x.codeUnits)).map((x) => sha3(x)).toList();
  var tree = MerkleTree(leaves: leaves, hashAlgo: sha256);

merkletree's People

Contributors

konstantinullrich avatar touhonoob avatar zcourts avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.