Edit: /tmp/tsx-0/17887-6684267a217de228e852fa8f2f046b73b7808fae (11718B)
{"code":"__filename=\"/opt/canhelp/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js\";(()=>{\nvar __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,\"name\",{value,configurable:true});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from===\"object\"||typeof from===\"function\"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},\"__esModule\",{value:true}),mod);var decrypt_exports={};__export(decrypt_exports,{flattenedDecrypt:()=>flattenedDecrypt});module.exports=__toCommonJS(decrypt_exports);var import_base64url=require(\"../../util/base64url.js\");var import_content_encryption=require(\"../../lib/content_encryption.js\");var import_helpers=require(\"../../lib/helpers.js\");var import_errors=require(\"../../util/errors.js\");var import_type_checks=require(\"../../lib/type_checks.js\");var import_type_checks2=require(\"../../lib/type_checks.js\");var import_key_management=require(\"../../lib/key_management.js\");var import_buffer_utils=require(\"../../lib/buffer_utils.js\");var import_content_encryption2=require(\"../../lib/content_encryption.js\");var import_validate_crit=require(\"../../lib/validate_crit.js\");var import_validate_algorithms=require(\"../../lib/validate_algorithms.js\");var import_normalize_key=require(\"../../lib/normalize_key.js\");var import_check_key_type=require(\"../../lib/check_key_type.js\");var import_deflate=require(\"../../lib/deflate.js\");async function flattenedDecrypt(jwe,key,options){if(!(0,import_type_checks2.isObject)(jwe)){throw new import_errors.JWEInvalid(\"Flattened JWE must be an object\")}if(jwe.protected===void 0&&jwe.header===void 0&&jwe.unprotected===void 0){throw new import_errors.JWEInvalid(\"JOSE Header missing\")}if(jwe.iv!==void 0&&typeof jwe.iv!==\"string\"){throw new import_errors.JWEInvalid(\"JWE Initialization Vector incorrect type\")}if(typeof jwe.ciphertext!==\"string\"){throw new import_errors.JWEInvalid(\"JWE Ciphertext missing or incorrect type\")}if(jwe.tag!==void 0&&typeof jwe.tag!==\"string\"){throw new import_errors.JWEInvalid(\"JWE Authentication Tag incorrect type\")}if(jwe.protected!==void 0&&typeof jwe.protected!==\"string\"){throw new import_errors.JWEInvalid(\"JWE Protected Header incorrect type\")}if(jwe.encrypted_key!==void 0&&typeof jwe.encrypted_key!==\"string\"){throw new import_errors.JWEInvalid(\"JWE Encrypted Key incorrect type\")}if(jwe.aad!==void 0&&typeof jwe.aad!==\"string\"){throw new import_errors.JWEInvalid(\"JWE AAD incorrect type\")}if(jwe.header!==void 0&&!(0,import_type_checks2.isObject)(jwe.header)){throw new import_errors.JWEInvalid(\"JWE Shared Unprotected Header incorrect type\")}if(jwe.unprotected!==void 0&&!(0,import_type_checks2.isObject)(jwe.unprotected)){throw new import_errors.JWEInvalid(\"JWE Per-Recipient Unprotected Header incorrect type\")}let parsedProt;if(jwe.protected){try{const protectedHeader2=(0,import_base64url.decode)(jwe.protected);parsedProt=JSON.parse(import_buffer_utils.decoder.decode(protectedHeader2))}catch{throw new import_errors.JWEInvalid(\"JWE Protected Header is invalid\")}}if(!(0,import_type_checks.isDisjoint)(parsedProt,jwe.header,jwe.unprotected)){throw new import_errors.JWEInvalid(\"JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint\")}const joseHeader={...parsedProt,...jwe.header,...jwe.unprotected};(0,import_validate_crit.validateCrit)(import_errors.JWEInvalid,new Map,options?.crit,parsedProt,joseHeader);if(joseHeader.zip!==void 0&&joseHeader.zip!==\"DEF\"){throw new import_errors.JOSENotSupported('Unsupported JWE \"zip\" (Compression Algorithm) Header Parameter value.')}if(joseHeader.zip!==void 0&&!parsedProt?.zip){throw new import_errors.JWEInvalid('JWE \"zip\" (Compression Algorithm) Header Parameter MUST be in a protected header.')}const{alg,enc}=joseHeader;if(typeof alg!==\"string\"||!alg){throw new import_errors.JWEInvalid(\"missing JWE Algorithm (alg) in JWE Header\")}if(typeof enc!==\"string\"||!enc){throw new import_errors.JWEInvalid(\"missing JWE Encryption Algorithm (enc) in JWE Header\")}const keyManagementAlgorithms=options&&(0,import_validate_algorithms.validateAlgorithms)(\"keyManagementAlgorithms\",options.keyManagementAlgorithms);const contentEncryptionAlgorithms=options&&(0,import_validate_algorithms.validateAlgorithms)(\"contentEncryptionAlgorithms\",options.contentEncryptionAlgorithms);if(keyManagementAlgorithms&&!keyManagementAlgorithms.has(alg)||!keyManagementAlgorithms&&alg.startsWith(\"PBES2\")){throw new import_errors.JOSEAlgNotAllowed('\"alg\" (Algorithm) Header Parameter value not allowed')}if(contentEncryptionAlgorithms&&!contentEncryptionAlgorithms.has(enc)){throw new import_errors.JOSEAlgNotAllowed('\"enc\" (Encryption Algorithm) Header Parameter value not allowed')}let encryptedKey;if(jwe.encrypted_key!==void 0){encryptedKey=(0,import_helpers.decodeBase64url)(jwe.encrypted_key,\"encrypted_key\",import_errors.JWEInvalid)}let resolvedKey=false;if(typeof key===\"function\"){key=await key(parsedProt,jwe);resolvedKey=true}(0,import_check_key_type.checkKeyType)(alg===\"dir\"?enc:alg,key,\"decrypt\");const k=await(0,import_normalize_key.normalizeKey)(key,alg);let cek;try{cek=await(0,import_key_management.decryptKeyManagement)(alg,k,encryptedKey,joseHeader,options)}catch(err){if(err instanceof TypeError||err instanceof import_errors.JWEInvalid||err instanceof import_errors.JOSENotSupported){throw err}cek=(0,import_content_encryption2.generateCek)(enc)}let iv;let tag;if(jwe.iv!==void 0){iv=(0,import_helpers.decodeBase64url)(jwe.iv,\"iv\",import_errors.JWEInvalid)}if(jwe.tag!==void 0){tag=(0,import_helpers.decodeBase64url)(jwe.tag,\"tag\",import_errors.JWEInvalid)}const protectedHeader=jwe.protected!==void 0?(0,import_buffer_utils.encode)(jwe.protected):new Uint8Array;let additionalData;if(jwe.aad!==void 0){additionalData=(0,import_buffer_utils.concat)(protectedHeader,(0,import_buffer_utils.encode)(\".\"),(0,import_buffer_utils.encode)(jwe.aad))}else{additionalData=protectedHeader}const ciphertext=(0,import_helpers.decodeBase64url)(jwe.ciphertext,\"ciphertext\",import_errors.JWEInvalid);const plaintext=await(0,import_content_encryption.decrypt)(enc,cek,ciphertext,iv,tag,additionalData);const result={plaintext};if(joseHeader.zip===\"DEF\"){const maxDecompressedLength=options?.maxDecompressedLength??25e4;if(maxDecompressedLength===0){throw new import_errors.JOSENotSupported('JWE \"zip\" (Compression Algorithm) Header Parameter is not supported.')}if(maxDecompressedLength!==Infinity&&(!Number.isSafeInteger(maxDecompressedLength)||maxDecompressedLength<1)){throw new TypeError(\"maxDecompressedLength must be 0, a positive safe integer, or Infinity\")}result.plaintext=await(0,import_deflate.decompress)(plaintext,maxDecompressedLength).catch(cause=>{if(cause instanceof import_errors.JWEInvalid)throw cause;throw new import_errors.JWEInvalid(\"Failed to decompress plaintext\",{cause})})}if(jwe.protected!==void 0){result.protectedHeader=parsedProt}if(jwe.aad!==void 0){result.additionalAuthenticatedData=(0,import_helpers.decodeBase64url)(jwe.aad,\"aad\",import_errors.JWEInvalid)}if(jwe.unprotected!==void 0){result.sharedUnprotectedHeader=jwe.unprotected}if(jwe.header!==void 0){result.unprotectedHeader=jwe.header}if(resolvedKey){return{...result,key:k}}return result}__name(flattenedDecrypt,\"flattenedDecrypt\");0&&(module.exports={flattenedDecrypt});\n})()\n","warnings":[],"map":{"version":3,"mappings":";suBAAA,2JAA+B,mCAC/B,8BAAwB,2CACxB,mBAAgC,gCAChC,kBAAgE,gCAChE,uBAA2B,oCAC3B,IAAAA,oBAAyB,oCACzB,0BAAqC,uCACrC,wBAAwC,qCACxC,IAAAC,2BAA4B,2CAC5B,yBAA6B,sCAC7B,+BAAmC,4CACnC,yBAA6B,sCAC7B,0BAA6B,uCAC7B,mBAA2B,gCAC3B,e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gCAAgB,IAAI,IAAK,MAAO,wBAAU,CACnF,CACA,GAAI,IAAI,cAAgB,OAAW,CAC/B,OAAO,wBAA0B,IAAI,WACzC,CACA,GAAI,IAAI,SAAW,OAAW,CAC1B,OAAO,kBAAoB,IAAI,MACnC,CACA,GAAI,YAAa,CACb,MAAO,CAAE,GAAG,OAAQ,IAAK,CAAE,CAC/B,CACA,OAAO,MACX,CAhJsB","names":["import_type_checks","import_content_encryption","protectedHeader","b64u"],"ignoreList":[],"sources":["/opt/canhelp/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js"],"sourcesContent":[null]}}