(no commit message provided)

This commit is contained in:
Prad Nukala
2024-07-05 22:20:13 -04:00
committed by Prad Nukala (aider)
commit 5fd43dfd6b
457 changed files with 115535 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
package js
templ Credentials() {
}
script CreateCredential(formId string) {
// Base64 encoding and decoding functions
function arrayBufferToBase64(buffer) {
return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)))
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=/g, "");
}
function base64ToArrayBuffer(base64) {
const binary = atob(base64.replace(/-/g, "+").replace(/_/g, "/"));
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i);
}
return bytes.buffer;
}
// Check if the form is valid
const form = document.getElementById(formId);
if (!form.checkValidity()) {
form.reportValidity();
return;
}
// Get user information from the form
const name = document.getElementById('name').value;
const handle = document.getElementById('handle').value;
let credential = navigator.credentials.create({
publicKey: {
challenge: new Uint8Array([117, 61, 252, 231, 191, 241]),
rp: { name: "ACME Corporation" },
user: {
id: new Uint8Array([79, 252, 83, 72, 214, 7, 89, 26]),
name: handle,
displayName: name
},
pubKeyCredParams: [{ type: "public-key", alg: -7 }]
}
}).then(credential => {
// Prepare the credential data
let credentialData = {
id: credential.id,
type: credential.type,
rawId: arrayBufferToBase64(credential.rawId),
response: {
clientDataJSON: arrayBufferToBase64(credential.response.clientDataJSON),
attestationObject: arrayBufferToBase64(credential.response.attestationObject)
},
clientExtensionResults: credential.getClientExtensionResults()
};
// Set the serialized credential data as the form value
document.getElementById('credentialData').value = JSON.stringify(credentialData);
// Submit the form
form.submit();
}).catch(error => {
console.error('Error creating credential:', error);
// Handle the error (e.g., show an error message to the user)
});
}
+101
View File
@@ -0,0 +1,101 @@
// Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.731
package js
//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 Credentials() 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
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)
return templ_7745c5c3_Err
})
}
func createCredential(formId string) templ.ComponentScript {
return templ.ComponentScript{
Name: `__templ_createCredential_190e`,
Function: `function __templ_createCredential_190e(formId){// Base64 encoding and decoding functions
function arrayBufferToBase64(buffer) {
return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)))
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=/g, "");
}
function base64ToArrayBuffer(base64) {
const binary = atob(base64.replace(/-/g, "+").replace(/_/g, "/"));
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i);
}
return bytes.buffer;
}
// Check if the form is valid
const form = document.getElementById(formId);
if (!form.checkValidity()) {
form.reportValidity();
return;
}
// Get user information from the form
const name = document.getElementById('name').value;
const handle = document.getElementById('handle').value;
let credential = navigator.credentials.create({
publicKey: {
challenge: new Uint8Array([117, 61, 252, 231, 191, 241]),
rp: { name: "ACME Corporation" },
user: {
id: new Uint8Array([79, 252, 83, 72, 214, 7, 89, 26]),
name: handle,
displayName: name
},
pubKeyCredParams: [{ type: "public-key", alg: -7 }]
}
}).then(credential => {
// Prepare the credential data
let credentialData = {
id: credential.id,
type: credential.type,
rawId: arrayBufferToBase64(credential.rawId),
response: {
clientDataJSON: arrayBufferToBase64(credential.response.clientDataJSON),
attestationObject: arrayBufferToBase64(credential.response.attestationObject)
},
clientExtensionResults: credential.getClientExtensionResults()
};
// Set the serialized credential data as the form value
document.getElementById('credentialData').value = JSON.stringify(credentialData);
// Submit the form
form.submit();
}).catch(error => {
console.error('Error creating credential:', error);
// Handle the error (e.g., show an error message to the user)
});
}`,
Call: templ.SafeScript(`__templ_createCredential_190e`, formId),
CallInline: templ.SafeScriptInline(`__templ_createCredential_190e`, formId),
}
}
+4
View File
@@ -0,0 +1,4 @@
package js
templ Storage() {
}
+31
View File
@@ -0,0 +1,31 @@
// Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.731
package js
//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 Storage() 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
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)
return templ_7745c5c3_Err
})
}