module.exports=[50227,(e,t,r)=>{t.exports=e.x("node:path",()=>require("node:path"))},12057,(e,t,r)=>{t.exports=e.x("node:util",()=>require("node:util"))},2157,(e,t,r)=>{t.exports=e.x("node:fs",()=>require("node:fs"))},60526,(e,t,r)=>{t.exports=e.x("node:os",()=>require("node:os"))},20217,e=>{"use strict";var t=e.i(66680),r=e.i(12057),s=e.i(2157),i=e.i(50227),a=e.i(60526);let n=(0,r.promisify)(t.scrypt),o="aes-256-gcm";class h{secretsDir;masterPassword;static async create(e,t){let r=new h(e,t);return await r.ensureMasterHash(),r}constructor(e,t){this.masterPassword=e,this.secretsDir=t??(0,i.join)((0,a.homedir)(),".personal-agent","secrets"),(0,s.mkdirSync)(this.secretsDir,{recursive:!0})}filePath(e){if(/[/\\]/.test(e))throw Error(`Invalid secret name: ${e}`);return(0,i.join)(this.secretsDir,`${e}.enc`)}masterHashPath(){return(0,i.join)(this.secretsDir,".master-hash")}async deriveKey(e){return await n(this.masterPassword,e,32,{N:16384,r:8,p:1})}async ensureMasterHash(){let e=this.masterHashPath();if((0,s.existsSync)(e)){let r=JSON.parse((0,s.readFileSync)(e,"utf-8")),i=Buffer.from(r.salt,"hex"),a=await this.deriveKey(i),n=Buffer.from(r.hash,"hex");if(!(0,t.timingSafeEqual)(a,n))throw Error("Master password mismatch. The password does not match the one used to create the secret store.")}else{let r=(0,t.randomBytes)(32),i=await this.deriveKey(r),a={salt:r.toString("hex"),hash:i.toString("hex")};(0,s.writeFileSync)(e,JSON.stringify(a),{encoding:"utf-8",mode:384})}}async has(e){return(0,s.existsSync)(this.filePath(e))}async get(e){let r=this.filePath(e);if(!(0,s.existsSync)(r))return null;let i=JSON.parse((0,s.readFileSync)(r,"utf-8")),a=Buffer.from(i.salt,"hex"),n=Buffer.from(i.iv,"hex"),h=Buffer.from(i.authTag,"hex"),c=Buffer.from(i.ciphertext,"hex"),f=await this.deriveKey(a),u=(0,t.createDecipheriv)(o,f,n);return u.setAuthTag(h),Buffer.concat([u.update(c),u.final()]).toString("utf-8")}async set(e,r){let i=(0,t.randomBytes)(32),a=(0,t.randomBytes)(12),n=await this.deriveKey(i),h=(0,t.createCipheriv)(o,n,a),c=Buffer.concat([h.update(r,"utf-8"),h.final()]),f=h.getAuthTag(),u={salt:i.toString("hex"),iv:a.toString("hex"),authTag:f.toString("hex"),ciphertext:c.toString("hex")};(0,s.writeFileSync)(this.filePath(e),JSON.stringify(u),{encoding:"utf-8",mode:384})}async delete(e){let t=this.filePath(e);(0,s.existsSync)(t)&&(0,s.unlinkSync)(t)}}e.s(["FileSecretClient",0,h,"resolveMasterPassword",0,function(e){if(process.env.PA_MASTER_PASSWORD)return process.env.PA_MASTER_PASSWORD;let t=e??(0,i.join)((0,a.homedir)(),".personal-agent","secrets"),r=(0,i.join)(t,".master-key");if((0,s.existsSync)(r)){let e=511&(0,s.statSync)(r).mode;if(384!==e&&256!==e)throw Error(`.master-key has permissions 0${e.toString(8)}, expected 0600 or 0400. Fix with: chmod 600 ${r}`);return(0,s.readFileSync)(r,"utf-8").trim()}return null}])}];

//# sourceMappingURL=%5Broot-of-the-server%5D__0gckkni._.js.map