jose-browser-runtime
Advanced tools
Comparing version 4.2.0 to 4.2.1
@@ -11,14 +11,9 @@ import { FlattenedEncrypt, unprotected } from '../flattened/encrypt.js'; | ||
setUnprotectedHeader(unprotectedHeader) { | ||
if (this._unprotectedHeader) { | ||
const ref = recipientRef.get(this); | ||
if (ref.unprotectedHeader) { | ||
throw new TypeError('setUnprotectedHeader can only be called once'); | ||
} | ||
this._unprotectedHeader = unprotectedHeader; | ||
ref.unprotectedHeader = unprotectedHeader; | ||
return this; | ||
} | ||
set _unprotectedHeader(value) { | ||
recipientRef.get(this).unprotectedHeader = value; | ||
} | ||
get _unprotectedHeader() { | ||
return recipientRef.get(this).unprotectedHeader; | ||
} | ||
} | ||
@@ -25,0 +20,0 @@ export class GeneralEncrypt { |
@@ -6,27 +6,17 @@ import { FlattenedSign } from '../flattened/sign.js'; | ||
setProtectedHeader(protectedHeader) { | ||
if (this._protectedHeader) { | ||
const ref = signatureRef.get(this); | ||
if (ref.protectedHeader) { | ||
throw new TypeError('setProtectedHeader can only be called once'); | ||
} | ||
this._protectedHeader = protectedHeader; | ||
ref.protectedHeader = protectedHeader; | ||
return this; | ||
} | ||
setUnprotectedHeader(unprotectedHeader) { | ||
if (this._unprotectedHeader) { | ||
const ref = signatureRef.get(this); | ||
if (ref.unprotectedHeader) { | ||
throw new TypeError('setUnprotectedHeader can only be called once'); | ||
} | ||
this._unprotectedHeader = unprotectedHeader; | ||
ref.unprotectedHeader = unprotectedHeader; | ||
return this; | ||
} | ||
set _protectedHeader(value) { | ||
signatureRef.get(this).protectedHeader = value; | ||
} | ||
get _protectedHeader() { | ||
return signatureRef.get(this).protectedHeader; | ||
} | ||
set _unprotectedHeader(value) { | ||
signatureRef.get(this).unprotectedHeader = value; | ||
} | ||
get _unprotectedHeader() { | ||
return signatureRef.get(this).unprotectedHeader; | ||
} | ||
} | ||
@@ -33,0 +23,0 @@ export class GeneralSign { |
@@ -5,2 +5,7 @@ import { JOSENotSupported } from '../util/errors.js'; | ||
switch (alg) { | ||
case 'A128GCM': | ||
return 128; | ||
case 'A192GCM': | ||
return 192; | ||
case 'A256GCM': | ||
case 'A128CBC-HS256': | ||
@@ -12,8 +17,2 @@ return 256; | ||
return 512; | ||
case 'A128GCM': | ||
return 128; | ||
case 'A192GCM': | ||
return 192; | ||
case 'A256GCM': | ||
return 256; | ||
default: | ||
@@ -20,0 +19,0 @@ throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`); |
@@ -43,3 +43,3 @@ import { unwrap as aesKw } from '../runtime/aeskw.js'; | ||
} | ||
const sharedSecret = await ECDH.deriveKey(epk, key, alg === 'ECDH-ES' ? joseHeader.enc : alg, parseInt(alg.substr(-5, 3), 10) || cekLength(joseHeader.enc), partyUInfo, partyVInfo); | ||
const sharedSecret = await ECDH.deriveKey(epk, key, alg === 'ECDH-ES' ? joseHeader.enc : alg, alg === 'ECDH-ES' ? cekLength(joseHeader.enc) : parseInt(alg.substr(-5, 3), 10), partyUInfo, partyVInfo); | ||
if (alg === 'ECDH-ES') | ||
@@ -46,0 +46,0 @@ return sharedSecret; |
@@ -32,3 +32,3 @@ import { wrap as aesKw } from '../runtime/aeskw.js'; | ||
const { x, y, crv, kty } = await exportJWK(ephemeralKey); | ||
const sharedSecret = await ECDH.deriveKey(key, ephemeralKey, alg === 'ECDH-ES' ? enc : alg, parseInt(alg.substr(-5, 3), 10) || cekLength(enc), apu, apv); | ||
const sharedSecret = await ECDH.deriveKey(key, ephemeralKey, alg === 'ECDH-ES' ? enc : alg, alg === 'ECDH-ES' ? cekLength(enc) : parseInt(alg.substr(-5, 3), 10), apu, apv); | ||
parameters = { epk: { x, y, crv, kty } }; | ||
@@ -35,0 +35,0 @@ if (apu) |
@@ -5,20 +5,13 @@ import { JOSENotSupported } from '../util/errors.js'; | ||
switch (alg) { | ||
case 'A128CBC-HS256': | ||
return 128; | ||
case 'A128GCM': | ||
return 96; | ||
case 'A128GCMKW': | ||
return 96; | ||
case 'A192CBC-HS384': | ||
return 128; | ||
case 'A192GCM': | ||
return 96; | ||
case 'A192GCMKW': | ||
case 'A256GCM': | ||
case 'A256GCMKW': | ||
return 96; | ||
case 'A128CBC-HS256': | ||
case 'A192CBC-HS384': | ||
case 'A256CBC-HS512': | ||
return 128; | ||
case 'A256GCM': | ||
return 96; | ||
case 'A256GCMKW': | ||
return 96; | ||
default: | ||
@@ -25,0 +18,0 @@ throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`); |
@@ -5,2 +5,3 @@ import bogusWebCrypto from './bogus.js'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
function checkKeySize(key, alg) { | ||
@@ -19,3 +20,3 @@ if (key.algorithm.length !== parseInt(alg.substr(1, 3), 10)) { | ||
} | ||
throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array')); | ||
} | ||
@@ -22,0 +23,0 @@ export const wrap = async (alg, key, cek) => { |
@@ -7,5 +7,6 @@ import { isCloudflareWorkers, isNodeJs } from './env.js'; | ||
import { JOSENotSupported } from '../util/errors.js'; | ||
import { types } from './is_key_like.js'; | ||
const genericExport = async (keyType, keyFormat, key) => { | ||
if (!isCryptoKey(key)) { | ||
throw new TypeError(invalidKeyInput(key, 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(key, ...types)); | ||
} | ||
@@ -12,0 +13,0 @@ if (!key.extractable) { |
@@ -9,2 +9,3 @@ import { concat, uint64be } from '../lib/buffer_utils.js'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) { | ||
@@ -65,3 +66,3 @@ if (!(cek instanceof Uint8Array)) { | ||
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) { | ||
throw new TypeError(invalidKeyInput(cek, 'CryptoKey', 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(cek, ...types, 'Uint8Array')); | ||
} | ||
@@ -68,0 +69,0 @@ checkIvLength(enc, iv); |
@@ -6,9 +6,10 @@ import { encoder, concat, uint32be, lengthAndInput, concatKdf } from '../lib/buffer_utils.js'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
export const deriveKey = async (publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) => { | ||
if (!isCryptoKey(publicKey)) { | ||
throw new TypeError(invalidKeyInput(publicKey, 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(publicKey, ...types)); | ||
} | ||
checkEncCryptoKey(publicKey, 'ECDH-ES'); | ||
if (!isCryptoKey(privateKey)) { | ||
throw new TypeError(invalidKeyInput(privateKey, 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(privateKey, ...types)); | ||
} | ||
@@ -29,3 +30,3 @@ checkEncCryptoKey(privateKey, 'ECDH-ES', 'deriveBits', 'deriveKey'); | ||
if (!isCryptoKey(key)) { | ||
throw new TypeError(invalidKeyInput(key, 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(key, ...types)); | ||
} | ||
@@ -36,5 +37,5 @@ return (await crypto.subtle.generateKey({ name: 'ECDH', namedCurve: key.algorithm.namedCurve }, true, ['deriveBits'])).privateKey; | ||
if (!isCryptoKey(key)) { | ||
throw new TypeError(invalidKeyInput(key, 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(key, ...types)); | ||
} | ||
return ['P-256', 'P-384', 'P-521'].includes(key.algorithm.namedCurve); | ||
}; |
@@ -8,2 +8,3 @@ import { concat, uint64be } from '../lib/buffer_utils.js'; | ||
import { JOSENotSupported } from '../util/errors.js'; | ||
import { types } from './is_key_like.js'; | ||
async function cbcEncrypt(enc, plaintext, cek, iv, aad) { | ||
@@ -48,3 +49,3 @@ if (!(cek instanceof Uint8Array)) { | ||
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) { | ||
throw new TypeError(invalidKeyInput(cek, 'CryptoKey', 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(cek, ...types, 'Uint8Array')); | ||
} | ||
@@ -51,0 +52,0 @@ checkIvLength(enc, iv); |
import crypto, { isCryptoKey } from './webcrypto.js'; | ||
import { checkSigCryptoKey } from '../lib/crypto_key.js'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
export default function getCryptoKey(alg, key, usage) { | ||
@@ -11,7 +12,7 @@ if (isCryptoKey(key)) { | ||
if (!alg.startsWith('HS')) { | ||
throw new TypeError(invalidKeyInput(key, 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(key, ...types)); | ||
} | ||
return crypto.subtle.importKey('raw', key, { hash: `SHA-${alg.substr(-3)}`, name: 'HMAC' }, false, [usage]); | ||
} | ||
throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array')); | ||
} |
import crypto, { isCryptoKey } from './webcrypto.js'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { encode as base64url } from './base64url.js'; | ||
import { types } from './is_key_like.js'; | ||
const keyToJWK = async (key) => { | ||
@@ -12,3 +13,3 @@ if (key instanceof Uint8Array) { | ||
if (!isCryptoKey(key)) { | ||
throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array')); | ||
} | ||
@@ -15,0 +16,0 @@ if (!key.extractable) { |
@@ -9,2 +9,3 @@ import random from './random.js'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
function getCryptoKey(key, alg) { | ||
@@ -18,3 +19,3 @@ if (key instanceof Uint8Array) { | ||
} | ||
throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array')); | ||
} | ||
@@ -21,0 +22,0 @@ async function deriveKey(p2s, alg, p2c, key) { |
@@ -7,5 +7,6 @@ import subtleAlgorithm from './subtle_rsaes.js'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
export const encrypt = async (alg, key, cek) => { | ||
if (!isCryptoKey(key)) { | ||
throw new TypeError(invalidKeyInput(key, 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(key, ...types)); | ||
} | ||
@@ -25,3 +26,3 @@ checkEncCryptoKey(key, alg, 'encrypt', 'wrapKey'); | ||
if (!isCryptoKey(key)) { | ||
throw new TypeError(invalidKeyInput(key, 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(key, ...types)); | ||
} | ||
@@ -28,0 +29,0 @@ checkEncCryptoKey(key, alg, 'decrypt', 'unwrapKey'); |
{ | ||
"name": "jose-browser-runtime", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"description": "(Browser Runtime) 'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
160772
3942