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

@maincc/jwt-lib

v0.0.3

Published

> A cryptocurrency-compliant js library > 一个实现符合加密货币的js库 > > Based on jsontokens library (https://github.com/stacks-network/jsontokens-js). > 基于jsontokens库进行扩展。

Downloads

133

Readme

jwt-lib

A cryptocurrency-compliant js library 一个实现符合加密货币的js库

Based on jsontokens library (https://github.com/stacks-network/jsontokens-js). 基于jsontokens库进行扩展。

INSTALL

npm install @maincc/jwt-lib

Documentation

example import

import WalletJwt from "@maincc/jwt-lib";
  • If you don't have an Ethereum account, you can generate it through generate.
    如果你并没有以太坊的账户,可以通过generate生成。

    example generate

    const wallet = WalletJwt.generate();

    result

    {
      privateKey: '0xc5b893aef8c2e847dc14ddadb7dfd3be5781b7a5a46e0cbcc00bfa992c626ddc',
      publicKey: '0x6f592757f8e6506a5f950df6fcbb6b8000b3ef00c24cc69dfdb3155d322b182c4d31216ae1154b63211c8970977ccb2a72272ac0cce8004e0c26c86dfc01046a',
      compressPubKey: '026f592757f8e6506a5f950df6fcbb6b8000b3ef00c24cc69dfdb3155d322b182c',
      address: '0x50692568f1184911ecbfa2de4147fecba5b0b386'
    }
  • If you have an Ethereum account and have its public and private keys. Then you can perform jwt related operations.
    如果你拥有了以太坊的账户,并掌握其公私钥。那么可以进行jwt的相关操作。

    • example sign
    const data = {
      header:{
        type: 'CWT',
        chain: 'ethereum'
      },
      payload:{
        sub: '1234567890',
        name: 'John Doe',
      }
    };
    const jwt = WalletJwt.sign(data, wallet.privateKey);

    result

    eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksiLCJ0eXBlIjoiQ1dUIiwiY2hhaW4iOiJldGhlcmV1bSJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIn0.5ZICOX22jNPVeewb3o0fsMSJM04CQnO5aIbZaW_vfakwYUReR2-mZEiDkz-ezdmkOH6xKObnZDpMcNCnv9n-Rw

    The signature must contain payload and header fields.

    签名的内容必须带有payload和header字段。

    • example decode
    WalletJwt.decode(jwt)

    result

    {
      header: { typ: 'JWT', alg: 'ES256K', type: 'CWT', chain: 'ethereum' },
      payload: { sub: '1234567890', name: 'John Doe' },
      signature: '5ZICOX22jNPVeewb3o0fsMSJM04CQnO5aIbZaW_vfakwYUReR2-mZEiDkz-ezdmkOH6xKObnZDpMcNCnv9n-Rw'
    }
    • example verify
    WalletJwt.verify(jwt, wallet.publicKey) or WalletJwt.verify(jwt, wallet.compressPubKey)

    result

    true
  • If you need public and private keys in pem format, or Signature in jwt is ASN.1 DER format.
    如果你需要pem格式的公私钥,或者需要jwt里的Signature是ASN.1 DER格式。

  • example privToPem

WalletJwt.privToPem(wallet.privateKey)

Convert the private key to pem format. Note: The resulting pem is SEC1 specification.
将私钥转换成pem格式,注:生成的是SEC1规范的pem。

**`result`**  
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIMW4k674wuhH3BTdrbff075XgbelpG4MvMAL+pksYm3coAcGBSuBBAAK
oUQDQgAEb1knV/jmUGpflQ32/LtrgACz7wDCTMad/bMVXTIrGCxNMSFq4RVLYyEc
iXCXfMsqcicqwMzoAE4MJsht/AEEag==
-----END EC PRIVATE KEY-----
  • example pubToPem
WalletJwt.pubToPem(wallet.publicKey)

Convert the public key to pem format. Note: The parameter must be an uncompressed public key.
将公钥转换成pem格式,注:参数必须是未压缩的公钥。

**`result`**  
-----BEGIN PUBLIC KEY-----
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEb1knV/jmUGpflQ32/LtrgACz7wDCTMad
/bMVXTIrGCxNMSFq4RVLYyEciXCXfMsqcicqwMzoAE4MJsht/AEEag==
-----END PUBLIC KEY-----
  • example sign(... , 'der') && verify(... , 'der')
const jwtDer = WalletJwt.sign(data, wallet.privateKey, 'der');
WalletJwt.verify(jwtDer, wallet.publicKey, 'der');

Generate jwt in ASN.1 DER format (to meet openssl and other cryptographic libraries) and verify.
生成符合ASN.1 DER格式的jwt(满足openssl等密码库)并验证。

**`result`**  
eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksiLCJ0eXBlIjoiQ1dUIiwiY2hhaW4iOiJldGhlcmV1bSJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIn0.MEUCIQDlkgI5fbaM09V57BvejR-wxIkzTgJCc7lohtlpb-99qQIgMGFEXkdvpmRIg5M_ns3ZpDh-sSjm52Q6THDQp7_Z_kc
true