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

paywordts

v0.0.5

Published

It uses npm, TypeScript compiler, Jest, webpack, ESLint, Prettier, husky, pinst, commitlint. The production files include CommonJS, ES Modules, UMD version and TypeScript declaration files.

Downloads

11

Readme

Payword on Typescript

It uses npm, TypeScript compiler, Jest, webpack, ESLint, Prettier, husky, pinst, commitlint. The production files include CommonJS, ES Modules, UMD version and TypeScript declaration files.

Using the library

npm i payword-ts node-forge
npm i --save-dev @types/node-forge

Node

import { UserCertification, UserCertificationSigned, generateUserCertification, hash, verifyUserCertificationSigned } from 'paywordts'
import dotenv from 'dotenv'
import { pki } from 'node-forge'

dotenv.config()
const brokerPrivateKey = pki.privateKeyFromPem(
    process.env['BROKER_PRIVATE_KEY'] ?? ''
)
const brokerPublicKey = pki.publicKeyFromPem(
    process.env['BROKER_PUBLIC_KEY'] ?? ''
)
const userPrivateKey = pki.privateKeyFromPem(
    process.env['USER_PRIVATE_KEY'] ?? ''
)
const userPublicKey = pki.publicKeyFromPem(process.env['USER_PUBLIC_KEY'] ?? '')

const userCertification: UserCertification = {
    brokerId: 'brokerId',
    userId: 'userId',
    vendorId: 'vendorId',
    expirationDate: 123321,
    toAddress: 'toAddress',
    userPubKey: userPublicKey,
}

const userCertificationSigned: UserCertificationSigned =
    generateUserCertification(userCertification, brokerPrivateKey)

const isValid: boolean = verifyUserCertificationSigned(
    userCertificationSigned,
    brokerPublicKey
)

console.log(isValid)

React ( Vite )

import {
  UserCertification,
  UserCertificationSigned,
  UserMessage,
  UserMessageSigned,
  generateUserCertification,
  generateUserMessageSigned,
  getHashChainArrayByMessage,
} from "paywordts";
import "./App.css";
import { pki } from "node-forge";

const brokerPrivateKey = pki.privateKeyFromPem(
  import.meta.env.VITE_BROKER_PRIVATE_KEY ?? ""
);

const userPrivateKey = pki.privateKeyFromPem(
  import.meta.env.VITE_USER_PRIVATE_KEY ?? ""
);
const userPublicKey = pki.publicKeyFromPem(
  import.meta.env.VITE_USER_PUBLIC_KEY ?? ""
);

function App() {
  const userCertification: UserCertification = {
    brokerId: "brokerId",
    userId: "userId",
    vendorId: "vendorId",
    expirationDate: 123321,
    toAddress: "toAddress",
    userPubKey: userPublicKey,
  };

  const userCertificationSigned: UserCertificationSigned =
    generateUserCertification(userCertification, brokerPrivateKey);

  const h0: string = "hashzero";
  const n = 100;
  const hashArray: string[] = getHashChainArrayByMessage(h0, n);
  const hn: string = hashArray[n] ?? "";

  const userMessage: UserMessage = {
    expirationDate: 1010,
    hn,
    n,
    userCertificationSigned,
    vendorId: "vendorId",
  };

  const userMessageSigned: UserMessageSigned = generateUserMessageSigned(
    userPrivateKey,
    userMessage
  );
  return <>{JSON.stringify(userMessageSigned)}</>;
}

export default App;

Development from source

The source code is avaliable at our repository

Set up tools and environment

You need to have Node.js installed. Node includes npm as its default package manager.

Open the whole package folder with a good code editor, preferably Visual Studio Code. Consider installing VS Code extensions ES Lint and Prettier.

In the VS Code top menu: Terminal -> New Terminal

Install dependencies

Install dependencies with npm:

npm i

Test

Test your code with Jest framework:

npm run test

Note: Example TypeScript Package uses husky, pinst and commitlint to automatically execute test and lint commit message before every commit.

Build

Build production (distribution) files in your dist folder:

npm run build

It generates CommonJS (in dist/cjs folder), ES Modules (in dist/esm folder), bundled and minified UMD (in dist/umd folder), as well as TypeScript declaration files (in dist/types folder).

Try it before publishing

Run:

npm link

npm link will create a symlink in the global folder, which may be {prefix}/lib/node_modules/example-typescript-package or C:\Users<username>\AppData\Roaming\npm\node_modules\example-typescript-package.

Create an empty folder elsewhere, you don't even need to npm init (to generate package.json). Open the folder with VS Code, open a terminal and just run:

npm link example-typescript-package

This will create a symbolic link from globally-installed example-typescript-package to node_modules/ of the current folder.

You can then create a, for example, testnum.ts file with the content:

import { Num } from 'example-typescript-package'
console.log(new Num(5).add(new Num(6)).val() === 11)

If you don't see any linting errors in VS Code, if you put your mouse cursor over Num and see its type, then it's all good.

Whenever you want to uninstall the globally-installed example-typescript-package and remove the symlink in the global folder, run:

npm uninstall example-typescript-package -g

References

Btw, if you want to publish Python package, go to Example PyPI (Python Package Index) Package & Tutorial / Instruction / Workflow for 2021.