npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bigint-pedersen

v1.0.1

Published

This library provides an implementation of Pedersen Commitments, a cryptographic technique widely used for creating non-interactive commitments with strong security properties like homomorphic addition, subtraction, and multiplication.

Downloads

131

Readme

Pedersen Commitment Library

This library provides an implementation of Pedersen Commitments, a cryptographic technique widely used for creating non-interactive commitments with strong security properties like homomorphic addition, subtraction, and multiplication.

Features

  • Miller-Rabin Primality Test: Ensures prime numbers are correctly identified.
  • Pedersen Parameters Generation: Generates valid Pedersen parameters including prime, generator, and secondary generator.
  • Homomorphic Properties: Supports operations like addition, subtraction, and multiplication of commitments.
  • Secure Randomness: Utilizes Node.js crypto module to generate secure random values for blinding.

Installation

To use this library, you need to have Node.js installed. Run the following command to install the package:

npm install bigint-pedersen

Usage

Here is a simple example to demonstrate how to create a Pedersen Commitment and use its homomorphic sum property:

Creating a Commitment

import pedersen from 'bigint-pedersen';

// Generate Pedersen parameters
const parans = await pedersen.generator(2048); // 2048-bit safety

// Create a commitment for a message
const message1 = 42n;
const randomness1 = pedersen.randomBlinding();
const commitment1 = pedersen.commitment(message1, randomness1, parans);

console.log(`Commitment1: ${commitment1}`);

Homomorphic Sum of Commitments

Here is how you can sum two commitments homomorphically:

// Create a second commitment
const message2 = 58n;
const randomness2 = pedersen.randomBlinding();
const commitment2 = pedersen.commitment(message2, randomness2, parans);

console.log(`Commitment2: ${commitment2}`);

// Sum the commitments
const commitmentSum = pedersen.sum(commitment1, commitment2, parans);

console.log(`Sum of Commitments: ${commitmentSum}`);

In this example, the result commitmentSum is a valid commitment of the sum of the original messages (message1 + message2), demonstrating the library's homomorphic properties.

API Reference

Functions

  • isPrimeMillerRabin(n: bigint, k?: number): boolean
    Performs the Miller-Rabin primality test on n.

  • generator(bits: number): Promise<PedersenParameters>
    Generates Pedersen parameters including a prime p and generators g and h.

  • commitment(m: bigint, r: bigint, parans: PedersenParameters): bigint
    Computes a Pedersen commitment for the message m and randomness r.

  • sum(C1: bigint, C2: bigint, parans: PedersenParameters): bigint
    Computes the sum of two commitments C1 and C2.

  • sub(C1: bigint, C2: bigint, parans: PedersenParameters): bigint
    Computes the difference between two commitments C1 and C2.

  • multiply(C: bigint, scalar: bigint, parans: PedersenParameters): bigint
    Multiplies a commitment C by a scalar value.

Tests

To run the tests for this project, use the following command:

npm run test

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

  • Utilizes the Node.js crypto module for random value generation.
  • Implementation inspired by cryptographic primitives common in privacy-preserving protocols.