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

jwt-encode

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jwt-encode - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

package.json
{
"name": "jwt-encode",
"version": "1.0.0",
"version": "1.0.1",
"description": "Generate json webtokens in the browser",

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

const CryptoJS = require('ts.cryptojs256');
/**
* Default options for JWT signature
*/
const defaultHeader = { alg: 'HS256', typ: 'JWT' };
/**
* Return a base64 URL

@@ -26,7 +31,3 @@ *

function sign (data, secret, options = {}) {
const defaultOptions = {
alg: 'HS256',
typ: 'JWT'
};
const header = Object.assign(defaultOptions, options);
const header = Object.assign(defaultHeader, options);
if (header.alg !== 'HS256' && header.typ !== 'JWT') {

@@ -36,8 +37,5 @@ throw new Error('jwt-encode only support the HS256 algorithm and the JWT type of hash');

const stringifiedHeader = CryptoJS.enc.Utf8.parse(JSON.stringify(header));
const encodedHeader = base64url(stringifiedHeader);
const encodedHeader = encode(header);
const encodedData = encode(data);
const stringifiedData = CryptoJS.enc.Utf8.parse(JSON.stringify(data));
const encodedData = base64url(stringifiedData);
let signature = `${encodedHeader}.${encodedData}`;

@@ -49,2 +47,13 @@ signature = CryptoJS.HmacSHA256(signature, secret);

/**
* Safely base64url encode a JS Object in a way that is UTF-8 safe
*
* @param {Object} Javascript object payload to be encoded
* @return {string} utf-8 safe base64url encoded payload
*/
function encode (data) {
const stringifiedData = CryptoJS.enc.Utf8.parse(JSON.stringify(data));
return base64url(stringifiedData);
}
module.exports = sign;
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