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

@feelinglovelynow/jwt

v1.0.7

Published

Node and/or Edge helper functions to create JWK's, create JWT's, decode JWT's and verify JWT's with the subtle crypto api's ECDSA: SHA-512 algorithm

Downloads

29

Readme

🕉 @feelinglovelynow/jwt

💎 Install

pnpm add @feelinglovelynow/jwt
pnpm add buffer # only necessary if @ browser or edge (cloudflare workers)

🤓 Unit Tests

Statements

🙏 Description

  • Node and/or Edge helper functions to create JWK's, create JWT's, decode JWT's and verify JWT's with the subtle crypto api's ECDSA: SHA-512 algorithm
  • First we create JWK's which give us a private and public JWK (I love to put them in my .env file)
  • Then with the private JWK we may create JWT's
  • With the public JWK we may verify JWT's
  • And with no JWK required we may decode JWT's

💚 Create public and private JWK's

  • This function will log the public & private JWK's in the terminal
  • Calling this function is only necessary when we first create the JWK's. Once we store the pulic and private JWK's this code may be removed. So place this code locally somewhere server side, call it for the number of JWK's you'd love and then remove it when they're in your .env file. The same private JWK can create many JWT's.
import { createJWKs } from '@feelinglovelynow/jwt'

createJWKs()

💛 Create JWT

  • createJWT(jwtPayload: Object, expiresInAsSeconds: number, privateJWK: string, Buffer: any): Promise<string>
import { Buffer } from 'buffer/' // edge
import { Buffer } from 'node:buffer' // node
import { createJWT } from '@feelinglovelynow/jwt'
import { JWK_PRIVATE } from '$env/static/private'

const jwtPayload = { userId: 1 }
const expiresInAsSeconds = 32400 // 9 hours
const jwt = await createJWT(jwtPayload, expiresInAsSeconds, JWK_PRIVATE, Buffer)

🧡 Decode JWT

  • decodeJWT(jwt: string, Buffer: any): any
import { Buffer } from 'buffer/' // edge
import { Buffer } from 'node:buffer' // node
import { decodeJWT } from '@feelinglovelynow/jwt'

const decoded = decodeJWT(jwt, Buffer)
  • 🔥 Errors we may throw
if (!jwt || typeof jwt !== 'string' || jwt.split('.').length !== 3) {
  throw { id: 'fln__decode__invalid-jwt', message: 'Please provide a string token, with 3 parts, seperated by a dot', _errorData: { jwt } }
}

❤️ Verify JWT

  • verifyJWT(jwt: string, publicJWK: string, Buffer: any): Promise<any>
import { Buffer } from 'buffer/' // edge
import { Buffer } from 'node:buffer' // node
import { verifyJWT } from '@feelinglovelynow/jwt'
import { JWK_PUBLIC } from '$env/static/private'

const payload = await verifyJWT(jwt, JWK_PUBLIC, Buffer)
  • 🔥 Errors we may throw
if (!jwt || typeof jwt !== 'string' || jwt.split('.').length !== 3) {
  throw { id: 'fln__verify__bad-format', message: 'Please provide a string token, with 3 parts, seperated by a dot', _errorData: { jwt } }
}

if (expiresInAsSeconds <= now()) {
  throw { id: 'fln__verify__expired', message: 'Token has expired', _errorData: { jwt } }
}

if (!isValid) throw { id: 'fln__verify__invalid', message: 'Token is invalid', _errorData: { jwt } }

🎁 All Our Packages

  1. @feelinglovelynow/datetime-local: NPMGithub
  2. @feelinglovelynow/dgraph: NPMGithub
  3. @feelinglovelynow/env-write: NPMGithub
  4. @feelinglovelynow/get-form-entries: NPMGithub
  5. @feelinglovelynow/get-relative-time: NPMGithub
  6. @feelinglovelynow/global-style: NPMGithub
  7. @feelinglovelynow/jwt: NPMGithub
  8. @feelinglovelynow/loop-backwards: NPMGithub
  9. @feelinglovelynow/slug: NPMGithub
  10. @feelinglovelynow/svelte-catch: NPMGithub
  11. @feelinglovelynow/svelte-kv: NPMGithub
  12. @feelinglovelynow/svelte-loading-anchor: NPMGithub
  13. @feelinglovelynow/svelte-modal: NPMGithub
  14. @feelinglovelynow/svelte-turnstile: NPMGithub
  15. @feelinglovelynow/toast: NPMGithub