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

jose-browser-runtime

Package Overview
Dependencies
Maintainers
1
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jose-browser-runtime - npm Package Compare versions

Comparing version 3.13.0 to 3.14.0

dist/browser/runtime/invalid_key_input.js

7

dist/browser/jwk/from_key_like.js

@@ -1,10 +0,3 @@

import { encode as base64url } from '../runtime/base64url.js';
import asJWK from '../runtime/key_to_jwk.js';
async function fromKeyLike(key) {
if (key instanceof Uint8Array) {
return {
kty: 'oct',
k: base64url(key),
};
}
return asJWK(key);

@@ -11,0 +4,0 @@ }

2

dist/browser/jws/flattened/sign.js

@@ -50,3 +50,3 @@ import isDisjoint from '../../lib/is_disjoint.js';

}
checkKeyType(alg, key);
checkKeyType(alg, key, 'sign');
let payload = this._payload;

@@ -53,0 +53,0 @@ if (b64) {

@@ -71,3 +71,3 @@ import { JOSEAlgNotAllowed, JWSInvalid, JWSSignatureVerificationFailed } from '../../util/errors.js';

}
checkKeyType(alg, key);
checkKeyType(alg, key, 'verify');
const data = concat(encoder.encode((_a = jws.protected) !== null && _a !== void 0 ? _a : ''), encoder.encode('.'), typeof jws.payload === 'string' ? encoder.encode(jws.payload) : jws.payload);

@@ -74,0 +74,0 @@ const signature = base64url(jws.signature);

@@ -14,3 +14,5 @@ import CompactSign from '../jws/compact/sign.js';

