@chainsafe/hashtree
Simple NAPI wrapper around https://github.com/prysmaticlabs/hashtree
Last updated 2 years ago by wemeetagain .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @chainsafe/hashtree 
SYNC missed versions from official npm registry.

@chainsafe/hashtree

Simple NAPI wrapper around https://github.com/prysmaticlabs/hashtree

Example

import {hash, hashInto} from "@chainsafe/hashtree"

// input is a Uint8Array of concatenated left-right tuples
const input: Uint8Array = Buffer.concat([
  Buffer.alloc(32), Buffer.alloc(32),
  Buffer.alloc(32, 1), Buffer.alloc(32, 1),
])

// output will be a Uint8Array of concatenated output hashes
const output = hash(input)

// for example, when compared to node:crypto usage:
import {createHash} from "node:crypto"

Buffer.compare(
  createHash("sha256").update(input.slice(0, 64)).digest(),
  output.slice(0, 32)
) === 0
Buffer.compare(
  createHash("sha256").update(input.slice(64)).digest(),
  output.slice(32)
) === 0

// alternative interface with preallocated output
const output2 = new Uint8Array(input.length / 2)
hashInto(input, output2)

License

MIT

Current Tags

  • 1.0.2                                ...           latest (8 months ago)

3 Versions

  • 1.0.2                                ...           8 months ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (15)

Copyright 2013 - present © cnpmjs.org | Home |