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

isomorphic-secp256k1-js

v3.0.0

Published

An ultra lightweight (2 kbyte) pure JavaScript implimentation for the secp256k1 curve for node and browsers.

Downloads

26

Readme

secp256k1 logo

Isomorphic SEPC256K1 JS

NPM Package CI status License: MIT

An ultra lightweight (1.6kb minify + gzip) Universal JavaScript Elliptic Curve Digital Signature Algorithm (ECDSA) for the Koblitz secp256k1 curve.

Cross platform support for Node.js and Deno.

Exports

The npm package isomorphic-secp256k1-js features optimal JavaScript module design. It doesn’t have a main index module, so use deep imports from the ECMAScript modules that are exported via the package.json field exports:

Impact on your bundle

Using the esbuild minify and gzip you can generate a digital signature with less than 1.6kb impact to your bundle.

cat dist/sign.mjs | wc
  1      86    2898

cat dist/sign.mjs.zip | wc
  10      59    1604
cat dist/get_public_key.mjs | wc
  1      27    1389

cat dist/get_public_key.mjs.zip | wc
  3      29    1006
cat dist/recover_public_key.mjs | wc
  1      50    2055

cat dist/recover_public_key.mjs.zip | wc
  4      38    1360

Installation

For Node.js, to install isomorphic-secp256k1-js run:

npm i isomorphic-secp256k1-js

For Deno.js, at the root of your project add a deno.json file and include these import paths:

{
  "imports": {
    "universal-sha256-js/": "https://deno.land/x/sha256js/",
    "universal-hmac-sha256-js/": "https://deno.land/x/hmacsha256/",
    "universal-hmac-sha256-js/hmac-sha256-node.mjs": "https://deno.land/x/hmacsha256/hmac-sha256-deno.mjs"
  }
}

Then import:

import recover_public_key from "https://deno.land/x/secp256k1js/recover_public_key.mjs";
import sign from "https://deno.land/x/secp256k1js/sign.mjs";
import get_public_key from "https://deno.land/x/secp256k1js/get_public_key.mjs";

Examples

Recover public key from private key.

const private_key = new Uint8Array([
  210, 101, 63, 247, 203, 178, 216, 255, 18, 154, 194, 126, 245, 120, 28, 230,
  139, 37, 88, 196, 26, 116, 175, 31, 45, 220, 166, 53, 203, 238, 240, 125,
]);

// Compressed public key.
console.log(get_public_key(private_key));

Generate a secp25k1 digital signature.

const private_key = new Uint8Array([
  210, 101, 63, 247, 203, 178, 216, 255, 18, 154, 194, 126, 245, 120, 28, 230,
  139, 37, 88, 196, 26, 116, 175, 31, 45, 220, 166, 53, 203, 238, 240, 125,
]);

const data = Uint8Array.from([
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
]);
sign({ data, private_key }).then(console.log);

The logged output is { r: [23, …, 89], s: [111, …, 142], v: 1 }

Note

As this package is ESM if you need to require it in a Common JS package, then you can require like this:

(async function () {
  const { default: recover_public_key } = await import(
    "isomorphic-secp256k1-js/recover_public_key.mjs"
  );
  const { number_to_array } = await import("./private/utils.mjs");

  const key_pair = await recover_public_key({
    data,
    signature: {
      r: number_to_array(
        50172533143525448505731076092836454339589141171079665638497512992118311974590n
      ),
      s: number_to_array(
        3372897403575535231543296615264124933490702058654620386530787287980439847001n
      ),
      v: 0,
    },
  });
  console.log(key_pair);
})();

Logged output was Uint8Array(33) [2,192,222,210,188,31,19,5,…

Requirements

Supported runtime environments: