// Code generated by templ - DO NOT EDIT. // templ: version: v0.3.819 package input //lint:file-ignore SA4006 This context is only used if a nested component is present. import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" func PasskeyInitial(addr string, userHandle string, challenge string) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { return templ_7745c5c3_CtxErr } templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { defer func() { templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) if templ_7745c5c3_Err == nil { templ_7745c5c3_Err = templ_7745c5c3_BufErr } }() } ctx = templ.InitializeContext(ctx) templ_7745c5c3_Var1 := templ.GetChildren(ctx) if templ_7745c5c3_Var1 == nil { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, navigatorCredentialsCreate(addr, userHandle, challenge)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, " Register Passkey") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } return nil }) } func PasskeyError(addr string, userHandle string, challenge string) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { return templ_7745c5c3_CtxErr } templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { defer func() { templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) if templ_7745c5c3_Err == nil { templ_7745c5c3_Err = templ_7745c5c3_BufErr } }() } ctx = templ.InitializeContext(ctx) templ_7745c5c3_Var3 := templ.GetChildren(ctx) if templ_7745c5c3_Var3 == nil { templ_7745c5c3_Var3 = templ.NopComponent } ctx = templ.ClearChildren(ctx) templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, navigatorCredentialsCreate(addr, userHandle, challenge)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, " Register Passkey") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } return nil }) } func PasskeySuccess(addr string, userHandle string, challenge string) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { return templ_7745c5c3_CtxErr } templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { defer func() { templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) if templ_7745c5c3_Err == nil { templ_7745c5c3_Err = templ_7745c5c3_BufErr } }() } ctx = templ.InitializeContext(ctx) templ_7745c5c3_Var5 := templ.GetChildren(ctx) if templ_7745c5c3_Var5 == nil { templ_7745c5c3_Var5 = templ.NopComponent } ctx = templ.ClearChildren(ctx) templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, navigatorCredentialsCreate(addr, userHandle, challenge)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, " Register Passkey") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } return nil }) } func navigatorCredentialsCreate(userId string, userHandle string, challenge string) templ.ComponentScript { return templ.ComponentScript{ Name: `__templ_navigatorCredentialsCreate_8f96`, Function: `function __templ_navigatorCredentialsCreate_8f96(userId, userHandle, challenge){const publicKey = { challenge: Uint8Array.from(challenge, (c) => c.charCodeAt(0)), rp: { name: "Sonr.ID", }, user: { // Assuming that userId is ASCII-only id: Uint8Array.from(userId, (c) => c.charCodeAt(0)), name: userId, displayName: userHandle, }, pubKeyCredParams: [ { type: "public-key", alg: -7, // "ES256" }, { type: "public-key", alg: -257, // "RS256" }, ], authenticatorSelection: { userVerification: "required", residentKey: "required", authenticatorAttachment: "platform", }, timeout: 60000, // 1 minute extensions: { payment: { isPayment: true, }, largeBlob: { supported: "preferred", }, }, }; // Helper function to convert ArrayBuffer to Base64URL string function arrayBufferToBase64URL(buffer) { const bytes = new Uint8Array(buffer); let str = ''; bytes.forEach(byte => { str += String.fromCharCode(byte) }); return btoa(str) .replace(/\+/g, '-') .replace(/\//g, '_') .replace(/=/g, ''); } navigator.credentials .create({ publicKey }) .then((newCredentialInfo) => { if (!(newCredentialInfo instanceof PublicKeyCredential)) { throw new Error('Received credential is not a PublicKeyCredential'); } const response = newCredentialInfo.response; if (!(response instanceof AuthenticatorAttestationResponse)) { throw new Error('Response is not an AuthenticatorAttestationResponse'); } // Convert the credential data to a cross-platform compatible format const credentialJSON = { id: newCredentialInfo.id, rawId: arrayBufferToBase64URL(newCredentialInfo.rawId), type: newCredentialInfo.type, authenticatorAttachment: newCredentialInfo.authenticatorAttachment || null, transports: Array.isArray(response.getTransports) ? response.getTransports() : [], clientExtensionResults: newCredentialInfo.getClientExtensionResults(), response: { attestationObject: arrayBufferToBase64URL(response.attestationObject), clientDataJSON: arrayBufferToBase64URL(response.clientDataJSON) } }; // Set the form value with the stringified credential data const credential = document.getElementById('credential-data'); credential.value = JSON.stringify(credentialJSON); // Submit the form const form = document.getElementById('passkey-form'); form.submit(); }) .catch((err) => { console.error('Passkey creation failed:', err); alert(` + "`" + `Failed to create passkey: ${err.message || 'Unknown error'}` + "`" + `); }); }`, Call: templ.SafeScript(`__templ_navigatorCredentialsCreate_8f96`, userId, userHandle, challenge), CallInline: templ.SafeScriptInline(`__templ_navigatorCredentialsCreate_8f96`, userId, userHandle, challenge), } } var _ = templruntime.GeneratedTemplate