1(function(n,u){const c=u(n||{});typeof module<"u"&&module.exports&&(module.exports={...c,createDeviceSession:u}),n&&(n.XxdDeviceSession=c)})(typeof globalThis<"u"?globalThis:this,function(n){const u="xxd-device-session-v1",c="device-keys",b="primary",K="xxd-device-session-v1",k=typeof TextEncoder=="function"?new TextEncoder:null;let d=null,_=null,l=null,v=0,f=null,o=null;const p=new Set;function E(e,t){return String(n.__XXD_LOCALE__||n.document?.documentElement?.lang||"zh-CN").toLowerCase().startsWith("en")?t:e}function s(e,t=e){const r=new Error(t);return r.code=e,r}function C(){return!!(n.crypto?.subtle&&n.crypto?.getRandomValues&&k)}function y(e){return!!(e&&/^[A-Za-z0-9_-]{16,128}$/.test(String(e.deviceId||""))&&e.privateKey&&e.privateKey.type==="private"&&e.privateKey.extractable===!1&&e.publicJwk?.kty==="EC"&&e.publicJwk?.crv==="P-256")}function I(){if(typeof n.crypto?.randomUUID=="function")return n.crypto.randomUUID();const e=new Uint8Array(24);return n.crypto.getRandomValues(e),S(e)}function S(e){let t="";for(const r of e)t+=String.fromCharCode(r);return n.btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function x(){return new Promise((e,t)=>{if(!n.indexedDB)return t(s("device_storage_unavailable"));const r=n.indexedDB.open(u,1);r.onupgradeneeded=()=>{r.result.objectStoreNames.contains(c)||r.result.createObjectStore(c)},r.onsuccess=()=>e(r.result),r.onerror=()=>t(r.error||s("device_storage_unavailable")),r.onblocked=()=>t(s("device_storage_blocked"))})}async function O(){const e=await x();try{return await new Promise((t,r)=>{const a=e.transaction(c,"readonly").objectStore(c).get(b);a.onsuccess=()=>t(a.result||null),a.onerror=()=>r(a.error||s("device_storage_read_failed"))})}finally{e.close()}}async function J(e){const t=await x();try{await new Promise((r,a)=>{const i=t.transaction(c,"readwrite");i.objectStore(c).put(e,b),i.oncomplete=()=>r(),i.onerror=()=>a(i.error||s("device_storage_write_failed")),i.onabort=()=>a(i.error||s("device_storage_write_failed"))})}finally{t.close()}}function g(){if(o||typeof n.BroadcastChannel!="function")return o;try{o=new n.BroadcastChannel(K),o.onmessage=e=>{const t=e?.data||{};if(t.type==="key-request"&&y(_))try{o.postMessage({type:"key-offer",record:_})}catch{}if(t.type==="key-offer"&&y(t.record)){for(const r of p)r(t.record);p.clear()}t.type==="session-renewed"&&(v=0,f=null)}}catch{o=null}return o}async function L(e=250){const t=g();return t?new Promise(r=>{let a=!1;const i=h=>{a||(a=!0,p.delete(i),r(h))};p.add(i);try{t.postMessage({type:"key-request"})}catch{i(null)}n.setTimeout(()=>i(null),e)}):null}async function U(){const e=await n.crypto.subtle.generateKey({name:"ECDSA",namedCurve:"P-256"},!1,["sign","verify"]),t=await n.crypto.subtle.exportKey("jwk",e.publicKey);return{deviceId:I(),privateKey:e.privateKey,publicJwk:{kty:"EC",crv:"P-256",x:t.x,y:t.y},createdThisLoad:!0,temporary:!1}}async function j(){if(!C())throw s("device_crypto_unsupported",E("å½åæµè§å¨ä¸æ¯æä¼å设å¤å®å
¨å¯é¥ã","This browser does not support the member device security key."));g();try{const r=await O();if(y(r))return{...r,createdThisLoad:!1,temporary:!1}}catch{}const e=await L();if(y(e))return{...e,createdThisLoad:!1,temporary:!0};const t=await U();try{const r={deviceId:t.deviceId,privateKey:t.privateKey,publicJwk:t.publicJwk};return await J(r),t}catch{return{...t,temporary:!0}}}function A(){return d||(d=j().then(e=>(_=e,e)).catch(e=>{throw d=null,e})),d}async function T(){const e=await A();return{deviceId:e.deviceId,publicJwk:e.publicJwk}}function D(e){if(!(!e||e==="logged_out")){n.__XXD_DEVICE_AUTH_ERROR=e;try{const t=new URL(n.location.href);t.searchParams.get("auth_error")||t.searchParams.set("auth_error",e),n.history?.replaceState?.({},"",`${t.pathname}${t.search}${t.hash}`)}catch{}}}async function P(){try{await n.fetch("/api/auth/local-forget",{method:"POST",credentials:"same-origin",headers:{accept:"application/json"},keepalive:!0})}catch{}}async function m(e){const t=await e.json().catch(()=>({}));if(!e.ok){const r=s(t?.error||"device_session_unavailable",t?.message||t?.error||E("设å¤ä¼è¯ææ¶ä¸å¯ç¨ã","The device session is temporarily unavailable."));throw r.status=e.status,r.payload=t,r}return t}async function B(e){const t={accept:"application/json"};return e?.deviceId&&(t["x-xxd-device-id"]=e.deviceId),m(await n.fetch("/api/session",{credentials:"same-origin",cache:"no-store",headers:t}))}async function M(e,t){const r=await n.crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e.privateKey,k.encode(t)),a=JSON.stringify({deviceId:e.deviceId,challenge:t,signature:S(new Uint8Array(r))});let i=null;for(let h=0;h<2;
1h+=1)try{return await m(await n.fetch("/api/session/renew",{method:"POST",credentials:"same-origin",headers:{accept:"application/json","content-type":"application/json"},body:a}))}catch(w){if(i=w,w?.status&&w.status<500)throw w}throw i||s("device_renewal_failed")}async function N(){let e=null,t=null;try{e=await A()}catch(a){t=a}const r=await B(e);if(r?.challenge&&e)try{const a=await M(e,r.challenge);try{g()?.postMessage({type:"session-renewed"})}catch{}return a}catch(a){if(r.leaseValid===!1&&D("device_renewal_failed"),r.leaseValid===!1)throw a;return{...r,renewalFailed:!0}}if(r?.authenticated===!1&&r.reason!=="logged_out"){let a=r.reason;return a==="device_reauthentication_required"&&(t?.code==="device_crypto_unsupported"?a="device_crypto_unsupported":e?.createdThisLoad&&(a="device_key_missing")),await P(),D(a),{...r,reason:a}}return r}function q(e){const t=n.navigator?.locks;return typeof t?.request=="function"?t.request("xxd-device-session-renew",{mode:"exclusive"},e):e()}function R({force:e=!1}={}){return!e&&f&&Date.now()-v<4e3?Promise.resolve(f):l||(l=q(async()=>{const t=await N();return f=t,v=Date.now(),t}).finally(()=>{l=null}),l)}async function H(e){try{await R()}catch{}return typeof e=="function"?e():void 0}async function V(){const e=await T();return await m(await n.fetch("/api/auth/device-intent",{method:"POST",credentials:"same-origin",headers:{accept:"application/json","content-type":"application/json"},body:JSON.stringify(e)})),!0}return{getBinding:T,checkSession:R,guard:H,prepareOAuth:V,localForget:P,cryptoAvailable:C}});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.