pedersen-fast
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

ts-essentials

pedersen-fast

Blazing Fast Pedersen hash implementation for Node.JS

Exposes starknet-crypto's implementation written in Rust as WASM package.

Usage

npm i pedersen-fast

Package exposes two functions, one for calculations from HEX strings, the other from decimal strings:

import { pedersen_from_hex, pedersen_from_dec } from "pedersen-fast";

// returns a hex string starting with 0x
pedersen_from_hex(
  "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcde",
  "0x11223344556677889900aabbccddeeff11223344556677889900aabbccddeef",
);

Current state

According to our benchmarks, the fastest implementation would be the native module (via NEON). The problem with native modules is a need to compile them on the client or precompile them before. None of these solutions is trivial, that's why we use WASM for now.

napi-rs seems to be great at simplifying shipping native modules for nodejs. but its performance is much worse than neons. This needs further research.

Benchmarks

For 10 000 hash calculations from hex strings:

Implementation Time Hash/s
Starknet JS 23,493 ms 425.659 hash/s
starknet_crypto (WASM) 241 ms 41,493.776 hash/s
starknet_crypto (native module) 90 ms 111,111.111 hash/s

Acknowledgments

Thanks goes to:

  • starknet-rs team for the fastest implementation our there :)

Development

To compile every package and run benchmarks do:

./scripts/benchmark.sh

License

MIT

Package Sidebar

Install

npm i pedersen-fast

Weekly Downloads

27

Version

0.4.0

License

MIT

Unpacked Size

247 kB

Total Files

6

Last publish

Collaborators

  • krzkaczor