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

nilajs-digital-signature

v1.0.0

Published

A simple library for generating elliptic curve (secp256k1) key pairs, digital signature, signing data, verifying signatures, and validating public keys.

Downloads

3

Readme

nilajs-digital-signature

A digital signature is a cryptographic mechanism used to verify the authenticity and integrity of digital messages or documents. It provides assurances that the message was indeed created by a particular entity (authentication) and that the message has not been altered or tampered with since it was signed (integrity).

A simple library for generating elliptic curve (secp256k1) key pairs, signing data, verifying signatures, and validating public keys.

Installation

You can install the package via npm:

npm install nilajs-digital-signature

Usage

Import the Library

const {
  generateWallet,
  checkPublicKeyValid,
  signData,
  verifySignature
} = require('nilajs-digital-signature');

Generate Wallet

Generate a new wallet (elliptic curve (secp256k1) key pair) :

const { publicKey, privateKey } = generateWallet();
console.log(`Public Key: ${publicKey}`);
console.log(`Private Key: ${privateKey}`);

Validate Public Key

Check if a given public key is valid:

const publicKey = 'YOUR_PUBLIC_KEY';
const result = checkPublicKeyValid(publicKey);
console.log(result); // { valid: true/false, public_key: 'YOUR_PUBLIC_KEY' }

Sign Data

Sign a piece of data with a private key:

const privateKey = 'YOUR_PRIVATE_KEY';
const data = 'This is the data to be signed';
const signatureObject = signData(privateKey, data);
console.log(signatureObject);
/*
{
  data: 'This is the data to be signed',
  signature: {
    r: 'SIGNATURE_R',
    s: 'SIGNATURE_S'
  }
}
*/

Verify Signature

Verify the signature of the data with a public key:

const publicKey = 'YOUR_PUBLIC_KEY';
const data = 'This is the data to be signed';
const signature = {
  r: 'SIGNATURE_R',
  s: 'SIGNATURE_S'
};
const verificationResult = verifySignature(publicKey, data, signature);
console.log(verificationResult);
/*
{
  data: 'This is the data to be signed',
  signature: {
    r: 'SIGNATURE_R',
    s: 'SIGNATURE_S'
  },
  is_verified: true/false
}
*/

API Reference

generateWallet()

Generates a new elliptic curve (secp256k1) key pair.

Returns:

  • Object: An object containing the publicKey and privateKey as hexadecimal strings.

checkPublicKeyValid(publicKey)

Checks if a given public key is valid.

Parameters:

  • publicKey (string): The public key to validate.

Returns:

  • Object: An object containing:
    • valid (boolean): Whether the public key is valid.
    • public_key (string): The provided public key.

signData(privateKey, data)

Signs a piece of data with a private key.

Parameters:

  • privateKey (string): The private key to sign with.
  • data (string): The data to sign.

Returns:

  • Object: An object containing the signed data and signature (with r and s as hexadecimal strings).

verifySignature(publicKey, data, signature)

Verifies the signature of the data with a public key.

Parameters:

  • publicKey (string): The public key to verify with.
  • data (string): The signed data.
  • signature (Object): The signature object containing r and s as hexadecimal strings.

Returns:

  • Object: An object containing:
    • data (string): The signed data.
    • signature (Object): The signature object.
    • is_verified (boolean): Whether the signature is valid.

License

MIT