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

@pascalcoin-sbx/crypto

v0.0.18-alpha.0

Published

Cryptographic functionalities for the PascalCoin BlockChain project.

Downloads

14

Readme

SBX Crypto library

A sub package of sbx

This library provides basic crypto functionalities used in PascalCoin.

Installation

npm install @sbx/crypto

SBX Dependencies

This library depends on the following SBX dependencies:

  • @pascalcoin-sbx/common

For all code examples in this documentation expect the import of the SBX libraries to be named: sbxPackage.

Example

const sbxCommon = require('@pascalcoin-sbx/common');
const sbxCrypto = require('@sbx/crypto');
// ...and so on

Other dependencies

External dependencies are:

  • mipher https://github.com/mpaland/mipher
  • elliptic https://github.com/indutny/elliptic

Usage

(@sbx/common).Keys

A class that provides static methods to handle key related functionalities.

PascalCoin provides 4 Key-Types (elliptic curve types):

  • secp256k1 (ID: 714)
  • secp384r1 (ID: 715)
  • secp283k1 (ID: 729)
  • secp521r1 (ID: 716)

All but secp283k1 are supported by this library. When using an unsopprted curve the library will throw an exception that you have to catch.

Generating a new keypair

The following code generates a new KeyPair based on the given curve.

const sbxCommon = require('@sbx/common');
const sbxCrypto = require('@sbx/crypto');

// a new curve instance can created by with the name or the id of the curve
const curve = new sbxCommon.Types.Keys.Curve(sbxCommon.Types.Keys.Curve.CI_SECP256K1());

// check if the curve is supported
if (curve.supported) {
  /** @var kp sbxCommon.Types.Keys.KeyPair */
  let kp = sbxCrypto.Keys.generate(curve);
  console.log(kp.privateKey.encode().toHex());
  console.log(kp.publicKey.encode().toHex());
}

Importing an encrypted private key

The library can decrypt an encrypted private key from the wallet and returns a KeyPair.

const sbxCrypto = require('@sbx/crypto');

/** @var kp sbxCommon.Types.Keys.KeyPair */
let kp = sbxCrypto.Keys.decrypt(
  '53616C7465645F5FED4A37ECAD2BF13FF24A66DDA299A57632520447B28B9E642C4B2A301CACC217FBD7713F6282C20CCCFDC5FFD2AB93A8E48D8C2C81704D36', 
  'test1234'
);
console.log(kp.privateKey.encode().toHex());
console.log(kp.publicKey.encode().toHex());

Exporting a private key

The library can encrypt a private key that can be imported into the wallet.

const sbxCrypto = require('@sbx/crypto');

/** @var kp sbxCommon.Types.Keys.KeyPair */
let kp = sbxCrypto.Keys.decrypt(
  '53616C7465645F5FED4A37ECAD2BF13FF24A66DDA299A57632520447B28B9E642C4B2A301CACC217FBD7713F6282C20CCCFDC5FFD2AB93A8E48D8C2C81704D36', 
  'test1234'
);

console.log(sbxCrypto.Keys.encrypt(kp.privateKey, 'my_password').toHex());

`

Create a KeyPair from a private key

The library can create a new keypair (derives the public key) from a private key instance.

const sbxCommon = require('@sbx/common');
const sbxCrypto = require('@sbx/crypto');

const privateKey = sbxCommon.Types.Keys.decode('CA02200046B7A086680D208272F6982F574FE226042F30D049F9A226283FC3346506411D');

/** @var kp sbxCommon.Types.Keys.KeyPair */
let kp = sbxCrypto.Keys.fromPrivateKey('ABCD', 'test123');