You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@chainsafe/hashtree

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chainsafe/hashtree

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

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
2.7K
0.44%
Maintainers
0
Weekly downloads
 
Created
Source

@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

Keywords

hash

FAQs

Package last updated on 26 Jun 2024

Did you know?

Socket

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.

Install

Related posts