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

@webbuf/secp256k1

v3.0.26

Published

Rust/wasm optimized secp256k1 ecdsa and Diffie-Hellman for the web, node.js, deno, and bun.

Downloads

886

Readme

@earthbucks/secp256k1

@earthbucks/secp256k1 is a TypeScript/Node.js library with WebAssembly (WASM) support, providing ECDSA and Diffie-Hellman functionality for the secp256k1 elliptic curve, commonly used in Bitcoin, Ethereum, and EarthBucks. The library allows you to perform key operations, message signing/verification, and Diffie-Hellman key exchanges using a pre-built WebAssembly module.


Features

  • ECDSA Operations: Sign and verify messages using the secp256k1 elliptic curve.
  • Diffie-Hellman Key Exchange: Compute shared secrets with elliptic curve Diffie-Hellman.
  • Key Handling: Verify, create, and add private and public keys.
  • WASM Support: High performance via WebAssembly, easily usable in Node.js and the browser.
  • Blockchain Compatibility: Works with Bitcoin, Ethereum, and EarthBucks-style keys and signatures.

Installation

To install the package in your Node.js or TypeScript project:

npm install earthbucks-secp256k1

Usage

TypeScript/Node.js Example

import { private_key_verify, public_key_create, public_key_verify, shared_secret, ecdsa_sign, ecdsa_verify } from 'earthbucks-secp256k1';

// Private key as Uint8Array
const privKey = new Uint8Array(32).fill(1); // Example private key
const message = new Uint8Array(32).fill(2); // Example message (digest)

// Verify the private key
console.log(private_key_verify(privKey)); // true

// Create a public key from the private key
const pubKey = public_key_create(privKey);
console.log('Public Key:', new Uint8Array(pubKey));

// Verify the public key
console.log(public_key_verify(pubKey)); // true

// Sign a message with the private key
const signature = ecdsa_sign(message, privKey);
console.log('Signature:', new Uint8Array(signature));

// Verify the signature with the public key and message
console.log(ecdsa_verify(signature, message, pubKey)); // true

// Perform Diffie-Hellman key exchange with another public key
const otherPubKey = public_key_create(new Uint8Array(32).fill(2)); // Another example public key
const sharedSecret = shared_secret(privKey, otherPubKey);
console.log('Shared Secret:', new Uint8Array(sharedSecret));

API Documentation

  • private_key_verify(priv_key_buf: Uint8Array): boolean
    Verifies whether a 32-byte private key is valid.

  • public_key_verify(pub_key_buf: Uint8Array): boolean
    Verifies a 33-byte compressed public key in SEC1 format.

  • public_key_create(priv_key_buf: Uint8Array): Uint8Array
    Generates a public key from a 32-byte private key and returns it in compressed SEC1 format.

  • private_key_add(priv_key_buf_1: Uint8Array, priv_key_buf_2: Uint8Array): Uint8Array
    Adds two private keys together and returns the resulting private key.

  • public_key_add(pub_key_buf_1: Uint8Array, pub_key_buf_2: Uint8Array): Uint8Array
    Adds two public keys together (both in compressed SEC1 format) and returns the result.

  • ecdsa_sign(digest: Uint8Array, priv_key_buf: Uint8Array): Uint8Array
    Signs a 32-byte message digest with a private key and returns the 64-byte signature.

  • ecdsa_verify(sig_buf: Uint8Array, digest: Uint8Array, pub_key_buf: Uint8Array): boolean
    Verifies the provided signature, digest, and public key.

  • shared_secret(priv_key_buf: Uint8Array, pub_key_buf: Uint8Array): Uint8Array
    Performs elliptic curve Diffie-Hellman (ECDH) to compute a shared secret between a private key and a public key.


Running Tests

To ensure the library works as expected, run the tests:

npm test

License

This project is licensed under the MIT License. See the LICENSE file for more information.


Contributing

Contributions are welcome! Please open an issue or submit a pull request.


This updated README includes instructions for using the WASM functions re-exported in TypeScript, along with the updated API and usage examples for Node.js projects. Let me know if you need further adjustments!