
Isomorphic SEPC256K1 JS

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.
Parameter | Type | Description |
---|
private_key | Uint8Array | secp256k1 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)
The logged output was [2, …, 207].
function recover_public_key
Recovers a public key from a digital signature on the secp256k1 Koblitz curve.
Parameter | Type | Description |
---|
Arg | object | Argument. |
Arg.signature | Uin8Array | secp256k1 signature. |
Arg.data | Uin8Array | Data 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.
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
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 }