New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

universal-ecdsa

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

universal-ecdsa

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

  • 1.1.4
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
14
increased by40%
Maintainers
1
Weekly downloads
 
Created
Source

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.

ParameterTypeDescription
private_keyUint8Arraysecp256k1 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.

ParameterTypeDescription
dataUint8ArrayBinary 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.

ParameterTypeDescription
ArgobjectArgument.
Arg.private_keyUin8Arraysecp256k1 private key.
Arg.dataUin8ArrayData 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] }

Keywords

FAQs

Package last updated on 17 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc