Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tsndr/cloudflare-worker-jwt

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tsndr/cloudflare-worker-jwt - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

index.d.ts

22

index.js

@@ -30,7 +30,5 @@ class Base64URL {

utf8ToUint8Array(str) {
const chars = []
str = btoa(unescape(encodeURIComponent(str)))
return Base64URL.parse(str)
return Base64URL.parse(btoa(unescape(encodeURIComponent(str))))
}
async sign(payload, secret, alg = 'HS256') {
async sign(payload, secret, algorithm = 'HS256') {
if (payload === null || typeof payload !== 'object')

@@ -40,9 +38,9 @@ throw new Error('payload must be an object')

throw new Error('secret must be a string')
if (typeof alg !== 'string')
throw new Error('alg must be a string')
const importAlgorithm = this.algorithms[alg]
if (typeof algorithm !== 'string')
throw new Error('algorithm must be a string')
const importAlgorithm = this.algorithms[algorithm]
if (!importAlgorithm)
throw new Error('algorithm not found')
const payloadAsJSON = JSON.stringify(payload)
const partialToken = `${Base64URL.stringify(this.utf8ToUint8Array(JSON.stringify({ alg, typ: 'JWT' })))}.${Base64URL.stringify(this.utf8ToUint8Array(payloadAsJSON))}`
const partialToken = `${Base64URL.stringify(this.utf8ToUint8Array(JSON.stringify({ alg: algorithm, typ: 'JWT' })))}.${Base64URL.stringify(this.utf8ToUint8Array(payloadAsJSON))}`
const key = await crypto.subtle.importKey('raw', this.utf8ToUint8Array(secret), importAlgorithm, false, ['sign'])

@@ -61,3 +59,3 @@ const characters = payloadAsJSON.split('')

}
async verify(token, secret, alg = 'HS256') {
async verify(token, secret, algorithm = 'HS256') {
if (typeof token !== 'string')

@@ -67,8 +65,8 @@ throw new Error('token must be a string')

throw new Error('secret must be a string')
if (typeof alg !== 'string')
throw new Error('alg must be a string')
if (typeof algorithm !== 'string')
throw new Error('algorithm must be a string')
const tokenParts = token.split('.')
if (tokenParts.length !== 3)
throw new Error('token must have 3 parts')
const importAlgorithm = this.algorithms[alg]
const importAlgorithm = this.algorithms[algorithm]
if (!importAlgorithm)

@@ -75,0 +73,0 @@ throw new Error('algorithm not found')

{
"name": "@tsndr/cloudflare-worker-jwt",
"version": "1.0.6",
"version": "1.0.7",
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc