(()=>{"use strict";var e={6561:(e,t,n)=>{n.r(t)}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var a=t[r]={exports:{}};return e[r](a,a.exports,n),a.exports}function r(e){const t=window.location.href;e=e.replace(/[\[\]]/g,"\\$&");const n=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)").exec(t);return n?n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):"":null}function o(e,t=!1){return t&&(e=e.replace(/ /g,"+")),decodeURIComponent(Array.prototype.map.call(atob(e),(e=>"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2))).join(""))}function a(e){if(Array.isArray(e)&&(e=Uint8Array.from(e)),e instanceof ArrayBuffer&&(e=new Uint8Array(e)),e instanceof Uint8Array){let t="";const n=e.byteLength;for(let r=0;r<n;r++)t+=String.fromCharCode(e[r]);e=window.btoa(t)}if("string"!=typeof e)throw new Error("could not coerce to string");return e=e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=*$/g,"")}n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(6561);const i="bitwarden://webauthn-callback";let c,d=!1,s=null,l=null,u=null,p=null,g=null,f=null,w=!1,y=!1,b=!1,m=null;const h=["tw-bg-secondary-300","tw-border-secondary-300","!tw-text-muted","!tw-cursor-not-allowed","hover:tw-bg-secondary-300","hover:tw-border-secondary-300","hover:!tw-text-muted","hover:tw-no-underline"],v=["tw-bg-primary-600","tw-border-primary-600","!tw-text-contrast","hover:tw-bg-primary-700","hover:tw-border-primary-700","hover:!tw-text-contrast","hover:tw-no-underline"];function x(){if(!l)return;const e=document.getElementById("webauthn-button");e.onclick=C,e.innerText=decodeURI(l),e.classList.remove(...h),e.classList.add(...v)}function U(){if(d)return;if(g=r("parent"),!g)return void I("No parent.");g=decodeURIComponent(g),f=new URL(g).origin;"1"===r("v")?function(){const e=r("data");if(!e)return void I("No data.");c=o(e),s=r("headerText"),l=r("btnText"),u=r("btnAwaitingInteractionText"),p=r("btnReturnText")}():function(){let e=null;try{e=JSON.parse(o(r("data")))}catch(t){return void I("Cannot parse data.")}w=null!=e.callbackUri||!0===e.mobile,c=e.data,s=e.headerText,l=e.btnText,p=e.btnReturnText}(),d=!0}function A(){if(b=!1,"credentials"in navigator){if(U(),s){document.getElementById("webauthn-header").innerText=decodeURI(s)}if(x(),c){try{m=function(e){const t=JSON.parse(e),n=t.challenge.replace(/-/g,"+").replace(/_/g,"/");return t.challenge=Uint8Array.from(atob(n),(e=>e.charCodeAt(0))),t.allowCredentials.forEach((e=>{const t=e.id.replace(/\_/g,"/").replace(/\-/g,"+");e.id=Uint8Array.from(atob(t),(e=>e.charCodeAt(0)))})),t}(c)}catch(e){return void I("Cannot parse webauthn data.")}y=!1,w||-1!==navigator.userAgent.indexOf(" Safari/")&&-1===navigator.userAgent.indexOf("Chrome")||C()}else I("No data.")}else I("WebAuthn is not supported in this browser.")}function C(){y?x():(!function(){if(!u)return;const e=document.getElementById("webauthn-button");e.innerText=decodeURI(u),e.onclick=null,e.classList.remove(...v),e.classList.add(...h)}(),navigator.credentials.get({publicKey:m}).then(R).catch(I))}function I(e){w?(document.location.replace(i+"?error="+encodeURIComponent(e)),T(i+"?error="+encodeURIComponent(e))):(parent.postMessage("error|"+e,g),x())}function R(e){if(b)return;const t=function(e){const t=e.response,n=new Uint8Array(t.authenticatorData),r=new Uint8Array(t.clientDataJSON),o=new Uint8Array(e.rawId),i=new Uint8Array(t.signature),c={id:e.id,rawId:a(o),type:e.type,extensions:e.getClientExtensionResults(),response:{authenticatorData:a(n),clientDataJson:a(r),signature:a(i)}};return JSON.stringify(c)}(e);w?(document.location.replace(i+"?data="+encodeURIComponent(t)),T(i+"?data="+encodeURIComponent(t))):(parent.postMessage("success|"+t,g),b=!0)}function T(e){const t=document.getElementById("webauthn-button");t.innerText=decodeURI(p),t.onclick=()=>{document.location.replace(e)}}document.addEventListener("DOMContentLoaded",(()=>{var e;A(),window.addEventListener("message",(e=>{e.origin&&""!==e.origin&&e.origin===f&&("stop"===e.data?(x(),y=!0):"start"===e.data&&y&&A())}),!1),e="ready",w||parent.postMessage("info|"+e,g)}))})();
//# sourceMappingURL=webauthn.b8f01de2a110dcccf490.js.map