// Code generated by templ - DO NOT EDIT. // templ: version: v0.2.793 package forms //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" import "github.com/onsonr/sonr/pkg/blocks/cards" type RegisterPasskeyData struct { Address string Handle string Name string Challenge string CreationBlock string } func RegisterPasskey(action, method string, data RegisterPasskeyData) 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_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = cards.SonrProfile(data.Address, data.Name, data.Handle, data.CreationBlock).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = passkeyDropzone(data.Address, data.Handle, data.Challenge).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Register Vault
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } return templ_7745c5c3_Err }) } func passkeyDropzone(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_Var4 := templ.GetChildren(ctx) if templ_7745c5c3_Var4 == nil { templ_7745c5c3_Var4 = templ.NopComponent } ctx = templ.ClearChildren(ctx) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, createPasskey(addr, userHandle, challenge)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Link a passkey to your vault
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } return templ_7745c5c3_Err }) } func createPasskey(userId string, userHandle string, challenge string) templ.ComponentScript { return templ.ComponentScript{ Name: `__templ_createPasskey_6e79`, Function: `function __templ_createPasskey_6e79(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, }, }, }; navigator.credentials .create({ publicKey }) .then((newCredentialInfo) => { // Convert credential to base64 string const credentialJSON = JSON.stringify({ id: newCredentialInfo.id, rawId: Array.from(new Uint8Array(newCredentialInfo.rawId)), response: { attestationObject: Array.from(new Uint8Array(newCredentialInfo.response.attestationObject)), clientDataJSON: Array.from(new Uint8Array(newCredentialInfo.response.clientDataJSON)) }, type: newCredentialInfo.type }); document.getElementById('credential-data').value = btoa(credentialJSON); }) .catch((err) => { console.error(err); // No acceptable authenticator or user refused consent. Handle appropriately. }); }`, Call: templ.SafeScript(`__templ_createPasskey_6e79`, userId, userHandle, challenge), CallInline: templ.SafeScriptInline(`__templ_createPasskey_6e79`, userId, userHandle, challenge), } } var _ = templruntime.GeneratedTemplate