function a(n){let e="";for(const o of n)e+=String.fromCharCode(o);return(typeof btoa=="function"?btoa(e):Buffer.from(n).toString("base64")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function s(n){return a(new TextEncoder().encode(JSON.stringify(n)))}async function b(n){const e=Math.floor((n.nowMs??Date.now())/1e3),t=n.ttlSeconds??6*60*60,o={alg:"HS256",typ:"JWT"},r={iss:n.apiKey,sub:n.identity,name:n.name??n.identity,nbf:e,iat:e,exp:e+t,video:{room:n.grant.room,roomJoin:n.grant.roomJoin??!0,canPublish:n.grant.canPublish??!0,canSubscribe:n.grant.canSubscribe??!0,canPublishData:n.grant.canPublishData??!0}},c=`${s(o)}.${s(r)}`,i=await crypto.subtle.importKey("raw",new TextEncoder().encode(n.apiSecret),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),u=await crypto.subtle.sign("HMAC",i,new TextEncoder().encode(c));return`${c}.${a(new Uint8Array(u))}`}function f(n){const t=(n.split(".")[1]??"").replace(/-/g,"+").replace(/_/g,"/"),o=typeof atob=="function"?atob(t):Buffer.from(t,"base64").toString("binary"),r=Uint8Array.from(o,c=>c.charCodeAt(0));return JSON.parse(new TextDecoder().decode(r))}async function l(n,e){const[t,o,r]=n.split(".");if(!t||!o||!r)return!1;const c=await crypto.subtle.importKey("raw",new TextEncoder().encode(e),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),i=await crypto.subtle.sign("HMAC",c,new TextEncoder().encode(`${t}.${o}`));return a(new Uint8Array(i))===r}export{f as decodeJwtPayload,b as mintLiveKitToken,l as verifyLiveKitToken};
//# sourceMappingURL=livekit_token-CF-llvhK.js.map
