#!/usr/bin/env node
import'./chunk-XHJ27CER.js';import*as n from'fs';import*as f from'path';import*as p from'os';import*as s from'crypto';var d=f.join(p.homedir(),".paradigm","score"),a=f.join(d,"peers.json"),g=300*1e3;function i(){try{if(!n.existsSync(a))return [];let r=n.readFileSync(a,"utf-8"),e=JSON.parse(r);return Array.isArray(e)?e:[]}catch{return []}}function c(r){n.existsSync(d)||n.mkdirSync(d,{recursive:true}),n.writeFileSync(a,JSON.stringify(r,null,2),{mode:384});}function S(r){return i().find(t=>t.id===r)??null}function l(r){let e=i(),t=e.findIndex(o=>o.id===r.id);t>=0?e[t]=r:e.push(r),c(e);}function m(r){let e=i(),t=e.find(o=>o.id===r);return t?(t.revoked=true,c(e),true):false}function x(){let e=i().length;return n.existsSync(a)&&n.unlinkSync(a),e}function y(r){let e=i(),t=e.find(o=>o.id===r);t&&(t.lastSeen=new Date().toISOString(),c(e));}function P(r,e){let t=i(),o=t.find(u=>u.id===r);o&&(o.agents=e,c(t));}function A(){let r=s.randomBytes(32).toString("hex"),e=(parseInt(s.randomBytes(3).toString("hex"),16)%1e6).toString().padStart(6,"0"),t=s.createHash("sha256").update(e).digest("hex");return {code:e,codeHash:t,sharedSecret:r,createdAt:Date.now()}}function v(r,e){return Date.now()-r.createdAt>g?false:s.createHash("sha256").update(e).digest("hex")===r.codeHash}function h(r,e){return s.createHmac("sha256",e).update(r).digest("hex")}function R(r,e,t){let o=h(r,e);if(o.length!==t.length)return  false;try{return s.timingSafeEqual(Buffer.from(o,"hex"),Buffer.from(t,"hex"))}catch{return  false}}export{g as PAIRING_TTL_MS,a as PEERS_FILE,l as addPeer,h as computeHmacProof,S as findPeer,x as forgetAllPeers,A as generatePairing,i as loadPeers,m as revokePeer,c as savePeers,P as updatePeerAgents,y as updatePeerLastSeen,R as verifyHmacProof,v as verifyPairingCode};