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