@snyxex/pipex 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/LICENSE +1 -1
- package/README.md +238 -139
- package/dist/compression-B0xKUa-N.d.mts +35 -0
- package/dist/compression-C1nLQVur.d.cts +35 -0
- package/dist/compression-ChJlMVwP.mjs +1 -0
- package/dist/compression-ZHOsKTJC.cjs +1 -0
- package/dist/compression.cjs +1 -0
- package/dist/compression.d.cts +2 -0
- package/dist/compression.d.mts +2 -0
- package/dist/compression.mjs +1 -0
- package/dist/core-DNchiRD5.mjs +2 -0
- package/dist/core-DSIwvTqu.cjs +2 -0
- package/dist/dataEngine-6R3J-WtS.cjs +1 -0
- package/dist/dataEngine-C-xYat2f.d.cts +223 -0
- package/dist/dataEngine-Zap1RwAJ.d.mts +223 -0
- package/dist/dataEngine-raQdutX5.mjs +1 -0
- package/dist/encryption-CCPoyX4q.d.cts +39 -0
- package/dist/encryption-CHvy--rb.mjs +1 -0
- package/dist/encryption-D4eC9ubl.d.mts +39 -0
- package/dist/encryption-DwdO7Y4J.cjs +1 -0
- package/dist/encryption.cjs +1 -0
- package/dist/encryption.d.cts +2 -0
- package/dist/encryption.d.mts +2 -0
- package/dist/encryption.mjs +1 -0
- package/dist/hashing-C6TkcsUE.d.cts +30 -0
- package/dist/hashing-CEwtXh2V.d.mts +30 -0
- package/dist/hashing-DF_guuZf.cjs +1 -0
- package/dist/hashing-DU3rmGMP.mjs +1 -0
- package/dist/hashing.cjs +1 -0
- package/dist/hashing.d.cts +2 -0
- package/dist/hashing.d.mts +2 -0
- package/dist/hashing.mjs +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +285 -0
- package/dist/index.d.mts +143 -623
- package/dist/index.mjs +1 -3
- package/dist/kms.cjs +1 -0
- package/dist/kms.d.cts +3 -0
- package/dist/kms.d.mts +3 -0
- package/dist/kms.mjs +1 -0
- package/dist/kms_encryption-1G54Lcuo.mjs +1 -0
- package/dist/kms_encryption-B07lunjB.cjs +1 -0
- package/dist/kms_encryption-BBIHGi_O.d.cts +30 -0
- package/dist/kms_encryption-BbtS7rXa.d.mts +30 -0
- package/dist/native.cjs +1 -0
- package/dist/native.d.cts +2 -0
- package/dist/native.d.mts +2 -0
- package/dist/native.mjs +1 -0
- package/dist/parallel.cjs +1 -0
- package/dist/parallel.d.cts +2 -0
- package/dist/parallel.d.mts +2 -0
- package/dist/parallel.mjs +1 -0
- package/dist/plugin-D85NMNiy.d.mts +13 -0
- package/dist/plugin-c_iSNY86.d.cts +13 -0
- package/dist/resourceLimits-CpDWwraK.mjs +1 -0
- package/dist/resourceLimits-lJrEhDE5.cjs +1 -0
- package/dist/types-B50Urzn2.d.cts +152 -0
- package/dist/types-B50Urzn2.d.mts +152 -0
- package/dist/validation-BgdV4KdW.cjs +1 -0
- package/dist/validation-BkJxOs7q.mjs +1 -0
- package/dist/validation-hcvcixaS.d.cts +29 -0
- package/dist/validation-xIBvnsSH.d.mts +29 -0
- package/dist/validation.cjs +1 -0
- package/dist/validation.d.cts +2 -0
- package/dist/validation.d.mts +2 -0
- package/dist/validation.mjs +1 -0
- package/dist/worker-1Q2hRcRB.cjs +1 -0
- package/dist/worker-DT7RYWwo.d.cts +34 -0
- package/dist/worker-iSO3KhfN.d.mts +34 -0
- package/dist/worker-ul8lQ0SH.mjs +1 -0
- package/package.json +128 -31
- package/SECURITY.md +0 -41
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/docs/architecture.md +0 -124
- package/docs/encryption-v4-migration.md +0 -45
- package/docs/enterprise.md +0 -280
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EventEmitter as e}from"node:events";import{randomUUID as t}from"node:crypto";import"zod";import{A as n,B as r,C as i,E as a,F as o,H as s,I as c,L as l,N as u,O as d,P as f,R as p,S as m,T as h,U as g,V as _,_ as v,a as y,b,c as x,d as S,g as C,h as w,k as T,l as E,p as D,s as O,t as k,u as A,v as j,w as M,x as N,y as P,z as F}from"./core-DNchiRD5.mjs";import{Duplex as ee,PassThrough as I,Readable as L,Transform as R,Writable as z}from"node:stream";import{closeSync as B,constants as V,fstatSync as H,openSync as U,realpathSync as W}from"node:fs";import G from"node:path";import{createRequire as K}from"node:module";import{t as q,w as J}from"./resourceLimits-CpDWwraK.mjs";let Y;const X=()=>Y??=K(import.meta.url)(`koffi`),Z=e=>{throw Error(`[PipeX] Secure file `+e+` failed`)},Q=e=>{let t=G.parse(e).root;return e.slice(t.length).split(G.sep).filter(Boolean)};function te(e,t,n){let r=W.native(G.resolve(n??process.cwd())),i=x(e,r),a=T(t,r);if(i===a)throw Error(`[PipeX] Input and output must be different files`);return process.platform===`win32`?ie(i,a,r):se(i,a)}let ne;function re(){let e=X(),t=e.load(`kernel32.dll`),n=e.load(`ntdll.dll`),r=e.struct({Length:`uint16_t`,MaximumLength:`uint16_t`,Buffer:`str16`}),i=e.struct({Length:`uint32_t`,RootDirectory:`intptr_t`,ObjectName:e.pointer(r),Attributes:`uint32_t`,SecurityDescriptor:`void *`,SecurityQualityOfService:`void *`}),a=e.struct({Status:`intptr_t`,Information:`uintptr_t`});return{setRelativeInfo:n.func(`__stdcall`,`NtSetInformationFile`,`int32_t`,[`intptr_t`,e.out(e.pointer(a)),`void *`,`uint32_t`,`int`]),relativeOpen:n.func(`__stdcall`,`NtCreateFile`,`int32_t`,[`_Out_ intptr_t *`,`uint32_t`,e.pointer(i),e.out(e.pointer(a)),`void *`,`uint32_t`,`uint32_t`,`uint32_t`,`uint32_t`,`void *`,`uint32_t`]),attributesSize:e.sizeof(i),pointerBytes:e.sizeof(`void *`),finalPath:t.func(`__stdcall`,`GetFinalPathNameByHandleW`,`uint32_t`,[`intptr_t`,`_Out_ void *`,`uint32_t`,`uint32_t`]),open:t.func(`__stdcall`,`CreateFileW`,`intptr_t`,[`str16`,`uint32_t`,`uint32_t`,`void *`,`uint32_t`,`uint32_t`,`void *`]),info:t.func(`__stdcall`,`GetFileInformationByHandle`,`int`,[`intptr_t`,`_Out_ void *`]),type:t.func(`__stdcall`,`GetFileType`,`uint32_t`,[`intptr_t`]),read:t.func(`__stdcall`,`ReadFile`,`int`,[`intptr_t`,`_Out_ void *`,`uint32_t`,`_Out_ uint32_t *`,`void *`]),write:t.func(`__stdcall`,`WriteFile`,`int`,[`intptr_t`,`void *`,`uint32_t`,`_Out_ uint32_t *`,`void *`]),setInfo:t.func(`__stdcall`,`SetFileInformationByHandle`,`int`,[`intptr_t`,`int`,`void *`,`uint32_t`]),close:t.func(`__stdcall`,`CloseHandle`,`int`,[`intptr_t`])}}function ie(e,n,r){let i=ne??=re(),a=[],o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Set,c=!1,l=!1,u,d,f=e=>{let t=Buffer.alloc(52);return i.info(e,t)||Z(`handle inspection`),t},p=(e,t,n,r,o)=>{let s=i.open(e,t,n,null,r,2097152|(o?33554432:128),null);BigInt(s)===-1n&&Z(`open`),a.push(s);let c=f(s).readUInt32LE(0);return(c&1024||!!(c&16)!==o||i.type(s)!==1)&&Z(`file type validation`),s},m=(e,t,n,r,o,s=!1)=>{(!t||t===`.`||t===`..`||/[\\/:]/.test(t))&&Z(`relative name validation`);let c=[0],l=i.relativeOpen(c,(n|1048576)>>>0,{Length:i.attributesSize,RootDirectory:e,ObjectName:{Length:Buffer.byteLength(t,`utf16le`),MaximumLength:Buffer.byteLength(t,`utf16le`)+2,Buffer:t},Attributes:64,SecurityDescriptor:null,SecurityQualityOfService:null},{},null,128,o?3:1,r?2:1,2097184|(o?1:64),null,0);if(l<0){if(s&&l>>>0==0xc0000034)return;Z(`relative open`)}let u=c[0];a.push(u),r&&(d=u);let p=f(u).readUInt32LE(0);return(p&1024||!!(p&16)!==o||i.type(u)!==1)&&Z(`relative type validation`),u},h=(e,t)=>{let n=``,i=t;for(let t of Q(G.relative(r,G.dirname(e)))){n=G.join(n,t);let e=o.get(n.toLowerCase());e===void 0?(i=m(i,t,0x80000000,!1,!0),o.set(n.toLowerCase(),i)):i=e}return i},g,_=()=>{for(let e of a.reverse())i.close(e);a.length=0};try{let o=p(r,0x80000000,3,3,!0),s=Buffer.alloc(65536),c=i.finalPath(o,s,s.length/2,0);(!c||c>=s.length/2)&&Z(`root identity validation`),G.normalize((e=>e.startsWith(`\\\\?\\UNC\\`)?`\\\\`+e.slice(8):e.startsWith(`\\\\?\\`)?e.slice(4):e)(s.subarray(0,c*2).toString(`utf16le`))).toLowerCase()!==G.normalize(r).toLowerCase()&&Z(`root identity validation`);let l=h(e,o);g=h(n,o),u=m(l,G.basename(e),0x80000000,!1,!1);let _=m(g,G.basename(n),0x80000000,!1,!1,!0);if(_!==void 0)try{let e=f(u),t=f(_);if(e.readUInt32LE(28)===t.readUInt32LE(28)&&e.subarray(44,52).equals(t.subarray(44,52)))throw Error(`[PipeX] Input and output must be different files`);t.readUInt32LE(0)&1024&&Z(`output reparse validation`)}finally{i.close(_),a.pop()}let v=`.pipex-`+t()+`.tmp`;d=m(g,v,0x40010080,!0,!1)}catch(e){throw d!==void 0&&i.setInfo(d,4,Buffer.from([1]),1),_(),e}let v=(e,t)=>{let n=[0],r=new Promise((r,a)=>{(e?i.write:i.read).async(e?d:u,t,t.length,n,null,(t,i)=>{t||!i?a(/* @__PURE__ */ Error(`[PipeX] Secure file `+(e?`write`:`read`)+` failed`)):r(n[0])})});return s.add(r),r.then(()=>s.delete(r),()=>s.delete(r)),r},y=!1,b=new L({highWaterMark:k,read(){if(y)return;y=!0;let e=Buffer.allocUnsafe(k);v(!1,e).then(t=>{y=!1,this.destroyed||this.push(t?e.subarray(0,t):null)},e=>{y=!1,this.destroy(e)})}}),x=new z({highWaterMark:k,write(e,t,n){let r=(async()=>{let t=0;for(;t<e.length;){l&&Z(`write after disposal`);let n=await v(!0,e.subarray(t));n||Z(`write progress`),t+=n}})();s.add(r),r.then(()=>{s.delete(r),n()},e=>{s.delete(r),n(e)})}});return{source:b,destination:x,commit(){(l||c)&&Z(`commit state`);let e=i.pointerBytes,t=e===8?8:4,r=t+e,a=r+4,o=Buffer.from(G.basename(n)+`\0`,`utf16le`),s=Buffer.alloc(a+o.length);s[0]=1,e===8?s.writeBigUInt64LE(BigInt(g),t):s.writeUInt32LE(Number(g),t),s.writeUInt32LE(o.length-2,r),o.copy(s,a);let u=i.setRelativeInfo(d,{},s,s.length,10);u<0&&Z(`atomic rename status `+(u>>>0).toString(16)),c=!0},async dispose(){l||(l=!0,b.destroy(),x.destroy(),await Promise.allSettled([...s]),c||i.setInfo(d,4,Buffer.from([1]),1),_())}}}let ae;function oe(){let e=X().load(null);return{read:e.func(`intptr_t read(int fd, _Out_ void *buffer, size_t count)`),write:e.func(`intptr_t write(int fd, const void *buffer, size_t count)`),fcntl:e.func(`int fcntl(int fd, int command, int argument)`),openat:e.func(`int openat(int dirfd, const char *path, int flags, unsigned int mode)`),mkdirat:e.func(`int mkdirat(int dirfd, const char *path, unsigned int mode)`),renameat:e.func(`int renameat(int oldfd, const char *oldname, int newfd, const char *newname)`),unlinkat:e.func(`int unlinkat(int dirfd, const char *path, int flags)`)}}function se(e,n){let r=ae??=oe(),i=[],a=V.O_NOFOLLOW,o=V.O_DIRECTORY;a&&o||Z(`platform support`);let s=()=>{for(let e of i.reverse())try{B(e)}catch{}i.length=0},c=(e,t,n,o=0)=>{let s=r.openat(e,t,n|a,o);return s<0&&Z(`relative open`),i.push(s),r.fcntl(s,2,1)<0&&Z(`descriptor inheritance protection`),s},l=e=>{let t=U(G.parse(e).root,V.O_RDONLY|o);i.push(t);for(let n of Q(G.dirname(e)))t=c(t,n,V.O_RDONLY|o);return t},u=`.pipex-`+t(),d,f,p,m,h=!1,g=!1,_=!1,v=/* @__PURE__ */ new Set,y=process.platform===`linux`?512:process.platform===`darwin`?128:process.platform===`openbsd`?8:2048,b=()=>{f!==void 0&&!h&&r.unlinkat(f,`data`,0),d!==void 0&&_&&r.unlinkat(d,u,y),s()};try{let t=l(e);d=l(n),p=c(t,G.basename(e),V.O_RDONLY|V.O_NONBLOCK);let i=H(p,{bigint:!0});i.isFile()||Z(`input type validation`);let s=r.openat(d,G.basename(n),V.O_RDONLY|a|V.O_NONBLOCK,0);if(s>=0)try{let e=H(s,{bigint:!0});if(i.dev===e.dev&&i.ino===e.ino)throw Error(`[PipeX] Input and output must be different files`)}finally{B(s)}r.mkdirat(d,u,448)!==0&&Z(`temporary directory creation`),_=!0,f=c(d,u,V.O_RDONLY|o);let h=H(f);(h.mode&63||h.uid!==process.geteuid?.())&&Z(`temporary directory permissions`),m=c(f,`data`,V.O_WRONLY|V.O_CREAT|V.O_EXCL,384)}catch(e){throw b(),e}let x=(e,t)=>{let n=new Promise((n,i)=>{(e?r.write:r.read).async(e?m:p,t,t.length,(e,t)=>{e||t<0?i(/* @__PURE__ */ Error(`[PipeX] Secure relative file I/O failed`)):n(Number(t))})});return v.add(n),n.then(()=>v.delete(n),()=>v.delete(n)),n},S=!1,C=new L({highWaterMark:k,read(){if(S)return;S=!0;let e=Buffer.allocUnsafe(k);x(!1,e).then(t=>{S=!1,this.destroyed||this.push(t?e.subarray(0,t):null)},e=>{S=!1,this.destroy(e)})}}),w=new z({highWaterMark:k,write(e,t,n){let r=(async()=>{let t=0;for(;t<e.length;){g&&Z(`write after disposal`);let n=await x(!0,e.subarray(t));n||Z(`relative write progress`),t+=n}})();v.add(r),r.then(()=>{v.delete(r),n()},e=>{v.delete(r),n(e)})}});return{source:C,destination:w,commit(){(g||h)&&Z(`commit state`),r.renameat(f,`data`,d,G.basename(n))!==0&&Z(`atomic relative rename`),h=!0},async dispose(){g||(g=!0,C.destroy(),w.destroy(),await Promise.allSettled([...v]),b())}}}var ce=class{#e;constructor(e){this.#e=e}async#t(e,t,n,i,a){let o=te(e,t,n);try{await a(o.source,o.destination),r(i),o.commit()}finally{await o.dispose()}}#n(e,t){return{requestId:e,signal:t,track:t=>this.#e.trackWork(e,t),limits:this.#e.limits,logger:this.#e.logger,tracer:this.#e.tracer}}async process(e,t,i,a={}){let o=this.#e.createOperationSignal(a);r(o);let s=this.#e.startRequest();try{if(this.#e.schema)throw Error(`[PipeX] Global object schemas cannot validate raw file streams`);await this.#t(e,t,i,o,async(e,t)=>{let r=this.#n(s,o),i=[D(this.#e.limits.maxInputBytes,`input`),...N(this.#e.plugins,`compress`,!1,e=>this.#e.emitProgress(e,s),this.#e.logger,this.#e.tracer,this.#e.dlq,r),D(this.#e.limits.maxOutputBytes,`output`)];await n(e,i,t,{signal:o})}),await p(this.#e.emitAudit({requestId:s,operation:`process`,metadata:{controller:`file`}}),o,e=>this.#e.trackWork(s,e)),r(o),this.#e.endRequest(s)}catch(e){throw this.#e.emitError(e,s),e}}async reverse(e,t,i,a={}){let o=this.#e.createOperationSignal(a);r(o);let s=this.#e.startRequest();try{if(this.#e.schema)throw Error(`[PipeX] Global object schemas cannot validate raw file streams`);await this.#t(e,t,i,o,async(e,t)=>{let r=this.#n(s,o),i=[D(this.#e.limits.maxInputBytes,`input`),...N(this.#e.plugins,`decompress`,!0,e=>this.#e.emitProgress(e,s),this.#e.logger,this.#e.tracer,this.#e.dlq,r),D(this.#e.limits.maxOutputBytes,`output`)];await n(e,i,t,{signal:o})}),await p(this.#e.emitAudit({requestId:s,operation:`reverse`,metadata:{controller:`file`}}),o,e=>this.#e.trackWork(s,e)),r(o),this.#e.endRequest(s)}catch(e){throw this.#e.emitError(e,s),e}}async pack(e,t,i,a={}){let o=this.#e.createOperationSignal(a);r(o);let c=this.#e.startRequest();try{await this.#t(e,t,i,o,async(e,t)=>{let r=[D(this.#e.limits.maxInputBytes,`input`),b(this.#e.limits.maxFrames),w(this.#e.limits.maxFrameBytes,`MessagePack frame`),m(),j(C([])),s(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),D(this.#e.limits.maxOutputBytes,`output`)];await n(e,r,t,{signal:o})}),await p(this.#e.emitAudit({requestId:c,operation:`pack`,metadata:{controller:`file`}}),o,e=>this.#e.trackWork(c,e)),r(o),this.#e.endRequest(c)}catch(e){throw this.#e.emitError(e,c),e}}async unpack(e,t,a,o={}){let c=this.#e.createOperationSignal(o);r(c);let l=this.#e.startRequest();try{await this.#t(e,t,a,c,async(e,t)=>{let r=i(this.#e.limits.maxInputBytes),a=v(e=>{let t=[];if(e.plugins.length!==t.length||e.plugins.some((e,n)=>e!==t[n]))throw Error(`[PipeX] Manifest plugin chain does not match the configured engine`);this.#e.emit(`manifest`,e,l)}),o=P(),u=new R({writableObjectMode:!0,readableObjectMode:!0,transform:(e,t,n)=>{try{this.#e.validate(e),n(null,e)}catch(e){n(e)}}});await n(e,[D(this.#e.limits.maxInputBytes,`input`),s(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),r,a,b(this.#e.limits.maxFrames),u,o,D(this.#e.limits.maxOutputBytes,`output`)],t,{signal:c})}),await p(this.#e.emitAudit({requestId:l,operation:`unpack`,metadata:{controller:`file`}}),c,e=>this.#e.trackWork(l,e)),r(c),this.#e.endRequest(l)}catch(e){throw this.#e.emitError(e,l),e}}},le=class{#e;constructor(e){this.#e=e}pack(e){try{E(e,Math.min(this.#e.limits.maxInputBytes,this.#e.limits.maxFrameBytes),`Serialization input`);let t=y.pack(e);if(t.length>this.#e.limits.maxInputBytes)throw Error(`[PipeX] Packed input exceeds configured limit`);if(_(t,this.#e.limits.maxFrameBytes,1),t.length>this.#e.limits.maxOutputBytes)throw Error(`[PipeX] Packed output exceeds configured limit`);return t}catch(e){throw e instanceof Error&&e.message.startsWith(`[PipeX]`)?e:new J({stage:`pack`})}}unpack(e){try{if(e.byteLength>this.#e.limits.maxInputBytes)throw Error(`[PipeX] Serialized input exceeds configured limit`);return _(e,this.#e.limits.maxFrameBytes,1),O.unpack(e)}catch(e){throw e instanceof Error&&e.message.startsWith(`[PipeX]`)?e:new J({stage:`unpack`})}}#t=/* @__PURE__ */ new WeakMap;async run(e,t={}){let n=this.#e.createOperationSignal(t);r(n);let i=M(e);A(i);let a=this.#e.plugins,o=[...this.#e.pipeline],s=this.#e.limits,c=this.#e.startRequest({operation:`run`}),l=Date.now(),m=this.#e.tracer?.startSpan(`binary:run`,{requestId:c});try{m?.setAttribute(`input.type`,i),this.#e.validate(e),E(e,s.maxInputBytes,`Input`);let t=u(e);if(t.length>s.maxInputBytes)throw Error(`[PipeX] Input exceeds configured limit`);(i===`object`||i===`array`)&&_(t,s.maxFrameBytes,1);let h=Object.create(null);for(let e of a){let r=Date.now(),a=this.#e.tracer?.startSpan(`plugin:${e.name}`,{requestId:c});try{a?.setAttribute(`mode`,`process`);let r=d(c,{originalType:i},this.#e.logger,a,n,s);if(t=await f(()=>e.process(t,r),e.retryOptions,this.#e.logger,{signal:n,limits:s,track:e=>this.#e.trackWork(c,e)}),!Buffer.isBuffer(t)||t.length>s.maxOutputBytes)throw Error(`[PipeX] Plugin output exceeds configured limit`)}catch(e){throw a?.setAttribute(`error`,!0),e}finally{a?.end()}h[e.name]=Date.now()-r,this.#e.emit(`plugin:after`,e.name,h[e.name])}if(t.length>s.maxOutputBytes)throw Error(`[PipeX] Output exceeds configured limit`);r(n);let g=Date.now()-l;await p(this.#e.emitAudit({requestId:c,operation:`process`,metadata:{inputType:i,durationMs:g}}),n,e=>this.#e.trackWork(c,e)),r(n),this.#t.set(t,i);let v={data:t,originalType:i,pipeline:o,metrics:{durationMs:g,steps:h}};return m?.setAttribute(`duration_ms`,g),this.#e.endRequest(c,g),v}catch(e){throw m?.setAttribute(`error`,!0),this.#e.emitError(e,c),e}finally{m?.end(),this.#e.releaseRequest(c)}}async undo(e,t,n={}){let i=Buffer.isBuffer(e),a,o,s;if(i)A(t),a=e,o=t,s=n;else{let n=e;if(!n||typeof n!=`object`||!Buffer.isBuffer(n.data)||!Array.isArray(n.pipeline)||n.pipeline.length>256||!n.pipeline.every(e=>typeof e==`string`&&e.length<=512)||!n.metrics||!Number.isFinite(n.metrics.durationMs)||n.metrics.durationMs<0||!n.metrics.steps||typeof n.metrics.steps!=`object`||Array.isArray(n.metrics.steps)||!Object.values(n.metrics.steps).every(e=>typeof e==`number`&&Number.isFinite(e)&&e>=0))throw Error(`[PipeX] Invalid EngineResult`);if(A(n.originalType),t!==void 0&&(typeof t!=`object`||!t))throw Error(`[PipeX] Invalid undo options`);let r=t,i=r?.expectedType??this.#t.get(n.data);if(i===void 0)throw Error(`[PipeX] Transported EngineResult requires a trusted expectedType`);if(A(i),i!==n.originalType)throw Error(`[PipeX] Result type does not match the expected type`);a=n.data,o=i,s=r??{}}let c=this.#e.createOperationSignal(s);r(c);let l=this.#e.plugins;S(l);let m=this.#e.limits;if(a.length>m.maxInputBytes)throw Error(`[PipeX] Undo input exceeds configured limit`);let g=this.#e.startRequest({operation:`undo`,originalType:o}),_=this.#e.tracer?.startSpan(`binary:undo`,{requestId:g});try{if(i&&l.length===0&&a.length>0){let e;try{e=this.unpackWithManifest(a)}catch{}if(e){if(e.manifest.plugins.length!==0)throw Error(`[PipeX] Manifest plugin chain does not match the configured engine`);if(M(e.data)!==o)throw Error(`[PipeX] Manifest data does not match the expected type`);a=u(e.data)}}for(let e of[...l].reverse()){let t=this.#e.tracer?.startSpan(`plugin:${e.name}`,{requestId:g});try{t?.setAttribute(`mode`,`reverse`);let n=d(g,{originalType:o},this.#e.logger,t,c,m);if(a=await f(()=>e.reverse(a,n),e.retryOptions,this.#e.logger,{signal:c,limits:m,track:e=>this.#e.trackWork(g,e)}),!Buffer.isBuffer(a)||a.length>m.maxOutputBytes)throw Error(`[PipeX] Plugin output exceeds configured limit`)}catch(e){throw t?.setAttribute(`error`,!0),e}finally{t?.end()}this.#e.emit(`plugin:after`,e.name,0)}if(a.length>m.maxOutputBytes)throw Error(`[PipeX] Output exceeds configured limit`);r(c);let e=h(a,o,m.maxFrameBytes);return this.#e.validate(e),r(c),await p(this.#e.emitAudit({requestId:g,operation:`reverse`,metadata:{originalType:o}}),c,e=>this.#e.trackWork(g,e)),r(c),this.#e.endRequest(g),e}catch(e){throw _?.setAttribute(`error`,!0),this.#e.emitError(e,g),e}finally{_?.end(),this.#e.releaseRequest(g)}}packWithManifest(e){if(this.#e.plugins.length>0)throw Error(`[PipeX] packWithManifest is serialization-only; use binary.run for plugin transforms`);let t=C([]);E(e,Math.min(this.#e.limits.maxInputBytes,this.#e.limits.maxFrameBytes),`Serialization input`);let n=y.pack(t),r=y.pack(e);if(_(n,this.#e.limits.maxFrameBytes,1),_(r,this.#e.limits.maxFrameBytes,1),n.length+r.length>Math.min(this.#e.limits.maxInputBytes,this.#e.limits.maxOutputBytes))throw Error(`[PipeX] Serialized input exceeds configured limit`);return Buffer.concat([n,r])}unpackWithManifest(e){if(e.length>this.#e.limits.maxInputBytes)throw Error(`[PipeX] Serialized input exceeds configured limit`);_(e,this.#e.limits.maxFrameBytes,2);let t=[];try{O.unpackMultiple(e,e=>{if(t.length>=2)throw Error(`[PipeX] Frame count exceeds configured limit`);t.push(e)})}catch(e){throw e instanceof Error&&e.message.startsWith(`[PipeX]`)?e:Error(`[PipeX] binary.unpackWithManifest: invalid MessagePack input`)}if(t.length<2)throw Error(`[PipeX] binary.unpackWithManifest: buffer contains fewer than 2 frames`);if(!g(t[0]))throw Error(`[PipeX] binary.unpackWithManifest: first frame is not a PipeXManifest`);return{manifest:t[0],data:t[1]}}},ue=class{#e;constructor(e){this.#e=e}#t(e,t){return{requestId:e,signal:t,track:t=>this.#e.trackWork(e,t),limits:this.#e.limits,logger:this.#e.logger,tracer:this.#e.tracer}}#n(e,t){return ee.from({writable:e,readable:t})}#r(e,t,i){let a=this.#e.createOperationSignal(i);if(r(a),this.#e.schema)throw Error(`[PipeX] Global object schemas cannot validate raw byte streams`);let o=this.#e.startRequest(),s=this.#t(o,a),c=t?`decompress`:`compress`,l;try{l=N(this.#e.plugins,c,t,e=>this.#e.emitProgress(e,o),this.#e.logger,this.#e.tracer,this.#e.dlq,s)}catch(e){throw this.#e.emitError(e,o),e}let u=new I,d,f=new z({write(t,n,r){if(u.destroyed){let t=e.errored??u.errored;r(t instanceof Error?t:/* @__PURE__ */ Error(`[PipeX] Stream pipeline is closed`))}else u.write(t,n,r)},final(e){d=e,u.end()},destroy(e,t){d=void 0,u.destroyed||u.destroy(e??void 0),t(e)}}),m=e=>{let t=d;d=void 0,t?t(e):e&&!f.destroyed&&f.destroy(e)};return n(u,[D(this.#e.limits.maxInputBytes,`input`),...l,D(this.#e.limits.maxOutputBytes,`output`)],e,{signal:a}).then(async()=>{await p(this.#e.emitAudit({requestId:o,operation:t?`reverse`:`process`,metadata:{controller:`stream`}}),a,e=>this.#e.trackWork(o,e)),r(a),this.#e.endRequest(o),m()}).catch(e=>{let t=e instanceof Error?e:Error(String(e));this.#e.emitError(t,o),m(t)}),f}into(e,t={}){return this.#r(e,!1,t)}reverseInto(e,t={}){return this.#r(e,!0,t)}pack(e={}){let t=this.#e.createOperationSignal(e);r(t);let i=this.#e.startRequest({operation:`pack`}),a=new I({objectMode:!0}),o=new I,c=[b(this.#e.limits.maxFrames),w(this.#e.limits.maxFrameBytes,`MessagePack frame`),m(),j(C([])),s(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),D(this.#e.limits.maxOutputBytes,`output`)],l=this.#n(a,o);return n(a,c,o,{signal:t}).then(async()=>{await p(this.#e.emitAudit({requestId:i,operation:`pack`,metadata:{controller:`stream`}}),t,e=>this.#e.trackWork(i,e)),r(t),this.#e.endRequest(i)}).catch(e=>{this.#e.emitError(e,i),l.destroy(e instanceof Error?e:Error(String(e)))}),l}unpack(e={}){let t=this.#e.createOperationSignal(e);r(t);let a=this.#e.startRequest({operation:`unpack`}),o=new I,c=new I({objectMode:!0}),l=i(this.#e.limits.maxInputBytes),u=v(e=>{let t=[];if(e.plugins.length!==t.length||e.plugins.some((e,n)=>e!==t[n]))throw Error(`[PipeX] Manifest plugin chain does not match the configured engine`);this.#e.emit(`manifest`,e,a)}),d=new R({writableObjectMode:!0,readableObjectMode:!0,transform:(e,t,n)=>{try{this.#e.validate(e),n(null,e)}catch(e){n(e)}}}),f=[D(this.#e.limits.maxInputBytes,`input`),s(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),l,u,b(this.#e.limits.maxFrames),d],m=this.#n(o,c);return n(o,f,c,{signal:t}).then(async()=>{await p(this.#e.emitAudit({requestId:a,operation:`unpack`,metadata:{controller:`stream`}}),t,e=>this.#e.trackWork(a,e)),r(t),this.#e.endRequest(a)}).catch(e=>{this.#e.emitError(e,a),m.destroy(e instanceof Error?e:Error(String(e)))}),m}async pipe(e,t,i=!1,a={}){let o=this.#e.createOperationSignal(a);if(r(o),this.#e.schema)throw Error(`[PipeX] Global object schemas cannot validate raw byte streams`);let s=this.#e.startRequest(),c=i?`decompress`:`compress`,l=this.#t(s,o);try{let a=N(this.#e.plugins,c,i,e=>this.#e.emitProgress(e,s),this.#e.logger,this.#e.tracer,this.#e.dlq,l);await n(e,[D(this.#e.limits.maxInputBytes,`input`),...a,D(this.#e.limits.maxOutputBytes,`output`)],t,{signal:o}),await p(this.#e.emitAudit({requestId:s,operation:i?`reverse`:`process`,metadata:{controller:`stream`}}),o,e=>this.#e.trackWork(s,e)),r(o),this.#e.endRequest(s)}catch(e){throw this.#e.emitError(e,s),e}}};const $=0x7fffffff;var de=class n extends e{static pluginRegistry=/* @__PURE__ */ new Map;static registerPlugin(e,t){if(!/^[a-z0-9][a-z0-9-]{0,63}$/i.test(e)||typeof t!=`function`)throw Error(`[PipeX] Invalid plugin registration`);this.pluginRegistry.set(e,e=>new t(e))}static async fromConfig(e){if(!e||typeof e!=`object`)throw Error(`[PipeX] Configuration must be an object`);let t=new n(e.limits);if(e.logger&&t.setLogger(e.logger),e.tracer&&t.setTracer(e.tracer),e.auditLogger&&t.setAuditLogger(e.auditLogger),e.dlq&&t.setDlq(e.dlq),e.schemaRegistry&&t.setSchemaRegistry(e.schemaRegistry),e.schema&&t.setSchema(e.schema),e.plugins){if(!Array.isArray(e.plugins))throw Error(`[PipeX] Configuration plugins must be an array`);for(let n of e.plugins){let e=this.pluginRegistry.get(n.name);if(!e)throw Error(`[PipeX] Unknown plugin in config: ${n.name}`);try{t.use(e(n.options))}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`[PipeX] Failed to initialize plugin "${n.name}": ${t}`,{cause:e})}}}return t}#e=[];#t=Object.freeze([]);#n;#r;#i;#a;#o;#s;#c;#l=/* @__PURE__ */ new Set;#u=/* @__PURE__ */ new Map;#d=/* @__PURE__ */ new Set;#f=/* @__PURE__ */ new Map;file;binary;stream;constructor(e={}){super(),this.#c=Object.freeze({...q,...e}),this.#p(this.#c),this.file=new ce(this),this.binary=new le(this),this.stream=new ue(this)}#p(e){for(let[t,n]of Object.entries(e))if(!Number.isSafeInteger(n)||n<0)throw Error(`[PipeX] Invalid engine limit ${t}`);if(e.maxInputBytes<1||e.maxOutputBytes<1||e.maxFrameBytes<1||e.maxFrames<1||e.maxConcurrentOperations<1||e.maxRetryAttempts<1||e.maxKmsEncryptedKeyBytes<1||e.maxKmsKeyIdBytes<1)throw Error(`[PipeX] Engine limits must be positive`);if(e.operationTimeoutMs>$||e.maxKmsEncryptedKeyBytes>0xffffffff)throw Error(`[PipeX] Engine limit exceeds its supported protocol or timer range`)}get limits(){return this.#c}setLimits(e){if(this.#l.size>0)throw Error(`[PipeX] Cannot modify engine limits while operations are active`);let t={...this.#c,...e};return this.#p(t),this.#c=Object.freeze(t),this}createOperationSignal(e={}){let t=e.timeoutMs??this.#c.operationTimeoutMs;if(!Number.isSafeInteger(t)||t<0||t>$)throw Error(`[PipeX] Invalid operation timeout`);let n=e.signal?[e.signal]:[];t>0&&n.push(AbortSignal.timeout(t));let r=n.length===0?new AbortController().signal:AbortSignal.any(n);return F(r,t),r}setDlq(e){if(!e||typeof e.write!=`function`)throw Error(`[PipeX] DLQ must be a writable stream`);return this.#o=e,this}get dlq(){return this.#o}setLogger(e){if(!e||![`info`,`warn`,`error`,`debug`].every(t=>typeof e[t]==`function`))throw Error(`[PipeX] Logger must implement info, warn, error, and debug`);return this.#i=c(e),this}get logger(){return this.#i}setTracer(e){if(!e||typeof e.startSpan!=`function`)throw Error(`[PipeX] Tracer must implement startSpan`);return this.#a=l(e),this}get tracer(){return this.#a}setAuditLogger(e){if(!e||typeof e.log!=`function`)throw Error(`[PipeX] Audit logger must implement log`);return this.#s=e,this}async emitAudit(e){this.#s&&await this.#s.log({...e,pluginChain:e.operation===`pack`||e.operation===`unpack`?[]:[...this.#f.get(e.requestId)??this.pipeline],timestamp:Date.now()})}setSchemaRegistry(e){if(!e||typeof e.getSchema!=`function`)throw Error(`[PipeX] Schema registry must implement getSchema`);return this.#r=e,this}async loadSchema(e,t){if(!this.#r)throw Error(`[PipeX] No Schema Registry configured`);let n=await this.#r.getSchema(e,t);this.setSchema(n)}setSchema(e){if(!e||typeof e.safeParse!=`function`)throw Error(`[PipeX] Schema must implement safeParse`);return this.#n=e,this}get schema(){return this.#n}validate(e){if(this.#n&&!this.#n.safeParse(e).success)throw Error(`[PipeX] Core Validation failed`)}use(e){if(!e||typeof e.name!=`string`||e.name.length===0||e.name.length>128||typeof e.version!=`string`||e.version.length===0||typeof e.process!=`function`)throw Error(`[PipeX] Invalid processor plugin`);if(a(e),this.#l.size>0)throw Error(`[PipeX] Cannot modify the plugin pipeline while operations are active`);if(this.#e.length>=256)throw Error(`[PipeX] Maximum plugin count exceeded`);return this.#e.push(e),this.#t=Object.freeze([...this.#e]),this}get plugins(){return this.#t}get pipeline(){return Object.freeze(this.#t.map(e=>`${e.name}@${e.version}`))}get pluginCapabilities(){return Object.freeze(this.#t.map(e=>Object.freeze({plugin:`${e.name}@${e.version}`,...a(e)})))}startRequest(e={}){if(this.#l.size>=this.#c.maxConcurrentOperations)throw Error(`[PipeX] Maximum concurrent operations exceeded`);let n=t();this.#l.add(n),this.#f.set(n,this.pipeline);try{this.#i?.info(`[PipeX] Request started`,{requestId:n,...e})}catch{}return this.emit(`start`,n),n}trackWork(e,t){let n=this.#u.get(e);n||this.#u.set(e,n=/* @__PURE__ */ new Set),n.add(t);let r=()=>{n.delete(t),n.size===0&&(this.#u.delete(e),this.#d.has(e)&&this.releaseRequest(e))};t.then(r,r)}releaseRequest(e){this.#u.get(e)?.size?this.#d.add(e):(this.#l.delete(e),this.#d.delete(e),this.#f.delete(e))}endRequest(e,t){this.releaseRequest(e);try{this.#i?.info(`[PipeX] Request ended`,{requestId:e,durationMs:t})}catch{}this.emit(`end`,e,t)}emitProgress(e,t){this.emit(`progress`,e,t)}emitError(e,t){let n=e instanceof Error?e:Error(String(e));this.releaseRequest(t);try{this.#i?.error(`[PipeX] Request failed`,{requestId:t,error:n.message})}catch{}this.listenerCount(`error`)>0&&this.emit(`error`,n,t)}emit(e,...t){let n=this.rawListeners(e);for(let e of n)o(()=>Reflect.apply(e,this,t));return n.length>0}on(e,t){return super.on(e,t)}once(e,t){return super.once(e,t)}};export{de as t};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Transform } from "node:stream";
|
|
2
|
+
import { t as BasePlugin } from "./plugin-c_iSNY86.cjs";
|
|
3
|
+
import { C as StreamPluginContext, _ as ProcessorContext } from "./types-B50Urzn2.cjs";
|
|
4
|
+
type EncryptionAlgorithm = 'aes-256-gcm' | 'chacha20-poly1305';
|
|
5
|
+
/** Shared authenticated-encryption settings. */
|
|
6
|
+
interface EncryptionCommonOptions {
|
|
7
|
+
/** Secret 32-byte encryption key; length is enforced at runtime. */
|
|
8
|
+
readonly key: Buffer;
|
|
9
|
+
/** Maximum plaintext bytes per authenticated frame (default 64 KiB). */
|
|
10
|
+
readonly frameSizeBytes?: number;
|
|
11
|
+
/** Allow reading old records only during an explicit migration. */
|
|
12
|
+
readonly allowLegacyDecrypt?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** AES-256-GCM configuration. */
|
|
15
|
+
interface Aes256GcmOptions extends EncryptionCommonOptions {
|
|
16
|
+
readonly algorithm: 'aes-256-gcm';
|
|
17
|
+
}
|
|
18
|
+
/** ChaCha20-Poly1305 configuration. */
|
|
19
|
+
interface ChaCha20Poly1305Options extends EncryptionCommonOptions {
|
|
20
|
+
readonly algorithm: 'chacha20-poly1305';
|
|
21
|
+
}
|
|
22
|
+
/** Algorithm-discriminated encryption settings. */
|
|
23
|
+
type EncryptionOptions = Aes256GcmOptions | ChaCha20Poly1305Options;
|
|
24
|
+
/**
|
|
25
|
+
* Authenticated, bounded-memory stream encryption.
|
|
26
|
+
*
|
|
27
|
+
* Version 4 writes the versioned PXAE framed format. The legacy unversioned
|
|
28
|
+
* format can be explicitly enabled for migration, but is never written.
|
|
29
|
+
*/
|
|
30
|
+
declare class EncryptionPlugin extends BasePlugin {
|
|
31
|
+
protected options: EncryptionOptions;
|
|
32
|
+
readonly name = "encryption";
|
|
33
|
+
readonly version = "4.0.0";
|
|
34
|
+
constructor(options: EncryptionOptions);
|
|
35
|
+
process(data: Buffer, context: ProcessorContext): Promise<Buffer>;
|
|
36
|
+
reverse(data: Buffer, context: ProcessorContext): Promise<Buffer>;
|
|
37
|
+
createStream(mode: 'compress' | 'decompress', context?: StreamPluginContext): Transform;
|
|
38
|
+
}
|
|
39
|
+
export { EncryptionPlugin as a, EncryptionOptions as i, ChaCha20Poly1305Options as n, EncryptionAlgorithm as o, EncryptionCommonOptions as r, Aes256GcmOptions as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,b as t,i as n,l as r,n as i,r as a,s as o,t as s}from"./resourceLimits-CpDWwraK.mjs";import{createCipheriv as c,createDecipheriv as l,hkdfSync as u,randomBytes as d}from"node:crypto";import{Transform as f}from"node:stream";const p=Buffer.from(`PXAE`),m={"aes-256-gcm":1,"chacha20-poly1305":2},h={1:`aes-256-gcm`,2:`chacha20-poly1305`};function g(e){if(!Buffer.isBuffer(e)||e.length!==32)throw new r}function _(e){return{maxInputBytes:i(e),maxOutputBytes:a(e),maxFrameBytes:e?.limits?.maxFrameBytes??s.maxFrameBytes,maxFrames:e?.limits?.maxFrames??s.maxFrames}}function v(e,t){let n=t.maxFrameBytes-29;if(n<1||t.maxFrameBytes<28)throw Error(`[PipeX] Encryption frame limit ${t.maxFrameBytes} bytes is too small`);let r=e.frameSizeBytes??Math.min(65536,n);if(!Number.isSafeInteger(r)||r<1||r>0xffffffff)throw Error(`[PipeX] Encryption frameSizeBytes must be a positive 32-bit integer`);if(r>n)throw Error(`[PipeX] Encryption frameSizeBytes exceeds the ${t.maxFrameBytes}-byte frame limit`);return r}function y(e,t){let n=e===0?0:Math.ceil(e/t);return 28+e+(n+1)*29}function b(e,t){return e===0?0:Math.ceil(e/t)}function x(e,t,n=d(16)){let r=Buffer.alloc(28);return p.copy(r,0),r.writeUInt8(1,4),r.writeUInt8(m[e],5),r.writeUInt16BE(0,6),r.writeUInt32BE(t,8),n.copy(r,12),r}function S(e,t){if(e.length!==28||!e.subarray(0,4).equals(p))throw Error(`[PipeX] Decryption failed: invalid framed header`);if(e.readUInt8(4)!==1)throw Error(`[PipeX] Decryption failed: unsupported format version`);let n=h[e.readUInt8(5)];if(!n||e.readUInt16BE(6)!==0)throw Error(`[PipeX] Decryption failed: invalid framed header`);let r=e.readUInt32BE(8);if(r<1||r>t.maxFrameBytes-29)throw Error(`[PipeX] Decryption failed: invalid frame size`);return{bytes:e,algorithm:n,frameSizeBytes:r,salt:e.subarray(12,28)}}function C(e,t){let n=Buffer.from(`PipeX AEAD framed v1:${t.algorithm}`,`utf8`);return Buffer.from(u(`sha256`,e,t.salt,n,32))}function w(e){if(e<0n||e>18446744073709551615n)throw Error(`[PipeX] Encryption frame sequence exhausted`);let t=Buffer.alloc(12);return t.writeBigUInt64BE(e,4),t}function T(e,t,n){let r=Buffer.alloc(13);return r.writeUInt8(e,0),r.writeBigUInt64BE(t,1),r.writeUInt32BE(n,9),r}function E(e,t,n,r,i,a){let o=T(t,n,e.length),s=w(n);try{let t=c(r,i,s,{authTagLength:16});t.setAAD(Buffer.concat([a,o]));let n=Buffer.concat([t.update(e),t.final()]);return Buffer.concat([o,n,t.getAuthTag()],29+n.length)}finally{s.fill(0)}}function D(t,n,r,i,a,o,s){let c=w(i),u=l(a,o,c,{authTagLength:16});if(u.setAAD(Buffer.concat([s,r])),n.length!==16)throw new e;u.setAuthTag(n);let d=u.update(t);try{let e=u.final();return e.length===0?d:Buffer.concat([d,e])}catch{throw d.fill(0),new e}finally{c.fill(0)}}function O(e,t,n){if(e.length<29)throw Error(`[PipeX] Decryption failed: packet too short`);if(e.length-29>n.maxOutputBytes)throw Error(`[PipeX] Decryption output exceeds ${n.maxOutputBytes} bytes`);let r=h[e.readUInt8(0)];if(!r)throw Error(`[PipeX] Decryption failed: unknown legacy algorithm`);let i=l(r,t,e.subarray(1,13),{authTagLength:16});i.setAuthTag(e.subarray(13,29));let a=i.update(e.subarray(29));try{let e=i.final();return e.length===0?a:Buffer.concat([a,e])}catch{throw a.fill(0),Error(`[PipeX] Decryption failed: authentication failed`)}}function k(e){return e.length>=p.length&&e.subarray(0,p.length).equals(p)}function A(e,t,n){g(t.key);let r=_(n);if(e.length>r.maxInputBytes)throw Error(`[PipeX] Encryption input exceeds ${r.maxInputBytes} bytes`);let i=v(t,r);if(b(e.length,i)>r.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${r.maxFrames}`);let a=y(e.length,i);if(a>r.maxOutputBytes)throw Error(`[PipeX] Encryption output exceeds ${r.maxOutputBytes} bytes`);let o=x(t.algorithm,i),s=S(o,r),c=C(t.key,s),l=[o],u=0n;try{for(let n=0;n<e.length;n+=i)l.push(E(e.subarray(n,Math.min(e.length,n+i)),1,u++,t.algorithm,c,o));return l.push(E(Buffer.alloc(0),2,u,t.algorithm,c,o)),Buffer.concat(l,a)}finally{c.fill(0)}}function j(e,t,n){g(t.key);let r=_(n);if(e.length>r.maxInputBytes)throw Error(`[PipeX] Decryption input exceeds ${r.maxInputBytes} bytes`);if(e.length===0||!k(e)&&e.readUInt8(0)!==p.readUInt8(0)){if(t.allowLegacyDecrypt!==!0)throw Error(`[PipeX] Decryption failed: legacy format disabled`);return O(e,t.key,r)}if(e.length<28)throw Error(`[PipeX] Decryption failed: incomplete framed header`);let i=S(e.subarray(0,28),r),a=C(t.key,i),o=[],s=0,c=28,l=0n,u=0,d=!1;try{for(;c<e.length;){if(d||e.length-c<13)throw Error(`[PipeX] Decryption failed: incomplete or trailing frame`);let t=e.subarray(c,c+13);c+=13;let n=t.readUInt8(0),f=t.readBigUInt64BE(1),p=t.readUInt32BE(9);if(f!==l)throw Error(`[PipeX] Decryption failed: invalid frame sequence`);if(n!==1&&n!==2)throw Error(`[PipeX] Decryption failed: invalid frame type`);if(n===2&&p!==0)throw Error(`[PipeX] Decryption failed: invalid final frame`);if(p>i.frameSizeBytes||p>r.maxFrameBytes-29)throw Error(`[PipeX] Decryption failed: frame length exceeds configured limit`);if(n===1&&u>=r.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${r.maxFrames}`);if(n===1&&p>r.maxOutputBytes-s)throw Error(`[PipeX] Decryption output exceeds ${r.maxOutputBytes} bytes`);if(e.length-c<p+16)throw Error(`[PipeX] Decryption failed: incomplete frame`);let m=e.subarray(c,c+p);c+=p;let h=e.subarray(c,c+16);c+=16;let g=D(m,h,t,f,i.algorithm,a,i.bytes);n===2?(g.fill(0),d=!0):(u++,s+=g.length,o.push(g)),l++}if(!d)throw Error(`[PipeX] Decryption failed: missing authenticated final frame`);let t=Buffer.concat(o,s);for(let e of o)e.fill(0);return t}catch(e){for(let e of o)e.fill(0);throw e}finally{a.fill(0)}}function M(e,t){g(e.key);let n=_(t),r=v(e,n);if(y(0,r)>n.maxOutputBytes)throw Error(`[PipeX] Encryption output exceeds ${n.maxOutputBytes} bytes`);let i=x(e.algorithm,r),a=S(i,n),o=C(e.key,a),s=Buffer.alloc(r),c=0,l=0,u=0,d=0n,p=!1,m=()=>{s.fill(0),o.fill(0)};return new f({transform(t,a,f){try{let a=Buffer.isBuffer(t)?t:Buffer.from(t);if(a.length>n.maxInputBytes-l)throw Error(`[PipeX] Encryption input exceeds ${n.maxInputBytes} bytes`);let m=l+a.length;if(b(m,r)>n.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${n.maxFrames}`);if(y(m,r)>n.maxOutputBytes)throw Error(`[PipeX] Encryption output exceeds ${n.maxOutputBytes} bytes`);l=m,p||=(this.push(i),!0);let h=0;for(;h<a.length;){let t=Math.min(r-c,a.length-h);if(a.copy(s,c,h,h+t),c+=t,h+=t,c===r){if(++u>n.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${n.maxFrames}`);this.push(E(s,1,d++,e.algorithm,o,i)),s.fill(0),c=0}}f()}catch(e){m(),f(e)}},flush(t){try{if(p||=(this.push(i),!0),c>0){if(++u>n.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${n.maxFrames}`);this.push(E(s.subarray(0,c),1,d++,e.algorithm,o,i))}this.push(E(Buffer.alloc(0),2,d,e.algorithm,o,i)),m(),t()}catch(e){m(),t(e)}},destroy(e,t){m(),t(e)}})}function N(e,t){g(e.key);let n=_(t),r=`unknown`,i=0,a=0,o=Buffer.alloc(28),s=0,c,l,u=Buffer.alloc(13),d=0,m,h=0,v=0n,y=0,b=!1,x=[],w=()=>{l?.fill(0),m?.fill(0),o.fill(0),u.fill(0),x=[]},T=(t,r)=>{let i=0;for(;i<t.length;){if(b)throw Error(`[PipeX] Decryption failed: trailing data after final frame`);if(!c){let r=Math.min(28-s,t.length-i);t.copy(o,s,i,i+r),s+=r,i+=r,s===28&&(c=S(o,n),l=C(e.key,c));continue}if(d<13){let e=Math.min(13-d,t.length-i);if(t.copy(u,d,i,i+e),d+=e,i+=e,d<13)continue;let r=u.readUInt8(0),o=u.readBigUInt64BE(1),s=u.readUInt32BE(9);if(o!==v)throw Error(`[PipeX] Decryption failed: invalid frame sequence`);if(r!==1&&r!==2)throw Error(`[PipeX] Decryption failed: invalid frame type`);if(r===2&&s!==0)throw Error(`[PipeX] Decryption failed: invalid final frame`);if(s>c.frameSizeBytes||s>n.maxFrameBytes-29)throw Error(`[PipeX] Decryption failed: frame length exceeds configured limit`);if(r===1&&y>=n.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${n.maxFrames}`);if(r===1&&s>n.maxOutputBytes-a)throw Error(`[PipeX] Decryption output exceeds ${n.maxOutputBytes} bytes`);m=Buffer.alloc(s+16),h=0}let f=Math.min(m.length-h,t.length-i);if(t.copy(m,h,i,i+f),h+=f,i+=f,h<m.length)continue;let p=u.readUInt8(0),g=u.readBigUInt64BE(1),_=u.readUInt32BE(9),x=D(m.subarray(0,_),m.subarray(_),u,g,c.algorithm,l,c.bytes);p===2?(x.fill(0),b=!0):(y++,a+=x.length,r.push(x)),v++,m.fill(0),m=void 0,h=0,u.fill(0),d=0}};return new f({transform(t,a,o){try{let a=Buffer.isBuffer(t)?t:Buffer.from(t);if(a.length>n.maxInputBytes-i)throw Error(`[PipeX] Decryption input exceeds ${n.maxInputBytes} bytes`);if(i+=a.length,a.length===0)return o();if(r===`unknown`&&(r=a.readUInt8(0)===p.readUInt8(0)?`framed`:`legacy`,r===`legacy`&&e.allowLegacyDecrypt===!1))throw Error(`[PipeX] Decryption failed: legacy format disabled`);r===`legacy`?x.push(a):T(a,this),o()}catch(e){w(),o(e)}},flush(t){try{if(r===`legacy`){let r=O(Buffer.concat(x,i),e.key,n);return this.push(r),w(),t()}if(r!==`framed`||!c||d!==0||m)throw Error(`[PipeX] Decryption failed: incomplete encrypted stream`);if(!b)throw Error(`[PipeX] Decryption failed: missing authenticated final frame`);w(),t()}catch(e){w(),t(e)}},destroy(e,t){w(),t(e)}})}var P=class extends n{options;name=`encryption`;version=`4.0.0`;constructor(e){if(super(e),this.options=e,!e||!Buffer.isBuffer(e.key)||e.key.length!==32)throw new r;if(![`aes-256-gcm`,`chacha20-poly1305`].includes(e.algorithm))throw new t({transformName:`encryption`,stage:`configuration`});if(e.frameSizeBytes!==void 0&&(!Number.isSafeInteger(e.frameSizeBytes)||e.frameSizeBytes<1||e.frameSizeBytes>0xffffffff))throw new o(`[PipeX] Invalid encryption frame size`);if(e.allowLegacyDecrypt!==void 0&&typeof e.allowLegacyDecrypt!=`boolean`)throw new o(`[PipeX] Invalid legacy decryption setting`)}async process(e,t){return A(e,this.options,t)}async reverse(e,t){return j(e,this.options,t)}createStream(e,t){return e===`compress`?M(this.options,t):N(this.options,t)}};export{P as t};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Transform } from "node:stream";
|
|
2
|
+
import { t as BasePlugin } from "./plugin-D85NMNiy.mjs";
|
|
3
|
+
import { C as StreamPluginContext, _ as ProcessorContext } from "./types-B50Urzn2.mjs";
|
|
4
|
+
type EncryptionAlgorithm = 'aes-256-gcm' | 'chacha20-poly1305';
|
|
5
|
+
/** Shared authenticated-encryption settings. */
|
|
6
|
+
interface EncryptionCommonOptions {
|
|
7
|
+
/** Secret 32-byte encryption key; length is enforced at runtime. */
|
|
8
|
+
readonly key: Buffer;
|
|
9
|
+
/** Maximum plaintext bytes per authenticated frame (default 64 KiB). */
|
|
10
|
+
readonly frameSizeBytes?: number;
|
|
11
|
+
/** Allow reading old records only during an explicit migration. */
|
|
12
|
+
readonly allowLegacyDecrypt?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** AES-256-GCM configuration. */
|
|
15
|
+
interface Aes256GcmOptions extends EncryptionCommonOptions {
|
|
16
|
+
readonly algorithm: 'aes-256-gcm';
|
|
17
|
+
}
|
|
18
|
+
/** ChaCha20-Poly1305 configuration. */
|
|
19
|
+
interface ChaCha20Poly1305Options extends EncryptionCommonOptions {
|
|
20
|
+
readonly algorithm: 'chacha20-poly1305';
|
|
21
|
+
}
|
|
22
|
+
/** Algorithm-discriminated encryption settings. */
|
|
23
|
+
type EncryptionOptions = Aes256GcmOptions | ChaCha20Poly1305Options;
|
|
24
|
+
/**
|
|
25
|
+
* Authenticated, bounded-memory stream encryption.
|
|
26
|
+
*
|
|
27
|
+
* Version 4 writes the versioned PXAE framed format. The legacy unversioned
|
|
28
|
+
* format can be explicitly enabled for migration, but is never written.
|
|
29
|
+
*/
|
|
30
|
+
declare class EncryptionPlugin extends BasePlugin {
|
|
31
|
+
protected options: EncryptionOptions;
|
|
32
|
+
readonly name = "encryption";
|
|
33
|
+
readonly version = "4.0.0";
|
|
34
|
+
constructor(options: EncryptionOptions);
|
|
35
|
+
process(data: Buffer, context: ProcessorContext): Promise<Buffer>;
|
|
36
|
+
reverse(data: Buffer, context: ProcessorContext): Promise<Buffer>;
|
|
37
|
+
createStream(mode: 'compress' | 'decompress', context?: StreamPluginContext): Transform;
|
|
38
|
+
}
|
|
39
|
+
export { EncryptionPlugin as a, EncryptionOptions as i, ChaCha20Poly1305Options as n, EncryptionAlgorithm as o, EncryptionCommonOptions as r, Aes256GcmOptions as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./resourceLimits-lJrEhDE5.cjs");let t=require("node:crypto"),n=require("node:stream");const r=Buffer.from(`PXAE`),i={"aes-256-gcm":1,"chacha20-poly1305":2},a={1:`aes-256-gcm`,2:`chacha20-poly1305`};function o(t){if(!Buffer.isBuffer(t)||t.length!==32)throw new e.l}function s(t){return{maxInputBytes:e.n(t),maxOutputBytes:e.r(t),maxFrameBytes:t?.limits?.maxFrameBytes??e.t.maxFrameBytes,maxFrames:t?.limits?.maxFrames??e.t.maxFrames}}function c(e,t){let n=t.maxFrameBytes-29;if(n<1||t.maxFrameBytes<28)throw Error(`[PipeX] Encryption frame limit ${t.maxFrameBytes} bytes is too small`);let r=e.frameSizeBytes??Math.min(65536,n);if(!Number.isSafeInteger(r)||r<1||r>0xffffffff)throw Error(`[PipeX] Encryption frameSizeBytes must be a positive 32-bit integer`);if(r>n)throw Error(`[PipeX] Encryption frameSizeBytes exceeds the ${t.maxFrameBytes}-byte frame limit`);return r}function l(e,t){let n=e===0?0:Math.ceil(e/t);return 28+e+(n+1)*29}function u(e,t){return e===0?0:Math.ceil(e/t)}function d(e,n,a=(0,t.randomBytes)(16)){let o=Buffer.alloc(28);return r.copy(o,0),o.writeUInt8(1,4),o.writeUInt8(i[e],5),o.writeUInt16BE(0,6),o.writeUInt32BE(n,8),a.copy(o,12),o}function f(e,t){if(e.length!==28||!e.subarray(0,4).equals(r))throw Error(`[PipeX] Decryption failed: invalid framed header`);if(e.readUInt8(4)!==1)throw Error(`[PipeX] Decryption failed: unsupported format version`);let n=a[e.readUInt8(5)];if(!n||e.readUInt16BE(6)!==0)throw Error(`[PipeX] Decryption failed: invalid framed header`);let i=e.readUInt32BE(8);if(i<1||i>t.maxFrameBytes-29)throw Error(`[PipeX] Decryption failed: invalid frame size`);return{bytes:e,algorithm:n,frameSizeBytes:i,salt:e.subarray(12,28)}}function p(e,n){let r=Buffer.from(`PipeX AEAD framed v1:${n.algorithm}`,`utf8`);return Buffer.from((0,t.hkdfSync)(`sha256`,e,n.salt,r,32))}function m(e){if(e<0n||e>18446744073709551615n)throw Error(`[PipeX] Encryption frame sequence exhausted`);let t=Buffer.alloc(12);return t.writeBigUInt64BE(e,4),t}function h(e,t,n){let r=Buffer.alloc(13);return r.writeUInt8(e,0),r.writeBigUInt64BE(t,1),r.writeUInt32BE(n,9),r}function g(e,n,r,i,a,o){let s=h(n,r,e.length),c=m(r);try{let n=(0,t.createCipheriv)(i,a,c,{authTagLength:16});n.setAAD(Buffer.concat([o,s]));let r=Buffer.concat([n.update(e),n.final()]);return Buffer.concat([s,r,n.getAuthTag()],29+r.length)}finally{c.fill(0)}}function _(n,r,i,a,o,s,c){let l=m(a),u=(0,t.createDecipheriv)(o,s,l,{authTagLength:16});if(u.setAAD(Buffer.concat([c,i])),r.length!==16)throw new e.a;u.setAuthTag(r);let d=u.update(n);try{let e=u.final();return e.length===0?d:Buffer.concat([d,e])}catch{throw d.fill(0),new e.a}finally{l.fill(0)}}function v(e,n,r){if(e.length<29)throw Error(`[PipeX] Decryption failed: packet too short`);if(e.length-29>r.maxOutputBytes)throw Error(`[PipeX] Decryption output exceeds ${r.maxOutputBytes} bytes`);let i=a[e.readUInt8(0)];if(!i)throw Error(`[PipeX] Decryption failed: unknown legacy algorithm`);let o=(0,t.createDecipheriv)(i,n,e.subarray(1,13),{authTagLength:16});o.setAuthTag(e.subarray(13,29));let s=o.update(e.subarray(29));try{let e=o.final();return e.length===0?s:Buffer.concat([s,e])}catch{throw s.fill(0),Error(`[PipeX] Decryption failed: authentication failed`)}}function y(e){return e.length>=r.length&&e.subarray(0,r.length).equals(r)}function b(e,t,n){o(t.key);let r=s(n);if(e.length>r.maxInputBytes)throw Error(`[PipeX] Encryption input exceeds ${r.maxInputBytes} bytes`);let i=c(t,r);if(u(e.length,i)>r.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${r.maxFrames}`);let a=l(e.length,i);if(a>r.maxOutputBytes)throw Error(`[PipeX] Encryption output exceeds ${r.maxOutputBytes} bytes`);let m=d(t.algorithm,i),h=f(m,r),_=p(t.key,h),v=[m],y=0n;try{for(let n=0;n<e.length;n+=i)v.push(g(e.subarray(n,Math.min(e.length,n+i)),1,y++,t.algorithm,_,m));return v.push(g(Buffer.alloc(0),2,y,t.algorithm,_,m)),Buffer.concat(v,a)}finally{_.fill(0)}}function x(e,t,n){o(t.key);let i=s(n);if(e.length>i.maxInputBytes)throw Error(`[PipeX] Decryption input exceeds ${i.maxInputBytes} bytes`);if(e.length===0||!y(e)&&e.readUInt8(0)!==r.readUInt8(0)){if(t.allowLegacyDecrypt!==!0)throw Error(`[PipeX] Decryption failed: legacy format disabled`);return v(e,t.key,i)}if(e.length<28)throw Error(`[PipeX] Decryption failed: incomplete framed header`);let a=f(e.subarray(0,28),i),c=p(t.key,a),l=[],u=0,d=28,m=0n,h=0,g=!1;try{for(;d<e.length;){if(g||e.length-d<13)throw Error(`[PipeX] Decryption failed: incomplete or trailing frame`);let t=e.subarray(d,d+13);d+=13;let n=t.readUInt8(0),r=t.readBigUInt64BE(1),o=t.readUInt32BE(9);if(r!==m)throw Error(`[PipeX] Decryption failed: invalid frame sequence`);if(n!==1&&n!==2)throw Error(`[PipeX] Decryption failed: invalid frame type`);if(n===2&&o!==0)throw Error(`[PipeX] Decryption failed: invalid final frame`);if(o>a.frameSizeBytes||o>i.maxFrameBytes-29)throw Error(`[PipeX] Decryption failed: frame length exceeds configured limit`);if(n===1&&h>=i.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${i.maxFrames}`);if(n===1&&o>i.maxOutputBytes-u)throw Error(`[PipeX] Decryption output exceeds ${i.maxOutputBytes} bytes`);if(e.length-d<o+16)throw Error(`[PipeX] Decryption failed: incomplete frame`);let s=e.subarray(d,d+o);d+=o;let f=e.subarray(d,d+16);d+=16;let p=_(s,f,t,r,a.algorithm,c,a.bytes);n===2?(p.fill(0),g=!0):(h++,u+=p.length,l.push(p)),m++}if(!g)throw Error(`[PipeX] Decryption failed: missing authenticated final frame`);let t=Buffer.concat(l,u);for(let e of l)e.fill(0);return t}catch(e){for(let e of l)e.fill(0);throw e}finally{c.fill(0)}}function S(e,t){o(e.key);let r=s(t),i=c(e,r);if(l(0,i)>r.maxOutputBytes)throw Error(`[PipeX] Encryption output exceeds ${r.maxOutputBytes} bytes`);let a=d(e.algorithm,i),m=f(a,r),h=p(e.key,m),_=Buffer.alloc(i),v=0,y=0,b=0,x=0n,S=!1,C=()=>{_.fill(0),h.fill(0)};return new n.Transform({transform(t,n,o){try{let n=Buffer.isBuffer(t)?t:Buffer.from(t);if(n.length>r.maxInputBytes-y)throw Error(`[PipeX] Encryption input exceeds ${r.maxInputBytes} bytes`);let s=y+n.length;if(u(s,i)>r.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${r.maxFrames}`);if(l(s,i)>r.maxOutputBytes)throw Error(`[PipeX] Encryption output exceeds ${r.maxOutputBytes} bytes`);y=s,S||=(this.push(a),!0);let c=0;for(;c<n.length;){let t=Math.min(i-v,n.length-c);if(n.copy(_,v,c,c+t),v+=t,c+=t,v===i){if(++b>r.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${r.maxFrames}`);this.push(g(_,1,x++,e.algorithm,h,a)),_.fill(0),v=0}}o()}catch(e){C(),o(e)}},flush(t){try{if(S||=(this.push(a),!0),v>0){if(++b>r.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${r.maxFrames}`);this.push(g(_.subarray(0,v),1,x++,e.algorithm,h,a))}this.push(g(Buffer.alloc(0),2,x,e.algorithm,h,a)),C(),t()}catch(e){C(),t(e)}},destroy(e,t){C(),t(e)}})}function C(e,t){o(e.key);let i=s(t),a=`unknown`,c=0,l=0,u=Buffer.alloc(28),d=0,m,h,g=Buffer.alloc(13),y=0,b,x=0,S=0n,C=0,w=!1,T=[],E=()=>{h?.fill(0),b?.fill(0),u.fill(0),g.fill(0),T=[]},D=(t,n)=>{let r=0;for(;r<t.length;){if(w)throw Error(`[PipeX] Decryption failed: trailing data after final frame`);if(!m){let n=Math.min(28-d,t.length-r);t.copy(u,d,r,r+n),d+=n,r+=n,d===28&&(m=f(u,i),h=p(e.key,m));continue}if(y<13){let e=Math.min(13-y,t.length-r);if(t.copy(g,y,r,r+e),y+=e,r+=e,y<13)continue;let n=g.readUInt8(0),a=g.readBigUInt64BE(1),o=g.readUInt32BE(9);if(a!==S)throw Error(`[PipeX] Decryption failed: invalid frame sequence`);if(n!==1&&n!==2)throw Error(`[PipeX] Decryption failed: invalid frame type`);if(n===2&&o!==0)throw Error(`[PipeX] Decryption failed: invalid final frame`);if(o>m.frameSizeBytes||o>i.maxFrameBytes-29)throw Error(`[PipeX] Decryption failed: frame length exceeds configured limit`);if(n===1&&C>=i.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${i.maxFrames}`);if(n===1&&o>i.maxOutputBytes-l)throw Error(`[PipeX] Decryption output exceeds ${i.maxOutputBytes} bytes`);b=Buffer.alloc(o+16),x=0}let a=Math.min(b.length-x,t.length-r);if(t.copy(b,x,r,r+a),x+=a,r+=a,x<b.length)continue;let o=g.readUInt8(0),s=g.readBigUInt64BE(1),c=g.readUInt32BE(9),v=_(b.subarray(0,c),b.subarray(c),g,s,m.algorithm,h,m.bytes);o===2?(v.fill(0),w=!0):(C++,l+=v.length,n.push(v)),S++,b.fill(0),b=void 0,x=0,g.fill(0),y=0}};return new n.Transform({transform(t,n,o){try{let n=Buffer.isBuffer(t)?t:Buffer.from(t);if(n.length>i.maxInputBytes-c)throw Error(`[PipeX] Decryption input exceeds ${i.maxInputBytes} bytes`);if(c+=n.length,n.length===0)return o();if(a===`unknown`&&(a=n.readUInt8(0)===r.readUInt8(0)?`framed`:`legacy`,a===`legacy`&&e.allowLegacyDecrypt===!1))throw Error(`[PipeX] Decryption failed: legacy format disabled`);a===`legacy`?T.push(n):D(n,this),o()}catch(e){E(),o(e)}},flush(t){try{if(a===`legacy`){let n=v(Buffer.concat(T,c),e.key,i);return this.push(n),E(),t()}if(a!==`framed`||!m||y!==0||b)throw Error(`[PipeX] Decryption failed: incomplete encrypted stream`);if(!w)throw Error(`[PipeX] Decryption failed: missing authenticated final frame`);E(),t()}catch(e){E(),t(e)}},destroy(e,t){E(),t(e)}})}var w=class extends e.i{options;name=`encryption`;version=`4.0.0`;constructor(t){if(super(t),this.options=t,!t||!Buffer.isBuffer(t.key)||t.key.length!==32)throw new e.l;if(![`aes-256-gcm`,`chacha20-poly1305`].includes(t.algorithm))throw new e.b({transformName:`encryption`,stage:`configuration`});if(t.frameSizeBytes!==void 0&&(!Number.isSafeInteger(t.frameSizeBytes)||t.frameSizeBytes<1||t.frameSizeBytes>0xffffffff))throw new e.s(`[PipeX] Invalid encryption frame size`);if(t.allowLegacyDecrypt!==void 0&&typeof t.allowLegacyDecrypt!=`boolean`)throw new e.s(`[PipeX] Invalid legacy decryption setting`)}async process(e,t){return b(e,this.options,t)}async reverse(e,t){return x(e,this.options,t)}createStream(e,t){return e===`compress`?S(this.options,t):C(this.options,t)}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return w}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./encryption-DwdO7Y4J.cjs");exports.EncryptionPlugin=e.t;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as EncryptionPlugin, i as EncryptionOptions, n as ChaCha20Poly1305Options, o as EncryptionAlgorithm, r as EncryptionCommonOptions, t as Aes256GcmOptions } from "./encryption-CCPoyX4q.cjs";
|
|
2
|
+
export { type Aes256GcmOptions, type ChaCha20Poly1305Options, type EncryptionAlgorithm, type EncryptionCommonOptions, type EncryptionOptions, EncryptionPlugin };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as EncryptionPlugin, i as EncryptionOptions, n as ChaCha20Poly1305Options, o as EncryptionAlgorithm, r as EncryptionCommonOptions, t as Aes256GcmOptions } from "./encryption-D4eC9ubl.mjs";
|
|
2
|
+
export { type Aes256GcmOptions, type ChaCha20Poly1305Options, type EncryptionAlgorithm, type EncryptionCommonOptions, type EncryptionOptions, EncryptionPlugin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as EncryptionPlugin}from"./encryption-CHvy--rb.mjs";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Transform } from "node:stream";
|
|
2
|
+
import { t as BasePlugin } from "./plugin-c_iSNY86.cjs";
|
|
3
|
+
import { C as StreamPluginContext, _ as ProcessorContext } from "./types-B50Urzn2.cjs";
|
|
4
|
+
type HashAlgorithm = 'sha256' | 'sha512';
|
|
5
|
+
/** HMAC-SHA-256 options. Secret must be at least 16 characters at runtime. */
|
|
6
|
+
interface Sha256HashingOptions {
|
|
7
|
+
readonly algorithm: 'sha256';
|
|
8
|
+
readonly secret: string;
|
|
9
|
+
}
|
|
10
|
+
/** HMAC-SHA-512 options. Secret must be at least 16 characters at runtime. */
|
|
11
|
+
interface Sha512HashingOptions {
|
|
12
|
+
readonly algorithm: 'sha512';
|
|
13
|
+
readonly secret: string;
|
|
14
|
+
}
|
|
15
|
+
/** Algorithm-discriminated HMAC configuration. */
|
|
16
|
+
type HashingOptions = Sha256HashingOptions | Sha512HashingOptions;
|
|
17
|
+
/**
|
|
18
|
+
* HashingPlugin — Standard library plugin for HMAC integrity checks.
|
|
19
|
+
* Appends a digest to the end of the buffer/stream.
|
|
20
|
+
*/
|
|
21
|
+
declare class HashingPlugin extends BasePlugin {
|
|
22
|
+
protected options: HashingOptions;
|
|
23
|
+
readonly name = "hashing";
|
|
24
|
+
readonly version = "3.0.0";
|
|
25
|
+
constructor(options: HashingOptions);
|
|
26
|
+
process(data: Buffer, context: ProcessorContext): Promise<Buffer>;
|
|
27
|
+
reverse(data: Buffer, context: ProcessorContext): Promise<Buffer>;
|
|
28
|
+
createStream(mode: 'compress' | 'decompress', context?: StreamPluginContext): Transform;
|
|
29
|
+
}
|
|
30
|
+
export { Sha512HashingOptions as a, Sha256HashingOptions as i, HashingOptions as n, HashingPlugin as r, HashAlgorithm as t };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Transform } from "node:stream";
|
|
2
|
+
import { t as BasePlugin } from "./plugin-D85NMNiy.mjs";
|
|
3
|
+
import { C as StreamPluginContext, _ as ProcessorContext } from "./types-B50Urzn2.mjs";
|
|
4
|
+
type HashAlgorithm = 'sha256' | 'sha512';
|
|
5
|
+
/** HMAC-SHA-256 options. Secret must be at least 16 characters at runtime. */
|
|
6
|
+
interface Sha256HashingOptions {
|
|
7
|
+
readonly algorithm: 'sha256';
|
|
8
|
+
readonly secret: string;
|
|
9
|
+
}
|
|
10
|
+
/** HMAC-SHA-512 options. Secret must be at least 16 characters at runtime. */
|
|
11
|
+
interface Sha512HashingOptions {
|
|
12
|
+
readonly algorithm: 'sha512';
|
|
13
|
+
readonly secret: string;
|
|
14
|
+
}
|
|
15
|
+
/** Algorithm-discriminated HMAC configuration. */
|
|
16
|
+
type HashingOptions = Sha256HashingOptions | Sha512HashingOptions;
|
|
17
|
+
/**
|
|
18
|
+
* HashingPlugin — Standard library plugin for HMAC integrity checks.
|
|
19
|
+
* Appends a digest to the end of the buffer/stream.
|
|
20
|
+
*/
|
|
21
|
+
declare class HashingPlugin extends BasePlugin {
|
|
22
|
+
protected options: HashingOptions;
|
|
23
|
+
readonly name = "hashing";
|
|
24
|
+
readonly version = "3.0.0";
|
|
25
|
+
constructor(options: HashingOptions);
|
|
26
|
+
process(data: Buffer, context: ProcessorContext): Promise<Buffer>;
|
|
27
|
+
reverse(data: Buffer, context: ProcessorContext): Promise<Buffer>;
|
|
28
|
+
createStream(mode: 'compress' | 'decompress', context?: StreamPluginContext): Transform;
|
|
29
|
+
}
|
|
30
|
+
export { Sha512HashingOptions as a, Sha256HashingOptions as i, HashingOptions as n, HashingPlugin as r, HashAlgorithm as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=require("node:crypto"),t=require("node:stream");const n=require("./resourceLimits-lJrEhDE5.cjs"),r={sha256:32,sha512:64};var i=class extends n.i{options;name=`hashing`;version=`3.0.0`;constructor(e){if(super(e),this.options=e,!(e.algorithm in r))throw new n.b({transformName:`hashing`,stage:`configuration`});if(!e.secret||e.secret.length<16)throw new n.c({transformName:`hashing`})}async process(t,i){let a=n.n(i),o=n.r(i),s=r[this.options.algorithm];if(t.length>a)throw new n.c({transformName:`hashing`,stage:`input`});if(t.length>o-s)throw new n.c({transformName:`hashing`,stage:`output`});i.metadata??={};let c=(0,e.createHmac)(this.options.algorithm,this.options.secret).update(t).digest();return i.metadata.hmac=c.toString(`hex`),Buffer.concat([t,c])}async reverse(t,i){let a=r[this.options.algorithm],o=n.n(i),s=n.r(i);if(t.length>o)throw new n.c({transformName:`hashing`,stage:`input`});if(t.length<a)throw new n.c({transformName:`hashing`});if(t.length-a>s)throw new n.c({transformName:`hashing`,stage:`output`});let c=t.subarray(0,t.length-a),l=t.subarray(t.length-a),u=(0,e.createHmac)(this.options.algorithm,this.options.secret).update(c).digest();try{if(!(0,e.timingSafeEqual)(l,u))throw new n.c({transformName:`hashing`});return i.metadata??={},i.metadata.verified_hmac=l.toString(`hex`),c}finally{u.fill(0)}}createStream(i,a){let{algorithm:o,secret:s}=this.options,c=(0,e.createHmac)(o,s),l=r[o],u=n.n(a),d=n.r(a);if(i===`compress`){let e=0;return new t.Transform({construct(e){e(d<l?new n.c({transformName:`hashing`,stage:`output`}):void 0)},transform(t,r,i){if(t.length>u-e)return i(new n.c({transformName:`hashing`,stage:`input`}));if(t.length>d-l-e)return i(new n.c({transformName:`hashing`,stage:`output`}));e+=t.length,c.update(t),this.push(t),i()},flush(e){this.push(c.digest()),e()}})}{let r=[],i=0;return new t.Transform({transform(e,t,a){if(e.length>u-i)return a(new n.c({transformName:`hashing`,stage:`input`}));i+=e.length,r.push(e),a()},flush(t){let a=Buffer.concat(r,i);r=[];let o;try{if(a.length<l)throw new n.c({transformName:`hashing`});let r=a.subarray(0,a.length-l);if(r.length>d)throw new n.c({transformName:`hashing`,stage:`output`});let i=a.subarray(a.length-l);if(c.update(r),o=c.digest(),!(0,e.timingSafeEqual)(i,o))throw new n.c({transformName:`hashing`});let s=Buffer.from(r);a.fill(0),this.push(s),t()}catch(e){a.fill(0),t(e)}finally{o?.fill(0)}},destroy(e,t){r=[],t(e)}})}}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createHmac as e,timingSafeEqual as t}from"node:crypto";import{Transform as n}from"node:stream";import{b as r,c as i,i as a,n as o,r as s}from"./resourceLimits-CpDWwraK.mjs";const c={sha256:32,sha512:64};var l=class extends a{options;name=`hashing`;version=`3.0.0`;constructor(e){if(super(e),this.options=e,!(e.algorithm in c))throw new r({transformName:`hashing`,stage:`configuration`});if(!e.secret||e.secret.length<16)throw new i({transformName:`hashing`})}async process(t,n){let r=o(n),a=s(n),l=c[this.options.algorithm];if(t.length>r)throw new i({transformName:`hashing`,stage:`input`});if(t.length>a-l)throw new i({transformName:`hashing`,stage:`output`});n.metadata??={};let u=e(this.options.algorithm,this.options.secret).update(t).digest();return n.metadata.hmac=u.toString(`hex`),Buffer.concat([t,u])}async reverse(n,r){let a=c[this.options.algorithm],l=o(r),u=s(r);if(n.length>l)throw new i({transformName:`hashing`,stage:`input`});if(n.length<a)throw new i({transformName:`hashing`});if(n.length-a>u)throw new i({transformName:`hashing`,stage:`output`});let d=n.subarray(0,n.length-a),f=n.subarray(n.length-a),p=e(this.options.algorithm,this.options.secret).update(d).digest();try{if(!t(f,p))throw new i({transformName:`hashing`});return r.metadata??={},r.metadata.verified_hmac=f.toString(`hex`),d}finally{p.fill(0)}}createStream(r,a){let{algorithm:l,secret:u}=this.options,d=e(l,u),f=c[l],p=o(a),m=s(a);if(r===`compress`){let e=0;return new n({construct(e){e(m<f?new i({transformName:`hashing`,stage:`output`}):void 0)},transform(t,n,r){if(t.length>p-e)return r(new i({transformName:`hashing`,stage:`input`}));if(t.length>m-f-e)return r(new i({transformName:`hashing`,stage:`output`}));e+=t.length,d.update(t),this.push(t),r()},flush(e){this.push(d.digest()),e()}})}{let e=[],r=0;return new n({transform(t,n,a){if(t.length>p-r)return a(new i({transformName:`hashing`,stage:`input`}));r+=t.length,e.push(t),a()},flush(n){let a=Buffer.concat(e,r);e=[];let o;try{if(a.length<f)throw new i({transformName:`hashing`});let e=a.subarray(0,a.length-f);if(e.length>m)throw new i({transformName:`hashing`,stage:`output`});let r=a.subarray(a.length-f);if(d.update(e),o=d.digest(),!t(r,o))throw new i({transformName:`hashing`});let s=Buffer.from(e);a.fill(0),this.push(s),n()}catch(e){a.fill(0),n(e)}finally{o?.fill(0)}},destroy(t,n){e=[],n(t)}})}}};export{l as t};
|
package/dist/hashing.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./hashing-DF_guuZf.cjs");exports.HashingPlugin=e.t;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as Sha512HashingOptions, i as Sha256HashingOptions, n as HashingOptions, r as HashingPlugin, t as HashAlgorithm } from "./hashing-C6TkcsUE.cjs";
|
|
2
|
+
export { type HashAlgorithm, type HashingOptions, HashingPlugin, type Sha256HashingOptions, type Sha512HashingOptions };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as Sha512HashingOptions, i as Sha256HashingOptions, n as HashingOptions, r as HashingPlugin, t as HashAlgorithm } from "./hashing-CEwtXh2V.mjs";
|
|
2
|
+
export { type HashAlgorithm, type HashingOptions, HashingPlugin, type Sha256HashingOptions, type Sha512HashingOptions };
|
package/dist/hashing.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as HashingPlugin}from"./hashing-DU3rmGMP.mjs";
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./core-DSIwvTqu.cjs"),t=require("./dataEngine-6R3J-WtS.cjs"),n=require("./resourceLimits-lJrEhDE5.cjs"),r=require("./kms_encryption-B07lunjB.cjs"),i=require("./hashing-DF_guuZf.cjs"),a=require("./encryption-DwdO7Y4J.cjs"),o=require("./compression-ZHOsKTJC.cjs"),s=require("./worker-1Q2hRcRB.cjs"),c=require("./validation-BgdV4KdW.cjs");var l=class e{transforms;constructor(e){this.transforms=e}static from(t){return new e([t])}pipe(t){return new e([...this.transforms,t])}async run(e,t={}){let r=e,i=t.signal,a=()=>{if(i?.aborted)throw new n.g};a();for(let e of this.transforms){a();let o=Promise.resolve(e(r,t));r=i?await new Promise((e,t)=>{let r=()=>t(new n.g);i.addEventListener(`abort`,r,{once:!0}),o.then(e,t).finally(()=>i.removeEventListener(`abort`,r)).catch(()=>{}),i.aborted&&r()}):await o}return a(),r}},u=class extends n.i{name=`benchmark`;version=`2.0.0`;async process(e,t){t.metadata??={};let n=t.metadata[`benchmark:start`]||Date.now();return t.metadata[`benchmark:in_bytes`]=e.length,t.metadata[`benchmark:start`]=n,e}async reverse(e,t){t.metadata??={},t.metadata[`benchmark:out_bytes`]=e.length;let n=t.metadata[`benchmark:start`];return n&&(t.metadata[`benchmark:duration_ms`]=Date.now()-n),e}};const d={Hashing:i.t,Encryption:a.t,Compression:o.t,Benchmark:u,WorkerPool:s.t,Validation:c.t,KmsEncryption:r.t};t.t.registerPlugin(`hashing`,i.t),t.t.registerPlugin(`encryption`,a.t),t.t.registerPlugin(`compression`,o.t),t.t.registerPlugin(`benchmark`,u),t.t.registerPlugin(`worker-pool`,s.t),t.t.registerPlugin(`validation`,c.t),t.t.registerPlugin(`kms-encryption`,r.t),exports.AuthenticationError=n.a,exports.BasePlugin=n.i,exports.BenchmarkPlugin=u,exports.CompressionError=n.o,exports.CompressionPlugin=o.t,exports.DEFAULT_HIGH_WATER=e.t,exports.DEFAULT_LIMITS=n.t,exports.DataEngine=t.t,exports.EncryptionError=n.s,exports.EncryptionPlugin=a.t,exports.GuardedUnpackrStream=e.n,exports.HashingError=n.c,exports.HashingPlugin=i.t,exports.InvalidKeyError=n.l,exports.InvalidKmsProviderCapabilityError=n.u,exports.InvalidPluginCapabilityError=n.d,exports.KmsAuthenticationError=n.f,exports.KmsEncryptionPlugin=r.t,exports.KmsProviderAuthenticationError=n.p,exports.KmsProviderError=n.m,exports.KmsProviderUnavailableError=n.h,exports.MAX_FRAME_BYTES=e.r,exports.ORIGINAL_TYPES=e.i,exports.OperationAbortedError=n.g,exports.OperationTimeoutError=n._,exports.PACKR=e.a,exports.PIPEX_MANIFEST_KEY=e.o,exports.PipeXError=n.v,exports.PipelineAbortedError=n.y,exports.Plugins=d,exports.TypedPipeline=l,exports.UNPACKR=e.s,exports.UnsupportedAlgorithmError=n.b,exports.UnsupportedKmsOperationError=n.x,exports.UnsupportedReverseError=n.S,exports.UnsupportedStreamingError=n.C,exports.ValidationError=n.w,exports.ValidationPlugin=c.t,exports.WorkerPoolCloseError=n.T,exports.WorkerPoolClosedError=n.E,exports.WorkerPoolPlugin=s.t,exports.WorkerQueueFullError=n.D,exports.WorkerTaskError=n.O,exports.assertExists=e.c,exports.assertKnownValueByteLimit=e.l,exports.assertMessagePackFrameLimits=e.V,exports.assertOriginalType=e.u,exports.assertReversiblePipeline=e.d,exports.assertStreamingPipeline=e.f,exports.buildByteLimitTransform=e.p,exports.buildFallbackTransform=e.m,exports.buildFrameLimitTransform=e.H,exports.buildKnownValueByteLimitTransform=e.h,exports.buildManifest=e.g,exports.buildManifestExtractTransform=e._,exports.buildManifestHeaderTransform=e.v,exports.buildNdjsonTransform=e.y,exports.buildObjectLimitTransform=e.b,exports.buildTransformChain=e.x,exports.createPackrStream=e.S,exports.createUnpackrStream=e.C,exports.detectType=e.w,exports.fromBuffer=e.T,exports.getKmsProviderCapabilities=r.n,exports.getPluginCapabilities=e.E,exports.hasStreamSupport=e.D,exports.isManifest=e.U,exports.makeContext=e.O,exports.resolveOutputPath=e.k,exports.runPipeline=e.A,exports.supportsKmsOperation=r.r,exports.supportsOperation=e.j,exports.supportsReverse=e.M,exports.toBuffer=e.N,exports.typedPipeline=function(e){return l.from(e)},exports.withRetry=e.P;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { Duplex, Readable, Transform, TransformCallback, Writable } from "node:stream";
|
|
2
|
+
import { Packr, PackrStream, Unpackr, UnpackrStream } from "msgpackr";
|
|
3
|
+
import { C as StreamPluginContext, S as Span, T as isManifest, _ as ProcessorContext, a as EngineEvents, b as RetryOptions, c as KmsOperation, d as KmsRequestOptions, f as Logger, g as PluginOperation, h as PluginCapabilities, i as EngineConfig, l as KmsProvider, m as PipeXManifest, n as AuditRecord, o as EngineLimits, p as OperationOptions, r as BinaryUndoOptions, s as EngineResult, t as AuditLogger, u as KmsProviderCapabilities, v as ProcessorPlugin, w as Tracer, x as SchemaRegistry, y as RegisteredPluginCapabilities } from "./types-B50Urzn2.cjs";
|
|
4
|
+
import { n as PluginConstructor, t as DataEngine } from "./dataEngine-C-xYat2f.cjs";
|
|
5
|
+
import { t as BasePlugin } from "./plugin-c_iSNY86.cjs";
|
|
6
|
+
import { n as HashingOptions, r as HashingPlugin, t as HashAlgorithm } from "./hashing-C6TkcsUE.cjs";
|
|
7
|
+
import { a as EncryptionPlugin, i as EncryptionOptions, o as EncryptionAlgorithm } from "./encryption-CCPoyX4q.cjs";
|
|
8
|
+
import { i as CompressionType, n as CompressionOptions, r as CompressionPlugin } from "./compression-C1nLQVur.cjs";
|
|
9
|
+
import { n as WorkerPoolPlugin, t as WorkerPoolOptions } from "./worker-DT7RYWwo.cjs";
|
|
10
|
+
import { n as ValidationPlugin, t as ValidationOptions } from "./validation-hcvcixaS.cjs";
|
|
11
|
+
import { n as KmsEncryptionPlugin, t as KmsEncryptionOptions } from "./kms_encryption-BBIHGi_O.cjs";
|
|
12
|
+
export declare function assertMessagePackFrameLimits(input: Buffer | Uint8Array, maxFrameBytes: number, maxFrames?: number): number;
|
|
13
|
+
export declare function buildFrameLimitTransform(maxFrameBytes: number, maxFrames: number): Transform;
|
|
14
|
+
export declare const DEFAULT_LIMITS: Readonly<EngineLimits>;
|
|
15
|
+
/**
|
|
16
|
+
* Executes a function with automatic retries and backoff.
|
|
17
|
+
*/
|
|
18
|
+
export declare function withRetry<T>(fn: () => Promise<T> | T, options?: RetryOptions, logger?: Logger, control?: {
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
limits?: Pick<EngineLimits, 'maxRetryAttempts' | 'maxRetryDelayMs'>;
|
|
21
|
+
track?: (pending: Promise<unknown>) => void;
|
|
22
|
+
}): Promise<T>;
|
|
23
|
+
export declare const PIPEX_MANIFEST_KEY: '__pipex_v';
|
|
24
|
+
export declare const PACKR: Packr;
|
|
25
|
+
export declare const UNPACKR: Unpackr;
|
|
26
|
+
/** @deprecated Use `DEFAULT_LIMITS.maxFrameBytes` or an engine-specific limit. */
|
|
27
|
+
export declare const MAX_FRAME_BYTES: number;
|
|
28
|
+
export declare const DEFAULT_HIGH_WATER: number;
|
|
29
|
+
type PluginWithStream = ProcessorPlugin & {
|
|
30
|
+
createStream(mode: 'compress' | 'decompress', context?: StreamPluginContext): Duplex;
|
|
31
|
+
};
|
|
32
|
+
export declare function hasStreamSupport(p: ProcessorPlugin): p is PluginWithStream;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the effective capabilities of a plugin after validating declarations.
|
|
35
|
+
* Explicit `false` declarations are authoritative, which supports plugins whose
|
|
36
|
+
* implementation is present but disabled by configuration (for example workers).
|
|
37
|
+
*/
|
|
38
|
+
export declare function getPluginCapabilities(plugin: ProcessorPlugin): Readonly<PluginCapabilities>;
|
|
39
|
+
/** Query an operation without attempting to execute it. Invalid declarations fail closed. */
|
|
40
|
+
export declare function supportsOperation(plugin: ProcessorPlugin, operation: PluginOperation): boolean;
|
|
41
|
+
export declare function supportsReverse(plugin: ProcessorPlugin): plugin is ProcessorPlugin & Required<Pick<ProcessorPlugin, 'reverse'>>;
|
|
42
|
+
export declare function assertReversiblePipeline(plugins: readonly ProcessorPlugin[]): void;
|
|
43
|
+
export declare function assertStreamingPipeline(plugins: readonly ProcessorPlugin[]): void;
|
|
44
|
+
export declare function detectType(input: unknown): string;
|
|
45
|
+
export declare function toBuffer(input: unknown): Buffer;
|
|
46
|
+
export declare const ORIGINAL_TYPES: readonly ["buffer", "object", "array", "string", "number", "boolean", "null", "undefined", "bigint", "json"];
|
|
47
|
+
export declare function assertOriginalType(value: unknown): asserts value is string;
|
|
48
|
+
export declare function fromBuffer(buffer: Buffer, targetType: string, maxFrameBytes?: number): unknown;
|
|
49
|
+
export declare function makeContext(requestId: string, extra?: Record<string, unknown>, logger?: Logger, span?: Span, signal?: AbortSignal, limits?: Readonly<EngineLimits>): ProcessorContext;
|
|
50
|
+
export declare function buildManifest(plugins: readonly ProcessorPlugin[]): PipeXManifest;
|
|
51
|
+
/**
|
|
52
|
+
* A passthrough Transform that prepends a single msgpack-encoded manifest frame
|
|
53
|
+
* to the byte stream before forwarding any data chunks.
|
|
54
|
+
* Inserted between PackrStream output and the file destination.
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildManifestHeaderTransform(manifest: PipeXManifest): Transform;
|
|
57
|
+
/**
|
|
58
|
+
* Object-mode Transform that sits after UnpackrStream.
|
|
59
|
+
* Intercepts the first decoded frame: if it is a PipeXManifest, captures it
|
|
60
|
+
* via onManifest() and drops it from the output; all other frames pass through.
|
|
61
|
+
*/
|
|
62
|
+
export declare function buildManifestExtractTransform(onManifest: (m: PipeXManifest) => void): Transform;
|
|
63
|
+
/** DoS-safe UnpackrStream subclass — rejects oversized raw chunks before decode. */
|
|
64
|
+
export declare class GuardedUnpackrStream extends UnpackrStream {
|
|
65
|
+
#private;
|
|
66
|
+
constructor(options?: Record<string, unknown>, maxInputBytes?: number);
|
|
67
|
+
_transform(chunk: Buffer, enc: BufferEncoding, cb: TransformCallback): void;
|
|
68
|
+
}
|
|
69
|
+
/** PackrStream with useRecords disabled (safe default). */
|
|
70
|
+
export declare function createPackrStream(): PackrStream;
|
|
71
|
+
/** GuardedUnpackrStream with useRecords disabled. */
|
|
72
|
+
export declare function createUnpackrStream(maxInputBytes?: number): GuardedUnpackrStream;
|
|
73
|
+
export declare function buildByteLimitTransform(maxBytes: number, label: string): Transform;
|
|
74
|
+
export declare function buildObjectLimitTransform(maxFrames: number): Transform;
|
|
75
|
+
/** Rejects known byte-backed values before MessagePack copies their payload. */
|
|
76
|
+
export declare function assertKnownValueByteLimit(value: unknown, maxBytes: number, label: string): void;
|
|
77
|
+
export declare function buildKnownValueByteLimitTransform(maxBytes: number, label: string): Transform;
|
|
78
|
+
/**
|
|
79
|
+
* Wraps a plugin's process/reverse call in a Transform.
|
|
80
|
+
* requestId is fixed per stream instance — not per chunk — to avoid
|
|
81
|
+
* 60× randomUUID() overhead on high-throughput paths.
|
|
82
|
+
*/
|
|
83
|
+
export declare function buildFallbackTransform(plugin: ProcessorPlugin, reverse: boolean, emitProgress?: (bytes: number) => void, logger?: Logger, tracer?: Tracer, dlq?: Writable, streamContext?: StreamPluginContext): Transform;
|
|
84
|
+
/** Serialises JS objects to NDJSON lines. */
|
|
85
|
+
export declare function buildNdjsonTransform(): Transform;
|
|
86
|
+
/**
|
|
87
|
+
* Builds the ordered Transform chain from a plugin list.
|
|
88
|
+
* Uses native createStream() when available; falls back to buildFallbackTransform.
|
|
89
|
+
*/
|
|
90
|
+
export declare function buildTransformChain(plugins: readonly ProcessorPlugin[], mode: 'compress' | 'decompress', reverse?: boolean, onProgress?: (bytes: number) => void, logger?: Logger, tracer?: Tracer, dlq?: Writable, streamContext?: StreamPluginContext): (Duplex | Transform | PackrStream | GuardedUnpackrStream)[];
|
|
91
|
+
/**
|
|
92
|
+
* Runs an arbitrary pipeline: Source → [...Transforms] → Destination.
|
|
93
|
+
* The `any` cast is scoped to this single call site — nowhere else.
|
|
94
|
+
*/
|
|
95
|
+
export declare function runPipeline(source: Readable, transforms: (Duplex | Transform | PackrStream | GuardedUnpackrStream)[], destination: Writable, options?: {
|
|
96
|
+
signal?: AbortSignal;
|
|
97
|
+
}): Promise<void>;
|
|
98
|
+
export declare function assertExists(inputPath: string, allowedRoot?: string): string;
|
|
99
|
+
export declare function resolveOutputPath(outputPath: string, allowedRoot?: string): string;
|
|
100
|
+
/** A synchronous or asynchronous transformation from Input to Output. */
|
|
101
|
+
type TypedTransform<Input, Output> = (input: Input, options: Readonly<OperationOptions>) => Output | Promise<Output>;
|
|
102
|
+
/** Cancellation options for typed application pipelines. */
|
|
103
|
+
type TypedPipelineOptions = Readonly<OperationOptions>;
|
|
104
|
+
/** An immutable pipeline whose input and output types are preserved across steps. */
|
|
105
|
+
export declare class TypedPipeline<Input, Output> {
|
|
106
|
+
private readonly transforms;
|
|
107
|
+
private constructor();
|
|
108
|
+
/**
|
|
109
|
+
* Start a pipeline from an initial typed transform.
|
|
110
|
+
* @param transform First transformation; its input type becomes the pipeline input.
|
|
111
|
+
*/
|
|
112
|
+
static from<Input, Output>(transform: TypedTransform<Input, Output>): TypedPipeline<Input, Awaited<Output>>;
|
|
113
|
+
/**
|
|
114
|
+
* Append a transform. Its input must accept this pipeline's current output.
|
|
115
|
+
* The returned pipeline infers the appended asynchronous or synchronous output.
|
|
116
|
+
*/
|
|
117
|
+
pipe<Next>(transform: TypedTransform<Output, Next>): TypedPipeline<Input, Awaited<Next>>;
|
|
118
|
+
/** Execute all transforms in order, honouring cancellation between awaits. */
|
|
119
|
+
run(input: Input, options?: TypedPipelineOptions): Promise<Output>;
|
|
120
|
+
}
|
|
121
|
+
/** Create a typed pipeline with automatic end-to-end transform inference. */
|
|
122
|
+
export declare function typedPipeline<Input, Output>(first: TypedTransform<Input, Output>): TypedPipeline<Input, Awaited<Output>>;
|
|
123
|
+
type PipeXErrorCode = 'VALIDATION_FAILED' | 'COMPRESSION_FAILED' | 'HASHING_FAILED' | 'UNSUPPORTED_ALGORITHM' | 'UNSUPPORTED_REVERSE' | 'UNSUPPORTED_STREAMING' | 'INVALID_PLUGIN_CAPABILITY' | 'ENCRYPTION_ERROR' | 'INVALID_ENCRYPTION_KEY' | 'ENCRYPTION_AUTHENTICATION_FAILED' | 'OPERATION_ABORTED' | 'OPERATION_TIMEOUT' | 'KMS_PROVIDER_FAILURE' | 'KMS_AUTHENTICATION_FAILED' | 'KMS_PROVIDER_AUTHENTICATION_FAILED' | 'KMS_PROVIDER_UNAVAILABLE' | 'UNSUPPORTED_KMS_OPERATION' | 'INVALID_KMS_PROVIDER_CAPABILITY' | 'WORKER_POOL_CLOSED' | 'WORKER_QUEUE_FULL' | 'WORKER_POOL_CLOSE_FAILURE' | 'WORKER_TASK_FAILURE';
|
|
124
|
+
export declare class PipeXError extends Error {
|
|
125
|
+
readonly code: PipeXErrorCode;
|
|
126
|
+
readonly name: string;
|
|
127
|
+
readonly transformName?: string;
|
|
128
|
+
readonly stage?: string;
|
|
129
|
+
constructor(code: PipeXErrorCode, message: string, options?: ErrorOptions & {
|
|
130
|
+
transformName?: string;
|
|
131
|
+
stage?: string;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/** Domain failures use fixed, non-sensitive messages. Never include input, keys or arbitrary provider errors. */
|
|
135
|
+
export declare class ValidationError extends PipeXError {
|
|
136
|
+
readonly name = "ValidationError";
|
|
137
|
+
constructor(options?: ErrorOptions & {
|
|
138
|
+
transformName?: string;
|
|
139
|
+
stage?: string;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
export declare class CompressionError extends PipeXError {
|
|
143
|
+
readonly name = "CompressionError";
|
|
144
|
+
constructor(options?: ErrorOptions & {
|
|
145
|
+
transformName?: string;
|
|
146
|
+
stage?: string;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
export declare class HashingError extends PipeXError {
|
|
150
|
+
readonly name = "HashingError";
|
|
151
|
+
constructor(options?: ErrorOptions & {
|
|
152
|
+
transformName?: string;
|
|
153
|
+
stage?: string;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
export declare class UnsupportedAlgorithmError extends PipeXError {
|
|
157
|
+
readonly name = "UnsupportedAlgorithmError";
|
|
158
|
+
constructor(options?: ErrorOptions & {
|
|
159
|
+
transformName?: string;
|
|
160
|
+
stage?: string;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/** Alias hierarchy: existing OperationAbortedError retains its code and instanceof contract. */
|
|
164
|
+
export declare class PipelineAbortedError extends PipeXError {
|
|
165
|
+
readonly name: string;
|
|
166
|
+
constructor(options?: ErrorOptions & {
|
|
167
|
+
transformName?: string;
|
|
168
|
+
stage?: string;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
export declare class UnsupportedReverseError extends PipeXError {
|
|
172
|
+
readonly plugin: string;
|
|
173
|
+
readonly name: string;
|
|
174
|
+
constructor(plugin: string);
|
|
175
|
+
}
|
|
176
|
+
export declare class UnsupportedStreamingError extends PipeXError {
|
|
177
|
+
readonly plugin: string;
|
|
178
|
+
readonly name: string;
|
|
179
|
+
constructor(plugin: string);
|
|
180
|
+
}
|
|
181
|
+
type InvalidPluginCapabilityIssue = 'MUST_BE_BOOLEAN' | 'MISSING_IMPLEMENTATION' | 'CONFLICTING_IMPLEMENTATION';
|
|
182
|
+
export declare class InvalidPluginCapabilityError extends PipeXError {
|
|
183
|
+
readonly plugin: string;
|
|
184
|
+
readonly capability: 'reversible' | 'streaming';
|
|
185
|
+
readonly issue: InvalidPluginCapabilityIssue;
|
|
186
|
+
readonly name: string;
|
|
187
|
+
constructor(plugin: string, capability: 'reversible' | 'streaming', issue: InvalidPluginCapabilityIssue);
|
|
188
|
+
}
|
|
189
|
+
export declare class OperationAbortedError extends PipelineAbortedError {
|
|
190
|
+
readonly name: string;
|
|
191
|
+
constructor(options?: ErrorOptions);
|
|
192
|
+
}
|
|
193
|
+
export declare class OperationTimeoutError extends PipeXError {
|
|
194
|
+
readonly name: string;
|
|
195
|
+
constructor(options?: ErrorOptions);
|
|
196
|
+
}
|
|
197
|
+
export declare class KmsProviderError extends PipeXError {
|
|
198
|
+
readonly operation: 'generateDataKey' | 'decrypt' | 'encrypt';
|
|
199
|
+
readonly name: string;
|
|
200
|
+
constructor(operation: 'generateDataKey' | 'decrypt' | 'encrypt', options?: ErrorOptions);
|
|
201
|
+
}
|
|
202
|
+
export declare class KmsAuthenticationError extends PipeXError {
|
|
203
|
+
readonly name: string;
|
|
204
|
+
constructor();
|
|
205
|
+
}
|
|
206
|
+
export declare class KmsProviderAuthenticationError extends PipeXError {
|
|
207
|
+
readonly operation: 'generateDataKey' | 'decrypt' | 'encrypt';
|
|
208
|
+
readonly name: string;
|
|
209
|
+
constructor(operation: 'generateDataKey' | 'decrypt' | 'encrypt');
|
|
210
|
+
}
|
|
211
|
+
export declare class KmsProviderUnavailableError extends PipeXError {
|
|
212
|
+
readonly operation: 'generateDataKey' | 'decrypt' | 'encrypt';
|
|
213
|
+
readonly name: string;
|
|
214
|
+
constructor(operation: 'generateDataKey' | 'decrypt' | 'encrypt');
|
|
215
|
+
}
|
|
216
|
+
export declare class UnsupportedKmsOperationError extends PipeXError {
|
|
217
|
+
readonly operation: 'generateDataKey' | 'decrypt' | 'encrypt';
|
|
218
|
+
readonly name: string;
|
|
219
|
+
constructor(operation: 'generateDataKey' | 'decrypt' | 'encrypt');
|
|
220
|
+
}
|
|
221
|
+
type InvalidKmsProviderCapabilityIssue = 'MUST_BE_BOOLEAN' | 'MISSING_IMPLEMENTATION';
|
|
222
|
+
export declare class InvalidKmsProviderCapabilityError extends PipeXError {
|
|
223
|
+
readonly operation: 'generateDataKey' | 'decrypt' | 'encrypt';
|
|
224
|
+
readonly issue: InvalidKmsProviderCapabilityIssue;
|
|
225
|
+
readonly name: string;
|
|
226
|
+
constructor(operation: 'generateDataKey' | 'decrypt' | 'encrypt', issue: InvalidKmsProviderCapabilityIssue);
|
|
227
|
+
}
|
|
228
|
+
export declare class WorkerPoolClosedError extends PipeXError {
|
|
229
|
+
readonly name: string;
|
|
230
|
+
constructor();
|
|
231
|
+
}
|
|
232
|
+
export declare class WorkerQueueFullError extends PipeXError {
|
|
233
|
+
readonly maxQueue: number;
|
|
234
|
+
readonly name: string;
|
|
235
|
+
constructor(maxQueue: number);
|
|
236
|
+
}
|
|
237
|
+
export declare class WorkerPoolCloseError extends PipeXError {
|
|
238
|
+
readonly name: string;
|
|
239
|
+
constructor(options?: ErrorOptions);
|
|
240
|
+
}
|
|
241
|
+
export declare class WorkerTaskError extends PipeXError {
|
|
242
|
+
readonly taskName: string;
|
|
243
|
+
readonly name: string;
|
|
244
|
+
constructor(taskName: string, options?: ErrorOptions);
|
|
245
|
+
}
|
|
246
|
+
/** Public cryptographic failure categories; never include keys or ciphertext in messages. */
|
|
247
|
+
export declare class EncryptionError extends PipeXError {
|
|
248
|
+
readonly name: string;
|
|
249
|
+
constructor(message?: string);
|
|
250
|
+
}
|
|
251
|
+
export declare class InvalidKeyError extends PipeXError {
|
|
252
|
+
readonly name: string;
|
|
253
|
+
constructor();
|
|
254
|
+
}
|
|
255
|
+
export declare class AuthenticationError extends PipeXError {
|
|
256
|
+
readonly name: string;
|
|
257
|
+
constructor();
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Returns an immutable, runtime-validated view of a generic KMS provider.
|
|
261
|
+
* Explicit false declarations support legacy provider stubs that exist only
|
|
262
|
+
* to throw; such methods are never invoked through PipeX.
|
|
263
|
+
*/
|
|
264
|
+
export declare function getKmsProviderCapabilities(provider: KmsProvider): Readonly<KmsProviderCapabilities>;
|
|
265
|
+
export declare function supportsKmsOperation(provider: KmsProvider, operation: KmsOperation): boolean;
|
|
266
|
+
/**
|
|
267
|
+
* BenchmarkPlugin — Standard library plugin for monitoring data throughput.
|
|
268
|
+
* Records input/output byte counts in context metadata.
|
|
269
|
+
*/
|
|
270
|
+
export declare class BenchmarkPlugin extends BasePlugin {
|
|
271
|
+
readonly name = "benchmark";
|
|
272
|
+
readonly version = "2.0.0";
|
|
273
|
+
process(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
|
|
274
|
+
reverse(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
|
|
275
|
+
}
|
|
276
|
+
export declare const Plugins: {
|
|
277
|
+
readonly Hashing: typeof HashingPlugin;
|
|
278
|
+
readonly Encryption: typeof EncryptionPlugin;
|
|
279
|
+
readonly Compression: typeof CompressionPlugin;
|
|
280
|
+
readonly Benchmark: typeof BenchmarkPlugin;
|
|
281
|
+
readonly WorkerPool: typeof WorkerPoolPlugin;
|
|
282
|
+
readonly Validation: typeof ValidationPlugin;
|
|
283
|
+
readonly KmsEncryption: typeof KmsEncryptionPlugin;
|
|
284
|
+
};
|
|
285
|
+
export { type AuditLogger, type AuditRecord, BasePlugin, type BinaryUndoOptions, type CompressionOptions, CompressionPlugin, type CompressionType, DataEngine, type EncryptionAlgorithm, type EncryptionOptions, EncryptionPlugin, type EngineConfig, type EngineEvents, type EngineLimits, type EngineResult, type HashAlgorithm, type HashingOptions, HashingPlugin, type InvalidKmsProviderCapabilityIssue, type InvalidPluginCapabilityIssue, type KmsEncryptionOptions, KmsEncryptionPlugin, type KmsOperation, type KmsProvider, type KmsProviderCapabilities, type KmsRequestOptions, type Logger, type OperationOptions, type PipeXErrorCode, type PipeXManifest, type PluginCapabilities, type PluginConstructor, type PluginOperation, type ProcessorContext, type ProcessorPlugin, type RegisteredPluginCapabilities, type RetryOptions, type SchemaRegistry, type Span, type StreamPluginContext, type Tracer, type TypedPipelineOptions, type TypedTransform, type ValidationOptions, ValidationPlugin, type WorkerPoolOptions, WorkerPoolPlugin, isManifest };
|