Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
akdombrowski committed Nov 12, 2023
1 parent a8c9311 commit 6798fd0
Show file tree
Hide file tree
Showing 7 changed files with 1,291 additions and 1,454 deletions.
2 changes: 1 addition & 1 deletion cli/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { jwtDecode, base64URLEncode } from "../lib";
import { jwtDecode, base64URLEncode } from "../src/index.js";
import clipboardy from "clipboardy";

const GENERIC_ERROR_CODE = 1;
Expand Down
6 changes: 3 additions & 3 deletions cli/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions cli_lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ var decode = /*#__PURE__*/function () {
return _ref.apply(this, arguments);
};
}();
var HELP_TEXT = "******HELP*****\n\
var HELP_TEXT = exports.HELP_TEXT = "******HELP*****\n\
use -c or --clipboard or call command with no arguments to decode the JWT in your clipboard\n\
or call command with JWT as first argument\n\
****************";
exports.HELP_TEXT = HELP_TEXT;
var cli = /*#__PURE__*/function () {
var cli = exports.cli = /*#__PURE__*/function () {
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(clipboard, argv) {
var arg2, arg3, decoded, bases64urlified, _decoded;
return _regenerator["default"].wrap(function _callee2$(_context2) {
Expand Down Expand Up @@ -154,7 +153,6 @@ var cli = /*#__PURE__*/function () {
}();

// read from clipboard
exports.cli = cli;
var clipboard;
try {
clipboard = _clipboardy["default"].readSync();
Expand All @@ -165,5 +163,4 @@ try {
// read passed in argument
var argv = process.argv;
cli(clipboard, argv);
var _default = cli;
exports["default"] = _default;
var _default = exports["default"] = cli;
36 changes: 12 additions & 24 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var _crypto = _interopRequireDefault(require("crypto"));
* @returns The decoded JWT as an object with header, payload, and signature
* as the keys.
*/
var jwtDecode = function jwtDecode(jwt) {
var jwtDecode = exports.jwtDecode = function jwtDecode(jwt) {
try {
// 1. Verify that the JWT contains at least one period ('.')
// character.
Expand Down Expand Up @@ -81,7 +81,6 @@ var jwtDecode = function jwtDecode(jwt) {
throw e;
}
};
exports.jwtDecode = jwtDecode;
var debugging = function debugging(e) {
// debugging
console.error(e.message, e);
Expand All @@ -104,7 +103,7 @@ var debugging = function debugging(e) {
* @param {*} key The private key used to sign the JWT.
* @returns The signature in base64url encoding.
*/
var hs256Sign = function hs256Sign(headerPayload, key) {
var hs256Sign = exports.hs256Sign = function hs256Sign(headerPayload, key) {
var secret = _crypto["default"].createSecretKey(key, "base64url");
var hmac = _crypto["default"].createHmac("sha256", secret);
hmac.update(headerPayload, "ascii");
Expand All @@ -125,8 +124,7 @@ var hs256Sign = function hs256Sign(headerPayload, key) {
* @returns Returns the signature in base64url encoding, or null if
* failure occurs.
*/
exports.hs256Sign = hs256Sign;
var rs256JWKSign = function rs256JWKSign(headerPayload, privateKey) {
var rs256JWKSign = exports.rs256JWKSign = function rs256JWKSign(headerPayload, privateKey) {
var hashes = _crypto["default"].getHashes();
if (hashes.includes("RSA-SHA256")) {
var secret;
Expand Down Expand Up @@ -178,8 +176,7 @@ var rs256JWKSign = function rs256JWKSign(headerPayload, privateKey) {
* encrypted key is given with no passphrase. Returns null if RSA-SHA256
* hash is unavailable in the currently used version of node.
*/
exports.rs256JWKSign = rs256JWKSign;
var rs256PEMSign = function rs256PEMSign(headerPayload, privateKey, passphrase) {
var rs256PEMSign = exports.rs256PEMSign = function rs256PEMSign(headerPayload, privateKey, passphrase) {
var hashes = _crypto["default"].getHashes();
var pemKey;
if (!hashes.includes("RSA-SHA256")) {
Expand Down Expand Up @@ -230,8 +227,7 @@ var rs256PEMSign = function rs256PEMSign(headerPayload, privateKey, passphrase)
* Must be in jwk format for this method.
* @returns True if the signature has been verified, false otherwise.
*/
exports.rs256PEMSign = rs256PEMSign;
var rs256JWKVerify = function rs256JWKVerify(jwt, publicKey) {
var rs256JWKVerify = exports.rs256JWKVerify = function rs256JWKVerify(jwt, publicKey) {
var jwtComponents = jwt.split(".");
var headerPayload = jwtComponents[0] + "." + jwtComponents[1];
var signature = jwtComponents[2];
Expand Down Expand Up @@ -267,8 +263,7 @@ var rs256JWKVerify = function rs256JWKVerify(jwt, publicKey) {
* for this method
* @returns True if verified, false otherwise.
*/
exports.rs256JWKVerify = rs256JWKVerify;
var rs256PEMVerify = function rs256PEMVerify(jwt, publicKey) {
var rs256PEMVerify = exports.rs256PEMVerify = function rs256PEMVerify(jwt, publicKey) {
var jwtComponents = jwt.split(".");
var headerPayload = jwtComponents[0] + "." + jwtComponents[1];
var signature = jwtComponents[2];
Expand Down Expand Up @@ -302,8 +297,7 @@ var rs256PEMVerify = function rs256PEMVerify(jwt, publicKey) {
*
* @returns True if verified, false otherwise.
*/
exports.rs256PEMVerify = rs256PEMVerify;
var hs256Verify = function hs256Verify(jwt, passphrase, passphraseEncoding) {
var hs256Verify = exports.hs256Verify = function hs256Verify(jwt, passphrase, passphraseEncoding) {
var jwtComponents = jwt.split(".");
var headerPayload = jwtComponents[0] + "." + jwtComponents[1];
var signature = jwtComponents[2];
Expand Down Expand Up @@ -340,8 +334,7 @@ var hs256Verify = function hs256Verify(jwt, passphrase, passphraseEncoding) {
* @returns The combined the header payload portion of the JWT. It is equal to
* base64url(header) + "." + base64url(payload).
*/
exports.hs256Verify = hs256Verify;
var createHeaderPayload = function createHeaderPayload(header, payload) {
var createHeaderPayload = exports.createHeaderPayload = function createHeaderPayload(header, payload) {
if (Buffer.isEncoding("base64url")) {
var headerBase64URL;
var payloadBase64URL;
Expand Down Expand Up @@ -374,8 +367,7 @@ var createHeaderPayload = function createHeaderPayload(header, payload) {
* @param {*} input A string literal to be base64url encoded.
* @returns The base64URL encoding of the input.
*/
exports.createHeaderPayload = createHeaderPayload;
var base64URLEncode = function base64URLEncode(input) {
var base64URLEncode = exports.base64URLEncode = function base64URLEncode(input) {
if (Buffer.isEncoding("base64url")) {
var buf = Buffer.from(input, "ascii");
var base64URLified = buf.toString("base64url");
Expand All @@ -402,8 +394,7 @@ var base64URLEncode = function base64URLEncode(input) {
* JSON object.
* @returns The input as a JSON object.
*/
exports.base64URLEncode = base64URLEncode;
var parseToJSON = function parseToJSON(input) {
var parseToJSON = exports.parseToJSON = function parseToJSON(input) {
var json = input;
if (Buffer.isEncoding("base64url")) {
if (input instanceof Object) {
Expand Down Expand Up @@ -431,8 +422,7 @@ var parseToJSON = function parseToJSON(input) {
* if alg is HS256. passphrase is to decrypt an encrypted PEM key.
* @returns The encoded JWT.
*/
exports.parseToJSON = parseToJSON;
var jwtEncode = function jwtEncode(header, payload, key, options) {
var jwtEncode = exports.jwtEncode = function jwtEncode(header, payload, key, options) {
var headerBase64URL;
var jsonHeader = header;
if (Buffer.isEncoding("base64url")) {
Expand Down Expand Up @@ -484,6 +474,4 @@ var jwtEncode = function jwtEncode(header, payload, key, options) {
};

// Default use-case is to decode a JWT.
exports.jwtEncode = jwtEncode;
var _default = jwtDecode;
exports["default"] = _default;
var _default = exports["default"] = jwtDecode;
2 changes: 1 addition & 1 deletion lib/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6798fd0

Please sign in to comment.