Edit: /tmp/tsx-0/17887-a161268cc93a99ef993812591a2ffc76db0fa844 (9951B)
{"code":"__filename=\"/opt/canhelp/node_modules/jose/dist/webapi/jwe/flattened/encrypt.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 encrypt_exports={};__export(encrypt_exports,{FlattenedEncrypt:()=>FlattenedEncrypt});module.exports=__toCommonJS(encrypt_exports);var import_base64url=require(\"../../util/base64url.js\");var import_helpers=require(\"../../lib/helpers.js\");var import_content_encryption=require(\"../../lib/content_encryption.js\");var import_key_management=require(\"../../lib/key_management.js\");var import_errors=require(\"../../util/errors.js\");var import_type_checks=require(\"../../lib/type_checks.js\");var import_buffer_utils=require(\"../../lib/buffer_utils.js\");var import_validate_crit=require(\"../../lib/validate_crit.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\");class FlattenedEncrypt{static{__name(this,\"FlattenedEncrypt\")}#plaintext;#protectedHeader;#sharedUnprotectedHeader;#unprotectedHeader;#aad;#cek;#iv;#keyManagementParameters;constructor(plaintext){if(!(plaintext instanceof Uint8Array)){throw new TypeError(\"plaintext must be an instance of Uint8Array\")}this.#plaintext=plaintext}setKeyManagementParameters(parameters){(0,import_helpers.assertNotSet)(this.#keyManagementParameters,\"setKeyManagementParameters\");this.#keyManagementParameters=parameters;return this}setProtectedHeader(protectedHeader){(0,import_helpers.assertNotSet)(this.#protectedHeader,\"setProtectedHeader\");this.#protectedHeader=protectedHeader;return this}setSharedUnprotectedHeader(sharedUnprotectedHeader){(0,import_helpers.assertNotSet)(this.#sharedUnprotectedHeader,\"setSharedUnprotectedHeader\");this.#sharedUnprotectedHeader=sharedUnprotectedHeader;return this}setUnprotectedHeader(unprotectedHeader){(0,import_helpers.assertNotSet)(this.#unprotectedHeader,\"setUnprotectedHeader\");this.#unprotectedHeader=unprotectedHeader;return this}setAdditionalAuthenticatedData(aad){this.#aad=aad;return this}setContentEncryptionKey(cek){(0,import_helpers.assertNotSet)(this.#cek,\"setContentEncryptionKey\");this.#cek=cek;return this}setInitializationVector(iv){(0,import_helpers.assertNotSet)(this.#iv,\"setInitializationVector\");this.#iv=iv;return this}async encrypt(key,options){if(!this.#protectedHeader&&!this.#unprotectedHeader&&!this.#sharedUnprotectedHeader){throw new import_errors.JWEInvalid(\"either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()\")}if(!(0,import_type_checks.isDisjoint)(this.#protectedHeader,this.#unprotectedHeader,this.#sharedUnprotectedHeader)){throw new import_errors.JWEInvalid(\"JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint\")}const joseHeader={...this.#protectedHeader,...this.#unprotectedHeader,...this.#sharedUnprotectedHeader};(0,import_validate_crit.validateCrit)(import_errors.JWEInvalid,new Map,options?.crit,this.#protectedHeader,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&&!this.#protectedHeader?.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('JWE \"alg\" (Algorithm) Header Parameter missing or invalid')}if(typeof enc!==\"string\"||!enc){throw new import_errors.JWEInvalid('JWE \"enc\" (Encryption Algorithm) Header Parameter missing or invalid')}let encryptedKey;if(this.#cek&&(alg===\"dir\"||alg===\"ECDH-ES\")){throw new TypeError(`setContentEncryptionKey cannot be called with JWE \"alg\" (Algorithm) Header ${alg}`)}(0,import_check_key_type.checkKeyType)(alg===\"dir\"?enc:alg,key,\"encrypt\");let cek;{let parameters;const k=await(0,import_normalize_key.normalizeKey)(key,alg);({cek,encryptedKey,parameters}=await(0,import_key_management.encryptKeyManagement)(alg,enc,k,this.#cek,this.#keyManagementParameters));if(parameters){if(options&&import_helpers.unprotected in options){if(!this.#unprotectedHeader){this.setUnprotectedHeader(parameters)}else{this.#unprotectedHeader={...this.#unprotectedHeader,...parameters}}}else if(!this.#protectedHeader){this.setProtectedHeader(parameters)}else{this.#protectedHeader={...this.#protectedHeader,...parameters}}}}let additionalData;let protectedHeaderS;let protectedHeaderB;let aadMember;if(this.#protectedHeader){protectedHeaderS=(0,import_base64url.encode)(JSON.stringify(this.#protectedHeader));protectedHeaderB=(0,import_buffer_utils.encode)(protectedHeaderS)}else{protectedHeaderS=\"\";protectedHeaderB=new Uint8Array}if(this.#aad){aadMember=(0,import_base64url.encode)(this.#aad);const aadMemberBytes=(0,import_buffer_utils.encode)(aadMember);additionalData=(0,import_buffer_utils.concat)(protectedHeaderB,(0,import_buffer_utils.encode)(\".\"),aadMemberBytes)}else{additionalData=protectedHeaderB}let plaintext=this.#plaintext;if(joseHeader.zip===\"DEF\"){plaintext=await(0,import_deflate.compress)(plaintext).catch(cause=>{throw new import_errors.JWEInvalid(\"Failed to compress plaintext\",{cause})})}const{ciphertext,tag,iv}=await(0,import_content_encryption.encrypt)(enc,plaintext,cek,this.#iv,additionalData);const jwe={ciphertext:(0,import_base64url.encode)(ciphertext)};if(iv){jwe.iv=(0,import_base64url.encode)(iv)}if(tag){jwe.tag=(0,import_base64url.encode)(tag)}if(encryptedKey){jwe.encrypted_key=(0,import_base64url.encode)(encryptedKey)}if(aadMember){jwe.aad=aadMember}if(this.#protectedHeader){jwe.protected=protectedHeaderS}if(this.#sharedUnprotectedHeader){jwe.unprotected=this.#sharedUnprotectedHeader}if(this.#unprotectedHeader){jwe.header=this.#unprotectedHeader}return jwe}}0&&(module.exports={FlattenedEncrypt});\n})()\n","warnings":[],"map":{"version":3,"mappings":";suBAAA,2JAA+B,mCAC/B,mBAA0C,gCAC1C,8BAAwB,2CACxB,0BAAqC,uCACrC,kBAA6C,gCAC7C,uBAA2B,oCAC3B,wBAA+B,qCAC/B,yBAA6B,sCAC7B,yBAA6B,sCAC7B,0BAA6B,uCAC7B,mBAAyB,gCAClB,MAAM,gBAAiB,CAX9B,MAW8B,iCAC1B,WACA,iBACA,yBACA,mBACA,KACA,KACA,IACA,yBACA,YAAY,UAAW,CACnB,GAAI,EAAE,qBAAqB,YAAa,CACpC,MAAM,IAAI,UAAU,6CAA6C,CACrE,CACA,KAAK,WAAa,SACtB,CACA,2BAA2B,WAAY,IACnC,6BAAa,KAAK,yBAA0B,4BAA4B,EACxE,KAAK,yBAA2B,WAChC,OAAO,IACX,CACA,mBAAmB,gBAAiB,IAChC,6BAAa,KAAK,iBAAkB,oBAAoB,EACxD,KAAK,iBAAmB,gBACxB,OAAO,IACX,CACA,2BAA2B,wBAAyB,IAChD,6BAAa,KAAK,yBAA0B,4BAA4B,EACxE,KAAK,yBAA2B,wBAChC,OAAO,IACX,CACA,qBAAqB,kBAAmB,IACpC,6BAAa,KAAK,mBAAoB,sBAAsB,EAC5D,KAAK,mBAAqB,kBAC1B,OAAO,IACX,CACA,+BAA+B,IAAK,CAChC,KAAK,KAAO,IACZ,OAAO,IACX,CACA,wBAAwB,IAAK,IACzB,6BAAa,KAAK,KAAM,yBAAyB,EACjD,KAAK,KAAO,IACZ,OAAO,IACX,CACA,wBAAwB,GAAI,IACxB,6BAAa,KAAK,IAAK,yBAAyB,EAChD,KAAK,IAAM,GACX,O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,GAAI,KAAK,yBAA0B,CAC/B,IAAI,YAAc,KAAK,wBAC3B,CACA,GAAI,KAAK,mBAAoB,CACzB,IAAI,OAAS,KAAK,kBACtB,CACA,OAAO,GACX,CACJ","names":["b64u"],"ignoreList":[],"sources":["/opt/canhelp/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js"],"sourcesContent":[null]}}