Catalog npm
Back to packageRELEASE DETAILS

0.0.0-alpha0

npm

@0xcert/merkle-tree

Merkle tree management tool.

Published29 Sept 2018
Direct dependencies5
Transitive dependenciesNot calculated

README

Current package documentation

Define Convention

Asset convention is defined as a list of data items.

IndexTypeDescription
0StringFirst name of a user.
1StringMiddle name of a user.
2StringLast name of a user.
3StringEmail address of a user.
4IntegerAge of a user.

This can be converted into a merkle tree where leafs represent the values and the root represents the proof.

                    [0,0]             
                    99999               MerkleNode
            [1,0]               [1,1]
            88888               55555   MerkleNode
    [2,0]           [2,1]       [2,2]
    66666           77777       55555   MerkleNode
[3,0]   [3,1]   [3,2]   [3,3]   [3,4]
11111   22222   33333   44444   55555   MerkleNode
-----   -----   -----   -----   —----
  a       b       c       d       e     MerkleValue

Usage

Create an instance of a merkle tree.

import { sha256 } from '@0xcert/crypto'; 
import { Merkle } from '@0xcert/merkle-tree'; 

const merkle = new Merkle({
  algo: sha256, 
});

Build merkle tree nodes from a list of values.

const allNodes = merkle.build([
  { index: 0, value: 'a' },
  { index: 1, value: 'b' },
  { index: 2, value: 'c' },
  { index: 3, value: 'd' },
  { index: 4, value: 'e' },
]);

Create a minimal list of nodes from which a tree root can be calculated.

const recipeNodes = await merkle.pack(
  allNodes, 
  [0, 2] // expose values `a` and `c`
);

Recalculate the tree root hash object.

const rootNode = await merkle.calculate([
  // values
  { index: 0, value: 'a' },
], [
  // nodes
  { level: 0, index: 0, hash: '0x...' },
  { level: 1, index: 0, hash: '0x...' },
  { level: 1, index: 1, hash: '0x...' },
  { level: 2, index: 0, hash: '0x...' },
]);

License (MIT)

Copyright (c) 2017+ Kristijan Sedlak <xpepermint@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated modelation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 5

Native requirements
5 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@0xcert/crypto
Environment
{
  "local_name": "@0xcert/crypto",
  "alias": false,
  "peer_metadata": null
}
0.0.0-alpha0development
@hayspec/cli
Environment
{
  "local_name": "@hayspec/cli",
  "alias": false,
  "peer_metadata": null
}
^0.4.21development
@hayspec/spec
Environment
{
  "local_name": "@hayspec/spec",
  "alias": false,
  "peer_metadata": null
}
^0.4.21development
ts-node
Environment
{
  "local_name": "ts-node",
  "alias": false,
  "peer_metadata": null
}
^7.0.1development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^3.1.1development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-Ce0j78rBVfrY1nHJpTBxxXI/MtWqDRcC3ZbhBd8ZEkgQdbAxR2GxLLp2fIDuhCtkfMNd7sIq+KJZu7K42dPgaA==",
  "shasum": "840827492b85e85dcacb3de52c59bbf0a1612102",
  "tarball": "https://registry.npmjs.org/@0xcert/merkle-tree/-/merkle-tree-0.0.0-alpha0.tgz",
  "fileCount": 11,
  "unpackedSize": 40682,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbrzjcCRA9TVsSAnZWagAAbmQP/i6mjlpsqUjlEA8WKvu+\nhhLerNxJmkQc+i4flN6YTiAtdsJfCbh1bc5AjI81eP2NAsWCaO7AV0suXf8U\nvHGRXpx09aI79pO6/KNbTW2uggTkVsXGnIn1eoJDL/8ih/61yTUOddCW7YMA\n9Ic5wFoH36aMUmVXJplcSIvfSPq798AmCPcwhL/4SG47JckhOD7l4isPr70P\nEG2whcI5BQvy6bJf3gzGHCf1tlV2j1LAz8SaeJp4HcpNEKggcjFu1mI2J0VZ\ntpgTUrXdNCS1AzB8v4hIxGTYT3ND/eq4wnTJDppp5l3xY50xTVrmYvqmdSqP\n2At9EnO0OBeQwrE6e51MBSwY0KlDtsDV6P9zEKyWT8QLgMhHQPnaAQINkZYa\nIGL0duXvSzxju15RcoRYo3C2/ou1Ax/sW3gaQqsICaBwAlg4IQklyyjth0uv\n3iFd8VZWru1+dLO+maBwyx8yXJAME5agcjk4DZx69AheEfRO6lbEWpEKwpnc\n1vlsIAYBmSUAfo7Qa1d81jytuy/zdNtcz8ZY11Z5jIIib+tR0s5MQpoTcDK4\n4EB8RcgdfEN0l2FPPDFVMfWShkUhHRz+QjMoBffIupFsgVcAq1POuVtgeU3n\n8gKQBqrFHKryAQ1pPpHoF2puC60F3Km0Jp9KITgNlIuYrOm0MzyqmNJXXsEh\ng8Ru\r\n=rE00\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIQCyaYL86NBDGjEXjB2nEINdt8n09Dx6uEQ+0ihl51XhIAIgc7VU1xkJDs1kdZlh6B/jUTllP/N7hT4+q3kPLYmCyKg="
    }
  ]
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:48 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:83d69af3e93367a0cdea2700c2b7caa37db69d15aa05f6ed22b8dffa6a990312

Other collected versions

View all collected versions →