mirror of
https://github.com/onsonr/hway.git
synced 2025-03-10 13:07:09 +00:00
149 lines
5.3 KiB
Go
149 lines
5.3 KiB
Go
// Code generated by templ - DO NOT EDIT.
|
|
|
|
// templ: version: v0.2.793
|
|
package islands
|
|
|
|
//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 InputPasskey(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 = templ_7745c5c3_Buffer.WriteString("<sl-button style=\"width: 100%;\" onclick=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var2 templ.ComponentScript = navigatorCredentialsCreate(addr, userHandle, challenge)
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2.Call)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><sl-icon slot=\"prefix\" name=\"passkey\" library=\"sonr\" style=\"font-size: 24px;\" class=\"text-neutral-500\"></sl-icon> Register Passkey</sl-button>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return templ_7745c5c3_Err
|
|
})
|
|
}
|
|
|
|
func navigatorCredentialsCreate(userId string, userHandle string, challenge string) templ.ComponentScript {
|
|
return templ.ComponentScript{
|
|
Name: `__templ_navigatorCredentialsCreate_63c0`,
|
|
Function: `function __templ_navigatorCredentialsCreate_63c0(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_63c0`, userId, userHandle, challenge),
|
|
CallInline: templ.SafeScriptInline(`__templ_navigatorCredentialsCreate_63c0`, userId, userHandle, challenge),
|
|
}
|
|
}
|
|
|
|
var _ = templruntime.GeneratedTemplate
|