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

jose-node-esm-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-node-esm-runtime - npm Package Compare versions

Comparing version 4.2.1 to 4.3.0

55

dist/node/esm/jwe/general/encrypt.js

@@ -8,12 +8,24 @@ import { FlattenedEncrypt, unprotected } from '../flattened/encrypt.js';

import validateCrit from '../../lib/validate_crit.js';
const recipientRef = new WeakMap();
class IndividualRecipient {
constructor(enc, key, options) {
this.parent = enc;
this.key = key;
this.options = options;
}
setUnprotectedHeader(unprotectedHeader) {
const ref = recipientRef.get(this);
if (ref.unprotectedHeader) {
if (this.unprotectedHeader) {
throw new TypeError('setUnprotectedHeader can only be called once');
}
ref.unprotectedHeader = unprotectedHeader;
this.unprotectedHeader = unprotectedHeader;
return this;
}
addRecipient(...args) {
return this.parent.addRecipient(...args);
}
encrypt(...args) {
return this.parent.encrypt(...args);
}
done() {
return this.parent;
}
}

@@ -26,4 +38,3 @@ export class GeneralEncrypt {

addRecipient(key, options) {
const recipient = new IndividualRecipient();
recipientRef.set(recipient, { key, options: { crit: options === null || options === void 0 ? void 0 : options.crit } });
const recipient = new IndividualRecipient(this, key, { crit: options === null || options === void 0 ? void 0 : options.crit });
this._recipients.push(recipient);

@@ -51,3 +62,3 @@ return recipient;

async encrypt(options) {
var _a, _b;
var _a, _b, _c;
if (!this._recipients.length) {

@@ -58,3 +69,3 @@ throw new JWEInvalid('at least one recipient must be added');

if (this._recipients.length === 1) {
const { unprotectedHeader, options: recipientOpts, key, } = recipientRef.get(this._recipients[0]);
const [recipient] = this._recipients;
const flattened = await new FlattenedEncrypt(this._plaintext)

@@ -64,4 +75,4 @@ .setAdditionalAuthenticatedData(this._aad)

.setSharedUnprotectedHeader(this._unprotectedHeader)
.setUnprotectedHeader(unprotectedHeader)
.encrypt(key, { ...recipientOpts, ...options });
.setUnprotectedHeader(recipient.unprotectedHeader)
.encrypt(recipient.key, { ...recipient.options, ...options });
let jwe = {

@@ -88,4 +99,3 @@ ciphertext: flattened.ciphertext,

const recipient = this._recipients[i];
const { unprotectedHeader, options: recipientOpts } = recipientRef.get(recipient);
if (!isDisjoint(this._protectedHeader, this._unprotectedHeader, unprotectedHeader)) {
if (!isDisjoint(this._protectedHeader, this._unprotectedHeader, recipient.unprotectedHeader)) {
throw new JWEInvalid('JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint');

@@ -96,3 +106,3 @@ }

...this._unprotectedHeader,
...unprotectedHeader,
...recipient.unprotectedHeader,
};

@@ -115,3 +125,3 @@ const { alg } = joseHeader;

}
validateCrit(JWEInvalid, new Map(), recipientOpts === null || recipientOpts === void 0 ? void 0 : recipientOpts.crit, this._protectedHeader, joseHeader);
validateCrit(JWEInvalid, new Map(), recipient.options.crit, this._protectedHeader, joseHeader);
if (joseHeader.zip !== undefined) {

@@ -134,3 +144,2 @@ if (!this._protectedHeader || !this._protectedHeader.zip) {

jwe.recipients.push(target);
const { unprotectedHeader, options: recipientOpts, key } = recipientRef.get(recipient);
if (i === 0) {

@@ -142,4 +151,8 @@ const flattened = await new FlattenedEncrypt(this._plaintext)

.setSharedUnprotectedHeader(this._unprotectedHeader)
.setUnprotectedHeader(unprotectedHeader)
.encrypt(key, { ...recipientOpts, ...options, [unprotected]: true });
.setUnprotectedHeader(recipient.unprotectedHeader)
.encrypt(recipient.key, {
...recipient.options,
...options,
[unprotected]: true,
});
jwe.ciphertext = flattened.ciphertext;

@@ -159,6 +172,8 @@ jwe.iv = flattened.iv;

}
const { encryptedKey, parameters } = await encryptKeyManagement((unprotectedHeader === null || unprotectedHeader === void 0 ? void 0 : unprotectedHeader.alg) || ((_a = this._protectedHeader) === null || _a === void 0 ? void 0 : _a.alg) || ((_b = this._unprotectedHeader) === null || _b === void 0 ? void 0 : _b.alg), enc, key, cek);
const { encryptedKey, parameters } = await encryptKeyManagement(((_a = recipient.unprotectedHeader) === null || _a === void 0 ? void 0 : _a.alg) ||
((_b = this._protectedHeader) === null || _b === void 0 ? void 0 : _b.alg) ||
((_c = this._unprotectedHeader) === null || _c === void 0 ? void 0 : _c.alg), enc, recipient.key, cek);
target.encrypted_key = base64url(encryptedKey);
if (unprotectedHeader || parameters)
target.header = { ...unprotectedHeader, ...parameters };
if (recipient.unprotectedHeader || parameters)
target.header = { ...recipient.unprotectedHeader, ...parameters };
}

@@ -165,0 +180,0 @@ return jwe;

import { FlattenedSign } from '../flattened/sign.js';
import { JWSInvalid } from '../../util/errors.js';
const signatureRef = new WeakMap();
class IndividualSignature {
constructor(sig, key, options) {
this.parent = sig;
this.key = key;
this.options = options;
}
setProtectedHeader(protectedHeader) {
const ref = signatureRef.get(this);
if (ref.protectedHeader) {
if (this.protectedHeader) {
throw new TypeError('setProtectedHeader can only be called once');
}
ref.protectedHeader = protectedHeader;
this.protectedHeader = protectedHeader;
return this;
}
setUnprotectedHeader(unprotectedHeader) {
const ref = signatureRef.get(this);
if (ref.unprotectedHeader) {
if (this.unprotectedHeader) {
throw new TypeError('setUnprotectedHeader can only be called once');
}
ref.unprotectedHeader = unprotectedHeader;
this.unprotectedHeader = unprotectedHeader;
return this;
}
addSignature(...args) {
return this.parent.addSignature(...args);
}
sign(...args) {
return this.parent.sign(...args);
}
done() {
return this.parent;
}
}

@@ -28,4 +39,3 @@ export class GeneralSign {

addSignature(key, options) {
const signature = new IndividualSignature();
signatureRef.set(signature, { key, options });
const signature = new IndividualSignature(this, key, options);
this._signatures.push(signature);

@@ -42,19 +52,15 @@ return signature;

};
let payloads = new Set();
await Promise.all(this._signatures.map(async (sig) => {
const { protectedHeader, unprotectedHeader, options, key } = signatureRef.get(sig);
for (let i = 0; i < this._signatures.length; i++) {
const signature = this._signatures[i];
const flattened = new FlattenedSign(this._payload);
if (protectedHeader) {
flattened.setProtectedHeader(protectedHeader);
flattened.setProtectedHeader(signature.protectedHeader);
flattened.setUnprotectedHeader(signature.unprotectedHeader);
const { payload, ...rest } = await flattened.sign(signature.key, signature.options);
if (i === 0) {
jws.payload = payload;
}
if (unprotectedHeader) {
flattened.setUnprotectedHeader(unprotectedHeader);
else if (jws.payload !== payload) {
throw new JWSInvalid('inconsistent use of JWS Unencoded Payload Option (RFC7797)');
}
const { payload, ...rest } = await flattened.sign(key, options);
payloads.add(payload);
jws.payload = payload;
jws.signatures.push(rest);
}));
if (payloads.size !== 1) {
throw new JWSInvalid('inconsistent use of JWS Unencoded Payload Option (RFC7797)');
}

@@ -61,0 +67,0 @@ return jws;

import type { KeyLike, GeneralJWE, JWEHeaderParameters, CritOption, DeflateOption } from '../../types';
export interface Recipient {
setUnprotectedHeader(unprotectedHeader: JWEHeaderParameters): Recipient;
addRecipient(...args: Parameters<GeneralEncrypt['addRecipient']>): Recipient;
encrypt(...args: Parameters<GeneralEncrypt['encrypt']>): Promise<GeneralJWE>;
done(): GeneralEncrypt;
}

@@ -5,0 +8,0 @@ export declare class GeneralEncrypt {

@@ -5,2 +5,5 @@ import type { KeyLike, GeneralJWS, JWSHeaderParameters, SignOptions } from '../../types';

setUnprotectedHeader(unprotectedHeader: JWSHeaderParameters): Signature;
addSignature(...args: Parameters<GeneralSign['addSignature']>): Signature;
sign(...args: Parameters<GeneralSign['sign']>): Promise<GeneralJWS>;
done(): GeneralSign;
}

@@ -7,0 +10,0 @@ export declare class GeneralSign {

@@ -38,4 +38,2 @@ /**

* ```js
* import { importSPKI } from 'jose'
*
* const algorithm = 'ES256'

@@ -46,3 +44,3 @@ * const spki = `-----BEGIN PUBLIC KEY-----

* -----END PUBLIC KEY-----`
* const ecPublicKey = await importSPKI(spki, algorithm)
* const ecPublicKey = await jose.importSPKI(spki, algorithm)
* ```

@@ -52,4 +50,2 @@ *

* ```js
* import { importX509 } from 'jose'
*
* const algorithm = 'ES256'

@@ -66,3 +62,3 @@ * const x509 = `-----BEGIN CERTIFICATE-----

* -----END CERTIFICATE-----`
* const ecPublicKey = await importX509(x509, algorithm)
* const ecPublicKey = await jose.importX509(x509, algorithm)
* ```

@@ -72,4 +68,2 @@ *

* ```js
* import { importPKCS8 } from 'jose'
*
* const algorithm = 'ES256'

@@ -81,3 +75,3 @@ * const pkcs8 = `-----BEGIN PRIVATE KEY-----

* -----END PRIVATE KEY-----`
* const ecPrivateKey = await importPKCS8(pkcs8, algorithm)
* const ecPrivateKey = await jose.importPKCS8(pkcs8, algorithm)
* ```

@@ -87,5 +81,3 @@ *

* ```js
* import { importJWK } from 'jose'
*
* const ecPublicKey = await importJWK({
* const ecPublicKey = await jose.importJWK({
* crv: 'P-256',

@@ -97,3 +89,3 @@ * kty: 'EC',

*
* const rsaPublicKey = await importJWK({
* const rsaPublicKey = await jose.importJWK({
* kty: 'RSA',

@@ -100,0 +92,0 @@ * e: 'AQAB',

{
"name": "jose-node-esm-runtime",
"version": "4.2.1",
"description": "(Node.JS ESM Runtime) 'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto",
"keywords": [
"compact",
"decode",
"decrypt",
"detached",
"ec",
"ecdsa",
"eddsa",
"electron",
"embedded",
"encrypt",
"flattened",
"general",
"jose",
"json web token",
"jsonwebtoken",
"jwa",
"jwe",
"jwk",
"jwks",
"jws",
"jwt",
"oct",
"okp",
"payload",
"pem",
"pkcs8",
"rsa",
"secp256k1",
"sign",
"signature",
"spki",
"validate",
"verify",
"x509"
],
"version": "4.3.0",
"homepage": "https://github.com/panva/jose",

@@ -67,7 +30,7 @@ "repository": "panva/jose",

"!dist/types/lib/*",
"!dist/**/package.json",
"!dist/browser/**/*",
"!dist/node/cjs/**/*",
"!dist/**/package.json"
"!dist/node/cjs/**/*"
],
"type": "module"
}
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