mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
196 lines
7.8 KiB
Go
196 lines
7.8 KiB
Go
// 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("<form action=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var2 templ.SafeURL = templ.SafeURL(action)
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var2)))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" method=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var3 string
|
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(method)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/blocks/forms/register_passkey.templ`, Line: 14, Col: 55}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><input type=\"hidden\" name=\"credential\" id=\"credential-data\" required> <sl-card class=\"card-form gap-4 max-w-lg\"><div slot=\"header\"><div class=\"w-full py-1\">")
|
|
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("</div></div>")
|
|
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("<div slot=\"footer\"><sl-button type=\"submit\" pill style=\"width: 100%;\" variant=\"primary\"><sl-icon slot=\"prefix\" name=\"shield-fill-check\"></sl-icon> Register Vault <sl-icon slot=\"suffix\" name=\"arrow-outbound\" library=\"sonr\"></sl-icon></sl-button></div><style>\n \t\t.card-form [slot='footer'] {\n \t\tdisplay: flex;\n \t\tjustify-content: space-between;\n \t\talign-items: center;\n \t\t}\n\t\t</style></sl-card></form>")
|
|
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("<div class=\"w-full flex flex-col items-center justify-center\">")
|
|
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("<div class=\"w-full p-4 border-dashed border-2 border-neutral-500 cursor-pointer rounded-md hover:border-neutral-400 transition-colors\" onclick=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var5 templ.ComponentScript = createPasskey(addr, userHandle, challenge)
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var5.Call)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><div class=\"flex flex-col items-center gap-2\"><sl-icon slot=\"prefix\" name=\"passkey\" library=\"sonr\" style=\"font-size: 24px;\" class=\"text-neutral-500\"></sl-icon> <span class=\"text-neutral-500\">Link a passkey to your vault</span></div></div></div>")
|
|
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
|