import{createCipheriv as h,createDecipheriv as p,hkdf as l,randomBytes as s}from"crypto";var a="aes-256-gcm",c=32,g=12,B=16;function T(e,r,n){if(r.length!==c)throw new Error(`Key must be ${c} bytes, got ${r.length}`);let o=s(g),t=h(a,r,o,{authTagLength:B});n!==void 0&&t.setAAD(n);let f=typeof e=="string"?Buffer.from(e,"utf-8"):e,u=t.update(f);u=Buffer.concat([u,t.final()]);let i=t.getAuthTag();return{ciphertext:u,iv:o,authTag:i}}function A(e,r,n,o){if(r.length!==c)throw new Error(`Key must be ${c} bytes, got ${r.length}`);let t=p(a,r,n.iv);t.setAuthTag(n.authTag),o!==void 0&&t.setAAD(o);let f=t.update(e);return f=Buffer.concat([f,t.final()]),f}function d(e,r,n){let o=typeof e=="string"?Buffer.from(e,"utf-8"):e;return new Promise((t,f)=>{l("sha256",o,r??Buffer.alloc(0),n??Buffer.alloc(0),c,(u,i)=>{u?f(u):t(Buffer.from(i))})})}function x(e=c){return s(e)}function E(){return s(g)}function b(e){return e.toString("base64")}function v(e){return Buffer.from(e,"base64")}export{T as a,A as b,d as c,x as d,E as e,b as f,v as g};
