{"version":3,"sources":["backend.ts"],"sourcesContent":["import { Datex } from \"datex-core-legacy/mod.ts\";\n\nconst sessions = new Map<Datex.Endpoint, Set<string>>().setAutoDefault(Set)\nconst unverifiedSessions = new Map<Datex.Endpoint, Set<string>>().setAutoDefault(Set)\n\nexport function createSession(endpoint: Datex.Endpoint, verified = true) {\n\t// SECURITY: cryptographically secure random session token (Math.random() is predictable)\n\tconst token = Array.from(crypto.getRandomValues(new Uint8Array(32)), b => b.toString(16).padStart(2, \"0\")).join(\"\");\n\tif (verified) sessions.getAuto(endpoint.main).add(token)\n\telse unverifiedSessions.getAuto(endpoint.main).add(token)\n\treturn token;\n}\n\nexport function validateVerifiedSession(endpoint: Datex.Endpoint, token: string) {\n\treturn sessions.getAuto(endpoint.main).has(token)\n}\n\nexport function validateUnverifiedSession(endpoint: Datex.Endpoint, token: string) {\n\t// SECURITY: previously returned the result of Map.delete() for invalid tokens (true if a session existed),\n\t// which accepted any token for endpoints with an unverified session\n\treturn unverifiedSessions.get(endpoint.main)?.has(token) ?? false;\n}\n\nexport function unverifiedSessionExists(endpoint: Datex.Endpoint) {\n\treturn unverifiedSessions.has(endpoint.main)\n}"],"names":["sessions","Map","setAutoDefault","Set","unverifiedSessions","createSession","endpoint","verified","token","Array","from","crypto","getRandomValues","Uint8Array","b","toString","padStart","join","getAuto","main","add","validateVerifiedSession","has","validateUnverifiedSession","get","unverifiedSessionExists"],"mappings":"AAEA,IAAMA,WAAW,IAAIC,MAAmCC,cAAc,CAACC,MACjEC,qBAAqB,IAAIH,MAAmCC,cAAc,CAACC;AAEjF,OAAO,SAASE,cAAcC,QAAwB,EAAEC,WAAW,CAAA,CAAI;IAEtE,IAAMC,QAAQC,MAAMC,IAAI,CAACC,OAAOC,eAAe,CAAC,IAAIC,WAAW,MAAMC,CAAAA,IAAKA,EAAEC,QAAQ,CAAC,IAAIC,QAAQ,CAAC,GAAG,MAAMC,IAAI,CAAC;IAGhH,OAFIV,WAAUP,SAASkB,OAAO,CAACZ,SAASa,IAAI,EAAEC,GAAG,CAACZ,SAC7CJ,mBAAmBc,OAAO,CAACZ,SAASa,IAAI,EAAEC,GAAG,CAACZ,QAC5CA;AACR;AAEA,OAAO,SAASa,wBAAwBf,QAAwB,EAAEE,KAAa;IAC9E,OAAOR,SAASkB,OAAO,CAACZ,SAASa,IAAI,EAAEG,GAAG,CAACd;AAC5C;AAEA,OAAO,SAASe,0BAA0BjB,QAAwB,EAAEE,KAAa;IAGhF,OAAOJ,mBAAmBoB,GAAG,CAAClB,SAASa,IAAI,GAAGG,IAAId,UAAU,CAAA;AAC7D;AAEA,OAAO,SAASiB,wBAAwBnB,QAAwB;IAC/D,OAAOF,mBAAmBkB,GAAG,CAAChB,SAASa,IAAI;AAC5C","sourceRoot":"/lib/uix-0.3.33/src/session/","file":"backend.ts"}