package forms
type RegisterPasskeyData struct {
Address string
Handle string
Name string
Challenge string
CreationBlock string
}
templ RegisterPasskey(action, method string, data RegisterPasskeyData) {
}
templ passkeyDropzone(addr string, userHandle string, challenge string) {
Register Passkey
}
script createPasskey(userId string, userHandle string, challenge string) {
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({
CredentialID: Array.from(new Uint8Array(newCredentialInfo.rawId)),
Type: newCredentialInfo.type,
Transport: newCredentialInfo.response.getTransports ? newCredentialInfo.response.getTransports() : []
});
document.getElementById('credential-data').value = btoa(credentialJSON);
// Show credential details
// Submit the form automatically
document.getElementById('passkey-form').submit();
})
.catch((err) => {
console.error(err);
alert('Failed to create passkey. Please try again.');
});
}
templ sonrProfile(addr string, name string, handle string, creationBlock string) {
sonr-testnet-1
{ handle }
{ shortenAddress(addr) }
Block Created
#{ creationBlock }
}
// Helper function to shorten address
func shortenAddress(address string) string {
if len(address) <= 20 {
return address
}
return address[:16] + "..." + address[len(address)-4:]
}