1import{t as e}from"./index-DMA67SNg.js";function t(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=``;for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function n(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`)+`===`.slice((e.length+3)%4),n=atob(t),r=new ArrayBuffer(n.length),i=new Uint8Array(r);for(let e=0;e<n.length;e++)i[e]=n.charCodeAt(e);return r}async function r(r){if(!r.challenge||!r.userHandle)return{ok:!1,error:`Firefox pending request missing challenge or userHandle`};let i=n(r.challenge),a=n(r.userHandle),o;try{let e=await navigator.credentials.create({publicKey:{challenge:i,rp:{id:r.rpId,name:r.rpName},user:{id:a,name:r.userName,displayName:r.userDisplayName??r.userName},pubKeyCredParams:[{type:`public-key`,alg:-7},{type:`public-key`,alg:-8}],authenticatorSelection:{residentKey:`preferred`,userVerification:`preferred`},timeout:6e4}});if(!e||!(e instanceof PublicKeyCredential))return{ok:!1,error:`no credential returned`};o=e}catch(e){return e instanceof DOMException&&e.name===`NotAllowedError`?{ok:!1,error:`user cancelled`}:{ok:!1,error:e instanceof Error?e.message:`credential creation failed`}}let s=o.response,c=s.getPublicKeyAlgorithm()===-8?-8:-7,l=s.getPublicKey(),u=typeof s.getTransports==`function`?s.getTransports():[`internal`],d=await e({type:`COMPLETE_FIREFOX_PASSKEY_CREATE`,payload:{requestId:r.requestId,rpId:r.rpId,rpName:r.rpName,userName:r.userName,userDisplayName:r.userDisplayName,userHandle:r.userHandle,credentialId:o.id,publicKeyCose:l?t(l):``,algorithm:c,transports:u,backupEligible:!1,backupState:!1}});return d?.ok?{ok:!0}:{ok:!1,error:d?.error??`vault store failed`}}export{r as createFirefoxPasskey};