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

isomorphic-secp256k1-js

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isomorphic-secp256k1-js

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

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

secp256k1 logo

Isomorphic SEPC256K1 JS

NPM Package CI status License: MIT

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

Setup

npm i isomorphic-secp256k1-js

Suport

  • Node.js >=15
  • Browser defaults, no IE 11

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 'isomorphic-secp256k1-js'

Ways to require.

const { get_public_key } = require('isomorphic-secp256k1-js')

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 recover_public_key

Recovers a public key from a digital signature on the secp256k1 Koblitz curve.

ParameterTypeDescription
ArgobjectArgument.
Arg.signatureUin8Arraysecp256k1 signature.
Arg.dataUin8ArrayData that was signed to produce the signature.

Returns: Uint8Array — recovered Public key.

Examples

Ways to import.

import { recover_public_key } from 'isomorphic-secp256k1-js'

Ways to require.

const { recover_public_key } = require('isomorphic-secp256k1-js')

Usage sign.

const data = Uint8Array.from([
  2, 33, 65, 233, 23, 23, 123, 244, 23, 23, 123, 244
])

const signature = {
  r: number_to_array(
    50172533143525448505731076092836454339589141171079665638497512992118311974590n
  ),
  s: number_to_array(
    3372897403575535231543296615264124933490702058654620386530787287980439847001n
  ),
  v: 0
}

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 [2, 192, 222, 210, …]


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 and v values.

Examples

Ways to import.

import { sign } from 'isomorphic-secp256k1-js'

Ways to require.

const { sign } = require('isomorphic-secp256k1-js')

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], v: 1 }

Keywords

FAQs

Package last updated on 27 Oct 2022

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