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

universal-ecdsa

v1.1.4

Published

A universal JavaScript Elliptic Curve Digital Signature Algorithm (ECDSA) for the Koblitz secp256k1 curve.

Downloads

97

Readme

secp256k1 logo

Universal ECDSA

NPM Package CI status License: MIT

A Universal JavaScript Elliptic Curve Digital Signature Algorithm (ECDSA) for the Koblitz secp256k1 curve.

Info

The Web Assembly binary file esdsa.json that is consumed by the JavaScript environments is compiled from C/C++, see cpp/readme.md.

  • ~28 kB (minifeied + gzipped) to bundle

Setup

npm i universal-ecdsa

Suport

  • Node.js ^12.20.1 || >= 13.2
  • Browser defaults, no IE 11

You will need Node +15 web crypto for passing test.

API

function get_public_key

Generates a compressed public key for the secp256k1 curve.

| Parameter | Type | Description | | :------------ | :--------- | :--------------------------- | | private_key | Uint8Array | secp256k1 valid private key. |

Returns: Uint8Array — Public key.

Examples

Ways to import.

import { get_public_key } from 'universal-ecdsa'

Ways to require.

const { get_public_key } = require('universal-ecdsa')

Usage get_public_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
])

get_public_key(private_key).then(console.log) // compressed public key.

The logged output was [2, …, 207].


function sha256

Universal sha256 message digest helper function.

| Parameter | Type | Description | | :-------- | :--------- | :------------------- | | data | Uint8Array | Binary data to hash. |

Returns: Uint8Array — Message digest.

Examples

Ways to import.

import { sha256 } from 'universal-ecdsa'

Ways to require.

const { sha256 } = require('universal-ecdsa')

Usage sha256 in node.

const array = Uint8Array.from(
  Buffer.from('The quick brown fox jumped over the lazy dog')
)

sha256(array).then(console.log)

The logged output is [215, …, 146 ]


function sign

Generates a digital signature on the secp256k1 Koblitz curve.

| Parameter | Type | Description | | :---------------- | :-------- | :--------------------- | | Arg | object | Argument. | | Arg.private_key | Uin8Array | secp256k1 private key. | | Arg.data | Uin8Array | Data to sign. |

Returns: Signature — Digital signature object containing r and s values.

Examples

Ways to import.

import { sign } from 'universal-ecdsa'

Ways to require.

const { sign } = require('universal-ecdsa')

Usage sign.

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([104, 101, 108, 108, 111])
sign({ data, private_key }).then(console.log)

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