sig.setProtectedHeader(this._protectedHeader);
if (((_a = this._protectedHeader.crit) === null || _a === void 0 ? void 0 : _a.includes('b64')) && this._protectedHeader.b64 === false) {
if (Array.isArray((_a = this._protectedHeader) === null || _a === void 0 ? void 0 : _a.crit) &&
this._protectedHeader.crit.includes('b64') &&
this._protectedHeader.b64 === false) {
throw new JWTInvalid('JWTs MUST NOT use unencoded payload');

@@ -17,0 +19,0 @@ }

@@ -1,6 +0,10 @@

const checkKeyType = (alg, key) => {
import invalidKeyInput from '../runtime/invalid_key_input.js';
const checkKeyType = (alg, key, usage) => {
if (!(key instanceof Uint8Array) && !(key === null || key === void 0 ? void 0 : key.type)) {
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey', 'Uint8Array'));
}
if (alg.startsWith('HS') ||
alg === 'dir' ||
alg.startsWith('PBES2') ||
alg.match(/^A\d{3}(?:GCM)KW$/)) {
alg.match(/^A\d{3}(?:GCM)?KW$/)) {
if (key instanceof Uint8Array || key.type === 'secret') {

@@ -12,3 +16,3 @@ return;

if (key instanceof Uint8Array) {
throw new TypeError('CryptoKey or KeyObject instances must be used for asymmetric algorithms');
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey'));
}

@@ -18,3 +22,9 @@ if (key.type === 'secret') {

}
if (usage === 'sign' && key.type === 'public') {
throw new TypeError('CryptoKey or KeyObject instances for asymmetric algorithm signing must be of type "private"');
}
if (usage === 'decrypt' && key.type === 'public') {
throw new TypeError('CryptoKey or KeyObject instances for asymmetric algorithm decryption must be of type "private"');
}
};
export default checkKeyType;

@@ -10,2 +10,3 @@ import { JOSENotSupported, JWEInvalid } from '../util/errors.js';

import { parseJwk } from '../jwk/parse.js';
import checkKeyType from './check_key_type.js';
function assertEnryptedKey(encryptedKey) {

@@ -22,2 +23,3 @@ if (!encryptedKey) {

async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
checkKeyType(alg, key, 'decrypt');
switch (alg) {

@@ -24,0 +26,0 @@ case 'dir': {

@@ -11,2 +11,3 @@ import cekFactory, { bitLengths as cekLengths } from '../lib/cek.js';

import { fromKeyLike } from '../jwk/from_key_like.js';
import checkKeyType from './check_key_type.js';
const generateCek = cekFactory(random);

@@ -17,2 +18,3 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {

let cek;
checkKeyType(alg, key, 'encrypt');
switch (alg) {

@@ -19,0 +21,0 @@ case 'dir': {

@@ -57,3 +57,3 @@ import { JWTClaimValidationFailed, JWTExpired, JWTInvalid } from '../util/errors.js';

default:
throw new TypeError('invalid clockTolerance option type');
throw new TypeError('Invalid clockTolerance option type');
}

@@ -60,0 +60,0 @@ const { currentDate } = options;

@@ -10,3 +10,3 @@ const minute = 60;

if (!matched) {
throw new TypeError('invalid time period format');
throw new TypeError('Invalid time period format');
}

@@ -13,0 +13,0 @@ const value = parseFloat(matched[1]);

import bogusWebCrypto from './bogus.js';
import crypto, { isCryptoKey } from './webcrypto.js';
import invalidKeyInput from './invalid_key_input.js';
function checkKeySize(key, alg) {

@@ -15,3 +16,3 @@ if (key.algorithm.length !== parseInt(alg.substr(1, 3), 10)) {

}
throw new TypeError('invalid key input');
throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'Uint8Array'));
}

@@ -18,0 +19,0 @@ export const wrap = async (alg, key, cek) => {

@@ -7,2 +7,3 @@ import { concat, uint64be } from '../lib/buffer_utils.js';

import crypto, { isCryptoKey } from './webcrypto.js';
import invalidKeyInput from './invalid_key_input.js';
async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {

@@ -55,3 +56,3 @@ const keySize = parseInt(enc.substr(1, 3), 10);

if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
throw new TypeError('invalid key input');
throw new TypeError(invalidKeyInput(cek, 'CryptoKey', 'Uint8Array'));
}

@@ -58,0 +59,0 @@ checkCekLength(enc, cek);

import { encoder, concat, uint32be, lengthAndInput, concatKdf } from '../lib/buffer_utils.js';
import crypto, { isCryptoKey } from './webcrypto.js';
import digest from './digest.js';
import invalidKeyInput from './invalid_key_input.js';
export const deriveKey = async (publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) => {
if (!isCryptoKey(publicKey)) {
throw new TypeError('invalid key input');
throw new TypeError(invalidKeyInput(publicKey, 'CryptoKey'));
}
if (!isCryptoKey(privateKey)) {
throw new TypeError('invalid key input');
throw new TypeError(invalidKeyInput(privateKey, 'CryptoKey'));
}

@@ -24,3 +25,3 @@ const value = concat(lengthAndInput(encoder.encode(algorithm)), lengthAndInput(apu), lengthAndInput(apv), uint32be(keyLength));

if (!isCryptoKey(key)) {
throw new TypeError('invalid key input');
throw new TypeError(invalidKeyInput(key, 'CryptoKey'));
}

@@ -31,5 +32,5 @@ return (await crypto.subtle.generateKey({ name: 'ECDH', namedCurve: key.algorithm.namedCurve }, true, ['deriveBits'])).privateKey;

if (!isCryptoKey(key)) {
throw new TypeError('invalid key input');
throw new TypeError(invalidKeyInput(key, 'CryptoKey'));
}
return ['P-256', 'P-384', 'P-521'].includes(key.algorithm.namedCurve);
};

@@ -5,2 +5,3 @@ import { concat, uint64be } from '../lib/buffer_utils.js';

import crypto, { isCryptoKey } from './webcrypto.js';
import invalidKeyInput from './invalid_key_input.js';
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {

@@ -37,3 +38,3 @@ const keySize = parseInt(enc.substr(1, 3), 10);

if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
throw new TypeError('invalid key input');
throw new TypeError(invalidKeyInput(cek, 'CryptoKey', 'Uint8Array'));
}

@@ -40,0 +41,0 @@ checkCekLength(enc, cek);

@@ -48,3 +48,3 @@ import crypto from './webcrypto.js';

if (typeof modulusLength !== 'number' || modulusLength < 2048) {
throw new JOSENotSupported('invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used');
throw new JOSENotSupported('Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used');
}

@@ -51,0 +51,0 @@ return modulusLength;

import crypto, { isCryptoKey } from './webcrypto.js';
import invalidKeyInput from './invalid_key_input.js';
export default function getCryptoKey(alg, key, usage) {

@@ -8,7 +9,7 @@ if (isCryptoKey(key)) {

if (!alg.startsWith('HS')) {
throw new TypeError('symmetric keys are only applicable for HMAC-based algorithms');
throw new TypeError(invalidKeyInput(key, 'CryptoKey'));
}
return crypto.subtle.importKey('raw', key, { hash: { name: `SHA-${alg.substr(-3)}` }, name: 'HMAC' }, false, [usage]);
}
throw new TypeError('invalid key input');
throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'Uint8Array'));
}
import crypto, { isCryptoKey } from './webcrypto.js';
import invalidKeyInput from './invalid_key_input.js';
import { encode as base64url } from './base64url.js';
const keyToJWK = async (key) => {
if (key instanceof Uint8Array) {
return {
kty: 'oct',
k: base64url(key),
};
}
if (!isCryptoKey(key)) {
throw new TypeError('invalid key input');
throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'Uint8Array'));
}

@@ -6,0 +14,0 @@ if (!key.extractable) {

@@ -7,2 +7,3 @@ import random from './random.js';

import crypto, { isCryptoKey } from './webcrypto.js';
import invalidKeyInput from './invalid_key_input.js';
function getCryptoKey(key) {

@@ -15,3 +16,3 @@ if (key instanceof Uint8Array) {

}
throw new TypeError('invalid key input');
throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'Uint8Array'));
}

@@ -18,0 +19,0 @@ export const encrypt = async (alg, key, cek, p2c = Math.floor(Math.random() * 2049) + 2048, p2s = random(new Uint8Array(16))) => {

@@ -5,5 +5,6 @@ import subtleAlgorithm from './subtle_rsaes.js';

import checkKeyLength from './check_key_length.js';
import invalidKeyInput from './invalid_key_input.js';
export const encrypt = async (alg, key, cek) => {
if (!isCryptoKey(key)) {
throw new TypeError('invalid key input');
throw new TypeError(invalidKeyInput(key, 'CryptoKey'));
}

@@ -22,3 +23,3 @@ checkKeyLength(alg, key);

if (!isCryptoKey(key)) {
throw new TypeError('invalid key input');
throw new TypeError(invalidKeyInput(key, 'CryptoKey'));
}

@@ -25,0 +26,0 @@ checkKeyLength(alg, key);

@@ -1,2 +0,2 @@

import type { KeyLike, DecryptOptions, JWEHeaderParameters, GetKeyFunction, FlattenedJWE, CompactDecryptResult } from '../../types.d';
import type { KeyLike, DecryptOptions, JWEHeaderParameters, GetKeyFunction, FlattenedJWE, CompactDecryptResult } from '../../types';
export interface CompactDecryptGetKey extends GetKeyFunction<JWEHeaderParameters, FlattenedJWE> {

@@ -3,0 +3,0 @@ }

@@ -1,2 +0,2 @@

import type { KeyLike, JWEKeyManagementHeaderParameters, JWEHeaderParameters, EncryptOptions } from '../../types.d';
import type { KeyLike, JWEKeyManagementHeaderParameters, JWEHeaderParameters, EncryptOptions } from '../../types';
declare class CompactEncrypt {

@@ -3,0 +3,0 @@ private _flattened;

@@ -1,2 +0,2 @@

import type { FlattenedDecryptResult, KeyLike, FlattenedJWE, JWEHeaderParameters, DecryptOptions, GetKeyFunction } from '../../types.d';
import type { FlattenedDecryptResult, KeyLike, FlattenedJWE, JWEHeaderParameters, DecryptOptions, GetKeyFunction } from '../../types';
export interface FlattenedDecryptGetKey extends GetKeyFunction<JWEHeaderParameters | undefined, FlattenedJWE> {

@@ -3,0 +3,0 @@ }

@@ -1,2 +0,2 @@

import type { KeyLike, FlattenedJWE, JWEHeaderParameters, JWEKeyManagementHeaderParameters, EncryptOptions } from '../../types.d';
import type { KeyLike, FlattenedJWE, JWEHeaderParameters, JWEKeyManagementHeaderParameters, EncryptOptions } from '../../types';
declare class FlattenedEncrypt {

@@ -3,0 +3,0 @@ private _plaintext;

@@ -1,2 +0,2 @@

import type { KeyLike, DecryptOptions, JWEHeaderParameters, GetKeyFunction, FlattenedJWE, GeneralJWE, GeneralDecryptResult } from '../../types.d';
import type { KeyLike, DecryptOptions, JWEHeaderParameters, GetKeyFunction, FlattenedJWE, GeneralJWE, GeneralDecryptResult } from '../../types';
export interface GeneralDecryptGetKey extends GetKeyFunction<JWEHeaderParameters, FlattenedJWE> {

@@ -3,0 +3,0 @@ }

/// <reference types="node" />
import type { KeyObject } from 'crypto';
import type { FlattenedJWSInput, JWSHeaderParameters } from '../types.d';
import type { FlattenedJWSInput, JWSHeaderParameters } from '../types';
declare function EmbeddedJWK(protectedHeader: JWSHeaderParameters, token: FlattenedJWSInput): Promise<CryptoKey | KeyObject>;
export { EmbeddedJWK };
export default EmbeddedJWK;

@@ -1,2 +0,2 @@

import type { JWK, KeyLike } from '../types.d';
import type { JWK, KeyLike } from '../types';
declare function fromKeyLike(key: KeyLike): Promise<JWK>;

@@ -3,0 +3,0 @@ export { fromKeyLike };

@@ -1,2 +0,2 @@

import type { JWK, KeyLike } from '../types.d';
import type { JWK, KeyLike } from '../types';
declare function parseJwk(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promise<KeyLike>;

@@ -3,0 +3,0 @@ export { parseJwk };

@@ -1,2 +0,2 @@

import type { JWK } from '../types.d';
import type { JWK } from '../types';
declare function calculateThumbprint(jwk: JWK, digestAlgorithm?: 'sha256' | 'sha384' | 'sha512'): Promise<string>;

@@ -3,0 +3,0 @@ export { calculateThumbprint };

/// <reference types="node" />
import type * as http from 'http';
import type * as https from 'https';
import type { JWSHeaderParameters, FlattenedJWSInput, GetKeyFunction } from '../types.d';
import type { JWSHeaderParameters, FlattenedJWSInput, GetKeyFunction } from '../types';
export interface RemoteJWKSetOptions {

@@ -6,0 +6,0 @@ timeoutDuration?: number;

@@ -1,2 +0,2 @@

import type { JWSHeaderParameters, KeyLike, SignOptions } from '../../types.d';
import type { JWSHeaderParameters, KeyLike, SignOptions } from '../../types';
declare class CompactSign {

@@ -3,0 +3,0 @@ private _flattened;

@@ -1,2 +0,2 @@

import type { CompactVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions } from '../../types.d';
import type { CompactVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions } from '../../types';
export interface CompactVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {

@@ -3,0 +3,0 @@ }

@@ -1,2 +0,2 @@

import type { KeyLike, FlattenedJWS, JWSHeaderParameters, SignOptions } from '../../types.d';
import type { KeyLike, FlattenedJWS, JWSHeaderParameters, SignOptions } from '../../types';
declare class FlattenedSign {

@@ -3,0 +3,0 @@ private _payload;

@@ -1,2 +0,2 @@

import type { FlattenedVerifyResult, KeyLike, FlattenedJWSInput, JWSHeaderParameters, VerifyOptions, GetKeyFunction } from '../../types.d';
import type { FlattenedVerifyResult, KeyLike, FlattenedJWSInput, JWSHeaderParameters, VerifyOptions, GetKeyFunction } from '../../types';
export interface FlattenedVerifyGetKey extends GetKeyFunction<JWSHeaderParameters | undefined, FlattenedJWSInput> {

@@ -3,0 +3,0 @@ }

@@ -1,2 +0,2 @@

import type { KeyLike, GeneralJWS, JWSHeaderParameters, SignOptions } from '../../types.d';
import type { KeyLike, GeneralJWS, JWSHeaderParameters, SignOptions } from '../../types';
export interface Signature {

@@ -3,0 +3,0 @@ setProtectedHeader(protectedHeader: JWSHeaderParameters): Signature;

@@ -1,2 +0,2 @@

import type { GeneralJWSInput, GeneralVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions } from '../../types.d';
import type { GeneralJWSInput, GeneralVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions } from '../../types';
export interface GeneralVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {

@@ -3,0 +3,0 @@ }

@@ -1,2 +0,2 @@

import type { KeyLike, DecryptOptions, JWTPayload, JWTClaimVerificationOptions, GetKeyFunction, JWEHeaderParameters, FlattenedJWE, JWTDecryptResult } from '../types.d';
import type { KeyLike, DecryptOptions, JWTPayload, JWTClaimVerificationOptions, GetKeyFunction, JWEHeaderParameters, FlattenedJWE, JWTDecryptResult } from '../types';
interface JWTDecryptOptions extends DecryptOptions, JWTClaimVerificationOptions {

@@ -3,0 +3,0 @@ }

@@ -1,3 +0,3 @@

import type { EncryptOptions, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWTPayload, KeyLike } from '../types.d';
import ProduceJWT from '../lib/jwt_producer.js';
import type { EncryptOptions, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWTPayload, KeyLike } from '../types';
import ProduceJWT from '../lib/jwt_producer';
declare class EncryptJWT extends ProduceJWT {

@@ -4,0 +4,0 @@ private _cek;

@@ -1,3 +0,3 @@

import type { JWSHeaderParameters, JWTPayload, KeyLike, SignOptions } from '../types.d';
import ProduceJWT from '../lib/jwt_producer.js';
import type { JWSHeaderParameters, JWTPayload, KeyLike, SignOptions } from '../types';
import ProduceJWT from '../lib/jwt_producer';
declare class SignJWT extends ProduceJWT {

@@ -4,0 +4,0 @@ private _protectedHeader;

@@ -1,3 +0,3 @@

import type { JWSHeaderParameters, JWTClaimVerificationOptions, JWTPayload } from '../types.d';
import ProduceJWT from '../lib/jwt_producer.js';
import type { JWSHeaderParameters, JWTClaimVerificationOptions, JWTPayload } from '../types';
import ProduceJWT from '../lib/jwt_producer';
interface UnsecuredResult {

@@ -4,0 +4,0 @@ payload: JWTPayload;

@@ -1,2 +0,2 @@

import type { KeyLike, VerifyOptions, JWTPayload, JWTClaimVerificationOptions, JWSHeaderParameters, GetKeyFunction, FlattenedJWSInput, JWTVerifyResult } from '../types.d';
import type { KeyLike, VerifyOptions, JWTPayload, JWTClaimVerificationOptions, JWSHeaderParameters, GetKeyFunction, FlattenedJWSInput, JWTVerifyResult } from '../types';
interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOptions {

@@ -3,0 +3,0 @@ }

@@ -1,2 +0,2 @@

import type { JWTPayload } from '../types.d';
import type { JWTPayload } from '../types';
export default class ProduceJWT {

@@ -3,0 +3,0 @@ protected _payload: JWTPayload;

@@ -31,2 +31,3 @@ /// <reference lib="dom"/>

x5u?: string
[propName: string]: unknown
}

@@ -60,2 +61,3 @@ export interface GetKeyFunction<T, T2> {

x5u?: string
jku?: string
jwk?: Pick<JWK, 'kty' | 'crv' | 'x' | 'y' | 'e' | 'n'>

@@ -62,0 +64,0 @@ typ?: string

@@ -1,2 +0,2 @@

import type { JWSHeaderParameters, JWEHeaderParameters } from '../types.d';
import type { JWSHeaderParameters, JWEHeaderParameters } from '../types';
export declare type ProtectedHeaderParameters = JWSHeaderParameters & JWEHeaderParameters;

@@ -3,0 +3,0 @@ declare function decodeProtectedHeader(token: string | object): ProtectedHeaderParameters;

@@ -1,2 +0,2 @@

import type { KeyLike } from '../types.js';
import type { KeyLike } from '../types';
export interface GenerateKeyPairOptions {

@@ -3,0 +3,0 @@ crv?: string;

@@ -1,2 +0,2 @@

import type { KeyLike } from '../types.d';
import type { KeyLike } from '../types';
export interface GenerateSecretOptions {

@@ -3,0 +3,0 @@ extractable?: boolean;

{
"name": "jose-browser-runtime",
"version": "3.13.0",
"version": "3.14.0",
"description": "(Browser Runtime) 'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK with no dependencies",

@@ -5,0 +5,0 @@ "keywords": [

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