1import{l as f}from"./index-f--GfbGy.js";function l(e){const t=new Uint8Array(e);let n="";for(const i of t)n+=String.fromCharCode(i);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function b(e){const t=e.replace(/-/g,"+").replace(/_/g,"/"),n=(4-t.length%4)%4,r=t.padEnd(t.length+n,"="),i=atob(r),s=new ArrayBuffer(i.length),o=new Uint8Array(s);for(let u=0;u<i.length;u++)o[u]=i.charCodeAt(u);return s}function R(){return window?.PublicKeyCredential!==void 0&&typeof window.PublicKeyCredential=="function"}function E(e){const{id:t}=e;return{...e,id:b(t),transports:e.transports}}function y(e){return e==="localhost"||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)}class a extends Error{constructor({message:t,code:n,cause:r,name:i}){super(t,{cause:r}),this.name=i??r.name,this.code=n}}function _({error:e,options:t}){const{publicKey:n}=t;if(!n)throw Error("options was missing required publicKey property");if(e.name==="AbortError"){if(t.signal instanceof AbortSignal)return new a({message:"Registration ceremony was sent an abort signal",code:"ERROR_CEREMONY_ABORTED",cause:e})}else if(e.name==="ConstraintError"){if(n.authenticatorSelection?.requireResidentKey===!0)return new a({message:"Discoverable credentials were required but no available authenticator supported it",code:"ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT",cause:e});if(n.authenticatorSelection?.userVerification==="required")return new a({message:"User verification was required but no available authenticator supported it",code:"ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT",cause:e})}else{if(e.name==="InvalidStateError")return new a({message:"The authenticator was previously registered",code:"ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED",cause:e});if(e.name==="NotAllowedError")return new a({message:e.message,code:"ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",cause:e});if(e.name==="NotSupportedError")return n.pubKeyCredParams.filter(i=>i.type==="public-key").length===0?new a({message:'No entry in pubKeyCredParams was of type "public-key"',code:"ERROR_MALFORMED_PUBKEYCREDPARAMS",cause:e}):new a({message:"No available authenticator supported any of the specified pubKeyCredParams algorithms",code:"ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG",cause:e});if(e.name==="SecurityError"){const r=window.location.hostname;if(y(r)){if(n.rp.id!==r)return new a({message:`The RP ID "${n.rp.id}" is invalid for this domain`,code:"ERROR_INVALID_RP_ID",cause:e})}else return new a({message:`${window.location.hostname} is an invalid domain`,code:"ERROR_INVALID_DOMAIN",cause:e})}else if(e.name==="TypeError"){if(n.user.id.byteLength<1||n.user.id.byteLength>64)return new a({message:"User ID was not between 1 and 64 characters",code:"ERROR_INVALID_USER_ID_LENGTH",cause:e})}else if(e.name==="UnknownError")return new a({message:"The authenticator was unable to process the specified options, or could not create a new credential",code:"ERROR_AUTHENTICATOR_GENERAL_ERROR",cause:e})}return e}class P{createNewAbortSignal(){if(this.controller){const n=new Error("Cancelling existing WebAuthn API call for new one");n.name="AbortError",this.controller.abort(n)}const t=new AbortController;return this.controller=t,t.signal}cancelCeremony(){if(this.controller){const t=new Error("Manually cancelling existing WebAuthn API call");t.name="AbortError",this.controller.abort(t),this.controller=void 0}}}const m=new P,I=["cross-platform","platform"];function A(e){if(e&&!(I.indexOf(e)<0))return e}async function C(e){if(!R())throw new Error("WebAuthn is not supported in this browser");const n={publicKey:{...e,challenge:b(e.challenge),user:{...e.user,id:b(e.user.id)},excludeCredentials:e.excludeCredentials?.map(E)}};n.signal=m.createNewAbortSignal();let r;try{r=await navigator.credentials.create(n)}catch(c){throw _({error:c,options:n})}if(!r)throw new Error("Registration was not completed");const{id:i,rawId:s,response:o,type:u}=r;let d;typeof o.getTransports=="function"&&(d=o.getTransports());let g;if(typeof o.getPublicKeyAlgorithm=="function")try{g=o.getPublicKeyAlgorithm()}catch(c){p("getPublicKeyAlgorithm()",c)}let h;
1if(typeof o.getPublicKey=="function")try{const c=o.getPublicKey();c!==null&&(h=l(c))}catch(c){p("getPublicKey()",c)}let w;if(typeof o.getAuthenticatorData=="function")try{w=l(o.getAuthenticatorData())}catch(c){p("getAuthenticatorData()",c)}return{id:i,rawId:l(s),response:{attestationObject:l(o.attestationObject),clientDataJSON:l(o.clientDataJSON),transports:d,publicKeyAlgorithm:g,publicKey:h,authenticatorData:w},type:u,clientExtensionResults:r.getClientExtensionResults(),authenticatorAttachment:A(r.authenticatorAttachment)}}function p(e,t){console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${e}. You should report this error to them. 2`,t)}function O(){if(!R())return new Promise(t=>t(!1));const e=window.PublicKeyCredential;return e.isConditionalMediationAvailable===void 0?new Promise(t=>t(!1)):e.isConditionalMediationAvailable()}function T({error:e,options:t}){const{publicKey:n}=t;if(!n)throw Error("options was missing required publicKey property");if(e.name==="AbortError"){if(t.signal instanceof AbortSignal)return new a({message:"Authentication ceremony was sent an abort signal",code:"ERROR_CEREMONY_ABORTED",cause:e})}else{if(e.name==="NotAllowedError")return new a({message:e.message,code:"ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",cause:e});if(e.name==="SecurityError"){const r=window.location.hostname;if(y(r)){if(n.rpId!==r)return new a({message:`The RP ID "${n.rpId}" is invalid for this domain`,code:"ERROR_INVALID_RP_ID",cause:e})}else return new a({message:`${window.location.hostname} is an invalid domain`,code:"ERROR_INVALID_DOMAIN",cause:e})}else if(e.name==="UnknownError")return new a({message:"The authenticator was unable to process the specified options, or could not create a new assertion signature",code:"ERROR_AUTHENTICATOR_GENERAL_ERROR",cause:e})}return e}async function S(e,t=!1){if(!R())throw new Error("WebAuthn is not supported in this browser");let n;e.allowCredentials?.length!==0&&(n=e.allowCredentials?.map(E));const r={...e,challenge:b(e.challenge),allowCredentials:n},i={};if(t){if(!await O())throw Error("Browser does not support WebAuthn autofill");if(document.querySelectorAll("input[autocomplete$='webauthn']").length<1)throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');i.mediation="conditional",r.allowCredentials=[]}i.publicKey=r,i.signal=m.createNewAbortSignal();let s;try{s=await navigator.credentials.get(i)}catch(w){throw T({error:w,options:i})}if(!s)throw new Error("Authentication was not completed");const{id:o,rawId:u,response:d,type:g}=s;let h;return d.userHandle&&(h=l(d.userHandle)),{id:o,rawId:l(u),response:{authenticatorData:l(d.authenticatorData),clientDataJSON:l(d.clientDataJSON),signature:l(d.signature),userHandle:h},type:g,clientExtensionResults:s.getClientExtensionResults(),authenticatorAttachment:A(s.authenticatorAttachment)}}async function v(e={}){const t=await f.functions.invoke("passkey-register-begin",{body:{origin:window.location.origin,device_label:e.deviceLabel}});if(t.error)throw new Error(t.error.message??"Could not start passkey registration");const n=t.data.options,r=await C(n),i=await f.functions.invoke("passkey-register-finish",{body:{origin:window.location.origin,response:r,device_label:e.deviceLabel}});if(i.error)throw new Error(i.error.message??"Could not finish passkey registration");return i.data}async function K(){const e=await f.functions.invoke("passkey-auth-begin",{body:{origin:window.location.origin}});if(e.error)throw new Error(e.error.message??"Could not start passkey sign-in");const t=e.data.options,n=await S(t),r=await f.functions.invoke("passkey-auth-finish",{body:{origin:window.location.origin,response:n}});if(r.error)throw new Error(r.error.message??"Passkey sign-in failed");const i=r.data,{error:s}=await f.auth.verifyOtp({type:"magiclink",token_hash:i.token_hash});if(s)throw new Error(s.message);return{ok:!0}}async function N(){const{data:e,error:t}=await f.from("passkey_credentials").select("id, device_label, last_used_at, created_at, transports").order("created_at",{ascending:!1});if(t)throw new Error(t.message);return e??[]}async function k(e){const{error:t}=await f.from("passkey_credentials").delete().eq("id",e);if(t)throw new Error(t.message)}export{k as d,N as l,v as r,K as s};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.