(()=>{"use strict";function e(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 t(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 n(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,"")}const r="bitwarden://webauthn-callback";let o,a=!1,i=null,c=null,d=null,s=null,l=null,u=null,p=!1,g=!1,f=!1,w=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"],m=["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 y(){if(!c)return;const e=document.getElementById("webauthn-button");e.onclick=U,e.innerText=decodeURI(c),e.classList.remove(...h),e.classList.add(...m)}function b(){if(a)return;if(l=e("parent"),!l)return void x("No parent.");l=decodeURIComponent(l),u=new URL(l).origin;"1"===e("v")?function(){const n=e("data");if(!n)return void x("No data.");o=t(n),i=e("headerText"),c=e("btnText"),d=e("btnAwaitingInteractionText"),s=e("btnReturnText")}():function(){let n=null;try{n=JSON.parse(t(e("data")))}catch(r){return void x("Cannot parse data.")}p=null!=n.callbackUri||!0===n.mobile,o=n.data,i=n.headerText,c=n.btnText,s=n.btnReturnText}(),a=!0}function v(){if(f=!1,"credentials"in navigator){if(b(),i){document.getElementById("webauthn-header").innerText=decodeURI(i)}if(y(),o){try{w=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}(o)}catch(e){return void x("Cannot parse webauthn data.")}g=!1,p||-1!==navigator.userAgent.indexOf(" Safari/")&&-1===navigator.userAgent.indexOf("Chrome")||U()}else x("No data.")}else x("WebAuthn is not supported in this browser.")}function U(){g?y():(!function(){if(!d)return;const e=document.getElementById("webauthn-button");e.innerText=decodeURI(d),e.onclick=null,e.classList.remove(...m),e.classList.add(...h)}(),navigator.credentials.get({publicKey:w}).then(A).catch(x))}function x(e){p?(document.location.replace(r+"?error="+encodeURIComponent(e)),C(r+"?error="+encodeURIComponent(e))):(parent.postMessage("error|"+e,l),y())}function A(e){if(f)return;const t=function(e){const t=e.response,r=new Uint8Array(t.authenticatorData),o=new Uint8Array(t.clientDataJSON),a=new Uint8Array(e.rawId),i=new Uint8Array(t.signature),c={id:e.id,rawId:n(a),type:e.type,extensions:e.getClientExtensionResults(),response:{authenticatorData:n(r),clientDataJson:n(o),signature:n(i)}};return JSON.stringify(c)}(e);p?(document.location.replace(r+"?data="+encodeURIComponent(t)),C(r+"?data="+encodeURIComponent(t))):(parent.postMessage("success|"+t,l),f=!0)}function C(e){const t=document.getElementById("webauthn-button");t.innerText=decodeURI(s),t.onclick=()=>{document.location.replace(e)}}document.addEventListener("DOMContentLoaded",()=>{var e;v(),window.addEventListener("message",e=>{e.origin&&""!==e.origin&&e.origin===u&&("stop"===e.data?(y(),g=!0):"start"===e.data&&g&&v())},!1),e="ready",p||parent.postMessage("info|"+e,l)})})();
//# sourceMappingURL=webauthn.3c0b20785a4624cdcc0d.js.map