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

@jccdex/cwt-lib

v1.0.3

Published

chain web token

Downloads

79

Readme

cwt-lib (chain-web-token)

npm build Coverage Status npm downloads

用于区块链身份认证的js库;
js library for blockchain identity authentication;

使用区块链的私钥对数据结构({header: ... , payload: ...})进行签名,生成cwt;
Using the private key data structure of the blockchain ({header:... , payload: ... }) sign and generate cwt;

使用区块链的公钥对cwt进行验证,证明其身份;
Verify the cwt using the blockchain's public key to prove its identity;

Synopsis

chain web token (缩写cwt) 是有三部分组成 header.payload.Signature,其中的 Signature 是对 header.payload进行签名。
chain web token (abbreviated cwt) is composed of three partsheader.payload.Signature, where Signature is the signature of header.payload.

目前支持ethereumripplebitcoinjingtum
Currently support ethereum, ripple, bitcoin, jingtum.

Install

npm install @jccdex/cwt-lib

CDN

ChainWebToken as a global variable. Size is 135k.

<script src="https://unpkg.com/@jccdex/cwt-lib/dist/cwt-lib.min.js"></script>

Table of Contents

API

sign

syntax

const sign = ({ chain: string; privateKey: string; usr: string; time?: number; alg?: string; })

arguments

chain: Support chain ('jingtum', 'ripple', 'ethereum', 'bitcoin')

privateKey: Private key or secret

usr: User name

type: To distinguish between individuals and businesses. Non-essential ('CWT'(default), 'CWT_ENT')

If you represent your business, please do not ignore it and assign CWT_ENT to it; if you represent yourself, then it is optional for you, but if you decide to use it, please assign CWT to it.

time: Timestamp unit:s Non-essential

If you want to generate cwt for a specific time, please do not ignore it, otherwise is current time.

alg: Algorithm Non-essential

If the private key is ripple or jingtum chain, length is 64 and algorithm is ed25519, alg is ed25519.

Code Examples

import { sign } from "@jccdex/cwt-lib";
// const sign = require("@jccdex/cwt-lib").sign

const cwt = sign({
  chain: "",
  privateKey: "",
  usr: ""
});

// Result example:
// eyJhbGciOiJzZWNwMjU2azEiLCJ4NWMiOlsiLS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS1cbk1GWXdFQVlIS29aSXpqMENBUVlGSzRFRUFBb0RRZ0FFTVRxOXVhdENOQVhXSFV2U2tPYm0wOTd0cDFJVVAyZVJcbjFyKzU4T3ljNHoyeTNaSFBobFN3K01JUTBHczRkSVZDcHFiMmJjcE9aTkpvUEY5TzYxSEJiQT09XG4tLS0tLUVORCBQVUJMSUMgS0VZLS0tLS0iXSwidHlwZSI6IkNXVCIsImNoYWluIjoiamluZ3R1bSJ9.eyJ1c3IiOiJqaW5ndHVtX3NlY3AyNTZrMSIsInRpbWUiOjEyMzQ1Nn0.MEUCIH546Iz3wqdTgTLHJg3czMbQqLVJHj9iddqXPIr6MnG9AiEAkvKelTLl-ZWvCNJ9O8rWHhksuggz_jgg8wEM44mf9xk

// cwt decode:
//   {
//   header: {
//     alg: 'secp256k1',
//     x5c: [
//       '-----BEGIN PUBLIC KEY-----\n' +
//         'MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEMTq9uatCNAXWHUvSkObm097tp1IUP2eR\n' +
//         '1r+58Oyc4z2y3ZHPhlSw+MIQ0Gs4dIVCpqb2bcpOZNJoPF9O61HBbA==\n' +
//         '-----END PUBLIC KEY-----'
//     ],// Public key in pem format
//     type: 'CWT',
//     chain: 'jingtum'
//   },
//   payload: { usr: '...usr...', time: Timestamp(unit:s) },
//   signature: 'MEUCIH546Iz3wqdTgTLHJg3czMbQqLVJHj9iddqXPIr6MnG9AiEAkvKelTLl-ZWvCNJ9O8rWHhksuggz_jgg8wEM44mf9xk'
// }